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() {
old_details.representation(), old_field_type, next_representation,
target_field_type, isolate_);
Handle<Object> wrapped_type(Map::WrapType(next_field_type));
Handle<Object> wrapped_type(Map::WrapFieldType(next_field_type));
Descriptor d;
if (next_kind == kData) {
d = Descriptor::DataField(key, current_offset, wrapped_type,
......@@ -476,7 +476,7 @@ Handle<DescriptorArray> MapUpdater::BuildDescriptorArray() {
Handle<FieldType> old_field_type =
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;
if (next_kind == kData) {
d = Descriptor::DataField(key, current_offset, wrapped_type,
......
......@@ -3128,6 +3128,12 @@ int DescriptorArray::GetFieldIndex(int descriptor_number) {
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) {
return GetValue(descriptor_number);
}
......
......@@ -336,10 +336,9 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT
descs->GetKey(i)->NamePrint(os);
os << ": ";
PropertyDetails details = descs->GetDetails(i);
FieldIndex field_index;
switch (details.location()) {
case kField: {
field_index = FieldIndex::ForDescriptor(map(), i);
FieldIndex field_index = FieldIndex::ForDescriptor(map(), i);
if (IsUnboxedDoubleField(field_index)) {
os << "<unboxed double> " << RawFastDoublePropertyAt(field_index);
} else {
......@@ -351,16 +350,8 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT
os << Brief(descs->GetValue(i));
break;
}
os << " (" << (details.kind() == kData ? "data" : "accessor");
switch (details.location()) {
case kField: {
os << " field at offset " << field_index.property_index();
break;
}
case kDescriptor:
break;
}
os << ")";
os << " ";
details.PrintAsFastTo(os, PropertyDetails::kForProperties);
}
} else if (IsJSGlobalObject()) {
global_dictionary()->Print(os);
......@@ -1146,7 +1137,8 @@ void Cell::CellPrint(std::ostream& os) { // NOLINT
void PropertyCell::PropertyCellPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "PropertyCell");
os << "\n - value: " << Brief(value());
os << "\n - details: " << property_details();
os << "\n - details: ";
property_details().PrintAsSlowTo(os);
PropertyCellType cell_type = property_details().cell_type();
os << "\n - cell_type: ";
if (value()->IsTheHole(GetIsolate())) {
......@@ -1588,15 +1580,43 @@ void DescriptorArray::Print() {
void DescriptorArray::PrintDescriptors(std::ostream& os) { // NOLINT
HandleScope scope(GetIsolate());
os << "Descriptor array #" << number_of_descriptors();
os << "Descriptor array #" << number_of_descriptors() << ":";
for (int i = 0; i < number_of_descriptors(); i++) {
Descriptor desc;
Get(i, &desc);
os << "\n " << i << ": " << desc;
Name* key = GetKey(i);
os << "\n [" << i << "]: ";
#ifdef OBJECT_PRINT
key->NamePrint(os);
#else
key->ShortPrint(os);
#endif
os << " ";
PrintDescriptorDetails(os, i, PropertyDetails::kPrintFull);
}
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() {
OFStream os(stdout);
......@@ -1634,20 +1654,13 @@ void TransitionArray::PrintTransitions(std::ostream& os, Object* transitions,
} else if (key == heap->strict_function_transition_symbol()) {
os << " (transition to strict function)";
} else {
PropertyDetails details = GetTargetDetails(key, target);
DCHECK(!IsSpecialTransition(key));
os << "(transition to ";
if (details.location() == kDescriptor) {
os << "immutable ";
}
os << (details.kind() == kData ? "data" : "accessor");
if (details.location() == kDescriptor) {
Object* value =
target->instance_descriptors()->GetValue(target->LastAdded());
os << " " << Brief(value);
} else {
os << " field";
}
os << ", attrs: " << details.attributes() << ")";
int descriptor = target->LastAdded();
DescriptorArray* descriptors = target->instance_descriptors();
descriptors->PrintDescriptorDetails(os, descriptor,
PropertyDetails::kForTransitions);
os << ")";
}
os << " -> " << Brief(target);
}
......
......@@ -3328,11 +3328,20 @@ Context* JSReceiver::GetCreationContext() {
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());
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,
Handle<FieldType> type,
PropertyAttributes attributes,
......@@ -3357,7 +3366,7 @@ MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, Handle<Name> name,
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,
representation);
......@@ -4140,7 +4149,7 @@ void Map::GeneralizeField(Handle<Map> map, int modify_index,
PropertyDetails details = descriptors->GetDetails(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,
wrapped_type);
field_owner->dependent_code()->DeoptimizeDependentCodeGroup(
......@@ -9110,16 +9119,6 @@ Handle<Map> Map::CopyForPreventExtensions(Handle<Map> 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 {
bool CanHoldValue(DescriptorArray* descriptors, int descriptor, Object* value) {
......@@ -15757,7 +15756,8 @@ void Dictionary<Derived, Shape, Key>::Print(std::ostream& os) { // NOLINT
} else {
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 {
inline PropertyDetails GetDetails(int descriptor_number);
inline PropertyType GetType(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* GetCallbacksObject(int descriptor_number);
inline AccessorDescriptor* GetCallbacks(int descriptor_number);
......@@ -3330,6 +3330,9 @@ class DescriptorArray: public FixedArray {
// Print all the descriptors.
void PrintDescriptors(std::ostream& os); // NOLINT
void PrintDescriptorDetails(std::ostream& os, int descriptor,
PropertyDetails::PrintMode mode);
#endif
#ifdef DEBUG
......@@ -6184,7 +6187,8 @@ class Map: public HeapObject {
Descriptor* descriptor,
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(
Handle<Map> map, Handle<Name> name, Handle<FieldType> type,
......
......@@ -375,6 +375,19 @@ class PropertyDetails BASE_EMBEDDED {
void Print(bool dictionary_mode);
#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:
PropertyDetails(int value, int pointer) {
value_ = DescriptorPointer::update(value, pointer);
......@@ -393,7 +406,6 @@ class PropertyDetails BASE_EMBEDDED {
std::ostream& operator<<(std::ostream& os,
const PropertyAttributes& attributes);
std::ostream& operator<<(std::ostream& os, const PropertyDetails& details);
} // namespace internal
} // namespace v8
......
......@@ -29,66 +29,49 @@ Descriptor Descriptor::DataField(Handle<Name> key, int field_index,
representation, field_index);
}
struct FastPropertyDetails {
explicit FastPropertyDetails(const PropertyDetails& v) : details(v) {}
const PropertyDetails details;
};
// Outputs PropertyDetails as a dictionary details.
std::ostream& operator<<(std::ostream& os, const PropertyDetails& details) {
void PropertyDetails::PrintAsSlowTo(std::ostream& os) {
os << "(";
if (details.location() == kDescriptor) {
os << "immutable ";
}
os << (details.kind() == kData ? "data" : "accessor");
return os << ", dictionary_index: " << details.dictionary_index()
<< ", attrs: " << details.attributes() << ")";
os << (kind() == kData ? "data" : "accessor");
os << ", dictionary_index: " << dictionary_index();
os << ", attrs: " << attributes() << ")";
}
// Outputs PropertyDetails as a descriptor array details.
std::ostream& operator<<(std::ostream& os,
const FastPropertyDetails& details_fast) {
const PropertyDetails& details = details_fast.details;
void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) {
os << "(";
if (details.location() == kDescriptor) {
os << "immutable ";
os << (kind() == kData ? "data" : "accessor");
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");
os << ": " << details.representation().Mnemonic();
if (details.location() == kField) {
os << ", field_index: " << details.field_index();
if (mode & kPrintAttributes) {
os << ", attrs: " << attributes();
}
return os << ", p: " << details.pointer()
<< ", attrs: " << details.attributes() << ")";
os << ")";
}
#ifdef OBJECT_PRINT
void PropertyDetails::Print(bool dictionary_mode) {
OFStream os(stdout);
if (dictionary_mode) {
os << *this;
PrintAsSlowTo(os);
} else {
os << FastPropertyDetails(*this);
PrintAsFastTo(os, PrintMode::kPrintFull);
}
os << "\n" << std::flush;
}
#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 v8
......@@ -88,8 +88,6 @@ class Descriptor final BASE_EMBEDDED {
friend class MapUpdater;
};
std::ostream& operator<<(std::ostream& os, const Descriptor& d);
} // namespace internal
} // 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