diff --git a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp index a8e4394de0c..a743e16a1bf 100644 --- a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp @@ -40,10 +40,10 @@ #include "oops/objArrayKlass.hpp" #include "runtime/frame.inline.hpp" #include "runtime/sharedRuntime.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_aarch64.inline.hpp" - #ifndef PRODUCT #define COMMENT(x) do { __ block_comment(x); } while (0) #else @@ -1747,7 +1747,7 @@ void LIR_Assembler::arith_op(LIR_Code code, LIR_Opr left, LIR_Opr right, LIR_Opr code == lir_add ? __ add(dreg, lreg_lo, c) : __ sub(dreg, lreg_lo, c); break; case lir_div: - assert(c > 0 && is_power_of_2_long(c), "divisor must be power-of-2 constant"); + assert(c > 0 && is_power_of_2(c), "divisor must be power-of-2 constant"); if (c == 1) { // move lreg_lo to dreg if divisor is 1 __ mov(dreg, lreg_lo); @@ -1760,7 +1760,7 @@ void LIR_Assembler::arith_op(LIR_Code code, LIR_Opr left, LIR_Opr right, LIR_Opr } break; case lir_rem: - assert(c > 0 && is_power_of_2_long(c), "divisor must be power-of-2 constant"); + assert(c > 0 && is_power_of_2(c), "divisor must be power-of-2 constant"); if (c == 1) { // move 0 to dreg if divisor is 1 __ mov(dreg, zr); diff --git a/src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp b/src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp index eecc18d2b3e..312002e851a 100644 --- a/src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp @@ -37,6 +37,7 @@ #include "ci/ciTypeArrayKlass.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_aarch64.inline.hpp" #ifdef ASSERT @@ -447,7 +448,7 @@ void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) { // no need to do div-by-zero check if the divisor is a non-zero constant if (c != 0) need_zero_check = false; // do not load right if the divisor is a power-of-2 constant - if (c > 0 && is_power_of_2_long(c)) { + if (c > 0 && is_power_of_2(c)) { right.dont_load_item(); } else { right.load_item(); diff --git a/src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp b/src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp index 99883ddf32d..bc49f84985a 100644 --- a/src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp @@ -43,6 +43,7 @@ #include "runtime/signature.hpp" #include "runtime/vframe.hpp" #include "runtime/vframeArray.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_aarch64.inline.hpp" diff --git a/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp b/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp index 1a9df423ade..4891be542fb 100644 --- a/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp @@ -43,7 +43,7 @@ #include "runtime/safepointMechanism.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/thread.inline.hpp" - +#include "utilities/powerOfTwo.hpp" void InterpreterMacroAssembler::narrow(Register result) { diff --git a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp index a63fcfc891a..c8d3dde8c16 100644 --- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp @@ -47,6 +47,7 @@ #include "runtime/jniHandles.inline.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/thread.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef COMPILER1 #include "c1/c1_LIRAssembler.hpp" #endif diff --git a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp index 34973d49f75..2168a8c835c 100644 --- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp +++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp @@ -28,6 +28,7 @@ #include "asm/assembler.hpp" #include "oops/compressedOops.hpp" +#include "utilities/powerOfTwo.hpp" // MacroAssembler extends Assembler by frequently used macros. // diff --git a/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp b/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp index 973a0a7eb68..48aa12c2c79 100644 --- a/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp @@ -43,6 +43,7 @@ #include "runtime/stubRoutines.hpp" #include "runtime/thread.inline.hpp" #include "utilities/align.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef COMPILER2 #include "opto/runtime.hpp" #endif diff --git a/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp b/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp index 0f68771dcb3..d31cd5f0994 100644 --- a/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp @@ -49,6 +49,7 @@ #include "runtime/timer.hpp" #include "runtime/vframeArray.hpp" #include "utilities/debug.hpp" +#include "utilities/powerOfTwo.hpp" #include #ifndef PRODUCT diff --git a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp index f09ccc6a40a..a8ba062f932 100644 --- a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp @@ -40,6 +40,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "runtime/synchronizer.hpp" +#include "utilities/powerOfTwo.hpp" #define __ _masm-> diff --git a/src/hotspot/cpu/arm/c1_LIRAssembler_arm.cpp b/src/hotspot/cpu/arm/c1_LIRAssembler_arm.cpp index 9ab3f64c6b0..ebf81d4ba0c 100644 --- a/src/hotspot/cpu/arm/c1_LIRAssembler_arm.cpp +++ b/src/hotspot/cpu/arm/c1_LIRAssembler_arm.cpp @@ -37,6 +37,7 @@ #include "oops/objArrayKlass.hpp" #include "runtime/frame.inline.hpp" #include "runtime/sharedRuntime.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_arm.inline.hpp" #define __ _masm-> diff --git a/src/hotspot/cpu/arm/c1_LIRGenerator_arm.cpp b/src/hotspot/cpu/arm/c1_LIRGenerator_arm.cpp index 7cf2ff055b5..4dc1f81c63e 100644 --- a/src/hotspot/cpu/arm/c1_LIRGenerator_arm.cpp +++ b/src/hotspot/cpu/arm/c1_LIRGenerator_arm.cpp @@ -40,6 +40,7 @@ #include "gc/shared/cardTableBarrierSet.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_arm.inline.hpp" #ifdef ASSERT diff --git a/src/hotspot/cpu/arm/c1_MacroAssembler_arm.cpp b/src/hotspot/cpu/arm/c1_MacroAssembler_arm.cpp index 6c4c3ad408f..dd82f993338 100644 --- a/src/hotspot/cpu/arm/c1_MacroAssembler_arm.cpp +++ b/src/hotspot/cpu/arm/c1_MacroAssembler_arm.cpp @@ -35,6 +35,7 @@ #include "runtime/os.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" +#include "utilities/powerOfTwo.hpp" // Note: Rtemp usage is this file should not impact C2 and should be // correct as long as it is not implicitly used in lower layers (the diff --git a/src/hotspot/cpu/arm/interp_masm_arm.cpp b/src/hotspot/cpu/arm/interp_masm_arm.cpp index 60ddb874630..f3417f17ee2 100644 --- a/src/hotspot/cpu/arm/interp_masm_arm.cpp +++ b/src/hotspot/cpu/arm/interp_masm_arm.cpp @@ -44,6 +44,7 @@ #include "runtime/frame.inline.hpp" #include "runtime/safepointMechanism.hpp" #include "runtime/sharedRuntime.hpp" +#include "utilities/powerOfTwo.hpp" //-------------------------------------------------------------------- // Implementation of InterpreterMacroAssembler diff --git a/src/hotspot/cpu/arm/macroAssembler_arm.cpp b/src/hotspot/cpu/arm/macroAssembler_arm.cpp index f02d5a50f55..6418cafd58a 100644 --- a/src/hotspot/cpu/arm/macroAssembler_arm.cpp +++ b/src/hotspot/cpu/arm/macroAssembler_arm.cpp @@ -46,6 +46,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" // Implementation of AddressLiteral diff --git a/src/hotspot/cpu/arm/macroAssembler_arm.hpp b/src/hotspot/cpu/arm/macroAssembler_arm.hpp index b647e548ca5..14bdfaf6d94 100644 --- a/src/hotspot/cpu/arm/macroAssembler_arm.hpp +++ b/src/hotspot/cpu/arm/macroAssembler_arm.hpp @@ -26,6 +26,7 @@ #define CPU_ARM_MACROASSEMBLER_ARM_HPP #include "code/relocInfo.hpp" +#include "utilities/powerOfTwo.hpp" class BiasedLockingCounters; diff --git a/src/hotspot/cpu/arm/sharedRuntime_arm.cpp b/src/hotspot/cpu/arm/sharedRuntime_arm.cpp index ae3d223b989..47f750a8ff5 100644 --- a/src/hotspot/cpu/arm/sharedRuntime_arm.cpp +++ b/src/hotspot/cpu/arm/sharedRuntime_arm.cpp @@ -37,6 +37,7 @@ #include "runtime/safepointMechanism.hpp" #include "runtime/vframeArray.hpp" #include "utilities/align.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_arm.inline.hpp" #ifdef COMPILER1 #include "c1/c1_Runtime1.hpp" diff --git a/src/hotspot/cpu/arm/stubGenerator_arm.cpp b/src/hotspot/cpu/arm/stubGenerator_arm.cpp index e04eff772b9..fd82a6d20bb 100644 --- a/src/hotspot/cpu/arm/stubGenerator_arm.cpp +++ b/src/hotspot/cpu/arm/stubGenerator_arm.cpp @@ -41,6 +41,7 @@ #include "runtime/stubCodeGenerator.hpp" #include "runtime/stubRoutines.hpp" #include "utilities/align.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef COMPILER2 #include "opto/runtime.hpp" #endif diff --git a/src/hotspot/cpu/arm/templateTable_arm.cpp b/src/hotspot/cpu/arm/templateTable_arm.cpp index 60dbabb6944..28eb576fc4d 100644 --- a/src/hotspot/cpu/arm/templateTable_arm.cpp +++ b/src/hotspot/cpu/arm/templateTable_arm.cpp @@ -39,6 +39,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "runtime/synchronizer.hpp" +#include "utilities/powerOfTwo.hpp" #define __ _masm-> diff --git a/src/hotspot/cpu/ppc/assembler_ppc.cpp b/src/hotspot/cpu/ppc/assembler_ppc.cpp index b646371b6d6..bee11245f5d 100644 --- a/src/hotspot/cpu/ppc/assembler_ppc.cpp +++ b/src/hotspot/cpu/ppc/assembler_ppc.cpp @@ -37,6 +37,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef PRODUCT #define BLOCK_COMMENT(str) // nothing @@ -78,13 +79,13 @@ int Assembler::branch_destination(int inst, int pos) { // Low-level andi-one-instruction-macro. void Assembler::andi(Register a, Register s, const long ui16) { - if (is_power_of_2_long(((jlong) ui16)+1)) { + if (is_power_of_2(((jlong) ui16)+1)) { // pow2minus1 - clrldi(a, s, 64-log2_long((((jlong) ui16)+1))); - } else if (is_power_of_2_long((jlong) ui16)) { + clrldi(a, s, 64-log2((((jlong) ui16)+1))); + } else if (is_power_of_2((jlong) ui16)) { // pow2 rlwinm(a, s, 0, 31-log2_long((jlong) ui16), 31-log2_long((jlong) ui16)); - } else if (is_power_of_2_long((jlong)-ui16)) { + } else if (is_power_of_2((jlong)-ui16)) { // negpow2 clrrdi(a, s, log2_long((jlong)-ui16)); } else { diff --git a/src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp b/src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp index 8d195243535..346f79bcef1 100644 --- a/src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp +++ b/src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp @@ -40,6 +40,7 @@ #include "runtime/frame.inline.hpp" #include "runtime/safepointMechanism.inline.hpp" #include "runtime/sharedRuntime.hpp" +#include "utilities/powerOfTwo.hpp" #define __ _masm-> @@ -1762,7 +1763,7 @@ void LIR_Assembler::logic_op(LIR_Code code, LIR_Opr left, LIR_Opr right, LIR_Opr switch (code) { case lir_logic_and: - if (uimmss != 0 || (uimms != 0 && (uimm & 0xFFFF) != 0) || is_power_of_2_long(uimm)) { + if (uimmss != 0 || (uimms != 0 && (uimm & 0xFFFF) != 0) || is_power_of_2(uimm)) { __ andi(d, l, uimm); // special cases } else if (uimms != 0) { __ andis_(d, l, uimms); } else { __ andi_(d, l, uimm); } diff --git a/src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp b/src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp index 88ef0cd9878..9c15fbccfbd 100644 --- a/src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp +++ b/src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp @@ -37,6 +37,7 @@ #include "ci/ciTypeArrayKlass.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_ppc.inline.hpp" #ifdef ASSERT @@ -574,13 +575,13 @@ inline bool can_handle_logic_op_as_uimm(ValueType *type, Bytecodes::Code bc) { // see Assembler::andi if (bc == Bytecodes::_iand && - (is_power_of_2_long(int_or_long_const+1) || - is_power_of_2_long(int_or_long_const) || - is_power_of_2_long(-int_or_long_const))) return true; + (is_power_of_2(int_or_long_const+1) || + is_power_of_2(int_or_long_const) || + is_power_of_2(-int_or_long_const))) return true; if (bc == Bytecodes::_land && - (is_power_of_2_long(int_or_long_const+1) || - (Assembler::is_uimm(int_or_long_const, 32) && is_power_of_2_long(int_or_long_const)) || - (int_or_long_const != min_jlong && is_power_of_2_long(-int_or_long_const)))) return true; + (is_power_of_2(int_or_long_const+1) || + (Assembler::is_uimm(int_or_long_const, 32) && is_power_of_2(int_or_long_const)) || + (int_or_long_const != min_jlong && is_power_of_2(-int_or_long_const)))) return true; // special case: xor -1 if ((bc == Bytecodes::_ixor || bc == Bytecodes::_lxor) && diff --git a/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp b/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp index 28ee116eb31..4fd6a35642f 100644 --- a/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp +++ b/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp @@ -38,7 +38,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "utilities/align.hpp" - +#include "utilities/powerOfTwo.hpp" void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) { const Register temp_reg = R12_scratch2; diff --git a/src/hotspot/cpu/ppc/c1_Runtime1_ppc.cpp b/src/hotspot/cpu/ppc/c1_Runtime1_ppc.cpp index 925b5d8d206..37f4566b34a 100644 --- a/src/hotspot/cpu/ppc/c1_Runtime1_ppc.cpp +++ b/src/hotspot/cpu/ppc/c1_Runtime1_ppc.cpp @@ -42,6 +42,7 @@ #include "runtime/vframeArray.hpp" #include "utilities/align.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_ppc.inline.hpp" // Implementation of StubAssembler diff --git a/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp b/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp index 1fbcf9c32fb..ab14c5beb16 100644 --- a/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp +++ b/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp @@ -34,6 +34,7 @@ #include "runtime/frame.inline.hpp" #include "runtime/safepointMechanism.hpp" #include "runtime/sharedRuntime.hpp" +#include "utilities/powerOfTwo.hpp" // Implementation of InterpreterMacroAssembler. diff --git a/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp b/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp index b6c4dbf2490..d7796d36e1e 100644 --- a/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp +++ b/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp @@ -44,6 +44,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef COMPILER2 #include "opto/intrinsicnode.hpp" #endif diff --git a/src/hotspot/cpu/ppc/macroAssembler_ppc.inline.hpp b/src/hotspot/cpu/ppc/macroAssembler_ppc.inline.hpp index 6ac8491aa2e..28f3210b5b7 100644 --- a/src/hotspot/cpu/ppc/macroAssembler_ppc.inline.hpp +++ b/src/hotspot/cpu/ppc/macroAssembler_ppc.inline.hpp @@ -35,6 +35,7 @@ #include "oops/accessDecorators.hpp" #include "oops/compressedOops.hpp" #include "runtime/safepointMechanism.hpp" +#include "utilities/powerOfTwo.hpp" inline bool MacroAssembler::is_ld_largeoffset(address a) { const int inst1 = *(int *)a; @@ -56,7 +57,7 @@ inline int MacroAssembler::get_ld_largeoffset_offset(address a) { } inline void MacroAssembler::round_to(Register r, int modulus) { - assert(is_power_of_2_long((jlong)modulus), "must be power of 2"); + assert(is_power_of_2((jlong)modulus), "must be power of 2"); addi(r, r, modulus-1); clrrdi(r, r, log2_long((jlong)modulus)); } diff --git a/src/hotspot/cpu/ppc/ppc.ad b/src/hotspot/cpu/ppc/ppc.ad index b1557b3f3a7..34cb0f8947e 100644 --- a/src/hotspot/cpu/ppc/ppc.ad +++ b/src/hotspot/cpu/ppc/ppc.ad @@ -4350,7 +4350,7 @@ operand immIhi16() %{ %} operand immInegpow2() %{ - predicate(is_power_of_2_long((jlong) (julong) (juint) (-(n->get_int())))); + predicate(is_power_of_2((jlong) (julong) (juint) (-(n->get_int())))); match(ConI); op_cost(0); format %{ %} @@ -4358,7 +4358,7 @@ operand immInegpow2() %{ %} operand immIpow2minus1() %{ - predicate(is_power_of_2_long((((jlong) (n->get_int()))+1))); + predicate(is_power_of_2((((jlong) (n->get_int()))+1))); match(ConI); op_cost(0); format %{ %} @@ -4366,7 +4366,7 @@ operand immIpow2minus1() %{ %} operand immIpowerOf2() %{ - predicate(is_power_of_2_long((((jlong) (julong) (juint) (n->get_int()))))); + predicate(is_power_of_2((((jlong) (julong) (juint) (n->get_int()))))); match(ConI); op_cost(0); format %{ %} @@ -4600,7 +4600,7 @@ operand immLhighest16() %{ %} operand immLnegpow2() %{ - predicate(is_power_of_2_long((jlong)-(n->get_long()))); + predicate(is_power_of_2((jlong)-(n->get_long()))); match(ConL); op_cost(0); format %{ %} @@ -4608,7 +4608,7 @@ operand immLnegpow2() %{ %} operand immLpow2minus1() %{ - predicate(is_power_of_2_long((((jlong) (n->get_long()))+1)) && + predicate(is_power_of_2((((jlong) (n->get_long()))+1)) && (n->get_long() != (jlong)0xffffffffffffffffL)); match(ConL); op_cost(0); diff --git a/src/hotspot/cpu/ppc/stubGenerator_ppc.cpp b/src/hotspot/cpu/ppc/stubGenerator_ppc.cpp index 3cf4d7fe193..071ee8ce7fd 100644 --- a/src/hotspot/cpu/ppc/stubGenerator_ppc.cpp +++ b/src/hotspot/cpu/ppc/stubGenerator_ppc.cpp @@ -41,6 +41,7 @@ #include "runtime/stubRoutines.hpp" #include "runtime/thread.inline.hpp" #include "utilities/align.hpp" +#include "utilities/powerOfTwo.hpp" // Declaration and definition of StubGenerator (no .hpp file). // For a more detailed description of the stub routine structure diff --git a/src/hotspot/cpu/ppc/templateTable_ppc_64.cpp b/src/hotspot/cpu/ppc/templateTable_ppc_64.cpp index c6e13a93762..b7bd9d27d20 100644 --- a/src/hotspot/cpu/ppc/templateTable_ppc_64.cpp +++ b/src/hotspot/cpu/ppc/templateTable_ppc_64.cpp @@ -42,6 +42,7 @@ #include "runtime/stubRoutines.hpp" #include "runtime/synchronizer.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #undef __ #define __ _masm-> diff --git a/src/hotspot/cpu/ppc/vm_version_ppc.cpp b/src/hotspot/cpu/ppc/vm_version_ppc.cpp index 1b98ca46e6c..679aa09f738 100644 --- a/src/hotspot/cpu/ppc/vm_version_ppc.cpp +++ b/src/hotspot/cpu/ppc/vm_version_ppc.cpp @@ -36,6 +36,7 @@ #include "utilities/align.hpp" #include "utilities/defaultStream.hpp" #include "utilities/globalDefinitions.hpp" +#include "utilities/powerOfTwo.hpp" #include #if defined(_AIX) diff --git a/src/hotspot/cpu/s390/c1_LIRAssembler_s390.cpp b/src/hotspot/cpu/s390/c1_LIRAssembler_s390.cpp index 0ef75ab1436..d68e27f8b21 100644 --- a/src/hotspot/cpu/s390/c1_LIRAssembler_s390.cpp +++ b/src/hotspot/cpu/s390/c1_LIRAssembler_s390.cpp @@ -39,6 +39,7 @@ #include "runtime/frame.inline.hpp" #include "runtime/safepointMechanism.inline.hpp" #include "runtime/sharedRuntime.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_s390.inline.hpp" #define __ _masm-> @@ -1798,7 +1799,7 @@ void LIR_Assembler::arithmetic_idiv(LIR_Code code, LIR_Opr left, LIR_Opr right, if (left->is_double_cpu()) { // 64 bit integer case assert(left->is_double_cpu(), "left must be register"); - assert(right->is_double_cpu() || is_power_of_2_long(right->as_jlong()), + assert(right->is_double_cpu() || is_power_of_2(right->as_jlong()), "right must be register or power of 2 constant"); assert(result->is_double_cpu(), "result must be register"); diff --git a/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp b/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp index f3e3e3a9f65..8ff4b3a5152 100644 --- a/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp +++ b/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp @@ -37,6 +37,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "vmreg_s390.inline.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef ASSERT #define __ gen()->lir(__FILE__, __LINE__)-> diff --git a/src/hotspot/cpu/s390/c1_Runtime1_s390.cpp b/src/hotspot/cpu/s390/c1_Runtime1_s390.cpp index e7526d17c6d..42914737e29 100644 --- a/src/hotspot/cpu/s390/c1_Runtime1_s390.cpp +++ b/src/hotspot/cpu/s390/c1_Runtime1_s390.cpp @@ -38,12 +38,13 @@ #include "oops/oop.inline.hpp" #include "prims/jvmtiExport.hpp" #include "register_s390.hpp" +#include "registerSaver_s390.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/signature.hpp" #include "runtime/vframeArray.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_s390.inline.hpp" -#include "registerSaver_s390.hpp" // Implementation of StubAssembler diff --git a/src/hotspot/cpu/s390/interp_masm_s390.cpp b/src/hotspot/cpu/s390/interp_masm_s390.cpp index cbee39e3eae..7d085e6b59b 100644 --- a/src/hotspot/cpu/s390/interp_masm_s390.cpp +++ b/src/hotspot/cpu/s390/interp_masm_s390.cpp @@ -42,6 +42,7 @@ #include "runtime/safepointMechanism.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/thread.inline.hpp" +#include "utilities/powerOfTwo.hpp" // Implementation of InterpreterMacroAssembler. // This file specializes the assembler with interpreter-specific macros. diff --git a/src/hotspot/cpu/s390/macroAssembler_s390.cpp b/src/hotspot/cpu/s390/macroAssembler_s390.cpp index e774e0a9748..4abc0d3efed 100644 --- a/src/hotspot/cpu/s390/macroAssembler_s390.cpp +++ b/src/hotspot/cpu/s390/macroAssembler_s390.cpp @@ -55,6 +55,7 @@ #include "runtime/stubRoutines.hpp" #include "utilities/events.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #include diff --git a/src/hotspot/cpu/s390/stubGenerator_s390.cpp b/src/hotspot/cpu/s390/stubGenerator_s390.cpp index 4a2e28b9569..f5540d41fe2 100644 --- a/src/hotspot/cpu/s390/stubGenerator_s390.cpp +++ b/src/hotspot/cpu/s390/stubGenerator_s390.cpp @@ -42,6 +42,7 @@ #include "runtime/stubCodeGenerator.hpp" #include "runtime/stubRoutines.hpp" #include "runtime/thread.inline.hpp" +#include "utilities/powerOfTwo.hpp" // Declaration and definition of StubGenerator (no .hpp file). // For a more detailed description of the stub routine structure diff --git a/src/hotspot/cpu/s390/templateTable_s390.cpp b/src/hotspot/cpu/s390/templateTable_s390.cpp index fc127e7afd5..79ca843447d 100644 --- a/src/hotspot/cpu/s390/templateTable_s390.cpp +++ b/src/hotspot/cpu/s390/templateTable_s390.cpp @@ -39,6 +39,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "runtime/synchronizer.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef PRODUCT #define __ _masm-> diff --git a/src/hotspot/cpu/sparc/c1_LIRAssembler_sparc.cpp b/src/hotspot/cpu/sparc/c1_LIRAssembler_sparc.cpp index 73f05246dab..4faa45fdc72 100644 --- a/src/hotspot/cpu/sparc/c1_LIRAssembler_sparc.cpp +++ b/src/hotspot/cpu/sparc/c1_LIRAssembler_sparc.cpp @@ -40,6 +40,7 @@ #include "runtime/jniHandles.inline.hpp" #include "runtime/safepointMechanism.inline.hpp" #include "runtime/sharedRuntime.hpp" +#include "utilities/powerOfTwo.hpp" #define __ _masm-> diff --git a/src/hotspot/cpu/sparc/c1_LIRGenerator_sparc.cpp b/src/hotspot/cpu/sparc/c1_LIRGenerator_sparc.cpp index 618220b8296..403f7cc5e52 100644 --- a/src/hotspot/cpu/sparc/c1_LIRGenerator_sparc.cpp +++ b/src/hotspot/cpu/sparc/c1_LIRGenerator_sparc.cpp @@ -37,6 +37,7 @@ #include "runtime/safepointMechanism.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_sparc.inline.hpp" #ifdef ASSERT diff --git a/src/hotspot/cpu/sparc/interp_masm_sparc.cpp b/src/hotspot/cpu/sparc/interp_masm_sparc.cpp index 21b69206a87..a8dd0bb6600 100644 --- a/src/hotspot/cpu/sparc/interp_masm_sparc.cpp +++ b/src/hotspot/cpu/sparc/interp_masm_sparc.cpp @@ -42,6 +42,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/thread.inline.hpp" #include "utilities/align.hpp" +#include "utilities/powerOfTwo.hpp" // Implementation of InterpreterMacroAssembler diff --git a/src/hotspot/cpu/sparc/macroAssembler_sparc.cpp b/src/hotspot/cpu/sparc/macroAssembler_sparc.cpp index 8c9e8703558..3f77ca85720 100644 --- a/src/hotspot/cpu/sparc/macroAssembler_sparc.cpp +++ b/src/hotspot/cpu/sparc/macroAssembler_sparc.cpp @@ -48,6 +48,7 @@ #include "runtime/stubRoutines.hpp" #include "utilities/align.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef COMPILER2 #include "opto/intrinsicnode.hpp" #endif diff --git a/src/hotspot/cpu/x86/assembler_x86.hpp b/src/hotspot/cpu/x86/assembler_x86.hpp index b2934299530..2781a0fa963 100644 --- a/src/hotspot/cpu/x86/assembler_x86.hpp +++ b/src/hotspot/cpu/x86/assembler_x86.hpp @@ -27,6 +27,7 @@ #include "asm/register.hpp" #include "runtime/vm_version.hpp" +#include "utilities/powerOfTwo.hpp" class BiasedLockingCounters; diff --git a/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp b/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp index b99d7431102..868a3f5d019 100644 --- a/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp @@ -38,6 +38,7 @@ #include "runtime/frame.inline.hpp" #include "runtime/safepointMechanism.hpp" #include "runtime/sharedRuntime.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_x86.inline.hpp" diff --git a/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp b/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp index cf736d5a6fb..bcb2afbf800 100644 --- a/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp +++ b/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp @@ -36,6 +36,7 @@ #include "gc/shared/c1/barrierSetC1.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" +#include "utilities/powerOfTwo.hpp" #include "vmreg_x86.inline.hpp" #ifdef ASSERT diff --git a/src/hotspot/cpu/x86/interp_masm_x86.cpp b/src/hotspot/cpu/x86/interp_masm_x86.cpp index 4ed93169c76..da3e8828596 100644 --- a/src/hotspot/cpu/x86/interp_masm_x86.cpp +++ b/src/hotspot/cpu/x86/interp_masm_x86.cpp @@ -39,6 +39,7 @@ #include "runtime/safepointMechanism.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/thread.inline.hpp" +#include "utilities/powerOfTwo.hpp" // Implementation of InterpreterMacroAssembler diff --git a/src/hotspot/cpu/x86/vm_version_x86.cpp b/src/hotspot/cpu/x86/vm_version_x86.cpp index 3edda88244f..8a17f4ddb54 100644 --- a/src/hotspot/cpu/x86/vm_version_x86.cpp +++ b/src/hotspot/cpu/x86/vm_version_x86.cpp @@ -33,6 +33,7 @@ #include "runtime/os.hpp" #include "runtime/stubCodeGenerator.hpp" #include "runtime/vm_version.hpp" +#include "utilities/powerOfTwo.hpp" #include "utilities/virtualizationSupport.hpp" #include OS_HEADER_INLINE(os) diff --git a/src/hotspot/cpu/x86/x86_64.ad b/src/hotspot/cpu/x86/x86_64.ad index cacda490ccd..9c286576893 100644 --- a/src/hotspot/cpu/x86/x86_64.ad +++ b/src/hotspot/cpu/x86/x86_64.ad @@ -3120,7 +3120,7 @@ operand immL32() operand immL_Pow2() %{ - predicate(is_power_of_2_long(n->get_long())); + predicate(is_power_of_2(n->get_long())); match(ConL); op_cost(15); @@ -3130,7 +3130,7 @@ operand immL_Pow2() operand immL_NotPow2() %{ - predicate(is_power_of_2_long(~n->get_long())); + predicate(is_power_of_2(~n->get_long())); match(ConL); op_cost(15); diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 14e65e16509..b1577aff0c2 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -74,6 +74,7 @@ #include "utilities/elfFile.hpp" #include "utilities/growableArray.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #include "utilities/vmError.hpp" // put OS-includes here diff --git a/src/hotspot/share/adlc/main.cpp b/src/hotspot/share/adlc/main.cpp index 1423cb38dc9..be04e91a84a 100644 --- a/src/hotspot/share/adlc/main.cpp +++ b/src/hotspot/share/adlc/main.cpp @@ -233,6 +233,7 @@ int main(int argc, char *argv[]) AD.addInclude(AD._CPP_file, "runtime/sharedRuntime.hpp"); AD.addInclude(AD._CPP_file, "runtime/stubRoutines.hpp"); AD.addInclude(AD._CPP_file, "utilities/growableArray.hpp"); + AD.addInclude(AD._CPP_file, "utilities/powerOfTwo.hpp"); AD.addInclude(AD._HPP_file, "memory/allocation.hpp"); AD.addInclude(AD._HPP_file, "oops/compressedOops.hpp"); AD.addInclude(AD._HPP_file, "code/nativeInst.hpp"); @@ -268,6 +269,8 @@ int main(int argc, char *argv[]) AD.addInclude(AD._DFA_file, "opto/narrowptrnode.hpp"); AD.addInclude(AD._DFA_file, "opto/opcodes.hpp"); AD.addInclude(AD._DFA_file, "opto/convertnode.hpp"); + AD.addInclude(AD._DFA_file, "utilities/powerOfTwo.hpp"); + // Make sure each .cpp file starts with include lines: // files declaring and defining generators for Mach* Objects (hpp,cpp) // Generate the result files: diff --git a/src/hotspot/share/aot/aotCodeHeap.cpp b/src/hotspot/share/aot/aotCodeHeap.cpp index 7aec0a29e46..970f373ebca 100644 --- a/src/hotspot/share/aot/aotCodeHeap.cpp +++ b/src/hotspot/share/aot/aotCodeHeap.cpp @@ -47,6 +47,7 @@ #include "runtime/safepointVerifiers.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/vmOperations.hpp" +#include "utilities/powerOfTwo.hpp" #include "utilities/sizes.hpp" bool AOTLib::_narrow_oop_shift_initialized = false; diff --git a/src/hotspot/share/asm/codeBuffer.cpp b/src/hotspot/share/asm/codeBuffer.cpp index 1f494843af7..558dee23ecc 100644 --- a/src/hotspot/share/asm/codeBuffer.cpp +++ b/src/hotspot/share/asm/codeBuffer.cpp @@ -32,6 +32,7 @@ #include "runtime/safepointVerifiers.hpp" #include "utilities/align.hpp" #include "utilities/copy.hpp" +#include "utilities/powerOfTwo.hpp" #include "utilities/xmlstream.hpp" // The structure of a CodeSection: diff --git a/src/hotspot/share/c1/c1_GraphBuilder.cpp b/src/hotspot/share/c1/c1_GraphBuilder.cpp index 2e45bdca9e8..fd970d2ea9f 100644 --- a/src/hotspot/share/c1/c1_GraphBuilder.cpp +++ b/src/hotspot/share/c1/c1_GraphBuilder.cpp @@ -42,6 +42,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/vm_version.hpp" #include "utilities/bitMap.inline.hpp" +#include "utilities/powerOfTwo.hpp" class BlockListBuilder { private: diff --git a/src/hotspot/share/c1/c1_LIRGenerator.cpp b/src/hotspot/share/c1/c1_LIRGenerator.cpp index aea0565a77e..260895e998d 100644 --- a/src/hotspot/share/c1/c1_LIRGenerator.cpp +++ b/src/hotspot/share/c1/c1_LIRGenerator.cpp @@ -43,6 +43,7 @@ #include "runtime/vm_version.hpp" #include "utilities/bitMap.inline.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef ASSERT #define __ gen()->lir(__FILE__, __LINE__)-> diff --git a/src/hotspot/share/ci/ciArray.cpp b/src/hotspot/share/ci/ciArray.cpp index e7c6dd62890..6db31f4cb88 100644 --- a/src/hotspot/share/ci/ciArray.cpp +++ b/src/hotspot/share/ci/ciArray.cpp @@ -31,6 +31,7 @@ #include "oops/objArrayOop.inline.hpp" #include "oops/oop.inline.hpp" #include "oops/typeArrayOop.inline.hpp" +#include "utilities/powerOfTwo.hpp" // ciArray // diff --git a/src/hotspot/share/code/codeHeapState.cpp b/src/hotspot/share/code/codeHeapState.cpp index ca5c439fcde..19d336a661a 100644 --- a/src/hotspot/share/code/codeHeapState.cpp +++ b/src/hotspot/share/code/codeHeapState.cpp @@ -27,6 +27,7 @@ #include "code/codeHeapState.hpp" #include "compiler/compileBroker.hpp" #include "runtime/sweeper.hpp" +#include "utilities/powerOfTwo.hpp" // ------------------------- // | General Description | diff --git a/src/hotspot/share/code/vtableStubs.cpp b/src/hotspot/share/code/vtableStubs.cpp index b1bf9e8e5df..08914882dc3 100644 --- a/src/hotspot/share/code/vtableStubs.cpp +++ b/src/hotspot/share/code/vtableStubs.cpp @@ -38,6 +38,7 @@ #include "runtime/mutexLocker.hpp" #include "runtime/sharedRuntime.hpp" #include "utilities/align.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef COMPILER2 #include "opto/matcher.hpp" #endif @@ -128,7 +129,7 @@ void VtableStubs::initialize() { { MutexLocker ml(VtableStubs_lock, Mutex::_no_safepoint_check_flag); assert(_number_of_vtable_stubs == 0, "potential performance bug: VtableStubs initialized more than once"); - assert(is_power_of_2(N), "N must be a power of 2"); + assert(is_power_of_2(int(N)), "N must be a power of 2"); for (int i = 0; i < N; i++) { _table[i] = NULL; } diff --git a/src/hotspot/share/gc/g1/g1BiasedArray.hpp b/src/hotspot/share/gc/g1/g1BiasedArray.hpp index e669a139fab..1e98033a2db 100644 --- a/src/hotspot/share/gc/g1/g1BiasedArray.hpp +++ b/src/hotspot/share/gc/g1/g1BiasedArray.hpp @@ -27,6 +27,7 @@ #include "memory/memRegion.hpp" #include "utilities/debug.hpp" +#include "utilities/powerOfTwo.hpp" // Implements the common base functionality for arrays that contain provisions // for accessing its elements using a biased index. diff --git a/src/hotspot/share/gc/g1/g1RegionMarkStatsCache.cpp b/src/hotspot/share/gc/g1/g1RegionMarkStatsCache.cpp index d436efa51b5..f5ff7b404ac 100644 --- a/src/hotspot/share/gc/g1/g1RegionMarkStatsCache.cpp +++ b/src/hotspot/share/gc/g1/g1RegionMarkStatsCache.cpp @@ -25,6 +25,7 @@ #include "precompiled.hpp" #include "gc/g1/g1RegionMarkStatsCache.inline.hpp" #include "memory/allocation.inline.hpp" +#include "utilities/powerOfTwo.hpp" G1RegionMarkStatsCache::G1RegionMarkStatsCache(G1RegionMarkStats* target, uint max_regions, uint num_cache_entries) : _target(target), diff --git a/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp b/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp index b187f90ac75..cef4c9b1ab3 100644 --- a/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp +++ b/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp @@ -35,6 +35,7 @@ #include "utilities/align.hpp" #include "utilities/bitMap.inline.hpp" #include "utilities/formatBuffer.hpp" +#include "utilities/powerOfTwo.hpp" G1RegionToSpaceMapper::G1RegionToSpaceMapper(ReservedSpace rs, size_t used_size, diff --git a/src/hotspot/share/gc/parallel/parallelArguments.cpp b/src/hotspot/share/gc/parallel/parallelArguments.cpp index 30216323ffd..23dcbe52d08 100644 --- a/src/hotspot/share/gc/parallel/parallelArguments.cpp +++ b/src/hotspot/share/gc/parallel/parallelArguments.cpp @@ -35,6 +35,7 @@ #include "runtime/globals_extension.hpp" #include "runtime/java.hpp" #include "utilities/defaultStream.hpp" +#include "utilities/powerOfTwo.hpp" static const double MaxRamFractionForYoung = 0.8; diff --git a/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp b/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp index 35fc39e287a..af3c8832f9b 100644 --- a/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp +++ b/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp @@ -36,6 +36,7 @@ #include "runtime/thread.inline.hpp" #include "utilities/align.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #if INCLUDE_G1GC #include "gc/g1/jvmFlagConstraintsG1.hpp" #endif diff --git a/src/hotspot/share/gc/shared/oopStorage.cpp b/src/hotspot/share/gc/shared/oopStorage.cpp index 71aff618080..416afce7034 100644 --- a/src/hotspot/share/gc/shared/oopStorage.cpp +++ b/src/hotspot/share/gc/shared/oopStorage.cpp @@ -45,6 +45,7 @@ #include "utilities/globalDefinitions.hpp" #include "utilities/macros.hpp" #include "utilities/ostream.hpp" +#include "utilities/powerOfTwo.hpp" OopStorage::AllocationListEntry::AllocationListEntry() : _prev(NULL), _next(NULL) {} diff --git a/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp b/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp index ee7e8efc9a4..27fe53f6868 100644 --- a/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp +++ b/src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp @@ -38,6 +38,7 @@ #include "runtime/atomic.hpp" #include "runtime/mutexLocker.hpp" #include "runtime/safepointVerifiers.hpp" +#include "utilities/powerOfTwo.hpp" // // List of deduplication table entries. Links table diff --git a/src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp b/src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp index 84e57c167b2..d5a06d1d0bc 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp @@ -34,6 +34,7 @@ #include "memory/resourceArea.hpp" #include "memory/universe.hpp" #include "runtime/atomic.hpp" +#include "utilities/powerOfTwo.hpp" ShenandoahParallelCodeCacheIterator::ShenandoahParallelCodeCacheIterator(const GrowableArray* heaps) { _length = heaps->length(); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp index efe06b2f594..173f983ac59 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp @@ -80,6 +80,7 @@ #include "runtime/safepointMechanism.hpp" #include "runtime/vmThread.hpp" #include "services/mallocTracker.hpp" +#include "utilities/powerOfTwo.hpp" #ifdef ASSERT template diff --git a/src/hotspot/share/gc/z/zAddress.inline.hpp b/src/hotspot/share/gc/z/zAddress.inline.hpp index 06a0e71a110..a752c91088b 100644 --- a/src/hotspot/share/gc/z/zAddress.inline.hpp +++ b/src/hotspot/share/gc/z/zAddress.inline.hpp @@ -28,6 +28,7 @@ #include "gc/z/zGlobals.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" inline bool ZAddress::is_null(uintptr_t value) { return value == 0; diff --git a/src/hotspot/share/gc/z/zLiveMap.cpp b/src/hotspot/share/gc/z/zLiveMap.cpp index b3357d1edb3..7e04b7e8c37 100644 --- a/src/hotspot/share/gc/z/zLiveMap.cpp +++ b/src/hotspot/share/gc/z/zLiveMap.cpp @@ -29,6 +29,7 @@ #include "logging/log.hpp" #include "runtime/atomic.hpp" #include "utilities/debug.hpp" +#include "utilities/powerOfTwo.hpp" static const ZStatCounter ZCounterMarkSeqNumResetContention("Contention", "Mark SeqNum Reset Contention", ZStatUnitOpsPerSecond); static const ZStatCounter ZCounterMarkSegmentResetContention("Contention", "Mark Segment Reset Contention", ZStatUnitOpsPerSecond); diff --git a/src/hotspot/share/gc/z/zMarkCache.cpp b/src/hotspot/share/gc/z/zMarkCache.cpp index 91601ff8ad2..e41e3f3c3f4 100644 --- a/src/hotspot/share/gc/z/zMarkCache.cpp +++ b/src/hotspot/share/gc/z/zMarkCache.cpp @@ -24,6 +24,7 @@ #include "precompiled.hpp" #include "gc/z/zMarkCache.inline.hpp" #include "utilities/globalDefinitions.hpp" +#include "utilities/powerOfTwo.hpp" ZMarkCacheEntry::ZMarkCacheEntry() : _page(NULL), diff --git a/src/hotspot/share/gc/z/zMarkStack.cpp b/src/hotspot/share/gc/z/zMarkStack.cpp index 9aacc46bdde..b99c89a119a 100644 --- a/src/hotspot/share/gc/z/zMarkStack.cpp +++ b/src/hotspot/share/gc/z/zMarkStack.cpp @@ -26,6 +26,7 @@ #include "gc/z/zMarkStackAllocator.hpp" #include "logging/log.hpp" #include "utilities/debug.hpp" +#include "utilities/powerOfTwo.hpp" ZMarkStripe::ZMarkStripe() : _published(), diff --git a/src/hotspot/share/gc/z/zNMethodTable.cpp b/src/hotspot/share/gc/z/zNMethodTable.cpp index 258cd8e8f78..2f8ccafa201 100644 --- a/src/hotspot/share/gc/z/zNMethodTable.cpp +++ b/src/hotspot/share/gc/z/zNMethodTable.cpp @@ -43,6 +43,7 @@ #include "memory/iterator.hpp" #include "memory/resourceArea.hpp" #include "utilities/debug.hpp" +#include "utilities/powerOfTwo.hpp" ZNMethodTableEntry* ZNMethodTable::_table = NULL; size_t ZNMethodTable::_size = 0; diff --git a/src/hotspot/share/gc/z/zRelocationSetSelector.cpp b/src/hotspot/share/gc/z/zRelocationSetSelector.cpp index 36b79ae2ece..9aa89d9a65d 100644 --- a/src/hotspot/share/gc/z/zRelocationSetSelector.cpp +++ b/src/hotspot/share/gc/z/zRelocationSetSelector.cpp @@ -29,6 +29,7 @@ #include "logging/log.hpp" #include "runtime/globals.hpp" #include "utilities/debug.hpp" +#include "utilities/powerOfTwo.hpp" ZRelocationSetSelectorGroupStats::ZRelocationSetSelectorGroupStats() : _npages(0), diff --git a/src/hotspot/share/memory/arena.hpp b/src/hotspot/share/memory/arena.hpp index 05266014964..ceec3f2ea69 100644 --- a/src/hotspot/share/memory/arena.hpp +++ b/src/hotspot/share/memory/arena.hpp @@ -28,6 +28,7 @@ #include "memory/allocation.hpp" #include "runtime/globals.hpp" #include "utilities/globalDefinitions.hpp" +#include "utilities/powerOfTwo.hpp" #include diff --git a/src/hotspot/share/memory/heap.cpp b/src/hotspot/share/memory/heap.cpp index 31a6ee6f280..2044c1f0954 100644 --- a/src/hotspot/share/memory/heap.cpp +++ b/src/hotspot/share/memory/heap.cpp @@ -28,6 +28,7 @@ #include "runtime/os.hpp" #include "services/memTracker.hpp" #include "utilities/align.hpp" +#include "utilities/powerOfTwo.hpp" size_t CodeHeap::header_size() { return sizeof(HeapBlock); diff --git a/src/hotspot/share/memory/virtualspace.cpp b/src/hotspot/share/memory/virtualspace.cpp index ebf3efa6824..d8185889513 100644 --- a/src/hotspot/share/memory/virtualspace.cpp +++ b/src/hotspot/share/memory/virtualspace.cpp @@ -32,6 +32,7 @@ #include "runtime/os.inline.hpp" #include "services/memTracker.hpp" #include "utilities/align.hpp" +#include "utilities/powerOfTwo.hpp" // ReservedSpace diff --git a/src/hotspot/share/oops/klass.cpp b/src/hotspot/share/oops/klass.cpp index 62e8a866cb5..5de96b2a6b6 100644 --- a/src/hotspot/share/oops/klass.cpp +++ b/src/hotspot/share/oops/klass.cpp @@ -47,6 +47,7 @@ #include "runtime/atomic.hpp" #include "runtime/handles.inline.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #include "utilities/stack.inline.hpp" void Klass::set_java_mirror(Handle m) { diff --git a/src/hotspot/share/opto/arraycopynode.cpp b/src/hotspot/share/opto/arraycopynode.cpp index 1370af872d4..73a140ac2f5 100644 --- a/src/hotspot/share/opto/arraycopynode.cpp +++ b/src/hotspot/share/opto/arraycopynode.cpp @@ -30,6 +30,7 @@ #include "opto/graphKit.hpp" #include "runtime/sharedRuntime.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" ArrayCopyNode::ArrayCopyNode(Compile* C, bool alloc_tightly_coupled, bool has_negative_length_guard) : CallNode(arraycopy_type(), NULL, TypePtr::BOTTOM), diff --git a/src/hotspot/share/opto/block.hpp b/src/hotspot/share/opto/block.hpp index 9a6fccc5a1e..868d830dc57 100644 --- a/src/hotspot/share/opto/block.hpp +++ b/src/hotspot/share/opto/block.hpp @@ -28,6 +28,7 @@ #include "opto/multnode.hpp" #include "opto/node.hpp" #include "opto/phase.hpp" +#include "utilities/powerOfTwo.hpp" // Optimization - Graph Style diff --git a/src/hotspot/share/opto/callnode.cpp b/src/hotspot/share/opto/callnode.cpp index 3f215dcef83..f8ec757b821 100644 --- a/src/hotspot/share/opto/callnode.cpp +++ b/src/hotspot/share/opto/callnode.cpp @@ -42,6 +42,7 @@ #include "opto/regmask.hpp" #include "opto/rootnode.hpp" #include "opto/runtime.hpp" +#include "utilities/powerOfTwo.hpp" // Portions of code courtesy of Clifford Click diff --git a/src/hotspot/share/opto/divnode.cpp b/src/hotspot/share/opto/divnode.cpp index d56cf9a2f7a..968b1ddd5f3 100644 --- a/src/hotspot/share/opto/divnode.cpp +++ b/src/hotspot/share/opto/divnode.cpp @@ -34,6 +34,7 @@ #include "opto/mulnode.hpp" #include "opto/phaseX.hpp" #include "opto/subnode.hpp" +#include "utilities/powerOfTwo.hpp" // Portions of code courtesy of Clifford Click @@ -359,7 +360,7 @@ static Node *transform_long_divide( PhaseGVN *phase, Node *dividend, jlong divis // Just negate the value q = new SubLNode(phase->longcon(0), dividend); } - } else if ( is_power_of_2_long(d) ) { + } else if ( is_power_of_2(d) ) { // division by +/- a power of 2 @@ -377,7 +378,7 @@ static Node *transform_long_divide( PhaseGVN *phase, Node *dividend, jlong divis const TypeLong *andconl_t = phase->type( dividend->in(2) )->isa_long(); if( andconl_t && andconl_t->is_con() ) { jlong andconl = andconl_t->get_con(); - if( andconl < 0 && is_power_of_2_long(-andconl) && (-andconl) >= d ) { + if( andconl < 0 && is_power_of_2(-andconl) && (-andconl) >= d ) { if( (-andconl) == d ) // Remove AND if it clears bits which will be shifted dividend = dividend->in(1); needs_rounding = false; @@ -1044,7 +1045,7 @@ Node *ModLNode::Ideal(PhaseGVN *phase, bool can_reshape) { Node *hook = new Node(1); // Expand mod - if( con >= 0 && con < max_jlong && is_power_of_2_long(con+1) ) { + if( con >= 0 && con < max_jlong && is_power_of_2(con+1) ) { uint k = exact_log2_long(con+1); // Extract k // Basic algorithm by David Detlefs. See fastmod_long.java for gory details. @@ -1108,7 +1109,7 @@ Node *ModLNode::Ideal(PhaseGVN *phase, bool can_reshape) { int log2_con = -1; // If this is a power of two, then maybe we can mask it - if( is_power_of_2_long(pos_con) ) { + if( is_power_of_2(pos_con) ) { log2_con = exact_log2_long(pos_con); const Type *dt = phase->type(in(1)); diff --git a/src/hotspot/share/opto/graphKit.cpp b/src/hotspot/share/opto/graphKit.cpp index c7d2105c11b..75adf43c9d1 100644 --- a/src/hotspot/share/opto/graphKit.cpp +++ b/src/hotspot/share/opto/graphKit.cpp @@ -44,6 +44,7 @@ #include "runtime/deoptimization.hpp" #include "runtime/sharedRuntime.hpp" #include "utilities/bitMap.inline.hpp" +#include "utilities/powerOfTwo.hpp" //----------------------------GraphKit----------------------------------------- // Main utility constructor. diff --git a/src/hotspot/share/opto/library_call.cpp b/src/hotspot/share/opto/library_call.cpp index 7907cdf5c6b..e42be6f759b 100644 --- a/src/hotspot/share/opto/library_call.cpp +++ b/src/hotspot/share/opto/library_call.cpp @@ -58,7 +58,7 @@ #include "runtime/objectMonitor.hpp" #include "runtime/sharedRuntime.hpp" #include "utilities/macros.hpp" - +#include "utilities/powerOfTwo.hpp" class LibraryIntrinsic : public InlineCallGenerator { // Extend the set of intrinsics known to the runtime: diff --git a/src/hotspot/share/opto/loopnode.cpp b/src/hotspot/share/opto/loopnode.cpp index ce122b32702..ddae400d8a0 100644 --- a/src/hotspot/share/opto/loopnode.cpp +++ b/src/hotspot/share/opto/loopnode.cpp @@ -40,6 +40,7 @@ #include "opto/mulnode.hpp" #include "opto/rootnode.hpp" #include "opto/superword.hpp" +#include "utilities/powerOfTwo.hpp" //============================================================================= //--------------------------is_cloop_ind_var----------------------------------- diff --git a/src/hotspot/share/opto/macro.cpp b/src/hotspot/share/opto/macro.cpp index 0c4bc3fb4be..a54d43016e8 100644 --- a/src/hotspot/share/opto/macro.cpp +++ b/src/hotspot/share/opto/macro.cpp @@ -49,6 +49,7 @@ #include "opto/type.hpp" #include "runtime/sharedRuntime.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #if INCLUDE_G1GC #include "gc/g1/g1ThreadLocalData.hpp" #endif // INCLUDE_G1GC diff --git a/src/hotspot/share/opto/macroArrayCopy.cpp b/src/hotspot/share/opto/macroArrayCopy.cpp index 7eaedc6d6ca..bd7d34b3a15 100644 --- a/src/hotspot/share/opto/macroArrayCopy.cpp +++ b/src/hotspot/share/opto/macroArrayCopy.cpp @@ -31,7 +31,7 @@ #include "opto/macro.hpp" #include "opto/runtime.hpp" #include "utilities/align.hpp" - +#include "utilities/powerOfTwo.hpp" void PhaseMacroExpand::insert_mem_bar(Node** ctrl, Node** mem, int opcode, Node* precedent) { MemBarNode* mb = MemBarNode::make(C, opcode, Compile::AliasIdxBot, precedent); diff --git a/src/hotspot/share/opto/memnode.cpp b/src/hotspot/share/opto/memnode.cpp index ae72b2d43d9..3a308b279fc 100644 --- a/src/hotspot/share/opto/memnode.cpp +++ b/src/hotspot/share/opto/memnode.cpp @@ -48,6 +48,7 @@ #include "utilities/align.hpp" #include "utilities/copy.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #include "utilities/vmError.hpp" // Portions of code courtesy of Clifford Click diff --git a/src/hotspot/share/opto/mulnode.cpp b/src/hotspot/share/opto/mulnode.cpp index 691e0f5a8ef..441430c2504 100644 --- a/src/hotspot/share/opto/mulnode.cpp +++ b/src/hotspot/share/opto/mulnode.cpp @@ -31,6 +31,7 @@ #include "opto/mulnode.hpp" #include "opto/phaseX.hpp" #include "opto/subnode.hpp" +#include "utilities/powerOfTwo.hpp" // Portions of code courtesy of Clifford Click @@ -306,7 +307,7 @@ Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) { Node *n2 = phase->transform(new LShiftLNode(in(1), phase->intcon(log2_long(bit2)))); res = new AddLNode(n2, n1); - } else if (is_power_of_2_long(abs_con+1)) { + } else if (is_power_of_2(abs_con+1)) { // Sleezy: power-of-2 -1. Next time be generic. julong temp = abs_con + 1; Node *n1 = phase->transform( new LShiftLNode(in(1), phase->intcon(log2_long(temp)))); @@ -1409,4 +1410,3 @@ const Type* FmaFNode::Value(PhaseGVN* phase) const { uint MulAddS2INode::hash() const { return (uintptr_t)in(1) + (uintptr_t)in(2) + (uintptr_t)in(3) + (uintptr_t)in(4) + Opcode(); } - diff --git a/src/hotspot/share/opto/output.cpp b/src/hotspot/share/opto/output.cpp index 0205b1cc324..329dd47f2b5 100644 --- a/src/hotspot/share/opto/output.cpp +++ b/src/hotspot/share/opto/output.cpp @@ -46,6 +46,7 @@ #include "opto/subnode.hpp" #include "opto/type.hpp" #include "runtime/handles.inline.hpp" +#include "utilities/powerOfTwo.hpp" #include "utilities/xmlstream.hpp" #ifndef PRODUCT diff --git a/src/hotspot/share/opto/regmask.cpp b/src/hotspot/share/opto/regmask.cpp index 94070721f58..5b2de6cf718 100644 --- a/src/hotspot/share/opto/regmask.cpp +++ b/src/hotspot/share/opto/regmask.cpp @@ -29,6 +29,7 @@ #include "opto/node.hpp" #include "opto/regmask.hpp" #include "utilities/population_count.hpp" +#include "utilities/powerOfTwo.hpp" #define RM_SIZE _RM_SIZE /* a constant private to the class RegMask */ diff --git a/src/hotspot/share/opto/superword.cpp b/src/hotspot/share/opto/superword.cpp index 2fe372de51d..50a55e5d81d 100644 --- a/src/hotspot/share/opto/superword.cpp +++ b/src/hotspot/share/opto/superword.cpp @@ -39,6 +39,7 @@ #include "opto/superword.hpp" #include "opto/vectornode.hpp" #include "opto/movenode.hpp" +#include "utilities/powerOfTwo.hpp" // // S U P E R W O R D T R A N S F O R M diff --git a/src/hotspot/share/opto/type.cpp b/src/hotspot/share/opto/type.cpp index 8d3cebc83c2..3eb919df05b 100644 --- a/src/hotspot/share/opto/type.cpp +++ b/src/hotspot/share/opto/type.cpp @@ -39,6 +39,7 @@ #include "opto/node.hpp" #include "opto/opcodes.hpp" #include "opto/type.hpp" +#include "utilities/powerOfTwo.hpp" // Portions of code courtesy of Clifford Click diff --git a/src/hotspot/share/opto/vectornode.cpp b/src/hotspot/share/opto/vectornode.cpp index f649f337647..85e3ac0450c 100644 --- a/src/hotspot/share/opto/vectornode.cpp +++ b/src/hotspot/share/opto/vectornode.cpp @@ -25,6 +25,7 @@ #include "memory/allocation.inline.hpp" #include "opto/connode.hpp" #include "opto/vectornode.hpp" +#include "utilities/powerOfTwo.hpp" //------------------------------VectorNode-------------------------------------- diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 19f1a7fbfaa..0161b4e1383 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -54,6 +54,7 @@ #include "utilities/align.hpp" #include "utilities/defaultStream.hpp" #include "utilities/macros.hpp" +#include "utilities/powerOfTwo.hpp" #include "utilities/stringUtils.hpp" #if INCLUDE_JFR #include "jfr/jfr.hpp" diff --git a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp index 30537785587..04fc865e934 100644 --- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp +++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp @@ -33,6 +33,7 @@ #include "runtime/flags/jvmFlagConstraintsCompiler.hpp" #include "runtime/globals.hpp" #include "runtime/globals_extension.hpp" +#include "utilities/powerOfTwo.hpp" JVMFlag::Error AliasLevelConstraintFunc(intx value, bool verbose) { if ((value <= 1) && (Arguments::mode() == Arguments::_comp || Arguments::mode() == Arguments::_mixed)) { diff --git a/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp b/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp index 4603e75b425..61d58c53829 100644 --- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp +++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp @@ -29,6 +29,7 @@ #include "runtime/globals.hpp" #include "runtime/safepointMechanism.hpp" #include "runtime/task.hpp" +#include "utilities/powerOfTwo.hpp" JVMFlag::Error ObjectAlignmentInBytesConstraintFunc(intx value, bool verbose) { if (!is_power_of_2(value)) { diff --git a/src/hotspot/share/utilities/align.hpp b/src/hotspot/share/utilities/align.hpp index c139e3938c2..50c9808c7fa 100644 --- a/src/hotspot/share/utilities/align.hpp +++ b/src/hotspot/share/utilities/align.hpp @@ -26,6 +26,7 @@ #define SHARE_UTILITIES_ALIGN_HPP #include "utilities/globalDefinitions.hpp" +#include "utilities/powerOfTwo.hpp" // Signed variants of alignment helpers. There are two versions of each, a macro // for use in places like enum definitions that require compile-time constant @@ -46,17 +47,11 @@ #define is_aligned_(size, alignment) (((size) & align_mask(alignment)) == 0) -// Temporary declaration until this file has been restructured. -template -bool is_power_of_2_t(T x) { - return (x != T(0)) && ((x & (x - 1)) == T(0)); -} - // Helpers to align sizes and check for alignment template inline T align_up(T size, A alignment) { - assert(is_power_of_2_t(alignment), "must be a power of 2: " UINT64_FORMAT, (uint64_t)alignment); + assert(is_power_of_2(alignment), "must be a power of 2: " UINT64_FORMAT, (uint64_t)alignment); T ret = align_up_(size, alignment); assert(is_aligned_(ret, alignment), "must be aligned: " UINT64_FORMAT, (uint64_t)ret); @@ -66,7 +61,7 @@ inline T align_up(T size, A alignment) { template inline T align_down(T size, A alignment) { - assert(is_power_of_2_t(alignment), "must be a power of 2: " UINT64_FORMAT, (uint64_t)alignment); + assert(is_power_of_2(alignment), "must be a power of 2: " UINT64_FORMAT, (uint64_t)alignment); T ret = align_down_(size, alignment); assert(is_aligned_(ret, alignment), "must be aligned: " UINT64_FORMAT, (uint64_t)ret); @@ -76,7 +71,7 @@ inline T align_down(T size, A alignment) { template inline bool is_aligned(T size, A alignment) { - assert(is_power_of_2_t(alignment), "must be a power of 2: " UINT64_FORMAT, (uint64_t)alignment); + assert(is_power_of_2(alignment), "must be a power of 2: " UINT64_FORMAT, (uint64_t)alignment); return is_aligned_(size, alignment); } diff --git a/src/hotspot/share/utilities/globalDefinitions.cpp b/src/hotspot/share/utilities/globalDefinitions.cpp index b9fa8ade4bb..428919ee5ed 100644 --- a/src/hotspot/share/utilities/globalDefinitions.cpp +++ b/src/hotspot/share/utilities/globalDefinitions.cpp @@ -27,6 +27,7 @@ #include "runtime/os.hpp" #include "runtime/signature.hpp" #include "utilities/globalDefinitions.hpp" +#include "utilities/powerOfTwo.hpp" // Basic error support diff --git a/src/hotspot/share/utilities/globalDefinitions.hpp b/src/hotspot/share/utilities/globalDefinitions.hpp index d27c4b6c674..1e952b2609d 100644 --- a/src/hotspot/share/utilities/globalDefinitions.hpp +++ b/src/hotspot/share/utilities/globalDefinitions.hpp @@ -988,16 +988,6 @@ inline T clamp(T value, T min, T max) { return MIN2(MAX2(value, min), max); } -// true if x is a power of 2, false otherwise -inline bool is_power_of_2(intptr_t x) { - return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits)); -} - -// long version of is_power_of_2 -inline bool is_power_of_2_long(jlong x) { - return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits)); -} - // Returns largest i such that 2^i <= x. // If x == 0, the function returns -1. inline int log2_intptr(uintptr_t x) { @@ -1051,18 +1041,6 @@ inline int log2_jlong(jlong x) { return log2_long((julong)x); } -//* the argument must be exactly a power of 2 -inline int exact_log2(intptr_t x) { - assert(is_power_of_2(x), "x must be a power of 2: " INTPTR_FORMAT, x); - return log2_intptr(x); -} - -//* the argument must be exactly a power of 2 -inline int exact_log2_long(jlong x) { - assert(is_power_of_2_long(x), "x must be a power of 2: " JLONG_FORMAT, x); - return log2_long(x); -} - inline bool is_odd (intx x) { return x & 1; } inline bool is_even(intx x) { return !is_odd(x); } diff --git a/src/hotspot/share/utilities/powerOfTwo.hpp b/src/hotspot/share/utilities/powerOfTwo.hpp index c57e4e5b9fe..e197935bd7b 100644 --- a/src/hotspot/share/utilities/powerOfTwo.hpp +++ b/src/hotspot/share/utilities/powerOfTwo.hpp @@ -28,13 +28,29 @@ #include "metaprogramming/enableIf.hpp" #include "metaprogramming/isIntegral.hpp" #include "metaprogramming/isSigned.hpp" -#include "utilities/align.hpp" #include "utilities/count_leading_zeros.hpp" #include "utilities/debug.hpp" #include "utilities/globalDefinitions.hpp" // Power of two convenience library. +template +bool is_power_of_2(T x) { + return (x != T(0)) && ((x & (x - 1)) == T(0)); +} + +// Log2 of a power of 2 +inline int exact_log2(intptr_t x) { + assert(is_power_of_2(x), "x must be a power of 2: " INTPTR_FORMAT, x); + return log2_intptr(x); +} + +// Log2 of a power of 2 +inline int exact_log2_long(jlong x) { + assert(is_power_of_2(x), "x must be a power of 2: " JLONG_FORMAT, x); + return log2_long(x); +} + // Round down to the closest power of two greater to or equal to the given // value. @@ -69,7 +85,7 @@ inline typename EnableIf::value, T>::type round_up_power_of_2(T valu STATIC_ASSERT(IsIntegral::value); STATIC_ASSERT(IsSigned::value); assert(value > 0, "Invalid value"); - if (is_power_of_2_t(value)) { + if (is_power_of_2(value)) { return value; } uint32_t lz = count_leading_zeros(value); @@ -85,7 +101,7 @@ inline typename EnableIf::value, T>::type round_up_power_of_2(T val STATIC_ASSERT(IsIntegral::value); STATIC_ASSERT(!IsSigned::value); assert(value != 0, "Invalid value"); - if (is_power_of_2_t(value)) { + if (is_power_of_2(value)) { return value; } uint32_t lz = count_leading_zeros(value); diff --git a/test/hotspot/gtest/gc/z/test_zForwarding.cpp b/test/hotspot/gtest/gc/z/test_zForwarding.cpp index 3d91737bc3a..0c26abed730 100644 --- a/test/hotspot/gtest/gc/z/test_zForwarding.cpp +++ b/test/hotspot/gtest/gc/z/test_zForwarding.cpp @@ -40,10 +40,6 @@ class ZForwardingTest : public Test { public: // Helper functions - static bool is_power_of_2(size_t value) { - return ::is_power_of_2((intptr_t)value); - } - class SequenceToFromIndex : AllStatic { public: static uintptr_t even(size_t sequence_number) { @@ -60,7 +56,7 @@ class ZForwardingTest : public Test { // Test functions static void setup(ZForwarding* forwarding) { - EXPECT_PRED1(is_power_of_2, forwarding->_entries.length()) << CAPTURE(forwarding->_entries.length()); + EXPECT_PRED1(is_power_of_2, forwarding->_entries.length()) << CAPTURE(forwarding->_entries.length()); } static void find_empty(ZForwarding* forwarding) { diff --git a/test/hotspot/gtest/utilities/test_powerOfTwo.cpp b/test/hotspot/gtest/utilities/test_powerOfTwo.cpp index 401d0c41a94..9b8d419636b 100644 --- a/test/hotspot/gtest/utilities/test_powerOfTwo.cpp +++ b/test/hotspot/gtest/utilities/test_powerOfTwo.cpp @@ -32,6 +32,40 @@ template T max_pow2() { return max_val - (max_val >> 1); } +template static void test_is_power_of_2() { + EXPECT_FALSE(is_power_of_2(T(0))); + EXPECT_FALSE(is_power_of_2(~T(0))); + + // Test true + for (T i = max_pow2(); i > 0; i = (i >> 1)) { + EXPECT_TRUE(is_power_of_2(i)) << "value = " << T(i); + } + + // Test one less + for (T i = max_pow2(); i > 2; i = (i >> 1)) { + EXPECT_FALSE(is_power_of_2(i - 1)) << "value = " << T(i - 1); + } + + // Test one more + for (T i = max_pow2(); i > 1; i = (i >> 1)) { + EXPECT_FALSE(is_power_of_2(i + 1)) << "value = " << T(i + 1); + } +} + +TEST(power_of_2, is_power_of_2) { + test_is_power_of_2(); + test_is_power_of_2(); + test_is_power_of_2(); + test_is_power_of_2(); + test_is_power_of_2(); + test_is_power_of_2(); + test_is_power_of_2(); + test_is_power_of_2(); + + test_is_power_of_2(); + test_is_power_of_2(); +} + template void round_up_power_of_2() { EXPECT_EQ(round_up_power_of_2(T(1)), T(1)) << "value = " << T(1); EXPECT_EQ(round_up_power_of_2(T(2)), T(2)) << "value = " << T(2);