diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java index f1151c262bc2c1..119ce96c17cad4 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java @@ -382,6 +382,17 @@ public static class Debug { @ConfigItem public boolean enableDashboardDump; + /** + * Instruct GraalVM / Mandrel to parse compiler graphs only once before static analysis. When false, compiler graphs + * are parsed once for the static analysis and once again for the AOT compilation. + * + * This is set to {@code false} by default because single parsing significantly increases memory usage at build time + * see https://github.com/oracle/graal/issues/3435 and + * https://github.com/graalvm/mandrel/issues/304#issuecomment-952070568 for more details. + */ + @ConfigItem(defaultValue = "false") + public boolean enableParseOnce; + /** * Supported Container runtimes */ 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 3ff25b1ea90438..67bc8f0996ebec 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 @@ -690,6 +690,10 @@ public NativeImageInvokerInfo build() { nativeImageArgs.add("-H:+DashboardAll"); } + if (!nativeConfig.enableParseOnce) { + nativeImageArgs.add("-H:-ParseOnce"); + } + if (nativeImageSecurityProviders != null && !nativeImageSecurityProviders.isEmpty()) { String additionalSecurityProviders = nativeImageSecurityProviders.stream() .map(p -> p.getSecurityProvider())