Skip to content

Commit

Permalink
[vm/bytecode] Wire up bytecode generation in kernel service
Browse files Browse the repository at this point in the history
In order to simplify testing and performance comparison, it is useful to
be able to run a command-line VM with a Dart source and use bytecode pipeline.
The bytecode generation is turned on in kernel service if --enable-interpreter
or --use-bytecode-compiler VM option is specified.

Change-Id: I6eb222b4df1721075c08d5f48c6d299ec779cb8c
Reviewed-on: https://dart-review.googlesource.com/c/80960
Commit-Queue: Alexander Markov <[email protected]>
Reviewed-by: Régis Crelier <[email protected]>
  • Loading branch information
alexmarkov authored and [email protected] committed Oct 22, 2018
1 parent 914065d commit b4fbf1a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
39 changes: 33 additions & 6 deletions pkg/vm/bin/kernel_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -89,6 +91,7 @@ abstract class Compiler {
..packagesFileUri = packagesUri
..sdkSummary = platformKernelPath
..verbose = verbose
..bytecode = bytecode
..onDiagnostic = (DiagnosticMessage message) {
bool printMessage;
switch (message.severity) {
Expand All @@ -114,7 +117,18 @@ abstract class Compiler {
}

Future<Component> 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<Component> compileInternal(Uri script);
Expand All @@ -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<Component> compileInternal(Uri script) async {
Expand All @@ -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<Component> compileInternal(Uri script) async {
Expand All @@ -171,6 +192,7 @@ IncrementalCompilerWrapper lookupIncrementalCompiler(int isolateId) {
Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateId,
List sourceFiles, Uri platformKernelPath, List<int> platformKernel,
{bool suppressWarnings: false,
bool bytecode: false,
String packageConfig: null,
String multirootFilepaths,
String multirootScheme}) async {
Expand All @@ -187,7 +209,9 @@ Future<Compiler> 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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand All @@ -415,6 +441,7 @@ Future _processLoadRequest(request) async {
compiler = new SingleShotCompilerWrapper(fileSystem, platformKernelPath,
requireMain: false,
suppressWarnings: suppressWarnings,
bytecode: bytecode,
packageConfig: packageConfig);
}

Expand Down
22 changes: 12 additions & 10 deletions runtime/vm/kernel_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit b4fbf1a

Please sign in to comment.