Commit 7a161f64 authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[in-place weak refs] Add missing printing functionality.

In addition, remove the default branch from the swtich in HeapObjectPrint, so
that it's no longer possible to leave out printing functionality by accident.

BUG=v8:7308

Change-Id: I2db67549e328aea6228d3a370f9ebb7494ab3730
Reviewed-on: https://chromium-review.googlesource.com/997492
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52384}
parent 0f190686
......@@ -271,7 +271,36 @@ void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
case FEEDBACK_METADATA_TYPE:
FeedbackMetadata::cast(this)->FeedbackMetadataPrint(os);
break;
default:
case WEAK_FIXED_ARRAY_TYPE:
WeakFixedArray::cast(this)->WeakFixedArrayPrint(os);
break;
case INTERNALIZED_STRING_TYPE:
case EXTERNAL_INTERNALIZED_STRING_TYPE:
case ONE_BYTE_INTERNALIZED_STRING_TYPE:
case EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE:
case EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
case SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE:
case SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE:
case SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
case STRING_TYPE:
case CONS_STRING_TYPE:
case EXTERNAL_STRING_TYPE:
case SLICED_STRING_TYPE:
case THIN_STRING_TYPE:
case ONE_BYTE_STRING_TYPE:
case CONS_ONE_BYTE_STRING_TYPE:
case EXTERNAL_ONE_BYTE_STRING_TYPE:
case SLICED_ONE_BYTE_STRING_TYPE:
case THIN_ONE_BYTE_STRING_TYPE:
case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
case SHORT_EXTERNAL_STRING_TYPE:
case SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE:
case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
case SMALL_ORDERED_HASH_MAP_TYPE:
case SMALL_ORDERED_HASH_SET_TYPE:
case JS_ASYNC_FROM_SYNC_ITERATOR_TYPE:
case JS_STRING_ITERATOR_TYPE:
// TODO(all): Handle these types too.
os << "UNKNOWN TYPE " << map()->instance_type();
UNREACHABLE();
break;
......@@ -686,6 +715,37 @@ void PrintFixedArrayWithHeader(std::ostream& os, FixedArray* array,
PrintFixedArrayElements(os, array);
os << "\n";
}
void PrintWeakFixedArrayElements(std::ostream& os, WeakFixedArray* array) {
// Print in array notation for non-sparse arrays.
MaybeObject* previous_value = array->length() > 0 ? array->Get(0) : nullptr;
MaybeObject* 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() << ": " << MaybeObjectBrief(previous_value);
previous_index = i;
previous_value = value;
}
}
void PrintWeakFixedArrayWithHeader(std::ostream& os, WeakFixedArray* array) {
array->PrintHeader(os, "WeakFixedArray");
os << "\n - length: " << array->length() << "\n";
PrintWeakFixedArrayElements(os, array);
os << "\n";
}
} // namespace
void FixedArray::FixedArrayPrint(std::ostream& os) { // NOLINT
......@@ -712,6 +772,9 @@ void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT
os << "\n";
}
void WeakFixedArray::WeakFixedArrayPrint(std::ostream& os) {
PrintWeakFixedArrayWithHeader(os, this);
}
void TransitionArray::TransitionArrayPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "TransitionArray");
......
......@@ -2511,6 +2511,26 @@ std::ostream& operator<<(std::ostream& os, const Brief& v) {
return os;
}
std::ostream& operator<<(std::ostream& os, const MaybeObjectBrief& v) {
// TODO(marja): const-correct this the same way as the Object* version.
MaybeObject* maybe_object = const_cast<MaybeObject*>(v.value);
Smi* smi;
HeapObject* heap_object;
if (maybe_object->ToSmi(&smi)) {
smi->SmiPrint(os);
} else if (maybe_object->IsClearedWeakHeapObject()) {
os << "[cleared]";
} else if (maybe_object->ToWeakHeapObject(&heap_object)) {
os << "[weak] ";
heap_object->HeapObjectShortPrint(os);
} else if (maybe_object->ToStrongHeapObject(&heap_object)) {
heap_object->HeapObjectShortPrint(os);
} else {
UNREACHABLE();
}
return os;
}
void Smi::SmiPrint(std::ostream& os) const { // NOLINT
os << value();
}
......
......@@ -1566,7 +1566,14 @@ struct Brief {
const Object* value;
};
struct MaybeObjectBrief {
explicit MaybeObjectBrief(const MaybeObject* const v) : value(v) {}
const MaybeObject* value;
};
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, const Brief& v);
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
const MaybeObjectBrief& v);
// Smi represents integer Numbers that can be stored in 31 bits.
// Smis are immediate which means they are NOT allocated in the heap.
......
......@@ -267,6 +267,7 @@ class WeakFixedArray : public HeapObject {
// Gives access to raw memory which stores the array's data.
inline MaybeObject** data_start();
DECL_PRINTER(WeakFixedArray)
DECL_VERIFIER(WeakFixedArray)
class BodyDescriptor;
......
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