From 054236bef92044f08b35099ea93f1173c7bb7c31 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Thu, 19 Aug 2021 14:50:12 +0300 Subject: [PATCH 1/3] Re-enable single parsing of compiler graphs in native-image for 21.2 GraalVM 21.2-dev at some point introduced a new enhancement (enabled by default) to avoid parsing compiler graphs twice. This enhancement however results in increased memory usage at the moment (https://github.com/oracle/graal/issues/3435) which then results in Quarkus' Integration Test failures in CI. In GraalVM 21.2 this appears to no longer be an issue. --- .../io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java | 4 ---- 1 file changed, 4 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 75ba060b0e62c..bf8fd781618a3 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 @@ -713,10 +713,6 @@ public NativeImageInvokerInfo build() { } if (graalVMVersion.isNewerThan(GraalVM.Version.VERSION_21_1)) { - - // Disable single parsing of compiler graphs till https://github.com/oracle/graal/issues/3435 gets fixed - nativeImageArgs.add("-H:-ParseOnce"); - // AdditionalSecurityProviders if (nativeImageSecurityProviders != null && !nativeImageSecurityProviders.isEmpty()) { String additionalSecurityProviders = nativeImageSecurityProviders.stream() From 681d6fdaa1ab23a0c34841a1992912a62ddad908 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Fri, 24 Sep 2021 12:43:19 +0300 Subject: [PATCH 2/3] Enable InlineBeforeAnalysis by default Starting with GraalVM 21.3 InlineBeforeAnalysis is going to be enabled by default. This patch enables it for 21.2 as well. --- .../io/quarkus/deployment/pkg/NativeConfig.java | 2 +- .../io/quarkus/deployment/pkg/steps/GraalVM.java | 1 + .../pkg/steps/NativeImageBuildStep.java | 16 ++++++++-------- 3 files changed, 10 insertions(+), 9 deletions(-) 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 0ef6cd5a4c809..8af513280303a 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 @@ -42,7 +42,7 @@ public class NativeConfig { /** * If {@code -H:+InlineBeforeAnalysis} flag will be added to the native-image run */ - @ConfigItem + @ConfigItem(defaultValue = "true") public boolean inlineBeforeAnalysis; /** diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java index 748e598bc270e..609f93611a7e5 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java @@ -14,6 +14,7 @@ static final class Version implements Comparable { static final Version VERSION_20_3 = new Version("GraalVM 20.3", 20, 3, Distribution.ORACLE); static final Version VERSION_21_1 = new Version("GraalVM 21.1", 21, 1, Distribution.ORACLE); static final Version VERSION_21_2 = new Version("GraalVM 21.2", 21, 2, Distribution.ORACLE); + static final Version VERSION_21_3 = new Version("GraalVM 21.3", 21, 3, Distribution.ORACLE); static final Version MINIMUM = VERSION_20_3; static final Version CURRENT = VERSION_21_2; 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 bf8fd781618a3..38e9811ff5a30 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 @@ -578,7 +578,7 @@ public NativeImageInvokerInfo build() { } else if (prop.getKey().equals("quarkus.native.enable-all-charsets") && prop.getValue() != null) { addAllCharsets |= Boolean.parseBoolean(prop.getValue()); } else if (prop.getKey().equals("quarkus.native.inline-before-analysis") && prop.getValue() != null) { - inlineBeforeAnalysis |= Boolean.parseBoolean(prop.getValue()); + inlineBeforeAnalysis = Boolean.parseBoolean(prop.getValue()); } else { // todo maybe just -D is better than -J-D in this case if (prop.getValue() == null) { @@ -661,14 +661,14 @@ public NativeImageInvokerInfo build() { // This option was removed in GraalVM 21.1 https://github.com/oracle/graal/pull/3258 nativeImageArgs.add("--enable-all-security-services"); } - if (inlineBeforeAnalysis) { - if (graalVMVersion.isNewerThan(GraalVM.Version.VERSION_20_3)) { - nativeImageArgs.add("-H:+InlineBeforeAnalysis"); + if (graalVMVersion.isNewerThan(GraalVM.Version.VERSION_20_3)) { + if (inlineBeforeAnalysis) { + if (graalVMVersion.isOlderThan(GraalVM.Version.VERSION_21_3)) { + // Enabled by default in GraalVM >= 21.3 + nativeImageArgs.add("-H:+InlineBeforeAnalysis"); + } } else { - log.warn( - "The InlineBeforeAnalysis feature is not supported in GraalVM versions prior to 21.0.0." - + " InlineBeforeAnalysis will thus not be enabled, please consider using a newer" - + " GraalVM version if your application relies on this feature."); + nativeImageArgs.add("-H:-InlineBeforeAnalysis"); } } if (!noPIE.isEmpty()) { From b9e22a5560015552371a53f640f1761f5d847104 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Tue, 28 Sep 2021 13:41:27 +0300 Subject: [PATCH 3/3] Prevent GraalVM from figuring out the method name through inlining --- .../quarkus/jdbc/postgresql/runtime/graal/DomHelper.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/graal/DomHelper.java b/extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/graal/DomHelper.java index d62191f3b3f24..e4a25bdcf7c58 100644 --- a/extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/graal/DomHelper.java +++ b/extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/graal/DomHelper.java @@ -18,6 +18,8 @@ import org.postgresql.xml.DefaultPGXmlFactoryFactory; import org.postgresql.xml.PGXmlFactoryFactory; +import com.oracle.svm.core.annotate.NeverInline; + /** * Used by PgSQLXML: easier to keep the actual code separated from the substitutions. */ @@ -48,10 +50,9 @@ public static String maybeProcessAsDomResult(DOMResult domResult, BaseConnection } } - //When GraalVM can figure out a constant name for the target method to be invoked reflectively, - //it automatically registers it for reflection. We don't want that to happen in this particular case. + @NeverInline("Prevent GraalVM from figuring out the target method to be invoked reflectively, so that it can't automatically register it for reflection") private static String obfuscatedMethodName() { - return "reallyProcessDom" + "Result"; + return "reallyProcessDomResult"; } public static String reallyProcessDomResult(DOMResult domResult, BaseConnection conn) throws SQLException {