Commit 5d85e8cc authored by ishell's avatar ishell Committed by Commit bot

[printing] Remove duplicate code that prints property details.

BUG=

Review-Url: https://codereview.chromium.org/2627003005
Cr-Commit-Position: refs/heads/master@{#42291}
parent 40f9b0d7
...@@ -434,7 +434,7 @@ Handle<DescriptorArray> MapUpdater::BuildDescriptorArray() { ...@@ -434,7 +434,7 @@ Handle<DescriptorArray> MapUpdater::BuildDescriptorArray() {
old_details.representation(), old_field_type, next_representation, old_details.representation(), old_field_type, next_representation,
target_field_type, isolate_); target_field_type, isolate_);
Handle<Object> wrapped_type(Map::WrapType(next_field_type)); Handle<Object> wrapped_type(Map::WrapFieldType(next_field_type));
Descriptor d; Descriptor d;
if (next_kind == kData) { if (next_kind == kData) {
d = Descriptor::DataField(key, current_offset, wrapped_type, d = Descriptor::DataField(key, current_offset, wrapped_type,
...@@ -476,7 +476,7 @@ Handle<DescriptorArray> MapUpdater::BuildDescriptorArray() { ...@@ -476,7 +476,7 @@ Handle<DescriptorArray> MapUpdater::BuildDescriptorArray() {
Handle<FieldType> old_field_type = Handle<FieldType> old_field_type =
GetOrComputeFieldType(i, old_details.location(), next_representation); GetOrComputeFieldType(i, old_details.location(), next_representation);
Handle<Object> wrapped_type(Map::WrapType(old_field_type)); Handle<Object> wrapped_type(Map::WrapFieldType(old_field_type));
Descriptor d; Descriptor d;
if (next_kind == kData) { if (next_kind == kData) {
d = Descriptor::DataField(key, current_offset, wrapped_type, d = Descriptor::DataField(key, current_offset, wrapped_type,
......
...@@ -3128,6 +3128,12 @@ int DescriptorArray::GetFieldIndex(int descriptor_number) { ...@@ -3128,6 +3128,12 @@ int DescriptorArray::GetFieldIndex(int descriptor_number) {
return GetDetails(descriptor_number).field_index(); return GetDetails(descriptor_number).field_index();
} }
FieldType* DescriptorArray::GetFieldType(int descriptor_number) {
DCHECK(GetDetails(descriptor_number).location() == kField);
Object* wrapped_type = GetValue(descriptor_number);
return Map::UnwrapFieldType(wrapped_type);
}
Object* DescriptorArray::GetConstant(int descriptor_number) { Object* DescriptorArray::GetConstant(int descriptor_number) {
return GetValue(descriptor_number); return GetValue(descriptor_number);
} }
......
...@@ -336,10 +336,9 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT ...@@ -336,10 +336,9 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT
descs->GetKey(i)->NamePrint(os); descs->GetKey(i)->NamePrint(os);
os << ": "; os << ": ";
PropertyDetails details = descs->GetDetails(i); PropertyDetails details = descs->GetDetails(i);
FieldIndex field_index;
switch (details.location()) { switch (details.location()) {
case kField: { case kField: {
field_index = FieldIndex::ForDescriptor(map(), i); FieldIndex field_index = FieldIndex::ForDescriptor(map(), i);
if (IsUnboxedDoubleField(field_index)) { if (IsUnboxedDoubleField(field_index)) {
os << "<unboxed double> " << RawFastDoublePropertyAt(field_index); os << "<unboxed double> " << RawFastDoublePropertyAt(field_index);
} else { } else {
...@@ -351,16 +350,8 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT ...@@ -351,16 +350,8 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT
os << Brief(descs->GetValue(i)); os << Brief(descs->GetValue(i));
break; break;
} }
os << " (" << (details.kind() == kData ? "data" : "accessor"); os << " ";
switch (details.location()) { details.PrintAsFastTo(os, PropertyDetails::kForProperties);
case kField: {
os << " field at offset " << field_index.property_index();
break;
}
case kDescriptor:
break;
}
os << ")";
} }
} else if (IsJSGlobalObject()) { } else if (IsJSGlobalObject()) {
global_dictionary()->Print(os); global_dictionary()->Print(os);
...@@ -1146,7 +1137,8 @@ void Cell::CellPrint(std::ostream& os) { // NOLINT ...@@ -1146,7 +1137,8 @@ void Cell::CellPrint(std::ostream& os) { // NOLINT
void PropertyCell::PropertyCellPrint(std::ostream& os) { // NOLINT void PropertyCell::PropertyCellPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "PropertyCell"); HeapObject::PrintHeader(os, "PropertyCell");
os << "\n - value: " << Brief(value()); os << "\n - value: " << Brief(value());
os << "\n - details: " << property_details(); os << "\n - details: ";
property_details().PrintAsSlowTo(os);
PropertyCellType cell_type = property_details().cell_type(); PropertyCellType cell_type = property_details().cell_type();
os << "\n - cell_type: "; os << "\n - cell_type: ";
if (value()->IsTheHole(GetIsolate())) { if (value()->IsTheHole(GetIsolate())) {
...@@ -1588,15 +1580,43 @@ void DescriptorArray::Print() { ...@@ -1588,15 +1580,43 @@ void DescriptorArray::Print() {
void DescriptorArray::PrintDescriptors(std::ostream& os) { // NOLINT void DescriptorArray::PrintDescriptors(std::ostream& os) { // NOLINT
HandleScope scope(GetIsolate()); HandleScope scope(GetIsolate());
os << "Descriptor array #" << number_of_descriptors(); os << "Descriptor array #" << number_of_descriptors() << ":";
for (int i = 0; i < number_of_descriptors(); i++) { for (int i = 0; i < number_of_descriptors(); i++) {
Descriptor desc; Name* key = GetKey(i);
Get(i, &desc); os << "\n [" << i << "]: ";
os << "\n " << i << ": " << desc; #ifdef OBJECT_PRINT
key->NamePrint(os);
#else
key->ShortPrint(os);
#endif
os << " ";
PrintDescriptorDetails(os, i, PropertyDetails::kPrintFull);
} }
os << "\n"; os << "\n";
} }
void DescriptorArray::PrintDescriptorDetails(std::ostream& os, int descriptor,
PropertyDetails::PrintMode mode) {
PropertyDetails details = GetDetails(descriptor);
details.PrintAsFastTo(os, mode);
os << " @ ";
Object* value = GetValue(descriptor);
switch (details.location()) {
case kField: {
FieldType* field_type = Map::UnwrapFieldType(value);
field_type->PrintTo(os);
break;
}
case kDescriptor:
os << Brief(value);
if (value->IsAccessorPair()) {
AccessorPair* pair = AccessorPair::cast(value);
os << "(get: " << Brief(pair->getter())
<< ", set: " << Brief(pair->setter()) << ")";
}
break;
}
}
void TransitionArray::Print() { void TransitionArray::Print() {
OFStream os(stdout); OFStream os(stdout);
...@@ -1634,20 +1654,13 @@ void TransitionArray::PrintTransitions(std::ostream& os, Object* transitions, ...@@ -1634,20 +1654,13 @@ void TransitionArray::PrintTransitions(std::ostream& os, Object* transitions,
} else if (key == heap->strict_function_transition_symbol()) { } else if (key == heap->strict_function_transition_symbol()) {
os << " (transition to strict function)"; os << " (transition to strict function)";
} else { } else {
PropertyDetails details = GetTargetDetails(key, target); DCHECK(!IsSpecialTransition(key));
os << "(transition to "; os << "(transition to ";
if (details.location() == kDescriptor) { int descriptor = target->LastAdded();
os << "immutable "; DescriptorArray* descriptors = target->instance_descriptors();
} descriptors->PrintDescriptorDetails(os, descriptor,
os << (details.kind() == kData ? "data" : "accessor"); PropertyDetails::kForTransitions);
if (details.location() == kDescriptor) { os << ")";
Object* value =
target->instance_descriptors()->GetValue(target->LastAdded());
os << " " << Brief(value);
} else {
os << " field";
}
os << ", attrs: " << details.attributes() << ")";
} }
os << " -> " << Brief(target); os << " -> " << Brief(target);
} }
......
...@@ -3328,11 +3328,20 @@ Context* JSReceiver::GetCreationContext() { ...@@ -3328,11 +3328,20 @@ Context* JSReceiver::GetCreationContext() {
return function->context()->native_context(); return function->context()->native_context();
} }
Handle<Object> Map::WrapType(Handle<FieldType> type) { Handle<Object> Map::WrapFieldType(Handle<FieldType> type) {
if (type->IsClass()) return Map::WeakCellForMap(type->AsClass()); if (type->IsClass()) return Map::WeakCellForMap(type->AsClass());
return type; return type;
} }
FieldType* Map::UnwrapFieldType(Object* wrapped_type) {
Object* value = wrapped_type;
if (value->IsWeakCell()) {
if (WeakCell::cast(value)->cleared()) return FieldType::None();
value = WeakCell::cast(value)->value();
}
return FieldType::cast(value);
}
MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, Handle<Name> name, MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, Handle<Name> name,
Handle<FieldType> type, Handle<FieldType> type,
PropertyAttributes attributes, PropertyAttributes attributes,
...@@ -3357,7 +3366,7 @@ MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, Handle<Name> name, ...@@ -3357,7 +3366,7 @@ MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, Handle<Name> name,
type = FieldType::Any(isolate); type = FieldType::Any(isolate);
} }
Handle<Object> wrapped_type(WrapType(type)); Handle<Object> wrapped_type(WrapFieldType(type));
Descriptor d = Descriptor::DataField(name, index, wrapped_type, attributes, Descriptor d = Descriptor::DataField(name, index, wrapped_type, attributes,
representation); representation);
...@@ -4140,7 +4149,7 @@ void Map::GeneralizeField(Handle<Map> map, int modify_index, ...@@ -4140,7 +4149,7 @@ void Map::GeneralizeField(Handle<Map> map, int modify_index,
PropertyDetails details = descriptors->GetDetails(modify_index); PropertyDetails details = descriptors->GetDetails(modify_index);
Handle<Name> name(descriptors->GetKey(modify_index)); Handle<Name> name(descriptors->GetKey(modify_index));
Handle<Object> wrapped_type(WrapType(new_field_type)); Handle<Object> wrapped_type(WrapFieldType(new_field_type));
field_owner->UpdateFieldType(modify_index, name, new_representation, field_owner->UpdateFieldType(modify_index, name, new_representation,
wrapped_type); wrapped_type);
field_owner->dependent_code()->DeoptimizeDependentCodeGroup( field_owner->dependent_code()->DeoptimizeDependentCodeGroup(
...@@ -9110,16 +9119,6 @@ Handle<Map> Map::CopyForPreventExtensions(Handle<Map> map, ...@@ -9110,16 +9119,6 @@ Handle<Map> Map::CopyForPreventExtensions(Handle<Map> map,
return new_map; return new_map;
} }
FieldType* DescriptorArray::GetFieldType(int descriptor_number) {
DCHECK(GetDetails(descriptor_number).location() == kField);
Object* value = GetValue(descriptor_number);
if (value->IsWeakCell()) {
if (WeakCell::cast(value)->cleared()) return FieldType::None();
value = WeakCell::cast(value)->value();
}
return FieldType::cast(value);
}
namespace { namespace {
bool CanHoldValue(DescriptorArray* descriptors, int descriptor, Object* value) { bool CanHoldValue(DescriptorArray* descriptors, int descriptor, Object* value) {
...@@ -15757,7 +15756,8 @@ void Dictionary<Derived, Shape, Key>::Print(std::ostream& os) { // NOLINT ...@@ -15757,7 +15756,8 @@ void Dictionary<Derived, Shape, Key>::Print(std::ostream& os) { // NOLINT
} else { } else {
os << Brief(k); os << Brief(k);
} }
os << ": " << Brief(this->ValueAt(i)) << " " << this->DetailsAt(i); os << ": " << Brief(this->ValueAt(i)) << " ";
this->DetailsAt(i).PrintAsSlowTo(os);
} }
} }
} }
......
...@@ -3247,7 +3247,7 @@ class DescriptorArray: public FixedArray { ...@@ -3247,7 +3247,7 @@ class DescriptorArray: public FixedArray {
inline PropertyDetails GetDetails(int descriptor_number); inline PropertyDetails GetDetails(int descriptor_number);
inline PropertyType GetType(int descriptor_number); inline PropertyType GetType(int descriptor_number);
inline int GetFieldIndex(int descriptor_number); inline int GetFieldIndex(int descriptor_number);
FieldType* GetFieldType(int descriptor_number); inline FieldType* GetFieldType(int descriptor_number);
inline Object* GetConstant(int descriptor_number); inline Object* GetConstant(int descriptor_number);
inline Object* GetCallbacksObject(int descriptor_number); inline Object* GetCallbacksObject(int descriptor_number);
inline AccessorDescriptor* GetCallbacks(int descriptor_number); inline AccessorDescriptor* GetCallbacks(int descriptor_number);
...@@ -3330,6 +3330,9 @@ class DescriptorArray: public FixedArray { ...@@ -3330,6 +3330,9 @@ class DescriptorArray: public FixedArray {
// Print all the descriptors. // Print all the descriptors.
void PrintDescriptors(std::ostream& os); // NOLINT void PrintDescriptors(std::ostream& os); // NOLINT
void PrintDescriptorDetails(std::ostream& os, int descriptor,
PropertyDetails::PrintMode mode);
#endif #endif
#ifdef DEBUG #ifdef DEBUG
...@@ -6184,7 +6187,8 @@ class Map: public HeapObject { ...@@ -6184,7 +6187,8 @@ class Map: public HeapObject {
Descriptor* descriptor, Descriptor* descriptor,
TransitionFlag flag); TransitionFlag flag);
static Handle<Object> WrapType(Handle<FieldType> type); static Handle<Object> WrapFieldType(Handle<FieldType> type);
static FieldType* UnwrapFieldType(Object* wrapped_type);
MUST_USE_RESULT static MaybeHandle<Map> CopyWithField( MUST_USE_RESULT static MaybeHandle<Map> CopyWithField(
Handle<Map> map, Handle<Name> name, Handle<FieldType> type, Handle<Map> map, Handle<Name> name, Handle<FieldType> type,
......
...@@ -375,6 +375,19 @@ class PropertyDetails BASE_EMBEDDED { ...@@ -375,6 +375,19 @@ class PropertyDetails BASE_EMBEDDED {
void Print(bool dictionary_mode); void Print(bool dictionary_mode);
#endif #endif
enum PrintMode {
kPrintAttributes = 1 << 0,
kPrintFieldIndex = 1 << 1,
kPrintRepresentation = 1 << 2,
kPrintPointer = 1 << 3,
kForProperties = kPrintFieldIndex,
kForTransitions = kPrintAttributes,
kPrintFull = -1,
};
void PrintAsSlowTo(std::ostream& out);
void PrintAsFastTo(std::ostream& out, PrintMode mode = kPrintFull);
private: private:
PropertyDetails(int value, int pointer) { PropertyDetails(int value, int pointer) {
value_ = DescriptorPointer::update(value, pointer); value_ = DescriptorPointer::update(value, pointer);
...@@ -393,7 +406,6 @@ class PropertyDetails BASE_EMBEDDED { ...@@ -393,7 +406,6 @@ class PropertyDetails BASE_EMBEDDED {
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os,
const PropertyAttributes& attributes); const PropertyAttributes& attributes);
std::ostream& operator<<(std::ostream& os, const PropertyDetails& details);
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -29,66 +29,49 @@ Descriptor Descriptor::DataField(Handle<Name> key, int field_index, ...@@ -29,66 +29,49 @@ Descriptor Descriptor::DataField(Handle<Name> key, int field_index,
representation, field_index); representation, field_index);
} }
struct FastPropertyDetails {
explicit FastPropertyDetails(const PropertyDetails& v) : details(v) {}
const PropertyDetails details;
};
// Outputs PropertyDetails as a dictionary details. // Outputs PropertyDetails as a dictionary details.
std::ostream& operator<<(std::ostream& os, const PropertyDetails& details) { void PropertyDetails::PrintAsSlowTo(std::ostream& os) {
os << "("; os << "(";
if (details.location() == kDescriptor) { os << (kind() == kData ? "data" : "accessor");
os << "immutable "; os << ", dictionary_index: " << dictionary_index();
} os << ", attrs: " << attributes() << ")";
os << (details.kind() == kData ? "data" : "accessor");
return os << ", dictionary_index: " << details.dictionary_index()
<< ", attrs: " << details.attributes() << ")";
} }
// Outputs PropertyDetails as a descriptor array details. // Outputs PropertyDetails as a descriptor array details.
std::ostream& operator<<(std::ostream& os, void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) {
const FastPropertyDetails& details_fast) {
const PropertyDetails& details = details_fast.details;
os << "("; os << "(";
if (details.location() == kDescriptor) { os << (kind() == kData ? "data" : "accessor");
os << "immutable "; if (location() == kField) {
os << " field";
if (mode & kPrintFieldIndex) {
os << " " << field_index();
}
if (mode & kPrintRepresentation) {
os << ":" << representation().Mnemonic();
}
} else {
os << " descriptor";
}
if (mode & kPrintPointer) {
os << ", p: " << pointer();
} }
os << (details.kind() == kData ? "data" : "accessor"); if (mode & kPrintAttributes) {
os << ": " << details.representation().Mnemonic(); os << ", attrs: " << attributes();
if (details.location() == kField) {
os << ", field_index: " << details.field_index();
} }
return os << ", p: " << details.pointer() os << ")";
<< ", attrs: " << details.attributes() << ")";
} }
#ifdef OBJECT_PRINT #ifdef OBJECT_PRINT
void PropertyDetails::Print(bool dictionary_mode) { void PropertyDetails::Print(bool dictionary_mode) {
OFStream os(stdout); OFStream os(stdout);
if (dictionary_mode) { if (dictionary_mode) {
os << *this; PrintAsSlowTo(os);
} else { } else {
os << FastPropertyDetails(*this); PrintAsFastTo(os, PrintMode::kPrintFull);
} }
os << "\n" << std::flush; os << "\n" << std::flush;
} }
#endif #endif
std::ostream& operator<<(std::ostream& os, const Descriptor& d) {
Object* value = *d.GetValue();
os << "Descriptor " << Brief(*d.GetKey()) << " @ " << Brief(value) << " ";
if (value->IsAccessorPair()) {
AccessorPair* pair = AccessorPair::cast(value);
os << "(get: " << Brief(pair->getter())
<< ", set: " << Brief(pair->setter()) << ") ";
}
os << FastPropertyDetails(d.GetDetails());
return os;
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -88,8 +88,6 @@ class Descriptor final BASE_EMBEDDED { ...@@ -88,8 +88,6 @@ class Descriptor final BASE_EMBEDDED {
friend class MapUpdater; friend class MapUpdater;
}; };
std::ostream& operator<<(std::ostream& os, const Descriptor& d);
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
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