RFR: 8145096: Undefined behaviour in HotSpot, Take 2

Ioi Lam ioi.lam at oracle.com
Wed Dec 16 00:02:08 UTC 2015

Is it possible to change things like

1373   juint nrange = (juint)_hi - _lo;


1373   juint nrange = juint(_hi) - _lo;


1373   juint nrange = ((juint)_hi) - _lo;

I found the first kind of casting difficult to read -- I constantly need 
to think, "does the cast apply to the first operand only, or the whole 

- Ioi

On 12/15/15 8:44 AM, Andrew Haley wrote:
> To recap:
> I've been tracing through HotSpot with GCC's undefined behaviour
> sanitizer, which detects instances of undefined behaviour.  There are
> many instances of UB we probably don't want to fix (e.g. unaliged
> accesses on x86) but some of them are serious.
> This patch fixes some signed integer overflow bugs in HotSpot which
> are certainly known to occur.  These mostly occur in C2.  There are
> surely many more such bugs but to begin with I want to concentrate on
> those.
> This patch introduces some functions which perform java-like
> arithmetic: java-add, etc.  We think we've found a portable way to do
> this.
> I have tried my utmost to change things as little as possible.  There
> are certainly places where we could make things more efficient, but my
> goal was to limit the scope of this diff to fixing bugs.
> Apart from the undefined behaviour being fixed, this patch should
> cause no behavioural changes, except in one case.
> AdvancedThresholdPolicy::weight() grossly overflows, so much so that
> its result is substantially noise. That's fixed here.
> It might be that the hashing functions for C2 types really should have
> unsigned type rather than using java_add; I can make that change but
> (as I said) I'm trying to change things as little as possible.
> http://cr.openjdk.java.net/~aph/8145096-2/
> Andrew.

More information about the hotspot-dev mailing list