2021-05-21 08:54:53 +00:00
|
|
|
// Copyright 2021 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// Flags: --allow-natives-syntax --turbo-optimize-apply --opt
|
|
|
|
|
|
|
|
// These tests do not work well if this script is run more than once (e.g.
|
|
|
|
// --stress-opt); after a few runs the whole function is immediately compiled
|
|
|
|
// and assertions would fail. We prevent re-runs.
|
|
|
|
// Flags: --nostress-opt --no-always-opt
|
|
|
|
|
2021-05-25 17:52:21 +00:00
|
|
|
// Some of the tests rely on optimizing/deoptimizing at predictable moments, so
|
|
|
|
// this is not suitable for deoptimization fuzzing.
|
|
|
|
// Flags: --deopt-every-n-times=0
|
|
|
|
|
2021-05-21 08:54:53 +00:00
|
|
|
// Tests for optimization of CallWithSpread and CallWithArrayLike.
|
|
|
|
|
|
|
|
// Test JSCallReducer::ReduceJSCallWithArrayLike.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return a + b + c + d;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.apply(null, ["", x, y, z]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
|
|
|
assertOptimized(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertFalse(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
})();
|
|
|
|
|
2021-07-23 12:55:45 +00:00
|
|
|
// Test using receiver
|
|
|
|
(function () {
|
|
|
|
function bar() {
|
|
|
|
return this.gaga;
|
|
|
|
}
|
|
|
|
function foo(receiver) {
|
|
|
|
return bar.apply(receiver, [""]);
|
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(bar);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
var receiver = { gaga: 42 };
|
|
|
|
assertEquals(42, foo(receiver));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals(42, foo(receiver));
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
2021-05-21 08:54:53 +00:00
|
|
|
// Test with holey array.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return a + b + c + d;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.apply(null, ["",x,,y]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('AundefinedB', foo('A', 'B'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals('AundefinedB', foo('A', 'B'));
|
2021-06-06 22:42:17 +00:00
|
|
|
assertFalse(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test with holey-double array.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return a + b + (c ? c : .0) + d;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.apply(null, [3.14, x, , y]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals(45.31, foo(16.11, 26.06));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
|
|
|
|
// This is expected to deoptimize
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals(45.31, foo(16.11, 26.06));
|
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertUnoptimized(foo);
|
|
|
|
|
|
|
|
// Optimize again
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals(45.31, foo(16.11, 26.06));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
// This should stay optimized, but with the call not inlined.
|
|
|
|
assertEquals(45.31, foo(16.11, 26.06));
|
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test deopt when array size changes.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return a + b + c + d;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
let a = ["", x, y, z];
|
2021-05-21 08:54:53 +00:00
|
|
|
a.push('*');
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.apply(null, a);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
// Here array size changes.
|
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
// Here it should deoptimize.
|
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
|
|
|
assertUnoptimized(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
// Now speculation mode prevents the optimization.
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test with FixedDoubleArray.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return a + b + c + d;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.apply(null, [3.14, x, y, z]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals(56.34, foo(11.03, 16.11, 26.06));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
|
|
|
assertEquals(56.34, foo(11.03, 16.11, 26.06));
|
|
|
|
assertFalse(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test with empty array.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var got_interpreted = true;
|
|
|
|
function fortytwo() {
|
|
|
|
got_interpreted = %IsBeingInterpreted();
|
|
|
|
return 42;
|
|
|
|
}
|
|
|
|
function foo() {
|
|
|
|
return fortytwo.apply(null, []);
|
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(fortytwo);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals(42, foo());
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertTrue(got_interpreted);
|
|
|
|
assertEquals(42, foo());
|
|
|
|
assertFalse(got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test with empty array that changes size.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var got_interpreted = true;
|
|
|
|
function fortytwo() {
|
|
|
|
got_interpreted = %IsBeingInterpreted();
|
|
|
|
return 42 + arguments.length;
|
|
|
|
}
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
|
|
|
|
var len = 2;
|
2021-05-21 08:54:53 +00:00
|
|
|
function foo() {
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
let args = []
|
|
|
|
for (var i = 0; i < len; i++) { args.push(1); }
|
|
|
|
let result = fortytwo.apply(null, args);
|
2021-05-21 08:54:53 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(fortytwo);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
assertEquals(44, foo());
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertTrue(got_interpreted);
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
assertEquals(44, foo());
|
2021-05-21 08:54:53 +00:00
|
|
|
assertTrue(got_interpreted);
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
assertOptimized(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
len = 0;
|
|
|
|
assertEquals(42, foo());
|
|
|
|
assertFalse(got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test Reflect.apply().
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return a + b + c + d;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y ,z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return Reflect.apply(sum_js, null, ["", x, y, z]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-06-06 22:42:17 +00:00
|
|
|
assertFalse(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
// Test Reflect.apply() with empty array.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var got_interpreted = true;
|
|
|
|
function fortytwo() {
|
|
|
|
got_interpreted = %IsBeingInterpreted();
|
|
|
|
return 42;
|
|
|
|
}
|
|
|
|
function foo() {
|
|
|
|
return Reflect.apply(fortytwo, null, []);
|
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(fortytwo);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals(42, foo());
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
assertTrue(got_interpreted);
|
|
|
|
assertEquals(42, foo());
|
|
|
|
assertFalse(got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test Reflect.apply() with empty array that changes size.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var got_interpreted = true;
|
|
|
|
function fortytwo() {
|
|
|
|
got_interpreted = %IsBeingInterpreted();
|
|
|
|
return 42 + arguments.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
var len = 2;
|
|
|
|
function foo() {
|
|
|
|
let args = []
|
|
|
|
for (var i = 0; i < len; i++) { args.push(1); }
|
|
|
|
let result = Reflect.apply(fortytwo, null, args);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(fortytwo);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals(44, foo());
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
assertTrue(got_interpreted);
|
|
|
|
assertEquals(44, foo());
|
|
|
|
assertTrue(got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
assertEquals(42, foo());
|
|
|
|
assertFalse(got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
2021-05-21 08:54:53 +00:00
|
|
|
// Test JSCallReducer::ReduceJSCallWithSpread.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return a + b + c + d;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
const numbers = ["", x, y, z];
|
|
|
|
return sum_js(...numbers);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-06-06 22:42:17 +00:00
|
|
|
assertFalse(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test spread call with empty array.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
2021-05-21 08:54:53 +00:00
|
|
|
return a + b + c;
|
|
|
|
}
|
|
|
|
function foo(x, y, z) {
|
|
|
|
const args = [];
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js(x, y, z, ...args);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-06-06 22:42:17 +00:00
|
|
|
assertFalse(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
// Test spread call with empty array that changes size.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var max_got_interpreted = true;
|
|
|
|
function max() {
|
|
|
|
max_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return Math.max(...arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
var len = 2;
|
|
|
|
function foo(x, y, z) {
|
|
|
|
let args = [];
|
|
|
|
for (var i = 0; i < len; i++) { args.push(4 + i); }
|
|
|
|
return max(x, y, z, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(max);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals(5, foo(1, 2, 3));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
assertTrue(max_got_interpreted);
|
|
|
|
assertEquals(5, foo(1, 2, 3));
|
|
|
|
assertTrue(max_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
assertEquals(3, foo(1, 2, 3));
|
|
|
|
assertFalse(max_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
2021-05-21 08:54:53 +00:00
|
|
|
// Test spread call with more args.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var sum_js_got_interpreted = true;
|
2021-06-06 22:42:17 +00:00
|
|
|
function sum_js(a, b, c, d, e, f, g) {
|
|
|
|
assertEquals(7, arguments.length);
|
2021-05-21 08:54:53 +00:00
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
2021-06-06 22:42:17 +00:00
|
|
|
return a + b + c + d + e + f + g;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
const numbers = ["", z, y, x];
|
2021-05-21 08:54:53 +00:00
|
|
|
return sum_js(x, y, z, ...numbers);
|
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('abccba', foo('a', 'b', 'c'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
|
|
|
assertEquals('abccba', foo('a', 'b', 'c'));
|
|
|
|
assertFalse(sum_js_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
// Test on speculative optimization of introduced JSCall (array_size != 0).
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var F = Math.max;
|
|
|
|
var len;
|
|
|
|
function foo(x, y, z) {
|
|
|
|
var args = [z];
|
|
|
|
for (var i = 0; i < len; i++) { args.push(0); }
|
|
|
|
return F(x, y, ...args);
|
|
|
|
}
|
|
|
|
function foo1(x, y, z) {
|
|
|
|
var args = [z];
|
|
|
|
for (var i = 0; i < len; i++) { args.push(0); }
|
|
|
|
return F(x, y, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optimize JSCallWithSpread and Math.max
|
|
|
|
len = 0;
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals(3, foo(1, 2, 3));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
assertEquals(3, foo(1, 2, 3));
|
|
|
|
assertOptimized(foo);
|
|
|
|
// Deoptimize when input of Math.max is not number
|
|
|
|
foo('a', 'b', 3);
|
|
|
|
assertUnoptimized(foo);
|
|
|
|
|
|
|
|
// Optimize JSCallWithSpread and Math.max
|
|
|
|
len = 2;
|
|
|
|
%PrepareFunctionForOptimization(foo1);
|
|
|
|
assertEquals(3, foo1(1, 2, 3));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo1);
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
assertEquals(3, foo1(1, 2, 3));
|
|
|
|
//Deoptimize when array length changes
|
|
|
|
assertUnoptimized(foo1);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test on speculative optimization of introduced JSCall (array_size == 0).
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var F = Math.max;
|
|
|
|
var len;
|
|
|
|
function foo(x, y, z) {
|
|
|
|
var args = [];
|
|
|
|
for (var i = 0; i < len; i++) { args.push(z); }
|
|
|
|
return F(x, y, ...args);
|
|
|
|
}
|
|
|
|
function foo1(x, y, z) {
|
|
|
|
var args = [];
|
|
|
|
for (var i = 0; i < len; i++) { args.push(z); }
|
|
|
|
return F(x, y, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optimize JSCallWithSpread and Math.max
|
|
|
|
len = 0;
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals(2, foo(1, 2, 3));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
assertEquals(2, foo(1, 2, 3));
|
|
|
|
assertOptimized(foo);
|
|
|
|
// Deoptimzie when input of Math.max is not number
|
|
|
|
foo('a', 'b', 3);
|
|
|
|
assertUnoptimized(foo);
|
|
|
|
|
|
|
|
// Optimize JSCallWithSpread and Math.max
|
|
|
|
len = 2;
|
|
|
|
%PrepareFunctionForOptimization(foo1);
|
|
|
|
assertEquals(3, foo1(1, 2, 3));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo1);
|
Optimize JSCallWithArrayLike with diamond speculation when probable arguments list is empty literal array
The JSCallWithArraylike can be replaced with a JSCall if its probable arguments list is empty literal array. This replacement will introduce a deoptimization check to make sure the length of arguments list is 0 at runtime.
This CL change this optimization to a diamond speculation which may help avoid deoptimization once and keep the fast path. This change may benefit a following usecase,
function calcMax(testArray) {
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var result = [];
for (var i = 0; i < testArray.length - 3; i++) {
var positiveNumbers = [];
for (var j = 0; j < 3; j++) {
if (testArray[i + j] > 0) {
positiveNumbers.push(testArray[i + j]);
}
}
result.push(Array.max(positiveNumbers));
}
return result;
}
testArray = [-1, 2, 3, -4, -5, -6, -7, -8, -9, 10];
for (var i = 0; i < 1000000; i++) {
calcMax(testArray);
}
Bug: v8:9974
Change-Id: I595627e2fd937527350c8f8652d701c791b41dd3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967757
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75636}
2021-07-02 14:24:26 +00:00
|
|
|
assertEquals(3, foo1(1, 2, 3));
|
|
|
|
assertOptimized(foo1);
|
|
|
|
// No Deoptimization when array length changes
|
|
|
|
foo(1, 2, 3);
|
|
|
|
assertUnoptimized(foo);
|
|
|
|
})();
|
|
|
|
|
2021-05-21 08:54:53 +00:00
|
|
|
// Test apply on JSCreateClosure.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var sum_got_interpreted = true;
|
|
|
|
function foo_closure() {
|
2021-06-06 22:42:17 +00:00
|
|
|
return function(a, b, c, d) {
|
2021-05-21 08:54:53 +00:00
|
|
|
sum_got_interpreted = %IsBeingInterpreted();
|
2021-06-06 22:42:17 +00:00
|
|
|
return a + b + c + d;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const _foo_closure = foo_closure();
|
|
|
|
%PrepareFunctionForOptimization(_foo_closure);
|
|
|
|
|
|
|
|
function foo(x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return foo_closure().apply(null, ["", x, y, z]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(foo_closure);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo_closure);
|
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertTrue(sum_got_interpreted);
|
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
|
|
|
assertFalse(sum_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test apply with JSBoundFunction
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var sum_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d, e) {
|
|
|
|
sum_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return this.x + a + b + c + d + e;
|
|
|
|
}
|
|
|
|
const f = sum_js.bind({ x: 26 }, 11, 3);
|
|
|
|
function foo(a, b, c) {
|
|
|
|
return f.apply(null, [a, b, c]);
|
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals(166, foo(40, 42, 44));
|
|
|
|
assertTrue(sum_got_interpreted);
|
|
|
|
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals(166, foo(40, 42, 44));
|
|
|
|
assertFalse(sum_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test apply with nested bindings
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var sum_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d, e) {
|
|
|
|
sum_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return this.x + a + b + c + d + e;
|
|
|
|
}
|
|
|
|
const f = sum_js.bind({ x: 26 }, 11).bind({ y: 4 }, 3);
|
|
|
|
function foo(x, y, z) {
|
|
|
|
return f.apply(null, [x, y, z]);
|
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals(166, foo(40, 42, 44));
|
|
|
|
assertTrue(sum_got_interpreted);
|
|
|
|
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals(166, foo(40, 42, 44));
|
|
|
|
assertFalse(sum_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test apply on bound function (JSCreateBoundFunction).
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var sum_got_interpreted = true;
|
2021-06-06 22:42:17 +00:00
|
|
|
function sum_js(a, b, c, d) {
|
2021-05-21 08:54:53 +00:00
|
|
|
sum_got_interpreted = %IsBeingInterpreted();
|
2021-06-06 22:42:17 +00:00
|
|
|
return this.x + a + b + c + d;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.bind({ x: 42 }).apply(null, ["", x, y, z]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('42abc', foo('a', 'b', 'c'));
|
|
|
|
assertTrue(sum_got_interpreted);
|
|
|
|
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals('42abc', foo('a', 'b', 'c'));
|
|
|
|
assertFalse(sum_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test apply on bound function (JSCreateBoundFunction) with args.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var sum_got_interpreted = true;
|
2021-06-06 22:42:17 +00:00
|
|
|
function sum_js(a, b, c, d, e, f) {
|
2021-05-21 08:54:53 +00:00
|
|
|
sum_got_interpreted = %IsBeingInterpreted();
|
2021-06-06 22:42:17 +00:00
|
|
|
return this.x + a + b + c + d + e + f;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.bind({ x: 3 }, 11, 31).apply(null, ["", x, y, z]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('45abc', foo('a', 'b', 'c'));
|
|
|
|
assertTrue(sum_got_interpreted);
|
|
|
|
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals('45abc', foo('a', 'b', 'c'));
|
|
|
|
assertFalse(sum_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test call with array-like under-application.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var sum_js_got_interpreted = true;
|
2021-06-06 22:42:17 +00:00
|
|
|
function sum_js(a, b, c, d) {
|
2021-05-21 08:54:53 +00:00
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
2021-06-06 22:42:17 +00:00
|
|
|
return a + b + c + d + arguments.length;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.apply(null, ["", x, y]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals('ABundefined3', foo('A', 'B'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals('ABundefined3', foo('A', 'B'));
|
2021-05-21 08:54:53 +00:00
|
|
|
assertFalse(sum_js_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test call with array-like over-application.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var sum_js_got_interpreted = true;
|
2021-06-06 22:42:17 +00:00
|
|
|
function sum_js(a, b, c, d) {
|
2021-05-21 08:54:53 +00:00
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
2021-06-06 22:42:17 +00:00
|
|
|
return a + b + c + d + arguments.length;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(v, w, x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.apply(null, ["", v, w, x, y, z]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals('abc6', foo('a', 'b', 'c', 'd', 'e'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals('abc6', foo('a', 'b', 'c', 'd', 'e'));
|
2021-05-21 08:54:53 +00:00
|
|
|
assertFalse(sum_js_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test call with spread under-application.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var sum_js_got_interpreted = true;
|
2021-06-06 22:42:17 +00:00
|
|
|
function sum_js(a, b, c, d) {
|
2021-05-21 08:54:53 +00:00
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
2021-06-06 22:42:17 +00:00
|
|
|
return a + b + c + d + arguments.length;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y) {
|
2021-06-06 22:42:17 +00:00
|
|
|
const numbers = ["", x, y];
|
2021-05-21 08:54:53 +00:00
|
|
|
return sum_js(...numbers);
|
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals('ABundefined3', foo('A', 'B'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals('ABundefined3', foo('A', 'B'));
|
2021-05-21 08:54:53 +00:00
|
|
|
assertFalse(sum_js_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test call with spread over-application.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return a + b + c + d + arguments.length;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(v, w, x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
const numbers = ["", v, w, x, y, z];
|
|
|
|
return sum_js(...numbers);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertEquals('abc6', foo('a', 'b', 'c', 'd', 'e'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
|
|
|
assertEquals('abc6', foo('a', 'b', 'c', 'd', 'e'));
|
|
|
|
assertFalse(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test calling function that has rest parameters.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, ...moreArgs) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
2021-06-06 22:42:17 +00:00
|
|
|
return a + b + moreArgs[0] + moreArgs[1] + moreArgs[2] + moreArgs[3];
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(v, w, x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.apply(null, ["", v, w, x, y, z]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('abcde', foo('a', 'b', 'c', 'd', 'e'));
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
|
|
|
assertEquals('abcde', foo('a', 'b', 'c', 'd', 'e'));
|
|
|
|
assertFalse(sum_js_got_interpreted);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test with 'arguments'.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
2021-05-21 08:54:53 +00:00
|
|
|
return a + b + c;
|
|
|
|
}
|
|
|
|
function foo() {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.apply(null, arguments);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
|
|
|
|
// The call is not inlined with CreateArguments.
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(foo);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals('abc', foo('a', 'b', 'c'));
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Test with inlined calls.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
2021-06-06 22:42:17 +00:00
|
|
|
var sum_js_got_interpreted = true;
|
|
|
|
function sum_js(a, b, c, d) {
|
|
|
|
sum_js_got_interpreted = %IsBeingInterpreted();
|
|
|
|
return a + b + c + d;
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function foo(x, y, z) {
|
2021-06-06 22:42:17 +00:00
|
|
|
return sum_js.apply(null, ["", x, y, z]);
|
2021-05-21 08:54:53 +00:00
|
|
|
}
|
|
|
|
function bar(a, b, c) {
|
|
|
|
return foo(c, b, a);
|
|
|
|
}
|
|
|
|
|
2021-06-06 22:42:17 +00:00
|
|
|
%PrepareFunctionForOptimization(sum_js);
|
2021-05-21 08:54:53 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
%PrepareFunctionForOptimization(bar);
|
|
|
|
assertEquals('cba', bar('a', 'b', 'c'));
|
2021-06-06 22:42:17 +00:00
|
|
|
assertTrue(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
|
|
|
|
// Optimization also works if the call is in an inlined function.
|
2021-07-22 15:25:38 +00:00
|
|
|
%OptimizeFunctionForTopTier(bar);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertEquals('cba', bar('a', 'b', 'c'));
|
2021-06-06 22:42:17 +00:00
|
|
|
assertFalse(sum_js_got_interpreted);
|
2021-05-21 08:54:53 +00:00
|
|
|
assertOptimized(bar);
|
|
|
|
})();
|