[test] Add %PrepareFunctionForOptimize in mjsunit tests

Bug: v8:8801, v8:8394, v8:9183
Change-Id: Ic31f97a1b591317a004dc52c8eee777dd6353487
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1662299
Commit-Queue: Mythri Alle <mythria@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Auto-Submit: Mythri Alle <mythria@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62216}
This commit is contained in:
Mythri A 2019-06-17 14:34:07 +01:00 committed by Commit Bot
parent 0c5479df6d
commit 9b77a149a6
10 changed files with 79 additions and 2 deletions

View File

@ -13,6 +13,7 @@
f("abc", "de", 1); f("abc", "de", 1);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f("abc", "de", {}); f("abc", "de", {});
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f("abc", "de", {}); f("abc", "de", {});
assertOptimized(f); assertOptimized(f);
@ -27,6 +28,7 @@
f("abc", "de", 1); f("abc", "de", 1);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f("abc", {}, 1); f("abc", {}, 1);
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f("abc", {}, 1); f("abc", {}, 1);
assertOptimized(f); assertOptimized(f);
@ -39,8 +41,10 @@
%PrepareFunctionForOptimization(f); %PrepareFunctionForOptimization(f);
f("abc", "de", 1); f("abc", "de", 1);
f("abc", "de", 1); f("abc", "de", 1);
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f({}, "de", 1); f({}, "de", 1);
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f({}, "de", 1); f({}, "de", 1);
assertOptimized(f); assertOptimized(f);
@ -55,6 +59,7 @@
f("abc", 1); f("abc", 1);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f("abc", {}); f("abc", {});
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f({}, {}); f({}, {});
assertOptimized(f); assertOptimized(f);
@ -69,6 +74,7 @@
f("abc", 1); f("abc", 1);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f("abc", {}); f("abc", {});
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f("abc", {}); f("abc", {});
assertOptimized(f); assertOptimized(f);
@ -84,6 +90,7 @@
f("abc", 1); f("abc", 1);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f("abc", {}); f("abc", {});
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f("abc", {}); f("abc", {});
assertOptimized(f); assertOptimized(f);

View File

@ -168,10 +168,12 @@ assertEquals(2, a.BYTES_PER_ELEMENT);
// Test Float64Arrays. // Test Float64Arrays.
function get(a, index) { function get(a, index) {
return a[index]; return a[index];
} };
%PrepareFunctionForOptimization(get);
function set(a, index, value) { function set(a, index, value) {
a[index] = value; a[index] = value;
} };
%PrepareFunctionForOptimization(set);
function temp() { function temp() {
var array = new Float64Array(2); var array = new Float64Array(2);
for (var i = 0; i < 5; i++) { for (var i = 0; i < 5; i++) {
@ -294,6 +296,7 @@ function test_store_nan(array, sum) {
const kRuns = 10; const kRuns = 10;
function run_test(test_func, array, expected_result) { function run_test(test_func, array, expected_result) {
%PrepareFunctionForOptimization(test_func);
for (var i = 0; i < 5; i++) test_func(array, 0); for (var i = 0; i < 5; i++) test_func(array, 0);
%OptimizeFunctionOnNextCall(test_func); %OptimizeFunctionOnNextCall(test_func);
var sum = 0; var sum = 0;
@ -345,6 +348,7 @@ for (var t = 0; t < types.length; t++) {
assertTrue(delete a.length); assertTrue(delete a.length);
// Make sure bounds checks are handled correctly for external arrays. // Make sure bounds checks are handled correctly for external arrays.
%PrepareFunctionForOptimization(run_bounds_test);
run_bounds_test(a); run_bounds_test(a);
run_bounds_test(a); run_bounds_test(a);
run_bounds_test(a); run_bounds_test(a);
@ -365,6 +369,7 @@ for (var t = 0; t < types.length; t++) {
return a[0] = a[0] = 1; return a[0] = a[0] = 1;
} }
%PrepareFunctionForOptimization(array_load_set_smi_check2);
array_load_set_smi_check2(a); array_load_set_smi_check2(a);
%OptimizeFunctionOnNextCall(array_load_set_smi_check2); %OptimizeFunctionOnNextCall(array_load_set_smi_check2);
array_load_set_smi_check2(a); array_load_set_smi_check2(a);
@ -379,6 +384,7 @@ function store_float32_undefined(ext_array) {
ext_array[0] = undefined; ext_array[0] = undefined;
} }
%PrepareFunctionForOptimization(store_float32_undefined);
var float32_array = new Float32Array(1); var float32_array = new Float32Array(1);
// Make sure runtime does it right // Make sure runtime does it right
store_float32_undefined(float32_array); store_float32_undefined(float32_array);
@ -395,6 +401,7 @@ function store_float64_undefined(ext_array) {
ext_array[0] = undefined; ext_array[0] = undefined;
} }
%PrepareFunctionForOptimization(store_float64_undefined);
var float64_array = new Float64Array(1); var float64_array = new Float64Array(1);
// Make sure runtime does it right // Make sure runtime does it right
store_float64_undefined(float64_array); store_float64_undefined(float64_array);
@ -640,6 +647,8 @@ function boo(a, i, v) {
function do_tagged_index_external_array_test(constructor) { function do_tagged_index_external_array_test(constructor) {
var t_array = new constructor([1, 2, 3, 4, 5, 6]); var t_array = new constructor([1, 2, 3, 4, 5, 6]);
%PrepareFunctionForOptimization(goo);
%PrepareFunctionForOptimization(boo);
assertEquals(1, goo(t_array, 0)); assertEquals(1, goo(t_array, 0));
assertEquals(1, goo(t_array, 0)); assertEquals(1, goo(t_array, 0));
boo(t_array, 0, 13); boo(t_array, 0, 13);
@ -662,6 +671,8 @@ do_tagged_index_external_array_test(Float32Array);
do_tagged_index_external_array_test(Float64Array); do_tagged_index_external_array_test(Float64Array);
var built_in_array = new Array(1, 2, 3, 4, 5, 6); var built_in_array = new Array(1, 2, 3, 4, 5, 6);
%PrepareFunctionForOptimization(goo);
%PrepareFunctionForOptimization(boo);
assertEquals(1, goo(built_in_array, 0)); assertEquals(1, goo(built_in_array, 0));
assertEquals(1, goo(built_in_array, 0)); assertEquals(1, goo(built_in_array, 0));
%OptimizeFunctionOnNextCall(goo); %OptimizeFunctionOnNextCall(goo);
@ -672,6 +683,8 @@ assertEquals(11, goo(built_in_array, 0));
%ClearFunctionFeedback(boo); %ClearFunctionFeedback(boo);
built_in_array = new Array(1.5, 2, 3, 4, 5, 6); built_in_array = new Array(1.5, 2, 3, 4, 5, 6);
%PrepareFunctionForOptimization(goo);
%PrepareFunctionForOptimization(boo);
assertEquals(1.5, goo(built_in_array, 0)); assertEquals(1.5, goo(built_in_array, 0));
assertEquals(1.5, goo(built_in_array, 0)); assertEquals(1.5, goo(built_in_array, 0));
%OptimizeFunctionOnNextCall(goo); %OptimizeFunctionOnNextCall(goo);

View File

@ -613,6 +613,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertOptimized(g); assertOptimized(g);
deopt = true; deopt = true;
g(); g();
%PrepareFunctionForOptimization(g);
assertOptimized(g); assertOptimized(g);
deopt = false; deopt = false;
array = [11,'22',33,45,56,6,77,84,93,101]; array = [11,'22',33,45,56,6,77,84,93,101];
@ -644,6 +645,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertOptimized(g); assertOptimized(g);
deopt = true; deopt = true;
g(); g();
%PrepareFunctionForOptimization(g);
assertOptimized(g); assertOptimized(g);
deopt = false; deopt = false;
array = [11,'22',33,45,56,6,77,84,93,101]; array = [11,'22',33,45,56,6,77,84,93,101];
@ -688,6 +690,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertOptimized(g); assertOptimized(g);
deopt = true; deopt = true;
g(); g();
%PrepareFunctionForOptimization(g);
assertOptimized(g); assertOptimized(g);
deopt = false; deopt = false;
array = [11,'22',33,45,56,6,77,84,93,101]; array = [11,'22',33,45,56,6,77,84,93,101];
@ -745,6 +748,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -780,6 +784,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -815,6 +820,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -851,6 +857,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -910,6 +917,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -948,6 +956,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1050,6 +1059,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertOptimized(g); assertOptimized(g);
deopt = true; deopt = true;
g(); g();
%PrepareFunctionForOptimization(g);
deopt = false; deopt = false;
array = [11,'22',33,45,56,6,77,84,93,101]; array = [11,'22',33,45,56,6,77,84,93,101];
Object.freeze(array); Object.freeze(array);
@ -1105,6 +1115,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
done = true; done = true;
assertEquals(null, g()); assertEquals(null, g());
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1140,6 +1151,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1175,6 +1187,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1211,6 +1224,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
done = true; done = true;
assertEquals(null, g()); assertEquals(null, g());
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1269,6 +1283,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1307,6 +1322,7 @@ assertEquals(undefined, Object.freeze(arr).reduceRight(function(val) { return va
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();

View File

@ -613,6 +613,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertOptimized(g); assertOptimized(g);
deopt = true; deopt = true;
g(); g();
%PrepareFunctionForOptimization(g);
assertOptimized(g); assertOptimized(g);
deopt = false; deopt = false;
array = [11,'22',33,45,56,6,77,84,93,101]; array = [11,'22',33,45,56,6,77,84,93,101];
@ -648,6 +649,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
deopt = false; deopt = false;
array = [11,'22',33,45,56,6,77,84,93,101]; array = [11,'22',33,45,56,6,77,84,93,101];
Object.preventExtensions(array); Object.preventExtensions(array);
%PrepareFunctionForOptimization(g);
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
assertUnoptimized(g); assertUnoptimized(g);
@ -692,6 +694,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
deopt = false; deopt = false;
array = [11,'22',33,45,56,6,77,84,93,101]; array = [11,'22',33,45,56,6,77,84,93,101];
Object.preventExtensions(array); Object.preventExtensions(array);
%PrepareFunctionForOptimization(g);
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
assertUnoptimized(g); assertUnoptimized(g);
@ -745,6 +748,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -780,6 +784,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -815,6 +820,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -851,6 +857,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -910,6 +917,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -948,6 +956,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1050,6 +1059,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertOptimized(g); assertOptimized(g);
deopt = true; deopt = true;
g(); g();
%PrepareFunctionForOptimization(g);
deopt = false; deopt = false;
array = [11,'22',33,45,56,6,77,84,93,101]; array = [11,'22',33,45,56,6,77,84,93,101];
Object.preventExtensions(array); Object.preventExtensions(array);
@ -1105,6 +1115,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
done = true; done = true;
assertEquals(null, g()); assertEquals(null, g());
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1140,6 +1151,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1175,6 +1187,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1211,6 +1224,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
done = true; done = true;
assertEquals(null, g()); assertEquals(null, g());
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1269,6 +1283,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();
@ -1307,6 +1322,7 @@ assertEquals(undefined, Object.preventExtensions(arr).reduceRight(function(val)
assertEquals(null, g()); assertEquals(null, g());
assertOptimized(g); assertOptimized(g);
done = false; done = false;
%PrepareFunctionForOptimization(g);
g(); g(); g(); g();
%OptimizeFunctionOnNextCall(g); %OptimizeFunctionOnNextCall(g);
g(); g();

View File

@ -60,6 +60,7 @@
return v < 8; return v < 8;
}); });
} }
%PrepareFunctionForOptimization(softyPlusEarlyExit);
assertFalse(softyPlusEarlyExit(false)); assertFalse(softyPlusEarlyExit(false));
assertArrayEquals([1, 2, 3, 4, 5, 6, 7, 8], called_values); assertArrayEquals([1, 2, 3, 4, 5, 6, 7, 8], called_values);
softyPlusEarlyExit(false); softyPlusEarlyExit(false);

View File

@ -20,5 +20,6 @@ function f(v3) {
}; };
%PrepareFunctionForOptimization(f); %PrepareFunctionForOptimization(f);
f(Object); f(Object);
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
f(Object); f(Object);

View File

@ -59,4 +59,6 @@ for (i = 0; i < cases.length; ++i) {
%OptimizeFunctionOnNextCall(do_max); %OptimizeFunctionOnNextCall(do_max);
assertEquals(c[3], do_min(c[0], c[1])); assertEquals(c[3], do_min(c[0], c[1]));
assertEquals(c[2], do_max(c[0], c[1])); assertEquals(c[2], do_max(c[0], c[1]));
%PrepareFunctionForOptimization(do_min);
%PrepareFunctionForOptimization(do_max);
} }

View File

@ -52,6 +52,7 @@ f(100000, o3);
// This causes all code for f to be lazily deopted. // This causes all code for f to be lazily deopted.
o2.a = 5; o2.a = 5;
%PrepareFunctionForOptimization(f);
// If OSR did not evict the old code, it will be installed in f here. // If OSR did not evict the old code, it will be installed in f here.
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);

View File

@ -55,6 +55,7 @@ if (standalone) {
optimize = empty_func; optimize = empty_func;
clearFunctionTypeFeedback = empty_func; clearFunctionTypeFeedback = empty_func;
deoptimizeFunction = empty_func; deoptimizeFunction = empty_func;
prepareForOptimize = empty_func;
} else { } else {
optimize = function(name) { optimize = function(name) {
%OptimizeFunctionOnNextCall(name); %OptimizeFunctionOnNextCall(name);
@ -65,6 +66,9 @@ if (standalone) {
deoptimizeFunction = function(name) { deoptimizeFunction = function(name) {
%DeoptimizeFunction(name); %DeoptimizeFunction(name);
} }
prepareForOptimize = function(name) {
%PrepareFunctionForOptimization(name);
}
} }
function base_setter_test(create_func, index, store_value) { function base_setter_test(create_func, index, store_value) {
@ -76,6 +80,7 @@ function base_setter_test(create_func, index, store_value) {
var ap = []; var ap = [];
ap.__defineSetter__(index, function() { calls++; }); ap.__defineSetter__(index, function() { calls++; });
prepareForOptimize(foo);
foo(a); foo(a);
foo(a); foo(a);
foo(a); foo(a);
@ -141,6 +146,7 @@ function base_setter_test(create_func, index, store_value) {
a = create_func(); a = create_func();
ap2 = []; ap2 = [];
a.__proto__ = ap2; a.__proto__ = ap2;
prepareForOptimize(foo);
foo(a); foo(a);
foo(a); foo(a);
foo(a); foo(a);
@ -161,6 +167,7 @@ function base_setter_test(create_func, index, store_value) {
a = create_func(); a = create_func();
a.__proto__ = ap2; a.__proto__ = ap2;
bar = function(a) { a[index+1] = store_value; } bar = function(a) { a[index+1] = store_value; }
prepareForOptimize(bar);
bar(a); bar(a);
bar(a); bar(a);
bar(a); // store should be generic bar(a); // store should be generic

View File

@ -95,30 +95,36 @@
assertEquals(9, x); assertEquals(9, x);
// Test deopt at the beginning of the case label evaluation. // Test deopt at the beginning of the case label evaluation.
%PrepareFunctionForOptimization(f);
assertResult([2], "ca", "deopt", true); assertResult([2], "ca", "deopt", true);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
assertResult([4], "ca", "deopt", false); assertResult([4], "ca", "deopt", false);
assertEquals(10, x); assertEquals(10, x);
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
// Test deopt in the middle of the case label evaluation. // Test deopt in the middle of the case label evaluation.
assertResult([2], "ac", true, "deopt"); assertResult([2], "ac", true, "deopt");
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
assertResult([4], "ac", false, "deopt"); assertResult([4], "ac", false, "deopt");
assertEquals(11, x); assertEquals(11, x);
// Test deopt in the default case. // Test deopt in the default case.
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
print("here"); print("here");
assertResult([4], 10000, false, false, "deopt"); assertResult([4], 10000, false, false, "deopt");
assertEquals(12, x); assertEquals(12, x);
// Test deopt in the default case. // Test deopt in the default case.
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
assertResult([4], 10000, false, false, "deopt"); assertResult([4], 10000, false, false, "deopt");
assertEquals(13, x); assertEquals(13, x);
// Test deopt in x++ case. // Test deopt in x++ case.
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
assertResult([5], 13, false, false, "deopt"); assertResult([5], 13, false, false, "deopt");
assertEquals(14, x); assertEquals(14, x);
@ -159,6 +165,7 @@
break; break;
} }
} }
%PrepareFunctionForOptimization(f);
function assertResult(r, label, b1, b2, b3) { function assertResult(r, label, b1, b2, b3) {
f(label, b1, b2, b3); f(label, b1, b2, b3);
@ -192,30 +199,36 @@
assertEquals(9, x); assertEquals(9, x);
// Test deopt at the beginning of the case label evaluation. // Test deopt at the beginning of the case label evaluation.
%PrepareFunctionForOptimization(f);
assertResult([2,3], "ca", "deopt", true); assertResult([2,3], "ca", "deopt", true);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
assertResult([4,5], "ca", "deopt", false); assertResult([4,5], "ca", "deopt", false);
assertEquals(10, x); assertEquals(10, x);
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
// Test deopt in the middle of the case label evaluation. // Test deopt in the middle of the case label evaluation.
assertResult([2,3], "ac", true, "deopt"); assertResult([2,3], "ac", true, "deopt");
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
assertResult([4,5], "ac", false, "deopt"); assertResult([4,5], "ac", false, "deopt");
assertEquals(11, x); assertEquals(11, x);
// Test deopt in the default case. // Test deopt in the default case.
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
print("here"); print("here");
assertResult([4,5], 10000, false, false, "deopt"); assertResult([4,5], 10000, false, false, "deopt");
assertEquals(12, x); assertEquals(12, x);
// Test deopt in the default case. // Test deopt in the default case.
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
assertResult([4,5], 10000, false, false, "deopt"); assertResult([4,5], 10000, false, false, "deopt");
assertEquals(13, x); assertEquals(13, x);
// Test deopt in x++ case. // Test deopt in x++ case.
%PrepareFunctionForOptimization(f);
%OptimizeFunctionOnNextCall(f); %OptimizeFunctionOnNextCall(f);
assertResult([5], 13, false, false, "deopt"); assertResult([5], 13, false, false, "deopt");
assertEquals(14, x); assertEquals(14, x);