Commit ce9198e4 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

Reland "[snapshot] Factor out root serialization code"

This is a reland of 22b56f47

Nothing has changed. This is a reland of a speculative revert.

Original change's description:
> [snapshot] Factor out root serialization code
>
> Factors out a new method Serializer::SerializeRoot which attempts to
> serialize a given object as a Root if it is one and the Serializer's
> policy allows that root to be serialized (implemented as a new virtual
> method RootCanBeSerialized)..
>
> This is in preparation for adding a ReadOnlySerializer which change the
> way read-only roots are serialized.
>
> Bug: v8:8191
> Change-Id: I7fbb4e9520fba8b836a0b6bf95ca39abc3ded79e
> Reviewed-on: https://chromium-review.googlesource.com/c/1264698
> Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> Commit-Queue: Dan Elphick <delphick@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#56494}

TBR=jgruber

Bug: v8:8191
Change-Id: I30a606b9c99f5651fae323d12f8f74b13bb085fa
Reviewed-on: https://chromium-review.googlesource.com/c/1273103Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56519}
parent c4e20786
...@@ -57,7 +57,7 @@ class RootIndexMap { ...@@ -57,7 +57,7 @@ class RootIndexMap {
explicit RootIndexMap(Isolate* isolate); explicit RootIndexMap(Isolate* isolate);
// Returns true on successful lookup and sets *|out_root_list|. // Returns true on successful lookup and sets *|out_root_list|.
bool Lookup(HeapObject* obj, RootIndex* out_root_list) { bool Lookup(HeapObject* obj, RootIndex* out_root_list) const {
Maybe<uint32_t> maybe_index = map_->Get(obj); Maybe<uint32_t> maybe_index = map_->Get(obj);
if (maybe_index.IsJust()) { if (maybe_index.IsJust()) {
*out_root_list = static_cast<RootIndex>(maybe_index.FromJust()); *out_root_list = static_cast<RootIndex>(maybe_index.FromJust());
......
...@@ -70,12 +70,7 @@ void BuiltinSerializer::SerializeObject(HeapObject* o, HowToCode how_to_code, ...@@ -70,12 +70,7 @@ void BuiltinSerializer::SerializeObject(HeapObject* o, HowToCode how_to_code,
DCHECK(!o->IsSmi()); DCHECK(!o->IsSmi());
// Roots can simply be serialized as root references. // Roots can simply be serialized as root references.
RootIndex root_index; if (SerializeRoot(o, how_to_code, where_to_point, skip)) return;
if (root_index_map()->Lookup(o, &root_index)) {
DCHECK(startup_serializer_->root_has_been_serialized(root_index));
PutRoot(root_index, o, how_to_code, where_to_point, skip);
return;
}
// Builtins are serialized using a dedicated bytecode. We only reach this // Builtins are serialized using a dedicated bytecode. We only reach this
// point if encountering a Builtin e.g. while iterating the body of another // point if encountering a Builtin e.g. while iterating the body of another
......
...@@ -124,11 +124,7 @@ void CodeSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, ...@@ -124,11 +124,7 @@ void CodeSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
WhereToPoint where_to_point, int skip) { WhereToPoint where_to_point, int skip) {
if (SerializeHotObject(obj, how_to_code, where_to_point, skip)) return; if (SerializeHotObject(obj, how_to_code, where_to_point, skip)) return;
RootIndex root_index; if (SerializeRoot(obj, how_to_code, where_to_point, skip)) return;
if (root_index_map()->Lookup(obj, &root_index)) {
PutRoot(root_index, obj, how_to_code, where_to_point, skip);
return;
}
if (SerializeBackReference(obj, how_to_code, where_to_point, skip)) return; if (SerializeBackReference(obj, how_to_code, where_to_point, skip)) return;
......
...@@ -59,11 +59,7 @@ void PartialSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, ...@@ -59,11 +59,7 @@ void PartialSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
} }
if (SerializeHotObject(obj, how_to_code, where_to_point, skip)) return; if (SerializeHotObject(obj, how_to_code, where_to_point, skip)) return;
RootIndex root_index; if (SerializeRoot(obj, how_to_code, where_to_point, skip)) return;
if (root_index_map()->Lookup(obj, &root_index)) {
PutRoot(root_index, obj, how_to_code, where_to_point, skip);
return;
}
if (SerializeBackReference(obj, how_to_code, where_to_point, skip)) return; if (SerializeBackReference(obj, how_to_code, where_to_point, skip)) return;
......
...@@ -138,6 +138,21 @@ void Serializer<AllocatorT>::PrintStack() { ...@@ -138,6 +138,21 @@ void Serializer<AllocatorT>::PrintStack() {
} }
#endif // DEBUG #endif // DEBUG
template <class AllocatorT>
bool Serializer<AllocatorT>::SerializeRoot(HeapObject* obj,
HowToCode how_to_code,
WhereToPoint where_to_point,
int skip) {
RootIndex root_index;
// Derived serializers are responsible for determining if the root has
// actually been serialized before calling this.
if (root_index_map()->Lookup(obj, &root_index)) {
PutRoot(root_index, obj, how_to_code, where_to_point, skip);
return true;
}
return false;
}
template <class AllocatorT> template <class AllocatorT>
bool Serializer<AllocatorT>::SerializeHotObject(HeapObject* obj, bool Serializer<AllocatorT>::SerializeHotObject(HeapObject* obj,
HowToCode how_to_code, HowToCode how_to_code,
......
...@@ -182,6 +182,10 @@ class Serializer : public SerializerDeserializer { ...@@ -182,6 +182,10 @@ class Serializer : public SerializerDeserializer {
int PutAlignmentPrefix(HeapObject* object); int PutAlignmentPrefix(HeapObject* object);
void PutNextChunk(int space); void PutNextChunk(int space);
// Returns true if the object was successfully serialized as a root.
bool SerializeRoot(HeapObject* obj, HowToCode how_to_code,
WhereToPoint where_to_point, int skip);
// Returns true if the object was successfully serialized as hot object. // Returns true if the object was successfully serialized as hot object.
bool SerializeHotObject(HeapObject* obj, HowToCode how_to_code, bool SerializeHotObject(HeapObject* obj, HowToCode how_to_code,
WhereToPoint where_to_point, int skip); WhereToPoint where_to_point, int skip);
...@@ -237,7 +241,7 @@ class Serializer : public SerializerDeserializer { ...@@ -237,7 +241,7 @@ class Serializer : public SerializerDeserializer {
#endif // DEBUG #endif // DEBUG
SerializerReferenceMap* reference_map() { return &reference_map_; } SerializerReferenceMap* reference_map() { return &reference_map_; }
RootIndexMap* root_index_map() { return &root_index_map_; } const RootIndexMap* root_index_map() const { return &root_index_map_; }
AllocatorT* allocator() { return &allocator_; } AllocatorT* allocator() { return &allocator_; }
SnapshotByteSink sink_; // Used directly by subclasses. SnapshotByteSink sink_; // Used directly by subclasses.
......
...@@ -33,17 +33,9 @@ void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, ...@@ -33,17 +33,9 @@ void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
return; return;
} }
if (SerializeHotObject(obj, how_to_code, where_to_point, skip)) return; if (SerializeHotObject(obj, how_to_code, where_to_point, skip)) return;
if (IsRootAndHasBeenSerialized(obj) &&
RootIndex root_index; SerializeRoot(obj, how_to_code, where_to_point, skip))
// We can only encode roots as such if it has already been serialized. return;
// That applies to root indices below the wave front.
if (root_index_map()->Lookup(obj, &root_index)) {
if (root_has_been_serialized(root_index)) {
PutRoot(root_index, obj, how_to_code, where_to_point, skip);
return;
}
}
if (SerializeBackReference(obj, how_to_code, where_to_point, skip)) return; if (SerializeBackReference(obj, how_to_code, where_to_point, skip)) return;
FlushSkip(skip); FlushSkip(skip);
......
...@@ -32,6 +32,12 @@ class StartupSerializer : public Serializer<> { ...@@ -32,6 +32,12 @@ class StartupSerializer : public Serializer<> {
return root_has_been_serialized_.test(static_cast<size_t>(root_index)); return root_has_been_serialized_.test(static_cast<size_t>(root_index));
} }
bool IsRootAndHasBeenSerialized(HeapObject* obj) const {
RootIndex root_index;
return root_index_map()->Lookup(obj, &root_index) &&
root_has_been_serialized(root_index);
}
private: private:
class PartialCacheIndexMap { class PartialCacheIndexMap {
public: public:
......
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