Commit aca17974 authored by cbruni's avatar cbruni Committed by Commit bot

[printing] Improve FixedArray debug printing

- condense repeated elements
- print map

BUG=

Review-Url: https://codereview.chromium.org/2626023002
Cr-Commit-Position: refs/heads/master@{#42330}
parent 4caeb1e9
...@@ -327,12 +327,12 @@ void FixedTypedArray<Traits>::FixedTypedArrayPrint( ...@@ -327,12 +327,12 @@ void FixedTypedArray<Traits>::FixedTypedArrayPrint(
os << "fixed " << Traits::Designator(); os << "fixed " << Traits::Designator();
} }
bool JSObject::PrintProperties(std::ostream& os) { // NOLINT
void JSObject::PrintProperties(std::ostream& os) { // NOLINT
if (HasFastProperties()) { if (HasFastProperties()) {
DescriptorArray* descs = map()->instance_descriptors(); DescriptorArray* descs = map()->instance_descriptors();
for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) { int i = 0;
os << "\n "; for (; i < map()->NumberOfOwnDescriptors(); i++) {
os << "\n ";
descs->GetKey(i)->NamePrint(os); descs->GetKey(i)->NamePrint(os);
os << ": "; os << ": ";
PropertyDetails details = descs->GetDetails(i); PropertyDetails details = descs->GetDetails(i);
...@@ -353,11 +353,13 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT ...@@ -353,11 +353,13 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT
os << " "; os << " ";
details.PrintAsFastTo(os, PropertyDetails::kForProperties); details.PrintAsFastTo(os, PropertyDetails::kForProperties);
} }
return i > 0;
} else if (IsJSGlobalObject()) { } else if (IsJSGlobalObject()) {
global_dictionary()->Print(os); global_dictionary()->Print(os);
} else { } else {
property_dictionary()->Print(os); property_dictionary()->Print(os);
} }
return true;
} }
namespace { namespace {
...@@ -376,10 +378,8 @@ bool is_the_hole(double maybe_hole) { ...@@ -376,10 +378,8 @@ bool is_the_hole(double maybe_hole) {
return bit_cast<uint64_t>(maybe_hole) == kHoleNanInt64; return bit_cast<uint64_t>(maybe_hole) == kHoleNanInt64;
} }
} // namespace
template <class T, bool print_the_hole> template <class T, bool print_the_hole>
static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
T* array = T::cast(object); T* array = T::cast(object);
if (array->length() == 0) return; if (array->length() == 0) return;
int previous_index = 0; int previous_index = 0;
...@@ -410,38 +410,42 @@ static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT ...@@ -410,38 +410,42 @@ static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
} }
} }
void PrintFixedArrayElements(std::ostream& os, FixedArray* array) {
// Print in array notation for non-sparse arrays.
Object* previous_value = array->get(0);
Object* value = nullptr;
int previous_index = 0;
int i;
for (i = 1; i <= array->length(); i++) {
if (i < array->length()) value = array->get(i);
if (previous_value == value && i != array->length()) {
continue;
}
os << "\n";
std::stringstream ss;
ss << previous_index;
if (previous_index != i - 1) {
ss << '-' << (i - 1);
}
os << std::setw(12) << ss.str() << ": " << Brief(previous_value);
previous_index = i;
previous_value = value;
}
}
} // namespace
void JSObject::PrintElements(std::ostream& os) { // NOLINT bool JSObject::PrintElements(std::ostream& os) { // NOLINT
// Don't call GetElementsKind, its validation code can cause the printer to // Don't call GetElementsKind, its validation code can cause the printer to
// fail when debugging. // fail when debugging.
if (elements()->length() == 0) return; if (elements()->length() == 0) return false;
switch (map()->elements_kind()) { switch (map()->elements_kind()) {
case FAST_HOLEY_SMI_ELEMENTS: case FAST_HOLEY_SMI_ELEMENTS:
case FAST_SMI_ELEMENTS: case FAST_SMI_ELEMENTS:
case FAST_HOLEY_ELEMENTS: case FAST_HOLEY_ELEMENTS:
case FAST_ELEMENTS: case FAST_ELEMENTS:
case FAST_STRING_WRAPPER_ELEMENTS: { case FAST_STRING_WRAPPER_ELEMENTS: {
// Print in array notation for non-sparse arrays. PrintFixedArrayElements(os, FixedArray::cast(elements()));
FixedArray* array = FixedArray::cast(elements());
Object* previous_value = array->get(0);
Object* value = nullptr;
int previous_index = 0;
int i;
for (i = 1; i <= array->length(); i++) {
if (i < array->length()) value = array->get(i);
if (previous_value == value && i != array->length()) {
continue;
}
os << "\n";
std::stringstream ss;
ss << previous_index;
if (previous_index != i - 1) {
ss << '-' << (i - 1);
}
os << std::setw(12) << ss.str() << ": " << Brief(previous_value);
previous_index = i;
previous_value = value;
}
break; break;
} }
case FAST_HOLEY_DOUBLE_ELEMENTS: case FAST_HOLEY_DOUBLE_ELEMENTS:
...@@ -476,6 +480,7 @@ void JSObject::PrintElements(std::ostream& os) { // NOLINT ...@@ -476,6 +480,7 @@ void JSObject::PrintElements(std::ostream& os) { // NOLINT
case NO_ELEMENTS: case NO_ELEMENTS:
break; break;
} }
return true;
} }
...@@ -507,12 +512,12 @@ static void JSObjectPrintHeader(std::ostream& os, JSObject* obj, ...@@ -507,12 +512,12 @@ static void JSObjectPrintHeader(std::ostream& os, JSObject* obj,
static void JSObjectPrintBody(std::ostream& os, JSObject* obj, // NOLINT static void JSObjectPrintBody(std::ostream& os, JSObject* obj, // NOLINT
bool print_elements = true) { bool print_elements = true) {
os << "\n - properties = " << Brief(obj->properties()) << " {"; os << "\n - properties = " << Brief(obj->properties()) << " {";
obj->PrintProperties(os); if (obj->PrintProperties(os)) os << "\n ";
os << "\n }\n"; os << "}\n";
if (print_elements && obj->elements()->length() > 0) { if (print_elements && obj->elements()->length() > 0) {
os << " - elements = {"; os << " - elements = " << Brief(obj->elements()) << " {";
obj->PrintElements(os); if (obj->PrintElements(os)) os << "\n ";
os << "\n }\n"; os << "}\n";
} }
int internal_fields = obj->GetInternalFieldCount(); int internal_fields = obj->GetInternalFieldCount();
if (internal_fields > 0) { if (internal_fields > 0) {
...@@ -638,25 +643,18 @@ void AliasedArgumentsEntry::AliasedArgumentsEntryPrint( ...@@ -638,25 +643,18 @@ void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(
void FixedArray::FixedArrayPrint(std::ostream& os) { // NOLINT void FixedArray::FixedArrayPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "FixedArray"); HeapObject::PrintHeader(os, "FixedArray");
os << "\n - map = " << Brief(map());
os << "\n - length: " << length(); os << "\n - length: " << length();
for (int i = 0; i < length(); i++) { PrintFixedArrayElements(os, this);
os << "\n [" << i << "]: " << Brief(get(i));
}
os << "\n"; os << "\n";
} }
void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "FixedDoubleArray"); HeapObject::PrintHeader(os, "FixedDoubleArray");
os << "\n - map = " << Brief(map());
os << "\n - length: " << length(); os << "\n - length: " << length();
for (int i = 0; i < length(); i++) { DoPrintElements<FixedDoubleArray, true>(os, this);
os << "\n [" << i << "]: ";
if (is_the_hole(i)) {
os << "<the hole>";
} else {
os << get_scalar(i);
}
}
os << "\n"; os << "\n";
} }
......
...@@ -2568,8 +2568,8 @@ class JSObject: public JSReceiver { ...@@ -2568,8 +2568,8 @@ class JSObject: public JSReceiver {
DECLARE_PRINTER(JSObject) DECLARE_PRINTER(JSObject)
DECLARE_VERIFIER(JSObject) DECLARE_VERIFIER(JSObject)
#ifdef OBJECT_PRINT #ifdef OBJECT_PRINT
void PrintProperties(std::ostream& os); // NOLINT bool PrintProperties(std::ostream& os); // NOLINT
void PrintElements(std::ostream& os); // NOLINT bool PrintElements(std::ostream& os); // NOLINT
#endif #endif
#if defined(DEBUG) || defined(OBJECT_PRINT) #if defined(DEBUG) || defined(OBJECT_PRINT)
void PrintTransitions(std::ostream& os); // NOLINT void PrintTransitions(std::ostream& os); // NOLINT
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
var largeArray = [];
largeArray[0xFFFF00] = 123;
var objects = [
this,
true, false, null, undefined,
1, -1, 1.1, -2.2, -0, 0,
Infinity, -Infinity, NaN,
"aasdfasdfasdfasdf", "a"+"b",
{}, {1:1}, {a:1}, {1:1, 2:2}, Object.create(null),
[], [{}, {}], [1, 1, 1], [1.1, 1.1, 1.1, 1.1, 2], largeArray,
new Proxy({},{}),
new Date(), new String(" a"),
new Uint8Array(12),
/asdf/, new RegExp(),
Object.create, Object, Array,
Symbol.iterator,
[][Symbol.iterator](),
new Map(), new Set(),
(new Map()).entries(), (new Set()).entries()
];
for (var o of objects) %DebugPrint(o);
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