Commit Graph

16 Commits

Author SHA1 Message Date
Jens Johansen b32e313620 [vm] Introduce --script_uri_override to support Platform.script in dart run -r
If a script uses `Platform.script` running it with as `dart
<script.dart>` and `dart run <script.dart>` would give the correct
script ("<script.dart>"), but running it with `dart run -r
<script.dart>` would report a dill file in the temp directory which is
not only surprising, but also breaking and for instance running the CFEs
strong_suite.dart via `dart run -r` didn't work.

This CL introduces --script_uri_override to the VM and makes the
resident compiler setup pass it so that when running `dart run -r
<script.dart>`, even though the vm is actually launched from a dill file
that resides in temp, `Platform.script` will actually return
`<script.dart>` - and running the CFEs strong_suite.dart via `dart run
-r` now actually works.

Tested: Added pkg/dartdev/test/commands/run_test.dart and manual testing.
Change-Id: Ia65c01834485fe06af63584baf0448dd5b9ffdb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510343
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2026-06-11 06:34:20 -07:00
Ben Konyi 8d41c9b677 [dartdev] Synchronize environment variable modifications to fix getenv crash
Avoid a race condition between async setenv/unsetenv calls on the VM thread and concurrent getenv/environ reads on the main thread.

In glibc, setenv and getenv are not thread-safe against each other. VmInteropHandler.setEnvironmentVariable previously sent a message to the VM thread to call setenv/unsetenv asynchronously, while the main thread immediately proceeded to access Platform.environment or Platform.localeName (which calls getenv). This could cause a crash (SIGSEGV) in getenv.

This CL makes VmInteropHandler.setEnvironmentVariable synchronous by awaiting a reply from the VM thread before returning.

TEST=pkg/dartdev/test/environment_test.dart

Fixes https://github.com/dart-lang/sdk/issues/63460

Change-Id: Ic8211897ce26ffbdc142fa594cd397189a61f061
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506800
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Auto-Submit: Ben Konyi <bkonyi@google.com>
2026-05-29 10:26:54 -07:00
Ryan Macnak d36adbacaf [vm] Remove the VM isolate.
The former contents of the VM isolate are now included into each isolate group. This makes each isolate group's heap independent, and in particular allows each heap to be allocated to a separate pointer cage (not done in this CL).

The duplicated stubs that allowed PC relative calls are removed, since the originals can now be the target of PC relative calls.

The bootstrapping needing to load an AppJIT or AppAOT snapshot is reduced to allocating the oddballs. The code is entirely dropped in the AOT runtime, but the JIT runtime still has it to allow for flags to affect the compilation of the stub code. Further refactoring might be able to remove this for the JIT runtime too, with only gen_snapshot knowing how to bootstrap.

Class serialization no longer distinguishes predefined classes.

The page containing null is marked as never-evacuate. null, false and true must not move because the compiler relies on their low bits having certain patterns for some optimizations. (Previously, the entire VM isolate heap never moved.)

Compaction is disabled for IA32. Due to register pressure, some stub calls must not use a scratch register and embed the address of Code.

The page containing the call-through-safepoint stub is frozen when running with --write-protect-code and the stub is created at runtime (instead of loaded from an AppJIT or AppAOT snapshot). This stub must remain executable even during a safepoint, as a foreign call might during return during a safepoint and only block after the stub directs it to the runtime.

The snapshot symbols are renamed to kDartSnapshotData and kDartSnapshotText. There is no need to distinguish the VM isolate's snapshot, and snaphots are per isolate group not per isolate. Aliases with the old names are added to ease migration.

Some global flags that were automatically set based on the VM isolate's snapshot are now isolate group flags and automatically set by the isolate group's snapshot.

TEST=ci
Change-Id: Iee82016057d609112e9b021d178fc3d4d18b5044
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500621
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-05-18 11:35:03 -07:00
Ben Konyi c5a57427d1 [ CLI ] Add support for modifying the environment from package:dartdev
This change makes it possible to set environment variables for the
current process from package:dartdev.

As a proof of concept, package:dartdev now sets `DART_ROOT` to the path
of the Dart SDK in the environment.

Related to https://github.com/dart-lang/sdk/issues/63210 and https://github.com/dart-lang/sdk/issues/62876

TEST=pkg/dartdev/test/environment_test.dart
Change-Id: If3a90279e99dadaba435ae3e43a752dcfda69227
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499300
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-05-05 10:03:41 -07:00
Ryan Macnak e7f818b866 [vm, fuchsia] Always look for VmexResource.
TEST=ci
Bug: https://dartbug.com/52579
Change-Id: I856fb8ae5a5bc282471c1ecf3774fc49f7c5b57a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491926
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2026-03-31 19:59:09 -07:00
Ben Konyi f7a049dfb4 [ Service ] Initial implementation of VM Service based on package:dart_runtime_service
This change includes an initial implementation of the new VM service
implementation based on `package:dart_runtime_service`, along with the
necessary plumbing to start it in place of the legacy VM service
implementation.

The entrypoint for the new VM service implementation is located in
dart_runtime_service_vm/bin/vm_service_entrypoint.dart, which is
compiled into AppJIT and AOT snapshots when the
`--include-experimental-vm-service` flag is provided to `build.py`. To run
the VM with the new VM service implementation, the
`--experimental-vm-service` flag must be provided.

Currently, the experimental VM service implementation supports:

  - User specified ports
  - Authentication code flags
  - Enabling the HTTP server via SIGQUIT
  - Some service protocol RPCs that don't require an isolate ID (e.g.,
    `getVM`)

See go/dart-runtime-services-unification for more details.

TEST=Manual

CoreLibraryReviewExempt: dart:_vmservice is private
Change-Id: I4a58cd1fa0a386313baa3d5c5345720231279123
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/484820
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2026-03-10 13:27:01 -07:00
Alexander Aprelev 7cf7000a41 [vm/dartdev] Pass package_config option to spawned executable.
Fixes https://github.com/dart-lang/sdk/issues/62009
TEST=dartdev/run_test

Change-Id: I8fc114268d2f438fc78fa6b32f2d50e4b85cde91
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464660
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-12-01 11:28:58 -08:00
Slava Egorov dec87b98f0 [io] Provide dart::bin::SetupDartIoLibrary
Instead of requiring embedder to initialize dart:io by bits and pieces
by invoking various hooks and setting fields provide a structured C++
API for preparing dart:io for execution.

TEST=ci

CoreLibraryReviewExempt: VM specific changes only
Change-Id: I66e95c0a451d384b4f7582d1df059e506a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454062
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-10-14 13:15:21 -07:00
Jason Simmons 3e36557e3b [VM/dartdev] Escape VM options when running dartdev on Windows
VM options may include flags like --packages that include file paths.

TEST=ci

Bug: https://github.com/flutter/flutter/issues/173716
Change-Id: I0d88f5383a7d2daf27568ccfb5c8f447965592cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445113
Commit-Queue: Jason Simmons <jsimmons@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-08-14 09:50:29 -07:00
Vyacheslav Egorov 66bcc1e08b [dartdev] Fix race in DartDev::RunDartDev
It was checking DartDev::result_ was set to determine if
dartdev is done, however the intent of the code is to
only continue once we receive DartDev_Result_Exit from
dartdev (based on the fact that we only Notify in
ExitResultCallback).

This code was incorrect if we encounter a spurios wakeup:
we might reach RunExecResultCallback but only execute it
partially i.e. set result_ to DartDev_Result_RunExec but
only partially initialize argv_ and argc_, and not yet
initialize script_name_. However at this point we might
spuriously wakeup from our Wait in RunDartDev and think
that we can continue - which means we will hit a crash
once we try to use partially initialized information for
Process::Exec which would cause us to crash.

The bug was discovered based on stack traces provided by
Elliott Brooks (elliottbrooks) which occur on Dev Tools
CI.

TEST=too hard to reliably test this

Change-Id: Ied9cace6bec9505b51ac0142795708466d166f28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445180
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-08-14 05:24:21 -07:00
asiva 6fcb3d394e Fix for https://github.com/dart-lang/sdk/issues/61206
Ensure Platform.executable is not resolved.

TEST=new test case added

Bug: 61206
Change-Id: I0522869f57d519168542b453dc2e827d9d5e6486
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442942
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-08-01 11:11:18 -07:00
asiva ab44b20ab8 Reapply "[VM/dartdev] Switch dartdev to use an AOT runtime." and
Add the fixes that were done after original CL landed.

This reverts commit 97bc401163.

TEST=ci

Change-Id: I26373aecc325e4c0c379c92e779aa301e3a58c5a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441700
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2025-07-24 14:48:03 -07:00
asiva 97bc401163 Revert "[VM/dartdev] Switch dartdev to use an AOT runtime."
This reverts commit 5399dbf6f6.

Reason for revert : Flutter rolls are failing

TEST=ci

Change-Id: I76fede849705514496adbc2ab7f6c262de4103ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439661
Reviewed-by: Jason Simmons <jsimmons@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2025-07-09 23:08:28 -07:00
Siva Annamalai 17fc8b5007 Revert "Ensure executable paths are escaped on the Windows platform."
This reverts commit 49021a8fe8.

Reason for revert: Failure in Flutter roll

Original change's description:
> Ensure executable paths are escaped on the Windows platform.
>
> TEST=ci
>
> Change-Id: Ia6688aaa11d6898b20c92eb3a3a5510213c26d67
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439346
> Commit-Queue: Siva Annamalai <asiva@google.com>
> Reviewed-by: Jason Simmons <jsimmons@google.com>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I2408bb2fbe67c86ce2e57fc3f8c9c71476c82df3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439542
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Jason Simmons <jsimmons@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-07-09 13:28:21 -07:00
asiva 49021a8fe8 Ensure executable paths are escaped on the Windows platform.
TEST=ci

Change-Id: Ia6688aaa11d6898b20c92eb3a3a5510213c26d67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439346
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Jason Simmons <jsimmons@google.com>
2025-07-08 18:00:33 -07:00
asiva 5399dbf6f6 [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 <bkonyi@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-07-04 13:22:13 -07:00