Skip to content

Commit 6abaa31

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm,compiler] Cleanup catch entries from GraphEntry and fix IL serialization
After https://dart-review.googlesource.com/c/sdk/+/356311, GraphEntryInstr::catch_entries() is no longer needed and can be replaced with FlowGraph::try_entries(). This change also fixes crash during IL deserialization if flow graph contains a catch block. TEST=vm/dart/checked_parameter_assert_assignable_stacktrace_test Change-Id: Iad398e142bbd00110457e3b121bd446c32a5ac46 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401860 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]>
1 parent 922ad1b commit 6abaa31

File tree

11 files changed

+16
-37
lines changed

11 files changed

+16
-37
lines changed

runtime/tests/vm/dart/checked_parameter_assert_assignable_stacktrace_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88
// VMOptions=--save-debugging-info=$TEST_COMPILATION_DIR/debug.so
99
// VMOptions=--dwarf-stack-traces --save-debugging-info=$TEST_COMPILATION_DIR/debug.so
10+
// VMOptions=--test_il_serialization --save-debugging-info=$TEST_COMPILATION_DIR/debug.so
1011

1112
import 'awaiter_stacks/harness.dart' as harness;
1213

runtime/vm/compiler/backend/flow_graph.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,10 +1371,8 @@ void FlowGraph::Rename(GrowableArray<PhiInstr*>* live_phis,
13711371
env.FillWith(constant_dead(), 0, num_direct_parameters());
13721372
env.FillWith(constant_null(), num_direct_parameters(), num_stack_locals());
13731373

1374-
if (entry->catch_entries().is_empty()) {
1375-
ASSERT(entry->unchecked_entry() != nullptr ? entry->SuccessorCount() == 2
1376-
: entry->SuccessorCount() == 1);
1377-
}
1374+
ASSERT(entry->unchecked_entry() != nullptr ? entry->SuccessorCount() == 2
1375+
: entry->SuccessorCount() == 1);
13781376

13791377
// For OSR on a non-empty stack, insert synthetic phis on every joining entry.
13801378
// These phis are synthetic since they are not driven by live variable
@@ -1895,7 +1893,7 @@ void FlowGraph::ValidatePhis() {
18951893
void FlowGraph::RemoveDeadPhis(GrowableArray<PhiInstr*>* live_phis) {
18961894
// Augment live_phis with those that have implicit real used at
18971895
// potentially throwing instructions if there is a try-catch in this graph.
1898-
if (!graph_entry()->catch_entries().is_empty()) {
1896+
if (!try_entries().is_empty()) {
18991897
for (BlockIterator it(postorder_iterator()); !it.Done(); it.Advance()) {
19001898
JoinEntryInstr* join = it.Current()->AsJoinEntry();
19011899
if (join == nullptr) continue;

runtime/vm/compiler/backend/flow_graph_compiler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ void FlowGraphCompiler::RecordCatchEntryMoves(Environment* env) {
429429
if (is_optimizing() && env != nullptr && (try_index != kInvalidTryIndex)) {
430430
env = env->Outermost();
431431
CatchBlockEntryInstr* catch_block =
432-
flow_graph().graph_entry()->GetCatchEntry(try_index);
432+
flow_graph().GetCatchBlockByTryIndex(try_index);
433433
const GrowableArray<Definition*>* idefs =
434434
catch_block->initial_definitions();
435435
catch_entry_moves_maps_builder_->NewMapping(assembler()->CodeSize());

runtime/vm/compiler/backend/il.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,6 @@ GraphEntryInstr::GraphEntryInstr(const ParsedFunction& parsed_function,
12441244
deopt_id,
12451245
/*stack_depth*/ 0),
12461246
parsed_function_(parsed_function),
1247-
catch_entries_(),
12481247
indirect_entries_(),
12491248
osr_id_(osr_id),
12501249
entry_count_(0),
@@ -1261,15 +1260,6 @@ ConstantInstr* GraphEntryInstr::constant_null() {
12611260
return nullptr;
12621261
}
12631262

1264-
CatchBlockEntryInstr* GraphEntryInstr::GetCatchEntry(intptr_t index) {
1265-
// TODO(fschneider): Sort the catch entries by catch_try_index to avoid
1266-
// searching.
1267-
for (intptr_t i = 0; i < catch_entries_.length(); ++i) {
1268-
if (catch_entries_[i]->catch_try_index() == index) return catch_entries_[i];
1269-
}
1270-
return nullptr;
1271-
}
1272-
12731263
bool GraphEntryInstr::IsCompiledForOsr() const {
12741264
return osr_id_ != Compiler::kNoOSRDeoptId;
12751265
}

runtime/vm/compiler/backend/il.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,10 +1989,6 @@ class GraphEntryInstr : public BlockEntryWithInitialDefs {
19891989
virtual intptr_t SuccessorCount() const;
19901990
virtual BlockEntryInstr* SuccessorAt(intptr_t index) const;
19911991

1992-
void AddCatchEntry(CatchBlockEntryInstr* entry) { catch_entries_.Add(entry); }
1993-
1994-
CatchBlockEntryInstr* GetCatchEntry(intptr_t index);
1995-
19961992
void AddIndirectEntry(IndirectEntryInstr* entry) {
19971993
indirect_entries_.Add(entry);
19981994
}
@@ -2037,17 +2033,11 @@ class GraphEntryInstr : public BlockEntryWithInitialDefs {
20372033

20382034
const ParsedFunction& parsed_function() const { return parsed_function_; }
20392035

2040-
const GrowableArray<CatchBlockEntryInstr*>& catch_entries() const {
2041-
return catch_entries_;
2042-
}
2043-
20442036
const GrowableArray<IndirectEntryInstr*>& indirect_entries() const {
20452037
return indirect_entries_;
20462038
}
20472039

2048-
bool HasSingleEntryPoint() const {
2049-
return catch_entries().is_empty() && unchecked_entry() == nullptr;
2050-
}
2040+
bool HasSingleEntryPoint() const { return unchecked_entry() == nullptr; }
20512041

20522042
PRINT_BLOCK_HEADER_TO_SUPPORT
20532043
DECLARE_CUSTOM_SERIALIZATION(GraphEntryInstr)
@@ -2065,7 +2055,6 @@ class GraphEntryInstr : public BlockEntryWithInitialDefs {
20652055
FunctionEntryInstr* normal_entry_ = nullptr;
20662056
FunctionEntryInstr* unchecked_entry_ = nullptr;
20672057
OsrEntryInstr* osr_entry_ = nullptr;
2068-
GrowableArray<CatchBlockEntryInstr*> catch_entries_;
20692058
// Indirect targets are blocks reachable only through indirect gotos.
20702059
GrowableArray<IndirectEntryInstr*> indirect_entries_;
20712060
const intptr_t osr_id_;

runtime/vm/compiler/backend/il_serializer.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,6 @@ void GraphEntryInstr::WriteExtra(FlowGraphSerializer* s) {
988988
s->WriteRef<FunctionEntryInstr*>(normal_entry_);
989989
s->WriteRef<FunctionEntryInstr*>(unchecked_entry_);
990990
s->WriteRef<OsrEntryInstr*>(osr_entry_);
991-
s->WriteGrowableArrayOfRefs<CatchBlockEntryInstr*>(catch_entries_);
992991
s->WriteGrowableArrayOfRefs<IndirectEntryInstr*>(indirect_entries_);
993992
}
994993

@@ -997,7 +996,6 @@ void GraphEntryInstr::ReadExtra(FlowGraphDeserializer* d) {
997996
normal_entry_ = d->ReadRef<FunctionEntryInstr*>();
998997
unchecked_entry_ = d->ReadRef<FunctionEntryInstr*>();
999998
osr_entry_ = d->ReadRef<OsrEntryInstr*>();
1000-
catch_entries_ = d->ReadGrowableArrayOfRefs<CatchBlockEntryInstr*>();
1001999
indirect_entries_ = d->ReadGrowableArrayOfRefs<IndirectEntryInstr*>();
10021000
}
10031001

runtime/vm/compiler/backend/linearscan.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ void FlowGraphAllocator::BuildLiveRanges() {
640640

641641
CatchBlockEntryInstr* surrounding_catch_block =
642642
block->InsideTryBlock()
643-
? flow_graph_.graph_entry()->GetCatchEntry(block->try_index())
643+
? flow_graph_.GetCatchBlockByTryIndex(block->try_index())
644644
: nullptr;
645645
// Now process all instructions in reverse order.
646646
while (current != block) {

runtime/vm/compiler/backend/redundancy_elimination.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4214,7 +4214,11 @@ class TryCatchAnalyzer : public ValueObject {
42144214
// Assign sequential ids to each ParameterInstr in each CatchEntryBlock.
42154215
// Collect reverse mapping from try indexes to corresponding catches.
42164216
void NumberCatchEntryParameters() {
4217-
for (auto catch_entry : flow_graph_->graph_entry()->catch_entries()) {
4217+
for (TryEntryInstr* try_entry : flow_graph_->try_entries()) {
4218+
if (try_entry == nullptr) {
4219+
continue;
4220+
}
4221+
CatchBlockEntryInstr* const catch_entry = try_entry->catch_target();
42184222
const GrowableArray<Definition*>& idefs =
42194223
*catch_entry->initial_definitions();
42204224
for (auto idef : idefs) {
@@ -4418,7 +4422,7 @@ class TryCatchAnalyzer : public ValueObject {
44184422
};
44194423

44204424
void OptimizeCatchEntryStates(FlowGraph* flow_graph, bool is_aot) {
4421-
if (flow_graph->graph_entry()->catch_entries().is_empty()) {
4425+
if (flow_graph->try_entries().is_empty()) {
44224426
return;
44234427
}
44244428

runtime/vm/compiler/backend/redundancy_elimination_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static void TryCatchOptimizerTest(
8585
// Finally run TryCatchAnalyzer on the graph (in AOT mode).
8686
OptimizeCatchEntryStates(graph, /*is_aot=*/true);
8787

88-
EXPECT_EQ(1, graph->graph_entry()->catch_entries().length());
88+
EXPECT_EQ(1, graph->try_entries().length());
8989
auto scope = graph->parsed_function().scope();
9090

9191
GrowableArray<LocalVariable*> env;
@@ -104,7 +104,7 @@ static void TryCatchOptimizerTest(
104104
}
105105
}
106106

107-
CatchBlockEntryInstr* catch_entry = graph->graph_entry()->catch_entries()[0];
107+
CatchBlockEntryInstr* catch_entry = graph->GetCatchBlockByTryIndex(0);
108108

109109
// We should only synchronize state for variables from the synchronized list.
110110
for (auto defn : *catch_entry->initial_definitions()) {

runtime/vm/compiler/compiler_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ COMPILER_PASS(DelayAllocations, { DelayAllocations::Optimize(flow_graph); });
491491

492492
COMPILER_PASS(AllocationSinking_Sink, {
493493
// TODO(vegorov): Support allocation sinking with try-catch.
494-
if (flow_graph->graph_entry()->catch_entries().is_empty()) {
494+
if (flow_graph->try_entries().is_empty()) {
495495
state->sinking = new AllocationSinking(flow_graph);
496496
state->sinking->Optimize();
497497
}

0 commit comments

Comments
 (0)