diff --git a/runtime/vm/compiler/aot/precompiler.cc b/runtime/vm/compiler/aot/precompiler.cc index e3b3919a935..12d2c6ab957 100644 --- a/runtime/vm/compiler/aot/precompiler.cc +++ b/runtime/vm/compiler/aot/precompiler.cc @@ -2832,8 +2832,7 @@ bool PrecompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) { true, FLAG_max_speculative_inlining_attempts); while (!done) { - const intptr_t prev_deopt_id = thread()->deopt_id(); - thread()->set_deopt_id(0); + DeoptIdScope deopt_id_scope(thread(), 0); LongJumpScope jump; const intptr_t val = setjmp(*jump.Set()); if (val == 0) { @@ -2979,8 +2978,6 @@ bool PrecompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) { } is_compiled = false; } - // Reset global isolate state. - thread()->set_deopt_id(prev_deopt_id); } return is_compiled; } diff --git a/runtime/vm/compiler/backend/il.h b/runtime/vm/compiler/backend/il.h index 713fff7a1b0..2d92fc3adf7 100644 --- a/runtime/vm/compiler/backend/il.h +++ b/runtime/vm/compiler/backend/il.h @@ -755,6 +755,21 @@ class CallTargets : public Cids { void MergeIntoRanges(); }; +class DeoptIdScope : public StackResource { + public: + DeoptIdScope(Thread* thread, intptr_t deopt_id) + : StackResource(thread), prev_deopt_id_(thread->deopt_id()) { + thread->set_deopt_id(deopt_id); + } + + ~DeoptIdScope() { thread()->set_deopt_id(prev_deopt_id_); } + + private: + const intptr_t prev_deopt_id_; + + DISALLOW_COPY_AND_ASSIGN(DeoptIdScope); +}; + class Instruction : public ZoneAllocated { public: #define DECLARE_TAG(type, attrs) k##type, diff --git a/runtime/vm/compiler/backend/inliner.cc b/runtime/vm/compiler/backend/inliner.cc index b8afe45b01d..3fa4cf291ca 100644 --- a/runtime/vm/compiler/backend/inliner.cc +++ b/runtime/vm/compiler/backend/inliner.cc @@ -908,11 +908,11 @@ class CallSiteInliner : public ValueObject { return false; } - // Save and clear deopt id. - const intptr_t prev_deopt_id = thread()->deopt_id(); - thread()->set_deopt_id(0); Error& error = Error::Handle(); { + // Save and clear deopt id. + DeoptIdScope deopt_id_scope(thread(), 0); + // Install bailout jump. LongJumpScope jump; if (setjmp(*jump.Set()) == 0) { @@ -1162,7 +1162,6 @@ class CallSiteInliner : public ValueObject { (size > FLAG_inlining_constant_arguments_max_size_threshold)) { function.set_is_inlinable(false); } - thread()->set_deopt_id(prev_deopt_id); TRACE_INLINING( THR_Print(" Bailout: heuristics (%s) with " "code size: %" Pd ", " @@ -1193,7 +1192,6 @@ class CallSiteInliner : public ValueObject { if (is_recursive_call) { inlined_recursive_call_ = true; } - thread()->set_deopt_id(prev_deopt_id); call_data->callee_graph = callee_graph; call_data->parameter_stubs = param_stubs; @@ -1233,7 +1231,6 @@ class CallSiteInliner : public ValueObject { if (error.raw() == Object::background_compilation_error().raw()) { // Fall through to exit the compilation, and retry it later. } else { - thread()->set_deopt_id(prev_deopt_id); TRACE_INLINING( THR_Print(" Bailout: %s\n", error.ToErrorCString())); PRINT_INLINING_TREE("Bailout", &call_data->caller, &function, call); diff --git a/runtime/vm/compiler/jit/compiler.cc b/runtime/vm/compiler/jit/compiler.cc index 6adc6fa4ecf..0b50636c272 100644 --- a/runtime/vm/compiler/jit/compiler.cc +++ b/runtime/vm/compiler/jit/compiler.cc @@ -788,8 +788,7 @@ RawCode* CompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) { Code* volatile result = &Code::ZoneHandle(zone); while (!done) { *result = Code::null(); - const intptr_t prev_deopt_id = thread()->deopt_id(); - thread()->set_deopt_id(0); + DeoptIdScope deopt_id_scope(thread(), 0); LongJumpScope jump; if (setjmp(*jump.Set()) == 0) { FlowGraph* flow_graph = nullptr; @@ -847,9 +846,6 @@ RawCode* CompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) { #if defined(DART_USE_INTERPRETER) // TODO(regis): Revisit. if (flow_graph == NULL && function.HasBytecode()) { - // Reset global isolate state. - thread()->set_deopt_id(prev_deopt_id); - return Code::null(); } #endif @@ -971,8 +967,6 @@ RawCode* CompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) { thread()->clear_sticky_error(); } } - // Reset global isolate state. - thread()->set_deopt_id(prev_deopt_id); } return result->raw(); } @@ -1369,8 +1363,7 @@ void Compiler::ComputeLocalVarDescriptors(const Code& code) { ASSERT(!function.IsIrregexpFunction()); // In background compilation, parser can produce 'errors": bailouts // if state changed while compiling in background. - const intptr_t prev_deopt_id = Thread::Current()->deopt_id(); - Thread::Current()->set_deopt_id(0); + DeoptIdScope deopt_id_scope(Thread::Current(), 0); LongJumpScope jump; if (setjmp(*jump.Set()) == 0) { ZoneGrowableArray* ic_data_array = @@ -1402,7 +1395,6 @@ void Compiler::ComputeLocalVarDescriptors(const Code& code) { // Only possible with background compilation. ASSERT(Compiler::IsBackgroundCompilation()); } - Thread::Current()->set_deopt_id(prev_deopt_id); } RawError* Compiler::CompileAllFunctions(const Class& cls) {