Commit 62cca39e authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[compiler] Move ensuring deoptimization support to backends.

This moves the responsibility of preparing full-codegen code with
deoptimization support into the backends. This avoids generating such
code when optimization can be done directly from existing bytecode.

R=bmeurer@chromium.org
BUG=v8:4280
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#35517}
parent 7b2861e3
......@@ -322,28 +322,6 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
return AbortOptimization(kOptimizedTooManyTimes);
}
// Optimization requires a version of fullcode with deoptimization support.
// Recompile the unoptimized version of the code if the current version
// doesn't have deoptimization support already.
// Otherwise, if we are gathering compilation time and space statistics
// for hydrogen, gather baseline statistics for a fullcode compilation.
bool should_recompile = !info()->shared_info()->has_deoptimization_support();
if (should_recompile || FLAG_hydrogen_stats) {
base::ElapsedTimer timer;
if (FLAG_hydrogen_stats) {
timer.Start();
}
if (!Compiler::EnsureDeoptimizationSupport(info())) {
return SetLastStatus(FAILED);
}
if (FLAG_hydrogen_stats) {
isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed());
}
}
DCHECK(info()->shared_info()->has_deoptimization_support());
DCHECK(!info()->shared_info()->never_compiled());
if (FLAG_trace_opt) {
OFStream os(stdout);
os << "[compiling method " << Brief(*info()->closure()) << " using "
......
......@@ -504,6 +504,10 @@ PipelineCompilationJob::Status PipelineCompilationJob::CreateGraphImpl() {
info()->MarkAsDeoptimizationEnabled();
}
if (!info()->shared_info()->HasBytecodeArray()) {
if (!Compiler::EnsureDeoptimizationSupport(info())) return FAILED;
}
Pipeline pipeline(info());
pipeline.GenerateCode();
if (isolate()->has_pending_exception()) return FAILED; // Stack overflowed.
......
......@@ -114,6 +114,27 @@ class HOptimizedGraphBuilderWithPositions : public HOptimizedGraphBuilder {
HCompilationJob::Status HCompilationJob::CreateGraphImpl() {
bool dont_crankshaft = info()->shared_info()->dont_crankshaft();
// Optimization requires a version of fullcode with deoptimization support.
// Recompile the unoptimized version of the code if the current version
// doesn't have deoptimization support already.
// Otherwise, if we are gathering compilation time and space statistics
// for hydrogen, gather baseline statistics for a fullcode compilation.
bool should_recompile = !info()->shared_info()->has_deoptimization_support();
if (should_recompile || FLAG_hydrogen_stats) {
base::ElapsedTimer timer;
if (FLAG_hydrogen_stats) {
timer.Start();
}
if (!Compiler::EnsureDeoptimizationSupport(info())) {
return FAILED;
}
if (FLAG_hydrogen_stats) {
isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed());
}
}
DCHECK(info()->shared_info()->has_deoptimization_support());
DCHECK(!info()->shared_info()->never_compiled());
if (!isolate()->use_crankshaft() || dont_crankshaft) {
// Crankshaft is entirely disabled.
return FAILED;
......
......@@ -13517,8 +13517,15 @@ void SharedFunctionInfo::ResetForNewContext(int new_ic_age) {
set_ic_age(new_ic_age);
if (code()->kind() == Code::FUNCTION) {
code()->set_profiler_ticks(0);
if (optimization_disabled() &&
opt_count() >= FLAG_max_opt_count) {
if (optimization_disabled() && opt_count() >= FLAG_max_opt_count) {
// Re-enable optimizations if they were disabled due to opt_count limit.
set_optimization_disabled(false);
}
set_opt_count(0);
set_deopt_count(0);
} else if (code()->is_interpreter_entry_trampoline()) {
set_profiler_ticks(0);
if (optimization_disabled() && opt_count() >= FLAG_max_opt_count) {
// Re-enable optimizations if they were disabled due to opt_count limit.
set_optimization_disabled(false);
}
......
......@@ -2658,6 +2658,14 @@ TEST(InstanceOfStubWriteBarrier) {
CcTest::heap()->CollectGarbage(OLD_SPACE);
}
namespace {
int GetProfilerTicks(SharedFunctionInfo* shared) {
return FLAG_ignition ? shared->profiler_ticks()
: shared->code()->profiler_ticks();
}
} // namespace
TEST(ResetSharedFunctionInfoCountersDuringIncrementalMarking) {
i::FLAG_stress_compaction = false;
......@@ -2688,16 +2696,18 @@ TEST(ResetSharedFunctionInfoCountersDuringIncrementalMarking) {
CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
CHECK(f->IsOptimized());
IncrementalMarking* marking = CcTest::heap()->incremental_marking();
marking->Stop();
// Make sure incremental marking it not running.
CcTest::heap()->incremental_marking()->Stop();
CcTest::heap()->StartIncrementalMarking();
// The following calls will increment CcTest::heap()->global_ic_age().
CcTest::isolate()->ContextDisposedNotification();
SimulateIncrementalMarking(CcTest::heap());
CcTest::heap()->CollectAllGarbage();
CHECK_EQ(CcTest::heap()->global_ic_age(), f->shared()->ic_age());
CHECK_EQ(0, f->shared()->opt_count());
CHECK_EQ(0, f->shared()->code()->profiler_ticks());
CHECK_EQ(0, GetProfilerTicks(f->shared()));
}
......@@ -2728,9 +2738,9 @@ TEST(ResetSharedFunctionInfoCountersDuringMarkSweep) {
i::Handle<JSFunction> f = i::Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
CHECK(f->IsOptimized());
// Make sure incremental marking it not running.
CcTest::heap()->incremental_marking()->Stop();
// The following two calls will increment CcTest::heap()->global_ic_age().
......@@ -2739,7 +2749,7 @@ TEST(ResetSharedFunctionInfoCountersDuringMarkSweep) {
CHECK_EQ(CcTest::heap()->global_ic_age(), f->shared()->ic_age());
CHECK_EQ(0, f->shared()->opt_count());
CHECK_EQ(0, f->shared()->code()->profiler_ticks());
CHECK_EQ(0, GetProfilerTicks(f->shared()));
}
......
......@@ -759,7 +759,6 @@
'es6/debug-promises/stepin-constructor': [FAIL],
'es6/debug-stepin-proxies': [FAIL],
'regress/regress-crbug-119800': [FAIL],
'regress/regress-opt-after-debug-deopt': [FAIL],
# TODO(yangguo,4690): flaky failures on the bots.
'debug-stepin-builtin-callback-opt': [SKIP],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment