Skip to content

Commit 4faed73

Browse files
aamCommit Queue
authored andcommitted
[vm/shared] Use isolate_group instead of isolate in various native runtime calls.
TEST=shared_collect_all_garbage_test BUG=#61138 Change-Id: I5c9dbb1cd2700fac4392d368b19ead6a862ed3c0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441261 Commit-Queue: Alexander Aprelev <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 2b01dd9 commit 4faed73

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

runtime/lib/object.cc

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ DEFINE_NATIVE_ENTRY(Object_equals, 0, 1) {
3636
return Object::null();
3737
}
3838

39-
static intptr_t GetHash(Isolate* isolate, const ObjectPtr obj) {
39+
static intptr_t GetHash(IsolateGroup* isolate_group, const ObjectPtr obj) {
4040
#if defined(HASH_IN_OBJECT_HEADER)
4141
return Object::GetCachedHash(obj);
4242
#else
43-
Heap* heap = isolate->group()->heap();
43+
Heap* heap = isolate_group->heap();
4444
ASSERT(obj->IsDartInstance());
4545
return heap->GetHash(obj);
4646
#endif
@@ -50,7 +50,7 @@ DEFINE_NATIVE_ENTRY(Object_getHash, 0, 1) {
5050
// Please note that no handle is created for the argument.
5151
// This is safe since the argument is only used in a tail call.
5252
// The performance benefit is more than 5% when using hashCode.
53-
intptr_t hash = GetHash(isolate, arguments->NativeArgAt(0));
53+
intptr_t hash = GetHash(thread->isolate_group(), arguments->NativeArgAt(0));
5454
if (LIKELY(hash != 0)) {
5555
return Smi::New(hash);
5656
}
@@ -269,8 +269,9 @@ DEFINE_NATIVE_ENTRY(LibraryPrefix_loadingUnit, 0, 1) {
269269

270270
DEFINE_NATIVE_ENTRY(LibraryPrefix_issueLoad, 0, 1) {
271271
const Smi& id = Smi::CheckedHandle(zone, arguments->NativeArgAt(0));
272+
auto isolate_group = thread->isolate_group();
272273
Array& units =
273-
Array::Handle(zone, isolate->group()->object_store()->loading_units());
274+
Array::Handle(zone, isolate_group->object_store()->loading_units());
274275
if (units.IsNull()) {
275276
// Not actually split.
276277
const Library& lib = Library::Handle(zone, Library::CoreLibrary());
@@ -300,8 +301,9 @@ DEFINE_NATIVE_ENTRY(Internal_nativeEffect, 0, 1) {
300301
}
301302

302303
DEFINE_NATIVE_ENTRY(Internal_collectAllGarbage, 0, 0) {
303-
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging,
304-
/*compact=*/true);
304+
auto isolate_group = thread->isolate_group();
305+
isolate_group->heap()->CollectAllGarbage(GCReason::kDebugging,
306+
/*compact=*/true);
305307
return Object::null();
306308
}
307309

@@ -311,26 +313,28 @@ DEFINE_NATIVE_ENTRY(Internal_deoptimizeFunctionsOnStack, 0, 0) {
311313
}
312314

313315
DEFINE_NATIVE_ENTRY(Internal_allocateObjectInstructionsStart, 0, 0) {
314-
auto& stub = Code::Handle(
315-
zone, isolate->group()->object_store()->allocate_object_stub());
316+
auto isolate_group = thread->isolate_group();
317+
auto& stub =
318+
Code::Handle(zone, isolate_group->object_store()->allocate_object_stub());
316319
ASSERT(!stub.IsUnknownDartCode());
317320
// We return the start offset in the isolate instructions instead of the
318321
// full address because that fits into small Smis on 32-bit architectures
319322
// or compressed pointer builds.
320323
const uword instructions_start =
321-
reinterpret_cast<uword>(isolate->source()->snapshot_instructions);
324+
reinterpret_cast<uword>(isolate_group->source()->snapshot_instructions);
322325
return Smi::New(stub.PayloadStart() - instructions_start);
323326
}
324327

325328
DEFINE_NATIVE_ENTRY(Internal_allocateObjectInstructionsEnd, 0, 0) {
326-
auto& stub = Code::Handle(
327-
zone, isolate->group()->object_store()->allocate_object_stub());
329+
auto isolate_group = thread->isolate_group();
330+
auto& stub =
331+
Code::Handle(zone, isolate_group->object_store()->allocate_object_stub());
328332
ASSERT(!stub.IsUnknownDartCode());
329333
// We return the end offset in the isolate instructions instead of the
330334
// full address because that fits into small Smis on 32-bit architectures
331335
// or compressed pointer builds.
332336
const uword instructions_start =
333-
reinterpret_cast<uword>(isolate->source()->snapshot_instructions);
337+
reinterpret_cast<uword>(isolate_group->source()->snapshot_instructions);
334338
return Smi::New((stub.PayloadStart() - instructions_start) + stub.Size());
335339
}
336340

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// VMOptions=--experimental-shared-data
6+
//
7+
import 'dart:_internal' show VMInternalsForTesting;
8+
import 'package:dart_internal/isolate_group.dart' show IsolateGroup;
9+
10+
main() {
11+
IsolateGroup.runSync(() {
12+
VMInternalsForTesting.collectAllGarbage();
13+
});
14+
}

0 commit comments

Comments
 (0)