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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects-inl.h ('k') | test/cctest/heap/test-alloc.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-printer.cc
diff --git a/src/objects-printer.cc b/src/objects-printer.cc
index 10023db5597adbb661cc11dbb389ffdc9c39f2ff..137451bdc5044cbd824853bdaff6e5f8e598727f 100644
--- a/src/objects-printer.cc
+++ b/src/objects-printer.cc
@@ -365,21 +365,26 @@ bool JSObject::PrintProperties(std::ostream& os) { // NOLINT
namespace {
template <class T>
-double GetScalarElement(T* array, int index) {
- return array->get_scalar(index);
+bool IsTheHoleAt(T* array, int index) {
+ return false;
}
-double GetScalarElement(FixedDoubleArray* array, int index) {
- if (array->is_the_hole(index)) return bit_cast<double>(kHoleNanInt64);
- return array->get_scalar(index);
+template <>
+bool IsTheHoleAt(FixedDoubleArray* array, int index) {
+ return array->is_the_hole(index);
}
-bool is_the_hole(double maybe_hole) {
- return bit_cast<uint64_t>(maybe_hole) == kHoleNanInt64;
+template <class T>
+double GetScalarElement(T* array, int index) {
+ if (IsTheHoleAt(array, index)) {
+ return std::numeric_limits<double>::quiet_NaN();
+ }
+ return array->get_scalar(index);
}
-template <class T, bool print_the_hole>
+template <class T>
void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
+ const bool print_the_hole = std::is_same<T, FixedDoubleArray>::value;
T* array = T::cast(object);
if (array->length() == 0) return;
int previous_index = 0;
@@ -390,7 +395,7 @@ void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
if (i < array->length()) value = GetScalarElement(array, i);
bool values_are_nan = std::isnan(previous_value) && std::isnan(value);
if (i != array->length() && (previous_value == value || values_are_nan) &&
- is_the_hole(previous_value) == is_the_hole(value)) {
+ IsTheHoleAt(array, i - 1) == IsTheHoleAt(array, i)) {
continue;
}
os << "\n";
@@ -400,7 +405,7 @@ void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
ss << '-' << (i - 1);
}
os << std::setw(12) << ss.str() << ": ";
- if (print_the_hole && is_the_hole(previous_value)) {
+ if (print_the_hole && IsTheHoleAt(array, i - 1)) {
os << "<the_hole>";
} else {
os << previous_value;
@@ -450,14 +455,14 @@ bool JSObject::PrintElements(std::ostream& os) { // NOLINT
}
case FAST_HOLEY_DOUBLE_ELEMENTS:
case FAST_DOUBLE_ELEMENTS: {
- DoPrintElements<FixedDoubleArray, true>(os, elements());
+ DoPrintElements<FixedDoubleArray>(os, elements());
break;
}
-#define PRINT_ELEMENTS(Type, type, TYPE, elementType, size) \
- case TYPE##_ELEMENTS: { \
- DoPrintElements<Fixed##Type##Array, false>(os, elements()); \
- break; \
+#define PRINT_ELEMENTS(Type, type, TYPE, elementType, size) \
+ case TYPE##_ELEMENTS: { \
+ DoPrintElements<Fixed##Type##Array>(os, elements()); \
+ break; \
}
TYPED_ARRAYS(PRINT_ELEMENTS)
#undef PRINT_ELEMENTS
@@ -654,7 +659,7 @@ void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "FixedDoubleArray");
os << "\n - map = " << Brief(map());
os << "\n - length: " << length();
- DoPrintElements<FixedDoubleArray, true>(os, this);
+ DoPrintElements<FixedDoubleArray>(os, this);
os << "\n";
}
« 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