Files
sdk/runtime/vm/program_visitor.h
T
Teagan Strickland b55342cb3e [vm/aot] Drop some Function objects not needed at runtime.
In particular, don't serialize a function if its code is used by the
dispatch table, but there's no need for the function object itself
at runtime like dynamic lookup or dynamic invocation forwarders.

However, just because the owning function is not needed at runtime,
it may be used during serialization for things like assembly label
creation. Thus, instead of just clearing out the Code's owner field,
we add a new WeakSerializationReference (WSR) object whose target is
the original contents of the owner field. The WSR allows the
serializer to access the original owner, but also signals to the
serializer that the target should not be serialized in AOT snapshots
unless there are additional strong (non-WSR) references.

If no strong references are found, then the references to the WSR
in the snapshot are replaced with a reference to a WSR that only
contains the class ID of the original target. The serializer creates
only one WSR per class ID.

If strong references are found, then the target is still serialized.
In this case, the WSR is dropped entirely and any reference to it is
replaced with a direct reference to the serialized target. Thus, WSRs
only exist in the precompiled runtime for targets with no strong
references.

Changes on the Flutter gallery in release mode:
arm7: total size -1.10%, isolate size -6.08%
arm8: total size -1.16%, isolate size -6.09%

Bug: https://github.com/dart-lang/sdk/issues/41052

Change-Id: I5b435ca71ef85f50fe3484789087471a91aa4fe2
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-kernel-precomp-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137104
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2020-03-30 18:33:48 +00:00

62 lines
1.7 KiB
C++

// Copyright (c) 2015, 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.
#ifndef RUNTIME_VM_PROGRAM_VISITOR_H_
#define RUNTIME_VM_PROGRAM_VISITOR_H_
#include "vm/allocation.h"
namespace dart {
class Class;
class Code;
class Function;
template <typename T>
class Visitor : public ValueObject {
public:
virtual ~Visitor() {}
virtual void Visit(const T& obj) = 0;
};
using ClassVisitor = Visitor<Class>;
using CodeVisitor = Visitor<Code>;
using FunctionVisitor = Visitor<Function>;
class ProgramVisitor : public AllStatic {
public:
// Currently visits the following code objects:
// * Code objects for functions (visited via VisitFunctions) where HasCode()
// is true.
// * Code objects for entries in the dispatch table (if applicable).
//
// Notably, it does not visit any stubs not reachable via these routes.
static void VisitCode(CodeVisitor* visitor);
static void VisitFunctions(FunctionVisitor* visitor);
static void VisitClasses(ClassVisitor* visitor);
static void Dedup();
private:
#if !defined(DART_PRECOMPILED_RUNTIME)
static void BindStaticCalls();
static void ShareMegamorphicBuckets();
static void NormalizeAndDedupCompressedStackMaps();
static void DedupPcDescriptors();
static void DedupDeoptEntries();
#if defined(DART_PRECOMPILER)
static void DedupCatchEntryMovesMaps();
static void DedupUnlinkedCalls();
#endif
static void DedupCodeSourceMaps();
static void DedupLists();
static void DedupInstructions();
static void DedupInstructionsWithSameMetadata();
#endif // !defined(DART_PRECOMPILED_RUNTIME)
};
} // namespace dart
#endif // RUNTIME_VM_PROGRAM_VISITOR_H_