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,11 +327,11 @@ void FixedTypedArray<Traits>::FixedTypedArrayPrint(
os << "fixed " << Traits::Designator();
}
void JSObject::PrintProperties(std::ostream& os) { // NOLINT
bool JSObject::PrintProperties(std::ostream& os) { // NOLINT
if (HasFastProperties()) {
DescriptorArray* descs = map()->instance_descriptors();
for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
int i = 0;
for (; i < map()->NumberOfOwnDescriptors(); i++) {
os << "\n ";
descs->GetKey(i)->NamePrint(os);
os << ": ";
......@@ -353,11 +353,13 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT
os << " ";
details.PrintAsFastTo(os, PropertyDetails::kForProperties);
}
return i > 0;
} else if (IsJSGlobalObject()) {
global_dictionary()->Print(os);
} else {
property_dictionary()->Print(os);
}
return true;
}
namespace {
......@@ -376,10 +378,8 @@ bool is_the_hole(double maybe_hole) {
return bit_cast<uint64_t>(maybe_hole) == kHoleNanInt64;
}
} // namespace
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);
if (array->length() == 0) return;
int previous_index = 0;
......@@ -410,19 +410,8 @@ static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
}
}
void JSObject::PrintElements(std::ostream& os) { // NOLINT
// Don't call GetElementsKind, its validation code can cause the printer to
// fail when debugging.
if (elements()->length() == 0) return;
switch (map()->elements_kind()) {
case FAST_HOLEY_SMI_ELEMENTS:
case FAST_SMI_ELEMENTS:
case FAST_HOLEY_ELEMENTS:
case FAST_ELEMENTS:
case FAST_STRING_WRAPPER_ELEMENTS: {
void PrintFixedArrayElements(std::ostream& os, FixedArray* array) {
// Print in array notation for non-sparse arrays.
FixedArray* array = FixedArray::cast(elements());
Object* previous_value = array->get(0);
Object* value = nullptr;
int previous_index = 0;
......@@ -442,6 +431,21 @@ void JSObject::PrintElements(std::ostream& os) { // NOLINT
previous_index = i;
previous_value = value;
}
}
} // namespace
bool JSObject::PrintElements(std::ostream& os) { // NOLINT
// Don't call GetElementsKind, its validation code can cause the printer to
// fail when debugging.
if (elements()->length() == 0) return false;
switch (map()->elements_kind()) {
case FAST_HOLEY_SMI_ELEMENTS:
case FAST_SMI_ELEMENTS:
case FAST_HOLEY_ELEMENTS:
case FAST_ELEMENTS:
case FAST_STRING_WRAPPER_ELEMENTS: {
PrintFixedArrayElements(os, FixedArray::cast(elements()));
break;
}
case FAST_HOLEY_DOUBLE_ELEMENTS:
......@@ -476,6 +480,7 @@ void JSObject::PrintElements(std::ostream& os) { // NOLINT
case NO_ELEMENTS:
break;
}
return true;
}
......@@ -507,12 +512,12 @@ static void JSObjectPrintHeader(std::ostream& os, JSObject* obj,
static void JSObjectPrintBody(std::ostream& os, JSObject* obj, // NOLINT
bool print_elements = true) {
os << "\n - properties = " << Brief(obj->properties()) << " {";
obj->PrintProperties(os);
os << "\n }\n";
if (obj->PrintProperties(os)) os << "\n ";
os << "}\n";
if (print_elements && obj->elements()->length() > 0) {
os << " - elements = {";
obj->PrintElements(os);
os << "\n }\n";
os << " - elements = " << Brief(obj->elements()) << " {";
if (obj->PrintElements(os)) os << "\n ";
os << "}\n";
}
int internal_fields = obj->GetInternalFieldCount();
if (internal_fields > 0) {
......@@ -638,25 +643,18 @@ void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(
void FixedArray::FixedArrayPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "FixedArray");
os << "\n - map = " << Brief(map());
os << "\n - length: " << length();
for (int i = 0; i < length(); i++) {
os << "\n [" << i << "]: " << Brief(get(i));
}
PrintFixedArrayElements(os, this);
os << "\n";
}
void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "FixedDoubleArray");
os << "\n - map = " << Brief(map());
os << "\n - length: " << length();
for (int i = 0; i < length(); i++) {
os << "\n [" << i << "]: ";
if (is_the_hole(i)) {
os << "<the hole>";
} else {
os << get_scalar(i);
}
}
DoPrintElements<FixedDoubleArray, true>(os, this);
os << "\n";
}
......
......@@ -2568,8 +2568,8 @@ class JSObject: public JSReceiver {
DECLARE_PRINTER(JSObject)
DECLARE_VERIFIER(JSObject)
#ifdef OBJECT_PRINT
void PrintProperties(std::ostream& os); // NOLINT
void PrintElements(std::ostream& os); // NOLINT
bool PrintProperties(std::ostream& os); // NOLINT
bool PrintElements(std::ostream& os); // NOLINT
#endif
#if defined(DEBUG) || defined(OBJECT_PRINT)
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