From 1a1d4ea9148893ac4f4821ba6a4d79abc991217a Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Wed, 16 Aug 2023 17:51:17 +0300 Subject: [PATCH] Pass -H:+UnlockExperimentalVMOptions as necessary with Graalvm 23.1 Needed since https://github.com/oracle/graal/pull/7190 to avoid warnings --- .../pkg/steps/NativeImageBuildStep.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index 9734fa89d4de3..1995c8d6b0533 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -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"); } /* @@ -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"); @@ -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"); @@ -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) { @@ -1012,6 +1013,16 @@ private void handleAdditionalProperties(List command) { } } } + + private void addExperimentalVMOption(List 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"); + } + } } }