JDK-8305765 : CompressedClassPointers.java is unreliable due to ASLR
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 11,17,21,22
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-04-07
  • Updated: 2024-01-03
  • Resolved: 2023-10-04
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 22
22 b18Fixed
Related Reports
Relates :  
Relates :  
Sub Tasks
JDK-8305766 :  
Description
CompressedClassPointers.java expect the compressed class space (CCS) to be reserved in a certain range to satisfy the following:

output.shouldContain("Narrow klass base: 0x0000000000000000");

https://github.com/openjdk/jdk/blob/a8871f5d26e5cb42c031c7b736ec30b1b147a2bc/test/hotspot/jtreg/runtime/CompressedOops/CompressedClassPointers.java#L61-L74

However, this is not always possible due to Address Space Layout Randomization. This can be simulated on Linux/x64 with the following patch, which will cause the test to always fail.

$ git diff
diff --git a/src/hotspot/share/memory/metaspace.cpp b/src/hotspot/share/memory/metaspace.cpp
index db9579e4652..efd711b57b0 100644
--- a/src/hotspot/share/memory/metaspace.cpp
+++ b/src/hotspot/share/memory/metaspace.cpp
@@ -797,6 +797,7 @@ void Metaspace::global_initialize() {
 
       if (base != nullptr) {
         if (CompressedKlassPointers::is_valid_base(base)) {
+          if (0)
           rs = ReservedSpace(size, Metaspace::reserve_alignment(),
                              os::vm_page_size(), (char*)base);
         }

==============================
Proposed fix:

Add a VM log message to indicate whether it's able to reserve the CCS at the desired memory range. If not, the test cases in CompressedClassPointers.java should be skipped.
Comments
> Maybe you can try the fix for JDK-8318485 on AIX? That fix is in the shared OpenJDK codebase so we have it on AIX as well (except a removed st->cr(); in os_linux.cpp but this should not explain the failures on AIX) .
17-11-2023

[~mbaesken] JDK-8317610 was filed for the above failure you observed on linux-x64 and the test was excluded on linux-x64 and windows-x64 since we saw similar failure on windows-x64 as well. During investigation on the above bug, Thomas Stuefe filed and fixed JDK-8318485. I tested the fix and it addresses the narrow klass shift issue on linux-x64. I didn't test AIX since we don't have the setup here. Maybe you can try the fix for JDK-8318485 on AIX?
26-10-2023

JDK-8305765 removed the exclusion of test runtime/CompressedOops/CompressedClassPointers.java . Unfortunately we still see the test failing after JDK-8305765 ; lots of failures are on AIX, some can be seen on Linux x86_64 as well. Can we again exclude the test (maybe this time only on AIX because we see the most failures there) ? examples of errors : AIX : java.lang.RuntimeException: 'Narrow klass base: 0x0000000000000000' missing from stdout/stderr at jdk.test.lib.process.OutputAnalyzer.shouldContain(OutputAnalyzer.java:242) at CompressedClassPointers.smallHeapTestNoCoop(CompressedClassPointers.java:225) at CompressedClassPointers.main(CompressedClassPointers.java:349) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at com.sun.javatest.regtest.agent.MainActionHelper$AgentVMRunnable.run(MainActionHelper.java:333) at java.base/java.lang.Thread.run(Thread.java:1570) Linux x86_64: java.lang.RuntimeException: 'Narrow klass shift: 0' missing from stdout/stderr at jdk.test.lib.process.OutputAnalyzer.shouldContain(OutputAnalyzer.java:221) at CompressedClassPointers.smallHeapTestWith1GNoCoop(CompressedClassPointers.java:247) at CompressedClassPointers.main(CompressedClassPointers.java:350) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at com.sun.javatest.regtest.agent.MainActionHelper$AgentVMRunnable.run(MainActionHelper.java:333) at java.base/java.lang.Thread.run(Thread.java:1570)
26-10-2023

Changeset: ddacf927 Author: Calvin Cheung <ccheung@openjdk.org> Date: 2023-10-04 17:27:33 +0000 URL: https://git.openjdk.org/jdk/commit/ddacf92713aaa17f6fc50c1fb7a5da1ca7809702
04-10-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/16014 Date: 2023-10-02 18:30:54 +0000
02-10-2023

On macosx-aarch64 and macosx-aarch64-debug: java.lang.RuntimeException: 'Narrow klass base: 0x0000000000000000' missing from stdout/stderr at jdk.test.lib.process.OutputAnalyzer.shouldContain(OutputAnalyzer.java:221) at CompressedClassPointers.smallHeapTest(CompressedClassPointers.java:66) at CompressedClassPointers.main(CompressedClassPointers.java:320) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at com.sun.javatest.regtest.agent.MainActionHelper$AgentVMRunnable.run(MainActionHelper.java:312) at java.base/java.lang.Thread.run(Thread.java:842) On linux-aarch64-debug: java.lang.RuntimeException: 'Narrow klass base: 0x0000000000000000' missing from stdout/stderr at jdk.test.lib.process.OutputAnalyzer.shouldContain(OutputAnalyzer.java:221) at CompressedClassPointers.largeHeapAbove32GTest(CompressedClassPointers.java:127) at CompressedClassPointers.main(CompressedClassPointers.java:323) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at com.sun.javatest.regtest.agent.MainActionHelper$AgentVMRunnable.run(MainActionHelper.java:312) at java.base/java.lang.Thread.run(Thread.java:842) On linux-aarch64: java.lang.RuntimeException: 'Narrow klass base: 0x0000000000000000' missing from stdout/stderr at jdk.test.lib.process.OutputAnalyzer.shouldContain(OutputAnalyzer.java:221) at CompressedClassPointers.smallHeapTestWith1GNoCoop(CompressedClassPointers.java:225) at CompressedClassPointers.main(CompressedClassPointers.java:336) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at com.sun.javatest.regtest.agent.MainActionHelper$AgentVMRunnable.run(MainActionHelper.java:312) at java.base/java.lang.Thread.run(Thread.java:842)
12-07-2023