2014-08-20 13:05:03 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
#include "src/compilation-info.h"
|
2015-08-12 10:28:34 +00:00
|
|
|
#include "src/frames-inl.h"
|
2014-08-20 13:05:03 +00:00
|
|
|
#include "test/cctest/compiler/function-tester.h"
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2015-03-09 08:05:24 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-06-09 11:28:08 +00:00
|
|
|
// Helper to determine inline count via JavaScriptFrame::GetFunctions.
|
2014-09-18 08:56:52 +00:00
|
|
|
// Note that a count of 1 indicates that no inlining has occured.
|
2015-03-09 08:05:24 +00:00
|
|
|
void AssertInlineCount(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2016-06-30 06:55:22 +00:00
|
|
|
JavaScriptFrameIterator it(CcTest::i_isolate());
|
2014-09-18 08:56:52 +00:00
|
|
|
int frames_seen = 0;
|
2016-06-30 06:55:22 +00:00
|
|
|
JavaScriptFrame* topmost = it.frame();
|
2014-09-18 08:56:52 +00:00
|
|
|
while (!it.done()) {
|
2016-06-30 06:55:22 +00:00
|
|
|
JavaScriptFrame* frame = it.frame();
|
2015-06-09 11:28:08 +00:00
|
|
|
List<JSFunction*> functions(2);
|
|
|
|
frame->GetFunctions(&functions);
|
2014-09-18 08:56:52 +00:00
|
|
|
PrintF("%d %s, inline count: %d\n", frames_seen,
|
|
|
|
frame->function()->shared()->DebugName()->ToCString().get(),
|
2015-06-09 11:28:08 +00:00
|
|
|
functions.length());
|
2014-09-18 08:56:52 +00:00
|
|
|
frames_seen++;
|
|
|
|
it.Advance();
|
|
|
|
}
|
2015-06-09 11:28:08 +00:00
|
|
|
List<JSFunction*> functions(2);
|
|
|
|
topmost->GetFunctions(&functions);
|
2015-10-28 13:09:46 +00:00
|
|
|
CHECK_EQ(args[0]
|
|
|
|
->ToInt32(args.GetIsolate()->GetCurrentContext())
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Value(),
|
|
|
|
functions.length());
|
2014-08-20 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-09 08:05:24 +00:00
|
|
|
void InstallAssertInlineCountHelper(v8::Isolate* isolate) {
|
2014-08-20 13:05:03 +00:00
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
v8::Local<v8::FunctionTemplate> t =
|
2014-09-18 08:56:52 +00:00
|
|
|
v8::FunctionTemplate::New(isolate, AssertInlineCount);
|
2015-10-28 13:09:46 +00:00
|
|
|
CHECK(context->Global()
|
|
|
|
->Set(context, v8_str("AssertInlineCount"),
|
|
|
|
t->GetFunction(context).ToLocalChecked())
|
|
|
|
.FromJust());
|
2014-08-20 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 12:48:02 +00:00
|
|
|
const uint32_t kRestrictedInliningFlags =
|
2016-08-01 12:59:12 +00:00
|
|
|
CompilationInfo::kNativeContextSpecializing;
|
2015-03-09 08:05:24 +00:00
|
|
|
|
|
|
|
const uint32_t kInlineFlags = CompilationInfo::kInliningEnabled |
|
2016-08-01 12:59:12 +00:00
|
|
|
CompilationInfo::kNativeContextSpecializing;
|
2015-03-09 08:05:24 +00:00
|
|
|
|
|
|
|
} // namespace
|
2014-11-12 09:46:51 +00:00
|
|
|
|
|
|
|
|
2014-08-20 13:05:03 +00:00
|
|
|
TEST(SimpleInlining) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s) { AssertInlineCount(2); return s; };"
|
|
|
|
"function bar(s, t) { return foo(s); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.Val(1), T.Val(1), T.Val(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(SimpleInliningDeopt) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s) { %DeoptimizeFunction(bar); return s; };"
|
|
|
|
"function bar(s, t) { return foo(s); };"
|
|
|
|
"bar;",
|
2015-05-27 11:01:51 +00:00
|
|
|
kInlineFlags);
|
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.Val(1), T.Val(1), T.Val(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(SimpleInliningDeoptSelf) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s) { %_DeoptimizeNow(); return s; };"
|
|
|
|
"function bar(s, t) { return foo(s); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-09-18 08:56:52 +00:00
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-20 13:05:03 +00:00
|
|
|
T.CheckCall(T.Val(1), T.Val(1), T.Val(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(SimpleInliningContext) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s) { AssertInlineCount(2); var x = 12; return s + x; };"
|
|
|
|
"function bar(s, t) { return foo(s); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.Val(13), T.Val(1), T.Val(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(SimpleInliningContextDeopt) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s) {"
|
|
|
|
" AssertInlineCount(2); %DeoptimizeFunction(bar); var x = 12;"
|
|
|
|
" return s + x;"
|
|
|
|
"};"
|
|
|
|
"function bar(s, t) { return foo(s); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-09-18 08:56:52 +00:00
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-20 13:05:03 +00:00
|
|
|
T.CheckCall(T.Val(13), T.Val(1), T.Val(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(CaptureContext) {
|
|
|
|
FunctionTester T(
|
|
|
|
"var f = (function () {"
|
2014-11-12 09:46:51 +00:00
|
|
|
" var x = 42;"
|
|
|
|
" function bar(s) { return x + s; };"
|
|
|
|
" return (function (s) { return bar(s); });"
|
2014-08-20 13:05:03 +00:00
|
|
|
"})();"
|
2014-11-12 09:46:51 +00:00
|
|
|
"(function (s) { return f(s) })",
|
|
|
|
kInlineFlags);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-20 13:05:03 +00:00
|
|
|
T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(sigurds) For now we do not inline any native functions. If we do at
|
|
|
|
// some point, change this test.
|
|
|
|
TEST(DontInlineEval) {
|
|
|
|
FunctionTester T(
|
|
|
|
"var x = 42;"
|
2016-08-01 12:59:12 +00:00
|
|
|
"function bar(s, t) { return eval(\"AssertInlineCount(1); x\") };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-20 13:05:03 +00:00
|
|
|
T.CheckCall(T.Val(42), T.Val("x"), T.undefined());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InlineOmitArguments) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"var x = 42;"
|
|
|
|
"function bar(s, t, u, v) { AssertInlineCount(2); return x + s; };"
|
|
|
|
"function foo(s, t) { return bar(s); };"
|
|
|
|
"foo;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-20 13:05:03 +00:00
|
|
|
T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-16 13:04:25 +00:00
|
|
|
TEST(InlineOmitArgumentsObject) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function bar(s, t, u, v) { AssertInlineCount(2); return arguments; };"
|
|
|
|
"function foo(s, t) { var args = bar(s);"
|
|
|
|
" return args.length == 1 &&"
|
|
|
|
" args[0] == 11; };"
|
|
|
|
"foo;",
|
2015-09-16 13:04:25 +00:00
|
|
|
kInlineFlags);
|
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.true_value(), T.Val(11), T.undefined());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
TEST(InlineOmitArgumentsDeopt) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"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; }"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-09-18 08:56:52 +00:00
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.true_value(), T.Val(12), T.Val(14));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-20 13:05:03 +00:00
|
|
|
TEST(InlineSurplusArguments) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"var x = 42;"
|
|
|
|
"function foo(s) { AssertInlineCount(2); return x + s; };"
|
|
|
|
"function bar(s, t) { return foo(s, t, 13); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-20 13:05:03 +00:00
|
|
|
T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-16 13:04:25 +00:00
|
|
|
TEST(InlineSurplusArgumentsObject) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s) { AssertInlineCount(2); return arguments; };"
|
|
|
|
"function bar(s, t) { var args = foo(s, t, 13);"
|
|
|
|
" return args.length == 3 &&"
|
|
|
|
" args[0] == 11 &&"
|
|
|
|
" args[1] == 12 &&"
|
|
|
|
" args[2] == 13; };"
|
|
|
|
"bar;",
|
2015-09-16 13:04:25 +00:00
|
|
|
kInlineFlags);
|
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.true_value(), T.Val(11), T.Val(12));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
TEST(InlineSurplusArgumentsDeopt) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"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; }"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-09-18 08:56:52 +00:00
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.true_value(), T.Val(12), T.Val(14));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-20 13:05:03 +00:00
|
|
|
TEST(InlineTwice) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"var x = 42;"
|
|
|
|
"function bar(s) { AssertInlineCount(2); return x + s; };"
|
|
|
|
"function foo(s, t) { return bar(s) + bar(t); };"
|
|
|
|
"foo;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-20 13:05:03 +00:00
|
|
|
T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InlineTwiceDependent) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"var x = 42;"
|
|
|
|
"function foo(s) { AssertInlineCount(2); return x + s; };"
|
|
|
|
"function bar(s,t) { return foo(foo(s)); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-20 13:05:03 +00:00
|
|
|
T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InlineTwiceDependentDiamond) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"var x = 41;"
|
|
|
|
"function foo(s) { AssertInlineCount(2); if (s % 2 == 0) {"
|
|
|
|
" return x - s } else { return x + s; } };"
|
|
|
|
"function bar(s,t) { return foo(foo(s)); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-28 12:18:25 +00:00
|
|
|
T.CheckCall(T.Val(-11), T.Val(11), T.Val(4));
|
2014-08-20 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-28 12:18:25 +00:00
|
|
|
TEST(InlineTwiceDependentDiamondDifferent) {
|
2014-08-20 13:05:03 +00:00
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"var x = 41;"
|
|
|
|
"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); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-28 12:18:25 +00:00
|
|
|
T.CheckCall(T.Val(-329), T.Val(11), T.Val(4));
|
2014-08-20 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 08:58:51 +00:00
|
|
|
|
2014-11-12 09:46:51 +00:00
|
|
|
TEST(InlineLoopGuardedEmpty) {
|
2014-08-29 08:58:51 +00:00
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s) { AssertInlineCount(2); if (s) while (s); return s; };"
|
|
|
|
"function bar(s,t) { return foo(s); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InlineLoopGuardedOnce) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s,t) { AssertInlineCount(2); if (t > 0) while (s > 0) {"
|
|
|
|
" s = s - 1; }; return s; };"
|
|
|
|
"function bar(s,t) { return foo(s,t); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.Val(0.0), T.Val(11), T.Val(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InlineLoopGuardedTwice) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s,t) { AssertInlineCount(2); if (t > 0) while (s > 0) {"
|
|
|
|
" s = s - 1; }; return s; };"
|
|
|
|
"function bar(s,t) { return foo(foo(s,t),t); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-29 08:58:51 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-29 08:58:51 +00:00
|
|
|
T.CheckCall(T.Val(0.0), T.Val(11), T.Val(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-03 13:09:49 +00:00
|
|
|
TEST(InlineLoopUnguardedEmpty) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s) { AssertInlineCount(2); while (s); return s; };"
|
|
|
|
"function bar(s, t) { return foo(s); };"
|
|
|
|
"bar;",
|
2015-03-03 13:09:49 +00:00
|
|
|
kInlineFlags);
|
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InlineLoopUnguardedOnce) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s) { AssertInlineCount(2); while (s) {"
|
|
|
|
" s = s - 1; }; return s; };"
|
|
|
|
"function bar(s, t) { return foo(s); };"
|
|
|
|
"bar;",
|
2015-03-03 13:09:49 +00:00
|
|
|
kInlineFlags);
|
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InlineLoopUnguardedTwice) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s) { AssertInlineCount(2); while (s > 0) {"
|
|
|
|
" s = s - 1; }; return s; };"
|
|
|
|
"function bar(s,t) { return foo(foo(s,t),t); };"
|
|
|
|
"bar;",
|
2015-03-03 13:09:49 +00:00
|
|
|
kInlineFlags);
|
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-29 08:58:51 +00:00
|
|
|
TEST(InlineStrictIntoNonStrict) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"var x = Object.create({}, { y: { value:42, writable:false } });"
|
|
|
|
"function foo(s) { 'use strict';"
|
|
|
|
" x.y = 9; };"
|
|
|
|
"function bar(s,t) { return foo(s); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-29 08:58:51 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-29 08:58:51 +00:00
|
|
|
T.CheckThrows(T.undefined(), T.undefined());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InlineNonStrictIntoStrict) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"var x = Object.create({}, { y: { value:42, writable:false } });"
|
|
|
|
"function foo(s) { x.y = 9; return x.y; };"
|
|
|
|
"function bar(s,t) { \'use strict\'; return foo(s); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-08-29 08:58:51 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
2014-08-29 08:58:51 +00:00
|
|
|
T.CheckCall(T.Val(42), T.undefined(), T.undefined());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-20 07:56:50 +00:00
|
|
|
TEST(InlineWithArguments) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s,t,u) { AssertInlineCount(2);"
|
|
|
|
" return foo.arguments.length == 3 &&"
|
|
|
|
" foo.arguments[0] == 13 &&"
|
|
|
|
" foo.arguments[1] == 14 &&"
|
|
|
|
" foo.arguments[2] == 15;"
|
|
|
|
"}"
|
|
|
|
"function bar() { return foo(13, 14, 15); };"
|
|
|
|
"bar;",
|
2014-11-12 09:46:51 +00:00
|
|
|
kInlineFlags);
|
2014-10-20 07:56:50 +00:00
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.true_value(), T.Val(12), T.Val(14));
|
|
|
|
}
|
|
|
|
|
2015-03-09 08:05:24 +00:00
|
|
|
|
|
|
|
TEST(InlineBuiltin) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s,t,u) { AssertInlineCount(2); return true; }"
|
|
|
|
"function bar() { return foo(); };"
|
|
|
|
"%SetForceInlineFlag(foo);"
|
|
|
|
"bar;",
|
2015-05-20 12:48:02 +00:00
|
|
|
kRestrictedInliningFlags);
|
2015-03-09 08:05:24 +00:00
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.true_value());
|
|
|
|
}
|
|
|
|
|
2015-03-10 08:37:16 +00:00
|
|
|
|
|
|
|
TEST(InlineNestedBuiltin) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(s,t,u) { AssertInlineCount(3); return true; }"
|
|
|
|
"function baz(s,t,u) { return foo(s,t,u); }"
|
|
|
|
"function bar() { return baz(); };"
|
|
|
|
"%SetForceInlineFlag(foo);"
|
|
|
|
"%SetForceInlineFlag(baz);"
|
|
|
|
"bar;",
|
2015-05-20 12:48:02 +00:00
|
|
|
kRestrictedInliningFlags);
|
2015-03-10 08:37:16 +00:00
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.true_value());
|
|
|
|
}
|
|
|
|
|
2015-05-11 17:20:43 +00:00
|
|
|
|
2015-06-30 11:05:03 +00:00
|
|
|
TEST(InlineSelfRecursive) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function foo(x) { "
|
|
|
|
" AssertInlineCount(1);"
|
|
|
|
" if (x == 1) return foo(12);"
|
|
|
|
" return x;"
|
|
|
|
"}"
|
|
|
|
"foo;",
|
2015-06-30 11:05:03 +00:00
|
|
|
kInlineFlags);
|
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.Val(12), T.Val(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InlineMutuallyRecursive) {
|
|
|
|
FunctionTester T(
|
2016-08-01 12:59:12 +00:00
|
|
|
"function bar(x) { AssertInlineCount(2); return foo(x); }"
|
|
|
|
"function foo(x) { "
|
|
|
|
" if (x == 1) return bar(42);"
|
|
|
|
" return x;"
|
|
|
|
"}"
|
|
|
|
"foo;",
|
2015-06-30 11:05:03 +00:00
|
|
|
kInlineFlags);
|
|
|
|
|
|
|
|
InstallAssertInlineCountHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.Val(42), T.Val(1));
|
|
|
|
}
|
2015-10-30 09:16:26 +00:00
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|