Skip to content

Commit eba0e68

Browse files
mkustermannCommit Queue
authored and
Commit Queue
committed
[vm/ffi] Allow Pointer objects to be shared across isolates
We consider `Pointer` objects as simple value types. We may unbox them in the future to be simple integers - at which point our message sending code wouldn't even know they are pointers anymore. There's therefore no reason to prevent sending them across `SendPort`s. Owners of `Pointer`s may implement `Finalizable` and sending such finalizables across `SendPort`s is prohibited. Closes #50457 TEST=vm/dart/isiolates/fast_object_copy*_test Change-Id: Ia215d119c5bb0e48e2c5dc83cc82e132f46931c1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350822 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Daco Harkes <[email protected]>
1 parent cd53c84 commit eba0e68

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

runtime/tests/vm/dart/isolates/fast_object_copy2_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ final sharableObjects = [
7878
Float32x4(1.0, 2.0, 3.0, 4.0),
7979
Float64x2(1.0, 2.0),
8080
StackTrace.current,
81+
Pointer<Int8>.fromAddress(0xdeadbeef),
8182
];
8283

8384
final copyableClosures = <dynamic>[

runtime/tests/vm/dart/isolates/fast_object_copy_test.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ class SendReceiveTest extends SendReceiveTestBase {
257257
await testFinalizer();
258258
await testNativeFinalizer();
259259
await testFinalizable();
260-
await testPointer();
261260

262261
await testForbiddenClosures();
263262
}
@@ -791,13 +790,6 @@ class SendReceiveTest extends SendReceiveTestBase {
791790
Expect.throwsArgumentError(() => sendPort.send(finalizable));
792791
}
793792

794-
Future testPointer() async {
795-
print('testPointer');
796-
797-
final pointer = Pointer<Int8>.fromAddress(0xdeadbeef);
798-
Expect.throwsArgumentError(() => sendPort.send(pointer));
799-
}
800-
801793
Future testForbiddenClosures() async {
802794
print('testForbiddenClosures');
803795
for (final closure in nonCopyableClosures) {

runtime/vm/class_id.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ inline bool ShouldHaveImmutabilityBitSet(intptr_t index) {
433433
index == kFloat32x4Cid || index == kFloat64x2Cid ||
434434
index == kInt32x4Cid || index == kSendPortCid ||
435435
index == kCapabilityCid || index == kRegExpCid || index == kBoolCid ||
436-
index == kNullCid;
436+
index == kNullCid || index == kPointerCid;
437437
}
438438

439439
inline bool IsFfiTypeClassId(intptr_t index) {

tests/ffi/snapshot_test.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ import 'dart:isolate';
1010

1111
import 'package:expect/expect.dart';
1212

13+
class Foo implements Finalizable {
14+
final Pointer<Void> value;
15+
Foo(this.value);
16+
}
17+
1318
main(args) async {
1419
try {
15-
await Isolate.spawn(print, Pointer<Void>.fromAddress(1));
20+
await Isolate.spawn(print, Foo(Pointer<Void>.fromAddress(1)));
1621
} catch (e) {
1722
Expect.type<ArgumentError>(e);
1823
return;

0 commit comments

Comments
 (0)