diff options
Diffstat (limited to 'deps/v8/src/objects-printer.cc')
-rw-r--r-- | deps/v8/src/objects-printer.cc | 300 |
1 files changed, 181 insertions, 119 deletions
diff --git a/deps/v8/src/objects-printer.cc b/deps/v8/src/objects-printer.cc index 83e00b9f5f..1f10b9235d 100644 --- a/deps/v8/src/objects-printer.cc +++ b/deps/v8/src/objects-printer.cc @@ -7,6 +7,7 @@ #include <iomanip> #include <memory> +#include "src/bootstrapper.h" #include "src/disasm.h" #include "src/disassembler.h" #include "src/interpreter/bytecodes.h" @@ -149,11 +150,14 @@ void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT case JS_SPECIAL_API_OBJECT_TYPE: case JS_CONTEXT_EXTENSION_OBJECT_TYPE: case JS_GENERATOR_OBJECT_TYPE: - case JS_PROMISE_TYPE: case JS_ARGUMENTS_TYPE: case JS_ERROR_TYPE: + case JS_PROMISE_CAPABILITY_TYPE: JSObject::cast(this)->JSObjectPrint(os); break; + case JS_PROMISE_TYPE: + JSPromise::cast(this)->JSPromisePrint(os); + break; case JS_ARRAY_TYPE: JSArray::cast(this)->JSArrayPrint(os); break; @@ -232,9 +236,6 @@ void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT case JS_TYPED_ARRAY_TYPE: JSTypedArray::cast(this)->JSTypedArrayPrint(os); break; - case JS_FIXED_ARRAY_ITERATOR_TYPE: - JSFixedArrayIterator::cast(this)->JSFixedArrayIteratorPrint(os); - break; case JS_DATA_VIEW_TYPE: JSDataView::cast(this)->JSDataViewPrint(os); break; @@ -326,43 +327,39 @@ 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++) { - os << "\n "; + int i = 0; + for (; i < map()->NumberOfOwnDescriptors(); i++) { + os << "\n "; descs->GetKey(i)->NamePrint(os); os << ": "; - switch (descs->GetType(i)) { - case DATA: { - FieldIndex index = FieldIndex::ForDescriptor(map(), i); - if (IsUnboxedDoubleField(index)) { - os << "<unboxed double> " << RawFastDoublePropertyAt(index); + PropertyDetails details = descs->GetDetails(i); + switch (details.location()) { + case kField: { + FieldIndex field_index = FieldIndex::ForDescriptor(map(), i); + if (IsUnboxedDoubleField(field_index)) { + os << "<unboxed double> " << RawFastDoublePropertyAt(field_index); } else { - os << Brief(RawFastPropertyAt(index)); + os << Brief(RawFastPropertyAt(field_index)); } - os << " (data field at offset " << index.property_index() << ")"; - break; - } - case ACCESSOR: { - FieldIndex index = FieldIndex::ForDescriptor(map(), i); - os << " (accessor field at offset " << index.property_index() << ")"; break; } - case DATA_CONSTANT: - os << Brief(descs->GetConstant(i)) << " (data constant)"; - break; - case ACCESSOR_CONSTANT: - os << Brief(descs->GetCallbacksObject(i)) << " (accessor constant)"; + case kDescriptor: + os << Brief(descs->GetValue(i)); break; } + os << " "; + details.PrintAsFastTo(os, PropertyDetails::kForProperties); } + return i > 0; } else if (IsJSGlobalObject()) { global_dictionary()->Print(os); } else { property_dictionary()->Print(os); } + return true; } namespace { @@ -381,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; @@ -415,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 // fail when debugging. - if (elements()->length() == 0) return; + 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: { - // 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; - 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; - } + PrintFixedArrayElements(os, FixedArray::cast(elements())); break; } case FAST_HOLEY_DOUBLE_ELEMENTS: @@ -481,6 +480,7 @@ void JSObject::PrintElements(std::ostream& os) { // NOLINT case NO_ELEMENTS: break; } + return true; } @@ -511,19 +511,19 @@ static void JSObjectPrintHeader(std::ostream& os, JSObject* obj, static void JSObjectPrintBody(std::ostream& os, JSObject* obj, // NOLINT bool print_elements = true) { - os << "\n - properties = {"; - obj->PrintProperties(os); - os << "\n }\n"; + os << "\n - properties = " << Brief(obj->properties()) << " {"; + 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) { os << " - internal fields = {"; for (int i = 0; i < internal_fields; i++) { - os << "\n " << Brief(obj->GetInternalField(i)); + os << "\n " << obj->GetInternalField(i); } os << "\n }\n"; } @@ -541,6 +541,17 @@ void JSArray::JSArrayPrint(std::ostream& os) { // NOLINT JSObjectPrintBody(os, this); } +void JSPromise::JSPromisePrint(std::ostream& os) { // NOLINT + JSObjectPrintHeader(os, this, "JSPromise"); + os << "\n - status = " << JSPromise::Status(status()); + os << "\n - result = " << Brief(result()); + os << "\n - deferred_promise: " << Brief(deferred_promise()); + os << "\n - deferred_on_resolve: " << Brief(deferred_on_resolve()); + os << "\n - deferred_on_reject: " << Brief(deferred_on_reject()); + os << "\n - fulfill_reactions = " << Brief(fulfill_reactions()); + os << "\n - reject_reactions = " << Brief(reject_reactions()); + os << "\n - has_handler = " << has_handler(); +} void JSRegExp::JSRegExpPrint(std::ostream& os) { // NOLINT JSObjectPrintHeader(os, this, "JSRegExp"); @@ -578,6 +589,7 @@ void Map::MapPrint(std::ostream& os) { // NOLINT } if (is_deprecated()) os << "\n - deprecated_map"; if (is_stable()) os << "\n - stable_map"; + if (is_migration_target()) os << "\n - migration_target"; if (is_dictionary_map()) os << "\n - dictionary_map"; if (has_hidden_prototype()) os << "\n - has_hidden_prototype"; if (has_named_interceptor()) os << "\n - named_interceptor"; @@ -597,7 +609,8 @@ void Map::MapPrint(std::ostream& os) { // NOLINT << "#" << NumberOfOwnDescriptors() << ": " << Brief(instance_descriptors()); if (FLAG_unbox_double_fields) { - os << "\n - layout descriptor: " << Brief(layout_descriptor()); + os << "\n - layout descriptor: "; + layout_descriptor()->ShortPrint(os); } int nof_transitions = TransitionArray::NumberOfTransitions(raw_transitions()); if (nof_transitions > 0) { @@ -631,25 +644,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"; } @@ -686,16 +692,11 @@ void FeedbackVectorSpecBase<Derived>::FeedbackVectorSpecPrint( return; } - for (int slot = 0, name_index = 0; slot < slot_count;) { + for (int slot = 0; slot < slot_count;) { FeedbackVectorSlotKind kind = This()->GetKind(slot); int entry_size = TypeFeedbackMetadata::GetSlotSize(kind); DCHECK_LT(0, entry_size); - os << "\n Slot #" << slot << " " << kind; - if (TypeFeedbackMetadata::SlotRequiresName(kind)) { - os << ", " << Brief(*This()->GetName(name_index++)); - } - slot += entry_size; } os << "\n"; @@ -719,12 +720,14 @@ void TypeFeedbackMetadata::TypeFeedbackMetadataPrint( os << "\n - slot_count: " << slot_count(); TypeFeedbackMetadataIterator iter(this); + int parameter_index = 0; while (iter.HasNext()) { FeedbackVectorSlot slot = iter.Next(); FeedbackVectorSlotKind kind = iter.kind(); os << "\n Slot " << slot << " " << kind; - if (TypeFeedbackMetadata::SlotRequiresName(kind)) { - os << ", " << Brief(iter.name()); + if (TypeFeedbackMetadata::SlotRequiresParameter(kind)) { + int parameter_value = this->GetParameter(parameter_index++); + os << " [" << parameter_value << "]"; } } os << "\n"; @@ -746,15 +749,13 @@ void TypeFeedbackVector::TypeFeedbackVectorPrint(std::ostream& os) { // NOLINT return; } + int parameter_index = 0; TypeFeedbackMetadataIterator iter(metadata()); while (iter.HasNext()) { FeedbackVectorSlot slot = iter.Next(); FeedbackVectorSlotKind kind = iter.kind(); os << "\n Slot " << slot << " " << kind; - if (TypeFeedbackMetadata::SlotRequiresName(kind)) { - os << ", " << Brief(iter.name()); - } os << " "; switch (kind) { case FeedbackVectorSlotKind::LOAD_IC: { @@ -797,6 +798,17 @@ void TypeFeedbackVector::TypeFeedbackVectorPrint(std::ostream& os) { // NOLINT os << Code::ICState2String(nexus.StateFromFeedback()); break; } + case FeedbackVectorSlotKind::STORE_DATA_PROPERTY_IN_LITERAL_IC: { + StoreDataPropertyInLiteralICNexus nexus(this, slot); + os << Code::ICState2String(nexus.StateFromFeedback()); + break; + } + case FeedbackVectorSlotKind::CREATE_CLOSURE: { + // TODO(mvstanton): Integrate this into the iterator. + int parameter_value = metadata()->GetParameter(parameter_index++); + os << "[" << parameter_value << "]"; + break; + } case FeedbackVectorSlotKind::GENERAL: break; case FeedbackVectorSlotKind::INVALID: @@ -1011,15 +1023,6 @@ void JSArrayIterator::JSArrayIteratorPrint(std::ostream& os) { // NOLING JSObjectPrintBody(os, this); } -void JSFixedArrayIterator::JSFixedArrayIteratorPrint( - std::ostream& os) { // NOLINT - JSObjectPrintHeader(os, this, "JSFixedArrayIterator"); - os << "\n - array = " << Brief(array()); - os << "\n - index = " << index(); - os << "\n - initial_next = " << Brief(initial_next()); - JSObjectPrintBody(os, this); -} - void JSDataView::JSDataViewPrint(std::ostream& os) { // NOLINT JSObjectPrintHeader(os, this, "JSDataView"); os << "\n - buffer =" << Brief(buffer()); @@ -1105,7 +1108,9 @@ void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) { // NOLINT void JSGlobalProxy::JSGlobalProxyPrint(std::ostream& os) { // NOLINT JSObjectPrintHeader(os, this, "JSGlobalProxy"); - os << "\n - native context = " << Brief(native_context()); + if (!GetIsolate()->bootstrapper()->IsActive()) { + os << "\n - native context = " << Brief(native_context()); + } os << "\n - hash = " << Brief(hash()); JSObjectPrintBody(os, this); } @@ -1113,7 +1118,9 @@ void JSGlobalProxy::JSGlobalProxyPrint(std::ostream& os) { // NOLINT void JSGlobalObject::JSGlobalObjectPrint(std::ostream& os) { // NOLINT JSObjectPrintHeader(os, this, "JSGlobalObject"); - os << "\n - native context = " << Brief(native_context()); + if (!GetIsolate()->bootstrapper()->IsActive()) { + os << "\n - native context = " << Brief(native_context()); + } os << "\n - global proxy = " << Brief(global_proxy()); JSObjectPrintBody(os, this); } @@ -1129,7 +1136,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())) { @@ -1227,8 +1235,7 @@ void PromiseResolveThenableJobInfo::PromiseResolveThenableJobInfoPrint( os << "\n - then: " << Brief(then()); os << "\n - resolve: " << Brief(resolve()); os << "\n - reject: " << Brief(reject()); - os << "\n - debug id: " << Brief(debug_id()); - os << "\n - debug name: " << Brief(debug_name()); + os << "\n - debug id: " << debug_id(); os << "\n - context: " << Brief(context()); os << "\n"; } @@ -1238,9 +1245,10 @@ void PromiseReactionJobInfo::PromiseReactionJobInfoPrint( HeapObject::PrintHeader(os, "PromiseReactionJobInfo"); os << "\n - value: " << Brief(value()); os << "\n - tasks: " << Brief(tasks()); - os << "\n - deferred: " << Brief(deferred()); - os << "\n - debug id: " << Brief(debug_id()); - os << "\n - debug name: " << Brief(debug_name()); + os << "\n - deferred_promise: " << Brief(deferred_promise()); + os << "\n - deferred_on_resolve: " << Brief(deferred_on_resolve()); + os << "\n - deferred_on_reject: " << Brief(deferred_on_reject()); + os << "\n - debug id: " << debug_id(); os << "\n - reaction context: " << Brief(context()); os << "\n"; } @@ -1267,9 +1275,9 @@ void Module::ModulePrint(std::ostream& os) { // NOLINT } void JSModuleNamespace::JSModuleNamespacePrint(std::ostream& os) { // NOLINT - HeapObject::PrintHeader(os, "JSModuleNamespace"); + JSObjectPrintHeader(os, this, "JSModuleNamespace"); os << "\n - module: " << Brief(module()); - os << "\n"; + JSObjectPrintBody(os, this); } void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) { // NOLINT @@ -1282,6 +1290,13 @@ void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) { // NOLINT os << "\n"; } +void Tuple2::Tuple2Print(std::ostream& os) { // NOLINT + HeapObject::PrintHeader(os, "Tuple2"); + os << "\n - value1: " << Brief(value1()); + os << "\n - value2: " << Brief(value2()); + os << "\n"; +} + void Tuple3::Tuple3Print(std::ostream& os) { // NOLINT HeapObject::PrintHeader(os, "Tuple3"); os << "\n - value1: " << Brief(value1()); @@ -1297,6 +1312,13 @@ void ContextExtension::ContextExtensionPrint(std::ostream& os) { // NOLINT os << "\n"; } +void ConstantElementsPair::ConstantElementsPairPrint( + std::ostream& os) { // NOLINT + HeapObject::PrintHeader(os, "ConstantElementsPair"); + os << "\n - elements_kind: " << static_cast<ElementsKind>(elements_kind()); + os << "\n - constant_values: " << Brief(constant_values()); + os << "\n"; +} void AccessorPair::AccessorPairPrint(std::ostream& os) { // NOLINT HeapObject::PrintHeader(os, "AccessorPair"); @@ -1392,7 +1414,7 @@ void AllocationSite::AllocationSitePrint(std::ostream& os) { // NOLINT } else if (transition_info()->IsJSArray()) { os << "Array literal " << Brief(transition_info()); } else { - os << "unknown transition_info" << Brief(transition_info()); + os << "unknown transition_info " << Brief(transition_info()); } os << "\n"; } @@ -1460,16 +1482,24 @@ void LayoutDescriptor::Print() { os << std::flush; } +void LayoutDescriptor::ShortPrint(std::ostream& os) { + if (IsSmi()) { + os << this; // Print tagged value for easy use with "jld" gdb macro. + } else { + os << Brief(this); + } +} void LayoutDescriptor::Print(std::ostream& os) { // NOLINT os << "Layout descriptor: "; - if (IsOddball() && IsUninitialized(HeapObject::cast(this)->GetIsolate())) { - os << "<uninitialized>"; - } else if (IsFastPointerLayout()) { + if (IsFastPointerLayout()) { os << "<all tagged>"; } else if (IsSmi()) { os << "fast"; PrintBitMask(os, static_cast<uint32_t>(Smi::cast(this)->value())); + } else if (IsOddball() && + IsUninitialized(HeapObject::cast(this)->GetIsolate())) { + os << "<uninitialized>"; } else { os << "slow"; int len = length(); @@ -1546,15 +1576,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); @@ -1592,18 +1650,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); - } - os << "), attrs: " << details.attributes(); + int descriptor = target->LastAdded(); + DescriptorArray* descriptors = target->instance_descriptors(); + descriptors->PrintDescriptorDetails(os, descriptor, + PropertyDetails::kForTransitions); + os << ")"; } os << " -> " << Brief(target); } @@ -1649,6 +1702,15 @@ extern void _v8_internal_Print_DescriptorArray(void* object) { } } +extern void _v8_internal_Print_LayoutDescriptor(void* object) { + i::Object* o = reinterpret_cast<i::Object*>(object); + if (!o->IsLayoutDescriptor()) { + printf("Not a layout descriptor\n"); + } else { + reinterpret_cast<i::LayoutDescriptor*>(object)->Print(); + } +} + extern void _v8_internal_Print_TransitionArray(void* object) { if (reinterpret_cast<i::Object*>(object)->IsSmi()) { printf("Not a transition array\n"); |