By default JVMCI and Graal JIT are initialized on first request of compilation.
But it also can be triggered by switching off background compilation: -Xbatch. In which case it will try to initialize JVMCI and Graal during VM initialization:
http://hg.openjdk.java.net/jdk/jdk/file/125716343184/src/hotspot/share/runtime/thread.cpp#l4236
Unfortunately this mode does not work with dumping CDS archive: -Xshare:dump.
java -Xshare:dump -Xlog:cds,cds+hashtables -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=./test.jsa -Xbatch -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -Djvmci.Compiler=graal
narrow_klass_base = 0x0000000800000000, narrow_klass_shift = 3
Allocated temporary class space: 1073741824 bytes at 0x00000008c0000000
Allocated shared space: 3221225472 bytes at 0x0000000800000000
[0.038s][info][cds] Expanding shared spaces by 1048576 bytes [total 1048576 bytes ending at 0x800100000]
Error occurred during initialization of VM
java.lang.ExceptionInInitializerError
at jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime(jdk.internal.vm.ci@10-internal/HotSpotJVMCIRuntime.java:83)
at jdk.vm.ci.runtime.JVMCI.initializeRuntime(jdk.internal.vm.ci@10-internal/Native Method)
at jdk.vm.ci.runtime.JVMCI.<clinit>(jdk.internal.vm.ci@10-internal/JVMCI.java:58)
Caused by: java.lang.ClassNotFoundException: org/graalvm/compiler/hotspot/HotSpotGraalJVMCIServiceLocator
Note, this is NOT normal way to run Graal as JIT. That is why I am targeting JDK 11.
But it also can be triggered by switching off background compilation: -Xbatch. In which case it will try to initialize JVMCI and Graal during VM initialization:
http://hg.openjdk.java.net/jdk/jdk/file/125716343184/src/hotspot/share/runtime/thread.cpp#l4236
Unfortunately this mode does not work with dumping CDS archive: -Xshare:dump.
java -Xshare:dump -Xlog:cds,cds+hashtables -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=./test.jsa -Xbatch -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -Djvmci.Compiler=graal
narrow_klass_base = 0x0000000800000000, narrow_klass_shift = 3
Allocated temporary class space: 1073741824 bytes at 0x00000008c0000000
Allocated shared space: 3221225472 bytes at 0x0000000800000000
[0.038s][info][cds] Expanding shared spaces by 1048576 bytes [total 1048576 bytes ending at 0x800100000]
Error occurred during initialization of VM
java.lang.ExceptionInInitializerError
at jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime(jdk.internal.vm.ci@10-internal/HotSpotJVMCIRuntime.java:83)
at jdk.vm.ci.runtime.JVMCI.initializeRuntime(jdk.internal.vm.ci@10-internal/Native Method)
at jdk.vm.ci.runtime.JVMCI.<clinit>(jdk.internal.vm.ci@10-internal/JVMCI.java:58)
Caused by: java.lang.ClassNotFoundException: org/graalvm/compiler/hotspot/HotSpotGraalJVMCIServiceLocator
Note, this is NOT normal way to run Graal as JIT. That is why I am targeting JDK 11.