RFR(XS): 8135252: IdealLoopTree::dump_head() prints negative trip count
vladimir.kozlov at oracle.com
Fri Sep 11 03:38:29 UTC 2015
On 9/9/15 6:21 AM, Tobias Hartmann wrote:
> please review the following patch.
> 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 . The output is sometimes 2147483647 and sometimes -2147483648 depending on the generated assembly code.  demonstrates this undefined behaviour nicely.
>  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."
>  https://ideone.com/4ZalQW
More information about the hotspot-compiler-dev