diff --git a/pkg/vm/bin/kernel_service.dart b/pkg/vm/bin/kernel_service.dart index 7f9d55f95b411..01d4c2c61fff5 100644 --- a/pkg/vm/bin/kernel_service.dart +++ b/pkg/vm/bin/kernel_service.dart @@ -30,7 +30,9 @@ import 'package:build_integration/file_system/multi_root.dart'; import 'package:front_end/src/api_unstable/vm.dart'; import 'package:kernel/kernel.dart' show Component, Procedure; import 'package:kernel/target/targets.dart' show TargetFlags; +import 'package:vm/bytecode/gen_bytecode.dart' show generateBytecode; import 'package:vm/incremental_compiler.dart'; +import 'package:vm/kernel_front_end.dart' show runWithFrontEndCompilerContext; import 'package:vm/http_filesystem.dart'; import 'package:vm/target/vm.dart' show VmTarget; @@ -67,7 +69,7 @@ abstract class Compiler { Compiler(this.fileSystem, Uri platformKernelPath, {bool suppressWarnings: false, - bool syncAsync: false, + bool bytecode: false, String packageConfig: null}) { Uri packagesUri = null; if (packageConfig != null) { @@ -89,6 +91,7 @@ abstract class Compiler { ..packagesFileUri = packagesUri ..sdkSummary = platformKernelPath ..verbose = verbose + ..bytecode = bytecode ..onDiagnostic = (DiagnosticMessage message) { bool printMessage; switch (message.severity) { @@ -114,7 +117,18 @@ abstract class Compiler { } Future compile(Uri script) { - return runWithPrintToStderr(() => compileInternal(script)); + return runWithPrintToStderr(() async { + final component = await compileInternal(script); + + if (options.bytecode && errors.isEmpty) { + await runWithFrontEndCompilerContext(script, options, component, () { + // TODO(alexmarkov): pass environment defines + generateBytecode(component); + }); + } + + return component; + }); } Future compileInternal(Uri script); @@ -124,9 +138,13 @@ class IncrementalCompilerWrapper extends Compiler { IncrementalCompiler generator; IncrementalCompilerWrapper(FileSystem fileSystem, Uri platformKernelPath, - {bool suppressWarnings: false, String packageConfig: null}) + {bool suppressWarnings: false, + bool bytecode: false, + String packageConfig: null}) : super(fileSystem, platformKernelPath, - suppressWarnings: suppressWarnings, packageConfig: packageConfig); + suppressWarnings: suppressWarnings, + bytecode: bytecode, + packageConfig: packageConfig); @override Future compileInternal(Uri script) async { @@ -147,9 +165,12 @@ class SingleShotCompilerWrapper extends Compiler { SingleShotCompilerWrapper(FileSystem fileSystem, Uri platformKernelPath, {this.requireMain: false, bool suppressWarnings: false, + bool bytecode: false, String packageConfig: null}) : super(fileSystem, platformKernelPath, - suppressWarnings: suppressWarnings, packageConfig: packageConfig); + suppressWarnings: suppressWarnings, + bytecode: bytecode, + packageConfig: packageConfig); @override Future compileInternal(Uri script) async { @@ -171,6 +192,7 @@ IncrementalCompilerWrapper lookupIncrementalCompiler(int isolateId) { Future lookupOrBuildNewIncrementalCompiler(int isolateId, List sourceFiles, Uri platformKernelPath, List platformKernel, {bool suppressWarnings: false, + bool bytecode: false, String packageConfig: null, String multirootFilepaths, String multirootScheme}) async { @@ -187,7 +209,9 @@ Future lookupOrBuildNewIncrementalCompiler(int isolateId, // isolate needs to receive a message indicating that particular // isolate was shut down. Message should be handled here in this script. compiler = new IncrementalCompilerWrapper(fileSystem, platformKernelPath, - suppressWarnings: suppressWarnings, packageConfig: packageConfig); + suppressWarnings: suppressWarnings, + bytecode: bytecode, + packageConfig: packageConfig); isolateCompilers[isolateId] = compiler; } return compiler; @@ -353,6 +377,7 @@ Future _processLoadRequest(request) async { final int isolateId = request[6]; final List sourceFiles = request[7]; final bool suppressWarnings = request[8]; + final bool bytecode = request[9]; final String packageConfig = request[10]; final String multirootFilepaths = request[11]; final String multirootScheme = request[12]; @@ -406,6 +431,7 @@ Future _processLoadRequest(request) async { compiler = await lookupOrBuildNewIncrementalCompiler( isolateId, sourceFiles, platformKernelPath, platformKernel, suppressWarnings: suppressWarnings, + bytecode: bytecode, packageConfig: packageConfig, multirootFilepaths: multirootFilepaths, multirootScheme: multirootScheme); @@ -415,6 +441,7 @@ Future _processLoadRequest(request) async { compiler = new SingleShotCompilerWrapper(fileSystem, platformKernelPath, requireMain: false, suppressWarnings: suppressWarnings, + bytecode: bytecode, packageConfig: packageConfig); } diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc index 02f38c880726a..c56df9bed2d7e 100644 --- a/runtime/vm/kernel_isolate.cc +++ b/runtime/vm/kernel_isolate.cc @@ -448,10 +448,6 @@ class KernelCompilationRequest : public ValueObject { suppress_warnings.type = Dart_CObject_kBool; suppress_warnings.value.as_bool = FLAG_suppress_fe_warnings; - Dart_CObject dart_sync_async; - dart_sync_async.type = Dart_CObject_kBool; - dart_sync_async.value.as_bool = FLAG_sync_async; - Dart_CObject* message_arr[] = {&tag, &send_port, &isolate_id, @@ -461,8 +457,7 @@ class KernelCompilationRequest : public ValueObject { &library_uri_object, &class_object, &is_static_object, - &suppress_warnings, - &dart_sync_async}; + &suppress_warnings}; message.value.as_array.values = message_arr; message.value.as_array.length = ARRAY_SIZE(message_arr); // Send the message. @@ -568,9 +563,16 @@ class KernelCompilationRequest : public ValueObject { suppress_warnings.type = Dart_CObject_kBool; suppress_warnings.value.as_bool = FLAG_suppress_fe_warnings; - Dart_CObject dart_sync_async; - dart_sync_async.type = Dart_CObject_kBool; - dart_sync_async.value.as_bool = FLAG_sync_async; + Dart_CObject bytecode; + bytecode.type = Dart_CObject_kBool; + // Interpreter is supported only on x64 and arm64. +#if defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_ARM64) + bytecode.value.as_bool = + FLAG_enable_interpreter || FLAG_use_bytecode_compiler; +#else + bytecode.value.as_bool = + FLAG_use_bytecode_compiler && !FLAG_enable_interpreter; +#endif Dart_CObject package_config_uri; if (package_config != NULL) { @@ -616,7 +618,7 @@ class KernelCompilationRequest : public ValueObject { &isolate_id, &files, &suppress_warnings, - &dart_sync_async, + &bytecode, &package_config_uri, &multiroot_filepaths_object, &multiroot_scheme_object};