[compiler] Better encapsulation of MapData and DescriptorArrayData

Maps and DescriptorArrays are intertwined, but we can separate the
DescriptorArray's information inside DescriptorArrayData. Also,
encapsulate DescriptorArrayData's content and don't return the ZoneMap
as a value.

Bug: v8:7790
Change-Id: Icc29737e4dd9dd33b887e93d4ecd1e3f5aac1153
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2624613
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72258}
This commit is contained in:
Santiago Aboy Solanes 2021-01-22 14:21:21 +00:00 committed by Commit Bot
parent 494a38006e
commit aa0b5a42de

View File

@ -1360,12 +1360,83 @@ class DescriptorArrayData : public HeapObjectData {
Handle<DescriptorArray> object)
: HeapObjectData(broker, storage, object), contents_(broker->zone()) {}
ZoneMap<int, PropertyDescriptor>& contents() { return contents_; }
ObjectData* FindFieldOwner(InternalIndex descriptor_index) const {
return contents_.at(descriptor_index.as_int()).field_owner;
}
PropertyDetails GetPropertyDetails(InternalIndex descriptor_index) const {
return contents_.at(descriptor_index.as_int()).details;
}
ObjectData* GetPropertyKey(InternalIndex descriptor_index) const {
return contents_.at(descriptor_index.as_int()).key;
}
FieldIndex GetFieldIndexFor(InternalIndex descriptor_index) const {
return contents_.at(descriptor_index.as_int()).field_index;
}
ObjectData* GetFieldType(InternalIndex descriptor_index) const {
return contents_.at(descriptor_index.as_int()).field_type;
}
bool IsUnboxedDoubleField(InternalIndex descriptor_index) const {
return contents_.at(descriptor_index.as_int()).is_unboxed_double_field;
}
ObjectData* GetStrongValue(InternalIndex descriptor_index) const {
return contents_.at(descriptor_index.as_int()).value;
}
bool serialized_descriptor(InternalIndex descriptor_index) const {
return contents_.find(descriptor_index.as_int()) != contents_.end();
}
void SerializeDescriptor(JSHeapBroker* broker, Handle<Map> map,
InternalIndex descriptor_index);
private:
ZoneMap<int, PropertyDescriptor> contents_;
};
void DescriptorArrayData::SerializeDescriptor(JSHeapBroker* broker,
Handle<Map> map,
InternalIndex descriptor_index) {
CHECK_LT(descriptor_index.as_int(), map->NumberOfOwnDescriptors());
if (contents_.find(descriptor_index.as_int()) != contents_.end()) return;
Isolate* const isolate = broker->isolate();
auto descriptors = Handle<DescriptorArray>::cast(object());
CHECK_EQ(*descriptors, map->instance_descriptors(kRelaxedLoad));
PropertyDescriptor d;
d.key = broker->GetOrCreateData(descriptors->GetKey(descriptor_index));
MaybeObject value = descriptors->GetValue(descriptor_index);
HeapObject obj;
if (value.GetHeapObjectIfStrong(&obj)) {
d.value = broker->GetOrCreateData(obj);
}
d.details = descriptors->GetDetails(descriptor_index);
if (d.details.location() == kField) {
d.field_index = FieldIndex::ForDescriptor(*map, descriptor_index);
d.field_owner =
broker->GetOrCreateData(map->FindFieldOwner(isolate, descriptor_index));
d.field_type =
broker->GetOrCreateData(descriptors->GetFieldType(descriptor_index));
d.is_unboxed_double_field = map->IsUnboxedDoubleField(d.field_index);
}
contents_[descriptor_index.as_int()] = d;
if (d.details.location() == kField && !d.field_owner->should_access_heap()) {
// Recurse on the owner map.
d.field_owner->AsMap()->SerializeOwnDescriptor(broker, descriptor_index);
}
TRACE(broker, "Copied descriptor " << descriptor_index.as_int() << " into "
<< this << " (" << contents_.size()
<< " total)");
}
class FeedbackCellData : public HeapObjectData {
public:
FeedbackCellData(JSHeapBroker* broker, ObjectData** storage,
@ -2142,14 +2213,6 @@ void MapData::SerializeOwnDescriptors(JSHeapBroker* broker) {
}
}
ObjectData* MapData::GetStrongValue(InternalIndex descriptor_index) const {
DescriptorArrayData* descriptor_array =
instance_descriptors()->AsDescriptorArray();
auto data = descriptor_array->contents().find(descriptor_index.as_int());
if (data == descriptor_array->contents().end()) return nullptr;
return data->second.value;
}
void MapData::SerializeOwnDescriptor(JSHeapBroker* broker,
InternalIndex descriptor_index) {
TraceScope tracer(broker, this, "MapData::SerializeOwnDescriptor");
@ -2160,42 +2223,9 @@ void MapData::SerializeOwnDescriptor(JSHeapBroker* broker,
broker->GetOrCreateData(map->instance_descriptors(kRelaxedLoad));
}
ZoneMap<int, PropertyDescriptor>& contents =
instance_descriptors()->AsDescriptorArray()->contents();
CHECK_LT(descriptor_index.as_int(), map->NumberOfOwnDescriptors());
if (contents.find(descriptor_index.as_int()) != contents.end()) return;
Isolate* const isolate = broker->isolate();
auto descriptors =
Handle<DescriptorArray>::cast(instance_descriptors()->object());
CHECK_EQ(*descriptors, map->instance_descriptors(kRelaxedLoad));
PropertyDescriptor d;
d.key = broker->GetOrCreateData(descriptors->GetKey(descriptor_index));
MaybeObject value = descriptors->GetValue(descriptor_index);
HeapObject obj;
if (value.GetHeapObjectIfStrong(&obj)) {
d.value = broker->GetOrCreateData(obj);
}
d.details = descriptors->GetDetails(descriptor_index);
if (d.details.location() == kField) {
d.field_index = FieldIndex::ForDescriptor(*map, descriptor_index);
d.field_owner =
broker->GetOrCreateData(map->FindFieldOwner(isolate, descriptor_index));
d.field_type =
broker->GetOrCreateData(descriptors->GetFieldType(descriptor_index));
d.is_unboxed_double_field = map->IsUnboxedDoubleField(d.field_index);
}
contents[descriptor_index.as_int()] = d;
if (d.details.location() == kField && !d.field_owner->should_access_heap()) {
// Recurse on the owner map.
d.field_owner->AsMap()->SerializeOwnDescriptor(broker, descriptor_index);
}
TRACE(broker, "Copied descriptor " << descriptor_index.as_int() << " into "
<< instance_descriptors() << " ("
<< contents.size() << " total)");
DescriptorArrayData* descriptor_array =
instance_descriptors()->AsDescriptorArray();
descriptor_array->SerializeDescriptor(broker, map, descriptor_index);
}
void MapData::SerializeRootMap(JSHeapBroker* broker) {
@ -3068,7 +3098,7 @@ FieldIndex MapRef::GetFieldIndexFor(InternalIndex descriptor_index) const {
}
DescriptorArrayData* descriptors =
data()->AsMap()->instance_descriptors()->AsDescriptorArray();
return descriptors->contents().at(descriptor_index.as_int()).field_index;
return descriptors->GetFieldIndexFor(descriptor_index);
}
int MapRef::GetInObjectPropertyOffset(int i) const {
@ -3087,7 +3117,7 @@ PropertyDetails MapRef::GetPropertyDetails(
}
DescriptorArrayData* descriptors =
data()->AsMap()->instance_descriptors()->AsDescriptorArray();
return descriptors->contents().at(descriptor_index.as_int()).details;
return descriptors->GetPropertyDetails(descriptor_index);
}
NameRef MapRef::GetPropertyKey(InternalIndex descriptor_index) const {
@ -3099,8 +3129,7 @@ NameRef MapRef::GetPropertyKey(InternalIndex descriptor_index) const {
}
DescriptorArrayData* descriptors =
data()->AsMap()->instance_descriptors()->AsDescriptorArray();
return NameRef(broker(),
descriptors->contents().at(descriptor_index.as_int()).key);
return NameRef(broker(), descriptors->GetPropertyKey(descriptor_index));
}
bool MapRef::IsFixedCowArrayMap() const {
@ -3122,9 +3151,7 @@ MapRef MapRef::FindFieldOwner(InternalIndex descriptor_index) const {
}
DescriptorArrayData* descriptors =
data()->AsMap()->instance_descriptors()->AsDescriptorArray();
return MapRef(
broker(),
descriptors->contents().at(descriptor_index.as_int()).field_owner);
return MapRef(broker(), descriptors->FindFieldOwner(descriptor_index));
}
ObjectRef MapRef::GetFieldType(InternalIndex descriptor_index) const {
@ -3137,9 +3164,7 @@ ObjectRef MapRef::GetFieldType(InternalIndex descriptor_index) const {
}
DescriptorArrayData* descriptors =
data()->AsMap()->instance_descriptors()->AsDescriptorArray();
return ObjectRef(
broker(),
descriptors->contents().at(descriptor_index.as_int()).field_type);
return ObjectRef(broker(), descriptors->GetFieldType(descriptor_index));
}
bool MapRef::IsUnboxedDoubleField(InternalIndex descriptor_index) const {
@ -3149,9 +3174,7 @@ bool MapRef::IsUnboxedDoubleField(InternalIndex descriptor_index) const {
}
DescriptorArrayData* descriptors =
data()->AsMap()->instance_descriptors()->AsDescriptorArray();
return descriptors->contents()
.at(descriptor_index.as_int())
.is_unboxed_double_field;
return descriptors->IsUnboxedDoubleField(descriptor_index);
}
base::Optional<int> StringRef::length() const {
@ -3573,7 +3596,11 @@ base::Optional<ObjectRef> MapRef::GetStrongValue(
}
return base::nullopt;
}
ObjectData* value = data()->AsMap()->GetStrongValue(descriptor_index);
ObjectData* value = data()
->AsMap()
->instance_descriptors()
->AsDescriptorArray()
->GetStrongValue(descriptor_index);
if (!value) {
return base::nullopt;
}
@ -4262,8 +4289,7 @@ bool MapRef::serialized_own_descriptor(InternalIndex descriptor_index) const {
if (!maybe_desc_array_data) return false;
DescriptorArrayData* desc_array_data =
maybe_desc_array_data->AsDescriptorArray();
return desc_array_data->contents().find(descriptor_index.as_int()) !=
desc_array_data->contents().end();
return desc_array_data->serialized_descriptor(descriptor_index);
}
void MapRef::SerializeBackPointer() {