Skip to content

Commit c77f3db

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm] Switch switchable calls to load the target before the data.
Needed to be able to update call sites without pausing Dart execution. TEST=ci Change-Id: I8dd6e5cc4bec617da3c1198c6064cefbe86dbec2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441721 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]>
1 parent b1d1bbd commit c77f3db

24 files changed

+254
-201
lines changed

runtime/vm/code_patcher.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class CodePatcher : public AllStatic {
6969
const Code& code,
7070
ICData* ic_data);
7171

72-
static void InsertDeoptimizationCallAt(uword start);
73-
7472
static void PatchPoolPointerCallAt(uword return_address,
7573
const Code& code,
7674
const Code& new_target);
@@ -86,6 +84,8 @@ class CodePatcher : public AllStatic {
8684
const Code& target);
8785
static ObjectPtr GetSwitchableCallDataAt(uword return_address,
8886
const Code& caller_code);
87+
static ObjectPtr GetSwitchableCallTargetAt(uword return_address,
88+
const Code& caller_code);
8989
static uword GetSwitchableCallTargetEntryAt(uword return_address,
9090
const Code& caller_code);
9191

runtime/vm/code_patcher_arm.cc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ void CodePatcher::PatchStaticCallAt(uword return_address,
2727
call.SetTargetCode(new_target);
2828
}
2929

30-
void CodePatcher::InsertDeoptimizationCallAt(uword start) {
31-
UNREACHABLE();
30+
void CodePatcher::PatchPoolPointerCallAt(uword return_address,
31+
const Code& code,
32+
const Code& new_target) {
33+
ASSERT(code.ContainsInstructionAt(return_address));
34+
CallPattern call(return_address, code);
35+
call.SetTargetCode(new_target);
3236
}
3337

3438
CodePtr CodePatcher::GetInstanceCallAt(uword return_address,
@@ -107,14 +111,23 @@ void CodePatcher::PatchSwitchableCallAtWithMutatorsStopped(
107111
}
108112
}
109113

114+
ObjectPtr CodePatcher::GetSwitchableCallTargetAt(uword return_address,
115+
const Code& caller_code) {
116+
if (FLAG_precompiled_mode) {
117+
UNREACHABLE();
118+
} else {
119+
SwitchableCallPattern call(return_address, caller_code);
120+
return call.target();
121+
}
122+
}
123+
110124
uword CodePatcher::GetSwitchableCallTargetEntryAt(uword return_address,
111125
const Code& caller_code) {
112126
if (FLAG_precompiled_mode) {
113127
BareSwitchableCallPattern call(return_address);
114128
return call.target_entry();
115129
} else {
116-
SwitchableCallPattern call(return_address, caller_code);
117-
return call.target_entry();
130+
UNREACHABLE();
118131
}
119132
}
120133

runtime/vm/code_patcher_arm64.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ void CodePatcher::PatchPoolPointerCallAt(uword return_address,
6363
call.SetTarget(new_target);
6464
}
6565

66-
void CodePatcher::InsertDeoptimizationCallAt(uword start) {
67-
UNREACHABLE();
68-
}
69-
7066
CodePtr CodePatcher::GetInstanceCallAt(uword return_address,
7167
const Code& caller_code,
7268
Object* data) {
@@ -143,14 +139,23 @@ void CodePatcher::PatchSwitchableCallAtWithMutatorsStopped(
143139
}
144140
}
145141

142+
ObjectPtr CodePatcher::GetSwitchableCallTargetAt(uword return_address,
143+
const Code& caller_code) {
144+
if (FLAG_precompiled_mode) {
145+
UNREACHABLE();
146+
} else {
147+
SwitchableCallPattern call(return_address, caller_code);
148+
return call.target();
149+
}
150+
}
151+
146152
uword CodePatcher::GetSwitchableCallTargetEntryAt(uword return_address,
147153
const Code& caller_code) {
148154
if (FLAG_precompiled_mode) {
149155
BareSwitchableCallPattern call(return_address);
150156
return call.target_entry();
151157
} else {
152-
SwitchableCallPattern call(return_address, caller_code);
153-
return call.target_entry();
158+
UNREACHABLE();
154159
}
155160
}
156161

runtime/vm/code_patcher_arm64_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ ASSEMBLER_TEST_GENERATE(IcDataAccess, assembler) {
4848
SPILLS_LR_TO_FRAME({}); // Clobbered LR is OK.
4949

5050
compiler::ObjectPoolBuilder& op = __ object_pool_builder();
51-
const intptr_t ic_data_index =
52-
op.AddObject(ic_data, ObjectPool::Patchability::kPatchable);
5351
const intptr_t stub_index =
5452
op.AddObject(stub, ObjectPool::Patchability::kPatchable);
55-
ASSERT((ic_data_index + 1) == stub_index);
56-
__ LoadDoubleWordFromPoolIndex(R5, CODE_REG, ic_data_index);
53+
const intptr_t ic_data_index =
54+
op.AddObject(ic_data, ObjectPool::Patchability::kPatchable);
55+
ASSERT((stub_index + 1) == ic_data_index);
56+
__ LoadDoubleWordFromPoolIndex(CODE_REG, R5, stub_index);
5757
__ Call(compiler::FieldAddress(
5858
CODE_REG, Code::entry_point_offset(Code::EntryKind::kMonomorphic)));
5959
RESTORES_LR_FROM_FRAME({}); // Clobbered LR is OK.

runtime/vm/code_patcher_arm_test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ ASSEMBLER_TEST_GENERATE(IcDataAccess, assembler) {
4646
__ set_constant_pool_allowed(true); // Uninitialized pp is OK.
4747
SPILLS_LR_TO_FRAME({}); // Clobbered LR is OK.
4848

49+
__ LoadObject(CODE_REG, StubCode::OneArgCheckInlineCache());
4950
__ LoadObject(R9, ic_data);
50-
__ BranchLinkPatchable(StubCode::OneArgCheckInlineCache());
51+
__ Call(compiler::FieldAddress(
52+
CODE_REG, Code::entry_point_offset(Code::EntryKind::kMonomorphic)));
5153
RESTORES_LR_FROM_FRAME({}); // Clobbered LR is OK.
5254
__ Ret();
5355
}

runtime/vm/code_patcher_ia32.cc

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ void CodePatcher::PatchStaticCallAt(uword return_address,
198198
});
199199
}
200200

201-
void CodePatcher::InsertDeoptimizationCallAt(uword start) {
202-
UNREACHABLE();
203-
}
204-
205201
CodePtr CodePatcher::GetInstanceCallAt(uword return_address,
206202
const Code& caller_code,
207203
Object* data) {
@@ -258,18 +254,13 @@ void CodePatcher::PatchSwitchableCallAt(uword return_address,
258254
const Code& caller_code,
259255
const Object& data,
260256
const Code& target) {
261-
// Switchable instance calls only generated for precompilation.
262-
UNREACHABLE();
257+
PatchInstanceCallAt(return_address, caller_code, data, target);
263258
}
264259

265-
void CodePatcher::PatchSwitchableCallAtWithMutatorsStopped(
266-
Thread* thread,
267-
uword return_address,
268-
const Code& caller_code,
269-
const Object& data,
270-
const Code& target) {
271-
// Switchable instance calls only generated for precompilation.
272-
UNREACHABLE();
260+
ObjectPtr CodePatcher::GetSwitchableCallTargetAt(uword return_address,
261+
const Code& caller_code) {
262+
InstanceCall call(return_address, caller_code);
263+
return call.target();
273264
}
274265

275266
uword CodePatcher::GetSwitchableCallTargetEntryAt(uword return_address,
@@ -281,9 +272,8 @@ uword CodePatcher::GetSwitchableCallTargetEntryAt(uword return_address,
281272

282273
ObjectPtr CodePatcher::GetSwitchableCallDataAt(uword return_address,
283274
const Code& caller_code) {
284-
// Switchable instance calls only generated for precompilation.
285-
UNREACHABLE();
286-
return Object::null();
275+
InstanceCall call(return_address, caller_code);
276+
return call.data();
287277
}
288278

289279
void CodePatcher::PatchNativeCallAt(uword return_address,

runtime/vm/code_patcher_riscv.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ void CodePatcher::PatchPoolPointerCallAt(uword return_address,
7272
call.SetTarget(new_target);
7373
}
7474

75-
void CodePatcher::InsertDeoptimizationCallAt(uword start) {
76-
UNREACHABLE();
77-
}
78-
7975
CodePtr CodePatcher::GetInstanceCallAt(uword return_address,
8076
const Code& caller_code,
8177
Object* data) {
@@ -152,14 +148,23 @@ void CodePatcher::PatchSwitchableCallAtWithMutatorsStopped(
152148
}
153149
}
154150

151+
ObjectPtr CodePatcher::GetSwitchableCallTargetAt(uword return_address,
152+
const Code& caller_code) {
153+
if (FLAG_precompiled_mode) {
154+
UNREACHABLE();
155+
} else {
156+
SwitchableCallPattern call(return_address, caller_code);
157+
return call.target();
158+
}
159+
}
160+
155161
uword CodePatcher::GetSwitchableCallTargetEntryAt(uword return_address,
156162
const Code& caller_code) {
157163
if (FLAG_precompiled_mode) {
158164
BareSwitchableCallPattern call(return_address);
159165
return call.target_entry();
160166
} else {
161-
SwitchableCallPattern call(return_address, caller_code);
162-
return call.target_entry();
167+
UNREACHABLE();
163168
}
164169
}
165170

runtime/vm/code_patcher_riscv_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ ASSEMBLER_TEST_GENERATE(IcDataAccess, assembler) {
4545

4646
// Code is generated, but not executed. Just parsed with CodePatcher.
4747
__ set_constant_pool_allowed(true); // Uninitialized pp is OK.
48-
__ LoadUniqueObject(IC_DATA_REG, ic_data);
4948
__ LoadUniqueObject(CODE_REG, stub);
49+
__ LoadUniqueObject(IC_DATA_REG, ic_data);
5050
__ Call(compiler::FieldAddress(
5151
CODE_REG, Code::entry_point_offset(Code::EntryKind::kMonomorphic)));
5252
__ ret();

0 commit comments

Comments
 (0)