1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "src/disasm.h"
8 #include "src/disassembler.h"
9 #include "src/heap/objects-visiting.h"
10 #include "src/jsregexp.h"
11 #include "src/ostreams.h"
18 void Object::Print() {
25 void Object::Print(std::ostream& os) { // NOLINT
27 Smi::cast(this)->SmiPrint(os);
29 HeapObject::cast(this)->HeapObjectPrint(os);
34 void HeapObject::PrintHeader(std::ostream& os, const char* id) { // NOLINT
35 os << "" << reinterpret_cast<void*>(this) << ": [" << id << "]\n";
39 void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
40 InstanceType instance_type = map()->instance_type();
42 HandleScope scope(GetIsolate());
43 if (instance_type < FIRST_NONSTRING_TYPE) {
44 String::cast(this)->StringPrint(os);
48 switch (instance_type) {
50 Symbol::cast(this)->SymbolPrint(os);
53 Map::cast(this)->MapPrint(os);
55 case HEAP_NUMBER_TYPE:
56 HeapNumber::cast(this)->HeapNumberPrint(os);
58 case MUTABLE_HEAP_NUMBER_TYPE:
60 HeapNumber::cast(this)->HeapNumberPrint(os);
64 Float32x4::cast(this)->Float32x4Print(os);
67 Float64x2::cast(this)->Float64x2Print(os);
70 Int32x4::cast(this)->Int32x4Print(os);
72 case FIXED_DOUBLE_ARRAY_TYPE:
73 FixedDoubleArray::cast(this)->FixedDoubleArrayPrint(os);
75 case CONSTANT_POOL_ARRAY_TYPE:
76 ConstantPoolArray::cast(this)->ConstantPoolArrayPrint(os);
78 case FIXED_ARRAY_TYPE:
79 FixedArray::cast(this)->FixedArrayPrint(os);
82 ByteArray::cast(this)->ByteArrayPrint(os);
85 FreeSpace::cast(this)->FreeSpacePrint(os);
88 #define PRINT_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \
89 case EXTERNAL_##TYPE##_ARRAY_TYPE: \
90 External##Type##Array::cast(this)->External##Type##ArrayPrint(os); \
93 TYPED_ARRAYS(PRINT_EXTERNAL_ARRAY)
94 #undef PRINT_EXTERNAL_ARRAY
96 #define PRINT_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
97 case Fixed##Type##Array::kInstanceType: \
98 Fixed##Type##Array::cast(this)->FixedTypedArrayPrint(os); \
101 TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY)
102 #undef PRINT_FIXED_TYPED_ARRAY
107 case JS_OBJECT_TYPE: // fall through
108 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
110 case JS_GENERATOR_OBJECT_TYPE:
112 JSObject::cast(this)->JSObjectPrint(os);
115 Oddball::cast(this)->to_string()->Print(os);
118 JSModule::cast(this)->JSModulePrint(os);
120 case JS_FUNCTION_TYPE:
121 JSFunction::cast(this)->JSFunctionPrint(os);
123 case JS_GLOBAL_PROXY_TYPE:
124 JSGlobalProxy::cast(this)->JSGlobalProxyPrint(os);
126 case JS_GLOBAL_OBJECT_TYPE:
127 JSGlobalObject::cast(this)->JSGlobalObjectPrint(os);
129 case JS_BUILTINS_OBJECT_TYPE:
130 JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(os);
133 os << "Value wrapper around:";
134 JSValue::cast(this)->value()->Print(os);
137 JSDate::cast(this)->JSDatePrint(os);
140 Code::cast(this)->CodePrint(os);
143 JSProxy::cast(this)->JSProxyPrint(os);
145 case JS_FUNCTION_PROXY_TYPE:
146 JSFunctionProxy::cast(this)->JSFunctionProxyPrint(os);
149 JSSet::cast(this)->JSSetPrint(os);
152 JSMap::cast(this)->JSMapPrint(os);
154 case JS_SET_ITERATOR_TYPE:
155 JSSetIterator::cast(this)->JSSetIteratorPrint(os);
157 case JS_MAP_ITERATOR_TYPE:
158 JSMapIterator::cast(this)->JSMapIteratorPrint(os);
160 case JS_WEAK_MAP_TYPE:
161 JSWeakMap::cast(this)->JSWeakMapPrint(os);
163 case JS_WEAK_SET_TYPE:
164 JSWeakSet::cast(this)->JSWeakSetPrint(os);
167 Foreign::cast(this)->ForeignPrint(os);
169 case SHARED_FUNCTION_INFO_TYPE:
170 SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(os);
172 case JS_MESSAGE_OBJECT_TYPE:
173 JSMessageObject::cast(this)->JSMessageObjectPrint(os);
176 Cell::cast(this)->CellPrint(os);
178 case PROPERTY_CELL_TYPE:
179 PropertyCell::cast(this)->PropertyCellPrint(os);
182 WeakCell::cast(this)->WeakCellPrint(os);
184 case JS_ARRAY_BUFFER_TYPE:
185 JSArrayBuffer::cast(this)->JSArrayBufferPrint(os);
187 case JS_TYPED_ARRAY_TYPE:
188 JSTypedArray::cast(this)->JSTypedArrayPrint(os);
190 case JS_DATA_VIEW_TYPE:
191 JSDataView::cast(this)->JSDataViewPrint(os);
193 #define MAKE_STRUCT_CASE(NAME, Name, name) \
195 Name::cast(this)->Name##Print(os); \
197 STRUCT_LIST(MAKE_STRUCT_CASE)
198 #undef MAKE_STRUCT_CASE
201 os << "UNKNOWN TYPE " << map()->instance_type();
208 void ByteArray::ByteArrayPrint(std::ostream& os) { // NOLINT
209 os << "byte array, data starts at " << GetDataStartAddress();
213 void FreeSpace::FreeSpacePrint(std::ostream& os) { // NOLINT
214 os << "free space, size " << Size();
218 #define EXTERNAL_ARRAY_PRINTER(Type, type, TYPE, ctype, size) \
219 void External##Type##Array::External##Type##ArrayPrint(std::ostream& os) { \
220 os << "external " #type " array"; \
223 TYPED_ARRAYS(EXTERNAL_ARRAY_PRINTER)
225 #undef EXTERNAL_ARRAY_PRINTER
228 template <class Traits>
229 void FixedTypedArray<Traits>::FixedTypedArrayPrint(
230 std::ostream& os) { // NOLINT
231 os << "fixed " << Traits::Designator();
235 void JSObject::PrintProperties(std::ostream& os) { // NOLINT
236 if (HasFastProperties()) {
237 DescriptorArray* descs = map()->instance_descriptors();
238 for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
240 descs->GetKey(i)->NamePrint(os);
242 switch (descs->GetType(i)) {
244 FieldIndex index = FieldIndex::ForDescriptor(map(), i);
245 os << Brief(RawFastPropertyAt(index)) << " (field at offset "
246 << index.property_index() << ")\n";
250 os << Brief(descs->GetConstant(i)) << " (constant)\n";
253 os << Brief(descs->GetCallbacksObject(i)) << " (callback)\n";
255 case NORMAL: // only in slow mode
261 property_dictionary()->Print(os);
267 static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
268 T* p = T::cast(object);
269 for (int i = 0; i < p->length(); i++) {
270 os << " " << i << ": " << p->get_scalar(i) << "\n";
276 static void DoPrintFloat32x4Elements(std::ostream& os, Object* object) {
277 T* p = T::cast(object);
278 for (int i = 0; i < p->length(); i++) {
279 float32x4_value_t value = p->get_scalar(i);
280 os << " " << i << ": (" << value.storage[0] << value.storage[1] <<
281 value.storage[2] << value.storage[3] << ")\n";
287 static void DoPrintFloat64x2Elements(std::ostream& os, Object* object) {
288 T* p = T::cast(object);
289 for (int i = 0; i < p->length(); i++) {
290 float64x2_value_t value = p->get_scalar(i);
291 os << " " << i << ": (" << value.storage[0] << value.storage[1] << ")\n";
297 static void DoPrintInt32x4Elements(std::ostream& os, Object* object) {
298 T* p = T::cast(object);
299 for (int i = 0; i < p->length(); i++) {
300 int32x4_value_t value = p->get_scalar(i);
301 os << " " << i << ": (" << value.storage[0] << value.storage[1] <<
302 value.storage[2] << value.storage[3] << ")\n";
307 void JSObject::PrintElements(std::ostream& os) { // NOLINT
308 // Don't call GetElementsKind, its validation code can cause the printer to
309 // fail when debugging.
310 switch (map()->elements_kind()) {
311 case FAST_HOLEY_SMI_ELEMENTS:
312 case FAST_SMI_ELEMENTS:
313 case FAST_HOLEY_ELEMENTS:
314 case FAST_ELEMENTS: {
315 // Print in array notation for non-sparse arrays.
316 FixedArray* p = FixedArray::cast(elements());
317 for (int i = 0; i < p->length(); i++) {
318 os << " " << i << ": " << Brief(p->get(i)) << "\n";
322 case FAST_HOLEY_DOUBLE_ELEMENTS:
323 case FAST_DOUBLE_ELEMENTS: {
324 // Print in array notation for non-sparse arrays.
325 if (elements()->length() > 0) {
326 FixedDoubleArray* p = FixedDoubleArray::cast(elements());
327 for (int i = 0; i < p->length(); i++) {
328 os << " " << i << ": ";
329 if (p->is_the_hole(i)) {
332 os << p->get_scalar(i);
341 #define PRINT_ELEMENTS(Kind, Type) \
343 DoPrintElements<Type>(os, elements()); \
347 #define PRINT_FLOAT32x4_ELEMENTS(Kind, Type) \
349 DoPrintFloat32x4Elements<Type>(os, elements()); \
353 #define PRINT_FLOAT64x2_ELEMENTS(Kind, Type) \
355 DoPrintFloat64x2Elements<Type>(os, elements()); \
359 #define PRINT_INT32x4_ELEMENTS(Kind, Type) \
361 DoPrintInt32x4Elements<Type>(os, elements()); \
365 PRINT_ELEMENTS(EXTERNAL_UINT8_CLAMPED_ELEMENTS, ExternalUint8ClampedArray)
366 PRINT_ELEMENTS(EXTERNAL_INT8_ELEMENTS, ExternalInt8Array)
367 PRINT_ELEMENTS(EXTERNAL_UINT8_ELEMENTS,
369 PRINT_ELEMENTS(EXTERNAL_INT16_ELEMENTS, ExternalInt16Array)
370 PRINT_ELEMENTS(EXTERNAL_UINT16_ELEMENTS,
372 PRINT_ELEMENTS(EXTERNAL_INT32_ELEMENTS, ExternalInt32Array)
373 PRINT_ELEMENTS(EXTERNAL_UINT32_ELEMENTS,
375 PRINT_ELEMENTS(EXTERNAL_FLOAT32_ELEMENTS, ExternalFloat32Array)
376 PRINT_ELEMENTS(EXTERNAL_FLOAT64_ELEMENTS, ExternalFloat64Array)
377 PRINT_FLOAT32x4_ELEMENTS(EXTERNAL_FLOAT32x4_ELEMENTS,
378 ExternalFloat32x4Array)
379 PRINT_FLOAT64x2_ELEMENTS(EXTERNAL_FLOAT64x2_ELEMENTS,
380 ExternalFloat64x2Array)
381 PRINT_INT32x4_ELEMENTS(EXTERNAL_INT32x4_ELEMENTS, ExternalInt32x4Array)
383 PRINT_ELEMENTS(UINT8_ELEMENTS, FixedUint8Array)
384 PRINT_ELEMENTS(UINT8_CLAMPED_ELEMENTS, FixedUint8ClampedArray)
385 PRINT_ELEMENTS(INT8_ELEMENTS, FixedInt8Array)
386 PRINT_ELEMENTS(UINT16_ELEMENTS, FixedUint16Array)
387 PRINT_ELEMENTS(INT16_ELEMENTS, FixedInt16Array)
388 PRINT_ELEMENTS(UINT32_ELEMENTS, FixedUint32Array)
389 PRINT_ELEMENTS(INT32_ELEMENTS, FixedInt32Array)
390 PRINT_ELEMENTS(FLOAT32_ELEMENTS, FixedFloat32Array)
391 PRINT_ELEMENTS(FLOAT64_ELEMENTS, FixedFloat64Array)
392 PRINT_FLOAT32x4_ELEMENTS(FLOAT32x4_ELEMENTS, FixedFloat32x4Array)
393 PRINT_FLOAT64x2_ELEMENTS(FLOAT64x2_ELEMENTS, FixedFloat64x2Array)
394 PRINT_INT32x4_ELEMENTS(INT32x4_ELEMENTS, FixedInt32x4Array)
396 #undef PRINT_ELEMENTS
398 case DICTIONARY_ELEMENTS:
399 elements()->Print(os);
401 case SLOPPY_ARGUMENTS_ELEMENTS: {
402 FixedArray* p = FixedArray::cast(elements());
403 os << " parameter map:";
404 for (int i = 2; i < p->length(); i++) {
405 os << " " << (i - 2) << ":" << Brief(p->get(i));
407 os << "\n context: " << Brief(p->get(0))
408 << "\n arguments: " << Brief(p->get(1)) << "\n";
415 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT
416 if (!map()->HasTransitionArray()) return;
417 map()->transitions()->PrintTransitions(os, false);
421 void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT
422 HeapObject::PrintHeader(os, "JSObject");
423 // Don't call GetElementsKind, its validation code can cause the printer to
424 // fail when debugging.
425 PrototypeIterator iter(GetIsolate(), this);
426 os << " - map = " << reinterpret_cast<void*>(map()) << " ["
427 << ElementsKindToString(this->map()->elements_kind())
428 << "]\n - prototype = " << reinterpret_cast<void*>(iter.GetCurrent())
431 PrintTransitions(os);
437 void JSModule::JSModulePrint(std::ostream& os) { // NOLINT
438 HeapObject::PrintHeader(os, "JSModule");
439 os << " - map = " << reinterpret_cast<void*>(map()) << "\n"
441 context()->Print(os);
442 os << " - scope_info = " << Brief(scope_info())
443 << ElementsKindToString(this->map()->elements_kind()) << " {\n";
450 static const char* TypeToString(InstanceType type) {
452 #define TYPE_TO_STRING(TYPE) case TYPE: return #TYPE;
453 INSTANCE_TYPE_LIST(TYPE_TO_STRING)
454 #undef TYPE_TO_STRING
457 return "UNKNOWN"; // Keep the compiler happy.
461 void Symbol::SymbolPrint(std::ostream& os) { // NOLINT
462 HeapObject::PrintHeader(os, "Symbol");
463 os << " - hash: " << Hash();
464 os << "\n - name: " << Brief(name());
465 if (name()->IsUndefined()) {
466 os << " (" << PrivateSymbolToName() << ")";
468 os << "\n - private: " << is_private();
469 os << "\n - own: " << is_own();
474 void Map::MapPrint(std::ostream& os) { // NOLINT
475 HeapObject::PrintHeader(os, "Map");
476 os << " - type: " << TypeToString(instance_type()) << "\n";
477 os << " - instance size: " << instance_size() << "\n";
478 os << " - inobject properties: " << inobject_properties() << "\n";
479 os << " - elements kind: " << ElementsKindToString(elements_kind());
480 os << "\n - pre-allocated property fields: "
481 << pre_allocated_property_fields() << "\n";
482 os << " - unused property fields: " << unused_property_fields() << "\n";
483 if (is_dictionary_map()) os << " - dictionary_map\n";
484 if (is_prototype_map()) os << " - prototype_map\n";
485 if (is_hidden_prototype()) os << " - hidden_prototype\n";
486 if (has_named_interceptor()) os << " - named_interceptor\n";
487 if (has_indexed_interceptor()) os << " - indexed_interceptor\n";
488 if (is_undetectable()) os << " - undetectable\n";
489 if (has_instance_call_handler()) os << " - instance_call_handler\n";
490 if (is_access_check_needed()) os << " - access_check_needed\n";
493 } else if (!is_extensible()) {
496 os << " - back pointer: " << Brief(GetBackPointer());
497 os << "\n - instance descriptors " << (owns_descriptors() ? "(own) " : "")
498 << "#" << NumberOfOwnDescriptors() << ": "
499 << Brief(instance_descriptors());
500 if (HasTransitionArray()) {
501 os << "\n - transitions: " << Brief(transitions());
503 os << "\n - prototype: " << Brief(prototype());
504 os << "\n - constructor: " << Brief(constructor());
505 os << "\n - code cache: " << Brief(code_cache());
506 os << "\n - dependent code: " << Brief(dependent_code());
511 void CodeCache::CodeCachePrint(std::ostream& os) { // NOLINT
512 HeapObject::PrintHeader(os, "CodeCache");
513 os << "\n - default_cache: " << Brief(default_cache());
514 os << "\n - normal_type_cache: " << Brief(normal_type_cache());
518 void PolymorphicCodeCache::PolymorphicCodeCachePrint(
519 std::ostream& os) { // NOLINT
520 HeapObject::PrintHeader(os, "PolymorphicCodeCache");
521 os << "\n - cache: " << Brief(cache());
525 void TypeFeedbackInfo::TypeFeedbackInfoPrint(std::ostream& os) { // NOLINT
526 HeapObject::PrintHeader(os, "TypeFeedbackInfo");
527 os << " - ic_total_count: " << ic_total_count()
528 << ", ic_with_type_info_count: " << ic_with_type_info_count()
529 << ", ic_generic_count: " << ic_generic_count() << "\n";
533 void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(
534 std::ostream& os) { // NOLINT
535 HeapObject::PrintHeader(os, "AliasedArgumentsEntry");
536 os << "\n - aliased_context_slot: " << aliased_context_slot();
540 void FixedArray::FixedArrayPrint(std::ostream& os) { // NOLINT
541 HeapObject::PrintHeader(os, "FixedArray");
542 os << " - length: " << length();
543 for (int i = 0; i < length(); i++) {
544 os << "\n [" << i << "]: " << Brief(get(i));
550 void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT
551 HeapObject::PrintHeader(os, "FixedDoubleArray");
552 os << " - length: " << length();
553 for (int i = 0; i < length(); i++) {
554 os << "\n [" << i << "]: ";
555 if (is_the_hole(i)) {
565 void ConstantPoolArray::ConstantPoolArrayPrint(std::ostream& os) { // NOLINT
566 HeapObject::PrintHeader(os, "ConstantPoolArray");
567 os << " - length: " << length();
568 for (int i = 0; i <= last_index(INT32, SMALL_SECTION); i++) {
569 if (i < last_index(INT64, SMALL_SECTION)) {
570 os << "\n [" << i << "]: double: " << get_int64_entry_as_double(i);
571 } else if (i <= last_index(CODE_PTR, SMALL_SECTION)) {
572 os << "\n [" << i << "]: code target pointer: "
573 << reinterpret_cast<void*>(get_code_ptr_entry(i));
574 } else if (i <= last_index(HEAP_PTR, SMALL_SECTION)) {
575 os << "\n [" << i << "]: heap pointer: "
576 << reinterpret_cast<void*>(get_heap_ptr_entry(i));
577 } else if (i <= last_index(INT32, SMALL_SECTION)) {
578 os << "\n [" << i << "]: int32: " << get_int32_entry(i);
581 if (is_extended_layout()) {
582 os << "\n Extended section:";
583 for (int i = first_extended_section_index();
584 i <= last_index(INT32, EXTENDED_SECTION); i++) {
585 if (i < last_index(INT64, EXTENDED_SECTION)) {
586 os << "\n [" << i << "]: double: " << get_int64_entry_as_double(i);
587 } else if (i <= last_index(CODE_PTR, EXTENDED_SECTION)) {
588 os << "\n [" << i << "]: code target pointer: "
589 << reinterpret_cast<void*>(get_code_ptr_entry(i));
590 } else if (i <= last_index(HEAP_PTR, EXTENDED_SECTION)) {
591 os << "\n [" << i << "]: heap pointer: "
592 << reinterpret_cast<void*>(get_heap_ptr_entry(i));
593 } else if (i <= last_index(INT32, EXTENDED_SECTION)) {
594 os << "\n [" << i << "]: int32: " << get_int32_entry(i);
602 void JSValue::JSValuePrint(std::ostream& os) { // NOLINT
603 HeapObject::PrintHeader(os, "ValueObject");
608 void JSMessageObject::JSMessageObjectPrint(std::ostream& os) { // NOLINT
609 HeapObject::PrintHeader(os, "JSMessageObject");
610 os << " - type: " << Brief(type());
611 os << "\n - arguments: " << Brief(arguments());
612 os << "\n - start_position: " << start_position();
613 os << "\n - end_position: " << end_position();
614 os << "\n - script: " << Brief(script());
615 os << "\n - stack_frames: " << Brief(stack_frames());
620 void String::StringPrint(std::ostream& os) { // NOLINT
621 if (StringShape(this).IsInternalized()) {
623 } else if (StringShape(this).IsCons()) {
629 const char truncated_epilogue[] = "...<truncated>";
631 if (!FLAG_use_verbose_printer) {
633 len = 100 - sizeof(truncated_epilogue);
636 for (int i = 0; i < len; i++) {
637 os << AsUC16(Get(i));
639 if (len != length()) {
640 os << truncated_epilogue;
643 if (!StringShape(this).IsInternalized()) os << "\"";
647 void Name::NamePrint(std::ostream& os) { // NOLINT
649 String::cast(this)->StringPrint(os);
650 } else if (IsSymbol()) {
651 Symbol::cast(this)->name()->Print(os);
658 // This method is only meant to be called from gdb for debugging purposes.
659 // Since the string can also be in two-byte encoding, non-Latin1 characters
660 // will be ignored in the output.
661 char* String::ToAsciiArray() {
662 // Static so that subsequent calls frees previously allocated space.
663 // This also means that previous results will be overwritten.
664 static char* buffer = NULL;
665 if (buffer != NULL) delete[] buffer;
666 buffer = new char[length()+1];
667 WriteToFlat(this, reinterpret_cast<uint8_t*>(buffer), 0, length());
668 buffer[length()] = 0;
673 static const char* const weekdays[] = {
674 "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
678 void JSDate::JSDatePrint(std::ostream& os) { // NOLINT
679 HeapObject::PrintHeader(os, "JSDate");
680 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
683 if (!year()->IsSmi()) {
684 os << " - time = NaN\n";
686 // TODO(svenpanne) Add some basic formatting to our streams.
687 Vector<char> buf = Vector<char>::New(100);
689 buf, " - time = %s %04d/%02d/%02d %02d:%02d:%02d\n",
690 weekdays[weekday()->IsSmi() ? Smi::cast(weekday())->value() + 1 : 0],
691 year()->IsSmi() ? Smi::cast(year())->value() : -1,
692 month()->IsSmi() ? Smi::cast(month())->value() : -1,
693 day()->IsSmi() ? Smi::cast(day())->value() : -1,
694 hour()->IsSmi() ? Smi::cast(hour())->value() : -1,
695 min()->IsSmi() ? Smi::cast(min())->value() : -1,
696 sec()->IsSmi() ? Smi::cast(sec())->value() : -1);
702 void JSProxy::JSProxyPrint(std::ostream& os) { // NOLINT
703 HeapObject::PrintHeader(os, "JSProxy");
704 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
705 os << " - handler = ";
706 handler()->Print(os);
707 os << "\n - hash = ";
713 void JSFunctionProxy::JSFunctionProxyPrint(std::ostream& os) { // NOLINT
714 HeapObject::PrintHeader(os, "JSFunctionProxy");
715 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
716 os << " - handler = ";
717 handler()->Print(os);
718 os << "\n - call_trap = ";
719 call_trap()->Print(os);
720 os << "\n - construct_trap = ";
721 construct_trap()->Print(os);
726 void JSSet::JSSetPrint(std::ostream& os) { // NOLINT
727 HeapObject::PrintHeader(os, "JSSet");
728 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
729 os << " - table = " << Brief(table());
734 void JSMap::JSMapPrint(std::ostream& os) { // NOLINT
735 HeapObject::PrintHeader(os, "JSMap");
736 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
737 os << " - table = " << Brief(table());
742 template <class Derived, class TableType>
744 OrderedHashTableIterator<Derived, TableType>::OrderedHashTableIteratorPrint(
745 std::ostream& os) { // NOLINT
746 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
747 os << " - table = " << Brief(table());
748 os << "\n - index = " << Brief(index());
749 os << "\n - kind = " << Brief(kind());
754 template void OrderedHashTableIterator<
756 OrderedHashSet>::OrderedHashTableIteratorPrint(std::ostream& os); // NOLINT
759 template void OrderedHashTableIterator<
761 OrderedHashMap>::OrderedHashTableIteratorPrint(std::ostream& os); // NOLINT
764 void JSSetIterator::JSSetIteratorPrint(std::ostream& os) { // NOLINT
765 HeapObject::PrintHeader(os, "JSSetIterator");
766 OrderedHashTableIteratorPrint(os);
770 void JSMapIterator::JSMapIteratorPrint(std::ostream& os) { // NOLINT
771 HeapObject::PrintHeader(os, "JSMapIterator");
772 OrderedHashTableIteratorPrint(os);
776 void JSWeakMap::JSWeakMapPrint(std::ostream& os) { // NOLINT
777 HeapObject::PrintHeader(os, "JSWeakMap");
778 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
779 os << " - table = " << Brief(table());
784 void JSWeakSet::JSWeakSetPrint(std::ostream& os) { // NOLINT
785 HeapObject::PrintHeader(os, "JSWeakSet");
786 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
787 os << " - table = " << Brief(table());
792 void JSArrayBuffer::JSArrayBufferPrint(std::ostream& os) { // NOLINT
793 HeapObject::PrintHeader(os, "JSArrayBuffer");
794 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
795 os << " - backing_store = " << backing_store() << "\n";
796 os << " - byte_length = " << Brief(byte_length());
801 void JSTypedArray::JSTypedArrayPrint(std::ostream& os) { // NOLINT
802 HeapObject::PrintHeader(os, "JSTypedArray");
803 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
804 os << " - buffer = " << Brief(buffer());
805 os << "\n - byte_offset = " << Brief(byte_offset());
806 os << "\n - byte_length = " << Brief(byte_length());
807 os << "\n - length = " << Brief(length());
813 void JSDataView::JSDataViewPrint(std::ostream& os) { // NOLINT
814 HeapObject::PrintHeader(os, "JSDataView");
815 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
816 os << " - buffer =" << Brief(buffer());
817 os << "\n - byte_offset = " << Brief(byte_offset());
818 os << "\n - byte_length = " << Brief(byte_length());
823 void JSFunction::JSFunctionPrint(std::ostream& os) { // NOLINT
824 HeapObject::PrintHeader(os, "Function");
825 os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
826 os << " - initial_map = ";
827 if (has_initial_map()) os << Brief(initial_map());
828 os << "\n - shared_info = " << Brief(shared());
829 os << "\n - name = " << Brief(shared()->name());
830 os << "\n - context = " << Brief(context());
831 if (shared()->bound()) {
832 os << "\n - bindings = " << Brief(function_bindings());
834 os << "\n - literals = " << Brief(literals());
836 os << "\n - code = " << Brief(code());
844 void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) { // NOLINT
845 HeapObject::PrintHeader(os, "SharedFunctionInfo");
846 os << " - name: " << Brief(name());
847 os << "\n - expected_nof_properties: " << expected_nof_properties();
848 os << "\n - ast_node_count: " << ast_node_count();
849 os << "\n - instance class name = ";
850 instance_class_name()->Print(os);
851 os << "\n - code = " << Brief(code());
852 if (HasSourceCode()) {
853 os << "\n - source code = ";
854 String* source = String::cast(Script::cast(script())->source());
855 int start = start_position();
856 int length = end_position() - start;
857 SmartArrayPointer<char> source_string =
858 source->ToCString(DISALLOW_NULLS,
859 FAST_STRING_TRAVERSAL,
860 start, length, NULL);
861 os << source_string.get();
863 // Script files are often large, hard to read.
864 // os << "\n - script =";
865 // script()->Print(os);
866 os << "\n - function token position = " << function_token_position();
867 os << "\n - start position = " << start_position();
868 os << "\n - end position = " << end_position();
869 os << "\n - is expression = " << is_expression();
870 os << "\n - debug info = " << Brief(debug_info());
871 os << "\n - length = " << length();
872 os << "\n - optimized_code_map = " << Brief(optimized_code_map());
873 os << "\n - feedback_vector = ";
874 feedback_vector()->FixedArrayPrint(os);
879 void JSGlobalProxy::JSGlobalProxyPrint(std::ostream& os) { // NOLINT
880 os << "global_proxy ";
882 os << "native context : " << Brief(native_context());
887 void JSGlobalObject::JSGlobalObjectPrint(std::ostream& os) { // NOLINT
890 os << "native context : " << Brief(native_context());
895 void JSBuiltinsObject::JSBuiltinsObjectPrint(std::ostream& os) { // NOLINT
901 void Cell::CellPrint(std::ostream& os) { // NOLINT
902 HeapObject::PrintHeader(os, "Cell");
906 void PropertyCell::PropertyCellPrint(std::ostream& os) { // NOLINT
907 HeapObject::PrintHeader(os, "PropertyCell");
911 void WeakCell::WeakCellPrint(std::ostream& os) { // NOLINT
912 HeapObject::PrintHeader(os, "WeakCell");
916 void Code::CodePrint(std::ostream& os) { // NOLINT
917 HeapObject::PrintHeader(os, "Code");
918 #ifdef ENABLE_DISASSEMBLER
919 if (FLAG_use_verbose_printer) {
920 Disassemble(NULL, os);
926 void Foreign::ForeignPrint(std::ostream& os) { // NOLINT
927 os << "foreign address : " << foreign_address();
931 void ExecutableAccessorInfo::ExecutableAccessorInfoPrint(
932 std::ostream& os) { // NOLINT
933 HeapObject::PrintHeader(os, "ExecutableAccessorInfo");
934 os << "\n - name: " << Brief(name());
935 os << "\n - flag: " << Brief(flag());
936 os << "\n - getter: " << Brief(getter());
937 os << "\n - setter: " << Brief(setter());
938 os << "\n - data: " << Brief(data());
943 void DeclaredAccessorInfo::DeclaredAccessorInfoPrint(
944 std::ostream& os) { // NOLINT
945 HeapObject::PrintHeader(os, "DeclaredAccessorInfo");
946 os << "\n - name: " << Brief(name());
947 os << "\n - flag: " << Brief(flag());
948 os << "\n - descriptor: " << Brief(descriptor());
953 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorPrint(
954 std::ostream& os) { // NOLINT
955 HeapObject::PrintHeader(os, "DeclaredAccessorDescriptor");
956 os << "\n - internal field: " << Brief(serialized_data());
961 void Box::BoxPrint(std::ostream& os) { // NOLINT
962 HeapObject::PrintHeader(os, "Box");
963 os << "\n - value: " << Brief(value());
968 void AccessorPair::AccessorPairPrint(std::ostream& os) { // NOLINT
969 HeapObject::PrintHeader(os, "AccessorPair");
970 os << "\n - getter: " << Brief(getter());
971 os << "\n - setter: " << Brief(setter());
976 void AccessCheckInfo::AccessCheckInfoPrint(std::ostream& os) { // NOLINT
977 HeapObject::PrintHeader(os, "AccessCheckInfo");
978 os << "\n - named_callback: " << Brief(named_callback());
979 os << "\n - indexed_callback: " << Brief(indexed_callback());
980 os << "\n - data: " << Brief(data());
985 void InterceptorInfo::InterceptorInfoPrint(std::ostream& os) { // NOLINT
986 HeapObject::PrintHeader(os, "InterceptorInfo");
987 os << "\n - getter: " << Brief(getter());
988 os << "\n - setter: " << Brief(setter());
989 os << "\n - query: " << Brief(query());
990 os << "\n - deleter: " << Brief(deleter());
991 os << "\n - enumerator: " << Brief(enumerator());
992 os << "\n - data: " << Brief(data());
997 void CallHandlerInfo::CallHandlerInfoPrint(std::ostream& os) { // NOLINT
998 HeapObject::PrintHeader(os, "CallHandlerInfo");
999 os << "\n - callback: " << Brief(callback());
1000 os << "\n - data: " << Brief(data());
1005 void FunctionTemplateInfo::FunctionTemplateInfoPrint(
1006 std::ostream& os) { // NOLINT
1007 HeapObject::PrintHeader(os, "FunctionTemplateInfo");
1008 os << "\n - class name: " << Brief(class_name());
1009 os << "\n - tag: " << Brief(tag());
1010 os << "\n - property_list: " << Brief(property_list());
1011 os << "\n - serial_number: " << Brief(serial_number());
1012 os << "\n - call_code: " << Brief(call_code());
1013 os << "\n - property_accessors: " << Brief(property_accessors());
1014 os << "\n - prototype_template: " << Brief(prototype_template());
1015 os << "\n - parent_template: " << Brief(parent_template());
1016 os << "\n - named_property_handler: " << Brief(named_property_handler());
1017 os << "\n - indexed_property_handler: " << Brief(indexed_property_handler());
1018 os << "\n - instance_template: " << Brief(instance_template());
1019 os << "\n - signature: " << Brief(signature());
1020 os << "\n - access_check_info: " << Brief(access_check_info());
1021 os << "\n - hidden_prototype: " << (hidden_prototype() ? "true" : "false");
1022 os << "\n - undetectable: " << (undetectable() ? "true" : "false");
1023 os << "\n - need_access_check: " << (needs_access_check() ? "true" : "false");
1028 void ObjectTemplateInfo::ObjectTemplateInfoPrint(std::ostream& os) { // NOLINT
1029 HeapObject::PrintHeader(os, "ObjectTemplateInfo");
1030 os << " - tag: " << Brief(tag());
1031 os << "\n - property_list: " << Brief(property_list());
1032 os << "\n - property_accessors: " << Brief(property_accessors());
1033 os << "\n - constructor: " << Brief(constructor());
1034 os << "\n - internal_field_count: " << Brief(internal_field_count());
1039 void SignatureInfo::SignatureInfoPrint(std::ostream& os) { // NOLINT
1040 HeapObject::PrintHeader(os, "SignatureInfo");
1041 os << "\n - receiver: " << Brief(receiver());
1042 os << "\n - args: " << Brief(args());
1047 void TypeSwitchInfo::TypeSwitchInfoPrint(std::ostream& os) { // NOLINT
1048 HeapObject::PrintHeader(os, "TypeSwitchInfo");
1049 os << "\n - types: " << Brief(types());
1054 void AllocationSite::AllocationSitePrint(std::ostream& os) { // NOLINT
1055 HeapObject::PrintHeader(os, "AllocationSite");
1056 os << " - weak_next: " << Brief(weak_next());
1057 os << "\n - dependent code: " << Brief(dependent_code());
1058 os << "\n - nested site: " << Brief(nested_site());
1059 os << "\n - memento found count: "
1060 << Brief(Smi::FromInt(memento_found_count()));
1061 os << "\n - memento create count: "
1062 << Brief(Smi::FromInt(memento_create_count()));
1063 os << "\n - pretenure decision: "
1064 << Brief(Smi::FromInt(pretenure_decision()));
1065 os << "\n - transition_info: ";
1066 if (transition_info()->IsSmi()) {
1067 ElementsKind kind = GetElementsKind();
1068 os << "Array allocation with ElementsKind " << ElementsKindToString(kind);
1069 } else if (transition_info()->IsJSArray()) {
1070 os << "Array literal " << Brief(transition_info());
1072 os << "unknown transition_info" << Brief(transition_info());
1078 void AllocationMemento::AllocationMementoPrint(std::ostream& os) { // NOLINT
1079 HeapObject::PrintHeader(os, "AllocationMemento");
1080 os << " - allocation site: ";
1082 GetAllocationSite()->Print(os);
1084 os << "<invalid>\n";
1089 void Script::ScriptPrint(std::ostream& os) { // NOLINT
1090 HeapObject::PrintHeader(os, "Script");
1091 os << "\n - source: " << Brief(source());
1092 os << "\n - name: " << Brief(name());
1093 os << "\n - line_offset: " << Brief(line_offset());
1094 os << "\n - column_offset: " << Brief(column_offset());
1095 os << "\n - type: " << Brief(type());
1096 os << "\n - id: " << Brief(id());
1097 os << "\n - context data: " << Brief(context_data());
1098 os << "\n - wrapper: " << Brief(wrapper());
1099 os << "\n - compilation type: " << compilation_type();
1100 os << "\n - line ends: " << Brief(line_ends());
1101 os << "\n - eval from shared: " << Brief(eval_from_shared());
1102 os << "\n - eval from instructions offset: "
1103 << Brief(eval_from_instructions_offset());
1108 void DebugInfo::DebugInfoPrint(std::ostream& os) { // NOLINT
1109 HeapObject::PrintHeader(os, "DebugInfo");
1110 os << "\n - shared: " << Brief(shared());
1111 os << "\n - original_code: " << Brief(original_code());
1112 os << "\n - code: " << Brief(code());
1113 os << "\n - break_points: ";
1114 break_points()->Print(os);
1118 void BreakPointInfo::BreakPointInfoPrint(std::ostream& os) { // NOLINT
1119 HeapObject::PrintHeader(os, "BreakPointInfo");
1120 os << "\n - code_position: " << code_position()->value();
1121 os << "\n - source_position: " << source_position()->value();
1122 os << "\n - statement_position: " << statement_position()->value();
1123 os << "\n - break_point_objects: " << Brief(break_point_objects());
1128 void DescriptorArray::Print() {
1129 OFStream os(stdout);
1130 this->PrintDescriptors(os);
1135 void DescriptorArray::PrintDescriptors(std::ostream& os) { // NOLINT
1136 os << "Descriptor array " << number_of_descriptors() << "\n";
1137 for (int i = 0; i < number_of_descriptors(); i++) {
1140 os << " " << i << ": " << desc << "\n";
1146 void TransitionArray::Print() {
1147 OFStream os(stdout);
1148 this->PrintTransitions(os);
1153 void TransitionArray::PrintTransitions(std::ostream& os,
1154 bool print_header) { // NOLINT
1156 os << "Transition array " << number_of_transitions() << "\n";
1158 for (int i = 0; i < number_of_transitions(); i++) {
1159 Name* key = GetKey(i);
1163 if (key == GetHeap()->frozen_symbol()) {
1164 os << " (transition to frozen)";
1165 } else if (key == GetHeap()->elements_transition_symbol()) {
1166 os << " (transition to "
1167 << ElementsKindToString(GetTarget(i)->elements_kind()) << ")";
1168 } else if (key == GetHeap()->observed_symbol()) {
1169 os << " (transition to Object.observe)";
1171 PropertyDetails details = GetTargetDetails(i);
1172 switch (details.type()) {
1174 os << " (transition to field)";
1178 os << " (transition to constant " << Brief(GetTargetValue(i)) << ")";
1181 os << " (transition to callback " << Brief(GetTargetValue(i)) << ")";
1183 // Values below are never in the target descriptor array.
1188 os << ", attrs: " << details.attributes();
1190 os << " -> " << Brief(GetTarget(i)) << "\n";
1195 #endif // OBJECT_PRINT
1198 } } // namespace v8::internal