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 | |
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 | |
25 (function() { | |
26 function hot(o) { | |
27 return o.x + o.y; | |
28 } | |
29 function mapPlus(a, y) { | |
30 return a.map(x => hot({x, y})); | |
31 } | |
32 | |
33 var a = [1, 2, 3]; | |
34 print(mapPlus(a, 1)); | |
35 print(mapPlus(a, 2)); | |
36 %OptimizeFunctionOnNextCall(hot); | |
37 print(mapPlus(a, 3)); | |
38 gc(); // BOOOM! | |
39 assertOptimized(hot); | |
40 print(mapPlus(a, 4)); | |
41 })(); | |
42 | |
43 // Verify that we can handle the creation of a new script, where the | |
44 // code is cached and the feedback vector has to be re-created. | |
45 (function() { | |
46 var sopen = "function wrapper() { "; | |
47 var s1 = "function foo() { return bar(5); } "; | |
48 var s2 = "foo(); foo(); %OptimizeFunctionOnNextCall(foo); foo(); "; | |
49 var sclose = "} wrapper(); "; | |
50 var s = sopen + s1 + s2 + sclose; | |
51 function bar(i) { return i + 3 }; | |
52 | |
53 for (var i = 0; i < 4; i++) { | |
54 eval(s); | |
55 } | |
56 })(); | |
OLD | NEW |