e4c32b49db
Avoid the deprecated FLAG_* syntax, access flag values via the {v8_flags} struct instead. R=thibaudm@chromium.org Bug: v8:12887 Change-Id: Id2f457a1c0056d5015e2f9983d4599582d7189cd Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3876185 Reviewed-by: Thibaud Michaud <thibaudm@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/main@{#83219}
117 lines
3.5 KiB
C++
117 lines
3.5 KiB
C++
// 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.
|
|
|
|
#include "include/v8-function.h"
|
|
#include "src/execution/frames-inl.h"
|
|
#include "test/unittests/compiler/function-tester.h"
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace compiler {
|
|
|
|
static void IsOptimized(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
JavaScriptFrameIterator it(reinterpret_cast<Isolate*>(args.GetIsolate()));
|
|
JavaScriptFrame* frame = it.frame();
|
|
return args.GetReturnValue().Set(frame->is_turbofan());
|
|
}
|
|
|
|
class RunDeoptTest : public TestWithContext {
|
|
protected:
|
|
void InstallIsOptimizedHelper(v8::Isolate* isolate) {
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
v8::Local<v8::FunctionTemplate> t =
|
|
v8::FunctionTemplate::New(isolate, IsOptimized);
|
|
CHECK(context->Global()
|
|
->Set(context, NewString("IsOptimized"),
|
|
t->GetFunction(context).ToLocalChecked())
|
|
.FromJust());
|
|
}
|
|
};
|
|
|
|
TEST_F(RunDeoptTest, DeoptSimple) {
|
|
v8_flags.allow_natives_syntax = true;
|
|
|
|
FunctionTester T(i_isolate(),
|
|
"(function f(a) {"
|
|
" var b = 1;"
|
|
" if (!IsOptimized()) return 0;"
|
|
" %DeoptimizeFunction(f);"
|
|
" if (IsOptimized()) return 0;"
|
|
" return a + b;"
|
|
"})");
|
|
|
|
InstallIsOptimizedHelper(v8_isolate());
|
|
T.CheckCall(T.NewNumber(2), T.NewNumber(1));
|
|
}
|
|
|
|
TEST_F(RunDeoptTest, DeoptSimpleInExpr) {
|
|
v8_flags.allow_natives_syntax = true;
|
|
|
|
FunctionTester T(i_isolate(),
|
|
"(function f(a) {"
|
|
" var b = 1;"
|
|
" var c = 2;"
|
|
" if (!IsOptimized()) return 0;"
|
|
" var d = b + (%DeoptimizeFunction(f), c);"
|
|
" if (IsOptimized()) return 0;"
|
|
" return d + a;"
|
|
"})");
|
|
|
|
InstallIsOptimizedHelper(v8_isolate());
|
|
T.CheckCall(T.NewNumber(6), T.NewNumber(3));
|
|
}
|
|
|
|
TEST_F(RunDeoptTest, DeoptExceptionHandlerCatch) {
|
|
v8_flags.allow_natives_syntax = true;
|
|
|
|
FunctionTester T(i_isolate(),
|
|
"(function f() {"
|
|
" var is_opt = IsOptimized;"
|
|
" try {"
|
|
" DeoptAndThrow(f);"
|
|
" } catch (e) {"
|
|
" return is_opt();"
|
|
" }"
|
|
"})");
|
|
|
|
TryRunJS("function DeoptAndThrow(f) { %DeoptimizeFunction(f); throw 0; }");
|
|
InstallIsOptimizedHelper(v8_isolate());
|
|
T.CheckCall(T.false_value());
|
|
}
|
|
|
|
TEST_F(RunDeoptTest, DeoptExceptionHandlerFinally) {
|
|
v8_flags.allow_natives_syntax = true;
|
|
|
|
FunctionTester T(i_isolate(),
|
|
"(function f() {"
|
|
" var is_opt = IsOptimized;"
|
|
" try {"
|
|
" DeoptAndThrow(f);"
|
|
" } finally {"
|
|
" return is_opt();"
|
|
" }"
|
|
"})");
|
|
|
|
TryRunJS("function DeoptAndThrow(f) { %DeoptimizeFunction(f); throw 0; }");
|
|
InstallIsOptimizedHelper(v8_isolate());
|
|
T.CheckCall(T.false_value());
|
|
}
|
|
|
|
TEST_F(RunDeoptTest, DeoptTrivial) {
|
|
v8_flags.allow_natives_syntax = true;
|
|
|
|
FunctionTester T(i_isolate(),
|
|
"(function foo() {"
|
|
" %DeoptimizeFunction(foo);"
|
|
" return 1;"
|
|
"})");
|
|
|
|
T.CheckCall(T.NewNumber(1));
|
|
}
|
|
|
|
} // namespace compiler
|
|
} // namespace internal
|
|
} // namespace v8
|