| Index: test/cctest/compiler/test-run-inlining.cc
|
| diff --git a/test/cctest/compiler/test-run-inlining.cc b/test/cctest/compiler/test-run-inlining.cc
|
| index 1e52b3506da7f6426890dd2d6999d09c240f0c04..ad82fecaa20fab5e7f8f8eb7e8b274781cb38fe9 100644
|
| --- a/test/cctest/compiler/test-run-inlining.cc
|
| +++ b/test/cctest/compiler/test-run-inlining.cc
|
| @@ -11,49 +11,70 @@
|
| using namespace v8::internal;
|
| using namespace v8::internal::compiler;
|
|
|
| -// TODO(sigurds) At the moment we do not write optimization frames when
|
| -// inlining, thus the reported stack depth changes depending on inlining.
|
| -// AssertStackDepth checks the stack depth actually changes as a simple way
|
| -// to ensure that inlining actually occurs.
|
| -// Once inlining creates optimization frames, all these unit tests need to
|
| -// check that the optimization frame is there.
|
| -
|
| -
|
| -static void AssertStackDepth(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
| - v8::HandleScope scope(args.GetIsolate());
|
| - v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
|
| - args.GetIsolate(), 10, v8::StackTrace::kDetailed);
|
| - CHECK_EQ(args[0]->ToInt32()->Value(), stackTrace->GetFrameCount());
|
| +// Helper to determine inline count via JavaScriptFrame::GetInlineCount.
|
| +// Note that a count of 1 indicates that no inlining has occured.
|
| +static void AssertInlineCount(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
| + StackTraceFrameIterator it(CcTest::i_isolate());
|
| + int frames_seen = 0;
|
| + JavaScriptFrame* topmost = it.frame();
|
| + while (!it.done()) {
|
| + JavaScriptFrame* frame = it.frame();
|
| + PrintF("%d %s, inline count: %d\n", frames_seen,
|
| + frame->function()->shared()->DebugName()->ToCString().get(),
|
| + frame->GetInlineCount());
|
| + frames_seen++;
|
| + it.Advance();
|
| + }
|
| + CHECK_EQ(args[0]->ToInt32()->Value(), topmost->GetInlineCount());
|
| }
|
|
|
|
|
| -static void InstallAssertStackDepthHelper(v8::Isolate* isolate) {
|
| +static void InstallAssertInlineCountHelper(v8::Isolate* isolate) {
|
| v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
| v8::Local<v8::FunctionTemplate> t =
|
| - v8::FunctionTemplate::New(isolate, AssertStackDepth);
|
| - context->Global()->Set(v8_str("AssertStackDepth"), t->GetFunction());
|
| + v8::FunctionTemplate::New(isolate, AssertInlineCount);
|
| + context->Global()->Set(v8_str("AssertInlineCount"), t->GetFunction());
|
| }
|
|
|
|
|
| TEST(SimpleInlining) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function(){"
|
| - "function foo(s) { AssertStackDepth(1); return s; };"
|
| + "function foo(s) { AssertInlineCount(2); return s; };"
|
| "function bar(s, t) { return foo(s); };"
|
| "return bar;})();",
|
| CompilationInfo::kInliningEnabled |
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| + T.CheckCall(T.Val(1), T.Val(1), T.Val(2));
|
| +}
|
| +
|
| +
|
| +TEST(SimpleInliningDeopt) {
|
| + FLAG_turbo_deoptimization = true;
|
| + FunctionTester T(
|
| + "(function(){"
|
| + "function foo(s) { %DeoptimizeFunction(bar); return "
|
| + "s; };"
|
| + "function bar(s, t) { return foo(s); };"
|
| + "return bar;})();",
|
| + CompilationInfo::kInliningEnabled |
|
| + CompilationInfo::kContextSpecializing |
|
| + CompilationInfo::kTypingEnabled);
|
| +
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(1), T.Val(1), T.Val(2));
|
| }
|
|
|
|
|
| TEST(SimpleInliningContext) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function () {"
|
| - "function foo(s) { AssertStackDepth(1); var x = 12; return s + x; };"
|
| + "function foo(s) { AssertInlineCount(2); var x = 12; return s + x; };"
|
| "function bar(s, t) { return foo(s); };"
|
| "return bar;"
|
| "})();",
|
| @@ -61,12 +82,33 @@ TEST(SimpleInliningContext) {
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| + T.CheckCall(T.Val(13), T.Val(1), T.Val(2));
|
| +}
|
| +
|
| +
|
| +TEST(SimpleInliningContextDeopt) {
|
| + FLAG_turbo_deoptimization = true;
|
| + FunctionTester T(
|
| + "(function () {"
|
| + "function foo(s) { "
|
| + " AssertInlineCount(2); %DeoptimizeFunction(bar); var x = 12;"
|
| + " return s + x;"
|
| + "};"
|
| + "function bar(s, t) { return foo(s); };"
|
| + "return bar;"
|
| + "})();",
|
| + CompilationInfo::kInliningEnabled |
|
| + CompilationInfo::kContextSpecializing |
|
| + CompilationInfo::kTypingEnabled);
|
| +
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(13), T.Val(1), T.Val(2));
|
| }
|
|
|
|
|
| TEST(CaptureContext) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "var f = (function () {"
|
| "var x = 42;"
|
| @@ -78,7 +120,7 @@ TEST(CaptureContext) {
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
|
| }
|
|
|
| @@ -86,42 +128,65 @@ TEST(CaptureContext) {
|
| // TODO(sigurds) For now we do not inline any native functions. If we do at
|
| // some point, change this test.
|
| TEST(DontInlineEval) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "var x = 42;"
|
| "(function () {"
|
| - "function bar(s, t) { return eval(\"AssertStackDepth(2); x\") };"
|
| + "function bar(s, t) { return eval(\"AssertInlineCount(1); x\") };"
|
| "return bar;"
|
| "})();",
|
| CompilationInfo::kInliningEnabled |
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(42), T.Val("x"), T.undefined());
|
| }
|
|
|
|
|
| TEST(InlineOmitArguments) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function () {"
|
| "var x = 42;"
|
| - "function bar(s, t, u, v) { AssertStackDepth(1); return x + s; };"
|
| + "function bar(s, t, u, v) { AssertInlineCount(2); return x + s; };"
|
| "return (function (s,t) { return bar(s); });"
|
| "})();",
|
| CompilationInfo::kInliningEnabled |
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
|
| }
|
|
|
|
|
| +TEST(InlineOmitArgumentsDeopt) {
|
| + FLAG_turbo_deoptimization = true;
|
| + FunctionTester T(
|
| + "(function () {"
|
| + "function foo(s,t,u,v) { AssertInlineCount(2); %DeoptimizeFunction(bar); "
|
| + "return baz(); };"
|
| + "function bar() { return foo(11); };"
|
| + "function baz() { return foo.arguments.length == 1 && "
|
| + " foo.arguments[0] == 11 ; }"
|
| + "return bar;"
|
| + "})();",
|
| + CompilationInfo::kInliningEnabled |
|
| + CompilationInfo::kContextSpecializing |
|
| + CompilationInfo::kTypingEnabled);
|
| +
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| + T.CheckCall(T.true_value(), T.Val(12), T.Val(14));
|
| +}
|
| +
|
| +
|
| TEST(InlineSurplusArguments) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function () {"
|
| "var x = 42;"
|
| - "function foo(s) { AssertStackDepth(1); return x + s; };"
|
| + "function foo(s) { AssertInlineCount(2); return x + s; };"
|
| "function bar(s,t) { return foo(s,t,13); };"
|
| "return bar;"
|
| "})();",
|
| @@ -129,32 +194,56 @@ TEST(InlineSurplusArguments) {
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
|
| }
|
|
|
|
|
| +TEST(InlineSurplusArgumentsDeopt) {
|
| + FLAG_turbo_deoptimization = true;
|
| + FunctionTester T(
|
| + "(function () {"
|
| + "function foo(s) { AssertInlineCount(2); %DeoptimizeFunction(bar); "
|
| + "return baz(); };"
|
| + "function bar() { return foo(13, 14, 15); };"
|
| + "function baz() { return foo.arguments.length == 3 && "
|
| + " foo.arguments[0] == 13 && "
|
| + " foo.arguments[1] == 14 && "
|
| + " foo.arguments[2] == 15; }"
|
| + "return bar;"
|
| + "})();",
|
| + CompilationInfo::kInliningEnabled |
|
| + CompilationInfo::kContextSpecializing |
|
| + CompilationInfo::kTypingEnabled);
|
| +
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| + T.CheckCall(T.true_value(), T.Val(12), T.Val(14));
|
| +}
|
| +
|
| +
|
| TEST(InlineTwice) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function () {"
|
| "var x = 42;"
|
| - "function bar(s) { AssertStackDepth(1); return x + s; };"
|
| + "function bar(s) { AssertInlineCount(2); return x + s; };"
|
| "return (function (s,t) { return bar(s) + bar(t); });"
|
| "})();",
|
| CompilationInfo::kInliningEnabled |
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4));
|
| }
|
|
|
|
|
| TEST(InlineTwiceDependent) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function () {"
|
| "var x = 42;"
|
| - "function foo(s) { AssertStackDepth(1); return x + s; };"
|
| + "function foo(s) { AssertInlineCount(2); return x + s; };"
|
| "function bar(s,t) { return foo(foo(s)); };"
|
| "return bar;"
|
| "})();",
|
| @@ -162,16 +251,17 @@ TEST(InlineTwiceDependent) {
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4));
|
| }
|
|
|
|
|
| TEST(InlineTwiceDependentDiamond) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function () {"
|
| "var x = 41;"
|
| - "function foo(s) { AssertStackDepth(1); if (s % 2 == 0) {"
|
| + "function foo(s) { AssertInlineCount(2); if (s % 2 == 0) {"
|
| " return x - s } else { return x + s; } };"
|
| "function bar(s,t) { return foo(foo(s)); };"
|
| "return bar;"
|
| @@ -180,16 +270,17 @@ TEST(InlineTwiceDependentDiamond) {
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(-11), T.Val(11), T.Val(4));
|
| }
|
|
|
|
|
| TEST(InlineTwiceDependentDiamondDifferent) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function () {"
|
| "var x = 41;"
|
| - "function foo(s,t) { AssertStackDepth(1); if (s % 2 == 0) {"
|
| + "function foo(s,t) { AssertInlineCount(2); if (s % 2 == 0) {"
|
| " return x - s * t } else { return x + s * t; } };"
|
| "function bar(s,t) { return foo(foo(s, 3), 5); };"
|
| "return bar;"
|
| @@ -198,16 +289,17 @@ TEST(InlineTwiceDependentDiamondDifferent) {
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(-329), T.Val(11), T.Val(4));
|
| }
|
|
|
|
|
| TEST(InlineLoop) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function () {"
|
| "var x = 41;"
|
| - "function foo(s) { AssertStackDepth(1); while (s > 0) {"
|
| + "function foo(s) { AssertInlineCount(2); while (s > 0) {"
|
| " s = s - 1; }; return s; };"
|
| "function bar(s,t) { return foo(foo(s)); };"
|
| "return bar;"
|
| @@ -216,12 +308,13 @@ TEST(InlineLoop) {
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(0.0), T.Val(11), T.Val(4));
|
| }
|
|
|
|
|
| TEST(InlineStrictIntoNonStrict) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function () {"
|
| "var x = Object.create({}, { y: { value:42, writable:false } });"
|
| @@ -234,12 +327,13 @@ TEST(InlineStrictIntoNonStrict) {
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckThrows(T.undefined(), T.undefined());
|
| }
|
|
|
|
|
| TEST(InlineNonStrictIntoStrict) {
|
| + FLAG_turbo_deoptimization = true;
|
| FunctionTester T(
|
| "(function () {"
|
| "var x = Object.create({}, { y: { value:42, writable:false } });"
|
| @@ -251,7 +345,7 @@ TEST(InlineNonStrictIntoStrict) {
|
| CompilationInfo::kContextSpecializing |
|
| CompilationInfo::kTypingEnabled);
|
|
|
| - InstallAssertStackDepthHelper(CcTest::isolate());
|
| + InstallAssertInlineCountHelper(CcTest::isolate());
|
| T.CheckCall(T.Val(42), T.undefined(), T.undefined());
|
| }
|
|
|
|
|