Files
sdk/tests/lib/isolate/vm_rehash_test.dart
T
Alexander Aprelev 6b3abe0a98 [vm/concurrency] Add --experimental_enable_isolate_groups_jit flag, make --enable_isolate_groups AOT only.
Issue b/177800357.

TEST=existing test suite
Change-Id: Id6b113932ab7014b8fa6c105845c5c490b60f5e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181320
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-01-27 17:11:29 +00:00

63 lines
1.5 KiB
Dart

// Copyright (c) 2017, 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=--enable-isolate-groups --experimental-enable-isolate-groups-jit
// VMOptions=--no-enable-isolate-groups
import 'dart:async';
import 'dart:isolate';
int globalHash = 0;
class A {
int get hashCode => globalHash;
bool operator ==(other) => true;
}
final key = new A();
other(SendPort sendPort) async {
// We use a different hash than the main isolate, but the re-hashing on our
// side happens after this line and should therefore also deserialize the map
// with a new hash, so we should be able to find the value in the map.
globalHash = 4321;
final port = new ReceivePort();
sendPort.send(port.sendPort);
final Map map = await port.first;
sendPort.send(map[key]);
port.close();
}
void launchIsolate(argument) {
other(argument);
}
main() async {
final r = new ReceivePort();
final re = new ReceivePort();
final map = {};
globalHash = 1234;
map[key] = 1;
await Isolate.spawn(launchIsolate, r.sendPort, onError: re.sendPort);
re.listen((error) => throw 'Error $error');
final it = new StreamIterator(r);
await it.moveNext();
final SendPort port = it.current;
port.send(map);
await it.moveNext();
final otherIsolateMapEntry = await it.current;
if (map[key] != otherIsolateMapEntry) {
throw "test failed";
}
r.close();
re.close();
}