[vm/try_catch] Use same catch_entry parameter mechanism in JIT as in AOT.
This simplifies VM, enables further try-catch refactoring.
TEST=ci
Change-Id: Iff80e154f457ac7397a3b73dcf2b32cda2a2af2c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395344
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
diff --git a/runtime/vm/compiler/backend/flow_graph_compiler.cc b/runtime/vm/compiler/backend/flow_graph_compiler.cc
index 0e07ec7..91a091e 100644
--- a/runtime/vm/compiler/backend/flow_graph_compiler.cc
+++ b/runtime/vm/compiler/backend/flow_graph_compiler.cc
@@ -214,9 +214,7 @@
zone(), &code_source_map_builder_->inline_id_to_function());
exception_handlers_list_ =
new (zone()) ExceptionHandlerList(parsed_function().function());
-#if defined(DART_PRECOMPILER)
catch_entry_moves_maps_builder_ = new (zone()) CatchEntryMovesMapBuilder();
-#endif
block_info_.Clear();
// Initialize block info and search optimized (non-OSR) code for calls
// indicating a non-leaf routine and calls without IC data indicating
@@ -352,7 +350,6 @@
block_info->set_next_nonempty_label(nonempty_label);
}
-#if defined(DART_PRECOMPILER)
static intptr_t LocationToStackIndex(const Location& src) {
ASSERT(src.HasStackIndex());
return -compiler::target::frame_layout.VariableIndexForFrameSlot(
@@ -422,10 +419,8 @@
return CatchEntryMove::FromSlot(src_kind, LocationToStackIndex(src),
dst_index);
}
-#endif
void FlowGraphCompiler::RecordCatchEntryMoves(Environment* env) {
-#if defined(DART_PRECOMPILER)
const intptr_t try_index = CurrentTryIndex();
if (is_optimizing() && env != nullptr && (try_index != kInvalidTryIndex)) {
env = env->Outermost();
@@ -463,7 +458,6 @@
catch_entry_moves_maps_builder_->EndMapping();
}
-#endif // defined(DART_PRECOMPILER)
}
void FlowGraphCompiler::EmitCallsiteMetadata(const InstructionSource& source,
@@ -1363,15 +1357,9 @@
}
void FlowGraphCompiler::FinalizeCatchEntryMovesMap(const Code& code) {
-#if defined(DART_PRECOMPILER)
- if (FLAG_precompiled_mode) {
- TypedData& maps = TypedData::Handle(
- catch_entry_moves_maps_builder_->FinalizeCatchEntryMovesMap());
- code.set_catch_entry_moves_maps(maps);
- return;
- }
-#endif
- code.set_num_variables(flow_graph().variable_count());
+ TypedData& maps = TypedData::Handle(
+ catch_entry_moves_maps_builder_->FinalizeCatchEntryMovesMap());
+ code.set_catch_entry_moves_maps(maps);
}
void FlowGraphCompiler::FinalizeStaticCallTargetsTable(const Code& code) {
@@ -3131,18 +3119,18 @@
(compiler->CurrentTryIndex() != kInvalidTryIndex)) {
Environment* env =
compiler->SlowPathEnvironmentFor(instruction(), num_args);
- // TODO(47044): Should be able to say `FLAG_precompiled_mode` instead.
- if (CompilerState::Current().is_aot()) {
- compiler->RecordCatchEntryMoves(env);
- } else if (compiler->is_optimizing()) {
- ASSERT(env != nullptr);
- compiler->AddSlowPathDeoptInfo(deopt_id, env);
- } else {
- ASSERT(env == nullptr);
- const intptr_t deopt_id_after = DeoptId::ToDeoptAfter(deopt_id);
- // Add deoptimization continuation point.
- compiler->AddCurrentDescriptor(UntaggedPcDescriptors::kDeopt,
- deopt_id_after, instruction()->source());
+ compiler->RecordCatchEntryMoves(env);
+ if (!CompilerState::Current().is_aot()) {
+ if (compiler->is_optimizing()) {
+ ASSERT(env != nullptr);
+ compiler->AddSlowPathDeoptInfo(deopt_id, env);
+ } else {
+ ASSERT(env == nullptr);
+ const intptr_t deopt_id_after = DeoptId::ToDeoptAfter(deopt_id);
+ // Add deoptimization continuation point.
+ compiler->AddCurrentDescriptor(UntaggedPcDescriptors::kDeopt,
+ deopt_id_after, instruction()->source());
+ }
}
}
if (!use_shared_stub) {
diff --git a/runtime/vm/exceptions.cc b/runtime/vm/exceptions.cc
index 3e44171..16d7740 100644
--- a/runtime/vm/exceptions.cc
+++ b/runtime/vm/exceptions.cc
@@ -172,21 +172,7 @@
cached_catch_entry_moves_ = *cached_catch_entry_moves;
}
if (cached_catch_entry_moves_.IsEmpty()) {
-#if defined(DART_PRECOMPILED_RUNTIME)
- // Only AOT mode is supported.
ReadCompressedCatchEntryMoves();
-#elif defined(DART_PRECOMPILER)
- // Both AOT and JIT modes are supported.
- if (FLAG_precompiled_mode) {
- ReadCompressedCatchEntryMoves();
- } else {
- GetCatchEntryMovesFromDeopt(code_->num_variables(), frame);
- }
-#else
- // Only JIT mode is supported.
- ASSERT(!FLAG_precompiled_mode);
- GetCatchEntryMovesFromDeopt(code_->num_variables(), frame);
-#endif
}
}
}
@@ -321,7 +307,6 @@
}
}
-#if defined(DART_PRECOMPILED_RUNTIME) || defined(DART_PRECOMPILER)
void ReadCompressedCatchEntryMoves() {
const intptr_t pc_offset = pc_ - code_->PayloadStart();
const auto& td = TypedData::Handle(code_->catch_entry_moves_maps());
@@ -329,22 +314,6 @@
CatchEntryMovesMapReader reader(td);
catch_entry_moves_ = reader.ReadMovesForPcOffset(pc_offset);
}
-#endif // defined(DART_PRECOMPILED_RUNTIME) || defined(DART_PRECOMPILER)
-
-#if !defined(DART_PRECOMPILED_RUNTIME)
- void GetCatchEntryMovesFromDeopt(intptr_t num_vars, StackFrame* frame) {
- Isolate* isolate = thread_->isolate();
- DeoptContext* deopt_context =
- new DeoptContext(frame, *code_, DeoptContext::kDestIsAllocated, nullptr,
- nullptr, true, false /* deoptimizing_code */);
- isolate->set_deopt_context(deopt_context);
-
- catch_entry_moves_ = deopt_context->ToCatchEntryMoves(num_vars);
-
- isolate->set_deopt_context(nullptr);
- delete deopt_context;
- }
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
bool needs_stacktrace;
uword handler_pc;
@@ -381,13 +350,11 @@
return CatchEntryMove(src, dest_and_kind);
}
-#if !defined(DART_PRECOMPILED_RUNTIME)
void CatchEntryMove::WriteTo(BaseWriteStream* stream) {
using Writer = BaseWriteStream::Raw<sizeof(int32_t), int32_t>;
Writer::Write(stream, src_);
Writer::Write(stream, dest_and_kind_);
}
-#endif
#if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER)
static intptr_t SlotIndexToFrameIndex(intptr_t slot) {
diff --git a/runtime/vm/exceptions.h b/runtime/vm/exceptions.h
index c41c710..3251533 100644
--- a/runtime/vm/exceptions.h
+++ b/runtime/vm/exceptions.h
@@ -216,9 +216,7 @@
static CatchEntryMove ReadFrom(ReadStream* stream);
-#if !defined(DART_PRECOMPILED_RUNTIME)
void WriteTo(BaseWriteStream* stream);
-#endif
#if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER)
const char* ToCString() const;
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index b818bbc..f561f85 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -18002,16 +18002,12 @@
}
#endif
-#if defined(DART_PRECOMPILED_RUNTIME) || defined(DART_PRECOMPILER)
TypedDataPtr Code::catch_entry_moves_maps() const {
- ASSERT(FLAG_precompiled_mode);
return TypedData::RawCast(untag()->catch_entry());
}
void Code::set_catch_entry_moves_maps(const TypedData& maps) const {
- ASSERT(FLAG_precompiled_mode);
untag()->set_catch_entry(maps.ptr());
}
-#endif
void Code::set_deopt_info_array(const Array& array) const {
#if defined(DART_PRECOMPILED_RUNTIME)
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index dad3244..3b629cb 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -6956,10 +6956,8 @@
void set_num_variables(intptr_t num_variables) const;
#endif
-#if defined(DART_PRECOMPILED_RUNTIME) || defined(DART_PRECOMPILER)
TypedDataPtr catch_entry_moves_maps() const;
void set_catch_entry_moves_maps(const TypedData& maps) const;
-#endif
CompressedStackMapsPtr compressed_stackmaps() const {
return untag()->compressed_stackmaps();