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

Kim Barrett kbarrett at openjdk.org
Fri Apr 5 22:22:05 UTC 2024


On Thu, 4 Apr 2024 13:38:23 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

>> That is technically undefined behaviour.
>
> 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.

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

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


More information about the hotspot-runtime-dev mailing list