2017-12-14 09:22:17 +00:00
|
|
|
// Copyright 2017 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 --opt
|
|
|
|
|
|
|
|
(function test() {
|
|
|
|
function foo(a) { a.push(a.length = 2); }
|
|
|
|
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-14 09:22:17 +00:00
|
|
|
foo([1]);
|
|
|
|
foo([1]);
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo([1]);
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-14 09:22:17 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo([1]);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
2017-12-18 16:39:14 +00:00
|
|
|
(function testElementTypeCheckSmi() {
|
|
|
|
function foo(a) { a.push('a'); }
|
|
|
|
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-18 16:39:14 +00:00
|
|
|
foo([1]);
|
|
|
|
foo([1]);
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo([1]);
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-18 16:39:14 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo([1]);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function testElementTypeCheckDouble() {
|
|
|
|
function foo(a) { a.push('a'); }
|
|
|
|
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-18 16:39:14 +00:00
|
|
|
foo([0.3413312]);
|
|
|
|
foo([0.3413312]);
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo([0.3413312]);
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-18 16:39:14 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo([0.3413312]);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
2017-12-14 09:22:17 +00:00
|
|
|
(function test() {
|
|
|
|
function bar(a) { a.x = 2 };
|
|
|
|
%NeverOptimizeFunction(bar);
|
|
|
|
function foo(a) { a.push(bar(a)); }
|
|
|
|
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-14 09:22:17 +00:00
|
|
|
foo(["1"]);
|
|
|
|
foo(["1"]);
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo(["1"]);
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-14 09:22:17 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo(["1"]);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function test() {
|
|
|
|
function foo(a) { a.push(a.length = 2); }
|
|
|
|
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-14 09:22:17 +00:00
|
|
|
foo([0.34234]);
|
|
|
|
foo([0.34234]);
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo([0.34234]);
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-14 09:22:17 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo([0.34234]);
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
2017-12-15 13:59:20 +00:00
|
|
|
|
|
|
|
(function test() {
|
|
|
|
const N = 128 * 1024;
|
|
|
|
|
|
|
|
function foo(a) { a.push(1); }
|
|
|
|
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-15 13:59:20 +00:00
|
|
|
foo(new Array(N));
|
|
|
|
foo(new Array(N));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo(new Array(N));
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-12-15 13:59:20 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
foo(new Array(N));
|
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function test() {
|
2019-02-13 15:03:24 +00:00
|
|
|
// Conservative arrays lengths in slow and fast mode.
|
|
|
|
const kFastModeLength = 1024;
|
|
|
|
const kSlowModeLength = 512 * 1024;
|
|
|
|
function mkArray(length) {
|
2017-12-15 13:59:20 +00:00
|
|
|
let a = [0.1];
|
2019-02-13 15:03:24 +00:00
|
|
|
a.length = length;
|
2017-12-15 13:59:20 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
function foo(a) { a.push(0.23441233123); }
|
2019-02-13 15:03:24 +00:00
|
|
|
|
2019-02-27 15:51:57 +00:00
|
|
|
|
2019-02-13 15:03:24 +00:00
|
|
|
// 1. Optimize foo to handle fast mode arrays.
|
2019-02-27 15:51:57 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2019-02-13 15:03:24 +00:00
|
|
|
foo(mkArray(kFastModeLength));
|
|
|
|
foo(mkArray(kFastModeLength));
|
2017-12-15 13:59:20 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
2019-02-13 15:03:24 +00:00
|
|
|
foo(mkArray(kFastModeLength));
|
2019-02-27 15:51:57 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
|
|
|
|
// Prepare foo to be re-optimized, ensuring it's bytecode / feedback vector
|
|
|
|
// doesn't get flushed after deoptimization.
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
2019-02-13 15:03:24 +00:00
|
|
|
|
|
|
|
// 2. Given a slow mode array, foo will deopt.
|
|
|
|
foo(mkArray(kSlowModeLength));
|
|
|
|
|
|
|
|
// 3. Optimize foo again.
|
2017-12-15 13:59:20 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
2019-02-13 15:03:24 +00:00
|
|
|
foo(mkArray(kSlowModeLength));
|
|
|
|
// 4. It should stay optimized.
|
2017-12-15 13:59:20 +00:00
|
|
|
assertOptimized(foo);
|
|
|
|
})();
|