Commit 322a3785 authored by ishell's avatar ishell Committed by Commit bot

[runtime] Add DescriptorArray::GeneralizeAllFields().

... and rename [Copy]GeneralizeAllRepresentations() -> [Copy]GeneralizeAllFields().

BUG=v8:5495

Review-Url: https://codereview.chromium.org/2632373002
Cr-Commit-Position: refs/heads/master@{#42418}
parent 2fd43416
......@@ -3703,8 +3703,7 @@ Handle<Object> TranslatedState::MaterializeAt(int frame_index,
}
Handle<Object> map_object = materializer.At(value_index);
Handle<Map> map =
Map::GeneralizeAllFieldRepresentations(Handle<Map>::cast(map_object));
Handle<Map> map = Map::GeneralizeAllFields(Handle<Map>::cast(map_object));
switch (map->instance_type()) {
case MUTABLE_HEAP_NUMBER_TYPE:
case HEAP_NUMBER_TYPE: {
......
......@@ -149,11 +149,10 @@ Handle<Map> MapUpdater::Update() {
return result_map_;
}
MapUpdater::State MapUpdater::CopyGeneralizeAllRepresentations(
const char* reason) {
MapUpdater::State MapUpdater::CopyGeneralizeAllFields(const char* reason) {
StoreMode store_mode =
modified_descriptor_ >= 0 ? FORCE_FIELD : ALLOW_IN_DESCRIPTOR;
result_map_ = Map::CopyGeneralizeAllRepresentations(
result_map_ = Map::CopyGeneralizeAllFields(
old_map_, new_elements_kind_, modified_descriptor_, store_mode, new_kind_,
new_attributes_, reason);
state_ = kEnd;
......@@ -210,7 +209,7 @@ MapUpdater::State MapUpdater::FindRootMap() {
root_map_ = handle(old_map_->FindRootMap(), isolate_);
int root_nof = root_map_->NumberOfOwnDescriptors();
if (!old_map_->EquivalentToForTransition(*root_map_)) {
return CopyGeneralizeAllRepresentations("GenAll_NotEquivalent");
return CopyGeneralizeAllFields("GenAll_NotEquivalent");
}
ElementsKind from_kind = root_map_->elements_kind();
......@@ -221,7 +220,7 @@ MapUpdater::State MapUpdater::FindRootMap() {
to_kind != SLOW_SLOPPY_ARGUMENTS_ELEMENTS &&
!(IsTransitionableFastElementsKind(from_kind) &&
IsMoreGeneralElementsKindTransition(from_kind, to_kind))) {
return CopyGeneralizeAllRepresentations("GenAll_InvalidElementsTransition");
return CopyGeneralizeAllFields("GenAll_InvalidElementsTransition");
}
if (modified_descriptor_ >= 0 && modified_descriptor_ < root_nof) {
......@@ -229,13 +228,13 @@ MapUpdater::State MapUpdater::FindRootMap() {
old_descriptors_->GetDetails(modified_descriptor_);
if (old_details.kind() != new_kind_ ||
old_details.attributes() != new_attributes_) {
return CopyGeneralizeAllRepresentations("GenAll_RootModification1");
return CopyGeneralizeAllFields("GenAll_RootModification1");
}
if (!new_representation_.fits_into(old_details.representation())) {
return CopyGeneralizeAllRepresentations("GenAll_RootModification2");
return CopyGeneralizeAllFields("GenAll_RootModification2");
}
if (old_details.location() != kField) {
return CopyGeneralizeAllRepresentations("GenAll_RootModification3");
return CopyGeneralizeAllFields("GenAll_RootModification3");
}
DCHECK_EQ(kData, old_details.kind());
DCHECK_EQ(kData, new_kind_);
......@@ -243,7 +242,7 @@ MapUpdater::State MapUpdater::FindRootMap() {
FieldType* old_field_type =
old_descriptors_->GetFieldType(modified_descriptor_);
if (!new_field_type_->NowIs(old_field_type)) {
return CopyGeneralizeAllRepresentations("GenAll_RootModification4");
return CopyGeneralizeAllFields("GenAll_RootModification4");
}
}
......@@ -277,7 +276,7 @@ MapUpdater::State MapUpdater::FindTargetMap() {
if (old_details.kind() == kAccessor &&
!EqualImmutableValues(GetValue(i), tmp_descriptors->GetValue(i))) {
// TODO(ishell): mutable accessors are not implemented yet.
return CopyGeneralizeAllRepresentations("GenAll_Incompatible");
return CopyGeneralizeAllFields("GenAll_Incompatible");
}
// Check if old location fits into tmp location.
if (!LocationFitsInto(old_details.location(), tmp_details.location())) {
......@@ -353,7 +352,7 @@ MapUpdater::State MapUpdater::FindTargetMap() {
#endif
if (old_details.kind() == kAccessor &&
!EqualImmutableValues(GetValue(i), tmp_descriptors->GetValue(i))) {
return CopyGeneralizeAllRepresentations("GenAll_Incompatible");
return CopyGeneralizeAllFields("GenAll_Incompatible");
}
DCHECK(!tmp_map->is_deprecated());
target_map_ = tmp_map;
......@@ -562,7 +561,7 @@ MapUpdater::State MapUpdater::ConstructNewMap() {
// could be inserted regardless of whether transitions array is full or not.
if (maybe_transition == NULL &&
!TransitionArray::CanHaveMoreTransitions(split_map)) {
return CopyGeneralizeAllRepresentations("GenAll_CantHaveMoreTransitions");
return CopyGeneralizeAllFields("GenAll_CantHaveMoreTransitions");
}
old_map_->NotifyLeafMapLayoutChange();
......
......@@ -108,7 +108,7 @@ class MapUpdater {
// When a requested reconfiguration can not be done the result is a copy
// of |old_map_| where every field has |Tagged| representation and |Any|
// field type. This map is disconnected from the transition tree.
State CopyGeneralizeAllRepresentations(const char* reason);
State CopyGeneralizeAllFields(const char* reason);
// Returns name of a |descriptor| property.
inline Name* GetKey(int descriptor) const;
......
......@@ -3075,15 +3075,6 @@ void DescriptorArray::SetSortedKey(int descriptor_index, int pointer) {
}
void DescriptorArray::SetRepresentation(int descriptor_index,
Representation representation) {
DCHECK(!representation.IsNone());
PropertyDetails details = GetDetails(descriptor_index);
set(ToDetailsIndex(descriptor_index),
details.CopyWithRepresentation(representation).AsSmi());
}
Object** DescriptorArray::GetValueSlot(int descriptor_number) {
DCHECK(descriptor_number < number_of_descriptors());
return RawFieldOfElementAt(ToValueIndex(descriptor_number));
......
......@@ -3892,23 +3892,31 @@ int Map::NumberOfFields() {
return result;
}
Handle<Map> Map::CopyGeneralizeAllRepresentations(
Handle<Map> map, ElementsKind elements_kind, int modify_index,
StoreMode store_mode, PropertyKind kind, PropertyAttributes attributes,
void DescriptorArray::GeneralizeAllFields() {
int length = number_of_descriptors();
for (int i = 0; i < length; i++) {
PropertyDetails details = GetDetails(i);
details = details.CopyWithRepresentation(Representation::Tagged());
if (details.location() == kField) {
DCHECK_EQ(kData, details.kind());
SetValue(i, FieldType::Any());
}
set(ToDetailsIndex(i), details.AsSmi());
}
}
Handle<Map> Map::CopyGeneralizeAllFields(Handle<Map> map,
ElementsKind elements_kind,
int modify_index, StoreMode store_mode,
PropertyKind kind,
PropertyAttributes attributes,
const char* reason) {
Isolate* isolate = map->GetIsolate();
Handle<DescriptorArray> old_descriptors(map->instance_descriptors(), isolate);
int number_of_own_descriptors = map->NumberOfOwnDescriptors();
Handle<DescriptorArray> descriptors =
DescriptorArray::CopyUpTo(old_descriptors, number_of_own_descriptors);
for (int i = 0; i < number_of_own_descriptors; i++) {
descriptors->SetRepresentation(i, Representation::Tagged());
if (descriptors->GetDetails(i).location() == kField) {
DCHECK_EQ(kData, descriptors->GetDetails(i).kind());
descriptors->SetValue(i, FieldType::Any());
}
}
descriptors->GeneralizeAllFields();
Handle<LayoutDescriptor> new_layout_descriptor(
LayoutDescriptor::FastPointerLayout(), isolate);
......@@ -4169,9 +4177,8 @@ Handle<Map> Map::ReconfigureElementsKind(Handle<Map> map,
return mu.ReconfigureElementsKind(new_elements_kind);
}
// Generalize the representation of all DATA descriptors.
Handle<Map> Map::GeneralizeAllFieldRepresentations(
Handle<Map> map) {
// Generalize all fields and update the transition tree.
Handle<Map> Map::GeneralizeAllFields(Handle<Map> map) {
Isolate* isolate = map->GetIsolate();
Handle<FieldType> any_type = FieldType::Any(isolate);
......@@ -8843,14 +8850,7 @@ Handle<Map> Map::CopyReplaceDescriptors(
CHECK(maybe_name.ToHandle(&name));
ConnectTransition(map, result, name, simple_flag);
} else {
int length = descriptors->number_of_descriptors();
for (int i = 0; i < length; i++) {
descriptors->SetRepresentation(i, Representation::Tagged());
if (descriptors->GetDetails(i).location() == kField) {
DCHECK_EQ(kData, descriptors->GetDetails(i).kind());
descriptors->SetValue(i, FieldType::Any());
}
}
descriptors->GeneralizeAllFields();
result->InitializeDescriptors(*descriptors,
LayoutDescriptor::FastPointerLayout());
}
......@@ -9258,8 +9258,8 @@ Handle<Map> Map::ReconfigureExistingProperty(Handle<Map> map, int descriptor,
if (!map->GetBackPointer()->IsMap()) {
// There is no benefit from reconstructing transition tree for maps without
// back pointers.
return CopyGeneralizeAllRepresentations(
map, map->elements_kind(), descriptor, FORCE_FIELD, kind, attributes,
return CopyGeneralizeAllFields(map, map->elements_kind(), descriptor,
FORCE_FIELD, kind, attributes,
"GenAll_AttributesMismatchProtoMap");
}
......
......@@ -3244,8 +3244,6 @@ class DescriptorArray: public FixedArray {
inline Name* GetSortedKey(int descriptor_number);
inline int GetSortedKeyIndex(int descriptor_number);
inline void SetSortedKey(int pointer, int descriptor_number);
inline void SetRepresentation(int descriptor_number,
Representation representation);
// Accessor for complete descriptor.
inline void Get(int descriptor_number, Descriptor* desc);
......@@ -3254,6 +3252,9 @@ class DescriptorArray: public FixedArray {
PropertyDetails details);
void Replace(int descriptor_number, Descriptor* descriptor);
// Generalizes representation and field type of all field descriptors.
void GeneralizeAllFields();
// Append automatically sets the enumeration index. This should only be used
// to add descriptors in bulk at the end, followed by sorting the descriptor
// array.
......@@ -6037,7 +6038,7 @@ class Map: public HeapObject {
int target_inobject, int target_unused,
int* old_number_of_fields);
// TODO(ishell): moveit!
static Handle<Map> GeneralizeAllFieldRepresentations(Handle<Map> map);
static Handle<Map> GeneralizeAllFields(Handle<Map> map);
MUST_USE_RESULT static Handle<FieldType> GeneralizeFieldType(
Representation rep1, Handle<FieldType> type1, Representation rep2,
Handle<FieldType> type2, Isolate* isolate);
......@@ -6496,7 +6497,7 @@ class Map: public HeapObject {
PropertyNormalizationMode mode);
// TODO(ishell): Move to MapUpdater.
static Handle<Map> CopyGeneralizeAllRepresentations(
static Handle<Map> CopyGeneralizeAllFields(
Handle<Map> map, ElementsKind elements_kind, int modify_index,
StoreMode store_mode, PropertyKind kind, PropertyAttributes attributes,
const char* reason);
......
......@@ -1237,7 +1237,7 @@ struct CheckUnrelated {
// Checks that given |map| is NOT deprecated, and |new_map| is a result of
// copy-generalize-all-representations.
struct CheckCopyGeneralizeAllRepresentations {
struct CheckCopyGeneralizeAllFields {
void Check(Handle<Map> map, Handle<Map> new_map, Expectations& expectations) {
CHECK(!map->is_deprecated());
CHECK_NE(*map, *new_map);
......@@ -1509,11 +1509,11 @@ TEST(ReconfigureDataFieldAttribute_AccConstantToAccFieldAfterTargetMap) {
TestConfig config;
if (IS_ACCESSOR_FIELD_SUPPORTED) {
CheckCopyGeneralizeAllRepresentations checker;
CheckCopyGeneralizeAllFields checker;
TestReconfigureProperty_CustomPropertyAfterTargetMap(config, checker);
} else {
// Currently we have a copy-generalize-all-representations case.
CheckCopyGeneralizeAllRepresentations checker;
CheckCopyGeneralizeAllFields checker;
TestReconfigureProperty_CustomPropertyAfterTargetMap(config, checker);
}
}
......
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