Skip to content

Commit 0a6fa7a

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm] Fix --gc_at_throw, etc for isolate group callbacks.
TEST=ffi/isolate_group_shared_callback_test Change-Id: Ib4c241d59a36544495c264c51848753a0bc22bf4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429460 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 8f8ad12 commit 0a6fa7a

File tree

2 files changed

+37
-41
lines changed

2 files changed

+37
-41
lines changed

runtime/vm/runtime_entry.cc

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,7 @@ static void NullErrorHelper(Zone* zone,
231231
Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args);
232232
}
233233

234-
static void DoThrowNullError(Isolate* isolate,
235-
Thread* thread,
236-
Zone* zone,
237-
bool is_param) {
234+
static void DoThrowNullError(Thread* thread, Zone* zone, bool is_param) {
238235
DartFrameIterator iterator(thread,
239236
StackFrameIterator::kNoCrossThreadIteration);
240237
const StackFrame* caller_frame = iterator.NextFrame();
@@ -244,7 +241,7 @@ static void DoThrowNullError(Isolate* isolate,
244241
const uword pc_offset = caller_frame->pc() - code.PayloadStart();
245242

246243
if (FLAG_shared_slow_path_triggers_gc) {
247-
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging);
244+
thread->isolate_group()->heap()->CollectAllGarbage(GCReason::kDebugging);
248245
}
249246

250247
const CodeSourceMap& map =
@@ -266,7 +263,7 @@ static void DoThrowNullError(Isolate* isolate,
266263
}
267264

268265
DEFINE_RUNTIME_ENTRY(NullError, 0) {
269-
DoThrowNullError(isolate, thread, zone, /*is_param=*/false);
266+
DoThrowNullError(thread, zone, /*is_param=*/false);
270267
}
271268

272269
// Collects information about pointers within the top |kMaxSlotsCollected|
@@ -315,7 +312,7 @@ DEFINE_RUNTIME_ENTRY(DispatchTableNullError, 1) {
315312
RELEASE_ASSERT(caller_frame->IsDartFrame());
316313
ReportImpossibleNullError(cid.Value(), caller_frame, thread);
317314
}
318-
DoThrowNullError(isolate, thread, zone, /*is_param=*/false);
315+
DoThrowNullError(thread, zone, /*is_param=*/false);
319316
}
320317

321318
DEFINE_RUNTIME_ENTRY(NullErrorWithSelector, 1) {
@@ -328,7 +325,7 @@ DEFINE_RUNTIME_ENTRY(NullCastError, 0) {
328325
}
329326

330327
DEFINE_RUNTIME_ENTRY(ArgumentNullError, 0) {
331-
DoThrowNullError(isolate, thread, zone, /*is_param=*/true);
328+
DoThrowNullError(thread, zone, /*is_param=*/true);
332329
}
333330

334331
DEFINE_RUNTIME_ENTRY(ArgumentError, 1) {
@@ -423,7 +420,7 @@ DEFINE_RUNTIME_ENTRY(AllocateArray, 2) {
423420

424421
DEFINE_RUNTIME_ENTRY_NO_LAZY_DEOPT(AllocateDouble, 0) {
425422
if (FLAG_shared_slow_path_triggers_gc) {
426-
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging);
423+
thread->isolate_group()->heap()->CollectAllGarbage(GCReason::kDebugging);
427424
}
428425
arguments.SetReturn(
429426
Object::Handle(zone, Double::New(0.0, SpaceForRuntimeAllocation())));
@@ -453,7 +450,7 @@ DEFINE_RUNTIME_ENTRY_NO_LAZY_DEOPT(BoxFloat64x2, 0) {
453450

454451
DEFINE_RUNTIME_ENTRY_NO_LAZY_DEOPT(AllocateMint, 0) {
455452
if (FLAG_shared_slow_path_triggers_gc) {
456-
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging);
453+
thread->isolate_group()->heap()->CollectAllGarbage(GCReason::kDebugging);
457454
}
458455
arguments.SetReturn(Object::Handle(
459456
zone, Integer::New(kMaxInt64, SpaceForRuntimeAllocation())));
@@ -462,7 +459,7 @@ DEFINE_RUNTIME_ENTRY_NO_LAZY_DEOPT(AllocateMint, 0) {
462459

463460
DEFINE_RUNTIME_ENTRY_NO_LAZY_DEOPT(AllocateFloat32x4, 0) {
464461
if (FLAG_shared_slow_path_triggers_gc) {
465-
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging);
462+
thread->isolate_group()->heap()->CollectAllGarbage(GCReason::kDebugging);
466463
}
467464
arguments.SetReturn(Object::Handle(
468465
zone, Float32x4::New(0.0, 0.0, 0.0, 0.0, SpaceForRuntimeAllocation())));
@@ -471,7 +468,7 @@ DEFINE_RUNTIME_ENTRY_NO_LAZY_DEOPT(AllocateFloat32x4, 0) {
471468

472469
DEFINE_RUNTIME_ENTRY_NO_LAZY_DEOPT(AllocateFloat64x2, 0) {
473470
if (FLAG_shared_slow_path_triggers_gc) {
474-
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging);
471+
thread->isolate_group()->heap()->CollectAllGarbage(GCReason::kDebugging);
475472
}
476473
arguments.SetReturn(Object::Handle(
477474
zone, Float64x2::New(0.0, 0.0, SpaceForRuntimeAllocation())));
@@ -480,7 +477,7 @@ DEFINE_RUNTIME_ENTRY_NO_LAZY_DEOPT(AllocateFloat64x2, 0) {
480477

481478
DEFINE_RUNTIME_ENTRY_NO_LAZY_DEOPT(AllocateInt32x4, 0) {
482479
if (FLAG_shared_slow_path_triggers_gc) {
483-
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging);
480+
thread->isolate_group()->heap()->CollectAllGarbage(GCReason::kDebugging);
484481
}
485482
arguments.SetReturn(Object::Handle(
486483
zone, Int32x4::New(0, 0, 0, 0, SpaceForRuntimeAllocation())));
@@ -1564,7 +1561,8 @@ DEFINE_RUNTIME_ENTRY(TypeCheck, 7) {
15641561
// Ensure we do have a STC (lazily create it if not) and all threads use
15651562
// the same STC.
15661563
{
1567-
SafepointMutexLocker ml(isolate->group()->subtype_test_cache_mutex());
1564+
SafepointMutexLocker ml(
1565+
thread->isolate_group()->subtype_test_cache_mutex());
15681566
cache ^= pool.ObjectAt<std::memory_order_acquire>(stc_pool_idx);
15691567
if (cache.IsNull()) {
15701568
resolve_dst_name();
@@ -1600,10 +1598,10 @@ DEFINE_RUNTIME_ENTRY(TypeCheck, 7) {
16001598

16011599
DEFINE_RUNTIME_ENTRY(Throw, 1) {
16021600
if (FLAG_gc_at_throw) {
1603-
isolate->group()->heap()->CollectGarbage(thread, GCType::kEvacuate,
1604-
GCReason::kDebugging);
1605-
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging,
1606-
/*compact=*/true);
1601+
thread->isolate_group()->heap()->CollectGarbage(thread, GCType::kEvacuate,
1602+
GCReason::kDebugging);
1603+
thread->isolate_group()->heap()->CollectAllGarbage(GCReason::kDebugging,
1604+
/*compact=*/true);
16071605
}
16081606

16091607
const Instance& exception = Instance::CheckedHandle(zone, arguments.ArgAt(0));
@@ -1612,10 +1610,10 @@ DEFINE_RUNTIME_ENTRY(Throw, 1) {
16121610

16131611
DEFINE_RUNTIME_ENTRY(ReThrow, 3) {
16141612
if (FLAG_gc_at_throw) {
1615-
isolate->group()->heap()->CollectGarbage(thread, GCType::kEvacuate,
1616-
GCReason::kDebugging);
1617-
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging,
1618-
/*compact=*/true);
1613+
thread->isolate_group()->heap()->CollectGarbage(thread, GCType::kEvacuate,
1614+
GCReason::kDebugging);
1615+
thread->isolate_group()->heap()->CollectAllGarbage(GCReason::kDebugging,
1616+
/*compact=*/true);
16191617
}
16201618

16211619
const Instance& exception = Instance::CheckedHandle(zone, arguments.ArgAt(0));
@@ -1682,8 +1680,8 @@ DEFINE_RUNTIME_ENTRY(BreakpointRuntimeHandler, 0) {
16821680
ASSERT(caller_frame != nullptr);
16831681
Code& orig_stub = Code::Handle(zone);
16841682
if (!caller_frame->is_interpreted()) {
1685-
orig_stub =
1686-
isolate->group()->debugger()->GetPatchedStubAddress(caller_frame->pc());
1683+
orig_stub = thread->isolate_group()->debugger()->GetPatchedStubAddress(
1684+
caller_frame->pc());
16871685
}
16881686
const Error& error =
16891687
Error::Handle(zone, isolate->debugger()->PauseBreakpoint());
@@ -2015,11 +2013,9 @@ class SavedUnlinkedCallMapKeyEqualsTraits : public AllStatic {
20152013
using UnlinkedCallMap = UnorderedHashMap<SavedUnlinkedCallMapKeyEqualsTraits>;
20162014

20172015
static void SaveUnlinkedCall(Zone* zone,
2018-
Isolate* isolate,
2016+
IsolateGroup* isolate_group,
20192017
uword frame_pc,
20202018
const UnlinkedCall& unlinked_call) {
2021-
IsolateGroup* isolate_group = isolate->group();
2022-
20232019
SafepointMutexLocker ml(isolate_group->unlinked_call_map_mutex());
20242020
if (isolate_group->saved_unlinked_calls() == Array::null()) {
20252021
const auto& initial_map =
@@ -2040,10 +2036,8 @@ static void SaveUnlinkedCall(Zone* zone,
20402036
}
20412037

20422038
static UnlinkedCallPtr LoadUnlinkedCall(Zone* zone,
2043-
Isolate* isolate,
2039+
IsolateGroup* isolate_group,
20442040
uword pc) {
2045-
IsolateGroup* isolate_group = isolate->group();
2046-
20472041
SafepointMutexLocker ml(isolate_group->unlinked_call_map_mutex());
20482042
ASSERT(isolate_group->saved_unlinked_calls() != Array::null());
20492043
UnlinkedCallMap unlinked_call_map(zone,
@@ -2109,7 +2103,7 @@ class PatchableCallHandler {
21092103
StackFrame* caller_frame,
21102104
const Code& caller_code,
21112105
const Function& caller_function)
2112-
: isolate_(thread->isolate()),
2106+
: isolate_group_(thread->isolate_group()),
21132107
thread_(thread),
21142108
zone_(thread->zone()),
21152109
caller_arguments_(caller_arguments),
@@ -2190,7 +2184,7 @@ class PatchableCallHandler {
21902184
ICDataPtr NewICData();
21912185
ICDataPtr NewICDataWithTarget(intptr_t cid, const Function& target);
21922186

2193-
Isolate* isolate_;
2187+
IsolateGroup* isolate_group_;
21942188
Thread* thread_;
21952189
Zone* zone_;
21962190
const GrowableArray<const Instance*>& caller_arguments_;
@@ -2271,8 +2265,8 @@ bool PatchableCallHandler::CanExtendSingleTargetRange(
22712265
*upper = receiver().GetClassId();
22722266
}
22732267

2274-
return IsSingleTarget(isolate_->group(), zone_, unchecked_lower,
2275-
unchecked_upper, target_function, name);
2268+
return IsSingleTarget(isolate_group_, zone_, unchecked_lower, unchecked_upper,
2269+
target_function, name);
22762270
}
22772271
#endif // defined(DART_PRECOMPILED_RUNTIME)
22782272

@@ -2288,8 +2282,8 @@ void PatchableCallHandler::DoMonomorphicMissAOT(
22882282
old_expected_cid = MonomorphicSmiableCall::Cast(old_data).expected_cid();
22892283
}
22902284
const bool is_monomorphic_hit = old_expected_cid == receiver().GetClassId();
2291-
const auto& old_receiver_class = Class::Handle(
2292-
zone_, isolate_->group()->class_table()->At(old_expected_cid));
2285+
const auto& old_receiver_class =
2286+
Class::Handle(zone_, isolate_group_->class_table()->At(old_expected_cid));
22932287
const auto& old_target = Function::Handle(
22942288
zone_, Resolve(thread_, zone_, caller_arguments_, old_receiver_class,
22952289
name_, args_descriptor_));
@@ -2656,7 +2650,8 @@ FunctionPtr PatchableCallHandler::ResolveTargetFunction(const Object& data) {
26562650
//
26572651
// In JIT mode we always use ICData from the call site, which has the
26582652
// correct name/args-descriptor.
2659-
SaveUnlinkedCall(zone_, isolate_, caller_frame_->pc(), unlinked_call);
2653+
SaveUnlinkedCall(zone_, isolate_group_, caller_frame_->pc(),
2654+
unlinked_call);
26602655
#endif // defined(DART_PRECOMPILED_RUNTIME)
26612656

26622657
name_ = unlinked_call.target_name();
@@ -2670,7 +2665,7 @@ FunctionPtr PatchableCallHandler::ResolveTargetFunction(const Object& data) {
26702665
FALL_THROUGH;
26712666
case kSingleTargetCacheCid: {
26722667
const auto& unlinked_call = UnlinkedCall::Handle(
2673-
zone_, LoadUnlinkedCall(zone_, isolate_, caller_frame_->pc()));
2668+
zone_, LoadUnlinkedCall(zone_, isolate_group_, caller_frame_->pc()));
26742669
name_ = unlinked_call.target_name();
26752670
args_descriptor_ = unlinked_call.arguments_descriptor();
26762671
break;
@@ -2717,7 +2712,7 @@ void PatchableCallHandler::ResolveSwitchAndReturn(const Object& old_data) {
27172712
//
27182713
// Mutators are only stopped if we actually need to patch a patchable call.
27192714
// We may not do that if we e.g. just add one more check to an ICData.
2720-
SafepointMutexLocker ml(thread_->isolate_group()->patchable_call_mutex());
2715+
SafepointMutexLocker ml(isolate_group_->patchable_call_mutex());
27212716

27222717
#if defined(DART_PRECOMPILED_RUNTIME)
27232718
data =
@@ -4122,13 +4117,13 @@ DEFINE_RUNTIME_ENTRY(NotLoaded, 0) {
41224117
}
41234118

41244119
DEFINE_RUNTIME_ENTRY(FfiAsyncCallbackSend, 1) {
4125-
Dart_Port target_port = Thread::Current()->unboxed_int64_runtime_arg();
4120+
Dart_Port target_port = thread->unboxed_int64_runtime_arg();
41264121
TRACE_RUNTIME_CALL("FfiAsyncCallbackSend %p", (void*)target_port);
41274122
const Object& message = Object::Handle(zone, arguments.ArgAt(0));
41284123
const Array& msg_array = Array::Handle(zone, Array::New(3));
41294124
msg_array.SetAt(0, message);
41304125
PersistentHandle* handle =
4131-
isolate->group()->api_state()->AllocatePersistentHandle();
4126+
thread->isolate_group()->api_state()->AllocatePersistentHandle();
41324127
handle->set_ptr(msg_array);
41334128
PortMap::PostMessage(
41344129
Message::New(target_port, handle, Message::kNormalPriority));

tests/ffi/isolate_group_shared_callback_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// VMOptions=--experimental-shared-data --print-stacktrace-at-throw
88
// VMOptions=--experimental-shared-data --print-stacktrace-at-throw --use-slow-path
99
// VMOptions=--experimental-shared-data --print-stacktrace-at-throw --use-slow-path --stacktrace-every=100
10+
// VMOptions=--experimental-shared-data --print-stacktrace-at-throw --use-slow-path --shared_slow_path_triggers_gc
1011
// VMOptions=--experimental-shared-data --print-stacktrace-at-throw --dwarf_stack_traces --no-retain_function_objects --no-retain_code_objects
1112
// VMOptions=--experimental-shared-data --print-stacktrace-at-throw --test_il_serialization
1213
// VMOptions=--experimental-shared-data --print-stacktrace-at-throw --profiler --profile_vm=true

0 commit comments

Comments
 (0)