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
Wed Jan 18 05:59:19 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>

Ah, right, I completely forgot about that. I wonder why we still need the `inline` keyword though? I know for early versions of gcc you needed the `inline` declaration for always_inline to have any effect, but somewhere down the line gcc's maintainers (rightfully) decided that requiring the keyword and the attribute together was a little ridiculous, so today gcc will forcefully inline such declarations as we want it to, even with only the always_inline attribute requested without the corresponding `inline` keyword specified

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

PR: https://git.openjdk.org/jdk/pull/11978


More information about the hotspot-dev mailing list