2012-01-24 16:36:55 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2010-12-07 11:31:57 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/compilation-cache.h"
|
2015-07-31 11:07:50 +00:00
|
|
|
#include "src/debug/debug.h"
|
2019-05-20 13:01:00 +00:00
|
|
|
#include "src/deoptimizer/deoptimizer.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/isolate.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/objects-inl.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
using ::v8::base::OS;
|
2011-03-18 19:41:05 +00:00
|
|
|
using ::v8::internal::Deoptimizer;
|
|
|
|
using ::v8::internal::EmbeddedVector;
|
2011-03-18 20:35:07 +00:00
|
|
|
using ::v8::internal::Handle;
|
|
|
|
using ::v8::internal::JSFunction;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Size of temp buffer for formatting small strings.
|
|
|
|
#define SMALL_STRING_BUFFER_SIZE 80
|
|
|
|
|
2015-10-15 12:01:52 +00:00
|
|
|
// Utility class to set the following runtime flags when constructed and return
|
|
|
|
// to their default state when destroyed:
|
2017-07-13 11:22:37 +00:00
|
|
|
// --allow-natives-syntax --always-opt --noturbo-inlining
|
2010-12-07 11:31:57 +00:00
|
|
|
class AlwaysOptimizeAllowNativesSyntaxNoInlining {
|
|
|
|
public:
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining()
|
|
|
|
: always_opt_(i::FLAG_always_opt),
|
|
|
|
allow_natives_syntax_(i::FLAG_allow_natives_syntax),
|
2017-07-13 11:22:37 +00:00
|
|
|
turbo_inlining_(i::FLAG_turbo_inlining) {
|
2010-12-07 11:31:57 +00:00
|
|
|
i::FLAG_always_opt = true;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2015-10-15 12:01:52 +00:00
|
|
|
i::FLAG_turbo_inlining = false;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~AlwaysOptimizeAllowNativesSyntaxNoInlining() {
|
|
|
|
i::FLAG_always_opt = always_opt_;
|
2015-10-15 12:01:52 +00:00
|
|
|
i::FLAG_allow_natives_syntax = allow_natives_syntax_;
|
|
|
|
i::FLAG_turbo_inlining = turbo_inlining_;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool always_opt_;
|
|
|
|
bool allow_natives_syntax_;
|
2015-10-15 12:01:52 +00:00
|
|
|
bool turbo_inlining_;
|
2010-12-07 11:31:57 +00:00
|
|
|
};
|
|
|
|
|
2015-10-15 12:01:52 +00:00
|
|
|
// Utility class to set the following runtime flags when constructed and return
|
|
|
|
// to their default state when destroyed:
|
2017-07-13 11:22:37 +00:00
|
|
|
// --allow-natives-syntax --noturbo-inlining
|
2013-11-19 11:52:47 +00:00
|
|
|
class AllowNativesSyntaxNoInlining {
|
2010-12-07 11:31:57 +00:00
|
|
|
public:
|
2013-11-19 11:52:47 +00:00
|
|
|
AllowNativesSyntaxNoInlining()
|
2010-12-07 11:31:57 +00:00
|
|
|
: allow_natives_syntax_(i::FLAG_allow_natives_syntax),
|
2017-07-13 11:22:37 +00:00
|
|
|
turbo_inlining_(i::FLAG_turbo_inlining) {
|
2010-12-07 11:31:57 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2015-10-15 12:01:52 +00:00
|
|
|
i::FLAG_turbo_inlining = false;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2013-11-19 11:52:47 +00:00
|
|
|
~AllowNativesSyntaxNoInlining() {
|
2010-12-07 11:31:57 +00:00
|
|
|
i::FLAG_allow_natives_syntax = allow_natives_syntax_;
|
2015-10-15 12:01:52 +00:00
|
|
|
i::FLAG_turbo_inlining = turbo_inlining_;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool allow_natives_syntax_;
|
2015-10-15 12:01:52 +00:00
|
|
|
bool turbo_inlining_;
|
2010-12-07 11:31:57 +00:00
|
|
|
};
|
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
static Handle<JSFunction> GetJSFunction(v8::Local<v8::Context> context,
|
2011-05-11 14:16:24 +00:00
|
|
|
const char* property_name) {
|
2015-11-20 12:56:19 +00:00
|
|
|
v8::Local<v8::Function> fun = v8::Local<v8::Function>::Cast(
|
|
|
|
context->Global()->Get(context, v8_str(property_name)).ToLocalChecked());
|
2015-10-23 12:26:49 +00:00
|
|
|
return i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*fun));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeoptimizeSimple) {
|
2017-06-12 11:03:01 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2012-02-13 10:13:52 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Test lazy deoptimization of a simple function.
|
|
|
|
{
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining options;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"function h() { %DeoptimizeFunction(f); }"
|
|
|
|
"function g() { count++; h(); }"
|
|
|
|
"function f() { g(); };"
|
2012-02-13 10:13:52 +00:00
|
|
|
"f();");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
CHECK_EQ(1, env->Global()
|
|
|
|
->Get(env.local(), v8_str("count"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(env.local())
|
|
|
|
.FromJust());
|
|
|
|
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Test lazy deoptimization of a simple function. Call the function after the
|
|
|
|
// deoptimization while it is still activated further down the stack.
|
|
|
|
{
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining options;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"function g() { count++; %DeoptimizeFunction(f); f(false); }"
|
|
|
|
"function f(x) { if (x) { g(); } else { return } };"
|
2012-02-13 10:13:52 +00:00
|
|
|
"f(true);");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
CHECK_EQ(1, env->Global()
|
|
|
|
->Get(env.local(), v8_str("count"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(env.local())
|
|
|
|
.FromJust());
|
|
|
|
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeoptimizeSimpleWithArguments) {
|
2017-06-12 11:03:01 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2012-02-13 10:13:52 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Test lazy deoptimization of a simple function with some arguments.
|
|
|
|
{
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining options;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"function h(x) { %DeoptimizeFunction(f); }"
|
|
|
|
"function g(x, y) { count++; h(x); }"
|
|
|
|
"function f(x, y, z) { g(1,x); y+z; };"
|
2012-02-13 10:13:52 +00:00
|
|
|
"f(1, \"2\", false);");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
CHECK_EQ(1, env->Global()
|
|
|
|
->Get(env.local(), v8_str("count"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(env.local())
|
|
|
|
.FromJust());
|
|
|
|
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Test lazy deoptimization of a simple function with some arguments. Call the
|
|
|
|
// function after the deoptimization while it is still activated further down
|
|
|
|
// the stack.
|
|
|
|
{
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining options;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"function g(x, y) { count++; %DeoptimizeFunction(f); f(false, 1, y); }"
|
|
|
|
"function f(x, y, z) { if (x) { g(x, y); } else { return y + z; } };"
|
2012-02-13 10:13:52 +00:00
|
|
|
"f(true, 1, \"2\");");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
CHECK_EQ(1, env->Global()
|
|
|
|
->Get(env.local(), v8_str("count"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(env.local())
|
|
|
|
.FromJust());
|
|
|
|
CHECK(!GetJSFunction(env.local(), "f")->IsOptimized());
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeoptimizeSimpleNested) {
|
2017-06-12 11:03:01 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2012-02-13 10:13:52 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Test lazy deoptimization of a simple function. Have a nested function call
|
|
|
|
// do the deoptimization.
|
|
|
|
{
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining options;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"var result = 0;"
|
|
|
|
"function h(x, y, z) { return x + y + z; }"
|
|
|
|
"function g(z) { count++; %DeoptimizeFunction(f); return z;}"
|
|
|
|
"function f(x,y,z) { return h(x, y, g(z)); };"
|
2012-02-13 10:13:52 +00:00
|
|
|
"result = f(1, 2, 3);");
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeoptimizeRecursive) {
|
2017-06-12 11:03:01 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2012-02-13 10:13:52 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Test lazy deoptimization of a simple function called recursively. Call
|
|
|
|
// the function recursively a number of times before deoptimizing it.
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining options;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"var calls = 0;"
|
|
|
|
"function g() { count++; %DeoptimizeFunction(f); }"
|
|
|
|
"function f(x) { calls++; if (x > 0) { f(x - 1); } else { g(); } };"
|
2012-02-13 10:13:52 +00:00
|
|
|
"f(10);");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::Function> fun = v8::Local<v8::Function>::Cast(
|
2015-11-20 12:56:19 +00:00
|
|
|
env->Global()
|
|
|
|
->Get(env.local(), v8_str(CcTest::isolate(), "f"))
|
|
|
|
.ToLocalChecked());
|
2012-01-24 16:36:55 +00:00
|
|
|
CHECK(!fun.IsEmpty());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeoptimizeMultiple) {
|
2017-06-12 11:03:01 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2012-02-13 10:13:52 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining options;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"var result = 0;"
|
|
|
|
"function g() { count++;"
|
|
|
|
" %DeoptimizeFunction(f1);"
|
|
|
|
" %DeoptimizeFunction(f2);"
|
|
|
|
" %DeoptimizeFunction(f3);"
|
|
|
|
" %DeoptimizeFunction(f4);}"
|
|
|
|
"function f4(x) { g(); };"
|
|
|
|
"function f3(x, y, z) { f4(); return x + y + z; };"
|
|
|
|
"function f2(x, y) { return x + f3(y + 1, y + 1, y + 1) + y; };"
|
|
|
|
"function f1(x) { return f2(x + 1, x + 1) + x; };"
|
2012-02-13 10:13:52 +00:00
|
|
|
"result = f1(1);");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeoptimizeConstructor) {
|
2017-06-12 11:03:01 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2012-02-13 10:13:52 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining options;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"function g() { count++;"
|
|
|
|
" %DeoptimizeFunction(f); }"
|
|
|
|
"function f() { g(); };"
|
2012-02-13 10:13:52 +00:00
|
|
|
"result = new f() instanceof f;");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining options;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"var result = 0;"
|
|
|
|
"function g() { count++;"
|
|
|
|
" %DeoptimizeFunction(f); }"
|
|
|
|
"function f(x, y) { this.x = x; g(); this.y = y; };"
|
|
|
|
"result = new f(1, 2);"
|
2012-02-13 10:13:52 +00:00
|
|
|
"result = result.x + result.y;");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeoptimizeConstructorMultiple) {
|
2017-06-12 11:03:01 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2012-02-13 10:13:52 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
AlwaysOptimizeAllowNativesSyntaxNoInlining options;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"var result = 0;"
|
|
|
|
"function g() { count++;"
|
|
|
|
" %DeoptimizeFunction(f1);"
|
|
|
|
" %DeoptimizeFunction(f2);"
|
|
|
|
" %DeoptimizeFunction(f3);"
|
|
|
|
" %DeoptimizeFunction(f4);}"
|
|
|
|
"function f4(x) { this.result = x; g(); };"
|
|
|
|
"function f3(x, y, z) { this.result = new f4(x + y + z).result; };"
|
|
|
|
"function f2(x, y) {"
|
|
|
|
" this.result = x + new f3(y + 1, y + 1, y + 1).result + y; };"
|
|
|
|
"function f1(x) { this.result = new f2(x + 1, x + 1).result + x; };"
|
2012-02-13 10:13:52 +00:00
|
|
|
"result = new f1(1).result;");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2013-09-19 09:17:13 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
UNINITIALIZED_TEST(DeoptimizeBinaryOperationADDString) {
|
2017-06-12 11:03:01 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2013-11-19 11:52:47 +00:00
|
|
|
i::FLAG_concurrent_recompilation = false;
|
|
|
|
AllowNativesSyntaxNoInlining options;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
isolate->Enter();
|
2014-09-18 21:57:10 +00:00
|
|
|
{
|
2014-09-19 08:01:35 +00:00
|
|
|
LocalContext env(isolate);
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
const char* f_source = "function f(x, y) { return x + y; };";
|
|
|
|
|
|
|
|
{
|
|
|
|
// Compile function f and collect to type feedback to insert binary op
|
|
|
|
// stub call in the optimized code.
|
|
|
|
i::FLAG_prepare_always_opt = true;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"var result = 0;"
|
|
|
|
"var deopt = false;"
|
|
|
|
"function X() { };"
|
|
|
|
"X.prototype.toString = function () {"
|
|
|
|
" if (deopt) { count++; %DeoptimizeFunction(f); } return 'an X'"
|
|
|
|
"};");
|
|
|
|
CompileRun(f_source);
|
|
|
|
CompileRun(
|
|
|
|
"for (var i = 0; i < 5; i++) {"
|
|
|
|
" f('a+', new X());"
|
|
|
|
"};");
|
|
|
|
|
|
|
|
// Compile an optimized version of f.
|
|
|
|
i::FLAG_always_opt = true;
|
|
|
|
CompileRun(f_source);
|
|
|
|
CompileRun("f('a+', new X());");
|
2017-04-28 15:36:46 +00:00
|
|
|
CHECK(!i_isolate->use_optimizer() ||
|
2015-11-20 12:56:19 +00:00
|
|
|
GetJSFunction(env.local(), "f")->IsOptimized());
|
2014-09-19 08:01:35 +00:00
|
|
|
|
|
|
|
// Call f and force deoptimization while processing the binary operation.
|
|
|
|
CompileRun(
|
|
|
|
"deopt = true;"
|
|
|
|
"var result = f('a+', new X());");
|
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage(i_isolate);
|
2014-09-18 21:57:10 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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();
|
2014-09-19 08:01:35 +00:00
|
|
|
CHECK(result->IsString());
|
2017-08-24 21:49:48 +00:00
|
|
|
v8::String::Utf8Value utf8(isolate, result);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(0, strcmp("a+an X", *utf8));
|
2014-09-19 08:01:35 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
|
|
|
|
}
|
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CompileConstructorWithDeoptimizingValueOf() {
|
|
|
|
CompileRun("var count = 0;"
|
|
|
|
"var result = 0;"
|
|
|
|
"var deopt = false;"
|
|
|
|
"function X() { };"
|
|
|
|
"X.prototype.valueOf = function () {"
|
|
|
|
" if (deopt) { count++; %DeoptimizeFunction(f); } return 8"
|
|
|
|
"};");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void TestDeoptimizeBinaryOpHelper(LocalContext* env,
|
|
|
|
const char* binary_op) {
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>((*env)->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> f_source_buffer;
|
2014-06-13 16:43:27 +00:00
|
|
|
SNPrintF(f_source_buffer,
|
|
|
|
"function f(x, y) { return x %s y; };",
|
|
|
|
binary_op);
|
2019-04-29 11:06:49 +00:00
|
|
|
char* f_source = f_source_buffer.begin();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-11-19 11:52:47 +00:00
|
|
|
AllowNativesSyntaxNoInlining options;
|
2010-12-07 11:31:57 +00:00
|
|
|
// Compile function f and collect to type feedback to insert binary op stub
|
|
|
|
// call in the optimized code.
|
|
|
|
i::FLAG_prepare_always_opt = true;
|
|
|
|
CompileConstructorWithDeoptimizingValueOf();
|
|
|
|
CompileRun(f_source);
|
|
|
|
CompileRun("for (var i = 0; i < 5; i++) {"
|
|
|
|
" f(8, new X());"
|
|
|
|
"};");
|
|
|
|
|
|
|
|
// Compile an optimized version of f.
|
|
|
|
i::FLAG_always_opt = true;
|
|
|
|
CompileRun(f_source);
|
|
|
|
CompileRun("f(7, new X());");
|
2017-04-28 15:36:46 +00:00
|
|
|
CHECK(!i_isolate->use_optimizer() ||
|
2015-11-20 12:56:19 +00:00
|
|
|
GetJSFunction((*env).local(), "f")->IsOptimized());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Call f and force deoptimization while processing the binary operation.
|
|
|
|
CompileRun("deopt = true;"
|
2012-02-13 10:13:52 +00:00
|
|
|
"var result = f(7, new X());");
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage(i_isolate);
|
2015-11-20 12:56:19 +00:00
|
|
|
CHECK(!GetJSFunction((*env).local(), "f")->IsOptimized());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
UNINITIALIZED_TEST(DeoptimizeBinaryOperationADD) {
|
2017-06-13 09:25:18 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2013-11-19 11:52:47 +00:00
|
|
|
i::FLAG_concurrent_recompilation = false;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
isolate->Enter();
|
|
|
|
{
|
|
|
|
LocalContext env(isolate);
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
TestDeoptimizeBinaryOpHelper(&env, "+");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2014-09-19 08:01:35 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
|
|
|
|
}
|
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
UNINITIALIZED_TEST(DeoptimizeBinaryOperationSUB) {
|
2017-06-13 09:25:18 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2013-11-19 11:52:47 +00:00
|
|
|
i::FLAG_concurrent_recompilation = false;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
isolate->Enter();
|
|
|
|
{
|
|
|
|
LocalContext env(isolate);
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
TestDeoptimizeBinaryOpHelper(&env, "-");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2014-09-19 08:01:35 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
|
|
|
|
}
|
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
UNINITIALIZED_TEST(DeoptimizeBinaryOperationMUL) {
|
2017-06-13 09:25:18 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2013-11-19 11:52:47 +00:00
|
|
|
i::FLAG_concurrent_recompilation = false;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
isolate->Enter();
|
|
|
|
{
|
|
|
|
LocalContext env(isolate);
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
TestDeoptimizeBinaryOpHelper(&env, "*");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2014-09-19 08:01:35 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
|
|
|
|
}
|
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
UNINITIALIZED_TEST(DeoptimizeBinaryOperationDIV) {
|
2017-06-13 09:25:18 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2013-11-19 11:52:47 +00:00
|
|
|
i::FLAG_concurrent_recompilation = false;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
isolate->Enter();
|
|
|
|
{
|
|
|
|
LocalContext env(isolate);
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
TestDeoptimizeBinaryOpHelper(&env, "/");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2014-09-19 08:01:35 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
|
|
|
|
}
|
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
UNINITIALIZED_TEST(DeoptimizeBinaryOperationMOD) {
|
2017-06-13 09:25:18 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2013-11-19 11:52:47 +00:00
|
|
|
i::FLAG_concurrent_recompilation = false;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
isolate->Enter();
|
|
|
|
{
|
|
|
|
LocalContext env(isolate);
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
TestDeoptimizeBinaryOpHelper(&env, "%");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2014-09-19 08:01:35 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
|
|
|
|
}
|
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
UNINITIALIZED_TEST(DeoptimizeCompare) {
|
2017-06-13 09:25:18 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2013-11-19 11:52:47 +00:00
|
|
|
i::FLAG_concurrent_recompilation = false;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
isolate->Enter();
|
2014-09-18 21:57:10 +00:00
|
|
|
{
|
2014-09-19 08:01:35 +00:00
|
|
|
LocalContext env(isolate);
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
const char* f_source = "function f(x, y) { return x < y; };";
|
|
|
|
|
|
|
|
{
|
|
|
|
AllowNativesSyntaxNoInlining options;
|
|
|
|
// Compile function f and collect to type feedback to insert compare ic
|
|
|
|
// call in the optimized code.
|
|
|
|
i::FLAG_prepare_always_opt = true;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"var result = 0;"
|
|
|
|
"var deopt = false;"
|
|
|
|
"function X() { };"
|
|
|
|
"X.prototype.toString = function () {"
|
|
|
|
" if (deopt) { count++; %DeoptimizeFunction(f); } return 'b'"
|
|
|
|
"};");
|
|
|
|
CompileRun(f_source);
|
|
|
|
CompileRun(
|
|
|
|
"for (var i = 0; i < 5; i++) {"
|
|
|
|
" f('a', new X());"
|
|
|
|
"};");
|
|
|
|
|
|
|
|
// Compile an optimized version of f.
|
|
|
|
i::FLAG_always_opt = true;
|
|
|
|
CompileRun(f_source);
|
|
|
|
CompileRun("f('a', new X());");
|
2017-04-28 15:36:46 +00:00
|
|
|
CHECK(!i_isolate->use_optimizer() ||
|
2015-11-20 12:56:19 +00:00
|
|
|
GetJSFunction(env.local(), "f")->IsOptimized());
|
2014-09-19 08:01:35 +00:00
|
|
|
|
|
|
|
// Call f and force deoptimization while processing the comparison.
|
|
|
|
CompileRun(
|
|
|
|
"deopt = true;"
|
|
|
|
"var result = f('a', new X());");
|
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage(i_isolate);
|
2014-09-18 21:57:10 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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()
|
2018-09-24 11:05:31 +00:00
|
|
|
->BooleanValue(isolate));
|
2014-09-19 08:01:35 +00:00
|
|
|
CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
|
|
|
|
}
|
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
UNINITIALIZED_TEST(DeoptimizeLoadICStoreIC) {
|
2017-06-13 09:25:18 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2013-11-19 11:52:47 +00:00
|
|
|
i::FLAG_concurrent_recompilation = false;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
isolate->Enter();
|
2010-12-07 11:31:57 +00:00
|
|
|
{
|
2014-09-19 08:01:35 +00:00
|
|
|
LocalContext env(isolate);
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
// Functions to generate load/store/keyed load/keyed store IC calls.
|
|
|
|
const char* f1_source = "function f1(x) { return x.y; };";
|
|
|
|
const char* g1_source = "function g1(x) { x.y = 1; };";
|
|
|
|
const char* f2_source = "function f2(x, y) { return x[y]; };";
|
|
|
|
const char* g2_source = "function g2(x, y) { x[y] = 1; };";
|
|
|
|
|
|
|
|
{
|
|
|
|
AllowNativesSyntaxNoInlining options;
|
|
|
|
// Compile functions and collect to type feedback to insert ic
|
|
|
|
// calls in the optimized code.
|
|
|
|
i::FLAG_prepare_always_opt = true;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"var result = 0;"
|
|
|
|
"var deopt = false;"
|
|
|
|
"function X() { };"
|
|
|
|
"X.prototype.__defineGetter__('y', function () {"
|
|
|
|
" if (deopt) { count++; %DeoptimizeFunction(f1); };"
|
|
|
|
" return 13;"
|
|
|
|
"});"
|
|
|
|
"X.prototype.__defineSetter__('y', function () {"
|
|
|
|
" if (deopt) { count++; %DeoptimizeFunction(g1); };"
|
|
|
|
"});"
|
|
|
|
"X.prototype.__defineGetter__('z', function () {"
|
|
|
|
" if (deopt) { count++; %DeoptimizeFunction(f2); };"
|
|
|
|
" return 13;"
|
|
|
|
"});"
|
|
|
|
"X.prototype.__defineSetter__('z', function () {"
|
|
|
|
" if (deopt) { count++; %DeoptimizeFunction(g2); };"
|
|
|
|
"});");
|
|
|
|
CompileRun(f1_source);
|
|
|
|
CompileRun(g1_source);
|
|
|
|
CompileRun(f2_source);
|
|
|
|
CompileRun(g2_source);
|
|
|
|
CompileRun(
|
|
|
|
"for (var i = 0; i < 5; i++) {"
|
|
|
|
" f1(new X());"
|
|
|
|
" g1(new X());"
|
|
|
|
" f2(new X(), 'z');"
|
|
|
|
" g2(new X(), 'z');"
|
|
|
|
"};");
|
|
|
|
|
|
|
|
// Compile an optimized version of the functions.
|
|
|
|
i::FLAG_always_opt = true;
|
|
|
|
CompileRun(f1_source);
|
|
|
|
CompileRun(g1_source);
|
|
|
|
CompileRun(f2_source);
|
|
|
|
CompileRun(g2_source);
|
|
|
|
CompileRun("f1(new X());");
|
|
|
|
CompileRun("g1(new X());");
|
|
|
|
CompileRun("f2(new X(), 'z');");
|
|
|
|
CompileRun("g2(new X(), 'z');");
|
2017-04-28 15:36:46 +00:00
|
|
|
if (i_isolate->use_optimizer()) {
|
2015-11-20 12:56:19 +00:00
|
|
|
CHECK(GetJSFunction(env.local(), "f1")->IsOptimized());
|
|
|
|
CHECK(GetJSFunction(env.local(), "g1")->IsOptimized());
|
|
|
|
CHECK(GetJSFunction(env.local(), "f2")->IsOptimized());
|
|
|
|
CHECK(GetJSFunction(env.local(), "g2")->IsOptimized());
|
2014-09-19 08:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call functions and force deoptimization while processing the ics.
|
|
|
|
CompileRun(
|
|
|
|
"deopt = true;"
|
|
|
|
"var result = f1(new X());"
|
|
|
|
"g1(new X());"
|
|
|
|
"f2(new X(), 'z');"
|
|
|
|
"g2(new X(), 'z');");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage(i_isolate);
|
2014-09-19 08:01:35 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2014-09-19 08:01:35 +00:00
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
UNINITIALIZED_TEST(DeoptimizeLoadICStoreICNested) {
|
2017-06-13 09:25:18 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2013-11-19 11:52:47 +00:00
|
|
|
i::FLAG_concurrent_recompilation = false;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
isolate->Enter();
|
2010-12-07 11:31:57 +00:00
|
|
|
{
|
2014-09-19 08:01:35 +00:00
|
|
|
LocalContext env(isolate);
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
// Functions to generate load/store/keyed load/keyed store IC calls.
|
|
|
|
const char* f1_source = "function f1(x) { return x.y; };";
|
|
|
|
const char* g1_source = "function g1(x) { x.y = 1; };";
|
|
|
|
const char* f2_source = "function f2(x, y) { return x[y]; };";
|
|
|
|
const char* g2_source = "function g2(x, y) { x[y] = 1; };";
|
|
|
|
|
|
|
|
{
|
|
|
|
AllowNativesSyntaxNoInlining options;
|
|
|
|
// Compile functions and collect to type feedback to insert ic
|
|
|
|
// calls in the optimized code.
|
|
|
|
i::FLAG_prepare_always_opt = true;
|
|
|
|
CompileRun(
|
|
|
|
"var count = 0;"
|
|
|
|
"var result = 0;"
|
|
|
|
"var deopt = false;"
|
|
|
|
"function X() { };"
|
|
|
|
"X.prototype.__defineGetter__('y', function () {"
|
|
|
|
" g1(this);"
|
|
|
|
" return 13;"
|
|
|
|
"});"
|
|
|
|
"X.prototype.__defineSetter__('y', function () {"
|
|
|
|
" f2(this, 'z');"
|
|
|
|
"});"
|
|
|
|
"X.prototype.__defineGetter__('z', function () {"
|
|
|
|
" g2(this, 'z');"
|
|
|
|
"});"
|
|
|
|
"X.prototype.__defineSetter__('z', function () {"
|
|
|
|
" if (deopt) {"
|
|
|
|
" count++;"
|
|
|
|
" %DeoptimizeFunction(f1);"
|
|
|
|
" %DeoptimizeFunction(g1);"
|
|
|
|
" %DeoptimizeFunction(f2);"
|
|
|
|
" %DeoptimizeFunction(g2); };"
|
|
|
|
"});");
|
|
|
|
CompileRun(f1_source);
|
|
|
|
CompileRun(g1_source);
|
|
|
|
CompileRun(f2_source);
|
|
|
|
CompileRun(g2_source);
|
|
|
|
CompileRun(
|
|
|
|
"for (var i = 0; i < 5; i++) {"
|
|
|
|
" f1(new X());"
|
|
|
|
" g1(new X());"
|
|
|
|
" f2(new X(), 'z');"
|
|
|
|
" g2(new X(), 'z');"
|
|
|
|
"};");
|
|
|
|
|
|
|
|
// Compile an optimized version of the functions.
|
|
|
|
i::FLAG_always_opt = true;
|
|
|
|
CompileRun(f1_source);
|
|
|
|
CompileRun(g1_source);
|
|
|
|
CompileRun(f2_source);
|
|
|
|
CompileRun(g2_source);
|
|
|
|
CompileRun("f1(new X());");
|
|
|
|
CompileRun("g1(new X());");
|
|
|
|
CompileRun("f2(new X(), 'z');");
|
|
|
|
CompileRun("g2(new X(), 'z');");
|
2017-04-28 15:36:46 +00:00
|
|
|
if (i_isolate->use_optimizer()) {
|
2015-11-20 12:56:19 +00:00
|
|
|
CHECK(GetJSFunction(env.local(), "f1")->IsOptimized());
|
|
|
|
CHECK(GetJSFunction(env.local(), "g1")->IsOptimized());
|
|
|
|
CHECK(GetJSFunction(env.local(), "f2")->IsOptimized());
|
|
|
|
CHECK(GetJSFunction(env.local(), "g2")->IsOptimized());
|
2014-09-19 08:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call functions and force deoptimization while processing the ics.
|
|
|
|
CompileRun(
|
|
|
|
"deopt = true;"
|
|
|
|
"var result = f1(new X());");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage(i_isolate);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-20 12:56:19 +00:00
|
|
|
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());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2014-09-19 08:01:35 +00:00
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|