Skip to content

Commit

Permalink
deps: v8: serialize/deserialize external string table correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
liqyan committed Dec 8, 2017
1 parent d660ead commit 3115086
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions deps/v8/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ enum VisitMode {
VISIT_ALL_IN_MINOR_MC_UPDATE,
VISIT_ALL_IN_SCAVENGE,
VISIT_ALL_IN_SWEEP_NEWSPACE,
VISIT_ALL_FOR_STARTUP_DESERIALIZATION,
VISIT_ALL_FOR_STARTUP_SERIALIZATION,
VISIT_ONLY_STRONG,
VISIT_ONLY_STRONG_FOR_SERIALIZATION,
VISIT_ONLY_STRONG_ROOT_LIST,
Expand Down
22 changes: 22 additions & 0 deletions deps/v8/src/heap/heap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "src/objects/scope-info.h"
#include "src/objects/script-inl.h"
#include "src/profiler/heap-profiler.h"
#include "src/snapshot/startup-serializer.h"
#include "src/string-hasher.h"

namespace v8 {
Expand Down Expand Up @@ -585,6 +586,27 @@ void Heap::ExternalStringTable::IterateAll(RootVisitor* v) {
}
}

void Heap::ExternalStringTable::IterateAll(RootVisitor* v, VisitMode mode) {
if (mode == VISIT_ALL_FOR_STARTUP_DESERIALIZATION) {
StartupSerializer::IterateExternalStringTable(heap_->isolate_, &new_space_strings_, v);
StartupSerializer::IterateExternalStringTable(heap_->isolate_, &old_space_strings_, v);
} else if (mode == VISIT_ALL_FOR_STARTUP_SERIALIZATION) {
Object* undefined = heap_->undefined_value();
IterateNewSpaceStrings(v);
// end sentinel
v->VisitRootPointer(Root::kExternalStringsTable, &undefined);

if (!old_space_strings_.empty()) {
v->VisitRootPointers(Root::kExternalStringsTable, old_space_strings_.data(),
old_space_strings_.data() + old_space_strings_.size());
}
// end sentinel
v->VisitRootPointer(Root::kExternalStringsTable, &undefined);
} else {
IterateAll(v);
}
}


// Verify() is inline to avoid ifdef-s around its calls in release
// mode.
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/heap/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5266,7 +5266,7 @@ void Heap::IterateWeakRoots(RootVisitor* v, VisitMode mode) {
v->Synchronize(VisitorSynchronization::kStringTable);
if (!isMinorGC && mode != VISIT_ALL_IN_SWEEP_NEWSPACE) {
// Scavenge collections have special processing for this.
external_string_table_.IterateAll(v);
external_string_table_.IterateAll(v, mode);
}
v->Synchronize(VisitorSynchronization::kExternalStringsTable);
}
Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/heap/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,7 @@ class Heap {
inline void AddString(String* string);

inline void IterateAll(RootVisitor* v);
inline void IterateAll(RootVisitor* v, VisitMode mode);
inline void IterateNewSpaceStrings(RootVisitor* v);
inline void PromoteAllNewSpaceStrings();

Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/snapshot/startup-deserializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void StartupDeserializer::DeserializeInto(Isolate* isolate) {
isolate->heap()->IterateSmiRoots(this);
isolate->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG);
isolate->heap()->RepairFreeListsAfterDeserialization();
isolate->heap()->IterateWeakRoots(this, VISIT_ALL);
isolate->heap()->IterateWeakRoots(this, VISIT_ALL_FOR_STARTUP_DESERIALIZATION);
DeserializeDeferredObjects();
FlushICacheForNewIsolate();
RestoreExternalReferenceRedirectors(accessor_infos());
Expand Down
13 changes: 12 additions & 1 deletion deps/v8/src/snapshot/startup-serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ StartupSerializer::~StartupSerializer() {
OutputStatistics("StartupSerializer");
}

void StartupSerializer::IterateExternalStringTable(Isolate* isolate,
std::vector<Object*>* strings,
RootVisitor* visitor) {
for (size_t i = 0;; ++i) {
Object* obj;
visitor->VisitRootPointer(Root::kExternalStringsTable, &obj);
if (obj->IsUndefined(isolate)) break;
if (obj->IsExternalString()) strings->push_back(obj);
}
}

void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
WhereToPoint where_to_point, int skip) {
DCHECK(!obj->IsJSFunction());
Expand Down Expand Up @@ -87,7 +98,7 @@ void StartupSerializer::SerializeWeakReferencesAndDeferred() {
// one entry with 'undefined' to terminate the partial snapshot cache.
Object* undefined = isolate()->heap()->undefined_value();
VisitRootPointer(Root::kPartialSnapshotCache, &undefined);
isolate()->heap()->IterateWeakRoots(this, VISIT_ALL);
isolate()->heap()->IterateWeakRoots(this, VISIT_ALL_FOR_STARTUP_SERIALIZATION);
SerializeDeferredObjects();
Pad();
}
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/snapshot/startup-serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define V8_SNAPSHOT_STARTUP_SERIALIZER_H_

#include <bitset>
#include <vector>
#include "include/v8.h"
#include "src/snapshot/serializer.h"

Expand All @@ -19,6 +20,9 @@ class StartupSerializer : public Serializer {
v8::SnapshotCreator::FunctionCodeHandling function_code_handling);
~StartupSerializer() override;

static void IterateExternalStringTable(Isolate* isolate,
std::vector<Object*>* strings, RootVisitor* visitor);

// Serialize the current state of the heap. The order is:
// 1) Immortal immovable roots
// 2) Remaining strong references.
Expand Down

0 comments on commit 3115086

Please sign in to comment.