RFR: JDK-8312018: Improve reservation of class space and CDS [v10]
Shaojin Wen
duke at openjdk.org
Sun Oct 15 07:30:42 UTC 2023
On Wed, 30 Aug 2023 08:38:10 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
>> This PR rewrites memory reservation of class space and CDS to have ASLR and a much better chance of low-address placement.
>>
>> ------
>>
>> Motivation:
>>
>> (I was advised to keep PR text short lest I spam the mailing lists with Skara generated mails. So, for motivation, see JBS issue)
>>
>> -------
>>
>> The patch introduces a new API to reserve memory within an address range at a randomized location, while trying to be smart about it. The API is generic, and future planned uses of this API could include replacing the zero-based heap allocation and the zero-based reservation of Shenandoah Collection Sets, thereby allowing us to consolidate coding.
>>
>> This PR complements @iklam 's current work that rewrites archive heap initialization at runtime. Once his work is in, we will be able to recalculate narrow Klass IDs for objects loaded from the archive, and that will allow us to reap the benefits of this patch for the CDS runtime case too.
>>
>> -------
>>
>> Noteworthy functional changes:
>>
>> - class space is now likely to be reserved at a random location in low address ranges; this now includes ranges below 2 GB, which had been excluded before due to the use of HeapBaseMinAddress as minimal attach point.
>> - Note that this makes no problem with sbrk() - the only platform still having this problem is AIX, and we solved it differently there, see comment in AIX implementation of `os::vm_min_address()`
>> - I removed the PPC/AARCH64 specific coding that attempted to map at 4G/32G aligned addresses. That section has a complex history - it was originally introduced to deal with AARCH64 immediate-loading shortcomings, but PPC piggybacked on it for its perceived ability to allocate for zero-based, which got subsequently lost, so its broken now (see https://bugs.openjdk.org/browse/JDK-8313669). The new code is a better replacement for this coding.
>>
>> -------
>>
>> Example (linux amd64):
>>
>> We start the JVM with a 30GB heap.
>>
>> In the stock JVM, the JVM will place the heap in the lower address ranges starting at 2G (0x8000_0000). But then it is unable to place the class space in lower regions too, so it placed it at 32 GB (0x8_0000_0000), and we don't have zero-based encoding (Narrow klass base: 0x0000000800000000). This scenario repeats for every iteration, so we will always use these two addresses (no ASLR):
>>
>>
>> thomas at starfish $ ./images/jdk/bin/java -Xshare:off -Xmx30g -Xlog:gc+heap+exit -Xlog:gc+metaspace -version
>> [0.019s][info][gc,metaspace] ...
>
> Thomas Stuefe has updated the pull request incrementally with one additional commit since the last revision:
>
> omit gtests on Aix until 8315321 is fixed
This PR cause compilation errors on Orange Pi5 Plus (http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-plus.html)
The error message is as follows:
orangepi5plus:jdk:# make images <89d18ea40f3 ✗>
Building target 'images' in configuration 'linux-aarch64-server-release'
Creating support/modules_libs/java.base/jrt-fs.jar
Updating support/modules_libs/java.base/server/libjvm.so due to 6 file(s)
Creating interim java.base.jmod
Creating support/demos/image/jfc/FileChooserDemo/FileChooserDemo.jar
Creating support/demos/image/jfc/CodePointIM/CodePointIM.jar
Creating support/demos/image/jfc/SwingSet2/SwingSet2.jar
Creating support/demos/image/jfc/Font2DTest/Font2DTest.jar
Creating support/demos/image/jfc/J2Ddemo/J2Ddemo.jar
Creating support/demos/image/jfc/Metalworks/Metalworks.jar
Creating support/demos/image/jfc/Notepad/Notepad.jar
Creating support/demos/image/jfc/Stylepad/Stylepad.jar
Creating support/demos/image/jfc/SampleTree/SampleTree.jar
Creating support/demos/image/jfc/TableExample/TableExample.jar
Creating support/demos/image/jfc/TransparentRuler/TransparentRuler.jar
Creating interim jimage
Creating support/classlist.jar
/usr/bin/bash: line 15: 1795239 Aborted (core dumped) /root/git/jdk/build/linux-aarch64-server-release/support/interim-image/bin/java -XX:DumpLoadedClassList=/root/git/jdk/build/linux-aarch64-server-release/support/link_opt/classlist.raw.2 -XX:SharedClassListFile=/root/git/jdk/build/linux-aarch64-server-release/support/link_opt/classlist.interim -XX:SharedArchiveFile=/root/git/jdk/build/linux-aarch64-server-release/support/link_opt/classlist.jsa -Djava.lang.invoke.MethodHandle.TRACE_RESOLVE=true -Duser.language=en -Duser.country=US --module-path /root/git/jdk/build/linux-aarch64-server-release/support/classlist.jar -cp /root/git/jdk/build/linux-aarch64-server-release/support/classlist.jar build.tools.classlist.HelloClasslist 2> /root/git/jdk/build/linux-aarch64-server-release/support/link_opt/stderr > /root/git/jdk/build/linux-aarch64-server-release/support/link_opt/default_jli_trace.txt
ERROR: Failed to generate link optimization data. This is likely a problem with the newly built JVM/JDK.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (macroAssembler_aarch64.cpp:4550), pid=1795239, tid=1795240
# guarantee((shifted_base & 0xffff0000ffffffff) == 0) failed: compressed class base bad alignment
#
# JRE version: (22.0) (build )
# Java VM: OpenJDK 64-Bit Server VM (22-internal-adhoc.root.jdk, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-aarch64)
# Problematic frame:
# V [libjvm.so+0xae1ca0] MacroAssembler::decode_klass_not_null(Register, Register)+0x250
#
# Core dump will be written. Default location: /root/git/jdk/make/core
#
# An error report file with more information is saved as:
# /root/git/jdk/make/hs_err_pid1795239.log
#
#
gmake[3]: *** [GenerateLinkOptData.gmk:71: /root/git/jdk/build/linux-aarch64-server-release/support/link_opt/classlist] Error 134
gmake[2]: *** [make/Main.gmk:649: generate-link-opt-data] Error 2
ERROR: Build failed for target 'images' in configuration 'linux-aarch64-server-release' (exit code 2)
No indication of failed target found.
HELP: Try searching the build log for '] Error'.
HELP: Run 'make doctor' to diagnose build problems.
make[1]: *** [/root/git/jdk/make/Init.gmk:323: main] Error 2
make: *** [/root/git/jdk/make/Init.gmk:189: images] Error 2
[hs_err_pid1795239.log](https://github.com/openjdk/jdk/files/12908894/hs_err_pid1795239.log)
-------------
PR Comment: https://git.openjdk.org/jdk/pull/15041#issuecomment-1763305298
More information about the hotspot-runtime-dev
mailing list