blob: 9117440c2c843fe0b37ee68f5cd059e2b7314d1c [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
3// found in the LICENSE file.
4
5// New space must be at max capacity to trigger pretenuring decision.
6// Flags: --allow-natives-syntax --verify-heap --max-semi-space-size=1
7
8var global = []; // Used to keep some objects alive.
9
10function Ctor() {
11 var result = {a: {}, b: {}, c: {}, d: {}, e: {}, f: {}, g: {}};
12 return result;
13}
14
15for (var i = 0; i < 120; i++) {
16 // Make the "a" property long-lived, while everything else is short-lived.
17 global.push(Ctor().a);
18 (function FillNewSpace() { new Array(10000); })();
19}
20
21// The bad situation is only triggered if Ctor wasn't optimized too early.
22assertUnoptimized(Ctor);
23// Optimized code for Ctor will pretenure the "a" property, so it will have
24// three allocations:
25// #1 Allocate the "result" object in new-space.
26// #2 Allocate the object stored in the "a" property in old-space.
27// #3 Allocate the objects for the "b" through "g" properties in new-space.
28%OptimizeFunctionOnNextCall(Ctor);
29for (var i = 0; i < 10000; i++) {
30 // At least one of these calls will run out of new space. The bug is
31 // triggered when it is allocation #3 that triggers GC.
32 Ctor();
33}