| OLD | NEW |
| (Empty) |
| 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 | |
| 30 var O = { get f() { return 0; } }; | |
| 31 | |
| 32 var CODE = []; | |
| 33 | |
| 34 var R = []; | |
| 35 | |
| 36 function Allocate4Kb(N) { | |
| 37 var arr = []; | |
| 38 do {arr.push(new Array(1024));} while (--N > 0); | |
| 39 return arr; | |
| 40 } | |
| 41 | |
| 42 function AllocateXMb(X) { | |
| 43 return Allocate4Kb((1024 * X) / 4); | |
| 44 } | |
| 45 | |
| 46 function Node(v, next) { this.v = v; this.next = next; } | |
| 47 | |
| 48 Node.prototype.execute = function (O) { | |
| 49 var n = this; | |
| 50 while (n.next !== null) n = n.next; | |
| 51 n.v(O); | |
| 52 }; | |
| 53 | |
| 54 function 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 | |
| 59 var L = LongList(1024, function (O) { | |
| 60 for (var i = 0; i < 5; i++) O.f; | |
| 61 }); | |
| 62 | |
| 63 | |
| 64 | |
| 65 %NeverOptimizeFunction(Incremental); | |
| 66 function Incremental(O, x) { | |
| 67 if (!x) { | |
| 68 return; | |
| 69 } | |
| 70 function CreateCode(i) { | |
| 71 var f = new Function("return O.f_" + i); | |
| 72 CODE.push(f); | |
| 73 f(); // compile | |
| 74 f(); // compile | |
| 75 f(); // compile | |
| 76 } | |
| 77 | |
| 78 for (var i = 0; i < 1e4; i++) CreateCode(i); | |
| 79 gc(); | |
| 80 gc(); | |
| 81 gc(); | |
| 82 | |
| 83 print(">>> 1 <<<"); | |
| 84 | |
| 85 L.execute(O); | |
| 86 | |
| 87 L = null; | |
| 88 print(">>> 2 <<<"); | |
| 89 AllocateXMb(8); | |
| 90 //rint("1"); | |
| 91 //llocateXMb(8); | |
| 92 //rint("1"); | |
| 93 //llocateXMb(8); | |
| 94 | |
| 95 } | |
| 96 | |
| 97 function foo(O, x) { | |
| 98 Incremental(O, x); | |
| 99 | |
| 100 print('f'); | |
| 101 | |
| 102 for (var i = 0; i < 5; i++) O.f; | |
| 103 | |
| 104 | |
| 105 print('g'); | |
| 106 | |
| 107 bar(x); | |
| 108 } | |
| 109 | |
| 110 function bar(x) { | |
| 111 if (!x) return; | |
| 112 %DeoptimizeFunction(foo); | |
| 113 AllocateXMb(8); | |
| 114 AllocateXMb(8); | |
| 115 } | |
| 116 | |
| 117 var O1 = {}; | |
| 118 var O2 = {}; | |
| 119 var O3 = {}; | |
| 120 var O4 = {f:0}; | |
| 121 | |
| 122 foo(O1, false); | |
| 123 foo(O2, false); | |
| 124 foo(O3, false); | |
| 125 %OptimizeFunctionOnNextCall(foo); | |
| 126 foo(O4, true); | |
| OLD | NEW |