[9] RFR(XS): 8135252: IdealLoopTree::dump_head() prints negative trip count
Vladimir Kozlov
vladimir.kozlov at oracle.com
Fri Sep 11 03:38:29 UTC 2015
Looks good.
Thanks,
Vladimir
On 9/9/15 6:21 AM, Tobias Hartmann wrote:
> Hi,
>
> please review the following patch.
>
> https://bugs.openjdk.java.net/browse/JDK-8135252
> http://cr.openjdk.java.net/~thartmann/8135252/webrev.00/
>
> IdealLoopTree::dump_head() used by -XX:TraceLoopOpts prints a negative trip count if CountedLoopNode::profile_trip_cnt() is large:
>
> compute_profile_trip_cnt lp: 1676 cnt: 2147483648.000000
> Loop: N1676/N1546 limit_check predicated counted [0,100),+8 (-2147483648 iters)
>
> The problem is that we cast a large float (2147483648.0) to int
>
> 1904 tty->print(" (%d iters) ", (int)cl->profile_trip_cnt());
>
> causing an overflow and leading to undefined behaviour [1]. The output is sometimes 2147483647 and sometimes -2147483648 depending on the generated assembly code. [2] demonstrates this undefined behaviour nicely.
>
> Thanks,
> Tobias
>
>
> [1] C++ standard, 4.9 Floating-integral conversions
> "A prvalue of a floating point type can be converted to a prvalue of an integer type. The conversion truncates;
> that is, the fractional part is discarded. The behavior is undefined if the truncated value cannot be
> represented in the destination type."
> http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4527.pdf
>
> [2] https://ideone.com/4ZalQW
>
More information about the hotspot-compiler-dev
mailing list