JDK-8174986 : CDS archived java heap region may not compatible with AOT
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-02-15
  • Updated: 2019-05-22
  • Resolved: 2017-10-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 10
10 b31Fixed
Related Reports
Relates :  
Relates :  
Description
Problem description:

See JDK-8168703 for more details. In summary:

In order to support a wide range of metaspace size, AOT forces klass_shift to 3. However, in JDK 9, CDS shared string regions will always be dumped with klass_shift of 0 (because CompressedClassSpaceSize has a hard limit of 3GB, and during archive creation, the klass space is always based from 0x80000000). As a result, the shared string regions will fail to load when AOT is enabled.

Possible fixes:

[Option A] Change CDS to be similar to AOT (JDK-8173054). Always force _narrow_klass._shift to be 3. This will allow CDS to be compatible with different sizes of heap and metaspace settings. The downside is small performance degradation when AOT is not used. 

[Option B] In the CDS archive, create 2 separate string regions, one for klasshift=0, and another for klasshift=3. Map the correct one according to runtime settings. 





Comments
After some analysis, I agree that always using 3 as _narrow_klass_shift for archived heap data is acceptable in order to work with AOT.
29-09-2017

Patch for option A (patch_8174986.txt): when CDS is enabled, always Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes). This is the same behavior as AOT. ======== $ jaotc --output hello.so Hello.class $ java -Xshare:dump Allocated shared space: 56868864 bytes at 0x0000000800000000 Loading classes to share ... Loading classes to share: done. Rewriting and linking classes ... Rewriting and linking classes: done Number of classes 1191 instance classes = 1177 obj array classes = 6 type array classes = 8 Updating ConstMethods ... done. Removing unshareable information ... done. ro space: 7194792 [ 40.2% of total] out of 13631488 bytes [ 52.8% used] at 0x0000000800000000 rw space: 4208648 [ 23.5% of total] out of 10485760 bytes [ 40.1% used] at 0x0000000800d00000 md space: 146256 [ 0.8% of total] out of 4194304 bytes [ 3.5% used] at 0x0000000801700000 mc space: 1 [ 0.0% of total] out of 122880 bytes [ 0.0% used] at 0x0000000801b00000 st space: 16384 [ 0.1% of total] out of 16384 bytes [100.0% used] at 0x00000007bfc00000 od space: 6334680 [ 35.4% of total] out of 24117248 bytes [ 26.3% used] at 0x0000000801b1e000 total : 17900761 [100.0% of total] out of 52568064 bytes [ 34.1% used] $ java -Xshare:on -Xlog:cds=trace -XX:+UseAOT -cp . -XX:AOTLibrary=./hello.so -Xlog:aot+class+load=trace Hello [0.067s][trace][cds] narrow_oop_mode wants 1, has 1 [0.068s][trace][cds] narrow_oop_shift wants 3, has 3 [0.068s][trace][cds] narrow_klass_base wants 0x800000000, has 0x800000000 [0.068s][trace][cds] narrow_klass_shift wants 3, has 3 [0.120s][trace][aot,class,load] found java.lang.Object in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.121s][trace][aot,class,load] found java.lang.CharSequence in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.121s][trace][aot,class,load] found java.lang.String in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.121s][trace][aot,class,load] found java.lang.System in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.122s][trace][aot,class,load] found java.lang.reflect.AnnotatedElement in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.122s][trace][aot,class,load] found java.lang.reflect.Type in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.122s][trace][aot,class,load] found java.lang.Class in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.134s][trace][aot,class,load] found java.lang.ClassLoader in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.138s][trace][aot,class,load] found jdk.internal.reflect.Reflection in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.158s][trace][aot,class,load] found java.io.OutputStream in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.160s][trace][aot,class,load] found java.io.FilterOutputStream in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.160s][trace][aot,class,load] found java.io.PrintStream in ./hello.so for classloader 0x7f1670277510 tid=0x00007f167001b800 [0.286s][trace][aot,class,load] found Hello in ./hello.so for classloader 0x7f16703c1040 tid=0x00007f167001b800 Hello
28-06-2017