mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 21:20:36 +00:00
[standalone] Fix Isolate.spawnUri to work with AOT snapshots.
Fixes missing initialization of dart:_builtin during AOT. Change-Id: If9f24f3658b91f490fc8215f2e9343bd437b2744 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/156050 Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
parent
e41b4c1357
commit
9cb5d8e5be
|
@ -138,16 +138,11 @@ Dart_Handle Loader::ReloadNativeExtensions() {
|
|||
return Dart_True();
|
||||
}
|
||||
|
||||
#if defined(DART_PRECOMPILED_RUNTIME)
|
||||
Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag,
|
||||
Dart_Handle library,
|
||||
Dart_Handle url) {
|
||||
return Dart_Null();
|
||||
}
|
||||
#else
|
||||
#if !defined(DART_PRECOMPILED_RUNTIME)
|
||||
static void MallocFinalizer(void* isolate_callback_data, void* peer) {
|
||||
free(peer);
|
||||
}
|
||||
#endif
|
||||
|
||||
Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag,
|
||||
Dart_Handle library,
|
||||
|
@ -174,6 +169,7 @@ Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag,
|
|||
}
|
||||
return Dart_DefaultCanonicalizeUrl(library_url, url);
|
||||
}
|
||||
#if !defined(DART_PRECOMPILED_RUNTIME)
|
||||
if (tag == Dart_kKernelTag) {
|
||||
uint8_t* kernel_buffer = NULL;
|
||||
intptr_t kernel_buffer_size = 0;
|
||||
|
@ -216,8 +212,10 @@ Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag,
|
|||
}
|
||||
}
|
||||
return DartUtils::NewError("Invalid tag : %d '%s'", tag, url_string);
|
||||
}
|
||||
#else // !defined(DART_PRECOMPILED_RUNTIME)
|
||||
return DartUtils::NewError("Unimplemented tag : %d '%s'", tag, url_string);
|
||||
#endif // !defined(DART_PRECOMPILED_RUNTIME)
|
||||
}
|
||||
|
||||
Dart_Handle Loader::DeferredLoadHandler(intptr_t loading_unit_id) {
|
||||
// A synchronous implementation. An asynchronous implementation would be
|
||||
|
|
|
@ -221,10 +221,8 @@ static bool OnIsolateInitialize(void** child_callback_data, char** error) {
|
|||
if (Dart_IsError(result)) goto failed;
|
||||
|
||||
if (isolate_run_app_snapshot) {
|
||||
if (Dart_IsVMFlagSet("support_service") || !Dart_IsPrecompiledRuntime()) {
|
||||
result = Loader::InitForSnapshot(script_uri, isolate_data);
|
||||
if (Dart_IsError(result)) goto failed;
|
||||
}
|
||||
result = Loader::InitForSnapshot(script_uri, isolate_data);
|
||||
if (Dart_IsError(result)) goto failed;
|
||||
} else {
|
||||
result = DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri));
|
||||
if (Dart_IsError(result)) return result != nullptr;
|
||||
|
@ -333,10 +331,8 @@ static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate,
|
|||
}
|
||||
|
||||
if (isolate_run_app_snapshot) {
|
||||
if (Dart_IsVMFlagSet("support_service") || !Dart_IsPrecompiledRuntime()) {
|
||||
Dart_Handle result = Loader::InitForSnapshot(script_uri, isolate_data);
|
||||
CHECK_RESULT(result);
|
||||
}
|
||||
Dart_Handle result = Loader::InitForSnapshot(script_uri, isolate_data);
|
||||
CHECK_RESULT(result);
|
||||
#if !defined(DART_PRECOMPILED_RUNTIME)
|
||||
if (is_main_isolate) {
|
||||
// Find the canonical uri of the app snapshot. We'll use this to decide if
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
// Verify that using spawnUri to spawn an isolate from app-jit snapshot works.
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'snapshot_test_helper.dart';
|
||||
|
||||
Future<void> main() =>
|
||||
runAppJitTest(Platform.script.resolve('appjit_spawnuri_test_body.dart'),
|
||||
runSnapshot: (snapshotPath) async {
|
||||
final exitPort = ReceivePort();
|
||||
final messagePort = ReceivePort();
|
||||
await Isolate.spawnUri(Uri.file(snapshotPath), [], messagePort.sendPort,
|
||||
onExit: exitPort.sendPort);
|
||||
final result = await Future.wait([messagePort.first, exitPort.first]);
|
||||
print('DONE (${result[0]})');
|
||||
return Result('Isolate.spawnUri(${Uri.file(snapshotPath)})',
|
||||
ProcessResult(0, 0, result[0], ''));
|
||||
});
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
// Verify that using spawnUri to spawn an isolate from app-jit snapshot works.
|
||||
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
int computation(int n) =>
|
||||
List.generate(n, (i) => i == 0 ? 1 : 0).fold(0, (a, b) => a + b);
|
||||
|
||||
Future<void> main(List<String> args, [dynamic sendPort]) async {
|
||||
final isTraining = args.contains('--train');
|
||||
|
||||
var result = 0;
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
result += computation(i);
|
||||
}
|
||||
Expect.equals(999, result);
|
||||
if (isTraining) {
|
||||
print('OK(Trained)');
|
||||
} else {
|
||||
(sendPort as SendPort).send('OK(Run)');
|
||||
}
|
||||
}
|
34
runtime/tests/vm/dart/spawnuri_snapshot_test.dart
Normal file
34
runtime/tests/vm/dart/spawnuri_snapshot_test.dart
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
// Check spawnUri accepts any program format that `dart` accepts. Currently this
|
||||
// is source, kernel, AppJIT (blob container) and AppAOT (ELF).
|
||||
|
||||
import "dart:isolate";
|
||||
import "dart:io";
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
int fib(int n) {
|
||||
if (n <= 1) return 1;
|
||||
return fib(n - 1) + fib(n - 2);
|
||||
}
|
||||
|
||||
main(List<String> args, [dynamic sendPort]) {
|
||||
if (sendPort == null) {
|
||||
print("Parent start");
|
||||
var port = new RawReceivePort();
|
||||
port.handler = (result) {
|
||||
Expect.equals(14930352, result);
|
||||
port.close();
|
||||
print("Parent end");
|
||||
};
|
||||
print("Spawn ${Platform.script}");
|
||||
Isolate.spawnUri(Platform.script, <String>[], port.sendPort);
|
||||
} else {
|
||||
print("Child start");
|
||||
sendPort.send(fib(35));
|
||||
print("Child end");
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
// Verify that using spawnUri to spawn an isolate from app-jit snapshot works.
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'snapshot_test_helper.dart';
|
||||
|
||||
Future<void> main() =>
|
||||
runAppJitTest(Platform.script.resolve('appjit_spawnuri_test_body.dart'),
|
||||
runSnapshot: (snapshotPath) async {
|
||||
final exitPort = ReceivePort();
|
||||
final messagePort = ReceivePort();
|
||||
await Isolate.spawnUri(Uri.file(snapshotPath), [], messagePort.sendPort,
|
||||
onExit: exitPort.sendPort);
|
||||
final result = await Future.wait([messagePort.first, exitPort.first]);
|
||||
print('DONE (${result[0]})');
|
||||
return Result('Isolate.spawnUri(${Uri.file(snapshotPath)})',
|
||||
ProcessResult(0, 0, result[0], ''));
|
||||
});
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
// Verify that using spawnUri to spawn an isolate from app-jit snapshot works.
|
||||
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
int computation(int n) =>
|
||||
List.generate(n, (i) => i == 0 ? 1 : 0).fold(0, (a, b) => a + b);
|
||||
|
||||
Future<void> main(List<String> args, [dynamic sendPort]) async {
|
||||
final isTraining = args.contains('--train');
|
||||
|
||||
var result = 0;
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
result += computation(i);
|
||||
}
|
||||
Expect.equals(999, result);
|
||||
if (isTraining) {
|
||||
print('OK(Trained)');
|
||||
} else {
|
||||
(sendPort as SendPort).send('OK(Run)');
|
||||
}
|
||||
}
|
34
runtime/tests/vm/dart_2/spawnuri_snapshot_test.dart
Normal file
34
runtime/tests/vm/dart_2/spawnuri_snapshot_test.dart
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
// Check spawnUri accepts any program format that `dart` accepts. Currently this
|
||||
// is source, kernel, AppJIT (blob container) and AppAOT (ELF).
|
||||
|
||||
import "dart:isolate";
|
||||
import "dart:io";
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
int fib(int n) {
|
||||
if (n <= 1) return 1;
|
||||
return fib(n - 1) + fib(n - 2);
|
||||
}
|
||||
|
||||
main(List<String> args, [dynamic sendPort]) {
|
||||
if (sendPort == null) {
|
||||
print("Parent start");
|
||||
var port = new RawReceivePort();
|
||||
port.handler = (result) {
|
||||
Expect.equals(14930352, result);
|
||||
port.close();
|
||||
print("Parent end");
|
||||
};
|
||||
print("Spawn ${Platform.script}");
|
||||
Isolate.spawnUri(Platform.script, <String>[], port.sendPort);
|
||||
} else {
|
||||
print("Child start");
|
||||
sendPort.send(fib(35));
|
||||
print("Child end");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue