1.1 --- a/src/share/vm/utilities/globalDefinitions.hpp Thu May 02 17:12:38 2019 +0100 1.2 +++ b/src/share/vm/utilities/globalDefinitions.hpp Fri Jan 18 17:05:41 2019 +0100 1.3 @@ -211,15 +211,20 @@ 1.4 const jlong NANOSECS_PER_SEC = CONST64(1000000000); 1.5 const jint NANOSECS_PER_MILLISEC = 1000000; 1.6 1.7 +// Proper units routines try to maintain at least three significant digits. 1.8 +// In worst case, it would print five significant digits with lower prefix. 1.9 +// G is close to MAX_SIZE on 32-bit platforms, so its product can easily overflow, 1.10 +// and therefore we need to be careful. 1.11 + 1.12 inline const char* proper_unit_for_byte_size(size_t s) { 1.13 #ifdef _LP64 1.14 - if (s >= 10*G) { 1.15 + if (s >= 100*G) { 1.16 return "G"; 1.17 } 1.18 #endif 1.19 - if (s >= 10*M) { 1.20 + if (s >= 100*M) { 1.21 return "M"; 1.22 - } else if (s >= 10*K) { 1.23 + } else if (s >= 100*K) { 1.24 return "K"; 1.25 } else { 1.26 return "B"; 1.27 @@ -229,13 +234,13 @@ 1.28 template <class T> 1.29 inline T byte_size_in_proper_unit(T s) { 1.30 #ifdef _LP64 1.31 - if (s >= 10*G) { 1.32 + if (s >= 100*G) { 1.33 return (T)(s/G); 1.34 } 1.35 #endif 1.36 - if (s >= 10*M) { 1.37 + if (s >= 100*M) { 1.38 return (T)(s/M); 1.39 - } else if (s >= 10*K) { 1.40 + } else if (s >= 100*K) { 1.41 return (T)(s/K); 1.42 } else { 1.43 return s; 1.44 @@ -1486,6 +1491,7 @@ 1.45 class GlobalDefinitions { 1.46 public: 1.47 static void test_globals(); 1.48 + static void test_proper_unit(); 1.49 }; 1.50 1.51 #endif // PRODUCT