Commit 86ebfc96 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[object] Add Object::Relaxed_ReadField

This method has no users in this CL and is a pre-requisite for shared
strings.

Bug: v8:12007
Change-Id: Id8eaf58aa8bb3092c710279c0c9ae0eda5581284
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3321564Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78312}
parent 780d9b88
......@@ -178,6 +178,27 @@ using AsAtomic8 = AsAtomicImpl<base::Atomic8>;
using AsAtomic32 = AsAtomicImpl<base::Atomic32>;
using AsAtomicWord = AsAtomicImpl<base::AtomicWord>;
template <int Width>
struct AtomicTypeFromByteWidth {};
template <>
struct AtomicTypeFromByteWidth<1> {
using type = base::Atomic8;
};
template <>
struct AtomicTypeFromByteWidth<2> {
using type = base::Atomic16;
};
template <>
struct AtomicTypeFromByteWidth<4> {
using type = base::Atomic32;
};
#if V8_HOST_ARCH_64_BIT
template <>
struct AtomicTypeFromByteWidth<8> {
using type = base::Atomic64;
};
#endif
// This is similar to AsAtomicWord but it explicitly deletes functionality
// provided atomic access to bit representation of stored values.
template <typename TAtomicStorageType>
......
......@@ -145,6 +145,20 @@ bool Object::IsNoSharedNameSentinel() const {
return *this == SharedFunctionInfo::kNoSharedNameSentinel;
}
template <class T,
typename std::enable_if<(std::is_arithmetic<T>::value ||
std::is_enum<T>::value) &&
!std::is_floating_point<T>::value,
int>::type>
T Object::Relaxed_ReadField(size_t offset) const {
// Pointer compression causes types larger than kTaggedSize to be
// unaligned. Atomic loads must be aligned.
DCHECK_IMPLIES(COMPRESS_POINTERS_BOOL, sizeof(T) <= kTaggedSize);
using AtomicT = typename base::AtomicTypeFromByteWidth<sizeof(T)>::type;
return static_cast<T>(base::AsAtomicImpl<AtomicT>::Relaxed_Load(
reinterpret_cast<AtomicT*>(field_address(offset))));
}
bool HeapObject::InSharedHeap() const {
if (IsReadOnlyHeapObject(*this)) return V8_SHARED_RO_HEAP_BOOL;
return InSharedWritableHeap();
......
......@@ -681,6 +681,15 @@ class Object : public TaggedImpl<HeapObjectReferenceType::STRONG, Address> {
}
}
// Atomically reads a field using relaxed memory ordering. Can only be used
// with integral types whose size is <= kTaggedSize (to guarantee alignment).
template <class T,
typename std::enable_if<(std::is_arithmetic<T>::value ||
std::is_enum<T>::value) &&
!std::is_floating_point<T>::value,
int>::type = 0>
inline T Relaxed_ReadField(size_t offset) const;
template <class T, typename std::enable_if<std::is_arithmetic<T>::value ||
std::is_enum<T>::value,
int>::type = 0>
......
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