1// Copyright 2011 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28// Flags: --allow-natives-syntax --always-compact --expose-gc 29 30var O = { get f() { return 0; } }; 31 32var CODE = []; 33 34var R = []; 35 36function Allocate4Kb(N) { 37 var arr = []; 38 do {arr.push(new Array(1024));} while (--N > 0); 39 return arr; 40} 41 42function AllocateXMb(X) { 43 return Allocate4Kb((1024 * X) / 4); 44} 45 46function Node(v, next) { this.v = v; this.next = next; } 47 48Node.prototype.execute = function (O) { 49 var n = this; 50 while (n.next !== null) n = n.next; 51 n.v(O); 52}; 53 54function LongList(N, x) { 55 if (N == 0) return new Node(x, null); 56 return new Node(new Array(1024), LongList(N - 1, x)); 57} 58 59var L = LongList(1024, function (O) { 60 for (var i = 0; i < 5; i++) O.f; 61}); 62 63 64 65function Incremental(O, x) { 66 if (!x) { 67 return; 68 } 69 function CreateCode(i) { 70 var f = new Function("return O.f_" + i); 71 CODE.push(f); 72 f(); // compile 73 f(); // compile 74 f(); // compile 75 } 76 77 for (var i = 0; i < 1e4; i++) CreateCode(i); 78 gc(); 79 gc(); 80 gc(); 81 82 print(">>> 1 <<<"); 83 84 L.execute(O); 85 86 try {} catch (e) {} 87 88 L = null; 89 print(">>> 2 <<<"); 90 AllocateXMb(8); 91 //rint("1"); 92 //llocateXMb(8); 93 //rint("1"); 94 //llocateXMb(8); 95 96} 97 98function foo(O, x) { 99 Incremental(O, x); 100 101 print('f'); 102 103 for (var i = 0; i < 5; i++) O.f; 104 105 106 print('g'); 107 108 bar(x); 109} 110 111function bar(x) { 112 if (!x) return; 113 %DeoptimizeFunction(foo); 114 AllocateXMb(8); 115 AllocateXMb(8); 116} 117 118var O1 = {}; 119var O2 = {}; 120var O3 = {}; 121var O4 = {f:0}; 122 123foo(O1, false); 124foo(O2, false); 125foo(O3, false); 126%OptimizeFunctionOnNextCall(foo); 127foo(O4, true); 128