V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
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/objects.h"
6 
7 #include <iomanip>
8 #include <memory>
9 
10 #include "src/bootstrapper.h"
11 #include "src/disasm.h"
12 #include "src/disassembler.h"
13 #include "src/interpreter/bytecodes.h"
14 #include "src/objects-inl.h"
15 #include "src/objects/arguments-inl.h"
16 #include "src/objects/data-handler-inl.h"
17 #include "src/objects/debug-objects-inl.h"
18 #include "src/objects/embedder-data-array-inl.h"
19 #include "src/objects/embedder-data-slot-inl.h"
20 #include "src/objects/hash-table-inl.h"
21 #include "src/objects/js-array-buffer-inl.h"
22 #include "src/objects/js-array-inl.h"
23 #include "src/snapshot/embedded-data.h"
24 #ifdef V8_INTL_SUPPORT
25 #include "src/objects/js-break-iterator-inl.h"
26 #include "src/objects/js-collator-inl.h"
27 #endif // V8_INTL_SUPPORT
28 #include "src/objects/js-collection-inl.h"
29 #ifdef V8_INTL_SUPPORT
30 #include "src/objects/js-date-time-format-inl.h"
31 #endif // V8_INTL_SUPPORT
32 #include "src/objects/js-generator-inl.h"
33 #ifdef V8_INTL_SUPPORT
34 #include "src/objects/js-list-format-inl.h"
35 #include "src/objects/js-locale-inl.h"
36 #include "src/objects/js-number-format-inl.h"
37 #include "src/objects/js-plural-rules-inl.h"
38 #endif // V8_INTL_SUPPORT
39 #include "src/objects/js-regexp-inl.h"
40 #include "src/objects/js-regexp-string-iterator-inl.h"
41 #ifdef V8_INTL_SUPPORT
42 #include "src/objects/js-relative-time-format-inl.h"
43 #include "src/objects/js-segment-iterator-inl.h"
44 #include "src/objects/js-segmenter-inl.h"
45 #endif // V8_INTL_SUPPORT
46 #include "src/objects/js-weak-refs-inl.h"
47 #include "src/objects/literal-objects-inl.h"
48 #include "src/objects/microtask-inl.h"
49 #include "src/objects/module-inl.h"
50 #include "src/objects/promise-inl.h"
51 #include "src/objects/stack-frame-info-inl.h"
52 #include "src/ostreams.h"
53 #include "src/regexp/jsregexp.h"
54 #include "src/transitions-inl.h"
55 #include "src/wasm/wasm-code-manager.h"
56 #include "src/wasm/wasm-engine.h"
57 #include "src/wasm/wasm-objects-inl.h"
58 
59 namespace v8 {
60 namespace internal {
61 
62 #ifdef OBJECT_PRINT
63 
64 void Object::Print() {
65  StdoutStream os;
66  this->Print(os);
67  os << std::flush;
68 }
69 
70 void Object::Print(std::ostream& os) { // NOLINT
71  if (IsSmi()) {
72  os << "Smi: " << std::hex << "0x" << Smi::ToInt(this);
73  os << std::dec << " (" << Smi::ToInt(this) << ")\n";
74  } else {
75  HeapObject::cast(this)->HeapObjectPrint(os);
76  }
77 }
78 
79 void HeapObject::PrintHeader(std::ostream& os, const char* id) { // NOLINT
80  os << reinterpret_cast<void*>(this) << ": [";
81  if (id != nullptr) {
82  os << id;
83  } else {
84  os << map()->instance_type();
85  }
86  os << "]";
87  MemoryChunk* chunk = MemoryChunk::FromAddress(
88  reinterpret_cast<Address>(const_cast<HeapObject*>(this)));
89  if (chunk->owner()->identity() == OLD_SPACE) os << " in OldSpace";
90  if (!IsMap()) os << "\n - map: " << Brief(map());
91 }
92 
93 void HeapObjectPtr::PrintHeader(std::ostream& os, const char* id) { // NOLINT
94  os << reinterpret_cast<void*>(ptr()) << ": [";
95  if (id != nullptr) {
96  os << id;
97  } else {
98  os << map()->instance_type();
99  }
100  os << "]";
101  MemoryChunk* chunk = MemoryChunk::FromAddress(ptr());
102  if (chunk->owner()->identity() == OLD_SPACE) os << " in OldSpace";
103  if (!IsMap()) os << "\n - map: " << Brief(map());
104 }
105 
106 void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
107  InstanceType instance_type = map()->instance_type();
108 
109  if (instance_type < FIRST_NONSTRING_TYPE) {
110  String::cast(this)->StringPrint(os);
111  os << "\n";
112  return;
113  }
114 
115  switch (instance_type) {
116  case SYMBOL_TYPE:
117  Symbol::cast(this)->SymbolPrint(os);
118  break;
119  case MAP_TYPE:
120  Map::cast(this)->MapPrint(os);
121  break;
122  case HEAP_NUMBER_TYPE:
123  HeapNumber::cast(this)->HeapNumberPrint(os);
124  os << "\n";
125  break;
126  case MUTABLE_HEAP_NUMBER_TYPE:
127  os << "<mutable ";
128  MutableHeapNumber::cast(this)->MutableHeapNumberPrint(os);
129  os << ">\n";
130  break;
131  case BIGINT_TYPE:
132  BigInt::cast(this)->BigIntPrint(os);
133  os << "\n";
134  break;
135  case EMBEDDER_DATA_ARRAY_TYPE:
136  EmbedderDataArray::cast(this)->EmbedderDataArrayPrint(os);
137  break;
138  case FIXED_DOUBLE_ARRAY_TYPE:
139  FixedDoubleArray::cast(this)->FixedDoubleArrayPrint(os);
140  break;
141  case FIXED_ARRAY_TYPE:
142  FixedArray::cast(this)->FixedArrayPrint(os);
143  break;
144  case AWAIT_CONTEXT_TYPE:
145  case BLOCK_CONTEXT_TYPE:
146  case CATCH_CONTEXT_TYPE:
147  case DEBUG_EVALUATE_CONTEXT_TYPE:
148  case EVAL_CONTEXT_TYPE:
149  case FUNCTION_CONTEXT_TYPE:
150  case MODULE_CONTEXT_TYPE:
151  case SCRIPT_CONTEXT_TYPE:
152  case WITH_CONTEXT_TYPE:
153  case SCRIPT_CONTEXT_TABLE_TYPE:
154  Context::cast(this)->ContextPrint(os);
155  break;
156  case NATIVE_CONTEXT_TYPE:
157  NativeContext::cast(this)->NativeContextPrint(os);
158  break;
159  case HASH_TABLE_TYPE:
160  case ORDERED_HASH_MAP_TYPE:
161  case ORDERED_HASH_SET_TYPE:
162  case ORDERED_NAME_DICTIONARY_TYPE:
163  case NAME_DICTIONARY_TYPE:
164  case GLOBAL_DICTIONARY_TYPE:
165  case SIMPLE_NUMBER_DICTIONARY_TYPE:
166  case STRING_TABLE_TYPE:
167  ObjectHashTable::cast(this)->ObjectHashTablePrint(os);
168  break;
169  case NUMBER_DICTIONARY_TYPE:
170  NumberDictionary::cast(this)->NumberDictionaryPrint(os);
171  break;
172  case EPHEMERON_HASH_TABLE_TYPE:
173  EphemeronHashTable::cast(this)->EphemeronHashTablePrint(os);
174  break;
175  case OBJECT_BOILERPLATE_DESCRIPTION_TYPE:
176  ObjectBoilerplateDescription::cast(this)
177  ->ObjectBoilerplateDescriptionPrint(os);
178  break;
179  case PROPERTY_ARRAY_TYPE:
180  PropertyArray::cast(this)->PropertyArrayPrint(os);
181  break;
182  case BYTE_ARRAY_TYPE:
183  ByteArray::cast(this)->ByteArrayPrint(os);
184  break;
185  case BYTECODE_ARRAY_TYPE:
186  BytecodeArray::cast(this)->BytecodeArrayPrint(os);
187  break;
188  case DESCRIPTOR_ARRAY_TYPE:
189  DescriptorArray::cast(this)->DescriptorArrayPrint(os);
190  break;
191  case TRANSITION_ARRAY_TYPE:
192  TransitionArray::cast(this)->TransitionArrayPrint(os);
193  break;
194  case FEEDBACK_CELL_TYPE:
195  FeedbackCell::cast(this)->FeedbackCellPrint(os);
196  break;
197  case FEEDBACK_VECTOR_TYPE:
198  FeedbackVector::cast(this)->FeedbackVectorPrint(os);
199  break;
200  case FREE_SPACE_TYPE:
201  FreeSpace::cast(this)->FreeSpacePrint(os);
202  break;
203 
204 #define PRINT_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype) \
205  case Fixed##Type##Array::kInstanceType: \
206  Fixed##Type##Array::cast(this)->FixedTypedArrayPrint(os); \
207  break;
208 
209  TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY)
210 #undef PRINT_FIXED_TYPED_ARRAY
211 
212  case FILLER_TYPE:
213  os << "filler";
214  break;
215  case JS_OBJECT_TYPE: // fall through
216  case JS_API_OBJECT_TYPE:
217  case JS_SPECIAL_API_OBJECT_TYPE:
218  case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
219  case JS_ASYNC_FUNCTION_OBJECT_TYPE:
220  case JS_ASYNC_GENERATOR_OBJECT_TYPE:
221  case JS_ARGUMENTS_TYPE:
222  case JS_ERROR_TYPE:
223  // TODO(titzer): debug printing for more wasm objects
224  case WASM_EXCEPTION_TYPE:
225  case WASM_GLOBAL_TYPE:
226  case WASM_MEMORY_TYPE:
227  case WASM_TABLE_TYPE:
228  JSObject::cast(this)->JSObjectPrint(os);
229  break;
230  case WASM_MODULE_TYPE:
231  WasmModuleObject::cast(this)->WasmModuleObjectPrint(os);
232  break;
233  case WASM_INSTANCE_TYPE:
234  WasmInstanceObject::cast(this)->WasmInstanceObjectPrint(os);
235  break;
236  case JS_GENERATOR_OBJECT_TYPE:
237  JSGeneratorObject::cast(this)->JSGeneratorObjectPrint(os);
238  break;
239  case JS_PROMISE_TYPE:
240  JSPromise::cast(this)->JSPromisePrint(os);
241  break;
242  case JS_ARRAY_TYPE:
243  JSArray::cast(this)->JSArrayPrint(os);
244  break;
245  case JS_REGEXP_TYPE:
246  JSRegExp::cast(this)->JSRegExpPrint(os);
247  break;
248  case JS_REGEXP_STRING_ITERATOR_TYPE:
249  JSRegExpStringIterator::cast(this)->JSRegExpStringIteratorPrint(os);
250  break;
251  case ODDBALL_TYPE:
252  Oddball::cast(this)->to_string()->Print(os);
253  break;
254  case JS_BOUND_FUNCTION_TYPE:
255  JSBoundFunction::cast(this)->JSBoundFunctionPrint(os);
256  break;
257  case JS_FUNCTION_TYPE:
258  JSFunction::cast(this)->JSFunctionPrint(os);
259  break;
260  case JS_GLOBAL_PROXY_TYPE:
261  JSGlobalProxy::cast(this)->JSGlobalProxyPrint(os);
262  break;
263  case JS_GLOBAL_OBJECT_TYPE:
264  JSGlobalObject::cast(this)->JSGlobalObjectPrint(os);
265  break;
266  case JS_VALUE_TYPE:
267  JSValue::cast(this)->JSValuePrint(os);
268  break;
269  case JS_DATE_TYPE:
270  JSDate::cast(this)->JSDatePrint(os);
271  break;
272  case CODE_TYPE:
273  Code::cast(this)->CodePrint(os);
274  break;
275  case CODE_DATA_CONTAINER_TYPE:
276  CodeDataContainer::cast(this)->CodeDataContainerPrint(os);
277  break;
278  case JS_PROXY_TYPE:
279  JSProxy::cast(this)->JSProxyPrint(os);
280  break;
281  case JS_SET_TYPE:
282  JSSet::cast(this)->JSSetPrint(os);
283  break;
284  case JS_MAP_TYPE:
285  JSMap::cast(this)->JSMapPrint(os);
286  break;
287  case JS_SET_KEY_VALUE_ITERATOR_TYPE:
288  case JS_SET_VALUE_ITERATOR_TYPE:
289  JSSetIterator::cast(this)->JSSetIteratorPrint(os);
290  break;
291  case JS_MAP_KEY_ITERATOR_TYPE:
292  case JS_MAP_KEY_VALUE_ITERATOR_TYPE:
293  case JS_MAP_VALUE_ITERATOR_TYPE:
294  JSMapIterator::cast(this)->JSMapIteratorPrint(os);
295  break;
296  case JS_WEAK_CELL_TYPE:
297  case JS_WEAK_REF_TYPE:
298  JSWeakCell::cast(this)->JSWeakCellPrint(os);
299  break;
300  case JS_WEAK_FACTORY_TYPE:
301  JSWeakFactory::cast(this)->JSWeakFactoryPrint(os);
302  break;
303  case JS_WEAK_FACTORY_CLEANUP_ITERATOR_TYPE:
304  JSWeakFactoryCleanupIterator::cast(this)
305  ->JSWeakFactoryCleanupIteratorPrint(os);
306  break;
307  case JS_WEAK_MAP_TYPE:
308  JSWeakMap::cast(this)->JSWeakMapPrint(os);
309  break;
310  case JS_WEAK_SET_TYPE:
311  JSWeakSet::cast(this)->JSWeakSetPrint(os);
312  break;
313  case JS_MODULE_NAMESPACE_TYPE:
314  JSModuleNamespace::cast(this)->JSModuleNamespacePrint(os);
315  break;
316  case FOREIGN_TYPE:
317  Foreign::cast(this)->ForeignPrint(os);
318  break;
319  case CALL_HANDLER_INFO_TYPE:
320  CallHandlerInfo::cast(this)->CallHandlerInfoPrint(os);
321  break;
322  case PRE_PARSED_SCOPE_DATA_TYPE:
323  PreParsedScopeData::cast(this)->PreParsedScopeDataPrint(os);
324  break;
325  case UNCOMPILED_DATA_WITHOUT_PRE_PARSED_SCOPE_TYPE:
326  UncompiledDataWithoutPreParsedScope::cast(this)
327  ->UncompiledDataWithoutPreParsedScopePrint(os);
328  break;
329  case UNCOMPILED_DATA_WITH_PRE_PARSED_SCOPE_TYPE:
330  UncompiledDataWithPreParsedScope::cast(this)
331  ->UncompiledDataWithPreParsedScopePrint(os);
332  break;
333  case SHARED_FUNCTION_INFO_TYPE:
334  SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(os);
335  break;
336  case JS_MESSAGE_OBJECT_TYPE:
337  JSMessageObject::cast(this)->JSMessageObjectPrint(os);
338  break;
339  case CELL_TYPE:
340  Cell::cast(this)->CellPrint(os);
341  break;
342  case PROPERTY_CELL_TYPE:
343  PropertyCell::cast(this)->PropertyCellPrint(os);
344  break;
345  case JS_ARRAY_BUFFER_TYPE:
346  JSArrayBuffer::cast(this)->JSArrayBufferPrint(os);
347  break;
348  case JS_ARRAY_ITERATOR_TYPE:
349  JSArrayIterator::cast(this)->JSArrayIteratorPrint(os);
350  break;
351  case JS_TYPED_ARRAY_TYPE:
352  JSTypedArray::cast(this)->JSTypedArrayPrint(os);
353  break;
354  case JS_DATA_VIEW_TYPE:
355  JSDataView::cast(this)->JSDataViewPrint(os);
356  break;
357 #ifdef V8_INTL_SUPPORT
358  case JS_INTL_V8_BREAK_ITERATOR_TYPE:
359  JSV8BreakIterator::cast(this)->JSV8BreakIteratorPrint(os);
360  break;
361  case JS_INTL_COLLATOR_TYPE:
362  JSCollator::cast(this)->JSCollatorPrint(os);
363  break;
364  case JS_INTL_DATE_TIME_FORMAT_TYPE:
365  JSDateTimeFormat::cast(this)->JSDateTimeFormatPrint(os);
366  break;
367  case JS_INTL_LIST_FORMAT_TYPE:
368  JSListFormat::cast(this)->JSListFormatPrint(os);
369  break;
370  case JS_INTL_LOCALE_TYPE:
371  JSLocale::cast(this)->JSLocalePrint(os);
372  break;
373  case JS_INTL_NUMBER_FORMAT_TYPE:
374  JSNumberFormat::cast(this)->JSNumberFormatPrint(os);
375  break;
376  case JS_INTL_PLURAL_RULES_TYPE:
377  JSPluralRules::cast(this)->JSPluralRulesPrint(os);
378  break;
379  case JS_INTL_RELATIVE_TIME_FORMAT_TYPE:
380  JSRelativeTimeFormat::cast(this)->JSRelativeTimeFormatPrint(os);
381  break;
382  case JS_INTL_SEGMENT_ITERATOR_TYPE:
383  JSSegmentIterator::cast(this)->JSSegmentIteratorPrint(os);
384  break;
385  case JS_INTL_SEGMENTER_TYPE:
386  JSSegmenter::cast(this)->JSSegmenterPrint(os);
387  break;
388 #endif // V8_INTL_SUPPORT
389 #define MAKE_STRUCT_CASE(TYPE, Name, name) \
390  case TYPE: \
391  Name::cast(this)->Name##Print(os); \
392  break;
393  STRUCT_LIST(MAKE_STRUCT_CASE)
394 #undef MAKE_STRUCT_CASE
395 
396  case ALLOCATION_SITE_TYPE:
397  AllocationSite::cast(this)->AllocationSitePrint(os);
398  break;
399  case LOAD_HANDLER_TYPE:
400  LoadHandler::cast(this)->LoadHandlerPrint(os);
401  break;
402  case STORE_HANDLER_TYPE:
403  StoreHandler::cast(this)->StoreHandlerPrint(os);
404  break;
405  case SCOPE_INFO_TYPE:
406  ScopeInfo::cast(this)->ScopeInfoPrint(os);
407  break;
408  case FEEDBACK_METADATA_TYPE:
409  FeedbackMetadata::cast(this)->FeedbackMetadataPrint(os);
410  break;
411  case WEAK_FIXED_ARRAY_TYPE:
412  WeakFixedArray::cast(this)->WeakFixedArrayPrint(os);
413  break;
414  case WEAK_ARRAY_LIST_TYPE:
415  WeakArrayList::cast(this)->WeakArrayListPrint(os);
416  break;
417  case INTERNALIZED_STRING_TYPE:
418  case EXTERNAL_INTERNALIZED_STRING_TYPE:
419  case ONE_BYTE_INTERNALIZED_STRING_TYPE:
420  case EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE:
421  case EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
422  case UNCACHED_EXTERNAL_INTERNALIZED_STRING_TYPE:
423  case UNCACHED_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE:
424  case UNCACHED_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
425  case STRING_TYPE:
426  case CONS_STRING_TYPE:
427  case EXTERNAL_STRING_TYPE:
428  case SLICED_STRING_TYPE:
429  case THIN_STRING_TYPE:
430  case ONE_BYTE_STRING_TYPE:
431  case CONS_ONE_BYTE_STRING_TYPE:
432  case EXTERNAL_ONE_BYTE_STRING_TYPE:
433  case SLICED_ONE_BYTE_STRING_TYPE:
434  case THIN_ONE_BYTE_STRING_TYPE:
435  case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
436  case UNCACHED_EXTERNAL_STRING_TYPE:
437  case UNCACHED_EXTERNAL_ONE_BYTE_STRING_TYPE:
438  case UNCACHED_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
439  case SMALL_ORDERED_HASH_MAP_TYPE:
440  case SMALL_ORDERED_HASH_SET_TYPE:
441  case SMALL_ORDERED_NAME_DICTIONARY_TYPE:
442  case JS_ASYNC_FROM_SYNC_ITERATOR_TYPE:
443  case JS_STRING_ITERATOR_TYPE:
444  // TODO(all): Handle these types too.
445  os << "UNKNOWN TYPE " << map()->instance_type();
446  UNREACHABLE();
447  break;
448  }
449 }
450 
451 void ByteArray::ByteArrayPrint(std::ostream& os) { // NOLINT
452  os << "byte array, data starts at "
453  << static_cast<void*>(GetDataStartAddress());
454 }
455 
456 void BytecodeArray::BytecodeArrayPrint(std::ostream& os) { // NOLINT
457  PrintHeader(os, "BytecodeArray");
458  Disassemble(os);
459 }
460 
461 
462 void FreeSpace::FreeSpacePrint(std::ostream& os) { // NOLINT
463  os << "free space, size " << Size();
464 }
465 
466 
467 template <class Traits>
468 void FixedTypedArray<Traits>::FixedTypedArrayPrint(
469  std::ostream& os) { // NOLINT
470  os << "fixed " << Traits::Designator();
471 }
472 
473 bool JSObject::PrintProperties(std::ostream& os) { // NOLINT
474  if (HasFastProperties()) {
475  DescriptorArray* descs = map()->instance_descriptors();
476  int nof_inobject_properties = map()->GetInObjectProperties();
477  int i = 0;
478  for (; i < map()->NumberOfOwnDescriptors(); i++) {
479  os << "\n ";
480  descs->GetKey(i)->NamePrint(os);
481  os << ": ";
482  PropertyDetails details = descs->GetDetails(i);
483  switch (details.location()) {
484  case kField: {
485  FieldIndex field_index = FieldIndex::ForDescriptor(map(), i);
486  if (IsUnboxedDoubleField(field_index)) {
487  os << "<unboxed double> " << RawFastDoublePropertyAt(field_index);
488  } else {
489  os << Brief(RawFastPropertyAt(field_index));
490  }
491  break;
492  }
493  case kDescriptor:
494  os << Brief(descs->GetStrongValue(i));
495  break;
496  }
497  os << " ";
498  details.PrintAsFastTo(os, PropertyDetails::kForProperties);
499  if (details.location() != kField) continue;
500  int field_index = details.field_index();
501  if (nof_inobject_properties <= field_index) {
502  field_index -= nof_inobject_properties;
503  os << " properties[" << field_index << "]";
504  }
505  }
506  return i > 0;
507  } else if (IsJSGlobalObject()) {
508  JSGlobalObject::cast(this)->global_dictionary()->Print(os);
509  } else {
510  property_dictionary()->Print(os);
511  }
512  return true;
513 }
514 
515 namespace {
516 
517 template <class T>
518 bool IsTheHoleAt(T array, int index) {
519  return false;
520 }
521 
522 template <>
523 bool IsTheHoleAt(FixedDoubleArray array, int index) {
524  return array->is_the_hole(index);
525 }
526 
527 template <class T>
528 double GetScalarElement(T array, int index) {
529  if (IsTheHoleAt(array, index)) {
530  return std::numeric_limits<double>::quiet_NaN();
531  }
532  return array->get_scalar(index);
533 }
534 
535 template <class T>
536 void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
537  const bool print_the_hole = std::is_same<T, FixedDoubleArray>::value;
538  T array = T::cast(object);
539  if (array->length() == 0) return;
540  int previous_index = 0;
541  double previous_value = GetScalarElement(array, 0);
542  double value = 0.0;
543  int i;
544  for (i = 1; i <= array->length(); i++) {
545  if (i < array->length()) value = GetScalarElement(array, i);
546  bool values_are_nan = std::isnan(previous_value) && std::isnan(value);
547  if (i != array->length() && (previous_value == value || values_are_nan) &&
548  IsTheHoleAt(array, i - 1) == IsTheHoleAt(array, i)) {
549  continue;
550  }
551  os << "\n";
552  std::stringstream ss;
553  ss << previous_index;
554  if (previous_index != i - 1) {
555  ss << '-' << (i - 1);
556  }
557  os << std::setw(12) << ss.str() << ": ";
558  if (print_the_hole && IsTheHoleAt(array, i - 1)) {
559  os << "<the_hole>";
560  } else {
561  os << previous_value;
562  }
563  previous_index = i;
564  previous_value = value;
565  }
566 }
567 
568 template <typename T>
569 void PrintFixedArrayElements(std::ostream& os, T array) {
570  // Print in array notation for non-sparse arrays.
571  Object* previous_value = array->length() > 0 ? array->get(0) : nullptr;
572  Object* value = nullptr;
573  int previous_index = 0;
574  int i;
575  for (i = 1; i <= array->length(); i++) {
576  if (i < array->length()) value = array->get(i);
577  if (previous_value == value && i != array->length()) {
578  continue;
579  }
580  os << "\n";
581  std::stringstream ss;
582  ss << previous_index;
583  if (previous_index != i - 1) {
584  ss << '-' << (i - 1);
585  }
586  os << std::setw(12) << ss.str() << ": " << Brief(previous_value);
587  previous_index = i;
588  previous_value = value;
589  }
590 }
591 
592 void PrintDictionaryElements(std::ostream& os, FixedArrayBase elements) {
593  // Print some internal fields
594  NumberDictionary dict = NumberDictionary::cast(elements);
595  if (dict->requires_slow_elements()) {
596  os << "\n - requires_slow_elements";
597  } else {
598  os << "\n - max_number_key: " << dict->max_number_key();
599  }
600  dict->Print(os);
601 }
602 
603 void PrintSloppyArgumentElements(std::ostream& os, ElementsKind kind,
604  SloppyArgumentsElements elements) {
605  FixedArray arguments_store = elements->arguments();
606  os << "\n 0: context: " << Brief(elements->context())
607  << "\n 1: arguments_store: " << Brief(arguments_store)
608  << "\n parameter to context slot map:";
609  for (uint32_t i = 0; i < elements->parameter_map_length(); i++) {
610  uint32_t raw_index = i + SloppyArgumentsElements::kParameterMapStart;
611  Object* mapped_entry = elements->get_mapped_entry(i);
612  os << "\n " << raw_index << ": param(" << i
613  << "): " << Brief(mapped_entry);
614  if (mapped_entry->IsTheHole()) {
615  os << " in the arguments_store[" << i << "]";
616  } else {
617  os << " in the context";
618  }
619  }
620  if (arguments_store->length() == 0) return;
621  os << "\n }"
622  << "\n - arguments_store: " << Brief(arguments_store) << " "
623  << ElementsKindToString(arguments_store->map()->elements_kind()) << " {";
624  if (kind == FAST_SLOPPY_ARGUMENTS_ELEMENTS) {
625  PrintFixedArrayElements(os, arguments_store);
626  } else {
627  DCHECK_EQ(kind, SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
628  PrintDictionaryElements(os, arguments_store);
629  }
630 }
631 
632 void PrintEmbedderData(std::ostream& os, EmbedderDataSlot slot) {
633  DisallowHeapAllocation no_gc;
634  Object* value = slot.load_tagged();
635  os << Brief(value);
636  void* raw_pointer;
637  if (slot.ToAlignedPointer(&raw_pointer)) {
638  os << ", aligned pointer: " << raw_pointer;
639  }
640 }
641 
642 } // namespace
643 
644 void JSObject::PrintElements(std::ostream& os) { // NOLINT
645  // Don't call GetElementsKind, its validation code can cause the printer to
646  // fail when debugging.
647  os << " - elements: " << Brief(elements()) << " {";
648  if (elements()->length() == 0) {
649  os << " }\n";
650  return;
651  }
652  switch (map()->elements_kind()) {
653  case HOLEY_SMI_ELEMENTS:
654  case PACKED_SMI_ELEMENTS:
655  case HOLEY_ELEMENTS:
656  case PACKED_ELEMENTS:
657  case FAST_STRING_WRAPPER_ELEMENTS: {
658  PrintFixedArrayElements(os, FixedArray::cast(elements()));
659  break;
660  }
661  case HOLEY_DOUBLE_ELEMENTS:
662  case PACKED_DOUBLE_ELEMENTS: {
663  DoPrintElements<FixedDoubleArray>(os, elements());
664  break;
665  }
666 
667 #define PRINT_ELEMENTS(Type, type, TYPE, elementType) \
668  case TYPE##_ELEMENTS: { \
669  DoPrintElements<Fixed##Type##Array>(os, elements()); \
670  break; \
671  }
672  TYPED_ARRAYS(PRINT_ELEMENTS)
673 #undef PRINT_ELEMENTS
674 
675  case DICTIONARY_ELEMENTS:
676  case SLOW_STRING_WRAPPER_ELEMENTS:
677  PrintDictionaryElements(os, elements());
678  break;
679  case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
680  case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
681  PrintSloppyArgumentElements(os, map()->elements_kind(),
682  SloppyArgumentsElements::cast(elements()));
683  break;
684  case NO_ELEMENTS:
685  break;
686  }
687  os << "\n }\n";
688 }
689 
690 static void JSObjectPrintHeader(std::ostream& os, JSObject* obj,
691  const char* id) { // NOLINT
692  Isolate* isolate = obj->GetIsolate();
693  obj->PrintHeader(os, id);
694  // Don't call GetElementsKind, its validation code can cause the printer to
695  // fail when debugging.
696  os << " [";
697  if (obj->HasFastProperties()) {
698  os << "FastProperties";
699  } else {
700  os << "DictionaryProperties";
701  }
702  PrototypeIterator iter(isolate, obj);
703  os << "]\n - prototype: " << Brief(iter.GetCurrent());
704  os << "\n - elements: " << Brief(obj->elements()) << " ["
705  << ElementsKindToString(obj->map()->elements_kind());
706  if (obj->elements()->IsCowArray()) os << " (COW)";
707  os << "]";
708  Object* hash = obj->GetHash();
709  if (hash->IsSmi()) {
710  os << "\n - hash: " << Brief(hash);
711  }
712  if (obj->GetEmbedderFieldCount() > 0) {
713  os << "\n - embedder fields: " << obj->GetEmbedderFieldCount();
714  }
715 }
716 
717 static void JSObjectPrintBody(std::ostream& os,
718  JSObject* obj, // NOLINT
719  bool print_elements = true) {
720  os << "\n - properties: ";
721  Object* properties_or_hash = obj->raw_properties_or_hash();
722  if (!properties_or_hash->IsSmi()) {
723  os << Brief(properties_or_hash);
724  }
725  os << " {";
726  if (obj->PrintProperties(os)) os << "\n ";
727  os << "}\n";
728  if (print_elements && obj->elements()->length() > 0) {
729  obj->PrintElements(os);
730  }
731  int embedder_fields = obj->GetEmbedderFieldCount();
732  if (embedder_fields > 0) {
733  os << " - embedder fields = {";
734  for (int i = 0; i < embedder_fields; i++) {
735  os << "\n ";
736  PrintEmbedderData(os, EmbedderDataSlot(obj, i));
737  }
738  os << "\n }\n";
739  }
740 }
741 
742 void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT
743  JSObjectPrintHeader(os, this, nullptr);
744  JSObjectPrintBody(os, this);
745 }
746 
747 void JSGeneratorObject::JSGeneratorObjectPrint(std::ostream& os) { // NOLINT
748  JSObjectPrintHeader(os, this, "JSGeneratorObject");
749  os << "\n - function: " << Brief(function());
750  os << "\n - context: " << Brief(context());
751  os << "\n - receiver: " << Brief(receiver());
752  if (is_executing() || is_closed()) {
753  os << "\n - input: " << Brief(input_or_debug_pos());
754  } else {
755  DCHECK(is_suspended());
756  os << "\n - debug pos: " << Brief(input_or_debug_pos());
757  }
758  const char* mode = "(invalid)";
759  switch (resume_mode()) {
760  case kNext:
761  mode = ".next()";
762  break;
763  case kReturn:
764  mode = ".return()";
765  break;
766  case kThrow:
767  mode = ".throw()";
768  break;
769  }
770  os << "\n - resume mode: " << mode;
771  os << "\n - continuation: " << continuation();
772  if (is_closed()) os << " (closed)";
773  if (is_executing()) os << " (executing)";
774  if (is_suspended()) os << " (suspended)";
775  if (is_suspended()) {
776  DisallowHeapAllocation no_gc;
777  SharedFunctionInfo* fun_info = function()->shared();
778  if (fun_info->HasSourceCode()) {
779  Script* script = Script::cast(fun_info->script());
780  int lin = script->GetLineNumber(source_position()) + 1;
781  int col = script->GetColumnNumber(source_position()) + 1;
782  String script_name = script->name()->IsString()
783  ? String::cast(script->name())
784  : GetReadOnlyRoots().empty_string();
785  os << "\n - source position: " << source_position();
786  os << " (";
787  script_name->PrintUC16(os);
788  os << ", lin " << lin;
789  os << ", col " << col;
790  os << ")";
791  }
792  }
793  os << "\n - register file: " << Brief(parameters_and_registers());
794  JSObjectPrintBody(os, this);
795 }
796 
797 void JSArray::JSArrayPrint(std::ostream& os) { // NOLINT
798  JSObjectPrintHeader(os, this, "JSArray");
799  os << "\n - length: " << Brief(this->length());
800  JSObjectPrintBody(os, this);
801 }
802 
803 void JSPromise::JSPromisePrint(std::ostream& os) { // NOLINT
804  JSObjectPrintHeader(os, this, "JSPromise");
805  os << "\n - status: " << JSPromise::Status(status());
806  if (status() == Promise::kPending) {
807  os << "\n - reactions: " << Brief(reactions());
808  } else {
809  os << "\n - result: " << Brief(result());
810  }
811  os << "\n - has_handler: " << has_handler();
812  JSObjectPrintBody(os, this);
813 }
814 
815 void JSRegExp::JSRegExpPrint(std::ostream& os) { // NOLINT
816  JSObjectPrintHeader(os, this, "JSRegExp");
817  os << "\n - data: " << Brief(data());
818  os << "\n - source: " << Brief(source());
819  JSObjectPrintBody(os, this);
820 }
821 
822 void JSRegExpStringIterator::JSRegExpStringIteratorPrint(
823  std::ostream& os) { // NOLINT
824  JSObjectPrintHeader(os, this, "JSRegExpStringIterator");
825  os << "\n - regex: " << Brief(iterating_regexp());
826  os << "\n - string: " << Brief(iterating_string());
827  os << "\n - done: " << done();
828  os << "\n - global: " << global();
829  os << "\n - unicode: " << unicode();
830  JSObjectPrintBody(os, this);
831 }
832 
833 void Symbol::SymbolPrint(std::ostream& os) { // NOLINT
834  PrintHeader(os, "Symbol");
835  os << "\n - hash: " << Hash();
836  os << "\n - name: " << Brief(name());
837  if (name()->IsUndefined()) {
838  os << " (" << PrivateSymbolToName() << ")";
839  }
840  os << "\n - private: " << is_private();
841 }
842 
843 void Map::MapPrint(std::ostream& os) { // NOLINT
844  PrintHeader(os, "Map");
845  os << "\n - type: " << instance_type();
846  os << "\n - instance size: ";
847  if (instance_size() == kVariableSizeSentinel) {
848  os << "variable";
849  } else {
850  os << instance_size();
851  }
852  if (IsJSObjectMap()) {
853  os << "\n - inobject properties: " << GetInObjectProperties();
854  }
855  os << "\n - elements kind: " << ElementsKindToString(elements_kind());
856  os << "\n - unused property fields: " << UnusedPropertyFields();
857  os << "\n - enum length: ";
858  if (EnumLength() == kInvalidEnumCacheSentinel) {
859  os << "invalid";
860  } else {
861  os << EnumLength();
862  }
863  if (is_deprecated()) os << "\n - deprecated_map";
864  if (is_stable()) os << "\n - stable_map";
865  if (is_migration_target()) os << "\n - migration_target";
866  if (is_dictionary_map()) os << "\n - dictionary_map";
867  if (has_hidden_prototype()) os << "\n - has_hidden_prototype";
868  if (has_named_interceptor()) os << "\n - named_interceptor";
869  if (has_indexed_interceptor()) os << "\n - indexed_interceptor";
870  if (may_have_interesting_symbols()) os << "\n - may_have_interesting_symbols";
871  if (is_undetectable()) os << "\n - undetectable";
872  if (is_callable()) os << "\n - callable";
873  if (is_constructor()) os << "\n - constructor";
874  if (has_prototype_slot()) {
875  os << "\n - has_prototype_slot";
876  if (has_non_instance_prototype()) os << " (non-instance prototype)";
877  }
878  if (is_access_check_needed()) os << "\n - access_check_needed";
879  if (!is_extensible()) os << "\n - non-extensible";
880  if (is_prototype_map()) {
881  os << "\n - prototype_map";
882  os << "\n - prototype info: " << Brief(prototype_info());
883  } else {
884  os << "\n - back pointer: " << Brief(GetBackPointer());
885  }
886  os << "\n - prototype_validity cell: " << Brief(prototype_validity_cell());
887  os << "\n - instance descriptors " << (owns_descriptors() ? "(own) " : "")
888  << "#" << NumberOfOwnDescriptors() << ": "
889  << Brief(instance_descriptors());
890  if (FLAG_unbox_double_fields) {
891  os << "\n - layout descriptor: ";
892  layout_descriptor()->ShortPrint(os);
893  }
894 
895  Isolate* isolate;
896  // Read-only maps can't have transitions, which is fortunate because we need
897  // the isolate to iterate over the transitions.
898  if (Isolate::FromWritableHeapObject(reinterpret_cast<HeapObject*>(ptr()),
899  &isolate)) {
900  DisallowHeapAllocation no_gc;
901  TransitionsAccessor transitions(isolate, *this, &no_gc);
902  int nof_transitions = transitions.NumberOfTransitions();
903  if (nof_transitions > 0) {
904  os << "\n - transitions #" << nof_transitions << ": ";
905  HeapObject* heap_object;
906  Smi smi;
907  if (raw_transitions()->ToSmi(&smi)) {
908  os << Brief(smi);
909  } else if (raw_transitions()->GetHeapObject(&heap_object)) {
910  os << Brief(heap_object);
911  }
912  transitions.PrintTransitions(os);
913  }
914  }
915  os << "\n - prototype: " << Brief(prototype());
916  os << "\n - constructor: " << Brief(GetConstructor());
917  os << "\n - dependent code: " << Brief(dependent_code());
918  os << "\n - construction counter: " << construction_counter();
919  os << "\n";
920 }
921 
922 void DescriptorArray::DescriptorArrayPrint(std::ostream& os) {
923  HeapObject::PrintHeader(os, "DescriptorArray");
924  os << "\n - enum_cache: ";
925  if (enum_cache()->keys()->length() == 0) {
926  os << "empty";
927  } else {
928  os << enum_cache()->keys()->length();
929  os << "\n - keys: " << Brief(enum_cache()->keys());
930  os << "\n - indices: " << Brief(enum_cache()->indices());
931  }
932  os << "\n - nof slack descriptors: " << number_of_slack_descriptors();
933  os << "\n - nof descriptors: " << number_of_descriptors();
934  PrintDescriptors(os);
935 }
936 
937 void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(
938  std::ostream& os) { // NOLINT
939  HeapObject::PrintHeader(os, "AliasedArgumentsEntry");
940  os << "\n - aliased_context_slot: " << aliased_context_slot();
941 }
942 
943 namespace {
944 void PrintFixedArrayWithHeader(std::ostream& os, FixedArray array,
945  const char* type) {
946  array->PrintHeader(os, type);
947  os << "\n - length: " << array->length();
948  PrintFixedArrayElements(os, array);
949  os << "\n";
950 }
951 
952 template <typename T>
953 void PrintHashTableWithHeader(std::ostream& os, T table, const char* type) {
954  table->PrintHeader(os, type);
955  os << "\n - length: " << table->length();
956  os << "\n - elements: " << table->NumberOfElements();
957  os << "\n - deleted: " << table->NumberOfDeletedElements();
958  os << "\n - capacity: " << table->Capacity();
959 
960  os << "\n - elements: {";
961  for (int i = 0; i < table->Capacity(); i++) {
962  os << '\n'
963  << std::setw(12) << i << ": " << Brief(table->KeyAt(i)) << " -> "
964  << Brief(table->ValueAt(i));
965  }
966  os << "\n }\n";
967 }
968 
969 template <typename T>
970 void PrintWeakArrayElements(std::ostream& os, T* array) {
971  // Print in array notation for non-sparse arrays.
972  MaybeObject previous_value =
973  array->length() > 0 ? array->Get(0) : MaybeObject(kNullAddress);
974  MaybeObject value;
975  int previous_index = 0;
976  int i;
977  for (i = 1; i <= array->length(); i++) {
978  if (i < array->length()) value = array->Get(i);
979  if (previous_value == value && i != array->length()) {
980  continue;
981  }
982  os << "\n";
983  std::stringstream ss;
984  ss << previous_index;
985  if (previous_index != i - 1) {
986  ss << '-' << (i - 1);
987  }
988  os << std::setw(12) << ss.str() << ": " << Brief(previous_value);
989  previous_index = i;
990  previous_value = value;
991  }
992 }
993 
994 } // namespace
995 
996 void EmbedderDataArray::EmbedderDataArrayPrint(std::ostream& os) {
997  PrintHeader(os, "EmbedderDataArray");
998  os << "\n - length: " << length();
999  EmbedderDataSlot start(*this, 0);
1000  EmbedderDataSlot end(*this, length());
1001  for (EmbedderDataSlot slot = start; slot < end; ++slot) {
1002  os << "\n ";
1003  PrintEmbedderData(os, slot);
1004  }
1005  os << "\n";
1006 }
1007 
1008 void FixedArray::FixedArrayPrint(std::ostream& os) {
1009  PrintFixedArrayWithHeader(os, *this, "FixedArray");
1010 }
1011 
1012 namespace {
1013 void PrintContextWithHeader(std::ostream& os, Context context,
1014  const char* type) {
1015  context->PrintHeader(os, type);
1016  os << "\n - length: " << context->length();
1017  os << "\n - scope_info: " << Brief(context->scope_info());
1018  os << "\n - previous: " << Brief(context->previous());
1019  os << "\n - extension_object: " << Brief(context->extension_object());
1020  os << "\n - native_context: " << Brief(context->native_context());
1021  PrintFixedArrayElements(os, context);
1022  os << "\n";
1023 }
1024 } // namespace
1025 
1026 void Context::ContextPrint(std::ostream& os) {
1027  PrintContextWithHeader(os, *this, "Context");
1028 }
1029 
1030 void NativeContext::NativeContextPrint(std::ostream& os) {
1031  PrintContextWithHeader(os, *this, "NativeContext");
1032  os << " - microtask_queue: " << microtask_queue() << "\n";
1033 }
1034 
1035 void ObjectHashTable::ObjectHashTablePrint(std::ostream& os) {
1036  PrintHashTableWithHeader(os, *this, "ObjectHashTable");
1037 }
1038 
1039 void NumberDictionary::NumberDictionaryPrint(std::ostream& os) {
1040  PrintHashTableWithHeader(os, *this, "NumberDictionary");
1041 }
1042 
1043 void EphemeronHashTable::EphemeronHashTablePrint(std::ostream& os) {
1044  PrintHashTableWithHeader(os, *this, "EphemeronHashTable");
1045 }
1046 
1047 void ObjectBoilerplateDescription::ObjectBoilerplateDescriptionPrint(
1048  std::ostream& os) {
1049  PrintFixedArrayWithHeader(os, *this, "ObjectBoilerplateDescription");
1050 }
1051 
1052 void PropertyArray::PropertyArrayPrint(std::ostream& os) { // NOLINT
1053  PrintHeader(os, "PropertyArray");
1054  os << "\n - length: " << length();
1055  os << "\n - hash: " << Hash();
1056  PrintFixedArrayElements(os, *this);
1057  os << "\n";
1058 }
1059 
1060 void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT
1061  PrintHeader(os, "FixedDoubleArray");
1062  os << "\n - length: " << length();
1063  DoPrintElements<FixedDoubleArray>(os, *this);
1064  os << "\n";
1065 }
1066 
1067 void WeakFixedArray::WeakFixedArrayPrint(std::ostream& os) {
1068  PrintHeader(os, "WeakFixedArray");
1069  os << "\n - length: " << length() << "\n";
1070  PrintWeakArrayElements(os, this);
1071  os << "\n";
1072 }
1073 
1074 void WeakArrayList::WeakArrayListPrint(std::ostream& os) {
1075  PrintHeader(os, "WeakArrayList");
1076  os << "\n - capacity: " << capacity();
1077  os << "\n - length: " << length() << "\n";
1078  PrintWeakArrayElements(os, this);
1079  os << "\n";
1080 }
1081 
1082 void TransitionArray::TransitionArrayPrint(std::ostream& os) { // NOLINT
1083  HeapObject::PrintHeader(os, "TransitionArray");
1084  PrintInternal(os);
1085 }
1086 
1087 void FeedbackCell::FeedbackCellPrint(std::ostream& os) { // NOLINT
1088  HeapObject::PrintHeader(os, "FeedbackCell");
1089  ReadOnlyRoots roots = GetReadOnlyRoots();
1090  if (map() == roots.no_closures_cell_map()) {
1091  os << "\n - no closures";
1092  } else if (map() == roots.one_closure_cell_map()) {
1093  os << "\n - one closure";
1094  } else if (map() == roots.many_closures_cell_map()) {
1095  os << "\n - many closures";
1096  } else {
1097  os << "\n - Invalid FeedbackCell map";
1098  }
1099  os << " - value: " << Brief(value());
1100  os << "\n";
1101 }
1102 
1103 void FeedbackVectorSpec::Print() {
1104  StdoutStream os;
1105 
1106  FeedbackVectorSpecPrint(os);
1107 
1108  os << std::flush;
1109 }
1110 
1111 void FeedbackVectorSpec::FeedbackVectorSpecPrint(std::ostream& os) { // NOLINT
1112  int slot_count = slots();
1113  os << " - slot_count: " << slot_count;
1114  if (slot_count == 0) {
1115  os << " (empty)\n";
1116  return;
1117  }
1118 
1119  for (int slot = 0; slot < slot_count;) {
1120  FeedbackSlotKind kind = GetKind(FeedbackSlot(slot));
1121  int entry_size = FeedbackMetadata::GetSlotSize(kind);
1122  DCHECK_LT(0, entry_size);
1123  os << "\n Slot #" << slot << " " << kind;
1124  slot += entry_size;
1125  }
1126  os << "\n";
1127 }
1128 
1129 void FeedbackMetadata::FeedbackMetadataPrint(std::ostream& os) {
1130  HeapObject::PrintHeader(os, "FeedbackMetadata");
1131  os << "\n - slot_count: " << slot_count();
1132 
1133  FeedbackMetadataIterator iter(this);
1134  while (iter.HasNext()) {
1135  FeedbackSlot slot = iter.Next();
1136  FeedbackSlotKind kind = iter.kind();
1137  os << "\n Slot " << slot << " " << kind;
1138  }
1139  os << "\n";
1140 }
1141 
1142 void FeedbackVector::FeedbackVectorPrint(std::ostream& os) { // NOLINT
1143  HeapObject::PrintHeader(os, "FeedbackVector");
1144  os << "\n - length: " << length();
1145  if (length() == 0) {
1146  os << " (empty)\n";
1147  return;
1148  }
1149 
1150  os << "\n - shared function info: " << Brief(shared_function_info());
1151  os << "\n - optimized code/marker: ";
1152  if (has_optimized_code()) {
1153  os << Brief(optimized_code());
1154  } else {
1155  os << optimization_marker();
1156  }
1157  os << "\n - invocation count: " << invocation_count();
1158  os << "\n - profiler ticks: " << profiler_ticks();
1159 
1160  FeedbackMetadataIterator iter(metadata());
1161  while (iter.HasNext()) {
1162  FeedbackSlot slot = iter.Next();
1163  FeedbackSlotKind kind = iter.kind();
1164 
1165  os << "\n - slot " << slot << " " << kind << " ";
1166  FeedbackSlotPrint(os, slot);
1167 
1168  int entry_size = iter.entry_size();
1169  if (entry_size > 0) os << " {";
1170  for (int i = 0; i < entry_size; i++) {
1171  int index = GetIndex(slot) + i;
1172  os << "\n [" << index << "]: " << Brief(get(index));
1173  }
1174  if (entry_size > 0) os << "\n }";
1175  }
1176  os << "\n";
1177 }
1178 
1179 void FeedbackVector::FeedbackSlotPrint(std::ostream& os,
1180  FeedbackSlot slot) { // NOLINT
1181  FeedbackNexus nexus(this, slot);
1182  nexus.Print(os);
1183 }
1184 
1185 void FeedbackNexus::Print(std::ostream& os) { // NOLINT
1186  switch (kind()) {
1187  case FeedbackSlotKind::kCall:
1188  case FeedbackSlotKind::kLoadProperty:
1189  case FeedbackSlotKind::kLoadKeyed:
1190  case FeedbackSlotKind::kLoadGlobalInsideTypeof:
1191  case FeedbackSlotKind::kLoadGlobalNotInsideTypeof:
1192  case FeedbackSlotKind::kStoreNamedSloppy:
1193  case FeedbackSlotKind::kStoreNamedStrict:
1194  case FeedbackSlotKind::kStoreOwnNamed:
1195  case FeedbackSlotKind::kStoreGlobalSloppy:
1196  case FeedbackSlotKind::kStoreGlobalStrict:
1197  case FeedbackSlotKind::kStoreKeyedSloppy:
1198  case FeedbackSlotKind::kInstanceOf:
1199  case FeedbackSlotKind::kStoreDataPropertyInLiteral:
1200  case FeedbackSlotKind::kStoreKeyedStrict:
1201  case FeedbackSlotKind::kStoreInArrayLiteral:
1202  case FeedbackSlotKind::kCloneObject: {
1203  os << InlineCacheState2String(StateFromFeedback());
1204  break;
1205  }
1206  case FeedbackSlotKind::kBinaryOp: {
1207  os << "BinaryOp:" << GetBinaryOperationFeedback();
1208  break;
1209  }
1210  case FeedbackSlotKind::kCompareOp: {
1211  os << "CompareOp:" << GetCompareOperationFeedback();
1212  break;
1213  }
1214  case FeedbackSlotKind::kForIn: {
1215  os << "ForIn:" << GetForInFeedback();
1216  break;
1217  }
1218  case FeedbackSlotKind::kCreateClosure:
1219  case FeedbackSlotKind::kLiteral:
1220  case FeedbackSlotKind::kTypeProfile:
1221  break;
1222  case FeedbackSlotKind::kInvalid:
1223  case FeedbackSlotKind::kKindsNumber:
1224  UNREACHABLE();
1225  break;
1226  }
1227 }
1228 
1229 void JSValue::JSValuePrint(std::ostream& os) { // NOLINT
1230  JSObjectPrintHeader(os, this, "JSValue");
1231  os << "\n - value: " << Brief(value());
1232  JSObjectPrintBody(os, this);
1233 }
1234 
1235 void JSMessageObject::JSMessageObjectPrint(std::ostream& os) { // NOLINT
1236  JSObjectPrintHeader(os, this, "JSMessageObject");
1237  os << "\n - type: " << static_cast<int>(type());
1238  os << "\n - arguments: " << Brief(argument());
1239  os << "\n - start_position: " << start_position();
1240  os << "\n - end_position: " << end_position();
1241  os << "\n - script: " << Brief(script());
1242  os << "\n - stack_frames: " << Brief(stack_frames());
1243  JSObjectPrintBody(os, this);
1244 }
1245 
1246 
1247 void String::StringPrint(std::ostream& os) { // NOLINT
1248  if (!HasOnlyOneByteChars()) {
1249  os << "u";
1250  }
1251  if (StringShape(*this).IsInternalized()) {
1252  os << "#";
1253  } else if (StringShape(*this).IsCons()) {
1254  os << "c\"";
1255  } else if (StringShape(*this).IsThin()) {
1256  os << ">\"";
1257  } else {
1258  os << "\"";
1259  }
1260 
1261  const char truncated_epilogue[] = "...<truncated>";
1262  int len = length();
1263  if (!FLAG_use_verbose_printer) {
1264  if (len > 100) {
1265  len = 100 - sizeof(truncated_epilogue);
1266  }
1267  }
1268  for (int i = 0; i < len; i++) {
1269  os << AsUC16(Get(i));
1270  }
1271  if (len != length()) {
1272  os << truncated_epilogue;
1273  }
1274 
1275  if (!StringShape(*this).IsInternalized()) os << "\"";
1276 }
1277 
1278 
1279 void Name::NamePrint(std::ostream& os) { // NOLINT
1280  if (IsString()) {
1281  String::cast(*this)->StringPrint(os);
1282  } else {
1283  os << Brief(*this);
1284  }
1285 }
1286 
1287 
1288 static const char* const weekdays[] = {
1289  "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
1290 };
1291 
1292 void JSDate::JSDatePrint(std::ostream& os) { // NOLINT
1293  JSObjectPrintHeader(os, this, "JSDate");
1294  os << "\n - value: " << Brief(value());
1295  if (!year()->IsSmi()) {
1296  os << "\n - time = NaN\n";
1297  } else {
1298  // TODO(svenpanne) Add some basic formatting to our streams.
1299  ScopedVector<char> buf(100);
1300  SNPrintF(buf, "\n - time = %s %04d/%02d/%02d %02d:%02d:%02d\n",
1301  weekdays[weekday()->IsSmi() ? Smi::ToInt(weekday()) + 1 : 0],
1302  year()->IsSmi() ? Smi::ToInt(year()) : -1,
1303  month()->IsSmi() ? Smi::ToInt(month()) : -1,
1304  day()->IsSmi() ? Smi::ToInt(day()) : -1,
1305  hour()->IsSmi() ? Smi::ToInt(hour()) : -1,
1306  min()->IsSmi() ? Smi::ToInt(min()) : -1,
1307  sec()->IsSmi() ? Smi::ToInt(sec()) : -1);
1308  os << buf.start();
1309  }
1310  JSObjectPrintBody(os, this);
1311 }
1312 
1313 
1314 void JSProxy::JSProxyPrint(std::ostream& os) { // NOLINT
1315  HeapObject::PrintHeader(os, "JSProxy");
1316  os << "\n - target: ";
1317  target()->ShortPrint(os);
1318  os << "\n - handler: ";
1319  handler()->ShortPrint(os);
1320  os << "\n";
1321 }
1322 
1323 void JSSet::JSSetPrint(std::ostream& os) { // NOLINT
1324  JSObjectPrintHeader(os, this, "JSSet");
1325  os << " - table: " << Brief(table());
1326  JSObjectPrintBody(os, this);
1327 }
1328 
1329 void JSMap::JSMapPrint(std::ostream& os) { // NOLINT
1330  JSObjectPrintHeader(os, this, "JSMap");
1331  os << " - table: " << Brief(table());
1332  JSObjectPrintBody(os, this);
1333 }
1334 
1335 void JSCollectionIterator::JSCollectionIteratorPrint(
1336  std::ostream& os, const char* name) { // NOLINT
1337  JSObjectPrintHeader(os, this, name);
1338  os << "\n - table: " << Brief(table());
1339  os << "\n - index: " << Brief(index());
1340  JSObjectPrintBody(os, this);
1341 }
1342 
1343 void JSSetIterator::JSSetIteratorPrint(std::ostream& os) { // NOLINT
1344  JSCollectionIteratorPrint(os, "JSSetIterator");
1345 }
1346 
1347 void JSMapIterator::JSMapIteratorPrint(std::ostream& os) { // NOLINT
1348  JSCollectionIteratorPrint(os, "JSMapIterator");
1349 }
1350 
1351 void JSWeakCell::JSWeakCellPrint(std::ostream& os) {
1352  JSObjectPrintHeader(os, this, "JSWeakCell");
1353  os << "\n - factory: " << Brief(factory());
1354  os << "\n - target: " << Brief(target());
1355  os << "\n - holdings: " << Brief(holdings());
1356  os << "\n - prev: " << Brief(prev());
1357  os << "\n - next: " << Brief(next());
1358  JSObjectPrintBody(os, this);
1359 }
1360 
1361 void JSWeakFactory::JSWeakFactoryPrint(std::ostream& os) {
1362  JSObjectPrintHeader(os, this, "JSWeakFactory");
1363  os << "\n - native_context: " << Brief(native_context());
1364  os << "\n - cleanup: " << Brief(cleanup());
1365  os << "\n - active_cells: " << Brief(active_cells());
1366  os << "\n - cleared_cells: " << Brief(cleared_cells());
1367  JSObjectPrintBody(os, this);
1368 }
1369 
1370 void JSWeakFactoryCleanupIterator::JSWeakFactoryCleanupIteratorPrint(
1371  std::ostream& os) {
1372  JSObjectPrintHeader(os, this, "JSWeakFactoryCleanupIterator");
1373  os << "\n - factory: " << Brief(factory());
1374  JSObjectPrintBody(os, this);
1375 }
1376 
1377 void WeakFactoryCleanupJobTask::WeakFactoryCleanupJobTaskPrint(
1378  std::ostream& os) {
1379  HeapObject::PrintHeader(os, "WeakFactoryCleanupJobTask");
1380  os << "\n - factory: " << Brief(factory());
1381 }
1382 
1383 void JSWeakMap::JSWeakMapPrint(std::ostream& os) { // NOLINT
1384  JSObjectPrintHeader(os, this, "JSWeakMap");
1385  os << "\n - table: " << Brief(table());
1386  JSObjectPrintBody(os, this);
1387 }
1388 
1389 void JSWeakSet::JSWeakSetPrint(std::ostream& os) { // NOLINT
1390  JSObjectPrintHeader(os, this, "JSWeakSet");
1391  os << "\n - table: " << Brief(table());
1392  JSObjectPrintBody(os, this);
1393 }
1394 
1395 void JSArrayBuffer::JSArrayBufferPrint(std::ostream& os) { // NOLINT
1396  JSObjectPrintHeader(os, this, "JSArrayBuffer");
1397  os << "\n - backing_store: " << backing_store();
1398  os << "\n - byte_length: " << byte_length();
1399  if (is_external()) os << "\n - external";
1400  if (is_neuterable()) os << "\n - neuterable";
1401  if (was_neutered()) os << "\n - neutered";
1402  if (is_shared()) os << "\n - shared";
1403  if (is_wasm_memory()) os << "\n - is_wasm_memory";
1404  if (is_growable()) os << "\n - growable";
1405  JSObjectPrintBody(os, this, !was_neutered());
1406 }
1407 
1408 void JSTypedArray::JSTypedArrayPrint(std::ostream& os) { // NOLINT
1409  JSObjectPrintHeader(os, this, "JSTypedArray");
1410  os << "\n - buffer: " << Brief(buffer());
1411  os << "\n - byte_offset: " << byte_offset();
1412  os << "\n - byte_length: " << byte_length();
1413  os << "\n - length: " << Brief(length());
1414  if (WasNeutered()) os << "\n - neutered";
1415  JSObjectPrintBody(os, this, !WasNeutered());
1416 }
1417 
1418 void JSArrayIterator::JSArrayIteratorPrint(std::ostream& os) { // NOLING
1419  JSObjectPrintHeader(os, this, "JSArrayIterator");
1420  os << "\n - iterated_object: " << Brief(iterated_object());
1421  os << "\n - next_index: " << Brief(next_index());
1422  os << "\n - kind: " << kind();
1423  JSObjectPrintBody(os, this);
1424 }
1425 
1426 void JSDataView::JSDataViewPrint(std::ostream& os) { // NOLINT
1427  JSObjectPrintHeader(os, this, "JSDataView");
1428  os << "\n - buffer =" << Brief(buffer());
1429  os << "\n - byte_offset: " << byte_offset();
1430  os << "\n - byte_length: " << byte_length();
1431  if (WasNeutered()) os << "\n - neutered";
1432  JSObjectPrintBody(os, this, !WasNeutered());
1433 }
1434 
1435 void JSBoundFunction::JSBoundFunctionPrint(std::ostream& os) { // NOLINT
1436  JSObjectPrintHeader(os, this, "JSBoundFunction");
1437  os << "\n - bound_target_function: " << Brief(bound_target_function());
1438  os << "\n - bound_this: " << Brief(bound_this());
1439  os << "\n - bound_arguments: " << Brief(bound_arguments());
1440  JSObjectPrintBody(os, this);
1441 }
1442 
1443 void JSFunction::JSFunctionPrint(std::ostream& os) { // NOLINT
1444  Isolate* isolate = GetIsolate();
1445  JSObjectPrintHeader(os, this, "Function");
1446  os << "\n - function prototype: ";
1447  if (has_prototype_slot()) {
1448  if (has_prototype()) {
1449  os << Brief(prototype());
1450  if (map()->has_non_instance_prototype()) {
1451  os << " (non-instance prototype)";
1452  }
1453  }
1454  os << "\n - initial_map: ";
1455  if (has_initial_map()) os << Brief(initial_map());
1456  } else {
1457  os << "<no-prototype-slot>";
1458  }
1459  os << "\n - shared_info: " << Brief(shared());
1460  os << "\n - name: " << Brief(shared()->Name());
1461 
1462  // Print Builtin name for builtin functions
1463  int builtin_index = code()->builtin_index();
1464  if (Builtins::IsBuiltinId(builtin_index) && !IsInterpreted()) {
1465  os << "\n - builtin: " << isolate->builtins()->name(builtin_index);
1466  }
1467 
1468  os << "\n - formal_parameter_count: "
1469  << shared()->internal_formal_parameter_count();
1470  os << "\n - kind: " << shared()->kind();
1471  os << "\n - context: " << Brief(context());
1472  os << "\n - code: " << Brief(code());
1473  if (IsInterpreted()) {
1474  os << "\n - interpreted";
1475  if (shared()->HasBytecodeArray()) {
1476  os << "\n - bytecode: " << shared()->GetBytecodeArray();
1477  }
1478  }
1479  if (WasmExportedFunction::IsWasmExportedFunction(this)) {
1480  WasmExportedFunction* function = WasmExportedFunction::cast(this);
1481  os << "\n - WASM instance "
1482  << reinterpret_cast<void*>(function->instance());
1483  os << "\n - WASM function index " << function->function_index();
1484  }
1485  shared()->PrintSourceCode(os);
1486  JSObjectPrintBody(os, this);
1487  os << "\n - feedback vector: ";
1488  if (!shared()->HasFeedbackMetadata()) {
1489  os << "feedback metadata is not available in SFI\n";
1490  } else if (has_feedback_vector()) {
1491  feedback_vector()->FeedbackVectorPrint(os);
1492  } else {
1493  os << "not available\n";
1494  }
1495 }
1496 
1497 void SharedFunctionInfo::PrintSourceCode(std::ostream& os) {
1498  if (HasSourceCode()) {
1499  os << "\n - source code: ";
1500  String source = String::cast(Script::cast(script())->source());
1501  int start = StartPosition();
1502  int length = EndPosition() - start;
1503  std::unique_ptr<char[]> source_string = source->ToCString(
1504  DISALLOW_NULLS, FAST_STRING_TRAVERSAL, start, length, nullptr);
1505  os << source_string.get();
1506  }
1507 }
1508 
1509 void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) { // NOLINT
1510  HeapObject::PrintHeader(os, "SharedFunctionInfo");
1511  os << "\n - name: ";
1512  if (HasSharedName()) {
1513  os << Brief(Name());
1514  } else {
1515  os << "<no-shared-name>";
1516  }
1517  if (HasInferredName()) {
1518  os << "\n - inferred name: " << Brief(inferred_name());
1519  }
1520  os << "\n - kind: " << kind();
1521  if (needs_home_object()) {
1522  os << "\n - needs_home_object";
1523  }
1524  os << "\n - function_map_index: " << function_map_index();
1525  os << "\n - formal_parameter_count: " << internal_formal_parameter_count();
1526  os << "\n - expected_nof_properties: " << expected_nof_properties();
1527  os << "\n - language_mode: " << language_mode();
1528  os << "\n - data: " << Brief(function_data());
1529  os << "\n - code (from data): " << Brief(GetCode());
1530  PrintSourceCode(os);
1531  // Script files are often large, hard to read.
1532  // os << "\n - script =";
1533  // script()->Print(os);
1534  if (is_named_expression()) {
1535  os << "\n - named expression";
1536  } else if (is_anonymous_expression()) {
1537  os << "\n - anonymous expression";
1538  } else if (is_declaration()) {
1539  os << "\n - declaration";
1540  }
1541  os << "\n - function token position: " << function_token_position();
1542  os << "\n - start position: " << StartPosition();
1543  os << "\n - end position: " << EndPosition();
1544  if (HasDebugInfo()) {
1545  os << "\n - debug info: " << Brief(GetDebugInfo());
1546  } else {
1547  os << "\n - no debug info";
1548  }
1549  os << "\n - scope info: " << Brief(scope_info());
1550  if (HasOuterScopeInfo()) {
1551  os << "\n - outer scope info: " << Brief(GetOuterScopeInfo());
1552  }
1553  os << "\n - length: " << length();
1554  os << "\n - feedback_metadata: ";
1555  if (HasFeedbackMetadata()) {
1556  feedback_metadata()->FeedbackMetadataPrint(os);
1557  } else {
1558  os << "<none>";
1559  }
1560  os << "\n";
1561 }
1562 
1563 void JSGlobalProxy::JSGlobalProxyPrint(std::ostream& os) { // NOLINT
1564  JSObjectPrintHeader(os, this, "JSGlobalProxy");
1565  if (!GetIsolate()->bootstrapper()->IsActive()) {
1566  os << "\n - native context: " << Brief(native_context());
1567  }
1568  JSObjectPrintBody(os, this);
1569 }
1570 
1571 void JSGlobalObject::JSGlobalObjectPrint(std::ostream& os) { // NOLINT
1572  JSObjectPrintHeader(os, this, "JSGlobalObject");
1573  if (!GetIsolate()->bootstrapper()->IsActive()) {
1574  os << "\n - native context: " << Brief(native_context());
1575  }
1576  os << "\n - global proxy: " << Brief(global_proxy());
1577  JSObjectPrintBody(os, this);
1578 }
1579 
1580 void Cell::CellPrint(std::ostream& os) { // NOLINT
1581  HeapObject::PrintHeader(os, "Cell");
1582  os << "\n - value: " << Brief(value());
1583  os << "\n";
1584 }
1585 
1586 void PropertyCell::PropertyCellPrint(std::ostream& os) { // NOLINT
1587  HeapObject::PrintHeader(os, "PropertyCell");
1588  os << "\n - name: ";
1589  name()->NamePrint(os);
1590  os << "\n - value: " << Brief(value());
1591  os << "\n - details: ";
1592  property_details().PrintAsSlowTo(os);
1593  PropertyCellType cell_type = property_details().cell_type();
1594  os << "\n - cell_type: ";
1595  if (value()->IsTheHole()) {
1596  switch (cell_type) {
1597  case PropertyCellType::kUninitialized:
1598  os << "Uninitialized";
1599  break;
1600  case PropertyCellType::kInvalidated:
1601  os << "Invalidated";
1602  break;
1603  default:
1604  os << "??? " << static_cast<int>(cell_type);
1605  break;
1606  }
1607  } else {
1608  switch (cell_type) {
1609  case PropertyCellType::kUndefined:
1610  os << "Undefined";
1611  break;
1612  case PropertyCellType::kConstant:
1613  os << "Constant";
1614  break;
1615  case PropertyCellType::kConstantType:
1616  os << "ConstantType"
1617  << " (";
1618  switch (GetConstantType()) {
1619  case PropertyCellConstantType::kSmi:
1620  os << "Smi";
1621  break;
1622  case PropertyCellConstantType::kStableMap:
1623  os << "StableMap";
1624  break;
1625  }
1626  os << ")";
1627  break;
1628  case PropertyCellType::kMutable:
1629  os << "Mutable";
1630  break;
1631  }
1632  }
1633  os << "\n";
1634 }
1635 
1636 void Code::CodePrint(std::ostream& os) { // NOLINT
1637  PrintHeader(os, "Code");
1638  os << "\n";
1639 #ifdef ENABLE_DISASSEMBLER
1640  if (FLAG_use_verbose_printer) {
1641  Disassemble(nullptr, os);
1642  }
1643 #endif
1644 }
1645 
1646 void CodeDataContainer::CodeDataContainerPrint(std::ostream& os) { // NOLINT
1647  HeapObject::PrintHeader(os, "CodeDataContainer");
1648  os << "\n - kind_specific_flags: " << kind_specific_flags();
1649  os << "\n";
1650 }
1651 
1652 void Foreign::ForeignPrint(std::ostream& os) { // NOLINT
1653  os << "foreign address : " << reinterpret_cast<void*>(foreign_address());
1654  os << "\n";
1655 }
1656 
1657 
1658 void AccessorInfo::AccessorInfoPrint(std::ostream& os) { // NOLINT
1659  HeapObject::PrintHeader(os, "AccessorInfo");
1660  os << "\n - name: " << Brief(name());
1661  os << "\n - flags: " << flags();
1662  os << "\n - getter: " << Brief(getter());
1663  os << "\n - setter: " << Brief(setter());
1664  os << "\n - js_getter: " << Brief(js_getter());
1665  os << "\n - data: " << Brief(data());
1666  os << "\n";
1667 }
1668 
1669 void CallbackTask::CallbackTaskPrint(std::ostream& os) { // NOLINT
1670  HeapObject::PrintHeader(os, "CallbackTask");
1671  os << "\n - callback: " << Brief(callback());
1672  os << "\n - data: " << Brief(data());
1673  os << "\n";
1674 }
1675 
1676 void CallableTask::CallableTaskPrint(std::ostream& os) { // NOLINT
1677  HeapObject::PrintHeader(os, "CallableTask");
1678  os << "\n - context: " << Brief(context());
1679  os << "\n - callable: " << Brief(callable());
1680  os << "\n";
1681 }
1682 
1683 void PromiseFulfillReactionJobTask::PromiseFulfillReactionJobTaskPrint(
1684  std::ostream& os) { // NOLINT
1685  HeapObject::PrintHeader(os, "PromiseFulfillReactionJobTask");
1686  os << "\n - argument: " << Brief(argument());
1687  os << "\n - context: " << Brief(context());
1688  os << "\n - handler: " << Brief(handler());
1689  os << "\n - promise_or_capability: " << Brief(promise_or_capability());
1690  os << "\n";
1691 }
1692 
1693 void PromiseRejectReactionJobTask::PromiseRejectReactionJobTaskPrint(
1694  std::ostream& os) { // NOLINT
1695  HeapObject::PrintHeader(os, "PromiseRejectReactionJobTask");
1696  os << "\n - argument: " << Brief(argument());
1697  os << "\n - context: " << Brief(context());
1698  os << "\n - handler: " << Brief(handler());
1699  os << "\n - promise_or_capability: " << Brief(promise_or_capability());
1700  os << "\n";
1701 }
1702 
1703 void PromiseResolveThenableJobTask::PromiseResolveThenableJobTaskPrint(
1704  std::ostream& os) { // NOLINT
1705  HeapObject::PrintHeader(os, "PromiseResolveThenableJobTask");
1706  os << "\n - context: " << Brief(context());
1707  os << "\n - promise_to_resolve: " << Brief(promise_to_resolve());
1708  os << "\n - then: " << Brief(then());
1709  os << "\n - thenable: " << Brief(thenable());
1710  os << "\n";
1711 }
1712 
1713 void PromiseCapability::PromiseCapabilityPrint(std::ostream& os) { // NOLINT
1714  HeapObject::PrintHeader(os, "PromiseCapability");
1715  os << "\n - promise: " << Brief(promise());
1716  os << "\n - resolve: " << Brief(resolve());
1717  os << "\n - reject: " << Brief(reject());
1718  os << "\n";
1719 }
1720 
1721 void PromiseReaction::PromiseReactionPrint(std::ostream& os) { // NOLINT
1722  HeapObject::PrintHeader(os, "PromiseReaction");
1723  os << "\n - next: " << Brief(next());
1724  os << "\n - reject_handler: " << Brief(reject_handler());
1725  os << "\n - fulfill_handler: " << Brief(fulfill_handler());
1726  os << "\n - promise_or_capability: " << Brief(promise_or_capability());
1727  os << "\n";
1728 }
1729 
1730 void AsyncGeneratorRequest::AsyncGeneratorRequestPrint(
1731  std::ostream& os) { // NOLINT
1732  HeapObject::PrintHeader(os, "AsyncGeneratorRequest");
1733  const char* mode = "Invalid!";
1734  switch (resume_mode()) {
1735  case JSGeneratorObject::kNext:
1736  mode = ".next()";
1737  break;
1738  case JSGeneratorObject::kReturn:
1739  mode = ".return()";
1740  break;
1741  case JSGeneratorObject::kThrow:
1742  mode = ".throw()";
1743  break;
1744  }
1745  os << "\n - resume mode: " << mode;
1746  os << "\n - value: " << Brief(value());
1747  os << "\n - next: " << Brief(next());
1748  os << "\n";
1749 }
1750 
1751 void ModuleInfoEntry::ModuleInfoEntryPrint(std::ostream& os) { // NOLINT
1752  HeapObject::PrintHeader(os, "ModuleInfoEntry");
1753  os << "\n - export_name: " << Brief(export_name());
1754  os << "\n - local_name: " << Brief(local_name());
1755  os << "\n - import_name: " << Brief(import_name());
1756  os << "\n - module_request: " << module_request();
1757  os << "\n - cell_index: " << cell_index();
1758  os << "\n - beg_pos: " << beg_pos();
1759  os << "\n - end_pos: " << end_pos();
1760  os << "\n";
1761 }
1762 
1763 void Module::ModulePrint(std::ostream& os) { // NOLINT
1764  HeapObject::PrintHeader(os, "Module");
1765  os << "\n - origin: " << Brief(script()->GetNameOrSourceURL());
1766  os << "\n - code: " << Brief(code());
1767  os << "\n - exports: " << Brief(exports());
1768  os << "\n - requested_modules: " << Brief(requested_modules());
1769  os << "\n - script: " << Brief(script());
1770  os << "\n - import_meta: " << Brief(import_meta());
1771  os << "\n - status: " << status();
1772  os << "\n - exception: " << Brief(exception());
1773  os << "\n";
1774 }
1775 
1776 void JSModuleNamespace::JSModuleNamespacePrint(std::ostream& os) { // NOLINT
1777  JSObjectPrintHeader(os, this, "JSModuleNamespace");
1778  os << "\n - module: " << Brief(module());
1779  JSObjectPrintBody(os, this);
1780 }
1781 
1782 void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) { // NOLINT
1783  HeapObject::PrintHeader(os, "PrototypeInfo");
1784  os << "\n - module namespace: " << Brief(module_namespace());
1785  os << "\n - prototype users: " << Brief(prototype_users());
1786  os << "\n - registry slot: " << registry_slot();
1787  os << "\n - object create map: " << Brief(object_create_map());
1788  os << "\n - should_be_fast_map: " << should_be_fast_map();
1789  os << "\n";
1790 }
1791 
1792 void Tuple2::Tuple2Print(std::ostream& os) { // NOLINT
1793  HeapObject::PrintHeader(os, "Tuple2");
1794  os << "\n - value1: " << Brief(value1());
1795  os << "\n - value2: " << Brief(value2());
1796  os << "\n";
1797 }
1798 
1799 void Tuple3::Tuple3Print(std::ostream& os) { // NOLINT
1800  HeapObject::PrintHeader(os, "Tuple3");
1801  os << "\n - value1: " << Brief(value1());
1802  os << "\n - value2: " << Brief(value2());
1803  os << "\n - value3: " << Brief(value3());
1804  os << "\n";
1805 }
1806 
1807 void ArrayBoilerplateDescription::ArrayBoilerplateDescriptionPrint(
1808  std::ostream& os) { // NOLINT
1809  HeapObject::PrintHeader(os, "ArrayBoilerplateDescription");
1810  os << "\n - elements kind: " << elements_kind();
1811  os << "\n - constant elements: " << Brief(constant_elements());
1812  os << "\n";
1813 }
1814 
1815 void AsmWasmData::AsmWasmDataPrint(std::ostream& os) { // NOLINT
1816  HeapObject::PrintHeader(os, "AsmWasmData");
1817  os << "\n - native module: " << Brief(managed_native_module());
1818  os << "\n - export_wrappers: " << Brief(export_wrappers());
1819  os << "\n - offset table: " << Brief(asm_js_offset_table());
1820  os << "\n - uses bitset: " << uses_bitset()->value();
1821  os << "\n";
1822 }
1823 
1824 void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT
1825  HeapObject::PrintHeader(os, "WasmDebugInfo");
1826  os << "\n - wasm_instance: " << Brief(wasm_instance());
1827  os << "\n";
1828 }
1829 
1830 void WasmInstanceObject::WasmInstanceObjectPrint(std::ostream& os) { // NOLINT
1831  HeapObject::PrintHeader(os, "WasmInstanceObject");
1832  os << "\n - module_object: " << Brief(module_object());
1833  os << "\n - exports_object: " << Brief(exports_object());
1834  os << "\n - native_context: " << Brief(native_context());
1835  if (has_memory_object()) {
1836  os << "\n - memory_object: " << Brief(memory_object());
1837  }
1838  if (has_globals_buffer()) {
1839  os << "\n - globals_buffer: " << Brief(globals_buffer());
1840  }
1841  if (has_imported_mutable_globals_buffers()) {
1842  os << "\n - imported_mutable_globals_buffers: "
1843  << Brief(imported_mutable_globals_buffers());
1844  }
1845  if (has_debug_info()) {
1846  os << "\n - debug_info: " << Brief(debug_info());
1847  }
1848  if (has_table_object()) {
1849  os << "\n - table_object: " << Brief(table_object());
1850  }
1851  os << "\n - imported_function_refs: " << Brief(imported_function_refs());
1852  if (has_indirect_function_table_refs()) {
1853  os << "\n - indirect_function_table_refs: "
1854  << Brief(indirect_function_table_refs());
1855  }
1856  if (has_managed_native_allocations()) {
1857  os << "\n - managed_native_allocations: "
1858  << Brief(managed_native_allocations());
1859  }
1860  os << "\n - memory_start: " << static_cast<void*>(memory_start());
1861  os << "\n - memory_size: " << memory_size();
1862  os << "\n - memory_mask: " << AsHex(memory_mask());
1863  os << "\n - imported_function_targets: "
1864  << static_cast<void*>(imported_function_targets());
1865  os << "\n - globals_start: " << static_cast<void*>(globals_start());
1866  os << "\n - imported_mutable_globals: "
1867  << static_cast<void*>(imported_mutable_globals());
1868  os << "\n - indirect_function_table_size: " << indirect_function_table_size();
1869  os << "\n - indirect_function_table_sig_ids: "
1870  << static_cast<void*>(indirect_function_table_sig_ids());
1871  os << "\n - indirect_function_table_targets: "
1872  << static_cast<void*>(indirect_function_table_targets());
1873  os << "\n";
1874 }
1875 
1876 void WasmExportedFunctionData::WasmExportedFunctionDataPrint(
1877  std::ostream& os) { // NOLINT
1878  HeapObject::PrintHeader(os, "WasmExportedFunctionData");
1879  os << "\n - wrapper_code: " << Brief(wrapper_code());
1880  os << "\n - instance: " << Brief(instance());
1881  os << "\n - function_index: " << function_index();
1882  os << "\n";
1883 }
1884 
1885 void WasmModuleObject::WasmModuleObjectPrint(std::ostream& os) { // NOLINT
1886  HeapObject::PrintHeader(os, "WasmModuleObject");
1887  os << "\n - module: " << module();
1888  os << "\n - native module: " << native_module();
1889  os << "\n - export wrappers: " << Brief(export_wrappers());
1890  os << "\n - script: " << Brief(script());
1891  if (has_asm_js_offset_table()) {
1892  os << "\n - asm_js_offset_table: " << Brief(asm_js_offset_table());
1893  }
1894  if (has_breakpoint_infos()) {
1895  os << "\n - breakpoint_infos: " << Brief(breakpoint_infos());
1896  }
1897  os << "\n";
1898 }
1899 
1900 void LoadHandler::LoadHandlerPrint(std::ostream& os) { // NOLINT
1901  HeapObject::PrintHeader(os, "LoadHandler");
1902  // TODO(ishell): implement printing based on handler kind
1903  os << "\n - handler: " << Brief(smi_handler());
1904  os << "\n - validity_cell: " << Brief(validity_cell());
1905  int data_count = data_field_count();
1906  if (data_count >= 1) {
1907  os << "\n - data1: " << Brief(data1());
1908  }
1909  if (data_count >= 2) {
1910  os << "\n - data2: " << Brief(data2());
1911  }
1912  if (data_count >= 3) {
1913  os << "\n - data3: " << Brief(data3());
1914  }
1915  os << "\n";
1916 }
1917 
1918 void StoreHandler::StoreHandlerPrint(std::ostream& os) { // NOLINT
1919  HeapObject::PrintHeader(os, "StoreHandler");
1920  // TODO(ishell): implement printing based on handler kind
1921  os << "\n - handler: " << Brief(smi_handler());
1922  os << "\n - validity_cell: " << Brief(validity_cell());
1923  int data_count = data_field_count();
1924  if (data_count >= 1) {
1925  os << "\n - data1: " << Brief(data1());
1926  }
1927  if (data_count >= 2) {
1928  os << "\n - data2: " << Brief(data2());
1929  }
1930  if (data_count >= 3) {
1931  os << "\n - data3: " << Brief(data3());
1932  }
1933  os << "\n";
1934 }
1935 
1936 void AccessorPair::AccessorPairPrint(std::ostream& os) { // NOLINT
1937  HeapObject::PrintHeader(os, "AccessorPair");
1938  os << "\n - getter: " << Brief(getter());
1939  os << "\n - setter: " << Brief(setter());
1940  os << "\n";
1941 }
1942 
1943 
1944 void AccessCheckInfo::AccessCheckInfoPrint(std::ostream& os) { // NOLINT
1945  HeapObject::PrintHeader(os, "AccessCheckInfo");
1946  os << "\n - callback: " << Brief(callback());
1947  os << "\n - named_interceptor: " << Brief(named_interceptor());
1948  os << "\n - indexed_interceptor: " << Brief(indexed_interceptor());
1949  os << "\n - data: " << Brief(data());
1950  os << "\n";
1951 }
1952 
1953 void CallHandlerInfo::CallHandlerInfoPrint(std::ostream& os) { // NOLINT
1954  HeapObject::PrintHeader(os, "CallHandlerInfo");
1955  os << "\n - callback: " << Brief(callback());
1956  os << "\n - js_callback: " << Brief(js_callback());
1957  os << "\n - data: " << Brief(data());
1958  os << "\n - side_effect_free: "
1959  << (IsSideEffectFreeCallHandlerInfo() ? "true" : "false");
1960  os << "\n";
1961 }
1962 
1963 void InterceptorInfo::InterceptorInfoPrint(std::ostream& os) { // NOLINT
1964  HeapObject::PrintHeader(os, "InterceptorInfo");
1965  os << "\n - getter: " << Brief(getter());
1966  os << "\n - setter: " << Brief(setter());
1967  os << "\n - query: " << Brief(query());
1968  os << "\n - deleter: " << Brief(deleter());
1969  os << "\n - enumerator: " << Brief(enumerator());
1970  os << "\n - data: " << Brief(data());
1971  os << "\n";
1972 }
1973 
1974 
1975 void FunctionTemplateInfo::FunctionTemplateInfoPrint(
1976  std::ostream& os) { // NOLINT
1977  HeapObject::PrintHeader(os, "FunctionTemplateInfo");
1978  os << "\n - class name: " << Brief(class_name());
1979  os << "\n - tag: " << Brief(tag());
1980  os << "\n - serial_number: " << Brief(serial_number());
1981  os << "\n - property_list: " << Brief(property_list());
1982  os << "\n - call_code: " << Brief(call_code());
1983  os << "\n - property_accessors: " << Brief(property_accessors());
1984  os << "\n - signature: " << Brief(signature());
1985  os << "\n - cached_property_name: " << Brief(cached_property_name());
1986  os << "\n - hidden_prototype: " << (hidden_prototype() ? "true" : "false");
1987  os << "\n - undetectable: " << (undetectable() ? "true" : "false");
1988  os << "\n - need_access_check: " << (needs_access_check() ? "true" : "false");
1989  os << "\n - instantiated: " << (instantiated() ? "true" : "false");
1990  os << "\n - rare_data: " << Brief(rare_data());
1991  os << "\n";
1992 }
1993 
1994 void FunctionTemplateRareData::FunctionTemplateRareDataPrint(
1995  std::ostream& os) { // NOLINT
1996  HeapObject::PrintHeader(os, "FunctionTemplateRareData");
1997  os << "\n - prototype_template: " << Brief(prototype_template());
1998  os << "\n - prototype_provider_template: "
1999  << Brief(prototype_provider_template());
2000  os << "\n - parent_template: " << Brief(parent_template());
2001  os << "\n - named_property_handler: " << Brief(named_property_handler());
2002  os << "\n - indexed_property_handler: " << Brief(indexed_property_handler());
2003  os << "\n - instance_template: " << Brief(instance_template());
2004  os << "\n - instance_call_handler: " << Brief(instance_call_handler());
2005  os << "\n - access_check_info: " << Brief(access_check_info());
2006  os << "\n";
2007 }
2008 
2009 void ObjectTemplateInfo::ObjectTemplateInfoPrint(std::ostream& os) { // NOLINT
2010  HeapObject::PrintHeader(os, "ObjectTemplateInfo");
2011  os << "\n - tag: " << Brief(tag());
2012  os << "\n - serial_number: " << Brief(serial_number());
2013  os << "\n - property_list: " << Brief(property_list());
2014  os << "\n - property_accessors: " << Brief(property_accessors());
2015  os << "\n - constructor: " << Brief(constructor());
2016  os << "\n - embedder_field_count: " << embedder_field_count();
2017  os << "\n - immutable_proto: " << (immutable_proto() ? "true" : "false");
2018  os << "\n";
2019 }
2020 
2021 
2022 void AllocationSite::AllocationSitePrint(std::ostream& os) { // NOLINT
2023  HeapObject::PrintHeader(os, "AllocationSite");
2024  if (this->HasWeakNext()) os << "\n - weak_next: " << Brief(weak_next());
2025  os << "\n - dependent code: " << Brief(dependent_code());
2026  os << "\n - nested site: " << Brief(nested_site());
2027  os << "\n - memento found count: "
2028  << Brief(Smi::FromInt(memento_found_count()));
2029  os << "\n - memento create count: "
2030  << Brief(Smi::FromInt(memento_create_count()));
2031  os << "\n - pretenure decision: "
2032  << Brief(Smi::FromInt(pretenure_decision()));
2033  os << "\n - transition_info: ";
2034  if (!PointsToLiteral()) {
2035  ElementsKind kind = GetElementsKind();
2036  os << "Array allocation with ElementsKind " << ElementsKindToString(kind);
2037  } else if (boilerplate()->IsJSArray()) {
2038  os << "Array literal with boilerplate " << Brief(boilerplate());
2039  } else {
2040  os << "Object literal with boilerplate " << Brief(boilerplate());
2041  }
2042  os << "\n";
2043 }
2044 
2045 
2046 void AllocationMemento::AllocationMementoPrint(std::ostream& os) { // NOLINT
2047  HeapObject::PrintHeader(os, "AllocationMemento");
2048  os << "\n - allocation site: ";
2049  if (IsValid()) {
2050  GetAllocationSite()->AllocationSitePrint(os);
2051  } else {
2052  os << "<invalid>\n";
2053  }
2054 }
2055 
2056 
2057 void Script::ScriptPrint(std::ostream& os) { // NOLINT
2058  HeapObject::PrintHeader(os, "Script");
2059  os << "\n - source: " << Brief(source());
2060  os << "\n - name: " << Brief(name());
2061  os << "\n - line_offset: " << line_offset();
2062  os << "\n - column_offset: " << column_offset();
2063  os << "\n - type: " << type();
2064  os << "\n - id: " << id();
2065  os << "\n - context data: " << Brief(context_data());
2066  os << "\n - compilation type: " << compilation_type();
2067  os << "\n - line ends: " << Brief(line_ends());
2068  if (has_eval_from_shared()) {
2069  os << "\n - eval from shared: " << Brief(eval_from_shared());
2070  }
2071  if (is_wrapped()) {
2072  os << "\n - wrapped arguments: " << Brief(wrapped_arguments());
2073  }
2074  os << "\n - eval from position: " << eval_from_position();
2075  os << "\n - shared function infos: " << Brief(shared_function_infos());
2076  os << "\n";
2077 }
2078 
2079 #ifdef V8_INTL_SUPPORT
2080 void JSV8BreakIterator::JSV8BreakIteratorPrint(std::ostream& os) { // NOLINT
2081  JSObjectPrintHeader(os, this, "JSV8BreakIterator");
2082  os << "\n - locale: " << Brief(locale());
2083  os << "\n - type: " << TypeAsString();
2084  os << "\n - break iterator: " << Brief(break_iterator());
2085  os << "\n - unicode string: " << Brief(unicode_string());
2086  os << "\n - bound adopt text: " << Brief(bound_adopt_text());
2087  os << "\n - bound first: " << Brief(bound_first());
2088  os << "\n - bound next: " << Brief(bound_next());
2089  os << "\n - bound current: " << Brief(bound_current());
2090  os << "\n - bound break type: " << Brief(bound_break_type());
2091  os << "\n";
2092 }
2093 
2094 void JSCollator::JSCollatorPrint(std::ostream& os) { // NOLINT
2095  JSObjectPrintHeader(os, this, "JSCollator");
2096  os << "\n - icu collator: " << Brief(icu_collator());
2097  os << "\n - bound compare: " << Brief(bound_compare());
2098  JSObjectPrintBody(os, this);
2099 }
2100 
2101 void JSDateTimeFormat::JSDateTimeFormatPrint(std::ostream& os) { // NOLINT
2102  JSObjectPrintHeader(os, this, "JSDateTimeFormat");
2103  os << "\n - icu locale: " << Brief(icu_locale());
2104  os << "\n - icu simple date format: " << Brief(icu_simple_date_format());
2105  os << "\n - bound format: " << Brief(bound_format());
2106  JSObjectPrintBody(os, this);
2107 }
2108 
2109 void JSListFormat::JSListFormatPrint(std::ostream& os) { // NOLINT
2110  JSObjectPrintHeader(os, this, "JSListFormat");
2111  os << "\n - locale: " << Brief(locale());
2112  os << "\n - style: " << StyleAsString();
2113  os << "\n - type: " << TypeAsString();
2114  os << "\n - icu formatter: " << Brief(icu_formatter());
2115  JSObjectPrintBody(os, this);
2116 }
2117 
2118 void JSLocale::JSLocalePrint(std::ostream& os) { // NOLINT
2119  JSObjectPrintHeader(os, this, "JSLocale");
2120  os << "\n - language: " << Brief(language());
2121  os << "\n - script: " << Brief(script());
2122  os << "\n - region: " << Brief(region());
2123  os << "\n - baseName: " << Brief(base_name());
2124  os << "\n - locale: " << Brief(locale());
2125  os << "\n - calendar: " << Brief(calendar());
2126  os << "\n - caseFirst: " << CaseFirstAsString();
2127  os << "\n - collation: " << Brief(collation());
2128  os << "\n - hourCycle: " << HourCycleAsString();
2129  os << "\n - numeric: " << NumericAsString();
2130  os << "\n - numberingSystem: " << Brief(numbering_system());
2131  os << "\n";
2132 }
2133 
2134 void JSNumberFormat::JSNumberFormatPrint(std::ostream& os) { // NOLINT
2135  JSObjectPrintHeader(os, this, "JSNumberFormat");
2136  os << "\n - locale: " << Brief(locale());
2137  os << "\n - icu_number_format: " << Brief(icu_number_format());
2138  os << "\n - bound_format: " << Brief(bound_format());
2139  os << "\n - style: " << StyleAsString();
2140  os << "\n - currency_display: " << CurrencyDisplayAsString();
2141  JSObjectPrintBody(os, this);
2142 }
2143 
2144 void JSPluralRules::JSPluralRulesPrint(std::ostream& os) { // NOLINT
2145  JSObjectPrintHeader(os, this, "JSPluralRules");
2146  os << "\n - locale: " << Brief(locale());
2147  os << "\n - type: " << TypeAsString();
2148  os << "\n - icu plural rules: " << Brief(icu_plural_rules());
2149  os << "\n - icu decimal format: " << Brief(icu_decimal_format());
2150  JSObjectPrintBody(os, this);
2151 }
2152 
2153 void JSRelativeTimeFormat::JSRelativeTimeFormatPrint(
2154  std::ostream& os) { // NOLINT
2155  JSObjectPrintHeader(os, this, "JSRelativeTimeFormat");
2156  os << "\n - locale: " << Brief(locale());
2157  os << "\n - style: " << StyleAsString();
2158  os << "\n - numeric: " << NumericAsString();
2159  os << "\n - icu formatter: " << Brief(icu_formatter());
2160  os << "\n";
2161 }
2162 
2163 void JSSegmentIterator::JSSegmentIteratorPrint(std::ostream& os) { // NOLINT
2164  JSObjectPrintHeader(os, this, "JSSegmentIterator");
2165  os << "\n - icu break iterator: " << Brief(icu_break_iterator());
2166  os << "\n - unicode string: " << Brief(unicode_string());
2167  os << "\n - granularity: " << GranularityAsString();
2168  os << "\n";
2169 }
2170 
2171 void JSSegmenter::JSSegmenterPrint(std::ostream& os) { // NOLINT
2172  JSObjectPrintHeader(os, this, "JSSegmenter");
2173  os << "\n - locale: " << Brief(locale());
2174  os << "\n - granularity: " << GranularityAsString();
2175  os << "\n - lineBreakStyle: " << LineBreakStyleAsString();
2176  os << "\n - icu break iterator: " << Brief(icu_break_iterator());
2177  JSObjectPrintBody(os, this);
2178 }
2179 #endif // V8_INTL_SUPPORT
2180 
2181 namespace {
2182 void PrintScopeInfoList(ScopeInfo scope_info, std::ostream& os,
2183  const char* list_name, int nof_internal_slots,
2184  int start, int length) {
2185  if (length <= 0) return;
2186  int end = start + length;
2187  os << "\n - " << list_name;
2188  if (nof_internal_slots > 0) {
2189  os << " " << start << "-" << end << " [internal slots]";
2190  }
2191  os << " {\n";
2192  for (int i = nof_internal_slots; start < end; ++i, ++start) {
2193  os << " - " << i << ": ";
2194  String::cast(scope_info->get(start))->ShortPrint(os);
2195  os << "\n";
2196  }
2197  os << " }";
2198 }
2199 } // namespace
2200 
2201 void ScopeInfo::ScopeInfoPrint(std::ostream& os) { // NOLINT
2202  PrintHeader(os, "ScopeInfo");
2203  if (length() == 0) {
2204  os << "\n - length = 0\n";
2205  return;
2206  }
2207  int flags = Flags();
2208 
2209  os << "\n - parameters: " << ParameterCount();
2210  os << "\n - context locals : " << ContextLocalCount();
2211 
2212  os << "\n - scope type: " << scope_type();
2213  if (CallsSloppyEval()) os << "\n - sloppy eval";
2214  os << "\n - language mode: " << language_mode();
2215  if (is_declaration_scope()) os << "\n - declaration scope";
2216  if (HasReceiver()) {
2217  os << "\n - receiver: " << ReceiverVariableField::decode(flags);
2218  }
2219  if (HasNewTarget()) os << "\n - needs new target";
2220  if (HasFunctionName()) {
2221  os << "\n - function name(" << FunctionVariableField::decode(flags)
2222  << "): ";
2223  FunctionName()->ShortPrint(os);
2224  }
2225  if (IsAsmModule()) os << "\n - asm module";
2226  if (HasSimpleParameters()) os << "\n - simple parameters";
2227  os << "\n - function kind: " << function_kind();
2228  if (HasOuterScopeInfo()) {
2229  os << "\n - outer scope info: " << Brief(OuterScopeInfo());
2230  }
2231  if (HasFunctionName()) {
2232  os << "\n - function name: " << Brief(FunctionName());
2233  }
2234  if (HasInferredFunctionName()) {
2235  os << "\n - inferred function name: " << Brief(InferredFunctionName());
2236  }
2237 
2238  if (HasPositionInfo()) {
2239  os << "\n - start position: " << StartPosition();
2240  os << "\n - end position: " << EndPosition();
2241  }
2242  os << "\n - length: " << length();
2243  if (length() > 0) {
2244  PrintScopeInfoList(*this, os, "context slots", Context::MIN_CONTEXT_SLOTS,
2245  ContextLocalNamesIndex(), ContextLocalCount());
2246  // TODO(neis): Print module stuff if present.
2247  }
2248  os << "\n";
2249 }
2250 
2251 void DebugInfo::DebugInfoPrint(std::ostream& os) { // NOLINT
2252  HeapObject::PrintHeader(os, "DebugInfo");
2253  os << "\n - flags: " << flags();
2254  os << "\n - debugger_hints: " << debugger_hints();
2255  os << "\n - shared: " << Brief(shared());
2256  os << "\n - script: " << Brief(script());
2257  os << "\n - original bytecode array: " << Brief(original_bytecode_array());
2258  os << "\n - debug bytecode array: " << Brief(debug_bytecode_array());
2259  os << "\n - break_points: ";
2260  break_points()->FixedArrayPrint(os);
2261  os << "\n - coverage_info: " << Brief(coverage_info());
2262 }
2263 
2264 
2265 void StackFrameInfo::StackFrameInfoPrint(std::ostream& os) { // NOLINT
2266  HeapObject::PrintHeader(os, "StackFrame");
2267  os << "\n - line_number: " << line_number();
2268  os << "\n - column_number: " << column_number();
2269  os << "\n - script_id: " << script_id();
2270  os << "\n - script_name: " << Brief(script_name());
2271  os << "\n - script_name_or_source_url: "
2272  << Brief(script_name_or_source_url());
2273  os << "\n - function_name: " << Brief(function_name());
2274  os << "\n - is_eval: " << (is_eval() ? "true" : "false");
2275  os << "\n - is_constructor: " << (is_constructor() ? "true" : "false");
2276  os << "\n";
2277 }
2278 
2279 static void PrintBitMask(std::ostream& os, uint32_t value) { // NOLINT
2280  for (int i = 0; i < 32; i++) {
2281  if ((i & 7) == 0) os << " ";
2282  os << (((value & 1) == 0) ? "_" : "x");
2283  value >>= 1;
2284  }
2285 }
2286 
2287 void LayoutDescriptor::Print() {
2288  StdoutStream os;
2289  this->Print(os);
2290  os << std::flush;
2291 }
2292 
2293 void LayoutDescriptor::ShortPrint(std::ostream& os) {
2294  if (IsSmi()) {
2295  // Print tagged value for easy use with "jld" gdb macro.
2296  os << reinterpret_cast<void*>(ptr());
2297  } else {
2298  os << Brief(*this);
2299  }
2300 }
2301 
2302 void LayoutDescriptor::Print(std::ostream& os) { // NOLINT
2303  os << "Layout descriptor: ";
2304  if (IsFastPointerLayout()) {
2305  os << "<all tagged>";
2306  } else if (IsSmi()) {
2307  os << "fast";
2308  PrintBitMask(os, static_cast<uint32_t>(Smi::ToInt(*this)));
2309  } else if (IsOddball() && IsUninitialized()) {
2310  os << "<uninitialized>";
2311  } else {
2312  os << "slow";
2313  int num_words = number_of_layout_words();
2314  for (int i = 0; i < num_words; i++) {
2315  if (i > 0) os << " |";
2316  PrintBitMask(os, get_layout_word(i));
2317  }
2318  }
2319  os << "\n";
2320 }
2321 
2322 void PreParsedScopeData::PreParsedScopeDataPrint(std::ostream& os) { // NOLINT
2323  HeapObject::PrintHeader(os, "PreParsedScopeData");
2324  os << "\n - scope_data: " << Brief(scope_data());
2325  os << "\n - length: " << length();
2326  for (int i = 0; i < length(); ++i) {
2327  os << "\n - [" << i << "]: " << Brief(child_data(i));
2328  }
2329  os << "\n";
2330 }
2331 
2332 void UncompiledDataWithoutPreParsedScope::
2333  UncompiledDataWithoutPreParsedScopePrint(std::ostream& os) { // NOLINT
2334  HeapObject::PrintHeader(os, "UncompiledDataWithoutPreParsedScope");
2335  os << "\n - start position: " << start_position();
2336  os << "\n - end position: " << end_position();
2337  os << "\n";
2338 }
2339 
2340 void UncompiledDataWithPreParsedScope::UncompiledDataWithPreParsedScopePrint(
2341  std::ostream& os) { // NOLINT
2342  HeapObject::PrintHeader(os, "UncompiledDataWithPreParsedScope");
2343  os << "\n - start position: " << start_position();
2344  os << "\n - end position: " << end_position();
2345  os << "\n - pre_parsed_scope_data: " << Brief(pre_parsed_scope_data());
2346  os << "\n";
2347 }
2348 
2349 void InterpreterData::InterpreterDataPrint(std::ostream& os) { // NOLINT
2350  HeapObject::PrintHeader(os, "InterpreterData");
2351  os << "\n - bytecode_array: " << Brief(bytecode_array());
2352  os << "\n - interpreter_trampoline: " << Brief(interpreter_trampoline());
2353  os << "\n";
2354 }
2355 
2356 void MaybeObject::Print() {
2357  StdoutStream os;
2358  this->Print(os);
2359  os << std::flush;
2360 }
2361 
2362 void MaybeObject::Print(std::ostream& os) {
2363  Smi smi;
2364  HeapObject* heap_object;
2365  if (ToSmi(&smi)) {
2366  smi->SmiPrint(os);
2367  } else if (IsCleared()) {
2368  os << "[cleared]";
2369  } else if (GetHeapObjectIfWeak(&heap_object)) {
2370  os << "[weak] ";
2371  heap_object->HeapObjectPrint(os);
2372  } else if (GetHeapObjectIfStrong(&heap_object)) {
2373  heap_object->HeapObjectPrint(os);
2374  } else {
2375  UNREACHABLE();
2376  }
2377 }
2378 
2379 #endif // OBJECT_PRINT
2380 
2381 void HeapNumber::HeapNumberPrint(std::ostream& os) { os << value(); }
2382 
2383 void MutableHeapNumber::MutableHeapNumberPrint(std::ostream& os) {
2384  os << value();
2385 }
2386 
2387 // TODO(cbruni): remove once the new maptracer is in place.
2388 void Name::NameShortPrint() {
2389  if (this->IsString()) {
2390  PrintF("%s", String::cast(*this)->ToCString().get());
2391  } else {
2392  DCHECK(this->IsSymbol());
2393  Symbol s = Symbol::cast(*this);
2394  if (s->name()->IsUndefined()) {
2395  PrintF("#<%s>", s->PrivateSymbolToName());
2396  } else {
2397  PrintF("<%s>", String::cast(s->name())->ToCString().get());
2398  }
2399  }
2400 }
2401 
2402 // TODO(cbruni): remove once the new maptracer is in place.
2403 int Name::NameShortPrint(Vector<char> str) {
2404  if (this->IsString()) {
2405  return SNPrintF(str, "%s", String::cast(*this)->ToCString().get());
2406  } else {
2407  DCHECK(this->IsSymbol());
2408  Symbol s = Symbol::cast(*this);
2409  if (s->name()->IsUndefined()) {
2410  return SNPrintF(str, "#<%s>", s->PrivateSymbolToName());
2411  } else {
2412  return SNPrintF(str, "<%s>", String::cast(s->name())->ToCString().get());
2413  }
2414  }
2415 }
2416 
2417 void Map::PrintMapDetails(std::ostream& os) {
2418  DisallowHeapAllocation no_gc;
2419 #ifdef OBJECT_PRINT
2420  this->MapPrint(os);
2421 #else
2422  os << "Map=" << reinterpret_cast<void*>(ptr());
2423 #endif
2424  os << "\n";
2425  instance_descriptors()->PrintDescriptors(os);
2426 }
2427 
2428 void DescriptorArray::PrintDescriptors(std::ostream& os) {
2429  for (int i = 0; i < number_of_descriptors(); i++) {
2430  Name key = GetKey(i);
2431  os << "\n [" << i << "]: ";
2432 #ifdef OBJECT_PRINT
2433  key->NamePrint(os);
2434 #else
2435  key->ShortPrint(os);
2436 #endif
2437  os << " ";
2438  PrintDescriptorDetails(os, i, PropertyDetails::kPrintFull);
2439  }
2440  os << "\n";
2441 }
2442 
2443 void DescriptorArray::PrintDescriptorDetails(std::ostream& os, int descriptor,
2444  PropertyDetails::PrintMode mode) {
2445  PropertyDetails details = GetDetails(descriptor);
2446  details.PrintAsFastTo(os, mode);
2447  os << " @ ";
2448  switch (details.location()) {
2449  case kField: {
2450  FieldType field_type = GetFieldType(descriptor);
2451  field_type->PrintTo(os);
2452  break;
2453  }
2454  case kDescriptor:
2455  Object* value = GetStrongValue(descriptor);
2456  os << Brief(value);
2457  if (value->IsAccessorPair()) {
2458  AccessorPair* pair = AccessorPair::cast(value);
2459  os << "(get: " << Brief(pair->getter())
2460  << ", set: " << Brief(pair->setter()) << ")";
2461  }
2462  break;
2463  }
2464 }
2465 
2466 #if defined(DEBUG) || defined(OBJECT_PRINT)
2467 // This method is only meant to be called from gdb for debugging purposes.
2468 // Since the string can also be in two-byte encoding, non-Latin1 characters
2469 // will be ignored in the output.
2470 char* String::ToAsciiArray() {
2471  // Static so that subsequent calls frees previously allocated space.
2472  // This also means that previous results will be overwritten.
2473  static char* buffer = nullptr;
2474  if (buffer != nullptr) delete[] buffer;
2475  buffer = new char[length() + 1];
2476  WriteToFlat(*this, reinterpret_cast<uint8_t*>(buffer), 0, length());
2477  buffer[length()] = 0;
2478  return buffer;
2479 }
2480 
2481 // static
2482 void TransitionsAccessor::PrintOneTransition(std::ostream& os, Name key,
2483  Map target) {
2484  os << "\n ";
2485 #ifdef OBJECT_PRINT
2486  key->NamePrint(os);
2487 #else
2488  key->ShortPrint(os);
2489 #endif
2490  os << ": ";
2491  ReadOnlyRoots roots = key->GetReadOnlyRoots();
2492  if (key == roots.nonextensible_symbol()) {
2493  os << "(transition to non-extensible)";
2494  } else if (key == roots.sealed_symbol()) {
2495  os << "(transition to sealed)";
2496  } else if (key == roots.frozen_symbol()) {
2497  os << "(transition to frozen)";
2498  } else if (key == roots.elements_transition_symbol()) {
2499  os << "(transition to " << ElementsKindToString(target->elements_kind())
2500  << ")";
2501  } else if (key == roots.strict_function_transition_symbol()) {
2502  os << " (transition to strict function)";
2503  } else {
2504  DCHECK(!IsSpecialTransition(roots, key));
2505  os << "(transition to ";
2506  int descriptor = target->LastAdded();
2507  DescriptorArray* descriptors = target->instance_descriptors();
2508  descriptors->PrintDescriptorDetails(os, descriptor,
2509  PropertyDetails::kForTransitions);
2510  os << ")";
2511  }
2512  os << " -> " << Brief(target);
2513 }
2514 
2515 void TransitionArray::PrintInternal(std::ostream& os) {
2516  int num_transitions = number_of_transitions();
2517  os << "Transition array #" << num_transitions << ":";
2518  for (int i = 0; i < num_transitions; i++) {
2519  Name key = GetKey(i);
2520  Map target = GetTarget(i);
2521  TransitionsAccessor::PrintOneTransition(os, key, target);
2522  }
2523  os << "\n" << std::flush;
2524 }
2525 
2526 void TransitionsAccessor::PrintTransitions(std::ostream& os) { // NOLINT
2527  switch (encoding()) {
2528  case kPrototypeInfo:
2529  case kUninitialized:
2530  case kMigrationTarget:
2531  return;
2532  case kWeakRef: {
2533  Map target = Map::cast(raw_transitions_->GetHeapObjectAssumeWeak());
2534  Name key = GetSimpleTransitionKey(target);
2535  PrintOneTransition(os, key, target);
2536  break;
2537  }
2538  case kFullTransitionArray:
2539  return transitions()->PrintInternal(os);
2540  }
2541 }
2542 
2543 void TransitionsAccessor::PrintTransitionTree() {
2544  StdoutStream os;
2545  os << "map= " << Brief(map_);
2546  DisallowHeapAllocation no_gc;
2547  PrintTransitionTree(os, 0, &no_gc);
2548  os << "\n" << std::flush;
2549 }
2550 
2551 void TransitionsAccessor::PrintTransitionTree(std::ostream& os, int level,
2552  DisallowHeapAllocation* no_gc) {
2553  ReadOnlyRoots roots = ReadOnlyRoots(isolate_);
2554  int num_transitions = NumberOfTransitions();
2555  if (num_transitions == 0) return;
2556  for (int i = 0; i < num_transitions; i++) {
2557  Name key = GetKey(i);
2558  Map target = GetTarget(i);
2559  os << std::endl
2560  << " " << level << "/" << i << ":" << std::setw(level * 2 + 2) << " ";
2561  std::stringstream ss;
2562  ss << Brief(target);
2563  os << std::left << std::setw(50) << ss.str() << ": ";
2564 
2565  if (key == roots.nonextensible_symbol()) {
2566  os << "to non-extensible";
2567  } else if (key == roots.sealed_symbol()) {
2568  os << "to sealed ";
2569  } else if (key == roots.frozen_symbol()) {
2570  os << "to frozen";
2571  } else if (key == roots.elements_transition_symbol()) {
2572  os << "to " << ElementsKindToString(target->elements_kind());
2573  } else if (key == roots.strict_function_transition_symbol()) {
2574  os << "to strict function";
2575  } else {
2576 #ifdef OBJECT_PRINT
2577  key->NamePrint(os);
2578 #else
2579  key->ShortPrint(os);
2580 #endif
2581  os << " ";
2582  DCHECK(!IsSpecialTransition(ReadOnlyRoots(isolate_), key));
2583  os << "to ";
2584  int descriptor = target->LastAdded();
2585  DescriptorArray* descriptors = target->instance_descriptors();
2586  descriptors->PrintDescriptorDetails(os, descriptor,
2587  PropertyDetails::kForTransitions);
2588  }
2589  TransitionsAccessor transitions(isolate_, target, no_gc);
2590  transitions.PrintTransitionTree(os, level + 1, no_gc);
2591  }
2592 }
2593 
2594 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT
2595  DisallowHeapAllocation no_gc;
2596  TransitionsAccessor ta(GetIsolate(), map(), &no_gc);
2597  if (ta.NumberOfTransitions() == 0) return;
2598  os << "\n - transitions";
2599  ta.PrintTransitions(os);
2600 }
2601 
2602 #endif // defined(DEBUG) || defined(OBJECT_PRINT)
2603 } // namespace internal
2604 } // namespace v8
2605 
2606 //
2607 // The following functions are used by our gdb macros.
2608 //
2609 V8_EXPORT_PRIVATE extern void _v8_internal_Print_Object(void* object) {
2610  reinterpret_cast<i::Object*>(object)->Print();
2611 }
2612 
2613 V8_EXPORT_PRIVATE extern void _v8_internal_Print_Code(void* object) {
2614  i::Address address = reinterpret_cast<i::Address>(object);
2615  i::Isolate* isolate = i::Isolate::Current();
2616 
2617  i::wasm::WasmCode* wasm_code =
2618  isolate->wasm_engine()->code_manager()->LookupCode(address);
2619  if (wasm_code) {
2620  i::StdoutStream os;
2621  wasm_code->Disassemble(nullptr, os, address);
2622  return;
2623  }
2624 
2625  if (!isolate->heap()->InSpaceSlow(address, i::CODE_SPACE) &&
2626  !isolate->heap()->InSpaceSlow(address, i::LO_SPACE) &&
2627  !i::InstructionStream::PcIsOffHeap(isolate, address)) {
2628  i::PrintF(
2629  "%p is not within the current isolate's large object, code or embedded "
2630  "spaces\n",
2631  object);
2632  return;
2633  }
2634 
2635  i::Code code = isolate->FindCodeObject(address);
2636  if (!code->IsCode()) {
2637  i::PrintF("No code object found containing %p\n", object);
2638  return;
2639  }
2640 #ifdef ENABLE_DISASSEMBLER
2641  i::StdoutStream os;
2642  code->Disassemble(nullptr, os, address);
2643 #else // ENABLE_DISASSEMBLER
2644  code->Print();
2645 #endif // ENABLE_DISASSEMBLER
2646 }
2647 
2648 V8_EXPORT_PRIVATE extern void _v8_internal_Print_LayoutDescriptor(
2649  void* object) {
2650  i::Object* o = reinterpret_cast<i::Object*>(object);
2651  if (!o->IsLayoutDescriptor()) {
2652  printf("Please provide a layout descriptor\n");
2653  } else {
2654  i::LayoutDescriptor::cast(o)->Print();
2655  }
2656 }
2657 
2658 V8_EXPORT_PRIVATE extern void _v8_internal_Print_StackTrace() {
2659  i::Isolate* isolate = i::Isolate::Current();
2660  isolate->PrintStack(stdout);
2661 }
2662 
2663 V8_EXPORT_PRIVATE extern void _v8_internal_Print_TransitionTree(void* object) {
2664  i::Object* o = reinterpret_cast<i::Object*>(object);
2665  if (!o->IsMap()) {
2666  printf("Please provide a valid Map\n");
2667  } else {
2668 #if defined(DEBUG) || defined(OBJECT_PRINT)
2670  i::Map map = i::Map::unchecked_cast(o);
2671  i::TransitionsAccessor transitions(i::Isolate::Current(), map, &no_gc);
2672  transitions.PrintTransitionTree();
2673 #endif
2674  }
2675 }
Definition: libplatform.h:13