Remove usage of deprecated APIs from compiler/deopt test

BUG=4134
R=epertoso@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/1458003006

Cr-Commit-Position: refs/heads/master@{#32146}
This commit is contained in:
jochen 2015-11-20 04:56:19 -08:00 committed by Commit bot
parent aeb41de0e6
commit 9951a617d5
2 changed files with 344 additions and 146 deletions

View File

@ -25,6 +25,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// TODO(jochen): Remove this after the setting is turned on globally.
#define V8_IMMINENT_DEPRECATION_WARNINGS
#include <stdlib.h>
#include <wchar.h>
@ -262,8 +265,7 @@ TEST(Regression236) {
TEST(GetScriptLineNumber) {
LocalContext context;
v8::HandleScope scope(CcTest::isolate());
v8::ScriptOrigin origin =
v8::ScriptOrigin(v8::String::NewFromUtf8(CcTest::isolate(), "test"));
v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test"));
const char function_f[] = "function f() {}";
const int max_rows = 1000;
const int buffer_size = max_rows + sizeof(function_f);
@ -275,12 +277,13 @@ TEST(GetScriptLineNumber) {
if (i > 0)
buffer[i - 1] = '\n';
MemCopy(&buffer[i], function_f, sizeof(function_f) - 1);
v8::Handle<v8::String> script_body =
v8::String::NewFromUtf8(CcTest::isolate(), buffer.start());
v8::Script::Compile(script_body, &origin)->Run();
v8::Local<v8::Function> f =
v8::Local<v8::Function>::Cast(context->Global()->Get(
v8::String::NewFromUtf8(CcTest::isolate(), "f")));
v8::Local<v8::String> script_body = v8_str(buffer.start());
v8::Script::Compile(context.local(), script_body, &origin)
.ToLocalChecked()
->Run(context.local())
.ToLocalChecked();
v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
context->Global()->Get(context.local(), v8_str("f")).ToLocalChecked());
CHECK_EQ(i, f->GetScriptLineNumber());
}
}
@ -292,14 +295,16 @@ TEST(FeedbackVectorPreservedAcrossRecompiles) {
CcTest::InitializeVM();
if (!CcTest::i_isolate()->use_crankshaft()) return;
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
// Make sure function f has a call that uses a type feedback slot.
CompileRun("function fun() {};"
"fun1 = fun;"
"function f(a) { a(); } f(fun1);");
Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
*v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))));
Handle<JSFunction> f = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
CcTest::global()->Get(context, v8_str("f")).ToLocalChecked())));
// We shouldn't have deoptimization support. We want to recompile and
// verify that our feedback vector preserves information.
@ -329,6 +334,7 @@ TEST(FeedbackVectorUnaffectedByScopeChanges) {
if (i::FLAG_always_opt || !i::FLAG_lazy) return;
CcTest::InitializeVM();
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
CompileRun("function builder() {"
" call_target = function() { return 3; };"
@ -342,9 +348,10 @@ TEST(FeedbackVectorUnaffectedByScopeChanges) {
"}"
"morphing_call = builder();");
Handle<JSFunction> f = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Handle<v8::Function>::Cast(
CcTest::global()->Get(v8_str("morphing_call")))));
Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(CcTest::global()
->Get(context, v8_str("morphing_call"))
.ToLocalChecked())));
// Not compiled, and so no feedback vector allocated yet.
CHECK(!f->shared()->is_compiled());
@ -367,8 +374,9 @@ TEST(OptimizedCodeSharing1) {
v8::HandleScope scope(CcTest::isolate());
for (int i = 0; i < 3; i++) {
LocalContext env;
env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"),
v8::Integer::New(CcTest::isolate(), i));
env->Global()
->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), i))
.FromJust();
CompileRun(
"function MakeClosure() {"
" return function() { return x; };"
@ -381,10 +389,14 @@ TEST(OptimizedCodeSharing1) {
"var closure2 = MakeClosure();");
Handle<JSFunction> fun1 = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
env->Global()->Get(v8_str("closure1")))));
env->Global()
->Get(env.local(), v8_str("closure1"))
.ToLocalChecked())));
Handle<JSFunction> fun2 = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
env->Global()->Get(v8_str("closure2")))));
env->Global()
->Get(env.local(), v8_str("closure2"))
.ToLocalChecked())));
CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
CHECK_EQ(fun1->code(), fun2->code());
@ -410,9 +422,13 @@ TEST(OptimizedCodeSharing2) {
Handle<Code> reference_code;
{
LocalContext env;
env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"),
v8::Integer::New(CcTest::isolate(), 23));
script->GetUnboundScript()->BindToCurrentContext()->Run();
env->Global()
->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), 23))
.FromJust();
script->GetUnboundScript()
->BindToCurrentContext()
->Run(env.local())
.ToLocalChecked();
CompileRun(
"var closure0 = MakeClosure();"
"%DebugPrint(closure0());"
@ -420,15 +436,21 @@ TEST(OptimizedCodeSharing2) {
"%DebugPrint(closure0());");
Handle<JSFunction> fun0 = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
env->Global()->Get(v8_str("closure0")))));
env->Global()
->Get(env.local(), v8_str("closure0"))
.ToLocalChecked())));
CHECK(fun0->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
reference_code = handle(fun0->code());
}
for (int i = 0; i < 3; i++) {
LocalContext env;
env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"),
v8::Integer::New(CcTest::isolate(), i));
script->GetUnboundScript()->BindToCurrentContext()->Run();
env->Global()
->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), i))
.FromJust();
script->GetUnboundScript()
->BindToCurrentContext()
->Run(env.local())
.ToLocalChecked();
CompileRun(
"var closure0 = MakeClosure();"
"%DebugPrint(closure0());"
@ -438,10 +460,14 @@ TEST(OptimizedCodeSharing2) {
"var closure2 = MakeClosure();");
Handle<JSFunction> fun1 = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
env->Global()->Get(v8_str("closure1")))));
env->Global()
->Get(env.local(), v8_str("closure1"))
.ToLocalChecked())));
Handle<JSFunction> fun2 = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
env->Global()->Get(v8_str("closure2")))));
env->Global()
->Get(env.local(), v8_str("closure2"))
.ToLocalChecked())));
CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
CHECK_EQ(*reference_code, fun1->code());
@ -468,9 +494,13 @@ TEST(OptimizedCodeSharing3) {
Handle<Code> reference_code;
{
LocalContext env;
env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"),
v8::Integer::New(CcTest::isolate(), 23));
script->GetUnboundScript()->BindToCurrentContext()->Run();
env->Global()
->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), 23))
.FromJust();
script->GetUnboundScript()
->BindToCurrentContext()
->Run(env.local())
.ToLocalChecked();
CompileRun(
"var closure0 = MakeClosure();"
"%DebugPrint(closure0());"
@ -478,7 +508,9 @@ TEST(OptimizedCodeSharing3) {
"%DebugPrint(closure0());");
Handle<JSFunction> fun0 = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
env->Global()->Get(v8_str("closure0")))));
env->Global()
->Get(env.local(), v8_str("closure0"))
.ToLocalChecked())));
CHECK(fun0->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
reference_code = handle(fun0->code());
// Evict only the context-dependent entry from the optimized code map. This
@ -487,9 +519,13 @@ TEST(OptimizedCodeSharing3) {
}
for (int i = 0; i < 3; i++) {
LocalContext env;
env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"),
v8::Integer::New(CcTest::isolate(), i));
script->GetUnboundScript()->BindToCurrentContext()->Run();
env->Global()
->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), i))
.FromJust();
script->GetUnboundScript()
->BindToCurrentContext()
->Run(env.local())
.ToLocalChecked();
CompileRun(
"var closure0 = MakeClosure();"
"%DebugPrint(closure0());"
@ -499,10 +535,14 @@ TEST(OptimizedCodeSharing3) {
"var closure2 = MakeClosure();");
Handle<JSFunction> fun1 = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
env->Global()->Get(v8_str("closure1")))));
env->Global()
->Get(env.local(), v8_str("closure1"))
.ToLocalChecked())));
Handle<JSFunction> fun2 = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
env->Global()->Get(v8_str("closure2")))));
env->Global()
->Get(env.local(), v8_str("closure2"))
.ToLocalChecked())));
CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
CHECK_EQ(*reference_code, fun1->code());
@ -516,28 +556,33 @@ TEST(CompileFunctionInContext) {
v8::HandleScope scope(CcTest::isolate());
LocalContext env;
CompileRun("var r = 10;");
v8::Local<v8::Object> math =
v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("Math")));
v8::Local<v8::Object> math = v8::Local<v8::Object>::Cast(
env->Global()->Get(env.local(), v8_str("Math")).ToLocalChecked());
v8::ScriptCompiler::Source script_source(v8_str(
"a = PI * r * r;"
"x = r * cos(PI);"
"y = r * sin(PI / 2);"));
v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
CcTest::isolate(), &script_source, env.local(), 0, NULL, 1, &math);
v8::Local<v8::Function> fun =
v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source,
0, NULL, 1, &math)
.ToLocalChecked();
CHECK(!fun.IsEmpty());
fun->Call(env->Global(), 0, NULL);
CHECK(env->Global()->Has(v8_str("a")));
v8::Local<v8::Value> a = env->Global()->Get(v8_str("a"));
fun->Call(env.local(), env->Global(), 0, NULL).ToLocalChecked();
CHECK(env->Global()->Has(env.local(), v8_str("a")).FromJust());
v8::Local<v8::Value> a =
env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked();
CHECK(a->IsNumber());
CHECK(env->Global()->Has(v8_str("x")));
v8::Local<v8::Value> x = env->Global()->Get(v8_str("x"));
CHECK(env->Global()->Has(env.local(), v8_str("x")).FromJust());
v8::Local<v8::Value> x =
env->Global()->Get(env.local(), v8_str("x")).ToLocalChecked();
CHECK(x->IsNumber());
CHECK(env->Global()->Has(v8_str("y")));
v8::Local<v8::Value> y = env->Global()->Get(v8_str("y"));
CHECK(env->Global()->Has(env.local(), v8_str("y")).FromJust());
v8::Local<v8::Value> y =
env->Global()->Get(env.local(), v8_str("y")).ToLocalChecked();
CHECK(y->IsNumber());
CHECK_EQ(314.1592653589793, a->NumberValue());
CHECK_EQ(-10.0, x->NumberValue());
CHECK_EQ(10.0, y->NumberValue());
CHECK_EQ(314.1592653589793, a->NumberValue(env.local()).FromJust());
CHECK_EQ(-10.0, x->NumberValue(env.local()).FromJust());
CHECK_EQ(10.0, y->NumberValue(env.local()).FromJust());
}
@ -552,17 +597,22 @@ TEST(CompileFunctionInContextComplex) {
"var a = {x: 8, y: 16};"
"var b = {x: 32};");
v8::Local<v8::Object> ext[2];
ext[0] = v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a")));
ext[1] = v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("b")));
ext[0] = v8::Local<v8::Object>::Cast(
env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked());
ext[1] = v8::Local<v8::Object>::Cast(
env->Global()->Get(env.local(), v8_str("b")).ToLocalChecked());
v8::ScriptCompiler::Source script_source(v8_str("result = x + y + z"));
v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
CcTest::isolate(), &script_source, env.local(), 0, NULL, 2, ext);
v8::Local<v8::Function> fun =
v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source,
0, NULL, 2, ext)
.ToLocalChecked();
CHECK(!fun.IsEmpty());
fun->Call(env->Global(), 0, NULL);
CHECK(env->Global()->Has(v8_str("result")));
v8::Local<v8::Value> result = env->Global()->Get(v8_str("result"));
fun->Call(env.local(), env->Global(), 0, NULL).ToLocalChecked();
CHECK(env->Global()->Has(env.local(), v8_str("result")).FromJust());
v8::Local<v8::Value> result =
env->Global()->Get(env.local(), v8_str("result")).ToLocalChecked();
CHECK(result->IsNumber());
CHECK_EQ(52.0, result->NumberValue());
CHECK_EQ(52.0, result->NumberValue(env.local()).FromJust());
}
@ -572,18 +622,22 @@ TEST(CompileFunctionInContextArgs) {
LocalContext env;
CompileRun("var a = {x: 23};");
v8::Local<v8::Object> ext[1];
ext[0] = v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a")));
ext[0] = v8::Local<v8::Object>::Cast(
env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked());
v8::ScriptCompiler::Source script_source(v8_str("result = x + b"));
v8::Local<v8::String> arg = v8_str("b");
v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
CcTest::isolate(), &script_source, env.local(), 1, &arg, 1, ext);
v8::Local<v8::Function> fun =
v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source,
1, &arg, 1, ext)
.ToLocalChecked();
CHECK(!fun.IsEmpty());
v8::Local<v8::Value> b_value = v8::Number::New(CcTest::isolate(), 42.0);
fun->Call(env->Global(), 1, &b_value);
CHECK(env->Global()->Has(v8_str("result")));
v8::Local<v8::Value> result = env->Global()->Get(v8_str("result"));
fun->Call(env.local(), env->Global(), 1, &b_value).ToLocalChecked();
CHECK(env->Global()->Has(env.local(), v8_str("result")).FromJust());
v8::Local<v8::Value> result =
env->Global()->Get(env.local(), v8_str("result")).ToLocalChecked();
CHECK(result->IsNumber());
CHECK_EQ(65.0, result->NumberValue());
CHECK_EQ(65.0, result->NumberValue(env.local()).FromJust());
}
@ -593,19 +647,23 @@ TEST(CompileFunctionInContextComments) {
LocalContext env;
CompileRun("var a = {x: 23, y: 1, z: 2};");
v8::Local<v8::Object> ext[1];
ext[0] = v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a")));
ext[0] = v8::Local<v8::Object>::Cast(
env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked());
v8::ScriptCompiler::Source script_source(
v8_str("result = /* y + */ x + b // + z"));
v8::Local<v8::String> arg = v8_str("b");
v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
CcTest::isolate(), &script_source, env.local(), 1, &arg, 1, ext);
v8::Local<v8::Function> fun =
v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source,
1, &arg, 1, ext)
.ToLocalChecked();
CHECK(!fun.IsEmpty());
v8::Local<v8::Value> b_value = v8::Number::New(CcTest::isolate(), 42.0);
fun->Call(env->Global(), 1, &b_value);
CHECK(env->Global()->Has(v8_str("result")));
v8::Local<v8::Value> result = env->Global()->Get(v8_str("result"));
fun->Call(env.local(), env->Global(), 1, &b_value).ToLocalChecked();
CHECK(env->Global()->Has(env.local(), v8_str("result")).FromJust());
v8::Local<v8::Value> result =
env->Global()->Get(env.local(), v8_str("result")).ToLocalChecked();
CHECK(result->IsNumber());
CHECK_EQ(65.0, result->NumberValue());
CHECK_EQ(65.0, result->NumberValue(env.local()).FromJust());
}
@ -615,9 +673,9 @@ TEST(CompileFunctionInContextNonIdentifierArgs) {
LocalContext env;
v8::ScriptCompiler::Source script_source(v8_str("result = 1"));
v8::Local<v8::String> arg = v8_str("b }");
v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
CcTest::isolate(), &script_source, env.local(), 1, &arg, 0, NULL);
CHECK(fun.IsEmpty());
CHECK(v8::ScriptCompiler::CompileFunctionInContext(
env.local(), &script_source, 1, &arg, 0, NULL)
.IsEmpty());
}
@ -629,12 +687,14 @@ TEST(CompileFunctionInContextScriptOrigin) {
v8::Integer::New(CcTest::isolate(), 22),
v8::Integer::New(CcTest::isolate(), 41));
v8::ScriptCompiler::Source script_source(v8_str("throw new Error()"), origin);
v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
CcTest::isolate(), &script_source, env.local(), 0, NULL, 0, NULL);
v8::Local<v8::Function> fun =
v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source,
0, NULL, 0, NULL)
.ToLocalChecked();
CHECK(!fun.IsEmpty());
v8::TryCatch try_catch;
v8::TryCatch try_catch(CcTest::isolate());
CcTest::isolate()->SetCaptureStackTraceForUncaughtExceptions(true);
fun->Call(env->Global(), 0, NULL);
CHECK(fun->Call(env.local(), env->Global(), 0, NULL).IsEmpty());
CHECK(try_catch.HasCaught());
CHECK(!try_catch.Exception().IsEmpty());
v8::Local<v8::StackTrace> stack =
@ -648,10 +708,11 @@ TEST(CompileFunctionInContextScriptOrigin) {
#ifdef ENABLE_DISASSEMBLER
static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj,
static Handle<JSFunction> GetJSFunction(v8::Local<v8::Object> obj,
const char* property_name) {
v8::Local<v8::Function> fun =
v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name)));
v8::Local<v8::Function> fun = v8::Local<v8::Function>::Cast(
obj->Get(CcTest::isolate()->GetCurrentContext(), v8_str(property_name))
.ToLocalChecked());
return Handle<JSFunction>::cast(v8::Utils::OpenHandle(*fun));
}

View File

@ -25,6 +25,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// TODO(jochen): Remove this after the setting is turned on globally.
#define V8_IMMINENT_DEPRECATION_WARNINGS
#include <stdlib.h>
#include "src/v8.h"
@ -113,10 +116,10 @@ static void NonIncrementalGC(i::Isolate* isolate) {
}
static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj,
static Handle<JSFunction> GetJSFunction(v8::Local<v8::Context> context,
const char* property_name) {
v8::Local<v8::Function> fun =
v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name)));
v8::Local<v8::Function> fun = v8::Local<v8::Function>::Cast(
context->Global()->Get(context, v8_str(property_name)).ToLocalChecked());
return i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*fun));
}
@ -137,8 +140,12 @@ TEST(DeoptimizeSimple) {
}
NonIncrementalGC(CcTest::i_isolate());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
// Test lazy deoptimization of a simple function. Call the function after the
@ -153,8 +160,12 @@ TEST(DeoptimizeSimple) {
}
NonIncrementalGC(CcTest::i_isolate());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
}
@ -175,8 +186,12 @@ TEST(DeoptimizeSimpleWithArguments) {
}
NonIncrementalGC(CcTest::i_isolate());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
// Test lazy deoptimization of a simple function with some arguments. Call the
@ -192,8 +207,12 @@ TEST(DeoptimizeSimpleWithArguments) {
}
NonIncrementalGC(CcTest::i_isolate());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
}
@ -215,9 +234,17 @@ TEST(DeoptimizeSimpleNested) {
"result = f(1, 2, 3);");
NonIncrementalGC(CcTest::i_isolate());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(6, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(6, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
}
}
@ -240,12 +267,22 @@ TEST(DeoptimizeRecursive) {
}
NonIncrementalGC(CcTest::i_isolate());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(11, env->Global()->Get(v8_str("calls"))->Int32Value());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(11, env->Global()
->Get(env.local(), v8_str("calls"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
v8::Local<v8::Function> fun = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(CcTest::isolate(), "f")));
env->Global()
->Get(env.local(), v8_str(CcTest::isolate(), "f"))
.ToLocalChecked());
CHECK(!fun.IsEmpty());
}
@ -272,8 +309,16 @@ TEST(DeoptimizeMultiple) {
}
NonIncrementalGC(CcTest::i_isolate());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(14, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(14, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
}
@ -293,8 +338,15 @@ TEST(DeoptimizeConstructor) {
}
NonIncrementalGC(CcTest::i_isolate());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK(env->Global()->Get(v8_str("result"))->IsTrue());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK(env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->IsTrue());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
{
@ -310,8 +362,16 @@ TEST(DeoptimizeConstructor) {
}
NonIncrementalGC(CcTest::i_isolate());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(3, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(3, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
}
@ -339,8 +399,16 @@ TEST(DeoptimizeConstructorMultiple) {
}
NonIncrementalGC(CcTest::i_isolate());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(14, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(14, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
}
@ -382,7 +450,7 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationADDString) {
CompileRun(f_source);
CompileRun("f('a+', new X());");
CHECK(!i_isolate->use_crankshaft() ||
GetJSFunction(env->Global(), "f")->IsOptimized());
GetJSFunction(env.local(), "f")->IsOptimized());
// Call f and force deoptimization while processing the binary operation.
CompileRun(
@ -391,9 +459,14 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationADDString) {
}
NonIncrementalGC(i_isolate);
CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
v8::Handle<v8::Value> result = env->Global()->Get(v8_str("result"));
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
v8::Local<v8::Value> result =
env->Global()->Get(env.local(), v8_str("result")).ToLocalChecked();
CHECK(result->IsString());
v8::String::Utf8Value utf8(result);
CHECK_EQ(0, strcmp("a+an X", *utf8));
@ -439,13 +512,13 @@ static void TestDeoptimizeBinaryOpHelper(LocalContext* env,
CompileRun(f_source);
CompileRun("f(7, new X());");
CHECK(!i_isolate->use_crankshaft() ||
GetJSFunction((*env)->Global(), "f")->IsOptimized());
GetJSFunction((*env).local(), "f")->IsOptimized());
// Call f and force deoptimization while processing the binary operation.
CompileRun("deopt = true;"
"var result = f(7, new X());");
NonIncrementalGC(i_isolate);
CHECK(!GetJSFunction((*env)->Global(), "f")->IsOptimized());
CHECK(!GetJSFunction((*env).local(), "f")->IsOptimized());
}
@ -462,8 +535,16 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationADD) {
TestDeoptimizeBinaryOpHelper(&env, "+");
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(15, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(15, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
}
isolate->Exit();
@ -484,8 +565,16 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationSUB) {
TestDeoptimizeBinaryOpHelper(&env, "-");
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(-1, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(-1, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
}
isolate->Exit();
@ -506,8 +595,16 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationMUL) {
TestDeoptimizeBinaryOpHelper(&env, "*");
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(56, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(56, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
}
isolate->Exit();
@ -528,8 +625,16 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationDIV) {
TestDeoptimizeBinaryOpHelper(&env, "/");
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(0, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(0, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
}
isolate->Exit();
@ -550,8 +655,16 @@ UNINITIALIZED_TEST(DeoptimizeBinaryOperationMOD) {
TestDeoptimizeBinaryOpHelper(&env, "%");
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(7, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(7, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
}
isolate->Exit();
@ -596,7 +709,7 @@ UNINITIALIZED_TEST(DeoptimizeCompare) {
CompileRun(f_source);
CompileRun("f('a', new X());");
CHECK(!i_isolate->use_crankshaft() ||
GetJSFunction(env->Global(), "f")->IsOptimized());
GetJSFunction(env.local(), "f")->IsOptimized());
// Call f and force deoptimization while processing the comparison.
CompileRun(
@ -605,9 +718,17 @@ UNINITIALIZED_TEST(DeoptimizeCompare) {
}
NonIncrementalGC(i_isolate);
CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(true, env->Global()->Get(v8_str("result"))->BooleanValue());
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(true, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->BooleanValue(env.local())
.FromJust());
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
}
isolate->Exit();
@ -679,10 +800,10 @@ UNINITIALIZED_TEST(DeoptimizeLoadICStoreIC) {
CompileRun("f2(new X(), 'z');");
CompileRun("g2(new X(), 'z');");
if (i_isolate->use_crankshaft()) {
CHECK(GetJSFunction(env->Global(), "f1")->IsOptimized());
CHECK(GetJSFunction(env->Global(), "g1")->IsOptimized());
CHECK(GetJSFunction(env->Global(), "f2")->IsOptimized());
CHECK(GetJSFunction(env->Global(), "g2")->IsOptimized());
CHECK(GetJSFunction(env.local(), "f1")->IsOptimized());
CHECK(GetJSFunction(env.local(), "g1")->IsOptimized());
CHECK(GetJSFunction(env.local(), "f2")->IsOptimized());
CHECK(GetJSFunction(env.local(), "g2")->IsOptimized());
}
// Call functions and force deoptimization while processing the ics.
@ -695,12 +816,20 @@ UNINITIALIZED_TEST(DeoptimizeLoadICStoreIC) {
}
NonIncrementalGC(i_isolate);
CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized());
CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized());
CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized());
CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized());
CHECK_EQ(4, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK(!GetJSFunction(env.local(), "f1")->IsOptimized());
CHECK(!GetJSFunction(env.local(), "g1")->IsOptimized());
CHECK(!GetJSFunction(env.local(), "f2")->IsOptimized());
CHECK(!GetJSFunction(env.local(), "g2")->IsOptimized());
CHECK_EQ(4, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(13, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
}
isolate->Exit();
isolate->Dispose();
@ -775,10 +904,10 @@ UNINITIALIZED_TEST(DeoptimizeLoadICStoreICNested) {
CompileRun("f2(new X(), 'z');");
CompileRun("g2(new X(), 'z');");
if (i_isolate->use_crankshaft()) {
CHECK(GetJSFunction(env->Global(), "f1")->IsOptimized());
CHECK(GetJSFunction(env->Global(), "g1")->IsOptimized());
CHECK(GetJSFunction(env->Global(), "f2")->IsOptimized());
CHECK(GetJSFunction(env->Global(), "g2")->IsOptimized());
CHECK(GetJSFunction(env.local(), "f1")->IsOptimized());
CHECK(GetJSFunction(env.local(), "g1")->IsOptimized());
CHECK(GetJSFunction(env.local(), "f2")->IsOptimized());
CHECK(GetJSFunction(env.local(), "g2")->IsOptimized());
}
// Call functions and force deoptimization while processing the ics.
@ -788,12 +917,20 @@ UNINITIALIZED_TEST(DeoptimizeLoadICStoreICNested) {
}
NonIncrementalGC(i_isolate);
CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized());
CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized());
CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized());
CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized());
CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value());
CHECK(!GetJSFunction(env.local(), "f1")->IsOptimized());
CHECK(!GetJSFunction(env.local(), "g1")->IsOptimized());
CHECK(!GetJSFunction(env.local(), "f2")->IsOptimized());
CHECK(!GetJSFunction(env.local(), "g2")->IsOptimized());
CHECK_EQ(1, env->Global()
->Get(env.local(), v8_str("count"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
CHECK_EQ(13, env->Global()
->Get(env.local(), v8_str("result"))
.ToLocalChecked()
->Int32Value(env.local())
.FromJust());
}
isolate->Exit();
isolate->Dispose();