JDK-8236604 : Optimize SystemDictionary::resolve_well_known_classes for CDS
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 14
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-01-02
  • Updated: 2020-03-05
  • Resolved: 2020-02-28
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 15
15 b13Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
Profiling shows that when CDS is enabled, SystemDictionary::resolve_well_known_classes() can cost up to 7% of the total time for running "java -cp . HelloWorld" (3.3ms out of 43ms -- see details in comments).

There's no way for the user to affect how these well-known classes are loaded -- we will always end up loading the classes from the CDS archive. Therefore, it should be possible to store a pre-populated system dictionary in the CDS archive, where all of these classes are already loaded and linked. This avoids the complex work of looking up these classes and building the system dictionary at run time.

Note that when this function is called, the JVM is in JVMTI_PHASE_PRIMORDIAL state (i.e., JvmtiExport::is_early_phase() == true). Before JDK-8212200, the user could replace some of these classes with a JVMTI agent that requests the can_generate_all_class_hook_events or can_generate_early_class_hook_events capabilities. However, since JDK-8212200, CDS is automatically disabled when such an agent exists.

We might have to fake JFR class loading events and -Xlog:class+load messages to make the 'loading' of these classes observable.
Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/f227e770495f User: minqi Date: 2020-02-28 23:30:47 +0000
28-02-2020

Update: I redo the above measure on top of my prototype of 8026297 (Generating AdapterHandlerEntry during CDS dump). The saving is less (because linking of the well known classes no longer require adapter generation), but is still significant: (perf stat -r 400 java -Xint -XX:-UsePerfData -Xshare:on -cp /home/iklam/tmp HelloWorld) Timing: mod 1: 11.285 ms mod 2: 12.911ms no mods: 38.944ms Ratio = (12.911 - 11.285) / 38.944 = 4.18%
29-01-2020

Measurement is done by calling "exit" at these locations, and run the JVM with "perf stat -r 100 java -XX:-UsePerfData -cp . HelloWorld": void SystemDictionary::initialize(TRAPS) { .... // mod 1: if (UseSharedSpaces) { exit(0); } resolve_well_known_classes(CHECK); // mod 2: if (UseSharedSpaces) { exit(0); } } Timing: mod 1: 11.655ms mod 2: 14.965ms no mods: 43.117ms Ratio = (14.965 - 11.655) / 43.117 = 7.67%
02-01-2020