Skip to content

Commit eca32d7

Browse files
aamCommit Queue
authored andcommitted
[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 <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent 9c24301 commit eca32d7

File tree

5 files changed

+15
-68
lines changed

5 files changed

+15
-68
lines changed

runtime/vm/compiler/backend/flow_graph_compiler.cc

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,7 @@ void FlowGraphCompiler::InitCompiler() {
214214
zone(), &code_source_map_builder_->inline_id_to_function());
215215
exception_handlers_list_ =
216216
new (zone()) ExceptionHandlerList(parsed_function().function());
217-
#if defined(DART_PRECOMPILER)
218217
catch_entry_moves_maps_builder_ = new (zone()) CatchEntryMovesMapBuilder();
219-
#endif
220218
block_info_.Clear();
221219
// Initialize block info and search optimized (non-OSR) code for calls
222220
// indicating a non-leaf routine and calls without IC data indicating
@@ -352,7 +350,6 @@ void FlowGraphCompiler::CompactBlocks() {
352350
block_info->set_next_nonempty_label(nonempty_label);
353351
}
354352

355-
#if defined(DART_PRECOMPILER)
356353
static intptr_t LocationToStackIndex(const Location& src) {
357354
ASSERT(src.HasStackIndex());
358355
return -compiler::target::frame_layout.VariableIndexForFrameSlot(
@@ -422,10 +419,8 @@ static CatchEntryMove CatchEntryMoveFor(compiler::Assembler* assembler,
422419
return CatchEntryMove::FromSlot(src_kind, LocationToStackIndex(src),
423420
dst_index);
424421
}
425-
#endif
426422

427423
void FlowGraphCompiler::RecordCatchEntryMoves(Environment* env) {
428-
#if defined(DART_PRECOMPILER)
429424
const intptr_t try_index = CurrentTryIndex();
430425
if (is_optimizing() && env != nullptr && (try_index != kInvalidTryIndex)) {
431426
env = env->Outermost();
@@ -463,7 +458,6 @@ void FlowGraphCompiler::RecordCatchEntryMoves(Environment* env) {
463458

464459
catch_entry_moves_maps_builder_->EndMapping();
465460
}
466-
#endif // defined(DART_PRECOMPILER)
467461
}
468462

469463
void FlowGraphCompiler::EmitCallsiteMetadata(const InstructionSource& source,
@@ -1363,15 +1357,9 @@ void FlowGraphCompiler::FinalizeVarDescriptors(const Code& code) {
13631357
}
13641358

13651359
void FlowGraphCompiler::FinalizeCatchEntryMovesMap(const Code& code) {
1366-
#if defined(DART_PRECOMPILER)
1367-
if (FLAG_precompiled_mode) {
1368-
TypedData& maps = TypedData::Handle(
1369-
catch_entry_moves_maps_builder_->FinalizeCatchEntryMovesMap());
1370-
code.set_catch_entry_moves_maps(maps);
1371-
return;
1372-
}
1373-
#endif
1374-
code.set_num_variables(flow_graph().variable_count());
1360+
TypedData& maps = TypedData::Handle(
1361+
catch_entry_moves_maps_builder_->FinalizeCatchEntryMovesMap());
1362+
code.set_catch_entry_moves_maps(maps);
13751363
}
13761364

13771365
void FlowGraphCompiler::FinalizeStaticCallTargetsTable(const Code& code) {
@@ -3131,18 +3119,18 @@ void ThrowErrorSlowPathCode::EmitNativeCode(FlowGraphCompiler* compiler) {
31313119
(compiler->CurrentTryIndex() != kInvalidTryIndex)) {
31323120
Environment* env =
31333121
compiler->SlowPathEnvironmentFor(instruction(), num_args);
3134-
// TODO(47044): Should be able to say `FLAG_precompiled_mode` instead.
3135-
if (CompilerState::Current().is_aot()) {
3136-
compiler->RecordCatchEntryMoves(env);
3137-
} else if (compiler->is_optimizing()) {
3138-
ASSERT(env != nullptr);
3139-
compiler->AddSlowPathDeoptInfo(deopt_id, env);
3140-
} else {
3141-
ASSERT(env == nullptr);
3142-
const intptr_t deopt_id_after = DeoptId::ToDeoptAfter(deopt_id);
3143-
// Add deoptimization continuation point.
3144-
compiler->AddCurrentDescriptor(UntaggedPcDescriptors::kDeopt,
3145-
deopt_id_after, instruction()->source());
3122+
compiler->RecordCatchEntryMoves(env);
3123+
if (!CompilerState::Current().is_aot()) {
3124+
if (compiler->is_optimizing()) {
3125+
ASSERT(env != nullptr);
3126+
compiler->AddSlowPathDeoptInfo(deopt_id, env);
3127+
} else {
3128+
ASSERT(env == nullptr);
3129+
const intptr_t deopt_id_after = DeoptId::ToDeoptAfter(deopt_id);
3130+
// Add deoptimization continuation point.
3131+
compiler->AddCurrentDescriptor(UntaggedPcDescriptors::kDeopt,
3132+
deopt_id_after, instruction()->source());
3133+
}
31463134
}
31473135
}
31483136
if (!use_shared_stub) {

runtime/vm/exceptions.cc

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,7 @@ class ExceptionHandlerFinder : public StackResource {
172172
cached_catch_entry_moves_ = *cached_catch_entry_moves;
173173
}
174174
if (cached_catch_entry_moves_.IsEmpty()) {
175-
#if defined(DART_PRECOMPILED_RUNTIME)
176-
// Only AOT mode is supported.
177175
ReadCompressedCatchEntryMoves();
178-
#elif defined(DART_PRECOMPILER)
179-
// Both AOT and JIT modes are supported.
180-
if (FLAG_precompiled_mode) {
181-
ReadCompressedCatchEntryMoves();
182-
} else {
183-
GetCatchEntryMovesFromDeopt(code_->num_variables(), frame);
184-
}
185-
#else
186-
// Only JIT mode is supported.
187-
ASSERT(!FLAG_precompiled_mode);
188-
GetCatchEntryMovesFromDeopt(code_->num_variables(), frame);
189-
#endif
190176
}
191177
}
192178
}
@@ -321,30 +307,13 @@ class ExceptionHandlerFinder : public StackResource {
321307
}
322308
}
323309

324-
#if defined(DART_PRECOMPILED_RUNTIME) || defined(DART_PRECOMPILER)
325310
void ReadCompressedCatchEntryMoves() {
326311
const intptr_t pc_offset = pc_ - code_->PayloadStart();
327312
const auto& td = TypedData::Handle(code_->catch_entry_moves_maps());
328313

329314
CatchEntryMovesMapReader reader(td);
330315
catch_entry_moves_ = reader.ReadMovesForPcOffset(pc_offset);
331316
}
332-
#endif // defined(DART_PRECOMPILED_RUNTIME) || defined(DART_PRECOMPILER)
333-
334-
#if !defined(DART_PRECOMPILED_RUNTIME)
335-
void GetCatchEntryMovesFromDeopt(intptr_t num_vars, StackFrame* frame) {
336-
Isolate* isolate = thread_->isolate();
337-
DeoptContext* deopt_context =
338-
new DeoptContext(frame, *code_, DeoptContext::kDestIsAllocated, nullptr,
339-
nullptr, true, false /* deoptimizing_code */);
340-
isolate->set_deopt_context(deopt_context);
341-
342-
catch_entry_moves_ = deopt_context->ToCatchEntryMoves(num_vars);
343-
344-
isolate->set_deopt_context(nullptr);
345-
delete deopt_context;
346-
}
347-
#endif // !defined(DART_PRECOMPILED_RUNTIME)
348317

349318
bool needs_stacktrace;
350319
uword handler_pc;
@@ -381,13 +350,11 @@ CatchEntryMove CatchEntryMove::ReadFrom(ReadStream* stream) {
381350
return CatchEntryMove(src, dest_and_kind);
382351
}
383352

384-
#if !defined(DART_PRECOMPILED_RUNTIME)
385353
void CatchEntryMove::WriteTo(BaseWriteStream* stream) {
386354
using Writer = BaseWriteStream::Raw<sizeof(int32_t), int32_t>;
387355
Writer::Write(stream, src_);
388356
Writer::Write(stream, dest_and_kind_);
389357
}
390-
#endif
391358

392359
#if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER)
393360
static intptr_t SlotIndexToFrameIndex(intptr_t slot) {

runtime/vm/exceptions.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,7 @@ class CatchEntryMove {
216216

217217
static CatchEntryMove ReadFrom(ReadStream* stream);
218218

219-
#if !defined(DART_PRECOMPILED_RUNTIME)
220219
void WriteTo(BaseWriteStream* stream);
221-
#endif
222220

223221
#if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER)
224222
const char* ToCString() const;

runtime/vm/object.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18002,16 +18002,12 @@ void Code::set_num_variables(intptr_t num_variables) const {
1800218002
}
1800318003
#endif
1800418004

18005-
#if defined(DART_PRECOMPILED_RUNTIME) || defined(DART_PRECOMPILER)
1800618005
TypedDataPtr Code::catch_entry_moves_maps() const {
18007-
ASSERT(FLAG_precompiled_mode);
1800818006
return TypedData::RawCast(untag()->catch_entry());
1800918007
}
1801018008
void Code::set_catch_entry_moves_maps(const TypedData& maps) const {
18011-
ASSERT(FLAG_precompiled_mode);
1801218009
untag()->set_catch_entry(maps.ptr());
1801318010
}
18014-
#endif
1801518011

1801618012
void Code::set_deopt_info_array(const Array& array) const {
1801718013
#if defined(DART_PRECOMPILED_RUNTIME)

runtime/vm/object.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6956,10 +6956,8 @@ class Code : public Object {
69566956
void set_num_variables(intptr_t num_variables) const;
69576957
#endif
69586958

6959-
#if defined(DART_PRECOMPILED_RUNTIME) || defined(DART_PRECOMPILER)
69606959
TypedDataPtr catch_entry_moves_maps() const;
69616960
void set_catch_entry_moves_maps(const TypedData& maps) const;
6962-
#endif
69636961

69646962
CompressedStackMapsPtr compressed_stackmaps() const {
69656963
return untag()->compressed_stackmaps();

0 commit comments

Comments
 (0)