| 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 <iomanip> | 7 #include <iomanip> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 os << "free space, size " << Size(); | 320 os << "free space, size " << Size(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 | 323 |
| 324 template <class Traits> | 324 template <class Traits> |
| 325 void FixedTypedArray<Traits>::FixedTypedArrayPrint( | 325 void FixedTypedArray<Traits>::FixedTypedArrayPrint( |
| 326 std::ostream& os) { // NOLINT | 326 std::ostream& os) { // NOLINT |
| 327 os << "fixed " << Traits::Designator(); | 327 os << "fixed " << Traits::Designator(); |
| 328 } | 328 } |
| 329 | 329 |
| 330 | 330 bool JSObject::PrintProperties(std::ostream& os) { // NOLINT |
| 331 void JSObject::PrintProperties(std::ostream& os) { // NOLINT | |
| 332 if (HasFastProperties()) { | 331 if (HasFastProperties()) { |
| 333 DescriptorArray* descs = map()->instance_descriptors(); | 332 DescriptorArray* descs = map()->instance_descriptors(); |
| 334 for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) { | 333 int i = 0; |
| 335 os << "\n "; | 334 for (; i < map()->NumberOfOwnDescriptors(); i++) { |
| 335 os << "\n "; |
| 336 descs->GetKey(i)->NamePrint(os); | 336 descs->GetKey(i)->NamePrint(os); |
| 337 os << ": "; | 337 os << ": "; |
| 338 PropertyDetails details = descs->GetDetails(i); | 338 PropertyDetails details = descs->GetDetails(i); |
| 339 switch (details.location()) { | 339 switch (details.location()) { |
| 340 case kField: { | 340 case kField: { |
| 341 FieldIndex field_index = FieldIndex::ForDescriptor(map(), i); | 341 FieldIndex field_index = FieldIndex::ForDescriptor(map(), i); |
| 342 if (IsUnboxedDoubleField(field_index)) { | 342 if (IsUnboxedDoubleField(field_index)) { |
| 343 os << "<unboxed double> " << RawFastDoublePropertyAt(field_index); | 343 os << "<unboxed double> " << RawFastDoublePropertyAt(field_index); |
| 344 } else { | 344 } else { |
| 345 os << Brief(RawFastPropertyAt(field_index)); | 345 os << Brief(RawFastPropertyAt(field_index)); |
| 346 } | 346 } |
| 347 break; | 347 break; |
| 348 } | 348 } |
| 349 case kDescriptor: | 349 case kDescriptor: |
| 350 os << Brief(descs->GetValue(i)); | 350 os << Brief(descs->GetValue(i)); |
| 351 break; | 351 break; |
| 352 } | 352 } |
| 353 os << " "; | 353 os << " "; |
| 354 details.PrintAsFastTo(os, PropertyDetails::kForProperties); | 354 details.PrintAsFastTo(os, PropertyDetails::kForProperties); |
| 355 } | 355 } |
| 356 return i > 0; |
| 356 } else if (IsJSGlobalObject()) { | 357 } else if (IsJSGlobalObject()) { |
| 357 global_dictionary()->Print(os); | 358 global_dictionary()->Print(os); |
| 358 } else { | 359 } else { |
| 359 property_dictionary()->Print(os); | 360 property_dictionary()->Print(os); |
| 360 } | 361 } |
| 362 return true; |
| 361 } | 363 } |
| 362 | 364 |
| 363 namespace { | 365 namespace { |
| 364 | 366 |
| 365 template <class T> | 367 template <class T> |
| 366 double GetScalarElement(T* array, int index) { | 368 double GetScalarElement(T* array, int index) { |
| 367 return array->get_scalar(index); | 369 return array->get_scalar(index); |
| 368 } | 370 } |
| 369 | 371 |
| 370 double GetScalarElement(FixedDoubleArray* array, int index) { | 372 double GetScalarElement(FixedDoubleArray* array, int index) { |
| 371 if (array->is_the_hole(index)) return bit_cast<double>(kHoleNanInt64); | 373 if (array->is_the_hole(index)) return bit_cast<double>(kHoleNanInt64); |
| 372 return array->get_scalar(index); | 374 return array->get_scalar(index); |
| 373 } | 375 } |
| 374 | 376 |
| 375 bool is_the_hole(double maybe_hole) { | 377 bool is_the_hole(double maybe_hole) { |
| 376 return bit_cast<uint64_t>(maybe_hole) == kHoleNanInt64; | 378 return bit_cast<uint64_t>(maybe_hole) == kHoleNanInt64; |
| 377 } | 379 } |
| 378 | 380 |
| 379 } // namespace | |
| 380 | |
| 381 template <class T, bool print_the_hole> | 381 template <class T, bool print_the_hole> |
| 382 static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT | 382 void DoPrintElements(std::ostream& os, Object* object) { // NOLINT |
| 383 T* array = T::cast(object); | 383 T* array = T::cast(object); |
| 384 if (array->length() == 0) return; | 384 if (array->length() == 0) return; |
| 385 int previous_index = 0; | 385 int previous_index = 0; |
| 386 double previous_value = GetScalarElement(array, 0); | 386 double previous_value = GetScalarElement(array, 0); |
| 387 double value = 0.0; | 387 double value = 0.0; |
| 388 int i; | 388 int i; |
| 389 for (i = 1; i <= array->length(); i++) { | 389 for (i = 1; i <= array->length(); i++) { |
| 390 if (i < array->length()) value = GetScalarElement(array, i); | 390 if (i < array->length()) value = GetScalarElement(array, i); |
| 391 bool values_are_nan = std::isnan(previous_value) && std::isnan(value); | 391 bool values_are_nan = std::isnan(previous_value) && std::isnan(value); |
| 392 if (i != array->length() && (previous_value == value || values_are_nan) && | 392 if (i != array->length() && (previous_value == value || values_are_nan) && |
| (...skipping 10 matching lines...) Expand all Loading... |
| 403 if (print_the_hole && is_the_hole(previous_value)) { | 403 if (print_the_hole && is_the_hole(previous_value)) { |
| 404 os << "<the_hole>"; | 404 os << "<the_hole>"; |
| 405 } else { | 405 } else { |
| 406 os << previous_value; | 406 os << previous_value; |
| 407 } | 407 } |
| 408 previous_index = i; | 408 previous_index = i; |
| 409 previous_value = value; | 409 previous_value = value; |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 | 412 |
| 413 void PrintFixedArrayElements(std::ostream& os, FixedArray* array) { |
| 414 // Print in array notation for non-sparse arrays. |
| 415 Object* previous_value = array->get(0); |
| 416 Object* value = nullptr; |
| 417 int previous_index = 0; |
| 418 int i; |
| 419 for (i = 1; i <= array->length(); i++) { |
| 420 if (i < array->length()) value = array->get(i); |
| 421 if (previous_value == value && i != array->length()) { |
| 422 continue; |
| 423 } |
| 424 os << "\n"; |
| 425 std::stringstream ss; |
| 426 ss << previous_index; |
| 427 if (previous_index != i - 1) { |
| 428 ss << '-' << (i - 1); |
| 429 } |
| 430 os << std::setw(12) << ss.str() << ": " << Brief(previous_value); |
| 431 previous_index = i; |
| 432 previous_value = value; |
| 433 } |
| 434 } |
| 413 | 435 |
| 414 void JSObject::PrintElements(std::ostream& os) { // NOLINT | 436 } // namespace |
| 437 |
| 438 bool JSObject::PrintElements(std::ostream& os) { // NOLINT |
| 415 // Don't call GetElementsKind, its validation code can cause the printer to | 439 // Don't call GetElementsKind, its validation code can cause the printer to |
| 416 // fail when debugging. | 440 // fail when debugging. |
| 417 if (elements()->length() == 0) return; | 441 if (elements()->length() == 0) return false; |
| 418 switch (map()->elements_kind()) { | 442 switch (map()->elements_kind()) { |
| 419 case FAST_HOLEY_SMI_ELEMENTS: | 443 case FAST_HOLEY_SMI_ELEMENTS: |
| 420 case FAST_SMI_ELEMENTS: | 444 case FAST_SMI_ELEMENTS: |
| 421 case FAST_HOLEY_ELEMENTS: | 445 case FAST_HOLEY_ELEMENTS: |
| 422 case FAST_ELEMENTS: | 446 case FAST_ELEMENTS: |
| 423 case FAST_STRING_WRAPPER_ELEMENTS: { | 447 case FAST_STRING_WRAPPER_ELEMENTS: { |
| 424 // Print in array notation for non-sparse arrays. | 448 PrintFixedArrayElements(os, FixedArray::cast(elements())); |
| 425 FixedArray* array = FixedArray::cast(elements()); | |
| 426 Object* previous_value = array->get(0); | |
| 427 Object* value = nullptr; | |
| 428 int previous_index = 0; | |
| 429 int i; | |
| 430 for (i = 1; i <= array->length(); i++) { | |
| 431 if (i < array->length()) value = array->get(i); | |
| 432 if (previous_value == value && i != array->length()) { | |
| 433 continue; | |
| 434 } | |
| 435 os << "\n"; | |
| 436 std::stringstream ss; | |
| 437 ss << previous_index; | |
| 438 if (previous_index != i - 1) { | |
| 439 ss << '-' << (i - 1); | |
| 440 } | |
| 441 os << std::setw(12) << ss.str() << ": " << Brief(previous_value); | |
| 442 previous_index = i; | |
| 443 previous_value = value; | |
| 444 } | |
| 445 break; | 449 break; |
| 446 } | 450 } |
| 447 case FAST_HOLEY_DOUBLE_ELEMENTS: | 451 case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 448 case FAST_DOUBLE_ELEMENTS: { | 452 case FAST_DOUBLE_ELEMENTS: { |
| 449 DoPrintElements<FixedDoubleArray, true>(os, elements()); | 453 DoPrintElements<FixedDoubleArray, true>(os, elements()); |
| 450 break; | 454 break; |
| 451 } | 455 } |
| 452 | 456 |
| 453 #define PRINT_ELEMENTS(Type, type, TYPE, elementType, size) \ | 457 #define PRINT_ELEMENTS(Type, type, TYPE, elementType, size) \ |
| 454 case TYPE##_ELEMENTS: { \ | 458 case TYPE##_ELEMENTS: { \ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 469 for (int i = 2; i < p->length(); i++) { | 473 for (int i = 2; i < p->length(); i++) { |
| 470 os << " " << (i - 2) << ":" << Brief(p->get(i)); | 474 os << " " << (i - 2) << ":" << Brief(p->get(i)); |
| 471 } | 475 } |
| 472 os << "\n context: " << Brief(p->get(0)) | 476 os << "\n context: " << Brief(p->get(0)) |
| 473 << "\n arguments: " << Brief(p->get(1)); | 477 << "\n arguments: " << Brief(p->get(1)); |
| 474 break; | 478 break; |
| 475 } | 479 } |
| 476 case NO_ELEMENTS: | 480 case NO_ELEMENTS: |
| 477 break; | 481 break; |
| 478 } | 482 } |
| 483 return true; |
| 479 } | 484 } |
| 480 | 485 |
| 481 | 486 |
| 482 static void JSObjectPrintHeader(std::ostream& os, JSObject* obj, | 487 static void JSObjectPrintHeader(std::ostream& os, JSObject* obj, |
| 483 const char* id) { // NOLINT | 488 const char* id) { // NOLINT |
| 484 obj->PrintHeader(os, id); | 489 obj->PrintHeader(os, id); |
| 485 // Don't call GetElementsKind, its validation code can cause the printer to | 490 // Don't call GetElementsKind, its validation code can cause the printer to |
| 486 // fail when debugging. | 491 // fail when debugging. |
| 487 os << "\n - map = " << reinterpret_cast<void*>(obj->map()) << " ["; | 492 os << "\n - map = " << reinterpret_cast<void*>(obj->map()) << " ["; |
| 488 if (obj->HasFastProperties()) { | 493 if (obj->HasFastProperties()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 500 os << "]"; | 505 os << "]"; |
| 501 if (obj->GetInternalFieldCount() > 0) { | 506 if (obj->GetInternalFieldCount() > 0) { |
| 502 os << "\n - internal fields: " << obj->GetInternalFieldCount(); | 507 os << "\n - internal fields: " << obj->GetInternalFieldCount(); |
| 503 } | 508 } |
| 504 } | 509 } |
| 505 | 510 |
| 506 | 511 |
| 507 static void JSObjectPrintBody(std::ostream& os, JSObject* obj, // NOLINT | 512 static void JSObjectPrintBody(std::ostream& os, JSObject* obj, // NOLINT |
| 508 bool print_elements = true) { | 513 bool print_elements = true) { |
| 509 os << "\n - properties = " << Brief(obj->properties()) << " {"; | 514 os << "\n - properties = " << Brief(obj->properties()) << " {"; |
| 510 obj->PrintProperties(os); | 515 if (obj->PrintProperties(os)) os << "\n "; |
| 511 os << "\n }\n"; | 516 os << "}\n"; |
| 512 if (print_elements && obj->elements()->length() > 0) { | 517 if (print_elements && obj->elements()->length() > 0) { |
| 513 os << " - elements = {"; | 518 os << " - elements = " << Brief(obj->elements()) << " {"; |
| 514 obj->PrintElements(os); | 519 if (obj->PrintElements(os)) os << "\n "; |
| 515 os << "\n }\n"; | 520 os << "}\n"; |
| 516 } | 521 } |
| 517 int internal_fields = obj->GetInternalFieldCount(); | 522 int internal_fields = obj->GetInternalFieldCount(); |
| 518 if (internal_fields > 0) { | 523 if (internal_fields > 0) { |
| 519 os << " - internal fields = {"; | 524 os << " - internal fields = {"; |
| 520 for (int i = 0; i < internal_fields; i++) { | 525 for (int i = 0; i < internal_fields; i++) { |
| 521 os << "\n " << Brief(obj->GetInternalField(i)); | 526 os << "\n " << Brief(obj->GetInternalField(i)); |
| 522 } | 527 } |
| 523 os << "\n }\n"; | 528 os << "\n }\n"; |
| 524 } | 529 } |
| 525 } | 530 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 | 636 |
| 632 void AliasedArgumentsEntry::AliasedArgumentsEntryPrint( | 637 void AliasedArgumentsEntry::AliasedArgumentsEntryPrint( |
| 633 std::ostream& os) { // NOLINT | 638 std::ostream& os) { // NOLINT |
| 634 HeapObject::PrintHeader(os, "AliasedArgumentsEntry"); | 639 HeapObject::PrintHeader(os, "AliasedArgumentsEntry"); |
| 635 os << "\n - aliased_context_slot: " << aliased_context_slot(); | 640 os << "\n - aliased_context_slot: " << aliased_context_slot(); |
| 636 } | 641 } |
| 637 | 642 |
| 638 | 643 |
| 639 void FixedArray::FixedArrayPrint(std::ostream& os) { // NOLINT | 644 void FixedArray::FixedArrayPrint(std::ostream& os) { // NOLINT |
| 640 HeapObject::PrintHeader(os, "FixedArray"); | 645 HeapObject::PrintHeader(os, "FixedArray"); |
| 646 os << "\n - map = " << Brief(map()); |
| 641 os << "\n - length: " << length(); | 647 os << "\n - length: " << length(); |
| 642 for (int i = 0; i < length(); i++) { | 648 PrintFixedArrayElements(os, this); |
| 643 os << "\n [" << i << "]: " << Brief(get(i)); | |
| 644 } | |
| 645 os << "\n"; | 649 os << "\n"; |
| 646 } | 650 } |
| 647 | 651 |
| 648 | 652 |
| 649 void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT | 653 void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT |
| 650 HeapObject::PrintHeader(os, "FixedDoubleArray"); | 654 HeapObject::PrintHeader(os, "FixedDoubleArray"); |
| 655 os << "\n - map = " << Brief(map()); |
| 651 os << "\n - length: " << length(); | 656 os << "\n - length: " << length(); |
| 652 for (int i = 0; i < length(); i++) { | 657 DoPrintElements<FixedDoubleArray, true>(os, this); |
| 653 os << "\n [" << i << "]: "; | |
| 654 if (is_the_hole(i)) { | |
| 655 os << "<the hole>"; | |
| 656 } else { | |
| 657 os << get_scalar(i); | |
| 658 } | |
| 659 } | |
| 660 os << "\n"; | 658 os << "\n"; |
| 661 } | 659 } |
| 662 | 660 |
| 663 | 661 |
| 664 void TransitionArray::TransitionArrayPrint(std::ostream& os) { // NOLINT | 662 void TransitionArray::TransitionArrayPrint(std::ostream& os) { // NOLINT |
| 665 HeapObject::PrintHeader(os, "TransitionArray"); | 663 HeapObject::PrintHeader(os, "TransitionArray"); |
| 666 os << "\n - capacity: " << length(); | 664 os << "\n - capacity: " << length(); |
| 667 for (int i = 0; i < length(); i++) { | 665 for (int i = 0; i < length(); i++) { |
| 668 os << "\n [" << i << "]: " << Brief(get(i)); | 666 os << "\n [" << i << "]: " << Brief(get(i)); |
| 669 if (i == kNextLinkIndex) os << " (next link)"; | 667 if (i == kNextLinkIndex) os << " (next link)"; |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 printf("Not a transition array\n"); | 1717 printf("Not a transition array\n"); |
| 1720 } else { | 1718 } else { |
| 1721 reinterpret_cast<i::TransitionArray*>(object)->Print(); | 1719 reinterpret_cast<i::TransitionArray*>(object)->Print(); |
| 1722 } | 1720 } |
| 1723 } | 1721 } |
| 1724 | 1722 |
| 1725 extern void _v8_internal_Print_StackTrace() { | 1723 extern void _v8_internal_Print_StackTrace() { |
| 1726 i::Isolate* isolate = i::Isolate::Current(); | 1724 i::Isolate* isolate = i::Isolate::Current(); |
| 1727 isolate->PrintStack(stdout); | 1725 isolate->PrintStack(stdout); |
| 1728 } | 1726 } |
| OLD | NEW |