RFR: 8309751: Duplicate constant pool entries added during default method processing [v2]

David Holmes dholmes at openjdk.org
Mon Apr 8 07:00:12 UTC 2024


On Fri, 5 Apr 2024 23:54:50 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Not a review, just a drive-by comment.
>> 
>> I'm assuming the UB @dholmes-ora  is referring to is storing a value in one member of
>> a union and then reading from another, aka the "union trick". That is indeed
>> UB according to the C++ standard. It used to also be UB in C, but that was
>> changed in C99.
>> 
>> However, "Many compilers implement, as a non-standard language extension, the
>> ability to read inactive members of a union."
>> https://en.cppreference.com/w/cpp/language/union
>> 
>> And indeed, gcc and msvc both explicitly document providing that extension.  I
>> expect clang does too (for compatibility reasons), though I've not found the
>> words that say so.
>> 
>> The "union trick" is used in several places in HotSpot, sometimes even with
>> commentary about the UB per-the-standard but compiler supported.  Perhaps the
>> style guide should explicitly mention it, so I can avoid needing to repeat
>> this comment.
>
> https://bugs.openjdk.org/browse/JDK-8329818 - HotSpot Style Guide should explicitly permit the "union trick"

Thanks @kimbarrett . I didn't recognise this code as "the union trick" as such, but it is - we use the `value` member to access the bit pattern of the real (primitive) value for hashing purposes. Certainly should be safe/harmless for the types involved.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18548#discussion_r1555311971


More information about the hotspot-runtime-dev mailing list