Commit 8cfec358 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[cleanup] Fix kPointerSize usages in src/objects/bigint.*

Bug: v8:8477, v8:8238
Change-Id: Ice11af2becb3b88a884c9231ed9610210efcc4d6
Reviewed-on: https://chromium-review.googlesource.com/c/1352292Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57916}
parent ef8323ea
...@@ -2311,7 +2311,9 @@ Handle<FreshlyAllocatedBigInt> Factory::NewBigInt(int length, ...@@ -2311,7 +2311,9 @@ Handle<FreshlyAllocatedBigInt> Factory::NewBigInt(int length,
} }
HeapObject* result = AllocateRawWithImmortalMap(BigInt::SizeFor(length), HeapObject* result = AllocateRawWithImmortalMap(BigInt::SizeFor(length),
pretenure, *bigint_map()); pretenure, *bigint_map());
return handle(FreshlyAllocatedBigInt::cast(result), isolate()); FreshlyAllocatedBigInt* bigint = FreshlyAllocatedBigInt::cast(result);
bigint->clear_padding();
return handle(bigint, isolate());
} }
Handle<Object> Factory::NewError(Handle<JSFunction> constructor, Handle<Object> Factory::NewError(Handle<JSFunction> constructor,
......
...@@ -24,19 +24,21 @@ class ValueSerializer; ...@@ -24,19 +24,21 @@ class ValueSerializer;
class BigIntBase : public HeapObject { class BigIntBase : public HeapObject {
public: public:
inline int length() const { inline int length() const {
intptr_t bitfield = RELAXED_READ_INTPTR_FIELD(this, kBitfieldOffset); int32_t bitfield = RELAXED_READ_INT32_FIELD(this, kBitfieldOffset);
return LengthBits::decode(static_cast<uint32_t>(bitfield)); return LengthBits::decode(static_cast<uint32_t>(bitfield));
} }
// For use by the GC. // For use by the GC.
inline int synchronized_length() const { inline int synchronized_length() const {
intptr_t bitfield = ACQUIRE_READ_INTPTR_FIELD(this, kBitfieldOffset); int32_t bitfield = ACQUIRE_READ_INT32_FIELD(this, kBitfieldOffset);
return LengthBits::decode(static_cast<uint32_t>(bitfield)); return LengthBits::decode(static_cast<uint32_t>(bitfield));
} }
// Increasing kMaxLength will require code changes. // Increasing kMaxLength will require code changes.
static const int kMaxLengthBits = kMaxInt - kPointerSize * kBitsPerByte - 1; static const int kMaxLengthBits =
static const int kMaxLength = kMaxLengthBits / (kPointerSize * kBitsPerByte); kMaxInt - kSystemPointerSize * kBitsPerByte - 1;
static const int kMaxLength =
kMaxLengthBits / (kSystemPointerSize * kBitsPerByte);
// Sign and length are stored in the same bitfield. Since the GC needs to be // Sign and length are stored in the same bitfield. Since the GC needs to be
// able to read the length concurrently, the getters and setters are atomic. // able to read the length concurrently, the getters and setters are atomic.
...@@ -46,9 +48,16 @@ class BigIntBase : public HeapObject { ...@@ -46,9 +48,16 @@ class BigIntBase : public HeapObject {
class LengthBits : public BitField<int, SignBits::kNext, kLengthFieldBits> {}; class LengthBits : public BitField<int, SignBits::kNext, kLengthFieldBits> {};
STATIC_ASSERT(LengthBits::kNext <= 32); STATIC_ASSERT(LengthBits::kNext <= 32);
static const int kBitfieldOffset = HeapObject::kHeaderSize; // Layout description.
static const int kDigitsOffset = kBitfieldOffset + kPointerSize; #define BIGINT_FIELDS(V) \
static const int kHeaderSize = kDigitsOffset; V(kBitfieldOffset, kInt32Size) \
V(kOptionalPaddingOffset, POINTER_SIZE_PADDING(kOptionalPaddingOffset)) \
/* Header size. */ \
V(kHeaderSize, 0) \
V(kDigitsOffset, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, BIGINT_FIELDS)
#undef BIGINT_FIELDS
private: private:
friend class ::v8::internal::BigInt; // MSVC wants full namespace. friend class ::v8::internal::BigInt; // MSVC wants full namespace.
...@@ -57,7 +66,7 @@ class BigIntBase : public HeapObject { ...@@ -57,7 +66,7 @@ class BigIntBase : public HeapObject {
typedef uintptr_t digit_t; typedef uintptr_t digit_t;
static const int kDigitSize = sizeof(digit_t); static const int kDigitSize = sizeof(digit_t);
// kMaxLength definition assumes this: // kMaxLength definition assumes this:
STATIC_ASSERT(kDigitSize == kPointerSize); STATIC_ASSERT(kDigitSize == kSystemPointerSize);
static const int kDigitBits = kDigitSize * kBitsPerByte; static const int kDigitBits = kDigitSize * kBitsPerByte;
static const int kHalfDigitBits = kDigitBits / 2; static const int kHalfDigitBits = kDigitBits / 2;
...@@ -95,6 +104,15 @@ class FreshlyAllocatedBigInt : public BigIntBase { ...@@ -95,6 +104,15 @@ class FreshlyAllocatedBigInt : public BigIntBase {
public: public:
inline static FreshlyAllocatedBigInt* cast(Object* object); inline static FreshlyAllocatedBigInt* cast(Object* object);
// Clear uninitialized padding space.
inline void clear_padding() {
if (FIELD_SIZE(kOptionalPaddingOffset)) {
DCHECK_EQ(4, FIELD_SIZE(kOptionalPaddingOffset));
memset(reinterpret_cast<void*>(address() + kOptionalPaddingOffset), 0,
FIELD_SIZE(kOptionalPaddingOffset));
}
}
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(FreshlyAllocatedBigInt); DISALLOW_IMPLICIT_CONSTRUCTORS(FreshlyAllocatedBigInt);
}; };
......
...@@ -381,6 +381,10 @@ ...@@ -381,6 +381,10 @@
static_cast<intptr_t>(base::Acquire_Load( \ static_cast<intptr_t>(base::Acquire_Load( \
reinterpret_cast<const base::AtomicWord*>(FIELD_ADDR(p, offset)))) reinterpret_cast<const base::AtomicWord*>(FIELD_ADDR(p, offset))))
#define ACQUIRE_READ_INT32_FIELD(p, offset) \
static_cast<int32_t>(base::Acquire_Load( \
reinterpret_cast<const base::Atomic32*>(FIELD_ADDR(p, offset))))
#define RELAXED_READ_INTPTR_FIELD(p, offset) \ #define RELAXED_READ_INTPTR_FIELD(p, offset) \
static_cast<intptr_t>(base::Relaxed_Load( \ static_cast<intptr_t>(base::Relaxed_Load( \
reinterpret_cast<const base::AtomicWord*>(FIELD_ADDR(p, offset)))) reinterpret_cast<const base::AtomicWord*>(FIELD_ADDR(p, offset))))
......
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