Commit ad49f129 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[cleanup] Move Compressed[XXX]Slot definitions to separate header

... and fix header includes to please the respective bot.

Drive-by-fix: decompression implementation is now MSVC friendly.

Bug: v8:7703, v8:8834
Change-Id: Iaf589138e5bafb32b0d9feab5cf074b71f241a3c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1505579
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60074}
parent 1297c928
......@@ -2276,6 +2276,8 @@ v8_source_set("v8_base") {
"src/objects/code.h",
"src/objects/compilation-cache-inl.h",
"src/objects/compilation-cache.h",
"src/objects/compressed-slots-inl.h",
"src/objects/compressed-slots.h",
"src/objects/data-handler.h",
"src/objects/debug-objects-inl.h",
"src/objects/debug-objects.cc",
......
......@@ -318,7 +318,7 @@ V8_INLINE A implicit_cast(A x) {
#define V8PRIdPTR V8_PTR_PREFIX "d"
#define V8PRIuPTR V8_PTR_PREFIX "u"
#ifdef V8_TARGET_ARCH_64_BIT
#if V8_TARGET_ARCH_64_BIT
#define V8_PTR_HEX_DIGITS 12
#define V8PRIxPTR_FMT "0x%012" V8PRIxPTR
#else
......
......@@ -8,7 +8,6 @@
#include "src/heap/factory.h"
#include "src/objects/fixed-array.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/slots.h"
#include "src/snapshot/natives.h"
#include "src/visitors.h"
......
......@@ -15,6 +15,7 @@
// elsewhere.
#include "src/isolate.h"
#include "src/objects/code.h"
#include "src/objects/compressed-slots-inl.h"
#include "src/objects/fixed-array.h"
#include "src/objects/heap-object.h"
#include "src/objects/maybe-object-inl.h"
......
......@@ -11,13 +11,10 @@
#include "src/allocation.h"
#include "src/base/atomic-utils.h"
#include "src/base/bits.h"
#include "src/objects/compressed-slots.h"
#include "src/objects/slots.h"
#include "src/utils.h"
#ifdef V8_COMPRESS_POINTERS
#include "src/ptr-compr.h"
#endif
namespace v8 {
namespace internal {
......
......@@ -2786,7 +2786,7 @@ Isolate* Isolate::New(IsolateAllocationMode mode) {
// Construct Isolate object in the allocated memory.
void* isolate_ptr = isolate_allocator->isolate_memory();
Isolate* isolate = new (isolate_ptr) Isolate(std::move(isolate_allocator));
#ifdef V8_TARGET_ARCH_64_BIT
#if V8_TARGET_ARCH_64_BIT
DCHECK_IMPLIES(
mode == IsolateAllocationMode::kInV8Heap,
IsAligned(isolate->isolate_root(), kPtrComprIsolateRootAlignment));
......
......@@ -14,7 +14,6 @@
#include "src/objects/js-collection.h"
#include "src/objects/js-weak-refs.h"
#include "src/objects/oddball.h"
#include "src/objects/slots.h"
#include "src/reloc-info.h"
#include "src/transitions.h"
#include "src/wasm/wasm-objects-inl.h"
......
......@@ -26,10 +26,6 @@
#include "src/property-details.h"
#include "src/utils.h"
#ifdef V8_COMPRESS_POINTERS
#include "src/ptr-compr.h"
#endif
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_COMPRESSED_SLOTS_INL_H_
#define V8_OBJECTS_COMPRESSED_SLOTS_INL_H_
#ifdef V8_COMPRESS_POINTERS
#include "src/objects/compressed-slots.h"
#include "src/objects/heap-object-inl.h"
#include "src/objects/maybe-object-inl.h"
#include "src/ptr-compr-inl.h"
namespace v8 {
namespace internal {
//
// CompressedObjectSlot implementation.
//
CompressedObjectSlot::CompressedObjectSlot(Object* object)
: SlotBase(reinterpret_cast<Address>(&object->ptr_)) {}
Object CompressedObjectSlot::operator*() const {
Tagged_t value = *location();
return Object(DecompressTaggedAny(address(), value));
}
void CompressedObjectSlot::store(Object value) const {
*location() = CompressTagged(value->ptr());
}
Object CompressedObjectSlot::Acquire_Load() const {
AtomicTagged_t value = AsAtomicTagged::Acquire_Load(location());
return Object(DecompressTaggedAny(address(), value));
}
Object CompressedObjectSlot::Relaxed_Load() const {
AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location());
return Object(DecompressTaggedAny(address(), value));
}
void CompressedObjectSlot::Relaxed_Store(Object value) const {
Tagged_t ptr = CompressTagged(value->ptr());
AsAtomicTagged::Relaxed_Store(location(), ptr);
}
void CompressedObjectSlot::Release_Store(Object value) const {
Tagged_t ptr = CompressTagged(value->ptr());
AsAtomicTagged::Release_Store(location(), ptr);
}
Object CompressedObjectSlot::Release_CompareAndSwap(Object old,
Object target) const {
Tagged_t old_ptr = CompressTagged(old->ptr());
Tagged_t target_ptr = CompressTagged(target->ptr());
Tagged_t result =
AsAtomicTagged::Release_CompareAndSwap(location(), old_ptr, target_ptr);
return Object(DecompressTaggedAny(address(), result));
}
//
// CompressedMapWordSlot implementation.
//
bool CompressedMapWordSlot::contains_value(Address raw_value) const {
AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location());
return static_cast<uint32_t>(value) ==
static_cast<uint32_t>(static_cast<Tagged_t>(raw_value));
}
Object CompressedMapWordSlot::operator*() const {
Tagged_t value = *location();
return Object(DecompressTaggedPointer(address(), value));
}
void CompressedMapWordSlot::store(Object value) const {
*location() = CompressTagged(value.ptr());
}
Object CompressedMapWordSlot::Relaxed_Load() const {
AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location());
return Object(DecompressTaggedPointer(address(), value));
}
void CompressedMapWordSlot::Relaxed_Store(Object value) const {
Tagged_t ptr = CompressTagged(value.ptr());
AsAtomicTagged::Relaxed_Store(location(), ptr);
}
Object CompressedMapWordSlot::Acquire_Load() const {
AtomicTagged_t value = AsAtomicTagged::Acquire_Load(location());
return Object(DecompressTaggedPointer(address(), value));
}
void CompressedMapWordSlot::Release_Store(Object value) const {
Tagged_t ptr = CompressTagged(value->ptr());
AsAtomicTagged::Release_Store(location(), ptr);
}
Object CompressedMapWordSlot::Release_CompareAndSwap(Object old,
Object target) const {
Tagged_t old_ptr = CompressTagged(old->ptr());
Tagged_t target_ptr = CompressTagged(target->ptr());
Tagged_t result =
AsAtomicTagged::Release_CompareAndSwap(location(), old_ptr, target_ptr);
return Object(DecompressTaggedPointer(address(), result));
}
//
// CompressedMaybeObjectSlot implementation.
//
MaybeObject CompressedMaybeObjectSlot::operator*() const {
Tagged_t value = *location();
return MaybeObject(DecompressTaggedAny(address(), value));
}
void CompressedMaybeObjectSlot::store(MaybeObject value) const {
*location() = CompressTagged(value->ptr());
}
MaybeObject CompressedMaybeObjectSlot::Relaxed_Load() const {
AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location());
return MaybeObject(DecompressTaggedAny(address(), value));
}
void CompressedMaybeObjectSlot::Relaxed_Store(MaybeObject value) const {
Tagged_t ptr = CompressTagged(value->ptr());
AsAtomicTagged::Relaxed_Store(location(), ptr);
}
void CompressedMaybeObjectSlot::Release_CompareAndSwap(
MaybeObject old, MaybeObject target) const {
Tagged_t old_ptr = CompressTagged(old->ptr());
Tagged_t target_ptr = CompressTagged(target->ptr());
AsAtomicTagged::Release_CompareAndSwap(location(), old_ptr, target_ptr);
}
//
// CompressedHeapObjectSlot implementation.
//
HeapObjectReference CompressedHeapObjectSlot::operator*() const {
Tagged_t value = *location();
return HeapObjectReference(DecompressTaggedPointer(address(), value));
}
void CompressedHeapObjectSlot::store(HeapObjectReference value) const {
*location() = CompressTagged(value.ptr());
}
HeapObject CompressedHeapObjectSlot::ToHeapObject() const {
Tagged_t value = *location();
DCHECK_EQ(value & kHeapObjectTagMask, kHeapObjectTag);
return HeapObject::cast(Object(DecompressTaggedPointer(address(), value)));
}
void CompressedHeapObjectSlot::StoreHeapObject(HeapObject value) const {
*location() = CompressTagged(value->ptr());
}
} // namespace internal
} // namespace v8
#endif // V8_COMPRESS_POINTERS
#endif // V8_OBJECTS_COMPRESSED_SLOTS_INL_H_
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_COMPRESSED_SLOTS_H_
#define V8_OBJECTS_COMPRESSED_SLOTS_H_
#ifdef V8_COMPRESS_POINTERS
#include "src/objects/slots.h"
namespace v8 {
namespace internal {
// A CompressedObjectSlot instance describes a kTaggedSize-sized field ("slot")
// holding a compressed tagged pointer (smi or heap object).
// Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store().
class CompressedObjectSlot : public SlotBase<CompressedObjectSlot, Tagged_t> {
public:
using TObject = Object;
using THeapObjectSlot = CompressedHeapObjectSlot;
static constexpr bool kCanBeWeak = false;
CompressedObjectSlot() : SlotBase(kNullAddress) {}
explicit CompressedObjectSlot(Address ptr) : SlotBase(ptr) {}
explicit CompressedObjectSlot(Address* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
inline explicit CompressedObjectSlot(Object* object);
explicit CompressedObjectSlot(Object const* const* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
template <typename T>
explicit CompressedObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
: SlotBase(slot.address()) {}
inline Object operator*() const;
inline void store(Object value) const;
inline Object Acquire_Load() const;
inline Object Relaxed_Load() const;
inline void Relaxed_Store(Object value) const;
inline void Release_Store(Object value) const;
inline Object Release_CompareAndSwap(Object old, Object target) const;
};
// A CompressedMapWordSlot instance describes a kTaggedSize-sized map-word field
// ("slot") of heap objects holding a compressed tagged pointer or a Smi
// representing forwaring pointer value.
// This slot kind is similar to CompressedObjectSlot but decompression of
// forwarding pointer is different.
// Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store().
class CompressedMapWordSlot : public SlotBase<CompressedMapWordSlot, Tagged_t> {
public:
using TObject = Object;
static constexpr bool kCanBeWeak = false;
CompressedMapWordSlot() : SlotBase(kNullAddress) {}
explicit CompressedMapWordSlot(Address ptr) : SlotBase(ptr) {}
// Compares memory representation of a value stored in the slot with given
// raw value without decompression.
inline bool contains_value(Address raw_value) const;
inline Object operator*() const;
inline void store(Object value) const;
inline Object Relaxed_Load() const;
inline void Relaxed_Store(Object value) const;
inline Object Acquire_Load() const;
inline void Release_Store(Object value) const;
inline Object Release_CompareAndSwap(Object old, Object target) const;
};
// A CompressedMaybeObjectSlot instance describes a kTaggedSize-sized field
// ("slot") holding a possibly-weak compressed tagged pointer
// (think: MaybeObject).
// Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store().
class CompressedMaybeObjectSlot
: public SlotBase<CompressedMaybeObjectSlot, Tagged_t> {
public:
using TObject = MaybeObject;
using THeapObjectSlot = CompressedHeapObjectSlot;
static constexpr bool kCanBeWeak = true;
CompressedMaybeObjectSlot() : SlotBase(kNullAddress) {}
explicit CompressedMaybeObjectSlot(Address ptr) : SlotBase(ptr) {}
explicit CompressedMaybeObjectSlot(Object* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
explicit CompressedMaybeObjectSlot(MaybeObject* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
template <typename T>
explicit CompressedMaybeObjectSlot(
SlotBase<T, TData, kSlotDataAlignment> slot)
: SlotBase(slot.address()) {}
inline MaybeObject operator*() const;
inline void store(MaybeObject value) const;
inline MaybeObject Relaxed_Load() const;
inline void Relaxed_Store(MaybeObject value) const;
inline void Release_CompareAndSwap(MaybeObject old, MaybeObject target) const;
};
// A CompressedHeapObjectSlot instance describes a kTaggedSize-sized field
// ("slot") holding a weak or strong compressed pointer to a heap object (think:
// HeapObjectReference).
// Its address() is the address of the slot.
// 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,
// ToHeapObject() can be used to retrieve that heap object.
class CompressedHeapObjectSlot
: public SlotBase<CompressedHeapObjectSlot, Tagged_t> {
public:
CompressedHeapObjectSlot() : SlotBase(kNullAddress) {}
explicit CompressedHeapObjectSlot(Address ptr) : SlotBase(ptr) {}
explicit CompressedHeapObjectSlot(Object* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
template <typename T>
explicit CompressedHeapObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
: SlotBase(slot.address()) {}
inline HeapObjectReference operator*() const;
inline void store(HeapObjectReference value) const;
inline HeapObject ToHeapObject() const;
inline void StoreHeapObject(HeapObject value) const;
};
} // namespace internal
} // namespace v8
#endif // V8_COMPRESS_POINTERS
#endif // V8_OBJECTS_COMPRESSED_SLOTS_H_
......@@ -9,7 +9,6 @@
#include "src/objects/instance-type-inl.h"
#include "src/objects/maybe-object-inl.h"
#include "src/objects/slots.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
......
......@@ -13,6 +13,7 @@
#include "src/heap/heap-write-barrier-inl.h"
#include "src/objects-inl.h"
#include "src/objects/bigint.h"
#include "src/objects/compressed-slots.h"
#include "src/objects/heap-number-inl.h"
#include "src/objects/map.h"
#include "src/objects/maybe-object-inl.h"
......
......@@ -7,7 +7,6 @@
#include "src/maybe-handles.h"
#include "src/objects/instance-type.h"
#include "src/objects/slots.h"
#include "src/objects/smi.h"
#include "torque-generated/class-definitions-from-dsl.h"
......
......@@ -9,7 +9,6 @@
#include "include/v8.h"
#include "src/globals.h"
#include "src/objects.h"
#include "src/objects/slots.h"
#include "src/objects/smi.h"
namespace v8 {
......
......@@ -9,7 +9,9 @@
#include "src/heap/heap.h"
#include "src/objects-inl.h"
#include "src/objects/compressed-slots.h"
#include "src/objects/fixed-array-inl.h"
#include "src/objects/slots.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
......@@ -47,6 +49,22 @@ template <class Derived>
SmallOrderedHashTable<Derived>::SmallOrderedHashTable(Address ptr)
: HeapObject(ptr) {}
template <class Derived>
Object SmallOrderedHashTable<Derived>::KeyAt(int entry) const {
DCHECK_LT(entry, Capacity());
Offset entry_offset = GetDataEntryOffset(entry, Derived::kKeyIndex);
return READ_FIELD(*this, entry_offset);
}
template <class Derived>
Object SmallOrderedHashTable<Derived>::GetDataEntry(int entry,
int relative_index) {
DCHECK_LT(entry, Capacity());
DCHECK_LE(static_cast<unsigned>(relative_index), Derived::kEntrySize);
Offset entry_offset = GetDataEntryOffset(entry, relative_index);
return READ_FIELD(*this, entry_offset);
}
OBJECT_CONSTRUCTORS_IMPL(SmallOrderedHashSet,
SmallOrderedHashTable<SmallOrderedHashSet>)
OBJECT_CONSTRUCTORS_IMPL(SmallOrderedHashMap,
......
......@@ -403,11 +403,7 @@ class SmallOrderedHashTable : public HeapObject {
int NumberOfBuckets() const { return getByte(NumberOfBucketsOffset(), 0); }
Object KeyAt(int entry) const {
DCHECK_LT(entry, Capacity());
Offset entry_offset = GetDataEntryOffset(entry, Derived::kKeyIndex);
return READ_FIELD(*this, entry_offset);
}
V8_INLINE Object KeyAt(int entry) const;
DECL_VERIFIER(SmallOrderedHashTable)
......@@ -487,12 +483,7 @@ class SmallOrderedHashTable : public HeapObject {
return getByte(GetChainTableOffset(), entry);
}
Object GetDataEntry(int entry, int relative_index) {
DCHECK_LT(entry, Capacity());
DCHECK_LE(static_cast<unsigned>(relative_index), Derived::kEntrySize);
Offset entry_offset = GetDataEntryOffset(entry, relative_index);
return READ_FIELD(*this, entry_offset);
}
V8_INLINE Object GetDataEntry(int entry, int relative_index);
int HashToBucket(int hash) const { return hash & (NumberOfBuckets() - 1); }
......
......@@ -9,7 +9,9 @@
#include "src/function-kind.h"
#include "src/objects.h"
#include "src/objects/builtin-function-id.h"
#include "src/objects/compressed-slots.h"
#include "src/objects/script.h"
#include "src/objects/slots.h"
#include "src/objects/smi.h"
#include "src/objects/struct.h"
#include "torque-generated/class-definitions-from-dsl.h"
......
......@@ -6,6 +6,7 @@
#define V8_OBJECTS_SLOTS_ATOMIC_INL_H_
#include "src/base/atomic-utils.h"
#include "src/objects/compressed-slots.h"
#include "src/objects/slots.h"
namespace v8 {
......
......@@ -12,10 +12,7 @@
#include "src/objects.h"
#include "src/objects/heap-object-inl.h"
#include "src/objects/maybe-object.h"
#ifdef V8_COMPRESS_POINTERS
#include "src/ptr-compr-inl.h"
#endif
namespace v8 {
namespace internal {
......
......@@ -7,7 +7,7 @@
#if V8_TARGET_ARCH_64_BIT
#include "src/objects/heap-object-inl.h"
#include "include/v8-internal.h"
#include "src/ptr-compr.h"
namespace v8 {
......@@ -29,176 +29,34 @@ V8_INLINE Address GetRootFromOnHeapAddress(Address addr) {
// preserving both weak- and smi- tags.
V8_INLINE Address DecompressTaggedPointer(Address on_heap_addr,
Tagged_t raw_value) {
int32_t value = static_cast<int32_t>(raw_value);
// Current compression scheme requires |raw_value| to be sign-extended
// from int32_t to intptr_t.
intptr_t value = static_cast<intptr_t>(static_cast<int32_t>(raw_value));
Address root = GetRootFromOnHeapAddress(on_heap_addr);
// Current compression scheme requires value to be sign-extended to inptr_t
// before adding the |root|.
return root + static_cast<Address>(static_cast<intptr_t>(value));
return root + static_cast<Address>(value);
}
// Decompresses any tagged value, preserving both weak- and smi- tags.
V8_INLINE Address DecompressTaggedAny(Address on_heap_addr,
Tagged_t raw_value) {
int32_t value = static_cast<int32_t>(raw_value);
// Current compression scheme requires |raw_value| to be sign-extended
// from int32_t to intptr_t.
intptr_t value = static_cast<intptr_t>(static_cast<int32_t>(raw_value));
// |root_mask| is 0 if the |value| was a smi or -1 otherwise.
Address root_mask = -static_cast<Address>(value & kSmiTagMask);
Address root_mask = static_cast<Address>(-(value & kSmiTagMask));
Address root_or_zero = root_mask & GetRootFromOnHeapAddress(on_heap_addr);
// Current compression scheme requires value to be sign-extended to inptr_t
// before adding the |root_or_zero|.
return root_or_zero + static_cast<Address>(static_cast<intptr_t>(value));
return root_or_zero + static_cast<Address>(value);
}
#ifdef V8_COMPRESS_POINTERS
STATIC_ASSERT(kPtrComprHeapReservationSize ==
Internals::kPtrComprHeapReservationSize);
STATIC_ASSERT(kPtrComprIsolateRootBias == Internals::kPtrComprIsolateRootBias);
STATIC_ASSERT(kPtrComprIsolateRootAlignment ==
Internals::kPtrComprIsolateRootAlignment);
//
// CompressedObjectSlot implementation.
//
CompressedObjectSlot::CompressedObjectSlot(Object* object)
: SlotBase(reinterpret_cast<Address>(&object->ptr_)) {}
Object CompressedObjectSlot::operator*() const {
Tagged_t value = *location();
return Object(DecompressTaggedAny(address(), value));
}
void CompressedObjectSlot::store(Object value) const {
*location() = CompressTagged(value->ptr());
}
Object CompressedObjectSlot::Acquire_Load() const {
AtomicTagged_t value = AsAtomicTagged::Acquire_Load(location());
return Object(DecompressTaggedAny(address(), value));
}
Object CompressedObjectSlot::Relaxed_Load() const {
AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location());
return Object(DecompressTaggedAny(address(), value));
}
void CompressedObjectSlot::Relaxed_Store(Object value) const {
Tagged_t ptr = CompressTagged(value->ptr());
AsAtomicTagged::Relaxed_Store(location(), ptr);
}
void CompressedObjectSlot::Release_Store(Object value) const {
Tagged_t ptr = CompressTagged(value->ptr());
AsAtomicTagged::Release_Store(location(), ptr);
}
Object CompressedObjectSlot::Release_CompareAndSwap(Object old,
Object target) const {
Tagged_t old_ptr = CompressTagged(old->ptr());
Tagged_t target_ptr = CompressTagged(target->ptr());
Tagged_t result =
AsAtomicTagged::Release_CompareAndSwap(location(), old_ptr, target_ptr);
return Object(DecompressTaggedAny(address(), result));
}
//
// CompressedMapWordSlot implementation.
//
bool CompressedMapWordSlot::contains_value(Address raw_value) const {
AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location());
return static_cast<uint32_t>(value) ==
static_cast<uint32_t>(static_cast<Tagged_t>(raw_value));
}
Object CompressedMapWordSlot::operator*() const {
Tagged_t value = *location();
return Object(DecompressTaggedPointer(address(), value));
}
void CompressedMapWordSlot::store(Object value) const {
*location() = CompressTagged(value.ptr());
}
Object CompressedMapWordSlot::Relaxed_Load() const {
AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location());
return Object(DecompressTaggedPointer(address(), value));
}
void CompressedMapWordSlot::Relaxed_Store(Object value) const {
Tagged_t ptr = CompressTagged(value.ptr());
AsAtomicTagged::Relaxed_Store(location(), ptr);
}
Object CompressedMapWordSlot::Acquire_Load() const {
AtomicTagged_t value = AsAtomicTagged::Acquire_Load(location());
return Object(DecompressTaggedPointer(address(), value));
}
void CompressedMapWordSlot::Release_Store(Object value) const {
Tagged_t ptr = CompressTagged(value->ptr());
AsAtomicTagged::Release_Store(location(), ptr);
}
Object CompressedMapWordSlot::Release_CompareAndSwap(Object old,
Object target) const {
Tagged_t old_ptr = CompressTagged(old->ptr());
Tagged_t target_ptr = CompressTagged(target->ptr());
Tagged_t result =
AsAtomicTagged::Release_CompareAndSwap(location(), old_ptr, target_ptr);
return Object(DecompressTaggedPointer(address(), result));
}
//
// CompressedMaybeObjectSlot implementation.
//
MaybeObject CompressedMaybeObjectSlot::operator*() const {
Tagged_t value = *location();
return MaybeObject(DecompressTaggedAny(address(), value));
}
void CompressedMaybeObjectSlot::store(MaybeObject value) const {
*location() = CompressTagged(value->ptr());
}
MaybeObject CompressedMaybeObjectSlot::Relaxed_Load() const {
AtomicTagged_t value = AsAtomicTagged::Relaxed_Load(location());
return MaybeObject(DecompressTaggedAny(address(), value));
}
void CompressedMaybeObjectSlot::Relaxed_Store(MaybeObject value) const {
Tagged_t ptr = CompressTagged(value->ptr());
AsAtomicTagged::Relaxed_Store(location(), ptr);
}
void CompressedMaybeObjectSlot::Release_CompareAndSwap(
MaybeObject old, MaybeObject target) const {
Tagged_t old_ptr = CompressTagged(old->ptr());
Tagged_t target_ptr = CompressTagged(target->ptr());
AsAtomicTagged::Release_CompareAndSwap(location(), old_ptr, target_ptr);
}
//
// CompressedHeapObjectSlot implementation.
//
HeapObjectReference CompressedHeapObjectSlot::operator*() const {
Tagged_t value = *location();
return HeapObjectReference(DecompressTaggedPointer(address(), value));
}
void CompressedHeapObjectSlot::store(HeapObjectReference value) const {
*location() = CompressTagged(value.ptr());
}
HeapObject CompressedHeapObjectSlot::ToHeapObject() const {
Tagged_t value = *location();
DCHECK_EQ(value & kHeapObjectTagMask, kHeapObjectTag);
return HeapObject::cast(Object(DecompressTaggedPointer(address(), value)));
}
void CompressedHeapObjectSlot::StoreHeapObject(HeapObject value) const {
*location() = CompressTagged(value->ptr());
}
#endif // V8_COMPRESS_POINTERS
} // namespace internal
} // namespace v8
......
......@@ -8,7 +8,6 @@
#if V8_TARGET_ARCH_64_BIT
#include "src/globals.h"
#include "src/objects/slots.h"
namespace v8 {
namespace internal {
......@@ -18,127 +17,6 @@ constexpr size_t kPtrComprHeapReservationSize = size_t{4} * GB;
constexpr size_t kPtrComprIsolateRootBias = kPtrComprHeapReservationSize / 2;
constexpr size_t kPtrComprIsolateRootAlignment = size_t{4} * GB;
// A CompressedObjectSlot instance describes a kTaggedSize-sized field ("slot")
// holding a compressed tagged pointer (smi or heap object).
// Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store().
class CompressedObjectSlot : public SlotBase<CompressedObjectSlot, Tagged_t> {
public:
using TObject = Object;
using THeapObjectSlot = CompressedHeapObjectSlot;
static constexpr bool kCanBeWeak = false;
CompressedObjectSlot() : SlotBase(kNullAddress) {}
explicit CompressedObjectSlot(Address ptr) : SlotBase(ptr) {}
explicit CompressedObjectSlot(Address* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
inline explicit CompressedObjectSlot(Object* object);
explicit CompressedObjectSlot(Object const* const* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
template <typename T>
explicit CompressedObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
: SlotBase(slot.address()) {}
inline Object operator*() const;
inline void store(Object value) const;
inline Object Acquire_Load() const;
inline Object Relaxed_Load() const;
inline void Relaxed_Store(Object value) const;
inline void Release_Store(Object value) const;
inline Object Release_CompareAndSwap(Object old, Object target) const;
};
// A CompressedMapWordSlot instance describes a kTaggedSize-sized map-word field
// ("slot") of heap objects holding a compressed tagged pointer or a Smi
// representing forwaring pointer value.
// This slot kind is similar to CompressedObjectSlot but decompression of
// forwarding pointer is different.
// Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store().
class CompressedMapWordSlot : public SlotBase<CompressedMapWordSlot, Tagged_t> {
public:
using TObject = Object;
static constexpr bool kCanBeWeak = false;
CompressedMapWordSlot() : SlotBase(kNullAddress) {}
explicit CompressedMapWordSlot(Address ptr) : SlotBase(ptr) {}
// Compares memory representation of a value stored in the slot with given
// raw value without decompression.
inline bool contains_value(Address raw_value) const;
inline Object operator*() const;
inline void store(Object value) const;
inline Object Relaxed_Load() const;
inline void Relaxed_Store(Object value) const;
inline Object Acquire_Load() const;
inline void Release_Store(Object value) const;
inline Object Release_CompareAndSwap(Object old, Object target) const;
};
// A CompressedMaybeObjectSlot instance describes a kTaggedSize-sized field
// ("slot") holding a possibly-weak compressed tagged pointer
// (think: MaybeObject).
// Its address() is the address of the slot.
// The slot's contents can be read and written using operator* and store().
class CompressedMaybeObjectSlot
: public SlotBase<CompressedMaybeObjectSlot, Tagged_t> {
public:
using TObject = MaybeObject;
using THeapObjectSlot = CompressedHeapObjectSlot;
static constexpr bool kCanBeWeak = true;
CompressedMaybeObjectSlot() : SlotBase(kNullAddress) {}
explicit CompressedMaybeObjectSlot(Address ptr) : SlotBase(ptr) {}
explicit CompressedMaybeObjectSlot(Object* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
explicit CompressedMaybeObjectSlot(MaybeObject* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
template <typename T>
explicit CompressedMaybeObjectSlot(
SlotBase<T, TData, kSlotDataAlignment> slot)
: SlotBase(slot.address()) {}
inline MaybeObject operator*() const;
inline void store(MaybeObject value) const;
inline MaybeObject Relaxed_Load() const;
inline void Relaxed_Store(MaybeObject value) const;
inline void Release_CompareAndSwap(MaybeObject old, MaybeObject target) const;
};
// A CompressedHeapObjectSlot instance describes a kTaggedSize-sized field
// ("slot") holding a weak or strong compressed pointer to a heap object (think:
// HeapObjectReference).
// Its address() is the address of the slot.
// 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,
// ToHeapObject() can be used to retrieve that heap object.
class CompressedHeapObjectSlot
: public SlotBase<CompressedHeapObjectSlot, Tagged_t> {
public:
CompressedHeapObjectSlot() : SlotBase(kNullAddress) {}
explicit CompressedHeapObjectSlot(Address ptr) : SlotBase(ptr) {}
explicit CompressedHeapObjectSlot(Object* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
template <typename T>
explicit CompressedHeapObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
: SlotBase(slot.address()) {}
inline HeapObjectReference operator*() const;
inline void store(HeapObjectReference value) const;
inline HeapObject ToHeapObject() const;
inline void StoreHeapObject(HeapObject value) const;
};
} // namespace internal
} // namespace v8
......
......@@ -7,6 +7,7 @@
#include "src/globals.h"
#include "src/objects/code.h"
#include "src/objects/compressed-slots.h"
#include "src/objects/foreign.h"
#include "src/objects/slots.h"
......
......@@ -255,7 +255,7 @@ TEST(IsValidPositiveSmi) {
typedef std::numeric_limits<int32_t> int32_limits;
IsValidPositiveSmiCase(isolate, int32_limits::max());
IsValidPositiveSmiCase(isolate, int32_limits::min());
#ifdef V8_TARGET_ARCH_64_BIT
#if V8_TARGET_ARCH_64_BIT
IsValidPositiveSmiCase(isolate,
static_cast<intptr_t>(int32_limits::max()) + 1);
IsValidPositiveSmiCase(isolate,
......
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