Skip to content

Commit

Permalink
Pass -H:+UnlockExperimentalVMOptions as necessary with Graalvm 23.1
Browse files Browse the repository at this point in the history
Needed since oracle/graal#7190 to avoid warnings
  • Loading branch information
zakkak authored and gsmet committed Aug 17, 2023
1 parent 9867dde commit 1a1d4ea
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,8 @@ public NativeImageInvokerInfo build() {
nativeImageArgs.add("-H:ImageBuildStatisticsFile=" + nativeImageName + "-timing-stats.json");
}
// For getting the build output stats as a JSON file
nativeImageArgs.add("-H:BuildOutputJSONFile=" + nativeImageName + "-build-output-stats.json");
addExperimentalVMOption(nativeImageArgs,
"-H:BuildOutputJSONFile=" + nativeImageName + "-build-output-stats.json");
}

/*
Expand All @@ -802,7 +803,7 @@ public NativeImageInvokerInfo build() {
*/
handleAdditionalProperties(nativeImageArgs);

nativeImageArgs.add("-H:+AllowFoldMethods");
addExperimentalVMOption(nativeImageArgs, "-H:+AllowFoldMethods");

if (nativeConfig.headless()) {
nativeImageArgs.add("-J-Djava.awt.headless=true");
Expand All @@ -824,7 +825,7 @@ public NativeImageInvokerInfo build() {
nativeImageArgs.add("--report-unsupported-elements-at-runtime");
}
if (nativeConfig.reportExceptionStackTraces()) {
nativeImageArgs.add("-H:+ReportExceptionStackTraces");
addExperimentalVMOption(nativeImageArgs, "-H:+ReportExceptionStackTraces");
}
if (nativeConfig.debug().enabled()) {
nativeImageArgs.add("-g");
Expand Down Expand Up @@ -897,11 +898,11 @@ public NativeImageInvokerInfo build() {
}
}
if (nativeConfig.autoServiceLoaderRegistration()) {
nativeImageArgs.add("-H:+UseServiceLoaderFeature");
addExperimentalVMOption(nativeImageArgs, "-H:+UseServiceLoaderFeature");
//When enabling, at least print what exactly is being added:
nativeImageArgs.add("-H:+TraceServiceLoaderFeature");
} else {
nativeImageArgs.add("-H:-UseServiceLoaderFeature");
addExperimentalVMOption(nativeImageArgs, "-H:-UseServiceLoaderFeature");
}
// This option has no effect on GraalVM 23.1+
if (graalVMVersion.compareTo(GraalVM.Version.VERSION_23_1_0) < 0) {
Expand Down Expand Up @@ -1012,6 +1013,16 @@ private void handleAdditionalProperties(List<String> command) {
}
}
}

private void addExperimentalVMOption(List<String> nativeImageArgs, String option) {
if (graalVMVersion.compareTo(GraalVM.Version.VERSION_23_1_0) >= 0) {
nativeImageArgs.add("-H:+UnlockExperimentalVMOptions");
}
nativeImageArgs.add(option);
if (graalVMVersion.compareTo(GraalVM.Version.VERSION_23_1_0) >= 0) {
nativeImageArgs.add("-H:-UnlockExperimentalVMOptions");
}
}
}
}

Expand Down

0 comments on commit 1a1d4ea

Please sign in to comment.