Commit c06d24b9 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[serializer] Clean-up and de-macro ReadDataCase

Refactors weak prefix handling, in particular the post-hoc weak prefix
read and HeapObjectReference creation, to a few function calls. This
simplifies ReadDataCase sufficiently that it can be inlined into
ReadData, which removes the need for a) having two places where we
branch on the bytecode value (ReadData and ReadDataCase), and b)
removes the need for the macro helper which calls ReadData. With a
bit of refactoring we can therefore make the big switch much more
explicit.

This patch also moves that switch into a per-bytecode helper, so that
switch entries can return the updated slot, rather than remembering to
update in-place and continue looping.

It also moves the weak prefix handling from the deserializer allocator
to the deserializer itself, as weak prefixes don't have anything to do
with allocation.

Change-Id: I84fbda021cb65d5bfb91fc3ef27f72823acee05a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2395557
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69800}
parent c8303fe6
......@@ -55,6 +55,19 @@ HeapObjectReference HeapObjectReference::Weak(Object object) {
return HeapObjectReference(object.ptr() | kWeakHeapObjectMask);
}
// static
HeapObjectReference HeapObjectReference::From(Object object,
HeapObjectReferenceType type) {
DCHECK(!object.IsSmi());
DCHECK(!HasWeakHeapObjectTag(object));
switch (type) {
case HeapObjectReferenceType::STRONG:
return HeapObjectReference::Strong(object);
case HeapObjectReferenceType::WEAK:
return HeapObjectReference::Weak(object);
}
}
// static
HeapObjectReference HeapObjectReference::ClearedValue(const Isolate* isolate) {
// Construct cleared weak ref value.
......
......@@ -47,6 +47,9 @@ class HeapObjectReference : public MaybeObject {
V8_INLINE static HeapObjectReference Weak(Object object);
V8_INLINE static HeapObjectReference From(Object object,
HeapObjectReferenceType type);
V8_INLINE static HeapObjectReference ClearedValue(const Isolate* isolate);
template <typename THeapObjectSlot>
......
......@@ -37,20 +37,6 @@ class DeserializerAllocator final {
next_alignment_ = static_cast<AllocationAlignment>(alignment);
}
void set_next_reference_is_weak(bool next_reference_is_weak) {
next_reference_is_weak_ = next_reference_is_weak;
}
bool GetAndClearNextReferenceIsWeak() {
bool saved = next_reference_is_weak_;
next_reference_is_weak_ = false;
return saved;
}
#ifdef DEBUG
bool next_reference_is_weak() const { return next_reference_is_weak_; }
#endif
HeapObject GetMap(uint32_t index);
HeapObject GetLargeObject(uint32_t index);
HeapObject GetObject(SnapshotSpace space, uint32_t chunk_index,
......@@ -89,7 +75,6 @@ class DeserializerAllocator final {
// The alignment of the next allocation.
AllocationAlignment next_alignment_ = kWordAligned;
bool next_reference_is_weak_ = false;
// All required maps are pre-allocated during reservation. {next_map_index_}
// stores the index of the next map to return from allocation.
......
This diff is collapsed.
......@@ -8,6 +8,7 @@
#include <utility>
#include <vector>
#include "src/common/globals.h"
#include "src/objects/allocation-site.h"
#include "src/objects/api-callbacks.h"
#include "src/objects/backing-store.h"
......@@ -125,6 +126,10 @@ class V8_EXPORT_PRIVATE Deserializer : public SerializerDeserializer {
template <typename TSlot>
inline TSlot Write(TSlot dest, MaybeObject value);
template <typename TSlot>
inline TSlot Write(TSlot dest, HeapObject value,
HeapObjectReferenceType type);
template <typename TSlot>
inline TSlot WriteAddress(TSlot dest, Address value);
......@@ -138,11 +143,12 @@ class V8_EXPORT_PRIVATE Deserializer : public SerializerDeserializer {
template <typename TSlot>
void ReadData(TSlot start, TSlot end, Address object_address);
// A helper function for ReadData, templatized on the bytecode for efficiency.
// Returns the new value of {current}.
template <typename TSlot, Bytecode bytecode>
inline TSlot ReadDataCase(TSlot current, Address current_object_address,
byte data);
// Helper for ReadData which reads the given bytecode and fills in some heap
// data into the given slot. May fill in zero or multiple slots, so it returns
// the next unfilled slot.
template <typename TSlot>
TSlot ReadSingleBytecodeData(byte data, TSlot current,
Address object_address);
// A helper function for ReadData for reading external references.
inline Address ReadExternalReferenceCase();
......@@ -151,6 +157,8 @@ class V8_EXPORT_PRIVATE Deserializer : public SerializerDeserializer {
HeapObject ReadMetaMap();
void ReadCodeObjectBody(Address code_object_address);
HeapObjectReferenceType GetAndResetNextReferenceType();
protected:
HeapObject ReadObject();
......@@ -199,6 +207,8 @@ class V8_EXPORT_PRIVATE Deserializer : public SerializerDeserializer {
DeserializerAllocator allocator_;
const bool deserializing_user_code_;
bool next_reference_is_weak_ = false;
// TODO(6593): generalize rehashing, and remove this flag.
bool can_rehash_;
std::vector<HeapObject> to_rehash_;
......
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