[9] RFR(XS): 8135252: IdealLoopTree::dump_head() prints negative trip count

Tobias Hartmann tobias.hartmann at oracle.com
Wed Sep 9 13:21:27 UTC 2015


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 [1]. The output is sometimes 2147483647 and sometimes -2147483648 depending on the generated assembly code. [2] demonstrates this undefined behaviour nicely.


[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."

[2] https://ideone.com/4ZalQW

More information about the hotspot-compiler-dev mailing list