1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "disassembler.h"
33 #include "objects-visiting.h"
40 void MaybeObject::Print() {
45 void MaybeObject::Print(FILE* out) {
46 Object* this_as_object;
47 if (ToObject(&this_as_object)) {
48 if (this_as_object->IsSmi()) {
49 Smi::cast(this_as_object)->SmiPrint(out);
51 HeapObject::cast(this_as_object)->HeapObjectPrint(out);
54 Failure::cast(this)->FailurePrint(out);
60 void MaybeObject::PrintLn() {
65 void MaybeObject::PrintLn(FILE* out) {
71 void HeapObject::PrintHeader(FILE* out, const char* id) {
72 PrintF(out, "%p: [%s]\n", reinterpret_cast<void*>(this), id);
76 void HeapObject::HeapObjectPrint(FILE* out) {
77 InstanceType instance_type = map()->instance_type();
79 HandleScope scope(GetIsolate());
80 if (instance_type < FIRST_NONSTRING_TYPE) {
81 String::cast(this)->StringPrint(out);
85 switch (instance_type) {
87 Symbol::cast(this)->SymbolPrint(out);
90 Map::cast(this)->MapPrint(out);
92 case HEAP_NUMBER_TYPE:
93 HeapNumber::cast(this)->HeapNumberPrint(out);
96 Float32x4::cast(this)->Float32x4Print(out);
99 Int32x4::cast(this)->Int32x4Print(out);
101 case FIXED_DOUBLE_ARRAY_TYPE:
102 FixedDoubleArray::cast(this)->FixedDoubleArrayPrint(out);
104 case CONSTANT_POOL_ARRAY_TYPE:
105 ConstantPoolArray::cast(this)->ConstantPoolArrayPrint(out);
107 case FIXED_ARRAY_TYPE:
108 FixedArray::cast(this)->FixedArrayPrint(out);
110 case BYTE_ARRAY_TYPE:
111 ByteArray::cast(this)->ByteArrayPrint(out);
113 case FREE_SPACE_TYPE:
114 FreeSpace::cast(this)->FreeSpacePrint(out);
117 #define PRINT_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \
118 case EXTERNAL_##TYPE##_ARRAY_TYPE: \
119 External##Type##Array::cast(this)->External##Type##ArrayPrint(out); \
122 TYPED_ARRAYS(PRINT_EXTERNAL_ARRAY)
123 #undef PRINT_EXTERNAL_ARRAY
125 #define PRINT_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
126 case Fixed##Type##Array::kInstanceType: \
127 Fixed##Type##Array::cast(this)->FixedTypedArrayPrint(out); \
130 TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY)
131 #undef PRINT_FIXED_TYPED_ARRAY
134 PrintF(out, "filler");
136 case JS_OBJECT_TYPE: // fall through
137 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
139 case JS_GENERATOR_OBJECT_TYPE:
141 JSObject::cast(this)->JSObjectPrint(out);
144 Oddball::cast(this)->to_string()->Print(out);
147 JSModule::cast(this)->JSModulePrint(out);
149 case JS_FUNCTION_TYPE:
150 JSFunction::cast(this)->JSFunctionPrint(out);
152 case JS_GLOBAL_PROXY_TYPE:
153 JSGlobalProxy::cast(this)->JSGlobalProxyPrint(out);
155 case JS_GLOBAL_OBJECT_TYPE:
156 JSGlobalObject::cast(this)->JSGlobalObjectPrint(out);
158 case JS_BUILTINS_OBJECT_TYPE:
159 JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(out);
162 PrintF(out, "Value wrapper around:");
163 JSValue::cast(this)->value()->Print(out);
166 JSDate::cast(this)->JSDatePrint(out);
169 Code::cast(this)->CodePrint(out);
172 JSProxy::cast(this)->JSProxyPrint(out);
174 case JS_FUNCTION_PROXY_TYPE:
175 JSFunctionProxy::cast(this)->JSFunctionProxyPrint(out);
178 JSSet::cast(this)->JSSetPrint(out);
181 JSMap::cast(this)->JSMapPrint(out);
183 case JS_WEAK_MAP_TYPE:
184 JSWeakMap::cast(this)->JSWeakMapPrint(out);
186 case JS_WEAK_SET_TYPE:
187 JSWeakSet::cast(this)->JSWeakSetPrint(out);
190 Foreign::cast(this)->ForeignPrint(out);
192 case SHARED_FUNCTION_INFO_TYPE:
193 SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(out);
195 case JS_MESSAGE_OBJECT_TYPE:
196 JSMessageObject::cast(this)->JSMessageObjectPrint(out);
199 Cell::cast(this)->CellPrint(out);
201 case PROPERTY_CELL_TYPE:
202 PropertyCell::cast(this)->PropertyCellPrint(out);
204 case JS_ARRAY_BUFFER_TYPE:
205 JSArrayBuffer::cast(this)->JSArrayBufferPrint(out);
207 case JS_TYPED_ARRAY_TYPE:
208 JSTypedArray::cast(this)->JSTypedArrayPrint(out);
210 case JS_DATA_VIEW_TYPE:
211 JSDataView::cast(this)->JSDataViewPrint(out);
213 #define MAKE_STRUCT_CASE(NAME, Name, name) \
215 Name::cast(this)->Name##Print(out); \
217 STRUCT_LIST(MAKE_STRUCT_CASE)
218 #undef MAKE_STRUCT_CASE
221 PrintF(out, "UNKNOWN TYPE %d", map()->instance_type());
228 void ByteArray::ByteArrayPrint(FILE* out) {
229 PrintF(out, "byte array, data starts at %p", GetDataStartAddress());
233 void FreeSpace::FreeSpacePrint(FILE* out) {
234 PrintF(out, "free space, size %d", Size());
238 #define EXTERNAL_ARRAY_PRINTER(Type, type, TYPE, ctype, size) \
239 void External##Type##Array::External##Type##ArrayPrint(FILE* out) { \
240 PrintF(out, "external " #type " array"); \
243 TYPED_ARRAYS(EXTERNAL_ARRAY_PRINTER)
245 #undef EXTERNAL_ARRAY_PRINTER
248 template <class Traits>
249 void FixedTypedArray<Traits>::FixedTypedArrayPrint(FILE* out) {
250 PrintF(out, "fixed %s", Traits::Designator());
254 void JSObject::PrintProperties(FILE* out) {
255 if (HasFastProperties()) {
256 DescriptorArray* descs = map()->instance_descriptors();
257 for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
259 descs->GetKey(i)->NamePrint(out);
261 switch (descs->GetType(i)) {
263 int index = descs->GetFieldIndex(i);
264 RawFastPropertyAt(index)->ShortPrint(out);
265 PrintF(out, " (field at offset %d)\n", index);
269 descs->GetConstant(i)->ShortPrint(out);
270 PrintF(out, " (constant)\n");
273 descs->GetCallbacksObject(i)->ShortPrint(out);
274 PrintF(out, " (callback)\n");
276 case NORMAL: // only in slow mode
277 case HANDLER: // only in lookup results, not in descriptors
278 case INTERCEPTOR: // only in lookup results, not in descriptors
279 // There are no transitions in the descriptor array.
287 property_dictionary()->Print(out);
293 static void DoPrintElements(FILE *out, Object* object) {
294 T* p = T::cast(object);
295 for (int i = 0; i < p->length(); i++) {
296 PrintF(out, " %d: %d\n", i, p->get_scalar(i));
302 static void DoPrintDoubleElements(FILE* out, Object* object) {
303 T* p = T::cast(object);
304 for (int i = 0; i < p->length(); i++) {
305 PrintF(out, " %d: %f\n", i, p->get_scalar(i));
311 static void DoPrintFloat32x4Elements(FILE* out, Object* object) {
312 T* p = T::cast(object);
313 for (int i = 0; i < p->length(); i++) {
314 float32x4_value_t value = p->get_scalar(i);
315 PrintF(out, " %d: (%f, %f, %f, %f)\n",
316 i, value.storage[0], value.storage[1],
317 value.storage[2], value.storage[3]);
323 static void DoPrintInt32x4Elements(FILE* out, Object* object) {
324 T* p = T::cast(object);
325 for (int i = 0; i < p->length(); i++) {
326 int32x4_value_t value = p->get_scalar(i);
327 PrintF(out, " %d: (%d, %d, %d, %d)\n",
328 i, value.storage[0], value.storage[1],
329 value.storage[2], value.storage[3]);
334 void JSObject::PrintElements(FILE* out) {
335 // Don't call GetElementsKind, its validation code can cause the printer to
336 // fail when debugging.
337 switch (map()->elements_kind()) {
338 case FAST_HOLEY_SMI_ELEMENTS:
339 case FAST_SMI_ELEMENTS:
340 case FAST_HOLEY_ELEMENTS:
341 case FAST_ELEMENTS: {
342 // Print in array notation for non-sparse arrays.
343 FixedArray* p = FixedArray::cast(elements());
344 for (int i = 0; i < p->length(); i++) {
345 PrintF(out, " %d: ", i);
346 p->get(i)->ShortPrint(out);
351 case FAST_HOLEY_DOUBLE_ELEMENTS:
352 case FAST_DOUBLE_ELEMENTS: {
353 // Print in array notation for non-sparse arrays.
354 if (elements()->length() > 0) {
355 FixedDoubleArray* p = FixedDoubleArray::cast(elements());
356 for (int i = 0; i < p->length(); i++) {
357 if (p->is_the_hole(i)) {
358 PrintF(out, " %d: <the hole>", i);
360 PrintF(out, " %d: %g", i, p->get_scalar(i));
369 #define PRINT_ELEMENTS(Kind, Type) \
371 DoPrintElements<Type>(out, elements()); \
375 #define PRINT_DOUBLE_ELEMENTS(Kind, Type) \
377 DoPrintDoubleElements<Type>(out, elements()); \
381 #define PRINT_FLOAT32x4_ELEMENTS(Kind, Type) \
383 DoPrintFloat32x4Elements<Type>(out, elements()); \
387 #define PRINT_INT32x4_ELEMENTS(Kind, Type) \
389 DoPrintInt32x4Elements<Type>(out, elements()); \
393 PRINT_ELEMENTS(EXTERNAL_UINT8_CLAMPED_ELEMENTS, ExternalUint8ClampedArray)
394 PRINT_ELEMENTS(EXTERNAL_INT8_ELEMENTS, ExternalInt8Array)
395 PRINT_ELEMENTS(EXTERNAL_UINT8_ELEMENTS,
397 PRINT_ELEMENTS(EXTERNAL_INT16_ELEMENTS, ExternalInt16Array)
398 PRINT_ELEMENTS(EXTERNAL_UINT16_ELEMENTS,
400 PRINT_ELEMENTS(EXTERNAL_INT32_ELEMENTS, ExternalInt32Array)
401 PRINT_ELEMENTS(EXTERNAL_UINT32_ELEMENTS,
403 PRINT_DOUBLE_ELEMENTS(EXTERNAL_FLOAT32_ELEMENTS, ExternalFloat32Array)
404 PRINT_DOUBLE_ELEMENTS(EXTERNAL_FLOAT64_ELEMENTS, ExternalFloat64Array)
405 PRINT_FLOAT32x4_ELEMENTS(EXTERNAL_FLOAT32x4_ELEMENTS,
406 ExternalFloat32x4Array)
407 PRINT_INT32x4_ELEMENTS(EXTERNAL_INT32x4_ELEMENTS, ExternalInt32x4Array)
410 PRINT_ELEMENTS(UINT8_ELEMENTS, FixedUint8Array)
411 PRINT_ELEMENTS(UINT8_CLAMPED_ELEMENTS, FixedUint8ClampedArray)
412 PRINT_ELEMENTS(INT8_ELEMENTS, FixedInt8Array)
413 PRINT_ELEMENTS(UINT16_ELEMENTS, FixedUint16Array)
414 PRINT_ELEMENTS(INT16_ELEMENTS, FixedInt16Array)
415 PRINT_ELEMENTS(UINT32_ELEMENTS, FixedUint32Array)
416 PRINT_ELEMENTS(INT32_ELEMENTS, FixedInt32Array)
417 PRINT_DOUBLE_ELEMENTS(FLOAT32_ELEMENTS, FixedFloat32Array)
418 PRINT_DOUBLE_ELEMENTS(FLOAT64_ELEMENTS, FixedFloat64Array)
419 PRINT_FLOAT32x4_ELEMENTS(FLOAT32x4_ELEMENTS, FixedFloat32x4Array)
420 PRINT_INT32x4_ELEMENTS(INT32x4_ELEMENTS, FixedInt32x4Array)
422 #undef PRINT_DOUBLE_ELEMENTS
423 #undef PRINT_ELEMENTS
425 case DICTIONARY_ELEMENTS:
426 elements()->Print(out);
428 case SLOPPY_ARGUMENTS_ELEMENTS: {
429 FixedArray* p = FixedArray::cast(elements());
430 PrintF(out, " parameter map:");
431 for (int i = 2; i < p->length(); i++) {
432 PrintF(out, " %d:", i - 2);
433 p->get(i)->ShortPrint(out);
435 PrintF(out, "\n context: ");
436 p->get(0)->ShortPrint(out);
437 PrintF(out, "\n arguments: ");
438 p->get(1)->ShortPrint(out);
446 void JSObject::PrintTransitions(FILE* out) {
447 if (!map()->HasTransitionArray()) return;
448 TransitionArray* transitions = map()->transitions();
449 for (int i = 0; i < transitions->number_of_transitions(); i++) {
450 Name* key = transitions->GetKey(i);
454 if (key == GetHeap()->frozen_symbol()) {
455 PrintF(out, " (transition to frozen)\n");
456 } else if (key == GetHeap()->elements_transition_symbol()) {
457 PrintF(out, " (transition to ");
458 PrintElementsKind(out, transitions->GetTarget(i)->elements_kind());
460 } else if (key == GetHeap()->observed_symbol()) {
461 PrintF(out, " (transition to Object.observe)\n");
463 switch (transitions->GetTargetDetails(i).type()) {
465 PrintF(out, " (transition to field)\n");
469 PrintF(out, " (transition to constant)\n");
472 PrintF(out, " (transition to callback)\n");
474 // Values below are never in the target descriptor array.
488 void JSObject::JSObjectPrint(FILE* out) {
489 PrintF(out, "%p: [JSObject]\n", reinterpret_cast<void*>(this));
490 PrintF(out, " - map = %p [", reinterpret_cast<void*>(map()));
491 // Don't call GetElementsKind, its validation code can cause the printer to
492 // fail when debugging.
493 PrintElementsKind(out, this->map()->elements_kind());
495 "]\n - prototype = %p\n",
496 reinterpret_cast<void*>(GetPrototype()));
498 PrintProperties(out);
499 PrintTransitions(out);
505 void JSModule::JSModulePrint(FILE* out) {
506 HeapObject::PrintHeader(out, "JSModule");
507 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
508 PrintF(out, " - context = ");
509 context()->Print(out);
510 PrintF(out, " - scope_info = ");
511 scope_info()->ShortPrint(out);
512 PrintElementsKind(out, this->map()->elements_kind());
514 PrintProperties(out);
520 static const char* TypeToString(InstanceType type) {
522 #define TYPE_TO_STRING(TYPE) case TYPE: return #TYPE;
523 INSTANCE_TYPE_LIST(TYPE_TO_STRING)
524 #undef TYPE_TO_STRING
527 return "UNKNOWN"; // Keep the compiler happy.
531 void Symbol::SymbolPrint(FILE* out) {
532 HeapObject::PrintHeader(out, "Symbol");
533 PrintF(out, " - hash: %d\n", Hash());
534 PrintF(out, " - name: ");
535 name()->ShortPrint();
536 PrintF(out, " - private: %d\n", is_private());
541 void Map::MapPrint(FILE* out) {
542 HeapObject::PrintHeader(out, "Map");
543 PrintF(out, " - type: %s\n", TypeToString(instance_type()));
544 PrintF(out, " - instance size: %d\n", instance_size());
545 PrintF(out, " - inobject properties: %d\n", inobject_properties());
546 PrintF(out, " - elements kind: ");
547 PrintElementsKind(out, elements_kind());
548 PrintF(out, "\n - pre-allocated property fields: %d\n",
549 pre_allocated_property_fields());
550 PrintF(out, " - unused property fields: %d\n", unused_property_fields());
551 if (is_hidden_prototype()) {
552 PrintF(out, " - hidden_prototype\n");
554 if (has_named_interceptor()) {
555 PrintF(out, " - named_interceptor\n");
557 if (has_indexed_interceptor()) {
558 PrintF(out, " - indexed_interceptor\n");
560 if (is_undetectable()) {
561 PrintF(out, " - undetectable\n");
563 if (has_instance_call_handler()) {
564 PrintF(out, " - instance_call_handler\n");
566 if (is_access_check_needed()) {
567 PrintF(out, " - access_check_needed\n");
570 PrintF(out, " - frozen\n");
571 } else if (!is_extensible()) {
572 PrintF(out, " - sealed\n");
574 PrintF(out, " - back pointer: ");
575 GetBackPointer()->ShortPrint(out);
576 PrintF(out, "\n - instance descriptors %s#%i: ",
577 owns_descriptors() ? "(own) " : "",
578 NumberOfOwnDescriptors());
579 instance_descriptors()->ShortPrint(out);
580 if (HasTransitionArray()) {
581 PrintF(out, "\n - transitions: ");
582 transitions()->ShortPrint(out);
584 PrintF(out, "\n - prototype: ");
585 prototype()->ShortPrint(out);
586 PrintF(out, "\n - constructor: ");
587 constructor()->ShortPrint(out);
588 PrintF(out, "\n - code cache: ");
589 code_cache()->ShortPrint(out);
590 PrintF(out, "\n - dependent code: ");
591 dependent_code()->ShortPrint(out);
596 void CodeCache::CodeCachePrint(FILE* out) {
597 HeapObject::PrintHeader(out, "CodeCache");
598 PrintF(out, "\n - default_cache: ");
599 default_cache()->ShortPrint(out);
600 PrintF(out, "\n - normal_type_cache: ");
601 normal_type_cache()->ShortPrint(out);
605 void PolymorphicCodeCache::PolymorphicCodeCachePrint(FILE* out) {
606 HeapObject::PrintHeader(out, "PolymorphicCodeCache");
607 PrintF(out, "\n - cache: ");
608 cache()->ShortPrint(out);
612 void TypeFeedbackInfo::TypeFeedbackInfoPrint(FILE* out) {
613 HeapObject::PrintHeader(out, "TypeFeedbackInfo");
614 PrintF(out, " - ic_total_count: %d, ic_with_type_info_count: %d\n",
615 ic_total_count(), ic_with_type_info_count());
616 PrintF(out, " - feedback_vector: ");
617 feedback_vector()->FixedArrayPrint(out);
621 void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(FILE* out) {
622 HeapObject::PrintHeader(out, "AliasedArgumentsEntry");
623 PrintF(out, "\n - aliased_context_slot: %d", aliased_context_slot());
627 void FixedArray::FixedArrayPrint(FILE* out) {
628 HeapObject::PrintHeader(out, "FixedArray");
629 PrintF(out, " - length: %d", length());
630 for (int i = 0; i < length(); i++) {
631 PrintF(out, "\n [%d]: ", i);
632 get(i)->ShortPrint(out);
638 void FixedDoubleArray::FixedDoubleArrayPrint(FILE* out) {
639 HeapObject::PrintHeader(out, "FixedDoubleArray");
640 PrintF(out, " - length: %d", length());
641 for (int i = 0; i < length(); i++) {
642 if (is_the_hole(i)) {
643 PrintF(out, "\n [%d]: <the hole>", i);
645 PrintF(out, "\n [%d]: %g", i, get_scalar(i));
652 void ConstantPoolArray::ConstantPoolArrayPrint(FILE* out) {
653 HeapObject::PrintHeader(out, "ConstantPoolArray");
654 PrintF(out, " - length: %d", length());
655 for (int i = 0; i < length(); i++) {
656 if (i < first_code_ptr_index()) {
657 PrintF(out, "\n [%d]: double: %g", i, get_int64_entry_as_double(i));
658 } else if (i < first_heap_ptr_index()) {
659 PrintF(out, "\n [%d]: code target pointer: %p", i,
660 reinterpret_cast<void*>(get_code_ptr_entry(i)));
661 } else if (i < first_int32_index()) {
662 PrintF(out, "\n [%d]: heap pointer: %p", i,
663 reinterpret_cast<void*>(get_heap_ptr_entry(i)));
665 PrintF(out, "\n [%d]: int32: %d", i, get_int32_entry(i));
672 void JSValue::JSValuePrint(FILE* out) {
673 HeapObject::PrintHeader(out, "ValueObject");
678 void JSMessageObject::JSMessageObjectPrint(FILE* out) {
679 HeapObject::PrintHeader(out, "JSMessageObject");
680 PrintF(out, " - type: ");
681 type()->ShortPrint(out);
682 PrintF(out, "\n - arguments: ");
683 arguments()->ShortPrint(out);
684 PrintF(out, "\n - start_position: %d", start_position());
685 PrintF(out, "\n - end_position: %d", end_position());
686 PrintF(out, "\n - script: ");
687 script()->ShortPrint(out);
688 PrintF(out, "\n - stack_frames: ");
689 stack_frames()->ShortPrint(out);
694 void String::StringPrint(FILE* out) {
695 if (StringShape(this).IsInternalized()) {
697 } else if (StringShape(this).IsCons()) {
703 const char truncated_epilogue[] = "...<truncated>";
705 if (!FLAG_use_verbose_printer) {
707 len = 100 - sizeof(truncated_epilogue);
710 for (int i = 0; i < len; i++) {
711 PrintF(out, "%c", Get(i));
713 if (len != length()) {
714 PrintF(out, "%s", truncated_epilogue);
717 if (!StringShape(this).IsInternalized()) PrintF(out, "\"");
721 void Name::NamePrint(FILE* out) {
723 String::cast(this)->StringPrint(out);
729 // This method is only meant to be called from gdb for debugging purposes.
730 // Since the string can also be in two-byte encoding, non-ASCII characters
731 // will be ignored in the output.
732 char* String::ToAsciiArray() {
733 // Static so that subsequent calls frees previously allocated space.
734 // This also means that previous results will be overwritten.
735 static char* buffer = NULL;
736 if (buffer != NULL) free(buffer);
737 buffer = new char[length()+1];
738 WriteToFlat(this, reinterpret_cast<uint8_t*>(buffer), 0, length());
739 buffer[length()] = 0;
744 static const char* const weekdays[] = {
745 "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
749 void JSDate::JSDatePrint(FILE* out) {
750 HeapObject::PrintHeader(out, "JSDate");
751 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
752 PrintF(out, " - value = ");
754 if (!year()->IsSmi()) {
755 PrintF(out, " - time = NaN\n");
757 PrintF(out, " - time = %s %04d/%02d/%02d %02d:%02d:%02d\n",
758 weekdays[weekday()->IsSmi() ? Smi::cast(weekday())->value() + 1 : 0],
759 year()->IsSmi() ? Smi::cast(year())->value() : -1,
760 month()->IsSmi() ? Smi::cast(month())->value() : -1,
761 day()->IsSmi() ? Smi::cast(day())->value() : -1,
762 hour()->IsSmi() ? Smi::cast(hour())->value() : -1,
763 min()->IsSmi() ? Smi::cast(min())->value() : -1,
764 sec()->IsSmi() ? Smi::cast(sec())->value() : -1);
769 void JSProxy::JSProxyPrint(FILE* out) {
770 HeapObject::PrintHeader(out, "JSProxy");
771 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
772 PrintF(out, " - handler = ");
773 handler()->Print(out);
774 PrintF(out, " - hash = ");
780 void JSFunctionProxy::JSFunctionProxyPrint(FILE* out) {
781 HeapObject::PrintHeader(out, "JSFunctionProxy");
782 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
783 PrintF(out, " - handler = ");
784 handler()->Print(out);
785 PrintF(out, " - call_trap = ");
786 call_trap()->Print(out);
787 PrintF(out, " - construct_trap = ");
788 construct_trap()->Print(out);
793 void JSSet::JSSetPrint(FILE* out) {
794 HeapObject::PrintHeader(out, "JSSet");
795 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
796 PrintF(out, " - table = ");
797 table()->ShortPrint(out);
802 void JSMap::JSMapPrint(FILE* out) {
803 HeapObject::PrintHeader(out, "JSMap");
804 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
805 PrintF(out, " - table = ");
806 table()->ShortPrint(out);
811 void JSWeakMap::JSWeakMapPrint(FILE* out) {
812 HeapObject::PrintHeader(out, "JSWeakMap");
813 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
814 PrintF(out, " - table = ");
815 table()->ShortPrint(out);
820 void JSWeakSet::JSWeakSetPrint(FILE* out) {
821 HeapObject::PrintHeader(out, "JSWeakSet");
822 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
823 PrintF(out, " - table = ");
824 table()->ShortPrint(out);
829 void JSArrayBuffer::JSArrayBufferPrint(FILE* out) {
830 HeapObject::PrintHeader(out, "JSArrayBuffer");
831 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
832 PrintF(out, " - backing_store = %p\n", backing_store());
833 PrintF(out, " - byte_length = ");
834 byte_length()->ShortPrint(out);
839 void JSTypedArray::JSTypedArrayPrint(FILE* out) {
840 HeapObject::PrintHeader(out, "JSTypedArray");
841 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
842 PrintF(out, " - buffer =");
843 buffer()->ShortPrint(out);
844 PrintF(out, "\n - byte_offset = ");
845 byte_offset()->ShortPrint(out);
846 PrintF(out, "\n - byte_length = ");
847 byte_length()->ShortPrint(out);
848 PrintF(out, "\n - length = ");
849 length()->ShortPrint(out);
855 void JSDataView::JSDataViewPrint(FILE* out) {
856 HeapObject::PrintHeader(out, "JSDataView");
857 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
858 PrintF(out, " - buffer =");
859 buffer()->ShortPrint(out);
860 PrintF(out, "\n - byte_offset = ");
861 byte_offset()->ShortPrint(out);
862 PrintF(out, "\n - byte_length = ");
863 byte_length()->ShortPrint(out);
868 void JSFunction::JSFunctionPrint(FILE* out) {
869 HeapObject::PrintHeader(out, "Function");
870 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
871 PrintF(out, " - initial_map = ");
872 if (has_initial_map()) {
873 initial_map()->ShortPrint(out);
875 PrintF(out, "\n - shared_info = ");
876 shared()->ShortPrint(out);
877 PrintF(out, "\n - name = ");
878 shared()->name()->Print(out);
879 PrintF(out, "\n - context = ");
880 context()->ShortPrint(out);
881 if (shared()->bound()) {
882 PrintF(out, "\n - bindings = ");
883 function_bindings()->ShortPrint(out);
885 PrintF(out, "\n - literals = ");
886 literals()->ShortPrint(out);
888 PrintF(out, "\n - code = ");
889 code()->ShortPrint(out);
892 PrintProperties(out);
899 void SharedFunctionInfo::SharedFunctionInfoPrint(FILE* out) {
900 HeapObject::PrintHeader(out, "SharedFunctionInfo");
901 PrintF(out, " - name: ");
902 name()->ShortPrint(out);
903 PrintF(out, "\n - expected_nof_properties: %d", expected_nof_properties());
904 PrintF(out, "\n - instance class name = ");
905 instance_class_name()->Print(out);
906 PrintF(out, "\n - code = ");
907 code()->ShortPrint(out);
908 if (HasSourceCode()) {
909 PrintF(out, "\n - source code = ");
910 String* source = String::cast(Script::cast(script())->source());
911 int start = start_position();
912 int length = end_position() - start;
913 SmartArrayPointer<char> source_string =
914 source->ToCString(DISALLOW_NULLS,
915 FAST_STRING_TRAVERSAL,
916 start, length, NULL);
917 PrintF(out, "%s", source_string.get());
919 // Script files are often large, hard to read.
920 // PrintF(out, "\n - script =");
921 // script()->Print(out);
922 PrintF(out, "\n - function token position = %d", function_token_position());
923 PrintF(out, "\n - start position = %d", start_position());
924 PrintF(out, "\n - end position = %d", end_position());
925 PrintF(out, "\n - is expression = %d", is_expression());
926 PrintF(out, "\n - debug info = ");
927 debug_info()->ShortPrint(out);
928 PrintF(out, "\n - length = %d", length());
929 PrintF(out, "\n - optimized_code_map = ");
930 optimized_code_map()->ShortPrint(out);
935 void JSGlobalProxy::JSGlobalProxyPrint(FILE* out) {
936 PrintF(out, "global_proxy ");
938 PrintF(out, "native context : ");
939 native_context()->ShortPrint(out);
944 void JSGlobalObject::JSGlobalObjectPrint(FILE* out) {
945 PrintF(out, "global ");
947 PrintF(out, "native context : ");
948 native_context()->ShortPrint(out);
953 void JSBuiltinsObject::JSBuiltinsObjectPrint(FILE* out) {
954 PrintF(out, "builtins ");
959 void Cell::CellPrint(FILE* out) {
960 HeapObject::PrintHeader(out, "Cell");
964 void PropertyCell::PropertyCellPrint(FILE* out) {
965 HeapObject::PrintHeader(out, "PropertyCell");
969 void Code::CodePrint(FILE* out) {
970 HeapObject::PrintHeader(out, "Code");
971 #ifdef ENABLE_DISASSEMBLER
972 if (FLAG_use_verbose_printer) {
973 Disassemble(NULL, out);
979 void Foreign::ForeignPrint(FILE* out) {
980 PrintF(out, "foreign address : %p", foreign_address());
984 void ExecutableAccessorInfo::ExecutableAccessorInfoPrint(FILE* out) {
985 HeapObject::PrintHeader(out, "ExecutableAccessorInfo");
986 PrintF(out, "\n - name: ");
987 name()->ShortPrint(out);
988 PrintF(out, "\n - flag: ");
989 flag()->ShortPrint(out);
990 PrintF(out, "\n - getter: ");
991 getter()->ShortPrint(out);
992 PrintF(out, "\n - setter: ");
993 setter()->ShortPrint(out);
994 PrintF(out, "\n - data: ");
995 data()->ShortPrint(out);
999 void DeclaredAccessorInfo::DeclaredAccessorInfoPrint(FILE* out) {
1000 HeapObject::PrintHeader(out, "DeclaredAccessorInfo");
1001 PrintF(out, "\n - name: ");
1002 name()->ShortPrint(out);
1003 PrintF(out, "\n - flag: ");
1004 flag()->ShortPrint(out);
1005 PrintF(out, "\n - descriptor: ");
1006 descriptor()->ShortPrint(out);
1010 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorPrint(FILE* out) {
1011 HeapObject::PrintHeader(out, "DeclaredAccessorDescriptor");
1012 PrintF(out, "\n - internal field: ");
1013 serialized_data()->ShortPrint(out);
1017 void Box::BoxPrint(FILE* out) {
1018 HeapObject::PrintHeader(out, "Box");
1019 PrintF(out, "\n - value: ");
1020 value()->ShortPrint(out);
1024 void AccessorPair::AccessorPairPrint(FILE* out) {
1025 HeapObject::PrintHeader(out, "AccessorPair");
1026 PrintF(out, "\n - getter: ");
1027 getter()->ShortPrint(out);
1028 PrintF(out, "\n - setter: ");
1029 setter()->ShortPrint(out);
1030 PrintF(out, "\n - flag: ");
1031 access_flags()->ShortPrint(out);
1035 void AccessCheckInfo::AccessCheckInfoPrint(FILE* out) {
1036 HeapObject::PrintHeader(out, "AccessCheckInfo");
1037 PrintF(out, "\n - named_callback: ");
1038 named_callback()->ShortPrint(out);
1039 PrintF(out, "\n - indexed_callback: ");
1040 indexed_callback()->ShortPrint(out);
1041 PrintF(out, "\n - data: ");
1042 data()->ShortPrint(out);
1046 void InterceptorInfo::InterceptorInfoPrint(FILE* out) {
1047 HeapObject::PrintHeader(out, "InterceptorInfo");
1048 PrintF(out, "\n - getter: ");
1049 getter()->ShortPrint(out);
1050 PrintF(out, "\n - setter: ");
1051 setter()->ShortPrint(out);
1052 PrintF(out, "\n - query: ");
1053 query()->ShortPrint(out);
1054 PrintF(out, "\n - deleter: ");
1055 deleter()->ShortPrint(out);
1056 PrintF(out, "\n - enumerator: ");
1057 enumerator()->ShortPrint(out);
1058 PrintF(out, "\n - data: ");
1059 data()->ShortPrint(out);
1063 void CallHandlerInfo::CallHandlerInfoPrint(FILE* out) {
1064 HeapObject::PrintHeader(out, "CallHandlerInfo");
1065 PrintF(out, "\n - callback: ");
1066 callback()->ShortPrint(out);
1067 PrintF(out, "\n - data: ");
1068 data()->ShortPrint(out);
1069 PrintF(out, "\n - call_stub_cache: ");
1073 void FunctionTemplateInfo::FunctionTemplateInfoPrint(FILE* out) {
1074 HeapObject::PrintHeader(out, "FunctionTemplateInfo");
1075 PrintF(out, "\n - class name: ");
1076 class_name()->ShortPrint(out);
1077 PrintF(out, "\n - tag: ");
1078 tag()->ShortPrint(out);
1079 PrintF(out, "\n - property_list: ");
1080 property_list()->ShortPrint(out);
1081 PrintF(out, "\n - serial_number: ");
1082 serial_number()->ShortPrint(out);
1083 PrintF(out, "\n - call_code: ");
1084 call_code()->ShortPrint(out);
1085 PrintF(out, "\n - property_accessors: ");
1086 property_accessors()->ShortPrint(out);
1087 PrintF(out, "\n - prototype_template: ");
1088 prototype_template()->ShortPrint(out);
1089 PrintF(out, "\n - parent_template: ");
1090 parent_template()->ShortPrint(out);
1091 PrintF(out, "\n - named_property_handler: ");
1092 named_property_handler()->ShortPrint(out);
1093 PrintF(out, "\n - indexed_property_handler: ");
1094 indexed_property_handler()->ShortPrint(out);
1095 PrintF(out, "\n - instance_template: ");
1096 instance_template()->ShortPrint(out);
1097 PrintF(out, "\n - signature: ");
1098 signature()->ShortPrint(out);
1099 PrintF(out, "\n - access_check_info: ");
1100 access_check_info()->ShortPrint(out);
1101 PrintF(out, "\n - hidden_prototype: %s",
1102 hidden_prototype() ? "true" : "false");
1103 PrintF(out, "\n - undetectable: %s", undetectable() ? "true" : "false");
1104 PrintF(out, "\n - need_access_check: %s",
1105 needs_access_check() ? "true" : "false");
1109 void ObjectTemplateInfo::ObjectTemplateInfoPrint(FILE* out) {
1110 HeapObject::PrintHeader(out, "ObjectTemplateInfo");
1111 PrintF(out, " - tag: ");
1112 tag()->ShortPrint(out);
1113 PrintF(out, "\n - property_list: ");
1114 property_list()->ShortPrint(out);
1115 PrintF(out, "\n - property_accessors: ");
1116 property_accessors()->ShortPrint(out);
1117 PrintF(out, "\n - constructor: ");
1118 constructor()->ShortPrint(out);
1119 PrintF(out, "\n - internal_field_count: ");
1120 internal_field_count()->ShortPrint(out);
1125 void SignatureInfo::SignatureInfoPrint(FILE* out) {
1126 HeapObject::PrintHeader(out, "SignatureInfo");
1127 PrintF(out, "\n - receiver: ");
1128 receiver()->ShortPrint(out);
1129 PrintF(out, "\n - args: ");
1130 args()->ShortPrint(out);
1134 void TypeSwitchInfo::TypeSwitchInfoPrint(FILE* out) {
1135 HeapObject::PrintHeader(out, "TypeSwitchInfo");
1136 PrintF(out, "\n - types: ");
1137 types()->ShortPrint(out);
1141 void AllocationSite::AllocationSitePrint(FILE* out) {
1142 HeapObject::PrintHeader(out, "AllocationSite");
1143 PrintF(out, " - weak_next: ");
1144 weak_next()->ShortPrint(out);
1145 PrintF(out, "\n - dependent code: ");
1146 dependent_code()->ShortPrint(out);
1147 PrintF(out, "\n - nested site: ");
1148 nested_site()->ShortPrint(out);
1149 PrintF(out, "\n - memento found count: ");
1150 Smi::FromInt(memento_found_count())->ShortPrint(out);
1151 PrintF(out, "\n - memento create count: ");
1152 Smi::FromInt(memento_create_count())->ShortPrint(out);
1153 PrintF(out, "\n - pretenure decision: ");
1154 Smi::FromInt(pretenure_decision())->ShortPrint(out);
1155 PrintF(out, "\n - transition_info: ");
1156 if (transition_info()->IsSmi()) {
1157 ElementsKind kind = GetElementsKind();
1158 PrintF(out, "Array allocation with ElementsKind ");
1159 PrintElementsKind(out, kind);
1162 } else if (transition_info()->IsJSArray()) {
1163 PrintF(out, "Array literal ");
1164 transition_info()->ShortPrint(out);
1169 PrintF(out, "unknown transition_info");
1170 transition_info()->ShortPrint(out);
1175 void AllocationMemento::AllocationMementoPrint(FILE* out) {
1176 HeapObject::PrintHeader(out, "AllocationMemento");
1177 PrintF(out, " - allocation site: ");
1179 GetAllocationSite()->Print();
1181 PrintF(out, "<invalid>\n");
1186 void Script::ScriptPrint(FILE* out) {
1187 HeapObject::PrintHeader(out, "Script");
1188 PrintF(out, "\n - source: ");
1189 source()->ShortPrint(out);
1190 PrintF(out, "\n - name: ");
1191 name()->ShortPrint(out);
1192 PrintF(out, "\n - line_offset: ");
1193 line_offset()->ShortPrint(out);
1194 PrintF(out, "\n - column_offset: ");
1195 column_offset()->ShortPrint(out);
1196 PrintF(out, "\n - type: ");
1197 type()->ShortPrint(out);
1198 PrintF(out, "\n - id: ");
1199 id()->ShortPrint(out);
1200 PrintF(out, "\n - context data: ");
1201 context_data()->ShortPrint(out);
1202 PrintF(out, "\n - wrapper: ");
1203 wrapper()->ShortPrint(out);
1204 PrintF(out, "\n - compilation type: %d", compilation_type());
1205 PrintF(out, "\n - line ends: ");
1206 line_ends()->ShortPrint(out);
1207 PrintF(out, "\n - eval from shared: ");
1208 eval_from_shared()->ShortPrint(out);
1209 PrintF(out, "\n - eval from instructions offset: ");
1210 eval_from_instructions_offset()->ShortPrint(out);
1215 #ifdef ENABLE_DEBUGGER_SUPPORT
1216 void DebugInfo::DebugInfoPrint(FILE* out) {
1217 HeapObject::PrintHeader(out, "DebugInfo");
1218 PrintF(out, "\n - shared: ");
1219 shared()->ShortPrint(out);
1220 PrintF(out, "\n - original_code: ");
1221 original_code()->ShortPrint(out);
1222 PrintF(out, "\n - code: ");
1223 code()->ShortPrint(out);
1224 PrintF(out, "\n - break_points: ");
1225 break_points()->Print(out);
1229 void BreakPointInfo::BreakPointInfoPrint(FILE* out) {
1230 HeapObject::PrintHeader(out, "BreakPointInfo");
1231 PrintF(out, "\n - code_position: %d", code_position()->value());
1232 PrintF(out, "\n - source_position: %d", source_position()->value());
1233 PrintF(out, "\n - statement_position: %d", statement_position()->value());
1234 PrintF(out, "\n - break_point_objects: ");
1235 break_point_objects()->ShortPrint(out);
1237 #endif // ENABLE_DEBUGGER_SUPPORT
1240 void DescriptorArray::PrintDescriptors(FILE* out) {
1241 PrintF(out, "Descriptor array %d\n", number_of_descriptors());
1242 for (int i = 0; i < number_of_descriptors(); i++) {
1243 PrintF(out, " %d: ", i);
1252 void TransitionArray::PrintTransitions(FILE* out) {
1253 PrintF(out, "Transition array %d\n", number_of_transitions());
1254 for (int i = 0; i < number_of_transitions(); i++) {
1255 PrintF(out, " %d: ", i);
1256 GetKey(i)->NamePrint(out);
1258 switch (GetTargetDetails(i).type()) {
1260 PrintF(out, " (transition to field)\n");
1264 PrintF(out, " (transition to constant)\n");
1267 PrintF(out, " (transition to callback)\n");
1269 // Values below are never in the target descriptor array.
1283 #endif // OBJECT_PRINT
1286 } } // namespace v8::internal