Skip to content

Commit 0f00649

Browse files
committed
disable C2 when running Native Image on JDK 21 prior to 21.0.4 due to JDK-8328702
1 parent 9f429e9 commit 0f00649

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,27 @@ public List<String> getBuilderJavaArgs() {
615615
builderJavaArgs.add("-XX:+UseJVMCINativeLibrary");
616616
} else if (getHostFlags().hasUseJVMCICompiler()) {
617617
builderJavaArgs.add("-XX:-UseJVMCICompiler");
618+
619+
if (JavaVersionUtil.JAVA_SPEC == 21) {
620+
Runtime.Version version = Runtime.version();
621+
if (version.interim() == 0 && version.update() < 4) {
622+
/*
623+
* Native Image regularly crashes due to JDK-8328702. In JDK 21, the fix
624+
* only landed in 20.0.4 so in earlier JDK 21 versions, disable C2. This
625+
* workaround can be removed when GR-55515, GR-60648 or GR-60669 is
626+
* resolved.
627+
*/
628+
builderJavaArgs.add("-XX:TieredStopAtLevel=1");
629+
630+
/*
631+
* From the java man page section on ReservedCodeCacheSize: "the default
632+
* maximum code cache size is 240 MB; if you disable tiered compilation ...
633+
* then the default size is 48 MB". Experience shows that Native Image needs
634+
* the larger code cache, even when C2 is disabled.
635+
*/
636+
builderJavaArgs.add("-XX:ReservedCodeCacheSize=240M");
637+
}
638+
}
618639
}
619640

620641
return builderJavaArgs;

0 commit comments

Comments
 (0)