objects-printer.cc 87.1 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5
#include "src/objects.h"
6

7
#include <iomanip>
8 9
#include <memory>

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/cell-inl.h"
17
#include "src/objects/data-handler-inl.h"
18
#include "src/objects/debug-objects-inl.h"
19
#include "src/objects/embedder-data-array-inl.h"
20
#include "src/objects/embedder-data-slot-inl.h"
21
#include "src/objects/feedback-cell-inl.h"
22
#include "src/objects/foreign-inl.h"
23
#include "src/objects/free-space-inl.h"
24
#include "src/objects/hash-table-inl.h"
25
#include "src/objects/heap-number-inl.h"
26 27
#include "src/objects/js-array-buffer-inl.h"
#include "src/objects/js-array-inl.h"
28
#include "src/snapshot/embedded-data.h"
29
#ifdef V8_INTL_SUPPORT
30
#include "src/objects/js-break-iterator-inl.h"
31 32
#include "src/objects/js-collator-inl.h"
#endif  // V8_INTL_SUPPORT
33
#include "src/objects/js-collection-inl.h"
34 35 36
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-date-time-format-inl.h"
#endif  // V8_INTL_SUPPORT
37
#include "src/objects/js-generator-inl.h"
38
#ifdef V8_INTL_SUPPORT
39
#include "src/objects/js-list-format-inl.h"
40
#include "src/objects/js-locale-inl.h"
41 42
#include "src/objects/js-number-format-inl.h"
#include "src/objects/js-plural-rules-inl.h"
43
#endif  // V8_INTL_SUPPORT
44 45
#include "src/objects/js-regexp-inl.h"
#include "src/objects/js-regexp-string-iterator-inl.h"
46 47
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-relative-time-format-inl.h"
48
#include "src/objects/js-segment-iterator-inl.h"
49
#include "src/objects/js-segmenter-inl.h"
50
#endif  // V8_INTL_SUPPORT
51
#include "src/objects/js-weak-refs-inl.h"
52
#include "src/objects/literal-objects-inl.h"
53
#include "src/objects/microtask-inl.h"
54
#include "src/objects/module-inl.h"
55
#include "src/objects/oddball-inl.h"
56
#include "src/objects/promise-inl.h"
57
#include "src/objects/stack-frame-info-inl.h"
58
#include "src/objects/struct-inl.h"
59
#include "src/ostreams.h"
60
#include "src/regexp/jsregexp.h"
61
#include "src/transitions-inl.h"
62
#include "src/wasm/wasm-code-manager.h"
63
#include "src/wasm/wasm-engine.h"
64
#include "src/wasm/wasm-objects-inl.h"
65 66 67 68 69 70

namespace v8 {
namespace internal {

#ifdef OBJECT_PRINT

71
void Object::Print() const {
72
  StdoutStream os;
73
  this->Print(os);
74
  os << std::flush;
75 76
}

77
void Object::Print(std::ostream& os) const {  // NOLINT
78
  if (IsSmi()) {
79 80
    os << "Smi: " << std::hex << "0x" << Smi::ToInt(*this);
    os << std::dec << " (" << Smi::ToInt(*this) << ")\n";
81
  } else {
82
    HeapObject::cast(*this)->HeapObjectPrint(os);
83 84 85
  }
}

86
void HeapObject::PrintHeader(std::ostream& os, const char* id) {  // NOLINT
87 88 89 90 91 92 93 94 95 96 97 98
  os << reinterpret_cast<void*>(ptr()) << ": [";
  if (id != nullptr) {
    os << id;
  } else {
    os << map()->instance_type();
  }
  os << "]";
  MemoryChunk* chunk = MemoryChunk::FromAddress(ptr());
  if (chunk->owner()->identity() == OLD_SPACE) os << " in OldSpace";
  if (!IsMap()) os << "\n - map: " << Brief(map());
}

99
void HeapObject::HeapObjectPrint(std::ostream& os) {  // NOLINT
100 101 102
  InstanceType instance_type = map()->instance_type();

  if (instance_type < FIRST_NONSTRING_TYPE) {
103
    String::cast(*this)->StringPrint(os);
104
    os << "\n";
105 106 107 108
    return;
  }

  switch (instance_type) {
109
    case SYMBOL_TYPE:
110
      Symbol::cast(*this)->SymbolPrint(os);
111
      break;
112
    case MAP_TYPE:
113
      Map::cast(*this)->MapPrint(os);
114 115
      break;
    case HEAP_NUMBER_TYPE:
116
      HeapNumber::cast(*this)->HeapNumberPrint(os);
117
      os << "\n";
118
      break;
119
    case MUTABLE_HEAP_NUMBER_TYPE:
120
      os << "<mutable ";
121
      MutableHeapNumber::cast(*this)->MutableHeapNumberPrint(os);
122
      os << ">\n";
123
      break;
124
    case BIGINT_TYPE:
125
      BigInt::cast(*this)->BigIntPrint(os);
126 127
      os << "\n";
      break;
128
    case EMBEDDER_DATA_ARRAY_TYPE:
129
      EmbedderDataArray::cast(*this)->EmbedderDataArrayPrint(os);
130
      break;
131
    case FIXED_DOUBLE_ARRAY_TYPE:
132
      FixedDoubleArray::cast(*this)->FixedDoubleArrayPrint(os);
133
      break;
134
    case FIXED_ARRAY_TYPE:
135
      FixedArray::cast(*this)->FixedArrayPrint(os);
136
      break;
137
    case AWAIT_CONTEXT_TYPE:
138 139 140 141 142 143 144 145
    case BLOCK_CONTEXT_TYPE:
    case CATCH_CONTEXT_TYPE:
    case DEBUG_EVALUATE_CONTEXT_TYPE:
    case EVAL_CONTEXT_TYPE:
    case FUNCTION_CONTEXT_TYPE:
    case MODULE_CONTEXT_TYPE:
    case SCRIPT_CONTEXT_TYPE:
    case WITH_CONTEXT_TYPE:
146
    case SCRIPT_CONTEXT_TABLE_TYPE:
147
      Context::cast(*this)->ContextPrint(os);
148 149
      break;
    case NATIVE_CONTEXT_TYPE:
150
      NativeContext::cast(*this)->NativeContextPrint(os);
151
      break;
152
    case HASH_TABLE_TYPE:
153 154
    case ORDERED_HASH_MAP_TYPE:
    case ORDERED_HASH_SET_TYPE:
155
    case ORDERED_NAME_DICTIONARY_TYPE:
156 157 158
    case NAME_DICTIONARY_TYPE:
    case GLOBAL_DICTIONARY_TYPE:
    case SIMPLE_NUMBER_DICTIONARY_TYPE:
159 160
      FixedArray::cast(*this)->FixedArrayPrint(os);
      break;
161
    case STRING_TABLE_TYPE:
162
      ObjectHashTable::cast(*this)->ObjectHashTablePrint(os);
163
      break;
164
    case NUMBER_DICTIONARY_TYPE:
165
      NumberDictionary::cast(*this)->NumberDictionaryPrint(os);
166
      break;
167
    case EPHEMERON_HASH_TABLE_TYPE:
168
      EphemeronHashTable::cast(*this)->EphemeronHashTablePrint(os);
169
      break;
170
    case OBJECT_BOILERPLATE_DESCRIPTION_TYPE:
171
      ObjectBoilerplateDescription::cast(*this)
172
          ->ObjectBoilerplateDescriptionPrint(os);
173
      break;
174
    case PROPERTY_ARRAY_TYPE:
175
      PropertyArray::cast(*this)->PropertyArrayPrint(os);
176
      break;
177
    case BYTE_ARRAY_TYPE:
178
      ByteArray::cast(*this)->ByteArrayPrint(os);
179
      break;
180
    case BYTECODE_ARRAY_TYPE:
181
      BytecodeArray::cast(*this)->BytecodeArrayPrint(os);
182
      break;
183
    case DESCRIPTOR_ARRAY_TYPE:
184
      DescriptorArray::cast(*this)->DescriptorArrayPrint(os);
185
      break;
186
    case TRANSITION_ARRAY_TYPE:
187
      TransitionArray::cast(*this)->TransitionArrayPrint(os);
188
      break;
189
    case FEEDBACK_CELL_TYPE:
190
      FeedbackCell::cast(*this)->FeedbackCellPrint(os);
191
      break;
192
    case FEEDBACK_VECTOR_TYPE:
193
      FeedbackVector::cast(*this)->FeedbackVectorPrint(os);
194
      break;
195
    case FREE_SPACE_TYPE:
196
      FreeSpace::cast(*this)->FreeSpacePrint(os);
197
      break;
198

199 200 201
#define PRINT_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype)       \
  case Fixed##Type##Array::kInstanceType:                      \
    Fixed##Type##Array::cast(*this)->FixedTypedArrayPrint(os); \
202
    break;
203

204
      TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY)
205
#undef PRINT_FIXED_TYPED_ARRAY
206

207
    case FILLER_TYPE:
208
      os << "filler";
209 210
      break;
    case JS_OBJECT_TYPE:  // fall through
211
    case JS_API_OBJECT_TYPE:
212
    case JS_SPECIAL_API_OBJECT_TYPE:
213
    case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
214
    case JS_ASYNC_FUNCTION_OBJECT_TYPE:
215
    case JS_ASYNC_GENERATOR_OBJECT_TYPE:
216 217
    case JS_ARGUMENTS_TYPE:
    case JS_ERROR_TYPE:
218
    // TODO(titzer): debug printing for more wasm objects
219
    case WASM_EXCEPTION_TYPE:
220
    case WASM_GLOBAL_TYPE:
221 222
    case WASM_MEMORY_TYPE:
    case WASM_TABLE_TYPE:
223
      JSObject::cast(*this)->JSObjectPrint(os);
224
      break;
225
    case WASM_MODULE_TYPE:
226
      WasmModuleObject::cast(*this)->WasmModuleObjectPrint(os);
227
      break;
228
    case WASM_INSTANCE_TYPE:
229
      WasmInstanceObject::cast(*this)->WasmInstanceObjectPrint(os);
230
      break;
231
    case JS_GENERATOR_OBJECT_TYPE:
232
      JSGeneratorObject::cast(*this)->JSGeneratorObjectPrint(os);
233
      break;
234
    case JS_PROMISE_TYPE:
235
      JSPromise::cast(*this)->JSPromisePrint(os);
236
      break;
237
    case JS_ARRAY_TYPE:
238
      JSArray::cast(*this)->JSArrayPrint(os);
239
      break;
240
    case JS_REGEXP_TYPE:
241
      JSRegExp::cast(*this)->JSRegExpPrint(os);
242
      break;
243
    case JS_REGEXP_STRING_ITERATOR_TYPE:
244
      JSRegExpStringIterator::cast(*this)->JSRegExpStringIteratorPrint(os);
245
      break;
246
    case ODDBALL_TYPE:
247
      Oddball::cast(*this)->to_string()->Print(os);
248
      break;
249
    case JS_BOUND_FUNCTION_TYPE:
250
      JSBoundFunction::cast(*this)->JSBoundFunctionPrint(os);
251
      break;
252
    case JS_FUNCTION_TYPE:
253
      JSFunction::cast(*this)->JSFunctionPrint(os);
254 255
      break;
    case JS_GLOBAL_PROXY_TYPE:
256
      JSGlobalProxy::cast(*this)->JSGlobalProxyPrint(os);
257 258
      break;
    case JS_GLOBAL_OBJECT_TYPE:
259
      JSGlobalObject::cast(*this)->JSGlobalObjectPrint(os);
260 261
      break;
    case JS_VALUE_TYPE:
262
      JSValue::cast(*this)->JSValuePrint(os);
263
      break;
264
    case JS_DATE_TYPE:
265
      JSDate::cast(*this)->JSDatePrint(os);
266
      break;
267
    case CODE_TYPE:
268
      Code::cast(*this)->CodePrint(os);
269
      break;
270
    case CODE_DATA_CONTAINER_TYPE:
271
      CodeDataContainer::cast(*this)->CodeDataContainerPrint(os);
272
      break;
273
    case JS_PROXY_TYPE:
274
      JSProxy::cast(*this)->JSProxyPrint(os);
275
      break;
276
    case JS_SET_TYPE:
277
      JSSet::cast(*this)->JSSetPrint(os);
278 279
      break;
    case JS_MAP_TYPE:
280
      JSMap::cast(*this)->JSMapPrint(os);
281
      break;
282 283
    case JS_SET_KEY_VALUE_ITERATOR_TYPE:
    case JS_SET_VALUE_ITERATOR_TYPE:
284
      JSSetIterator::cast(*this)->JSSetIteratorPrint(os);
285
      break;
286 287 288
    case JS_MAP_KEY_ITERATOR_TYPE:
    case JS_MAP_KEY_VALUE_ITERATOR_TYPE:
    case JS_MAP_VALUE_ITERATOR_TYPE:
289
      JSMapIterator::cast(*this)->JSMapIteratorPrint(os);
290
      break;
291
    case JS_WEAK_CELL_TYPE:
292
      JSWeakCell::cast(*this)->JSWeakCellPrint(os);
293
      break;
294
    case JS_WEAK_REF_TYPE:
295
      JSWeakRef::cast(*this)->JSWeakRefPrint(os);
296
      break;
297
    case JS_WEAK_FACTORY_TYPE:
298
      JSWeakFactory::cast(*this)->JSWeakFactoryPrint(os);
299 300
      break;
    case JS_WEAK_FACTORY_CLEANUP_ITERATOR_TYPE:
301
      JSWeakFactoryCleanupIterator::cast(*this)
302 303
          ->JSWeakFactoryCleanupIteratorPrint(os);
      break;
304
    case JS_WEAK_MAP_TYPE:
305
      JSWeakMap::cast(*this)->JSWeakMapPrint(os);
306
      break;
307
    case JS_WEAK_SET_TYPE:
308
      JSWeakSet::cast(*this)->JSWeakSetPrint(os);
309
      break;
310
    case JS_MODULE_NAMESPACE_TYPE:
311
      JSModuleNamespace::cast(*this)->JSModuleNamespacePrint(os);
312
      break;
313
    case FOREIGN_TYPE:
314
      Foreign::cast(*this)->ForeignPrint(os);
315
      break;
316
    case CALL_HANDLER_INFO_TYPE:
317
      CallHandlerInfo::cast(*this)->CallHandlerInfoPrint(os);
318
      break;
319
    case PREPARSE_DATA_TYPE:
320
      PreparseData::cast(*this)->PreparseDataPrint(os);
321
      break;
322
    case UNCOMPILED_DATA_WITHOUT_PREPARSE_DATA_TYPE:
323 324
      UncompiledDataWithoutPreparseData::cast(*this)
          ->UncompiledDataWithoutPreparseDataPrint(os);
325
      break;
326
    case UNCOMPILED_DATA_WITH_PREPARSE_DATA_TYPE:
327 328
      UncompiledDataWithPreparseData::cast(*this)
          ->UncompiledDataWithPreparseDataPrint(os);
329
      break;
330
    case SHARED_FUNCTION_INFO_TYPE:
331
      SharedFunctionInfo::cast(*this)->SharedFunctionInfoPrint(os);
332
      break;
333
    case JS_MESSAGE_OBJECT_TYPE:
334
      JSMessageObject::cast(*this)->JSMessageObjectPrint(os);
335
      break;
336
    case CELL_TYPE:
337
      Cell::cast(*this)->CellPrint(os);
338 339
      break;
    case PROPERTY_CELL_TYPE:
340
      PropertyCell::cast(*this)->PropertyCellPrint(os);
341
      break;
342
    case JS_ARRAY_BUFFER_TYPE:
343
      JSArrayBuffer::cast(*this)->JSArrayBufferPrint(os);
344
      break;
345
    case JS_ARRAY_ITERATOR_TYPE:
346
      JSArrayIterator::cast(*this)->JSArrayIteratorPrint(os);
347
      break;
348
    case JS_TYPED_ARRAY_TYPE:
349
      JSTypedArray::cast(*this)->JSTypedArrayPrint(os);
350
      break;
351
    case JS_DATA_VIEW_TYPE:
352
      JSDataView::cast(*this)->JSDataViewPrint(os);
353
      break;
354
#ifdef V8_INTL_SUPPORT
355
    case JS_INTL_V8_BREAK_ITERATOR_TYPE:
356
      JSV8BreakIterator::cast(*this)->JSV8BreakIteratorPrint(os);
357
      break;
358
    case JS_INTL_COLLATOR_TYPE:
359
      JSCollator::cast(*this)->JSCollatorPrint(os);
360
      break;
361
    case JS_INTL_DATE_TIME_FORMAT_TYPE:
362
      JSDateTimeFormat::cast(*this)->JSDateTimeFormatPrint(os);
363
      break;
364
    case JS_INTL_LIST_FORMAT_TYPE:
365
      JSListFormat::cast(*this)->JSListFormatPrint(os);
366
      break;
367
    case JS_INTL_LOCALE_TYPE:
368
      JSLocale::cast(*this)->JSLocalePrint(os);
369
      break;
370
    case JS_INTL_NUMBER_FORMAT_TYPE:
371
      JSNumberFormat::cast(*this)->JSNumberFormatPrint(os);
372
      break;
373
    case JS_INTL_PLURAL_RULES_TYPE:
374
      JSPluralRules::cast(*this)->JSPluralRulesPrint(os);
375
      break;
376
    case JS_INTL_RELATIVE_TIME_FORMAT_TYPE:
377
      JSRelativeTimeFormat::cast(*this)->JSRelativeTimeFormatPrint(os);
378
      break;
379
    case JS_INTL_SEGMENT_ITERATOR_TYPE:
380
      JSSegmentIterator::cast(*this)->JSSegmentIteratorPrint(os);
381
      break;
382
    case JS_INTL_SEGMENTER_TYPE:
383
      JSSegmenter::cast(*this)->JSSegmenterPrint(os);
384
      break;
385
#endif  // V8_INTL_SUPPORT
386 387
#define MAKE_STRUCT_CASE(TYPE, Name, name) \
  case TYPE:                               \
388
    Name::cast(*this)->Name##Print(os);    \
389
    break;
390
      STRUCT_LIST(MAKE_STRUCT_CASE)
391 392
#undef MAKE_STRUCT_CASE

393
    case ALLOCATION_SITE_TYPE:
394
      AllocationSite::cast(*this)->AllocationSitePrint(os);
395
      break;
396
    case LOAD_HANDLER_TYPE:
397
      LoadHandler::cast(*this)->LoadHandlerPrint(os);
398 399
      break;
    case STORE_HANDLER_TYPE:
400
      StoreHandler::cast(*this)->StoreHandlerPrint(os);
401
      break;
402
    case SCOPE_INFO_TYPE:
403
      ScopeInfo::cast(*this)->ScopeInfoPrint(os);
404
      break;
405
    case FEEDBACK_METADATA_TYPE:
406
      FeedbackMetadata::cast(*this)->FeedbackMetadataPrint(os);
407
      break;
408
    case WEAK_FIXED_ARRAY_TYPE:
409
      WeakFixedArray::cast(*this)->WeakFixedArrayPrint(os);
410
      break;
411
    case WEAK_ARRAY_LIST_TYPE:
412
      WeakArrayList::cast(*this)->WeakArrayListPrint(os);
413
      break;
414 415 416 417 418
    case INTERNALIZED_STRING_TYPE:
    case EXTERNAL_INTERNALIZED_STRING_TYPE:
    case ONE_BYTE_INTERNALIZED_STRING_TYPE:
    case EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE:
    case EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
419 420 421
    case UNCACHED_EXTERNAL_INTERNALIZED_STRING_TYPE:
    case UNCACHED_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE:
    case UNCACHED_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
422 423 424 425 426 427 428 429 430 431 432
    case STRING_TYPE:
    case CONS_STRING_TYPE:
    case EXTERNAL_STRING_TYPE:
    case SLICED_STRING_TYPE:
    case THIN_STRING_TYPE:
    case ONE_BYTE_STRING_TYPE:
    case CONS_ONE_BYTE_STRING_TYPE:
    case EXTERNAL_ONE_BYTE_STRING_TYPE:
    case SLICED_ONE_BYTE_STRING_TYPE:
    case THIN_ONE_BYTE_STRING_TYPE:
    case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
433 434 435
    case UNCACHED_EXTERNAL_STRING_TYPE:
    case UNCACHED_EXTERNAL_ONE_BYTE_STRING_TYPE:
    case UNCACHED_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
436 437
    case SMALL_ORDERED_HASH_MAP_TYPE:
    case SMALL_ORDERED_HASH_SET_TYPE:
438
    case SMALL_ORDERED_NAME_DICTIONARY_TYPE:
439 440 441
    case JS_ASYNC_FROM_SYNC_ITERATOR_TYPE:
    case JS_STRING_ITERATOR_TYPE:
      // TODO(all): Handle these types too.
442
      os << "UNKNOWN TYPE " << map()->instance_type();
443 444 445 446 447
      UNREACHABLE();
      break;
  }
}

448
void ByteArray::ByteArrayPrint(std::ostream& os) {  // NOLINT
449 450 451 452
  PrintHeader(os, "ByteArray");
  os << "\n - length: " << length()
     << "\n - data-start: " << static_cast<void*>(GetDataStartAddress())
     << "\n";
453 454
}

455
void BytecodeArray::BytecodeArrayPrint(std::ostream& os) {  // NOLINT
456
  PrintHeader(os, "BytecodeArray");
457
  Disassemble(os);
458 459 460
}


461
void FreeSpace::FreeSpacePrint(std::ostream& os) {  // NOLINT
462
  os << "free space, size " << Size();
463 464 465
}


466
template <class Traits>
467 468
void FixedTypedArray<Traits>::FixedTypedArrayPrint(
    std::ostream& os) {  // NOLINT
469
  os << "fixed " << Traits::Designator();
470 471
}

472
bool JSObject::PrintProperties(std::ostream& os) {  // NOLINT
473
  if (HasFastProperties()) {
474
    DescriptorArray descs = map()->instance_descriptors();
475
    int nof_inobject_properties = map()->GetInObjectProperties();
476 477 478
    int i = 0;
    for (; i < map()->NumberOfOwnDescriptors(); i++) {
      os << "\n    ";
479 480
      descs->GetKey(i)->NamePrint(os);
      os << ": ";
481 482 483
      PropertyDetails details = descs->GetDetails(i);
      switch (details.location()) {
        case kField: {
484
          FieldIndex field_index = FieldIndex::ForDescriptor(map(), i);
485 486
          if (IsUnboxedDoubleField(field_index)) {
            os << "<unboxed double> " << RawFastDoublePropertyAt(field_index);
487
          } else {
488
            os << Brief(RawFastPropertyAt(field_index));
489
          }
490 491
          break;
        }
492
        case kDescriptor:
493
          os << Brief(descs->GetStrongValue(i));
494
          break;
495
      }
496 497
      os << " ";
      details.PrintAsFastTo(os, PropertyDetails::kForProperties);
498 499 500 501 502 503
      if (details.location() != kField) continue;
      int field_index = details.field_index();
      if (nof_inobject_properties <= field_index) {
        field_index -= nof_inobject_properties;
        os << " properties[" << field_index << "]";
      }
504
    }
505
    return i > 0;
506
  } else if (IsJSGlobalObject()) {
507
    JSGlobalObject::cast(*this)->global_dictionary()->Print(os);
508
  } else {
509
    property_dictionary()->Print(os);
510
  }
511
  return true;
512 513
}

514 515 516
namespace {

template <class T>
517
bool IsTheHoleAt(T array, int index) {
518
  return false;
519 520
}

521
template <>
522
bool IsTheHoleAt(FixedDoubleArray array, int index) {
523
  return array->is_the_hole(index);
524 525
}

526
template <class T>
527
double GetScalarElement(T array, int index) {
528 529 530 531
  if (IsTheHoleAt(array, index)) {
    return std::numeric_limits<double>::quiet_NaN();
  }
  return array->get_scalar(index);
532 533
}

534
template <class T>
535
void DoPrintElements(std::ostream& os, Object object) {  // NOLINT
536
  const bool print_the_hole = std::is_same<T, FixedDoubleArray>::value;
537
  T array = T::cast(object);
538 539
  if (array->length() == 0) return;
  int previous_index = 0;
540
  double previous_value = GetScalarElement(array, 0);
541 542 543
  double value = 0.0;
  int i;
  for (i = 1; i <= array->length(); i++) {
544
    if (i < array->length()) value = GetScalarElement(array, i);
545
    bool values_are_nan = std::isnan(previous_value) && std::isnan(value);
546
    if (i != array->length() && (previous_value == value || values_are_nan) &&
547
        IsTheHoleAt(array, i - 1) == IsTheHoleAt(array, i)) {
548 549 550 551 552 553 554 555 556
      continue;
    }
    os << "\n";
    std::stringstream ss;
    ss << previous_index;
    if (previous_index != i - 1) {
      ss << '-' << (i - 1);
    }
    os << std::setw(12) << ss.str() << ": ";
557
    if (print_the_hole && IsTheHoleAt(array, i - 1)) {
558 559 560 561 562 563
      os << "<the_hole>";
    } else {
      os << previous_value;
    }
    previous_index = i;
    previous_value = value;
564 565 566
  }
}

567
template <typename T>
568
void PrintFixedArrayElements(std::ostream& os, T array) {
569
  // Print in array notation for non-sparse arrays.
570 571
  Object previous_value = array->length() > 0 ? array->get(0) : Object();
  Object value;
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
  int previous_index = 0;
  int i;
  for (i = 1; i <= array->length(); i++) {
    if (i < array->length()) value = array->get(i);
    if (previous_value == value && i != array->length()) {
      continue;
    }
    os << "\n";
    std::stringstream ss;
    ss << previous_index;
    if (previous_index != i - 1) {
      ss << '-' << (i - 1);
    }
    os << std::setw(12) << ss.str() << ": " << Brief(previous_value);
    previous_index = i;
    previous_value = value;
  }
}

591
void PrintDictionaryElements(std::ostream& os, FixedArrayBase elements) {
592
  // Print some internal fields
593
  NumberDictionary dict = NumberDictionary::cast(elements);
594 595 596 597 598 599 600 601
  if (dict->requires_slow_elements()) {
    os << "\n   - requires_slow_elements";
  } else {
    os << "\n   - max_number_key: " << dict->max_number_key();
  }
  dict->Print(os);
}

602
void PrintSloppyArgumentElements(std::ostream& os, ElementsKind kind,
603
                                 SloppyArgumentsElements elements) {
604
  FixedArray arguments_store = elements->arguments();
605 606
  os << "\n    0: context: " << Brief(elements->context())
     << "\n    1: arguments_store: " << Brief(arguments_store)
607 608 609
     << "\n    parameter to context slot map:";
  for (uint32_t i = 0; i < elements->parameter_map_length(); i++) {
    uint32_t raw_index = i + SloppyArgumentsElements::kParameterMapStart;
610
    Object mapped_entry = elements->get_mapped_entry(i);
611
    os << "\n    " << raw_index << ": param(" << i
612
       << "): " << Brief(mapped_entry);
613
    if (mapped_entry->IsTheHole()) {
Mathias Bynens's avatar
Mathias Bynens committed
614
      os << " in the arguments_store[" << i << "]";
615 616 617
    } else {
      os << " in the context";
    }
618 619 620
  }
  if (arguments_store->length() == 0) return;
  os << "\n }"
621
     << "\n - arguments_store: " << Brief(arguments_store) << " "
622 623 624 625 626
     << ElementsKindToString(arguments_store->map()->elements_kind()) << " {";
  if (kind == FAST_SLOPPY_ARGUMENTS_ELEMENTS) {
    PrintFixedArrayElements(os, arguments_store);
  } else {
    DCHECK_EQ(kind, SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
627
    PrintDictionaryElements(os, arguments_store);
628 629 630
  }
}

631 632
void PrintEmbedderData(std::ostream& os, EmbedderDataSlot slot) {
  DisallowHeapAllocation no_gc;
633
  Object value = slot.load_tagged();
634 635 636 637 638 639 640
  os << Brief(value);
  void* raw_pointer;
  if (slot.ToAlignedPointer(&raw_pointer)) {
    os << ", aligned pointer: " << raw_pointer;
  }
}

641
}  // namespace
642

643
void JSObject::PrintElements(std::ostream& os) {  // NOLINT
644 645
  // Don't call GetElementsKind, its validation code can cause the printer to
  // fail when debugging.
646
  os << " - elements: " << Brief(elements()) << " {";
647 648 649 650
  if (elements()->length() == 0) {
    os << " }\n";
    return;
  }
651
  switch (map()->elements_kind()) {
652 653 654 655
    case HOLEY_SMI_ELEMENTS:
    case PACKED_SMI_ELEMENTS:
    case HOLEY_ELEMENTS:
    case PACKED_ELEMENTS:
656
    case FAST_STRING_WRAPPER_ELEMENTS: {
657
      PrintFixedArrayElements(os, FixedArray::cast(elements()));
658 659
      break;
    }
660 661
    case HOLEY_DOUBLE_ELEMENTS:
    case PACKED_DOUBLE_ELEMENTS: {
662
      DoPrintElements<FixedDoubleArray>(os, elements());
663 664
      break;
    }
665

666 667 668 669
#define PRINT_ELEMENTS(Type, type, TYPE, elementType)    \
  case TYPE##_ELEMENTS: {                                \
    DoPrintElements<Fixed##Type##Array>(os, elements()); \
    break;                                               \
670
  }
671
      TYPED_ARRAYS(PRINT_ELEMENTS)
672 673
#undef PRINT_ELEMENTS

674
    case DICTIONARY_ELEMENTS:
675
    case SLOW_STRING_WRAPPER_ELEMENTS:
676
      PrintDictionaryElements(os, elements());
677
      break;
678
    case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
679
    case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
680
      PrintSloppyArgumentElements(os, map()->elements_kind(),
681
                                  SloppyArgumentsElements::cast(elements()));
682
      break;
683 684
    case NO_ELEMENTS:
      break;
685
  }
686
  os << "\n }\n";
687 688
}

689
static void JSObjectPrintHeader(std::ostream& os, JSObject obj,
690
                                const char* id) {  // NOLINT
691
  Isolate* isolate = obj->GetIsolate();
692
  obj->PrintHeader(os, id);
693 694
  // Don't call GetElementsKind, its validation code can cause the printer to
  // fail when debugging.
695
  os << " [";
696 697 698 699
  if (obj->HasFastProperties()) {
    os << "FastProperties";
  } else {
    os << "DictionaryProperties";
700
  }
701
  PrototypeIterator iter(isolate, obj);
702 703
  os << "]\n - prototype: " << Brief(iter.GetCurrent());
  os << "\n - elements: " << Brief(obj->elements()) << " ["
704
     << ElementsKindToString(obj->map()->elements_kind());
705
  if (obj->elements()->IsCowArray()) os << " (COW)";
706
  os << "]";
707
  Object hash = obj->GetHash();
708
  if (hash->IsSmi()) {
709
    os << "\n - hash: " << Brief(hash);
710
  }
711
  if (obj->GetEmbedderFieldCount() > 0) {
712
    os << "\n - embedder fields: " << obj->GetEmbedderFieldCount();
713
  }
714 715
}

716
static void JSObjectPrintBody(std::ostream& os,
717
                              JSObject obj,  // NOLINT
718
                              bool print_elements = true) {
719
  os << "\n - properties: ";
720
  Object properties_or_hash = obj->raw_properties_or_hash();
721 722 723 724
  if (!properties_or_hash->IsSmi()) {
    os << Brief(properties_or_hash);
  }
  os << " {";
725 726
  if (obj->PrintProperties(os)) os << "\n ";
  os << "}\n";
727
  if (print_elements && obj->elements()->length() > 0) {
728
    obj->PrintElements(os);
729
  }
730 731
  int embedder_fields = obj->GetEmbedderFieldCount();
  if (embedder_fields > 0) {
732
    os << " - embedder fields = {";
733
    for (int i = 0; i < embedder_fields; i++) {
734
      os << "\n    ";
735
      PrintEmbedderData(os, EmbedderDataSlot(obj, i));
736 737 738
    }
    os << "\n }\n";
  }
739 740
}

741
void JSObject::JSObjectPrint(std::ostream& os) {  // NOLINT
742 743
  JSObjectPrintHeader(os, *this, nullptr);
  JSObjectPrintBody(os, *this);
744 745
}

746
void JSGeneratorObject::JSGeneratorObjectPrint(std::ostream& os) {  // NOLINT
747
  JSObjectPrintHeader(os, *this, "JSGeneratorObject");
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
  os << "\n - function: " << Brief(function());
  os << "\n - context: " << Brief(context());
  os << "\n - receiver: " << Brief(receiver());
  if (is_executing() || is_closed()) {
    os << "\n - input: " << Brief(input_or_debug_pos());
  } else {
    DCHECK(is_suspended());
    os << "\n - debug pos: " << Brief(input_or_debug_pos());
  }
  const char* mode = "(invalid)";
  switch (resume_mode()) {
    case kNext:
      mode = ".next()";
      break;
    case kReturn:
      mode = ".return()";
      break;
    case kThrow:
      mode = ".throw()";
      break;
  }
  os << "\n - resume mode: " << mode;
  os << "\n - continuation: " << continuation();
  if (is_closed()) os << " (closed)";
  if (is_executing()) os << " (executing)";
  if (is_suspended()) os << " (suspended)";
  if (is_suspended()) {
    DisallowHeapAllocation no_gc;
776
    SharedFunctionInfo fun_info = function()->shared();
777
    if (fun_info->HasSourceCode()) {
778
      Script script = Script::cast(fun_info->script());
779 780
      int lin = script->GetLineNumber(source_position()) + 1;
      int col = script->GetColumnNumber(source_position()) + 1;
781 782 783
      String script_name = script->name()->IsString()
                               ? String::cast(script->name())
                               : GetReadOnlyRoots().empty_string();
784 785 786 787 788 789 790 791
      os << "\n - source position: " << source_position();
      os << " (";
      script_name->PrintUC16(os);
      os << ", lin " << lin;
      os << ", col " << col;
      os << ")";
    }
  }
792
  os << "\n - register file: " << Brief(parameters_and_registers());
793
  JSObjectPrintBody(os, *this);
794 795
}

796
void JSArray::JSArrayPrint(std::ostream& os) {  // NOLINT
797
  JSObjectPrintHeader(os, *this, "JSArray");
798
  os << "\n - length: " << Brief(this->length());
799
  JSObjectPrintBody(os, *this);
800 801
}

802
void JSPromise::JSPromisePrint(std::ostream& os) {  // NOLINT
803
  JSObjectPrintHeader(os, *this, "JSPromise");
804
  os << "\n - status: " << JSPromise::Status(status());
805
  if (status() == Promise::kPending) {
806
    os << "\n - reactions: " << Brief(reactions());
807
  } else {
808
    os << "\n - result: " << Brief(result());
809
  }
810
  os << "\n - has_handler: " << has_handler();
811
  JSObjectPrintBody(os, *this);
812
}
813

814
void JSRegExp::JSRegExpPrint(std::ostream& os) {  // NOLINT
815
  JSObjectPrintHeader(os, *this, "JSRegExp");
816 817
  os << "\n - data: " << Brief(data());
  os << "\n - source: " << Brief(source());
818
  JSObjectPrintBody(os, *this);
819 820
}

821 822
void JSRegExpStringIterator::JSRegExpStringIteratorPrint(
    std::ostream& os) {  // NOLINT
823
  JSObjectPrintHeader(os, *this, "JSRegExpStringIterator");
824 825 826 827 828
  os << "\n - regex: " << Brief(iterating_regexp());
  os << "\n - string: " << Brief(iterating_string());
  os << "\n - done: " << done();
  os << "\n - global: " << global();
  os << "\n - unicode: " << unicode();
829
  JSObjectPrintBody(os, *this);
830
}
831

832
void Symbol::SymbolPrint(std::ostream& os) {  // NOLINT
833
  PrintHeader(os, "Symbol");
834
  os << "\n - hash: " << Hash();
835
  os << "\n - name: " << Brief(name());
836 837
  if (name()->IsUndefined()) {
    os << " (" << PrivateSymbolToName() << ")";
838
  }
839
  os << "\n - private: " << is_private();
840 841
}

842

843
void DescriptorArray::DescriptorArrayPrint(std::ostream& os) {
844
  PrintHeader(os, "DescriptorArray");
845
  os << "\n - enum_cache: ";
846
  if (enum_cache()->keys()->length() == 0) {
847 848
    os << "empty";
  } else {
849 850 851
    os << enum_cache()->keys()->length();
    os << "\n   - keys: " << Brief(enum_cache()->keys());
    os << "\n   - indices: " << Brief(enum_cache()->indices());
852
  }
853
  os << "\n - nof slack descriptors: " << number_of_slack_descriptors();
854
  os << "\n - nof descriptors: " << number_of_descriptors();
855 856 857 858
  int16_t raw_marked = raw_number_of_marked_descriptors();
  os << "\n - raw marked descriptors: mc epoch "
     << NumberOfMarkedDescriptors::Epoch::decode(raw_marked) << ", marked "
     << NumberOfMarkedDescriptors::Marked::decode(raw_marked);
859 860
  PrintDescriptors(os);
}
861

862 863
void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(
    std::ostream& os) {  // NOLINT
864
  PrintHeader(os, "AliasedArgumentsEntry");
865
  os << "\n - aliased_context_slot: " << aliased_context_slot();
866 867
}

868
namespace {
869
void PrintFixedArrayWithHeader(std::ostream& os, FixedArray array,
870 871 872 873 874 875
                               const char* type) {
  array->PrintHeader(os, type);
  os << "\n - length: " << array->length();
  PrintFixedArrayElements(os, array);
  os << "\n";
}
876

877
template <typename T>
878
void PrintHashTableWithHeader(std::ostream& os, T table, const char* type) {
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893
  table->PrintHeader(os, type);
  os << "\n - length: " << table->length();
  os << "\n - elements: " << table->NumberOfElements();
  os << "\n - deleted: " << table->NumberOfDeletedElements();
  os << "\n - capacity: " << table->Capacity();

  os << "\n - elements: {";
  for (int i = 0; i < table->Capacity(); i++) {
    os << '\n'
       << std::setw(12) << i << ": " << Brief(table->KeyAt(i)) << " -> "
       << Brief(table->ValueAt(i));
  }
  os << "\n }\n";
}

894 895
template <typename T>
void PrintWeakArrayElements(std::ostream& os, T* array) {
896
  // Print in array notation for non-sparse arrays.
897 898 899
  MaybeObject previous_value =
      array->length() > 0 ? array->Get(0) : MaybeObject(kNullAddress);
  MaybeObject value;
900 901 902 903 904 905 906 907 908 909 910 911 912
  int previous_index = 0;
  int i;
  for (i = 1; i <= array->length(); i++) {
    if (i < array->length()) value = array->Get(i);
    if (previous_value == value && i != array->length()) {
      continue;
    }
    os << "\n";
    std::stringstream ss;
    ss << previous_index;
    if (previous_index != i - 1) {
      ss << '-' << (i - 1);
    }
913
    os << std::setw(12) << ss.str() << ": " << Brief(previous_value);
914 915 916 917 918
    previous_index = i;
    previous_value = value;
  }
}

919
}  // namespace
920

921 922 923
void EmbedderDataArray::EmbedderDataArrayPrint(std::ostream& os) {
  PrintHeader(os, "EmbedderDataArray");
  os << "\n - length: " << length();
924 925 926
  EmbedderDataSlot start(*this, 0);
  EmbedderDataSlot end(*this, length());
  for (EmbedderDataSlot slot = start; slot < end; ++slot) {
927 928 929 930 931 932 933
    os << "\n    ";
    PrintEmbedderData(os, slot);
  }
  os << "\n";
}

void FixedArray::FixedArrayPrint(std::ostream& os) {
934
  PrintFixedArrayWithHeader(os, *this, "FixedArray");
935
}
936

937 938 939 940 941 942 943 944 945 946 947 948 949 950
namespace {
void PrintContextWithHeader(std::ostream& os, Context context,
                            const char* type) {
  context->PrintHeader(os, type);
  os << "\n - length: " << context->length();
  os << "\n - scope_info: " << Brief(context->scope_info());
  os << "\n - previous: " << Brief(context->previous());
  os << "\n - extension_object: " << Brief(context->extension_object());
  os << "\n - native_context: " << Brief(context->native_context());
  PrintFixedArrayElements(os, context);
  os << "\n";
}
}  // namespace

951
void Context::ContextPrint(std::ostream& os) {
952
  PrintContextWithHeader(os, *this, "Context");
953 954 955
}

void NativeContext::NativeContextPrint(std::ostream& os) {
956
  PrintContextWithHeader(os, *this, "NativeContext");
957 958 959
  os << " - microtask_queue: " << microtask_queue() << "\n";
}

960
void ObjectHashTable::ObjectHashTablePrint(std::ostream& os) {
961
  PrintHashTableWithHeader(os, *this, "ObjectHashTable");
962
}
963

964
void NumberDictionary::NumberDictionaryPrint(std::ostream& os) {
965
  PrintHashTableWithHeader(os, *this, "NumberDictionary");
966 967
}

968
void EphemeronHashTable::EphemeronHashTablePrint(std::ostream& os) {
969
  PrintHashTableWithHeader(os, *this, "EphemeronHashTable");
970 971
}

972 973
void ObjectBoilerplateDescription::ObjectBoilerplateDescriptionPrint(
    std::ostream& os) {
974
  PrintFixedArrayWithHeader(os, *this, "ObjectBoilerplateDescription");
975 976
}

977
void PropertyArray::PropertyArrayPrint(std::ostream& os) {  // NOLINT
978
  PrintHeader(os, "PropertyArray");
979
  os << "\n - length: " << length();
980
  os << "\n - hash: " << Hash();
981
  PrintFixedArrayElements(os, *this);
982 983
  os << "\n";
}
984

985
void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) {  // NOLINT
986
  PrintHeader(os, "FixedDoubleArray");
987
  os << "\n - length: " << length();
988
  DoPrintElements<FixedDoubleArray>(os, *this);
989
  os << "\n";
990 991
}

992
void WeakFixedArray::WeakFixedArrayPrint(std::ostream& os) {
993 994 995 996
  PrintHeader(os, "WeakFixedArray");
  os << "\n - length: " << length() << "\n";
  PrintWeakArrayElements(os, this);
  os << "\n";
997
}
998

999
void WeakArrayList::WeakArrayListPrint(std::ostream& os) {
1000 1001 1002 1003 1004
  PrintHeader(os, "WeakArrayList");
  os << "\n - capacity: " << capacity();
  os << "\n - length: " << length() << "\n";
  PrintWeakArrayElements(os, this);
  os << "\n";
1005 1006
}

1007
void TransitionArray::TransitionArrayPrint(std::ostream& os) {  // NOLINT
1008
  PrintHeader(os, "TransitionArray");
1009
  PrintInternal(os);
1010 1011
}

1012
void FeedbackCell::FeedbackCellPrint(std::ostream& os) {  // NOLINT
1013
  PrintHeader(os, "FeedbackCell");
1014 1015
  ReadOnlyRoots roots = GetReadOnlyRoots();
  if (map() == roots.no_closures_cell_map()) {
1016
    os << "\n - no closures";
1017
  } else if (map() == roots.one_closure_cell_map()) {
1018
    os << "\n - one closure";
1019
  } else if (map() == roots.many_closures_cell_map()) {
1020 1021 1022 1023 1024 1025 1026 1027
    os << "\n - many closures";
  } else {
    os << "\n - Invalid FeedbackCell map";
  }
  os << " - value: " << Brief(value());
  os << "\n";
}

1028
void FeedbackVectorSpec::Print() {
1029
  StdoutStream os;
1030

1031
  FeedbackVectorSpecPrint(os);
1032

1033 1034 1035
  os << std::flush;
}

1036 1037
void FeedbackVectorSpec::FeedbackVectorSpecPrint(std::ostream& os) {  // NOLINT
  int slot_count = slots();
1038 1039 1040 1041 1042 1043
  os << " - slot_count: " << slot_count;
  if (slot_count == 0) {
    os << " (empty)\n";
    return;
  }

1044
  for (int slot = 0; slot < slot_count;) {
1045
    FeedbackSlotKind kind = GetKind(FeedbackSlot(slot));
1046
    int entry_size = FeedbackMetadata::GetSlotSize(kind);
1047 1048 1049 1050 1051 1052
    DCHECK_LT(0, entry_size);
    os << "\n Slot #" << slot << " " << kind;
    slot += entry_size;
  }
  os << "\n";
}
1053

1054
void FeedbackMetadata::FeedbackMetadataPrint(std::ostream& os) {
1055
  PrintHeader(os, "FeedbackMetadata");
1056
  os << "\n - slot_count: " << slot_count();
1057

1058
  FeedbackMetadataIterator iter(*this);
1059
  while (iter.HasNext()) {
1060 1061
    FeedbackSlot slot = iter.Next();
    FeedbackSlotKind kind = iter.kind();
1062 1063 1064 1065 1066
    os << "\n Slot " << slot << " " << kind;
  }
  os << "\n";
}

1067
void FeedbackVector::FeedbackVectorPrint(std::ostream& os) {  // NOLINT
1068
  PrintHeader(os, "FeedbackVector");
1069
  os << "\n - length: " << length();
1070 1071 1072 1073 1074
  if (length() == 0) {
    os << " (empty)\n";
    return;
  }

1075 1076
  os << "\n - shared function info: " << Brief(shared_function_info());
  os << "\n - optimized code/marker: ";
1077 1078 1079 1080 1081
  if (has_optimized_code()) {
    os << Brief(optimized_code());
  } else {
    os << optimization_marker();
  }
1082 1083
  os << "\n - invocation count: " << invocation_count();
  os << "\n - profiler ticks: " << profiler_ticks();
1084

1085
  FeedbackMetadataIterator iter(metadata());
1086
  while (iter.HasNext()) {
1087 1088
    FeedbackSlot slot = iter.Next();
    FeedbackSlotKind kind = iter.kind();
1089

1090
    os << "\n - slot " << slot << " " << kind << " ";
1091
    FeedbackSlotPrint(os, slot);
1092

1093
    int entry_size = iter.entry_size();
1094
    if (entry_size > 0) os << " {";
1095 1096
    for (int i = 0; i < entry_size; i++) {
      int index = GetIndex(slot) + i;
1097
      os << "\n     [" << index << "]: " << Brief(get(index));
1098
    }
1099
    if (entry_size > 0) os << "\n  }";
1100 1101 1102 1103
  }
  os << "\n";
}

1104 1105
void FeedbackVector::FeedbackSlotPrint(std::ostream& os,
                                       FeedbackSlot slot) {  // NOLINT
1106
  FeedbackNexus nexus(*this, slot);
1107
  nexus.Print(os);
1108 1109
}

1110 1111 1112 1113 1114
void FeedbackNexus::Print(std::ostream& os) {  // NOLINT
  switch (kind()) {
    case FeedbackSlotKind::kCall:
    case FeedbackSlotKind::kLoadProperty:
    case FeedbackSlotKind::kLoadKeyed:
1115
    case FeedbackSlotKind::kLoadGlobalInsideTypeof:
1116
    case FeedbackSlotKind::kLoadGlobalNotInsideTypeof:
1117 1118 1119 1120
    case FeedbackSlotKind::kStoreNamedSloppy:
    case FeedbackSlotKind::kStoreNamedStrict:
    case FeedbackSlotKind::kStoreOwnNamed:
    case FeedbackSlotKind::kStoreGlobalSloppy:
1121
    case FeedbackSlotKind::kStoreGlobalStrict:
1122
    case FeedbackSlotKind::kStoreKeyedSloppy:
1123 1124
    case FeedbackSlotKind::kInstanceOf:
    case FeedbackSlotKind::kStoreDataPropertyInLiteral:
1125
    case FeedbackSlotKind::kStoreKeyedStrict:
1126 1127
    case FeedbackSlotKind::kStoreInArrayLiteral:
    case FeedbackSlotKind::kCloneObject: {
1128
      os << InlineCacheState2String(StateFromFeedback());
1129 1130 1131
      break;
    }
    case FeedbackSlotKind::kBinaryOp: {
1132
      os << "BinaryOp:" << GetBinaryOperationFeedback();
1133 1134 1135
      break;
    }
    case FeedbackSlotKind::kCompareOp: {
1136
      os << "CompareOp:" << GetCompareOperationFeedback();
1137 1138 1139
      break;
    }
    case FeedbackSlotKind::kForIn: {
1140
      os << "ForIn:" << GetForInFeedback();
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
      break;
    }
    case FeedbackSlotKind::kCreateClosure:
    case FeedbackSlotKind::kLiteral:
    case FeedbackSlotKind::kTypeProfile:
      break;
    case FeedbackSlotKind::kInvalid:
    case FeedbackSlotKind::kKindsNumber:
      UNREACHABLE();
      break;
  }
}
1153

1154
void JSValue::JSValuePrint(std::ostream& os) {  // NOLINT
1155
  JSObjectPrintHeader(os, *this, "JSValue");
1156
  os << "\n - value: " << Brief(value());
1157
  JSObjectPrintBody(os, *this);
1158 1159
}

1160
void JSMessageObject::JSMessageObjectPrint(std::ostream& os) {  // NOLINT
1161
  JSObjectPrintHeader(os, *this, "JSMessageObject");
1162
  os << "\n - type: " << static_cast<int>(type());
1163
  os << "\n - arguments: " << Brief(argument());
1164 1165 1166 1167
  os << "\n - start_position: " << start_position();
  os << "\n - end_position: " << end_position();
  os << "\n - script: " << Brief(script());
  os << "\n - stack_frames: " << Brief(stack_frames());
1168
  JSObjectPrintBody(os, *this);
1169 1170 1171
}


1172
void String::StringPrint(std::ostream& os) {  // NOLINT
1173 1174 1175
  if (!HasOnlyOneByteChars()) {
    os << "u";
  }
1176
  if (StringShape(*this).IsInternalized()) {
1177
    os << "#";
1178
  } else if (StringShape(*this).IsCons()) {
1179
    os << "c\"";
1180
  } else if (StringShape(*this).IsThin()) {
1181
    os << ">\"";
1182
  } else {
1183
    os << "\"";
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
  }

  const char truncated_epilogue[] = "...<truncated>";
  int len = length();
  if (!FLAG_use_verbose_printer) {
    if (len > 100) {
      len = 100 - sizeof(truncated_epilogue);
    }
  }
  for (int i = 0; i < len; i++) {
1194
    os << AsUC16(Get(i));
1195 1196
  }
  if (len != length()) {
1197
    os << truncated_epilogue;
1198 1199
  }

1200
  if (!StringShape(*this).IsInternalized()) os << "\"";
1201 1202 1203
}


1204
void Name::NamePrint(std::ostream& os) {  // NOLINT
1205
  if (IsString()) {
1206
    String::cast(*this)->StringPrint(os);
1207
  } else {
1208
    os << Brief(*this);
1209
  }
1210 1211 1212
}


1213 1214 1215 1216
static const char* const weekdays[] = {
  "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};

1217
void JSDate::JSDatePrint(std::ostream& os) {  // NOLINT
1218
  JSObjectPrintHeader(os, *this, "JSDate");
1219
  os << "\n - value: " << Brief(value());
1220
  if (!year()->IsSmi()) {
1221
    os << "\n - time = NaN\n";
1222
  } else {
1223
    // TODO(svenpanne) Add some basic formatting to our streams.
1224
    ScopedVector<char> buf(100);
jgruber's avatar
jgruber committed
1225 1226 1227 1228 1229 1230 1231 1232
    SNPrintF(buf, "\n - time = %s %04d/%02d/%02d %02d:%02d:%02d\n",
             weekdays[weekday()->IsSmi() ? Smi::ToInt(weekday()) + 1 : 0],
             year()->IsSmi() ? Smi::ToInt(year()) : -1,
             month()->IsSmi() ? Smi::ToInt(month()) : -1,
             day()->IsSmi() ? Smi::ToInt(day()) : -1,
             hour()->IsSmi() ? Smi::ToInt(hour()) : -1,
             min()->IsSmi() ? Smi::ToInt(min()) : -1,
             sec()->IsSmi() ? Smi::ToInt(sec()) : -1);
1233
    os << buf.start();
1234
  }
1235
  JSObjectPrintBody(os, *this);
1236 1237 1238
}


1239
void JSProxy::JSProxyPrint(std::ostream& os) {  // NOLINT
1240
  PrintHeader(os, "JSProxy");
1241
  os << "\n - target: ";
1242
  target()->ShortPrint(os);
1243
  os << "\n - handler: ";
1244
  handler()->ShortPrint(os);
1245
  os << "\n";
1246 1247
}

1248
void JSSet::JSSetPrint(std::ostream& os) {  // NOLINT
1249
  JSObjectPrintHeader(os, *this, "JSSet");
1250
  os << " - table: " << Brief(table());
1251
  JSObjectPrintBody(os, *this);
1252 1253
}

1254
void JSMap::JSMapPrint(std::ostream& os) {  // NOLINT
1255
  JSObjectPrintHeader(os, *this, "JSMap");
1256
  os << " - table: " << Brief(table());
1257
  JSObjectPrintBody(os, *this);
1258 1259
}

1260
void JSCollectionIterator::JSCollectionIteratorPrint(
1261
    std::ostream& os, const char* name) {  // NOLINT
1262
  JSObjectPrintHeader(os, *this, name);
1263 1264
  os << "\n - table: " << Brief(table());
  os << "\n - index: " << Brief(index());
1265
  JSObjectPrintBody(os, *this);
1266 1267
}

1268
void JSSetIterator::JSSetIteratorPrint(std::ostream& os) {  // NOLINT
1269
  JSCollectionIteratorPrint(os, "JSSetIterator");
1270 1271
}

1272
void JSMapIterator::JSMapIteratorPrint(std::ostream& os) {  // NOLINT
1273
  JSCollectionIteratorPrint(os, "JSMapIterator");
1274 1275
}

1276
void JSWeakCell::JSWeakCellPrint(std::ostream& os) {
1277
  JSObjectPrintHeader(os, *this, "JSWeakCell");
1278 1279
  os << "\n - factory: " << Brief(factory());
  os << "\n - target: " << Brief(target());
1280
  os << "\n - holdings: " << Brief(holdings());
1281 1282
  os << "\n - prev: " << Brief(prev());
  os << "\n - next: " << Brief(next());
1283
  JSObjectPrintBody(os, *this);
1284 1285
}

1286 1287 1288 1289 1290 1291
void JSWeakRef::JSWeakRefPrint(std::ostream& os) {
  JSObjectPrintHeader(os, *this, "JSWeakRef");
  os << "\n - target: " << Brief(target());
  JSObjectPrintBody(os, *this);
}

1292
void JSWeakFactory::JSWeakFactoryPrint(std::ostream& os) {
1293
  JSObjectPrintHeader(os, *this, "JSWeakFactory");
1294
  os << "\n - native_context: " << Brief(native_context());
1295 1296 1297
  os << "\n - cleanup: " << Brief(cleanup());
  os << "\n - active_cells: " << Brief(active_cells());
  os << "\n - cleared_cells: " << Brief(cleared_cells());
1298
  JSObjectPrintBody(os, *this);
1299 1300 1301 1302
}

void JSWeakFactoryCleanupIterator::JSWeakFactoryCleanupIteratorPrint(
    std::ostream& os) {
1303
  JSObjectPrintHeader(os, *this, "JSWeakFactoryCleanupIterator");
1304
  os << "\n - factory: " << Brief(factory());
1305
  JSObjectPrintBody(os, *this);
1306 1307
}

1308 1309
void WeakFactoryCleanupJobTask::WeakFactoryCleanupJobTaskPrint(
    std::ostream& os) {
1310
  PrintHeader(os, "WeakFactoryCleanupJobTask");
1311 1312 1313
  os << "\n - factory: " << Brief(factory());
}

1314
void JSWeakMap::JSWeakMapPrint(std::ostream& os) {  // NOLINT
1315
  JSObjectPrintHeader(os, *this, "JSWeakMap");
1316
  os << "\n - table: " << Brief(table());
1317
  JSObjectPrintBody(os, *this);
1318 1319
}

1320
void JSWeakSet::JSWeakSetPrint(std::ostream& os) {  // NOLINT
1321
  JSObjectPrintHeader(os, *this, "JSWeakSet");
1322
  os << "\n - table: " << Brief(table());
1323
  JSObjectPrintBody(os, *this);
1324 1325
}

1326
void JSArrayBuffer::JSArrayBufferPrint(std::ostream& os) {  // NOLINT
1327
  JSObjectPrintHeader(os, *this, "JSArrayBuffer");
1328
  os << "\n - backing_store: " << backing_store();
1329
  os << "\n - byte_length: " << byte_length();
1330
  if (is_external()) os << "\n - external";
1331 1332
  if (is_detachable()) os << "\n - detachable";
  if (was_detached()) os << "\n - detached";
1333
  if (is_shared()) os << "\n - shared";
1334
  if (is_wasm_memory()) os << "\n - is_wasm_memory";
1335
  if (is_growable()) os << "\n - growable";
1336
  JSObjectPrintBody(os, *this, !was_detached());
1337 1338
}

1339
void JSTypedArray::JSTypedArrayPrint(std::ostream& os) {  // NOLINT
1340
  JSObjectPrintHeader(os, *this, "JSTypedArray");
1341
  os << "\n - buffer: " << Brief(buffer());
1342 1343
  os << "\n - byte_offset: " << byte_offset();
  os << "\n - byte_length: " << byte_length();
1344
  os << "\n - length: " << Brief(length());
1345 1346
  if (WasDetached()) os << "\n - detached";
  JSObjectPrintBody(os, *this, !WasDetached());
1347 1348
}

1349
void JSArrayIterator::JSArrayIteratorPrint(std::ostream& os) {  // NOLING
1350
  JSObjectPrintHeader(os, *this, "JSArrayIterator");
1351 1352 1353
  os << "\n - iterated_object: " << Brief(iterated_object());
  os << "\n - next_index: " << Brief(next_index());
  os << "\n - kind: " << kind();
1354
  JSObjectPrintBody(os, *this);
1355 1356
}

1357
void JSDataView::JSDataViewPrint(std::ostream& os) {  // NOLINT
1358
  JSObjectPrintHeader(os, *this, "JSDataView");
1359
  os << "\n - buffer =" << Brief(buffer());
1360 1361
  os << "\n - byte_offset: " << byte_offset();
  os << "\n - byte_length: " << byte_length();
1362 1363
  if (WasDetached()) os << "\n - detached";
  JSObjectPrintBody(os, *this, !WasDetached());
1364 1365
}

1366
void JSBoundFunction::JSBoundFunctionPrint(std::ostream& os) {  // NOLINT
1367
  JSObjectPrintHeader(os, *this, "JSBoundFunction");
1368 1369 1370
  os << "\n - bound_target_function: " << Brief(bound_target_function());
  os << "\n - bound_this: " << Brief(bound_this());
  os << "\n - bound_arguments: " << Brief(bound_arguments());
1371
  JSObjectPrintBody(os, *this);
1372 1373
}

1374 1375
void JSFunction::JSFunctionPrint(std::ostream& os) {  // NOLINT
  Isolate* isolate = GetIsolate();
1376
  JSObjectPrintHeader(os, *this, "Function");
1377
  os << "\n - function prototype: ";
1378 1379 1380 1381 1382 1383 1384
  if (has_prototype_slot()) {
    if (has_prototype()) {
      os << Brief(prototype());
      if (map()->has_non_instance_prototype()) {
        os << " (non-instance prototype)";
      }
    }
1385
    os << "\n - initial_map: ";
1386 1387 1388 1389
    if (has_initial_map()) os << Brief(initial_map());
  } else {
    os << "<no-prototype-slot>";
  }
1390
  os << "\n - shared_info: " << Brief(shared());
1391
  os << "\n - name: " << Brief(shared()->Name());
1392 1393 1394

  // Print Builtin name for builtin functions
  int builtin_index = code()->builtin_index();
1395 1396
  if (Builtins::IsBuiltinId(builtin_index) && !IsInterpreted()) {
    os << "\n - builtin: " << isolate->builtins()->name(builtin_index);
1397 1398
  }

1399
  os << "\n - formal_parameter_count: "
1400
     << shared()->internal_formal_parameter_count();
1401 1402 1403
  os << "\n - kind: " << shared()->kind();
  os << "\n - context: " << Brief(context());
  os << "\n - code: " << Brief(code());
1404 1405 1406
  if (IsInterpreted()) {
    os << "\n - interpreted";
    if (shared()->HasBytecodeArray()) {
1407
      os << "\n - bytecode: " << shared()->GetBytecodeArray();
1408 1409
    }
  }
1410 1411
  if (WasmExportedFunction::IsWasmExportedFunction(*this)) {
    WasmExportedFunction function = WasmExportedFunction::cast(*this);
1412
    os << "\n - WASM instance "
1413
       << reinterpret_cast<void*>(function->instance()->ptr());
1414 1415
    os << "\n - WASM function index " << function->function_index();
  }
1416
  shared()->PrintSourceCode(os);
1417
  JSObjectPrintBody(os, *this);
1418
  os << "\n - feedback vector: ";
1419 1420 1421
  if (!shared()->HasFeedbackMetadata()) {
    os << "feedback metadata is not available in SFI\n";
  } else if (has_feedback_vector()) {
1422 1423 1424 1425
    feedback_vector()->FeedbackVectorPrint(os);
  } else {
    os << "not available\n";
  }
1426 1427
}

1428 1429
void SharedFunctionInfo::PrintSourceCode(std::ostream& os) {
  if (HasSourceCode()) {
1430
    os << "\n - source code: ";
1431
    String source = String::cast(Script::cast(script())->source());
1432 1433
    int start = StartPosition();
    int length = EndPosition() - start;
1434
    std::unique_ptr<char[]> source_string = source->ToCString(
1435
        DISALLOW_NULLS, FAST_STRING_TRAVERSAL, start, length, nullptr);
1436 1437 1438 1439
    os << source_string.get();
  }
}

1440
void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) {  // NOLINT
1441
  PrintHeader(os, "SharedFunctionInfo");
1442
  os << "\n - name: ";
1443 1444
  if (HasSharedName()) {
    os << Brief(Name());
1445 1446 1447
  } else {
    os << "<no-shared-name>";
  }
1448 1449 1450
  if (HasInferredName()) {
    os << "\n - inferred name: " << Brief(inferred_name());
  }
1451
  os << "\n - kind: " << kind();
1452 1453 1454
  if (needs_home_object()) {
    os << "\n - needs_home_object";
  }
1455 1456 1457 1458
  os << "\n - function_map_index: " << function_map_index();
  os << "\n - formal_parameter_count: " << internal_formal_parameter_count();
  os << "\n - expected_nof_properties: " << expected_nof_properties();
  os << "\n - language_mode: " << language_mode();
1459 1460
  os << "\n - data: " << Brief(function_data());
  os << "\n - code (from data): " << Brief(GetCode());
1461
  PrintSourceCode(os);
1462
  // Script files are often large, hard to read.
1463 1464
  // os << "\n - script =";
  // script()->Print(os);
1465 1466 1467 1468 1469 1470 1471
  if (is_named_expression()) {
    os << "\n - named expression";
  } else if (is_anonymous_expression()) {
    os << "\n - anonymous expression";
  } else if (is_declaration()) {
    os << "\n - declaration";
  }
1472
  os << "\n - function token position: " << function_token_position();
1473 1474
  os << "\n - start position: " << StartPosition();
  os << "\n - end position: " << EndPosition();
1475
  if (HasDebugInfo()) {
1476
    os << "\n - debug info: " << Brief(GetDebugInfo());
1477 1478 1479
  } else {
    os << "\n - no debug info";
  }
1480
  os << "\n - scope info: " << Brief(scope_info());
1481 1482 1483
  if (HasOuterScopeInfo()) {
    os << "\n - outer scope info: " << Brief(GetOuterScopeInfo());
  }
1484 1485
  os << "\n - length: " << length();
  os << "\n - feedback_metadata: ";
1486 1487 1488 1489 1490
  if (HasFeedbackMetadata()) {
    feedback_metadata()->FeedbackMetadataPrint(os);
  } else {
    os << "<none>";
  }
1491
  os << "\n";
1492 1493
}

1494
void JSGlobalProxy::JSGlobalProxyPrint(std::ostream& os) {  // NOLINT
1495
  JSObjectPrintHeader(os, *this, "JSGlobalProxy");
1496
  if (!GetIsolate()->bootstrapper()->IsActive()) {
1497
    os << "\n - native context: " << Brief(native_context());
1498
  }
1499
  JSObjectPrintBody(os, *this);
1500 1501
}

1502
void JSGlobalObject::JSGlobalObjectPrint(std::ostream& os) {  // NOLINT
1503
  JSObjectPrintHeader(os, *this, "JSGlobalObject");
1504
  if (!GetIsolate()->bootstrapper()->IsActive()) {
1505
    os << "\n - native context: " << Brief(native_context());
1506
  }
1507
  os << "\n - global proxy: " << Brief(global_proxy());
1508
  JSObjectPrintBody(os, *this);
1509 1510
}

1511
void Cell::CellPrint(std::ostream& os) {  // NOLINT
1512
  PrintHeader(os, "Cell");
1513
  os << "\n - value: " << Brief(value());
1514
  os << "\n";
1515 1516
}

1517
void PropertyCell::PropertyCellPrint(std::ostream& os) {  // NOLINT
1518
  PrintHeader(os, "PropertyCell");
1519 1520
  os << "\n - name: ";
  name()->NamePrint(os);
1521
  os << "\n - value: " << Brief(value());
1522 1523
  os << "\n - details: ";
  property_details().PrintAsSlowTo(os);
1524 1525
  PropertyCellType cell_type = property_details().cell_type();
  os << "\n - cell_type: ";
1526
  if (value()->IsTheHole()) {
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
    switch (cell_type) {
      case PropertyCellType::kUninitialized:
        os << "Uninitialized";
        break;
      case PropertyCellType::kInvalidated:
        os << "Invalidated";
        break;
      default:
        os << "??? " << static_cast<int>(cell_type);
        break;
    }
  } else {
    switch (cell_type) {
      case PropertyCellType::kUndefined:
        os << "Undefined";
        break;
      case PropertyCellType::kConstant:
        os << "Constant";
        break;
      case PropertyCellType::kConstantType:
        os << "ConstantType"
           << " (";
        switch (GetConstantType()) {
          case PropertyCellConstantType::kSmi:
            os << "Smi";
            break;
          case PropertyCellConstantType::kStableMap:
            os << "StableMap";
            break;
        }
        os << ")";
        break;
      case PropertyCellType::kMutable:
        os << "Mutable";
        break;
    }
  }
1564
  os << "\n";
1565 1566
}

1567
void Code::CodePrint(std::ostream& os) {  // NOLINT
1568
  PrintHeader(os, "Code");
1569
  os << "\n";
1570 1571
#ifdef ENABLE_DISASSEMBLER
  if (FLAG_use_verbose_printer) {
1572
    Disassemble(nullptr, os);
1573 1574 1575 1576
  }
#endif
}

1577
void CodeDataContainer::CodeDataContainerPrint(std::ostream& os) {  // NOLINT
1578
  PrintHeader(os, "CodeDataContainer");
1579 1580 1581
  os << "\n - kind_specific_flags: " << kind_specific_flags();
  os << "\n";
}
1582

1583
void Foreign::ForeignPrint(std::ostream& os) {  // NOLINT
1584
  os << "foreign address : " << reinterpret_cast<void*>(foreign_address());
1585
  os << "\n";
1586 1587 1588
}


1589
void AccessorInfo::AccessorInfoPrint(std::ostream& os) {  // NOLINT
1590
  PrintHeader(os, "AccessorInfo");
1591
  os << "\n - name: " << Brief(name());
1592
  os << "\n - flags: " << flags();
1593 1594
  os << "\n - getter: " << Brief(getter());
  os << "\n - setter: " << Brief(setter());
1595
  os << "\n - js_getter: " << Brief(js_getter());
1596 1597
  os << "\n - data: " << Brief(data());
  os << "\n";
1598 1599
}

1600
void CallbackTask::CallbackTaskPrint(std::ostream& os) {  // NOLINT
1601
  PrintHeader(os, "CallbackTask");
1602 1603 1604 1605 1606 1607
  os << "\n - callback: " << Brief(callback());
  os << "\n - data: " << Brief(data());
  os << "\n";
}

void CallableTask::CallableTaskPrint(std::ostream& os) {  // NOLINT
1608
  PrintHeader(os, "CallableTask");
1609 1610
  os << "\n - context: " << Brief(context());
  os << "\n - callable: " << Brief(callable());
1611 1612 1613
  os << "\n";
}

1614
void PromiseFulfillReactionJobTask::PromiseFulfillReactionJobTaskPrint(
1615
    std::ostream& os) {  // NOLINT
1616
  PrintHeader(os, "PromiseFulfillReactionJobTask");
1617 1618 1619
  os << "\n - argument: " << Brief(argument());
  os << "\n - context: " << Brief(context());
  os << "\n - handler: " << Brief(handler());
1620
  os << "\n - promise_or_capability: " << Brief(promise_or_capability());
1621 1622 1623 1624 1625
  os << "\n";
}

void PromiseRejectReactionJobTask::PromiseRejectReactionJobTaskPrint(
    std::ostream& os) {  // NOLINT
1626
  PrintHeader(os, "PromiseRejectReactionJobTask");
1627 1628 1629
  os << "\n - argument: " << Brief(argument());
  os << "\n - context: " << Brief(context());
  os << "\n - handler: " << Brief(handler());
1630
  os << "\n - promise_or_capability: " << Brief(promise_or_capability());
1631 1632 1633 1634 1635
  os << "\n";
}

void PromiseResolveThenableJobTask::PromiseResolveThenableJobTaskPrint(
    std::ostream& os) {  // NOLINT
1636
  PrintHeader(os, "PromiseResolveThenableJobTask");
1637 1638
  os << "\n - context: " << Brief(context());
  os << "\n - promise_to_resolve: " << Brief(promise_to_resolve());
1639
  os << "\n - then: " << Brief(then());
1640 1641 1642 1643 1644
  os << "\n - thenable: " << Brief(thenable());
  os << "\n";
}

void PromiseCapability::PromiseCapabilityPrint(std::ostream& os) {  // NOLINT
1645
  PrintHeader(os, "PromiseCapability");
1646
  os << "\n - promise: " << Brief(promise());
1647 1648 1649 1650 1651
  os << "\n - resolve: " << Brief(resolve());
  os << "\n - reject: " << Brief(reject());
  os << "\n";
}

1652
void PromiseReaction::PromiseReactionPrint(std::ostream& os) {  // NOLINT
1653
  PrintHeader(os, "PromiseReaction");
1654 1655 1656
  os << "\n - next: " << Brief(next());
  os << "\n - reject_handler: " << Brief(reject_handler());
  os << "\n - fulfill_handler: " << Brief(fulfill_handler());
1657
  os << "\n - promise_or_capability: " << Brief(promise_or_capability());
1658 1659 1660
  os << "\n";
}

1661 1662
void AsyncGeneratorRequest::AsyncGeneratorRequestPrint(
    std::ostream& os) {  // NOLINT
1663
  PrintHeader(os, "AsyncGeneratorRequest");
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681
  const char* mode = "Invalid!";
  switch (resume_mode()) {
    case JSGeneratorObject::kNext:
      mode = ".next()";
      break;
    case JSGeneratorObject::kReturn:
      mode = ".return()";
      break;
    case JSGeneratorObject::kThrow:
      mode = ".throw()";
      break;
  }
  os << "\n - resume mode: " << mode;
  os << "\n - value: " << Brief(value());
  os << "\n - next: " << Brief(next());
  os << "\n";
}

1682
void ModuleInfoEntry::ModuleInfoEntryPrint(std::ostream& os) {  // NOLINT
1683
  PrintHeader(os, "ModuleInfoEntry");
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693
  os << "\n - export_name: " << Brief(export_name());
  os << "\n - local_name: " << Brief(local_name());
  os << "\n - import_name: " << Brief(import_name());
  os << "\n - module_request: " << module_request();
  os << "\n - cell_index: " << cell_index();
  os << "\n - beg_pos: " << beg_pos();
  os << "\n - end_pos: " << end_pos();
  os << "\n";
}

1694
void Module::ModulePrint(std::ostream& os) {  // NOLINT
1695
  PrintHeader(os, "Module");
1696
  os << "\n - origin: " << Brief(script()->GetNameOrSourceURL());
1697
  os << "\n - code: " << Brief(code());
1698
  os << "\n - exports: " << Brief(exports());
1699
  os << "\n - requested_modules: " << Brief(requested_modules());
1700
  os << "\n - script: " << Brief(script());
1701
  os << "\n - import_meta: " << Brief(import_meta());
1702 1703
  os << "\n - status: " << status();
  os << "\n - exception: " << Brief(exception());
1704 1705
  os << "\n";
}
1706

1707
void JSModuleNamespace::JSModuleNamespacePrint(std::ostream& os) {  // NOLINT
1708
  JSObjectPrintHeader(os, *this, "JSModuleNamespace");
1709
  os << "\n - module: " << Brief(module());
1710
  JSObjectPrintBody(os, *this);
1711 1712
}

1713
void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) {  // NOLINT
1714
  PrintHeader(os, "PrototypeInfo");
1715
  os << "\n - module namespace: " << Brief(module_namespace());
1716
  os << "\n - prototype users: " << Brief(prototype_users());
1717
  os << "\n - registry slot: " << registry_slot();
1718
  os << "\n - object create map: " << Brief(object_create_map());
1719
  os << "\n - should_be_fast_map: " << should_be_fast_map();
1720 1721 1722
  os << "\n";
}

1723
void Tuple2::Tuple2Print(std::ostream& os) {  // NOLINT
1724
  PrintHeader(os, "Tuple2");
1725 1726 1727 1728 1729
  os << "\n - value1: " << Brief(value1());
  os << "\n - value2: " << Brief(value2());
  os << "\n";
}

1730
void Tuple3::Tuple3Print(std::ostream& os) {  // NOLINT
1731
  PrintHeader(os, "Tuple3");
1732 1733 1734 1735 1736 1737
  os << "\n - value1: " << Brief(value1());
  os << "\n - value2: " << Brief(value2());
  os << "\n - value3: " << Brief(value3());
  os << "\n";
}

1738 1739
void ArrayBoilerplateDescription::ArrayBoilerplateDescriptionPrint(
    std::ostream& os) {  // NOLINT
1740
  PrintHeader(os, "ArrayBoilerplateDescription");
1741 1742 1743 1744 1745
  os << "\n - elements kind: " << elements_kind();
  os << "\n - constant elements: " << Brief(constant_elements());
  os << "\n";
}

1746
void AsmWasmData::AsmWasmDataPrint(std::ostream& os) {  // NOLINT
1747
  PrintHeader(os, "AsmWasmData");
1748 1749 1750 1751 1752 1753 1754
  os << "\n - native module: " << Brief(managed_native_module());
  os << "\n - export_wrappers: " << Brief(export_wrappers());
  os << "\n - offset table: " << Brief(asm_js_offset_table());
  os << "\n - uses bitset: " << uses_bitset()->value();
  os << "\n";
}

1755
void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) {  // NOLINT
1756
  PrintHeader(os, "WasmDebugInfo");
1757 1758 1759 1760
  os << "\n - wasm_instance: " << Brief(wasm_instance());
  os << "\n";
}

1761
void WasmExceptionTag::WasmExceptionTagPrint(std::ostream& os) {  // NOLINT
1762
  PrintHeader(os, "WasmExceptionTag");
1763 1764 1765 1766
  os << "\n - index: " << index();
  os << "\n";
}

1767
void WasmInstanceObject::WasmInstanceObjectPrint(std::ostream& os) {  // NOLINT
1768
  PrintHeader(os, "WasmInstanceObject");
1769 1770 1771
  os << "\n - module_object: " << Brief(module_object());
  os << "\n - exports_object: " << Brief(exports_object());
  os << "\n - native_context: " << Brief(native_context());
1772 1773 1774
  if (has_memory_object()) {
    os << "\n - memory_object: " << Brief(memory_object());
  }
1775 1776 1777 1778 1779
  if (has_untagged_globals_buffer()) {
    os << "\n - untagged_globals_buffer: " << Brief(untagged_globals_buffer());
  }
  if (has_tagged_globals_buffer()) {
    os << "\n - tagged_globals_buffer: " << Brief(tagged_globals_buffer());
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790
  }
  if (has_imported_mutable_globals_buffers()) {
    os << "\n - imported_mutable_globals_buffers: "
       << Brief(imported_mutable_globals_buffers());
  }
  if (has_debug_info()) {
    os << "\n - debug_info: " << Brief(debug_info());
  }
  if (has_table_object()) {
    os << "\n - table_object: " << Brief(table_object());
  }
1791 1792 1793 1794
  os << "\n - imported_function_refs: " << Brief(imported_function_refs());
  if (has_indirect_function_table_refs()) {
    os << "\n - indirect_function_table_refs: "
       << Brief(indirect_function_table_refs());
1795 1796 1797 1798 1799
  }
  if (has_managed_native_allocations()) {
    os << "\n - managed_native_allocations: "
       << Brief(managed_native_allocations());
  }
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815
  os << "\n - memory_start: " << static_cast<void*>(memory_start());
  os << "\n - memory_size: " << memory_size();
  os << "\n - memory_mask: " << AsHex(memory_mask());
  os << "\n - imported_function_targets: "
     << static_cast<void*>(imported_function_targets());
  os << "\n - globals_start: " << static_cast<void*>(globals_start());
  os << "\n - imported_mutable_globals: "
     << static_cast<void*>(imported_mutable_globals());
  os << "\n - indirect_function_table_size: " << indirect_function_table_size();
  os << "\n - indirect_function_table_sig_ids: "
     << static_cast<void*>(indirect_function_table_sig_ids());
  os << "\n - indirect_function_table_targets: "
     << static_cast<void*>(indirect_function_table_targets());
  os << "\n";
}

1816 1817
void WasmExportedFunctionData::WasmExportedFunctionDataPrint(
    std::ostream& os) {  // NOLINT
1818
  PrintHeader(os, "WasmExportedFunctionData");
1819 1820 1821 1822 1823 1824
  os << "\n - wrapper_code: " << Brief(wrapper_code());
  os << "\n - instance: " << Brief(instance());
  os << "\n - function_index: " << function_index();
  os << "\n";
}

1825
void WasmModuleObject::WasmModuleObjectPrint(std::ostream& os) {  // NOLINT
1826
  PrintHeader(os, "WasmModuleObject");
1827
  os << "\n - module: " << module();
1828 1829 1830
  os << "\n - native module: " << native_module();
  os << "\n - export wrappers: " << Brief(export_wrappers());
  os << "\n - script: " << Brief(script());
1831 1832 1833 1834 1835 1836
  if (has_asm_js_offset_table()) {
    os << "\n - asm_js_offset_table: " << Brief(asm_js_offset_table());
  }
  if (has_breakpoint_infos()) {
    os << "\n - breakpoint_infos: " << Brief(breakpoint_infos());
  }
1837 1838 1839
  os << "\n";
}

1840
void LoadHandler::LoadHandlerPrint(std::ostream& os) {  // NOLINT
1841
  PrintHeader(os, "LoadHandler");
1842 1843 1844
  // TODO(ishell): implement printing based on handler kind
  os << "\n - handler: " << Brief(smi_handler());
  os << "\n - validity_cell: " << Brief(validity_cell());
1845 1846
  int data_count = data_field_count();
  if (data_count >= 1) {
1847
    os << "\n - data1: " << Brief(data1());
1848 1849
  }
  if (data_count >= 2) {
1850
    os << "\n - data2: " << Brief(data2());
1851
  }
1852
  if (data_count >= 3) {
1853
    os << "\n - data3: " << Brief(data3());
1854
  }
1855 1856 1857 1858
  os << "\n";
}

void StoreHandler::StoreHandlerPrint(std::ostream& os) {  // NOLINT
1859
  PrintHeader(os, "StoreHandler");
1860 1861 1862
  // TODO(ishell): implement printing based on handler kind
  os << "\n - handler: " << Brief(smi_handler());
  os << "\n - validity_cell: " << Brief(validity_cell());
1863 1864
  int data_count = data_field_count();
  if (data_count >= 1) {
1865
    os << "\n - data1: " << Brief(data1());
1866 1867
  }
  if (data_count >= 2) {
1868
    os << "\n - data2: " << Brief(data2());
1869
  }
1870
  if (data_count >= 3) {
1871
    os << "\n - data3: " << Brief(data3());
1872
  }
1873 1874 1875
  os << "\n";
}

1876
void AccessorPair::AccessorPairPrint(std::ostream& os) {  // NOLINT
1877
  PrintHeader(os, "AccessorPair");
1878 1879 1880 1881 1882 1883
  os << "\n - getter: " << Brief(getter());
  os << "\n - setter: " << Brief(setter());
  os << "\n";
}


1884
void AccessCheckInfo::AccessCheckInfoPrint(std::ostream& os) {  // NOLINT
1885
  PrintHeader(os, "AccessCheckInfo");
1886
  os << "\n - callback: " << Brief(callback());
1887 1888
  os << "\n - named_interceptor: " << Brief(named_interceptor());
  os << "\n - indexed_interceptor: " << Brief(indexed_interceptor());
1889 1890 1891 1892
  os << "\n - data: " << Brief(data());
  os << "\n";
}

1893
void CallHandlerInfo::CallHandlerInfoPrint(std::ostream& os) {  // NOLINT
1894
  PrintHeader(os, "CallHandlerInfo");
1895 1896 1897 1898
  os << "\n - callback: " << Brief(callback());
  os << "\n - js_callback: " << Brief(js_callback());
  os << "\n - data: " << Brief(data());
  os << "\n - side_effect_free: "
1899
     << (IsSideEffectFreeCallHandlerInfo() ? "true" : "false");
1900 1901
  os << "\n";
}
1902

1903
void InterceptorInfo::InterceptorInfoPrint(std::ostream& os) {  // NOLINT
1904
  PrintHeader(os, "InterceptorInfo");
1905 1906 1907 1908 1909 1910 1911
  os << "\n - getter: " << Brief(getter());
  os << "\n - setter: " << Brief(setter());
  os << "\n - query: " << Brief(query());
  os << "\n - deleter: " << Brief(deleter());
  os << "\n - enumerator: " << Brief(enumerator());
  os << "\n - data: " << Brief(data());
  os << "\n";
1912 1913 1914
}


1915 1916
void FunctionTemplateInfo::FunctionTemplateInfoPrint(
    std::ostream& os) {  // NOLINT
1917
  PrintHeader(os, "FunctionTemplateInfo");
1918 1919
  os << "\n - class name: " << Brief(class_name());
  os << "\n - tag: " << Brief(tag());
1920
  os << "\n - serial_number: " << Brief(serial_number());
1921
  os << "\n - property_list: " << Brief(property_list());
1922 1923 1924
  os << "\n - call_code: " << Brief(call_code());
  os << "\n - property_accessors: " << Brief(property_accessors());
  os << "\n - signature: " << Brief(signature());
1925
  os << "\n - cached_property_name: " << Brief(cached_property_name());
1926 1927 1928
  os << "\n - hidden_prototype: " << (hidden_prototype() ? "true" : "false");
  os << "\n - undetectable: " << (undetectable() ? "true" : "false");
  os << "\n - need_access_check: " << (needs_access_check() ? "true" : "false");
1929
  os << "\n - instantiated: " << (instantiated() ? "true" : "false");
1930
  os << "\n - rare_data: " << Brief(rare_data());
1931 1932 1933
  os << "\n";
}

1934 1935
void FunctionTemplateRareData::FunctionTemplateRareDataPrint(
    std::ostream& os) {  // NOLINT
1936
  PrintHeader(os, "FunctionTemplateRareData");
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947
  os << "\n - prototype_template: " << Brief(prototype_template());
  os << "\n - prototype_provider_template: "
     << Brief(prototype_provider_template());
  os << "\n - parent_template: " << Brief(parent_template());
  os << "\n - named_property_handler: " << Brief(named_property_handler());
  os << "\n - indexed_property_handler: " << Brief(indexed_property_handler());
  os << "\n - instance_template: " << Brief(instance_template());
  os << "\n - instance_call_handler: " << Brief(instance_call_handler());
  os << "\n - access_check_info: " << Brief(access_check_info());
  os << "\n";
}
1948

1949
void ObjectTemplateInfo::ObjectTemplateInfoPrint(std::ostream& os) {  // NOLINT
1950
  PrintHeader(os, "ObjectTemplateInfo");
1951 1952
  os << "\n - tag: " << Brief(tag());
  os << "\n - serial_number: " << Brief(serial_number());
1953 1954 1955
  os << "\n - property_list: " << Brief(property_list());
  os << "\n - property_accessors: " << Brief(property_accessors());
  os << "\n - constructor: " << Brief(constructor());
1956
  os << "\n - embedder_field_count: " << embedder_field_count();
1957
  os << "\n - immutable_proto: " << (immutable_proto() ? "true" : "false");
1958 1959 1960 1961
  os << "\n";
}


1962
void AllocationSite::AllocationSitePrint(std::ostream& os) {  // NOLINT
1963
  PrintHeader(os, "AllocationSite");
1964
  if (this->HasWeakNext()) os << "\n - weak_next: " << Brief(weak_next());
1965 1966 1967 1968 1969 1970 1971 1972 1973
  os << "\n - dependent code: " << Brief(dependent_code());
  os << "\n - nested site: " << Brief(nested_site());
  os << "\n - memento found count: "
     << Brief(Smi::FromInt(memento_found_count()));
  os << "\n - memento create count: "
     << Brief(Smi::FromInt(memento_create_count()));
  os << "\n - pretenure decision: "
     << Brief(Smi::FromInt(pretenure_decision()));
  os << "\n - transition_info: ";
1974
  if (!PointsToLiteral()) {
1975
    ElementsKind kind = GetElementsKind();
1976
    os << "Array allocation with ElementsKind " << ElementsKindToString(kind);
1977 1978
  } else if (boilerplate()->IsJSArray()) {
    os << "Array literal with boilerplate " << Brief(boilerplate());
1979
  } else {
1980
    os << "Object literal with boilerplate " << Brief(boilerplate());
1981
  }
1982
  os << "\n";
1983 1984 1985
}


1986
void AllocationMemento::AllocationMementoPrint(std::ostream& os) {  // NOLINT
1987
  PrintHeader(os, "AllocationMemento");
1988
  os << "\n - allocation site: ";
1989
  if (IsValid()) {
1990
    GetAllocationSite()->AllocationSitePrint(os);
1991
  } else {
1992
    os << "<invalid>\n";
1993 1994 1995 1996
  }
}


1997
void Script::ScriptPrint(std::ostream& os) {  // NOLINT
1998
  PrintHeader(os, "Script");
1999 2000
  os << "\n - source: " << Brief(source());
  os << "\n - name: " << Brief(name());
2001 2002 2003 2004
  os << "\n - line_offset: " << line_offset();
  os << "\n - column_offset: " << column_offset();
  os << "\n - type: " << type();
  os << "\n - id: " << id();
2005 2006 2007
  os << "\n - context data: " << Brief(context_data());
  os << "\n - compilation type: " << compilation_type();
  os << "\n - line ends: " << Brief(line_ends());
2008 2009 2010 2011 2012 2013
  if (has_eval_from_shared()) {
    os << "\n - eval from shared: " << Brief(eval_from_shared());
  }
  if (is_wrapped()) {
    os << "\n - wrapped arguments: " << Brief(wrapped_arguments());
  }
2014
  os << "\n - eval from position: " << eval_from_position();
2015
  os << "\n - shared function infos: " << Brief(shared_function_infos());
2016 2017 2018
  os << "\n";
}

2019
#ifdef V8_INTL_SUPPORT
2020
void JSV8BreakIterator::JSV8BreakIteratorPrint(std::ostream& os) {  // NOLINT
2021
  JSObjectPrintHeader(os, *this, "JSV8BreakIterator");
2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033
  os << "\n - locale: " << Brief(locale());
  os << "\n - type: " << TypeAsString();
  os << "\n - break iterator: " << Brief(break_iterator());
  os << "\n - unicode string: " << Brief(unicode_string());
  os << "\n - bound adopt text: " << Brief(bound_adopt_text());
  os << "\n - bound first: " << Brief(bound_first());
  os << "\n - bound next: " << Brief(bound_next());
  os << "\n - bound current: " << Brief(bound_current());
  os << "\n - bound break type: " << Brief(bound_break_type());
  os << "\n";
}

2034
void JSCollator::JSCollatorPrint(std::ostream& os) {  // NOLINT
2035
  JSObjectPrintHeader(os, *this, "JSCollator");
2036
  os << "\n - icu collator: " << Brief(icu_collator());
2037
  os << "\n - bound compare: " << Brief(bound_compare());
2038
  JSObjectPrintBody(os, *this);
2039 2040
}

2041
void JSDateTimeFormat::JSDateTimeFormatPrint(std::ostream& os) {  // NOLINT
2042
  JSObjectPrintHeader(os, *this, "JSDateTimeFormat");
2043
  os << "\n - icu locale: " << Brief(icu_locale());
2044 2045
  os << "\n - icu simple date format: " << Brief(icu_simple_date_format());
  os << "\n - bound format: " << Brief(bound_format());
2046
  os << "\n - hour cycle: " << HourCycleAsString();
2047
  JSObjectPrintBody(os, *this);
2048 2049
}

2050
void JSListFormat::JSListFormatPrint(std::ostream& os) {  // NOLINT
2051
  JSObjectPrintHeader(os, *this, "JSListFormat");
2052 2053 2054
  os << "\n - locale: " << Brief(locale());
  os << "\n - style: " << StyleAsString();
  os << "\n - type: " << TypeAsString();
2055
  os << "\n - icu formatter: " << Brief(icu_formatter());
2056
  JSObjectPrintBody(os, *this);
2057 2058
}

2059
void JSLocale::JSLocalePrint(std::ostream& os) {  // NOLINT
2060
  JSObjectPrintHeader(os, *this, "JSLocale");
2061 2062
  os << "\n - icu locale: " << Brief(icu_locale());
  JSObjectPrintBody(os, *this);
2063
}
2064

2065
void JSNumberFormat::JSNumberFormatPrint(std::ostream& os) {  // NOLINT
2066
  JSObjectPrintHeader(os, *this, "JSNumberFormat");
2067 2068 2069 2070 2071
  os << "\n - locale: " << Brief(locale());
  os << "\n - icu_number_format: " << Brief(icu_number_format());
  os << "\n - bound_format: " << Brief(bound_format());
  os << "\n - style: " << StyleAsString();
  os << "\n - currency_display: " << CurrencyDisplayAsString();
2072
  JSObjectPrintBody(os, *this);
2073 2074
}

2075
void JSPluralRules::JSPluralRulesPrint(std::ostream& os) {  // NOLINT
2076
  JSObjectPrintHeader(os, *this, "JSPluralRules");
2077
  os << "\n - locale: " << Brief(locale());
2078
  os << "\n - type: " << TypeAsString();
2079 2080
  os << "\n - icu plural rules: " << Brief(icu_plural_rules());
  os << "\n - icu decimal format: " << Brief(icu_decimal_format());
2081
  JSObjectPrintBody(os, *this);
2082 2083
}

2084 2085
void JSRelativeTimeFormat::JSRelativeTimeFormatPrint(
    std::ostream& os) {  // NOLINT
2086
  JSObjectPrintHeader(os, *this, "JSRelativeTimeFormat");
2087
  os << "\n - locale: " << Brief(locale());
2088 2089
  os << "\n - style: " << StyleAsString();
  os << "\n - numeric: " << NumericAsString();
2090
  os << "\n - icu formatter: " << Brief(icu_formatter());
2091 2092
  os << "\n";
}
2093

2094
void JSSegmentIterator::JSSegmentIteratorPrint(std::ostream& os) {  // NOLINT
2095
  JSObjectPrintHeader(os, *this, "JSSegmentIterator");
2096 2097 2098 2099 2100 2101
  os << "\n - icu break iterator: " << Brief(icu_break_iterator());
  os << "\n - unicode string: " << Brief(unicode_string());
  os << "\n - granularity: " << GranularityAsString();
  os << "\n";
}

2102
void JSSegmenter::JSSegmenterPrint(std::ostream& os) {  // NOLINT
2103
  JSObjectPrintHeader(os, *this, "JSSegmenter");
2104 2105 2106
  os << "\n - locale: " << Brief(locale());
  os << "\n - granularity: " << GranularityAsString();
  os << "\n - lineBreakStyle: " << LineBreakStyleAsString();
2107
  os << "\n - icu break iterator: " << Brief(icu_break_iterator());
2108
  JSObjectPrintBody(os, *this);
2109
}
2110 2111
#endif  // V8_INTL_SUPPORT

2112
namespace {
2113
void PrintScopeInfoList(ScopeInfo scope_info, std::ostream& os,
2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132
                        const char* list_name, int nof_internal_slots,
                        int start, int length) {
  if (length <= 0) return;
  int end = start + length;
  os << "\n - " << list_name;
  if (nof_internal_slots > 0) {
    os << " " << start << "-" << end << " [internal slots]";
  }
  os << " {\n";
  for (int i = nof_internal_slots; start < end; ++i, ++start) {
    os << "    - " << i << ": ";
    String::cast(scope_info->get(start))->ShortPrint(os);
    os << "\n";
  }
  os << "  }";
}
}  // namespace

void ScopeInfo::ScopeInfoPrint(std::ostream& os) {  // NOLINT
2133
  PrintHeader(os, "ScopeInfo");
2134
  if (length() == 0) {
2135
    os << "\n - length = 0\n";
2136 2137
    return;
  }
2138 2139 2140 2141
  int flags = Flags();

  os << "\n - parameters: " << ParameterCount();
  os << "\n - context locals : " << ContextLocalCount();
2142

2143
  os << "\n - scope type: " << scope_type();
2144
  if (CallsSloppyEval()) os << "\n - sloppy eval";
2145
  os << "\n - language mode: " << language_mode();
2146 2147 2148 2149
  if (is_declaration_scope()) os << "\n - declaration scope";
  if (HasReceiver()) {
    os << "\n - receiver: " << ReceiverVariableField::decode(flags);
  }
2150
  if (HasNewTarget()) os << "\n - needs new target";
2151 2152 2153 2154 2155 2156 2157 2158
  if (HasFunctionName()) {
    os << "\n - function name(" << FunctionVariableField::decode(flags)
       << "): ";
    FunctionName()->ShortPrint(os);
  }
  if (IsAsmModule()) os << "\n - asm module";
  if (HasSimpleParameters()) os << "\n - simple parameters";
  os << "\n - function kind: " << function_kind();
2159 2160 2161 2162
  if (HasOuterScopeInfo()) {
    os << "\n - outer scope info: " << Brief(OuterScopeInfo());
  }
  if (HasFunctionName()) {
2163
    os << "\n - function name: " << Brief(FunctionName());
2164
  }
2165 2166 2167 2168
  if (HasInferredFunctionName()) {
    os << "\n - inferred function name: " << Brief(InferredFunctionName());
  }

2169
  if (HasPositionInfo()) {
2170 2171
    os << "\n - start position: " << StartPosition();
    os << "\n - end position: " << EndPosition();
2172
  }
2173 2174
  os << "\n - length: " << length();
  if (length() > 0) {
2175
    PrintScopeInfoList(*this, os, "context slots", Context::MIN_CONTEXT_SLOTS,
2176 2177 2178 2179 2180
                       ContextLocalNamesIndex(), ContextLocalCount());
    // TODO(neis): Print module stuff if present.
  }
  os << "\n";
}
2181

2182
void DebugInfo::DebugInfoPrint(std::ostream& os) {  // NOLINT
2183
  PrintHeader(os, "DebugInfo");
2184 2185
  os << "\n - flags: " << flags();
  os << "\n - debugger_hints: " << debugger_hints();
2186
  os << "\n - shared: " << Brief(shared());
2187
  os << "\n - script: " << Brief(script());
2188
  os << "\n - original bytecode array: " << Brief(original_bytecode_array());
2189
  os << "\n - debug bytecode array: " << Brief(debug_bytecode_array());
2190
  os << "\n - break_points: ";
2191
  break_points()->FixedArrayPrint(os);
2192
  os << "\n - coverage_info: " << Brief(coverage_info());
2193 2194 2195
}


2196
void StackFrameInfo::StackFrameInfoPrint(std::ostream& os) {  // NOLINT
2197
  PrintHeader(os, "StackFrame");
2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208
  os << "\n - line_number: " << line_number();
  os << "\n - column_number: " << column_number();
  os << "\n - script_id: " << script_id();
  os << "\n - script_name: " << Brief(script_name());
  os << "\n - script_name_or_source_url: "
     << Brief(script_name_or_source_url());
  os << "\n - function_name: " << Brief(function_name());
  os << "\n - is_eval: " << (is_eval() ? "true" : "false");
  os << "\n - is_constructor: " << (is_constructor() ? "true" : "false");
  os << "\n";
}
2209

2210 2211 2212 2213 2214 2215 2216 2217
static void PrintBitMask(std::ostream& os, uint32_t value) {  // NOLINT
  for (int i = 0; i < 32; i++) {
    if ((i & 7) == 0) os << " ";
    os << (((value & 1) == 0) ? "_" : "x");
    value >>= 1;
  }
}

2218
void LayoutDescriptor::Print() {
2219
  StdoutStream os;
2220 2221 2222 2223
  this->Print(os);
  os << std::flush;
}

2224 2225
void LayoutDescriptor::ShortPrint(std::ostream& os) {
  if (IsSmi()) {
2226 2227
    // Print tagged value for easy use with "jld" gdb macro.
    os << reinterpret_cast<void*>(ptr());
2228
  } else {
2229
    os << Brief(*this);
2230 2231
  }
}
2232 2233 2234

void LayoutDescriptor::Print(std::ostream& os) {  // NOLINT
  os << "Layout descriptor: ";
2235
  if (IsFastPointerLayout()) {
2236 2237 2238
    os << "<all tagged>";
  } else if (IsSmi()) {
    os << "fast";
2239
    PrintBitMask(os, static_cast<uint32_t>(Smi::ToInt(*this)));
2240
  } else if (IsOddball() && IsUninitialized()) {
2241
    os << "<uninitialized>";
2242 2243
  } else {
    os << "slow";
2244 2245
    int num_words = number_of_layout_words();
    for (int i = 0; i < num_words; i++) {
2246
      if (i > 0) os << " |";
2247
      PrintBitMask(os, get_layout_word(i));
2248 2249 2250 2251 2252
    }
  }
  os << "\n";
}

2253 2254
void PreparseData::PreparseDataPrint(std::ostream& os) {  // NOLINT
  PrintHeader(os, "PreparseData");
2255 2256 2257 2258
  os << "\n - data_length: " << data_length();
  os << "\n - children_length: " << children_length();
  for (int i = 0; i < children_length(); ++i) {
    os << "\n - [" << i << "]: " << Brief(get_child(i));
2259
  }
2260 2261
  os << "\n";
}
2262

2263 2264 2265
void UncompiledDataWithoutPreparseData::UncompiledDataWithoutPreparseDataPrint(
    std::ostream& os) {  // NOLINT
  PrintHeader(os, "UncompiledDataWithoutPreparseData");
2266 2267 2268 2269 2270
  os << "\n - start position: " << start_position();
  os << "\n - end position: " << end_position();
  os << "\n";
}

2271
void UncompiledDataWithPreparseData::UncompiledDataWithPreparseDataPrint(
2272
    std::ostream& os) {  // NOLINT
2273
  PrintHeader(os, "UncompiledDataWithPreparseData");
2274 2275
  os << "\n - start position: " << start_position();
  os << "\n - end position: " << end_position();
2276
  os << "\n - preparse_data: " << Brief(preparse_data());
2277 2278 2279
  os << "\n";
}

2280
void InterpreterData::InterpreterDataPrint(std::ostream& os) {  // NOLINT
2281
  PrintHeader(os, "InterpreterData");
2282 2283 2284 2285 2286
  os << "\n - bytecode_array: " << Brief(bytecode_array());
  os << "\n - interpreter_trampoline: " << Brief(interpreter_trampoline());
  os << "\n";
}

2287
void MaybeObject::Print() {
2288
  StdoutStream os;
2289
  this->Print(os);
2290 2291 2292
  os << std::flush;
}

2293
void MaybeObject::Print(std::ostream& os) {
2294
  Smi smi;
2295
  HeapObject heap_object;
2296 2297
  if (ToSmi(&smi)) {
    smi->SmiPrint(os);
2298
  } else if (IsCleared()) {
2299
    os << "[cleared]";
2300
  } else if (GetHeapObjectIfWeak(&heap_object)) {
2301
    os << "[weak] ";
2302
    heap_object->HeapObjectPrint(os);
2303
  } else if (GetHeapObjectIfStrong(&heap_object)) {
2304
    heap_object->HeapObjectPrint(os);
2305 2306 2307 2308 2309
  } else {
    UNREACHABLE();
  }
}

2310 2311
#endif  // OBJECT_PRINT

2312 2313 2314 2315 2316 2317
void HeapNumber::HeapNumberPrint(std::ostream& os) { os << value(); }

void MutableHeapNumber::MutableHeapNumberPrint(std::ostream& os) {
  os << value();
}

2318
// TODO(cbruni): remove once the new maptracer is in place.
2319
void Name::NameShortPrint() {
2320
  if (this->IsString()) {
2321
    PrintF("%s", String::cast(*this)->ToCString().get());
2322 2323
  } else {
    DCHECK(this->IsSymbol());
2324
    Symbol s = Symbol::cast(*this);
2325 2326
    if (s->name()->IsUndefined()) {
      PrintF("#<%s>", s->PrivateSymbolToName());
2327 2328 2329 2330 2331 2332
    } else {
      PrintF("<%s>", String::cast(s->name())->ToCString().get());
    }
  }
}

2333
// TODO(cbruni): remove once the new maptracer is in place.
2334
int Name::NameShortPrint(Vector<char> str) {
2335
  if (this->IsString()) {
2336
    return SNPrintF(str, "%s", String::cast(*this)->ToCString().get());
2337 2338
  } else {
    DCHECK(this->IsSymbol());
2339
    Symbol s = Symbol::cast(*this);
2340 2341
    if (s->name()->IsUndefined()) {
      return SNPrintF(str, "#<%s>", s->PrivateSymbolToName());
2342 2343 2344 2345 2346 2347
    } else {
      return SNPrintF(str, "<%s>", String::cast(s->name())->ToCString().get());
    }
  }
}

2348
void Map::PrintMapDetails(std::ostream& os) {
2349
  DisallowHeapAllocation no_gc;
2350
  this->MapPrint(os);
2351 2352 2353 2354 2355 2356
  instance_descriptors()->PrintDescriptors(os);
}

void Map::MapPrint(std::ostream& os) {  // NOLINT
#ifdef OBJECT_PRINT
  PrintHeader(os, "Map");
2357
#else
2358
  os << "Map=" << reinterpret_cast<void*>(ptr());
2359
#endif
2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412
  os << "\n - type: " << instance_type();
  os << "\n - instance size: ";
  if (instance_size() == kVariableSizeSentinel) {
    os << "variable";
  } else {
    os << instance_size();
  }
  if (IsJSObjectMap()) {
    os << "\n - inobject properties: " << GetInObjectProperties();
  }
  os << "\n - elements kind: " << ElementsKindToString(elements_kind());
  os << "\n - unused property fields: " << UnusedPropertyFields();
  os << "\n - enum length: ";
  if (EnumLength() == kInvalidEnumCacheSentinel) {
    os << "invalid";
  } else {
    os << EnumLength();
  }
  if (is_deprecated()) os << "\n - deprecated_map";
  if (is_stable()) os << "\n - stable_map";
  if (is_migration_target()) os << "\n - migration_target";
  if (is_dictionary_map()) os << "\n - dictionary_map";
  if (has_hidden_prototype()) os << "\n - has_hidden_prototype";
  if (has_named_interceptor()) os << "\n - named_interceptor";
  if (has_indexed_interceptor()) os << "\n - indexed_interceptor";
  if (may_have_interesting_symbols()) os << "\n - may_have_interesting_symbols";
  if (is_undetectable()) os << "\n - undetectable";
  if (is_callable()) os << "\n - callable";
  if (is_constructor()) os << "\n - constructor";
  if (has_prototype_slot()) {
    os << "\n - has_prototype_slot";
    if (has_non_instance_prototype()) os << " (non-instance prototype)";
  }
  if (is_access_check_needed()) os << "\n - access_check_needed";
  if (!is_extensible()) os << "\n - non-extensible";
  if (is_prototype_map()) {
    os << "\n - prototype_map";
    os << "\n - prototype info: " << Brief(prototype_info());
  } else {
    os << "\n - back pointer: " << Brief(GetBackPointer());
  }
  os << "\n - prototype_validity cell: " << Brief(prototype_validity_cell());
  os << "\n - instance descriptors " << (owns_descriptors() ? "(own) " : "")
     << "#" << NumberOfOwnDescriptors() << ": "
     << Brief(instance_descriptors());
  if (FLAG_unbox_double_fields) {
    os << "\n - layout descriptor: ";
    layout_descriptor()->ShortPrint(os);
  }

  Isolate* isolate;
  // Read-only maps can't have transitions, which is fortunate because we need
  // the isolate to iterate over the transitions.
2413
  if (Isolate::FromWritableHeapObject(*this, &isolate)) {
2414 2415 2416 2417 2418
    DisallowHeapAllocation no_gc;
    TransitionsAccessor transitions(isolate, *this, &no_gc);
    int nof_transitions = transitions.NumberOfTransitions();
    if (nof_transitions > 0) {
      os << "\n - transitions #" << nof_transitions << ": ";
2419
      HeapObject heap_object;
2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434
      Smi smi;
      if (raw_transitions()->ToSmi(&smi)) {
        os << Brief(smi);
      } else if (raw_transitions()->GetHeapObject(&heap_object)) {
        os << Brief(heap_object);
      }
#ifdef OBJECT_PRINT
      transitions.PrintTransitions(os);
#endif  // OBJECT_PRINT
    }
  }
  os << "\n - prototype: " << Brief(prototype());
  os << "\n - constructor: " << Brief(GetConstructor());
  os << "\n - dependent code: " << Brief(dependent_code());
  os << "\n - construction counter: " << construction_counter();
2435
  os << "\n";
2436 2437
}

2438
void DescriptorArray::PrintDescriptors(std::ostream& os) {
2439
  for (int i = 0; i < number_of_descriptors(); i++) {
2440
    Name key = GetKey(i);
2441 2442 2443 2444 2445 2446 2447 2448
    os << "\n  [" << i << "]: ";
#ifdef OBJECT_PRINT
    key->NamePrint(os);
#else
    key->ShortPrint(os);
#endif
    os << " ";
    PrintDescriptorDetails(os, i, PropertyDetails::kPrintFull);
2449 2450 2451 2452
  }
  os << "\n";
}

2453 2454 2455 2456 2457 2458 2459
void DescriptorArray::PrintDescriptorDetails(std::ostream& os, int descriptor,
                                             PropertyDetails::PrintMode mode) {
  PropertyDetails details = GetDetails(descriptor);
  details.PrintAsFastTo(os, mode);
  os << " @ ";
  switch (details.location()) {
    case kField: {
2460
      FieldType field_type = GetFieldType(descriptor);
2461 2462 2463 2464
      field_type->PrintTo(os);
      break;
    }
    case kDescriptor:
2465
      Object value = GetStrongValue(descriptor);
2466 2467
      os << Brief(value);
      if (value->IsAccessorPair()) {
2468
        AccessorPair pair = AccessorPair::cast(value);
2469 2470 2471 2472 2473 2474
        os << "(get: " << Brief(pair->getter())
           << ", set: " << Brief(pair->setter()) << ")";
      }
      break;
  }
}
2475

2476 2477 2478 2479 2480 2481 2482 2483 2484 2485
#if defined(DEBUG) || defined(OBJECT_PRINT)
// This method is only meant to be called from gdb for debugging purposes.
// Since the string can also be in two-byte encoding, non-Latin1 characters
// will be ignored in the output.
char* String::ToAsciiArray() {
  // Static so that subsequent calls frees previously allocated space.
  // This also means that previous results will be overwritten.
  static char* buffer = nullptr;
  if (buffer != nullptr) delete[] buffer;
  buffer = new char[length() + 1];
2486
  WriteToFlat(*this, reinterpret_cast<uint8_t*>(buffer), 0, length());
2487 2488 2489 2490
  buffer[length()] = 0;
  return buffer;
}

2491
// static
2492
void TransitionsAccessor::PrintOneTransition(std::ostream& os, Name key,
2493
                                             Map target) {
2494 2495 2496 2497 2498 2499 2500
  os << "\n     ";
#ifdef OBJECT_PRINT
  key->NamePrint(os);
#else
  key->ShortPrint(os);
#endif
  os << ": ";
2501 2502
  ReadOnlyRoots roots = key->GetReadOnlyRoots();
  if (key == roots.nonextensible_symbol()) {
2503
    os << "(transition to non-extensible)";
2504
  } else if (key == roots.sealed_symbol()) {
2505
    os << "(transition to sealed)";
2506
  } else if (key == roots.frozen_symbol()) {
2507
    os << "(transition to frozen)";
2508
  } else if (key == roots.elements_transition_symbol()) {
2509 2510
    os << "(transition to " << ElementsKindToString(target->elements_kind())
       << ")";
2511
  } else if (key == roots.strict_function_transition_symbol()) {
2512 2513
    os << " (transition to strict function)";
  } else {
2514
    DCHECK(!IsSpecialTransition(roots, key));
2515 2516
    os << "(transition to ";
    int descriptor = target->LastAdded();
2517
    DescriptorArray descriptors = target->instance_descriptors();
2518 2519 2520 2521 2522 2523 2524
    descriptors->PrintDescriptorDetails(os, descriptor,
                                        PropertyDetails::kForTransitions);
    os << ")";
  }
  os << " -> " << Brief(target);
}

2525
void TransitionArray::PrintInternal(std::ostream& os) {
2526 2527
  int num_transitions = number_of_transitions();
  os << "Transition array #" << num_transitions << ":";
2528
  for (int i = 0; i < num_transitions; i++) {
2529
    Name key = GetKey(i);
2530
    Map target = GetTarget(i);
2531
    TransitionsAccessor::PrintOneTransition(os, key, target);
2532
  }
2533 2534 2535 2536 2537 2538 2539
  os << "\n" << std::flush;
}

void TransitionsAccessor::PrintTransitions(std::ostream& os) {  // NOLINT
  switch (encoding()) {
    case kPrototypeInfo:
    case kUninitialized:
2540
    case kMigrationTarget:
2541
      return;
2542
    case kWeakRef: {
2543
      Map target = Map::cast(raw_transitions_->GetHeapObjectAssumeWeak());
2544
      Name key = GetSimpleTransitionKey(target);
2545
      PrintOneTransition(os, key, target);
2546
      break;
2547
    }
2548
    case kFullTransitionArray:
2549
      return transitions()->PrintInternal(os);
2550
  }
2551 2552
}

2553
void TransitionsAccessor::PrintTransitionTree() {
2554
  StdoutStream os;
2555 2556 2557
  os << "map= " << Brief(map_);
  DisallowHeapAllocation no_gc;
  PrintTransitionTree(os, 0, &no_gc);
2558 2559 2560
  os << "\n" << std::flush;
}

2561 2562
void TransitionsAccessor::PrintTransitionTree(std::ostream& os, int level,
                                              DisallowHeapAllocation* no_gc) {
2563
  ReadOnlyRoots roots = ReadOnlyRoots(isolate_);
2564
  int num_transitions = NumberOfTransitions();
2565 2566
  if (num_transitions == 0) return;
  for (int i = 0; i < num_transitions; i++) {
2567
    Name key = GetKey(i);
2568
    Map target = GetTarget(i);
2569 2570
    os << std::endl
       << "  " << level << "/" << i << ":" << std::setw(level * 2 + 2) << " ";
2571 2572 2573 2574
    std::stringstream ss;
    ss << Brief(target);
    os << std::left << std::setw(50) << ss.str() << ": ";

2575
    if (key == roots.nonextensible_symbol()) {
2576
      os << "to non-extensible";
2577
    } else if (key == roots.sealed_symbol()) {
2578
      os << "to sealed ";
2579
    } else if (key == roots.frozen_symbol()) {
2580
      os << "to frozen";
2581
    } else if (key == roots.elements_transition_symbol()) {
2582
      os << "to " << ElementsKindToString(target->elements_kind());
2583
    } else if (key == roots.strict_function_transition_symbol()) {
2584 2585 2586 2587 2588 2589 2590 2591
      os << "to strict function";
    } else {
#ifdef OBJECT_PRINT
      key->NamePrint(os);
#else
      key->ShortPrint(os);
#endif
      os << " ";
2592
      DCHECK(!IsSpecialTransition(ReadOnlyRoots(isolate_), key));
2593
      os << "to ";
2594
      int descriptor = target->LastAdded();
2595
      DescriptorArray descriptors = target->instance_descriptors();
2596 2597 2598
      descriptors->PrintDescriptorDetails(os, descriptor,
                                          PropertyDetails::kForTransitions);
    }
2599
    TransitionsAccessor transitions(isolate_, target, no_gc);
2600
    transitions.PrintTransitionTree(os, level + 1, no_gc);
2601 2602
  }
}
2603

2604
void JSObject::PrintTransitions(std::ostream& os) {  // NOLINT
2605
  DisallowHeapAllocation no_gc;
2606
  TransitionsAccessor ta(GetIsolate(), map(), &no_gc);
2607
  if (ta.NumberOfTransitions() == 0) return;
2608
  os << "\n - transitions";
2609
  ta.PrintTransitions(os);
2610
}
2611

2612
#endif  // defined(DEBUG) || defined(OBJECT_PRINT)
2613 2614
}  // namespace internal
}  // namespace v8
2615 2616 2617 2618

//
// The following functions are used by our gdb macros.
//
2619
V8_EXPORT_PRIVATE extern void _v8_internal_Print_Object(void* object) {
2620
  i::Object(reinterpret_cast<i::Address>(object))->Print();
2621 2622
}

2623
V8_EXPORT_PRIVATE extern void _v8_internal_Print_Code(void* object) {
2624
  i::Address address = reinterpret_cast<i::Address>(object);
2625
  i::Isolate* isolate = i::Isolate::Current();
2626

2627
  i::wasm::WasmCode* wasm_code =
2628
      isolate->wasm_engine()->code_manager()->LookupCode(address);
2629
  if (wasm_code) {
2630
    i::StdoutStream os;
2631
    wasm_code->Disassemble(nullptr, os, address);
2632 2633
    return;
  }
2634 2635

  if (!isolate->heap()->InSpaceSlow(address, i::CODE_SPACE) &&
2636 2637
      !isolate->heap()->InSpaceSlow(address, i::LO_SPACE) &&
      !i::InstructionStream::PcIsOffHeap(isolate, address)) {
2638
    i::PrintF(
2639 2640
        "%p is not within the current isolate's large object, code or embedded "
        "spaces\n",
2641
        object);
2642 2643 2644
    return;
  }

2645
  i::Code code = isolate->FindCodeObject(address);
2646
  if (!code->IsCode()) {
2647
    i::PrintF("No code object found containing %p\n", object);
2648 2649 2650
    return;
  }
#ifdef ENABLE_DISASSEMBLER
2651
  i::StdoutStream os;
2652
  code->Disassemble(nullptr, os, address);
2653
#else   // ENABLE_DISASSEMBLER
2654
  code->Print();
2655
#endif  // ENABLE_DISASSEMBLER
2656 2657
}

2658 2659
V8_EXPORT_PRIVATE extern void _v8_internal_Print_LayoutDescriptor(
    void* object) {
2660
  i::Object o(reinterpret_cast<i::Address>(object));
2661
  if (!o->IsLayoutDescriptor()) {
2662
    printf("Please provide a layout descriptor\n");
2663
  } else {
2664
    i::LayoutDescriptor::cast(o)->Print();
2665 2666 2667
  }
}

2668
V8_EXPORT_PRIVATE extern void _v8_internal_Print_StackTrace() {
2669 2670 2671
  i::Isolate* isolate = i::Isolate::Current();
  isolate->PrintStack(stdout);
}
2672

2673
V8_EXPORT_PRIVATE extern void _v8_internal_Print_TransitionTree(void* object) {
2674
  i::Object o(reinterpret_cast<i::Address>(object));
2675 2676 2677 2678
  if (!o->IsMap()) {
    printf("Please provide a valid Map\n");
  } else {
#if defined(DEBUG) || defined(OBJECT_PRINT)
2679
    i::DisallowHeapAllocation no_gc;
2680
    i::Map map = i::Map::unchecked_cast(o);
2681
    i::TransitionsAccessor transitions(i::Isolate::Current(), map, &no_gc);
2682
    transitions.PrintTransitionTree();
2683 2684 2685
#endif
  }
}