JDK-8287869 : -XX:+AutoCreateSharedArchive doesn't work when JDK build is switched
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 19
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-06-06
  • Updated: 2022-06-07
  • Resolved: 2022-06-07
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 19
19 masterFixed
Related Reports
Relates :  
Description
Expected: When you switch to a different JDK build, -XX:+AutoCreateSharedArchive should automatically update the specified dynamic CDS archive to match the new JDK.

Actual: the new JDK fails to load the base archive, and thus is unable to generate the dynamic archive.

=================================
$ rm -f /tmp/foo.jsa
$ /mybld/java/images/jdk/bin/java -Xlog:cds -Xlog:cds+map=debug:file=cds.map:none:filesize=0 -XX:+AutoCreateSharedArchive -cp ~/tmp/HelloWorld.jar -XX:SharedArchiveFile=/tmp/foo.jsa HelloWorld
[0.001s][info][cds] UseSharedSpaces: Specified shared archive not found (/tmp/foo.jsa)
[0.008s][info][cds] trying to map /mybld/java/images/jdk/lib/server/classes.jsa
[0.008s][info][cds] Opened archive /mybld/java/images/jdk/lib/server/classes.jsa.
[0.008s][info][cds] Archive was created with UseCompressedOops = 1, UseCompressedClassPointers = 1
[0.008s][info][cds] Core region alignment: 4096
[0.008s][info][cds] Reserved archive_space_rs [0x0000000800000000 - 0x0000000801000000] (16777216) bytes
[0.008s][info][cds] Reserved class_space_rs   [0x0000000801000000 - 0x0000000841000000] (1073741824) bytes
[0.008s][info][cds] Mapped static  region #0 at base 0x0000000800000000 top 0x000000080046f000 (ReadWrite)
[0.008s][info][cds] Mapped static  region #1 at base 0x000000080046f000 top 0x0000000800c42000 (ReadOnly)
[0.008s][info][cds] CDS archive was created with max heap size = 128M, and the following configuration:
[0.008s][info][cds]     narrow_klass_base = 0x0000000800000000, narrow_klass_shift = 0
[0.008s][info][cds]     narrow_oop_mode = 0, narrow_oop_base = 0x0000000000000000, narrow_oop_shift = 0
[0.008s][info][cds]     heap range = [0x00000000f8000000 - 0x0000000100000000]
[0.008s][info][cds] The current max heap size = 16088M, HeapRegion::GrainBytes = 8388608
[0.008s][info][cds]     narrow_klass_base = 0x0000000800000000, narrow_klass_shift = 0
[0.008s][info][cds]     narrow_oop_mode = 1, narrow_oop_base = 0x0000000000000000, narrow_oop_shift = 3
[0.008s][info][cds]     heap range = [0x0000000412800000 - 0x0000000800000000]
[0.008s][info][cds] CDS heap data needs to be relocated because the archive was created with an incompatible oop encoding mode.
[0.008s][info][cds] CDS heap data relocation delta = 30064771072 bytes
[0.008s][info][cds] CDS heap data needs to be relocated lower by a further 7340032 bytes to 30057431040 to be aligned with HeapRegion::GrainBytes
[0.008s][info][cds] Mapped static  region #2 at base 0x00007f3a24080000 top 0x00007f3a240b9000 (Bitmap)
[0.008s][info][cds] Trying to map heap data: region[3] at 0x00000007ff800000, size =   528384 bytes
[0.008s][info][cds] Trying to map heap data: region[5] at 0x00000007ff700000, size =   487424 bytes
[0.008s][info][cds] optimized module handling: enabled
[0.008s][info][cds] full module graph: enabled
[0.008s][info][cds] use_full_module_graph = true; java.base = 0x0000000800469208
[0.008s][info][cds] patching heap embedded pointers
[0.010s][info][cds] Unmapping region #2 at base 0x00007f3a24080000 (Bitmap)
Hello World
[0.042s][info][cds] Regenerate MethodHandle Holder classes...
[.....]
[0.176s][info][cds] Dumping shared data to file: 
[0.176s][info][cds]    /tmp/foo.jsa
[0.176s][info][cds] Shared file region (rw )  0:    45936 bytes, addr 0x0000000800c42000 file offset 0x00001000 crc 0xabcded7d
[0.176s][info][cds] Shared file region (ro )  1:    57616 bytes, addr 0x0000000800c4e000 file offset 0x0000d000 crc 0xbc845f02
[0.176s][info][cds] Shared file region (bm )  2:     1672 bytes, addr 0x0000000000000000 file offset 0x0001c000 crc 0xa045a902

$ /mybld/java-fastdebug/images/jdk/bin/java -Xlog:cds -XX:+AutoCreateSharedArchive -cp ~/tmp/HelloWorld.jar -XX:SharedArchiveFile=/tmp/foo.jsa HelloWorld
[0.046s][info][cds] trying to map /mybld/java/images/jdk/lib/server/classes.jsa
[0.046s][info][cds] Opened archive /mybld/java/images/jdk/lib/server/classes.jsa.
[0.046s][info][cds] _jvm_ident expected: Java HotSpot(TM) 64-Bit Server VM (fastdebug 19-internal-adhoc.iklam.src) for linux-amd64 JRE (19-internal-adhoc.iklam.src), built on Jun  6 2022 20:46:08 by "iklam" with gcc 10.3.0
[0.046s][info][cds]              actual: Java HotSpot(TM) 64-Bit Server VM (19-internal-adhoc.iklam.src) for linux-amd64 JRE (19-internal-adhoc.iklam.src), built on Jun  6 2022 20:38:06 by "iklam" with gcc 10.3.0
[0.046s][info][cds] UseSharedSpaces: The shared archive file was created by a different version or build of HotSpot
[0.046s][info][cds] UseSharedSpaces: Initialize static archive failed.
[0.046s][info][cds] UseSharedSpaces: Unable to map shared spaces
Hello World

=================================
The problem is here: 

$ head -8 cds.map
Dynamic CDS archive map for /tmp/foo.jsa
[header             0x0000000000000000 - 0x00000000000003f8      1016 bytes]
- magic:                          0xf00baba8
- crc:                            0x0ac363f5
- version:                        14
- header_size:                    1016
- base_archive_name_offset:       968
- base_archive_name_size:         48

According to https://github.com/openjdk/jdk/blob/master/src/hotspot/share/include/cds.h#L72

base_archive_name_offset and base_archive_name_size should both be zero to indicate that /tmp/foo.jsa is generated using the default CDS archive.


Comments
Changeset: 68c5957b Author: Ioi Lam <iklam@openjdk.org> Date: 2022-06-07 23:11:33 +0000 URL: https://git.openjdk.java.net/jdk/commit/68c5957b9e2306d96bec2d655ec743f13f250dae
07-06-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/9046 Date: 2022-06-06 22:30:13 +0000
06-06-2022

With the fix, the archive is automatically regenerated after we switch the JVM. $ head -8 cds.map Dynamic CDS archive map for /tmp/foo.jsa [header 0x0000000000000000 - 0x00000000000003c8 968 bytes] - magic: 0xf00baba8 - crc: 0x9f849d02 - version: 0xe - header_size: 968 - base_archive_name_offset: 0 - base_archive_name_size: 0 $ /mybld/java-fastdebug/images/jdk/bin/java -Xlog:cds -Xlog:cds+map=debug:file=cds.map:none:filesize=0 -XX:+AutoCreateSharedArchive -cp ~/tmp/HelloWorld.jar -XX:SharedArchiveFile=/tmp/foo.jsa HelloWorld [0.044s][info][cds] trying to map /mybld/java-fastdebug/images/jdk/lib/server/classes.jsa [0.044s][info][cds] Opened archive /mybld/java-fastdebug/images/jdk/lib/server/classes.jsa. [0.044s][info][cds] Archive was created with UseCompressedOops = 1, UseCompressedClassPointers = 1 [0.044s][info][cds] Core region alignment: 4096 [0.044s][info][cds] trying to map /tmp/foo.jsa [0.044s][info][cds] Opened archive /tmp/foo.jsa. [0.044s][info][cds] _jvm_ident expected: Java HotSpot(TM) 64-Bit Server VM (fastdebug 19-internal-adhoc.iklam.zoo) for linux-amd64 JRE (19-internal-adhoc.iklam.zoo), built on Jun 6 2022 20:46:08 by "iklam" with gcc 10.3.0 [0.044s][info][cds] actual: Java HotSpot(TM) 64-Bit Server VM (19-internal-adhoc.iklam.zoo) for linux-amd64 JRE (19-internal-adhoc.iklam.zoo), built on Jun 6 2022 22:08:16 by "iklam" with gcc 10.3.0 [0.044s][info][cds] UseSharedSpaces: The shared archive file was created by a different version or build of HotSpot [0.044s][info][cds] UseSharedSpaces: Initialize dynamic archive failed. [0.044s][info][cds] Reserved archive_space_rs [0x0000000800000000 - 0x0000000801000000] (16777216) bytes [0.044s][info][cds] Reserved class_space_rs [0x0000000801000000 - 0x0000000841000000] (1073741824) bytes [0.044s][info][cds] Mapped static region #0 at base 0x0000000800000000 top 0x00000008004f0000 (ReadWrite) [0.044s][info][cds] Mapped static region #1 at base 0x00000008004f0000 top 0x0000000800cc6000 (ReadOnly) [0.044s][info][cds] CDS archive was created with max heap size = 2022M, and the following configuration: [0.044s][info][cds] narrow_klass_base = 0x0000000800000000, narrow_klass_shift = 0 [0.044s][info][cds] narrow_oop_mode = 0, narrow_oop_base = 0x0000000000000000, narrow_oop_shift = 0 [0.044s][info][cds] heap range = [0x0000000081a00000 - 0x0000000100000000] [0.044s][info][cds] The current max heap size = 16088M, HeapRegion::GrainBytes = 8388608 [0.044s][info][cds] narrow_klass_base = 0x0000000800000000, narrow_klass_shift = 0 [0.044s][info][cds] narrow_oop_mode = 1, narrow_oop_base = 0x0000000000000000, narrow_oop_shift = 3 [0.044s][info][cds] heap range = [0x0000000412800000 - 0x0000000800000000] [0.044s][info][cds] CDS heap data needs to be relocated because the archive was created with an incompatible oop encoding mode. [0.044s][info][cds] CDS heap data relocation delta = 30064771072 bytes [0.044s][info][cds] CDS heap data needs to be relocated lower by a further 7340032 bytes to 30057431040 to be aligned with HeapRegion::GrainBytes [0.044s][info][cds] Mapped static region #2 at base 0x00007f78c802f000 top 0x00007f78c806a000 (Bitmap) [0.044s][info][cds] Trying to map heap data: region[3] at 0x00000007ff800000, size = 528384 bytes [0.044s][info][cds] Trying to map heap data: region[5] at 0x00000007ff700000, size = 487424 bytes [0.044s][info][cds] optimized module handling: enabled [0.044s][info][cds] full module graph: enabled [0.045s][info][cds] use_full_module_graph = true; java.base = 0x00000008004ea0d0 [0.045s][info][cds] patching heap embedded pointers [0.050s][info][cds] Unmapping region #2 at base 0x00007f78c802f000 (Bitmap) Hello World [0.158s][info][cds] Regenerate MethodHandle Holder classes... [0.464s][info][cds] Checking class java/lang/invoke/DelegatingMethodHandle$Holder [0.466s][info][cds] Checking class java/lang/invoke/DirectMethodHandle$Holder [0.467s][info][cds] Checking class java/lang/invoke/Invokers$Holder [0.468s][info][cds] Checking class java/lang/invoke/LambdaForm$Holder [0.468s][info][cds] Regenerate MethodHandle Holder classes...done [0.496s][info][cds] Verify Before CDS dynamic dump [0.603s][info][cds] Gathering all archivable objects ... [0.604s][info][cds] Gathering classes and symbols ... [0.607s][info][cds] _estimated_hashtable_bytes = 1592 + 600 = 2192 [0.607s][info][cds] _estimated_metaspaceobj_bytes = 104088 [0.607s][info][cds] total estimate bytes = 114472 [0.607s][info][cds] Reserved output buffer space at 0x00007f7884022000 [114688 bytes] [0.607s][info][cds] Allocating RW objects ... [0.607s][info][cds] done (381 objects) [0.607s][info][cds] Allocating RO objects ... [0.607s][info][cds] done (721 objects) [0.607s][info][cds] Relocating embedded pointers in core regions ... [0.607s][info][cds] Relocating external roots ... [0.607s][info][cds] done [0.607s][info][cds] MetaspaceObjs estimate = 104088 used = 104088; diff = 0 bytes [0.608s][info][cds] Hashtables estimate = 2192 used = 816; diff = 1376 bytes [0.608s][info][cds] Make classes shareable [0.608s][info][cds] Number of classes 8 [0.608s][info][cds] instance classes = 8 [0.608s][info][cds] boot = 7 [0.608s][info][cds] app = 1 [0.608s][info][cds] platform = 0 [0.608s][info][cds] unregistered = 0 [0.608s][info][cds] (hidden) = 3 [0.608s][info][cds] (unlinked) = 0 [0.608s][info][cds] obj array classes = 0 [0.608s][info][cds] type array classes = 0 [0.608s][info][cds] symbols = 9 [0.608s][info][cds] Adjust lambda proxy class dictionary [0.608s][info][cds] Dumping shared data to file: [0.608s][info][cds] /tmp/foo.jsa [0.608s][info][cds] Shared file region (rw ) 0: 51368 bytes, addr 0x0000000800cc6000 file offset 0x00001000 crc 0xdc946884 [0.609s][info][cds] Shared file region (ro ) 1: 53536 bytes, addr 0x0000000800cd3000 file offset 0x0000e000 crc 0xde25e9ff [0.609s][info][cds] Shared file region (bm ) 2: 1672 bytes, addr 0x0000000000000000 file offset 0x0001c000 crc 0xadd1d064 [0.618s][info][cds] Verify After CDS dynamic dump
06-06-2022