Skip to content

Commit 7eedcb7

Browse files
committed
Omit kernel data from AOT snapshot
Omit kernel function bodies when writing AOT snapshot. Saves 2.7MB (16%) on the snapshot size of Flutter Gallery. Bug: #30616 Change-Id: I7ab40d13e43607fe7c68670f8e923807b9cea37f Reviewed-on: https://dart-review.googlesource.com/5220 Reviewed-by: Vyacheslav Egorov <[email protected]> Reviewed-by: Siva Chandra <[email protected]>
1 parent abd20df commit 7eedcb7

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

runtime/vm/clustered_snapshot.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ class FunctionSerializationCluster : public SerializationCluster {
506506
objects_.Add(func);
507507

508508
RawObject** from = func->from();
509-
RawObject** to = func->to_snapshot();
509+
RawObject** to = func->to_snapshot(s->kind());
510510
for (RawObject** p = from; p <= to; p++) {
511511
s->Push(*p);
512512
}
@@ -535,7 +535,7 @@ class FunctionSerializationCluster : public SerializationCluster {
535535
for (intptr_t i = 0; i < count; i++) {
536536
RawFunction* func = objects_[i];
537537
RawObject** from = func->from();
538-
RawObject** to = func->to_snapshot();
538+
RawObject** to = func->to_snapshot(s->kind());
539539
for (RawObject** p = from; p <= to; p++) {
540540
s->WriteRef(*p);
541541
}
@@ -601,7 +601,7 @@ class FunctionDeserializationCluster : public DeserializationCluster {
601601
Deserializer::InitializeHeader(func, kFunctionCid,
602602
Function::InstanceSize(), is_vm_object);
603603
RawObject** from = func->from();
604-
RawObject** to_snapshot = func->to_snapshot();
604+
RawObject** to_snapshot = func->to_snapshot(d->kind());
605605
RawObject** to = func->to();
606606
for (RawObject** p = from; p <= to_snapshot; p++) {
607607
*p = d->ReadRef();

runtime/vm/raw_object.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,21 @@ class RawFunction : public RawObject {
849849
RawTypeArguments* type_parameters_; // Array of TypeParameter.
850850
RawObject* data_; // Additional data specific to the function kind.
851851
RawTypedData* kernel_data_;
852-
RawObject** to_snapshot() {
853-
return reinterpret_cast<RawObject**>(&ptr()->kernel_data_);
852+
RawObject** to_snapshot(Snapshot::Kind kind) {
853+
switch (kind) {
854+
case Snapshot::kFullAOT:
855+
return reinterpret_cast<RawObject**>(&ptr()->data_);
856+
case Snapshot::kFull:
857+
case Snapshot::kFullJIT:
858+
case Snapshot::kScript:
859+
return reinterpret_cast<RawObject**>(&ptr()->kernel_data_);
860+
case Snapshot::kMessage:
861+
case Snapshot::kNone:
862+
case Snapshot::kInvalid:
863+
break;
864+
}
865+
UNREACHABLE();
866+
return NULL;
854867
}
855868
RawArray* ic_data_array_; // ICData of unoptimized code.
856869
RawObject** to_no_code() {

runtime/vm/raw_object_snapshot.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ RawFunction* Function::ReadFrom(SnapshotReader* reader,
736736
func.set_was_compiled(false);
737737

738738
// Set all the object fields.
739-
READ_OBJECT_FIELDS(func, func.raw()->from(), func.raw()->to_snapshot(),
739+
READ_OBJECT_FIELDS(func, func.raw()->from(), func.raw()->to_snapshot(kind),
740740
kAsReference);
741741
// Initialize all fields that are not part of the snapshot.
742742
bool is_optimized = func.usage_counter() != 0;
@@ -810,7 +810,7 @@ void RawFunction::WriteTo(SnapshotWriter* writer,
810810

811811
// Write out all the object pointer fields.
812812
SnapshotWriterVisitor visitor(writer, kAsReference);
813-
visitor.VisitPointers(from(), to_snapshot());
813+
visitor.VisitPointers(from(), to_snapshot(kind));
814814
if (is_optimized) {
815815
// Write out the ic data array as the function is optimized.
816816
writer->WriteObjectImpl(ptr()->ic_data_array_, kAsReference);

0 commit comments

Comments
 (0)