From b9591a58e90818360299fe256d789ba6493cbf7d Mon Sep 17 00:00:00 2001 From: Igor Sheludko Date: Mon, 17 Jun 2019 17:06:37 +0200 Subject: [PATCH] [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 Reviewed-by: Toon Verwaest Cr-Commit-Position: refs/heads/master@{#62221} --- src/objects/js-objects-inl.h | 12 +---- src/objects/map-inl.h | 48 ++++++-------------- src/objects/object-macros-undef.h | 1 - src/objects/object-macros.h | 73 +++++++++++++++++-------------- 4 files changed, 56 insertions(+), 78 deletions(-) diff --git a/src/objects/js-objects-inl.h b/src/objects/js-objects-inl.h index df7ad59afd..7218f6acd9 100644 --- a/src/objects/js-objects-inl.h +++ b/src/objects/js-objects-inl.h @@ -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 object) { JSObject::ValidateElements(*object); @@ -238,14 +235,9 @@ void JSObject::SetMapAndElements(Handle object, Handle 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() { diff --git a/src/objects/map-inl.h b/src/objects/map-inl.h index 721351b621..6546846c42 100644 --- a/src/objects/map-inl.h +++ b/src/objects/map-inl.h @@ -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::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::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::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()); diff --git a/src/objects/object-macros-undef.h b/src/objects/object-macros-undef.h index c8ebf57ce7..a524cafb8a 100644 --- a/src/objects/object-macros-undef.h +++ b/src/objects/object-macros-undef.h @@ -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 diff --git a/src/objects/object-macros.h b/src/objects/object-macros.h index 6d98cb23ae..ad29f7938d 100644 --- a/src/objects/object-macros.h +++ b/src/objects/object-macros.h @@ -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::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::Relaxed_Store(*this, value); \ + } else { \ + TaggedField::store(*this, value); \ + } \ + TaggedField::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::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::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::Relaxed_Store(*this, value); \ + } else { \ + TaggedField::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::load(*this); \ + return value.value(); \ + } \ + void holder::set_##name(int value) { \ + DCHECK(condition); \ + if (V8_CONCURRENT_MARKING_BOOL) { \ + TaggedField::Relaxed_Store(*this, Smi::FromInt(value)); \ + } else { \ + TaggedField::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::Acquire_Load(*this); \ + return value.value(); \ + } \ + void holder::synchronized_set_##name(int value) { \ + TaggedField::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::Relaxed_Load(*this); \ + return value.value(); \ + } \ + void holder::relaxed_write_##name(int value) { \ + TaggedField::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) \