Commit 90698aee authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[ptr-compr] Support decompression in include/v8.h and include/v8-internal.h

Bug: v8:7703
Change-Id: I2cc5ceb7b70a9b53d5bcc90b32276c011f89ffbe
Reviewed-on: https://chromium-review.googlesource.com/c/1388530
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58476}
parent 030550f4
......@@ -209,12 +209,12 @@ class Internals {
V8_INLINE static int GetInstanceType(const internal::Address obj) {
typedef internal::Address A;
A map = ReadField<A>(obj, kHeapObjectMapOffset);
return ReadField<uint16_t>(map, kMapInstanceTypeOffset);
A map = ReadTaggedPointerField(obj, kHeapObjectMapOffset);
return ReadRawField<uint16_t>(map, kMapInstanceTypeOffset);
}
V8_INLINE static int GetOddballKind(const internal::Address obj) {
return SmiValue(ReadField<internal::Address>(obj, kOddballKindOffset));
return SmiValue(ReadTaggedSignedField(obj, kOddballKindOffset));
}
V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
......@@ -268,24 +268,74 @@ class Internals {
}
template <typename T>
V8_INLINE static T ReadField(const internal::Address heap_object_ptr,
int offset) {
V8_INLINE static T ReadRawField(internal::Address heap_object_ptr,
int offset) {
internal::Address addr = heap_object_ptr + offset - kHeapObjectTag;
return *reinterpret_cast<const T*>(addr);
}
#ifndef V8_COMPRESS_POINTERS
V8_INLINE static internal::Address ReadTaggedPointerField(
internal::Address heap_object_ptr, int offset) {
#ifdef V8_COMPRESS_POINTERS
int32_t value = ReadRawField<int32_t>(heap_object_ptr, offset);
internal::Address root = GetRootFromOnHeapAddress(heap_object_ptr);
return root + static_cast<internal::Address>(static_cast<intptr_t>(value));
#else
return ReadRawField<internal::Address>(heap_object_ptr, offset);
#endif
}
V8_INLINE static internal::Address ReadTaggedSignedField(
internal::Address heap_object_ptr, int offset) {
#ifdef V8_COMPRESS_POINTERS
int32_t value = ReadRawField<int32_t>(heap_object_ptr, offset);
return static_cast<internal::Address>(static_cast<intptr_t>(value));
#else
return ReadRawField<internal::Address>(heap_object_ptr, offset);
#endif
}
V8_INLINE static internal::Address ReadTaggedAnyField(
internal::Address heap_object_ptr, int offset) {
#ifdef V8_COMPRESS_POINTERS
int32_t value = ReadRawField<int32_t>(heap_object_ptr, offset);
internal::Address root_mask = static_cast<internal::Address>(
-static_cast<intptr_t>(value & kSmiTagMask));
internal::Address root_or_zero =
root_mask & GetRootFromOnHeapAddress(heap_object_ptr);
return root_or_zero +
static_cast<internal::Address>(static_cast<intptr_t>(value));
#else
return ReadRawField<internal::Address>(heap_object_ptr, offset);
#endif
}
#ifdef V8_COMPRESS_POINTERS
static constexpr size_t kPtrComprHeapReservationSize = size_t{1} << 32;
static constexpr size_t kPtrComprIsolateRootBias =
kPtrComprHeapReservationSize / 2;
static constexpr size_t kPtrComprIsolateRootAlignment = size_t{1} << 32;
V8_INLINE static internal::Address GetRootFromOnHeapAddress(
internal::Address addr) {
return (addr + kPtrComprIsolateRootBias) &
-static_cast<intptr_t>(kPtrComprIsolateRootAlignment);
}
#else
template <typename T>
V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
typedef internal::Address A;
typedef internal::Internals I;
A ctx = *reinterpret_cast<const A*>(context);
A embedder_data = I::ReadField<A>(ctx, I::kNativeContextEmbedderDataOffset);
A embedder_data =
I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
int value_offset =
I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
return I::ReadField<T>(embedder_data, value_offset);
return I::ReadRawField<T>(embedder_data, value_offset);
}
#endif
#endif // V8_COMPRESS_POINTERS
};
// Only perform cast check for types derived from v8::Data since
......
......@@ -695,7 +695,7 @@ template <class T, class M> class Persistent : public PersistentBase<T> {
V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
Copy(that);
}
V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
V8_INLINE Persistent& operator=(const Persistent& that) {
Copy(that);
return *this;
}
......@@ -779,7 +779,7 @@ class Global : public PersistentBase<T> {
/**
* Move constructor.
*/
V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) {
other.val_ = nullptr;
}
V8_INLINE ~Global() { this->Reset(); }
......@@ -9934,7 +9934,7 @@ Local<Value> Object::GetInternalField(int index) {
instance_type == I::kJSSpecialApiObjectType) {
int offset = I::kJSObjectHeaderSizeForEmbedderFields +
(I::kEmbedderDataSlotSize * index);
A value = I::ReadField<A>(obj, offset);
A value = I::ReadTaggedAnyField(obj, offset);
A* result = HandleScope::CreateHandle(
reinterpret_cast<internal::NeverReadOnlySpaceObject*>(obj), value);
return Local<Value>(reinterpret_cast<Value*>(result));
......@@ -9957,7 +9957,7 @@ void* Object::GetAlignedPointerFromInternalField(int index) {
instance_type == I::kJSSpecialApiObjectType)) {
int offset = I::kJSObjectHeaderSizeForEmbedderFields +
(I::kEmbedderDataSlotSize * index);
return I::ReadField<void*>(obj, offset);
return I::ReadRawField<void*>(obj, offset);
}
#endif
return SlowGetAlignedPointerFromInternalField(index);
......@@ -9987,7 +9987,7 @@ String::ExternalStringResource* String::GetExternalStringResource() const {
ExternalStringResource* result;
if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
void* value = I::ReadRawField<void*>(obj, I::kStringResourceOffset);
result = reinterpret_cast<String::ExternalStringResource*>(value);
} else {
result = GetExternalStringResourceSlow();
......@@ -10009,7 +10009,7 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
ExternalStringResourceBase* resource;
if (type == I::kExternalOneByteRepresentationTag ||
type == I::kExternalTwoByteRepresentationTag) {
void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
void* value = I::ReadRawField<void*>(obj, I::kStringResourceOffset);
resource = static_cast<ExternalStringResourceBase*>(value);
} else {
resource = GetExternalStringResourceBaseSlow(encoding_out);
......
......@@ -5560,7 +5560,7 @@ String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
}
if (i::StringShape(str).IsExternalTwoByte()) {
void* value = I::ReadField<void*>(str.ptr(), I::kStringResourceOffset);
void* value = I::ReadRawField<void*>(str.ptr(), I::kStringResourceOffset);
return reinterpret_cast<String::ExternalStringResource*>(value);
}
return nullptr;
......@@ -5582,7 +5582,7 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
*encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
if (i::StringShape(str).IsExternalOneByte() ||
i::StringShape(str).IsExternalTwoByte()) {
void* value = I::ReadField<void*>(string, I::kStringResourceOffset);
void* value = I::ReadRawField<void*>(string, I::kStringResourceOffset);
resource = static_cast<ExternalStringResourceBase*>(value);
}
return resource;
......@@ -5613,9 +5613,15 @@ Local<Value> Symbol::Name() const {
// objects are immovable we can use the Handle(Address*) constructor with
// the address of the name field in the Symbol object without needing an
// isolate.
#ifdef V8_COMPRESS_POINTERS
// Compressed fields can't serve as handle locations.
// TODO(ishell): get Isolate as a parameter.
isolate = i::Isolate::Current();
#else
i::Handle<i::HeapObject> ro_name(reinterpret_cast<i::Address*>(
sym->GetFieldAddress(i::Symbol::kNameOffset)));
return Utils::ToLocal(ro_name);
#endif
}
i::Handle<i::Object> name(sym->name(), isolate);
......
......@@ -33,9 +33,9 @@ V8_INLINE RootIndex operator++(RootIndex& index) {
bool RootsTable::IsRootHandleLocation(Address* handle_location,
RootIndex* index) const {
ObjectSlot location(handle_location);
ObjectSlot first_root(&roots_[0]);
ObjectSlot last_root(&roots_[kEntriesCount]);
FullObjectSlot location(handle_location);
FullObjectSlot first_root(&roots_[0]);
FullObjectSlot last_root(&roots_[kEntriesCount]);
if (location >= last_root) return false;
if (location < first_root) return false;
*index = static_cast<RootIndex>(location - first_root);
......
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