Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / v8 / src / objects-printer.cc
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.
4
5 #include "src/v8.h"
6
7 #include "src/disasm.h"
8 #include "src/disassembler.h"
9 #include "src/heap/objects-visiting.h"
10 #include "src/jsregexp.h"
11 #include "src/ostreams.h"
12
13 namespace v8 {
14 namespace internal {
15
16 #ifdef OBJECT_PRINT
17
18 void Object::Print() {
19   OFStream os(stdout);
20   this->Print(os);
21   os << std::flush;
22 }
23
24
25 void Object::Print(std::ostream& os) {  // NOLINT
26   if (IsSmi()) {
27     Smi::cast(this)->SmiPrint(os);
28   } else {
29     HeapObject::cast(this)->HeapObjectPrint(os);
30   }
31 }
32
33
34 void HeapObject::PrintHeader(std::ostream& os, const char* id) {  // NOLINT
35   os << "" << reinterpret_cast<void*>(this) << ": [" << id << "]\n";
36 }
37
38
39 void HeapObject::HeapObjectPrint(std::ostream& os) {  // NOLINT
40   InstanceType instance_type = map()->instance_type();
41
42   HandleScope scope(GetIsolate());
43   if (instance_type < FIRST_NONSTRING_TYPE) {
44     String::cast(this)->StringPrint(os);
45     return;
46   }
47
48   switch (instance_type) {
49     case SYMBOL_TYPE:
50       Symbol::cast(this)->SymbolPrint(os);
51       break;
52     case MAP_TYPE:
53       Map::cast(this)->MapPrint(os);
54       break;
55     case HEAP_NUMBER_TYPE:
56       HeapNumber::cast(this)->HeapNumberPrint(os);
57       break;
58     case MUTABLE_HEAP_NUMBER_TYPE:
59       os << "<mutable ";
60       HeapNumber::cast(this)->HeapNumberPrint(os);
61       os << ">";
62       break;
63     case FLOAT32x4_TYPE:
64       Float32x4::cast(this)->Float32x4Print(os);
65       break;
66     case FLOAT64x2_TYPE:
67       Float64x2::cast(this)->Float64x2Print(os);
68       break;
69     case INT32x4_TYPE:
70       Int32x4::cast(this)->Int32x4Print(os);
71       break;
72     case FIXED_DOUBLE_ARRAY_TYPE:
73       FixedDoubleArray::cast(this)->FixedDoubleArrayPrint(os);
74       break;
75     case CONSTANT_POOL_ARRAY_TYPE:
76       ConstantPoolArray::cast(this)->ConstantPoolArrayPrint(os);
77       break;
78     case FIXED_ARRAY_TYPE:
79       FixedArray::cast(this)->FixedArrayPrint(os);
80       break;
81     case BYTE_ARRAY_TYPE:
82       ByteArray::cast(this)->ByteArrayPrint(os);
83       break;
84     case FREE_SPACE_TYPE:
85       FreeSpace::cast(this)->FreeSpacePrint(os);
86       break;
87
88 #define PRINT_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size)            \
89   case EXTERNAL_##TYPE##_ARRAY_TYPE:                                   \
90     External##Type##Array::cast(this)->External##Type##ArrayPrint(os); \
91     break;
92
93      TYPED_ARRAYS(PRINT_EXTERNAL_ARRAY)
94 #undef PRINT_EXTERNAL_ARRAY
95
96 #define PRINT_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
97   case Fixed##Type##Array::kInstanceType:                      \
98     Fixed##Type##Array::cast(this)->FixedTypedArrayPrint(os);  \
99     break;
100
101     TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY)
102 #undef PRINT_FIXED_TYPED_ARRAY
103
104     case FILLER_TYPE:
105       os << "filler";
106       break;
107     case JS_OBJECT_TYPE:  // fall through
108     case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
109     case JS_ARRAY_TYPE:
110     case JS_GENERATOR_OBJECT_TYPE:
111     case JS_REGEXP_TYPE:
112       JSObject::cast(this)->JSObjectPrint(os);
113       break;
114     case ODDBALL_TYPE:
115       Oddball::cast(this)->to_string()->Print(os);
116       break;
117     case JS_MODULE_TYPE:
118       JSModule::cast(this)->JSModulePrint(os);
119       break;
120     case JS_FUNCTION_TYPE:
121       JSFunction::cast(this)->JSFunctionPrint(os);
122       break;
123     case JS_GLOBAL_PROXY_TYPE:
124       JSGlobalProxy::cast(this)->JSGlobalProxyPrint(os);
125       break;
126     case JS_GLOBAL_OBJECT_TYPE:
127       JSGlobalObject::cast(this)->JSGlobalObjectPrint(os);
128       break;
129     case JS_BUILTINS_OBJECT_TYPE:
130       JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(os);
131       break;
132     case JS_VALUE_TYPE:
133       os << "Value wrapper around:";
134       JSValue::cast(this)->value()->Print(os);
135       break;
136     case JS_DATE_TYPE:
137       JSDate::cast(this)->JSDatePrint(os);
138       break;
139     case CODE_TYPE:
140       Code::cast(this)->CodePrint(os);
141       break;
142     case JS_PROXY_TYPE:
143       JSProxy::cast(this)->JSProxyPrint(os);
144       break;
145     case JS_FUNCTION_PROXY_TYPE:
146       JSFunctionProxy::cast(this)->JSFunctionProxyPrint(os);
147       break;
148     case JS_SET_TYPE:
149       JSSet::cast(this)->JSSetPrint(os);
150       break;
151     case JS_MAP_TYPE:
152       JSMap::cast(this)->JSMapPrint(os);
153       break;
154     case JS_SET_ITERATOR_TYPE:
155       JSSetIterator::cast(this)->JSSetIteratorPrint(os);
156       break;
157     case JS_MAP_ITERATOR_TYPE:
158       JSMapIterator::cast(this)->JSMapIteratorPrint(os);
159       break;
160     case JS_WEAK_MAP_TYPE:
161       JSWeakMap::cast(this)->JSWeakMapPrint(os);
162       break;
163     case JS_WEAK_SET_TYPE:
164       JSWeakSet::cast(this)->JSWeakSetPrint(os);
165       break;
166     case FOREIGN_TYPE:
167       Foreign::cast(this)->ForeignPrint(os);
168       break;
169     case SHARED_FUNCTION_INFO_TYPE:
170       SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(os);
171       break;
172     case JS_MESSAGE_OBJECT_TYPE:
173       JSMessageObject::cast(this)->JSMessageObjectPrint(os);
174       break;
175     case CELL_TYPE:
176       Cell::cast(this)->CellPrint(os);
177       break;
178     case PROPERTY_CELL_TYPE:
179       PropertyCell::cast(this)->PropertyCellPrint(os);
180       break;
181     case WEAK_CELL_TYPE:
182       WeakCell::cast(this)->WeakCellPrint(os);
183       break;
184     case JS_ARRAY_BUFFER_TYPE:
185       JSArrayBuffer::cast(this)->JSArrayBufferPrint(os);
186       break;
187     case JS_TYPED_ARRAY_TYPE:
188       JSTypedArray::cast(this)->JSTypedArrayPrint(os);
189       break;
190     case JS_DATA_VIEW_TYPE:
191       JSDataView::cast(this)->JSDataViewPrint(os);
192       break;
193 #define MAKE_STRUCT_CASE(NAME, Name, name) \
194   case NAME##_TYPE:                        \
195     Name::cast(this)->Name##Print(os);     \
196     break;
197   STRUCT_LIST(MAKE_STRUCT_CASE)
198 #undef MAKE_STRUCT_CASE
199
200     default:
201       os << "UNKNOWN TYPE " << map()->instance_type();
202       UNREACHABLE();
203       break;
204   }
205 }
206
207
208 void ByteArray::ByteArrayPrint(std::ostream& os) {  // NOLINT
209   os << "byte array, data starts at " << GetDataStartAddress();
210 }
211
212
213 void FreeSpace::FreeSpacePrint(std::ostream& os) {  // NOLINT
214   os << "free space, size " << Size();
215 }
216
217
218 #define EXTERNAL_ARRAY_PRINTER(Type, type, TYPE, ctype, size)                \
219   void External##Type##Array::External##Type##ArrayPrint(std::ostream& os) { \
220     os << "external " #type " array";                                        \
221   }
222
223 TYPED_ARRAYS(EXTERNAL_ARRAY_PRINTER)
224
225 #undef EXTERNAL_ARRAY_PRINTER
226
227
228 template <class Traits>
229 void FixedTypedArray<Traits>::FixedTypedArrayPrint(
230     std::ostream& os) {  // NOLINT
231   os << "fixed " << Traits::Designator();
232 }
233
234
235 void JSObject::PrintProperties(std::ostream& os) {  // NOLINT
236   if (HasFastProperties()) {
237     DescriptorArray* descs = map()->instance_descriptors();
238     for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
239       os << "   ";
240       descs->GetKey(i)->NamePrint(os);
241       os << ": ";
242       switch (descs->GetType(i)) {
243         case FIELD: {
244           FieldIndex index = FieldIndex::ForDescriptor(map(), i);
245           os << Brief(RawFastPropertyAt(index)) << " (field at offset "
246              << index.property_index() << ")\n";
247           break;
248         }
249         case CONSTANT:
250           os << Brief(descs->GetConstant(i)) << " (constant)\n";
251           break;
252         case CALLBACKS:
253           os << Brief(descs->GetCallbacksObject(i)) << " (callback)\n";
254           break;
255         case NORMAL:  // only in slow mode
256           UNREACHABLE();
257           break;
258       }
259     }
260   } else {
261     property_dictionary()->Print(os);
262   }
263 }
264
265
266 template <class T>
267 static void DoPrintElements(std::ostream& os, Object* object) {  // NOLINT
268   T* p = T::cast(object);
269   for (int i = 0; i < p->length(); i++) {
270     os << "   " << i << ": " << p->get_scalar(i) << "\n";
271   }
272 }
273
274
275 template<class T>
276 static void DoPrintFloat32x4Elements(std::ostream& os, Object* object) {
277   T* p = T::cast(object);
278   for (int i = 0; i < p->length(); i++) {
279     float32x4_value_t value =  p->get_scalar(i);
280     os << "   " << i << ": (" << value.storage[0] << value.storage[1] <<
281         value.storage[2] << value.storage[3] << ")\n";
282   }
283 }
284
285
286 template<class T>
287 static void DoPrintFloat64x2Elements(std::ostream& os, Object* object) {
288   T* p = T::cast(object);
289   for (int i = 0; i < p->length(); i++) {
290     float64x2_value_t value =  p->get_scalar(i);
291     os << "   " << i << ": (" << value.storage[0] << value.storage[1] << ")\n";
292   }
293 }
294
295
296 template<class T>
297 static void DoPrintInt32x4Elements(std::ostream& os, Object* object) {
298   T* p = T::cast(object);
299   for (int i = 0; i < p->length(); i++) {
300     int32x4_value_t value =  p->get_scalar(i);
301     os << "   " << i << ": (" << value.storage[0] << value.storage[1] <<
302         value.storage[2] << value.storage[3] << ")\n";
303   }
304 }
305
306
307 void JSObject::PrintElements(std::ostream& os) {  // NOLINT
308   // Don't call GetElementsKind, its validation code can cause the printer to
309   // fail when debugging.
310   switch (map()->elements_kind()) {
311     case FAST_HOLEY_SMI_ELEMENTS:
312     case FAST_SMI_ELEMENTS:
313     case FAST_HOLEY_ELEMENTS:
314     case FAST_ELEMENTS: {
315       // Print in array notation for non-sparse arrays.
316       FixedArray* p = FixedArray::cast(elements());
317       for (int i = 0; i < p->length(); i++) {
318         os << "   " << i << ": " << Brief(p->get(i)) << "\n";
319       }
320       break;
321     }
322     case FAST_HOLEY_DOUBLE_ELEMENTS:
323     case FAST_DOUBLE_ELEMENTS: {
324       // Print in array notation for non-sparse arrays.
325       if (elements()->length() > 0) {
326         FixedDoubleArray* p = FixedDoubleArray::cast(elements());
327         for (int i = 0; i < p->length(); i++) {
328           os << "   " << i << ": ";
329           if (p->is_the_hole(i)) {
330             os << "<the hole>";
331           } else {
332             os << p->get_scalar(i);
333           }
334           os << "\n";
335         }
336       }
337       break;
338     }
339
340
341 #define PRINT_ELEMENTS(Kind, Type)         \
342   case Kind: {                             \
343     DoPrintElements<Type>(os, elements()); \
344     break;                                 \
345   }
346
347 #define PRINT_FLOAT32x4_ELEMENTS(Kind, Type)                                \
348     case Kind: {                                                            \
349       DoPrintFloat32x4Elements<Type>(os, elements());                       \
350       break;                                                                \
351     }
352
353 #define PRINT_FLOAT64x2_ELEMENTS(Kind, Type)                                \
354     case Kind: {                                                            \
355       DoPrintFloat64x2Elements<Type>(os, elements());                       \
356       break;                                                                \
357     }
358
359 #define PRINT_INT32x4_ELEMENTS(Kind, Type)                                  \
360     case Kind: {                                                            \
361       DoPrintInt32x4Elements<Type>(os, elements());                         \
362       break;                                                                \
363     }
364
365     PRINT_ELEMENTS(EXTERNAL_UINT8_CLAMPED_ELEMENTS, ExternalUint8ClampedArray)
366     PRINT_ELEMENTS(EXTERNAL_INT8_ELEMENTS, ExternalInt8Array)
367     PRINT_ELEMENTS(EXTERNAL_UINT8_ELEMENTS,
368         ExternalUint8Array)
369     PRINT_ELEMENTS(EXTERNAL_INT16_ELEMENTS, ExternalInt16Array)
370     PRINT_ELEMENTS(EXTERNAL_UINT16_ELEMENTS,
371         ExternalUint16Array)
372     PRINT_ELEMENTS(EXTERNAL_INT32_ELEMENTS, ExternalInt32Array)
373     PRINT_ELEMENTS(EXTERNAL_UINT32_ELEMENTS,
374         ExternalUint32Array)
375     PRINT_ELEMENTS(EXTERNAL_FLOAT32_ELEMENTS, ExternalFloat32Array)
376     PRINT_ELEMENTS(EXTERNAL_FLOAT64_ELEMENTS, ExternalFloat64Array)
377     PRINT_FLOAT32x4_ELEMENTS(EXTERNAL_FLOAT32x4_ELEMENTS,
378         ExternalFloat32x4Array)
379     PRINT_FLOAT64x2_ELEMENTS(EXTERNAL_FLOAT64x2_ELEMENTS,
380         ExternalFloat64x2Array)
381     PRINT_INT32x4_ELEMENTS(EXTERNAL_INT32x4_ELEMENTS, ExternalInt32x4Array)
382
383     PRINT_ELEMENTS(UINT8_ELEMENTS, FixedUint8Array)
384     PRINT_ELEMENTS(UINT8_CLAMPED_ELEMENTS, FixedUint8ClampedArray)
385     PRINT_ELEMENTS(INT8_ELEMENTS, FixedInt8Array)
386     PRINT_ELEMENTS(UINT16_ELEMENTS, FixedUint16Array)
387     PRINT_ELEMENTS(INT16_ELEMENTS, FixedInt16Array)
388     PRINT_ELEMENTS(UINT32_ELEMENTS, FixedUint32Array)
389     PRINT_ELEMENTS(INT32_ELEMENTS, FixedInt32Array)
390     PRINT_ELEMENTS(FLOAT32_ELEMENTS, FixedFloat32Array)
391     PRINT_ELEMENTS(FLOAT64_ELEMENTS, FixedFloat64Array)
392     PRINT_FLOAT32x4_ELEMENTS(FLOAT32x4_ELEMENTS, FixedFloat32x4Array)
393     PRINT_FLOAT64x2_ELEMENTS(FLOAT64x2_ELEMENTS, FixedFloat64x2Array)
394     PRINT_INT32x4_ELEMENTS(INT32x4_ELEMENTS, FixedInt32x4Array)
395
396 #undef PRINT_ELEMENTS
397
398     case DICTIONARY_ELEMENTS:
399       elements()->Print(os);
400       break;
401     case SLOPPY_ARGUMENTS_ELEMENTS: {
402       FixedArray* p = FixedArray::cast(elements());
403       os << "   parameter map:";
404       for (int i = 2; i < p->length(); i++) {
405         os << " " << (i - 2) << ":" << Brief(p->get(i));
406       }
407       os << "\n   context: " << Brief(p->get(0))
408          << "\n   arguments: " << Brief(p->get(1)) << "\n";
409       break;
410     }
411   }
412 }
413
414
415 void JSObject::PrintTransitions(std::ostream& os) {  // NOLINT
416   if (!map()->HasTransitionArray()) return;
417   map()->transitions()->PrintTransitions(os, false);
418 }
419
420
421 void JSObject::JSObjectPrint(std::ostream& os) {  // NOLINT
422   HeapObject::PrintHeader(os, "JSObject");
423   // Don't call GetElementsKind, its validation code can cause the printer to
424   // fail when debugging.
425   PrototypeIterator iter(GetIsolate(), this);
426   os << " - map = " << reinterpret_cast<void*>(map()) << " ["
427      << ElementsKindToString(this->map()->elements_kind())
428      << "]\n - prototype = " << reinterpret_cast<void*>(iter.GetCurrent())
429      << "\n {\n";
430   PrintProperties(os);
431   PrintTransitions(os);
432   PrintElements(os);
433   os << " }\n";
434 }
435
436
437 void JSModule::JSModulePrint(std::ostream& os) {  // NOLINT
438   HeapObject::PrintHeader(os, "JSModule");
439   os << " - map = " << reinterpret_cast<void*>(map()) << "\n"
440      << " - context = ";
441   context()->Print(os);
442   os << " - scope_info = " << Brief(scope_info())
443      << ElementsKindToString(this->map()->elements_kind()) << " {\n";
444   PrintProperties(os);
445   PrintElements(os);
446   os << " }\n";
447 }
448
449
450 static const char* TypeToString(InstanceType type) {
451   switch (type) {
452 #define TYPE_TO_STRING(TYPE) case TYPE: return #TYPE;
453   INSTANCE_TYPE_LIST(TYPE_TO_STRING)
454 #undef TYPE_TO_STRING
455   }
456   UNREACHABLE();
457   return "UNKNOWN";  // Keep the compiler happy.
458 }
459
460
461 void Symbol::SymbolPrint(std::ostream& os) {  // NOLINT
462   HeapObject::PrintHeader(os, "Symbol");
463   os << " - hash: " << Hash();
464   os << "\n - name: " << Brief(name());
465   if (name()->IsUndefined()) {
466     os << " (" << PrivateSymbolToName() << ")";
467   }
468   os << "\n - private: " << is_private();
469   os << "\n - own: " << is_own();
470   os << "\n";
471 }
472
473
474 void Map::MapPrint(std::ostream& os) {  // NOLINT
475   HeapObject::PrintHeader(os, "Map");
476   os << " - type: " << TypeToString(instance_type()) << "\n";
477   os << " - instance size: " << instance_size() << "\n";
478   os << " - inobject properties: " << inobject_properties() << "\n";
479   os << " - elements kind: " << ElementsKindToString(elements_kind());
480   os << "\n - pre-allocated property fields: "
481      << pre_allocated_property_fields() << "\n";
482   os << " - unused property fields: " << unused_property_fields() << "\n";
483   if (is_dictionary_map()) os << " - dictionary_map\n";
484   if (is_prototype_map()) os << " - prototype_map\n";
485   if (is_hidden_prototype()) os << " - hidden_prototype\n";
486   if (has_named_interceptor()) os << " - named_interceptor\n";
487   if (has_indexed_interceptor()) os << " - indexed_interceptor\n";
488   if (is_undetectable()) os << " - undetectable\n";
489   if (has_instance_call_handler()) os << " - instance_call_handler\n";
490   if (is_access_check_needed()) os << " - access_check_needed\n";
491   if (is_frozen()) {
492     os << " - frozen\n";
493   } else if (!is_extensible()) {
494     os << " - sealed\n";
495   }
496   os << " - back pointer: " << Brief(GetBackPointer());
497   os << "\n - instance descriptors " << (owns_descriptors() ? "(own) " : "")
498      << "#" << NumberOfOwnDescriptors() << ": "
499      << Brief(instance_descriptors());
500   if (HasTransitionArray()) {
501     os << "\n - transitions: " << Brief(transitions());
502   }
503   os << "\n - prototype: " << Brief(prototype());
504   os << "\n - constructor: " << Brief(constructor());
505   os << "\n - code cache: " << Brief(code_cache());
506   os << "\n - dependent code: " << Brief(dependent_code());
507   os << "\n";
508 }
509
510
511 void CodeCache::CodeCachePrint(std::ostream& os) {  // NOLINT
512   HeapObject::PrintHeader(os, "CodeCache");
513   os << "\n - default_cache: " << Brief(default_cache());
514   os << "\n - normal_type_cache: " << Brief(normal_type_cache());
515 }
516
517
518 void PolymorphicCodeCache::PolymorphicCodeCachePrint(
519     std::ostream& os) {  // NOLINT
520   HeapObject::PrintHeader(os, "PolymorphicCodeCache");
521   os << "\n - cache: " << Brief(cache());
522 }
523
524
525 void TypeFeedbackInfo::TypeFeedbackInfoPrint(std::ostream& os) {  // NOLINT
526   HeapObject::PrintHeader(os, "TypeFeedbackInfo");
527   os << " - ic_total_count: " << ic_total_count()
528      << ", ic_with_type_info_count: " << ic_with_type_info_count()
529      << ", ic_generic_count: " << ic_generic_count() << "\n";
530 }
531
532
533 void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(
534     std::ostream& os) {  // NOLINT
535   HeapObject::PrintHeader(os, "AliasedArgumentsEntry");
536   os << "\n - aliased_context_slot: " << aliased_context_slot();
537 }
538
539
540 void FixedArray::FixedArrayPrint(std::ostream& os) {  // NOLINT
541   HeapObject::PrintHeader(os, "FixedArray");
542   os << " - length: " << length();
543   for (int i = 0; i < length(); i++) {
544     os << "\n  [" << i << "]: " << Brief(get(i));
545   }
546   os << "\n";
547 }
548
549
550 void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) {  // NOLINT
551   HeapObject::PrintHeader(os, "FixedDoubleArray");
552   os << " - length: " << length();
553   for (int i = 0; i < length(); i++) {
554     os << "\n  [" << i << "]: ";
555     if (is_the_hole(i)) {
556       os << "<the hole>";
557     } else {
558       os << get_scalar(i);
559     }
560   }
561   os << "\n";
562 }
563
564
565 void ConstantPoolArray::ConstantPoolArrayPrint(std::ostream& os) {  // NOLINT
566   HeapObject::PrintHeader(os, "ConstantPoolArray");
567   os << " - length: " << length();
568   for (int i = 0; i <= last_index(INT32, SMALL_SECTION); i++) {
569     if (i < last_index(INT64, SMALL_SECTION)) {
570       os << "\n  [" << i << "]: double: " << get_int64_entry_as_double(i);
571     } else if (i <= last_index(CODE_PTR, SMALL_SECTION)) {
572       os << "\n  [" << i << "]: code target pointer: "
573          << reinterpret_cast<void*>(get_code_ptr_entry(i));
574     } else if (i <= last_index(HEAP_PTR, SMALL_SECTION)) {
575       os << "\n  [" << i << "]: heap pointer: "
576          << reinterpret_cast<void*>(get_heap_ptr_entry(i));
577     } else if (i <= last_index(INT32, SMALL_SECTION)) {
578       os << "\n  [" << i << "]: int32: " << get_int32_entry(i);
579     }
580   }
581   if (is_extended_layout()) {
582     os << "\n  Extended section:";
583     for (int i = first_extended_section_index();
584          i <= last_index(INT32, EXTENDED_SECTION); i++) {
585       if (i < last_index(INT64, EXTENDED_SECTION)) {
586         os << "\n  [" << i << "]: double: " << get_int64_entry_as_double(i);
587       } else if (i <= last_index(CODE_PTR, EXTENDED_SECTION)) {
588         os << "\n  [" << i << "]: code target pointer: "
589            << reinterpret_cast<void*>(get_code_ptr_entry(i));
590       } else if (i <= last_index(HEAP_PTR, EXTENDED_SECTION)) {
591         os << "\n  [" << i << "]: heap pointer: "
592            << reinterpret_cast<void*>(get_heap_ptr_entry(i));
593       } else if (i <= last_index(INT32, EXTENDED_SECTION)) {
594         os << "\n  [" << i << "]: int32: " << get_int32_entry(i);
595       }
596     }
597   }
598   os << "\n";
599 }
600
601
602 void JSValue::JSValuePrint(std::ostream& os) {  // NOLINT
603   HeapObject::PrintHeader(os, "ValueObject");
604   value()->Print(os);
605 }
606
607
608 void JSMessageObject::JSMessageObjectPrint(std::ostream& os) {  // NOLINT
609   HeapObject::PrintHeader(os, "JSMessageObject");
610   os << " - type: " << Brief(type());
611   os << "\n - arguments: " << Brief(arguments());
612   os << "\n - start_position: " << start_position();
613   os << "\n - end_position: " << end_position();
614   os << "\n - script: " << Brief(script());
615   os << "\n - stack_frames: " << Brief(stack_frames());
616   os << "\n";
617 }
618
619
620 void String::StringPrint(std::ostream& os) {  // NOLINT
621   if (StringShape(this).IsInternalized()) {
622     os << "#";
623   } else if (StringShape(this).IsCons()) {
624     os << "c\"";
625   } else {
626     os << "\"";
627   }
628
629   const char truncated_epilogue[] = "...<truncated>";
630   int len = length();
631   if (!FLAG_use_verbose_printer) {
632     if (len > 100) {
633       len = 100 - sizeof(truncated_epilogue);
634     }
635   }
636   for (int i = 0; i < len; i++) {
637     os << AsUC16(Get(i));
638   }
639   if (len != length()) {
640     os << truncated_epilogue;
641   }
642
643   if (!StringShape(this).IsInternalized()) os << "\"";
644 }
645
646
647 void Name::NamePrint(std::ostream& os) {  // NOLINT
648   if (IsString()) {
649     String::cast(this)->StringPrint(os);
650   } else if (IsSymbol()) {
651     Symbol::cast(this)->name()->Print(os);
652   } else {
653     os << Brief(this);
654   }
655 }
656
657
658 // This method is only meant to be called from gdb for debugging purposes.
659 // Since the string can also be in two-byte encoding, non-Latin1 characters
660 // will be ignored in the output.
661 char* String::ToAsciiArray() {
662   // Static so that subsequent calls frees previously allocated space.
663   // This also means that previous results will be overwritten.
664   static char* buffer = NULL;
665   if (buffer != NULL) delete[] buffer;
666   buffer = new char[length()+1];
667   WriteToFlat(this, reinterpret_cast<uint8_t*>(buffer), 0, length());
668   buffer[length()] = 0;
669   return buffer;
670 }
671
672
673 static const char* const weekdays[] = {
674   "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
675 };
676
677
678 void JSDate::JSDatePrint(std::ostream& os) {  // NOLINT
679   HeapObject::PrintHeader(os, "JSDate");
680   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
681   os << " - value = ";
682   value()->Print(os);
683   if (!year()->IsSmi()) {
684     os << " - time = NaN\n";
685   } else {
686     // TODO(svenpanne) Add some basic formatting to our streams.
687     Vector<char> buf = Vector<char>::New(100);
688     SNPrintF(
689         buf, " - time = %s %04d/%02d/%02d %02d:%02d:%02d\n",
690         weekdays[weekday()->IsSmi() ? Smi::cast(weekday())->value() + 1 : 0],
691         year()->IsSmi() ? Smi::cast(year())->value() : -1,
692         month()->IsSmi() ? Smi::cast(month())->value() : -1,
693         day()->IsSmi() ? Smi::cast(day())->value() : -1,
694         hour()->IsSmi() ? Smi::cast(hour())->value() : -1,
695         min()->IsSmi() ? Smi::cast(min())->value() : -1,
696         sec()->IsSmi() ? Smi::cast(sec())->value() : -1);
697     os << buf.start();
698   }
699 }
700
701
702 void JSProxy::JSProxyPrint(std::ostream& os) {  // NOLINT
703   HeapObject::PrintHeader(os, "JSProxy");
704   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
705   os << " - handler = ";
706   handler()->Print(os);
707   os << "\n - hash = ";
708   hash()->Print(os);
709   os << "\n";
710 }
711
712
713 void JSFunctionProxy::JSFunctionProxyPrint(std::ostream& os) {  // NOLINT
714   HeapObject::PrintHeader(os, "JSFunctionProxy");
715   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
716   os << " - handler = ";
717   handler()->Print(os);
718   os << "\n - call_trap = ";
719   call_trap()->Print(os);
720   os << "\n - construct_trap = ";
721   construct_trap()->Print(os);
722   os << "\n";
723 }
724
725
726 void JSSet::JSSetPrint(std::ostream& os) {  // NOLINT
727   HeapObject::PrintHeader(os, "JSSet");
728   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
729   os << " - table = " << Brief(table());
730   os << "\n";
731 }
732
733
734 void JSMap::JSMapPrint(std::ostream& os) {  // NOLINT
735   HeapObject::PrintHeader(os, "JSMap");
736   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
737   os << " - table = " << Brief(table());
738   os << "\n";
739 }
740
741
742 template <class Derived, class TableType>
743 void
744 OrderedHashTableIterator<Derived, TableType>::OrderedHashTableIteratorPrint(
745     std::ostream& os) {  // NOLINT
746   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
747   os << " - table = " << Brief(table());
748   os << "\n - index = " << Brief(index());
749   os << "\n - kind = " << Brief(kind());
750   os << "\n";
751 }
752
753
754 template void OrderedHashTableIterator<
755     JSSetIterator,
756     OrderedHashSet>::OrderedHashTableIteratorPrint(std::ostream& os);  // NOLINT
757
758
759 template void OrderedHashTableIterator<
760     JSMapIterator,
761     OrderedHashMap>::OrderedHashTableIteratorPrint(std::ostream& os);  // NOLINT
762
763
764 void JSSetIterator::JSSetIteratorPrint(std::ostream& os) {  // NOLINT
765   HeapObject::PrintHeader(os, "JSSetIterator");
766   OrderedHashTableIteratorPrint(os);
767 }
768
769
770 void JSMapIterator::JSMapIteratorPrint(std::ostream& os) {  // NOLINT
771   HeapObject::PrintHeader(os, "JSMapIterator");
772   OrderedHashTableIteratorPrint(os);
773 }
774
775
776 void JSWeakMap::JSWeakMapPrint(std::ostream& os) {  // NOLINT
777   HeapObject::PrintHeader(os, "JSWeakMap");
778   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
779   os << " - table = " << Brief(table());
780   os << "\n";
781 }
782
783
784 void JSWeakSet::JSWeakSetPrint(std::ostream& os) {  // NOLINT
785   HeapObject::PrintHeader(os, "JSWeakSet");
786   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
787   os << " - table = " << Brief(table());
788   os << "\n";
789 }
790
791
792 void JSArrayBuffer::JSArrayBufferPrint(std::ostream& os) {  // NOLINT
793   HeapObject::PrintHeader(os, "JSArrayBuffer");
794   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
795   os << " - backing_store = " << backing_store() << "\n";
796   os << " - byte_length = " << Brief(byte_length());
797   os << "\n";
798 }
799
800
801 void JSTypedArray::JSTypedArrayPrint(std::ostream& os) {  // NOLINT
802   HeapObject::PrintHeader(os, "JSTypedArray");
803   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
804   os << " - buffer = " << Brief(buffer());
805   os << "\n - byte_offset = " << Brief(byte_offset());
806   os << "\n - byte_length = " << Brief(byte_length());
807   os << "\n - length = " << Brief(length());
808   os << "\n";
809   PrintElements(os);
810 }
811
812
813 void JSDataView::JSDataViewPrint(std::ostream& os) {  // NOLINT
814   HeapObject::PrintHeader(os, "JSDataView");
815   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
816   os << " - buffer =" << Brief(buffer());
817   os << "\n - byte_offset = " << Brief(byte_offset());
818   os << "\n - byte_length = " << Brief(byte_length());
819   os << "\n";
820 }
821
822
823 void JSFunction::JSFunctionPrint(std::ostream& os) {  // NOLINT
824   HeapObject::PrintHeader(os, "Function");
825   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
826   os << " - initial_map = ";
827   if (has_initial_map()) os << Brief(initial_map());
828   os << "\n - shared_info = " << Brief(shared());
829   os << "\n   - name = " << Brief(shared()->name());
830   os << "\n - context = " << Brief(context());
831   if (shared()->bound()) {
832     os << "\n - bindings = " << Brief(function_bindings());
833   } else {
834     os << "\n - literals = " << Brief(literals());
835   }
836   os << "\n - code = " << Brief(code());
837   os << "\n";
838   PrintProperties(os);
839   PrintElements(os);
840   os << "\n";
841 }
842
843
844 void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) {  // NOLINT
845   HeapObject::PrintHeader(os, "SharedFunctionInfo");
846   os << " - name: " << Brief(name());
847   os << "\n - expected_nof_properties: " << expected_nof_properties();
848   os << "\n - ast_node_count: " << ast_node_count();
849   os << "\n - instance class name = ";
850   instance_class_name()->Print(os);
851   os << "\n - code = " << Brief(code());
852   if (HasSourceCode()) {
853     os << "\n - source code = ";
854     String* source = String::cast(Script::cast(script())->source());
855     int start = start_position();
856     int length = end_position() - start;
857     SmartArrayPointer<char> source_string =
858         source->ToCString(DISALLOW_NULLS,
859                           FAST_STRING_TRAVERSAL,
860                           start, length, NULL);
861     os << source_string.get();
862   }
863   // Script files are often large, hard to read.
864   // os << "\n - script =";
865   // script()->Print(os);
866   os << "\n - function token position = " << function_token_position();
867   os << "\n - start position = " << start_position();
868   os << "\n - end position = " << end_position();
869   os << "\n - is expression = " << is_expression();
870   os << "\n - debug info = " << Brief(debug_info());
871   os << "\n - length = " << length();
872   os << "\n - optimized_code_map = " << Brief(optimized_code_map());
873   os << "\n - feedback_vector = ";
874   feedback_vector()->FixedArrayPrint(os);
875   os << "\n";
876 }
877
878
879 void JSGlobalProxy::JSGlobalProxyPrint(std::ostream& os) {  // NOLINT
880   os << "global_proxy ";
881   JSObjectPrint(os);
882   os << "native context : " << Brief(native_context());
883   os << "\n";
884 }
885
886
887 void JSGlobalObject::JSGlobalObjectPrint(std::ostream& os) {  // NOLINT
888   os << "global ";
889   JSObjectPrint(os);
890   os << "native context : " << Brief(native_context());
891   os << "\n";
892 }
893
894
895 void JSBuiltinsObject::JSBuiltinsObjectPrint(std::ostream& os) {  // NOLINT
896   os << "builtins ";
897   JSObjectPrint(os);
898 }
899
900
901 void Cell::CellPrint(std::ostream& os) {  // NOLINT
902   HeapObject::PrintHeader(os, "Cell");
903 }
904
905
906 void PropertyCell::PropertyCellPrint(std::ostream& os) {  // NOLINT
907   HeapObject::PrintHeader(os, "PropertyCell");
908 }
909
910
911 void WeakCell::WeakCellPrint(std::ostream& os) {  // NOLINT
912   HeapObject::PrintHeader(os, "WeakCell");
913 }
914
915
916 void Code::CodePrint(std::ostream& os) {  // NOLINT
917   HeapObject::PrintHeader(os, "Code");
918 #ifdef ENABLE_DISASSEMBLER
919   if (FLAG_use_verbose_printer) {
920     Disassemble(NULL, os);
921   }
922 #endif
923 }
924
925
926 void Foreign::ForeignPrint(std::ostream& os) {  // NOLINT
927   os << "foreign address : " << foreign_address();
928 }
929
930
931 void ExecutableAccessorInfo::ExecutableAccessorInfoPrint(
932     std::ostream& os) {  // NOLINT
933   HeapObject::PrintHeader(os, "ExecutableAccessorInfo");
934   os << "\n - name: " << Brief(name());
935   os << "\n - flag: " << Brief(flag());
936   os << "\n - getter: " << Brief(getter());
937   os << "\n - setter: " << Brief(setter());
938   os << "\n - data: " << Brief(data());
939   os << "\n";
940 }
941
942
943 void DeclaredAccessorInfo::DeclaredAccessorInfoPrint(
944     std::ostream& os) {  // NOLINT
945   HeapObject::PrintHeader(os, "DeclaredAccessorInfo");
946   os << "\n - name: " << Brief(name());
947   os << "\n - flag: " << Brief(flag());
948   os << "\n - descriptor: " << Brief(descriptor());
949   os << "\n";
950 }
951
952
953 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorPrint(
954     std::ostream& os) {  // NOLINT
955   HeapObject::PrintHeader(os, "DeclaredAccessorDescriptor");
956   os << "\n - internal field: " << Brief(serialized_data());
957   os << "\n";
958 }
959
960
961 void Box::BoxPrint(std::ostream& os) {  // NOLINT
962   HeapObject::PrintHeader(os, "Box");
963   os << "\n - value: " << Brief(value());
964   os << "\n";
965 }
966
967
968 void AccessorPair::AccessorPairPrint(std::ostream& os) {  // NOLINT
969   HeapObject::PrintHeader(os, "AccessorPair");
970   os << "\n - getter: " << Brief(getter());
971   os << "\n - setter: " << Brief(setter());
972   os << "\n";
973 }
974
975
976 void AccessCheckInfo::AccessCheckInfoPrint(std::ostream& os) {  // NOLINT
977   HeapObject::PrintHeader(os, "AccessCheckInfo");
978   os << "\n - named_callback: " << Brief(named_callback());
979   os << "\n - indexed_callback: " << Brief(indexed_callback());
980   os << "\n - data: " << Brief(data());
981   os << "\n";
982 }
983
984
985 void InterceptorInfo::InterceptorInfoPrint(std::ostream& os) {  // NOLINT
986   HeapObject::PrintHeader(os, "InterceptorInfo");
987   os << "\n - getter: " << Brief(getter());
988   os << "\n - setter: " << Brief(setter());
989   os << "\n - query: " << Brief(query());
990   os << "\n - deleter: " << Brief(deleter());
991   os << "\n - enumerator: " << Brief(enumerator());
992   os << "\n - data: " << Brief(data());
993   os << "\n";
994 }
995
996
997 void CallHandlerInfo::CallHandlerInfoPrint(std::ostream& os) {  // NOLINT
998   HeapObject::PrintHeader(os, "CallHandlerInfo");
999   os << "\n - callback: " << Brief(callback());
1000   os << "\n - data: " << Brief(data());
1001   os << "\n";
1002 }
1003
1004
1005 void FunctionTemplateInfo::FunctionTemplateInfoPrint(
1006     std::ostream& os) {  // NOLINT
1007   HeapObject::PrintHeader(os, "FunctionTemplateInfo");
1008   os << "\n - class name: " << Brief(class_name());
1009   os << "\n - tag: " << Brief(tag());
1010   os << "\n - property_list: " << Brief(property_list());
1011   os << "\n - serial_number: " << Brief(serial_number());
1012   os << "\n - call_code: " << Brief(call_code());
1013   os << "\n - property_accessors: " << Brief(property_accessors());
1014   os << "\n - prototype_template: " << Brief(prototype_template());
1015   os << "\n - parent_template: " << Brief(parent_template());
1016   os << "\n - named_property_handler: " << Brief(named_property_handler());
1017   os << "\n - indexed_property_handler: " << Brief(indexed_property_handler());
1018   os << "\n - instance_template: " << Brief(instance_template());
1019   os << "\n - signature: " << Brief(signature());
1020   os << "\n - access_check_info: " << Brief(access_check_info());
1021   os << "\n - hidden_prototype: " << (hidden_prototype() ? "true" : "false");
1022   os << "\n - undetectable: " << (undetectable() ? "true" : "false");
1023   os << "\n - need_access_check: " << (needs_access_check() ? "true" : "false");
1024   os << "\n";
1025 }
1026
1027
1028 void ObjectTemplateInfo::ObjectTemplateInfoPrint(std::ostream& os) {  // NOLINT
1029   HeapObject::PrintHeader(os, "ObjectTemplateInfo");
1030   os << " - tag: " << Brief(tag());
1031   os << "\n - property_list: " << Brief(property_list());
1032   os << "\n - property_accessors: " << Brief(property_accessors());
1033   os << "\n - constructor: " << Brief(constructor());
1034   os << "\n - internal_field_count: " << Brief(internal_field_count());
1035   os << "\n";
1036 }
1037
1038
1039 void SignatureInfo::SignatureInfoPrint(std::ostream& os) {  // NOLINT
1040   HeapObject::PrintHeader(os, "SignatureInfo");
1041   os << "\n - receiver: " << Brief(receiver());
1042   os << "\n - args: " << Brief(args());
1043   os << "\n";
1044 }
1045
1046
1047 void TypeSwitchInfo::TypeSwitchInfoPrint(std::ostream& os) {  // NOLINT
1048   HeapObject::PrintHeader(os, "TypeSwitchInfo");
1049   os << "\n - types: " << Brief(types());
1050   os << "\n";
1051 }
1052
1053
1054 void AllocationSite::AllocationSitePrint(std::ostream& os) {  // NOLINT
1055   HeapObject::PrintHeader(os, "AllocationSite");
1056   os << " - weak_next: " << Brief(weak_next());
1057   os << "\n - dependent code: " << Brief(dependent_code());
1058   os << "\n - nested site: " << Brief(nested_site());
1059   os << "\n - memento found count: "
1060      << Brief(Smi::FromInt(memento_found_count()));
1061   os << "\n - memento create count: "
1062      << Brief(Smi::FromInt(memento_create_count()));
1063   os << "\n - pretenure decision: "
1064      << Brief(Smi::FromInt(pretenure_decision()));
1065   os << "\n - transition_info: ";
1066   if (transition_info()->IsSmi()) {
1067     ElementsKind kind = GetElementsKind();
1068     os << "Array allocation with ElementsKind " << ElementsKindToString(kind);
1069   } else if (transition_info()->IsJSArray()) {
1070     os << "Array literal " << Brief(transition_info());
1071   } else {
1072     os << "unknown transition_info" << Brief(transition_info());
1073   }
1074   os << "\n";
1075 }
1076
1077
1078 void AllocationMemento::AllocationMementoPrint(std::ostream& os) {  // NOLINT
1079   HeapObject::PrintHeader(os, "AllocationMemento");
1080   os << " - allocation site: ";
1081   if (IsValid()) {
1082     GetAllocationSite()->Print(os);
1083   } else {
1084     os << "<invalid>\n";
1085   }
1086 }
1087
1088
1089 void Script::ScriptPrint(std::ostream& os) {  // NOLINT
1090   HeapObject::PrintHeader(os, "Script");
1091   os << "\n - source: " << Brief(source());
1092   os << "\n - name: " << Brief(name());
1093   os << "\n - line_offset: " << Brief(line_offset());
1094   os << "\n - column_offset: " << Brief(column_offset());
1095   os << "\n - type: " << Brief(type());
1096   os << "\n - id: " << Brief(id());
1097   os << "\n - context data: " << Brief(context_data());
1098   os << "\n - wrapper: " << Brief(wrapper());
1099   os << "\n - compilation type: " << compilation_type();
1100   os << "\n - line ends: " << Brief(line_ends());
1101   os << "\n - eval from shared: " << Brief(eval_from_shared());
1102   os << "\n - eval from instructions offset: "
1103      << Brief(eval_from_instructions_offset());
1104   os << "\n";
1105 }
1106
1107
1108 void DebugInfo::DebugInfoPrint(std::ostream& os) {  // NOLINT
1109   HeapObject::PrintHeader(os, "DebugInfo");
1110   os << "\n - shared: " << Brief(shared());
1111   os << "\n - original_code: " << Brief(original_code());
1112   os << "\n - code: " << Brief(code());
1113   os << "\n - break_points: ";
1114   break_points()->Print(os);
1115 }
1116
1117
1118 void BreakPointInfo::BreakPointInfoPrint(std::ostream& os) {  // NOLINT
1119   HeapObject::PrintHeader(os, "BreakPointInfo");
1120   os << "\n - code_position: " << code_position()->value();
1121   os << "\n - source_position: " << source_position()->value();
1122   os << "\n - statement_position: " << statement_position()->value();
1123   os << "\n - break_point_objects: " << Brief(break_point_objects());
1124   os << "\n";
1125 }
1126
1127
1128 void DescriptorArray::Print() {
1129   OFStream os(stdout);
1130   this->PrintDescriptors(os);
1131   os << std::flush;
1132 }
1133
1134
1135 void DescriptorArray::PrintDescriptors(std::ostream& os) {  // NOLINT
1136   os << "Descriptor array " << number_of_descriptors() << "\n";
1137   for (int i = 0; i < number_of_descriptors(); i++) {
1138     Descriptor desc;
1139     Get(i, &desc);
1140     os << " " << i << ": " << desc << "\n";
1141   }
1142   os << "\n";
1143 }
1144
1145
1146 void TransitionArray::Print() {
1147   OFStream os(stdout);
1148   this->PrintTransitions(os);
1149   os << std::flush;
1150 }
1151
1152
1153 void TransitionArray::PrintTransitions(std::ostream& os,
1154                                        bool print_header) {  // NOLINT
1155   if (print_header) {
1156     os << "Transition array " << number_of_transitions() << "\n";
1157   }
1158   for (int i = 0; i < number_of_transitions(); i++) {
1159     Name* key = GetKey(i);
1160     os << "   ";
1161     key->NamePrint(os);
1162     os << ": ";
1163     if (key == GetHeap()->frozen_symbol()) {
1164       os << " (transition to frozen)";
1165     } else if (key == GetHeap()->elements_transition_symbol()) {
1166       os << " (transition to "
1167          << ElementsKindToString(GetTarget(i)->elements_kind()) << ")";
1168     } else if (key == GetHeap()->observed_symbol()) {
1169       os << " (transition to Object.observe)";
1170     } else {
1171       PropertyDetails details = GetTargetDetails(i);
1172       switch (details.type()) {
1173         case FIELD: {
1174           os << " (transition to field)";
1175           break;
1176         }
1177         case CONSTANT:
1178           os << " (transition to constant " << Brief(GetTargetValue(i)) << ")";
1179           break;
1180         case CALLBACKS:
1181           os << " (transition to callback " << Brief(GetTargetValue(i)) << ")";
1182           break;
1183         // Values below are never in the target descriptor array.
1184         case NORMAL:
1185           UNREACHABLE();
1186           break;
1187       }
1188       os << ", attrs: " << details.attributes();
1189     }
1190     os << " -> " << Brief(GetTarget(i)) << "\n";
1191   }
1192 }
1193
1194
1195 #endif  // OBJECT_PRINT
1196
1197
1198 } }  // namespace v8::internal