Revert "[ptr-compr] Improve ptr compression/decompresion in C++"

This reverts commit 77de44e1c4.

Reason for revert: Seems fuchsia doesn't like this improvement: https://ci.chromium.org/ui/p/chromium/builders/try/fuchsia-arm64-rel/68601/overview

Original change's description:
> [ptr-compr] Improve ptr compression/decompresion in C++
>
> Optimizations introduced in
> https://chromium-review.googlesource.com/c/v8/v8/+/1776079
> are currently defeated since Address is not a pointer type.
> Clang does not seem to carry over alignment information as range
> information when casting to ints.
>
> Using __builtin_assume we can restore the same effect. Additionally
> we can help the compiler remember that when compressing the removed
> bits are actually the cage base. This helps e.g. with
>  `decompress(compress(..))`.
>
> See https://godbolt.org/z/5r68G5qa6 for details.
>
> Bug: v8:9353
> Change-Id: Ief016fce0788f2bef6b684a18b104ada6e6d3856
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4156060
> Commit-Queue: Olivier Flückiger <olivf@chromium.org>
> Reviewed-by: Toon Verwaest <verwaest@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#85246}

Bug: v8:9353
Change-Id: I1fd6f36667302490f12d19c1fc8f64ca181c006b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4162933
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#85266}
This commit is contained in:
Leszek Swirski 2023-01-12 17:25:16 +00:00 committed by V8 LUCI CQ
parent 6491416033
commit 16a31ada22
6 changed files with 10 additions and 35 deletions

View File

@ -46,11 +46,8 @@ void V8HeapCompressionScheme::InitBase(Address base) {
base_ = base;
}
constexpr Address kPtrComprCageBaseMask = ~(kPtrComprCageBaseAlignment - 1);
// static
V8_CONST Address V8HeapCompressionScheme::base() {
V8_ASSUME((base_ & kPtrComprCageBaseMask) == base_);
return reinterpret_cast<Address>(V8_ASSUME_ALIGNED(
reinterpret_cast<void*>(base_), kPtrComprCageBaseAlignment));
}
@ -58,12 +55,6 @@ V8_CONST Address V8HeapCompressionScheme::base() {
// static
Tagged_t V8HeapCompressionScheme::CompressTagged(Address tagged) {
V8_ASSUME(HAS_SMI_TAG(tagged) || (tagged & kPtrComprCageBaseMask) == base_);
return static_cast<Tagged_t>(static_cast<uint32_t>(tagged));
}
// static
Tagged_t V8HeapCompressionScheme::CompressAny(Address tagged) {
return static_cast<Tagged_t>(static_cast<uint32_t>(tagged));
}
@ -141,7 +132,6 @@ void ExternalCodeCompressionScheme::InitBase(Address base) {
// static
V8_CONST Address ExternalCodeCompressionScheme::base() {
V8_ASSUME((base_ & kPtrComprCageBaseMask) == base_);
return reinterpret_cast<Address>(V8_ASSUME_ALIGNED(
reinterpret_cast<void*>(base_), kPtrComprCageBaseAlignment));
}
@ -149,12 +139,6 @@ V8_CONST Address ExternalCodeCompressionScheme::base() {
// static
Tagged_t ExternalCodeCompressionScheme::CompressTagged(Address tagged) {
V8_ASSUME(HAS_SMI_TAG(tagged) || (tagged & kPtrComprCageBaseMask) == base_);
return static_cast<Tagged_t>(static_cast<uint32_t>(tagged));
}
// static
Tagged_t ExternalCodeCompressionScheme::CompressAny(Address tagged) {
return static_cast<Tagged_t>(static_cast<uint32_t>(tagged));
}
@ -214,9 +198,6 @@ Tagged_t V8HeapCompressionScheme::CompressTagged(Address tagged) {
UNREACHABLE();
}
// static
Tagged_t V8HeapCompressionScheme::CompressAny(Address tagged) { UNREACHABLE(); }
// static
Address V8HeapCompressionScheme::DecompressTaggedSigned(Tagged_t raw_value) {
UNREACHABLE();

View File

@ -25,8 +25,6 @@ class V8HeapCompressionScheme {
// Compresses full-pointer representation of a tagged value to on-heap
// representation.
V8_INLINE static Tagged_t CompressTagged(Address tagged);
// Compress a potentially invalid pointer.
V8_INLINE static Tagged_t CompressAny(Address tagged);
// Decompresses smi value.
V8_INLINE static Address DecompressTaggedSigned(Tagged_t raw_value);
@ -80,8 +78,6 @@ class ExternalCodeCompressionScheme {
// Compresses full-pointer representation of a tagged value to on-heap
// representation.
V8_INLINE static Tagged_t CompressTagged(Address tagged);
// Compress a potentially invalid pointer.
V8_INLINE static Tagged_t CompressAny(Address tagged);
// Decompresses smi value.
V8_INLINE static Address DecompressTaggedSigned(Tagged_t raw_value);

View File

@ -110,7 +110,7 @@ MaybeObject CompressedMaybeObjectSlot::load(PtrComprCageBase cage_base) const {
}
void CompressedMaybeObjectSlot::store(MaybeObject value) const {
*location() = TCompressionScheme::CompressAny(value.ptr());
*location() = TCompressionScheme::CompressTagged(value.ptr());
}
MaybeObject CompressedMaybeObjectSlot::Relaxed_Load() const {
@ -125,14 +125,14 @@ MaybeObject CompressedMaybeObjectSlot::Relaxed_Load(
}
void CompressedMaybeObjectSlot::Relaxed_Store(MaybeObject value) const {
Tagged_t ptr = TCompressionScheme::CompressAny(value.ptr());
Tagged_t ptr = TCompressionScheme::CompressTagged(value.ptr());
AsAtomicTagged::Relaxed_Store(location(), ptr);
}
void CompressedMaybeObjectSlot::Release_CompareAndSwap(
MaybeObject old, MaybeObject target) const {
Tagged_t old_ptr = TCompressionScheme::CompressAny(old.ptr());
Tagged_t target_ptr = TCompressionScheme::CompressAny(target.ptr());
Tagged_t old_ptr = TCompressionScheme::CompressTagged(old.ptr());
Tagged_t target_ptr = TCompressionScheme::CompressTagged(target.ptr());
AsAtomicTagged::Release_CompareAndSwap(location(), old_ptr, target_ptr);
}

View File

@ -265,7 +265,7 @@ inline void CopyTagged(Address dst, const Address src, size_t num_tagged) {
// Sets |counter| number of kTaggedSize-sized values starting at |start| slot.
inline void MemsetTagged(Tagged_t* start, Object value, size_t counter) {
#ifdef V8_COMPRESS_POINTERS
Tagged_t raw_value = V8HeapCompressionScheme::CompressAny(value.ptr());
Tagged_t raw_value = V8HeapCompressionScheme::CompressTagged(value.ptr());
MemsetUint32(start, raw_value, counter);
#else
Address raw_value = value.ptr();

View File

@ -5,9 +5,10 @@
#ifndef V8_OBJECTS_TAGGED_FIELD_INL_H_
#define V8_OBJECTS_TAGGED_FIELD_INL_H_
#include "src/common/ptr-compr-inl.h"
#include "src/objects/tagged-field.h"
#include "src/common/ptr-compr-inl.h"
namespace v8 {
namespace internal {
@ -49,9 +50,6 @@ template <typename T, int kFieldOffset, typename CompressionScheme>
Tagged_t TaggedField<T, kFieldOffset, CompressionScheme>::full_to_tagged(
Address value) {
#ifdef V8_COMPRESS_POINTERS
if (std::is_same<MaybeObject, T>::value) {
return CompressionScheme::CompressAny(value);
}
return CompressionScheme::CompressTagged(value);
#else
return value;

View File

@ -53,9 +53,9 @@ static void SetUpNewSpaceWithPoisonedMementoAtTop() {
Object(new_space->top() + kHeapObjectTag));
memento.set_map_after_allocation(ReadOnlyRoots(heap).allocation_memento_map(),
SKIP_WRITE_BARRIER);
TaggedField<MaybeObject, AllocationMemento::kAllocationSiteOffset>::store(
memento, MaybeObject(kHeapObjectTag));
memento.set_allocation_site(
AllocationSite::unchecked_cast(Object(kHeapObjectTag)),
SKIP_WRITE_BARRIER);
}