2013-02-04 12:01:59 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
2018-06-14 15:01:46 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-07-29 09:12:16 +00:00
|
|
|
// Flags: --allow-natives-syntax
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
%NeverOptimizeFunction(test);
|
|
|
|
function test() {
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2018-06-14 15:01:46 +00:00
|
|
|
const iteration_count = 1;
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
function transition1(a, i, v) {
|
|
|
|
a[i] = v;
|
|
|
|
}
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
//
|
|
|
|
// Test PACKED SMI -> PACKED DOUBLE
|
|
|
|
//
|
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(transition1);
|
2018-06-14 15:01:46 +00:00
|
|
|
const a1 = [0, 1, 2, 3, 4];
|
2013-07-19 08:25:44 +00:00
|
|
|
transition1(a1, 0, 2.5);
|
2018-06-14 15:01:46 +00:00
|
|
|
const a2 = [0, 1, 2, 3, 4];
|
2013-07-19 08:25:44 +00:00
|
|
|
transition1(a2, 0, 2.5);
|
2017-06-30 18:00:44 +00:00
|
|
|
assertFalse(%HasHoleyElements(a2));
|
2013-07-19 08:25:44 +00:00
|
|
|
%OptimizeFunctionOnNextCall(transition1);
|
|
|
|
|
2018-06-14 15:01:46 +00:00
|
|
|
const a3 = [0, 1, 2, 3, 4];
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasSmiElements(a3));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition1(a3, 0, 2.5);
|
2017-06-30 18:00:44 +00:00
|
|
|
assertFalse(%HasHoleyElements(a3));
|
2013-07-19 08:25:44 +00:00
|
|
|
assertEquals(4, a3[4]);
|
|
|
|
assertEquals(2.5, a3[0]);
|
|
|
|
|
|
|
|
// Test handling of hole.
|
2018-06-14 15:01:46 +00:00
|
|
|
const a4 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
2013-07-19 08:25:44 +00:00
|
|
|
a4.length = 7;
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasSmiElements(a4));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition1(a4, 0, 2.5);
|
2017-06-30 18:00:44 +00:00
|
|
|
assertFalse(%HasHoleyElements(a4));
|
2013-07-19 08:25:44 +00:00
|
|
|
assertEquals(2.5, a4[0]);
|
|
|
|
assertEquals(undefined, a4[8]);
|
|
|
|
|
|
|
|
// Large array should deopt to runtimea
|
|
|
|
for (j = 0; j < iteration_count; ++j) {
|
2018-06-14 15:01:46 +00:00
|
|
|
const a5 = new Array();
|
2013-07-19 08:25:44 +00:00
|
|
|
for (i = 0; i < 0x40000; ++i) {
|
|
|
|
a5[i] = 0;
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasSmiElements(a5) || %HasDoubleElements(a5));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition1(a5, 0, 2.5);
|
|
|
|
assertEquals(2.5, a5[0]);
|
2013-02-04 12:01:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
//
|
|
|
|
// Test HOLEY SMI -> HOLEY DOUBLE
|
|
|
|
//
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
function transition2(a, i, v) {
|
|
|
|
a[i] = v;
|
|
|
|
}
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(transition2);
|
2018-06-14 15:01:46 +00:00
|
|
|
const b1 = [0, 1, 2, , 4];
|
2013-07-19 08:25:44 +00:00
|
|
|
transition2(b1, 0, 2.5);
|
2018-06-14 15:01:46 +00:00
|
|
|
const b2 = [0, 1, 2, , 4];
|
2013-07-19 08:25:44 +00:00
|
|
|
transition2(b2, 0, 2.5);
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasHoleyElements(b2));
|
2013-07-19 08:25:44 +00:00
|
|
|
%OptimizeFunctionOnNextCall(transition2);
|
|
|
|
|
2018-06-14 15:01:46 +00:00
|
|
|
const b3 = [0, 1, 2, , 4];
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasSmiElements(b3));
|
|
|
|
assertTrue(%HasHoleyElements(b3));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition2(b3, 0, 2.5);
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasHoleyElements(b3));
|
2013-07-19 08:25:44 +00:00
|
|
|
assertEquals(4, b3[4]);
|
|
|
|
assertEquals(2.5, b3[0]);
|
|
|
|
|
|
|
|
// Large array should deopt to runtime
|
|
|
|
for (j = 0; j < iteration_count; ++j) {
|
2018-06-14 15:01:46 +00:00
|
|
|
const b4 = [0, ,0];
|
2013-07-19 08:25:44 +00:00
|
|
|
for (i = 3; i < 0x40000; ++i) {
|
|
|
|
b4[i] = 0;
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasSmiElements(b4));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition2(b4, 0, 2.5);
|
|
|
|
assertEquals(2.5, b4[0]);
|
2013-02-04 12:01:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
//
|
|
|
|
// Test PACKED DOUBLE -> PACKED OBJECT
|
|
|
|
//
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
function transition3(a, i, v) {
|
|
|
|
a[i] = v;
|
|
|
|
}
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(transition3);
|
2018-06-14 15:01:46 +00:00
|
|
|
const c1 = [0, 1, 2, 3.5, 4];
|
2013-07-19 08:25:44 +00:00
|
|
|
transition3(c1, 0, new Object());
|
2018-06-14 15:01:46 +00:00
|
|
|
const c2 = [0, 1, 2, 3.5, 4];
|
2013-07-19 08:25:44 +00:00
|
|
|
transition3(c2, 0, new Object());
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasObjectElements(c2));
|
|
|
|
assertTrue(!%HasHoleyElements(c2));
|
2013-07-19 08:25:44 +00:00
|
|
|
%OptimizeFunctionOnNextCall(transition3);
|
|
|
|
|
2018-06-14 15:01:46 +00:00
|
|
|
const c3 = [0, 1, 2, 3.5, 4];
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasDoubleElements(c3));
|
|
|
|
assertTrue(!%HasHoleyElements(c3));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition3(c3, 0, new Array());
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(!%HasHoleyElements(c3));
|
|
|
|
assertTrue(%HasObjectElements(c3));
|
2013-07-19 08:25:44 +00:00
|
|
|
assertEquals(4, c3[4]);
|
|
|
|
assertEquals(0, c3[0].length);
|
|
|
|
|
|
|
|
// Large array under the deopt threshold should be able to trigger GC without
|
|
|
|
// causing crashes.
|
|
|
|
for (j = 0; j < iteration_count; ++j) {
|
2018-06-14 15:01:46 +00:00
|
|
|
const c4 = [0, 2.5, 0];
|
2013-07-19 08:25:44 +00:00
|
|
|
for (i = 3; i < 0xa000; ++i) {
|
|
|
|
c4[i] = 0;
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasDoubleElements(c4));
|
|
|
|
assertTrue(!%HasHoleyElements(c4));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition3(c4, 0, new Array(5));
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(!%HasHoleyElements(c4));
|
|
|
|
assertTrue(%HasObjectElements(c4));
|
2013-07-19 08:25:44 +00:00
|
|
|
assertEquals(5, c4[0].length);
|
2013-02-04 12:01:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
// Large array should deopt to runtime
|
|
|
|
for (j = 0; j < iteration_count; ++j) {
|
2018-06-14 15:01:46 +00:00
|
|
|
const c5 = [0, 2.5, 0];
|
2013-07-19 08:25:44 +00:00
|
|
|
for (i = 3; i < 0x40000; ++i) {
|
|
|
|
c5[i] = 0;
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasDoubleElements(c5));
|
|
|
|
assertTrue(!%HasHoleyElements(c5));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition3(c5, 0, new Array(5));
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(!%HasHoleyElements(c5));
|
|
|
|
assertTrue(%HasObjectElements(c5));
|
2013-07-19 08:25:44 +00:00
|
|
|
assertEquals(5, c5[0].length);
|
2013-02-04 12:01:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
//
|
|
|
|
// Test HOLEY DOUBLE -> HOLEY OBJECT
|
|
|
|
//
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
function transition4(a, i, v) {
|
|
|
|
a[i] = v;
|
|
|
|
}
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(transition4);
|
2018-06-14 15:01:46 +00:00
|
|
|
const d1 = [0, 1, , 3.5, 4];
|
2013-07-19 08:25:44 +00:00
|
|
|
transition4(d1, 0, new Object());
|
2018-06-14 15:01:46 +00:00
|
|
|
const d2 = [0, 1, , 3.5, 4];
|
2013-07-19 08:25:44 +00:00
|
|
|
transition4(d2, 0, new Object());
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasObjectElements(d2));
|
|
|
|
assertTrue(%HasHoleyElements(d2));
|
2013-07-19 08:25:44 +00:00
|
|
|
%OptimizeFunctionOnNextCall(transition4);
|
|
|
|
|
2018-06-14 15:01:46 +00:00
|
|
|
const d3 = [0, 1, , 3.5, 4];
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasDoubleElements(d3));
|
|
|
|
assertTrue(%HasHoleyElements(d3));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition4(d3, 0, new Array());
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasHoleyElements(d3));
|
|
|
|
assertTrue(%HasObjectElements(d3));
|
2013-07-19 08:25:44 +00:00
|
|
|
assertEquals(4, d3[4]);
|
|
|
|
assertEquals(0, d3[0].length);
|
|
|
|
|
|
|
|
// Large array under the deopt threshold should be able to trigger GC without
|
|
|
|
// causing crashes.
|
|
|
|
for (j = 0; j < iteration_count; ++j) {
|
2018-06-14 15:01:46 +00:00
|
|
|
const d4 = [, 2.5, ,];
|
2013-07-19 08:25:44 +00:00
|
|
|
for (i = 3; i < 0xa000; ++i) {
|
|
|
|
d4[i] = 0;
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasDoubleElements(d4));
|
|
|
|
assertTrue(%HasHoleyElements(d4));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition4(d4, 0, new Array(5));
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasHoleyElements(d4));
|
|
|
|
assertTrue(%HasObjectElements(d4));
|
2013-07-19 08:25:44 +00:00
|
|
|
assertEquals(5, d4[0].length);
|
|
|
|
assertEquals(undefined, d4[2]);
|
2013-02-04 12:01:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 08:25:44 +00:00
|
|
|
// Large array should deopt to runtime
|
|
|
|
for (j = 0; j < iteration_count; ++j) {
|
2018-06-14 15:01:46 +00:00
|
|
|
const d5 = [, 2.5, ,];
|
2013-07-19 08:25:44 +00:00
|
|
|
for (i = 3; i < 0x40000; ++i) {
|
|
|
|
d5[i] = 0;
|
|
|
|
}
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasDoubleElements(d5));
|
|
|
|
assertTrue(%HasHoleyElements(d5));
|
2013-07-19 08:25:44 +00:00
|
|
|
transition4(d5, 0, new Array(5));
|
2017-06-30 18:00:44 +00:00
|
|
|
assertTrue(%HasHoleyElements(d5));
|
|
|
|
assertTrue(%HasObjectElements(d5));
|
2013-07-19 08:25:44 +00:00
|
|
|
assertEquals(5, d5[0].length);
|
|
|
|
assertEquals(undefined, d5[2]);
|
2013-02-04 12:01:59 +00:00
|
|
|
}
|
2013-07-19 08:25:44 +00:00
|
|
|
|
2013-02-04 12:01:59 +00:00
|
|
|
}
|
2013-07-19 08:25:44 +00:00
|
|
|
test();
|