Commit 32a79b2b authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[ptr-compr] Rename XxxSlot classes to FullXxxSlot

and
1) make them represent kSystemPointerSize-sized off-heap slots,
2) reintroduce XxxSlots as an on-heap kTaggedSize-sized slots (for now they
   are just aliases to respective FullXxxSlots).

Bug: v8:8518
Change-Id: I8a9177562308bd9420b1eebca959cc52ceaa628e
Reviewed-on: https://chromium-review.googlesource.com/c/1363144
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58056}
parent 16afa0a2
...@@ -17,7 +17,6 @@ class JSGlobalObject; ...@@ -17,7 +17,6 @@ class JSGlobalObject;
class JSGlobalProxy; class JSGlobalProxy;
class MicrotaskQueue; class MicrotaskQueue;
class NativeContext; class NativeContext;
class ObjectSlot;
class RegExpMatchInfo; class RegExpMatchInfo;
enum ContextLookupFlags { enum ContextLookupFlags {
......
...@@ -574,7 +574,9 @@ class NewSpace; ...@@ -574,7 +574,9 @@ class NewSpace;
class NewLargeObjectSpace; class NewLargeObjectSpace;
class NumberDictionary; class NumberDictionary;
class Object; class Object;
class ObjectSlot; class FullObjectSlot;
class FullMaybeObjectSlot;
class FullHeapObjectSlot;
class OldSpace; class OldSpace;
class ParameterCount; class ParameterCount;
class ReadOnlySpace; class ReadOnlySpace;
...@@ -591,6 +593,41 @@ class Struct; ...@@ -591,6 +593,41 @@ class Struct;
class Symbol; class Symbol;
class Variable; class Variable;
enum class SlotLocation { kOnHeap, kOffHeap };
template <SlotLocation slot_location>
struct SlotTraits;
// Off-heap slots are always full-pointer slots.
template <>
struct SlotTraits<SlotLocation::kOffHeap> {
using TObjectSlot = FullObjectSlot;
using TMaybeObjectSlot = FullMaybeObjectSlot;
using THeapObjectSlot = FullHeapObjectSlot;
};
// On-heap slots are either full-pointer slots or compressed slots depending
// on whether the pointer compression is enabled or not.
template <>
struct SlotTraits<SlotLocation::kOnHeap> {
using TObjectSlot = FullObjectSlot;
using TMaybeObjectSlot = FullMaybeObjectSlot;
using THeapObjectSlot = FullHeapObjectSlot;
};
// An ObjectSlot instance describes a kTaggedSize-sized on-heap field ("slot")
// holding ObjectPtr value (smi or strong heap object).
using ObjectSlot = SlotTraits<SlotLocation::kOnHeap>::TObjectSlot;
// A MaybeObjectSlot instance describes a kTaggedSize-sized on-heap field
// ("slot") holding MaybeObject (smi or weak heap object or strong heap object).
using MaybeObjectSlot = SlotTraits<SlotLocation::kOnHeap>::TMaybeObjectSlot;
// A HeapObjectSlot instance describes a kTaggedSize-sized field ("slot")
// holding a weak or strong pointer to a heap object (think:
// HeapObjectReference).
using HeapObjectSlot = SlotTraits<SlotLocation::kOnHeap>::THeapObjectSlot;
typedef bool (*WeakSlotCallback)(ObjectSlot pointer); typedef bool (*WeakSlotCallback)(ObjectSlot pointer);
typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, ObjectSlot pointer); typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, ObjectSlot pointer);
......
...@@ -61,9 +61,7 @@ class SlotSnapshot { ...@@ -61,9 +61,7 @@ class SlotSnapshot {
Object* value(int i) const { return snapshot_[i].second; } Object* value(int i) const { return snapshot_[i].second; }
void clear() { number_of_slots_ = 0; } void clear() { number_of_slots_ = 0; }
void add(ObjectSlot slot, Object* value) { void add(ObjectSlot slot, Object* value) {
snapshot_[number_of_slots_].first = slot; snapshot_[number_of_slots_++] = {slot, value};
snapshot_[number_of_slots_].second = value;
++number_of_slots_;
} }
private: private:
...@@ -158,7 +156,7 @@ class ConcurrentMarkingVisitor final ...@@ -158,7 +156,7 @@ class ConcurrentMarkingVisitor final
// barrier will treat the weak reference as strong, so we won't miss the // barrier will treat the weak reference as strong, so we won't miss the
// weak reference. // weak reference.
ProcessStrongHeapObject(host, ObjectSlot(slot), heap_object); ProcessStrongHeapObject(host, ObjectSlot(slot), heap_object);
} else if (TSlot::kCanBeWeek && } else if (TSlot::kCanBeWeak &&
object.GetHeapObjectIfWeak(&heap_object)) { object.GetHeapObjectIfWeak(&heap_object)) {
ProcessWeakHeapObject(host, HeapObjectSlot(slot), heap_object); ProcessWeakHeapObject(host, HeapObjectSlot(slot), heap_object);
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define V8_HEAP_HEAP_WRITE_BARRIER_H_ #define V8_HEAP_HEAP_WRITE_BARRIER_H_
#include "include/v8-internal.h" #include "include/v8-internal.h"
#include "src/globals.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -16,9 +17,7 @@ class Heap; ...@@ -16,9 +17,7 @@ class Heap;
class HeapObject; class HeapObject;
class HeapObjectPtr; class HeapObjectPtr;
class MaybeObject; class MaybeObject;
class MaybeObjectSlot;
class Object; class Object;
class ObjectSlot;
class RelocInfo; class RelocInfo;
// Note: In general it is preferred to use the macros defined in // Note: In general it is preferred to use the macros defined in
......
...@@ -213,7 +213,7 @@ void MarkingVisitor<fixed_array_mode, retaining_path_mode, ...@@ -213,7 +213,7 @@ void MarkingVisitor<fixed_array_mode, retaining_path_mode,
if (object.GetHeapObjectIfStrong(&target_object)) { if (object.GetHeapObjectIfStrong(&target_object)) {
collector_->RecordSlot(host, HeapObjectSlot(slot), target_object); collector_->RecordSlot(host, HeapObjectSlot(slot), target_object);
MarkObject(host, target_object); MarkObject(host, target_object);
} else if (TSlot::kCanBeWeek && object.GetHeapObjectIfWeak(&target_object)) { } else if (TSlot::kCanBeWeak && object.GetHeapObjectIfWeak(&target_object)) {
if (marking_state()->IsBlackOrGrey(target_object)) { if (marking_state()->IsBlackOrGrey(target_object)) {
// Weak references with live values are directly processed here to reduce // Weak references with live values are directly processed here to reduce
// the processing time of weak cells during the main GC pause. // the processing time of weak cells during the main GC pause.
......
...@@ -272,7 +272,6 @@ class KeyAccumulator; ...@@ -272,7 +272,6 @@ class KeyAccumulator;
class LayoutDescriptor; class LayoutDescriptor;
class LookupIterator; class LookupIterator;
class FieldType; class FieldType;
class MaybeObjectSlot;
class Module; class Module;
class ModuleInfoEntry; class ModuleInfoEntry;
class ObjectHashTable; class ObjectHashTable;
......
...@@ -18,7 +18,6 @@ template <typename T> ...@@ -18,7 +18,6 @@ template <typename T>
class Handle; class Handle;
class Isolate; class Isolate;
class MaybeObjectSlot;
// An EnumCache is a pair used to hold keys and indices caches. // An EnumCache is a pair used to hold keys and indices caches.
class EnumCache : public Tuple2 { class EnumCache : public Tuple2 {
......
...@@ -74,7 +74,7 @@ Object* FixedArrayBase::unchecked_synchronized_length() const { ...@@ -74,7 +74,7 @@ Object* FixedArrayBase::unchecked_synchronized_length() const {
ACCESSORS(FixedTypedArrayBase, base_pointer, Object, kBasePointerOffset) ACCESSORS(FixedTypedArrayBase, base_pointer, Object, kBasePointerOffset)
ObjectSlot FixedArray::GetFirstElementAddress() { ObjectSlot FixedArray::GetFirstElementAddress() {
return ObjectSlot(FIELD_ADDR(this, OffsetOfElementAt(0))); return RawField(OffsetOfElementAt(0));
} }
bool FixedArray::ContainsOnlySmisOrHoles() { bool FixedArray::ContainsOnlySmisOrHoles() {
......
...@@ -136,7 +136,7 @@ class ObjectPtr { ...@@ -136,7 +136,7 @@ class ObjectPtr {
}; };
private: private:
friend class ObjectSlot; friend class FullObjectSlot;
Address ptr_; Address ptr_;
}; };
......
...@@ -156,9 +156,9 @@ template <class Derived> ...@@ -156,9 +156,9 @@ template <class Derived>
void SmallOrderedHashTable<Derived>::SetDataEntry(int entry, int relative_index, void SmallOrderedHashTable<Derived>::SetDataEntry(int entry, int relative_index,
Object* value) { Object* value) {
DCHECK_NE(kNotFound, entry); DCHECK_NE(kNotFound, entry);
Address entry_offset = GetDataEntryOffset(entry, relative_index); int entry_offset = GetDataEntryOffset(entry, relative_index);
RELAXED_WRITE_FIELD(this, entry_offset, value); RELAXED_WRITE_FIELD(this, entry_offset, value);
WRITE_BARRIER(this, static_cast<int>(entry_offset), value); WRITE_BARRIER(this, entry_offset, value);
} }
template <class Derived, class TableType> template <class Derived, class TableType>
......
...@@ -16,80 +16,108 @@ ...@@ -16,80 +16,108 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
ObjectSlot::ObjectSlot(ObjectPtr* object) //
// FullObjectSlot implementation.
//
FullObjectSlot::FullObjectSlot(ObjectPtr* object)
: SlotBase(reinterpret_cast<Address>(&object->ptr_)) {} : SlotBase(reinterpret_cast<Address>(&object->ptr_)) {}
ObjectPtr ObjectSlot::load() const { return ObjectPtr(*location()); } bool FullObjectSlot::contains_value(Address raw_value) const {
return *location() == raw_value;
}
Object* FullObjectSlot::operator*() const {
return reinterpret_cast<Object*>(*location());
}
ObjectPtr FullObjectSlot::load() const { return ObjectPtr(*location()); }
void ObjectSlot::store(Object* value) const { *location() = value->ptr(); } void FullObjectSlot::store(Object* value) const { *location() = value->ptr(); }
void FullObjectSlot::store(ObjectPtr value) const { *location() = value.ptr(); }
ObjectPtr ObjectSlot::Acquire_Load() const { ObjectPtr FullObjectSlot::Acquire_Load() const {
return ObjectPtr(AsAtomicTagged::Acquire_Load(location())); return ObjectPtr(base::AsAtomicPointer::Acquire_Load(location()));
} }
Object* ObjectSlot::Acquire_Load1() const { Object* FullObjectSlot::Acquire_Load1() const {
return reinterpret_cast<Object*>(AsAtomicTagged::Acquire_Load(location())); return reinterpret_cast<Object*>(
base::AsAtomicPointer::Acquire_Load(location()));
} }
ObjectPtr ObjectSlot::Relaxed_Load() const { ObjectPtr FullObjectSlot::Relaxed_Load() const {
return ObjectPtr(AsAtomicTagged::Relaxed_Load(location())); return ObjectPtr(base::AsAtomicPointer::Relaxed_Load(location()));
} }
void ObjectSlot::Relaxed_Store(ObjectPtr value) const { void FullObjectSlot::Relaxed_Store(ObjectPtr value) const {
AsAtomicTagged::Relaxed_Store(location(), value->ptr()); base::AsAtomicPointer::Relaxed_Store(location(), value->ptr());
} }
void ObjectSlot::Relaxed_Store1(Object* value) const { void FullObjectSlot::Relaxed_Store1(Object* value) const {
AsAtomicTagged::Relaxed_Store(location(), value->ptr()); base::AsAtomicPointer::Relaxed_Store(location(), value->ptr());
} }
void ObjectSlot::Release_Store1(Object* value) const { void FullObjectSlot::Release_Store1(Object* value) const {
AsAtomicTagged::Release_Store(location(), value->ptr()); base::AsAtomicPointer::Release_Store(location(), value->ptr());
} }
void ObjectSlot::Release_Store(ObjectPtr value) const { void FullObjectSlot::Release_Store(ObjectPtr value) const {
AsAtomicTagged::Release_Store(location(), value->ptr()); base::AsAtomicPointer::Release_Store(location(), value->ptr());
} }
ObjectPtr ObjectSlot::Release_CompareAndSwap(ObjectPtr old, ObjectPtr FullObjectSlot::Release_CompareAndSwap(ObjectPtr old,
ObjectPtr target) const { ObjectPtr target) const {
Address result = AsAtomicTagged::Release_CompareAndSwap( Address result = base::AsAtomicPointer::Release_CompareAndSwap(
location(), old->ptr(), target->ptr()); location(), old->ptr(), target->ptr());
return ObjectPtr(result); return ObjectPtr(result);
} }
MaybeObject MaybeObjectSlot::operator*() const { //
// FullMaybeObjectSlot implementation.
//
MaybeObject FullMaybeObjectSlot::operator*() const {
return MaybeObject(*location()); return MaybeObject(*location());
} }
MaybeObject MaybeObjectSlot::load() const { return MaybeObject(*location()); } MaybeObject FullMaybeObjectSlot::load() const {
return MaybeObject(*location());
}
void MaybeObjectSlot::store(MaybeObject value) const { void FullMaybeObjectSlot::store(MaybeObject value) const {
*location() = value.ptr(); *location() = value.ptr();
} }
MaybeObject MaybeObjectSlot::Relaxed_Load() const { MaybeObject FullMaybeObjectSlot::Relaxed_Load() const {
return MaybeObject(AsAtomicTagged::Relaxed_Load(location())); return MaybeObject(AsAtomicTagged::Relaxed_Load(location()));
} }
void MaybeObjectSlot::Relaxed_Store(MaybeObject value) const { void FullMaybeObjectSlot::Relaxed_Store(MaybeObject value) const {
AsAtomicTagged::Relaxed_Store(location(), value->ptr()); AsAtomicTagged::Relaxed_Store(location(), value->ptr());
} }
void MaybeObjectSlot::Release_CompareAndSwap(MaybeObject old, void FullMaybeObjectSlot::Release_CompareAndSwap(MaybeObject old,
MaybeObject target) const { MaybeObject target) const {
AsAtomicTagged::Release_CompareAndSwap(location(), old.ptr(), target.ptr()); AsAtomicTagged::Release_CompareAndSwap(location(), old.ptr(), target.ptr());
} }
HeapObjectReference HeapObjectSlot::operator*() const { //
// FullHeapObjectSlot implementation.
//
HeapObjectReference FullHeapObjectSlot::operator*() const {
return HeapObjectReference(*location()); return HeapObjectReference(*location());
} }
void HeapObjectSlot::store(HeapObjectReference value) const { void FullHeapObjectSlot::store(HeapObjectReference value) const {
*location() = value.ptr(); *location() = value.ptr();
} }
inline void MemsetPointer(ObjectSlot start, Object* value, size_t counter) { //
// Utils.
//
inline void MemsetPointer(FullObjectSlot start, Object* value, size_t counter) {
MemsetPointer(start.location(), reinterpret_cast<Address>(value), counter); MemsetPointer(start.location(), reinterpret_cast<Address>(value), counter);
} }
......
...@@ -84,32 +84,39 @@ class SlotBase { ...@@ -84,32 +84,39 @@ class SlotBase {
Address ptr_; Address ptr_;
}; };
// An ObjectSlot instance describes a kTaggedSize-sized field ("slot") holding // An FullObjectSlot instance describes a kSystemPointerSize-sized field
// a tagged pointer (smi or strong heap object). // ("slot") holding a tagged pointer (smi or strong heap object).
// Its address() is the address of the slot. // Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store(). // The slot's contents can be read and written using operator* and store().
class ObjectSlot : public SlotBase<ObjectSlot, Tagged_t, kTaggedSize> { class FullObjectSlot
: public SlotBase<FullObjectSlot, Address, kSystemPointerSize> {
public: public:
using TObject = ObjectPtr; using TObject = ObjectPtr;
using THeapObjectSlot = FullHeapObjectSlot;
// Tagged value stored in this slot is guaranteed to never be a weak pointer. // Tagged value stored in this slot is guaranteed to never be a weak pointer.
static constexpr bool kCanBeWeek = false; static constexpr bool kCanBeWeak = false;
ObjectSlot() : SlotBase(kNullAddress) {} FullObjectSlot() : SlotBase(kNullAddress) {}
explicit ObjectSlot(Address ptr) : SlotBase(ptr) {} explicit FullObjectSlot(Address ptr) : SlotBase(ptr) {}
explicit ObjectSlot(Address* ptr) explicit FullObjectSlot(Address* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {} : SlotBase(reinterpret_cast<Address>(ptr)) {}
inline explicit ObjectSlot(ObjectPtr* object); inline explicit FullObjectSlot(ObjectPtr* object);
explicit ObjectSlot(Object const* const* ptr) explicit FullObjectSlot(Object const* const* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {} : SlotBase(reinterpret_cast<Address>(ptr)) {}
template <typename T> template <typename T>
explicit ObjectSlot(SlotBase<T, TData, kSlotDataSize> slot) explicit FullObjectSlot(SlotBase<T, TData, kSlotDataSize> slot)
: SlotBase(slot.address()) {} : SlotBase(slot.address()) {}
Object* operator*() const { return *reinterpret_cast<Object**>(address()); } // Compares memory representation of a value stored in the slot with given
// raw value.
inline bool contains_value(Address raw_value) const;
inline Object* operator*() const;
// TODO(3770): drop this in favor of operator* once migration is complete. // TODO(3770): drop this in favor of operator* once migration is complete.
inline ObjectPtr load() const; inline ObjectPtr load() const;
inline void store(Object* value) const; inline void store(Object* value) const;
inline void store(ObjectPtr value) const;
inline ObjectPtr Acquire_Load() const; inline ObjectPtr Acquire_Load() const;
inline ObjectPtr Relaxed_Load() const; inline ObjectPtr Relaxed_Load() const;
...@@ -125,23 +132,29 @@ class ObjectSlot : public SlotBase<ObjectSlot, Tagged_t, kTaggedSize> { ...@@ -125,23 +132,29 @@ class ObjectSlot : public SlotBase<ObjectSlot, Tagged_t, kTaggedSize> {
inline void Release_Store1(Object* value) const; inline void Release_Store1(Object* value) const;
}; };
// A MaybeObjectSlot instance describes a kTaggedSize-sized field ("slot") // A FullMaybeObjectSlot instance describes a kSystemPointerSize-sized field
// holding a possibly-weak tagged pointer (think: MaybeObject). // ("slot") holding a possibly-weak tagged pointer (think: MaybeObject).
// Its address() is the address of the slot. // Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store(). // The slot's contents can be read and written using operator* and store().
class MaybeObjectSlot class FullMaybeObjectSlot
: public SlotBase<MaybeObjectSlot, Tagged_t, kTaggedSize> { : public SlotBase<FullMaybeObjectSlot, Address, kSystemPointerSize> {
public: public:
using TObject = MaybeObject; using TObject = MaybeObject;
using THeapObjectSlot = FullHeapObjectSlot;
// Tagged value stored in this slot can be a weak pointer. // Tagged value stored in this slot can be a weak pointer.
static constexpr bool kCanBeWeek = true; static constexpr bool kCanBeWeak = true;
explicit MaybeObjectSlot(Address ptr) : SlotBase(ptr) {} FullMaybeObjectSlot() : SlotBase(kNullAddress) {}
explicit MaybeObjectSlot(Object** ptr) explicit FullMaybeObjectSlot(Address ptr) : SlotBase(ptr) {}
explicit FullMaybeObjectSlot(ObjectPtr* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
explicit FullMaybeObjectSlot(Object** ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
explicit FullMaybeObjectSlot(HeapObject** ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {} : SlotBase(reinterpret_cast<Address>(ptr)) {}
template <typename T> template <typename T>
explicit MaybeObjectSlot(SlotBase<T, TData, kSlotDataSize> slot) explicit FullMaybeObjectSlot(SlotBase<T, TData, kSlotDataSize> slot)
: SlotBase(slot.address()) {} : SlotBase(slot.address()) {}
inline MaybeObject operator*() const; inline MaybeObject operator*() const;
...@@ -154,19 +167,20 @@ class MaybeObjectSlot ...@@ -154,19 +167,20 @@ class MaybeObjectSlot
inline void Release_CompareAndSwap(MaybeObject old, MaybeObject target) const; inline void Release_CompareAndSwap(MaybeObject old, MaybeObject target) const;
}; };
// A HeapObjectSlot instance describes a kTaggedSize-sized field ("slot") // A FullHeapObjectSlot instance describes a kSystemPointerSize-sized field
// holding a weak or strong pointer to a heap object (think: // ("slot") holding a weak or strong pointer to a heap object (think:
// HeapObjectReference). // HeapObjectReference).
// Its address() is the address of the slot. // Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store(). // The slot's contents can be read and written using operator* and store().
// In case it is known that that slot contains a strong heap object pointer, // In case it is known that that slot contains a strong heap object pointer,
// ToHeapObject() can be used to retrieve that heap object. // ToHeapObject() can be used to retrieve that heap object.
class HeapObjectSlot : public SlotBase<HeapObjectSlot, Tagged_t, kTaggedSize> { class FullHeapObjectSlot
: public SlotBase<HeapObjectSlot, Address, kSystemPointerSize> {
public: public:
HeapObjectSlot() : SlotBase(kNullAddress) {} FullHeapObjectSlot() : SlotBase(kNullAddress) {}
explicit HeapObjectSlot(Address ptr) : SlotBase(ptr) {} explicit FullHeapObjectSlot(Address ptr) : SlotBase(ptr) {}
template <typename T> template <typename T>
explicit HeapObjectSlot(SlotBase<T, TData, kSlotDataSize> slot) explicit FullHeapObjectSlot(SlotBase<T, TData, kSlotDataSize> slot)
: SlotBase(slot.address()) {} : SlotBase(slot.address()) {}
inline HeapObjectReference operator*() const; inline HeapObjectReference operator*() const;
......
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