[ptr-compr][cleanup] Remove ROOT_PARAM, ROOT_VALUE and friends

... in favor of Isolate*. It seems that it's better to be uniform in
using Isolate* or isolate root value, so if we decide to pass isolate
root value instead of Isolate* it should better be done everywhere and
it will be a separate CL anyway.

Regarding the "optionality" of the isolate parameter - C++ compilers
are smart enough to optimize it away during inlining.

Bug: v8:9353
Change-Id: Idf86a792476f49393041ced1c54b8671f5b1794a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1653121
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62107}
This commit is contained in:
Igor Sheludko 2019-06-11 19:06:14 +02:00 committed by Commit Bot
parent 823795fc2b
commit 0ebc2b6d76
8 changed files with 44 additions and 65 deletions

View File

@ -212,15 +212,6 @@ constexpr size_t kReservedCodeRangePages = 0;
STATIC_ASSERT(kSystemPointerSize == (1 << kSystemPointerSizeLog2)); STATIC_ASSERT(kSystemPointerSize == (1 << kSystemPointerSizeLog2));
// This macro is used for declaring and defining HeapObject getter methods that
// are a bit more efficient for the pointer compression case than the default
// parameterless getters because isolate root doesn't have to be computed from
// arbitrary field address but it comes "for free" instead.
// These alternatives are always defined (in order to avoid #ifdef mess but
// are not supposed to be used when pointer compression is not enabled.
#define ROOT_VALUE isolate_for_root
#define ROOT_PARAM Isolate* const ROOT_VALUE
#ifdef V8_COMPRESS_POINTERS #ifdef V8_COMPRESS_POINTERS
static_assert( static_assert(
kSystemPointerSize == kInt64Size, kSystemPointerSize == kInt64Size,
@ -234,11 +225,6 @@ constexpr int kTaggedSizeLog2 = 2;
using Tagged_t = int32_t; using Tagged_t = int32_t;
using AtomicTagged_t = base::Atomic32; using AtomicTagged_t = base::Atomic32;
#define DEFINE_ROOT_VALUE(isolate) ROOT_PARAM = isolate
#define WITH_ROOT_PARAM(...) ROOT_PARAM, ##__VA_ARGS__
#define WITH_ROOT_VALUE(...) ROOT_VALUE, ##__VA_ARGS__
#define WITH_ROOT(isolate_for_root, ...) isolate_for_root, ##__VA_ARGS__
#else #else
constexpr int kTaggedSize = kSystemPointerSize; constexpr int kTaggedSize = kSystemPointerSize;
@ -249,11 +235,6 @@ constexpr int kTaggedSizeLog2 = kSystemPointerSizeLog2;
using Tagged_t = Address; using Tagged_t = Address;
using AtomicTagged_t = base::AtomicWord; using AtomicTagged_t = base::AtomicWord;
#define DEFINE_ROOT_VALUE(isolate)
#define WITH_ROOT_PARAM(...) __VA_ARGS__
#define WITH_ROOT_VALUE(...) __VA_ARGS__
#define WITH_ROOT(isolate_for_root, ...) __VA_ARGS__
#endif // V8_COMPRESS_POINTERS #endif // V8_COMPRESS_POINTERS
// Defines whether the branchless or branchful implementation of pointer // Defines whether the branchless or branchful implementation of pointer

View File

@ -34,11 +34,6 @@ V8_INLINE Address GetIsolateRoot<Isolate*>(Isolate* isolate) {
return isolate->isolate_root(); return isolate->isolate_root();
} }
template <>
V8_INLINE Address GetIsolateRoot<const Isolate*>(const Isolate* isolate) {
return isolate->isolate_root();
}
// Decompresses smi value. // Decompresses smi value.
V8_INLINE Address DecompressTaggedSigned(Tagged_t raw_value) { V8_INLINE Address DecompressTaggedSigned(Tagged_t raw_value) {
// Current compression scheme requires |raw_value| to be sign-extended // Current compression scheme requires |raw_value| to be sign-extended

View File

@ -972,7 +972,6 @@ void StandardFrame::IterateCompiledFrame(RootVisitor* v) const {
parameters_limit); parameters_limit);
} }
DEFINE_ROOT_VALUE(isolate());
// Visit pointer spill slots and locals. // Visit pointer spill slots and locals.
uint8_t* safepoint_bits = safepoint_entry.bits(); uint8_t* safepoint_bits = safepoint_entry.bits();
for (unsigned index = 0; index < stack_slots; index++) { for (unsigned index = 0; index < stack_slots; index++) {
@ -992,7 +991,7 @@ void StandardFrame::IterateCompiledFrame(RootVisitor* v) const {
if (!HAS_SMI_TAG(compressed_value)) { if (!HAS_SMI_TAG(compressed_value)) {
// We don't need to update smi values. // We don't need to update smi values.
*spill_slot.location() = *spill_slot.location() =
DecompressTaggedPointer(ROOT_VALUE, compressed_value); DecompressTaggedPointer(isolate(), compressed_value);
} }
#endif #endif
v->VisitRootPointer(Root::kTop, nullptr, spill_slot); v->VisitRootPointer(Root::kTop, nullptr, spill_slot);

View File

@ -430,9 +430,8 @@ void SortIndices(Isolate* isolate, Handle<FixedArray> indices,
AtomicSlot end(start + sort_size); AtomicSlot end(start + sort_size);
std::sort(start, end, [isolate](Tagged_t elementA, Tagged_t elementB) { std::sort(start, end, [isolate](Tagged_t elementA, Tagged_t elementB) {
#ifdef V8_COMPRESS_POINTERS #ifdef V8_COMPRESS_POINTERS
DEFINE_ROOT_VALUE(isolate); Object a(DecompressTaggedAny(isolate, elementA));
Object a(DecompressTaggedAny(ROOT_VALUE, elementA)); Object b(DecompressTaggedAny(isolate, elementB));
Object b(DecompressTaggedAny(ROOT_VALUE, elementB));
#else #else
Object a(elementA); Object a(elementA);
Object b(elementB); Object b(elementB);

View File

@ -52,11 +52,11 @@ bool TaggedImpl<kRefType, StorageType>::GetHeapObject(
template <HeapObjectReferenceType kRefType, typename StorageType> template <HeapObjectReferenceType kRefType, typename StorageType>
bool TaggedImpl<kRefType, StorageType>::GetHeapObject( bool TaggedImpl<kRefType, StorageType>::GetHeapObject(
ROOT_PARAM, HeapObject* result) const { Isolate* isolate, HeapObject* result) const {
if (kIsFull) return GetHeapObject(result); if (kIsFull) return GetHeapObject(result);
// Implementation for compressed pointers. // Implementation for compressed pointers.
if (!IsStrongOrWeak()) return false; if (!IsStrongOrWeak()) return false;
*result = GetHeapObject(ROOT_VALUE); *result = GetHeapObject(isolate);
return true; return true;
} }
@ -79,14 +79,14 @@ bool TaggedImpl<kRefType, StorageType>::GetHeapObject(
template <HeapObjectReferenceType kRefType, typename StorageType> template <HeapObjectReferenceType kRefType, typename StorageType>
bool TaggedImpl<kRefType, StorageType>::GetHeapObject( bool TaggedImpl<kRefType, StorageType>::GetHeapObject(
ROOT_PARAM, HeapObject* result, Isolate* isolate, HeapObject* result,
HeapObjectReferenceType* reference_type) const { HeapObjectReferenceType* reference_type) const {
if (kIsFull) return GetHeapObject(result, reference_type); if (kIsFull) return GetHeapObject(result, reference_type);
// Implementation for compressed pointers. // Implementation for compressed pointers.
if (!IsStrongOrWeak()) return false; if (!IsStrongOrWeak()) return false;
*reference_type = IsWeakOrCleared() ? HeapObjectReferenceType::WEAK *reference_type = IsWeakOrCleared() ? HeapObjectReferenceType::WEAK
: HeapObjectReferenceType::STRONG; : HeapObjectReferenceType::STRONG;
*result = GetHeapObject(ROOT_VALUE); *result = GetHeapObject(isolate);
return true; return true;
} }
@ -107,12 +107,12 @@ bool TaggedImpl<kRefType, StorageType>::GetHeapObjectIfStrong(
template <HeapObjectReferenceType kRefType, typename StorageType> template <HeapObjectReferenceType kRefType, typename StorageType>
bool TaggedImpl<kRefType, StorageType>::GetHeapObjectIfStrong( bool TaggedImpl<kRefType, StorageType>::GetHeapObjectIfStrong(
ROOT_PARAM, HeapObject* result) const { Isolate* isolate, HeapObject* result) const {
if (kIsFull) return GetHeapObjectIfStrong(result); if (kIsFull) return GetHeapObjectIfStrong(result);
// Implementation for compressed pointers. // Implementation for compressed pointers.
if (IsStrong()) { if (IsStrong()) {
*result = *result = HeapObject::cast(
HeapObject::cast(Object(DecompressTaggedPointer(ROOT_VALUE, ptr_))); Object(DecompressTaggedPointer(isolate, static_cast<Tagged_t>(ptr_))));
return true; return true;
} }
return false; return false;
@ -132,11 +132,12 @@ HeapObject TaggedImpl<kRefType, StorageType>::GetHeapObjectAssumeStrong()
template <HeapObjectReferenceType kRefType, typename StorageType> template <HeapObjectReferenceType kRefType, typename StorageType>
HeapObject TaggedImpl<kRefType, StorageType>::GetHeapObjectAssumeStrong( HeapObject TaggedImpl<kRefType, StorageType>::GetHeapObjectAssumeStrong(
ROOT_PARAM) const { Isolate* isolate) const {
if (kIsFull) return GetHeapObjectAssumeStrong(); if (kIsFull) return GetHeapObjectAssumeStrong();
// Implementation for compressed pointers. // Implementation for compressed pointers.
DCHECK(IsStrong()); DCHECK(IsStrong());
return HeapObject::cast(Object(DecompressTaggedPointer(ROOT_VALUE, ptr_))); return HeapObject::cast(
Object(DecompressTaggedPointer(isolate, static_cast<Tagged_t>(ptr_))));
} }
// //
@ -161,12 +162,12 @@ bool TaggedImpl<kRefType, StorageType>::GetHeapObjectIfWeak(
template <HeapObjectReferenceType kRefType, typename StorageType> template <HeapObjectReferenceType kRefType, typename StorageType>
bool TaggedImpl<kRefType, StorageType>::GetHeapObjectIfWeak( bool TaggedImpl<kRefType, StorageType>::GetHeapObjectIfWeak(
ROOT_PARAM, HeapObject* result) const { Isolate* isolate, HeapObject* result) const {
if (kIsFull) return GetHeapObjectIfWeak(result); if (kIsFull) return GetHeapObjectIfWeak(result);
// Implementation for compressed pointers. // Implementation for compressed pointers.
if (kCanBeWeak) { if (kCanBeWeak) {
if (IsWeak()) { if (IsWeak()) {
*result = GetHeapObject(ROOT_VALUE); *result = GetHeapObject(isolate);
return true; return true;
} }
return false; return false;
@ -189,11 +190,11 @@ HeapObject TaggedImpl<kRefType, StorageType>::GetHeapObjectAssumeWeak() const {
template <HeapObjectReferenceType kRefType, typename StorageType> template <HeapObjectReferenceType kRefType, typename StorageType>
HeapObject TaggedImpl<kRefType, StorageType>::GetHeapObjectAssumeWeak( HeapObject TaggedImpl<kRefType, StorageType>::GetHeapObjectAssumeWeak(
ROOT_PARAM) const { Isolate* isolate) const {
if (kIsFull) return GetHeapObjectAssumeWeak(); if (kIsFull) return GetHeapObjectAssumeWeak();
// Implementation for compressed pointers. // Implementation for compressed pointers.
DCHECK(IsWeak()); DCHECK(IsWeak());
return GetHeapObject(ROOT_VALUE); return GetHeapObject(isolate);
} }
// //
@ -214,17 +215,19 @@ HeapObject TaggedImpl<kRefType, StorageType>::GetHeapObject() const {
} }
template <HeapObjectReferenceType kRefType, typename StorageType> template <HeapObjectReferenceType kRefType, typename StorageType>
HeapObject TaggedImpl<kRefType, StorageType>::GetHeapObject(ROOT_PARAM) const { HeapObject TaggedImpl<kRefType, StorageType>::GetHeapObject(
Isolate* isolate) const {
if (kIsFull) return GetHeapObject(); if (kIsFull) return GetHeapObject();
// Implementation for compressed pointers. // Implementation for compressed pointers.
DCHECK(!IsSmi()); DCHECK(!IsSmi());
if (kCanBeWeak) { if (kCanBeWeak) {
DCHECK(!IsCleared()); DCHECK(!IsCleared());
return HeapObject::cast(Object( return HeapObject::cast(Object(DecompressTaggedPointer(
DecompressTaggedPointer(ROOT_VALUE, ptr_ & ~kWeakHeapObjectMask))); isolate, static_cast<Tagged_t>(ptr_) & ~kWeakHeapObjectMask)));
} else { } else {
DCHECK(!HAS_WEAK_HEAP_OBJECT_TAG(ptr_)); DCHECK(!HAS_WEAK_HEAP_OBJECT_TAG(ptr_));
return HeapObject::cast(Object(DecompressTaggedPointer(ROOT_VALUE, ptr_))); return HeapObject::cast(
Object(DecompressTaggedPointer(isolate, static_cast<Tagged_t>(ptr_))));
} }
} }
@ -242,13 +245,14 @@ Object TaggedImpl<kRefType, StorageType>::GetHeapObjectOrSmi() const {
} }
template <HeapObjectReferenceType kRefType, typename StorageType> template <HeapObjectReferenceType kRefType, typename StorageType>
Object TaggedImpl<kRefType, StorageType>::GetHeapObjectOrSmi(ROOT_PARAM) const { Object TaggedImpl<kRefType, StorageType>::GetHeapObjectOrSmi(
Isolate* isolate) const {
if (kIsFull) return GetHeapObjectOrSmi(); if (kIsFull) return GetHeapObjectOrSmi();
// Implementation for compressed pointers. // Implementation for compressed pointers.
if (IsSmi()) { if (IsSmi()) {
return Object(DecompressTaggedSigned(ptr_)); return Object(DecompressTaggedSigned(static_cast<Tagged_t>(ptr_)));
} }
return GetHeapObject(ROOT_VALUE); return GetHeapObject(isolate);
} }
} // namespace internal } // namespace internal

View File

@ -107,50 +107,51 @@ class TaggedImpl {
// //
// The following set of methods get HeapObject out of the tagged value // The following set of methods get HeapObject out of the tagged value
// which may involve decompression in which case the ROOT_PARAM is required. // which may involve decompression in which case the isolate root is required.
// If the pointer compression is not enabled then the variants with // If the pointer compression is not enabled then the variants with
// ROOT_PARAM will be exactly the same as non-ROOT_PARAM ones. // isolate parameter will be exactly the same as the ones witout isolate
// parameter.
// //
// If this tagged value is a strong pointer to a HeapObject, returns true and // If this tagged value is a strong pointer to a HeapObject, returns true and
// sets *result. Otherwise returns false. // sets *result. Otherwise returns false.
inline bool GetHeapObjectIfStrong(HeapObject* result) const; inline bool GetHeapObjectIfStrong(HeapObject* result) const;
inline bool GetHeapObjectIfStrong(ROOT_PARAM, HeapObject* result) const; inline bool GetHeapObjectIfStrong(Isolate* isolate, HeapObject* result) const;
// DCHECKs that this tagged value is a strong pointer to a HeapObject and // DCHECKs that this tagged value is a strong pointer to a HeapObject and
// returns the HeapObject. // returns the HeapObject.
inline HeapObject GetHeapObjectAssumeStrong() const; inline HeapObject GetHeapObjectAssumeStrong() const;
inline HeapObject GetHeapObjectAssumeStrong(ROOT_PARAM) const; inline HeapObject GetHeapObjectAssumeStrong(Isolate* isolate) const;
// If this tagged value is a weak pointer to a HeapObject, returns true and // If this tagged value is a weak pointer to a HeapObject, returns true and
// sets *result. Otherwise returns false. // sets *result. Otherwise returns false.
inline bool GetHeapObjectIfWeak(HeapObject* result) const; inline bool GetHeapObjectIfWeak(HeapObject* result) const;
inline bool GetHeapObjectIfWeak(ROOT_PARAM, HeapObject* result) const; inline bool GetHeapObjectIfWeak(Isolate* isolate, HeapObject* result) const;
// DCHECKs that this tagged value is a weak pointer to a HeapObject and // DCHECKs that this tagged value is a weak pointer to a HeapObject and
// returns the HeapObject. // returns the HeapObject.
inline HeapObject GetHeapObjectAssumeWeak() const; inline HeapObject GetHeapObjectAssumeWeak() const;
inline HeapObject GetHeapObjectAssumeWeak(ROOT_PARAM) const; inline HeapObject GetHeapObjectAssumeWeak(Isolate* isolate) const;
// If this tagged value is a strong or weak pointer to a HeapObject, returns // If this tagged value is a strong or weak pointer to a HeapObject, returns
// true and sets *result. Otherwise returns false. // true and sets *result. Otherwise returns false.
inline bool GetHeapObject(HeapObject* result) const; inline bool GetHeapObject(HeapObject* result) const;
inline bool GetHeapObject(ROOT_PARAM, HeapObject* result) const; inline bool GetHeapObject(Isolate* isolate, HeapObject* result) const;
inline bool GetHeapObject(HeapObject* result, inline bool GetHeapObject(HeapObject* result,
HeapObjectReferenceType* reference_type) const; HeapObjectReferenceType* reference_type) const;
inline bool GetHeapObject(ROOT_PARAM, HeapObject* result, inline bool GetHeapObject(Isolate* isolate, HeapObject* result,
HeapObjectReferenceType* reference_type) const; HeapObjectReferenceType* reference_type) const;
// DCHECKs that this tagged value is a strong or a weak pointer to a // DCHECKs that this tagged value is a strong or a weak pointer to a
// HeapObject and returns the HeapObject. // HeapObject and returns the HeapObject.
inline HeapObject GetHeapObject() const; inline HeapObject GetHeapObject() const;
inline HeapObject GetHeapObject(ROOT_PARAM) const; inline HeapObject GetHeapObject(Isolate* isolate) const;
// DCHECKs that this tagged value is a strong or a weak pointer to a // DCHECKs that this tagged value is a strong or a weak pointer to a
// HeapObject or a Smi and returns the HeapObject or Smi. // HeapObject or a Smi and returns the HeapObject or Smi.
inline Object GetHeapObjectOrSmi() const; inline Object GetHeapObjectOrSmi() const;
inline Object GetHeapObjectOrSmi(ROOT_PARAM) const; inline Object GetHeapObjectOrSmi(Isolate* isolate) const;
// Cast operation is available only for full non-weak tagged values. // Cast operation is available only for full non-weak tagged values.
template <typename T> template <typename T>

View File

@ -17,17 +17,17 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
Object StrongTaggedValue::ToObject(WITH_ROOT_PARAM(StrongTaggedValue object)) { Object StrongTaggedValue::ToObject(Isolate* isolate, StrongTaggedValue object) {
#ifdef V8_COMPRESS_POINTERS #ifdef V8_COMPRESS_POINTERS
return Object(DecompressTaggedAny(ROOT_VALUE, object.ptr())); return Object(DecompressTaggedAny(isolate, object.ptr()));
#else #else
return Object(object.ptr()); return Object(object.ptr());
#endif #endif
} }
MaybeObject TaggedValue::ToMaybeObject(WITH_ROOT_PARAM(TaggedValue object)) { MaybeObject TaggedValue::ToMaybeObject(Isolate* isolate, TaggedValue object) {
#ifdef V8_COMPRESS_POINTERS #ifdef V8_COMPRESS_POINTERS
return MaybeObject(DecompressTaggedAny(ROOT_VALUE, object.ptr())); return MaybeObject(DecompressTaggedAny(isolate, object.ptr()));
#else #else
return MaybeObject(object.ptr()); return MaybeObject(object.ptr());
#endif #endif

View File

@ -22,7 +22,7 @@ class StrongTaggedValue
constexpr StrongTaggedValue() : TaggedImpl() {} constexpr StrongTaggedValue() : TaggedImpl() {}
explicit constexpr StrongTaggedValue(Tagged_t ptr) : TaggedImpl(ptr) {} explicit constexpr StrongTaggedValue(Tagged_t ptr) : TaggedImpl(ptr) {}
inline static Object ToObject(WITH_ROOT_PARAM(StrongTaggedValue object)); inline static Object ToObject(Isolate* isolate, StrongTaggedValue object);
}; };
// Almost same as MaybeObject but this one deals with in-heap and potentially // Almost same as MaybeObject but this one deals with in-heap and potentially
@ -33,7 +33,7 @@ class TaggedValue : public TaggedImpl<HeapObjectReferenceType::WEAK, Tagged_t> {
constexpr TaggedValue() : TaggedImpl() {} constexpr TaggedValue() : TaggedImpl() {}
explicit constexpr TaggedValue(Tagged_t ptr) : TaggedImpl(ptr) {} explicit constexpr TaggedValue(Tagged_t ptr) : TaggedImpl(ptr) {}
inline static MaybeObject ToMaybeObject(WITH_ROOT_PARAM(TaggedValue object)); inline static MaybeObject ToMaybeObject(Isolate* isolate, TaggedValue object);
}; };
} // namespace internal } // namespace internal