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 {
explicit RootIndexMap(Isolate* isolate);
// 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);
if (maybe_index.IsJust()) {
*out_root_list = static_cast<RootIndex>(maybe_index.FromJust());
......
......@@ -70,12 +70,7 @@ void BuiltinSerializer::SerializeObject(HeapObject* o, HowToCode how_to_code,
DCHECK(!o->IsSmi());
// Roots can simply be serialized as root references.
RootIndex root_index;
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;
}
if (SerializeRoot(o, how_to_code, where_to_point, skip)) return;
// Builtins are serialized using a dedicated bytecode. We only reach this
// 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,
WhereToPoint where_to_point, int skip) {
if (SerializeHotObject(obj, how_to_code, where_to_point, skip)) return;
RootIndex root_index;
if (root_index_map()->Lookup(obj, &root_index)) {
PutRoot(root_index, obj, how_to_code, where_to_point, skip);
return;
}
if (SerializeRoot(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,
}
if (SerializeHotObject(obj, how_to_code, where_to_point, skip)) return;
RootIndex root_index;
if (root_index_map()->Lookup(obj, &root_index)) {
PutRoot(root_index, obj, how_to_code, where_to_point, skip);
return;
}
if (SerializeRoot(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() {
}
#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>
bool Serializer<AllocatorT>::SerializeHotObject(HeapObject* obj,
HowToCode how_to_code,
......
......@@ -182,6 +182,10 @@ class Serializer : public SerializerDeserializer {
int PutAlignmentPrefix(HeapObject* object);
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.
bool SerializeHotObject(HeapObject* obj, HowToCode how_to_code,
WhereToPoint where_to_point, int skip);
......@@ -237,7 +241,7 @@ class Serializer : public SerializerDeserializer {
#endif // DEBUG
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_; }
SnapshotByteSink sink_; // Used directly by subclasses.
......
......@@ -33,17 +33,9 @@ void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
return;
}
if (SerializeHotObject(obj, how_to_code, where_to_point, skip)) return;
RootIndex root_index;
// We can only encode roots as such if it has already been serialized.
// 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 (IsRootAndHasBeenSerialized(obj) &&
SerializeRoot(obj, how_to_code, where_to_point, skip))
return;
if (SerializeBackReference(obj, how_to_code, where_to_point, skip)) return;
FlushSkip(skip);
......
......@@ -32,6 +32,12 @@ class StartupSerializer : public Serializer<> {
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:
class PartialCacheIndexMap {
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