RFR: 8186166: Generalize Atomic::cmpxchg with templates

Kim Barrett kim.barrett at oracle.com
Sat Aug 19 14:57:33 UTC 2017

> On Aug 19, 2017, at 3:57 AM, Andrew Haley <aph at redhat.com> wrote:
> On 18/08/17 20:58, Kim Barrett wrote:
>> BTW, the conversion technique presently used by the jmumble_cast suite
>> is explicitly called out by gcc documentation as still being undefined
>> behavior, even with the involvement of unions.
> Umm, what?  Can you explain this a little more?  I'd have to search
> for what jumble_cast might be.  The union trick is well defined by
> GCC.

jint_cast, jdouble_cast, &etc, in globalDefinitions.hpp around line
520 right now.  For example:

typedef union { jfloat f; jint i; } FloatIntConv;
jint jint_cast(jfloat x) { return ((FloatIntConv*)&x)->i; }

That's *not* the union trick.

Similarly, access by taking the address, casting the resulting pointer
and dereferencing the result has undefined behavior, even if the cast
uses a union type, e.g.: <code of the form used by jint_cast>.

More information about the hotspot-dev mailing list