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);
68 Float32x4::cast(this)->Float32x4Print(out);
71 Float64x2::cast(this)->Float64x2Print(out);
74 Int32x4::cast(this)->Int32x4Print(out);
76 case FIXED_DOUBLE_ARRAY_TYPE:
77 FixedDoubleArray::cast(this)->FixedDoubleArrayPrint(out);
79 case CONSTANT_POOL_ARRAY_TYPE:
80 ConstantPoolArray::cast(this)->ConstantPoolArrayPrint(out);
82 case FIXED_ARRAY_TYPE:
83 FixedArray::cast(this)->FixedArrayPrint(out);
86 ByteArray::cast(this)->ByteArrayPrint(out);
89 FreeSpace::cast(this)->FreeSpacePrint(out);
92 #define PRINT_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \
93 case EXTERNAL_##TYPE##_ARRAY_TYPE: \
94 External##Type##Array::cast(this)->External##Type##ArrayPrint(out); \
97 TYPED_ARRAYS(PRINT_EXTERNAL_ARRAY)
98 #undef PRINT_EXTERNAL_ARRAY
100 #define PRINT_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
101 case Fixed##Type##Array::kInstanceType: \
102 Fixed##Type##Array::cast(this)->FixedTypedArrayPrint(out); \
105 TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY)
106 #undef PRINT_FIXED_TYPED_ARRAY
109 PrintF(out, "filler");
111 case JS_OBJECT_TYPE: // fall through
112 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
114 case JS_GENERATOR_OBJECT_TYPE:
116 JSObject::cast(this)->JSObjectPrint(out);
119 Oddball::cast(this)->to_string()->Print(out);
122 JSModule::cast(this)->JSModulePrint(out);
124 case JS_FUNCTION_TYPE:
125 JSFunction::cast(this)->JSFunctionPrint(out);
127 case JS_GLOBAL_PROXY_TYPE:
128 JSGlobalProxy::cast(this)->JSGlobalProxyPrint(out);
130 case JS_GLOBAL_OBJECT_TYPE:
131 JSGlobalObject::cast(this)->JSGlobalObjectPrint(out);
133 case JS_BUILTINS_OBJECT_TYPE:
134 JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(out);
137 PrintF(out, "Value wrapper around:");
138 JSValue::cast(this)->value()->Print(out);
141 JSDate::cast(this)->JSDatePrint(out);
144 Code::cast(this)->CodePrint(out);
147 JSProxy::cast(this)->JSProxyPrint(out);
149 case JS_FUNCTION_PROXY_TYPE:
150 JSFunctionProxy::cast(this)->JSFunctionProxyPrint(out);
153 JSSet::cast(this)->JSSetPrint(out);
156 JSMap::cast(this)->JSMapPrint(out);
158 case JS_SET_ITERATOR_TYPE:
159 JSSetIterator::cast(this)->JSSetIteratorPrint(out);
161 case JS_MAP_ITERATOR_TYPE:
162 JSMapIterator::cast(this)->JSMapIteratorPrint(out);
164 case JS_WEAK_MAP_TYPE:
165 JSWeakMap::cast(this)->JSWeakMapPrint(out);
167 case JS_WEAK_SET_TYPE:
168 JSWeakSet::cast(this)->JSWeakSetPrint(out);
171 Foreign::cast(this)->ForeignPrint(out);
173 case SHARED_FUNCTION_INFO_TYPE:
174 SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(out);
176 case JS_MESSAGE_OBJECT_TYPE:
177 JSMessageObject::cast(this)->JSMessageObjectPrint(out);
180 Cell::cast(this)->CellPrint(out);
182 case PROPERTY_CELL_TYPE:
183 PropertyCell::cast(this)->PropertyCellPrint(out);
185 case JS_ARRAY_BUFFER_TYPE:
186 JSArrayBuffer::cast(this)->JSArrayBufferPrint(out);
188 case JS_TYPED_ARRAY_TYPE:
189 JSTypedArray::cast(this)->JSTypedArrayPrint(out);
191 case JS_DATA_VIEW_TYPE:
192 JSDataView::cast(this)->JSDataViewPrint(out);
194 #define MAKE_STRUCT_CASE(NAME, Name, name) \
196 Name::cast(this)->Name##Print(out); \
198 STRUCT_LIST(MAKE_STRUCT_CASE)
199 #undef MAKE_STRUCT_CASE
202 PrintF(out, "UNKNOWN TYPE %d", map()->instance_type());
209 void ByteArray::ByteArrayPrint(FILE* out) {
210 PrintF(out, "byte array, data starts at %p", GetDataStartAddress());
214 void FreeSpace::FreeSpacePrint(FILE* out) {
215 PrintF(out, "free space, size %d", Size());
219 #define EXTERNAL_ARRAY_PRINTER(Type, type, TYPE, ctype, size) \
220 void External##Type##Array::External##Type##ArrayPrint(FILE* out) { \
221 PrintF(out, "external " #type " array"); \
224 TYPED_ARRAYS(EXTERNAL_ARRAY_PRINTER)
226 #undef EXTERNAL_ARRAY_PRINTER
229 template <class Traits>
230 void FixedTypedArray<Traits>::FixedTypedArrayPrint(FILE* out) {
231 PrintF(out, "fixed %s", Traits::Designator());
235 void JSObject::PrintProperties(FILE* out) {
236 if (HasFastProperties()) {
237 DescriptorArray* descs = map()->instance_descriptors();
238 for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
240 descs->GetKey(i)->NamePrint(out);
242 switch (descs->GetType(i)) {
244 FieldIndex index = FieldIndex::ForDescriptor(map(), i);
245 RawFastPropertyAt(index)->ShortPrint(out);
246 PrintF(out, " (field at offset %d)\n", index.property_index());
250 descs->GetConstant(i)->ShortPrint(out);
251 PrintF(out, " (constant)\n");
254 descs->GetCallbacksObject(i)->ShortPrint(out);
255 PrintF(out, " (callback)\n");
257 case NORMAL: // only in slow mode
258 case HANDLER: // only in lookup results, not in descriptors
259 case INTERCEPTOR: // only in lookup results, not in descriptors
260 // There are no transitions in the descriptor array.
267 property_dictionary()->Print(out);
273 static void DoPrintElements(FILE *out, Object* object) {
274 T* p = T::cast(object);
275 for (int i = 0; i < p->length(); i++) {
276 PrintF(out, " %d: %d\n", i, p->get_scalar(i));
282 static void DoPrintDoubleElements(FILE* out, Object* object) {
283 T* p = T::cast(object);
284 for (int i = 0; i < p->length(); i++) {
285 PrintF(out, " %d: %f\n", i, p->get_scalar(i));
291 static void DoPrintFloat32x4Elements(FILE* out, Object* object) {
292 T* p = T::cast(object);
293 for (int i = 0; i < p->length(); i++) {
294 float32x4_value_t value = p->get_scalar(i);
295 PrintF(out, " %d: (%f, %f, %f, %f)\n",
296 i, value.storage[0], value.storage[1],
297 value.storage[2], value.storage[3]);
303 static void DoPrintFloat64x2Elements(FILE* out, Object* object) {
304 T* p = T::cast(object);
305 for (int i = 0; i < p->length(); i++) {
306 float64x2_value_t value = p->get_scalar(i);
307 PrintF(out, " %d: (%f, %f)\n", i, value.storage[0], value.storage[1]);
313 static void DoPrintInt32x4Elements(FILE* out, Object* object) {
314 T* p = T::cast(object);
315 for (int i = 0; i < p->length(); i++) {
316 int32x4_value_t value = p->get_scalar(i);
317 PrintF(out, " %d: (%d, %d, %d, %d)\n",
318 i, value.storage[0], value.storage[1],
319 value.storage[2], value.storage[3]);
324 void JSObject::PrintElements(FILE* out) {
325 // Don't call GetElementsKind, its validation code can cause the printer to
326 // fail when debugging.
327 switch (map()->elements_kind()) {
328 case FAST_HOLEY_SMI_ELEMENTS:
329 case FAST_SMI_ELEMENTS:
330 case FAST_HOLEY_ELEMENTS:
331 case FAST_ELEMENTS: {
332 // Print in array notation for non-sparse arrays.
333 FixedArray* p = FixedArray::cast(elements());
334 for (int i = 0; i < p->length(); i++) {
335 PrintF(out, " %d: ", i);
336 p->get(i)->ShortPrint(out);
341 case FAST_HOLEY_DOUBLE_ELEMENTS:
342 case FAST_DOUBLE_ELEMENTS: {
343 // Print in array notation for non-sparse arrays.
344 if (elements()->length() > 0) {
345 FixedDoubleArray* p = FixedDoubleArray::cast(elements());
346 for (int i = 0; i < p->length(); i++) {
347 if (p->is_the_hole(i)) {
348 PrintF(out, " %d: <the hole>", i);
350 PrintF(out, " %d: %g", i, p->get_scalar(i));
359 #define PRINT_ELEMENTS(Kind, Type) \
361 DoPrintElements<Type>(out, elements()); \
365 #define PRINT_DOUBLE_ELEMENTS(Kind, Type) \
367 DoPrintDoubleElements<Type>(out, elements()); \
371 #define PRINT_FLOAT32x4_ELEMENTS(Kind, Type) \
373 DoPrintFloat32x4Elements<Type>(out, elements()); \
377 #define PRINT_FLOAT64x2_ELEMENTS(Kind, Type) \
379 DoPrintFloat64x2Elements<Type>(out, elements()); \
383 #define PRINT_INT32x4_ELEMENTS(Kind, Type) \
385 DoPrintInt32x4Elements<Type>(out, elements()); \
389 PRINT_ELEMENTS(EXTERNAL_UINT8_CLAMPED_ELEMENTS, ExternalUint8ClampedArray)
390 PRINT_ELEMENTS(EXTERNAL_INT8_ELEMENTS, ExternalInt8Array)
391 PRINT_ELEMENTS(EXTERNAL_UINT8_ELEMENTS,
393 PRINT_ELEMENTS(EXTERNAL_INT16_ELEMENTS, ExternalInt16Array)
394 PRINT_ELEMENTS(EXTERNAL_UINT16_ELEMENTS,
396 PRINT_ELEMENTS(EXTERNAL_INT32_ELEMENTS, ExternalInt32Array)
397 PRINT_ELEMENTS(EXTERNAL_UINT32_ELEMENTS,
399 PRINT_DOUBLE_ELEMENTS(EXTERNAL_FLOAT32_ELEMENTS, ExternalFloat32Array)
400 PRINT_DOUBLE_ELEMENTS(EXTERNAL_FLOAT64_ELEMENTS, ExternalFloat64Array)
401 PRINT_FLOAT32x4_ELEMENTS(EXTERNAL_FLOAT32x4_ELEMENTS,
402 ExternalFloat32x4Array)
403 PRINT_FLOAT64x2_ELEMENTS(EXTERNAL_FLOAT64x2_ELEMENTS,
404 ExternalFloat64x2Array)
405 PRINT_INT32x4_ELEMENTS(EXTERNAL_INT32x4_ELEMENTS, ExternalInt32x4Array)
408 PRINT_ELEMENTS(UINT8_ELEMENTS, FixedUint8Array)
409 PRINT_ELEMENTS(UINT8_CLAMPED_ELEMENTS, FixedUint8ClampedArray)
410 PRINT_ELEMENTS(INT8_ELEMENTS, FixedInt8Array)
411 PRINT_ELEMENTS(UINT16_ELEMENTS, FixedUint16Array)
412 PRINT_ELEMENTS(INT16_ELEMENTS, FixedInt16Array)
413 PRINT_ELEMENTS(UINT32_ELEMENTS, FixedUint32Array)
414 PRINT_ELEMENTS(INT32_ELEMENTS, FixedInt32Array)
415 PRINT_DOUBLE_ELEMENTS(FLOAT32_ELEMENTS, FixedFloat32Array)
416 PRINT_DOUBLE_ELEMENTS(FLOAT64_ELEMENTS, FixedFloat64Array)
417 PRINT_FLOAT32x4_ELEMENTS(FLOAT32x4_ELEMENTS, FixedFloat32x4Array)
418 PRINT_FLOAT64x2_ELEMENTS(FLOAT64x2_ELEMENTS, FixedFloat64x2Array)
419 PRINT_INT32x4_ELEMENTS(INT32x4_ELEMENTS, FixedInt32x4Array)
421 #undef PRINT_DOUBLE_ELEMENTS
422 #undef PRINT_ELEMENTS
424 case DICTIONARY_ELEMENTS:
425 elements()->Print(out);
427 case SLOPPY_ARGUMENTS_ELEMENTS: {
428 FixedArray* p = FixedArray::cast(elements());
429 PrintF(out, " parameter map:");
430 for (int i = 2; i < p->length(); i++) {
431 PrintF(out, " %d:", i - 2);
432 p->get(i)->ShortPrint(out);
434 PrintF(out, "\n context: ");
435 p->get(0)->ShortPrint(out);
436 PrintF(out, "\n arguments: ");
437 p->get(1)->ShortPrint(out);
445 void JSObject::PrintTransitions(FILE* out) {
446 if (!map()->HasTransitionArray()) return;
447 TransitionArray* transitions = map()->transitions();
448 for (int i = 0; i < transitions->number_of_transitions(); i++) {
449 Name* key = transitions->GetKey(i);
453 if (key == GetHeap()->frozen_symbol()) {
454 PrintF(out, " (transition to frozen)\n");
455 } else if (key == GetHeap()->elements_transition_symbol()) {
456 PrintF(out, " (transition to ");
457 PrintElementsKind(out, transitions->GetTarget(i)->elements_kind());
459 } else if (key == GetHeap()->observed_symbol()) {
460 PrintF(out, " (transition to Object.observe)\n");
462 switch (transitions->GetTargetDetails(i).type()) {
464 PrintF(out, " (transition to field)\n");
468 PrintF(out, " (transition to constant)\n");
471 PrintF(out, " (transition to callback)\n");
473 // Values below are never in the target descriptor array.
486 void JSObject::JSObjectPrint(FILE* out) {
487 PrintF(out, "%p: [JSObject]\n", reinterpret_cast<void*>(this));
488 PrintF(out, " - map = %p [", reinterpret_cast<void*>(map()));
489 // Don't call GetElementsKind, its validation code can cause the printer to
490 // fail when debugging.
491 PrintElementsKind(out, this->map()->elements_kind());
493 "]\n - prototype = %p\n",
494 reinterpret_cast<void*>(GetPrototype()));
496 PrintProperties(out);
497 PrintTransitions(out);
503 void JSModule::JSModulePrint(FILE* out) {
504 HeapObject::PrintHeader(out, "JSModule");
505 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
506 PrintF(out, " - context = ");
507 context()->Print(out);
508 PrintF(out, " - scope_info = ");
509 scope_info()->ShortPrint(out);
510 PrintElementsKind(out, this->map()->elements_kind());
512 PrintProperties(out);
518 static const char* TypeToString(InstanceType type) {
520 #define TYPE_TO_STRING(TYPE) case TYPE: return #TYPE;
521 INSTANCE_TYPE_LIST(TYPE_TO_STRING)
522 #undef TYPE_TO_STRING
525 return "UNKNOWN"; // Keep the compiler happy.
529 void Symbol::SymbolPrint(FILE* out) {
530 HeapObject::PrintHeader(out, "Symbol");
531 PrintF(out, " - hash: %d\n", Hash());
532 PrintF(out, " - name: ");
533 name()->ShortPrint();
534 PrintF(out, " - private: %d\n", is_private());
539 void Map::MapPrint(FILE* out) {
540 HeapObject::PrintHeader(out, "Map");
541 PrintF(out, " - type: %s\n", TypeToString(instance_type()));
542 PrintF(out, " - instance size: %d\n", instance_size());
543 PrintF(out, " - inobject properties: %d\n", inobject_properties());
544 PrintF(out, " - elements kind: ");
545 PrintElementsKind(out, elements_kind());
546 PrintF(out, "\n - pre-allocated property fields: %d\n",
547 pre_allocated_property_fields());
548 PrintF(out, " - unused property fields: %d\n", unused_property_fields());
549 if (is_hidden_prototype()) {
550 PrintF(out, " - hidden_prototype\n");
552 if (has_named_interceptor()) {
553 PrintF(out, " - named_interceptor\n");
555 if (has_indexed_interceptor()) {
556 PrintF(out, " - indexed_interceptor\n");
558 if (is_undetectable()) {
559 PrintF(out, " - undetectable\n");
561 if (has_instance_call_handler()) {
562 PrintF(out, " - instance_call_handler\n");
564 if (is_access_check_needed()) {
565 PrintF(out, " - access_check_needed\n");
568 PrintF(out, " - frozen\n");
569 } else if (!is_extensible()) {
570 PrintF(out, " - sealed\n");
572 PrintF(out, " - back pointer: ");
573 GetBackPointer()->ShortPrint(out);
574 PrintF(out, "\n - instance descriptors %s#%i: ",
575 owns_descriptors() ? "(own) " : "",
576 NumberOfOwnDescriptors());
577 instance_descriptors()->ShortPrint(out);
578 if (HasTransitionArray()) {
579 PrintF(out, "\n - transitions: ");
580 transitions()->ShortPrint(out);
582 PrintF(out, "\n - prototype: ");
583 prototype()->ShortPrint(out);
584 PrintF(out, "\n - constructor: ");
585 constructor()->ShortPrint(out);
586 PrintF(out, "\n - code cache: ");
587 code_cache()->ShortPrint(out);
588 PrintF(out, "\n - dependent code: ");
589 dependent_code()->ShortPrint(out);
594 void CodeCache::CodeCachePrint(FILE* out) {
595 HeapObject::PrintHeader(out, "CodeCache");
596 PrintF(out, "\n - default_cache: ");
597 default_cache()->ShortPrint(out);
598 PrintF(out, "\n - normal_type_cache: ");
599 normal_type_cache()->ShortPrint(out);
603 void PolymorphicCodeCache::PolymorphicCodeCachePrint(FILE* out) {
604 HeapObject::PrintHeader(out, "PolymorphicCodeCache");
605 PrintF(out, "\n - cache: ");
606 cache()->ShortPrint(out);
610 void TypeFeedbackInfo::TypeFeedbackInfoPrint(FILE* out) {
611 HeapObject::PrintHeader(out, "TypeFeedbackInfo");
612 PrintF(out, " - ic_total_count: %d, ic_with_type_info_count: %d\n",
613 ic_total_count(), ic_with_type_info_count());
617 void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(FILE* out) {
618 HeapObject::PrintHeader(out, "AliasedArgumentsEntry");
619 PrintF(out, "\n - aliased_context_slot: %d", aliased_context_slot());
623 void FixedArray::FixedArrayPrint(FILE* out) {
624 HeapObject::PrintHeader(out, "FixedArray");
625 PrintF(out, " - length: %d", length());
626 for (int i = 0; i < length(); i++) {
627 PrintF(out, "\n [%d]: ", i);
628 get(i)->ShortPrint(out);
634 void FixedDoubleArray::FixedDoubleArrayPrint(FILE* out) {
635 HeapObject::PrintHeader(out, "FixedDoubleArray");
636 PrintF(out, " - length: %d", length());
637 for (int i = 0; i < length(); i++) {
638 if (is_the_hole(i)) {
639 PrintF(out, "\n [%d]: <the hole>", i);
641 PrintF(out, "\n [%d]: %g", i, get_scalar(i));
648 void ConstantPoolArray::ConstantPoolArrayPrint(FILE* out) {
649 HeapObject::PrintHeader(out, "ConstantPoolArray");
650 PrintF(out, " - length: %d", length());
651 for (int i = 0; i <= last_index(INT32, SMALL_SECTION); i++) {
652 if (i < last_index(INT64, SMALL_SECTION)) {
653 PrintF(out, "\n [%d]: double: %g", i, get_int64_entry_as_double(i));
654 } else if (i <= last_index(CODE_PTR, SMALL_SECTION)) {
655 PrintF(out, "\n [%d]: code target pointer: %p", i,
656 reinterpret_cast<void*>(get_code_ptr_entry(i)));
657 } else if (i <= last_index(HEAP_PTR, SMALL_SECTION)) {
658 PrintF(out, "\n [%d]: heap pointer: %p", i,
659 reinterpret_cast<void*>(get_heap_ptr_entry(i)));
660 } else if (i <= last_index(INT32, SMALL_SECTION)) {
661 PrintF(out, "\n [%d]: int32: %d", i, get_int32_entry(i));
664 if (is_extended_layout()) {
665 PrintF(out, "\n Extended section:");
666 for (int i = first_extended_section_index();
667 i <= last_index(INT32, EXTENDED_SECTION); i++) {
668 if (i < last_index(INT64, EXTENDED_SECTION)) {
669 PrintF(out, "\n [%d]: double: %g", i, get_int64_entry_as_double(i));
670 } else if (i <= last_index(CODE_PTR, EXTENDED_SECTION)) {
671 PrintF(out, "\n [%d]: code target pointer: %p", i,
672 reinterpret_cast<void*>(get_code_ptr_entry(i)));
673 } else if (i <= last_index(HEAP_PTR, EXTENDED_SECTION)) {
674 PrintF(out, "\n [%d]: heap pointer: %p", i,
675 reinterpret_cast<void*>(get_heap_ptr_entry(i)));
676 } else if (i <= last_index(INT32, EXTENDED_SECTION)) {
677 PrintF(out, "\n [%d]: int32: %d", i, get_int32_entry(i));
685 void JSValue::JSValuePrint(FILE* out) {
686 HeapObject::PrintHeader(out, "ValueObject");
691 void JSMessageObject::JSMessageObjectPrint(FILE* out) {
692 HeapObject::PrintHeader(out, "JSMessageObject");
693 PrintF(out, " - type: ");
694 type()->ShortPrint(out);
695 PrintF(out, "\n - arguments: ");
696 arguments()->ShortPrint(out);
697 PrintF(out, "\n - start_position: %d", start_position());
698 PrintF(out, "\n - end_position: %d", end_position());
699 PrintF(out, "\n - script: ");
700 script()->ShortPrint(out);
701 PrintF(out, "\n - stack_frames: ");
702 stack_frames()->ShortPrint(out);
707 void String::StringPrint(FILE* out) {
708 if (StringShape(this).IsInternalized()) {
710 } else if (StringShape(this).IsCons()) {
716 const char truncated_epilogue[] = "...<truncated>";
718 if (!FLAG_use_verbose_printer) {
720 len = 100 - sizeof(truncated_epilogue);
723 for (int i = 0; i < len; i++) {
724 PrintF(out, "%c", Get(i));
726 if (len != length()) {
727 PrintF(out, "%s", truncated_epilogue);
730 if (!StringShape(this).IsInternalized()) PrintF(out, "\"");
734 void Name::NamePrint(FILE* out) {
736 String::cast(this)->StringPrint(out);
742 // This method is only meant to be called from gdb for debugging purposes.
743 // Since the string can also be in two-byte encoding, non-ASCII characters
744 // will be ignored in the output.
745 char* String::ToAsciiArray() {
746 // Static so that subsequent calls frees previously allocated space.
747 // This also means that previous results will be overwritten.
748 static char* buffer = NULL;
749 if (buffer != NULL) free(buffer);
750 buffer = new char[length()+1];
751 WriteToFlat(this, reinterpret_cast<uint8_t*>(buffer), 0, length());
752 buffer[length()] = 0;
757 static const char* const weekdays[] = {
758 "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
762 void JSDate::JSDatePrint(FILE* out) {
763 HeapObject::PrintHeader(out, "JSDate");
764 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
765 PrintF(out, " - value = ");
767 if (!year()->IsSmi()) {
768 PrintF(out, " - time = NaN\n");
770 PrintF(out, " - time = %s %04d/%02d/%02d %02d:%02d:%02d\n",
771 weekdays[weekday()->IsSmi() ? Smi::cast(weekday())->value() + 1 : 0],
772 year()->IsSmi() ? Smi::cast(year())->value() : -1,
773 month()->IsSmi() ? Smi::cast(month())->value() : -1,
774 day()->IsSmi() ? Smi::cast(day())->value() : -1,
775 hour()->IsSmi() ? Smi::cast(hour())->value() : -1,
776 min()->IsSmi() ? Smi::cast(min())->value() : -1,
777 sec()->IsSmi() ? Smi::cast(sec())->value() : -1);
782 void JSProxy::JSProxyPrint(FILE* out) {
783 HeapObject::PrintHeader(out, "JSProxy");
784 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
785 PrintF(out, " - handler = ");
786 handler()->Print(out);
787 PrintF(out, "\n - hash = ");
793 void JSFunctionProxy::JSFunctionProxyPrint(FILE* out) {
794 HeapObject::PrintHeader(out, "JSFunctionProxy");
795 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
796 PrintF(out, " - handler = ");
797 handler()->Print(out);
798 PrintF(out, "\n - call_trap = ");
799 call_trap()->Print(out);
800 PrintF(out, "\n - construct_trap = ");
801 construct_trap()->Print(out);
806 void JSSet::JSSetPrint(FILE* out) {
807 HeapObject::PrintHeader(out, "JSSet");
808 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
809 PrintF(out, " - table = ");
810 table()->ShortPrint(out);
815 void JSMap::JSMapPrint(FILE* out) {
816 HeapObject::PrintHeader(out, "JSMap");
817 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
818 PrintF(out, " - table = ");
819 table()->ShortPrint(out);
824 template<class Derived, class TableType>
825 void OrderedHashTableIterator<Derived, TableType>::
826 OrderedHashTableIteratorPrint(FILE* out) {
827 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
828 PrintF(out, " - table = ");
829 table()->ShortPrint(out);
830 PrintF(out, "\n - index = ");
831 index()->ShortPrint(out);
832 PrintF(out, "\n - kind = ");
833 kind()->ShortPrint(out);
839 OrderedHashTableIterator<JSSetIterator,
840 OrderedHashSet>::OrderedHashTableIteratorPrint(FILE* out);
844 OrderedHashTableIterator<JSMapIterator,
845 OrderedHashMap>::OrderedHashTableIteratorPrint(FILE* out);
848 void JSSetIterator::JSSetIteratorPrint(FILE* out) {
849 HeapObject::PrintHeader(out, "JSSetIterator");
850 OrderedHashTableIteratorPrint(out);
854 void JSMapIterator::JSMapIteratorPrint(FILE* out) {
855 HeapObject::PrintHeader(out, "JSMapIterator");
856 OrderedHashTableIteratorPrint(out);
860 void JSWeakMap::JSWeakMapPrint(FILE* out) {
861 HeapObject::PrintHeader(out, "JSWeakMap");
862 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
863 PrintF(out, " - table = ");
864 table()->ShortPrint(out);
869 void JSWeakSet::JSWeakSetPrint(FILE* out) {
870 HeapObject::PrintHeader(out, "JSWeakSet");
871 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
872 PrintF(out, " - table = ");
873 table()->ShortPrint(out);
878 void JSArrayBuffer::JSArrayBufferPrint(FILE* out) {
879 HeapObject::PrintHeader(out, "JSArrayBuffer");
880 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
881 PrintF(out, " - backing_store = %p\n", backing_store());
882 PrintF(out, " - byte_length = ");
883 byte_length()->ShortPrint(out);
888 void JSTypedArray::JSTypedArrayPrint(FILE* out) {
889 HeapObject::PrintHeader(out, "JSTypedArray");
890 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
891 PrintF(out, " - buffer =");
892 buffer()->ShortPrint(out);
893 PrintF(out, "\n - byte_offset = ");
894 byte_offset()->ShortPrint(out);
895 PrintF(out, "\n - byte_length = ");
896 byte_length()->ShortPrint(out);
897 PrintF(out, "\n - length = ");
898 length()->ShortPrint(out);
904 void JSDataView::JSDataViewPrint(FILE* out) {
905 HeapObject::PrintHeader(out, "JSDataView");
906 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
907 PrintF(out, " - buffer =");
908 buffer()->ShortPrint(out);
909 PrintF(out, "\n - byte_offset = ");
910 byte_offset()->ShortPrint(out);
911 PrintF(out, "\n - byte_length = ");
912 byte_length()->ShortPrint(out);
917 void JSFunction::JSFunctionPrint(FILE* out) {
918 HeapObject::PrintHeader(out, "Function");
919 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
920 PrintF(out, " - initial_map = ");
921 if (has_initial_map()) {
922 initial_map()->ShortPrint(out);
924 PrintF(out, "\n - shared_info = ");
925 shared()->ShortPrint(out);
926 PrintF(out, "\n - name = ");
927 shared()->name()->Print(out);
928 PrintF(out, "\n - context = ");
929 context()->ShortPrint(out);
930 if (shared()->bound()) {
931 PrintF(out, "\n - bindings = ");
932 function_bindings()->ShortPrint(out);
934 PrintF(out, "\n - literals = ");
935 literals()->ShortPrint(out);
937 PrintF(out, "\n - code = ");
938 code()->ShortPrint(out);
941 PrintProperties(out);
948 void SharedFunctionInfo::SharedFunctionInfoPrint(FILE* out) {
949 HeapObject::PrintHeader(out, "SharedFunctionInfo");
950 PrintF(out, " - name: ");
951 name()->ShortPrint(out);
952 PrintF(out, "\n - expected_nof_properties: %d", expected_nof_properties());
953 PrintF(out, "\n - ast_node_count: %d", ast_node_count());
954 PrintF(out, "\n - instance class name = ");
955 instance_class_name()->Print(out);
956 PrintF(out, "\n - code = ");
957 code()->ShortPrint(out);
958 if (HasSourceCode()) {
959 PrintF(out, "\n - source code = ");
960 String* source = String::cast(Script::cast(script())->source());
961 int start = start_position();
962 int length = end_position() - start;
963 SmartArrayPointer<char> source_string =
964 source->ToCString(DISALLOW_NULLS,
965 FAST_STRING_TRAVERSAL,
966 start, length, NULL);
967 PrintF(out, "%s", source_string.get());
969 // Script files are often large, hard to read.
970 // PrintF(out, "\n - script =");
971 // script()->Print(out);
972 PrintF(out, "\n - function token position = %d", function_token_position());
973 PrintF(out, "\n - start position = %d", start_position());
974 PrintF(out, "\n - end position = %d", end_position());
975 PrintF(out, "\n - is expression = %d", is_expression());
976 PrintF(out, "\n - debug info = ");
977 debug_info()->ShortPrint(out);
978 PrintF(out, "\n - length = %d", length());
979 PrintF(out, "\n - optimized_code_map = ");
980 optimized_code_map()->ShortPrint(out);
981 PrintF(out, "\n - feedback_vector = ");
982 feedback_vector()->FixedArrayPrint(out);
987 void JSGlobalProxy::JSGlobalProxyPrint(FILE* out) {
988 PrintF(out, "global_proxy ");
990 PrintF(out, "native context : ");
991 native_context()->ShortPrint(out);
996 void JSGlobalObject::JSGlobalObjectPrint(FILE* out) {
997 PrintF(out, "global ");
999 PrintF(out, "native context : ");
1000 native_context()->ShortPrint(out);
1005 void JSBuiltinsObject::JSBuiltinsObjectPrint(FILE* out) {
1006 PrintF(out, "builtins ");
1011 void Cell::CellPrint(FILE* out) {
1012 HeapObject::PrintHeader(out, "Cell");
1016 void PropertyCell::PropertyCellPrint(FILE* out) {
1017 HeapObject::PrintHeader(out, "PropertyCell");
1021 void Code::CodePrint(FILE* out) {
1022 HeapObject::PrintHeader(out, "Code");
1023 #ifdef ENABLE_DISASSEMBLER
1024 if (FLAG_use_verbose_printer) {
1025 Disassemble(NULL, out);
1031 void Foreign::ForeignPrint(FILE* out) {
1032 PrintF(out, "foreign address : %p", foreign_address());
1036 void ExecutableAccessorInfo::ExecutableAccessorInfoPrint(FILE* out) {
1037 HeapObject::PrintHeader(out, "ExecutableAccessorInfo");
1038 PrintF(out, "\n - name: ");
1039 name()->ShortPrint(out);
1040 PrintF(out, "\n - flag: ");
1041 flag()->ShortPrint(out);
1042 PrintF(out, "\n - getter: ");
1043 getter()->ShortPrint(out);
1044 PrintF(out, "\n - setter: ");
1045 setter()->ShortPrint(out);
1046 PrintF(out, "\n - data: ");
1047 data()->ShortPrint(out);
1051 void DeclaredAccessorInfo::DeclaredAccessorInfoPrint(FILE* out) {
1052 HeapObject::PrintHeader(out, "DeclaredAccessorInfo");
1053 PrintF(out, "\n - name: ");
1054 name()->ShortPrint(out);
1055 PrintF(out, "\n - flag: ");
1056 flag()->ShortPrint(out);
1057 PrintF(out, "\n - descriptor: ");
1058 descriptor()->ShortPrint(out);
1062 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorPrint(FILE* out) {
1063 HeapObject::PrintHeader(out, "DeclaredAccessorDescriptor");
1064 PrintF(out, "\n - internal field: ");
1065 serialized_data()->ShortPrint(out);
1069 void Box::BoxPrint(FILE* out) {
1070 HeapObject::PrintHeader(out, "Box");
1071 PrintF(out, "\n - value: ");
1072 value()->ShortPrint(out);
1076 void AccessorPair::AccessorPairPrint(FILE* out) {
1077 HeapObject::PrintHeader(out, "AccessorPair");
1078 PrintF(out, "\n - getter: ");
1079 getter()->ShortPrint(out);
1080 PrintF(out, "\n - setter: ");
1081 setter()->ShortPrint(out);
1082 PrintF(out, "\n - flag: ");
1083 access_flags()->ShortPrint(out);
1087 void AccessCheckInfo::AccessCheckInfoPrint(FILE* out) {
1088 HeapObject::PrintHeader(out, "AccessCheckInfo");
1089 PrintF(out, "\n - named_callback: ");
1090 named_callback()->ShortPrint(out);
1091 PrintF(out, "\n - indexed_callback: ");
1092 indexed_callback()->ShortPrint(out);
1093 PrintF(out, "\n - data: ");
1094 data()->ShortPrint(out);
1098 void InterceptorInfo::InterceptorInfoPrint(FILE* out) {
1099 HeapObject::PrintHeader(out, "InterceptorInfo");
1100 PrintF(out, "\n - getter: ");
1101 getter()->ShortPrint(out);
1102 PrintF(out, "\n - setter: ");
1103 setter()->ShortPrint(out);
1104 PrintF(out, "\n - query: ");
1105 query()->ShortPrint(out);
1106 PrintF(out, "\n - deleter: ");
1107 deleter()->ShortPrint(out);
1108 PrintF(out, "\n - enumerator: ");
1109 enumerator()->ShortPrint(out);
1110 PrintF(out, "\n - data: ");
1111 data()->ShortPrint(out);
1115 void CallHandlerInfo::CallHandlerInfoPrint(FILE* out) {
1116 HeapObject::PrintHeader(out, "CallHandlerInfo");
1117 PrintF(out, "\n - callback: ");
1118 callback()->ShortPrint(out);
1119 PrintF(out, "\n - data: ");
1120 data()->ShortPrint(out);
1121 PrintF(out, "\n - call_stub_cache: ");
1125 void FunctionTemplateInfo::FunctionTemplateInfoPrint(FILE* out) {
1126 HeapObject::PrintHeader(out, "FunctionTemplateInfo");
1127 PrintF(out, "\n - class name: ");
1128 class_name()->ShortPrint(out);
1129 PrintF(out, "\n - tag: ");
1130 tag()->ShortPrint(out);
1131 PrintF(out, "\n - property_list: ");
1132 property_list()->ShortPrint(out);
1133 PrintF(out, "\n - serial_number: ");
1134 serial_number()->ShortPrint(out);
1135 PrintF(out, "\n - call_code: ");
1136 call_code()->ShortPrint(out);
1137 PrintF(out, "\n - property_accessors: ");
1138 property_accessors()->ShortPrint(out);
1139 PrintF(out, "\n - prototype_template: ");
1140 prototype_template()->ShortPrint(out);
1141 PrintF(out, "\n - parent_template: ");
1142 parent_template()->ShortPrint(out);
1143 PrintF(out, "\n - named_property_handler: ");
1144 named_property_handler()->ShortPrint(out);
1145 PrintF(out, "\n - indexed_property_handler: ");
1146 indexed_property_handler()->ShortPrint(out);
1147 PrintF(out, "\n - instance_template: ");
1148 instance_template()->ShortPrint(out);
1149 PrintF(out, "\n - signature: ");
1150 signature()->ShortPrint(out);
1151 PrintF(out, "\n - access_check_info: ");
1152 access_check_info()->ShortPrint(out);
1153 PrintF(out, "\n - hidden_prototype: %s",
1154 hidden_prototype() ? "true" : "false");
1155 PrintF(out, "\n - undetectable: %s", undetectable() ? "true" : "false");
1156 PrintF(out, "\n - need_access_check: %s",
1157 needs_access_check() ? "true" : "false");
1161 void ObjectTemplateInfo::ObjectTemplateInfoPrint(FILE* out) {
1162 HeapObject::PrintHeader(out, "ObjectTemplateInfo");
1163 PrintF(out, " - tag: ");
1164 tag()->ShortPrint(out);
1165 PrintF(out, "\n - property_list: ");
1166 property_list()->ShortPrint(out);
1167 PrintF(out, "\n - property_accessors: ");
1168 property_accessors()->ShortPrint(out);
1169 PrintF(out, "\n - constructor: ");
1170 constructor()->ShortPrint(out);
1171 PrintF(out, "\n - internal_field_count: ");
1172 internal_field_count()->ShortPrint(out);
1177 void SignatureInfo::SignatureInfoPrint(FILE* out) {
1178 HeapObject::PrintHeader(out, "SignatureInfo");
1179 PrintF(out, "\n - receiver: ");
1180 receiver()->ShortPrint(out);
1181 PrintF(out, "\n - args: ");
1182 args()->ShortPrint(out);
1186 void TypeSwitchInfo::TypeSwitchInfoPrint(FILE* out) {
1187 HeapObject::PrintHeader(out, "TypeSwitchInfo");
1188 PrintF(out, "\n - types: ");
1189 types()->ShortPrint(out);
1193 void AllocationSite::AllocationSitePrint(FILE* out) {
1194 HeapObject::PrintHeader(out, "AllocationSite");
1195 PrintF(out, " - weak_next: ");
1196 weak_next()->ShortPrint(out);
1197 PrintF(out, "\n - dependent code: ");
1198 dependent_code()->ShortPrint(out);
1199 PrintF(out, "\n - nested site: ");
1200 nested_site()->ShortPrint(out);
1201 PrintF(out, "\n - memento found count: ");
1202 Smi::FromInt(memento_found_count())->ShortPrint(out);
1203 PrintF(out, "\n - memento create count: ");
1204 Smi::FromInt(memento_create_count())->ShortPrint(out);
1205 PrintF(out, "\n - pretenure decision: ");
1206 Smi::FromInt(pretenure_decision())->ShortPrint(out);
1207 PrintF(out, "\n - transition_info: ");
1208 if (transition_info()->IsSmi()) {
1209 ElementsKind kind = GetElementsKind();
1210 PrintF(out, "Array allocation with ElementsKind ");
1211 PrintElementsKind(out, kind);
1214 } else if (transition_info()->IsJSArray()) {
1215 PrintF(out, "Array literal ");
1216 transition_info()->ShortPrint(out);
1221 PrintF(out, "unknown transition_info");
1222 transition_info()->ShortPrint(out);
1227 void AllocationMemento::AllocationMementoPrint(FILE* out) {
1228 HeapObject::PrintHeader(out, "AllocationMemento");
1229 PrintF(out, " - allocation site: ");
1231 GetAllocationSite()->Print();
1233 PrintF(out, "<invalid>\n");
1238 void Script::ScriptPrint(FILE* out) {
1239 HeapObject::PrintHeader(out, "Script");
1240 PrintF(out, "\n - source: ");
1241 source()->ShortPrint(out);
1242 PrintF(out, "\n - name: ");
1243 name()->ShortPrint(out);
1244 PrintF(out, "\n - line_offset: ");
1245 line_offset()->ShortPrint(out);
1246 PrintF(out, "\n - column_offset: ");
1247 column_offset()->ShortPrint(out);
1248 PrintF(out, "\n - type: ");
1249 type()->ShortPrint(out);
1250 PrintF(out, "\n - id: ");
1251 id()->ShortPrint(out);
1252 PrintF(out, "\n - context data: ");
1253 context_data()->ShortPrint(out);
1254 PrintF(out, "\n - wrapper: ");
1255 wrapper()->ShortPrint(out);
1256 PrintF(out, "\n - compilation type: %d", compilation_type());
1257 PrintF(out, "\n - line ends: ");
1258 line_ends()->ShortPrint(out);
1259 PrintF(out, "\n - eval from shared: ");
1260 eval_from_shared()->ShortPrint(out);
1261 PrintF(out, "\n - eval from instructions offset: ");
1262 eval_from_instructions_offset()->ShortPrint(out);
1267 void DebugInfo::DebugInfoPrint(FILE* out) {
1268 HeapObject::PrintHeader(out, "DebugInfo");
1269 PrintF(out, "\n - shared: ");
1270 shared()->ShortPrint(out);
1271 PrintF(out, "\n - original_code: ");
1272 original_code()->ShortPrint(out);
1273 PrintF(out, "\n - code: ");
1274 code()->ShortPrint(out);
1275 PrintF(out, "\n - break_points: ");
1276 break_points()->Print(out);
1280 void BreakPointInfo::BreakPointInfoPrint(FILE* out) {
1281 HeapObject::PrintHeader(out, "BreakPointInfo");
1282 PrintF(out, "\n - code_position: %d", code_position()->value());
1283 PrintF(out, "\n - source_position: %d", source_position()->value());
1284 PrintF(out, "\n - statement_position: %d", statement_position()->value());
1285 PrintF(out, "\n - break_point_objects: ");
1286 break_point_objects()->ShortPrint(out);
1290 void DescriptorArray::PrintDescriptors(FILE* out) {
1291 PrintF(out, "Descriptor array %d\n", number_of_descriptors());
1292 for (int i = 0; i < number_of_descriptors(); i++) {
1293 PrintF(out, " %d: ", i);
1302 void TransitionArray::PrintTransitions(FILE* out) {
1303 PrintF(out, "Transition array %d\n", number_of_transitions());
1304 for (int i = 0; i < number_of_transitions(); i++) {
1305 PrintF(out, " %d: ", i);
1306 GetKey(i)->NamePrint(out);
1308 switch (GetTargetDetails(i).type()) {
1310 PrintF(out, " (transition to field)\n");
1314 PrintF(out, " (transition to constant)\n");
1317 PrintF(out, " (transition to callback)\n");
1319 // Values below are never in the target descriptor array.
1332 #endif // OBJECT_PRINT
1335 } } // namespace v8::internal