JDK-8352426 : RelocIterator should correctly handle nullptr address of relocation data
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 25
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2025-03-19
  • Updated: 2025-03-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
Currently RelocIterator assumes that address of relocation data is never null even when there were no relocations. It never checks for null and assumes that `current - 1` address is valid.

It was true before JDK-8343789 which moved relocation data from code blob.
JDK-8352112 resolved the issue with setting relocation data address to some valid address.

We should consider enabling RelocIterator correctly handle null address of relocation data.
Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/24203 Date: 2025-03-24 17:04:04 +0000
24-03-2025

[~dlong] suggest to use dummy structure in case address is null: https://github.com/openjdk/jdk/pull/24102#discussion_r2002179287 I modified it to something like this: +++ b/src/hotspot/share/code/relocInfo.cpp @@ -116,6 +116,8 @@ void relocInfo::change_reloc_info_for_address(RelocIterator *itr, address pc, re // ---------------------------------------------------------------------------------------------------- // Implementation of RelocIterator +static relocInfo dummy_reloc[2]; + void RelocIterator::initialize(nmethod* nm, address begin, address limit) { initialize_misc(); @@ -127,8 +129,14 @@ void RelocIterator::initialize(nmethod* nm, address begin, address limit) { guarantee(nm != nullptr, "must be able to deduce nmethod from other arguments"); _code = nm; - _current = nm->relocation_begin() - 1; - _end = nm->relocation_end(); + // Check for no relocations case and use dummy data to avoid referencing wrong data. + if (nm->relocation_size() == 0) { + _current = dummy_reloc; + _end = dummy_reloc + 1; + } else { + _current = nm->relocation_begin() - 1; + _end = nm->relocation_end(); + } _addr = nm->content_begin(); // Initialize code sections.
19-03-2025