RFR: 8323556: CDS archive space addresses should be randomized with ArchiveRelocationMode=1

Ioi Lam iklam at openjdk.org
Wed Jan 17 02:31:51 UTC 2024


On Fri, 12 Jan 2024 22:02:34 GMT, Calvin Cheung <ccheung at openjdk.org> wrote:

> Please review this small fix for ensuring the reserved archive space addresses are different from run to run. The bug is only on the aarch64 platforms. The fix is to call `os::init_random()` if aslr is `true` and not dumping CDS static archive.
> 
> Tested manually on linux-aarch64 and macosx-aarch64 platforms.
> 
> % ./jdk-23/fastdebug/bin/java -Xlog:cds --version | grep archive_space_rs | tail -1
> [0.015s][info][cds] Reserved archive_space_rs [0x0000200000000000 - 0x0000200001000000] (16777216) bytes
> % ./jdk-23/fastdebug/bin/java -Xlog:cds --version | grep archive_space_rs | tail -1
> [0.014s][info][cds] Reserved archive_space_rs [0x0000080000000000 - 0x0000080001000000] (16777216) bytes
> 
> The fix also passed tiers 1 - 4 testing.

Changes requested by iklam (Reviewer).

src/hotspot/cpu/aarch64/compressedKlass_aarch64.cpp line 70:

> 68:     if (!CDSConfig::is_dumping_static_archive()) {
> 69:       // To ensure we have a deterministic static archive on aarch64 platform, call
> 70:       // os::init_random when not dumping static archive.

Does this code conflict with the call to `os::init_random(0x12345678)` in [ VM_PopulateDumpSharedSpace::doit()](https://github.com/openjdk/jdk/blob/2063bb8ffabd6096f547ec6da979cfcf68a56ba3/src/hotspot/share/cds/metaspaceShared.cpp#L499-L517)?

I think it's better to remove the call to os::init_random(), and change the following call to


const int start_index = aslr ? os::next_random(int)os::javaTimeNanos()) : 0;
``` 

That way we can avoid modifying a global state that may affect other VM components.

I also created https://bugs.openjdk.org/browse/JDK-8323900 to avoid calling `os::init_random(0x12345678)`

-------------

PR Review: https://git.openjdk.org/jdk/pull/17409#pullrequestreview-1826350380
PR Review Comment: https://git.openjdk.org/jdk/pull/17409#discussion_r1454379353


More information about the hotspot-runtime-dev mailing list