Skip to content

Commit b7909e1

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[vm/concurrency] Allow StackTrace objects to be shared
The existing lib/isolate/stacktrace_message_test was failing and also incorrectly written due to "!" in front of the expected stringification of the stacktrace. Issue #46623 TEST=vm/dart{,_2}/isolates/fast_object_copy2_test, lib{,_2}/isolate/stacktrace_message_test Change-Id: I169d8fd7a7c3cb3b8c57e00287565e3a5c622acf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216041 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent 9c10d2b commit b7909e1

File tree

6 files changed

+46
-56
lines changed

6 files changed

+46
-56
lines changed

runtime/lib/isolate.cc

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,30 @@ static ObjectPtr ValidateMessageObject(Zone* zone,
205205
ObjectPtr raw = working_set.RemoveLast();
206206

207207
const intptr_t cid = raw->GetClassId();
208-
// Keep the list in sync with the one in message_snapshot.cc
208+
// Keep the list in sync with the one in runtime/vm/object_graph_copy.cc
209209
switch (cid) {
210+
// Can be shared.
211+
case kOneByteStringCid:
212+
case kTwoByteStringCid:
213+
case kExternalOneByteStringCid:
214+
case kExternalTwoByteStringCid:
215+
case kMintCid:
216+
case kImmutableArrayCid:
217+
case kNeverCid:
218+
case kSentinelCid:
219+
case kInt32x4Cid:
220+
case kSendPortCid:
221+
case kCapabilityCid:
210222
case kRegExpCid:
211-
// Can be shared, need to be explicitly listed to prevent inspection.
223+
case kStackTraceCid:
212224
continue;
225+
// Cannot be shared due to possibly being mutable boxes for unboxed
226+
// fields in JIT, but can be transferred via Isolate.exit()
227+
case kDoubleCid:
228+
case kFloat32x4Cid:
229+
case kFloat64x2Cid:
230+
continue;
231+
213232
case kClosureCid:
214233
closure ^= raw;
215234
// Only context has to be checked.
@@ -223,15 +242,12 @@ static ObjectPtr ValidateMessageObject(Zone* zone,
223242
error_found = true; \
224243
break;
225244

226-
MESSAGE_SNAPSHOT_ILLEGAL(FunctionType);
245+
MESSAGE_SNAPSHOT_ILLEGAL(DynamicLibrary);
227246
MESSAGE_SNAPSHOT_ILLEGAL(MirrorReference);
247+
MESSAGE_SNAPSHOT_ILLEGAL(Pointer);
228248
MESSAGE_SNAPSHOT_ILLEGAL(ReceivePort);
229-
MESSAGE_SNAPSHOT_ILLEGAL(StackTrace);
230249
MESSAGE_SNAPSHOT_ILLEGAL(UserTag);
231250

232-
MESSAGE_SNAPSHOT_ILLEGAL(DynamicLibrary);
233-
MESSAGE_SNAPSHOT_ILLEGAL(Pointer);
234-
235251
default:
236252
if (cid >= kNumPredefinedCids) {
237253
klass = class_table->At(cid);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ final sharableObjects = [
7676
RegExp('a'),
7777
Isolate.current.pauseCapability,
7878
Int32x4(1, 2, 3, 4),
79+
StackTrace.current,
7980
];
8081

8182
final copyableClosures = <dynamic>[

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ final sharableObjects = [
7777
RegExp('a'),
7878
Isolate.current.pauseCapability,
7979
Int32x4(1, 2, 3, 4),
80+
StackTrace.current,
8081
];
8182

8283
final copyableClosures = <dynamic>[

runtime/vm/object_graph_copy.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ static ObjectPtr Marker() {
136136
return Object::unknown_constant().ptr();
137137
}
138138

139+
// Keep in sync with runtime/lib/isolate.cc:ValidateMessageObject
139140
DART_FORCE_INLINE
140141
static bool CanShareObject(ObjectPtr obj, uword tags) {
141142
if ((tags & UntaggedObject::CanonicalBit::mask_in_place()) != 0) {
@@ -150,6 +151,7 @@ static bool CanShareObject(ObjectPtr obj, uword tags) {
150151
if (cid == kImmutableArrayCid) return true;
151152
if (cid == kNeverCid) return true;
152153
if (cid == kSentinelCid) return true;
154+
if (cid == kStackTraceCid) return true;
153155
#if defined(DART_PRECOMPILED_RUNTIME)
154156
// In JIT mode we have field guards enabled which means
155157
// double/float32x4/float64x2 boxes can be mutable and we therefore cannot
@@ -590,11 +592,9 @@ class ObjectCopyBase {
590592
// those are the only non-abstract classes (so we avoid checking more cids
591593
// here that cannot happen in reality)
592594
HANDLE_ILLEGAL_CASE(DynamicLibrary)
593-
HANDLE_ILLEGAL_CASE(Pointer)
594-
HANDLE_ILLEGAL_CASE(FunctionType)
595595
HANDLE_ILLEGAL_CASE(MirrorReference)
596+
HANDLE_ILLEGAL_CASE(Pointer)
596597
HANDLE_ILLEGAL_CASE(ReceivePort)
597-
HANDLE_ILLEGAL_CASE(StackTrace)
598598
HANDLE_ILLEGAL_CASE(UserTag)
599599
default:
600600
return true;

tests/lib/isolate/stacktrace_message_test.dart

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,26 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:isolate';
6+
67
import "package:expect/expect.dart";
7-
import "package:async_helper/async_helper.dart";
88

99
// Test that StackTrace objects can be sent between isolates spawned from
1010
// the same isolate using Isolate.spawn.
1111

12-
void main() {
13-
asyncStart();
14-
ReceivePort reply = new ReceivePort();
12+
void main() async {
13+
final reply = ReceivePort();
1514
Isolate.spawn(runTest, reply.sendPort);
16-
reply.first.then((pair) {
17-
StackTrace? stack = pair[0];
18-
String stackString = pair[1];
19-
if (stack == null) {
20-
print("Failed to send stack-trace");
21-
print(stackString);
22-
Expect.fail("Sending stack-trace");
23-
}
24-
Expect.equals(stackString, "!$stack");
25-
print(stack);
26-
asyncEnd();
27-
});
15+
final pair = await reply.first;
16+
final stack = pair[0] as StackTrace;
17+
final stackString = pair[1] as String;
18+
Expect.isNotNull(stack);
19+
Expect.equals(stackString, "$stack");
2820
}
2921

3022
runTest(SendPort sendport) {
3123
try {
3224
throw 'sorry';
3325
} catch (e, stack) {
34-
try {
35-
sendport.send([stack, "$stack"]);
36-
print("Stacktrace sent");
37-
} catch (e, s) {
38-
print("Stacktrace not sent");
39-
sendport.send([null, "$e\n$s"]);
40-
}
26+
sendport.send([stack, "$stack"]);
4127
}
4228
}

tests/lib_2/isolate/stacktrace_message_test.dart

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,26 @@
55
// @dart = 2.9
66

77
import 'dart:isolate';
8+
89
import "package:expect/expect.dart";
9-
import "package:async_helper/async_helper.dart";
1010

1111
// Test that StackTrace objects can be sent between isolates spawned from
1212
// the same isolate using Isolate.spawn.
1313

14-
void main() {
15-
asyncStart();
16-
ReceivePort reply = new ReceivePort();
14+
void main() async {
15+
final reply = ReceivePort();
1716
Isolate.spawn(runTest, reply.sendPort);
18-
reply.first.then((pair) {
19-
StackTrace stack = pair[0];
20-
String stackString = pair[1];
21-
if (stack == null) {
22-
print("Failed to send stack-trace");
23-
print(stackString);
24-
Expect.fail("Sending stack-trace");
25-
}
26-
Expect.equals(stackString, "!$stack");
27-
print(stack);
28-
asyncEnd();
29-
});
17+
final pair = await reply.first;
18+
final stack = pair[0] as StackTrace;
19+
final stackString = pair[1] as String;
20+
Expect.isNotNull(stack);
21+
Expect.equals(stackString, "$stack");
3022
}
3123

3224
runTest(SendPort sendport) {
3325
try {
3426
throw 'sorry';
3527
} catch (e, stack) {
36-
try {
37-
sendport.send([stack, "$stack"]);
38-
print("Stacktrace sent");
39-
} catch (e, s) {
40-
print("Stacktrace not sent");
41-
sendport.send([null, "$e\n$s"]);
42-
}
28+
sendport.send([stack, "$stack"]);
4329
}
4430
}

0 commit comments

Comments
 (0)