Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1395)

Unified Diff: src/snapshot/serializer.cc

Issue 1992723002: [serializer] prepare attached references for general use. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: address comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/snapshot/serializer.h ('k') | src/snapshot/serializer-common.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/snapshot/serializer.cc
diff --git a/src/snapshot/serializer.cc b/src/snapshot/serializer.cc
index a0f54806e78bff38b6815c30785fae0431f9c268..f6f2200775be526712a44cc762b88983bfb37a42 100644
--- a/src/snapshot/serializer.cc
+++ b/src/snapshot/serializer.cc
@@ -124,10 +124,9 @@ void Serializer::EncodeReservations(
}
#ifdef DEBUG
-bool Serializer::BackReferenceIsAlreadyAllocated(BackReference reference) {
- DCHECK(reference.is_valid());
- DCHECK(!reference.is_source());
- DCHECK(!reference.is_global_proxy());
+bool Serializer::BackReferenceIsAlreadyAllocated(
+ SerializerReference reference) {
+ DCHECK(reference.is_back_reference());
AllocationSpace space = reference.space();
int chunk_index = reference.chunk_index();
if (space == LO_SPACE) {
@@ -163,25 +162,21 @@ bool Serializer::SerializeKnownObject(HeapObject* obj, HowToCode how_to_code,
return true;
}
}
- BackReference back_reference = back_reference_map_.Lookup(obj);
- if (back_reference.is_valid()) {
+ SerializerReference reference = reference_map_.Lookup(obj);
+ if (reference.is_valid()) {
// Encode the location of an already deserialized object in order to write
// its location into a later object. We can encode the location as an
// offset fromthe start of the deserialized objects or as an offset
// backwards from thecurrent allocation pointer.
- if (back_reference.is_source()) {
+ if (reference.is_attached_reference()) {
FlushSkip(skip);
- if (FLAG_trace_serializer) PrintF(" Encoding source object\n");
- DCHECK(how_to_code == kPlain && where_to_point == kStartOfObject);
- sink_->Put(kAttachedReference + kPlain + kStartOfObject, "Source");
- sink_->PutInt(kSourceObjectReference, "kSourceObjectReference");
- } else if (back_reference.is_global_proxy()) {
- FlushSkip(skip);
- if (FLAG_trace_serializer) PrintF(" Encoding global proxy\n");
- DCHECK(how_to_code == kPlain && where_to_point == kStartOfObject);
- sink_->Put(kAttachedReference + kPlain + kStartOfObject, "Global Proxy");
- sink_->PutInt(kGlobalProxyReference, "kGlobalProxyReference");
+ if (FLAG_trace_serializer) {
+ PrintF(" Encoding attached reference %d\n",
+ reference.attached_reference_index());
+ }
+ PutAttachedReference(reference, how_to_code, where_to_point);
} else {
+ DCHECK(reference.is_back_reference());
if (FLAG_trace_serializer) {
PrintF(" Encoding back reference to: ");
obj->ShortPrint();
@@ -189,7 +184,7 @@ bool Serializer::SerializeKnownObject(HeapObject* obj, HowToCode how_to_code,
}
PutAlignmentPrefix(obj);
- AllocationSpace space = back_reference.space();
+ AllocationSpace space = reference.space();
if (skip == 0) {
sink_->Put(kBackref + how_to_code + where_to_point + space, "BackRef");
} else {
@@ -197,7 +192,7 @@ bool Serializer::SerializeKnownObject(HeapObject* obj, HowToCode how_to_code,
"BackRefWithSkip");
sink_->PutInt(skip, "BackRefSkipDistance");
}
- PutBackReference(obj, back_reference);
+ PutBackReference(obj, reference);
}
return true;
}
@@ -236,12 +231,24 @@ void Serializer::PutSmi(Smi* smi) {
for (int i = 0; i < kPointerSize; i++) sink_->Put(bytes[i], "Byte");
}
-void Serializer::PutBackReference(HeapObject* object, BackReference reference) {
+void Serializer::PutBackReference(HeapObject* object,
+ SerializerReference reference) {
DCHECK(BackReferenceIsAlreadyAllocated(reference));
- sink_->PutInt(reference.reference(), "BackRefValue");
+ sink_->PutInt(reference.back_reference(), "BackRefValue");
hot_objects_.Add(object);
}
+void Serializer::PutAttachedReference(SerializerReference reference,
+ HowToCode how_to_code,
+ WhereToPoint where_to_point) {
+ DCHECK(reference.is_attached_reference());
+ DCHECK((how_to_code == kPlain && where_to_point == kStartOfObject) ||
+ (how_to_code == kPlain && where_to_point == kInnerPointer) ||
+ (how_to_code == kFromCode && where_to_point == kInnerPointer));
+ sink_->Put(kAttachedReference + how_to_code + where_to_point, "AttachedRef");
+ sink_->PutInt(reference.attached_reference_index(), "AttachedRefIndex");
+}
+
int Serializer::PutAlignmentPrefix(HeapObject* object) {
AllocationAlignment alignment = object->RequiredAlignment();
if (alignment != kWordAligned) {
@@ -253,14 +260,14 @@ int Serializer::PutAlignmentPrefix(HeapObject* object) {
return 0;
}
-BackReference Serializer::AllocateLargeObject(int size) {
+SerializerReference Serializer::AllocateLargeObject(int size) {
// Large objects are allocated one-by-one when deserializing. We do not
// have to keep track of multiple chunks.
large_objects_total_size_ += size;
- return BackReference::LargeObjectReference(seen_large_objects_index_++);
+ return SerializerReference::LargeObjectReference(seen_large_objects_index_++);
}
-BackReference Serializer::Allocate(AllocationSpace space, int size) {
+SerializerReference Serializer::Allocate(AllocationSpace space, int size) {
DCHECK(space >= 0 && space < kNumberOfPreallocatedSpaces);
DCHECK(size > 0 && size <= static_cast<int>(max_chunk_size(space)));
uint32_t new_chunk_size = pending_chunk_[space] + size;
@@ -270,14 +277,13 @@ BackReference Serializer::Allocate(AllocationSpace space, int size) {
sink_->Put(kNextChunk, "NextChunk");
sink_->Put(space, "NextChunkSpace");
completed_chunks_[space].Add(pending_chunk_[space]);
- DCHECK_LE(completed_chunks_[space].length(), BackReference::kMaxChunkIndex);
pending_chunk_[space] = 0;
new_chunk_size = size;
}
uint32_t offset = pending_chunk_[space];
pending_chunk_[space] = new_chunk_size;
- return BackReference::Reference(space, completed_chunks_[space].length(),
- offset);
+ return SerializerReference::BackReference(
+ space, completed_chunks_[space].length(), offset);
}
void Serializer::Pad() {
@@ -320,7 +326,7 @@ void Serializer::ObjectSerializer::SerializePrologue(AllocationSpace space,
CodeNameEvent(object_->address(), sink_->Position(), code_name));
}
- BackReference back_reference;
+ SerializerReference back_reference;
if (space == LO_SPACE) {
sink_->Put(kNewObject + reference_representation_ + space,
"NewLargeObject");
@@ -345,7 +351,7 @@ void Serializer::ObjectSerializer::SerializePrologue(AllocationSpace space,
#endif // OBJECT_PRINT
// Mark this object as already serialized.
- serializer_->back_reference_map()->Add(object_, back_reference);
+ serializer_->reference_map()->Add(object_, back_reference);
// Serialize the map (first word of the object).
serializer_->SerializeObject(map, kPlain, kStartOfObject, 0);
@@ -513,15 +519,17 @@ void Serializer::ObjectSerializer::SerializeDeferred() {
int size = object_->Size();
Map* map = object_->map();
- BackReference reference = serializer_->back_reference_map()->Lookup(object_);
+ SerializerReference back_reference =
+ serializer_->reference_map()->Lookup(object_);
+ DCHECK(back_reference.is_back_reference());
// Serialize the rest of the object.
CHECK_EQ(0, bytes_processed_so_far_);
bytes_processed_so_far_ = kPointerSize;
serializer_->PutAlignmentPrefix(object_);
- sink_->Put(kNewObject + reference.space(), "deferred object");
- serializer_->PutBackReference(object_, reference);
+ sink_->Put(kNewObject + back_reference.space(), "deferred object");
+ serializer_->PutBackReference(object_, back_reference);
sink_->PutInt(size >> kPointerSizeLog2, "deferred object size");
UnlinkWeakNextScope unlink_weak_next(object_);
« no previous file with comments | « src/snapshot/serializer.h ('k') | src/snapshot/serializer-common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698