forked from nodejs/node
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobjects-printer.cc
2793 lines (2566 loc) · 92.2 KB
/
objects-printer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/objects/objects.h"
#include <iomanip>
#include <memory>
#include "src/diagnostics/disasm.h"
#include "src/diagnostics/disassembler.h"
#include "src/heap/heap-inl.h" // For InOldSpace.
#include "src/heap/heap-write-barrier-inl.h" // For GetIsolateFromWritableObj.
#include "src/init/bootstrapper.h"
#include "src/interpreter/bytecodes.h"
#include "src/objects/arguments-inl.h"
#include "src/objects/cell-inl.h"
#include "src/objects/data-handler-inl.h"
#include "src/objects/debug-objects-inl.h"
#include "src/objects/embedder-data-array-inl.h"
#include "src/objects/embedder-data-slot-inl.h"
#include "src/objects/feedback-cell-inl.h"
#include "src/objects/foreign-inl.h"
#include "src/objects/free-space-inl.h"
#include "src/objects/hash-table-inl.h"
#include "src/objects/heap-number-inl.h"
#include "src/objects/js-aggregate-error-inl.h"
#include "src/objects/js-array-buffer-inl.h"
#include "src/objects/js-array-inl.h"
#include "src/objects/objects-inl.h"
#include "src/snapshot/embedded/embedded-data.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-break-iterator-inl.h"
#include "src/objects/js-collator-inl.h"
#endif // V8_INTL_SUPPORT
#include "src/objects/js-collection-inl.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-date-time-format-inl.h"
#include "src/objects/js-display-names-inl.h"
#endif // V8_INTL_SUPPORT
#include "src/objects/js-generator-inl.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-list-format-inl.h"
#include "src/objects/js-locale-inl.h"
#include "src/objects/js-number-format-inl.h"
#include "src/objects/js-plural-rules-inl.h"
#endif // V8_INTL_SUPPORT
#include "src/objects/js-regexp-inl.h"
#include "src/objects/js-regexp-string-iterator-inl.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-relative-time-format-inl.h"
#include "src/objects/js-segment-iterator-inl.h"
#include "src/objects/js-segmenter-inl.h"
#endif // V8_INTL_SUPPORT
#include "src/compiler/node.h"
#include "src/objects/js-weak-refs-inl.h"
#include "src/objects/literal-objects-inl.h"
#include "src/objects/microtask-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/oddball-inl.h"
#include "src/objects/promise-inl.h"
#include "src/objects/property-descriptor-object-inl.h"
#include "src/objects/stack-frame-info-inl.h"
#include "src/objects/struct-inl.h"
#include "src/objects/template-objects-inl.h"
#include "src/objects/transitions-inl.h"
#include "src/regexp/regexp.h"
#include "src/utils/ostreams.h"
#include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-objects-inl.h"
#include "torque-generated/class-definitions-tq-inl.h"
#include "torque-generated/exported-class-definitions-tq-inl.h"
#include "torque-generated/internal-class-definitions-tq-inl.h"
namespace v8 {
namespace internal {
#ifdef OBJECT_PRINT
void Object::Print() const {
// Output into debugger's command window if a debugger is attached.
DbgStdoutStream dbg_os;
this->Print(dbg_os);
dbg_os << std::flush;
StdoutStream os;
this->Print(os);
os << std::flush;
}
void Object::Print(std::ostream& os) const { // NOLINT
if (IsSmi()) {
os << "Smi: " << std::hex << "0x" << Smi::ToInt(*this);
os << std::dec << " (" << Smi::ToInt(*this) << ")\n";
} else {
HeapObject::cast(*this).HeapObjectPrint(os);
}
}
void HeapObject::PrintHeader(std::ostream& os, const char* id) { // NOLINT
os << reinterpret_cast<void*>(ptr()) << ": [";
if (id != nullptr) {
os << id;
} else {
os << map().instance_type();
}
os << "]";
if (ReadOnlyHeap::Contains(*this)) {
os << " in ReadOnlySpace";
} else if (GetHeapFromWritableObject(*this)->InOldSpace(*this)) {
os << " in OldSpace";
}
if (!IsMap()) os << "\n - map: " << Brief(map());
}
void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
InstanceType instance_type = map().instance_type();
if (instance_type < FIRST_NONSTRING_TYPE) {
String::cast(*this).StringPrint(os);
os << "\n";
return;
}
switch (instance_type) {
case FIXED_ARRAY_TYPE:
FixedArray::cast(*this).FixedArrayPrint(os);
break;
case AWAIT_CONTEXT_TYPE:
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:
case SCRIPT_CONTEXT_TABLE_TYPE:
Context::cast(*this).ContextPrint(os);
break;
case NATIVE_CONTEXT_TYPE:
NativeContext::cast(*this).NativeContextPrint(os);
break;
case HASH_TABLE_TYPE:
case ORDERED_HASH_MAP_TYPE:
case ORDERED_HASH_SET_TYPE:
case ORDERED_NAME_DICTIONARY_TYPE:
case NAME_DICTIONARY_TYPE:
case GLOBAL_DICTIONARY_TYPE:
case SIMPLE_NUMBER_DICTIONARY_TYPE:
FixedArray::cast(*this).FixedArrayPrint(os);
break;
case STRING_TABLE_TYPE:
ObjectHashTable::cast(*this).ObjectHashTablePrint(os);
break;
case NUMBER_DICTIONARY_TYPE:
NumberDictionary::cast(*this).NumberDictionaryPrint(os);
break;
case EPHEMERON_HASH_TABLE_TYPE:
EphemeronHashTable::cast(*this).EphemeronHashTablePrint(os);
break;
case OBJECT_BOILERPLATE_DESCRIPTION_TYPE:
ObjectBoilerplateDescription::cast(*this)
.ObjectBoilerplateDescriptionPrint(os);
break;
case TRANSITION_ARRAY_TYPE:
TransitionArray::cast(*this).TransitionArrayPrint(os);
break;
case CLOSURE_FEEDBACK_CELL_ARRAY_TYPE:
ClosureFeedbackCellArray::cast(*this).ClosureFeedbackCellArrayPrint(os);
break;
case FILLER_TYPE:
os << "filler";
break;
case JS_OBJECT_TYPE: // fall through
case JS_API_OBJECT_TYPE:
case JS_SPECIAL_API_OBJECT_TYPE:
case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
case JS_ERROR_TYPE:
JSObject::cast(*this).JSObjectPrint(os);
break;
case WASM_INSTANCE_OBJECT_TYPE:
WasmInstanceObject::cast(*this).WasmInstanceObjectPrint(os);
break;
case JS_GENERATOR_OBJECT_TYPE:
JSGeneratorObject::cast(*this).JSGeneratorObjectPrint(os);
break;
case CODE_TYPE:
Code::cast(*this).CodePrint(os);
break;
case CODE_DATA_CONTAINER_TYPE:
CodeDataContainer::cast(*this).CodeDataContainerPrint(os);
break;
case JS_SET_KEY_VALUE_ITERATOR_TYPE:
case JS_SET_VALUE_ITERATOR_TYPE:
JSSetIterator::cast(*this).JSSetIteratorPrint(os);
break;
case JS_MAP_KEY_ITERATOR_TYPE:
case JS_MAP_KEY_VALUE_ITERATOR_TYPE:
case JS_MAP_VALUE_ITERATOR_TYPE:
JSMapIterator::cast(*this).JSMapIteratorPrint(os);
break;
#define MAKE_TORQUE_CASE(Name, TYPE) \
case TYPE: \
Name::cast(*this).Name##Print(os); \
break;
// Every class that has its fields defined in a .tq file and corresponds
// to exactly one InstanceType value is included in the following list.
TORQUE_INSTANCE_CHECKERS_SINGLE_FULLY_DEFINED(MAKE_TORQUE_CASE)
TORQUE_INSTANCE_CHECKERS_MULTIPLE_FULLY_DEFINED(MAKE_TORQUE_CASE)
#undef MAKE_TORQUE_CASE
case ALLOCATION_SITE_TYPE:
AllocationSite::cast(*this).AllocationSitePrint(os);
break;
case LOAD_HANDLER_TYPE:
LoadHandler::cast(*this).LoadHandlerPrint(os);
break;
case STORE_HANDLER_TYPE:
StoreHandler::cast(*this).StoreHandlerPrint(os);
break;
case SCOPE_INFO_TYPE:
ScopeInfo::cast(*this).ScopeInfoPrint(os);
break;
case FEEDBACK_METADATA_TYPE:
FeedbackMetadata::cast(*this).FeedbackMetadataPrint(os);
break;
case WEAK_FIXED_ARRAY_TYPE:
WeakFixedArray::cast(*this).WeakFixedArrayPrint(os);
break;
case INTERNALIZED_STRING_TYPE:
case EXTERNAL_INTERNALIZED_STRING_TYPE:
case ONE_BYTE_INTERNALIZED_STRING_TYPE:
case EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE:
case UNCACHED_EXTERNAL_INTERNALIZED_STRING_TYPE:
case UNCACHED_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE:
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 UNCACHED_EXTERNAL_STRING_TYPE:
case UNCACHED_EXTERNAL_ONE_BYTE_STRING_TYPE:
// TODO(all): Handle these types too.
os << "UNKNOWN TYPE " << map().instance_type();
UNREACHABLE();
}
}
void ByteArray::ByteArrayPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "ByteArray");
os << "\n - length: " << length()
<< "\n - data-start: " << static_cast<void*>(GetDataStartAddress())
<< "\n";
}
void BytecodeArray::BytecodeArrayPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "BytecodeArray");
os << "\n";
Disassemble(os);
}
void FreeSpace::FreeSpacePrint(std::ostream& os) { // NOLINT
os << "free space, size " << Size() << "\n";
}
bool JSObject::PrintProperties(std::ostream& os) { // NOLINT
if (HasFastProperties()) {
DescriptorArray descs = map().instance_descriptors();
int nof_inobject_properties = map().GetInObjectProperties();
for (InternalIndex i : map().IterateOwnDescriptors()) {
os << "\n ";
descs.GetKey(i).NamePrint(os);
os << ": ";
PropertyDetails details = descs.GetDetails(i);
switch (details.location()) {
case kField: {
FieldIndex field_index = FieldIndex::ForDescriptor(map(), i);
if (IsUnboxedDoubleField(field_index)) {
os << "<unboxed double> " << RawFastDoublePropertyAt(field_index);
} else {
os << Brief(RawFastPropertyAt(field_index));
}
break;
}
case kDescriptor:
os << Brief(descs.GetStrongValue(i));
break;
}
os << " ";
details.PrintAsFastTo(os, PropertyDetails::kForProperties);
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 << "]";
}
}
return map().NumberOfOwnDescriptors() > 0;
} else if (IsJSGlobalObject()) {
JSGlobalObject::cast(*this).global_dictionary().Print(os);
} else {
property_dictionary().Print(os);
}
return true;
}
namespace {
template <class T>
bool IsTheHoleAt(T array, int index) {
return false;
}
template <>
bool IsTheHoleAt(FixedDoubleArray array, int index) {
return array.is_the_hole(index);
}
template <class T>
double GetScalarElement(T array, int index) {
if (IsTheHoleAt(array, index)) {
return std::numeric_limits<double>::quiet_NaN();
}
return array.get_scalar(index);
}
template <class T>
void DoPrintElements(std::ostream& os, Object object, int length) { // NOLINT
const bool print_the_hole = std::is_same<T, FixedDoubleArray>::value;
T array = T::cast(object);
if (length == 0) return;
int previous_index = 0;
double previous_value = GetScalarElement(array, 0);
double value = 0.0;
int i;
for (i = 1; i <= length; i++) {
if (i < length) value = GetScalarElement(array, i);
bool values_are_nan = std::isnan(previous_value) && std::isnan(value);
if (i != length && (previous_value == value || values_are_nan) &&
IsTheHoleAt(array, i - 1) == IsTheHoleAt(array, i)) {
continue;
}
os << "\n";
std::stringstream ss;
ss << previous_index;
if (previous_index != i - 1) {
ss << '-' << (i - 1);
}
os << std::setw(12) << ss.str() << ": ";
if (print_the_hole && IsTheHoleAt(array, i - 1)) {
os << "<the_hole>";
} else {
os << previous_value;
}
previous_index = i;
previous_value = value;
}
}
template <typename ElementType>
void PrintTypedArrayElements(std::ostream& os, const ElementType* data_ptr,
size_t length, bool is_on_heap) {
if (length == 0) return;
size_t previous_index = 0;
if (i::FLAG_mock_arraybuffer_allocator && !is_on_heap) {
// Don't try to print data that's not actually allocated.
os << "\n 0-" << length << ": <mocked array buffer bytes>";
return;
}
ElementType previous_value = data_ptr[0];
ElementType value = 0;
for (size_t i = 1; i <= length; i++) {
if (i < length) value = data_ptr[i];
if (i != length && previous_value == value) {
continue;
}
os << "\n";
std::stringstream ss;
ss << previous_index;
if (previous_index != i - 1) {
ss << '-' << (i - 1);
}
os << std::setw(12) << ss.str() << ": " << +previous_value;
previous_index = i;
previous_value = value;
}
}
template <typename T>
void PrintFixedArrayElements(std::ostream& os, T array) {
// Print in array notation for non-sparse arrays.
Object previous_value = array.length() > 0 ? array.get(0) : Object();
Object value;
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;
}
}
void PrintDictionaryElements(std::ostream& os, FixedArrayBase elements) {
// Print some internal fields
NumberDictionary dict = NumberDictionary::cast(elements);
if (dict.requires_slow_elements()) {
os << "\n - requires_slow_elements";
} else {
os << "\n - max_number_key: " << dict.max_number_key();
}
dict.Print(os);
}
void PrintSloppyArgumentElements(std::ostream& os, ElementsKind kind,
SloppyArgumentsElements elements) {
FixedArray arguments_store = elements.arguments();
os << "\n 0: context: " << Brief(elements.context())
<< "\n 1: arguments_store: " << Brief(arguments_store)
<< "\n parameter to context slot map:";
for (uint32_t i = 0; i < elements.parameter_map_length(); i++) {
uint32_t raw_index = i + SloppyArgumentsElements::kParameterMapStart;
Object mapped_entry = elements.get_mapped_entry(i);
os << "\n " << raw_index << ": param(" << i
<< "): " << Brief(mapped_entry);
if (mapped_entry.IsTheHole()) {
os << " in the arguments_store[" << i << "]";
} else {
os << " in the context";
}
}
if (arguments_store.length() == 0) return;
os << "\n }"
<< "\n - arguments_store: " << Brief(arguments_store) << " "
<< ElementsKindToString(arguments_store.map().elements_kind()) << " {";
if (kind == FAST_SLOPPY_ARGUMENTS_ELEMENTS) {
PrintFixedArrayElements(os, arguments_store);
} else {
DCHECK_EQ(kind, SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
PrintDictionaryElements(os, arguments_store);
}
}
void PrintEmbedderData(const Isolate* isolate, std::ostream& os,
EmbedderDataSlot slot) {
DisallowHeapAllocation no_gc;
Object value = slot.load_tagged();
os << Brief(value);
void* raw_pointer;
if (slot.ToAlignedPointer(isolate, &raw_pointer)) {
os << ", aligned pointer: " << raw_pointer;
}
}
} // namespace
void JSObject::PrintElements(std::ostream& os) { // NOLINT
// Don't call GetElementsKind, its validation code can cause the printer to
// fail when debugging.
os << " - elements: " << Brief(elements()) << " {";
switch (map().elements_kind()) {
case HOLEY_SMI_ELEMENTS:
case PACKED_SMI_ELEMENTS:
case HOLEY_ELEMENTS:
case HOLEY_FROZEN_ELEMENTS:
case HOLEY_SEALED_ELEMENTS:
case HOLEY_NONEXTENSIBLE_ELEMENTS:
case PACKED_ELEMENTS:
case PACKED_FROZEN_ELEMENTS:
case PACKED_SEALED_ELEMENTS:
case PACKED_NONEXTENSIBLE_ELEMENTS:
case FAST_STRING_WRAPPER_ELEMENTS: {
PrintFixedArrayElements(os, FixedArray::cast(elements()));
break;
}
case HOLEY_DOUBLE_ELEMENTS:
case PACKED_DOUBLE_ELEMENTS: {
DoPrintElements<FixedDoubleArray>(os, elements(), elements().length());
break;
}
#define PRINT_ELEMENTS(Type, type, TYPE, elementType) \
case TYPE##_ELEMENTS: { \
size_t length = JSTypedArray::cast(*this).length(); \
bool is_on_heap = JSTypedArray::cast(*this).is_on_heap(); \
const elementType* data_ptr = \
static_cast<const elementType*>(JSTypedArray::cast(*this).DataPtr()); \
PrintTypedArrayElements<elementType>(os, data_ptr, length, is_on_heap); \
break; \
}
TYPED_ARRAYS(PRINT_ELEMENTS)
#undef PRINT_ELEMENTS
case DICTIONARY_ELEMENTS:
case SLOW_STRING_WRAPPER_ELEMENTS:
PrintDictionaryElements(os, elements());
break;
case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
PrintSloppyArgumentElements(os, map().elements_kind(),
SloppyArgumentsElements::cast(elements()));
break;
case NO_ELEMENTS:
break;
}
os << "\n }\n";
}
static void JSObjectPrintHeader(std::ostream& os, JSObject obj,
const char* id) { // NOLINT
Isolate* isolate = obj.GetIsolate();
obj.PrintHeader(os, id);
// Don't call GetElementsKind, its validation code can cause the printer to
// fail when debugging.
os << " [";
if (obj.HasFastProperties()) {
os << "FastProperties";
} else {
os << "DictionaryProperties";
}
PrototypeIterator iter(isolate, obj);
os << "]\n - prototype: " << Brief(iter.GetCurrent());
os << "\n - elements: " << Brief(obj.elements()) << " ["
<< ElementsKindToString(obj.map().elements_kind());
if (obj.elements().IsCowArray()) os << " (COW)";
os << "]";
Object hash = obj.GetHash();
if (hash.IsSmi()) {
os << "\n - hash: " << Brief(hash);
}
if (obj.GetEmbedderFieldCount() > 0) {
os << "\n - embedder fields: " << obj.GetEmbedderFieldCount();
}
}
static void JSObjectPrintBody(std::ostream& os,
JSObject obj, // NOLINT
bool print_elements = true) {
os << "\n - properties: ";
Object properties_or_hash = obj.raw_properties_or_hash();
if (!properties_or_hash.IsSmi()) {
os << Brief(properties_or_hash);
}
os << " {";
if (obj.PrintProperties(os)) os << "\n ";
os << "}\n";
if (print_elements) {
size_t length = obj.IsJSTypedArray() ? JSTypedArray::cast(obj).length()
: obj.elements().length();
if (length > 0) obj.PrintElements(os);
}
int embedder_fields = obj.GetEmbedderFieldCount();
if (embedder_fields > 0) {
const Isolate* isolate = GetIsolateForPtrCompr(obj);
os << " - embedder fields = {";
for (int i = 0; i < embedder_fields; i++) {
os << "\n ";
PrintEmbedderData(isolate, os, EmbedderDataSlot(obj, i));
}
os << "\n }\n";
}
}
void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, *this, nullptr);
JSObjectPrintBody(os, *this);
}
void JSGeneratorObject::JSGeneratorObjectPrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, *this, "JSGeneratorObject");
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;
SharedFunctionInfo fun_info = function().shared();
if (fun_info.HasSourceCode()) {
Script script = Script::cast(fun_info.script());
String script_name = script.name().IsString()
? String::cast(script.name())
: GetReadOnlyRoots().empty_string();
os << "\n - source position: ";
// Can't collect source positions here if not available as that would
// allocate memory.
if (fun_info.HasBytecodeArray() &&
fun_info.GetBytecodeArray().HasSourcePositionTable()) {
os << source_position();
os << " (";
script_name.PrintUC16(os);
int lin = script.GetLineNumber(source_position()) + 1;
int col = script.GetColumnNumber(source_position()) + 1;
os << ", lin " << lin;
os << ", col " << col;
} else {
os << "unavailable";
}
os << ")";
}
}
os << "\n - register file: " << Brief(parameters_and_registers());
JSObjectPrintBody(os, *this);
}
void JSAggregateError::JSAggregateErrorPrint(std::ostream& os) {
JSObjectPrintHeader(os, *this, "JSAggregateError");
os << "\n - errors: " << Brief(errors());
JSObjectPrintBody(os, *this);
}
void JSArray::JSArrayPrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, *this, "JSArray");
os << "\n - length: " << Brief(this->length());
JSObjectPrintBody(os, *this);
}
void JSPromise::JSPromisePrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, *this, "JSPromise");
os << "\n - status: " << JSPromise::Status(status());
if (status() == Promise::kPending) {
os << "\n - reactions: " << Brief(reactions());
} else {
os << "\n - result: " << Brief(result());
}
os << "\n - has_handler: " << has_handler();
os << "\n - handled_hint: " << handled_hint();
JSObjectPrintBody(os, *this);
}
void JSRegExp::JSRegExpPrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, *this, "JSRegExp");
os << "\n - data: " << Brief(data());
os << "\n - source: " << Brief(source());
JSObjectPrintBody(os, *this);
}
void JSRegExpStringIterator::JSRegExpStringIteratorPrint(
std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, *this, "JSRegExpStringIterator");
os << "\n - regex: " << Brief(iterating_reg_exp());
os << "\n - string: " << Brief(iterated_string());
os << "\n - done: " << done();
os << "\n - global: " << global();
os << "\n - unicode: " << unicode();
JSObjectPrintBody(os, *this);
}
void Symbol::SymbolPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "Symbol");
os << "\n - hash: " << Hash();
os << "\n - description: " << Brief(description());
if (description().IsUndefined()) {
os << " (" << PrivateSymbolToName() << ")";
}
os << "\n - private: " << is_private();
}
void DescriptorArray::DescriptorArrayPrint(std::ostream& os) {
PrintHeader(os, "DescriptorArray");
os << "\n - enum_cache: ";
if (enum_cache().keys().length() == 0) {
os << "empty";
} else {
os << enum_cache().keys().length();
os << "\n - keys: " << Brief(enum_cache().keys());
os << "\n - indices: " << Brief(enum_cache().indices());
}
os << "\n - nof slack descriptors: " << number_of_slack_descriptors();
os << "\n - nof descriptors: " << number_of_descriptors();
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);
PrintDescriptors(os);
}
namespace {
void PrintFixedArrayWithHeader(std::ostream& os, FixedArray array,
const char* type) {
array.PrintHeader(os, type);
os << "\n - length: " << array.length();
PrintFixedArrayElements(os, array);
os << "\n";
}
template <typename T>
void PrintHashTableWithHeader(std::ostream& os, T table, const char* type) {
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 (InternalIndex i : table.IterateEntries()) {
os << '\n'
<< std::setw(12) << i.as_int() << ": " << Brief(table.KeyAt(i)) << " -> "
<< Brief(table.ValueAt(i));
}
os << "\n }\n";
}
template <typename T>
void PrintWeakArrayElements(std::ostream& os, T* array) {
// Print in array notation for non-sparse arrays.
MaybeObject previous_value =
array->length() > 0 ? array->Get(0) : MaybeObject(kNullAddress);
MaybeObject value;
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;
}
}
} // namespace
void EmbedderDataArray::EmbedderDataArrayPrint(std::ostream& os) {
const Isolate* isolate = GetIsolateForPtrCompr(*this);
PrintHeader(os, "EmbedderDataArray");
os << "\n - length: " << length();
EmbedderDataSlot start(*this, 0);
EmbedderDataSlot end(*this, length());
for (EmbedderDataSlot slot = start; slot < end; ++slot) {
os << "\n ";
PrintEmbedderData(isolate, os, slot);
}
os << "\n";
}
void FixedArray::FixedArrayPrint(std::ostream& os) {
PrintFixedArrayWithHeader(os, *this, "FixedArray");
}
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.unchecked_previous());
os << "\n - native_context: " << Brief(context.native_context());
PrintFixedArrayElements(os, context);
os << "\n";
}
} // namespace
void Context::ContextPrint(std::ostream& os) {
PrintContextWithHeader(os, *this, "Context");
}
void NativeContext::NativeContextPrint(std::ostream& os) {
PrintContextWithHeader(os, *this, "NativeContext");
os << " - microtask_queue: " << microtask_queue() << "\n";
}
void ObjectHashTable::ObjectHashTablePrint(std::ostream& os) {
PrintHashTableWithHeader(os, *this, "ObjectHashTable");
}
void NumberDictionary::NumberDictionaryPrint(std::ostream& os) {
PrintHashTableWithHeader(os, *this, "NumberDictionary");
}
void EphemeronHashTable::EphemeronHashTablePrint(std::ostream& os) {
PrintHashTableWithHeader(os, *this, "EphemeronHashTable");
}
void ObjectBoilerplateDescription::ObjectBoilerplateDescriptionPrint(
std::ostream& os) {
PrintFixedArrayWithHeader(os, *this, "ObjectBoilerplateDescription");
}
void PropertyArray::PropertyArrayPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "PropertyArray");
os << "\n - length: " << length();
os << "\n - hash: " << Hash();
PrintFixedArrayElements(os, *this);
os << "\n";
}
void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "FixedDoubleArray");
os << "\n - length: " << length();
DoPrintElements<FixedDoubleArray>(os, *this, length());
os << "\n";
}
void WeakFixedArray::WeakFixedArrayPrint(std::ostream& os) {
PrintHeader(os, "WeakFixedArray");
os << "\n - length: " << length() << "\n";
PrintWeakArrayElements(os, this);
os << "\n";
}
void WeakArrayList::WeakArrayListPrint(std::ostream& os) {
PrintHeader(os, "WeakArrayList");
os << "\n - capacity: " << capacity();
os << "\n - length: " << length() << "\n";
PrintWeakArrayElements(os, this);
os << "\n";
}
void TransitionArray::TransitionArrayPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "TransitionArray");
PrintInternal(os);
}
void FeedbackCell::FeedbackCellPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "FeedbackCell");
ReadOnlyRoots roots = GetReadOnlyRoots();
if (map() == roots.no_closures_cell_map()) {
os << "\n - no closures";
} else if (map() == roots.one_closure_cell_map()) {
os << "\n - one closure";
} else if (map() == roots.many_closures_cell_map()) {
os << "\n - many closures";
} else {
os << "\n - Invalid FeedbackCell map";
}
os << " - value: " << Brief(value());
os << "\n";
}
void FeedbackVectorSpec::Print() {
StdoutStream os;
FeedbackVectorSpecPrint(os);
os << std::flush;
}
void FeedbackVectorSpec::FeedbackVectorSpecPrint(std::ostream& os) { // NOLINT
int slot_count = slots();
os << " - slot_count: " << slot_count;
if (slot_count == 0) {
os << " (empty)\n";
return;
}
for (int slot = 0; slot < slot_count;) {
FeedbackSlotKind kind = GetKind(FeedbackSlot(slot));
int entry_size = FeedbackMetadata::GetSlotSize(kind);
DCHECK_LT(0, entry_size);
os << "\n Slot #" << slot << " " << kind;
slot += entry_size;
}
os << "\n";
}
void FeedbackMetadata::FeedbackMetadataPrint(std::ostream& os) {
PrintHeader(os, "FeedbackMetadata");
os << "\n - slot_count: " << slot_count();
FeedbackMetadataIterator iter(*this);
while (iter.HasNext()) {
FeedbackSlot slot = iter.Next();
FeedbackSlotKind kind = iter.kind();
os << "\n Slot " << slot << " " << kind;
}
os << "\n";
}
void ClosureFeedbackCellArray::ClosureFeedbackCellArrayPrint(std::ostream& os) {
PrintFixedArrayWithHeader(os, *this, "ClosureFeedbackCellArray");
}
void FeedbackVector::FeedbackVectorPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "FeedbackVector");
os << "\n - length: " << length();
if (length() == 0) {
os << " (empty)\n";
return;
}
os << "\n - shared function info: " << Brief(shared_function_info());
os << "\n - optimized code/marker: ";
if (has_optimized_code()) {
os << Brief(optimized_code());
} else {
os << optimization_marker();
}
os << "\n - invocation count: " << invocation_count();
os << "\n - profiler ticks: " << profiler_ticks();
FeedbackMetadataIterator iter(metadata());
while (iter.HasNext()) {
FeedbackSlot slot = iter.Next();
FeedbackSlotKind kind = iter.kind();
os << "\n - slot " << slot << " " << kind << " ";
FeedbackSlotPrint(os, slot);
int entry_size = iter.entry_size();
if (entry_size > 0) os << " {";
for (int i = 0; i < entry_size; i++) {
int index = GetIndex(slot) + i;
os << "\n [" << index << "]: " << Brief(get(index));
}
if (entry_size > 0) os << "\n }";
}
os << "\n";
}
void FeedbackVector::FeedbackSlotPrint(std::ostream& os,
FeedbackSlot slot) { // NOLINT
FeedbackNexus nexus(*this, slot);
nexus.Print(os);
}
void FeedbackNexus::Print(std::ostream& os) { // NOLINT
switch (kind()) {
case FeedbackSlotKind::kCall:
case FeedbackSlotKind::kCloneObject:
case FeedbackSlotKind::kHasKeyed:
case FeedbackSlotKind::kInstanceOf:
case FeedbackSlotKind::kLoadGlobalInsideTypeof:
case FeedbackSlotKind::kLoadGlobalNotInsideTypeof:
case FeedbackSlotKind::kLoadKeyed:
case FeedbackSlotKind::kLoadProperty:
case FeedbackSlotKind::kStoreDataPropertyInLiteral:
case FeedbackSlotKind::kStoreGlobalSloppy:
case FeedbackSlotKind::kStoreGlobalStrict:
case FeedbackSlotKind::kStoreInArrayLiteral:
case FeedbackSlotKind::kStoreKeyedSloppy:
case FeedbackSlotKind::kStoreKeyedStrict:
case FeedbackSlotKind::kStoreNamedSloppy:
case FeedbackSlotKind::kStoreNamedStrict:
case FeedbackSlotKind::kStoreOwnNamed: {
os << InlineCacheState2String(ic_state());
break;
}
case FeedbackSlotKind::kBinaryOp: {
os << "BinaryOp:" << GetBinaryOperationFeedback();
break;
}
case FeedbackSlotKind::kCompareOp: {
os << "CompareOp:" << GetCompareOperationFeedback();
break;
}
case FeedbackSlotKind::kForIn: {
os << "ForIn:" << GetForInFeedback();
break;
}
case FeedbackSlotKind::kLiteral:
case FeedbackSlotKind::kTypeProfile:
break;