2014-07-30 13:54:45 +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.
|
|
|
|
|
2014-07-30 15:35:29 +00:00
|
|
|
#include "src/v8.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-08-13 14:09:50 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2014-07-30 15:35:29 +00:00
|
|
|
#include "test/cctest/compiler/function-tester.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-08-13 14:09:50 +00:00
|
|
|
using namespace v8;
|
2014-07-30 13:54:45 +00:00
|
|
|
using namespace v8::internal;
|
|
|
|
using namespace v8::internal::compiler;
|
|
|
|
|
2014-08-13 14:47:32 +00:00
|
|
|
#if V8_TURBOFAN_TARGET
|
|
|
|
|
2014-08-13 14:09:50 +00:00
|
|
|
static void IsOptimized(const FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
JavaScriptFrameIterator it(CcTest::i_isolate());
|
|
|
|
JavaScriptFrame* frame = it.frame();
|
|
|
|
return args.GetReturnValue().Set(frame->is_optimized());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void InstallIsOptimizedHelper(v8::Isolate* isolate) {
|
|
|
|
Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
Local<v8::FunctionTemplate> t = FunctionTemplate::New(isolate, IsOptimized);
|
|
|
|
context->Global()->Set(v8_str("IsOptimized"), t->GetFunction());
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
TEST(TurboSimpleDeopt) {
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_turbo_deoptimization = true;
|
|
|
|
|
|
|
|
FunctionTester T(
|
|
|
|
"(function f(a) {"
|
|
|
|
"var b = 1;"
|
2014-08-13 14:09:50 +00:00
|
|
|
"if (!IsOptimized()) return 0;"
|
2014-07-30 13:54:45 +00:00
|
|
|
"%DeoptimizeFunction(f);"
|
2014-08-13 14:09:50 +00:00
|
|
|
"if (IsOptimized()) return 0;"
|
2014-07-30 13:54:45 +00:00
|
|
|
"return a + b; })");
|
|
|
|
|
2014-08-13 14:09:50 +00:00
|
|
|
InstallIsOptimizedHelper(CcTest::isolate());
|
2014-07-30 13:54:45 +00:00
|
|
|
T.CheckCall(T.Val(2), T.Val(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-06 11:49:02 +00:00
|
|
|
TEST(TurboSimpleDeoptInExpr) {
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_turbo_deoptimization = true;
|
|
|
|
|
|
|
|
FunctionTester T(
|
|
|
|
"(function f(a) {"
|
|
|
|
"var b = 1;"
|
|
|
|
"var c = 2;"
|
2014-08-13 14:09:50 +00:00
|
|
|
"if (!IsOptimized()) return 0;"
|
2014-08-06 11:49:02 +00:00
|
|
|
"var d = b + (%DeoptimizeFunction(f), c);"
|
2014-08-13 14:09:50 +00:00
|
|
|
"if (IsOptimized()) return 0;"
|
2014-08-06 11:49:02 +00:00
|
|
|
"return d + a; })");
|
|
|
|
|
2014-08-13 14:09:50 +00:00
|
|
|
InstallIsOptimizedHelper(CcTest::isolate());
|
2014-08-06 11:49:02 +00:00
|
|
|
T.CheckCall(T.Val(6), T.Val(3));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
TEST(TurboTrivialDeopt) {
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_turbo_deoptimization = true;
|
|
|
|
|
|
|
|
FunctionTester T(
|
|
|
|
"(function foo() {"
|
|
|
|
"%DeoptimizeFunction(foo);"
|
|
|
|
"return 1; })");
|
|
|
|
|
|
|
|
T.CheckCall(T.Val(1));
|
|
|
|
}
|