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/disassembler.h"
8 #include "src/disasm.h"
9 #include "src/jsregexp.h"
10 #include "src/objects-visiting.h"
17 void Object::Print() {
22 void Object::Print(FILE* out) {
24 Smi::cast(this)->SmiPrint(out);
26 HeapObject::cast(this)->HeapObjectPrint(out);
32 void Object::PrintLn() {
37 void Object::PrintLn(FILE* out) {
43 void HeapObject::PrintHeader(FILE* out, const char* id) {
44 PrintF(out, "%p: [%s]\n", reinterpret_cast<void*>(this), id);
48 void HeapObject::HeapObjectPrint(FILE* out) {
49 InstanceType instance_type = map()->instance_type();
51 HandleScope scope(GetIsolate());
52 if (instance_type < FIRST_NONSTRING_TYPE) {
53 String::cast(this)->StringPrint(out);
57 switch (instance_type) {
59 Symbol::cast(this)->SymbolPrint(out);
62 Map::cast(this)->MapPrint(out);
64 case HEAP_NUMBER_TYPE:
65 HeapNumber::cast(this)->HeapNumberPrint(out);
67 case FIXED_DOUBLE_ARRAY_TYPE:
68 FixedDoubleArray::cast(this)->FixedDoubleArrayPrint(out);
70 case CONSTANT_POOL_ARRAY_TYPE:
71 ConstantPoolArray::cast(this)->ConstantPoolArrayPrint(out);
73 case FIXED_ARRAY_TYPE:
74 FixedArray::cast(this)->FixedArrayPrint(out);
77 ByteArray::cast(this)->ByteArrayPrint(out);
80 FreeSpace::cast(this)->FreeSpacePrint(out);
83 #define PRINT_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \
84 case EXTERNAL_##TYPE##_ARRAY_TYPE: \
85 External##Type##Array::cast(this)->External##Type##ArrayPrint(out); \
88 TYPED_ARRAYS(PRINT_EXTERNAL_ARRAY)
89 #undef PRINT_EXTERNAL_ARRAY
91 #define PRINT_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
92 case Fixed##Type##Array::kInstanceType: \
93 Fixed##Type##Array::cast(this)->FixedTypedArrayPrint(out); \
96 TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY)
97 #undef PRINT_FIXED_TYPED_ARRAY
100 PrintF(out, "filler");
102 case JS_OBJECT_TYPE: // fall through
103 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
105 case JS_GENERATOR_OBJECT_TYPE:
107 JSObject::cast(this)->JSObjectPrint(out);
110 Oddball::cast(this)->to_string()->Print(out);
113 JSModule::cast(this)->JSModulePrint(out);
115 case JS_FUNCTION_TYPE:
116 JSFunction::cast(this)->JSFunctionPrint(out);
118 case JS_GLOBAL_PROXY_TYPE:
119 JSGlobalProxy::cast(this)->JSGlobalProxyPrint(out);
121 case JS_GLOBAL_OBJECT_TYPE:
122 JSGlobalObject::cast(this)->JSGlobalObjectPrint(out);
124 case JS_BUILTINS_OBJECT_TYPE:
125 JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(out);
128 PrintF(out, "Value wrapper around:");
129 JSValue::cast(this)->value()->Print(out);
132 JSDate::cast(this)->JSDatePrint(out);
135 Code::cast(this)->CodePrint(out);
138 JSProxy::cast(this)->JSProxyPrint(out);
140 case JS_FUNCTION_PROXY_TYPE:
141 JSFunctionProxy::cast(this)->JSFunctionProxyPrint(out);
144 JSSet::cast(this)->JSSetPrint(out);
147 JSMap::cast(this)->JSMapPrint(out);
149 case JS_SET_ITERATOR_TYPE:
150 JSSetIterator::cast(this)->JSSetIteratorPrint(out);
152 case JS_MAP_ITERATOR_TYPE:
153 JSMapIterator::cast(this)->JSMapIteratorPrint(out);
155 case JS_WEAK_MAP_TYPE:
156 JSWeakMap::cast(this)->JSWeakMapPrint(out);
158 case JS_WEAK_SET_TYPE:
159 JSWeakSet::cast(this)->JSWeakSetPrint(out);
162 Foreign::cast(this)->ForeignPrint(out);
164 case SHARED_FUNCTION_INFO_TYPE:
165 SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(out);
167 case JS_MESSAGE_OBJECT_TYPE:
168 JSMessageObject::cast(this)->JSMessageObjectPrint(out);
171 Cell::cast(this)->CellPrint(out);
173 case PROPERTY_CELL_TYPE:
174 PropertyCell::cast(this)->PropertyCellPrint(out);
176 case JS_ARRAY_BUFFER_TYPE:
177 JSArrayBuffer::cast(this)->JSArrayBufferPrint(out);
179 case JS_TYPED_ARRAY_TYPE:
180 JSTypedArray::cast(this)->JSTypedArrayPrint(out);
182 case JS_DATA_VIEW_TYPE:
183 JSDataView::cast(this)->JSDataViewPrint(out);
185 #define MAKE_STRUCT_CASE(NAME, Name, name) \
187 Name::cast(this)->Name##Print(out); \
189 STRUCT_LIST(MAKE_STRUCT_CASE)
190 #undef MAKE_STRUCT_CASE
193 PrintF(out, "UNKNOWN TYPE %d", map()->instance_type());
200 void ByteArray::ByteArrayPrint(FILE* out) {
201 PrintF(out, "byte array, data starts at %p", GetDataStartAddress());
205 void FreeSpace::FreeSpacePrint(FILE* out) {
206 PrintF(out, "free space, size %d", Size());
210 #define EXTERNAL_ARRAY_PRINTER(Type, type, TYPE, ctype, size) \
211 void External##Type##Array::External##Type##ArrayPrint(FILE* out) { \
212 PrintF(out, "external " #type " array"); \
215 TYPED_ARRAYS(EXTERNAL_ARRAY_PRINTER)
217 #undef EXTERNAL_ARRAY_PRINTER
220 template <class Traits>
221 void FixedTypedArray<Traits>::FixedTypedArrayPrint(FILE* out) {
222 PrintF(out, "fixed %s", Traits::Designator());
226 void JSObject::PrintProperties(FILE* out) {
227 if (HasFastProperties()) {
228 DescriptorArray* descs = map()->instance_descriptors();
229 for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
231 descs->GetKey(i)->NamePrint(out);
233 switch (descs->GetType(i)) {
235 FieldIndex index = FieldIndex::ForDescriptor(map(), i);
236 RawFastPropertyAt(index)->ShortPrint(out);
237 PrintF(out, " (field at offset %d)\n", index.property_index());
241 descs->GetConstant(i)->ShortPrint(out);
242 PrintF(out, " (constant)\n");
245 descs->GetCallbacksObject(i)->ShortPrint(out);
246 PrintF(out, " (callback)\n");
248 case NORMAL: // only in slow mode
249 case HANDLER: // only in lookup results, not in descriptors
250 case INTERCEPTOR: // only in lookup results, not in descriptors
251 // There are no transitions in the descriptor array.
258 property_dictionary()->Print(out);
264 static void DoPrintElements(FILE *out, Object* object) {
265 T* p = T::cast(object);
266 for (int i = 0; i < p->length(); i++) {
267 PrintF(out, " %d: %d\n", i, p->get_scalar(i));
273 static void DoPrintDoubleElements(FILE* out, Object* object) {
274 T* p = T::cast(object);
275 for (int i = 0; i < p->length(); i++) {
276 PrintF(out, " %d: %f\n", i, p->get_scalar(i));
281 void JSObject::PrintElements(FILE* out) {
282 // Don't call GetElementsKind, its validation code can cause the printer to
283 // fail when debugging.
284 switch (map()->elements_kind()) {
285 case FAST_HOLEY_SMI_ELEMENTS:
286 case FAST_SMI_ELEMENTS:
287 case FAST_HOLEY_ELEMENTS:
288 case FAST_ELEMENTS: {
289 // Print in array notation for non-sparse arrays.
290 FixedArray* p = FixedArray::cast(elements());
291 for (int i = 0; i < p->length(); i++) {
292 PrintF(out, " %d: ", i);
293 p->get(i)->ShortPrint(out);
298 case FAST_HOLEY_DOUBLE_ELEMENTS:
299 case FAST_DOUBLE_ELEMENTS: {
300 // Print in array notation for non-sparse arrays.
301 if (elements()->length() > 0) {
302 FixedDoubleArray* p = FixedDoubleArray::cast(elements());
303 for (int i = 0; i < p->length(); i++) {
304 if (p->is_the_hole(i)) {
305 PrintF(out, " %d: <the hole>", i);
307 PrintF(out, " %d: %g", i, p->get_scalar(i));
316 #define PRINT_ELEMENTS(Kind, Type) \
318 DoPrintElements<Type>(out, elements()); \
322 #define PRINT_DOUBLE_ELEMENTS(Kind, Type) \
324 DoPrintDoubleElements<Type>(out, elements()); \
328 PRINT_ELEMENTS(EXTERNAL_UINT8_CLAMPED_ELEMENTS, ExternalUint8ClampedArray)
329 PRINT_ELEMENTS(EXTERNAL_INT8_ELEMENTS, ExternalInt8Array)
330 PRINT_ELEMENTS(EXTERNAL_UINT8_ELEMENTS,
332 PRINT_ELEMENTS(EXTERNAL_INT16_ELEMENTS, ExternalInt16Array)
333 PRINT_ELEMENTS(EXTERNAL_UINT16_ELEMENTS,
335 PRINT_ELEMENTS(EXTERNAL_INT32_ELEMENTS, ExternalInt32Array)
336 PRINT_ELEMENTS(EXTERNAL_UINT32_ELEMENTS,
338 PRINT_DOUBLE_ELEMENTS(EXTERNAL_FLOAT32_ELEMENTS, ExternalFloat32Array)
339 PRINT_DOUBLE_ELEMENTS(EXTERNAL_FLOAT64_ELEMENTS, ExternalFloat64Array)
342 PRINT_ELEMENTS(UINT8_ELEMENTS, FixedUint8Array)
343 PRINT_ELEMENTS(UINT8_CLAMPED_ELEMENTS, FixedUint8ClampedArray)
344 PRINT_ELEMENTS(INT8_ELEMENTS, FixedInt8Array)
345 PRINT_ELEMENTS(UINT16_ELEMENTS, FixedUint16Array)
346 PRINT_ELEMENTS(INT16_ELEMENTS, FixedInt16Array)
347 PRINT_ELEMENTS(UINT32_ELEMENTS, FixedUint32Array)
348 PRINT_ELEMENTS(INT32_ELEMENTS, FixedInt32Array)
349 PRINT_DOUBLE_ELEMENTS(FLOAT32_ELEMENTS, FixedFloat32Array)
350 PRINT_DOUBLE_ELEMENTS(FLOAT64_ELEMENTS, FixedFloat64Array)
352 #undef PRINT_DOUBLE_ELEMENTS
353 #undef PRINT_ELEMENTS
355 case DICTIONARY_ELEMENTS:
356 elements()->Print(out);
358 case SLOPPY_ARGUMENTS_ELEMENTS: {
359 FixedArray* p = FixedArray::cast(elements());
360 PrintF(out, " parameter map:");
361 for (int i = 2; i < p->length(); i++) {
362 PrintF(out, " %d:", i - 2);
363 p->get(i)->ShortPrint(out);
365 PrintF(out, "\n context: ");
366 p->get(0)->ShortPrint(out);
367 PrintF(out, "\n arguments: ");
368 p->get(1)->ShortPrint(out);
376 void JSObject::PrintTransitions(FILE* out) {
377 if (!map()->HasTransitionArray()) return;
378 TransitionArray* transitions = map()->transitions();
379 for (int i = 0; i < transitions->number_of_transitions(); i++) {
380 Name* key = transitions->GetKey(i);
384 if (key == GetHeap()->frozen_symbol()) {
385 PrintF(out, " (transition to frozen)\n");
386 } else if (key == GetHeap()->elements_transition_symbol()) {
387 PrintF(out, " (transition to ");
388 PrintElementsKind(out, transitions->GetTarget(i)->elements_kind());
390 } else if (key == GetHeap()->observed_symbol()) {
391 PrintF(out, " (transition to Object.observe)\n");
393 switch (transitions->GetTargetDetails(i).type()) {
395 PrintF(out, " (transition to field)\n");
399 PrintF(out, " (transition to constant)\n");
402 PrintF(out, " (transition to callback)\n");
404 // Values below are never in the target descriptor array.
417 void JSObject::JSObjectPrint(FILE* out) {
418 PrintF(out, "%p: [JSObject]\n", reinterpret_cast<void*>(this));
419 PrintF(out, " - map = %p [", reinterpret_cast<void*>(map()));
420 // Don't call GetElementsKind, its validation code can cause the printer to
421 // fail when debugging.
422 PrintElementsKind(out, this->map()->elements_kind());
424 "]\n - prototype = %p\n",
425 reinterpret_cast<void*>(GetPrototype()));
427 PrintProperties(out);
428 PrintTransitions(out);
434 void JSModule::JSModulePrint(FILE* out) {
435 HeapObject::PrintHeader(out, "JSModule");
436 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
437 PrintF(out, " - context = ");
438 context()->Print(out);
439 PrintF(out, " - scope_info = ");
440 scope_info()->ShortPrint(out);
441 PrintElementsKind(out, this->map()->elements_kind());
443 PrintProperties(out);
449 static const char* TypeToString(InstanceType type) {
451 #define TYPE_TO_STRING(TYPE) case TYPE: return #TYPE;
452 INSTANCE_TYPE_LIST(TYPE_TO_STRING)
453 #undef TYPE_TO_STRING
456 return "UNKNOWN"; // Keep the compiler happy.
460 void Symbol::SymbolPrint(FILE* out) {
461 HeapObject::PrintHeader(out, "Symbol");
462 PrintF(out, " - hash: %d\n", Hash());
463 PrintF(out, " - name: ");
464 name()->ShortPrint();
465 PrintF(out, " - private: %d\n", is_private());
470 void Map::MapPrint(FILE* out) {
471 HeapObject::PrintHeader(out, "Map");
472 PrintF(out, " - type: %s\n", TypeToString(instance_type()));
473 PrintF(out, " - instance size: %d\n", instance_size());
474 PrintF(out, " - inobject properties: %d\n", inobject_properties());
475 PrintF(out, " - elements kind: ");
476 PrintElementsKind(out, elements_kind());
477 PrintF(out, "\n - pre-allocated property fields: %d\n",
478 pre_allocated_property_fields());
479 PrintF(out, " - unused property fields: %d\n", unused_property_fields());
480 if (is_hidden_prototype()) {
481 PrintF(out, " - hidden_prototype\n");
483 if (has_named_interceptor()) {
484 PrintF(out, " - named_interceptor\n");
486 if (has_indexed_interceptor()) {
487 PrintF(out, " - indexed_interceptor\n");
489 if (is_undetectable()) {
490 PrintF(out, " - undetectable\n");
492 if (has_instance_call_handler()) {
493 PrintF(out, " - instance_call_handler\n");
495 if (is_access_check_needed()) {
496 PrintF(out, " - access_check_needed\n");
499 PrintF(out, " - frozen\n");
500 } else if (!is_extensible()) {
501 PrintF(out, " - sealed\n");
503 PrintF(out, " - back pointer: ");
504 GetBackPointer()->ShortPrint(out);
505 PrintF(out, "\n - instance descriptors %s#%i: ",
506 owns_descriptors() ? "(own) " : "",
507 NumberOfOwnDescriptors());
508 instance_descriptors()->ShortPrint(out);
509 if (HasTransitionArray()) {
510 PrintF(out, "\n - transitions: ");
511 transitions()->ShortPrint(out);
513 PrintF(out, "\n - prototype: ");
514 prototype()->ShortPrint(out);
515 PrintF(out, "\n - constructor: ");
516 constructor()->ShortPrint(out);
517 PrintF(out, "\n - code cache: ");
518 code_cache()->ShortPrint(out);
519 PrintF(out, "\n - dependent code: ");
520 dependent_code()->ShortPrint(out);
525 void CodeCache::CodeCachePrint(FILE* out) {
526 HeapObject::PrintHeader(out, "CodeCache");
527 PrintF(out, "\n - default_cache: ");
528 default_cache()->ShortPrint(out);
529 PrintF(out, "\n - normal_type_cache: ");
530 normal_type_cache()->ShortPrint(out);
534 void PolymorphicCodeCache::PolymorphicCodeCachePrint(FILE* out) {
535 HeapObject::PrintHeader(out, "PolymorphicCodeCache");
536 PrintF(out, "\n - cache: ");
537 cache()->ShortPrint(out);
541 void TypeFeedbackInfo::TypeFeedbackInfoPrint(FILE* out) {
542 HeapObject::PrintHeader(out, "TypeFeedbackInfo");
543 PrintF(out, " - ic_total_count: %d, ic_with_type_info_count: %d\n",
544 ic_total_count(), ic_with_type_info_count());
548 void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(FILE* out) {
549 HeapObject::PrintHeader(out, "AliasedArgumentsEntry");
550 PrintF(out, "\n - aliased_context_slot: %d", aliased_context_slot());
554 void FixedArray::FixedArrayPrint(FILE* out) {
555 HeapObject::PrintHeader(out, "FixedArray");
556 PrintF(out, " - length: %d", length());
557 for (int i = 0; i < length(); i++) {
558 PrintF(out, "\n [%d]: ", i);
559 get(i)->ShortPrint(out);
565 void FixedDoubleArray::FixedDoubleArrayPrint(FILE* out) {
566 HeapObject::PrintHeader(out, "FixedDoubleArray");
567 PrintF(out, " - length: %d", length());
568 for (int i = 0; i < length(); i++) {
569 if (is_the_hole(i)) {
570 PrintF(out, "\n [%d]: <the hole>", i);
572 PrintF(out, "\n [%d]: %g", i, get_scalar(i));
579 void ConstantPoolArray::ConstantPoolArrayPrint(FILE* out) {
580 HeapObject::PrintHeader(out, "ConstantPoolArray");
581 PrintF(out, " - length: %d", length());
582 for (int i = 0; i <= last_index(INT32, SMALL_SECTION); i++) {
583 if (i < last_index(INT64, SMALL_SECTION)) {
584 PrintF(out, "\n [%d]: double: %g", i, get_int64_entry_as_double(i));
585 } else if (i <= last_index(CODE_PTR, SMALL_SECTION)) {
586 PrintF(out, "\n [%d]: code target pointer: %p", i,
587 reinterpret_cast<void*>(get_code_ptr_entry(i)));
588 } else if (i <= last_index(HEAP_PTR, SMALL_SECTION)) {
589 PrintF(out, "\n [%d]: heap pointer: %p", i,
590 reinterpret_cast<void*>(get_heap_ptr_entry(i)));
591 } else if (i <= last_index(INT32, SMALL_SECTION)) {
592 PrintF(out, "\n [%d]: int32: %d", i, get_int32_entry(i));
595 if (is_extended_layout()) {
596 PrintF(out, "\n Extended section:");
597 for (int i = first_extended_section_index();
598 i <= last_index(INT32, EXTENDED_SECTION); i++) {
599 if (i < last_index(INT64, EXTENDED_SECTION)) {
600 PrintF(out, "\n [%d]: double: %g", i, get_int64_entry_as_double(i));
601 } else if (i <= last_index(CODE_PTR, EXTENDED_SECTION)) {
602 PrintF(out, "\n [%d]: code target pointer: %p", i,
603 reinterpret_cast<void*>(get_code_ptr_entry(i)));
604 } else if (i <= last_index(HEAP_PTR, EXTENDED_SECTION)) {
605 PrintF(out, "\n [%d]: heap pointer: %p", i,
606 reinterpret_cast<void*>(get_heap_ptr_entry(i)));
607 } else if (i <= last_index(INT32, EXTENDED_SECTION)) {
608 PrintF(out, "\n [%d]: int32: %d", i, get_int32_entry(i));
616 void JSValue::JSValuePrint(FILE* out) {
617 HeapObject::PrintHeader(out, "ValueObject");
622 void JSMessageObject::JSMessageObjectPrint(FILE* out) {
623 HeapObject::PrintHeader(out, "JSMessageObject");
624 PrintF(out, " - type: ");
625 type()->ShortPrint(out);
626 PrintF(out, "\n - arguments: ");
627 arguments()->ShortPrint(out);
628 PrintF(out, "\n - start_position: %d", start_position());
629 PrintF(out, "\n - end_position: %d", end_position());
630 PrintF(out, "\n - script: ");
631 script()->ShortPrint(out);
632 PrintF(out, "\n - stack_frames: ");
633 stack_frames()->ShortPrint(out);
638 void String::StringPrint(FILE* out) {
639 if (StringShape(this).IsInternalized()) {
641 } else if (StringShape(this).IsCons()) {
647 const char truncated_epilogue[] = "...<truncated>";
649 if (!FLAG_use_verbose_printer) {
651 len = 100 - sizeof(truncated_epilogue);
654 for (int i = 0; i < len; i++) {
655 PrintF(out, "%c", Get(i));
657 if (len != length()) {
658 PrintF(out, "%s", truncated_epilogue);
661 if (!StringShape(this).IsInternalized()) PrintF(out, "\"");
665 void Name::NamePrint(FILE* out) {
667 String::cast(this)->StringPrint(out);
673 // This method is only meant to be called from gdb for debugging purposes.
674 // Since the string can also be in two-byte encoding, non-ASCII characters
675 // will be ignored in the output.
676 char* String::ToAsciiArray() {
677 // Static so that subsequent calls frees previously allocated space.
678 // This also means that previous results will be overwritten.
679 static char* buffer = NULL;
680 if (buffer != NULL) free(buffer);
681 buffer = new char[length()+1];
682 WriteToFlat(this, reinterpret_cast<uint8_t*>(buffer), 0, length());
683 buffer[length()] = 0;
688 static const char* const weekdays[] = {
689 "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
693 void JSDate::JSDatePrint(FILE* out) {
694 HeapObject::PrintHeader(out, "JSDate");
695 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
696 PrintF(out, " - value = ");
698 if (!year()->IsSmi()) {
699 PrintF(out, " - time = NaN\n");
701 PrintF(out, " - time = %s %04d/%02d/%02d %02d:%02d:%02d\n",
702 weekdays[weekday()->IsSmi() ? Smi::cast(weekday())->value() + 1 : 0],
703 year()->IsSmi() ? Smi::cast(year())->value() : -1,
704 month()->IsSmi() ? Smi::cast(month())->value() : -1,
705 day()->IsSmi() ? Smi::cast(day())->value() : -1,
706 hour()->IsSmi() ? Smi::cast(hour())->value() : -1,
707 min()->IsSmi() ? Smi::cast(min())->value() : -1,
708 sec()->IsSmi() ? Smi::cast(sec())->value() : -1);
713 void JSProxy::JSProxyPrint(FILE* out) {
714 HeapObject::PrintHeader(out, "JSProxy");
715 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
716 PrintF(out, " - handler = ");
717 handler()->Print(out);
718 PrintF(out, "\n - hash = ");
724 void JSFunctionProxy::JSFunctionProxyPrint(FILE* out) {
725 HeapObject::PrintHeader(out, "JSFunctionProxy");
726 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
727 PrintF(out, " - handler = ");
728 handler()->Print(out);
729 PrintF(out, "\n - call_trap = ");
730 call_trap()->Print(out);
731 PrintF(out, "\n - construct_trap = ");
732 construct_trap()->Print(out);
737 void JSSet::JSSetPrint(FILE* out) {
738 HeapObject::PrintHeader(out, "JSSet");
739 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
740 PrintF(out, " - table = ");
741 table()->ShortPrint(out);
746 void JSMap::JSMapPrint(FILE* out) {
747 HeapObject::PrintHeader(out, "JSMap");
748 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
749 PrintF(out, " - table = ");
750 table()->ShortPrint(out);
755 template<class Derived, class TableType>
756 void OrderedHashTableIterator<Derived, TableType>::
757 OrderedHashTableIteratorPrint(FILE* out) {
758 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
759 PrintF(out, " - table = ");
760 table()->ShortPrint(out);
761 PrintF(out, "\n - index = ");
762 index()->ShortPrint(out);
763 PrintF(out, "\n - kind = ");
764 kind()->ShortPrint(out);
770 OrderedHashTableIterator<JSSetIterator,
771 OrderedHashSet>::OrderedHashTableIteratorPrint(FILE* out);
775 OrderedHashTableIterator<JSMapIterator,
776 OrderedHashMap>::OrderedHashTableIteratorPrint(FILE* out);
779 void JSSetIterator::JSSetIteratorPrint(FILE* out) {
780 HeapObject::PrintHeader(out, "JSSetIterator");
781 OrderedHashTableIteratorPrint(out);
785 void JSMapIterator::JSMapIteratorPrint(FILE* out) {
786 HeapObject::PrintHeader(out, "JSMapIterator");
787 OrderedHashTableIteratorPrint(out);
791 void JSWeakMap::JSWeakMapPrint(FILE* out) {
792 HeapObject::PrintHeader(out, "JSWeakMap");
793 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
794 PrintF(out, " - table = ");
795 table()->ShortPrint(out);
800 void JSWeakSet::JSWeakSetPrint(FILE* out) {
801 HeapObject::PrintHeader(out, "JSWeakSet");
802 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
803 PrintF(out, " - table = ");
804 table()->ShortPrint(out);
809 void JSArrayBuffer::JSArrayBufferPrint(FILE* out) {
810 HeapObject::PrintHeader(out, "JSArrayBuffer");
811 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
812 PrintF(out, " - backing_store = %p\n", backing_store());
813 PrintF(out, " - byte_length = ");
814 byte_length()->ShortPrint(out);
819 void JSTypedArray::JSTypedArrayPrint(FILE* out) {
820 HeapObject::PrintHeader(out, "JSTypedArray");
821 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
822 PrintF(out, " - buffer =");
823 buffer()->ShortPrint(out);
824 PrintF(out, "\n - byte_offset = ");
825 byte_offset()->ShortPrint(out);
826 PrintF(out, "\n - byte_length = ");
827 byte_length()->ShortPrint(out);
828 PrintF(out, "\n - length = ");
829 length()->ShortPrint(out);
835 void JSDataView::JSDataViewPrint(FILE* out) {
836 HeapObject::PrintHeader(out, "JSDataView");
837 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
838 PrintF(out, " - buffer =");
839 buffer()->ShortPrint(out);
840 PrintF(out, "\n - byte_offset = ");
841 byte_offset()->ShortPrint(out);
842 PrintF(out, "\n - byte_length = ");
843 byte_length()->ShortPrint(out);
848 void JSFunction::JSFunctionPrint(FILE* out) {
849 HeapObject::PrintHeader(out, "Function");
850 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
851 PrintF(out, " - initial_map = ");
852 if (has_initial_map()) {
853 initial_map()->ShortPrint(out);
855 PrintF(out, "\n - shared_info = ");
856 shared()->ShortPrint(out);
857 PrintF(out, "\n - name = ");
858 shared()->name()->Print(out);
859 PrintF(out, "\n - context = ");
860 context()->ShortPrint(out);
861 if (shared()->bound()) {
862 PrintF(out, "\n - bindings = ");
863 function_bindings()->ShortPrint(out);
865 PrintF(out, "\n - literals = ");
866 literals()->ShortPrint(out);
868 PrintF(out, "\n - code = ");
869 code()->ShortPrint(out);
872 PrintProperties(out);
879 void SharedFunctionInfo::SharedFunctionInfoPrint(FILE* out) {
880 HeapObject::PrintHeader(out, "SharedFunctionInfo");
881 PrintF(out, " - name: ");
882 name()->ShortPrint(out);
883 PrintF(out, "\n - expected_nof_properties: %d", expected_nof_properties());
884 PrintF(out, "\n - ast_node_count: %d", ast_node_count());
885 PrintF(out, "\n - instance class name = ");
886 instance_class_name()->Print(out);
887 PrintF(out, "\n - code = ");
888 code()->ShortPrint(out);
889 if (HasSourceCode()) {
890 PrintF(out, "\n - source code = ");
891 String* source = String::cast(Script::cast(script())->source());
892 int start = start_position();
893 int length = end_position() - start;
894 SmartArrayPointer<char> source_string =
895 source->ToCString(DISALLOW_NULLS,
896 FAST_STRING_TRAVERSAL,
897 start, length, NULL);
898 PrintF(out, "%s", source_string.get());
900 // Script files are often large, hard to read.
901 // PrintF(out, "\n - script =");
902 // script()->Print(out);
903 PrintF(out, "\n - function token position = %d", function_token_position());
904 PrintF(out, "\n - start position = %d", start_position());
905 PrintF(out, "\n - end position = %d", end_position());
906 PrintF(out, "\n - is expression = %d", is_expression());
907 PrintF(out, "\n - debug info = ");
908 debug_info()->ShortPrint(out);
909 PrintF(out, "\n - length = %d", length());
910 PrintF(out, "\n - optimized_code_map = ");
911 optimized_code_map()->ShortPrint(out);
912 PrintF(out, "\n - feedback_vector = ");
913 feedback_vector()->FixedArrayPrint(out);
918 void JSGlobalProxy::JSGlobalProxyPrint(FILE* out) {
919 PrintF(out, "global_proxy ");
921 PrintF(out, "native context : ");
922 native_context()->ShortPrint(out);
927 void JSGlobalObject::JSGlobalObjectPrint(FILE* out) {
928 PrintF(out, "global ");
930 PrintF(out, "native context : ");
931 native_context()->ShortPrint(out);
936 void JSBuiltinsObject::JSBuiltinsObjectPrint(FILE* out) {
937 PrintF(out, "builtins ");
942 void Cell::CellPrint(FILE* out) {
943 HeapObject::PrintHeader(out, "Cell");
947 void PropertyCell::PropertyCellPrint(FILE* out) {
948 HeapObject::PrintHeader(out, "PropertyCell");
952 void Code::CodePrint(FILE* out) {
953 HeapObject::PrintHeader(out, "Code");
954 #ifdef ENABLE_DISASSEMBLER
955 if (FLAG_use_verbose_printer) {
956 Disassemble(NULL, out);
962 void Foreign::ForeignPrint(FILE* out) {
963 PrintF(out, "foreign address : %p", foreign_address());
967 void ExecutableAccessorInfo::ExecutableAccessorInfoPrint(FILE* out) {
968 HeapObject::PrintHeader(out, "ExecutableAccessorInfo");
969 PrintF(out, "\n - name: ");
970 name()->ShortPrint(out);
971 PrintF(out, "\n - flag: ");
972 flag()->ShortPrint(out);
973 PrintF(out, "\n - getter: ");
974 getter()->ShortPrint(out);
975 PrintF(out, "\n - setter: ");
976 setter()->ShortPrint(out);
977 PrintF(out, "\n - data: ");
978 data()->ShortPrint(out);
982 void DeclaredAccessorInfo::DeclaredAccessorInfoPrint(FILE* out) {
983 HeapObject::PrintHeader(out, "DeclaredAccessorInfo");
984 PrintF(out, "\n - name: ");
985 name()->ShortPrint(out);
986 PrintF(out, "\n - flag: ");
987 flag()->ShortPrint(out);
988 PrintF(out, "\n - descriptor: ");
989 descriptor()->ShortPrint(out);
993 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorPrint(FILE* out) {
994 HeapObject::PrintHeader(out, "DeclaredAccessorDescriptor");
995 PrintF(out, "\n - internal field: ");
996 serialized_data()->ShortPrint(out);
1000 void Box::BoxPrint(FILE* out) {
1001 HeapObject::PrintHeader(out, "Box");
1002 PrintF(out, "\n - value: ");
1003 value()->ShortPrint(out);
1007 void AccessorPair::AccessorPairPrint(FILE* out) {
1008 HeapObject::PrintHeader(out, "AccessorPair");
1009 PrintF(out, "\n - getter: ");
1010 getter()->ShortPrint(out);
1011 PrintF(out, "\n - setter: ");
1012 setter()->ShortPrint(out);
1013 PrintF(out, "\n - flag: ");
1014 access_flags()->ShortPrint(out);
1018 void AccessCheckInfo::AccessCheckInfoPrint(FILE* out) {
1019 HeapObject::PrintHeader(out, "AccessCheckInfo");
1020 PrintF(out, "\n - named_callback: ");
1021 named_callback()->ShortPrint(out);
1022 PrintF(out, "\n - indexed_callback: ");
1023 indexed_callback()->ShortPrint(out);
1024 PrintF(out, "\n - data: ");
1025 data()->ShortPrint(out);
1029 void InterceptorInfo::InterceptorInfoPrint(FILE* out) {
1030 HeapObject::PrintHeader(out, "InterceptorInfo");
1031 PrintF(out, "\n - getter: ");
1032 getter()->ShortPrint(out);
1033 PrintF(out, "\n - setter: ");
1034 setter()->ShortPrint(out);
1035 PrintF(out, "\n - query: ");
1036 query()->ShortPrint(out);
1037 PrintF(out, "\n - deleter: ");
1038 deleter()->ShortPrint(out);
1039 PrintF(out, "\n - enumerator: ");
1040 enumerator()->ShortPrint(out);
1041 PrintF(out, "\n - data: ");
1042 data()->ShortPrint(out);
1046 void CallHandlerInfo::CallHandlerInfoPrint(FILE* out) {
1047 HeapObject::PrintHeader(out, "CallHandlerInfo");
1048 PrintF(out, "\n - callback: ");
1049 callback()->ShortPrint(out);
1050 PrintF(out, "\n - data: ");
1051 data()->ShortPrint(out);
1052 PrintF(out, "\n - call_stub_cache: ");
1056 void FunctionTemplateInfo::FunctionTemplateInfoPrint(FILE* out) {
1057 HeapObject::PrintHeader(out, "FunctionTemplateInfo");
1058 PrintF(out, "\n - class name: ");
1059 class_name()->ShortPrint(out);
1060 PrintF(out, "\n - tag: ");
1061 tag()->ShortPrint(out);
1062 PrintF(out, "\n - property_list: ");
1063 property_list()->ShortPrint(out);
1064 PrintF(out, "\n - serial_number: ");
1065 serial_number()->ShortPrint(out);
1066 PrintF(out, "\n - call_code: ");
1067 call_code()->ShortPrint(out);
1068 PrintF(out, "\n - property_accessors: ");
1069 property_accessors()->ShortPrint(out);
1070 PrintF(out, "\n - prototype_template: ");
1071 prototype_template()->ShortPrint(out);
1072 PrintF(out, "\n - parent_template: ");
1073 parent_template()->ShortPrint(out);
1074 PrintF(out, "\n - named_property_handler: ");
1075 named_property_handler()->ShortPrint(out);
1076 PrintF(out, "\n - indexed_property_handler: ");
1077 indexed_property_handler()->ShortPrint(out);
1078 PrintF(out, "\n - instance_template: ");
1079 instance_template()->ShortPrint(out);
1080 PrintF(out, "\n - signature: ");
1081 signature()->ShortPrint(out);
1082 PrintF(out, "\n - access_check_info: ");
1083 access_check_info()->ShortPrint(out);
1084 PrintF(out, "\n - hidden_prototype: %s",
1085 hidden_prototype() ? "true" : "false");
1086 PrintF(out, "\n - undetectable: %s", undetectable() ? "true" : "false");
1087 PrintF(out, "\n - need_access_check: %s",
1088 needs_access_check() ? "true" : "false");
1092 void ObjectTemplateInfo::ObjectTemplateInfoPrint(FILE* out) {
1093 HeapObject::PrintHeader(out, "ObjectTemplateInfo");
1094 PrintF(out, " - tag: ");
1095 tag()->ShortPrint(out);
1096 PrintF(out, "\n - property_list: ");
1097 property_list()->ShortPrint(out);
1098 PrintF(out, "\n - property_accessors: ");
1099 property_accessors()->ShortPrint(out);
1100 PrintF(out, "\n - constructor: ");
1101 constructor()->ShortPrint(out);
1102 PrintF(out, "\n - internal_field_count: ");
1103 internal_field_count()->ShortPrint(out);
1108 void SignatureInfo::SignatureInfoPrint(FILE* out) {
1109 HeapObject::PrintHeader(out, "SignatureInfo");
1110 PrintF(out, "\n - receiver: ");
1111 receiver()->ShortPrint(out);
1112 PrintF(out, "\n - args: ");
1113 args()->ShortPrint(out);
1117 void TypeSwitchInfo::TypeSwitchInfoPrint(FILE* out) {
1118 HeapObject::PrintHeader(out, "TypeSwitchInfo");
1119 PrintF(out, "\n - types: ");
1120 types()->ShortPrint(out);
1124 void AllocationSite::AllocationSitePrint(FILE* out) {
1125 HeapObject::PrintHeader(out, "AllocationSite");
1126 PrintF(out, " - weak_next: ");
1127 weak_next()->ShortPrint(out);
1128 PrintF(out, "\n - dependent code: ");
1129 dependent_code()->ShortPrint(out);
1130 PrintF(out, "\n - nested site: ");
1131 nested_site()->ShortPrint(out);
1132 PrintF(out, "\n - memento found count: ");
1133 Smi::FromInt(memento_found_count())->ShortPrint(out);
1134 PrintF(out, "\n - memento create count: ");
1135 Smi::FromInt(memento_create_count())->ShortPrint(out);
1136 PrintF(out, "\n - pretenure decision: ");
1137 Smi::FromInt(pretenure_decision())->ShortPrint(out);
1138 PrintF(out, "\n - transition_info: ");
1139 if (transition_info()->IsSmi()) {
1140 ElementsKind kind = GetElementsKind();
1141 PrintF(out, "Array allocation with ElementsKind ");
1142 PrintElementsKind(out, kind);
1145 } else if (transition_info()->IsJSArray()) {
1146 PrintF(out, "Array literal ");
1147 transition_info()->ShortPrint(out);
1152 PrintF(out, "unknown transition_info");
1153 transition_info()->ShortPrint(out);
1158 void AllocationMemento::AllocationMementoPrint(FILE* out) {
1159 HeapObject::PrintHeader(out, "AllocationMemento");
1160 PrintF(out, " - allocation site: ");
1162 GetAllocationSite()->Print();
1164 PrintF(out, "<invalid>\n");
1169 void Script::ScriptPrint(FILE* out) {
1170 HeapObject::PrintHeader(out, "Script");
1171 PrintF(out, "\n - source: ");
1172 source()->ShortPrint(out);
1173 PrintF(out, "\n - name: ");
1174 name()->ShortPrint(out);
1175 PrintF(out, "\n - line_offset: ");
1176 line_offset()->ShortPrint(out);
1177 PrintF(out, "\n - column_offset: ");
1178 column_offset()->ShortPrint(out);
1179 PrintF(out, "\n - type: ");
1180 type()->ShortPrint(out);
1181 PrintF(out, "\n - id: ");
1182 id()->ShortPrint(out);
1183 PrintF(out, "\n - context data: ");
1184 context_data()->ShortPrint(out);
1185 PrintF(out, "\n - wrapper: ");
1186 wrapper()->ShortPrint(out);
1187 PrintF(out, "\n - compilation type: %d", compilation_type());
1188 PrintF(out, "\n - line ends: ");
1189 line_ends()->ShortPrint(out);
1190 PrintF(out, "\n - eval from shared: ");
1191 eval_from_shared()->ShortPrint(out);
1192 PrintF(out, "\n - eval from instructions offset: ");
1193 eval_from_instructions_offset()->ShortPrint(out);
1198 void DebugInfo::DebugInfoPrint(FILE* out) {
1199 HeapObject::PrintHeader(out, "DebugInfo");
1200 PrintF(out, "\n - shared: ");
1201 shared()->ShortPrint(out);
1202 PrintF(out, "\n - original_code: ");
1203 original_code()->ShortPrint(out);
1204 PrintF(out, "\n - code: ");
1205 code()->ShortPrint(out);
1206 PrintF(out, "\n - break_points: ");
1207 break_points()->Print(out);
1211 void BreakPointInfo::BreakPointInfoPrint(FILE* out) {
1212 HeapObject::PrintHeader(out, "BreakPointInfo");
1213 PrintF(out, "\n - code_position: %d", code_position()->value());
1214 PrintF(out, "\n - source_position: %d", source_position()->value());
1215 PrintF(out, "\n - statement_position: %d", statement_position()->value());
1216 PrintF(out, "\n - break_point_objects: ");
1217 break_point_objects()->ShortPrint(out);
1221 void DescriptorArray::PrintDescriptors(FILE* out) {
1222 PrintF(out, "Descriptor array %d\n", number_of_descriptors());
1223 for (int i = 0; i < number_of_descriptors(); i++) {
1224 PrintF(out, " %d: ", i);
1233 void TransitionArray::PrintTransitions(FILE* out) {
1234 PrintF(out, "Transition array %d\n", number_of_transitions());
1235 for (int i = 0; i < number_of_transitions(); i++) {
1236 PrintF(out, " %d: ", i);
1237 GetKey(i)->NamePrint(out);
1239 switch (GetTargetDetails(i).type()) {
1241 PrintF(out, " (transition to field)\n");
1245 PrintF(out, " (transition to constant)\n");
1248 PrintF(out, " (transition to callback)\n");
1250 // Values below are never in the target descriptor array.
1263 #endif // OBJECT_PRINT
1266 } } // namespace v8::internal