Skip to content

Commit 1f4707a

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm,dyn_modules] Avoid static calls to bytecode functions from optimized JIT code
Static (direct) calls in the optimized JIT are performed through Code objects without passing Function objects. This is not compatible with bytecode interpreter calling conventions, so optimized JIT should avoid static calls to bytecode functions. This change disables devirtualized and guarded static calls to functions declared in bytecode. TEST=ci Closes #60716 Change-Id: I95e4fa0706f376355f4fa7aea7fddf44f303e0a0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428340 Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent e0673fe commit 1f4707a

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

runtime/vm/compiler/backend/flow_graph_compiler.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,13 @@ void FlowGraphCompiler::EmitTestAndCall(const CallTargets& targets,
21982198
add_megamorphic_call = true;
21992199
break;
22002200
}
2201+
const Function& function = *targets.TargetAt(i)->target;
2202+
if (function.is_declared_in_bytecode()) {
2203+
// Optimized static calls dispatch via Code object without passing
2204+
// Function object which is incompatible to the bytecode interpreter.
2205+
add_megamorphic_call = true;
2206+
continue;
2207+
}
22012208
compiler::Label next_test;
22022209
if (!complete || !is_last_check) {
22032210
bias = EmitTestAndCallCheckCid(assembler(),
@@ -2207,7 +2214,6 @@ void FlowGraphCompiler::EmitTestAndCall(const CallTargets& targets,
22072214
}
22082215
// Do not use the code from the function, but let the code be patched so
22092216
// that we can record the outgoing edges to other code.
2210-
const Function& function = *targets.TargetAt(i)->target;
22112217
GenerateStaticDartCall(deopt_id, source_index,
22122218
UntaggedPcDescriptors::kOther, locs, function,
22132219
entry_kind);

runtime/vm/compiler/backend/il.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5592,6 +5592,11 @@ Definition* InstanceCallInstr::Canonicalize(FlowGraph* flow_graph) {
55925592

55935593
ASSERT(new_target->HasSingleTarget());
55945594
const Function& target = new_target->FirstTarget();
5595+
if (target.is_declared_in_bytecode()) {
5596+
// Optimized static calls dispatch via Code object without passing
5597+
// Function object which is incompatible to the bytecode interpreter.
5598+
return this;
5599+
}
55955600
StaticCallInstr* specialized = StaticCallInstr::FromCall(
55965601
flow_graph->zone(), this, target, new_target->AggregateCallCount());
55975602
flow_graph->InsertBefore(this, specialized, env(), FlowGraph::kValue);

runtime/vm/compiler/call_specializer.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ void CallSpecializer::SpecializePolymorphicInstanceCall(
193193

194194
ASSERT(targets->HasSingleTarget());
195195
const Function& target = targets->FirstTarget();
196+
if (target.is_declared_in_bytecode()) {
197+
// Optimized static calls dispatch via Code object without passing
198+
// Function object which is incompatible to the bytecode interpreter.
199+
return;
200+
}
196201
StaticCallInstr* specialized =
197202
StaticCallInstr::FromCall(Z, call, target, targets->AggregateCallCount());
198203
call->ReplaceWith(specialized, current_iterator());

runtime/vm/compiler/jit/jit_call_specializer.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ void JitCallSpecializer::VisitInstanceCall(InstanceCallInstr* instr) {
111111
has_one_target = PolymorphicInstanceCallInstr::ComputeRuntimeType(
112112
targets) != Type::null();
113113
} else {
114-
has_one_target =
115-
!target.is_polymorphic_target() && !target.IsDynamicallyOverridden();
114+
has_one_target = !target.is_polymorphic_target() &&
115+
!target.IsDynamicallyOverridden() &&
116+
!target.is_declared_in_bytecode();
116117
}
117118
}
118119

0 commit comments

Comments
 (0)