Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: src/objects-printer.cc

Issue 2652553003: Access double fields in C++ as uint64_t fields to preserve signaling bit of a NaN. (Closed)
Patch Set: More fixes Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects-inl.h ('k') | test/cctest/heap/test-alloc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 global_dictionary()->Print(os); 358 global_dictionary()->Print(os);
359 } else { 359 } else {
360 property_dictionary()->Print(os); 360 property_dictionary()->Print(os);
361 } 361 }
362 return true; 362 return true;
363 } 363 }
364 364
365 namespace { 365 namespace {
366 366
367 template <class T> 367 template <class T>
368 bool IsTheHoleAt(T* array, int index) {
369 return false;
370 }
371
372 template <>
373 bool IsTheHoleAt(FixedDoubleArray* array, int index) {
374 return array->is_the_hole(index);
375 }
376
377 template <class T>
368 double GetScalarElement(T* array, int index) { 378 double GetScalarElement(T* array, int index) {
379 if (IsTheHoleAt(array, index)) {
380 return std::numeric_limits<double>::quiet_NaN();
381 }
369 return array->get_scalar(index); 382 return array->get_scalar(index);
370 } 383 }
371 384
372 double GetScalarElement(FixedDoubleArray* array, int index) { 385 template <class T>
373 if (array->is_the_hole(index)) return bit_cast<double>(kHoleNanInt64);
374 return array->get_scalar(index);
375 }
376
377 bool is_the_hole(double maybe_hole) {
378 return bit_cast<uint64_t>(maybe_hole) == kHoleNanInt64;
379 }
380
381 template <class T, bool print_the_hole>
382 void DoPrintElements(std::ostream& os, Object* object) { // NOLINT 386 void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
387 const bool print_the_hole = std::is_same<T, FixedDoubleArray>::value;
383 T* array = T::cast(object); 388 T* array = T::cast(object);
384 if (array->length() == 0) return; 389 if (array->length() == 0) return;
385 int previous_index = 0; 390 int previous_index = 0;
386 double previous_value = GetScalarElement(array, 0); 391 double previous_value = GetScalarElement(array, 0);
387 double value = 0.0; 392 double value = 0.0;
388 int i; 393 int i;
389 for (i = 1; i <= array->length(); i++) { 394 for (i = 1; i <= array->length(); i++) {
390 if (i < array->length()) value = GetScalarElement(array, i); 395 if (i < array->length()) value = GetScalarElement(array, i);
391 bool values_are_nan = std::isnan(previous_value) && std::isnan(value); 396 bool values_are_nan = std::isnan(previous_value) && std::isnan(value);
392 if (i != array->length() && (previous_value == value || values_are_nan) && 397 if (i != array->length() && (previous_value == value || values_are_nan) &&
393 is_the_hole(previous_value) == is_the_hole(value)) { 398 IsTheHoleAt(array, i - 1) == IsTheHoleAt(array, i)) {
394 continue; 399 continue;
395 } 400 }
396 os << "\n"; 401 os << "\n";
397 std::stringstream ss; 402 std::stringstream ss;
398 ss << previous_index; 403 ss << previous_index;
399 if (previous_index != i - 1) { 404 if (previous_index != i - 1) {
400 ss << '-' << (i - 1); 405 ss << '-' << (i - 1);
401 } 406 }
402 os << std::setw(12) << ss.str() << ": "; 407 os << std::setw(12) << ss.str() << ": ";
403 if (print_the_hole && is_the_hole(previous_value)) { 408 if (print_the_hole && IsTheHoleAt(array, i - 1)) {
404 os << "<the_hole>"; 409 os << "<the_hole>";
405 } else { 410 } else {
406 os << previous_value; 411 os << previous_value;
407 } 412 }
408 previous_index = i; 413 previous_index = i;
409 previous_value = value; 414 previous_value = value;
410 } 415 }
411 } 416 }
412 417
413 void PrintFixedArrayElements(std::ostream& os, FixedArray* array) { 418 void PrintFixedArrayElements(std::ostream& os, FixedArray* array) {
(...skipping 29 matching lines...) Expand all
443 case FAST_HOLEY_SMI_ELEMENTS: 448 case FAST_HOLEY_SMI_ELEMENTS:
444 case FAST_SMI_ELEMENTS: 449 case FAST_SMI_ELEMENTS:
445 case FAST_HOLEY_ELEMENTS: 450 case FAST_HOLEY_ELEMENTS:
446 case FAST_ELEMENTS: 451 case FAST_ELEMENTS:
447 case FAST_STRING_WRAPPER_ELEMENTS: { 452 case FAST_STRING_WRAPPER_ELEMENTS: {
448 PrintFixedArrayElements(os, FixedArray::cast(elements())); 453 PrintFixedArrayElements(os, FixedArray::cast(elements()));
449 break; 454 break;
450 } 455 }
451 case FAST_HOLEY_DOUBLE_ELEMENTS: 456 case FAST_HOLEY_DOUBLE_ELEMENTS:
452 case FAST_DOUBLE_ELEMENTS: { 457 case FAST_DOUBLE_ELEMENTS: {
453 DoPrintElements<FixedDoubleArray, true>(os, elements()); 458 DoPrintElements<FixedDoubleArray>(os, elements());
454 break; 459 break;
455 } 460 }
456 461
457 #define PRINT_ELEMENTS(Type, type, TYPE, elementType, size) \ 462 #define PRINT_ELEMENTS(Type, type, TYPE, elementType, size) \
458 case TYPE##_ELEMENTS: { \ 463 case TYPE##_ELEMENTS: { \
459 DoPrintElements<Fixed##Type##Array, false>(os, elements()); \ 464 DoPrintElements<Fixed##Type##Array>(os, elements()); \
460 break; \ 465 break; \
461 } 466 }
462 TYPED_ARRAYS(PRINT_ELEMENTS) 467 TYPED_ARRAYS(PRINT_ELEMENTS)
463 #undef PRINT_ELEMENTS 468 #undef PRINT_ELEMENTS
464 469
465 case DICTIONARY_ELEMENTS: 470 case DICTIONARY_ELEMENTS:
466 case SLOW_STRING_WRAPPER_ELEMENTS: 471 case SLOW_STRING_WRAPPER_ELEMENTS:
467 SeededNumberDictionary::cast(elements())->Print(os); 472 SeededNumberDictionary::cast(elements())->Print(os);
468 break; 473 break;
469 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: 474 case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
470 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: { 475 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 os << "\n - length: " << length(); 652 os << "\n - length: " << length();
648 PrintFixedArrayElements(os, this); 653 PrintFixedArrayElements(os, this);
649 os << "\n"; 654 os << "\n";
650 } 655 }
651 656
652 657
653 void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT 658 void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT
654 HeapObject::PrintHeader(os, "FixedDoubleArray"); 659 HeapObject::PrintHeader(os, "FixedDoubleArray");
655 os << "\n - map = " << Brief(map()); 660 os << "\n - map = " << Brief(map());
656 os << "\n - length: " << length(); 661 os << "\n - length: " << length();
657 DoPrintElements<FixedDoubleArray, true>(os, this); 662 DoPrintElements<FixedDoubleArray>(os, this);
658 os << "\n"; 663 os << "\n";
659 } 664 }
660 665
661 666
662 void TransitionArray::TransitionArrayPrint(std::ostream& os) { // NOLINT 667 void TransitionArray::TransitionArrayPrint(std::ostream& os) { // NOLINT
663 HeapObject::PrintHeader(os, "TransitionArray"); 668 HeapObject::PrintHeader(os, "TransitionArray");
664 os << "\n - capacity: " << length(); 669 os << "\n - capacity: " << length();
665 for (int i = 0; i < length(); i++) { 670 for (int i = 0; i < length(); i++) {
666 os << "\n [" << i << "]: " << Brief(get(i)); 671 os << "\n [" << i << "]: " << Brief(get(i));
667 if (i == kNextLinkIndex) os << " (next link)"; 672 if (i == kNextLinkIndex) os << " (next link)";
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 printf("Not a transition array\n"); 1726 printf("Not a transition array\n");
1722 } else { 1727 } else {
1723 reinterpret_cast<i::TransitionArray*>(object)->Print(); 1728 reinterpret_cast<i::TransitionArray*>(object)->Print();
1724 } 1729 }
1725 } 1730 }
1726 1731
1727 extern void _v8_internal_Print_StackTrace() { 1732 extern void _v8_internal_Print_StackTrace() {
1728 i::Isolate* isolate = i::Isolate::Current(); 1733 i::Isolate* isolate = i::Isolate::Current();
1729 isolate->PrintStack(stdout); 1734 isolate->PrintStack(stdout);
1730 } 1735 }
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | test/cctest/heap/test-alloc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698