RFR: 8234331: Add robust and optimized utility for rounding up to next power of two+
David Holmes
david.holmes at oracle.com
Tue Nov 26 09:50:22 UTC 2019
Hi Claes,
Just some high-level comments
- should next_power_of_two be defined in globalDefinitions.hpp along
side the related functionality ie is_power_of_two ?
- can next_power_of_two build on the existing log2_* functions (or vice
versa)?
- do the existing ZUtils not cover the same general area?
./share/gc/z/zUtils.inline.hpp
inline size_t ZUtils::round_up_power_of_2(size_t value) {
assert(value != 0, "Invalid value");
if (is_power_of_2(value)) {
return value;
}
return (size_t)1 << (log2_intptr(value) + 1);
}
inline size_t ZUtils::round_down_power_of_2(size_t value) {
assert(value != 0, "Invalid value");
return (size_t)1 << log2_intptr(value);
}
Cheers,
David
On 26/11/2019 7:44 pm, Claes Redestad wrote:
> Hi,
>
> in various places in the hotspot we have custom code to calculate the
> next power of two, some of which have potential to go into an infinite
> loop in case of an overflow.
>
> This patch proposes adding next_power_of_two utility methods which
> avoid infinite loops on overflow, while providing slightly more
> efficient code in most cases.
>
> Bug: https://bugs.openjdk.java.net/browse/JDK-8234331
> Webrev: http://cr.openjdk.java.net/~redestad/8234331/open.01/
>
> Testing: tier1-3
>
> Thanks!
>
> /Claes
More information about the hotspot-compiler-dev
mailing list