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.
|
|
|
|
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/frames-inl.h"
|
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
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
static void IsOptimized(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2014-08-13 14:09:50 +00:00
|
|
|
JavaScriptFrameIterator it(CcTest::i_isolate());
|
|
|
|
JavaScriptFrame* frame = it.frame();
|
|
|
|
return args.GetReturnValue().Set(frame->is_optimized());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void InstallIsOptimizedHelper(v8::Isolate* isolate) {
|
2015-06-01 22:46:54 +00:00
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
v8::Local<v8::FunctionTemplate> t =
|
|
|
|
v8::FunctionTemplate::New(isolate, IsOptimized);
|
2015-10-28 13:09:46 +00:00
|
|
|
CHECK(context->Global()
|
|
|
|
->Set(context, v8_str("IsOptimized"),
|
|
|
|
t->GetFunction(context).ToLocalChecked())
|
|
|
|
.FromJust());
|
2014-08-13 14:09:50 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-06-17 05:40:28 +00:00
|
|
|
TEST(DeoptSimple) {
|
2014-07-30 13:54:45 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
|
|
|
|
FunctionTester T(
|
|
|
|
"(function f(a) {"
|
2015-06-17 05:40:28 +00:00
|
|
|
" var b = 1;"
|
|
|
|
" if (!IsOptimized()) return 0;"
|
|
|
|
" %DeoptimizeFunction(f);"
|
|
|
|
" if (IsOptimized()) return 0;"
|
|
|
|
" return a + b;"
|
|
|
|
"})");
|
2014-07-30 13:54:45 +00:00
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-17 05:40:28 +00:00
|
|
|
TEST(DeoptSimpleInExpr) {
|
2014-08-06 11:49:02 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
|
|
|
|
FunctionTester T(
|
|
|
|
"(function f(a) {"
|
2015-06-17 05:40:28 +00:00
|
|
|
" var b = 1;"
|
|
|
|
" var c = 2;"
|
|
|
|
" if (!IsOptimized()) return 0;"
|
|
|
|
" var d = b + (%DeoptimizeFunction(f), c);"
|
|
|
|
" if (IsOptimized()) return 0;"
|
|
|
|
" return d + a;"
|
|
|
|
"})");
|
2014-08-06 11:49:02 +00:00
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2015-06-17 05:40:28 +00:00
|
|
|
|
|
|
|
TEST(DeoptExceptionHandlerCatch) {
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
|
|
|
|
FunctionTester T(
|
|
|
|
"(function f() {"
|
|
|
|
" var is_opt = IsOptimized;"
|
|
|
|
" try {"
|
|
|
|
" DeoptAndThrow(f);"
|
|
|
|
" } catch (e) {"
|
|
|
|
" return is_opt();"
|
|
|
|
" }"
|
|
|
|
"})");
|
|
|
|
|
|
|
|
CompileRun("function DeoptAndThrow(f) { %DeoptimizeFunction(f); throw 0; }");
|
|
|
|
InstallIsOptimizedHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.false_value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeoptExceptionHandlerFinally) {
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
|
|
|
|
FunctionTester T(
|
|
|
|
"(function f() {"
|
|
|
|
" var is_opt = IsOptimized;"
|
|
|
|
" try {"
|
|
|
|
" DeoptAndThrow(f);"
|
|
|
|
" } finally {"
|
|
|
|
" return is_opt();"
|
|
|
|
" }"
|
|
|
|
"})");
|
|
|
|
|
|
|
|
CompileRun("function DeoptAndThrow(f) { %DeoptimizeFunction(f); throw 0; }");
|
|
|
|
InstallIsOptimizedHelper(CcTest::isolate());
|
|
|
|
T.CheckCall(T.false_value());
|
|
|
|
}
|
|
|
|
|
2014-08-06 11:49:02 +00:00
|
|
|
|
2015-06-17 05:40:28 +00:00
|
|
|
TEST(DeoptTrivial) {
|
2014-07-30 13:54:45 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
|
|
|
|
FunctionTester T(
|
|
|
|
"(function foo() {"
|
2015-06-17 05:40:28 +00:00
|
|
|
" %DeoptimizeFunction(foo);"
|
|
|
|
" return 1;"
|
|
|
|
"})");
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
T.CheckCall(T.Val(1));
|
|
|
|
}
|
2015-10-30 09:16:26 +00:00
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|