1.1 --- a/src/share/vm/utilities/globalDefinitions.hpp Wed Feb 06 14:59:45 2019 +0900 1.2 +++ b/src/share/vm/utilities/globalDefinitions.hpp Wed Feb 06 17:32:25 2019 +0100 1.3 @@ -1136,10 +1136,10 @@ 1.4 1.5 //* largest i such that 2^i <= x 1.6 // A negative value of 'x' will return '31' 1.7 -inline int log2_intptr(intptr_t x) { 1.8 +inline int log2_intptr(uintptr_t x) { 1.9 int i = -1; 1.10 uintptr_t p = 1; 1.11 - while (p != 0 && p <= (uintptr_t)x) { 1.12 + while (p != 0 && p <= x) { 1.13 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) 1.14 i++; p *= 2; 1.15 } 1.16 @@ -1150,10 +1150,10 @@ 1.17 1.18 //* largest i such that 2^i <= x 1.19 // A negative value of 'x' will return '63' 1.20 -inline int log2_long(jlong x) { 1.21 +inline int log2_long(unsigned long x) { 1.22 int i = -1; 1.23 julong p = 1; 1.24 - while (p != 0 && p <= (julong)x) { 1.25 + while (p != 0 && p <= x) { 1.26 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) 1.27 i++; p *= 2; 1.28 } 1.29 @@ -1162,6 +1162,22 @@ 1.30 return i; 1.31 } 1.32 1.33 +inline int log2_intptr(intptr_t x) { 1.34 + return log2_intptr((uintptr_t)x); 1.35 +} 1.36 + 1.37 +inline int log2_intptr(int x) { 1.38 + return log2_intptr((uintptr_t)x); 1.39 +} 1.40 + 1.41 +inline int log2_intptr(uint x) { 1.42 + return log2_intptr((uintptr_t)x); 1.43 +} 1.44 + 1.45 +inline int log2_long(jlong x) { 1.46 + return log2_long((unsigned long)x); 1.47 +} 1.48 + 1.49 //* the argument must be exactly a power of 2 1.50 inline int exact_log2(intptr_t x) { 1.51 #ifdef ASSERT 1.52 @@ -1201,6 +1217,29 @@ 1.53 inline bool is_odd (intx x) { return x & 1; } 1.54 inline bool is_even(intx x) { return !is_odd(x); } 1.55 1.56 +// abs methods which cannot overflow and so are well-defined across 1.57 +// the entire domain of integer types. 1.58 +static inline unsigned int uabs(unsigned int n) { 1.59 + union { 1.60 + unsigned int result; 1.61 + int value; 1.62 + }; 1.63 + result = n; 1.64 + if (value < 0) result = 0-result; 1.65 + return result; 1.66 +} 1.67 +static inline unsigned long uabs(unsigned long n) { 1.68 + union { 1.69 + unsigned long result; 1.70 + long value; 1.71 + }; 1.72 + result = n; 1.73 + if (value < 0) result = 0-result; 1.74 + return result; 1.75 +} 1.76 +static inline unsigned long uabs(jlong n) { return uabs((unsigned long)n); } 1.77 +static inline unsigned int uabs(int n) { return uabs((unsigned int)n); } 1.78 + 1.79 // "to" should be greater than "from." 1.80 inline intx byte_size(void* from, void* to) { 1.81 return (address)to - (address)from;