[ptr-compr] Using TaggedField<> in more places

Bug: v8:9353
Change-Id: Ie090f8f89eb4372845fe2c9d6aa74154c36f2d53
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1662291
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62221}
This commit is contained in:
Igor Sheludko 2019-06-17 17:06:37 +02:00 committed by Commit Bot
parent b1c2160c2f
commit b9591a58e9
4 changed files with 56 additions and 78 deletions

View File

@ -130,10 +130,7 @@ bool JSObject::PrototypeHasNoElements(Isolate* isolate, JSObject object) {
ACCESSORS(JSReceiver, raw_properties_or_hash, Object, kPropertiesOrHashOffset)
FixedArrayBase JSObject::elements() const {
Object array = READ_FIELD(*this, kElementsOffset);
return FixedArrayBase::cast(array);
}
ACCESSORS(JSObject, elements, FixedArrayBase, kElementsOffset)
void JSObject::EnsureCanContainHeapObjectElements(Handle<JSObject> object) {
JSObject::ValidateElements(*object);
@ -238,14 +235,9 @@ void JSObject::SetMapAndElements(Handle<JSObject> object, Handle<Map> new_map,
object->set_elements(*value);
}
void JSObject::set_elements(FixedArrayBase value, WriteBarrierMode mode) {
WRITE_FIELD(*this, kElementsOffset, value);
CONDITIONAL_WRITE_BARRIER(*this, kElementsOffset, value, mode);
}
void JSObject::initialize_elements() {
FixedArrayBase elements = map().GetInitialElements();
WRITE_FIELD(*this, kElementsOffset, elements);
set_elements(elements, SKIP_WRITE_BARRIER);
}
InterceptorInfo JSObject::GetIndexedInterceptor() {

View File

@ -31,19 +31,11 @@ OBJECT_CONSTRUCTORS_IMPL(Map, HeapObject)
CAST_ACCESSOR(Map)
DescriptorArray Map::instance_descriptors() const {
return DescriptorArray::cast(READ_FIELD(*this, kInstanceDescriptorsOffset));
return TaggedField<DescriptorArray, kInstanceDescriptorsOffset>::load(*this);
}
DescriptorArray Map::synchronized_instance_descriptors() const {
return DescriptorArray::cast(
ACQUIRE_READ_FIELD(*this, kInstanceDescriptorsOffset));
}
void Map::set_synchronized_instance_descriptors(DescriptorArray value,
WriteBarrierMode mode) {
RELEASE_WRITE_FIELD(*this, kInstanceDescriptorsOffset, value);
CONDITIONAL_WRITE_BARRIER(*this, kInstanceDescriptorsOffset, value, mode);
}
SYNCHRONIZED_ACCESSORS(Map, synchronized_instance_descriptors, DescriptorArray,
kInstanceDescriptorsOffset)
// A freshly allocated layout descriptor can be set on an existing map.
// We need to use release-store and acquire-load accessor pairs to ensure
@ -54,6 +46,12 @@ SYNCHRONIZED_ACCESSORS_CHECKED(Map, layout_descriptor, LayoutDescriptor,
FLAG_unbox_double_fields)
WEAK_ACCESSORS(Map, raw_transitions, kTransitionsOrPrototypeInfoOffset)
ACCESSORS_CHECKED2(Map, prototype, HeapObject, kPrototypeOffset, true,
value.IsNull() || value.IsJSReceiver())
ACCESSORS_CHECKED(Map, prototype_info, Object,
kTransitionsOrPrototypeInfoOffset, this->is_prototype_map())
// |bit_field| fields.
// Concurrent access to |has_prototype_slot| and |has_non_instance_prototype|
// is explicitly whitelisted here. The former is never modified after the map
@ -568,22 +566,13 @@ bool Map::IsPrimitiveMap() const {
return instance_type() <= LAST_PRIMITIVE_TYPE;
}
HeapObject Map::prototype() const {
return HeapObject::cast(READ_FIELD(*this, kPrototypeOffset));
}
void Map::set_prototype(HeapObject value, WriteBarrierMode mode) {
DCHECK(value.IsNull() || value.IsJSReceiver());
WRITE_FIELD(*this, kPrototypeOffset, value);
CONDITIONAL_WRITE_BARRIER(*this, kPrototypeOffset, value, mode);
}
LayoutDescriptor Map::layout_descriptor_gc_safe() const {
DCHECK(FLAG_unbox_double_fields);
// The loaded value can be dereferenced on background thread to load the
// bitmap. We need acquire load in order to ensure that the bitmap
// initializing stores are also visible to the background thread.
Object layout_desc = ACQUIRE_READ_FIELD(*this, kLayoutDescriptorOffset);
Object layout_desc =
TaggedField<Object, kLayoutDescriptorOffset>::Acquire_Load(*this);
return LayoutDescriptor::cast_gc_safe(layout_desc);
}
@ -591,7 +580,8 @@ bool Map::HasFastPointerLayout() const {
DCHECK(FLAG_unbox_double_fields);
// The loaded value is used for SMI check only and is not dereferenced,
// so relaxed load is safe.
Object layout_desc = RELAXED_READ_FIELD(*this, kLayoutDescriptorOffset);
Object layout_desc =
TaggedField<Object, kLayoutDescriptorOffset>::Relaxed_Load(*this);
return LayoutDescriptor::IsFastPointerLayout(layout_desc);
}
@ -698,18 +688,6 @@ Map Map::ElementsTransitionMap(Isolate* isolate) {
.SearchSpecial(ReadOnlyRoots(isolate).elements_transition_symbol());
}
Object Map::prototype_info() const {
DCHECK(is_prototype_map());
return READ_FIELD(*this, Map::kTransitionsOrPrototypeInfoOffset);
}
void Map::set_prototype_info(Object value, WriteBarrierMode mode) {
CHECK(is_prototype_map());
WRITE_FIELD(*this, Map::kTransitionsOrPrototypeInfoOffset, value);
CONDITIONAL_WRITE_BARRIER(*this, Map::kTransitionsOrPrototypeInfoOffset,
value, mode);
}
void Map::SetBackPointer(Object value, WriteBarrierMode mode) {
CHECK_GE(instance_type(), FIRST_JS_RECEIVER_TYPE);
CHECK(value.IsMap());

View File

@ -51,7 +51,6 @@
#undef RELAXED_READ_FIELD
#undef RELAXED_READ_WEAK_FIELD
#undef WRITE_FIELD
#undef WRITE_WEAK_FIELD
#undef RELEASE_WRITE_FIELD
#undef RELAXED_WRITE_FIELD
#undef RELAXED_WRITE_WEAK_FIELD

View File

@ -116,13 +116,18 @@
#define ACCESSORS_CHECKED2(holder, name, type, offset, get_condition, \
set_condition) \
type holder::name() const { \
type value = type::cast(READ_FIELD(*this, offset)); \
type value = TaggedField<type, offset>::load(*this); \
DCHECK(get_condition); \
return value; \
} \
void holder::set_##name(type value, WriteBarrierMode mode) { \
DCHECK(set_condition); \
WRITE_FIELD(*this, offset, value); \
if (V8_CONCURRENT_MARKING_BOOL) { \
TaggedField<type, offset>::Relaxed_Store(*this, value); \
} else { \
TaggedField<type, offset>::store(*this, value); \
} \
TaggedField<type, offset>::store(*this, value); \
CONDITIONAL_WRITE_BARRIER(*this, offset, value, mode); \
}
@ -135,13 +140,13 @@
#define SYNCHRONIZED_ACCESSORS_CHECKED2(holder, name, type, offset, \
get_condition, set_condition) \
type holder::name() const { \
type value = type::cast(ACQUIRE_READ_FIELD(*this, offset)); \
type value = TaggedField<type, offset>::Acquire_Load(*this); \
DCHECK(get_condition); \
return value; \
} \
void holder::set_##name(type value, WriteBarrierMode mode) { \
DCHECK(set_condition); \
RELEASE_WRITE_FIELD(*this, offset, value); \
TaggedField<type, offset>::Release_Store(*this, value); \
CONDITIONAL_WRITE_BARRIER(*this, offset, value, mode); \
}
@ -161,7 +166,11 @@
} \
void holder::set_##name(MaybeObject value, WriteBarrierMode mode) { \
DCHECK(set_condition); \
WRITE_WEAK_FIELD(*this, offset, value); \
if (V8_CONCURRENT_MARKING_BOOL) { \
TaggedField<MaybeObject, offset>::Relaxed_Store(*this, value); \
} else { \
TaggedField<MaybeObject, offset>::store(*this, value); \
} \
CONDITIONAL_WEAK_WRITE_BARRIER(*this, offset, value, mode); \
}
@ -172,36 +181,40 @@
WEAK_ACCESSORS_CHECKED(holder, name, offset, true)
// Getter that returns a Smi as an int and writes an int as a Smi.
#define SMI_ACCESSORS_CHECKED(holder, name, offset, condition) \
int holder::name() const { \
DCHECK(condition); \
Object value = READ_FIELD(*this, offset); \
return Smi::ToInt(value); \
} \
void holder::set_##name(int value) { \
DCHECK(condition); \
WRITE_FIELD(*this, offset, Smi::FromInt(value)); \
#define SMI_ACCESSORS_CHECKED(holder, name, offset, condition) \
int holder::name() const { \
DCHECK(condition); \
Smi value = TaggedField<Smi, offset>::load(*this); \
return value.value(); \
} \
void holder::set_##name(int value) { \
DCHECK(condition); \
if (V8_CONCURRENT_MARKING_BOOL) { \
TaggedField<Smi, offset>::Relaxed_Store(*this, Smi::FromInt(value)); \
} else { \
TaggedField<Smi, offset>::store(*this, Smi::FromInt(value)); \
} \
}
#define SMI_ACCESSORS(holder, name, offset) \
SMI_ACCESSORS_CHECKED(holder, name, offset, true)
#define SYNCHRONIZED_SMI_ACCESSORS(holder, name, offset) \
int holder::synchronized_##name() const { \
Object value = ACQUIRE_READ_FIELD(*this, offset); \
return Smi::ToInt(value); \
} \
void holder::synchronized_set_##name(int value) { \
RELEASE_WRITE_FIELD(*this, offset, Smi::FromInt(value)); \
#define SYNCHRONIZED_SMI_ACCESSORS(holder, name, offset) \
int holder::synchronized_##name() const { \
Smi value = TaggedField<Smi, offset>::Acquire_Load(*this); \
return value.value(); \
} \
void holder::synchronized_set_##name(int value) { \
TaggedField<Smi, offset>::Release_Store(*this, Smi::FromInt(value)); \
}
#define RELAXED_SMI_ACCESSORS(holder, name, offset) \
int holder::relaxed_read_##name() const { \
Object value = RELAXED_READ_FIELD(*this, offset); \
return Smi::ToInt(value); \
} \
void holder::relaxed_write_##name(int value) { \
RELAXED_WRITE_FIELD(*this, offset, Smi::FromInt(value)); \
#define RELAXED_SMI_ACCESSORS(holder, name, offset) \
int holder::relaxed_read_##name() const { \
Smi value = TaggedField<Smi, offset>::Relaxed_Load(*this); \
return value.value(); \
} \
void holder::relaxed_write_##name(int value) { \
TaggedField<Smi, offset>::Relaxed_Store(*this, Smi::FromInt(value)); \
}
#define BOOL_GETTER(holder, field, name, offset) \
@ -257,13 +270,9 @@
#ifdef V8_CONCURRENT_MARKING
#define WRITE_FIELD(p, offset, value) \
ObjectSlot(FIELD_ADDR(p, offset)).Relaxed_Store(value)
#define WRITE_WEAK_FIELD(p, offset, value) \
MaybeObjectSlot(FIELD_ADDR(p, offset)).Relaxed_Store(value)
#else
#define WRITE_FIELD(p, offset, value) \
ObjectSlot(FIELD_ADDR(p, offset)).store(value)
#define WRITE_WEAK_FIELD(p, offset, value) \
MaybeObjectSlot(FIELD_ADDR(p, offset)).store(value)
#endif
#define RELEASE_WRITE_FIELD(p, offset, value) \