[ffi/isolate_group] Move IsolateGroupBound callbacks from isolate to isolate group.

This allows creation of isolategroup-bound callbacks when isolate is not available. For example, to support proposed Isolate::onEvent/Isolate::handleEvent api https://github.com/dart-lang/language/blob/main/working/333%20-%20shared%20memory%20multithreading/shared_native_memory.md#additional-isolate-apis.

BUG=https://github.com/dart-lang/sdk/issues/63291
TEST=isolate_group_bound_callback_test

CoreLibraryReviewExempt: vm ffi-specific comments changes
Change-Id: I9a757a39ba8e152db64f59a66d337ca672103277
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499661
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev
2026-05-05 08:37:06 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent b10062cbbf
commit 00cda4d60f
7 changed files with 82 additions and 52 deletions
+17 -6
View File
@@ -2705,6 +2705,13 @@ void Isolate::LowLevelCleanup(Isolate* isolate) {
FinalizeWeakPersistentHandlesVisitor visitor(isolate_group);
isolate_group->api_state()->VisitWeakHandlesUnlocked(&visitor);
// Clean up any synchronous FFI callbacks registered with this
// isolate group. Skip if this isolate group never registered any.
if (isolate_group->ffi_callback_list_head_ != nullptr) {
FfiCallbackMetadata::Instance()->DeleteAllCallbacks(
&isolate_group->ffi_callback_list_head_);
}
Thread::ExitIsolateGroupAsHelper(/*bypass_safepoint=*/false);
}
@@ -3817,16 +3824,20 @@ FfiCallbackMetadata::Trampoline Isolate::CreateIsolateLocalFfiCallback(
&ffi_callback_list_head_);
}
// TODO(aam): Should this be in IsolateGroup?
FfiCallbackMetadata::Trampoline Isolate::CreateIsolateGroupBoundFfiCallback(
Zone* zone,
const Function& trampoline,
const Closure& target) {
FfiCallbackMetadata::Trampoline
IsolateGroup::CreateIsolateGroupBoundFfiCallback(Zone* zone,
const Function& trampoline,
const Closure& target) {
return FfiCallbackMetadata::Instance()->CreateLocalFfiCallback(
/*isolate=*/nullptr, group(), zone, trampoline, target,
/*isolate=*/nullptr, this, zone, trampoline, target,
&ffi_callback_list_head_);
}
void IsolateGroup::DeleteFfiCallback(FfiCallbackMetadata::Trampoline callback) {
FfiCallbackMetadata::Instance()->DeleteCallback(callback,
&ffi_callback_list_head_);
}
bool Isolate::HasLivePorts() {
ASSERT(0 <= open_ports_ && 0 <= open_ports_keepalive_ &&
open_ports_keepalive_ <= open_ports_);