Commit Graph

262 Commits

Author SHA1 Message Date
Tony 57b27a7b44 Refactor Dart runtime to replace DART_DYNAMIC_MODULES with DART_BYTECODE_INTERPRETER
- Updated conditional compilation flags throughout the runtime codebase to transition from DART_DYNAMIC_MODULES to DART_BYTECODE_INTERPRETER.
- Adjusted logic in various files including object_graph_copy.cc, object_reload.cc, profiler.cc, and others to ensure compatibility with the new interpreter model.
- Ensured that all references to dynamic modules are replaced with bytecode interpreter checks, maintaining functionality for interpreted code execution.
- Modified stack frame handling and service-related code to align with the new interpreter architecture.
- Updated tests and service implementations to reflect the changes in the runtime environment.

Signed-off-by: Tony <tonylu@tony-cloud.com>
2026-06-25 01:58:41 +08:00
Tony 08139af589 Add compact AOT patching support and related APIs
- Introduced Dart_SetObfuscationMap to restore obfuscation maps before AOT precompilation.
- Added Dart_AotPatchInstallOptions structure for AOT patch installation options.
- Implemented Dart_AotPatchingEnabled to check if compact AOT patching is supported.
- Created Dart_SetAotPatchKeyCallback for AES key resolution during AOT patch installation.
- Developed Dart_InstallAotPatch for validating and installing encrypted AOT patches.
- Added Dart_FreeAotPatchPayload to free memory allocated for patch payloads.
- Updated runtime_args.gni to include dart_enable_aot_patching flag.
- Added tests for AOT patching functionality and ensured exported symbols include new APIs.
- Refactored existing code to accommodate new AOT patching features and improve error handling.
2026-06-24 03:00:14 +08:00
Tess Strickland 7cd8fda37e [vm] Use Uint32Arrays for coverage arrays.
Also load/store canonical hashes in the heap for non-empty TypedData
instances in the same manner as canonical hashes for Arrays.

TEST=ci (refactoring only)

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try
Change-Id: I54274b558fa9f0c8e304198b18cb3f0e9c3e0dfb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504600
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2026-05-27 08:18:27 -07:00
Tess Strickland 52cfd29cbb [vm,dynamic_modules] Add RecordCoverage instruction.
The RecordCoverage instruction has an A/E encoding. The A argument
is the type of coverage being recorded, whereas the E argument is
the logical index into the coverage array for updating whether that
source position has been hit.

Also adds new metadata to the bytecode component for the coverage
arrays associated with bytecode containing RecordCoverage instructions
and a new runtime entry for lazily allocate the coverage array for
an interpreted function when needed.

The type of coverage is encoded in the RecordCoverage instruction,
despite being redundant with the information in the coverage array, so that checking whether that type of coverage is currently enabled at
runtime doesn't require either accessing the coverage array (which may
be lazily allocated), forcing allocation of the coverage array just to
discover that type of coverage is currently disabled, or reading the
serialized bytecode component to avoid that forced allocation.

------

Other changes:

Source reporting now treats unexecuted interpreted functions when
not forcing compilation as if they were uncompiled native functions,
so that the source report from running the same code gives the same
result whether using the interpreter or the native compiler.

Bytecode closures are no longer skipped in source reports. Previously
any closure without a context scope was skipped, but bytecode closures
don't have those.

TEST=vm/cc/SourceReport_Coverage

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try
Change-Id: I7557e5dd4c98331c7ca2f5c867dd5f6d03e9d756
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501520
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2026-05-19 04:27:39 -07:00
Sigmund Cherem d65783ef59 [dyn modules] add runtime flag for checking under JIT
At this time, this flag is mainly going to be used to enable partial
testing of the JIT runtime when loading applications from kernel
snapshots.

Bug: b/448095881

TEST=none yet, will be added in upcoming CL
Change-Id: I272d43cdab0c9a9c3653cccc9e96961c1122bbd7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503460
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2026-05-13 11:42:30 -07:00
Sigmund Cherem cca6298498 [dyn_modules] Check target of dcall from dynamic modules is valid.
Unlike other calls from Dynamic Modules, dynamic calls cannot be
validated entirely at compile time. While we check that the selector
used matches a selector that was allowed (either because a method with
that selector name was exposed as dynamically callable or because the
selector was allowlisted during bytecode compilation), the compiler
doesn't know statically whether the target of the call is exposed.

In prior changes we modified the annotator to add a pragma indicating
whether a member is dynamically-callable or
implicitly-dynamically-callable. Here we use that information to set a
bit on functions and their corresponding dynamic invocation forwarders,
which is verified by the interpreter to make sure the dynamic call is
still allowed.

TEST=none yet - will be added in subsequent CL (see CL chain)

Bug: b/448095881
Change-Id: I27acb4e690a68e08fe1f1ca94e0d77cc7dc4d11e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498300
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2026-05-13 09:40:57 -07:00
Alexander Markov 51d1c8923a Reland "[vm,dart2bytecode,modular_aot] Variable-length closure objects"
This is a reland of commit 88496ba1c3

Fixes on top of the original change:

* Closure layout is changed to avoid gap between fixed fields and
  variable-length elements on compressed pointers architecture.
  This gap was causing crashes in the GC when scanning closure
  objects.

* pkg/vm_snapshot_analysis/test/instruction_sizes_test is fixed
  on arm64 by decreasing threshold for detecting size changes.

Original change's description:
> [vm,dart2bytecode,modular_aot] Variable-length closure objects
>
> Extend closure objects with variable number of elements to capture.
> This is needed to support capturing multiple independent contexts
> after capturing is computed in the front-end.
>
> The following fixed Closure fields are moved into variable-length
> elements:
>  - delayed type arguments;
>  - instantiator type arguments;
>  - function type arguments;
>  - context.
>
> Number of elements and presence/indices of various type arguments
> are encoded into the new length_and_flags field in the Closure.
>
> Most closure objects don't need any of the type arguments so this
> change will reduce average Closure object size.

TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/61572
Issue: https://github.com/dart-lang/sdk/issues/61635

Change-Id: I8685e632e2d0832766ecdc470f3cf9a6b880de48
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494243
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-04-10 06:15:22 -07:00
Tess Strickland 432adf747e [vm,dyn_modules] Fix PrintStackFrames for entry frames, add more info.
The handling of entry frame in PrintStackFrames was broken, now it's
fixed.

In addition, the stack printer now print various info about the static
slots in stack frames, as well as printing out the objects in slots.

Now that entry frames are handled properly, printing with no limit
prints _all_ stack frames on the interpreter stack, noting call
boundaries as they are passed, instead of stopping at the closest
entry frame.

Move the separator between frame from the stack pointer for a frame
to the frame pointer for a frame, meaning that the metadata before
the frame pointer is printed as part of the previous frame, not the
current one.

TEST=ci (manual testing while debugging)

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try
Change-Id: Ia2ad07c832b791f0c2ce2bbdfbfc32d5d8968476
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/493402
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2026-04-10 04:49:32 -07:00
Alexander Markov 0dfaa16dc7 Revert "[vm,dart2bytecode,modular_aot] Variable-length closure objects"
This reverts commit 88496ba1c3.

Reason for revert: crashes on arm64c

Original change's description:
> [vm,dart2bytecode,modular_aot] Variable-length closure objects
>
> Extend closure objects with variable number of elements to capture.
> This is needed to support capturing multiple independent contexts
> after capturing is computed in the front-end.
>
> The following fixed Closure fields are moved into variable-length
> elements:
>  - delayed type arguments;
>  - instantiator type arguments;
>  - function type arguments;
>  - context.
>
> Number of elements and presence/indices of various type arguments
> are encoded into the new length_and_flags field in the Closure.
>
> Most closure objects don't need any of the type arguments so this
> change will reduce average Closure object size.
>
> TEST=ci
> Issue: https://github.com/dart-lang/sdk/issues/61572
> Issue: https://github.com/dart-lang/sdk/issues/61635
>
> Change-Id: I7ca5cec0fd8725c432a01d51781fb14e803997dd
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489482
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Reviewed-by: Tess Strickland <sstrickl@google.com>

Issue: https://github.com/dart-lang/sdk/issues/61572
Issue: https://github.com/dart-lang/sdk/issues/61635
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I94c88f8922f6ea49251e942ba791fee714911e25
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494261
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2026-04-09 14:12:09 -07:00
Alexander Markov 88496ba1c3 [vm,dart2bytecode,modular_aot] Variable-length closure objects
Extend closure objects with variable number of elements to capture.
This is needed to support capturing multiple independent contexts
after capturing is computed in the front-end.

The following fixed Closure fields are moved into variable-length
elements:
 - delayed type arguments;
 - instantiator type arguments;
 - function type arguments;
 - context.

Number of elements and presence/indices of various type arguments
are encoded into the new length_and_flags field in the Closure.

Most closure objects don't need any of the type arguments so this
change will reduce average Closure object size.

TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/61572
Issue: https://github.com/dart-lang/sdk/issues/61635

Change-Id: I7ca5cec0fd8725c432a01d51781fb14e803997dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489482
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2026-04-09 12:22:21 -07:00
Tess Strickland 32b8c8f12f [vm,dyn_modules] Fix the interpreter case in GenerateResumeStub.
Previously, it would always call the ResumeInterpreter runtime entry
passing null as the value to return to the resumed code. Instead,
appropriately retrieve the to-be-returned value from the stack.

Also fixes IL printing to print constants in non-SSA flow graphs and
adds Interpreter::TraceStackFrames, which prints the top frames of the
current stack, so calls to it can be added for easier debugging in the
future.

TEST=pkg/vm_service/test/async_star_step_out_test.dart
     (still fails, but the failure changes due to no longer spuriously
      calling get:current after the generator finishes)

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try
Change-Id: Ibb3524d32c8c4e1320f4f9dfd35947eda7d6ca68
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488181
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2026-03-16 09:35:38 -07:00
Tess Strickland 5792b6ecb7 [vm, dyn_modules] Fix tracing the original instruction at breakpoints.
https://dart-review.googlesource.com/c/sdk/+/481782 removed the tracing
of the original instruction for breakpoints. This CL adds it back.

Also increments icount_ before calling TraceInstruction in the dispatch
loop instead of afterwards so that breakpoint/single step tracing can
just use icount_ without adjusting it. In particular, this means tracing
the original instruction at a breakpoint can just use TraceInstruction
instead of duplicating it.

Also, now both the breakpoint instruction and the original instruction
are written to the instruction trace if requested, instead of only the
breakpoint instruction.

TEST=debugging only changes, so manually tested.

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try
Change-Id: I1999f1d9e7ba55b950c508e848ff12db0c8d5cab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/482320
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Tess Strickland <sstrickl@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2026-02-23 03:45:57 -08:00
Tess Strickland df48d89796 [vm,dyn_modules] Fix single stepping at breakpoints.
In compiled code, a block of instructions that calls the single step
handler in the runtime is generated for any pause points.  Enabling a
breakpoint at a pause point then patches those instructions to instead
call a stub. The stub first calls the breakpoint handler in the runtime.
The runtime's breakpoint handler returns the original call target for
the breakpoint, which the stub then calls.

Since the debugger ignores any pause points with the same source
location after hitting a breakpoint, this means that setting a
breakpoint at a pause point only generates a breakpoint hit event,
ensuring that a request to single step after hitting a breakpoint steps
to the next location, not the breakpoint location.

Similar to compiled code, enabling a breakpoint in interpreted code
replaces the original instruction with a special instruction that first
calls the breakpoint handler and then performs the original
instruction's implementation.

However, there is no specific instruction for pause points in
interpreted code. Instead, the dispatch loop in the interpreter has two
labels for each instruction: one for the instruction's implementation,
and another that is used instead when single stepping is enabled.  All
the single step labels point at the same code block, which first calls
the single step handler and then dispatches to the code for the
instruction's implementation.

This difference in handling breakpoints and single step checks means
that pause events are prioritized, not breakpoint hit events, which
means single stepping into a breakpoint generates first a pause event
and then a breakpoint hit event, which differs from the behavior
for compiled code.

To fix this, refactor single step handling in the interpreter so that
the single step label for breakpoint instructions point to a different
code block which first calls the breakpoint handler and then calls the
single step handler before dispatching to the original instruction's
implementation.

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try
Change-Id: Id33132bbecc5d0cbd9e92bc5a13d8d8a80155344
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/481782
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Auto-Submit: Tess Strickland <sstrickl@google.com>
2026-02-19 09:43:52 -08:00
Tess Strickland fe6ea5e39d [vm,dyn_modules] Rename DebugCheck to Nop and use after debugger() calls.
Normally, bytecodes no longer in use would be renamed to Unused<X>.
However, in the case of DebugCheck, its only use was to call the
debugger when single stepping, and since its original creation, the
interpreter has been changed to call the debugger when single stepping
on every instruction. Thus, DebugCheck instructions are effectively
no-ops, only used as a distinct PC offset for source positions, and this
CL changes their name to reflect this.

This CL also changes the bytecode generator to detect uses of debugger()
from dart:developer and to add a Nop after it, mimicking how
StreamingFlowGraphBuilder recognizes uses of debugger() and adds a
DebugStepCheck instruction afterwards. Doing this instead of just
using asm.emitSourcePosition() at the end of visitStaticInvocation
ensures that the source position isn't overwritten by the next emitted
instruction.

TEST=pkg/vm_service/test/set_sdk_library_debuggable_test

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try
Change-Id: Ie24bcea0b5aeb9e41d7765f25b1cd123bb2565b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480203
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2026-02-19 03:00:23 -08:00
Ryan Macnak 5196ec61ed [vm] Replace GCC __builtin_expect with C++20 [[likely]] attributes.
MSVC has no analogue of __builtin_expect but does support the standard attribute.

TEST=ci
Change-Id: Ide1edaf88425677bce784db4400a72be64e84346
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/481162
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2026-02-17 14:25:39 -08:00
Tess Strickland 62b145efbb [vm] Abstract out object header initialization.
Previously there were two separate implementations of the same
initialization code, one in object.cc and one in interpreter.cc.
Now they both use Object::InitializeHeader.

Make TryAllocate a static method of Interpreter instead of a file-local
function in interpreter.cc so that it gets access to the private method
Object::InitializeHeader.

TEST=ci (just code refactoring)

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try
Change-Id: I4e042fbf0db84e02c88f7ca0f3e025723660001b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476120
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2026-01-29 06:59:12 -08:00
Alexander Aprelev eb75c53d95 [vm/shared] Perform deeply-immutable initialization runtime check.
When an initial value is assigned into a class tagged as deeply-immutable, perform runtime check of that value. This is needed to support proper initialization of the closures as part of deeply-immutable classes.

BUG=https://github.com/dart-lang/sdk/issues/61962
TEST=run_isolate_group_run_test

Change-Id: I550746c0d22ca06ffb89959e8384cc9e6d28d590
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/468200
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-01-14 08:42:22 -08:00
Alexander Aprelev a949c74530 [vm/shared] Ensure stores into shared static variables are checked.
Closures going into shared variables in particular have to be confirmed to capture appropriate values.

BUG=https://github.com/dart-lang/sdk/issues/62179
TEST=run_isolate_group_run_test

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try,vm-aot-dyn-linux-debug-x64-try
Change-Id: I27416773fd77077018739ea4dbcc6e4695e67be8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469103
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-12-22 07:53:44 -08:00
Alexander Aprelev f04ff0410e [vm/shared/bytecode] Support use of vm:shared in bytecode/interpreter.
Fixes https://github.com/dart-lang/sdk/issues/62032
TEST=ci

Change-Id: I80600d81ee73b16338a337f7139bf4e898af6eca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466124
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-12-05 21:38:41 -08:00
Alexander Markov a37d042e68 [vm] Initial implementation of module snapshot reader
TEST=manual
Issue: https://github.com/dart-lang/sdk/issues/61635

Change-Id: I27f712d9687d45a09173b1018bc08812dd18658e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460580
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-11-21 06:42:16 -08:00
Tess Strickland b8ad514530 [pkg,dyn_modules] Use bytecode payload start for relative disassembly.
Add an additional argument to the base implementation of KernelBytecodeDisassembler::Disassemble that is the base address to use
when FLAG_disassemble_relative is enabled.

For the delegating versions of KernelBytecodeDisassembler::Disassemble
that take a Bytecode object, the payload start of the bytecode object
is retrieved and used as the base.

For the delegating versions of KernelBytecodeDisassembler::Disassemble
that take neither a base or a bytecode object, the start is used as
the base.

When tracing instructions in the interpreter, the bytecode is retrieved
via the frame pointer and then its payload start is passed in as the
base, so that the relative offset printed with the instructions match
the relative offsets printed when dumping function bytecode.

TEST=manual use of --disassemble-relative while tracing/dumping bytecode

Change-Id: I7f931037970acd950a330fa6be024df5beb144a7
Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/463022
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-11-19 07:56:49 -08:00
Tess Strickland 5729e6b87d [vm,dyn_modules] Handle traced allocation of classes.
Add a check in TryAllocate for whether allocations for the class id
should be traced and, if so, return false so the allocation runtime
entry is called instead.

TEST=pkg/vm_service/test/get_allocation_traces_test

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try
Change-Id: I6107423d099841c321c0eee440bedddddfacaccc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457020
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-10-24 05:28:40 -07:00
Tess Strickland 99a370942b [vm,dyn_modules] Update some coverage information for bytecode.
Add a flag to SourceFile which is true if the associated script
contains a list of covered const constructors, and serialize said
list if true.

Delay reading and resolving the list of covered const constructors in
the bytecode reader until code is read.

Update usage counters for interpreted functions in Entry instructions.

Fix up cases where SourceReport assumed compiled code as appropriate.

Remaining:
* Record call and assert coverage information if the current isolate
  group has coverage enabled.
* Record branch coverage information if the current isolate group
  has branch coverage enabled.

TEST=pkg/vm_service pkg/dart2bytecode

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-mac-debug-arm64-try
Change-Id: I14b6ffba1e175993e992c0fe939473557303bfeb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449900
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-10-01 09:51:59 -07:00
Tess Strickland 74f753f32d [vm,dyn_modules] More work on bytecode debugger support.
Detects yield points in Debugger::IsAtAsyncJump for bytecode by seeing
if the currently executing instruction is a direct call to an await
or yield compiled stub.

Adds a ResumptionBreakpointHandler runtime entry that is called
during Interpreter::Resume() if the current isolate has resumption
breakpoints.

Similarly, all the places where a DebugCheck could be emitted if
debugging stops are requested now include an explicit source position
emission when source positions are requested but debugger stops are not,
to ensure the debugger has appropriate information.

Fixes CompareTopDartFrameTo returning kSelf for non-top frames when
the top frame was interpreted but the stepping frame was not or
vice versa.

TEST=pkg/vm_service/test

Change-Id: I88cdc37cf745f30e8dfb6b14c19fc9b2c4cbaf2d
Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-mac-debug-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446300
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-09-12 04:19:40 -07:00
Alexander Markov de0f3697f7 [vm,dyn_modules] Avoid allocating large arrays in NewSpace
TEST=ci (co19/LibTest/collection/ListBase/ListBase_class_A01_t04)

Change-Id: I763897e7e850e9e3f683bd88410311bb2d075a4e
Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447760
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-09-10 07:10:52 -07:00
Alexander Markov 0b8e1534ca [vm,dyn_modules] Take --use_simulator flag into account when calling simulator from the interpreter
TEST=ci (vm-dyn-mac-debug-simarm64_arm64)

Change-Id: I123426bf633b4271803138c3c5b591db6ba0f519
Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try,vm-ffi-dyn-mac-debug-simarm64_arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447605
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2025-08-29 06:21:17 -07:00
Alexander Markov 68382660c8 [vm,dyn_modules] Initial support for FFI calls in the interpreter
Limitations:
* Compounds (structs, unions, arrays) are not supported yet.
* Only x64 and arm64 are supported.

TEST=ci

Change-Id: I2929d514dc49015369d29dad31f479c661161655
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446282
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-08-26 09:22:30 -07:00
Tess Strickland af074fb62d [vm,dyn_modules] Initial handling of breakpoints in the interpreter.
Adds a set of new VMInternal_Breakpoint instructions, one for each
possible instruction size, and adds a bytecode_ and saved_opcode_
field to code breakpoints.

When enabling a breakpoint, the original opcode of the instruction is
replaced with the same-sized VmInternal_Breakpoint opcode and stored in
the saved_opcode_ field of the CodeBreakpoint. When disabling it, the
original opcode is replaced.

New labels are added to the dispatch loop for single stepping
purposes. Both the computed goto and switch dispatch versions
of the dispatch loop are appropriately altered to dispatch to
the single stepping labels instead of the original ones if single
stepping is currently enabled.

Fix up more parts of the debugger that assumed functions had Code
objects to handle functions with Bytecode objects as well. In
particular, instead of using the PcDescriptors to find safepoint
source locations in Bytecode objects, the source positions information
is used instead (since the PcDescriptors for Bytecode objects only
stores information about the start and end of try blocks at the moment).

Todo (from looking at the remaining failing tests):
* Handle async jumps.
* Handle coverage information.

TEST=now-passing tests from pkg/vm_service like
     pkg/vm_service/test/break_on_function_test

Change-Id: Icbd4b818e00508d9a4e74c81520aad2363b26d41
Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-mac-debug-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444880
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-08-25 10:22:22 -07:00
Tess Strickland d34b08263c [vm,dyn_modules] Handle hash-based SubtypeTestCaches in the interpreter.
To do this, factor out the main search loop from
SubtypeTestCache::FindKeyOrUnused into a method suitable for calling
from the interpreter. Then, the only work on the interpreter side is to
calculate the initial index at which to start probing for entries.

TEST=ci

Change-Id: I620c3904458158519066074565218b6e4a77eea9
Cq-Include-Trybots: luci.dart.try:vm-linux-debug-x64-try,vm-aot-linux-debug-x64-try,vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444080
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-08-07 08:30:29 -07:00
Alexander Markov f46670e00c [vm,dyn_modules] Support instantiated tear-offs of generic instance methods in the interpreter
TEST=ci (co19/Language/Expressions/Property_Extraction/Generic_Method_Instantiation/generic_method_A02_t03)

Change-Id: I9b4862cdbaf6977230e1cce9f5f82c729464425f
Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443638
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-08-06 06:09:29 -07:00
Alexander Markov 6082256159 [vm,dyn_modules] Support error cases during hot reload when rebinding direct calls in bytecode
TEST=vm/cc/IsolateReload

Change-Id: Ib989d2d951a342e4725b99b1651e8ea298ba2f64
Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441826
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-07-28 13:32:36 -07:00
Alexander Markov dc42744638 [vm,dyn_modules] Check argument types in interpreted dynamic invocation forwarders
TEST=ci

Change-Id: I229b54413188393e792dcaeac523d094fa1f6a78
Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442002
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-07-25 06:21:51 -07:00
Alexander Markov 3e462c1343 [vm,dyn_modules] Support external/native methods in bytecode
TEST=ci

Change-Id: I2827c95f7b4d4bfa40239369d3675ef6adba4ab2
Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439545
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-07-11 06:31:19 -07:00
Ryan Macnak 7973eacdd0 [vm] Rename USING_SIMULATOR to DART_INCLUDE_SIMULATOR.
We now have a mode where the simulator is available but not always used.

TEST=ci
Change-Id: If271f334150e2a125a014a4baa2e03d726300d35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435562
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-06-18 13:07:22 -07:00
Alexander Markov c006202dc6 [vm,dyn_modules] Convert function type args to instance type args when allocating an object in constructor tear-off
TEST=tests/language/regress/regress60816_test.dart
Fixes https://github.com/dart-lang/sdk/issues/60816

Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try
Change-Id: Id4c9ae3dc14cf680ba5f04d54d019ebe589ad96d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432100
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-06-02 07:30:58 -07:00
Ryan Macnak b061f911f9 [vm] Fix dynamic module build.
Broken by 18aa7d3678.

TEST=ci
Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try
Change-Id: If6a11d4f541012c0503d82b4e26592ef0b810208
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431560
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Ryan Macnak <rmacnak@google.com>
2025-05-28 06:43:47 -07:00
Alexander Markov 5d0d9e467c [vm,dyn_modules] Fix creation of dynamic invocation forwarders for bytecode functions
TEST=ci

Change-Id: Id3e01591565c20fe8fe5f18438fdc66b61ac5e1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426521
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-05-05 12:56:11 -07:00
Vyacheslav Egorov 8085a97a63 [vm] Fix JumpToFrame execution state transition
Instead of handling FFI related execution state and safepoint
in assembly handle it in runtime code.

The transition needs to be done before JumpToFrame unwinds
stack because unwinding destroys exit frame and this can't
be done at safepoint as GC might be traversing the stack.

An incorrect order of operation was manifesting as crashes in
GC when one isolate in a group was encountering a lot of
exceptions thrown from an FFI call and another isolate is
triggering GCs.

To catch this in the future added a bit of validation to
ExitSafepoint runtime call which triggers when --use-slow-path
is enabled. Though after refactoring this code does not
trigger this code path anymore because it was completely
removed - but it is better than nothing.

This CL also removes a lot of unnecessary complexity which
was associated with handling this transition in the stub
itself.

TEST=ffi/vmspecific_handle_test

Bug: b/408377905
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-asan-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-msan-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-ubsan-linux-release-x64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-mac-debug-simarm64_arm64-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Change-Id: Ia073cb6bb9e1b5a0ea8514c7e048cee6019b84d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420324
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2025-04-07 05:22:56 -07:00
Alexander Markov bbdb840023 [vm, dynamic_modules] Handle native stack overflow in the interpreter
TEST=corelib/error_stack_trace2_test

Change-Id: I337c15eecddccbe770158fa493bf296c171f9f08
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415940
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-03-18 15:57:16 -07:00
Alexander Markov 151e9dd509 [vm, dynamic_modules] Fix instantiated tear-offs of generic static methods and factories
TEST=language/function_subtype/bound_closure7_test
TEST=language/named_arguments_anywhere/order_side_effects_ok_test
TEST=language/regress/regress52243_test

Change-Id: I09765f5a272941388fccac65c083d2239da27b1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414320
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-03-12 07:47:40 -07:00
Alexander Markov ebb7e1061c [vm] Use _setjmp instead of setjmp on MacOS/iOS
setjmp is extremely expensive on MacOS/iOS as it always saves
signal mask.

Introduce DART_SETJMP / DART_LONGJMP macros to use _setjmp instead of
setjmp on MacOS/iOS.

DeltaBlue on Mac/arm64 on the interpreter:
179585.3 us -> 58347.9 us. (3x faster)

TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/60205

Change-Id: I2122f2eb4d5de66ae2ef904a7034af1ed09f1d07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412320
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-02-26 14:01:44 -08:00
Alexander Markov d76f568f0e [vm,dynamic_modules] Fix object allocation/initialization in interpreter in compressed pointers mode
Fix initialization of a newly allocated Closure object when compressed
pointers are used.

Also, fix how instance size is calculated when allocating an object with
instance type arguments.

Fixes b/383719624.
TEST=tools/test.py -n vm-aot-dyn-linux-debug-x64c language corelib

Change-Id: I4bf848ac9b9c9c76d069d1861683cb6dc626ceb9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400400
Commit-Queue: Slava Egorov <vegorov@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-12-13 06:29:44 -08:00
Alexander Markov 24eafd67d3 [vm/interpreter] Fix return value and type arguments in constructor tear-offs
TEST=ci

Change-Id: Ibe1ede1bc1c4e044285ee3b3f75ca138d7596e8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384682
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-09-12 15:15:08 +00:00
Alexander Markov 1225b45bc7 [dart2bytecode, vm/interpreter] Async exceptions
TEST=ci (vm-aot-dyn-linux-debug-x64)

Change-Id: I9d5bb0f7f2544e41078ec9aeb75bce6224087976
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383706
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-09-09 13:44:04 +00:00
Alexander Markov a17bc048b4 [dart2bytecode, vm/interpreter] Late final fields and variables
* Also, add implicitly overridden _Enum._enumToString to dynamic
  interface.

TEST=ci (vm-aot-dyn-linux-debug-x64)

Change-Id: I9d9d368715d0837d8b1039a46451152e03be7eec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383024
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-09-04 14:18:09 +00:00
Alexander Markov 52304b29d0 [vm/interpreter] Fix type checks and async stack traces
TEST=ci (vm-aot-dyn-linux-debug-x64)

Change-Id: Ia8d5dff98ef1b1afa97108a40f1835545e08790f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382962
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
2024-09-04 08:14:18 +00:00
Alexander Markov ce571036e1 [vm] Cleanup legacy AssertBoolean checks
With sound null safety front-end guarantees that all logical
expressions have a non-nullable bool type, so legacy AssertBoolean
checks are no longer needed and can be removed.

TEST=ci

Change-Id: If952da7bd0ac83c43de3e5d98845c5e5d8d29f6a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382744
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-08-29 16:45:00 +00:00
Alexander Markov 0ec691222d [dart2bytecode, vm/interpreter] Constructor tear-offs and more fixes
* Make dynamic module entry point fully compatible to script main
  function (allow taking optional parameters and up to 2 arguments).

* Fix reading of function types within generic members.

* Add crashing tests to status files to avoid generation of
  core dumps on the bots.

TEST=ci (vm-aot-dyn-linux-debug-x64)

Change-Id: Ibe8651ca13734101f2df2c8634f70ebf421dccef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382640
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-08-29 14:30:38 +00:00
Alexander Markov a3b7c9fb5a [dart2bytecode, vm/interpreter] Small fixes
* Use AllocateClosure instruction for closure instantiations in order
  to initialize closure entry point.

* Fix null handling in operator== to be before argument type checks.

* Add _InvocationMirror._withType to dynamic interface as it is
  implicitly used by noSuchMethod forwarders.

* Fix AssertAssignable for null objects.

TEST=language tests in vm-aot-dyn-linux-debug-x64 configuration

Change-Id: I7b1a037d4fde4d22ed32969e0f099b31ea4432ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382500
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-08-29 14:28:40 +00:00
Alexander Markov 2e63d3135a [dart2bytecode, vm/interpreter] Records
TEST=language tests in vm-aot-dyn-linux-debug-x64 configuration

Change-Id: I6dd7d5617f5c076c722304ab2a753159f22c0bf6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382421
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-08-28 13:12:48 +00:00