Commit Graph

20 Commits

Author SHA1 Message Date
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
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
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 db8563d4d6 [vm,dyn_modules] Recognize the vm:invisible pragma.
Adds a new isInvisible flag for both FunctionDeclarations and
ClosureDeclarations and sets it if the function or closure declaration
is annotated with @pragma('vm:invisible'). This way, function visibility
is appropriately recorded even if options.emitAnnotations is false.

The bytecode reader checks for the isInvisible flag when reading
FunctionDeclarations and ClosureDeclarations and appropriately
sets the is_visible flag for the Function object accordingly.

TEST=pkg/dart2bytecode/test/bytecode_generator_test
     vm/dart/invisible_function_pragma_test

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try
Change-Id: If435afbe5e74adc022ce064784b6b3e5e8a88164
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486381
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2026-03-09 10:16:02 -07:00
Alexander Markov ffa7e990f0 [vm,dart2bytecode] Use local function IDs to register and find functions
TEST=ci

Change-Id: I275a7f9e81a8fa69a004518b150c7dfcf1fe7bd6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483844
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-03-02 07:55:38 -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
Alexander Aprelev 170df25b66 [vm/shared] Prohibit capturing of 'late final' variables by isolategroup-bound closures.
TEST=run_isolate_group_run_test
BUG=https://github.com/dart-lang/sdk/issues/62181

Change-Id: I50037ede337367020176262b98d2c2fd100b050a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466820
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-12-10 08:29:57 -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
Tess Strickland 7af4d14267 [vm,dyn_modules] Mark extension type members appropriately.
TEST=pkg/vm_service/test/step_through_extension_type_method_call_test

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try
Change-Id: I3bf331e175847280964fd42eb027e9f812598bf2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464705
Auto-Submit: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-12-02 06:31:15 -08:00
Tess Strickland df693c20b0 [vm,dyn_modules] Add flags to bytecode source positions.
There are two possible flags for each source position currently:
a flag that marks the source position as synthetic and a flag that
marks the source position as within a yield point.

Synthetic source positions in bytecode are treated the same as synthetic
source positions in compiled code. That is, they encode the source
position in the text that caused them to be synthesized, but denote that
the covered instructions are internal and not to be used for debugger
pause points or for call site/branch coverage information.

Adding these flags allow us to mark appropriate parts of the async
machinery as synthetic, and also allow us to mark all the bytecode
involved in yield points as having the same token position.

The latter fixes tests where the code would step over a previous
expression, thus being paused at the start of the await bytecode,
and would record the fp and token position there as the ones to
ignore. However, since a new source position wasn't emitted until the
direct call to the await method, the recorded token position would
be the token position prior to the await call, and so the change
in token position at the await call would trigger an early pause.

TEST=pkg/vm_service/test/async_single_step_exception_test
     pkg/vm_service/test/async_single_step_into_test
     pkg/vm_service/test/async_single_step_out_test
     pkg/vm_service/test/async_star_single_step_into_test
     pkg/vm_service/test/async_step_out_test
     pkg/vm_service/test/positive_token_pos_test
     pkg/vm_service/test/step_into_async_no_await_test

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,vm-aot-linux-debug-x64-try,vm-aot-linux-product-x64-try
Change-Id: Ic7642a74fb76227a473f461f360e84dd3d5a45a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453322
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-10-09 09:15:42 -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
Alexander Markov 5f3466ea7c [vm,dyn_modules] Support deferred libraries
TEST=ci

Change-Id: I0c9ba10b3220729aa9114ae965a4d3d2a4037a88
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/+/447761
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-09-08 07:56:13 -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
Alexander Markov a3038b85f8 [vm,dyn_modules] Support pragmas on local functions in bytecode
Pragmas on local functions are used internally by FFI.

TEST=ci

Change-Id: I3ffb9984d8fcd943b22a98746faa915b2ce7c9fa
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/+/446121
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-08-21 07:00:49 -07:00
Alexander Markov 9f72f1034c [vm,dyn_modules] Support class modifiers in bytecode
TEST=ci

Change-Id: I521b27c793269dc6076b353f50e2cdaa629002e9
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/+/441987
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-07-24 06:02:35 -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
Alexander Markov 18a44b3095 [vm, dynamic_modules] Support required named parameters in function types
TEST=language/nnbd/subtyping/function_type_required_params_test

Change-Id: I050f8fdd331985512f204b265d81c7deec0d67fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415640
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-03-18 14:50:45 -07:00
Alexander Markov e200a3a722 [dart2bytecode] Avoid merging function types with different number of enclosing type parameters
When creating function types, VM takes number of parent function type
arguments into account. So function types with distinct number of
parent function type arguments should not be merged in the bytecode
object table and should be represented as distinct types.

TEST=language/mixin/type_parameter_inference_test
Fixes https://github.com/dart-lang/sdk/issues/59633

Change-Id: I9c8b0923c52b1b95628ff8daa3bbfa135c559912
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398500
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-12-09 15:19:43 +00:00
Alexander Markov 6903672599 [dart2bytecode] Add document describing Dart bytecode file format
TEST=ci

Change-Id: Id12824cf667181122d4d2c4e7af7dc6206d1f85b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384043
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-09-10 13:39:57 +00:00