src/share/vm/utilities/globalDefinitions.hpp

changeset 9667
1a1aec8c87b7
parent 9619
71bd8f8ad1fb
child 9677
af43bab3c5d0
equal deleted inserted replaced
9666:4fdf42cda0d5 9667:1a1aec8c87b7
209 const int NANOUNITS = 1000000000; // nano units per base unit 209 const int NANOUNITS = 1000000000; // nano units per base unit
210 210
211 const jlong NANOSECS_PER_SEC = CONST64(1000000000); 211 const jlong NANOSECS_PER_SEC = CONST64(1000000000);
212 const jint NANOSECS_PER_MILLISEC = 1000000; 212 const jint NANOSECS_PER_MILLISEC = 1000000;
213 213
214 // Proper units routines try to maintain at least three significant digits.
215 // In worst case, it would print five significant digits with lower prefix.
216 // G is close to MAX_SIZE on 32-bit platforms, so its product can easily overflow,
217 // and therefore we need to be careful.
218
214 inline const char* proper_unit_for_byte_size(size_t s) { 219 inline const char* proper_unit_for_byte_size(size_t s) {
215 #ifdef _LP64 220 #ifdef _LP64
216 if (s >= 10*G) { 221 if (s >= 100*G) {
217 return "G"; 222 return "G";
218 } 223 }
219 #endif 224 #endif
220 if (s >= 10*M) { 225 if (s >= 100*M) {
221 return "M"; 226 return "M";
222 } else if (s >= 10*K) { 227 } else if (s >= 100*K) {
223 return "K"; 228 return "K";
224 } else { 229 } else {
225 return "B"; 230 return "B";
226 } 231 }
227 } 232 }
228 233
229 template <class T> 234 template <class T>
230 inline T byte_size_in_proper_unit(T s) { 235 inline T byte_size_in_proper_unit(T s) {
231 #ifdef _LP64 236 #ifdef _LP64
232 if (s >= 10*G) { 237 if (s >= 100*G) {
233 return (T)(s/G); 238 return (T)(s/G);
234 } 239 }
235 #endif 240 #endif
236 if (s >= 10*M) { 241 if (s >= 100*M) {
237 return (T)(s/M); 242 return (T)(s/M);
238 } else if (s >= 10*K) { 243 } else if (s >= 100*K) {
239 return (T)(s/K); 244 return (T)(s/K);
240 } else { 245 } else {
241 return s; 246 return s;
242 } 247 }
243 } 248 }
1484 1489
1485 // For unit testing only 1490 // For unit testing only
1486 class GlobalDefinitions { 1491 class GlobalDefinitions {
1487 public: 1492 public:
1488 static void test_globals(); 1493 static void test_globals();
1494 static void test_proper_unit();
1489 }; 1495 };
1490 1496
1491 #endif // PRODUCT 1497 #endif // PRODUCT
1492 1498
1493 #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP 1499 #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP

mercurial