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