[vm/shared] Use isolate_group instead of isolate in various native runtime calls.
TEST=shared_collect_all_garbage_test
BUG=https://github.com/dart-lang/sdk/issues/61138
Change-Id: I5c9dbb1cd2700fac4392d368b19ead6a862ed3c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441261
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/lib/object.cc b/runtime/lib/object.cc
index 60f9f16..5ead098 100644
--- a/runtime/lib/object.cc
+++ b/runtime/lib/object.cc
@@ -36,11 +36,11 @@
return Object::null();
}
-static intptr_t GetHash(Isolate* isolate, const ObjectPtr obj) {
+static intptr_t GetHash(IsolateGroup* isolate_group, const ObjectPtr obj) {
#if defined(HASH_IN_OBJECT_HEADER)
return Object::GetCachedHash(obj);
#else
- Heap* heap = isolate->group()->heap();
+ Heap* heap = isolate_group->heap();
ASSERT(obj->IsDartInstance());
return heap->GetHash(obj);
#endif
@@ -50,7 +50,7 @@
// Please note that no handle is created for the argument.
// This is safe since the argument is only used in a tail call.
// The performance benefit is more than 5% when using hashCode.
- intptr_t hash = GetHash(isolate, arguments->NativeArgAt(0));
+ intptr_t hash = GetHash(thread->isolate_group(), arguments->NativeArgAt(0));
if (LIKELY(hash != 0)) {
return Smi::New(hash);
}
@@ -269,8 +269,9 @@
DEFINE_NATIVE_ENTRY(LibraryPrefix_issueLoad, 0, 1) {
const Smi& id = Smi::CheckedHandle(zone, arguments->NativeArgAt(0));
+ auto isolate_group = thread->isolate_group();
Array& units =
- Array::Handle(zone, isolate->group()->object_store()->loading_units());
+ Array::Handle(zone, isolate_group->object_store()->loading_units());
if (units.IsNull()) {
// Not actually split.
const Library& lib = Library::Handle(zone, Library::CoreLibrary());
@@ -300,8 +301,9 @@
}
DEFINE_NATIVE_ENTRY(Internal_collectAllGarbage, 0, 0) {
- isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging,
- /*compact=*/true);
+ auto isolate_group = thread->isolate_group();
+ isolate_group->heap()->CollectAllGarbage(GCReason::kDebugging,
+ /*compact=*/true);
return Object::null();
}
@@ -311,26 +313,28 @@
}
DEFINE_NATIVE_ENTRY(Internal_allocateObjectInstructionsStart, 0, 0) {
- auto& stub = Code::Handle(
- zone, isolate->group()->object_store()->allocate_object_stub());
+ auto isolate_group = thread->isolate_group();
+ auto& stub =
+ Code::Handle(zone, isolate_group->object_store()->allocate_object_stub());
ASSERT(!stub.IsUnknownDartCode());
// We return the start offset in the isolate instructions instead of the
// full address because that fits into small Smis on 32-bit architectures
// or compressed pointer builds.
const uword instructions_start =
- reinterpret_cast<uword>(isolate->source()->snapshot_instructions);
+ reinterpret_cast<uword>(isolate_group->source()->snapshot_instructions);
return Smi::New(stub.PayloadStart() - instructions_start);
}
DEFINE_NATIVE_ENTRY(Internal_allocateObjectInstructionsEnd, 0, 0) {
- auto& stub = Code::Handle(
- zone, isolate->group()->object_store()->allocate_object_stub());
+ auto isolate_group = thread->isolate_group();
+ auto& stub =
+ Code::Handle(zone, isolate_group->object_store()->allocate_object_stub());
ASSERT(!stub.IsUnknownDartCode());
// We return the end offset in the isolate instructions instead of the
// full address because that fits into small Smis on 32-bit architectures
// or compressed pointer builds.
const uword instructions_start =
- reinterpret_cast<uword>(isolate->source()->snapshot_instructions);
+ reinterpret_cast<uword>(isolate_group->source()->snapshot_instructions);
return Smi::New((stub.PayloadStart() - instructions_start) + stub.Size());
}
diff --git a/runtime/tests/vm/dart/shared_collect_all_garbage_test.dart b/runtime/tests/vm/dart/shared_collect_all_garbage_test.dart
new file mode 100644
index 0000000..d9de1b9
--- /dev/null
+++ b/runtime/tests/vm/dart/shared_collect_all_garbage_test.dart
@@ -0,0 +1,14 @@
+// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// VMOptions=--experimental-shared-data
+//
+import 'dart:_internal' show VMInternalsForTesting;
+import 'package:dart_internal/isolate_group.dart' show IsolateGroup;
+
+main() {
+ IsolateGroup.runSync(() {
+ VMInternalsForTesting.collectAllGarbage();
+ });
+}