JDK-8340184 : Bug in CompressedKlassPointers::is_in_encodable_range
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 24
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-09-16
  • Updated: 2025-08-08
  • Resolved: 2024-09-17
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.
JDK 24
24 b16Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Since JDK-8338526, we keep only those Klass in class space that need to be encodable with a narrowKlass. 

To check whether a Klass can be encoded, we call `CompressedKlassPointers::is_in_encodable_range()`. Unfortunately there is an error that results from the confusion around "encoding range" vs "klass range" when it comes to narrowKlass encoding. These terms are not cleanly used and therefore errors like this happen.

The "Encoding Range" is the range that can be encoded with the current encoding base, encoding shift and (implicitly) the bit size of the narrowKlass. The encoding range reaches from `[ <encoding base> ... <encoding base> + 1 << (32 + <encoding shift>) ).`. Its size is either 4G (shift=0) or 32G (shift=3).

The "Klass Range" is the range within the encoding range that actually holds Klass structures. It is usually just a small part of the encoding range:

- With zero-based encoding, the encoding base is zero, so it precedes the start of the Klass range
- and usually the encoding range reaches far beyond the Klass range, since the class space is just 1GB.

----

The error in this case, introduced with 8338526, was that we use the range `[<encoding base> ... <klass range end>)` for `is_in_encodable_range()`. That can lead to false positives. Since the base can be zero, a non-class Metaspage region may live in address regions below the Klass range (between `0` and `<klass range start>`). A Klass in that region would falsely be recognized as "is encodable" even though it lives not in the klass range.

The error is extremely unlikely to happen, mostly because non-class Metaspace regions - freely placed by the OS - typically live in high-address ranges far beyond a low-placed class space, and also it is restricted to zero-based encoding which is only used if CDS is disabled.


Comments
Changeset: 7849f252 Branch: master Author: Thomas Stuefe <stuefe@openjdk.org> Date: 2024-09-17 05:22:59 +0000 URL: https://git.openjdk.org/jdk/commit/7849f252937dc774a1935cc4c68f2a46649f180b
17-09-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/21015 Date: 2024-09-16 10:37:55 +0000
16-09-2024