v8/test/mjsunit/optimized-foreach-polymorph.js
Mythri A 41ef63df21 [Test] Add %PrepareForOptimization in tests
With bytecode flushing and lazy feedback allocation, we need to call
%PrepareForOptimization before we call %OptimizeFunctionOnNextCall

Bug: v8:8801, v8:8394
Change-Id: I81918f174b2f97cbaa8b8ef2e459080c2581f535
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1588415
Commit-Queue: Mythri Alle <mythria@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61122}
2019-04-30 14:18:22 +00:00

117 lines
2.7 KiB
JavaScript

// 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 --expose-gc --turbo-inline-array-builtins
var a = [0, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,0,0];
var b = [{}, {}];
var c = [,,,,,2,3,4];
var d = [0.5,3,4];
var e = [,,,,0.5,3,4];
// Make sure that calls to forEach handle a certain degree of polymorphism (no
// hole check)
(function() {
var result = 0;
var polymorph1 = function(arg) {
var sum = function(v,i,o) {
result += i;
}
arg.forEach(sum);
};
%PrepareFunctionForOptimization(polymorph1);
polymorph1(a);
polymorph1(a);
polymorph1(b);
polymorph1(a);
polymorph1(a);
%OptimizeFunctionOnNextCall(polymorph1);
polymorph1(a);
polymorph1(b);
assertEquals(1757, result);
})();
// Make sure that calls to forEach handle a certain degree of polymorphism.
(function() {
var result = 0;
var polymorph1 = function(arg) {
var sum = function(v,i,o) {
result += i;
}
arg.forEach(sum);
};
%PrepareFunctionForOptimization(polymorph1);
polymorph1(a);
polymorph1(a);
polymorph1(b);
polymorph1(a);
polymorph1(c);
polymorph1(a);
%OptimizeFunctionOnNextCall(polymorph1);
polymorph1(a);
polymorph1(b);
assertEquals(1775, result);
})();
// Make sure that calls to forEach with mixed object/double arrays don't inline
// forEach.
(function() {
var result = 0;
var polymorph1 = function(arg) {
var sum = function(v,i,o) {
result += i;
}
arg.forEach(sum);
};
%PrepareFunctionForOptimization(polymorph1);
polymorph1(a);
polymorph1(a);
polymorph1(b);
polymorph1(a);
polymorph1(d);
polymorph1(a);
%OptimizeFunctionOnNextCall(polymorph1);
polymorph1(a);
polymorph1(b);
assertEquals(1760, result);
})();
// Make sure that calls to forEach with double arrays get the right result
(function() {
var result = 0;
var polymorph1 = function(arg) {
var sum = function(v,i,o) {
result += v;
}
arg.forEach(sum);
};
%PrepareFunctionForOptimization(polymorph1);
polymorph1(d);
polymorph1(d);
polymorph1(d);
%OptimizeFunctionOnNextCall(polymorph1);
polymorph1(d);
polymorph1(d);
assertEquals(37.5, result);
})();
// Make sure that calls to forEach with mixed double arrays get the right result
(function() {
var result = 0;
var polymorph1 = function(arg) {
var sum = function(v,i,o) {
result += v;
}
arg.forEach(sum);
};
%PrepareFunctionForOptimization(polymorph1);
polymorph1(d);
polymorph1(e);
polymorph1(d);
%OptimizeFunctionOnNextCall(polymorph1);
polymorph1(d);
polymorph1(e);
assertEquals(37.5, result);
})();