Files
sdk/pkg/vm_snapshot_analysis/lib/instruction_sizes.dart
T
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

124 lines
4.5 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// Helper functions for parsing output of `--print-instructions-sizes-to` flag.
library;
import 'package:vm_snapshot_analysis/name.dart';
import 'package:vm_snapshot_analysis/program_info.dart';
/// Parse the output of `--print-instructions-sizes-to` saved in the given
/// file [input].
List<SymbolInfo> fromJson(List<dynamic> json) {
return json
.cast<Map<String, dynamic>>()
.map(SymbolInfo._fromJson)
.toList(growable: false);
}
/// Parse the output of `--print-instructions-sizes-to` saved in the given
/// file [input] into [ProgramInfo] structure representing the sizes
/// of individual functions.
///
/// If [collapseAnonymousClosures] is set to [true] then all anonymous closures
/// within the same scopes are collapsed together. Collapsing closures is
/// helpful when comparing symbol sizes between two versions of the same
/// program because in general there is no reliable way to recognize the same
/// anonymous closures into two independent compilations.
ProgramInfo loadProgramInfo(List<dynamic> json,
{bool collapseAnonymousClosures = false}) {
final symbols = fromJson(json);
return toProgramInfo(symbols,
collapseAnonymousClosures: collapseAnonymousClosures);
}
/// Information about the size of the instruction object.
class SymbolInfo {
/// Name of the code object (`Code::QualifiedName`) owning these instructions.
final Name name;
/// If this instructions object originated from a function then [libraryUri]
/// will contain uri of the library of that function.
final String? libraryUri;
/// If this instructions object originated from a function then [className]
/// would contain name of the class owning that function.
final String? className;
/// Size of the instructions object in bytes.
final int size;
SymbolInfo(
{required String name,
this.libraryUri,
this.className,
required this.size})
: name = Name(name);
static SymbolInfo _fromJson(Map<String, dynamic> map) {
return SymbolInfo(
libraryUri: map['l'],
className: map['c'],
name: map['n'],
size: map['s']);
}
}
/// Restore hierarchical [ProgramInfo] representation from the list of
/// symbols by parsing function names.
///
/// If [collapseAnonymousClosures] is set to [true] then all anonymous closures
/// within the same scopes are collapsed together. Collapsing closures is
/// helpful when comparing symbol sizes between two versions of the same
/// program because in general there is no reliable way to recognize the same
/// anonymous closures into two independent compilations.
ProgramInfo toProgramInfo(List<SymbolInfo> symbols,
{bool collapseAnonymousClosures = false}) {
final program = ProgramInfo();
for (var sym in symbols) {
final scrubbed = sym.name.scrubbed;
final libraryUri = sym.libraryUri;
// Handle stubs specially.
if (libraryUri == null) {
// The UnknownDartCode stub mostly pretends to be function code. This
// seems to have originally been for the profiler to deal with collected
// code. Is this still worthwhile?
assert(
sym.name.isStub || sym.name.raw == '[Unoptimized] <optimized out>');
final node = program.makeNode(
name: scrubbed, parent: program.stubs, type: NodeType.functionNode);
assert(node.size == null || sym.name.isTypeTestingStub);
node.size = (node.size ?? 0) + sym.size;
continue;
}
// Split the name into components (names of individual functions).
final path = sym.name.components;
var node = program.root;
final package = packageOf(libraryUri);
if (package != libraryUri) {
node = program.makeNode(
name: package, parent: node, type: NodeType.packageNode);
}
node = program.makeNode(
name: libraryUri, parent: node, type: NodeType.libraryNode);
node = program.makeNode(
name: sym.className!, parent: node, type: NodeType.classNode);
node = program.makeNode(
name: path.first, parent: node, type: NodeType.functionNode);
for (var name in path.skip(1)) {
if (collapseAnonymousClosures) {
name = Name.collapse(name);
}
node = program.makeNode(
name: name, parent: node, type: NodeType.functionNode);
}
node.size = (node.size ?? 0) + sym.size;
}
return program;
}