Chromium Code Reviews| Index: runtime/vm/raw_object_snapshot.cc |
| diff --git a/runtime/vm/raw_object_snapshot.cc b/runtime/vm/raw_object_snapshot.cc |
| index 13791de86ce08e556787214d9f9775b80492b2a0..7fa871e8f628c0b027fb8dd2f57a19548136e82e 100644 |
| --- a/runtime/vm/raw_object_snapshot.cc |
| +++ b/runtime/vm/raw_object_snapshot.cc |
| @@ -504,10 +504,7 @@ RawPatchClass* PatchClass::ReadFrom(SnapshotReader* reader, |
| // Set all the object fields. |
| READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to(), kAsReference); |
| - ASSERT(((kind == Snapshot::kScript) && |
| - !Class::IsInFullSnapshot(cls.source_class())) || |
| - (kind == Snapshot::kFull)); |
| - |
| + ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| return cls.raw(); |
| } |
| @@ -631,37 +628,44 @@ RawFunction* Function::ReadFrom(SnapshotReader* reader, |
| ASSERT(reader != NULL); |
| ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| - // Allocate function object. |
| - Function& func = Function::ZoneHandle( |
| - reader->zone(), NEW_OBJECT(Function)); |
| - reader->AddBackRef(object_id, &func, kIsDeserialized); |
| - |
| - // Set all the non object fields. |
| - func.set_token_pos(reader->Read<int32_t>()); |
| - func.set_end_token_pos(reader->Read<int32_t>()); |
| - func.set_usage_counter(reader->Read<int32_t>()); |
| - func.set_num_fixed_parameters(reader->Read<int16_t>()); |
| - func.set_num_optional_parameters(reader->Read<int16_t>()); |
| - func.set_deoptimization_counter(reader->Read<int16_t>()); |
| - func.set_kind_tag(reader->Read<uint32_t>()); |
| - func.set_optimized_instruction_count(reader->Read<uint16_t>()); |
| - func.set_optimized_call_site_count(reader->Read<uint16_t>()); |
| + bool is_in_fullsnapshot = reader->Read<bool>(); |
| + if ((kind == Snapshot::kFull) || !is_in_fullsnapshot) { |
| + // Allocate function object. |
| + Function& func = Function::ZoneHandle( |
| + reader->zone(), NEW_OBJECT(Function)); |
| + reader->AddBackRef(object_id, &func, kIsDeserialized); |
| + |
| + // Set all the non object fields. |
| + func.set_token_pos(reader->Read<int32_t>()); |
| + func.set_end_token_pos(reader->Read<int32_t>()); |
| + func.set_usage_counter(reader->Read<int32_t>()); |
| + func.set_num_fixed_parameters(reader->Read<int16_t>()); |
| + func.set_num_optional_parameters(reader->Read<int16_t>()); |
| + func.set_deoptimization_counter(reader->Read<int16_t>()); |
| + func.set_kind_tag(reader->Read<uint32_t>()); |
| + func.set_optimized_instruction_count(reader->Read<uint16_t>()); |
| + func.set_optimized_call_site_count(reader->Read<uint16_t>()); |
| - // Set all the object fields. |
| - READ_OBJECT_FIELDS(func, |
| - func.raw()->from(), |
| - reader->snapshot_code() ? func.raw()->to() |
| - : func.raw()->to_snapshot(), |
| - kAsReference); |
| + // Set all the object fields. |
| + READ_OBJECT_FIELDS(func, |
| + func.raw()->from(), |
| + reader->snapshot_code() ? func.raw()->to() |
| + : func.raw()->to_snapshot(), |
| + kAsReference); |
| - if (!reader->snapshot_code()) { |
| - // Initialize all fields that are not part of the snapshot. |
| - func.ClearICDataArray(); |
| - func.ClearCode(); |
| + if (!reader->snapshot_code()) { |
| + // Initialize all fields that are not part of the snapshot. |
| + if (func.usage_counter() == 0) { |
|
rmacnak
2015/09/14 23:34:17
Might as well clear it on the write-side to make t
siva
2015/09/15 21:40:04
Done.
|
| + func.ClearICDataArray(); |
| + } |
| + func.ClearCode(); |
| + } else { |
| + // TODO(rmacnak): Fix entry_point_. |
| + } |
| + return func.raw(); |
| } else { |
| - // TODO(rmacnak): Fix entry_point_. |
| + return reader->ReadFunctionId(object_id); |
| } |
| - return func.raw(); |
| } |
| @@ -670,6 +674,17 @@ void RawFunction::WriteTo(SnapshotWriter* writer, |
| Snapshot::Kind kind) { |
| ASSERT(writer != NULL); |
| ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| + bool is_in_fullsnapshot = false; |
| + bool owner_is_class = false; |
| + if (kind == Snapshot::kScript) { |
| + intptr_t tags = writer->GetObjectTags(ptr()->owner_); |
| + intptr_t cid = ClassIdTag::decode(tags); |
| + owner_is_class = (cid == kClassCid); |
| + is_in_fullsnapshot = owner_is_class ? |
| + Class::IsInFullSnapshot(reinterpret_cast<RawClass*>(ptr()->owner_)) : |
| + PatchClass::IsInFullSnapshot( |
| + reinterpret_cast<RawPatchClass*>(ptr()->owner_)); |
| + } |
| // Write out the serialization header value for this object. |
| writer->WriteInlinedObjectHeader(object_id); |
| @@ -678,25 +693,34 @@ void RawFunction::WriteTo(SnapshotWriter* writer, |
| writer->WriteVMIsolateObject(kFunctionCid); |
| writer->WriteTags(writer->GetObjectTags(this)); |
| - // Write out all the non object fields. |
| - writer->Write<int32_t>(ptr()->token_pos_); |
| - writer->Write<int32_t>(ptr()->end_token_pos_); |
| - if (Code::IsOptimized(ptr()->instructions_->ptr()->code_)) { |
| - writer->Write<int32_t>(FLAG_optimization_counter_threshold); |
| + // Write out the boolean is_in_fullsnapshot first as this will |
| + // help the reader decide how the rest of the information needs |
| + // to be interpreted. |
| + writer->Write<bool>(is_in_fullsnapshot); |
| + |
| + if (kind == Snapshot::kFull || !is_in_fullsnapshot) { |
| + // Write out all the non object fields. |
| + writer->Write<int32_t>(ptr()->token_pos_); |
| + writer->Write<int32_t>(ptr()->end_token_pos_); |
| + if (Code::IsOptimized(ptr()->instructions_->ptr()->code_)) { |
| + writer->Write<int32_t>(FLAG_optimization_counter_threshold); |
| + } else { |
| + writer->Write<int32_t>(0); |
| + } |
| + writer->Write<int16_t>(ptr()->num_fixed_parameters_); |
| + writer->Write<int16_t>(ptr()->num_optional_parameters_); |
| + writer->Write<int16_t>(ptr()->deoptimization_counter_); |
| + writer->Write<uint32_t>(ptr()->kind_tag_); |
| + writer->Write<uint16_t>(ptr()->optimized_instruction_count_); |
| + writer->Write<uint16_t>(ptr()->optimized_call_site_count_); |
| + |
| + // Write out all the object pointer fields. |
| + SnapshotWriterVisitor visitor(writer); |
| + visitor.VisitPointers( |
| + from(), writer->snapshot_code() ? to() : to_snapshot()); |
| } else { |
| - writer->Write<int32_t>(0); |
| + writer->WriteFunctionId(this, owner_is_class); |
| } |
| - writer->Write<int16_t>(ptr()->num_fixed_parameters_); |
| - writer->Write<int16_t>(ptr()->num_optional_parameters_); |
| - writer->Write<int16_t>(ptr()->deoptimization_counter_); |
| - writer->Write<uint32_t>(ptr()->kind_tag_); |
| - writer->Write<uint16_t>(ptr()->optimized_instruction_count_); |
| - writer->Write<uint16_t>(ptr()->optimized_call_site_count_); |
| - |
| - // Write out all the object pointer fields. |
| - SnapshotWriterVisitor visitor(writer); |
| - visitor.VisitPointers(from(), writer->snapshot_code() ? to() |
| - : to_snapshot()); |
| } |
| @@ -1665,8 +1689,7 @@ RawICData* ICData::ReadFrom(SnapshotReader* reader, |
| intptr_t object_id, |
| intptr_t tags, |
| Snapshot::Kind kind) { |
| - ASSERT(reader->snapshot_code()); |
| - ASSERT(kind == Snapshot::kFull); |
| + ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData)); |
| reader->AddBackRef(object_id, &result, kIsDeserialized); |
| @@ -1686,8 +1709,7 @@ RawICData* ICData::ReadFrom(SnapshotReader* reader, |
| void RawICData::WriteTo(SnapshotWriter* writer, |
| intptr_t object_id, |
| Snapshot::Kind kind) { |
| - ASSERT(writer->snapshot_code()); |
| - ASSERT(kind == Snapshot::kFull); |
| + ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); |
| // Write out the serialization header value for this object. |
| writer->WriteInlinedObjectHeader(object_id); |