Commit 509eb133 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

Make writing fields uniform via a template

Bug: v8:9264
Change-Id: I936d203d38410a6aefff8a54acf49468abb20e39
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1621933
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61707}
parent 344473ca
......@@ -242,8 +242,8 @@ MicrotaskQueue* NativeContext::microtask_queue() const {
}
void NativeContext::set_microtask_queue(MicrotaskQueue* microtask_queue) {
WRITE_INTPTR_FIELD(*this, kMicrotaskQueueOffset,
reinterpret_cast<intptr_t>(microtask_queue));
WriteField<Address>(kMicrotaskQueueOffset,
reinterpret_cast<Address>(microtask_queue));
}
OBJECT_CONSTRUCTORS_IMPL(NativeContext, Context)
......
......@@ -3813,7 +3813,7 @@ void TranslatedState::InitializeJSObjectAt(
CHECK(field_value->IsHeapNumber());
double_field_value = HeapNumber::cast(*field_value)->value();
}
WRITE_DOUBLE_FIELD(*object_storage, offset, double_field_value);
object_storage->WriteField<double>(offset, double_field_value);
} else if (marker == kStoreMutableHeapNumber) {
CHECK(field_value->IsMutableHeapNumber());
WRITE_FIELD(*object_storage, offset, *field_value);
......
......@@ -51,7 +51,7 @@ int32_t FeedbackMetadata::get(int index) const {
void FeedbackMetadata::set(int index, int32_t value) {
DCHECK(index >= 0 && index < length());
int offset = kHeaderSize + index * kInt32Size;
WRITE_INT32_FIELD(*this, offset, value);
WriteField<int32_t>(offset, value);
}
bool FeedbackMetadata::is_empty() const { return slot_count() == 0; }
......
......@@ -642,6 +642,23 @@ class Object : public TaggedImpl<HeapObjectReferenceType::STRONG, Address> {
}
}
template <class T, typename std::enable_if<std::is_arithmetic<T>::value,
int>::type = 0>
inline void WriteField(size_t offset, T value) const {
// Pointer compression causes types larger than kTaggedSize to be unaligned.
#ifdef V8_COMPRESS_POINTERS
constexpr bool v8_pointer_compression_unaligned = sizeof(T) > kTaggedSize;
#else
constexpr bool v8_pointer_compression_unaligned = false;
#endif
if (std::is_same<T, double>::value || v8_pointer_compression_unaligned) {
// Bug(v8:8875) Double fields may be unaligned.
WriteUnalignedValue<T>(field_address(offset), value);
} else {
Memory<T>(field_address(offset)) = value;
}
}
protected:
inline Address field_address(size_t offset) const {
return ptr() + offset - kHeapObjectTag;
......@@ -738,13 +755,9 @@ class MapWord {
// View this map word as a forwarding address.
inline HeapObject ToForwardingAddress();
static inline MapWord FromRawValue(uintptr_t value) {
return MapWord(value);
}
static inline MapWord FromRawValue(uintptr_t value) { return MapWord(value); }
inline uintptr_t ToRawValue() {
return value_;
}
inline uintptr_t ToRawValue() { return value_; }
private:
// HeapObject calls the private constructor and directly reads the value.
......@@ -773,12 +786,8 @@ enum EnsureElementsMode {
ALLOW_CONVERTED_DOUBLE_ELEMENTS
};
// Indicator for one component of an AccessorPair.
enum AccessorComponent {
ACCESSOR_GETTER,
ACCESSOR_SETTER
};
enum AccessorComponent { ACCESSOR_GETTER, ACCESSOR_SETTER };
enum class GetKeysConversion {
kKeepNumbers = static_cast<int>(v8::KeyConversionMode::kKeepNumbers),
......@@ -799,7 +808,7 @@ class Relocatable {
explicit inline Relocatable(Isolate* isolate);
inline virtual ~Relocatable();
virtual void IterateInstance(RootVisitor* v) {}
virtual void PostGarbageCollection() { }
virtual void PostGarbageCollection() {}
static void PostGarbageCollectionProcessing(Isolate* isolate);
static int ArchiveSpacePerThread();
......@@ -831,7 +840,6 @@ class BooleanBit : public AllStatic {
}
};
} // NOLINT, false-positive due to second-order macros.
} // NOLINT, false-positive due to second-order macros.
......
......@@ -202,11 +202,11 @@ class MutableBigInt : public FreshlyAllocatedBigInt {
}
inline void initialize_bitfield(bool sign, int length) {
int32_t bitfield = LengthBits::encode(length) | SignBits::encode(sign);
WRITE_INT32_FIELD(*this, kBitfieldOffset, bitfield);
WriteField<int32_t>(kBitfieldOffset, bitfield);
}
inline void set_digit(int n, digit_t value) {
SLOW_DCHECK(0 <= n && n < length());
WRITE_UINTPTR_FIELD(*this, kDigitsOffset + n * kDigitSize, value);
WriteField<digit_t>(kDigitsOffset + n * kDigitSize, value);
}
void set_64_bits(uint64_t bits);
......
......@@ -302,7 +302,7 @@ int Code::unwinding_info_size() const {
void Code::set_unwinding_info_size(int value) {
DCHECK(has_unwinding_info());
WRITE_UINT64_FIELD(*this, GetUnwindingInfoSizeOffset(), value);
WriteField<uint64_t>(GetUnwindingInfoSizeOffset(), value);
}
Address Code::unwinding_info_start() const {
......@@ -390,7 +390,7 @@ void Code::initialize_flags(Kind kind, bool has_unwinding_info,
IsTurbofannedField::encode(is_turbofanned) |
StackSlotsField::encode(stack_slots) |
IsOffHeapTrampoline::encode(is_off_heap_trampoline);
WRITE_UINT32_FIELD(*this, kFlagsOffset, flags);
WriteField<uint32_t>(kFlagsOffset, flags);
DCHECK_IMPLIES(stack_slots != 0, has_safepoint_info());
}
......@@ -480,7 +480,7 @@ int Code::builtin_index() const {
void Code::set_builtin_index(int index) {
DCHECK(index == -1 || Builtins::IsBuiltinId(index));
WRITE_INT_FIELD(*this, kBuiltinIndexOffset, index);
WriteField<int>(kBuiltinIndexOffset, index);
}
bool Code::is_builtin() const { return builtin_index() != -1; }
......@@ -547,7 +547,7 @@ int Code::constant_pool_offset() const {
void Code::set_constant_pool_offset(int value) {
if (!FLAG_enable_embedded_constant_pool) return;
DCHECK_LE(value, InstructionSize());
WRITE_INT_FIELD(*this, kConstantPoolOffsetOffset, value);
WriteField<int>(kConstantPoolOffsetOffset, value);
}
Address Code::constant_pool() const {
......@@ -619,13 +619,13 @@ byte BytecodeArray::get(int index) const {
void BytecodeArray::set(int index, byte value) {
DCHECK(index >= 0 && index < this->length());
WRITE_BYTE_FIELD(*this, kHeaderSize + index * kCharSize, value);
WriteField<byte>(kHeaderSize + index * kCharSize, value);
}
void BytecodeArray::set_frame_size(int frame_size) {
DCHECK_GE(frame_size, 0);
DCHECK(IsAligned(frame_size, kSystemPointerSize));
WRITE_INT_FIELD(*this, kFrameSizeOffset, frame_size);
WriteField<int>(kFrameSizeOffset, frame_size);
}
int BytecodeArray::frame_size() const {
......@@ -640,7 +640,7 @@ void BytecodeArray::set_parameter_count(int number_of_parameters) {
DCHECK_GE(number_of_parameters, 0);
// Parameter count is stored as the size on stack of the parameters to allow
// it to be used directly by generated code.
WRITE_INT_FIELD(*this, kParameterSizeOffset,
WriteField<int>(kParameterSizeOffset,
(number_of_parameters << kSystemPointerSizeLog2));
}
......@@ -658,12 +658,12 @@ interpreter::Register BytecodeArray::incoming_new_target_or_generator_register()
void BytecodeArray::set_incoming_new_target_or_generator_register(
interpreter::Register incoming_new_target_or_generator_register) {
if (!incoming_new_target_or_generator_register.is_valid()) {
WRITE_INT_FIELD(*this, kIncomingNewTargetOrGeneratorRegisterOffset, 0);
WriteField<int>(kIncomingNewTargetOrGeneratorRegisterOffset, 0);
} else {
DCHECK(incoming_new_target_or_generator_register.index() <
register_count());
DCHECK_NE(0, incoming_new_target_or_generator_register.ToOperand());
WRITE_INT_FIELD(*this, kIncomingNewTargetOrGeneratorRegisterOffset,
WriteField<int>(kIncomingNewTargetOrGeneratorRegisterOffset,
incoming_new_target_or_generator_register.ToOperand());
}
}
......@@ -675,7 +675,7 @@ int BytecodeArray::osr_loop_nesting_level() const {
void BytecodeArray::set_osr_loop_nesting_level(int depth) {
DCHECK(0 <= depth && depth <= AbstractCode::kMaxLoopNestingMarker);
STATIC_ASSERT(AbstractCode::kMaxLoopNestingMarker < kMaxInt8);
WRITE_INT8_FIELD(*this, kOSRNestingLevelOffset, depth);
WriteField<int8_t>(kOSRNestingLevelOffset, depth);
}
BytecodeArray::Age BytecodeArray::bytecode_age() const {
......
......@@ -377,9 +377,9 @@ void FixedDoubleArray::set(int index, double value) {
map() != GetReadOnlyRoots().fixed_array_map());
int offset = kHeaderSize + index * kDoubleSize;
if (std::isnan(value)) {
WRITE_DOUBLE_FIELD(*this, offset, std::numeric_limits<double>::quiet_NaN());
WriteField<double>(offset, std::numeric_limits<double>::quiet_NaN());
} else {
WRITE_DOUBLE_FIELD(*this, offset, value);
WriteField<double>(offset, value);
}
DCHECK(!is_the_hole(index));
}
......@@ -392,7 +392,7 @@ void FixedDoubleArray::set_the_hole(int index) {
DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() &&
map() != GetReadOnlyRoots().fixed_array_map());
int offset = kHeaderSize + index * kDoubleSize;
WRITE_UINT64_FIELD(*this, offset, kHoleNanInt64);
WriteUnalignedValue<uint64_t>(field_address(offset), kHoleNanInt64);
}
bool FixedDoubleArray::is_the_hole(Isolate* isolate, int index) {
......@@ -538,7 +538,7 @@ byte ByteArray::get(int index) const {
void ByteArray::set(int index, byte value) {
DCHECK(index >= 0 && index < this->length());
WRITE_BYTE_FIELD(*this, kHeaderSize + index * kCharSize, value);
WriteField<byte>(kHeaderSize + index * kCharSize, value);
}
void ByteArray::copy_in(int index, const byte* buffer, int length) {
......@@ -562,7 +562,7 @@ int ByteArray::get_int(int index) const {
void ByteArray::set_int(int index, int value) {
DCHECK(index >= 0 && index < this->length() / kIntSize);
WRITE_INT_FIELD(*this, kHeaderSize + index * kIntSize, value);
WriteField<int>(kHeaderSize + index * kIntSize, value);
}
uint32_t ByteArray::get_uint32(int index) const {
......@@ -572,7 +572,7 @@ uint32_t ByteArray::get_uint32(int index) const {
void ByteArray::set_uint32(int index, uint32_t value) {
DCHECK(index >= 0 && index < this->length() / kUInt32Size);
WRITE_UINT32_FIELD(*this, kHeaderSize + index * kUInt32Size, value);
WriteField<uint32_t>(kHeaderSize + index * kUInt32Size, value);
}
void ByteArray::clear_padding() {
......@@ -623,8 +623,7 @@ void* FixedTypedArrayBase::external_pointer() const {
}
void FixedTypedArrayBase::set_external_pointer(void* value) {
intptr_t ptr = reinterpret_cast<intptr_t>(value);
WRITE_INTPTR_FIELD(*this, kExternalPointerOffset, ptr);
WriteField<Address>(kExternalPointerOffset, reinterpret_cast<Address>(value));
}
void* FixedTypedArrayBase::DataPtr() {
......
......@@ -31,7 +31,7 @@ Address Foreign::foreign_address() {
}
void Foreign::set_foreign_address(Address value) {
WRITE_UINTPTR_FIELD(*this, kForeignAddressOffset, value);
WriteField<Address>(kForeignAddressOffset, value);
}
} // namespace internal
......
......@@ -26,7 +26,7 @@ CAST_ACCESSOR(MutableHeapNumber)
double HeapNumberBase::value() const { return ReadField<double>(kValueOffset); }
void HeapNumberBase::set_value(double value) {
WRITE_DOUBLE_FIELD(*this, kValueOffset, value);
WriteField<double>(kValueOffset, value);
}
uint64_t HeapNumberBase::value_as_bits() const {
......@@ -35,7 +35,7 @@ uint64_t HeapNumberBase::value_as_bits() const {
}
void HeapNumberBase::set_value_as_bits(uint64_t bits) {
WRITE_UINT64_FIELD(*this, kValueOffset, bits);
WriteUnalignedValue<uint64_t>(field_address(kValueOffset), bits);
}
int HeapNumberBase::get_exponent() {
......
......@@ -33,7 +33,7 @@ size_t JSArrayBuffer::byte_length() const {
}
void JSArrayBuffer::set_byte_length(size_t value) {
WRITE_UINTPTR_FIELD(*this, kByteLengthOffset, value);
WriteField<size_t>(kByteLengthOffset, value);
}
void* JSArrayBuffer::backing_store() const {
......@@ -41,8 +41,7 @@ void* JSArrayBuffer::backing_store() const {
}
void JSArrayBuffer::set_backing_store(void* value, WriteBarrierMode mode) {
intptr_t ptr = reinterpret_cast<intptr_t>(value);
WRITE_INTPTR_FIELD(*this, kBackingStoreOffset, ptr);
WriteField<Address>(kBackingStoreOffset, reinterpret_cast<Address>(value));
}
size_t JSArrayBuffer::allocation_length() const {
......@@ -92,7 +91,7 @@ void JSArrayBuffer::clear_padding() {
}
void JSArrayBuffer::set_bit_field(uint32_t bits) {
WRITE_UINT32_FIELD(*this, kBitFieldOffset, bits);
WriteField<uint32_t>(kBitFieldOffset, bits);
}
uint32_t JSArrayBuffer::bit_field() const {
......@@ -114,7 +113,7 @@ size_t JSArrayBufferView::byte_offset() const {
}
void JSArrayBufferView::set_byte_offset(size_t value) {
WRITE_UINTPTR_FIELD(*this, kByteOffsetOffset, value);
WriteField<size_t>(kByteOffsetOffset, value);
}
size_t JSArrayBufferView::byte_length() const {
......@@ -122,7 +121,7 @@ size_t JSArrayBufferView::byte_length() const {
}
void JSArrayBufferView::set_byte_length(size_t value) {
WRITE_UINTPTR_FIELD(*this, kByteLengthOffset, value);
WriteField<size_t>(kByteLengthOffset, value);
}
ACCESSORS(JSArrayBufferView, buffer, Object, kBufferOffset)
......@@ -134,7 +133,7 @@ bool JSArrayBufferView::WasDetached() const {
size_t JSTypedArray::length() const { return ReadField<size_t>(kLengthOffset); }
void JSTypedArray::set_length(size_t value) {
WRITE_UINTPTR_FIELD(*this, kLengthOffset, value);
WriteField<size_t>(kLengthOffset, value);
}
bool JSTypedArray::is_on_heap() const {
......@@ -172,8 +171,7 @@ void* JSDataView::data_pointer() const {
}
void JSDataView::set_data_pointer(void* value) {
intptr_t ptr = reinterpret_cast<intptr_t>(value);
WRITE_INTPTR_FIELD(*this, kDataPointerOffset, ptr);
WriteField<Address>(kDataPointerOffset, reinterpret_cast<Address>(value));
}
} // namespace internal
......
......@@ -295,7 +295,7 @@ InstanceType Map::instance_type() const {
}
void Map::set_instance_type(InstanceType value) {
WRITE_UINT16_FIELD(*this, kInstanceTypeOffset, value);
WriteField<uint16_t>(kInstanceTypeOffset, value);
}
int Map::UnusedPropertyFields() const {
......@@ -420,7 +420,7 @@ void Map::AccountAddedOutOfObjectPropertyField(int unused_in_property_array) {
byte Map::bit_field() const { return ReadField<byte>(kBitFieldOffset); }
void Map::set_bit_field(byte value) {
WRITE_BYTE_FIELD(*this, kBitFieldOffset, value);
WriteField<byte>(kBitFieldOffset, value);
}
byte Map::relaxed_bit_field() const {
......@@ -434,7 +434,7 @@ void Map::set_relaxed_bit_field(byte value) {
byte Map::bit_field2() const { return ReadField<byte>(kBitField2Offset); }
void Map::set_bit_field2(byte value) {
WRITE_BYTE_FIELD(*this, kBitField2Offset, value);
WriteField<byte>(kBitField2Offset, value);
}
bool Map::is_abandoned_prototype_map() const {
......
......@@ -55,7 +55,7 @@ bool Name::IsUniqueName() const {
uint32_t Name::hash_field() { return ReadField<uint32_t>(kHashFieldOffset); }
void Name::set_hash_field(uint32_t value) {
WRITE_UINT32_FIELD(*this, kHashFieldOffset, value);
WriteField<uint32_t>(kHashFieldOffset, value);
}
bool Name::Equals(Name other) {
......
......@@ -61,30 +61,17 @@
#undef CONDITIONAL_WRITE_BARRIER
#undef CONDITIONAL_WEAK_WRITE_BARRIER
#undef CONDITIONAL_EPHEMERON_KEY_WRITE_BARRIER
#undef WRITE_DOUBLE_FIELD
#undef WRITE_INT_FIELD
#undef ACQUIRE_READ_INT32_FIELD
#undef WRITE_UINT8_FIELD
#undef RELAXED_WRITE_INT8_FIELD
#undef RELAXED_READ_INT8_FIELD
#undef WRITE_INT8_FIELD
#undef WRITE_UINT16_FIELD
#undef WRITE_INT16_FIELD
#undef RELAXED_READ_INT16_FIELD
#undef RELAXED_WRITE_INT16_FIELD
#undef RELAXED_READ_UINT32_FIELD
#undef WRITE_UINT32_FIELD
#undef RELAXED_WRITE_UINT32_FIELD
#undef RELAXED_READ_INT32_FIELD
#undef WRITE_INT32_FIELD
#undef RELEASE_WRITE_INT32_FIELD
#undef RELAXED_WRITE_INT32_FIELD
#undef WRITE_FLOAT_FIELD
#undef WRITE_INTPTR_FIELD
#undef WRITE_UINTPTR_FIELD
#undef WRITE_UINT64_FIELD
#undef RELAXED_READ_BYTE_FIELD
#undef WRITE_BYTE_FIELD
#undef RELAXED_WRITE_BYTE_FIELD
#undef DECL_PRINTER
#undef DECL_VERIFIER
......
......@@ -82,13 +82,11 @@
#define INT_ACCESSORS(holder, name, offset) \
int holder::name() const { return ReadField<int>(offset); } \
void holder::set_##name(int value) { WRITE_INT_FIELD(*this, offset, value); }
void holder::set_##name(int value) { WriteField<int>(offset, value); }
#define INT32_ACCESSORS(holder, name, offset) \
int32_t holder::name() const { return ReadField<int32_t>(offset); } \
void holder::set_##name(int32_t value) { \
WRITE_INT32_FIELD(*this, offset, value); \
}
void holder::set_##name(int32_t value) { WriteField<int32_t>(offset, value); }
#define RELAXED_INT32_ACCESSORS(holder, name, offset) \
int32_t holder::name() const { \
......@@ -103,7 +101,7 @@
void holder::set_##name(int value) { \
DCHECK_GE(value, 0); \
DCHECK_LE(value, static_cast<uint16_t>(-1)); \
WRITE_UINT16_FIELD(*this, offset, value); \
WriteField<uint16_t>(offset, value); \
}
#define UINT8_ACCESSORS(holder, name, offset) \
......@@ -111,7 +109,7 @@
void holder::set_##name(int value) { \
DCHECK_GE(value, 0); \
DCHECK_LE(value, static_cast<uint8_t>(-1)); \
WRITE_UINT8_FIELD(*this, offset, value); \
WriteField<uint8_t>(offset, value); \
}
#define ACCESSORS_CHECKED2(holder, name, type, offset, get_condition, \
......@@ -336,20 +334,10 @@
} \
} while (false)
// BUG(v8:8875): Double fields may be unaligned.
#define WRITE_DOUBLE_FIELD(p, offset, value) \
WriteUnalignedValue<double>(FIELD_ADDR(p, offset), value)
#define WRITE_INT_FIELD(p, offset, value) \
(*reinterpret_cast<int*>(FIELD_ADDR(p, offset)) = value)
#define ACQUIRE_READ_INT32_FIELD(p, offset) \
static_cast<int32_t>(base::Acquire_Load( \
reinterpret_cast<const base::Atomic32*>(FIELD_ADDR(p, offset))))
#define WRITE_UINT8_FIELD(p, offset, value) \
(*reinterpret_cast<uint8_t*>(FIELD_ADDR(p, offset)) = value)
#define RELAXED_WRITE_INT8_FIELD(p, offset, value) \
base::Relaxed_Store(reinterpret_cast<base::Atomic8*>(FIELD_ADDR(p, offset)), \
static_cast<base::Atomic8>(value));
......@@ -357,15 +345,6 @@
static_cast<int8_t>(base::Relaxed_Load( \
reinterpret_cast<const base::Atomic8*>(FIELD_ADDR(p, offset))))
#define WRITE_INT8_FIELD(p, offset, value) \
(*reinterpret_cast<int8_t*>(FIELD_ADDR(p, offset)) = value)
#define WRITE_UINT16_FIELD(p, offset, value) \
(*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)) = value)
#define WRITE_INT16_FIELD(p, offset, value) \
(*reinterpret_cast<int16_t*>(FIELD_ADDR(p, offset)) = value)
#define RELAXED_READ_INT16_FIELD(p, offset) \
static_cast<int16_t>(base::Relaxed_Load( \
reinterpret_cast<const base::Atomic16*>(FIELD_ADDR(p, offset))))
......@@ -379,9 +358,6 @@
static_cast<uint32_t>(base::Relaxed_Load( \
reinterpret_cast<const base::Atomic32*>(FIELD_ADDR(p, offset))))
#define WRITE_UINT32_FIELD(p, offset, value) \
(*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)) = value)
#define RELAXED_WRITE_UINT32_FIELD(p, offset, value) \
base::Relaxed_Store( \
reinterpret_cast<base::Atomic32*>(FIELD_ADDR(p, offset)), \
......@@ -391,9 +367,6 @@
static_cast<int32_t>(base::Relaxed_Load( \
reinterpret_cast<const base::Atomic32*>(FIELD_ADDR(p, offset))))
#define WRITE_INT32_FIELD(p, offset, value) \
(*reinterpret_cast<int32_t*>(FIELD_ADDR(p, offset)) = value)
#define RELEASE_WRITE_INT32_FIELD(p, offset, value) \
base::Release_Store( \
reinterpret_cast<base::Atomic32*>(FIELD_ADDR(p, offset)), \
......@@ -404,44 +377,10 @@
reinterpret_cast<base::Atomic32*>(FIELD_ADDR(p, offset)), \
static_cast<base::Atomic32>(value));
#define WRITE_FLOAT_FIELD(p, offset, value) \
(*reinterpret_cast<float*>(FIELD_ADDR(p, offset)) = value)
// TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size fields
// (external pointers, doubles and BigInt data) are only kTaggedSize aligned so
// we have to use unaligned pointer friendly way of accessing them in order to
// avoid undefined behavior in C++ code.
#ifdef V8_COMPRESS_POINTERS
#define WRITE_INTPTR_FIELD(p, offset, value) \
WriteUnalignedValue<intptr_t>(FIELD_ADDR(p, offset), value)
#define WRITE_UINTPTR_FIELD(p, offset, value) \
WriteUnalignedValue<uintptr_t>(FIELD_ADDR(p, offset), value)
#define WRITE_UINT64_FIELD(p, offset, value) \
WriteUnalignedValue<uint64_t>(FIELD_ADDR(p, offset), value)
#else // V8_COMPRESS_POINTERS
#define WRITE_INTPTR_FIELD(p, offset, value) \
(*reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset)) = value)
#define WRITE_UINTPTR_FIELD(p, offset, value) \
(*reinterpret_cast<uintptr_t*>(FIELD_ADDR(p, offset)) = value)
#define WRITE_UINT64_FIELD(p, offset, value) \
(*reinterpret_cast<uint64_t*>(FIELD_ADDR(p, offset)) = value)
#endif // V8_COMPRESS_POINTERS
#define RELAXED_READ_BYTE_FIELD(p, offset) \
static_cast<byte>(base::Relaxed_Load( \
reinterpret_cast<const base::Atomic8*>(FIELD_ADDR(p, offset))))
#define WRITE_BYTE_FIELD(p, offset, value) \
(*reinterpret_cast<byte*>(FIELD_ADDR(p, offset)) = value)
#define RELAXED_WRITE_BYTE_FIELD(p, offset, value) \
base::Relaxed_Store(reinterpret_cast<base::Atomic8*>(FIELD_ADDR(p, offset)), \
static_cast<base::Atomic8>(value));
......
......@@ -27,11 +27,12 @@ double Oddball::to_number_raw() const {
}
void Oddball::set_to_number_raw(double value) {
WRITE_DOUBLE_FIELD(*this, kToNumberRawOffset, value);
WriteField<double>(kToNumberRawOffset, value);
}
void Oddball::set_to_number_raw_as_bits(uint64_t bits) {
WRITE_UINT64_FIELD(*this, kToNumberRawOffset, bits);
// Bug(v8:8875): HeapNumber's double may be unaligned.
WriteUnalignedValue<uint64_t>(field_address(kToNumberRawOffset), bits);
}
ACCESSORS(Oddball, to_string, String, kToStringOffset)
......
......@@ -192,7 +192,7 @@ Object OrderedHashTableIterator<Derived, TableType>::CurrentKey() {
inline void SmallOrderedNameDictionary::SetHash(int hash) {
DCHECK(PropertyArray::HashField::is_valid(hash));
WRITE_INT_FIELD(*this, PrefixOffset(), hash);
WriteField<int>(PrefixOffset(), hash);
}
inline int SmallOrderedNameDictionary::Hash() {
......
......@@ -546,7 +546,7 @@ class SmallOrderedHashTable : public HeapObject {
void setByte(Offset offset, ByteIndex index, byte value) {
DCHECK(offset < DataTableStartOffset() ||
offset >= GetBucketsStartOffset());
WRITE_BYTE_FIELD(*this, offset + (index * kOneByteSize), value);
WriteField<byte>(offset + (index * kOneByteSize), value);
}
Offset GetDataEntryOffset(int entry, int relative_index) const {
......
......@@ -54,7 +54,7 @@ void PreparseData::set(int index, byte value) {
DCHECK_LE(0, index);
DCHECK_LT(index, data_length());
int offset = kDataStartOffset + index * kByteSize;
WRITE_BYTE_FIELD(*this, offset, value);
WriteField<byte>(offset, value);
}
void PreparseData::copy_in(int index, const byte* buffer, int length) {
......
......@@ -489,8 +489,7 @@ uint8_t SeqOneByteString::Get(int index) {
void SeqOneByteString::SeqOneByteStringSet(int index, uint16_t value) {
DCHECK(index >= 0 && index < length() && value <= kMaxOneByteCharCode);
WRITE_BYTE_FIELD(*this, kHeaderSize + index * kCharSize,
static_cast<byte>(value));
WriteField<byte>(kHeaderSize + index * kCharSize, static_cast<byte>(value));
}
Address SeqOneByteString::GetCharsAddress() {
......@@ -518,7 +517,7 @@ uint16_t SeqTwoByteString::Get(int index) {
void SeqTwoByteString::SeqTwoByteStringSet(int index, uint16_t value) {
DCHECK(index >= 0 && index < length());
WRITE_UINT16_FIELD(*this, kHeaderSize + index * kShortSize, value);
WriteField<uint16_t>(kHeaderSize + index * kShortSize, value);
}
int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) {
......@@ -584,7 +583,7 @@ Address ExternalString::resource_as_address() {
}
void ExternalString::set_address_as_resource(Address address) {
WRITE_UINTPTR_FIELD(*this, kResourceOffset, address);
WriteField<Address>(kResourceOffset, address);
if (IsExternalOneByteString()) {
ExternalOneByteString::cast(*this)->update_data_cache();
} else {
......@@ -597,9 +596,9 @@ uint32_t ExternalString::resource_as_uint32() {
}
void ExternalString::set_uint32_as_resource(uint32_t value) {
WRITE_UINTPTR_FIELD(*this, kResourceOffset, value);
WriteField<Address>(kResourceOffset, value);
if (is_uncached()) return;
WRITE_UINTPTR_FIELD(*this, kResourceDataOffset, kNullAddress);
WriteField<Address>(kResourceDataOffset, kNullAddress);
}
void ExternalString::DisposeResource() {
......@@ -610,7 +609,7 @@ void ExternalString::DisposeResource() {
// Dispose of the C++ object if it has not already been disposed.
if (resource != nullptr) {
resource->Dispose();
WRITE_UINTPTR_FIELD(*this, ExternalString::kResourceOffset, kNullAddress);
WriteField<Address>(ExternalString::kResourceOffset, kNullAddress);
}
}
......@@ -620,7 +619,7 @@ const ExternalOneByteString::Resource* ExternalOneByteString::resource() {
void ExternalOneByteString::update_data_cache() {
if (is_uncached()) return;
WRITE_UINTPTR_FIELD(*this, kResourceDataOffset,
WriteField<Address>(kResourceDataOffset,
reinterpret_cast<Address>(resource()->data()));
}
......@@ -635,8 +634,7 @@ void ExternalOneByteString::SetResource(
void ExternalOneByteString::set_resource(
const ExternalOneByteString::Resource* resource) {
WRITE_UINTPTR_FIELD(*this, kResourceOffset,
reinterpret_cast<Address>(resource));
WriteField<Address>(kResourceOffset, reinterpret_cast<Address>(resource));
if (resource != nullptr) update_data_cache();
}
......@@ -655,7 +653,7 @@ const ExternalTwoByteString::Resource* ExternalTwoByteString::resource() {
void ExternalTwoByteString::update_data_cache() {
if (is_uncached()) return;
WRITE_UINTPTR_FIELD(*this, kResourceDataOffset,
WriteField<Address>(kResourceDataOffset,
reinterpret_cast<Address>(resource()->data()));
}
......@@ -670,8 +668,7 @@ void ExternalTwoByteString::SetResource(
void ExternalTwoByteString::set_resource(
const ExternalTwoByteString::Resource* resource) {
WRITE_UINTPTR_FIELD(*this, kResourceOffset,
reinterpret_cast<Address>(resource));
WriteField<Address>(kResourceOffset, reinterpret_cast<Address>(resource));
if (resource != nullptr) update_data_cache();
}
......
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