JDK-8152311 : [JVMCI] allow JVMCI compiler to change the compilation policy for a method
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-03-21
  • Updated: 2019-02-19
  • Resolved: 2016-05-11
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 9
9 b122Fixed
Related Reports
Blocks :  
Blocks :  
Blocks :  
Relates :  
Description
The CompilationPolicy hierarchy supports varying levels of sophistication for selecting when methods are to be compiled and in what order. However, it is restricted to using (mostly) compiler independent metrics when making decisions.

A compiler may be able to make a better decision in terms of when it's worth compiling a method. For example, an optimizing compiler such as Graal may decide after bytecode parsing that:

1. it won't do a better job than a lower tier compiler (e.g., C1), or
2. the method has constructs it doesn't support, or
3. Graal is likely to inline the method at all call sites and so there's no point in directly compiling it.

Based on the above, Graal may want to communicate to the CompileBroker that the method should be compiled later (e.g., when there's nothing else on the queue), compiled at a lower compilation level or not compiled at the current compilation level.

The CompilationRequestResult object returned by JVMCICompiler.compileMethod API should be expanded to encode the above ideas. This is the right place to support such communication as it is executed on a compiler thread and thus does not slow down handling of compilation counter overflows on an application thread.
Comments
JVMCI compilation policy participation is at the point where a compilation is being scheduled (i.e., on an application or compiler thread). That is, at a method invocation or back-edge counter overflow. The SimpleThresholdPolicy and AdvancedThresholdPolicy call JVMCIRuntime::adjust_comp_level once they have selected a compilation level. JVMCI can then adjust that compilation level as it wants. Since this all happens at counter overflow, it is not yet known if the price of executing extra Java code at that point will be too costly. As such, the existing mechanism for forcing compilation by C1 based on prefixes (i.e. JVMCIRuntime::treat_as_trivial) remains in place. To mitigate the cost of JVMCI compilation policy participation, a few optimizations are performed. First, no call into the JVMCI Java runtime is performed before HotSpotJVMCIRuntime is initialized. During HotSpotJVMCIRuntime initialization, the HotSpotJVMCIRuntime.compilationLevelAdjustment field is set to a non-zero value only if a JVMCI compiler may want to adjust compilation levels. The JVMCI compiler indicates this by overriding HotSpotJVMCICompilerFactory.getCompilationLevelAdjustment(HotSpotVMConfig) and returning a non-zero value. To avoid the cost of creating (or retrieving) a ResolvedJavaMethod at each counter overflow event, the Java interface for adjusting compilation levels is in terms of a declaring class, the method name and method signature: /** * Potentially modifies the compilation level currently selected by the VM compilation policy * for a method. * * @param config object for reading HotSpot {@code CompLevel} enum values * @param declaringClass the class in which the method is declared * @param name the name of the method or {@code null} depending on the value that was returned * by {@link #getCompilationLevelAdjustment(HotSpotVMConfig)} * @param signature the signature of the method or {@code null} depending on the value that was * returned by {@link #getCompilationLevelAdjustment(HotSpotVMConfig)} * @param isOsr specifies if the compilation being scheduled in an OSR compilation * @param level the compilation level currently selected by the VM compilation policy * @return the compilation level to use for the compilation being scheduled (must be a valid * {@code CompLevel} enum value) */ public int adjustCompilationLevel(HotSpotVMConfig config, Class<?> declaringClass, String name, String signature, boolean isOsr, int level) The declaringClass can be obtained for free but the name and signature values require converting a VM Symbol to a java.lang.String. A JVMCI implementation can inform the VM that these latter 2 values are not used when adjusting compilation levels in which case no Symbol to String conversion is performed. I opted to make this mechanism HotSpot specific, at least until we've experimented with it in JDK9 to know what the appropriate VM-independent abstractions might be for participating in a VM's compilation policy mechanism. This new specialization of JVMCICompilerFactory (i.e., HotSpotJVMCICompilerFactory) reflects that. It also now contains the trivial prefixes mechanism which was always HotSpot specific.
05-05-2016

Initial experimentation using this mechanism to implement Graal's CompileGraalWithC1Only[1] option shows no noticeable overhead of this mechanism. The first run below is not using the mechanism, the second one is. dsimon@kurz ~/g/graal-core> java -server -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -d64 -modulepath mxbuild/modules/graal.jar -XaddExports:java.base/com.sun.crypto.provider=graal -XaddExports:java.base/jdk.internal.misc=graal -Djvmci.Compiler=graal -Dgraal.CompileGraalWithC1Only=true -Dgraal.UseTrivialPrefixes=true -jar /Users/dsimon/.mx/cache/DACAPO_2626a9546df09009f6da0df854e6dc1113ef7dd4.jar pmd -n 10 ===== DaCapo 9.12 pmd starting warmup 1 ===== ===== DaCapo 9.12 pmd completed warmup 1 in 3924 msec ===== ===== DaCapo 9.12 pmd starting warmup 2 ===== ===== DaCapo 9.12 pmd completed warmup 2 in 2027 msec ===== ===== DaCapo 9.12 pmd starting warmup 3 ===== ===== DaCapo 9.12 pmd completed warmup 3 in 1712 msec ===== ===== DaCapo 9.12 pmd starting warmup 4 ===== ===== DaCapo 9.12 pmd completed warmup 4 in 1637 msec ===== ===== DaCapo 9.12 pmd starting warmup 5 ===== ===== DaCapo 9.12 pmd completed warmup 5 in 1597 msec ===== ===== DaCapo 9.12 pmd starting warmup 6 ===== ===== DaCapo 9.12 pmd completed warmup 6 in 1538 msec ===== ===== DaCapo 9.12 pmd starting warmup 7 ===== ===== DaCapo 9.12 pmd completed warmup 7 in 1579 msec ===== ===== DaCapo 9.12 pmd starting warmup 8 ===== ===== DaCapo 9.12 pmd completed warmup 8 in 1666 msec ===== ===== DaCapo 9.12 pmd starting warmup 9 ===== ===== DaCapo 9.12 pmd completed warmup 9 in 1622 msec ===== ===== DaCapo 9.12 pmd starting ===== ===== DaCapo 9.12 pmd PASSED in 1508 msec ===== dsimon@kurz ~/g/graal-core> java -server -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -d64 -modulepath mxbuild/modules/graal.jar -XaddExports:java.base/com.sun.crypto.provider=graal -XaddExports:java.base/jdk.internal.misc=graal -Djvmci.Compiler=graal -Dgraal.CompileGraalWithC1Only=true -Dgraal.UseTrivialPrefixes=false -jar /Users/dsimon/.mx/cache/DACAPO_2626a9546df09009f6da0df854e6dc1113ef7dd4.jar pmd -n 10 ===== DaCapo 9.12 pmd starting warmup 1 ===== ===== DaCapo 9.12 pmd completed warmup 1 in 3607 msec ===== ===== DaCapo 9.12 pmd starting warmup 2 ===== ===== DaCapo 9.12 pmd completed warmup 2 in 1978 msec ===== ===== DaCapo 9.12 pmd starting warmup 3 ===== ===== DaCapo 9.12 pmd completed warmup 3 in 1656 msec ===== ===== DaCapo 9.12 pmd starting warmup 4 ===== ===== DaCapo 9.12 pmd completed warmup 4 in 1894 msec ===== ===== DaCapo 9.12 pmd starting warmup 5 ===== ===== DaCapo 9.12 pmd completed warmup 5 in 1556 msec ===== ===== DaCapo 9.12 pmd starting warmup 6 ===== ===== DaCapo 9.12 pmd completed warmup 6 in 1713 msec ===== ===== DaCapo 9.12 pmd starting warmup 7 ===== ===== DaCapo 9.12 pmd completed warmup 7 in 1628 msec ===== ===== DaCapo 9.12 pmd starting warmup 8 ===== ===== DaCapo 9.12 pmd completed warmup 8 in 1538 msec ===== ===== DaCapo 9.12 pmd starting warmup 9 ===== ===== DaCapo 9.12 pmd completed warmup 9 in 1549 msec ===== ===== DaCapo 9.12 pmd starting ===== ===== DaCapo 9.12 pmd PASSED in 1522 msec ===== [1] http://hg.openjdk.java.net/graal/graal-core/file/2fa8e7c31813/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalCompilerFactory.java#l86
05-05-2016

http://cr.openjdk.java.net/~dnsimon/8152311/
05-05-2016

Yes.
21-03-2016

Very good enhancement. Are you planning on doing this for 9?
21-03-2016