Commit 6f6f1f62 authored by yangguo's avatar yangguo Committed by Commit bot

[snapshot] make snapshot sink a non-dynamic member of the serializer.

R=vogelheim@chromium.org

Review-Url: https://codereview.chromium.org/2052433003
Cr-Commit-Position: refs/heads/master@{#36890}
parent 235ed54a
......@@ -461,14 +461,10 @@ StartupData SnapshotCreator::CreateBlob(
}
data->contexts_.Clear();
i::SnapshotByteSink snapshot_sink;
i::StartupSerializer startup_serializer(isolate, &snapshot_sink,
function_code_handling);
i::StartupSerializer startup_serializer(isolate, function_code_handling);
startup_serializer.SerializeStrongReferences();
i::SnapshotByteSink context_sink;
i::PartialSerializer context_serializer(isolate, &startup_serializer,
&context_sink);
i::PartialSerializer context_serializer(isolate, &startup_serializer);
context_serializer.Serialize(&contexts[0]);
startup_serializer.SerializeWeakReferencesAndDeferred();
......
......@@ -26,15 +26,14 @@ ScriptData* CodeSerializer::Serialize(Isolate* isolate,
}
// Serialize code object.
SnapshotByteSink sink(info->code()->CodeSize() * 2);
CodeSerializer cs(isolate, &sink, *source);
CodeSerializer cs(isolate, *source);
DisallowHeapAllocation no_gc;
Object** location = Handle<Object>::cast(info).location();
cs.VisitPointer(location);
cs.SerializeDeferredObjects();
cs.Pad();
SerializedCodeData data(sink.data(), &cs);
SerializedCodeData data(cs.sink()->data(), &cs);
ScriptData* script_data = data.GetScriptData();
if (FLAG_profile_deserialization) {
......@@ -105,7 +104,7 @@ void CodeSerializer::SerializeGeneric(HeapObject* heap_object,
HowToCode how_to_code,
WhereToPoint where_to_point) {
// Object has not yet been serialized. Serialize it here.
ObjectSerializer serializer(this, heap_object, sink_, how_to_code,
ObjectSerializer serializer(this, heap_object, &sink_, how_to_code,
where_to_point);
serializer.Serialize();
}
......@@ -123,8 +122,8 @@ void CodeSerializer::SerializeBuiltin(int builtin_index, HowToCode how_to_code,
isolate()->builtins()->name(builtin_index));
}
sink_->Put(kBuiltin + how_to_code + where_to_point, "Builtin");
sink_->PutInt(builtin_index, "builtin_index");
sink_.Put(kBuiltin + how_to_code + where_to_point, "Builtin");
sink_.PutInt(builtin_index, "builtin_index");
}
void CodeSerializer::SerializeCodeStub(Code* code_stub, HowToCode how_to_code,
......
......@@ -28,8 +28,8 @@ class CodeSerializer : public Serializer {
const List<uint32_t>* stub_keys() const { return &stub_keys_; }
private:
CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source)
: Serializer(isolate, sink), source_(source) {
CodeSerializer(Isolate* isolate, String* source)
: Serializer(isolate), source_(source) {
reference_map_.AddAttachedReference(source);
}
......
......@@ -10,9 +10,8 @@ namespace v8 {
namespace internal {
PartialSerializer::PartialSerializer(Isolate* isolate,
Serializer* startup_snapshot_serializer,
SnapshotByteSink* sink)
: Serializer(isolate, sink),
Serializer* startup_snapshot_serializer)
: Serializer(isolate),
startup_serializer_(startup_snapshot_serializer),
next_partial_cache_index_(0) {
InitializeCodeAddressMap();
......@@ -63,9 +62,9 @@ void PartialSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
FlushSkip(skip);
int cache_index = PartialSnapshotCacheIndex(obj);
sink_->Put(kPartialSnapshotCache + how_to_code + where_to_point,
"PartialSnapshotCache");
sink_->PutInt(cache_index, "partial_snapshot_cache_index");
sink_.Put(kPartialSnapshotCache + how_to_code + where_to_point,
"PartialSnapshotCache");
sink_.PutInt(cache_index, "partial_snapshot_cache_index");
return;
}
......@@ -90,7 +89,7 @@ void PartialSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
}
// Object has not yet been serialized. Serialize it here.
ObjectSerializer serializer(this, obj, sink_, how_to_code, where_to_point);
ObjectSerializer serializer(this, obj, &sink_, how_to_code, where_to_point);
serializer.Serialize();
}
......
......@@ -13,8 +13,7 @@ namespace internal {
class PartialSerializer : public Serializer {
public:
PartialSerializer(Isolate* isolate, Serializer* startup_snapshot_serializer,
SnapshotByteSink* sink);
PartialSerializer(Isolate* isolate, Serializer* startup_snapshot_serializer);
~PartialSerializer() override;
......
......@@ -10,9 +10,8 @@
namespace v8 {
namespace internal {
Serializer::Serializer(Isolate* isolate, SnapshotByteSink* sink)
Serializer::Serializer(Isolate* isolate)
: isolate_(isolate),
sink_(sink),
external_reference_encoder_(isolate),
root_index_map_(isolate),
recursion_depth_(0),
......@@ -90,10 +89,10 @@ void Serializer::OutputStatistics(const char* name) {
void Serializer::SerializeDeferredObjects() {
while (deferred_objects_.length() > 0) {
HeapObject* obj = deferred_objects_.RemoveLast();
ObjectSerializer obj_serializer(this, obj, sink_, kPlain, kStartOfObject);
ObjectSerializer obj_serializer(this, obj, &sink_, kPlain, kStartOfObject);
obj_serializer.SerializeDeferred();
}
sink_->Put(kSynchronize, "Finished with deferred objects");
sink_.Put(kSynchronize, "Finished with deferred objects");
}
void Serializer::VisitPointers(Object** start, Object** end) {
......@@ -154,10 +153,10 @@ bool Serializer::SerializeKnownObject(HeapObject* obj, HowToCode how_to_code,
PrintF("\n");
}
if (skip != 0) {
sink_->Put(kHotObjectWithSkip + index, "HotObjectWithSkip");
sink_->PutInt(skip, "HotObjectSkipDistance");
sink_.Put(kHotObjectWithSkip + index, "HotObjectWithSkip");
sink_.PutInt(skip, "HotObjectSkipDistance");
} else {
sink_->Put(kHotObject + index, "HotObject");
sink_.Put(kHotObject + index, "HotObject");
}
return true;
}
......@@ -186,11 +185,11 @@ bool Serializer::SerializeKnownObject(HeapObject* obj, HowToCode how_to_code,
PutAlignmentPrefix(obj);
AllocationSpace space = reference.space();
if (skip == 0) {
sink_->Put(kBackref + how_to_code + where_to_point + space, "BackRef");
sink_.Put(kBackref + how_to_code + where_to_point + space, "BackRef");
} else {
sink_->Put(kBackrefWithSkip + how_to_code + where_to_point + space,
"BackRefWithSkip");
sink_->PutInt(skip, "BackRefSkipDistance");
sink_.Put(kBackrefWithSkip + how_to_code + where_to_point + space,
"BackRefWithSkip");
sink_.PutInt(skip, "BackRefSkipDistance");
}
PutBackReference(obj, reference);
}
......@@ -213,28 +212,28 @@ void Serializer::PutRoot(int root_index, HeapObject* object,
root_index < kNumberOfRootArrayConstants &&
!isolate()->heap()->InNewSpace(object)) {
if (skip == 0) {
sink_->Put(kRootArrayConstants + root_index, "RootConstant");
sink_.Put(kRootArrayConstants + root_index, "RootConstant");
} else {
sink_->Put(kRootArrayConstantsWithSkip + root_index, "RootConstant");
sink_->PutInt(skip, "SkipInPutRoot");
sink_.Put(kRootArrayConstantsWithSkip + root_index, "RootConstant");
sink_.PutInt(skip, "SkipInPutRoot");
}
} else {
FlushSkip(skip);
sink_->Put(kRootArray + how_to_code + where_to_point, "RootSerialization");
sink_->PutInt(root_index, "root_index");
sink_.Put(kRootArray + how_to_code + where_to_point, "RootSerialization");
sink_.PutInt(root_index, "root_index");
}
}
void Serializer::PutSmi(Smi* smi) {
sink_->Put(kOnePointerRawData, "Smi");
sink_.Put(kOnePointerRawData, "Smi");
byte* bytes = reinterpret_cast<byte*>(&smi);
for (int i = 0; i < kPointerSize; i++) sink_->Put(bytes[i], "Byte");
for (int i = 0; i < kPointerSize; i++) sink_.Put(bytes[i], "Byte");
}
void Serializer::PutBackReference(HeapObject* object,
SerializerReference reference) {
DCHECK(BackReferenceIsAlreadyAllocated(reference));
sink_->PutInt(reference.back_reference(), "BackRefValue");
sink_.PutInt(reference.back_reference(), "BackRefValue");
hot_objects_.Add(object);
}
......@@ -245,8 +244,8 @@ void Serializer::PutAttachedReference(SerializerReference 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");
sink_.Put(kAttachedReference + how_to_code + where_to_point, "AttachedRef");
sink_.PutInt(reference.attached_reference_index(), "AttachedRefIndex");
}
int Serializer::PutAlignmentPrefix(HeapObject* object) {
......@@ -254,7 +253,7 @@ int Serializer::PutAlignmentPrefix(HeapObject* object) {
if (alignment != kWordAligned) {
DCHECK(1 <= alignment && alignment <= 3);
byte prefix = (kAlignmentPrefix - 1) + alignment;
sink_->Put(prefix, "Alignment");
sink_.Put(prefix, "Alignment");
return Heap::GetMaximumFillToAlign(alignment);
}
return 0;
......@@ -274,8 +273,8 @@ SerializerReference Serializer::Allocate(AllocationSpace space, int size) {
if (new_chunk_size > max_chunk_size(space)) {
// The new chunk size would not fit onto a single page. Complete the
// current chunk and start a new one.
sink_->Put(kNextChunk, "NextChunk");
sink_->Put(space, "NextChunkSpace");
sink_.Put(kNextChunk, "NextChunk");
sink_.Put(space, "NextChunkSpace");
completed_chunks_[space].Add(pending_chunk_[space]);
pending_chunk_[space] = 0;
new_chunk_size = size;
......@@ -290,11 +289,11 @@ void Serializer::Pad() {
// The non-branching GetInt will read up to 3 bytes too far, so we need
// to pad the snapshot to make sure we don't read over the end.
for (unsigned i = 0; i < sizeof(int32_t) - 1; i++) {
sink_->Put(kNop, "Padding");
sink_.Put(kNop, "Padding");
}
// Pad up to pointer size for checksum.
while (!IsAligned(sink_->Position(), kPointerAlignment)) {
sink_->Put(kNop, "Padding");
while (!IsAligned(sink_.Position(), kPointerAlignment)) {
sink_.Put(kNop, "Padding");
}
}
......
......@@ -120,7 +120,7 @@ class CodeAddressMap : public CodeEventLogger {
// There can be only one serializer per V8 process.
class Serializer : public SerializerDeserializer {
public:
Serializer(Isolate* isolate, SnapshotByteSink* sink);
explicit Serializer(Isolate* isolate);
~Serializer() override;
void EncodeReservations(List<SerializedData::Reservation>* out) const;
......@@ -177,8 +177,8 @@ class Serializer : public SerializerDeserializer {
inline void FlushSkip(int skip) {
if (skip != 0) {
sink_->Put(kSkip, "SkipFromSerializeObject");
sink_->PutInt(skip, "SkipDistanceFromSerializeObject");
sink_.Put(kSkip, "SkipFromSerializeObject");
sink_.PutInt(skip, "SkipDistanceFromSerializeObject");
}
}
......@@ -208,7 +208,7 @@ class Serializer : public SerializerDeserializer {
return max_chunk_size_[space];
}
SnapshotByteSink* sink() const { return sink_; }
const SnapshotByteSink* sink() const { return &sink_; }
void QueueDeferredObject(HeapObject* obj) {
DCHECK(reference_map_.Lookup(obj).is_back_reference());
......@@ -219,7 +219,7 @@ class Serializer : public SerializerDeserializer {
Isolate* isolate_;
SnapshotByteSink* sink_;
SnapshotByteSink sink_;
ExternalReferenceEncoder external_reference_encoder_;
SerializerReferenceMap reference_map_;
......
......@@ -11,9 +11,9 @@ namespace v8 {
namespace internal {
StartupSerializer::StartupSerializer(
Isolate* isolate, SnapshotByteSink* sink,
Isolate* isolate,
v8::SnapshotCreator::FunctionCodeHandling function_code_handling)
: Serializer(isolate, sink),
: Serializer(isolate),
clear_function_code_(function_code_handling ==
v8::SnapshotCreator::FunctionCodeHandling::kClear),
serializing_builtins_(false) {
......@@ -65,7 +65,7 @@ void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
FlushSkip(skip);
// Object has not yet been serialized. Serialize it here.
ObjectSerializer object_serializer(this, obj, sink_, how_to_code,
ObjectSerializer object_serializer(this, obj, &sink_, how_to_code,
where_to_point);
object_serializer.Serialize();
......@@ -94,7 +94,7 @@ void StartupSerializer::Synchronize(VisitorSynchronization::SyncTag tag) {
// We expect the builtins tag after builtins have been serialized.
DCHECK(!serializing_builtins_ || tag == VisitorSynchronization::kBuiltins);
serializing_builtins_ = (tag == VisitorSynchronization::kHandleScope);
sink_->Put(kSynchronize, "Synchronize");
sink_.Put(kSynchronize, "Synchronize");
}
void StartupSerializer::SerializeStrongReferences() {
......
......@@ -15,7 +15,7 @@ namespace internal {
class StartupSerializer : public Serializer {
public:
StartupSerializer(
Isolate* isolate, SnapshotByteSink* sink,
Isolate* isolate,
v8::SnapshotCreator::FunctionCodeHandling function_code_handling);
~StartupSerializer() override;
......
......@@ -92,8 +92,7 @@ static Vector<const byte> Serialize(v8::Isolate* isolate) {
Isolate* internal_isolate = reinterpret_cast<Isolate*>(isolate);
internal_isolate->heap()->CollectAllAvailableGarbage("serialize");
SnapshotByteSink sink;
StartupSerializer ser(internal_isolate, &sink,
StartupSerializer ser(internal_isolate,
v8::SnapshotCreator::FunctionCodeHandling::kClear);
ser.SerializeStrongReferences();
ser.SerializeWeakReferencesAndDeferred();
......@@ -282,15 +281,11 @@ static void PartiallySerializeObject(Vector<const byte>* startup_blob_out,
}
env.Reset();
SnapshotByteSink startup_sink;
StartupSerializer startup_serializer(
isolate, &startup_sink,
v8::SnapshotCreator::FunctionCodeHandling::kClear);
isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear);
startup_serializer.SerializeStrongReferences();
SnapshotByteSink partial_sink;
PartialSerializer partial_serializer(isolate, &startup_serializer,
&partial_sink);
PartialSerializer partial_serializer(isolate, &startup_serializer);
partial_serializer.Serialize(&raw_foo);
startup_serializer.SerializeWeakReferencesAndDeferred();
......@@ -385,13 +380,11 @@ static void PartiallySerializeContext(Vector<const byte>* startup_blob_out,
SnapshotByteSink startup_sink;
StartupSerializer startup_serializer(
isolate, &startup_sink,
v8::SnapshotCreator::FunctionCodeHandling::kClear);
isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear);
startup_serializer.SerializeStrongReferences();
SnapshotByteSink partial_sink;
PartialSerializer partial_serializer(isolate, &startup_serializer,
&partial_sink);
PartialSerializer partial_serializer(isolate, &startup_serializer);
partial_serializer.Serialize(&raw_context);
startup_serializer.SerializeWeakReferencesAndDeferred();
......@@ -505,13 +498,11 @@ static void PartiallySerializeCustomContext(
SnapshotByteSink startup_sink;
StartupSerializer startup_serializer(
isolate, &startup_sink,
v8::SnapshotCreator::FunctionCodeHandling::kClear);
isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear);
startup_serializer.SerializeStrongReferences();
SnapshotByteSink partial_sink;
PartialSerializer partial_serializer(isolate, &startup_serializer,
&partial_sink);
PartialSerializer partial_serializer(isolate, &startup_serializer);
partial_serializer.Serialize(&raw_context);
startup_serializer.SerializeWeakReferencesAndDeferred();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment