OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax --expose-gc --turbo |
| 6 |
| 7 // Make sure literals are strongly rooted and safe from weak-code deopts. |
| 8 |
| 9 (function() { |
| 10 function foo() { |
| 11 var a = {y: 0}; |
| 12 a.y = 1; |
| 13 return a; |
| 14 } |
| 15 |
| 16 foo(); |
| 17 foo(); |
| 18 % OptimizeFunctionOnNextCall(foo); |
| 19 foo(); |
| 20 gc(); |
| 21 assertOptimized(foo); |
| 22 })(); |
| 23 |
| 24 (function() { |
| 25 function hot(o) { |
| 26 return o.x + o.y; |
| 27 } |
| 28 function mapPlus(a, y) { |
| 29 return a.map(x => hot({x, y})); |
| 30 } |
| 31 |
| 32 var a = [1, 2, 3]; |
| 33 print(mapPlus(a, 1)); |
| 34 print(mapPlus(a, 2)); |
| 35 % OptimizeFunctionOnNextCall(hot); |
| 36 print(mapPlus(a, 3)); |
| 37 gc(); // BOOOM! |
| 38 assertOptimized(hot); |
| 39 print(mapPlus(a, 4)); |
| 40 })(); |
| 41 |
| 42 // Verify that we can handle the creation of a new script, where the |
| 43 // code is cached and the feedback vector has to be re-created. |
| 44 (function() { |
| 45 var sopen = 'function wrapper() { '; |
| 46 var s1 = 'function foo() { return bar(5); } '; |
| 47 var s2 = 'foo(); foo(); %OptimizeFunctionOnNextCall(foo); foo(); '; |
| 48 var sclose = '} wrapper(); '; |
| 49 var s = sopen + s1 + s2 + sclose; |
| 50 function bar(i){return i + 3}; |
| 51 |
| 52 for (var i = 0; i < 4; i++) { |
| 53 eval(s); |
| 54 } |
| 55 })(); |
OLD | NEW |