1.1 --- a/src/share/vm/utilities/globalDefinitions.hpp Thu Sep 05 18:40:52 2019 +0800 1.2 +++ b/src/share/vm/utilities/globalDefinitions.hpp Thu Sep 05 18:52:27 2019 +0800 1.3 @@ -217,15 +217,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 @@ -235,13 +240,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 @@ -333,7 +338,7 @@ 1.45 // so far from the middle of the road that it is likely to be problematic in 1.46 // many C++ compilers. 1.47 // 1.48 -#define CAST_TO_FN_PTR(func_type, value) ((func_type)(castable_address(value))) 1.49 +#define CAST_TO_FN_PTR(func_type, value) (reinterpret_cast<func_type>(value)) 1.50 #define CAST_FROM_FN_PTR(new_type, func_ptr) ((new_type)((address_word)(func_ptr))) 1.51 1.52 // Unsigned byte types for os and stream.hpp 1.53 @@ -1495,6 +1500,7 @@ 1.54 class GlobalDefinitions { 1.55 public: 1.56 static void test_globals(); 1.57 + static void test_proper_unit(); 1.58 }; 1.59 1.60 #endif // PRODUCT