[test] Fix compiler/serializer-tester to work with lazy feedback allocation

Bug: v8:8394
Change-Id: Id506166f96cee5be7dc0875288f33532bae83db3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1601504
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Commit-Queue: Mythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61408}
This commit is contained in:
Mythri A 2019-05-09 10:32:00 +01:00 committed by Commit Bot
parent 6644f2b872
commit fb969041f6

View File

@ -30,6 +30,7 @@ SerializerTester::SerializerTester(const char* source)
FLAG_always_opt = false; FLAG_always_opt = false;
// We need allocation of executable memory for the compilation. // We need allocation of executable memory for the compilation.
FLAG_jitless = false; FLAG_jitless = false;
FLAG_allow_natives_syntax = true;
std::string function_string = "(function() { "; std::string function_string = "(function() { ";
function_string += source; function_string += source;
@ -49,7 +50,8 @@ SerializerTester::SerializerTester(const char* source)
} }
TEST(SerializeEmptyFunction) { TEST(SerializeEmptyFunction) {
SerializerTester tester("function f() {}; return f;"); SerializerTester tester(
"function f() {}; %EnsureFeedbackVectorForFunction(f); return f;");
CHECK(tester.function().IsSerializedForCompilation()); CHECK(tester.function().IsSerializedForCompilation());
} }
@ -79,32 +81,45 @@ void CheckForSerializedInlinee(const char* source, int argc = 0,
TEST(SerializeInlinedClosure) { TEST(SerializeInlinedClosure) {
CheckForSerializedInlinee( CheckForSerializedInlinee(
"function f() {" "function f() {"
" return (function g(){ return g; })();" " function g(){ return g; }"
"}; f(); return f;"); " %EnsureFeedbackVectorForFunction(g);"
" return g();"
"};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;");
} }
TEST(SerializeInlinedFunction) { TEST(SerializeInlinedFunction) {
CheckForSerializedInlinee( CheckForSerializedInlinee(
"function g() {};" "function g() {};"
"%EnsureFeedbackVectorForFunction(g);"
"function f() {" "function f() {"
" g(); return g;" " g(); return g;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;");
} }
TEST(SerializeCallUndefinedReceiver) { TEST(SerializeCallUndefinedReceiver) {
CheckForSerializedInlinee( CheckForSerializedInlinee(
"function g(a,b,c) {};" "function g(a,b,c) {};"
"%EnsureFeedbackVectorForFunction(g);"
"function f() {" "function f() {"
" g(1,2,3); return g;" " g(1,2,3); return g;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;");
} }
TEST(SerializeCallUndefinedReceiver2) { TEST(SerializeCallUndefinedReceiver2) {
CheckForSerializedInlinee( CheckForSerializedInlinee(
"function g(a,b) {};" "function g(a,b) {};"
"%EnsureFeedbackVectorForFunction(g);"
"function f() {" "function f() {"
" g(1,2); return g;" " g(1,2); return g;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;");
} }
TEST(SerializeCallProperty) { TEST(SerializeCallProperty) {
@ -112,9 +127,12 @@ TEST(SerializeCallProperty) {
"let obj = {" "let obj = {"
" g: function g(a,b,c) {}" " g: function g(a,b,c) {}"
"};" "};"
"%EnsureFeedbackVectorForFunction(obj.g);"
"function f() {" "function f() {"
" obj.g(1,2,3); return obj.g;" " obj.g(1,2,3); return obj.g;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;");
} }
TEST(SerializeCallProperty2) { TEST(SerializeCallProperty2) {
@ -122,9 +140,12 @@ TEST(SerializeCallProperty2) {
"let obj = {" "let obj = {"
" g: function g(a,b) {}" " g: function g(a,b) {}"
"};" "};"
"%EnsureFeedbackVectorForFunction(obj.g);"
"function f() {" "function f() {"
" obj.g(1,2); return obj.g;" " obj.g(1,2); return obj.g;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;");
} }
TEST(SerializeCallAnyReceiver) { TEST(SerializeCallAnyReceiver) {
@ -132,21 +153,26 @@ TEST(SerializeCallAnyReceiver) {
"let obj = {" "let obj = {"
" g: function g() {}" " g: function g() {}"
"};" "};"
"%EnsureFeedbackVectorForFunction(obj.g);"
"function f() {" "function f() {"
" with(obj) {" " with(obj) {"
" g(); return g;" " g(); return g;"
" };" " };"
"};" "};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;"); "f(); return f;");
} }
TEST(SerializeCallWithSpread) { TEST(SerializeCallWithSpread) {
CheckForSerializedInlinee( CheckForSerializedInlinee(
"function g(args) {};" "function g(args) {};"
"%EnsureFeedbackVectorForFunction(g);"
"const arr = [1,2,3];" "const arr = [1,2,3];"
"function f() {" "function f() {"
" g(...arr); return g;" " g(...arr); return g;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;");
} }
// The following test causes the CallIC of `g` to turn megamorphic, // The following test causes the CallIC of `g` to turn megamorphic,
@ -157,38 +183,53 @@ TEST(SerializeCallArguments) {
"function g(callee) { callee(); };" "function g(callee) { callee(); };"
"function h() {};" "function h() {};"
"function i() {};" "function i() {};"
"%EnsureFeedbackVectorForFunction(g);"
"g(h); g(i);" "g(h); g(i);"
"function f() {" "function f() {"
" function j() {};" " function j() {};"
" g(j);" " g(j);"
" return j;" " return j;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"var j = f();"
"%EnsureFeedbackVectorForFunction(j);"
"f(); return f;");
} }
TEST(SerializeConstruct) { TEST(SerializeConstruct) {
CheckForSerializedInlinee( CheckForSerializedInlinee(
"function g() {};" "function g() {};"
"%EnsureFeedbackVectorForFunction(g);"
"function f() {" "function f() {"
" new g(); return g;" " new g(); return g;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;");
} }
TEST(SerializeConstructWithSpread) { TEST(SerializeConstructWithSpread) {
CheckForSerializedInlinee( CheckForSerializedInlinee(
"function g(a, b, c) {};" "function g(a, b, c) {};"
"%EnsureFeedbackVectorForFunction(g);"
"const arr = [1, 2];" "const arr = [1, 2];"
"function f() {" "function f() {"
" new g(0, ...arr); return g;" " new g(0, ...arr); return g;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;");
} }
TEST(SerializeConstructSuper) { TEST(SerializeConstructSuper) {
CheckForSerializedInlinee( CheckForSerializedInlinee(
"class A {};" "class A {};"
"class B extends A { constructor() { super(); } };" "class B extends A { constructor() { super(); } };"
"%EnsureFeedbackVectorForFunction(A);"
"%EnsureFeedbackVectorForFunction(B);"
"function f() {" "function f() {"
" new B(); return A;" " new B(); return A;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"f(); return f;");
} }
TEST(SerializeConditionalJump) { TEST(SerializeConditionalJump) {
@ -202,7 +243,11 @@ TEST(SerializeConditionalJump) {
" function q() {};" " function q() {};"
" if (a) g(q);" " if (a) g(q);"
" return q;" " return q;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"var q = f();"
"%EnsureFeedbackVectorForFunction(q);"
"f(); return f;");
} }
TEST(SerializeUnconditionalJump) { TEST(SerializeUnconditionalJump) {
@ -210,6 +255,9 @@ TEST(SerializeUnconditionalJump) {
"function g(callee) { callee(); };" "function g(callee) { callee(); };"
"function h() {};" "function h() {};"
"function i() {};" "function i() {};"
"%EnsureFeedbackVectorForFunction(g);"
"%EnsureFeedbackVectorForFunction(h);"
"%EnsureFeedbackVectorForFunction(i);"
"let a = false;" "let a = false;"
"g(h); g(i);" "g(h); g(i);"
"function f() {" "function f() {"
@ -218,7 +266,11 @@ TEST(SerializeUnconditionalJump) {
" if (a) g(q);" " if (a) g(q);"
" else g(p);" " else g(p);"
" return p;" " return p;"
"}; f(); return f;"); "};"
"%EnsureFeedbackVectorForFunction(f);"
"var p = f();"
"%EnsureFeedbackVectorForFunction(p);"
"f(); return f;");
} }
} // namespace compiler } // namespace compiler