RFR: 8352426: RelocIterator should correctly handle nullptr address of relocation data
Boris Ulasevich
bulasevich at openjdk.org
Mon Mar 24 22:27:50 UTC 2025
This is a follow-up to the recent #24102 patch. It addresses an issue where RelocIterator may receive a nullptr as the relocation table address. This change can also serve as an independent fix for JDK-8352112.
RelocIterator::initialize() and RelocIterator::next() perform decrement/increment operations on an internal relocaction pointer.
If nm->relocation_begin() returns nullptr, this results in undefined behavior, as pointer arithmetic on nullptr is prohibited by the C++ Standard.
Instead of introducing a null-check (which would add overhead in RelocIterator::next(), a performance-sensitive path), we initialize _current with a dummy static variable. This pointer is never dereferenced, so its actual value is not important - it just serves to avoid undefined behavior.
RelocIterator::RelocIterator constructor can initialize _current pointer as well. However, in that place we have an assert to ensure that nullptr value is not allowed, and it seems we do not need to apply dummy value there.
Testing:
The fix has been verified against the failure in JDK-8352112. The issue no longer reproduces with this patch, regardless of whether the original fix from #24102 is applied.
-------------
Commit messages:
- 8352426: RelocIterator should correctly handle nullptr address of relocation data
Changes: https://git.openjdk.org/jdk/pull/24203/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=24203&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8352426
Stats: 12 lines in 1 file changed: 9 ins; 0 del; 3 mod
Patch: https://git.openjdk.org/jdk/pull/24203.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/24203/head:pull/24203
PR: https://git.openjdk.org/jdk/pull/24203
More information about the hotspot-compiler-dev
mailing list