| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include "src/disasm.h" | 7 #include "src/disasm.h" |
| 8 #include "src/disassembler.h" | 8 #include "src/disassembler.h" |
| 9 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
| 10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 void Object::Print(std::ostream& os) { // NOLINT | 26 void Object::Print(std::ostream& os) { // NOLINT |
| 27 if (IsSmi()) { | 27 if (IsSmi()) { |
| 28 Smi::cast(this)->SmiPrint(os); | 28 Smi::cast(this)->SmiPrint(os); |
| 29 } else { | 29 } else { |
| 30 HeapObject::cast(this)->HeapObjectPrint(os); | 30 HeapObject::cast(this)->HeapObjectPrint(os); |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 | 34 |
| 35 void HeapObject::PrintHeader(std::ostream& os, const char* id) { // NOLINT | 35 void HeapObject::PrintHeader(std::ostream& os, const char* id) { // NOLINT |
| 36 os << reinterpret_cast<void*>(this) << ": [" << id << "]"; | 36 os << reinterpret_cast<void*>(this) << ": ["; |
| 37 if (id != nullptr) { |
| 38 os << id; |
| 39 } else { |
| 40 os << map()->instance_type(); |
| 41 } |
| 42 os << "]"; |
| 37 } | 43 } |
| 38 | 44 |
| 39 | 45 |
| 40 void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT | 46 void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT |
| 41 InstanceType instance_type = map()->instance_type(); | 47 InstanceType instance_type = map()->instance_type(); |
| 42 | 48 |
| 43 HandleScope scope(GetIsolate()); | 49 HandleScope scope(GetIsolate()); |
| 44 if (instance_type < FIRST_NONSTRING_TYPE) { | 50 if (instance_type < FIRST_NONSTRING_TYPE) { |
| 45 String::cast(this)->StringPrint(os); | 51 String::cast(this)->StringPrint(os); |
| 46 return; | 52 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 96 |
| 91 TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY) | 97 TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY) |
| 92 #undef PRINT_FIXED_TYPED_ARRAY | 98 #undef PRINT_FIXED_TYPED_ARRAY |
| 93 | 99 |
| 94 case FILLER_TYPE: | 100 case FILLER_TYPE: |
| 95 os << "filler"; | 101 os << "filler"; |
| 96 break; | 102 break; |
| 97 case JS_OBJECT_TYPE: // fall through | 103 case JS_OBJECT_TYPE: // fall through |
| 98 case JS_SPECIAL_API_OBJECT_TYPE: | 104 case JS_SPECIAL_API_OBJECT_TYPE: |
| 99 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: | 105 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
| 100 case JS_ARRAY_TYPE: | |
| 101 case JS_GENERATOR_OBJECT_TYPE: | 106 case JS_GENERATOR_OBJECT_TYPE: |
| 102 case JS_PROMISE_TYPE: | 107 case JS_PROMISE_TYPE: |
| 103 JSObject::cast(this)->JSObjectPrint(os); | 108 JSObject::cast(this)->JSObjectPrint(os); |
| 104 break; | 109 break; |
| 110 case JS_ARRAY_TYPE: |
| 111 JSArray::cast(this)->JSArrayPrint(os); |
| 112 break; |
| 105 case JS_REGEXP_TYPE: | 113 case JS_REGEXP_TYPE: |
| 106 JSRegExp::cast(this)->JSRegExpPrint(os); | 114 JSRegExp::cast(this)->JSRegExpPrint(os); |
| 107 break; | 115 break; |
| 108 case ODDBALL_TYPE: | 116 case ODDBALL_TYPE: |
| 109 Oddball::cast(this)->to_string()->Print(os); | 117 Oddball::cast(this)->to_string()->Print(os); |
| 110 break; | 118 break; |
| 111 case JS_MODULE_TYPE: | 119 case JS_MODULE_TYPE: |
| 112 JSModule::cast(this)->JSModulePrint(os); | 120 JSModule::cast(this)->JSModulePrint(os); |
| 113 break; | 121 break; |
| 114 case JS_BOUND_FUNCTION_TYPE: | 122 case JS_BOUND_FUNCTION_TYPE: |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 break; | 397 break; |
| 390 } | 398 } |
| 391 } | 399 } |
| 392 | 400 |
| 393 | 401 |
| 394 static void JSObjectPrintHeader(std::ostream& os, JSObject* obj, | 402 static void JSObjectPrintHeader(std::ostream& os, JSObject* obj, |
| 395 const char* id) { // NOLINT | 403 const char* id) { // NOLINT |
| 396 obj->PrintHeader(os, id); | 404 obj->PrintHeader(os, id); |
| 397 // Don't call GetElementsKind, its validation code can cause the printer to | 405 // Don't call GetElementsKind, its validation code can cause the printer to |
| 398 // fail when debugging. | 406 // fail when debugging. |
| 399 os << "\n - map = " << reinterpret_cast<void*>(obj->map()) << " [" | 407 os << "\n - map = " << reinterpret_cast<void*>(obj->map()) << " ["; |
| 408 if (obj->HasFastProperties()) { |
| 409 os << "FastProperties"; |
| 410 } else { |
| 411 os << "DictionaryProperties"; |
| 412 } |
| 413 PrototypeIterator iter(obj->GetIsolate(), obj); |
| 414 os << "]\n - prototype = " << reinterpret_cast<void*>(iter.GetCurrent()); |
| 415 os << "\n - elements = " << Brief(obj->elements()) << " [" |
| 400 << ElementsKindToString(obj->map()->elements_kind()); | 416 << ElementsKindToString(obj->map()->elements_kind()); |
| 401 if (obj->elements()->map() == obj->GetHeap()->fixed_cow_array_map()) { | 417 if (obj->elements()->map() == obj->GetHeap()->fixed_cow_array_map()) { |
| 402 os << " (COW)"; | 418 os << " (COW)"; |
| 403 } | 419 } |
| 404 PrototypeIterator iter(obj->GetIsolate(), obj); | 420 os << "]"; |
| 405 os << "]\n - prototype = " << reinterpret_cast<void*>(iter.GetCurrent()); | |
| 406 if (obj->elements()->length() > 0) { | |
| 407 os << "\n - elements = " << Brief(obj->elements()); | |
| 408 } | |
| 409 } | 421 } |
| 410 | 422 |
| 411 | 423 |
| 412 static void JSObjectPrintBody(std::ostream& os, JSObject* obj, // NOLINT | 424 static void JSObjectPrintBody(std::ostream& os, JSObject* obj, // NOLINT |
| 413 bool print_elements = true) { | 425 bool print_elements = true) { |
| 414 os << "\n {"; | 426 os << "\n {"; |
| 415 obj->PrintProperties(os); | 427 obj->PrintProperties(os); |
| 416 obj->PrintTransitions(os); | |
| 417 if (print_elements) obj->PrintElements(os); | 428 if (print_elements) obj->PrintElements(os); |
| 418 os << "\n }\n"; | 429 os << "\n }\n"; |
| 419 } | 430 } |
| 420 | 431 |
| 421 | 432 |
| 422 void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT | 433 void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT |
| 423 JSObjectPrintHeader(os, this, "JSObject"); | 434 JSObjectPrintHeader(os, this, nullptr); |
| 424 JSObjectPrintBody(os, this); | 435 JSObjectPrintBody(os, this); |
| 425 } | 436 } |
| 426 | 437 |
| 438 void JSArray::JSArrayPrint(std::ostream& os) { // NOLINT |
| 439 JSObjectPrintHeader(os, this, "JSArray"); |
| 440 os << "\n - length = " << Brief(this->length()); |
| 441 JSObjectPrintBody(os, this); |
| 442 } |
| 443 |
| 427 | 444 |
| 428 void JSRegExp::JSRegExpPrint(std::ostream& os) { // NOLINT | 445 void JSRegExp::JSRegExpPrint(std::ostream& os) { // NOLINT |
| 429 JSObjectPrintHeader(os, this, "JSRegExp"); | 446 JSObjectPrintHeader(os, this, "JSRegExp"); |
| 430 os << "\n - data = " << Brief(data()); | 447 os << "\n - data = " << Brief(data()); |
| 431 JSObjectPrintBody(os, this); | 448 JSObjectPrintBody(os, this); |
| 432 } | 449 } |
| 433 | 450 |
| 434 | 451 |
| 435 void JSModule::JSModulePrint(std::ostream& os) { // NOLINT | 452 void JSModule::JSModulePrint(std::ostream& os) { // NOLINT |
| 436 JSObjectPrintHeader(os, this, "JSModule"); | 453 JSObjectPrintHeader(os, this, "JSModule"); |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 | 1289 |
| 1273 void TransitionArray::PrintTransitions(std::ostream& os, Object* transitions, | 1290 void TransitionArray::PrintTransitions(std::ostream& os, Object* transitions, |
| 1274 bool print_header) { // NOLINT | 1291 bool print_header) { // NOLINT |
| 1275 int num_transitions = NumberOfTransitions(transitions); | 1292 int num_transitions = NumberOfTransitions(transitions); |
| 1276 if (print_header) { | 1293 if (print_header) { |
| 1277 os << "Transition array #" << num_transitions << ":"; | 1294 os << "Transition array #" << num_transitions << ":"; |
| 1278 } | 1295 } |
| 1279 for (int i = 0; i < num_transitions; i++) { | 1296 for (int i = 0; i < num_transitions; i++) { |
| 1280 Name* key = GetKey(transitions, i); | 1297 Name* key = GetKey(transitions, i); |
| 1281 Map* target = GetTarget(transitions, i); | 1298 Map* target = GetTarget(transitions, i); |
| 1282 os << "\n "; | 1299 os << "\n "; |
| 1283 #ifdef OBJECT_PRINT | 1300 #ifdef OBJECT_PRINT |
| 1284 key->NamePrint(os); | 1301 key->NamePrint(os); |
| 1285 #else | 1302 #else |
| 1286 key->ShortPrint(os); | 1303 key->ShortPrint(os); |
| 1287 #endif | 1304 #endif |
| 1288 os << ": "; | 1305 os << ": "; |
| 1289 Heap* heap = key->GetHeap(); | 1306 Heap* heap = key->GetHeap(); |
| 1290 if (key == heap->nonextensible_symbol()) { | 1307 if (key == heap->nonextensible_symbol()) { |
| 1291 os << "(transition to non-extensible)"; | 1308 os << "(transition to non-extensible)"; |
| 1292 } else if (key == heap->sealed_symbol()) { | 1309 } else if (key == heap->sealed_symbol()) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1322 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT | 1339 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT |
| 1323 Object* transitions = map()->raw_transitions(); | 1340 Object* transitions = map()->raw_transitions(); |
| 1324 int num_transitions = TransitionArray::NumberOfTransitions(transitions); | 1341 int num_transitions = TransitionArray::NumberOfTransitions(transitions); |
| 1325 if (num_transitions == 0) return; | 1342 if (num_transitions == 0) return; |
| 1326 os << "\n - transitions"; | 1343 os << "\n - transitions"; |
| 1327 TransitionArray::PrintTransitions(os, transitions, false); | 1344 TransitionArray::PrintTransitions(os, transitions, false); |
| 1328 } | 1345 } |
| 1329 #endif // defined(DEBUG) || defined(OBJECT_PRINT) | 1346 #endif // defined(DEBUG) || defined(OBJECT_PRINT) |
| 1330 } // namespace internal | 1347 } // namespace internal |
| 1331 } // namespace v8 | 1348 } // namespace v8 |
| OLD | NEW |