< prev index next >

src/hotspot/share/utilities/globalDefinitions.hpp

Print this page
rev 53303 : 8217315: Proper units should print more significant digits
Reviewed-by: XXX

*** 228,262 **** const int NANOUNITS = 1000000000; // nano units per base unit const jlong NANOSECS_PER_SEC = CONST64(1000000000); const jint NANOSECS_PER_MILLISEC = 1000000; inline const char* proper_unit_for_byte_size(size_t s) { #ifdef _LP64 ! if (s >= 10*G) { return "G"; } #endif ! if (s >= 10*M) { return "M"; ! } else if (s >= 10*K) { return "K"; } else { return "B"; } } template <class T> inline T byte_size_in_proper_unit(T s) { #ifdef _LP64 ! if (s >= 10*G) { return (T)(s/G); } #endif ! if (s >= 10*M) { return (T)(s/M); ! } else if (s >= 10*K) { return (T)(s/K); } else { return s; } } --- 228,267 ---- const int NANOUNITS = 1000000000; // nano units per base unit const jlong NANOSECS_PER_SEC = CONST64(1000000000); const jint NANOSECS_PER_MILLISEC = 1000000; + // Proper units routines try to maintain at least three significant digits. + // In worst case, it would print five significant digits with lower prefix. + // G is close to MAX_SIZE on 32-bit platforms, so its product can easily overflow, + // and therefore we need to be careful. + inline const char* proper_unit_for_byte_size(size_t s) { #ifdef _LP64 ! if (s >= 100*G) { return "G"; } #endif ! if (s >= 100*M) { return "M"; ! } else if (s >= 100*K) { return "K"; } else { return "B"; } } template <class T> inline T byte_size_in_proper_unit(T s) { #ifdef _LP64 ! if (s >= 100*G) { return (T)(s/G); } #endif ! if (s >= 100*M) { return (T)(s/M); ! } else if (s >= 100*K) { return (T)(s/K); } else { return s; } }
< prev index next >