RFR: 8309751: Duplicate constant pool entries added during default method processing [v2]
Kim Barrett
kbarrett at openjdk.org
Fri Apr 5 23:57:09 UTC 2024
On Fri, 5 Apr 2024 22:19:05 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> I believe that. If this is also undefined behavior
>>
>> static unsigned hash(BytecodeCPEntry const& e0) {
>> return (unsigned)(e0._tag ^ e0._u.value);
>> }
>>
>> Then this BytecodeCPEntry class needs to be restructured a bit, which shouldn't be in this PR.
>
> 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"
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18548#discussion_r1554438995
More information about the hotspot-runtime-dev
mailing list