[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>
This commit is contained in:
Alexander Aprelev
2024-11-15 16:46:03 +00:00
committed by Commit Queue
parent 9c24301f5b
commit eca32d78e4
5 changed files with 15 additions and 68 deletions
@@ -214,9 +214,7 @@ void FlowGraphCompiler::InitCompiler() {
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 @@ void FlowGraphCompiler::CompactBlocks() {
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 @@ static CatchEntryMove CatchEntryMoveFor(compiler::Assembler* assembler,
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 @@ void FlowGraphCompiler::RecordCatchEntryMoves(Environment* env) {
catch_entry_moves_maps_builder_->EndMapping();
}
#endif // defined(DART_PRECOMPILER)
}
void FlowGraphCompiler::EmitCallsiteMetadata(const InstructionSource& source,
@@ -1363,15 +1357,9 @@ void FlowGraphCompiler::FinalizeVarDescriptors(const Code& code) {
}
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 @@ void ThrowErrorSlowPathCode::EmitNativeCode(FlowGraphCompiler* compiler) {
(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) {
-33
View File
@@ -172,21 +172,7 @@ class ExceptionHandlerFinder : public StackResource {
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 @@ class ExceptionHandlerFinder : public StackResource {
}
}
#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 @@ class ExceptionHandlerFinder : public StackResource {
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 @@ CatchEntryMove CatchEntryMove::ReadFrom(ReadStream* stream) {
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) {
-2
View File
@@ -216,9 +216,7 @@ class CatchEntryMove {
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;
-4
View File
@@ -18002,16 +18002,12 @@ void Code::set_num_variables(intptr_t num_variables) const {
}
#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)
-2
View File
@@ -6956,10 +6956,8 @@ class Code : public Object {
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();