RFR: 8367984: Eliminate offset_of in vmStructs

Julian Waters jwaters at openjdk.org
Thu Oct 2 16:23:41 UTC 2025


On Thu, 18 Sep 2025 12:49:10 GMT, Francesco Andreuzzi <fandreuzzi at openjdk.org> wrote:

>> There are several usages of `offset_of` in `vmStructs`, they can be replaced with standard `offsetof` due to [JDK-8367016](https://bugs.openjdk.org/browse/JDK-8367016).
>> 
>> Passes `tier1`.
>
> src/hotspot/share/runtime/vmStructs.cpp line 1984:
> 
>> 1982: 
>> 1983: JNIEXPORT VMStructEntry* gHotSpotVMStructs = VMStructs::localHotSpotVMStructs;
>> 1984: extern JNIEXPORT constexpr uint64_t gHotSpotVMStructEntryTypeNameOffset = offsetof(VMStructEntry, typeName);
> 
> I got a partial understanding about this change, I thought having `JNIEXPORT` and `constexpr` together wouldn't work. But the symbols are exported:
> 
> objdump --syms build/gcc/jdk/lib/server/libjvm.so | grep gHotSpotVMTypeEntryIsIntegerTypeOffset
> 000000000137ca78 g     O .rodata	0000000000000008              gHotSpotVMTypeEntryIsIntegerTypeOffset
> 
> and I tested that the values are still readable. I was wondering if this wouldn't be portable?

I believe constexpr means the entity marked as a constant expression will be treated as such if conditions allow it to be used as a compile time constant, and doesn't mean it will disappear from the final binary entirely. Since JNIEXPORT exports the symbol from HotSpot, it is obviously used and the compiler takes note of that, hence allowing it to be JNIEXPORT despite being constexpr

Also I think the JNIEXPORT would preferably be in front of the extern (Actually, could I ask why extern is required here?)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27362#discussion_r2399361039


More information about the hotspot-runtime-dev mailing list