[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}
This commit is contained in:
parent
4192bd4c82
commit
22b56f47e3
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user