RFR: 8331953: ubsan: metaspaceShared.cpp:1305:57: runtime error: applying non-zero offset 12849152 to null pointer
Matthias Baesken
mbaesken at openjdk.org
Tue May 14 08:21:02 UTC 2024
On Thu, 9 May 2024 06:28:48 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
> Reported by @MBaesken at SAP. ubsan complains about this line:
>
>
> const size_t ccs_begin_offset = align_up(base_address + archive_space_size,
> class_space_alignment) - base_address;
>
>
> `base_address` here is the wish address, with NULL being an explicitly allowed value that indicates "no preference". The line calculates the offset of the class space within the future combined CDS+class-space mapping. Ubsan complains about `base_address` being possibly NULL.
>
> Ubsan is missing the point somewhat. The addition is not a problem, on our platforms at least.
>
> However, it highlights a slight incorrectness (which it did not notice): `base_address` is the wish for the future base of the Klass range. That wish is not guaranteed to be fulfilled; the eventual start of the Klass range could be somewhere else. Therefore, calculating the class space offset with an alignment based on that wish address is wrong. It always worked in practice since `base_address` was always aligned to class_space_alignment (16MB).
>
> Hence, the fix is simple: We just make the alignment requirement for the base address explicit. When running with class space, we now assert that `base_address` is aligned to class space alignment (as well as CDS core region alignment, but that is much smaller). Since `base_address` is calculated either from a hard-wired default or from the `SharedBaseAddress` user input, and both are ensured to be properly aligned, that assert should never fire.
>
> Then, the offending calculation can be simplified by removing the base address from it.
We see now errors like this on Linux ppc64le with the patch added.
# Internal Error (/jdk/src/hotspot/share/cds/metaspaceShared.cpp:1295), pid=7002, tid=7006
# assert(is_aligned(base_address, base_address_alignment)) failed: Archive base address unaligned: 0x0000000000010000, needs alignment: 16777216.
#
# JRE version: (23.0) (fastdebug build )
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 23-internal-adhoc.jenkinsi.jdk, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-ppc64le)
# Problematic frame:
# V [libjvm.so+0x1546818] MetaspaceShared::reserve_address_space_for_archives(FileMapInfo*, FileMapInfo*, bool, ReservedSpace&, ReservedSpace&, ReservedSpace&)+0x258
Current thread (0x00007fff8c02ca00): JavaThread "Unknown thread" [_thread_in_vm, id=7006, stack(0x00007fff92350000,0x00007fff92550000) (2048K)]
Stack: [0x00007fff92350000,0x00007fff92550000], sp=0x00007fff9254dd60, free space=2039k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [libjvm.so+0x1546818] MetaspaceShared::reserve_address_space_for_archives(FileMapInfo*, FileMapInfo*, bool, ReservedSpace&, ReservedSpace&, ReservedSpace&)+0x258 (metaspaceShared.cpp:1295)
V [libjvm.so+0x154937c] MetaspaceShared::map_archives(FileMapInfo*, FileMapInfo*, bool)+0xcc (metaspaceShared.cpp:1050)
V [libjvm.so+0x1549d38] MetaspaceShared::initialize_runtime_shared_and_meta_spaces()+0x2c8 (metaspaceShared.cpp:931)
V [libjvm.so+0x153bd68] Metaspace::global_initialize()+0x178 (metaspace.cpp:714)
V [libjvm.so+0x1c203d8] universe_init()+0x168 (universe.cpp:866)
V [libjvm.so+0xf60130] init_globals()+0x90 (init.cpp:128)
V [libjvm.so+0x1bd8694] Threads::create_vm(JavaVMInitArgs*, bool*)+0x364 (threads.cpp:553)
V [libjvm.so+0x114c4b8] JNI_CreateJavaVM+0x98 (jni.cpp:3581)
C [libjli.so+0x5e94] JavaMain+0xd4 (java.c:1550)
C [libjli.so+0xbc38] ThreadJavaMain+0x18 (java_md.c:653)
C [libpthread.so.0+0xaa68] start_thread+0x108
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19152#issuecomment-2109564054
More information about the hotspot-runtime-dev
mailing list