Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1234)

Unified Diff: src/objects.cc

Issue 1636013002: Replace HeapType with a non-templated FieldType class. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix tracing of generalizations Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/ic/ic.cc ('K') | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 7057e7b70350d3bf549d870dbdf37118988c533e..64225b91cbf6ef711de11eab16244a6d6d43f41b 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -70,20 +70,19 @@ std::ostream& operator<<(std::ostream& os, InstanceType instance_type) {
return os << "UNKNOWN"; // Keep the compiler happy.
}
-
-Handle<HeapType> Object::OptimalType(Isolate* isolate,
- Representation representation) {
- if (representation.IsNone()) return HeapType::None(isolate);
+Handle<FieldType> Object::OptimalType(Isolate* isolate,
+ Representation representation) {
+ if (representation.IsNone()) return FieldType::None(isolate);
if (FLAG_track_field_types) {
if (representation.IsHeapObject() && IsHeapObject()) {
// We can track only JavaScript objects with stable maps.
Handle<Map> map(HeapObject::cast(this)->map(), isolate);
if (map->is_stable() && map->IsJSReceiverMap()) {
- return HeapType::Class(map, isolate);
+ return FieldType::Class(map, isolate);
}
}
}
- return HeapType::Any(isolate);
+ return FieldType::Any(isolate);
}
@@ -2105,17 +2104,12 @@ void Map::PrintReconfiguration(FILE* file, int modify_index, PropertyKind kind,
os << "]\n";
}
-
-void Map::PrintGeneralization(FILE* file,
- const char* reason,
- int modify_index,
- int split,
- int descriptors,
- bool constant_to_field,
- Representation old_representation,
- Representation new_representation,
- HeapType* old_field_type,
- HeapType* new_field_type) {
+void Map::PrintGeneralization(
+ FILE* file, const char* reason, int modify_index, int split,
+ int descriptors, bool constant_to_field, Representation old_representation,
+ Representation new_representation, MaybeHandle<FieldType> old_field_type,
+ MaybeHandle<Object> old_value, MaybeHandle<FieldType> new_field_type,
+ MaybeHandle<Object> new_value) {
OFStream os(file);
os << "[generalizing]";
Name* name = instance_descriptors()->GetKey(modify_index);
@@ -2129,11 +2123,19 @@ void Map::PrintGeneralization(FILE* file,
os << "c";
} else {
os << old_representation.Mnemonic() << "{";
- old_field_type->PrintTo(os, HeapType::SEMANTIC_DIM);
+ if (old_field_type.is_null()) {
+ os << Brief(*(old_value.ToHandleChecked()));
+ } else {
+ old_field_type.ToHandleChecked()->PrintTo(os);
+ }
os << "}";
}
os << "->" << new_representation.Mnemonic() << "{";
- new_field_type->PrintTo(os, HeapType::SEMANTIC_DIM);
+ if (new_field_type.is_null()) {
+ os << Brief(*(new_value.ToHandleChecked()));
+ } else {
+ new_field_type.ToHandleChecked()->PrintTo(os);
+ }
os << "} (";
if (strlen(reason) > 0) {
os << reason;
@@ -2588,16 +2590,13 @@ Context* JSReceiver::GetCreationContext() {
return function->context()->native_context();
}
-
-static Handle<Object> WrapType(Handle<HeapType> type) {
- if (type->IsClass()) return Map::WeakCellForMap(type->AsClass()->Map());
+static Handle<Object> WrapType(Handle<FieldType> type) {
+ if (type->IsClass()) return Map::WeakCellForMap(type->AsClass());
return type;
}
-
-MaybeHandle<Map> Map::CopyWithField(Handle<Map> map,
- Handle<Name> name,
- Handle<HeapType> type,
+MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, Handle<Name> name,
+ Handle<FieldType> type,
PropertyAttributes attributes,
Representation representation,
TransitionFlag flag) {
@@ -2617,7 +2616,7 @@ MaybeHandle<Map> Map::CopyWithField(Handle<Map> map,
if (map->instance_type() == JS_CONTEXT_EXTENSION_OBJECT_TYPE) {
representation = Representation::Tagged();
- type = HeapType::Any(isolate);
+ type = FieldType::Any(isolate);
}
Handle<Object> wrapped_type(WrapType(type));
@@ -3063,7 +3062,7 @@ Handle<Map> Map::CopyGeneralizeAllRepresentations(
for (int i = 0; i < number_of_own_descriptors; i++) {
descriptors->SetRepresentation(i, Representation::Tagged());
if (descriptors->GetDetails(i).type() == DATA) {
- descriptors->SetValue(i, HeapType::Any());
+ descriptors->SetValue(i, FieldType::Any());
}
}
@@ -3095,16 +3094,18 @@ Handle<Map> Map::CopyGeneralizeAllRepresentations(
}
if (FLAG_trace_generalization) {
- HeapType* field_type =
- (details.type() == DATA)
- ? map->instance_descriptors()->GetFieldType(modify_index)
- : NULL;
+ MaybeHandle<FieldType> field_type = FieldType::None(isolate);
+ if (details.type() == DATA) {
+ field_type = handle(
+ map->instance_descriptors()->GetFieldType(modify_index), isolate);
+ }
map->PrintGeneralization(
stdout, reason, modify_index, new_map->NumberOfOwnDescriptors(),
new_map->NumberOfOwnDescriptors(),
details.type() == DATA_CONSTANT && store_mode == FORCE_FIELD,
details.representation(), Representation::Tagged(), field_type,
- HeapType::Any());
+ MaybeHandle<Object>(), FieldType::Any(isolate),
+ MaybeHandle<Object>());
}
}
return new_map;
@@ -3197,7 +3198,7 @@ Map* Map::FindLastMatchMap(int verbatim,
if (!details.representation().Equals(next_details.representation())) break;
if (next_details.location() == kField) {
- HeapType* next_field_type = next_descriptors->GetFieldType(i);
+ FieldType* next_field_type = next_descriptors->GetFieldType(i);
if (!descriptors->GetFieldType(i)->NowIs(next_field_type)) {
break;
}
@@ -3253,42 +3254,41 @@ void Map::UpdateFieldType(int descriptor, Handle<Name> name,
instance_descriptors()->Replace(descriptor, &d);
}
-
-bool FieldTypeIsCleared(Representation rep, HeapType* type) {
- return type->Is(HeapType::None()) && rep.IsHeapObject();
+bool FieldTypeIsCleared(Representation rep, FieldType* type) {
+ return type->IsNone() && rep.IsHeapObject();
}
// static
-Handle<HeapType> Map::GeneralizeFieldType(Representation rep1,
- Handle<HeapType> type1,
- Representation rep2,
- Handle<HeapType> type2,
- Isolate* isolate) {
+Handle<FieldType> Map::GeneralizeFieldType(Representation rep1,
+ Handle<FieldType> type1,
+ Representation rep2,
+ Handle<FieldType> type2,
+ Isolate* isolate) {
// Cleared field types need special treatment. They represent lost knowledge,
// so we must be conservative, so their generalization with any other type
// is "Any".
if (FieldTypeIsCleared(rep1, *type1) || FieldTypeIsCleared(rep2, *type2)) {
- return HeapType::Any(isolate);
+ return FieldType::Any(isolate);
}
if (type1->NowIs(type2)) return type2;
if (type2->NowIs(type1)) return type1;
- return HeapType::Any(isolate);
+ return FieldType::Any(isolate);
}
// static
void Map::GeneralizeFieldType(Handle<Map> map, int modify_index,
Representation new_representation,
- Handle<HeapType> new_field_type) {
+ Handle<FieldType> new_field_type) {
Isolate* isolate = map->GetIsolate();
// Check if we actually need to generalize the field type at all.
Handle<DescriptorArray> old_descriptors(map->instance_descriptors(), isolate);
Representation old_representation =
old_descriptors->GetDetails(modify_index).representation();
- Handle<HeapType> old_field_type(old_descriptors->GetFieldType(modify_index),
- isolate);
+ Handle<FieldType> old_field_type(old_descriptors->GetFieldType(modify_index),
+ isolate);
if (old_representation.Equals(new_representation) &&
!FieldTypeIsCleared(new_representation, *new_field_type) &&
@@ -3322,20 +3322,16 @@ void Map::GeneralizeFieldType(Handle<Map> map, int modify_index,
if (FLAG_trace_generalization) {
map->PrintGeneralization(
- stdout, "field type generalization",
- modify_index, map->NumberOfOwnDescriptors(),
- map->NumberOfOwnDescriptors(), false,
- details.representation(), details.representation(),
- *old_field_type, *new_field_type);
+ stdout, "field type generalization", modify_index,
+ map->NumberOfOwnDescriptors(), map->NumberOfOwnDescriptors(), false,
+ details.representation(), details.representation(), old_field_type,
+ MaybeHandle<Object>(), new_field_type, MaybeHandle<Object>());
}
}
-
-static inline Handle<HeapType> GetFieldType(Isolate* isolate,
- Handle<DescriptorArray> descriptors,
- int descriptor,
- PropertyLocation location,
- Representation representation) {
+static inline Handle<FieldType> GetFieldType(
+ Isolate* isolate, Handle<DescriptorArray> descriptors, int descriptor,
+ PropertyLocation location, Representation representation) {
#ifdef DEBUG
PropertyDetails details = descriptors->GetDetails(descriptor);
DCHECK_EQ(kData, details.kind());
@@ -3380,7 +3376,7 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
PropertyKind new_kind,
PropertyAttributes new_attributes,
Representation new_representation,
- Handle<HeapType> new_field_type,
+ Handle<FieldType> new_field_type,
StoreMode store_mode) {
DCHECK_NE(kAccessor, new_kind); // TODO(ishell): not supported yet.
DCHECK(store_mode != FORCE_FIELD || modify_index >= 0);
@@ -3409,8 +3405,9 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
stdout, "uninitialized field", modify_index,
old_map->NumberOfOwnDescriptors(),
old_map->NumberOfOwnDescriptors(), false, old_representation,
- new_representation, old_descriptors->GetFieldType(modify_index),
- *new_field_type);
+ new_representation,
+ handle(old_descriptors->GetFieldType(modify_index), isolate),
+ MaybeHandle<Object>(), new_field_type, MaybeHandle<Object>());
}
Handle<Map> field_owner(old_map->FindFieldOwner(modify_index), isolate);
@@ -3526,11 +3523,11 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
PropertyLocation tmp_location = tmp_details.location();
if (tmp_location == kField) {
if (next_kind == kData) {
- Handle<HeapType> next_field_type;
+ Handle<FieldType> next_field_type;
if (modify_index == i) {
next_field_type = new_field_type;
if (!property_kind_reconfiguration) {
- Handle<HeapType> old_field_type =
+ Handle<FieldType> old_field_type =
GetFieldType(isolate, old_descriptors, i,
old_details.location(), tmp_representation);
Representation old_representation = old_details.representation();
@@ -3539,7 +3536,7 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
next_field_type, isolate);
}
} else {
- Handle<HeapType> old_field_type =
+ Handle<FieldType> old_field_type =
GetFieldType(isolate, old_descriptors, i, old_details.location(),
tmp_representation);
next_field_type = old_field_type;
@@ -3694,17 +3691,17 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
if (next_location == kField) {
if (next_kind == kData) {
- Handle<HeapType> target_field_type =
+ Handle<FieldType> target_field_type =
GetFieldType(isolate, target_descriptors, i,
target_details.location(), next_representation);
- Handle<HeapType> next_field_type;
+ Handle<FieldType> next_field_type;
if (modify_index == i) {
next_field_type = GeneralizeFieldType(
target_details.representation(), target_field_type,
new_representation, new_field_type, isolate);
if (!property_kind_reconfiguration) {
- Handle<HeapType> old_field_type =
+ Handle<FieldType> old_field_type =
GetFieldType(isolate, old_descriptors, i,
old_details.location(), next_representation);
next_field_type = GeneralizeFieldType(
@@ -3712,7 +3709,7 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
next_representation, next_field_type, isolate);
}
} else {
- Handle<HeapType> old_field_type =
+ Handle<FieldType> old_field_type =
GetFieldType(isolate, old_descriptors, i, old_details.location(),
next_representation);
next_field_type = GeneralizeFieldType(
@@ -3771,11 +3768,11 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
if (next_location == kField) {
if (next_kind == kData) {
- Handle<HeapType> next_field_type;
+ Handle<FieldType> next_field_type;
if (modify_index == i) {
next_field_type = new_field_type;
if (!property_kind_reconfiguration) {
- Handle<HeapType> old_field_type =
+ Handle<FieldType> old_field_type =
GetFieldType(isolate, old_descriptors, i,
old_details.location(), next_representation);
next_field_type = GeneralizeFieldType(
@@ -3783,7 +3780,7 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
next_representation, next_field_type, isolate);
}
} else {
- Handle<HeapType> old_field_type =
+ Handle<FieldType> old_field_type =
GetFieldType(isolate, old_descriptors, i, old_details.location(),
next_representation);
next_field_type = old_field_type;
@@ -3851,23 +3848,28 @@ Handle<Map> Map::ReconfigureProperty(Handle<Map> old_map, int modify_index,
if (FLAG_trace_generalization && modify_index >= 0) {
PropertyDetails old_details = old_descriptors->GetDetails(modify_index);
PropertyDetails new_details = new_descriptors->GetDetails(modify_index);
- Handle<HeapType> old_field_type =
- (old_details.type() == DATA)
- ? handle(old_descriptors->GetFieldType(modify_index), isolate)
- : HeapType::Constant(
- handle(old_descriptors->GetValue(modify_index), isolate),
- isolate);
- Handle<HeapType> new_field_type =
- (new_details.type() == DATA)
- ? handle(new_descriptors->GetFieldType(modify_index), isolate)
- : HeapType::Constant(
- handle(new_descriptors->GetValue(modify_index), isolate),
- isolate);
+ MaybeHandle<FieldType> old_field_type;
+ MaybeHandle<FieldType> new_field_type;
+ MaybeHandle<Object> old_value;
+ MaybeHandle<Object> new_value;
+ if (old_details.type() == DATA) {
+ old_field_type =
+ handle(old_descriptors->GetFieldType(modify_index), isolate);
+ } else {
+ old_value = handle(old_descriptors->GetValue(modify_index), isolate);
+ }
+ if (new_details.type() == DATA) {
+ new_field_type =
+ handle(new_descriptors->GetFieldType(modify_index), isolate);
+ } else {
+ new_value = handle(new_descriptors->GetValue(modify_index), isolate);
+ }
+
old_map->PrintGeneralization(
stdout, "", modify_index, split_nof, old_nof,
old_details.location() == kDescriptor && store_mode == FORCE_FIELD,
old_details.representation(), new_details.representation(),
- *old_field_type, *new_field_type);
+ old_field_type, old_value, new_field_type, new_value);
}
Handle<LayoutDescriptor> new_layout_descriptor =
@@ -3893,7 +3895,7 @@ Handle<Map> Map::GeneralizeAllFieldRepresentations(
if (details.type() == DATA) {
map = ReconfigureProperty(map, i, kData, details.attributes(),
Representation::Tagged(),
- HeapType::Any(map->GetIsolate()), FORCE_FIELD);
+ FieldType::Any(map->GetIsolate()), FORCE_FIELD);
}
}
return map;
@@ -3942,7 +3944,7 @@ MaybeHandle<Map> Map::TryUpdate(Handle<Map> old_map) {
}
switch (new_details.type()) {
case DATA: {
- HeapType* new_type = new_descriptors->GetFieldType(i);
+ FieldType* new_type = new_descriptors->GetFieldType(i);
// Cleared field types need special treatment. They represent lost
// knowledge, so we must first generalize the new_type to "Any".
if (FieldTypeIsCleared(new_details.representation(), new_type)) {
@@ -3950,7 +3952,7 @@ MaybeHandle<Map> Map::TryUpdate(Handle<Map> old_map) {
}
PropertyType old_property_type = old_details.type();
if (old_property_type == DATA) {
- HeapType* old_type = old_descriptors->GetFieldType(i);
+ FieldType* old_type = old_descriptors->GetFieldType(i);
if (FieldTypeIsCleared(old_details.representation(), old_type) ||
!old_type->NowIs(new_type)) {
return MaybeHandle<Map>();
@@ -3966,8 +3968,8 @@ MaybeHandle<Map> Map::TryUpdate(Handle<Map> old_map) {
}
case ACCESSOR: {
#ifdef DEBUG
- HeapType* new_type = new_descriptors->GetFieldType(i);
- DCHECK(HeapType::Any()->Is(new_type));
+ FieldType* new_type = new_descriptors->GetFieldType(i);
+ DCHECK(new_type->IsAny());
#endif
break;
}
@@ -3992,7 +3994,7 @@ MaybeHandle<Map> Map::TryUpdate(Handle<Map> old_map) {
Handle<Map> Map::Update(Handle<Map> map) {
if (!map->is_deprecated()) return map;
return ReconfigureProperty(map, -1, kData, NONE, Representation::None(),
- HeapType::None(map->GetIsolate()),
+ FieldType::None(map->GetIsolate()),
ALLOW_IN_DESCRIPTOR);
}
@@ -9438,7 +9440,7 @@ Handle<Map> Map::CopyReplaceDescriptors(
for (int i = 0; i < length; i++) {
descriptors->SetRepresentation(i, Representation::Tagged());
if (descriptors->GetDetails(i).type() == DATA) {
- descriptors->SetValue(i, HeapType::Any());
+ descriptors->SetValue(i, FieldType::Any());
}
}
result->InitializeDescriptors(*descriptors,
@@ -9790,7 +9792,7 @@ Handle<Map> Map::PrepareForDataProperty(Handle<Map> map, int descriptor,
PropertyAttributes attributes =
descriptors->GetDetails(descriptor).attributes();
Representation representation = value->OptimalRepresentation();
- Handle<HeapType> type = value->OptimalType(isolate, representation);
+ Handle<FieldType> type = value->OptimalType(isolate, representation);
return ReconfigureProperty(map, descriptor, kData, attributes, representation,
type, FORCE_FIELD);
@@ -9827,7 +9829,7 @@ Handle<Map> Map::TransitionToDataProperty(Handle<Map> map, Handle<Name> name,
} else if (!map->TooManyFastProperties(store_mode)) {
Isolate* isolate = name->GetIsolate();
Representation representation = value->OptimalRepresentation();
- Handle<HeapType> type = value->OptimalType(isolate, representation);
+ Handle<FieldType> type = value->OptimalType(isolate, representation);
maybe_map =
Map::CopyWithField(map, name, type, attributes, representation, flag);
}
@@ -9872,7 +9874,7 @@ Handle<Map> Map::ReconfigureExistingProperty(Handle<Map> map, int descriptor,
Isolate* isolate = map->GetIsolate();
Handle<Map> new_map = ReconfigureProperty(
map, descriptor, kind, attributes, Representation::None(),
- HeapType::None(isolate), FORCE_FIELD);
+ FieldType::None(isolate), FORCE_FIELD);
return new_map;
}
« src/ic/ic.cc ('K') | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698