OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // New space must be at max capacity to trigger pretenuring decision. | 5 // New space must be at max capacity to trigger pretenuring decision. |
6 // Flags: --allow-natives-syntax --verify-heap --max-semi-space-size=1 | 6 // Flags: --allow-natives-syntax --verify-heap --max-semi-space-size=1 |
7 // Flags: --expose-gc | 7 // Flags: --expose-gc --no-always-opt |
| 8 |
| 9 assertFalse(isAlwaysOptimize()); |
8 | 10 |
9 var global = []; // Used to keep some objects alive. | 11 var global = []; // Used to keep some objects alive. |
10 | 12 |
11 function Ctor() { | 13 function Ctor() { |
12 var result = {a: {}, b: {}, c: {}, d: {}, e: {}, f: {}, g: {}}; | 14 var result = {a: {}, b: {}, c: {}, d: {}, e: {}, f: {}, g: {}}; |
13 return result; | 15 return result; |
14 } | 16 } |
15 | 17 |
16 gc(); | 18 gc(); |
17 | 19 |
18 for (var i = 0; i < 120; i++) { | 20 for (var i = 0; i < 120; i++) { |
19 // Make the "a" property long-lived, while everything else is short-lived. | 21 // Make the "a" property long-lived, while everything else is short-lived. |
20 global.push(Ctor().a); | 22 global.push(Ctor().a); |
21 (function FillNewSpace() { new Array(10000); })(); | 23 (function FillNewSpace() { new Array(10000); })(); |
22 } | 24 } |
23 | 25 |
24 // The bad situation is only triggered if Ctor wasn't optimized too early. | 26 // The bad situation is only triggered if Ctor wasn't optimized too early. |
25 assertUnoptimized(Ctor); | 27 assertUnoptimized(Ctor); |
26 // Optimized code for Ctor will pretenure the "a" property, so it will have | 28 // Optimized code for Ctor will pretenure the "a" property, so it will have |
27 // three allocations: | 29 // three allocations: |
28 // #1 Allocate the "result" object in new-space. | 30 // #1 Allocate the "result" object in new-space. |
29 // #2 Allocate the object stored in the "a" property in old-space. | 31 // #2 Allocate the object stored in the "a" property in old-space. |
30 // #3 Allocate the objects for the "b" through "g" properties in new-space. | 32 // #3 Allocate the objects for the "b" through "g" properties in new-space. |
31 %OptimizeFunctionOnNextCall(Ctor); | 33 %OptimizeFunctionOnNextCall(Ctor); |
32 for (var i = 0; i < 10000; i++) { | 34 for (var i = 0; i < 10000; i++) { |
33 // At least one of these calls will run out of new space. The bug is | 35 // At least one of these calls will run out of new space. The bug is |
34 // triggered when it is allocation #3 that triggers GC. | 36 // triggered when it is allocation #3 that triggers GC. |
35 Ctor(); | 37 Ctor(); |
36 } | 38 } |
OLD | NEW |