Skip to content

Commit 5399dbf

Browse files
a-sivaCommit Queue
authored andcommitted
[VM/dartdev] Switch dartdev to use an AOT runtime.
- split the Dart CLI tool out of the VM into it's own embedder which runs in AOT mode. The pure Dart VM executable is called 'dartvm' and has no Dart CLI functionality in it - the Dart CLI executable parses the CLI commands and invokes the rest of the AOT tools in the same process, for the 'run' and 'test' commands it execs a process which runs 'dartvm' to run - 'dart hello.dart' execs the 'dartvm' process and runs 'hello.dart' - the Dart CLI is not generated for ia32 as we are not shipping a Dart SDK for ia32 anymore (support to execute the 'dartvm' for ia32 architecture is retained) - the Dart CLI tool is not built in the internal Dart SDK builds TEST=ci Some performance improvement numbers 'dart format pkg/dartdev' goes from 1.17 secs to 0.22 secs 'dart doc pkg/dartdev' goes from 100.2 secs to 66.6 secs 'dart fix pkg/dartdev' goes from 19.3 secs to 14.5 secs Change-Id: I66984a26cb2ab014b34dc1873f1f3d2884e13518 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364202 Commit-Queue: Ben Konyi <[email protected]> Reviewed-by: Ben Konyi <[email protected]>
1 parent e86b736 commit 5399dbf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2641
-1690
lines changed

BUILD.gn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ group("runtime") {
4242

4343
deps = [
4444
"runtime/bin:dart",
45+
"runtime/bin:dartvm",
4546
"runtime/bin:ffi_test_dynamic_library",
4647
"runtime/bin:ffi_test_functions",
4748
"runtime/bin:process_test",
@@ -60,12 +61,15 @@ group("runtime") {
6061
deps += [
6162
"runtime/bin:dartaotruntime",
6263
"runtime/bin:dartaotruntime_product",
64+
"utils/dartdev:dartdev_aot_snapshot",
6365
"utils/dds:dds_aot",
66+
"utils/dtd:dtd_aot",
6467
"utils/kernel-service:frontend_server_aot_product",
6568
]
6669
} else {
6770
deps += [
6871
"utils/dds:dds",
72+
"utils/dtd:dtd",
6973
"utils/kernel-service:frontend_server",
7074
]
7175
}
@@ -420,7 +424,7 @@ if (is_fuchsia) {
420424
}
421425

422426
test_binaries = [
423-
"dart",
427+
"dartvm",
424428
"dartaotruntime",
425429
"run_vm_tests",
426430
]

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ constraint][language version] lower bound to 3.9 or greater (`sdk: '^3.9.0'`).
7575
Container<dynamic>().value('Invocation with missing runtime checks!');
7676
```
7777

78+
#### Dart CLI and Dart VM
79+
80+
- The Dart CLI and Dart VM have been split into two seperate executables.
81+
82+
The Dart CLI tool has been split out of the VM into it's own embedder which
83+
runs in AOT mode. The pure Dart VM executable is called `dartvm` and
84+
has no Dart CLI functionality in it
85+
86+
The Dart CLI executable parses the CLI commands and invokes the rest
87+
of the AOT tools in the same process, for the 'run' and 'test'
88+
commands it execs a process which runs `dartvm`
89+
90+
`dart hello.dart` execs the `dartvm` process and runs 'hello.dart'
91+
92+
The Dart CLI is not generated for ia32 as we are not shipping a
93+
Dart SDK for ia32 anymore (support to execute the `dartvm` for ia32
94+
architecture is retained)
95+
96+
7897
#### Pub
7998

8099
- Git dependencies can now be version-solved based on git tags.

build/dart/dart_action.gni

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import("../executable_suffix.gni")
1010
# - prebuilt_dart_action()
1111
# Runs Dart scripts using the downloaded prebuilt Dart SDK. This is the
1212
# preferred method of running Dart code during the build as it is much
13-
# faster than using dart_action() in debug and cross builds.
13+
# faster than using dartvm_action() in debug and cross builds.
1414
# However, prebuilt_dart_action() should *not* be used to generate snapshots.
1515
#
1616
# - prebuilt_dartaotruntime_action()
1717
# Runs Dart AOT snapshots using the downloaded prebuilt Dart SDK. This is the
1818
# preferred method of running Dart AOT code during the build as it avoids
1919
# the multiple layers of code that prebuilt_dart_action goes through.
2020
#
21-
# - dart_action()
21+
# - dartvm_action()
2222
# Runs Dart scripts using the binary built for runtime/bin:dart using the
2323
# host toolchain. It should only be used when an artifact agreeing exactly
2424
# with the version of the Dart VM being built must be produced, for example
@@ -350,10 +350,10 @@ template("_built_tool_action") {
350350
# outputs
351351
# testonly
352352
# visibility
353-
template("dart_action") {
353+
template("dartvm_action") {
354354
assert(defined(invoker.script), "script must be defined for $target_name")
355355
_built_tool_action(target_name) {
356-
tool = "$_dart_root/runtime/bin:dart"
356+
tool = "$_dart_root/runtime/bin:dartvm"
357357
forward_variables_from(invoker,
358358
[
359359
"args",

build/rbe/rewrapper_dart.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ def parse_rewrapper(self):
269269
elif arg.endswith('/dart'):
270270
self.dart_subdir = os.path.dirname(arg)
271271
return self.parse_dart()
272+
elif arg.endswith('/dartvm'):
273+
self.dart_subdir = os.path.dirname(arg)
274+
return self.parse_dart()
272275
elif arg.endswith('/dartaotruntime'):
273276
self.dart_subdir = os.path.dirname(arg)
274277
return self.parse_dartaotruntime()

pkg/analysis_server/integration_test/analysis/get_errors_non_standard_sdk_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class AnalysisDomainGetErrorsTest
2727
return path.join(sdkPath, 'bin', name);
2828
}
2929

30+
String executableVmFilePathIn(String sdkPath) {
31+
var name = Platform.isWindows ? 'dartvm.exe' : 'dartvm';
32+
return path.join(sdkPath, 'bin', name);
33+
}
34+
3035
String serverSnapshotPathIn(String sdkPath) {
3136
return path.join(
3237
sdkPath,
@@ -50,6 +55,10 @@ class AnalysisDomainGetErrorsTest
5055
executableFilePathIn(standardSdkPath),
5156
).copySync(executableFilePathIn(sdkPath));
5257

58+
File(
59+
executableVmFilePathIn(standardSdkPath),
60+
).copySync(executableVmFilePathIn(sdkPath));
61+
5362
File(
5463
serverSnapshotPathIn(standardSdkPath),
5564
).copySync(serverSnapshotPathIn(sdkPath));

pkg/dartdev/lib/src/commands/compile.dart

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,12 @@ class CompileJSCommand extends CompileSubcommandCommand {
9898
}
9999
final args = argResults!;
100100
var snapshot = sdk.dart2jsAotSnapshot;
101-
var script = sdk.dartAotRuntime;
102-
var useExecProcess = true;
103101
if (!Sdk.checkArtifactExists(snapshot, logError: false)) {
104-
// AOT snapshots cannot be generated on IA32, so we need this fallback
105-
// branch until support for IA32 is dropped (https://dartbug.com/49969).
106-
script = sdk.dart2jsSnapshot;
107-
if (!Sdk.checkArtifactExists(script)) {
108-
return genericErrorExitCode;
109-
}
110-
useExecProcess = false;
102+
log.stderr('Error: JS compilation failed');
103+
log.stderr('Unable to find $snapshot');
104+
return compileErrorExitCode;
111105
}
112106
final dart2jsCommand = [
113-
if (useExecProcess) snapshot,
114107
'--libraries-spec=${sdk.librariesJson}',
115108
'--cfe-invocation-modes=compile',
116109
'--invoker=dart_cli',
@@ -119,10 +112,10 @@ class CompileJSCommand extends CompileSubcommandCommand {
119112
];
120113
try {
121114
VmInteropHandler.run(
122-
script,
115+
snapshot,
123116
dart2jsCommand,
124117
packageConfigOverride: null,
125-
useExecProcess: useExecProcess,
118+
useExecProcess: false,
126119
);
127120
return 0;
128121
} catch (e, st) {
@@ -163,28 +156,21 @@ class CompileDDCCommand extends CompileSubcommandCommand {
163156
}
164157
final args = argResults!;
165158
var snapshot = sdk.ddcAotSnapshot;
166-
var script = sdk.dartAotRuntime;
167-
var useExecProcess = true;
168159
if (!Sdk.checkArtifactExists(snapshot, logError: false)) {
169-
// AOT snapshots cannot be generated on IA32, so we need this fallback
170-
// branch until support for IA32 is dropped (https://dartbug.com/49969).
171-
script = sdk.ddcSnapshot;
172-
if (!Sdk.checkArtifactExists(script)) {
173-
return genericErrorExitCode;
174-
}
175-
useExecProcess = false;
160+
log.stderr('Error: JS compilation failed');
161+
log.stderr('Unable to find $snapshot');
162+
return compileErrorExitCode;
176163
}
177164
final ddcCommand = <String>[
178-
if (useExecProcess) snapshot,
179165
// Add the remaining arguments.
180166
if (args.rest.isNotEmpty) ...args.rest.sublist(0),
181167
];
182168
try {
183169
VmInteropHandler.run(
184-
script,
170+
snapshot,
185171
ddcCommand,
186172
packageConfigOverride: null,
187-
useExecProcess: useExecProcess,
173+
useExecProcess: false,
188174
);
189175
return 0;
190176
} catch (e, st) {
@@ -459,7 +445,7 @@ class CompileJitSnapshotCommand extends CompileSubcommandCommand {
459445

460446
log.stdout('Compiling $sourcePath to jit-snapshot file $outputFile.');
461447
// TODO(bkonyi): perform compilation in same process.
462-
return await runProcess([sdk.dart, ...buildArgs]);
448+
return await runProcess([sdk.dartvm, ...buildArgs]);
463449
}
464450
}
465451

pkg/dartdev/lib/src/commands/dart_mcp_server.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ A stdio based Model Context Protocol (MCP) server to aid in Dart and Flutter dev
5151
}
5252
try {
5353
VmInteropHandler.run(
54-
sdk.dartAotRuntime,
54+
sdk.dartMCPServerAotSnapshot,
5555
[
56-
sdk.dartMCPServerAotSnapshot,
5756
...forwardedArgs,
5857
],
59-
useExecProcess: true,
58+
useExecProcess: false,
6059
);
6160
return 0;
6261
} catch (e, st) {

pkg/dartdev/lib/src/commands/development_service.dart

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

55
import 'dart:async';
6-
import 'dart:io';
76

87
import 'package:dds/src/arg_parser.dart';
98
import 'package:path/path.dart';
@@ -37,38 +36,22 @@ class DevelopmentServiceCommand extends DartdevCommand {
3736
Future<int> run() async {
3837
final sdkDir = dirname(sdk.dart);
3938
final fullSdk = sdkDir.endsWith('bin');
40-
var script = fullSdk
41-
? sdk.dartAotRuntime
42-
: absolute(sdkDir, 'dartaotruntime${Platform.isWindows ? '.exe' : ''}');
4339
var snapshot = fullSdk
4440
? sdk.ddsAotSnapshot
4541
: absolute(sdkDir, 'dds_aot.dart.snapshot');
46-
var useExecProcess = true;
4742
final args = argResults!.arguments;
4843

4944
if (!Sdk.checkArtifactExists(snapshot, logError: false)) {
50-
// On ia32 platforms we do not have an AOT snapshot and so we need
51-
// to run the JIT snapshot.
52-
useExecProcess = false;
53-
script =
54-
fullSdk ? sdk.ddsSnapshot : absolute(sdkDir, 'dds.dart.snapshot');
55-
if (!Sdk.checkArtifactExists(script, logError: false)) {
56-
log.stderr('Error: launching development server failed : '
57-
'Unable to find snapshot for the development server');
58-
return 255;
59-
}
45+
log.stderr('Error: launching development server failed : '
46+
'Unable to find snapshot for the development server');
47+
return 255;
6048
}
61-
final ddsCommand = [
62-
if (useExecProcess) snapshot,
63-
// Add the remaining args.
64-
if (args.isNotEmpty) ...args,
65-
];
6649
try {
6750
VmInteropHandler.run(
68-
script,
69-
ddsCommand,
51+
snapshot,
52+
args,
7053
packageConfigOverride: null,
71-
useExecProcess: useExecProcess,
54+
useExecProcess: false,
7255
);
7356
return 0;
7457
} catch (e, st) {

pkg/dartdev/lib/src/commands/language_server.dart

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,35 @@ For more information about the server's capabilities and configuration, see:
5454
args = [...args, '--$protocol=$lsp'];
5555
}
5656
try {
57+
var script = sdk.analysisServerAotSnapshot;
58+
var useExec = false;
5759
if (argResults!.flag(useAotSnapshotFlag)) {
58-
if (!Sdk.checkArtifactExists(sdk.dartAotRuntime)) {
60+
if (!Sdk.checkArtifactExists(sdk.analysisServerAotSnapshot)) {
61+
log.stderr('Error: launching language analysis server failed');
62+
log.stderr('${sdk.analysisServerAotSnapshot} not found');
5963
return _genericErrorExitCode;
6064
}
6165
args = [...args];
6266
args.remove('--$useAotSnapshotFlag');
63-
VmInteropHandler.run(
64-
sdk.dartAotRuntime,
65-
[sdk.analysisServerAotSnapshot, ...args],
66-
useExecProcess: true,
67-
);
6867
} else {
6968
args = [...args];
7069
args.remove('--no-$useAotSnapshotFlag');
71-
VmInteropHandler.run(
72-
sdk.analysisServerSnapshot,
73-
args,
74-
useExecProcess: false,
75-
);
70+
script = sdk.analysisServerSnapshot;
71+
useExec = true;
7672
}
73+
VmInteropHandler.run(
74+
script,
75+
args,
76+
useExecProcess: useExec,
77+
);
7778
return 0;
7879
} catch (e, st) {
7980
log.stderr('Error: launching language analysis server failed');
8081
log.stderr(e.toString());
8182
if (verbose) {
8283
log.stderr(st.toString());
8384
}
84-
return 255;
85+
return _genericErrorExitCode;
8586
}
8687
}
8788

0 commit comments

Comments
 (0)