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,
}
HeapObject* result = AllocateRawWithImmortalMap(BigInt::SizeFor(length),
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,
......
......@@ -24,19 +24,21 @@ class ValueSerializer;
class BigIntBase : public HeapObject {
public:
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));
}
// For use by the GC.
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));
}
// Increasing kMaxLength will require code changes.
static const int kMaxLengthBits = kMaxInt - kPointerSize * kBitsPerByte - 1;
static const int kMaxLength = kMaxLengthBits / (kPointerSize * kBitsPerByte);
static const int kMaxLengthBits =
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
// able to read the length concurrently, the getters and setters are atomic.
......@@ -46,9 +48,16 @@ class BigIntBase : public HeapObject {
class LengthBits : public BitField<int, SignBits::kNext, kLengthFieldBits> {};
STATIC_ASSERT(LengthBits::kNext <= 32);
static const int kBitfieldOffset = HeapObject::kHeaderSize;
static const int kDigitsOffset = kBitfieldOffset + kPointerSize;
static const int kHeaderSize = kDigitsOffset;
// Layout description.
#define BIGINT_FIELDS(V) \
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:
friend class ::v8::internal::BigInt; // MSVC wants full namespace.
......@@ -57,7 +66,7 @@ class BigIntBase : public HeapObject {
typedef uintptr_t digit_t;
static const int kDigitSize = sizeof(digit_t);
// kMaxLength definition assumes this:
STATIC_ASSERT(kDigitSize == kPointerSize);
STATIC_ASSERT(kDigitSize == kSystemPointerSize);
static const int kDigitBits = kDigitSize * kBitsPerByte;
static const int kHalfDigitBits = kDigitBits / 2;
......@@ -95,6 +104,15 @@ class FreshlyAllocatedBigInt : public BigIntBase {
public:
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:
DISALLOW_IMPLICIT_CONSTRUCTORS(FreshlyAllocatedBigInt);
};
......
......@@ -381,6 +381,10 @@
static_cast<intptr_t>(base::Acquire_Load( \
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) \
static_cast<intptr_t>(base::Relaxed_Load( \
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