Skip to content

Commit c9a49da

Browse files
bmeurerCommit bot
authored and
Commit bot
committed
[turbofan] Enable deoptimization for non-asm.js TurboFan code.
Replace the --turbo-deoptimization flag with --turbo-asm-deoptimization and enable deoptimization for non-asm.js TurboFan code unconditionally. [email protected] Review URL: https://codereview.chromium.org/1153483002 Cr-Commit-Position: refs/heads/master@{#28543}
1 parent 3996dc5 commit c9a49da

19 files changed

+49
-137
lines changed

src/compiler.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ CompilationInfo::CompilationInfo(ParseInfo* parse_info)
114114

115115
if (isolate_->debug()->is_active()) MarkAsDebug();
116116
if (FLAG_context_specialization) MarkAsContextSpecializing();
117-
if (FLAG_turbo_deoptimization) MarkAsDeoptimizationEnabled();
118117
if (FLAG_turbo_inlining) MarkAsInliningEnabled();
119118
if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled();
120119
if (FLAG_turbo_splitting) MarkAsSplittingEnabled();
@@ -393,6 +392,10 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
393392
info()->MarkAsTypeFeedbackEnabled();
394393
info()->EnsureFeedbackVector();
395394
}
395+
if (!info()->shared_info()->asm_function() ||
396+
FLAG_turbo_asm_deoptimization) {
397+
info()->MarkAsDeoptimizationEnabled();
398+
}
396399

397400
Timer t(this, &time_taken_to_create_graph_);
398401
compiler::Pipeline pipeline(info());
@@ -502,7 +505,7 @@ OptimizedCompileJob::Status OptimizedCompileJob::GenerateCode() {
502505
// TODO(turbofan): Currently everything is done in the first phase.
503506
if (!info()->code().is_null()) {
504507
info()->dependencies()->Commit(info()->code());
505-
if (FLAG_turbo_deoptimization) {
508+
if (info()->is_deoptimization_enabled()) {
506509
info()->parse_info()->context()->native_context()->AddOptimizedCode(
507510
*info()->code());
508511
}
@@ -848,7 +851,7 @@ MaybeHandle<Code> Compiler::GetLazyCode(Handle<JSFunction> function) {
848851
// If the debugger is active, do not compile with turbofan unless we can
849852
// deopt from turbofan code.
850853
if (FLAG_turbo_asm && function->shared()->asm_function() &&
851-
(FLAG_turbo_deoptimization || !isolate->debug()->is_active()) &&
854+
(FLAG_turbo_asm_deoptimization || !isolate->debug()->is_active()) &&
852855
!FLAG_turbo_osr) {
853856
CompilationInfoWithZone info(function);
854857

src/compiler/js-inlining.cc

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ Reduction JSInliner::Reduce(Node* node) {
302302
Zone zone;
303303
ParseInfo parse_info(&zone, function);
304304
CompilationInfo info(&parse_info);
305+
if (info_->is_deoptimization_enabled()) info.MarkAsDeoptimizationEnabled();
305306

306307
if (!Compiler::ParseAndAnalyze(info.parse_info())) return NoChange();
307308
if (!Compiler::EnsureDeoptimizationSupport(&info)) return NoChange();

src/debug.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,8 @@ void Debug::PrepareForBreakPoints() {
18821882
if (kind == Code::OPTIMIZED_FUNCTION) {
18831883
// Optimized code can only get here if DeoptimizeAll did not
18841884
// deoptimize turbo fan code.
1885-
DCHECK(!FLAG_turbo_deoptimization);
1885+
DCHECK(!FLAG_turbo_asm_deoptimization);
1886+
DCHECK(function->shared()->asm_function());
18861887
DCHECK(function->code()->is_turbofanned());
18871888
function->ReplaceCode(fallback);
18881889
}

src/deoptimizer.cc

+10-11
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ void Deoptimizer::DeoptimizeMarkedCodeForContext(Context* context) {
342342
StackFrame::Type type = it.frame()->type();
343343
if (type == StackFrame::OPTIMIZED) {
344344
Code* code = it.frame()->LookupCode();
345+
JSFunction* function =
346+
static_cast<OptimizedFrame*>(it.frame())->function();
345347
if (FLAG_trace_deopt) {
346-
JSFunction* function =
347-
static_cast<OptimizedFrame*>(it.frame())->function();
348348
CodeTracer::Scope scope(isolate->GetCodeTracer());
349349
PrintF(scope.file(), "[deoptimizer found activation of function: ");
350350
function->PrintName(scope.file());
@@ -354,7 +354,9 @@ void Deoptimizer::DeoptimizeMarkedCodeForContext(Context* context) {
354354
SafepointEntry safepoint = code->GetSafepointEntry(it.frame()->pc());
355355
int deopt_index = safepoint.deoptimization_index();
356356
// Turbofan deopt is checked when we are patching addresses on stack.
357-
bool turbofanned = code->is_turbofanned() && !FLAG_turbo_deoptimization;
357+
bool turbofanned = code->is_turbofanned() &&
358+
function->shared()->asm_function() &&
359+
!FLAG_turbo_asm_deoptimization;
358360
bool safe_to_deopt =
359361
deopt_index != Safepoint::kNoDeoptimizationIndex || turbofanned;
360362
CHECK(topmost_optimized_code == NULL || safe_to_deopt || turbofanned);
@@ -380,7 +382,6 @@ void Deoptimizer::DeoptimizeMarkedCodeForContext(Context* context) {
380382
Object* next = code->next_code_link();
381383

382384
if (code->marked_for_deoptimization()) {
383-
DCHECK(!code->is_turbofanned() || FLAG_turbo_deoptimization);
384385
// Put the code into the list for later patching.
385386
codes.Add(code, &zone);
386387

@@ -423,14 +424,12 @@ void Deoptimizer::DeoptimizeMarkedCodeForContext(Context* context) {
423424
shared->EvictFromOptimizedCodeMap(codes[i], "deoptimized code");
424425

425426
// Do platform-specific patching to force any activations to lazy deopt.
426-
if (!codes[i]->is_turbofanned() || FLAG_turbo_deoptimization) {
427-
PatchCodeForDeoptimization(isolate, codes[i]);
427+
PatchCodeForDeoptimization(isolate, codes[i]);
428428

429-
// We might be in the middle of incremental marking with compaction.
430-
// Tell collector to treat this code object in a special way and
431-
// ignore all slots that might have been recorded on it.
432-
isolate->heap()->mark_compact_collector()->InvalidateCode(codes[i]);
433-
}
429+
// We might be in the middle of incremental marking with compaction.
430+
// Tell collector to treat this code object in a special way and
431+
// ignore all slots that might have been recorded on it.
432+
isolate->heap()->mark_compact_collector()->InvalidateCode(codes[i]);
434433
}
435434
}
436435

src/flag-definitions.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ DEFINE_BOOL(omit_map_checks_for_leaf_maps, true,
384384
// Flags for TurboFan.
385385
DEFINE_BOOL(turbo, false, "enable TurboFan compiler")
386386
DEFINE_BOOL(turbo_greedy_regalloc, false, "use the greedy register allocator")
387-
DEFINE_IMPLICATION(turbo, turbo_deoptimization)
387+
DEFINE_IMPLICATION(turbo, turbo_asm_deoptimization)
388388
DEFINE_STRING(turbo_filter, "~~", "optimization filter for TurboFan compiler")
389389
DEFINE_BOOL(trace_turbo, false, "trace generated TurboFan IR")
390390
DEFINE_BOOL(trace_turbo_graph, false, "trace generated TurboFan graphs")
@@ -397,6 +397,8 @@ DEFINE_BOOL(trace_turbo_reduction, false, "trace TurboFan's various reducers")
397397
DEFINE_BOOL(trace_turbo_jt, false, "trace TurboFan's jump threading")
398398
DEFINE_BOOL(trace_turbo_ceq, false, "trace TurboFan's control equivalence")
399399
DEFINE_BOOL(turbo_asm, true, "enable TurboFan for asm.js code")
400+
DEFINE_BOOL(turbo_asm_deoptimization, false,
401+
"enable deoptimization in TurboFan for asm.js code")
400402
DEFINE_BOOL(turbo_verify, DEBUG_BOOL, "verify TurboFan graphs at each phase")
401403
DEFINE_BOOL(turbo_stats, false, "print TurboFan statistics")
402404
DEFINE_BOOL(turbo_splitting, true, "split nodes during scheduling in TurboFan")
@@ -408,7 +410,6 @@ DEFINE_BOOL(turbo_source_positions, false,
408410
DEFINE_IMPLICATION(trace_turbo, turbo_source_positions)
409411
DEFINE_BOOL(context_specialization, false,
410412
"enable context specialization in TurboFan")
411-
DEFINE_BOOL(turbo_deoptimization, false, "enable deoptimization in TurboFan")
412413
DEFINE_BOOL(turbo_inlining, false, "enable inlining in TurboFan")
413414
DEFINE_BOOL(trace_turbo_inlining, false, "trace TurboFan inlining")
414415
DEFINE_BOOL(loop_assignment_analysis, true, "perform loop assignment analysis")

src/frames.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,8 @@ void OptimizedFrame::Summarize(List<FrameSummary>* frames) {
879879

880880
// Delegate to JS frame in absence of turbofan deoptimization.
881881
// TODO(turbofan): Revisit once we support deoptimization across the board.
882-
if (LookupCode()->is_turbofanned() && !FLAG_turbo_deoptimization) {
882+
if (LookupCode()->is_turbofanned() && function()->shared()->asm_function() &&
883+
!FLAG_turbo_asm_deoptimization) {
883884
return JavaScriptFrame::Summarize(frames);
884885
}
885886

@@ -1016,7 +1017,8 @@ int OptimizedFrame::GetInlineCount() {
10161017

10171018
// Delegate to JS frame in absence of turbofan deoptimization.
10181019
// TODO(turbofan): Revisit once we support deoptimization across the board.
1019-
if (LookupCode()->is_turbofanned() && !FLAG_turbo_deoptimization) {
1020+
if (LookupCode()->is_turbofanned() && function()->shared()->asm_function() &&
1021+
!FLAG_turbo_asm_deoptimization) {
10201022
return JavaScriptFrame::GetInlineCount();
10211023
}
10221024

@@ -1040,7 +1042,8 @@ void OptimizedFrame::GetFunctions(List<JSFunction*>* functions) {
10401042

10411043
// Delegate to JS frame in absence of turbofan deoptimization.
10421044
// TODO(turbofan): Revisit once we support deoptimization across the board.
1043-
if (LookupCode()->is_turbofanned() && !FLAG_turbo_deoptimization) {
1045+
if (LookupCode()->is_turbofanned() && function()->shared()->asm_function() &&
1046+
!FLAG_turbo_asm_deoptimization) {
10441047
return JavaScriptFrame::GetFunctions(functions);
10451048
}
10461049

src/objects.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -12505,8 +12505,7 @@ bool DependentCode::MarkCodeForDeoptimization(
1250512505
WeakCell* cell = WeakCell::cast(obj);
1250612506
if (cell->cleared()) continue;
1250712507
Code* code = Code::cast(cell->value());
12508-
if (!code->marked_for_deoptimization() &&
12509-
(!code->is_turbofanned() || FLAG_turbo_deoptimization)) {
12508+
if (!code->marked_for_deoptimization()) {
1251012509
SetMarkedForDeoptimization(code, group);
1251112510
if (invalidate_embedded_objects) {
1251212511
code->InvalidateEmbeddedObjects();

src/runtime/runtime-debug.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,9 @@ class FrameInspector {
476476
// Calculate the deoptimized frame.
477477
if (frame->is_optimized()) {
478478
// TODO(turbofan): Revisit once we support deoptimization.
479-
if (frame->LookupCode()->is_turbofanned() && !FLAG_turbo_deoptimization) {
479+
if (frame->LookupCode()->is_turbofanned() &&
480+
frame->function()->shared()->asm_function() &&
481+
!FLAG_turbo_asm_deoptimization) {
480482
is_optimized_ = false;
481483
return;
482484
}
@@ -508,7 +510,9 @@ class FrameInspector {
508510
}
509511
Object* GetExpression(int index) {
510512
// TODO(turbofan): Revisit once we support deoptimization.
511-
if (frame_->LookupCode()->is_turbofanned() && !FLAG_turbo_deoptimization) {
513+
if (frame_->LookupCode()->is_turbofanned() &&
514+
frame_->function()->shared()->asm_function() &&
515+
!FLAG_turbo_asm_deoptimization) {
512516
return isolate_->heap()->undefined_value();
513517
}
514518
return is_optimized_ ? deoptimized_frame_->GetExpression(index)

src/runtime/runtime-test.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ RUNTIME_FUNCTION(Runtime_DeoptimizeFunction) {
2020
if (!function->IsOptimized()) return isolate->heap()->undefined_value();
2121

2222
// TODO(turbofan): Deoptimization is not supported yet.
23-
if (function->code()->is_turbofanned() && !FLAG_turbo_deoptimization) {
23+
if (function->code()->is_turbofanned() &&
24+
function->shared()->asm_function() && !FLAG_turbo_asm_deoptimization) {
2425
return isolate->heap()->undefined_value();
2526
}
2627

@@ -50,7 +51,8 @@ RUNTIME_FUNCTION(Runtime_DeoptimizeNow) {
5051
if (!function->IsOptimized()) return isolate->heap()->undefined_value();
5152

5253
// TODO(turbofan): Deoptimization is not supported yet.
53-
if (function->code()->is_turbofanned() && !FLAG_turbo_deoptimization) {
54+
if (function->code()->is_turbofanned() &&
55+
function->shared()->asm_function() && !FLAG_turbo_asm_deoptimization) {
5456
return isolate->heap()->undefined_value();
5557
}
5658

test/cctest/compiler/function-tester.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class FunctionTester : public InitializedHandleScope {
160160
Zone zone;
161161
ParseInfo parse_info(&zone, function);
162162
CompilationInfo info(&parse_info);
163+
info.MarkAsDeoptimizationEnabled();
163164

164165
CHECK(Parser::ParseStatic(info.parse_info()));
165166
info.SetOptimizing(BailoutId::None(), Handle<Code>(function->code()));
@@ -177,11 +178,8 @@ class FunctionTester : public InitializedHandleScope {
177178

178179
Pipeline pipeline(&info);
179180
Handle<Code> code = pipeline.GenerateCode();
180-
if (FLAG_turbo_deoptimization) {
181-
info.context()->native_context()->AddOptimizedCode(*code);
182-
}
183-
184181
CHECK(!code.is_null());
182+
info.context()->native_context()->AddOptimizedCode(*code);
185183
function->ReplaceCode(*code);
186184
#elif USE_CRANKSHAFT
187185
Handle<Code> unoptimized = Handle<Code>(function->code());

test/cctest/compiler/test-codegen-deopt.cc

-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ TEST(TurboTrivialDeoptCodegen) {
169169
InitializedHandleScope handles;
170170

171171
FLAG_allow_natives_syntax = true;
172-
FLAG_turbo_deoptimization = true;
173172

174173
TrivialDeoptCodegenTester t(&scope);
175174
t.GenerateCode();
@@ -190,7 +189,6 @@ TEST(TurboTrivialDeoptCodegenAndRun) {
190189
InitializedHandleScope handles;
191190

192191
FLAG_allow_natives_syntax = true;
193-
FLAG_turbo_deoptimization = true;
194192

195193
TrivialDeoptCodegenTester t(&scope);
196194
t.GenerateCode();
@@ -282,7 +280,6 @@ TEST(TurboTrivialRuntimeDeoptCodegenAndRun) {
282280
InitializedHandleScope handles;
283281

284282
FLAG_allow_natives_syntax = true;
285-
FLAG_turbo_deoptimization = true;
286283

287284
TrivialRuntimeDeoptCodegenTester t(&scope);
288285
t.GenerateCode();

test/cctest/compiler/test-js-typed-lowering.cc

+7-20
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,6 @@ TEST_WITH_STRONG(MixedComparison1) {
713713

714714

715715
TEST_WITH_STRONG(RemoveToNumberEffects) {
716-
FLAG_turbo_deoptimization = true;
717-
718716
JSTypedLoweringTester R;
719717

720718
Node* effect_use = NULL;
@@ -726,27 +724,16 @@ TEST_WITH_STRONG(RemoveToNumberEffects) {
726724

727725
switch (i) {
728726
case 0:
729-
if (FLAG_turbo_deoptimization) {
730-
DCHECK(OperatorProperties::GetFrameStateInputCount(
731-
R.javascript.ToNumber()) == 1);
732-
effect_use = R.graph.NewNode(R.javascript.ToNumber(), p0, R.context(),
733-
frame_state, ton, R.start());
734-
} else {
727+
DCHECK(OperatorProperties::GetFrameStateInputCount(
728+
R.javascript.ToNumber()) == 1);
735729
effect_use = R.graph.NewNode(R.javascript.ToNumber(), p0, R.context(),
736-
ton, R.start());
737-
}
730+
frame_state, ton, R.start());
738731
break;
739732
case 1:
740-
if (FLAG_turbo_deoptimization) {
741-
DCHECK(OperatorProperties::GetFrameStateInputCount(
742-
R.javascript.ToNumber()) == 1);
743-
effect_use =
744-
R.graph.NewNode(R.javascript.ToNumber(), ton, R.context(),
745-
frame_state, ton, R.start());
746-
} else {
747-
effect_use = R.graph.NewNode(R.javascript.ToNumber(), ton,
748-
R.context(), ton, R.start());
749-
}
733+
DCHECK(OperatorProperties::GetFrameStateInputCount(
734+
R.javascript.ToNumber()) == 1);
735+
effect_use = R.graph.NewNode(R.javascript.ToNumber(), ton, R.context(),
736+
frame_state, ton, R.start());
750737
break;
751738
case 2:
752739
effect_use = R.graph.NewNode(R.common.EffectPhi(1), ton, R.start());

test/cctest/compiler/test-run-deopt.cc

-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ static void InstallIsOptimizedHelper(v8::Isolate* isolate) {
2929

3030
TEST(TurboSimpleDeopt) {
3131
FLAG_allow_natives_syntax = true;
32-
FLAG_turbo_deoptimization = true;
3332

3433
FunctionTester T(
3534
"(function f(a) {"
@@ -46,7 +45,6 @@ TEST(TurboSimpleDeopt) {
4645

4746
TEST(TurboSimpleDeoptInExpr) {
4847
FLAG_allow_natives_syntax = true;
49-
FLAG_turbo_deoptimization = true;
5048

5149
FunctionTester T(
5250
"(function f(a) {"
@@ -65,7 +63,6 @@ TEST(TurboSimpleDeoptInExpr) {
6563

6664
TEST(TurboTrivialDeopt) {
6765
FLAG_allow_natives_syntax = true;
68-
FLAG_turbo_deoptimization = true;
6966

7067
FunctionTester T(
7168
"(function foo() {"

0 commit comments

Comments
 (0)