Skip to content

Commit

Permalink
deps: V8: cherry-pick 392316d
Browse files Browse the repository at this point in the history
Original commit message:

    [ptr-compr][x64] Define kTaggedSize as kInt32Size

    ... when pointer compression is enabled and some number of cleanups.

    Bug: v8:7703
    Change-Id: If7344abf68a1c4d54e4a79d066dc185f25055d7d
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1477737
    Commit-Queue: Igor Sheludko <ishell@chromium.org>
    Auto-Submit: Igor Sheludko <ishell@chromium.org>
    Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
    Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60056}

Refs: v8/v8@392316d

PR-URL: #26685
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
addaleax authored and refack committed Mar 28, 2019
1 parent 53ea813 commit 09f134f
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 224 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.1',
'v8_embedder_string': '-node.2',

##### V8 defaults for Node.js #####

Expand Down
46 changes: 13 additions & 33 deletions deps/v8/include/v8-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ static const Address kNullAddress = 0;
* Configuration of tagging scheme.
*/
const int kApiSystemPointerSize = sizeof(void*);
const int kApiTaggedSize = kApiSystemPointerSize;
const int kApiDoubleSize = sizeof(double);
const int kApiInt32Size = sizeof(int32_t);
const int kApiInt64Size = sizeof(int64_t);
Expand Down Expand Up @@ -92,6 +91,9 @@ struct SmiTagging<8> {
static_assert(
kApiSystemPointerSize == kApiInt64Size,
"Pointer compression can be enabled only for 64-bit architectures");
const int kApiTaggedSize = kApiInt32Size;
#else
const int kApiTaggedSize = kApiSystemPointerSize;
#endif

#ifdef V8_31BIT_SMIS_ON_64BIT_ARCH
Expand Down Expand Up @@ -131,11 +133,7 @@ class Internals {
static const int kJSObjectHeaderSize = 3 * kApiTaggedSize;
static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize;
static const int kEmbedderDataArrayHeaderSize = 2 * kApiTaggedSize;
static const int kEmbedderDataSlotSize =
#ifdef V8_COMPRESS_POINTERS
2 *
#endif
kApiSystemPointerSize;
static const int kEmbedderDataSlotSize = kApiSystemPointerSize;
static const int kNativeContextEmbedderDataOffset = 7 * kApiTaggedSize;
static const int kFullStringRepresentationMask = 0x0f;
static const int kStringEncodingMask = 0x8;
Expand Down Expand Up @@ -301,22 +299,8 @@ class Internals {
#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
// See v8:7703 or src/ptr-compr.* for details about pointer compression.
static constexpr size_t kPtrComprHeapReservationSize = size_t{1} << 32;
static constexpr size_t kPtrComprIsolateRootBias =
kPtrComprHeapReservationSize / 2;
Expand All @@ -328,18 +312,14 @@ class Internals {
-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::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
int value_offset =
I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
return I::ReadRawField<T>(embedder_data, value_offset);
V8_INLINE static internal::Address DecompressTaggedAnyField(
internal::Address heap_object_ptr, int32_t value) {
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));
}
#endif // V8_COMPRESS_POINTERS
};
Expand Down
38 changes: 30 additions & 8 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -10322,7 +10322,7 @@ AccessorSignature* AccessorSignature::Cast(Data* data) {
}

Local<Value> Object::GetInternalField(int index) {
#if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS)
#ifndef V8_ENABLE_CHECKS
typedef internal::Address A;
typedef internal::Internals I;
A obj = *reinterpret_cast<A*>(this);
Expand All @@ -10333,7 +10333,12 @@ Local<Value> Object::GetInternalField(int index) {
instance_type == I::kJSApiObjectType ||
instance_type == I::kJSSpecialApiObjectType) {
int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index);
A value = I::ReadTaggedAnyField(obj, offset);
A value = I::ReadRawField<A>(obj, offset);
#ifdef V8_COMPRESS_POINTERS
// We read the full pointer value and then decompress it in order to avoid
// dealing with potential endiannes issues.
value = I::DecompressTaggedAnyField(obj, static_cast<int32_t>(value));
#endif
internal::Isolate* isolate =
internal::IsolateFromNeverReadOnlySpaceObject(obj);
A* result = HandleScope::CreateHandle(isolate, value);
Expand All @@ -10345,7 +10350,7 @@ Local<Value> Object::GetInternalField(int index) {


void* Object::GetAlignedPointerFromInternalField(int index) {
#if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS)
#ifndef V8_ENABLE_CHECKS
typedef internal::Address A;
typedef internal::Internals I;
A obj = *reinterpret_cast<A*>(this);
Expand Down Expand Up @@ -10956,13 +10961,24 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
}

Local<Value> Context::GetEmbedderData(int index) {
#if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS)
#ifndef V8_ENABLE_CHECKS
typedef internal::Address A;
typedef internal::Internals I;
A ctx = *reinterpret_cast<const A*>(this);
A embedder_data =
I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
int value_offset =
I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
A value = I::ReadRawField<A>(embedder_data, value_offset);
#ifdef V8_COMPRESS_POINTERS
// We read the full pointer value and then decompress it in order to avoid
// dealing with potential endiannes issues.
value =
I::DecompressTaggedAnyField(embedder_data, static_cast<int32_t>(value));
#endif
internal::Isolate* isolate = internal::IsolateFromNeverReadOnlySpaceObject(
*reinterpret_cast<A*>(this));
A* result =
HandleScope::CreateHandle(isolate, I::ReadEmbedderData<A>(this, index));
A* result = HandleScope::CreateHandle(isolate, value);
return Local<Value>(reinterpret_cast<Value*>(result));
#else
return SlowGetEmbedderData(index);
Expand All @@ -10971,9 +10987,15 @@ Local<Value> Context::GetEmbedderData(int index) {


void* Context::GetAlignedPointerFromEmbedderData(int index) {
#if !defined(V8_ENABLE_CHECKS) && !defined(V8_COMPRESS_POINTERS)
#ifndef V8_ENABLE_CHECKS
typedef internal::Address A;
typedef internal::Internals I;
return I::ReadEmbedderData<void*>(this, index);
A ctx = *reinterpret_cast<const A*>(this);
A embedder_data =
I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
int value_offset =
I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
return I::ReadRawField<void*>(embedder_data, value_offset);
#else
return SlowGetAlignedPointerFromEmbedderData(index);
#endif
Expand Down
46 changes: 32 additions & 14 deletions deps/v8/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,28 +200,47 @@ constexpr size_t kReservedCodeRangePages = 0;

STATIC_ASSERT(kSystemPointerSize == (1 << kSystemPointerSizeLog2));

#ifdef V8_COMPRESS_POINTERS
static_assert(
kSystemPointerSize == kInt64Size,
"Pointer compression can be enabled only for 64-bit architectures");

constexpr int kTaggedSize = kInt32Size;
constexpr int kTaggedSizeLog2 = 2;

// These types define raw and atomic storage types for tagged values stored
// on V8 heap.
using Tagged_t = int32_t;
using AtomicTagged_t = base::Atomic32;

#else

constexpr int kTaggedSize = kSystemPointerSize;
constexpr int kTaggedSizeLog2 = kSystemPointerSizeLog2;
STATIC_ASSERT(kTaggedSize == (1 << kTaggedSizeLog2));

// These types define raw and atomic storage types for tagged values stored
// on V8 heap.
using Tagged_t = Address;
using AtomicTagged_t = base::AtomicWord;

#endif // V8_COMPRESS_POINTERS

STATIC_ASSERT(kTaggedSize == (1 << kTaggedSizeLog2));

using AsAtomicTagged = base::AsAtomicPointerImpl<AtomicTagged_t>;
STATIC_ASSERT(sizeof(Tagged_t) == kTaggedSize);
STATIC_ASSERT(sizeof(AtomicTagged_t) == kTaggedSize);

STATIC_ASSERT(kTaggedSize == kApiTaggedSize);

// TODO(ishell): use kTaggedSize or kSystemPointerSize instead.
#ifndef V8_COMPRESS_POINTERS
constexpr int kPointerSize = kSystemPointerSize;
constexpr int kPointerSizeLog2 = kSystemPointerSizeLog2;
STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));

constexpr int kEmbedderDataSlotSize =
#ifdef V8_COMPRESS_POINTERS
kTaggedSize +
#endif
kTaggedSize;

constexpr int kEmbedderDataSlotSize = kSystemPointerSize;

constexpr int kEmbedderDataSlotSizeInTaggedSlots =
kEmbedderDataSlotSize / kTaggedSize;
Expand Down Expand Up @@ -870,33 +889,32 @@ constexpr int kIeeeDoubleExponentWordOffset = 0;
::i::kHeapObjectTag))

// OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
#define OBJECT_POINTER_ALIGN(value) \
(((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
#define OBJECT_POINTER_ALIGN(value) \
(((value) + ::i::kObjectAlignmentMask) & ~::i::kObjectAlignmentMask)

// OBJECT_POINTER_PADDING returns the padding size required to align value
// as a HeapObject pointer
#define OBJECT_POINTER_PADDING(value) (OBJECT_POINTER_ALIGN(value) - (value))

// POINTER_SIZE_ALIGN returns the value aligned as a system pointer.
#define POINTER_SIZE_ALIGN(value) \
(((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
#define POINTER_SIZE_ALIGN(value) \
(((value) + ::i::kPointerAlignmentMask) & ~::i::kPointerAlignmentMask)

// POINTER_SIZE_PADDING returns the padding size required to align value
// as a system pointer.
#define POINTER_SIZE_PADDING(value) (POINTER_SIZE_ALIGN(value) - (value))

// CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
#define CODE_POINTER_ALIGN(value) \
(((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
#define CODE_POINTER_ALIGN(value) \
(((value) + ::i::kCodeAlignmentMask) & ~::i::kCodeAlignmentMask)

// CODE_POINTER_PADDING returns the padding size required to align value
// as a generated code segment.
#define CODE_POINTER_PADDING(value) (CODE_POINTER_ALIGN(value) - (value))

// DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
#define DOUBLE_POINTER_ALIGN(value) \
(((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)

(((value) + ::i::kDoubleAlignmentMask) & ~::i::kDoubleAlignmentMask)

// Defines hints about receiver values based on structural knowledge.
enum class ConvertReceiverMode : unsigned {
Expand Down
26 changes: 26 additions & 0 deletions deps/v8/src/memcopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ inline void CopyBytes(T* dst, const T* src, size_t num_bytes) {
CopyImpl<kMinComplexMemCopy>(dst, src, num_bytes);
}

inline void MemsetInt32(int32_t* dest, int32_t value, size_t counter) {
#if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64
#define STOS "stosl"
#endif

#if defined(MEMORY_SANITIZER)
// MemorySanitizer does not understand inline assembly.
#undef STOS
#endif

#if defined(__GNUC__) && defined(STOS)
asm volatile(
"cld;"
"rep ; " STOS
: "+&c"(counter), "+&D"(dest)
: "a"(value)
: "memory", "cc");
#else
for (size_t i = 0; i < counter; i++) {
dest[i] = value;
}
#endif

#undef STOS
}

inline void MemsetPointer(Address* dest, Address value, size_t counter) {
#if V8_HOST_ARCH_IA32
#define STOS "stosl"
Expand Down
21 changes: 3 additions & 18 deletions deps/v8/src/objects-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,33 +614,18 @@ HeapObject MapWord::ToForwardingAddress() {
#ifdef VERIFY_HEAP
void HeapObject::VerifyObjectField(Isolate* isolate, int offset) {
VerifyPointer(isolate, READ_FIELD(*this, offset));
#ifdef V8_COMPRESS_POINTERS
STATIC_ASSERT(kTaggedSize == kSystemPointerSize);
// Ensure upper 32-bits are zeros.
Address value = *(FullObjectSlot(FIELD_ADDR(*this, offset)).location());
CHECK_EQ(kNullAddress, RoundDown<kPtrComprIsolateRootAlignment>(value));
#endif
STATIC_ASSERT(!COMPRESS_POINTERS_BOOL || kTaggedSize == kInt32Size);
}

void HeapObject::VerifyMaybeObjectField(Isolate* isolate, int offset) {
MaybeObject::VerifyMaybeObjectPointer(isolate,
READ_WEAK_FIELD(*this, offset));
#ifdef V8_COMPRESS_POINTERS
STATIC_ASSERT(kTaggedSize == kSystemPointerSize);
// Ensure upper 32-bits are zeros.
Address value = *(FullObjectSlot(FIELD_ADDR(*this, offset)).location());
CHECK_EQ(kNullAddress, RoundDown<kPtrComprIsolateRootAlignment>(value));
#endif
STATIC_ASSERT(!COMPRESS_POINTERS_BOOL || kTaggedSize == kInt32Size);
}

void HeapObject::VerifySmiField(int offset) {
CHECK(READ_FIELD(*this, offset)->IsSmi());
#ifdef V8_COMPRESS_POINTERS
STATIC_ASSERT(kTaggedSize == kSystemPointerSize);
// Ensure upper 32-bits are zeros.
Address value = *(FullObjectSlot(FIELD_ADDR(*this, offset)).location());
CHECK_EQ(kNullAddress, RoundDown<kPtrComprIsolateRootAlignment>(value));
#endif
STATIC_ASSERT(!COMPRESS_POINTERS_BOOL || kTaggedSize == kInt32Size);
}

#endif
Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/objects/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@ class Code : public HeapObject {
// This documents the amount of free space we have in each Code object header
// due to padding for code alignment.
#if V8_TARGET_ARCH_ARM64
static constexpr int kHeaderPaddingSize = 0;
static constexpr int kHeaderPaddingSize = COMPRESS_POINTERS_BOOL ? 20 : 0;
#elif V8_TARGET_ARCH_MIPS64
static constexpr int kHeaderPaddingSize = 0;
#elif V8_TARGET_ARCH_X64
static constexpr int kHeaderPaddingSize = 0;
static constexpr int kHeaderPaddingSize = COMPRESS_POINTERS_BOOL ? 20 : 0;
#elif V8_TARGET_ARCH_ARM
static constexpr int kHeaderPaddingSize = 20;
#elif V8_TARGET_ARCH_IA32
Expand Down
Loading

0 comments on commit 09f134f

Please sign in to comment.