Line data Source code
1 : // Copyright 2012 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "src/objects.h"
6 :
7 : #include <iomanip>
8 : #include <memory>
9 :
10 : #include "src/bootstrapper.h"
11 : #include "src/disasm.h"
12 : #include "src/disassembler.h"
13 : #include "src/interpreter/bytecodes.h"
14 : #include "src/objects-inl.h"
15 : #include "src/objects/debug-objects-inl.h"
16 : #include "src/ostreams.h"
17 : #include "src/regexp/jsregexp.h"
18 : #include "src/transitions-inl.h"
19 : #include "src/wasm/wasm-objects-inl.h"
20 :
21 : namespace v8 {
22 : namespace internal {
23 :
24 : #ifdef OBJECT_PRINT
25 :
26 : void Object::Print() {
27 : OFStream os(stdout);
28 : this->Print(os);
29 : os << std::flush;
30 : }
31 :
32 :
33 : void Object::Print(std::ostream& os) { // NOLINT
34 : if (IsSmi()) {
35 : os << "Smi: " << std::hex << "0x" << Smi::ToInt(this);
36 : os << std::dec << " (" << Smi::ToInt(this) << ")\n";
37 : } else {
38 : HeapObject::cast(this)->HeapObjectPrint(os);
39 : }
40 : }
41 :
42 :
43 : void HeapObject::PrintHeader(std::ostream& os, const char* id) { // NOLINT
44 : os << reinterpret_cast<void*>(this) << ": [";
45 : if (id != nullptr) {
46 : os << id;
47 : } else {
48 : os << map()->instance_type();
49 : }
50 : os << "]";
51 : if (GetHeap()->InOldSpace(this)) os << " in OldSpace";
52 : }
53 :
54 :
55 : void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
56 : InstanceType instance_type = map()->instance_type();
57 :
58 : HandleScope scope(GetIsolate());
59 : if (instance_type < FIRST_NONSTRING_TYPE) {
60 : String::cast(this)->StringPrint(os);
61 : os << "\n";
62 : return;
63 : }
64 :
65 : switch (instance_type) {
66 : case SYMBOL_TYPE:
67 : Symbol::cast(this)->SymbolPrint(os);
68 : break;
69 : case MAP_TYPE:
70 : Map::cast(this)->MapPrint(os);
71 : break;
72 : case HEAP_NUMBER_TYPE:
73 : HeapNumber::cast(this)->HeapNumberPrint(os);
74 : os << "\n";
75 : break;
76 : case MUTABLE_HEAP_NUMBER_TYPE:
77 : os << "<mutable ";
78 : HeapNumber::cast(this)->HeapNumberPrint(os);
79 : os << ">\n";
80 : break;
81 : case BIGINT_TYPE:
82 : BigInt::cast(this)->BigIntPrint(os);
83 : os << "\n";
84 : break;
85 : case FIXED_DOUBLE_ARRAY_TYPE:
86 : FixedDoubleArray::cast(this)->FixedDoubleArrayPrint(os);
87 : break;
88 : case HASH_TABLE_TYPE:
89 : case FIXED_ARRAY_TYPE:
90 : FixedArray::cast(this)->FixedArrayPrint(os);
91 : break;
92 : case PROPERTY_ARRAY_TYPE:
93 : PropertyArray::cast(this)->PropertyArrayPrint(os);
94 : break;
95 : case BYTE_ARRAY_TYPE:
96 : ByteArray::cast(this)->ByteArrayPrint(os);
97 : break;
98 : case BYTECODE_ARRAY_TYPE:
99 : BytecodeArray::cast(this)->BytecodeArrayPrint(os);
100 : break;
101 : case TRANSITION_ARRAY_TYPE:
102 : TransitionArray::cast(this)->TransitionArrayPrint(os);
103 : break;
104 : case FEEDBACK_VECTOR_TYPE:
105 : FeedbackVector::cast(this)->FeedbackVectorPrint(os);
106 : break;
107 : case FREE_SPACE_TYPE:
108 : FreeSpace::cast(this)->FreeSpacePrint(os);
109 : break;
110 :
111 : #define PRINT_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
112 : case Fixed##Type##Array::kInstanceType: \
113 : Fixed##Type##Array::cast(this)->FixedTypedArrayPrint(os); \
114 : break;
115 :
116 : TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY)
117 : #undef PRINT_FIXED_TYPED_ARRAY
118 :
119 : #define ARRAY_ITERATOR_CASE(type) case type:
120 : ARRAY_ITERATOR_TYPE_LIST(ARRAY_ITERATOR_CASE)
121 : #undef ARRAY_ITERATOR_CASE
122 : JSArrayIterator::cast(this)->JSArrayIteratorPrint(os);
123 : break;
124 :
125 : case FILLER_TYPE:
126 : os << "filler";
127 : break;
128 : case JS_OBJECT_TYPE: // fall through
129 : case JS_API_OBJECT_TYPE:
130 : case JS_SPECIAL_API_OBJECT_TYPE:
131 : case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
132 : case JS_GENERATOR_OBJECT_TYPE:
133 : case JS_ASYNC_GENERATOR_OBJECT_TYPE:
134 : case JS_ARGUMENTS_TYPE:
135 : case JS_ERROR_TYPE:
136 : case WASM_INSTANCE_TYPE: // TODO(titzer): debug printing for wasm objects
137 : case WASM_MEMORY_TYPE:
138 : case WASM_MODULE_TYPE:
139 : case WASM_TABLE_TYPE:
140 : JSObject::cast(this)->JSObjectPrint(os);
141 : break;
142 : case JS_PROMISE_TYPE:
143 : JSPromise::cast(this)->JSPromisePrint(os);
144 : break;
145 : case JS_ARRAY_TYPE:
146 : JSArray::cast(this)->JSArrayPrint(os);
147 : break;
148 : case JS_REGEXP_TYPE:
149 : JSRegExp::cast(this)->JSRegExpPrint(os);
150 : break;
151 : case ODDBALL_TYPE:
152 : Oddball::cast(this)->to_string()->Print(os);
153 : break;
154 : case JS_BOUND_FUNCTION_TYPE:
155 : JSBoundFunction::cast(this)->JSBoundFunctionPrint(os);
156 : break;
157 : case JS_FUNCTION_TYPE:
158 : JSFunction::cast(this)->JSFunctionPrint(os);
159 : break;
160 : case JS_GLOBAL_PROXY_TYPE:
161 : JSGlobalProxy::cast(this)->JSGlobalProxyPrint(os);
162 : break;
163 : case JS_GLOBAL_OBJECT_TYPE:
164 : JSGlobalObject::cast(this)->JSGlobalObjectPrint(os);
165 : break;
166 : case JS_VALUE_TYPE:
167 : JSValue::cast(this)->JSValuePrint(os);
168 : break;
169 : case JS_DATE_TYPE:
170 : JSDate::cast(this)->JSDatePrint(os);
171 : break;
172 : case CODE_TYPE:
173 : Code::cast(this)->CodePrint(os);
174 : break;
175 : case JS_PROXY_TYPE:
176 : JSProxy::cast(this)->JSProxyPrint(os);
177 : break;
178 : case JS_SET_TYPE:
179 : JSSet::cast(this)->JSSetPrint(os);
180 : break;
181 : case JS_MAP_TYPE:
182 : JSMap::cast(this)->JSMapPrint(os);
183 : break;
184 : case JS_SET_KEY_VALUE_ITERATOR_TYPE:
185 : case JS_SET_VALUE_ITERATOR_TYPE:
186 : JSSetIterator::cast(this)->JSSetIteratorPrint(os);
187 : break;
188 : case JS_MAP_KEY_ITERATOR_TYPE:
189 : case JS_MAP_KEY_VALUE_ITERATOR_TYPE:
190 : case JS_MAP_VALUE_ITERATOR_TYPE:
191 : JSMapIterator::cast(this)->JSMapIteratorPrint(os);
192 : break;
193 : case JS_WEAK_MAP_TYPE:
194 : JSWeakMap::cast(this)->JSWeakMapPrint(os);
195 : break;
196 : case JS_WEAK_SET_TYPE:
197 : JSWeakSet::cast(this)->JSWeakSetPrint(os);
198 : break;
199 : case JS_MODULE_NAMESPACE_TYPE:
200 : JSModuleNamespace::cast(this)->JSModuleNamespacePrint(os);
201 : break;
202 : case FOREIGN_TYPE:
203 : Foreign::cast(this)->ForeignPrint(os);
204 : break;
205 : case SHARED_FUNCTION_INFO_TYPE:
206 : SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(os);
207 : break;
208 : case JS_MESSAGE_OBJECT_TYPE:
209 : JSMessageObject::cast(this)->JSMessageObjectPrint(os);
210 : break;
211 : case CELL_TYPE:
212 : Cell::cast(this)->CellPrint(os);
213 : break;
214 : case PROPERTY_CELL_TYPE:
215 : PropertyCell::cast(this)->PropertyCellPrint(os);
216 : break;
217 : case WEAK_CELL_TYPE:
218 : WeakCell::cast(this)->WeakCellPrint(os);
219 : break;
220 : case JS_ARRAY_BUFFER_TYPE:
221 : JSArrayBuffer::cast(this)->JSArrayBufferPrint(os);
222 : break;
223 : case JS_TYPED_ARRAY_TYPE:
224 : JSTypedArray::cast(this)->JSTypedArrayPrint(os);
225 : break;
226 : case JS_DATA_VIEW_TYPE:
227 : JSDataView::cast(this)->JSDataViewPrint(os);
228 : break;
229 : #define MAKE_STRUCT_CASE(NAME, Name, name) \
230 : case NAME##_TYPE: \
231 : Name::cast(this)->Name##Print(os); \
232 : break;
233 : STRUCT_LIST(MAKE_STRUCT_CASE)
234 : #undef MAKE_STRUCT_CASE
235 :
236 : default:
237 : os << "UNKNOWN TYPE " << map()->instance_type();
238 : UNREACHABLE();
239 : break;
240 : }
241 : }
242 :
243 : void ByteArray::ByteArrayPrint(std::ostream& os) { // NOLINT
244 : os << "byte array, data starts at " << GetDataStartAddress();
245 : }
246 :
247 :
248 : void BytecodeArray::BytecodeArrayPrint(std::ostream& os) { // NOLINT
249 : HeapObject::PrintHeader(os, "BytecodeArray");
250 : Disassemble(os);
251 : }
252 :
253 :
254 : void FreeSpace::FreeSpacePrint(std::ostream& os) { // NOLINT
255 : os << "free space, size " << Size();
256 : }
257 :
258 :
259 : template <class Traits>
260 : void FixedTypedArray<Traits>::FixedTypedArrayPrint(
261 : std::ostream& os) { // NOLINT
262 : os << "fixed " << Traits::Designator();
263 : }
264 :
265 : bool JSObject::PrintProperties(std::ostream& os) { // NOLINT
266 : if (HasFastProperties()) {
267 : DescriptorArray* descs = map()->instance_descriptors();
268 : int nof_inobject_properties = map()->GetInObjectProperties();
269 : int i = 0;
270 : for (; i < map()->NumberOfOwnDescriptors(); i++) {
271 : os << "\n ";
272 : descs->GetKey(i)->NamePrint(os);
273 : os << ": ";
274 : PropertyDetails details = descs->GetDetails(i);
275 : switch (details.location()) {
276 : case kField: {
277 : FieldIndex field_index = FieldIndex::ForDescriptor(map(), i);
278 : if (IsUnboxedDoubleField(field_index)) {
279 : os << "<unboxed double> " << RawFastDoublePropertyAt(field_index);
280 : } else {
281 : os << Brief(RawFastPropertyAt(field_index));
282 : }
283 : break;
284 : }
285 : case kDescriptor:
286 : os << Brief(descs->GetValue(i));
287 : break;
288 : }
289 : os << " ";
290 : details.PrintAsFastTo(os, PropertyDetails::kForProperties);
291 : if (details.location() != kField) continue;
292 : int field_index = details.field_index();
293 : if (nof_inobject_properties <= field_index) {
294 : field_index -= nof_inobject_properties;
295 : os << " properties[" << field_index << "]";
296 : }
297 : }
298 : return i > 0;
299 : } else if (IsJSGlobalObject()) {
300 : JSGlobalObject::cast(this)->global_dictionary()->Print(os);
301 : } else {
302 : property_dictionary()->Print(os);
303 : }
304 : return true;
305 : }
306 :
307 : namespace {
308 :
309 : template <class T>
310 : bool IsTheHoleAt(T* array, int index) {
311 : return false;
312 : }
313 :
314 : template <>
315 : bool IsTheHoleAt(FixedDoubleArray* array, int index) {
316 : return array->is_the_hole(index);
317 : }
318 :
319 : template <class T>
320 : double GetScalarElement(T* array, int index) {
321 : if (IsTheHoleAt(array, index)) {
322 : return std::numeric_limits<double>::quiet_NaN();
323 : }
324 : return array->get_scalar(index);
325 : }
326 :
327 : template <class T>
328 : void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
329 : const bool print_the_hole = std::is_same<T, FixedDoubleArray>::value;
330 : T* array = T::cast(object);
331 : if (array->length() == 0) return;
332 : int previous_index = 0;
333 : double previous_value = GetScalarElement(array, 0);
334 : double value = 0.0;
335 : int i;
336 : for (i = 1; i <= array->length(); i++) {
337 : if (i < array->length()) value = GetScalarElement(array, i);
338 : bool values_are_nan = std::isnan(previous_value) && std::isnan(value);
339 : if (i != array->length() && (previous_value == value || values_are_nan) &&
340 : IsTheHoleAt(array, i - 1) == IsTheHoleAt(array, i)) {
341 : continue;
342 : }
343 : os << "\n";
344 : std::stringstream ss;
345 : ss << previous_index;
346 : if (previous_index != i - 1) {
347 : ss << '-' << (i - 1);
348 : }
349 : os << std::setw(12) << ss.str() << ": ";
350 : if (print_the_hole && IsTheHoleAt(array, i - 1)) {
351 : os << "<the_hole>";
352 : } else {
353 : os << previous_value;
354 : }
355 : previous_index = i;
356 : previous_value = value;
357 : }
358 : }
359 :
360 : template <typename T>
361 : void PrintFixedArrayElements(std::ostream& os, T* array) {
362 : // Print in array notation for non-sparse arrays.
363 : Object* previous_value = array->length() > 0 ? array->get(0) : nullptr;
364 : Object* value = nullptr;
365 : int previous_index = 0;
366 : int i;
367 : for (i = 1; i <= array->length(); i++) {
368 : if (i < array->length()) value = array->get(i);
369 : if (previous_value == value && i != array->length()) {
370 : continue;
371 : }
372 : os << "\n";
373 : std::stringstream ss;
374 : ss << previous_index;
375 : if (previous_index != i - 1) {
376 : ss << '-' << (i - 1);
377 : }
378 : os << std::setw(12) << ss.str() << ": " << Brief(previous_value);
379 : previous_index = i;
380 : previous_value = value;
381 : }
382 : }
383 :
384 : void PrintDictionaryElements(std::ostream& os, FixedArrayBase* elements) {
385 : // Print some internal fields
386 : SeededNumberDictionary* dict = SeededNumberDictionary::cast(elements);
387 : if (dict->requires_slow_elements()) {
388 : os << "\n - requires_slow_elements";
389 : } else {
390 : os << "\n - max_number_key: " << dict->max_number_key();
391 : }
392 : dict->Print(os);
393 : }
394 :
395 : void PrintSloppyArgumentElements(std::ostream& os, ElementsKind kind,
396 : SloppyArgumentsElements* elements) {
397 : Isolate* isolate = elements->GetIsolate();
398 : FixedArray* arguments_store = elements->arguments();
399 : os << "\n 0: context = " << Brief(elements->context())
400 : << "\n 1: arguments_store = " << Brief(arguments_store)
401 : << "\n parameter to context slot map:";
402 : for (uint32_t i = 0; i < elements->parameter_map_length(); i++) {
403 : uint32_t raw_index = i + SloppyArgumentsElements::kParameterMapStart;
404 : Object* mapped_entry = elements->get_mapped_entry(i);
405 : os << "\n " << raw_index << ": param(" << i
406 : << ") = " << Brief(mapped_entry);
407 : if (mapped_entry->IsTheHole(isolate)) {
408 : os << " in the arguments_store[" << i << "]";
409 : } else {
410 : os << " in the context";
411 : }
412 : }
413 : if (arguments_store->length() == 0) return;
414 : os << "\n }"
415 : << "\n - arguments_store = " << Brief(arguments_store) << " "
416 : << ElementsKindToString(arguments_store->map()->elements_kind()) << " {";
417 : if (kind == FAST_SLOPPY_ARGUMENTS_ELEMENTS) {
418 : PrintFixedArrayElements(os, arguments_store);
419 : } else {
420 : DCHECK_EQ(kind, SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
421 : PrintDictionaryElements(os, arguments_store);
422 : }
423 : }
424 :
425 : } // namespace
426 :
427 : void JSObject::PrintElements(std::ostream& os) { // NOLINT
428 : // Don't call GetElementsKind, its validation code can cause the printer to
429 : // fail when debugging.
430 : os << " - elements = " << Brief(elements()) << " {";
431 : if (elements()->length() == 0) {
432 : os << " }\n";
433 : return;
434 : }
435 : switch (map()->elements_kind()) {
436 : case HOLEY_SMI_ELEMENTS:
437 : case PACKED_SMI_ELEMENTS:
438 : case HOLEY_ELEMENTS:
439 : case PACKED_ELEMENTS:
440 : case FAST_STRING_WRAPPER_ELEMENTS: {
441 : PrintFixedArrayElements(os, FixedArray::cast(elements()));
442 : break;
443 : }
444 : case HOLEY_DOUBLE_ELEMENTS:
445 : case PACKED_DOUBLE_ELEMENTS: {
446 : DoPrintElements<FixedDoubleArray>(os, elements());
447 : break;
448 : }
449 :
450 : #define PRINT_ELEMENTS(Type, type, TYPE, elementType, size) \
451 : case TYPE##_ELEMENTS: { \
452 : DoPrintElements<Fixed##Type##Array>(os, elements()); \
453 : break; \
454 : }
455 : TYPED_ARRAYS(PRINT_ELEMENTS)
456 : #undef PRINT_ELEMENTS
457 :
458 : case DICTIONARY_ELEMENTS:
459 : case SLOW_STRING_WRAPPER_ELEMENTS:
460 : PrintDictionaryElements(os, elements());
461 : break;
462 : case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
463 : case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
464 : PrintSloppyArgumentElements(os, map()->elements_kind(),
465 : SloppyArgumentsElements::cast(elements()));
466 : break;
467 : case NO_ELEMENTS:
468 : break;
469 : }
470 : os << "\n }\n";
471 : }
472 :
473 :
474 : static void JSObjectPrintHeader(std::ostream& os, JSObject* obj,
475 : const char* id) { // NOLINT
476 : obj->PrintHeader(os, id);
477 : // Don't call GetElementsKind, its validation code can cause the printer to
478 : // fail when debugging.
479 : os << "\n - map = " << reinterpret_cast<void*>(obj->map()) << " [";
480 : if (obj->HasFastProperties()) {
481 : os << "FastProperties";
482 : } else {
483 : os << "DictionaryProperties";
484 : }
485 : PrototypeIterator iter(obj->GetIsolate(), obj);
486 : os << "]\n - prototype = " << reinterpret_cast<void*>(iter.GetCurrent());
487 : os << "\n - elements = " << Brief(obj->elements()) << " ["
488 : << ElementsKindToString(obj->map()->elements_kind());
489 : if (obj->elements()->IsCowArray()) os << " (COW)";
490 : os << "]";
491 : if (obj->GetEmbedderFieldCount() > 0) {
492 : os << "\n - embedder fields: " << obj->GetEmbedderFieldCount();
493 : }
494 : }
495 :
496 :
497 : static void JSObjectPrintBody(std::ostream& os, JSObject* obj, // NOLINT
498 : bool print_elements = true) {
499 : os << "\n - properties = " << Brief(obj->raw_properties_or_hash()) << " {";
500 : if (obj->PrintProperties(os)) os << "\n ";
501 : os << "}\n";
502 : if (print_elements && obj->elements()->length() > 0) {
503 : obj->PrintElements(os);
504 : }
505 : int embedder_fields = obj->GetEmbedderFieldCount();
506 : if (embedder_fields > 0) {
507 : os << " - embedder fields = {";
508 : for (int i = 0; i < embedder_fields; i++) {
509 : os << "\n " << obj->GetEmbedderField(i);
510 : }
511 : os << "\n }\n";
512 : }
513 : }
514 :
515 :
516 : void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT
517 : JSObjectPrintHeader(os, this, nullptr);
518 : JSObjectPrintBody(os, this);
519 : }
520 :
521 : void JSArray::JSArrayPrint(std::ostream& os) { // NOLINT
522 : JSObjectPrintHeader(os, this, "JSArray");
523 : os << "\n - length = " << Brief(this->length());
524 : JSObjectPrintBody(os, this);
525 : }
526 :
527 : void JSPromise::JSPromisePrint(std::ostream& os) { // NOLINT
528 : JSObjectPrintHeader(os, this, "JSPromise");
529 : os << "\n - status = " << JSPromise::Status(status());
530 : os << "\n - result = " << Brief(result());
531 : os << "\n - deferred_promise: " << Brief(deferred_promise());
532 : os << "\n - deferred_on_resolve: " << Brief(deferred_on_resolve());
533 : os << "\n - deferred_on_reject: " << Brief(deferred_on_reject());
534 : os << "\n - fulfill_reactions = " << Brief(fulfill_reactions());
535 : os << "\n - reject_reactions = " << Brief(reject_reactions());
536 : os << "\n - has_handler = " << has_handler();
537 : os << "\n ";
538 : }
539 :
540 : void JSRegExp::JSRegExpPrint(std::ostream& os) { // NOLINT
541 : JSObjectPrintHeader(os, this, "JSRegExp");
542 : os << "\n - data = " << Brief(data());
543 : os << "\n - source = " << Brief(source());
544 : JSObjectPrintBody(os, this);
545 : }
546 :
547 :
548 : void Symbol::SymbolPrint(std::ostream& os) { // NOLINT
549 : HeapObject::PrintHeader(os, "Symbol");
550 : os << "\n - hash: " << Hash();
551 : os << "\n - name: " << Brief(name());
552 : if (name()->IsUndefined(GetIsolate())) {
553 : os << " (" << PrivateSymbolToName() << ")";
554 : }
555 : os << "\n - private: " << is_private();
556 : os << "\n";
557 : }
558 :
559 :
560 : void Map::MapPrint(std::ostream& os) { // NOLINT
561 : HeapObject::PrintHeader(os, "Map");
562 : os << "\n - type: " << instance_type();
563 : os << "\n - instance size: " << instance_size();
564 : if (IsJSObjectMap()) {
565 : os << "\n - inobject properties: " << GetInObjectProperties();
566 : }
567 : os << "\n - elements kind: " << ElementsKindToString(elements_kind());
568 : os << "\n - unused property fields: " << UnusedPropertyFields();
569 : os << "\n - enum length: ";
570 : if (EnumLength() == kInvalidEnumCacheSentinel) {
571 : os << "invalid";
572 : } else {
573 : os << EnumLength();
574 : }
575 : if (is_deprecated()) os << "\n - deprecated_map";
576 : if (is_stable()) os << "\n - stable_map";
577 : if (is_migration_target()) os << "\n - migration_target";
578 : if (is_dictionary_map()) os << "\n - dictionary_map";
579 : if (has_hidden_prototype()) os << "\n - has_hidden_prototype";
580 : if (has_named_interceptor()) os << "\n - named_interceptor";
581 : if (has_indexed_interceptor()) os << "\n - indexed_interceptor";
582 : if (may_have_interesting_symbols()) os << "\n - may_have_interesting_symbols";
583 : if (is_undetectable()) os << "\n - undetectable";
584 : if (is_callable()) os << "\n - callable";
585 : if (is_constructor()) os << "\n - constructor";
586 : if (has_prototype_slot()) {
587 : os << "\n - has_prototype_slot";
588 : if (has_non_instance_prototype()) os << " (non-instance prototype)";
589 : }
590 : if (is_access_check_needed()) os << "\n - access_check_needed";
591 : if (!is_extensible()) os << "\n - non-extensible";
592 : if (is_prototype_map()) {
593 : os << "\n - prototype_map";
594 : os << "\n - prototype info: " << Brief(prototype_info());
595 : } else {
596 : os << "\n - back pointer: " << Brief(GetBackPointer());
597 : }
598 : os << "\n - instance descriptors " << (owns_descriptors() ? "(own) " : "")
599 : << "#" << NumberOfOwnDescriptors() << ": "
600 : << Brief(instance_descriptors());
601 : if (FLAG_unbox_double_fields) {
602 : os << "\n - layout descriptor: ";
603 : layout_descriptor()->ShortPrint(os);
604 : }
605 : {
606 : DisallowHeapAllocation no_gc;
607 : TransitionsAccessor transitions(this, &no_gc);
608 : int nof_transitions = transitions.NumberOfTransitions();
609 : if (nof_transitions > 0) {
610 : os << "\n - transitions #" << nof_transitions << ": "
611 : << Brief(raw_transitions());
612 : transitions.PrintTransitions(os);
613 : }
614 : }
615 : os << "\n - prototype: " << Brief(prototype());
616 : os << "\n - constructor: " << Brief(GetConstructor());
617 : os << "\n - dependent code: " << Brief(dependent_code());
618 : os << "\n - construction counter: " << construction_counter();
619 : os << "\n";
620 : }
621 :
622 :
623 : void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(
624 : std::ostream& os) { // NOLINT
625 : HeapObject::PrintHeader(os, "AliasedArgumentsEntry");
626 : os << "\n - aliased_context_slot: " << aliased_context_slot();
627 : }
628 :
629 :
630 : void FixedArray::FixedArrayPrint(std::ostream& os) { // NOLINT
631 : HeapObject::PrintHeader(os, IsHashTable() ? "HashTable" : "FixedArray");
632 : os << "\n - map = " << Brief(map());
633 : os << "\n - length: " << length();
634 : PrintFixedArrayElements(os, this);
635 : os << "\n";
636 : }
637 :
638 : void PropertyArray::PropertyArrayPrint(std::ostream& os) { // NOLINT
639 : HeapObject::PrintHeader(os, "PropertyArray");
640 : os << "\n - map = " << Brief(map());
641 : os << "\n - length: " << length();
642 : os << "\n - hash: " << Hash();
643 : PrintFixedArrayElements(os, this);
644 : os << "\n";
645 : }
646 :
647 : void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT
648 : HeapObject::PrintHeader(os, "FixedDoubleArray");
649 : os << "\n - map = " << Brief(map());
650 : os << "\n - length: " << length();
651 : DoPrintElements<FixedDoubleArray>(os, this);
652 : os << "\n";
653 : }
654 :
655 :
656 : void TransitionArray::TransitionArrayPrint(std::ostream& os) { // NOLINT
657 : HeapObject::PrintHeader(os, "TransitionArray");
658 : os << "\n - capacity: " << length();
659 : for (int i = 0; i < length(); i++) {
660 : os << "\n [" << i << "]: " << Brief(get(i));
661 : if (i == kPrototypeTransitionsIndex) os << " (prototype transitions)";
662 : if (i == kTransitionLengthIndex) os << " (number of transitions)";
663 : }
664 : os << "\n";
665 : }
666 :
667 : template void FeedbackVectorSpecBase<StaticFeedbackVectorSpec>::Print();
668 : template void FeedbackVectorSpecBase<FeedbackVectorSpec>::Print();
669 :
670 : template <typename Derived>
671 : void FeedbackVectorSpecBase<Derived>::Print() {
672 : OFStream os(stdout);
673 : FeedbackVectorSpecPrint(os);
674 : os << std::flush;
675 : }
676 :
677 : template <typename Derived>
678 : void FeedbackVectorSpecBase<Derived>::FeedbackVectorSpecPrint(
679 : std::ostream& os) { // NOLINT
680 : int slot_count = This()->slots();
681 : os << " - slot_count: " << slot_count;
682 : if (slot_count == 0) {
683 : os << " (empty)\n";
684 : return;
685 : }
686 :
687 : for (int slot = 0; slot < slot_count;) {
688 : FeedbackSlotKind kind = This()->GetKind(FeedbackSlot(slot));
689 : int entry_size = FeedbackMetadata::GetSlotSize(kind);
690 : DCHECK_LT(0, entry_size);
691 : os << "\n Slot #" << slot << " " << kind;
692 : slot += entry_size;
693 : }
694 : os << "\n";
695 : }
696 :
697 : void FeedbackMetadata::Print() {
698 : OFStream os(stdout);
699 : FeedbackMetadataPrint(os);
700 : os << std::flush;
701 : }
702 :
703 : void FeedbackMetadata::FeedbackMetadataPrint(std::ostream& os) { // NOLINT
704 : HeapObject::PrintHeader(os, "FeedbackMetadata");
705 : os << "\n - length: " << length();
706 : if (length() == 0) {
707 : os << " (empty)\n";
708 : return;
709 : }
710 : os << "\n - slot_count: " << slot_count();
711 :
712 : FeedbackMetadataIterator iter(this);
713 : while (iter.HasNext()) {
714 : FeedbackSlot slot = iter.Next();
715 : FeedbackSlotKind kind = iter.kind();
716 : os << "\n Slot " << slot << " " << kind;
717 : }
718 : os << "\n";
719 : }
720 :
721 : void FeedbackVector::Print() {
722 : OFStream os(stdout);
723 : FeedbackVectorPrint(os);
724 : os << std::flush;
725 : }
726 :
727 : void FeedbackVector::FeedbackVectorPrint(std::ostream& os) { // NOLINT
728 : HeapObject::PrintHeader(os, "FeedbackVector");
729 : os << "\n - length: " << length();
730 : if (length() == 0) {
731 : os << " (empty)\n";
732 : return;
733 : }
734 :
735 : os << "\n SharedFunctionInfo: " << Brief(shared_function_info());
736 : os << "\n Optimized Code: " << Brief(optimized_code_cell());
737 : os << "\n Invocation Count: " << invocation_count();
738 : os << "\n Profiler Ticks: " << profiler_ticks();
739 :
740 : FeedbackMetadataIterator iter(metadata());
741 : while (iter.HasNext()) {
742 : FeedbackSlot slot = iter.Next();
743 : FeedbackSlotKind kind = iter.kind();
744 :
745 : os << "\n Slot " << slot << " " << kind;
746 : os << " ";
747 : switch (kind) {
748 : case FeedbackSlotKind::kLoadProperty: {
749 : LoadICNexus nexus(this, slot);
750 : os << Code::ICState2String(nexus.StateFromFeedback());
751 : break;
752 : }
753 : case FeedbackSlotKind::kLoadGlobalInsideTypeof:
754 : case FeedbackSlotKind::kLoadGlobalNotInsideTypeof: {
755 : LoadGlobalICNexus nexus(this, slot);
756 : os << Code::ICState2String(nexus.StateFromFeedback());
757 : break;
758 : }
759 : case FeedbackSlotKind::kLoadKeyed: {
760 : KeyedLoadICNexus nexus(this, slot);
761 : os << Code::ICState2String(nexus.StateFromFeedback());
762 : break;
763 : }
764 : case FeedbackSlotKind::kCall: {
765 : CallICNexus nexus(this, slot);
766 : os << Code::ICState2String(nexus.StateFromFeedback());
767 : break;
768 : }
769 : case FeedbackSlotKind::kStoreNamedSloppy:
770 : case FeedbackSlotKind::kStoreNamedStrict:
771 : case FeedbackSlotKind::kStoreOwnNamed:
772 : case FeedbackSlotKind::kStoreGlobalSloppy:
773 : case FeedbackSlotKind::kStoreGlobalStrict: {
774 : StoreICNexus nexus(this, slot);
775 : os << Code::ICState2String(nexus.StateFromFeedback());
776 : break;
777 : }
778 : case FeedbackSlotKind::kStoreKeyedSloppy:
779 : case FeedbackSlotKind::kStoreKeyedStrict: {
780 : KeyedStoreICNexus nexus(this, slot);
781 : os << Code::ICState2String(nexus.StateFromFeedback());
782 : break;
783 : }
784 : case FeedbackSlotKind::kBinaryOp: {
785 : BinaryOpICNexus nexus(this, slot);
786 : os << Code::ICState2String(nexus.StateFromFeedback()) << " ("
787 : << nexus.GetBinaryOperationFeedback() << ")";
788 : break;
789 : }
790 : case FeedbackSlotKind::kCompareOp: {
791 : CompareICNexus nexus(this, slot);
792 : os << Code::ICState2String(nexus.StateFromFeedback()) << " ("
793 : << nexus.GetCompareOperationFeedback() << ")";
794 : break;
795 : }
796 : case FeedbackSlotKind::kForIn: {
797 : ForInICNexus nexus(this, slot);
798 : os << Code::ICState2String(nexus.StateFromFeedback());
799 : break;
800 : }
801 : case FeedbackSlotKind::kStoreDataPropertyInLiteral: {
802 : StoreDataPropertyInLiteralICNexus nexus(this, slot);
803 : os << Code::ICState2String(nexus.StateFromFeedback());
804 : break;
805 : }
806 : case FeedbackSlotKind::kCreateClosure:
807 : case FeedbackSlotKind::kLiteral:
808 : case FeedbackSlotKind::kTypeProfile:
809 : break;
810 : case FeedbackSlotKind::kInvalid:
811 : case FeedbackSlotKind::kKindsNumber:
812 : UNREACHABLE();
813 : break;
814 : }
815 :
816 : int entry_size = iter.entry_size();
817 : for (int i = 0; i < entry_size; i++) {
818 : int index = GetIndex(slot) + i;
819 : os << "\n [" << index << "]: " << Brief(get(index));
820 : }
821 : }
822 : os << "\n";
823 : }
824 :
825 :
826 : void JSValue::JSValuePrint(std::ostream& os) { // NOLINT
827 : JSObjectPrintHeader(os, this, "JSValue");
828 : os << "\n - value = " << Brief(value());
829 : JSObjectPrintBody(os, this);
830 : }
831 :
832 :
833 : void JSMessageObject::JSMessageObjectPrint(std::ostream& os) { // NOLINT
834 : JSObjectPrintHeader(os, this, "JSMessageObject");
835 : os << "\n - type: " << type();
836 : os << "\n - arguments: " << Brief(argument());
837 : os << "\n - start_position: " << start_position();
838 : os << "\n - end_position: " << end_position();
839 : os << "\n - script: " << Brief(script());
840 : os << "\n - stack_frames: " << Brief(stack_frames());
841 : JSObjectPrintBody(os, this);
842 : }
843 :
844 :
845 : void String::StringPrint(std::ostream& os) { // NOLINT
846 : if (!HasOnlyOneByteChars()) {
847 : os << "u";
848 : }
849 : if (StringShape(this).IsInternalized()) {
850 : os << "#";
851 : } else if (StringShape(this).IsCons()) {
852 : os << "c\"";
853 : } else if (StringShape(this).IsThin()) {
854 : os << ">\"";
855 : } else {
856 : os << "\"";
857 : }
858 :
859 : const char truncated_epilogue[] = "...<truncated>";
860 : int len = length();
861 : if (!FLAG_use_verbose_printer) {
862 : if (len > 100) {
863 : len = 100 - sizeof(truncated_epilogue);
864 : }
865 : }
866 : for (int i = 0; i < len; i++) {
867 : os << AsUC16(Get(i));
868 : }
869 : if (len != length()) {
870 : os << truncated_epilogue;
871 : }
872 :
873 : if (!StringShape(this).IsInternalized()) os << "\"";
874 : }
875 :
876 :
877 : void Name::NamePrint(std::ostream& os) { // NOLINT
878 : if (IsString()) {
879 : String::cast(this)->StringPrint(os);
880 : } else {
881 : os << Brief(this);
882 : }
883 : }
884 :
885 :
886 : static const char* const weekdays[] = {
887 : "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
888 : };
889 :
890 :
891 : void JSDate::JSDatePrint(std::ostream& os) { // NOLINT
892 : JSObjectPrintHeader(os, this, "JSDate");
893 : os << "\n - value = " << Brief(value());
894 : if (!year()->IsSmi()) {
895 : os << "\n - time = NaN\n";
896 : } else {
897 : // TODO(svenpanne) Add some basic formatting to our streams.
898 : ScopedVector<char> buf(100);
899 : SNPrintF(buf, "\n - time = %s %04d/%02d/%02d %02d:%02d:%02d\n",
900 : weekdays[weekday()->IsSmi() ? Smi::ToInt(weekday()) + 1 : 0],
901 : year()->IsSmi() ? Smi::ToInt(year()) : -1,
902 : month()->IsSmi() ? Smi::ToInt(month()) : -1,
903 : day()->IsSmi() ? Smi::ToInt(day()) : -1,
904 : hour()->IsSmi() ? Smi::ToInt(hour()) : -1,
905 : min()->IsSmi() ? Smi::ToInt(min()) : -1,
906 : sec()->IsSmi() ? Smi::ToInt(sec()) : -1);
907 : os << buf.start();
908 : }
909 : JSObjectPrintBody(os, this);
910 : }
911 :
912 :
913 : void JSProxy::JSProxyPrint(std::ostream& os) { // NOLINT
914 : HeapObject::PrintHeader(os, "JSProxy");
915 : os << "\n - map = " << reinterpret_cast<void*>(map());
916 : os << "\n - target = ";
917 : target()->ShortPrint(os);
918 : os << "\n - handler = ";
919 : handler()->ShortPrint(os);
920 : os << "\n - hash = ";
921 : hash()->ShortPrint(os);
922 : os << "\n";
923 : }
924 :
925 :
926 : void JSSet::JSSetPrint(std::ostream& os) { // NOLINT
927 : JSObjectPrintHeader(os, this, "JSSet");
928 : os << " - table = " << Brief(table());
929 : JSObjectPrintBody(os, this);
930 : }
931 :
932 :
933 : void JSMap::JSMapPrint(std::ostream& os) { // NOLINT
934 : JSObjectPrintHeader(os, this, "JSMap");
935 : os << " - table = " << Brief(table());
936 : JSObjectPrintBody(os, this);
937 : }
938 :
939 : void JSCollectionIterator::JSCollectionIteratorPrint(
940 : std::ostream& os) { // NOLINT
941 : os << "\n - table = " << Brief(table());
942 : os << "\n - index = " << Brief(index());
943 : os << "\n";
944 : }
945 :
946 :
947 : void JSSetIterator::JSSetIteratorPrint(std::ostream& os) { // NOLINT
948 : JSObjectPrintHeader(os, this, "JSSetIterator");
949 : JSCollectionIteratorPrint(os);
950 : }
951 :
952 :
953 : void JSMapIterator::JSMapIteratorPrint(std::ostream& os) { // NOLINT
954 : JSObjectPrintHeader(os, this, "JSMapIterator");
955 : JSCollectionIteratorPrint(os);
956 : }
957 :
958 :
959 : void JSWeakMap::JSWeakMapPrint(std::ostream& os) { // NOLINT
960 : JSObjectPrintHeader(os, this, "JSWeakMap");
961 : os << "\n - table = " << Brief(table());
962 : JSObjectPrintBody(os, this);
963 : }
964 :
965 :
966 : void JSWeakSet::JSWeakSetPrint(std::ostream& os) { // NOLINT
967 : JSObjectPrintHeader(os, this, "JSWeakSet");
968 : os << "\n - table = " << Brief(table());
969 : JSObjectPrintBody(os, this);
970 : }
971 :
972 :
973 : void JSArrayBuffer::JSArrayBufferPrint(std::ostream& os) { // NOLINT
974 : JSObjectPrintHeader(os, this, "JSArrayBuffer");
975 : os << "\n - backing_store = " << backing_store();
976 : os << "\n - byte_length = " << Brief(byte_length());
977 : if (is_external()) os << "\n - external";
978 : if (is_neuterable()) os << "\n - neuterable";
979 : if (was_neutered()) os << "\n - neutered";
980 : if (is_shared()) os << "\n - shared";
981 : if (has_guard_region()) os << "\n - has_guard_region";
982 : if (is_wasm_buffer()) os << "\n - wasm_buffer";
983 : JSObjectPrintBody(os, this, !was_neutered());
984 : }
985 :
986 :
987 : void JSTypedArray::JSTypedArrayPrint(std::ostream& os) { // NOLINT
988 : JSObjectPrintHeader(os, this, "JSTypedArray");
989 : os << "\n - buffer = " << Brief(buffer());
990 : os << "\n - byte_offset = " << Brief(byte_offset());
991 : os << "\n - byte_length = " << Brief(byte_length());
992 : os << "\n - length = " << Brief(length());
993 : if (WasNeutered()) os << "\n - neutered";
994 : JSObjectPrintBody(os, this, !WasNeutered());
995 : }
996 :
997 : void JSArrayIterator::JSArrayIteratorPrint(std::ostream& os) { // NOLING
998 : JSObjectPrintHeader(os, this, "JSArrayIterator");
999 :
1000 : InstanceType instance_type = map()->instance_type();
1001 : std::string type;
1002 : if (instance_type <= LAST_ARRAY_KEY_ITERATOR_TYPE) {
1003 : type = "keys";
1004 : } else if (instance_type <= LAST_ARRAY_KEY_VALUE_ITERATOR_TYPE) {
1005 : type = "entries";
1006 : } else {
1007 : type = "values";
1008 : }
1009 :
1010 : os << "\n - type = " << type;
1011 : os << "\n - object = " << Brief(object());
1012 : os << "\n - index = " << Brief(index());
1013 :
1014 : JSObjectPrintBody(os, this);
1015 : }
1016 :
1017 : void JSDataView::JSDataViewPrint(std::ostream& os) { // NOLINT
1018 : JSObjectPrintHeader(os, this, "JSDataView");
1019 : os << "\n - buffer =" << Brief(buffer());
1020 : os << "\n - byte_offset = " << Brief(byte_offset());
1021 : os << "\n - byte_length = " << Brief(byte_length());
1022 : if (WasNeutered()) os << "\n - neutered";
1023 : JSObjectPrintBody(os, this, !WasNeutered());
1024 : }
1025 :
1026 :
1027 : void JSBoundFunction::JSBoundFunctionPrint(std::ostream& os) { // NOLINT
1028 : JSObjectPrintHeader(os, this, "JSBoundFunction");
1029 : os << "\n - bound_target_function = " << Brief(bound_target_function());
1030 : os << "\n - bound_this = " << Brief(bound_this());
1031 : os << "\n - bound_arguments = " << Brief(bound_arguments());
1032 : JSObjectPrintBody(os, this);
1033 : }
1034 :
1035 :
1036 : namespace {
1037 :
1038 : std::ostream& operator<<(std::ostream& os, FunctionKind kind) {
1039 : os << "[";
1040 : if (kind == FunctionKind::kNormalFunction) {
1041 : os << " NormalFunction";
1042 : } else {
1043 : #define PRINT_FLAG(name) \
1044 : if (static_cast<int>(kind) & static_cast<int>(FunctionKind::k##name)) { \
1045 : os << " " << #name; \
1046 : }
1047 :
1048 : PRINT_FLAG(ArrowFunction)
1049 : PRINT_FLAG(GeneratorFunction)
1050 : PRINT_FLAG(ConciseMethod)
1051 : PRINT_FLAG(DefaultConstructor)
1052 : PRINT_FLAG(DerivedConstructor)
1053 : PRINT_FLAG(BaseConstructor)
1054 : PRINT_FLAG(GetterFunction)
1055 : PRINT_FLAG(SetterFunction)
1056 : PRINT_FLAG(AsyncFunction)
1057 : PRINT_FLAG(Module)
1058 : #undef PRINT_FLAG
1059 : }
1060 : return os << " ]";
1061 : }
1062 :
1063 : } // namespace
1064 :
1065 : void JSFunction::JSFunctionPrint(std::ostream& os) { // NOLINT
1066 : JSObjectPrintHeader(os, this, "Function");
1067 : os << "\n - function prototype = ";
1068 : if (has_prototype_slot()) {
1069 : if (has_prototype()) {
1070 : os << Brief(prototype());
1071 : if (map()->has_non_instance_prototype()) {
1072 : os << " (non-instance prototype)";
1073 : }
1074 : }
1075 : os << "\n - initial_map = ";
1076 : if (has_initial_map()) os << Brief(initial_map());
1077 : } else {
1078 : os << "<no-prototype-slot>";
1079 : }
1080 : os << "\n - shared_info = " << Brief(shared());
1081 : os << "\n - name = " << Brief(shared()->name());
1082 : os << "\n - formal_parameter_count = "
1083 : << shared()->internal_formal_parameter_count();
1084 : os << "\n - kind = " << shared()->kind();
1085 : os << "\n - context = " << Brief(context());
1086 : os << "\n - code = " << Brief(code());
1087 : if (IsInterpreted()) {
1088 : os << "\n - interpreted";
1089 : if (shared()->HasBytecodeArray()) {
1090 : os << "\n - bytecode = " << shared()->bytecode_array();
1091 : }
1092 : }
1093 : if (WasmExportedFunction::IsWasmExportedFunction(this)) {
1094 : WasmExportedFunction* function = WasmExportedFunction::cast(this);
1095 : os << "\n - WASM instance "
1096 : << reinterpret_cast<void*>(function->instance());
1097 : os << "\n context "
1098 : << reinterpret_cast<void*>(function->instance()->wasm_context()->get());
1099 : os << "\n - WASM function index " << function->function_index();
1100 : }
1101 : shared()->PrintSourceCode(os);
1102 : JSObjectPrintBody(os, this);
1103 : os << "\n - feedback vector: ";
1104 : if (feedback_vector_cell()->value()->IsFeedbackVector()) {
1105 : feedback_vector()->FeedbackVectorPrint(os);
1106 : } else {
1107 : os << "not available\n";
1108 : }
1109 : }
1110 :
1111 : void SharedFunctionInfo::PrintSourceCode(std::ostream& os) {
1112 : if (HasSourceCode()) {
1113 : os << "\n - source code = ";
1114 : String* source = String::cast(Script::cast(script())->source());
1115 : int start = start_position();
1116 : int length = end_position() - start;
1117 : std::unique_ptr<char[]> source_string = source->ToCString(
1118 : DISALLOW_NULLS, FAST_STRING_TRAVERSAL, start, length, nullptr);
1119 : os << source_string.get();
1120 : }
1121 : }
1122 :
1123 : void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) { // NOLINT
1124 : HeapObject::PrintHeader(os, "SharedFunctionInfo");
1125 : os << "\n - name = ";
1126 : if (has_shared_name()) {
1127 : os << Brief(raw_name());
1128 : } else {
1129 : os << "<no-shared-name>";
1130 : }
1131 : os << "\n - kind = " << kind();
1132 : os << "\n - function_map_index = " << function_map_index();
1133 : os << "\n - formal_parameter_count = " << internal_formal_parameter_count();
1134 : os << "\n - expected_nof_properties = " << expected_nof_properties();
1135 : os << "\n - language_mode = " << language_mode();
1136 : os << "\n - instance class name = ";
1137 : instance_class_name()->Print(os);
1138 : os << " - code = " << Brief(code());
1139 : if (HasBytecodeArray()) {
1140 : os << "\n - bytecode_array = " << bytecode_array();
1141 : }
1142 : if (HasAsmWasmData()) {
1143 : os << "\n - asm_wasm_data = " << Brief(asm_wasm_data());
1144 : }
1145 : PrintSourceCode(os);
1146 : // Script files are often large, hard to read.
1147 : // os << "\n - script =";
1148 : // script()->Print(os);
1149 : if (is_named_expression()) {
1150 : os << "\n - named expression";
1151 : } else if (is_anonymous_expression()) {
1152 : os << "\n - anonymous expression";
1153 : } else if (is_declaration()) {
1154 : os << "\n - declaration";
1155 : }
1156 : os << "\n - function token position = " << function_token_position();
1157 : os << "\n - start position = " << start_position();
1158 : os << "\n - end position = " << end_position();
1159 : if (HasDebugInfo()) {
1160 : os << "\n - debug info = " << Brief(debug_info());
1161 : } else {
1162 : os << "\n - no debug info";
1163 : }
1164 : os << "\n - length = " << length();
1165 : os << "\n - feedback_metadata = ";
1166 : feedback_metadata()->FeedbackMetadataPrint(os);
1167 : if (HasPreParsedScopeData()) {
1168 : os << "\n - preparsed scope data = " << preparsed_scope_data();
1169 : } else {
1170 : os << "\n - no preparsed scope data";
1171 : }
1172 : os << "\n";
1173 : }
1174 :
1175 :
1176 : void JSGlobalProxy::JSGlobalProxyPrint(std::ostream& os) { // NOLINT
1177 : JSObjectPrintHeader(os, this, "JSGlobalProxy");
1178 : if (!GetIsolate()->bootstrapper()->IsActive()) {
1179 : os << "\n - native context = " << Brief(native_context());
1180 : }
1181 : os << "\n - hash = " << Brief(hash());
1182 : JSObjectPrintBody(os, this);
1183 : }
1184 :
1185 :
1186 : void JSGlobalObject::JSGlobalObjectPrint(std::ostream& os) { // NOLINT
1187 : JSObjectPrintHeader(os, this, "JSGlobalObject");
1188 : if (!GetIsolate()->bootstrapper()->IsActive()) {
1189 : os << "\n - native context = " << Brief(native_context());
1190 : }
1191 : os << "\n - global proxy = " << Brief(global_proxy());
1192 : JSObjectPrintBody(os, this);
1193 : }
1194 :
1195 :
1196 : void Cell::CellPrint(std::ostream& os) { // NOLINT
1197 : HeapObject::PrintHeader(os, "Cell");
1198 : os << "\n - value: " << Brief(value());
1199 : os << "\n";
1200 : }
1201 :
1202 :
1203 : void PropertyCell::PropertyCellPrint(std::ostream& os) { // NOLINT
1204 : HeapObject::PrintHeader(os, "PropertyCell");
1205 : os << "\n - name: ";
1206 : name()->NamePrint(os);
1207 : os << "\n - value: " << Brief(value());
1208 : os << "\n - details: ";
1209 : property_details().PrintAsSlowTo(os);
1210 : PropertyCellType cell_type = property_details().cell_type();
1211 : os << "\n - cell_type: ";
1212 : if (value()->IsTheHole(GetIsolate())) {
1213 : switch (cell_type) {
1214 : case PropertyCellType::kUninitialized:
1215 : os << "Uninitialized";
1216 : break;
1217 : case PropertyCellType::kInvalidated:
1218 : os << "Invalidated";
1219 : break;
1220 : default:
1221 : os << "??? " << static_cast<int>(cell_type);
1222 : break;
1223 : }
1224 : } else {
1225 : switch (cell_type) {
1226 : case PropertyCellType::kUndefined:
1227 : os << "Undefined";
1228 : break;
1229 : case PropertyCellType::kConstant:
1230 : os << "Constant";
1231 : break;
1232 : case PropertyCellType::kConstantType:
1233 : os << "ConstantType"
1234 : << " (";
1235 : switch (GetConstantType()) {
1236 : case PropertyCellConstantType::kSmi:
1237 : os << "Smi";
1238 : break;
1239 : case PropertyCellConstantType::kStableMap:
1240 : os << "StableMap";
1241 : break;
1242 : }
1243 : os << ")";
1244 : break;
1245 : case PropertyCellType::kMutable:
1246 : os << "Mutable";
1247 : break;
1248 : }
1249 : }
1250 : os << "\n";
1251 : }
1252 :
1253 :
1254 : void WeakCell::WeakCellPrint(std::ostream& os) { // NOLINT
1255 : HeapObject::PrintHeader(os, "WeakCell");
1256 : if (cleared()) {
1257 : os << "\n - cleared";
1258 : } else {
1259 : os << "\n - value: " << Brief(value());
1260 : }
1261 : os << "\n";
1262 : }
1263 :
1264 :
1265 : void Code::CodePrint(std::ostream& os) { // NOLINT
1266 : HeapObject::PrintHeader(os, "Code");
1267 : os << "\n";
1268 : #ifdef ENABLE_DISASSEMBLER
1269 : if (FLAG_use_verbose_printer) {
1270 : Disassemble(nullptr, os);
1271 : }
1272 : #endif
1273 : }
1274 :
1275 :
1276 : void Foreign::ForeignPrint(std::ostream& os) { // NOLINT
1277 : os << "foreign address : " << reinterpret_cast<void*>(foreign_address());
1278 : os << "\n";
1279 : }
1280 :
1281 :
1282 : void AccessorInfo::AccessorInfoPrint(std::ostream& os) { // NOLINT
1283 : HeapObject::PrintHeader(os, "AccessorInfo");
1284 : os << "\n - name: " << Brief(name());
1285 : os << "\n - flag: " << flag();
1286 : os << "\n - getter: " << Brief(getter());
1287 : os << "\n - setter: " << Brief(setter());
1288 : os << "\n - js_getter: " << Brief(js_getter());
1289 : os << "\n - data: " << Brief(data());
1290 : os << "\n";
1291 : }
1292 :
1293 : void PromiseCapability::PromiseCapabilityPrint(std::ostream& os) { // NOLINT
1294 : HeapObject::PrintHeader(os, "PromiseCapability");
1295 : os << "\n - promise: " << Brief(promise());
1296 : os << "\n - resolve: " << Brief(resolve());
1297 : os << "\n - reject: " << Brief(reject());
1298 : os << "\n";
1299 : }
1300 :
1301 : void PromiseResolveThenableJobInfo::PromiseResolveThenableJobInfoPrint(
1302 : std::ostream& os) { // NOLINT
1303 : HeapObject::PrintHeader(os, "PromiseResolveThenableJobInfo");
1304 : os << "\n - thenable: " << Brief(thenable());
1305 : os << "\n - then: " << Brief(then());
1306 : os << "\n - resolve: " << Brief(resolve());
1307 : os << "\n - reject: " << Brief(reject());
1308 : os << "\n - context: " << Brief(context());
1309 : os << "\n";
1310 : }
1311 :
1312 : void PromiseReactionJobInfo::PromiseReactionJobInfoPrint(
1313 : std::ostream& os) { // NOLINT
1314 : HeapObject::PrintHeader(os, "PromiseReactionJobInfo");
1315 : os << "\n - value: " << Brief(value());
1316 : os << "\n - tasks: " << Brief(tasks());
1317 : os << "\n - deferred_promise: " << Brief(deferred_promise());
1318 : os << "\n - deferred_on_resolve: " << Brief(deferred_on_resolve());
1319 : os << "\n - deferred_on_reject: " << Brief(deferred_on_reject());
1320 : os << "\n - reaction context: " << Brief(context());
1321 : os << "\n";
1322 : }
1323 :
1324 : void AsyncGeneratorRequest::AsyncGeneratorRequestPrint(
1325 : std::ostream& os) { // NOLINT
1326 : HeapObject::PrintHeader(os, "AsyncGeneratorRequest");
1327 : const char* mode = "Invalid!";
1328 : switch (resume_mode()) {
1329 : case JSGeneratorObject::kNext:
1330 : mode = ".next()";
1331 : break;
1332 : case JSGeneratorObject::kReturn:
1333 : mode = ".return()";
1334 : break;
1335 : case JSGeneratorObject::kThrow:
1336 : mode = ".throw()";
1337 : break;
1338 : }
1339 : os << "\n - resume mode: " << mode;
1340 : os << "\n - value: " << Brief(value());
1341 : os << "\n - next: " << Brief(next());
1342 : os << "\n";
1343 : }
1344 :
1345 : void ModuleInfoEntry::ModuleInfoEntryPrint(std::ostream& os) { // NOLINT
1346 : HeapObject::PrintHeader(os, "ModuleInfoEntry");
1347 : os << "\n - export_name: " << Brief(export_name());
1348 : os << "\n - local_name: " << Brief(local_name());
1349 : os << "\n - import_name: " << Brief(import_name());
1350 : os << "\n - module_request: " << module_request();
1351 : os << "\n - cell_index: " << cell_index();
1352 : os << "\n - beg_pos: " << beg_pos();
1353 : os << "\n - end_pos: " << end_pos();
1354 : os << "\n";
1355 : }
1356 :
1357 : void Module::ModulePrint(std::ostream& os) { // NOLINT
1358 : HeapObject::PrintHeader(os, "Module");
1359 : os << "\n - origin: " << Brief(script()->GetNameOrSourceURL());
1360 : os << "\n - code: " << Brief(code());
1361 : os << "\n - exports: " << Brief(exports());
1362 : os << "\n - requested_modules: " << Brief(requested_modules());
1363 : os << "\n - script: " << Brief(script());
1364 : os << "\n - import_meta: " << Brief(import_meta());
1365 : os << "\n - status: " << status();
1366 : os << "\n - exception: " << Brief(exception());
1367 : os << "\n";
1368 : }
1369 :
1370 : void JSModuleNamespace::JSModuleNamespacePrint(std::ostream& os) { // NOLINT
1371 : JSObjectPrintHeader(os, this, "JSModuleNamespace");
1372 : os << "\n - module: " << Brief(module());
1373 : JSObjectPrintBody(os, this);
1374 : }
1375 :
1376 : void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) { // NOLINT
1377 : HeapObject::PrintHeader(os, "PrototypeInfo");
1378 : os << "\n - weak cell: " << Brief(weak_cell());
1379 : os << "\n - prototype users: " << Brief(prototype_users());
1380 : os << "\n - registry slot: " << registry_slot();
1381 : os << "\n - validity cell: " << Brief(validity_cell());
1382 : os << "\n - object create map: " << Brief(object_create_map());
1383 : os << "\n";
1384 : }
1385 :
1386 : void Tuple2::Tuple2Print(std::ostream& os) { // NOLINT
1387 : HeapObject::PrintHeader(os, "Tuple2");
1388 : os << "\n - value1: " << Brief(value1());
1389 : os << "\n - value2: " << Brief(value2());
1390 : os << "\n";
1391 : }
1392 :
1393 : void Tuple3::Tuple3Print(std::ostream& os) { // NOLINT
1394 : HeapObject::PrintHeader(os, "Tuple3");
1395 : os << "\n - value1: " << Brief(value1());
1396 : os << "\n - value2: " << Brief(value2());
1397 : os << "\n - value3: " << Brief(value3());
1398 : os << "\n";
1399 : }
1400 :
1401 : void ContextExtension::ContextExtensionPrint(std::ostream& os) { // NOLINT
1402 : HeapObject::PrintHeader(os, "ContextExtension");
1403 : os << "\n - scope_info: " << Brief(scope_info());
1404 : os << "\n - extension: " << Brief(extension());
1405 : os << "\n";
1406 : }
1407 :
1408 : void AccessorPair::AccessorPairPrint(std::ostream& os) { // NOLINT
1409 : HeapObject::PrintHeader(os, "AccessorPair");
1410 : os << "\n - getter: " << Brief(getter());
1411 : os << "\n - setter: " << Brief(setter());
1412 : os << "\n";
1413 : }
1414 :
1415 :
1416 : void AccessCheckInfo::AccessCheckInfoPrint(std::ostream& os) { // NOLINT
1417 : HeapObject::PrintHeader(os, "AccessCheckInfo");
1418 : os << "\n - callback: " << Brief(callback());
1419 : os << "\n - named_interceptor: " << Brief(named_interceptor());
1420 : os << "\n - indexed_interceptor: " << Brief(indexed_interceptor());
1421 : os << "\n - data: " << Brief(data());
1422 : os << "\n";
1423 : }
1424 :
1425 :
1426 : void InterceptorInfo::InterceptorInfoPrint(std::ostream& os) { // NOLINT
1427 : HeapObject::PrintHeader(os, "InterceptorInfo");
1428 : os << "\n - getter: " << Brief(getter());
1429 : os << "\n - setter: " << Brief(setter());
1430 : os << "\n - query: " << Brief(query());
1431 : os << "\n - deleter: " << Brief(deleter());
1432 : os << "\n - enumerator: " << Brief(enumerator());
1433 : os << "\n - data: " << Brief(data());
1434 : os << "\n";
1435 : }
1436 :
1437 :
1438 : void FunctionTemplateInfo::FunctionTemplateInfoPrint(
1439 : std::ostream& os) { // NOLINT
1440 : HeapObject::PrintHeader(os, "FunctionTemplateInfo");
1441 : os << "\n - class name: " << Brief(class_name());
1442 : os << "\n - tag: " << Brief(tag());
1443 : os << "\n - serial_number: " << Brief(serial_number());
1444 : os << "\n - property_list: " << Brief(property_list());
1445 : os << "\n - call_code: " << Brief(call_code());
1446 : os << "\n - property_accessors: " << Brief(property_accessors());
1447 : os << "\n - prototype_template: " << Brief(prototype_template());
1448 : os << "\n - parent_template: " << Brief(parent_template());
1449 : os << "\n - named_property_handler: " << Brief(named_property_handler());
1450 : os << "\n - indexed_property_handler: " << Brief(indexed_property_handler());
1451 : os << "\n - instance_template: " << Brief(instance_template());
1452 : os << "\n - signature: " << Brief(signature());
1453 : os << "\n - access_check_info: " << Brief(access_check_info());
1454 : os << "\n - cached_property_name: " << Brief(cached_property_name());
1455 : os << "\n - hidden_prototype: " << (hidden_prototype() ? "true" : "false");
1456 : os << "\n - undetectable: " << (undetectable() ? "true" : "false");
1457 : os << "\n - need_access_check: " << (needs_access_check() ? "true" : "false");
1458 : os << "\n - instantiated: " << (instantiated() ? "true" : "false");
1459 : os << "\n";
1460 : }
1461 :
1462 :
1463 : void ObjectTemplateInfo::ObjectTemplateInfoPrint(std::ostream& os) { // NOLINT
1464 : HeapObject::PrintHeader(os, "ObjectTemplateInfo");
1465 : os << "\n - tag: " << Brief(tag());
1466 : os << "\n - serial_number: " << Brief(serial_number());
1467 : os << "\n - property_list: " << Brief(property_list());
1468 : os << "\n - property_accessors: " << Brief(property_accessors());
1469 : os << "\n - constructor: " << Brief(constructor());
1470 : os << "\n - embedder_field_count: " << embedder_field_count();
1471 : os << "\n - immutable_proto: " << (immutable_proto() ? "true" : "false");
1472 : os << "\n";
1473 : }
1474 :
1475 :
1476 : void AllocationSite::AllocationSitePrint(std::ostream& os) { // NOLINT
1477 : HeapObject::PrintHeader(os, "AllocationSite");
1478 : os << "\n - weak_next: " << Brief(weak_next());
1479 : os << "\n - dependent code: " << Brief(dependent_code());
1480 : os << "\n - nested site: " << Brief(nested_site());
1481 : os << "\n - memento found count: "
1482 : << Brief(Smi::FromInt(memento_found_count()));
1483 : os << "\n - memento create count: "
1484 : << Brief(Smi::FromInt(memento_create_count()));
1485 : os << "\n - pretenure decision: "
1486 : << Brief(Smi::FromInt(pretenure_decision()));
1487 : os << "\n - transition_info: ";
1488 : if (!PointsToLiteral()) {
1489 : ElementsKind kind = GetElementsKind();
1490 : os << "Array allocation with ElementsKind " << ElementsKindToString(kind);
1491 : } else if (boilerplate()->IsJSArray()) {
1492 : os << "Array literal with boilerplate " << Brief(boilerplate());
1493 : } else {
1494 : os << "Object literal with boilerplate " << Brief(boilerplate());
1495 : }
1496 : os << "\n";
1497 : }
1498 :
1499 :
1500 : void AllocationMemento::AllocationMementoPrint(std::ostream& os) { // NOLINT
1501 : HeapObject::PrintHeader(os, "AllocationMemento");
1502 : os << "\n - allocation site: ";
1503 : if (IsValid()) {
1504 : GetAllocationSite()->Print(os);
1505 : } else {
1506 : os << "<invalid>\n";
1507 : }
1508 : }
1509 :
1510 :
1511 : void Script::ScriptPrint(std::ostream& os) { // NOLINT
1512 : HeapObject::PrintHeader(os, "Script");
1513 : os << "\n - source: " << Brief(source());
1514 : os << "\n - name: " << Brief(name());
1515 : os << "\n - line_offset: " << line_offset();
1516 : os << "\n - column_offset: " << column_offset();
1517 : os << "\n - type: " << type();
1518 : os << "\n - id: " << id();
1519 : os << "\n - context data: " << Brief(context_data());
1520 : os << "\n - wrapper: " << Brief(wrapper());
1521 : os << "\n - compilation type: " << compilation_type();
1522 : os << "\n - line ends: " << Brief(line_ends());
1523 : os << "\n - eval from shared: " << Brief(eval_from_shared());
1524 : os << "\n - eval from position: " << eval_from_position();
1525 : os << "\n - shared function infos: " << Brief(shared_function_infos());
1526 : os << "\n";
1527 : }
1528 :
1529 :
1530 : void DebugInfo::DebugInfoPrint(std::ostream& os) { // NOLINT
1531 : HeapObject::PrintHeader(os, "DebugInfo");
1532 : os << "\n - flags: " << flags();
1533 : os << "\n - debugger_hints: " << debugger_hints();
1534 : os << "\n - shared: " << Brief(shared());
1535 : os << "\n - debug bytecode array: " << Brief(debug_bytecode_array());
1536 : os << "\n - break_points: ";
1537 : break_points()->Print(os);
1538 : os << "\n - coverage_info: " << Brief(coverage_info());
1539 : }
1540 :
1541 :
1542 : void StackFrameInfo::StackFrameInfoPrint(std::ostream& os) { // NOLINT
1543 : HeapObject::PrintHeader(os, "StackFrame");
1544 : os << "\n - line_number: " << line_number();
1545 : os << "\n - column_number: " << column_number();
1546 : os << "\n - script_id: " << script_id();
1547 : os << "\n - script_name: " << Brief(script_name());
1548 : os << "\n - script_name_or_source_url: "
1549 : << Brief(script_name_or_source_url());
1550 : os << "\n - function_name: " << Brief(function_name());
1551 : os << "\n - is_eval: " << (is_eval() ? "true" : "false");
1552 : os << "\n - is_constructor: " << (is_constructor() ? "true" : "false");
1553 : os << "\n";
1554 : }
1555 :
1556 : static void PrintBitMask(std::ostream& os, uint32_t value) { // NOLINT
1557 : for (int i = 0; i < 32; i++) {
1558 : if ((i & 7) == 0) os << " ";
1559 : os << (((value & 1) == 0) ? "_" : "x");
1560 : value >>= 1;
1561 : }
1562 : }
1563 :
1564 :
1565 : void LayoutDescriptor::Print() {
1566 : OFStream os(stdout);
1567 : this->Print(os);
1568 : os << std::flush;
1569 : }
1570 :
1571 : void LayoutDescriptor::ShortPrint(std::ostream& os) {
1572 : if (IsSmi()) {
1573 : os << this; // Print tagged value for easy use with "jld" gdb macro.
1574 : } else {
1575 : os << Brief(this);
1576 : }
1577 : }
1578 :
1579 : void LayoutDescriptor::Print(std::ostream& os) { // NOLINT
1580 : os << "Layout descriptor: ";
1581 : if (IsFastPointerLayout()) {
1582 : os << "<all tagged>";
1583 : } else if (IsSmi()) {
1584 : os << "fast";
1585 : PrintBitMask(os, static_cast<uint32_t>(Smi::ToInt(this)));
1586 : } else if (IsOddball() &&
1587 : IsUninitialized(HeapObject::cast(this)->GetIsolate())) {
1588 : os << "<uninitialized>";
1589 : } else {
1590 : os << "slow";
1591 : int num_words = number_of_layout_words();
1592 : for (int i = 0; i < num_words; i++) {
1593 : if (i > 0) os << " |";
1594 : PrintBitMask(os, get_layout_word(i));
1595 : }
1596 : }
1597 : os << "\n";
1598 : }
1599 :
1600 : void PreParsedScopeData::PreParsedScopeDataPrint(std::ostream& os) { // NOLINT
1601 : HeapObject::PrintHeader(os, "PreParsedScopeData");
1602 : os << "\n - scope_data: " << Brief(scope_data());
1603 : os << "\n - child_data: " << Brief(child_data());
1604 : os << "\n";
1605 : }
1606 :
1607 : #endif // OBJECT_PRINT
1608 :
1609 : #if V8_TRACE_MAPS
1610 :
1611 : void Name::NameShortPrint() {
1612 : if (this->IsString()) {
1613 : PrintF("%s", String::cast(this)->ToCString().get());
1614 : } else {
1615 : DCHECK(this->IsSymbol());
1616 : Symbol* s = Symbol::cast(this);
1617 : if (s->name()->IsUndefined(GetIsolate())) {
1618 : PrintF("#<%s>", s->PrivateSymbolToName());
1619 : } else {
1620 : PrintF("<%s>", String::cast(s->name())->ToCString().get());
1621 : }
1622 : }
1623 : }
1624 :
1625 :
1626 : int Name::NameShortPrint(Vector<char> str) {
1627 : if (this->IsString()) {
1628 : return SNPrintF(str, "%s", String::cast(this)->ToCString().get());
1629 : } else {
1630 : DCHECK(this->IsSymbol());
1631 : Symbol* s = Symbol::cast(this);
1632 : if (s->name()->IsUndefined(GetIsolate())) {
1633 : return SNPrintF(str, "#<%s>", s->PrivateSymbolToName());
1634 : } else {
1635 : return SNPrintF(str, "<%s>", String::cast(s->name())->ToCString().get());
1636 : }
1637 : }
1638 : }
1639 :
1640 : #endif // V8_TRACE_MAPS
1641 :
1642 : #if defined(DEBUG) || defined(OBJECT_PRINT)
1643 : // This method is only meant to be called from gdb for debugging purposes.
1644 : // Since the string can also be in two-byte encoding, non-Latin1 characters
1645 : // will be ignored in the output.
1646 : char* String::ToAsciiArray() {
1647 : // Static so that subsequent calls frees previously allocated space.
1648 : // This also means that previous results will be overwritten.
1649 : static char* buffer = nullptr;
1650 : if (buffer != nullptr) delete[] buffer;
1651 : buffer = new char[length() + 1];
1652 : WriteToFlat(this, reinterpret_cast<uint8_t*>(buffer), 0, length());
1653 : buffer[length()] = 0;
1654 : return buffer;
1655 : }
1656 :
1657 :
1658 : void DescriptorArray::Print() {
1659 : OFStream os(stdout);
1660 : this->PrintDescriptors(os);
1661 : os << std::flush;
1662 : }
1663 :
1664 :
1665 : void DescriptorArray::PrintDescriptors(std::ostream& os) { // NOLINT
1666 : HandleScope scope(GetIsolate());
1667 : os << "Descriptor array #" << number_of_descriptors() << ":";
1668 : for (int i = 0; i < number_of_descriptors(); i++) {
1669 : Name* key = GetKey(i);
1670 : os << "\n [" << i << "]: ";
1671 : #ifdef OBJECT_PRINT
1672 : key->NamePrint(os);
1673 : #else
1674 : key->ShortPrint(os);
1675 : #endif
1676 : os << " ";
1677 : PrintDescriptorDetails(os, i, PropertyDetails::kPrintFull);
1678 : }
1679 : os << "\n";
1680 : }
1681 :
1682 : void DescriptorArray::PrintDescriptorDetails(std::ostream& os, int descriptor,
1683 : PropertyDetails::PrintMode mode) {
1684 : PropertyDetails details = GetDetails(descriptor);
1685 : details.PrintAsFastTo(os, mode);
1686 : os << " @ ";
1687 : Object* value = GetValue(descriptor);
1688 : switch (details.location()) {
1689 : case kField: {
1690 : FieldType* field_type = Map::UnwrapFieldType(value);
1691 : field_type->PrintTo(os);
1692 : break;
1693 : }
1694 : case kDescriptor:
1695 : os << Brief(value);
1696 : if (value->IsAccessorPair()) {
1697 : AccessorPair* pair = AccessorPair::cast(value);
1698 : os << "(get: " << Brief(pair->getter())
1699 : << ", set: " << Brief(pair->setter()) << ")";
1700 : }
1701 : break;
1702 : }
1703 : }
1704 :
1705 : // static
1706 : void TransitionsAccessor::PrintOneTransition(std::ostream& os, Name* key,
1707 : Map* target, Object* raw_target) {
1708 : os << "\n ";
1709 : #ifdef OBJECT_PRINT
1710 : key->NamePrint(os);
1711 : #else
1712 : key->ShortPrint(os);
1713 : #endif
1714 : os << ": ";
1715 : Heap* heap = key->GetHeap();
1716 : if (key == heap->nonextensible_symbol()) {
1717 : os << "(transition to non-extensible)";
1718 : } else if (key == heap->sealed_symbol()) {
1719 : os << "(transition to sealed)";
1720 : } else if (key == heap->frozen_symbol()) {
1721 : os << "(transition to frozen)";
1722 : } else if (key == heap->elements_transition_symbol()) {
1723 : os << "(transition to " << ElementsKindToString(target->elements_kind())
1724 : << ")";
1725 : } else if (key == heap->strict_function_transition_symbol()) {
1726 : os << " (transition to strict function)";
1727 : } else {
1728 : DCHECK(!IsSpecialTransition(key));
1729 : os << "(transition to ";
1730 : int descriptor = target->LastAdded();
1731 : DescriptorArray* descriptors = target->instance_descriptors();
1732 : descriptors->PrintDescriptorDetails(os, descriptor,
1733 : PropertyDetails::kForTransitions);
1734 : os << ")";
1735 : }
1736 : os << " -> " << Brief(target);
1737 : if (!raw_target->IsMap() && !raw_target->IsWeakCell()) {
1738 : os << " (handler: " << Brief(raw_target) << ")";
1739 : }
1740 : }
1741 :
1742 : void TransitionArray::Print() {
1743 : OFStream os(stdout);
1744 : Print(os);
1745 : }
1746 :
1747 : void TransitionArray::Print(std::ostream& os) {
1748 : int num_transitions = number_of_transitions();
1749 : os << "Transition array #" << num_transitions << ":";
1750 : for (int i = 0; i < num_transitions; i++) {
1751 : Name* key = GetKey(i);
1752 : Map* target = GetTarget(i);
1753 : Object* raw_target = GetRawTarget(i);
1754 : TransitionsAccessor::PrintOneTransition(os, key, target, raw_target);
1755 : }
1756 : os << "\n" << std::flush;
1757 : }
1758 :
1759 : void TransitionsAccessor::PrintTransitions(std::ostream& os) { // NOLINT
1760 : WeakCell* cell = nullptr;
1761 : switch (encoding()) {
1762 : case kPrototypeInfo:
1763 : case kUninitialized:
1764 : return;
1765 : case kWeakCell:
1766 : cell = GetTargetCell<kWeakCell>();
1767 : break;
1768 : case kHandler:
1769 : cell = GetTargetCell<kHandler>();
1770 : break;
1771 : case kFullTransitionArray:
1772 : return transitions()->Print(os);
1773 : }
1774 : DCHECK(!cell->cleared());
1775 : Map* target = Map::cast(cell->value());
1776 : Name* key = GetSimpleTransitionKey(target);
1777 : PrintOneTransition(os, key, target, raw_transitions_);
1778 : }
1779 :
1780 : void TransitionsAccessor::PrintTransitionTree() {
1781 : OFStream os(stdout);
1782 : os << "map= " << Brief(map_);
1783 : DisallowHeapAllocation no_gc;
1784 : PrintTransitionTree(os, 0, &no_gc);
1785 : os << "\n" << std::flush;
1786 : }
1787 :
1788 : void TransitionsAccessor::PrintTransitionTree(std::ostream& os, int level,
1789 : DisallowHeapAllocation* no_gc) {
1790 : int num_transitions = NumberOfTransitions();
1791 : if (num_transitions == 0) return;
1792 : for (int i = 0; i < num_transitions; i++) {
1793 : Name* key = GetKey(i);
1794 : Map* target = GetTarget(i);
1795 : os << std::endl
1796 : << " " << level << "/" << i << ":" << std::setw(level * 2 + 2) << " ";
1797 : std::stringstream ss;
1798 : ss << Brief(target);
1799 : os << std::left << std::setw(50) << ss.str() << ": ";
1800 :
1801 : Heap* heap = key->GetHeap();
1802 : if (key == heap->nonextensible_symbol()) {
1803 : os << "to non-extensible";
1804 : } else if (key == heap->sealed_symbol()) {
1805 : os << "to sealed ";
1806 : } else if (key == heap->frozen_symbol()) {
1807 : os << "to frozen";
1808 : } else if (key == heap->elements_transition_symbol()) {
1809 : os << "to " << ElementsKindToString(target->elements_kind());
1810 : } else if (key == heap->strict_function_transition_symbol()) {
1811 : os << "to strict function";
1812 : } else {
1813 : #ifdef OBJECT_PRINT
1814 : key->NamePrint(os);
1815 : #else
1816 : key->ShortPrint(os);
1817 : #endif
1818 : os << " ";
1819 : DCHECK(!IsSpecialTransition(key));
1820 : os << "to ";
1821 : int descriptor = target->LastAdded();
1822 : DescriptorArray* descriptors = target->instance_descriptors();
1823 : descriptors->PrintDescriptorDetails(os, descriptor,
1824 : PropertyDetails::kForTransitions);
1825 : }
1826 : TransitionsAccessor transitions(target, no_gc);
1827 : transitions.PrintTransitionTree(os, level + 1, no_gc);
1828 : }
1829 : }
1830 :
1831 : void JSObject::PrintTransitions(std::ostream& os) { // NOLINT
1832 : DisallowHeapAllocation no_gc;
1833 : TransitionsAccessor ta(map(), &no_gc);
1834 : if (ta.NumberOfTransitions() == 0) return;
1835 : os << "\n - transitions";
1836 : ta.PrintTransitions(os);
1837 : }
1838 : #endif // defined(DEBUG) || defined(OBJECT_PRINT)
1839 : } // namespace internal
1840 : } // namespace v8
1841 :
1842 : //
1843 : // The following functions are used by our gdb macros.
1844 : //
1845 0 : extern void _v8_internal_Print_Object(void* object) {
1846 : reinterpret_cast<i::Object*>(object)->Print();
1847 0 : }
1848 :
1849 0 : extern void _v8_internal_Print_Code(void* object) {
1850 : i::Isolate* isolate = i::Isolate::Current();
1851 0 : isolate->FindCodeObject(reinterpret_cast<i::Address>(object))->Print();
1852 0 : }
1853 :
1854 0 : extern void _v8_internal_Print_FeedbackMetadata(void* object) {
1855 0 : if (reinterpret_cast<i::Object*>(object)->IsSmi()) {
1856 : printf("Please provide a feedback metadata object\n");
1857 : } else {
1858 : reinterpret_cast<i::FeedbackMetadata*>(object)->Print();
1859 : }
1860 0 : }
1861 :
1862 0 : extern void _v8_internal_Print_FeedbackVector(void* object) {
1863 0 : if (reinterpret_cast<i::Object*>(object)->IsSmi()) {
1864 : printf("Please provide a feedback vector\n");
1865 : } else {
1866 : reinterpret_cast<i::FeedbackVector*>(object)->Print();
1867 : }
1868 0 : }
1869 :
1870 0 : extern void _v8_internal_Print_DescriptorArray(void* object) {
1871 0 : if (reinterpret_cast<i::Object*>(object)->IsSmi()) {
1872 : printf("Please provide a descriptor array\n");
1873 : } else {
1874 : reinterpret_cast<i::DescriptorArray*>(object)->Print();
1875 : }
1876 0 : }
1877 :
1878 0 : extern void _v8_internal_Print_LayoutDescriptor(void* object) {
1879 : i::Object* o = reinterpret_cast<i::Object*>(object);
1880 0 : if (!o->IsLayoutDescriptor()) {
1881 : printf("Please provide a layout descriptor\n");
1882 : } else {
1883 : reinterpret_cast<i::LayoutDescriptor*>(object)->Print();
1884 : }
1885 0 : }
1886 :
1887 0 : extern void _v8_internal_Print_TransitionArray(void* object) {
1888 0 : if (reinterpret_cast<i::Object*>(object)->IsSmi()) {
1889 : printf("Please provide a transition array\n");
1890 : } else {
1891 : reinterpret_cast<i::TransitionArray*>(object)->Print();
1892 : }
1893 0 : }
1894 :
1895 0 : extern void _v8_internal_Print_StackTrace() {
1896 : i::Isolate* isolate = i::Isolate::Current();
1897 0 : isolate->PrintStack(stdout);
1898 0 : }
1899 :
1900 0 : extern void _v8_internal_Print_TransitionTree(void* object) {
1901 : i::Object* o = reinterpret_cast<i::Object*>(object);
1902 0 : if (!o->IsMap()) {
1903 : printf("Please provide a valid Map\n");
1904 : } else {
1905 : #if defined(DEBUG) || defined(OBJECT_PRINT)
1906 : i::DisallowHeapAllocation no_gc;
1907 : i::TransitionsAccessor transitions(reinterpret_cast<i::Map*>(object),
1908 : &no_gc);
1909 : transitions.PrintTransitionTree();
1910 : #endif
1911 : }
1912 0 : }
|