RFR: JDK-8300080: offset_of for GCC/Clang exhibits undefined behavior and is not always a compile-time constant [v4]
Julian Waters
jwaters at openjdk.org
Tue Jan 17 13:04:15 UTC 2023
On Fri, 13 Jan 2023 16:06:44 GMT, Justin King <jcking at openjdk.org> wrote:
>> The implementation of `offset_of` for GCC/Clang only deals with types are aligned to 16 bytes or less, if they are more, such as `zCollectedHeap` the behavior is undefined. UBSan also suggests that `offset_of` is not always a compile time constant, as the stack trace came from the dynamic loader during library loading. This patch changes `offset_of` to use `offsetof` and disables the warning `invalid-offsetof` for the JVM.
>
> Justin King has updated the pull request incrementally with one additional commit since the last revision:
>
> Move attribute on lambda to correct location
>
> Signed-off-by: Justin King <jcking at google.com>
Small nit, I think it might be better to use `ALWAYSINLINE` instead of the attribute for the custom `offset_of`, it looks somewhat neater
> Also, the FIXME comment added by JDK-8294902 suggesting using `offsetof` should be removed.
I partially agree with Justin on this one when it comes to `offsetof`, if I'm missing something important perhaps we could leave the comment as is or reword it to not be a `FIXME` while we stay on C++14, to leave it open for if HotSpot properly moves to a newer C++ version in the future. Just my 2¢ on the issue
> A change to the existing code would be to use `alignof(klass)` to align the space buffer, once use of
> `alignof` is approved. That would fix the alignment problem.
The `alignof` proposal is still awaiting approval, given that we're speaking of it :P
-------------
PR: https://git.openjdk.org/jdk/pull/11978
More information about the hotspot-dev
mailing list