[vm] Handle WSRs more generally in v8 snapshot profile writing.
Instead of special-casing the current fields that may have WeakSerializationReferences, handle WSRs appearing as elements or properties of objects more generally. This removes existing special casing and avoids the need for it in case of new future uses of WSRs. For artificial nodes being added for dropped WeakSerializationReference targets, add them as kArtificial nodes (not kSnapshot) that has the original offset (element) or name (property). The replacement is added as a kSnapshot node that has a negative offset with the same magnitude as the artificial node (element) or ":real_<property name>" (property). This simplifies the work done in pkg/vm_snapshot_analysis to use the artificial nodes instead of replacement ones for reassembling hierarchies and the like. This CL also cleans up the old SerializerWritingObjectScope class, both moving it to Serializer::WritingObjectScope and allowing nesting of WritingObjectScopes with the correct semantics. Thanks to this, not only can we recur when under a WritingObjectScope instead of lifting recursion outside of those scopes, but we can also create artificial nodes for non-empty per-code object pools and static call target tables instead of attributing their contents as supposed elements of the Code object being written. TEST=pkg/vm_snapshot_analysis/test/instruction_sizes_test Cq-Include-Trybots: luci.dart.try:pkg-linux-release-try,pkg-mac-release-try,pkg-win-release-try Change-Id: Ib945c5afcd89b1458b8be3559b6eae24048aba2f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194243 Commit-Queue: Tess Strickland <sstrickl@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
d8f2b7cc44
commit
dc88076767
@@ -88,6 +88,25 @@ class Snapshot {
|
||||
m['strings'],
|
||||
edgesStartIndexForNode);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final buffer = StringBuffer();
|
||||
buffer
|
||||
..write("Node count: ")
|
||||
..writeln(nodeCount)
|
||||
..write("Edge count: ")
|
||||
..writeln(edgeCount);
|
||||
buffer.write("Nodes:");
|
||||
for (final node in nodes) {
|
||||
buffer
|
||||
..writeln()
|
||||
..write(node.index)
|
||||
..write(': ')
|
||||
..writeln(node);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/// Meta-information about the serialized snapshot.
|
||||
@@ -228,12 +247,6 @@ class Node {
|
||||
}.toString();
|
||||
}
|
||||
|
||||
/// Returns the target of an outgoing edge with the given name (if any),
|
||||
/// but first checks for a corresponding artificial edge indicating a dropped
|
||||
/// object.
|
||||
Node possiblyDroppedTarget(String edgeName) =>
|
||||
this[':$edgeName'] ?? this[edgeName];
|
||||
|
||||
/// Returns the target of an outgoing edge with the given name (if any).
|
||||
Node operator [](String edgeName) => this
|
||||
.edges
|
||||
@@ -404,7 +417,7 @@ class _ProgramInfoBuilder {
|
||||
ProgramInfoNode createInfoNodeFor(Node node) {
|
||||
switch (node.type) {
|
||||
case 'Code':
|
||||
var owner = node.possiblyDroppedTarget('owner_');
|
||||
var owner = node['owner_'];
|
||||
if (owner.type != 'Type') {
|
||||
final ownerNode =
|
||||
owner.type == 'Null' ? program.stubs : getInfoNodeFor(owner);
|
||||
@@ -428,7 +441,7 @@ class _ProgramInfoBuilder {
|
||||
// Artificial nodes may not have a data_ field.
|
||||
var data = node['data_'];
|
||||
if (data?.type == 'ClosureData') {
|
||||
owner = data.possiblyDroppedTarget('parent_function_');
|
||||
owner = data['parent_function_'];
|
||||
}
|
||||
return makeInfoNode(node.index,
|
||||
name: node.name,
|
||||
|
||||
@@ -60,17 +60,21 @@ void main(List<String> args) => input.main(args);
|
||||
if (flag != null) '$flag=${snapshot.sizesJson}',
|
||||
];
|
||||
|
||||
// Compile input.dart to native and output instruction sizes.
|
||||
final result = await Process.run(dart2native, [
|
||||
final args = [
|
||||
'-o',
|
||||
snapshot.outputBinary,
|
||||
'--packages=$packages',
|
||||
'--extra-gen-snapshot-options=${extraGenSnapshotOptions.join(',')}',
|
||||
mainDart,
|
||||
]);
|
||||
];
|
||||
|
||||
// Compile input.dart to native and output instruction sizes.
|
||||
final result = await Process.run(dart2native, args);
|
||||
|
||||
expect(result.exitCode, equals(0), reason: '''
|
||||
Compilation completed successfully.
|
||||
Compilation completed with exit code ${result.exitCode}.
|
||||
|
||||
Command line: $dart2native ${args.join(' ')}
|
||||
|
||||
stdout: ${result.stdout}
|
||||
stderr: ${result.stderr}
|
||||
@@ -86,13 +90,18 @@ stderr: ${result.stderr}
|
||||
});
|
||||
}
|
||||
|
||||
const keepTempKey = 'KEEP_TEMPORARY_DIRECTORIES';
|
||||
|
||||
Future withTempDir(Future Function(String dir) f) async {
|
||||
final tempDir =
|
||||
Directory.systemTemp.createTempSync('instruction-sizes-test-');
|
||||
try {
|
||||
await f(tempDir.path);
|
||||
} finally {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
if (!Platform.environment.containsKey(keepTempKey) ||
|
||||
Platform.environment[keepTempKey].isEmpty) {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user