--- old/src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp 2018-11-22 20:42:24.521167989 +0100 +++ new/src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp 2018-11-22 20:42:18.937213192 +0100 @@ -292,11 +292,11 @@ bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) { assert(left != result, "should be different registers"); if (is_power_of_2(c + 1)) { - __ shift_left(left, log2_intptr(c + 1), result); + __ shift_left(left, log2_int(c + 1), result); __ sub(result, left, result); return true; } else if (is_power_of_2(c - 1)) { - __ shift_left(left, log2_intptr(c - 1), result); + __ shift_left(left, log2_int(c - 1), result); __ add(result, left, result); return true; } --- old/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp 2018-11-22 20:42:30.220121856 +0100 +++ new/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp 2018-11-22 20:42:24.619167196 +0100 @@ -227,12 +227,12 @@ if (tmp->is_valid()) { if (is_power_of_2(c + 1)) { __ move(left, tmp); - __ shift_left(left, log2_intptr(c + 1), left); + __ shift_left(left, log2_int(c + 1), left); __ sub(left, tmp, result); return true; } else if (is_power_of_2(c - 1)) { __ move(left, tmp); - __ shift_left(left, log2_intptr(c - 1), left); + __ shift_left(left, log2_int(c - 1), left); __ add(left, tmp, result); return true; } --- old/src/hotspot/cpu/sparc/c1_LIRAssembler_sparc.cpp 2018-11-22 20:42:35.613078201 +0100 +++ new/src/hotspot/cpu/sparc/c1_LIRAssembler_sparc.cpp 2018-11-22 20:42:30.300121209 +0100 @@ -502,7 +502,7 @@ __ and3(Rscratch, divisor - 1, Rscratch); } __ add(Rdividend, Rscratch, Rscratch); - __ sra(Rscratch, log2_intptr(divisor), Rresult); + __ sra(Rscratch, log2_int(divisor), Rresult); return; } else { if (divisor == 2) { --- old/src/hotspot/cpu/sparc/c1_LIRGenerator_sparc.cpp 2018-11-22 20:42:41.331031915 +0100 +++ new/src/hotspot/cpu/sparc/c1_LIRGenerator_sparc.cpp 2018-11-22 20:42:35.711077407 +0100 @@ -284,11 +284,11 @@ bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) { assert(left != result, "should be different registers"); if (is_power_of_2(c + 1)) { - __ shift_left(left, log2_intptr(c + 1), result); + __ shift_left(left, log2_int(c + 1), result); __ sub(result, left, result); return true; } else if (is_power_of_2(c - 1)) { - __ shift_left(left, log2_intptr(c - 1), result); + __ shift_left(left, log2_int(c - 1), result); __ add(result, left, result); return true; } --- old/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp 2018-11-22 20:42:46.941986494 +0100 +++ new/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp 2018-11-22 20:42:41.414031243 +0100 @@ -2555,7 +2555,7 @@ Register dreg = result->as_register(); if (right->is_constant()) { - int divisor = right->as_constant_ptr()->as_jint(); + jint divisor = right->as_constant_ptr()->as_jint(); assert(divisor > 0 && is_power_of_2(divisor), "must be"); if (code == lir_idiv) { assert(lreg == rax, "must be rax,"); @@ -2567,7 +2567,7 @@ __ andl(rdx, divisor - 1); __ addl(lreg, rdx); } - __ sarl(lreg, log2_intptr(divisor)); + __ sarl(lreg, log2_jint(divisor)); move_regs(lreg, dreg); } else if (code == lir_irem) { Label done; --- old/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp 2018-11-22 20:42:52.575940888 +0100 +++ new/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp 2018-11-22 20:42:47.043985668 +0100 @@ -244,12 +244,12 @@ if (tmp->is_valid() && c > 0 && c < max_jint) { if (is_power_of_2(c + 1)) { __ move(left, tmp); - __ shift_left(left, log2_intptr(c + 1), left); + __ shift_left(left, log2_jint(c + 1), left); __ sub(left, tmp, result); return true; } else if (is_power_of_2(c - 1)) { __ move(left, tmp); - __ shift_left(left, log2_intptr(c - 1), left); + __ shift_left(left, log2_jint(c - 1), left); __ add(left, tmp, result); return true; } --- old/src/hotspot/share/opto/divnode.cpp 2018-11-22 20:42:58.182895499 +0100 +++ new/src/hotspot/share/opto/divnode.cpp 2018-11-22 20:42:52.659940207 +0100 @@ -133,7 +133,7 @@ } // Add rounding to the shift to handle the sign bit - int l = log2_intptr(d-1)+1; + int l = log2_jint(d-1)+1; if (needs_rounding) { // Divide-by-power-of-2 can be made into a shift, but you have to do // more math for the rounding. You need to add 0 for positive --- old/src/hotspot/share/opto/mulnode.cpp 2018-11-22 20:43:03.363853559 +0100 +++ new/src/hotspot/share/opto/mulnode.cpp 2018-11-22 20:42:58.270894787 +0100 @@ -199,21 +199,21 @@ Node *res = NULL; unsigned int bit1 = abs_con & (0-abs_con); // Extract low bit if (bit1 == abs_con) { // Found a power of 2? - res = new LShiftINode(in(1), phase->intcon(log2_intptr(bit1))); + res = new LShiftINode(in(1), phase->intcon(log2_uint(bit1))); } else { // Check for constant with 2 bits set unsigned int bit2 = abs_con-bit1; bit2 = bit2 & (0-bit2); // Extract 2nd bit if (bit2 + bit1 == abs_con) { // Found all bits in con? - Node *n1 = phase->transform( new LShiftINode(in(1), phase->intcon(log2_intptr(bit1)))); - Node *n2 = phase->transform( new LShiftINode(in(1), phase->intcon(log2_intptr(bit2)))); + Node *n1 = phase->transform( new LShiftINode(in(1), phase->intcon(log2_uint(bit1)))); + Node *n2 = phase->transform( new LShiftINode(in(1), phase->intcon(log2_uint(bit2)))); res = new AddINode(n2, n1); } else if (is_power_of_2(abs_con+1)) { // Sleezy: power-of-2 -1. Next time be generic. unsigned int temp = abs_con + 1; - Node *n1 = phase->transform(new LShiftINode(in(1), phase->intcon(log2_intptr(temp)))); + Node *n1 = phase->transform(new LShiftINode(in(1), phase->intcon(log2_uint(temp)))); res = new SubINode(n1, in(1)); } else { return MulNode::Ideal(phase, can_reshape); @@ -445,7 +445,7 @@ // Masking off high bits which are always zero is useless. const TypeInt* t1 = phase->type( in(1) )->isa_int(); if (t1 != NULL && t1->_lo >= 0) { - jint t1_support = right_n_bits(1 + log2_intptr(t1->_hi)); + jint t1_support = right_n_bits(1 + log2_jint(t1->_hi)); if ((t1_support & con) == t1_support) return in1; } --- old/src/hotspot/share/runtime/compilationPolicy.cpp 2018-11-22 20:43:09.048807540 +0100 +++ new/src/hotspot/share/runtime/compilationPolicy.cpp 2018-11-22 20:43:03.449852863 +0100 @@ -228,7 +228,7 @@ // Example: if CICompilerCountPerCPU is true, then we get // max(log2(8)-1,1) = 2 compiler threads on an 8-way machine. // May help big-app startup time. - _compiler_count = MAX2(log2_intptr(os::active_processor_count())-1,1); + _compiler_count = MAX2(log2_int(os::active_processor_count())-1,1); // Make sure there is enough space in the code cache to hold all the compiler buffers size_t buffer_size = 1; #ifdef COMPILER1 --- old/src/hotspot/share/runtime/tieredThresholdPolicy.cpp 2018-11-22 20:43:14.684761917 +0100 +++ new/src/hotspot/share/runtime/tieredThresholdPolicy.cpp 2018-11-22 20:43:09.129806884 +0100 @@ -226,8 +226,8 @@ } if (CICompilerCountPerCPU) { // Simple log n seems to grow too slowly for tiered, try something faster: log n * log log n - int log_cpu = log2_intptr(os::active_processor_count()); - int loglog_cpu = log2_intptr(MAX2(log_cpu, 1)); + int log_cpu = log2_int(os::active_processor_count()); + int loglog_cpu = log2_int(MAX2(log_cpu, 1)); count = MAX2(log_cpu * loglog_cpu * 3 / 2, 2); // Make sure there is enough space in the code cache to hold all the compiler buffers size_t c1_size = Compiler::code_buffer_size(); --- old/src/hotspot/share/utilities/globalDefinitions.hpp 2018-11-22 20:43:20.218717120 +0100 +++ new/src/hotspot/share/utilities/globalDefinitions.hpp 2018-11-22 20:43:14.767761246 +0100 @@ -1048,7 +1048,7 @@ //* largest i such that 2^i <= x // A negative value of 'x' will return '63' -inline int log2_long(unsigned long x) { +inline int log2_long(julong x) { int i = -1; julong p = 1; while (p != 0 && p <= x) { @@ -1064,16 +1064,24 @@ return log2_intptr((uintptr_t)x); } -inline int log2_intptr(int x) { +inline int log2_int(int x) { + STATIC_ASSERT(sizeof(int) <= sizeof(uintptr_t)); return log2_intptr((uintptr_t)x); } -inline int log2_intptr(uint x) { +inline int log2_jint(jint x) { + STATIC_ASSERT(sizeof(jint) <= sizeof(uintptr_t)); return log2_intptr((uintptr_t)x); } -inline int log2_long(jlong x) { - return log2_long((unsigned long)x); +inline int log2_uint(uint x) { + STATIC_ASSERT(sizeof(uint) <= sizeof(uintptr_t)); + return log2_intptr((uintptr_t)x); +} + +inline int log2_jlong(jlong x) { + STATIC_ASSERT(sizeof(jlong) <= sizeof(julong)); + return log2_long((julong)x); } //* the argument must be exactly a power of 2 --- old/src/hotspot/share/utilities/hashtable.cpp 2018-11-22 20:43:25.672672970 +0100 +++ new/src/hotspot/share/utilities/hashtable.cpp 2018-11-22 20:43:20.300716456 +0100 @@ -62,7 +62,7 @@ if (_first_free_entry + _entry_size >= _end_block) { int block_size = MIN2(512, MAX2((int)_table_size / 2, (int)_number_of_entries)); int len = _entry_size * block_size; - len = 1 << log2_intptr(len); // round down to power of 2 + len = 1 << log2_int(len); // round down to power of 2 assert(len >= _entry_size, ""); _first_free_entry = NEW_C_HEAP_ARRAY2(char, len, F, CURRENT_PC); _entry_blocks->append(_first_free_entry);