| Index: runtime/vm/raw_object_snapshot.cc
|
| diff --git a/runtime/vm/raw_object_snapshot.cc b/runtime/vm/raw_object_snapshot.cc
|
| index da3c3a646719b30974de152695bc6150a87bc1f3..49ee85b237c2f47106247e2e2c9ff031ff003d99 100644
|
| --- a/runtime/vm/raw_object_snapshot.cc
|
| +++ b/runtime/vm/raw_object_snapshot.cc
|
| @@ -707,6 +707,8 @@ RawFunction* Function::ReadFrom(SnapshotReader* reader,
|
| // Initialize all fields that are not part of the snapshot.
|
| func.ClearICDataArray();
|
| func.ClearCode();
|
| + } else {
|
| + // TODO(rmacnak): Fix entry_point_.
|
| }
|
| return func.raw();
|
| }
|
| @@ -1188,7 +1190,6 @@ RawCode* Code::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| - UNREACHABLE(); // Untested.
|
| ASSERT(reader->snapshot_code());
|
| ASSERT(kind == Snapshot::kFull);
|
|
|
| @@ -1211,6 +1212,8 @@ RawCode* Code::ReadFrom(SnapshotReader* reader,
|
| reader->PassiveObjectHandle()->raw());
|
| }
|
|
|
| + // TODO(rmacnak): Fix entry_point_.
|
| +
|
| return result.raw();
|
| }
|
|
|
| @@ -1252,15 +1255,22 @@ RawInstructions* Instructions::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| - UNREACHABLE(); // Untested.
|
| ASSERT(reader->snapshot_code());
|
| ASSERT(kind == Snapshot::kFull);
|
|
|
| - intptr_t id = reader->Read<int32_t>();
|
| + intptr_t full_tags = static_cast<uword>(reader->Read<intptr_t>());
|
| + intptr_t offset = reader->Read<int32_t>();
|
| Instructions& result =
|
| Instructions::ZoneHandle(reader->zone(),
|
| - reader->GetInstructionsById(id));
|
| + reader->GetInstructionsAt(offset, full_tags));
|
| reader->AddBackRef(object_id, &result, kIsDeserialized);
|
| +
|
| + {
|
| + // TODO(rmacnak): Drop after calling convention change.
|
| + Code::CheckedHandle(reader->ReadObjectImpl(kAsReference));
|
| + ObjectPool::CheckedHandle(reader->ReadObjectImpl(kAsReference));
|
| + }
|
| +
|
| return result.raw();
|
| }
|
|
|
| @@ -1276,11 +1286,23 @@ void RawInstructions::WriteTo(SnapshotWriter* writer,
|
| writer->WriteInlinedObjectHeader(object_id);
|
| writer->WriteVMIsolateObject(kInstructionsCid);
|
| writer->WriteTags(writer->GetObjectTags(this));
|
| - writer->WriteObjectImpl(ptr()->code_, kAsReference);
|
| - writer->WriteObjectImpl(ptr()->object_pool_, kAsReference);
|
| }
|
|
|
| + writer->Write<intptr_t>(writer->GetObjectTags(this)); // For sanity check.
|
| +
|
| + // Temporarily restore the object header for writing to the text section.
|
| + // TODO(asiva): Don't mutate object headers during serialization.
|
| + uword object_tags = writer->GetObjectTags(this);
|
| + uword snapshot_tags = ptr()->tags_;
|
| + ptr()->tags_ = object_tags;
|
| writer->Write<int32_t>(writer->GetInstructionsId(this));
|
| + ptr()->tags_ = snapshot_tags;
|
| +
|
| + {
|
| + // TODO(rmacnak): Drop after calling convention change.
|
| + writer->WriteObjectImpl(ptr()->code_, kAsReference);
|
| + writer->WriteObjectImpl(ptr()->object_pool_, kAsReference);
|
| + }
|
| }
|
|
|
|
|
| @@ -1288,7 +1310,6 @@ RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| - UNREACHABLE(); // Untested.
|
| ASSERT(reader->snapshot_code());
|
| ASSERT(kind == Snapshot::kFull);
|
|
|
| @@ -1299,15 +1320,15 @@ RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader,
|
| NEW_OBJECT_WITH_LEN(ObjectPool, length));
|
| reader->AddBackRef(object_id, &result, kIsDeserialized);
|
|
|
| - RawTypedData* info_array = result.raw_ptr()->info_array_->ptr();
|
| + const TypedData& info_array =
|
| + TypedData::Handle(reader->NewTypedData(kTypedDataInt8ArrayCid, length));
|
| + result.set_info_array(info_array);
|
|
|
| - // Set all the object fields.
|
| - // TODO(5411462): Need to assert No GC can happen here, even though
|
| - // allocations may happen.
|
| + NoSafepointScope no_safepoint;
|
| for (intptr_t i = 0; i < length; i++) {
|
| ObjectPool::EntryType entry_type =
|
| - static_cast<ObjectPool::EntryType>(reader->Read<uint8_t>());
|
| - info_array->data()[i] = entry_type;
|
| + static_cast<ObjectPool::EntryType>(reader->Read<int8_t>());
|
| + *reinterpret_cast<int8_t*>(info_array.DataAddr(i)) = entry_type;
|
| switch (entry_type) {
|
| case ObjectPool::kTaggedObject: {
|
| (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference);
|
| @@ -1355,7 +1376,7 @@ void RawObjectPool::WriteTo(SnapshotWriter* writer,
|
| for (intptr_t i = 0; i < length; i++) {
|
| ObjectPool::EntryType entry_type =
|
| static_cast<ObjectPool::EntryType>(info_array->data()[i]);
|
| - writer->Write<uint8_t>(entry_type);
|
| + writer->Write<int8_t>(entry_type);
|
| Entry& entry = ptr()->data()[i];
|
| switch (entry_type) {
|
| case ObjectPool::kTaggedObject:
|
| @@ -1379,12 +1400,13 @@ RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| - UNREACHABLE(); // Untested.
|
| ASSERT(reader->snapshot_code());
|
| + ASSERT(kind == Snapshot::kFull);
|
|
|
| const int32_t length = reader->Read<int32_t>();
|
| - PcDescriptors& result = PcDescriptors::ZoneHandle(reader->zone(),
|
| - PcDescriptors::New(length));
|
| + PcDescriptors& result =
|
| + PcDescriptors::ZoneHandle(reader->zone(),
|
| + NEW_OBJECT_WITH_LEN(PcDescriptors, length));
|
| reader->AddBackRef(object_id, &result, kIsDeserialized);
|
|
|
| if (result.Length() > 0) {
|
| @@ -1402,6 +1424,7 @@ void RawPcDescriptors::WriteTo(SnapshotWriter* writer,
|
| intptr_t object_id,
|
| Snapshot::Kind kind) {
|
| ASSERT(writer->snapshot_code());
|
| + ASSERT(kind == Snapshot::kFull);
|
|
|
| // Write out the serialization header value for this object.
|
| writer->WriteInlinedObjectHeader(object_id);
|
| @@ -1420,19 +1443,19 @@ RawStackmap* Stackmap::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| - UNREACHABLE(); // Untested.
|
| ASSERT(reader->snapshot_code());
|
| + ASSERT(kind == Snapshot::kFull);
|
|
|
| const int32_t length = reader->Read<int32_t>();
|
| - const int32_t register_bit_count = reader->Read<int32_t>();
|
| - const uword pc_offset = reader->Read<uint32_t>();
|
| -
|
| Stackmap& result =
|
| Stackmap::ZoneHandle(reader->zone(),
|
| - Stackmap::New(length, register_bit_count, pc_offset));
|
| + reader->NewStackmap(length));
|
| reader->AddBackRef(object_id, &result, kIsDeserialized);
|
|
|
| - if (result.Length() > 0) {
|
| + result.SetRegisterBitCount(reader->Read<int32_t>());
|
| + result.SetPcOffset(reader->Read<uint32_t>());
|
| +
|
| + if (length > 0) {
|
| NoSafepointScope no_safepoint;
|
| intptr_t len = (result.Length() + 7) / 8;
|
| uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data());
|
| @@ -1447,11 +1470,13 @@ void RawStackmap::WriteTo(SnapshotWriter* writer,
|
| intptr_t object_id,
|
| Snapshot::Kind kind) {
|
| ASSERT(writer->snapshot_code());
|
| + ASSERT(kind == Snapshot::kFull);
|
|
|
| // Write out the serialization header value for this object.
|
| writer->WriteInlinedObjectHeader(object_id);
|
| writer->WriteIndexedObject(kStackmapCid);
|
| writer->WriteTags(writer->GetObjectTags(this));
|
| +
|
| writer->Write<int32_t>(ptr()->length_);
|
| writer->Write<int32_t>(ptr()->register_bit_count_);
|
| writer->Write<uint32_t>(ptr()->pc_offset_);
|
| @@ -1467,14 +1492,15 @@ RawLocalVarDescriptors* LocalVarDescriptors::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| - UNREACHABLE(); // Untested.
|
| ASSERT(reader->snapshot_code());
|
| + ASSERT(kind == Snapshot::kFull);
|
|
|
| const int32_t num_entries = reader->Read<int32_t>();
|
|
|
| LocalVarDescriptors& result =
|
| LocalVarDescriptors::ZoneHandle(reader->zone(),
|
| - LocalVarDescriptors::New(num_entries));
|
| + NEW_OBJECT_WITH_LEN(LocalVarDescriptors,
|
| + num_entries));
|
| reader->AddBackRef(object_id, &result, kIsDeserialized);
|
|
|
| for (intptr_t i = 0; i < num_entries; i++) {
|
| @@ -1499,6 +1525,7 @@ void RawLocalVarDescriptors::WriteTo(SnapshotWriter* writer,
|
| intptr_t object_id,
|
| Snapshot::Kind kind) {
|
| ASSERT(writer->snapshot_code());
|
| + ASSERT(kind == Snapshot::kFull);
|
|
|
| // Write out the serialization header value for this object.
|
| writer->WriteInlinedObjectHeader(object_id);
|
| @@ -1520,15 +1547,14 @@ RawExceptionHandlers* ExceptionHandlers::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| - UNREACHABLE(); // Untested.
|
| ASSERT(reader->snapshot_code());
|
| + ASSERT(kind == Snapshot::kFull);
|
|
|
| - // handled_types_data.
|
| - *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject);
|
| -
|
| + const int32_t num_entries = reader->Read<int32_t>();
|
| ExceptionHandlers& result =
|
| ExceptionHandlers::ZoneHandle(reader->zone(),
|
| - ExceptionHandlers::New(*reader->ArrayHandle()));
|
| + NEW_OBJECT_WITH_LEN(ExceptionHandlers,
|
| + num_entries));
|
| reader->AddBackRef(object_id, &result, kIsDeserialized);
|
|
|
| if (result.num_entries() > 0) {
|
| @@ -1540,6 +1566,10 @@ RawExceptionHandlers* ExceptionHandlers::ReadFrom(SnapshotReader* reader,
|
| reader->ReadBytes(data, len);
|
| }
|
|
|
| + *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject);
|
| + result.StorePointer(&result.raw_ptr()->handled_types_data_,
|
| + reader->ArrayHandle()->raw());
|
| +
|
| return result.raw();
|
| }
|
|
|
| @@ -1548,18 +1578,21 @@ void RawExceptionHandlers::WriteTo(SnapshotWriter* writer,
|
| intptr_t object_id,
|
| Snapshot::Kind kind) {
|
| ASSERT(writer->snapshot_code());
|
| + ASSERT(kind == Snapshot::kFull);
|
|
|
| // Write out the serialization header value for this object.
|
| writer->WriteInlinedObjectHeader(object_id);
|
| writer->WriteIndexedObject(kExceptionHandlersCid);
|
| writer->WriteTags(writer->GetObjectTags(this));
|
| - writer->WriteObjectImpl(ptr()->handled_types_data_, kAsInlinedObject);
|
| + writer->Write<int32_t>(ptr()->num_entries_);
|
|
|
| if (ptr()->num_entries_ > 0) {
|
| intptr_t len = ptr()->num_entries_ * sizeof(HandlerInfo);
|
| uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data());
|
| writer->WriteBytes(data, len);
|
| }
|
| +
|
| + writer->WriteObjectImpl(ptr()->handled_types_data_, kAsInlinedObject);
|
| }
|
|
|
|
|
| @@ -1635,7 +1668,6 @@ RawICData* ICData::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| - UNREACHABLE(); // Untested.
|
| ASSERT(reader->snapshot_code());
|
| ASSERT(kind == Snapshot::kFull);
|
|
|
| @@ -1686,7 +1718,6 @@ RawMegamorphicCache* MegamorphicCache::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| - UNREACHABLE(); // Untested.
|
| ASSERT(reader->snapshot_code());
|
| ASSERT(kind == Snapshot::kFull);
|
|
|
| @@ -1737,7 +1768,6 @@ RawSubtypeTestCache* SubtypeTestCache::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| - UNREACHABLE(); // Untested.
|
| ASSERT(reader->snapshot_code());
|
| ASSERT(kind == Snapshot::kFull);
|
|
|
| @@ -2539,13 +2569,18 @@ RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader,
|
|
|
| LinkedHashMap& map = LinkedHashMap::ZoneHandle(
|
| reader->zone(), LinkedHashMap::null());
|
| - if (kind == Snapshot::kFull || kind == Snapshot::kScript) {
|
| + if ((kind == Snapshot::kFull && !reader->snapshot_code()) ||
|
| + kind == Snapshot::kScript) {
|
| // The immutable maps that seed map literals are not yet VM-internal, so
|
| // we don't reach this.
|
| UNREACHABLE();
|
| } else {
|
| // Since the map might contain itself as a key or value, allocate first.
|
| - map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind));
|
| + if (kind == Snapshot::kFull) {
|
| + map = reader->NewLinkedHashMap();
|
| + } else {
|
| + map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind));
|
| + }
|
| }
|
| reader->AddBackRef(object_id, &map, kIsDeserialized);
|
|
|
| @@ -2566,7 +2601,9 @@ RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader,
|
| Utils::RoundUpToPowerOfTwo(used_data),
|
| static_cast<uintptr_t>(LinkedHashMap::kInitialIndexSize));
|
| Array& data = Array::ZoneHandle(reader->zone(),
|
| - Array::New(data_size, HEAP_SPACE(kind)));
|
| + NEW_OBJECT_WITH_LEN_SPACE(Array,
|
| + data_size,
|
| + kind));
|
| map.SetData(data);
|
| map.SetDeletedKeys(0);
|
|
|
| @@ -2590,10 +2627,10 @@ RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader,
|
| void RawLinkedHashMap::WriteTo(SnapshotWriter* writer,
|
| intptr_t object_id,
|
| Snapshot::Kind kind) {
|
| - if (kind == Snapshot::kFull || kind == Snapshot::kScript) {
|
| + if ((kind == Snapshot::kFull && !writer->snapshot_code()) ||
|
| + kind == Snapshot::kScript) {
|
| // The immutable maps that seed map literals are not yet VM-internal, so
|
| // we don't reach this.
|
| - UNREACHABLE();
|
| }
|
| ASSERT(writer != NULL);
|
|
|
| @@ -3039,11 +3076,18 @@ RawSendPort* SendPort::ReadFrom(SnapshotReader* reader,
|
| intptr_t object_id,
|
| intptr_t tags,
|
| Snapshot::Kind kind) {
|
| + ASSERT(kind == Snapshot::kMessage || reader->snapshot_code());
|
| +
|
| uint64_t id = reader->Read<uint64_t>();
|
| uint64_t origin_id = reader->Read<uint64_t>();
|
|
|
| - SendPort& result = SendPort::ZoneHandle(reader->zone(),
|
| - SendPort::New(id, origin_id));
|
| + SendPort& result = SendPort::ZoneHandle(reader->zone());
|
| + if (reader->snapshot_code()) {
|
| + // TODO(rmacnak): Reset fields in precompiled snapshots and assert
|
| + // this is unreachable.
|
| + } else {
|
| + result = SendPort::New(id, origin_id);
|
| + }
|
| reader->AddBackRef(object_id, &result, kIsDeserialized);
|
| return result.raw();
|
| }
|
|
|