From 89ff50f8ccac40e817fa4e0ebaca3c89612103dd Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Fri, 16 Sep 2022 09:20:28 +0300 Subject: [PATCH 1/3] Only use EnforceMaxRuntimeCompileMethods if LibGraal is present --- sdk/mx.sdk/mx_sdk_vm_impl.py | 3 ++- substratevm/mx.substratevm/mx_substratevm.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sdk/mx.sdk/mx_sdk_vm_impl.py b/sdk/mx.sdk/mx_sdk_vm_impl.py index 6639d1224d0e..e32c11b5479f 100644 --- a/sdk/mx.sdk/mx_sdk_vm_impl.py +++ b/sdk/mx.sdk/mx_sdk_vm_impl.py @@ -1308,9 +1308,10 @@ def contents(self): '--no-fallback', '-march=compatibility', # Target maximum portability of all GraalVM images. '-H:+AssertInitializationSpecifiedForAllClasses', - '-H:+EnforceMaxRuntimeCompileMethods', '-Dorg.graalvm.version={}'.format(_suite.release_version()), ] + if has_component('LibGraal'): + build_args += ['-H:+EnforceMaxRuntimeCompileMethods'] if _debug_images(): build_args += ['-ea', '-O0', '-H:+PreserveFramePointer', '-H:-DeleteLocalSymbols'] if _get_svm_support().generate_debug_info(image_config): diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index 710ed2a0a74c..eba5ca50430c 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -227,7 +227,9 @@ def vm_executable_path(executable, config=None): @contextmanager def native_image_context(common_args=None, hosted_assertions=True, native_image_cmd='', config=None, build_if_missing=False): common_args = [] if common_args is None else common_args - base_args = ['--no-fallback', '-H:+EnforceMaxRuntimeCompileMethods', '-H:+ReportExceptionStackTraces'] + base_args = ['--no-fallback', '-H:+ReportExceptionStackTraces'] + if mx_sdk_vm_impl.has_component('LibGraal'): + base_args += ['-H:+EnforceMaxRuntimeCompileMethods'] base_args += ['-H:Path=' + svmbuild_dir()] if mx.get_opts().verbose: base_args += ['--verbose'] From f7d522f461653c97556a381830f00ed106248471 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Fri, 16 Sep 2022 09:34:35 +0300 Subject: [PATCH 2/3] Make NativeImage driver's dependency on truffle jars optional --- .../src/com/oracle/svm/driver/NativeImage.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index fa4209c7fb86..b57c9e31fe95 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -544,7 +544,7 @@ public List getBuilderModulePath() { if (libJvmciDir != null) { result.addAll(getJars(libJvmciDir, "graal-sdk", "enterprise-graal")); } - result.addAll(getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-api", "truffle-compiler", "truffle-runtime", "truffle-enterprise")); + result.addAll(getJars(rootDir.resolve(Paths.get("lib", "truffle")), true, "truffle-api", "truffle-compiler", "truffle-runtime", "truffle-enterprise")); if (modulePathBuild) { result.addAll(getJars(rootDir.resolve(Paths.get("lib", "svm", "builder")))); } @@ -2044,6 +2044,10 @@ private static void show(Consumer printFunc, String message) { } protected static List getJars(Path dir, String... jarBaseNames) { + return getJars(dir, false, jarBaseNames); + } + + private static List getJars(Path dir, boolean optional, String... jarBaseNames) { try { List baseNameList = Arrays.asList(jarBaseNames); return Files.list(dir) @@ -2061,7 +2065,12 @@ protected static List getJars(Path dir, String... jarBaseNames) { }) .collect(Collectors.toList()); } catch (IOException e) { - throw showError("Unable to use jar-files from directory " + dir, e); + if (optional) { + LogUtils.warning("Unable to use jar-files from directory " + dir); + return Collections.emptyList(); + } else { + throw showError("Unable to use jar-files from directory " + dir, e); + } } } From 0a13043815bec03821ca0232f3fd8653ef5ed79b Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Mon, 19 Sep 2022 17:07:54 +0300 Subject: [PATCH 3/3] Introduce IsolatedTruffleCodeInstallBridge to avoid truffle dependency Implements `OptimizedAssumptionDependency` on top of `IsolatedCodeInstallBridge` in `com.oracle.svm.truffle` to avoid pulling truffle dependencies in `com.oracle.svm.graal`. --- .../isolated/IsolatedCodeInstallBridge.java | 17 +----- .../IsolatedCompilableTruffleAST.java | 3 +- .../IsolatedTruffleCodeInstallBridge.java | 55 +++++++++++++++++++ 3 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCodeInstallBridge.java diff --git a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCodeInstallBridge.java b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCodeInstallBridge.java index 5bea3b0063b1..41a15f0fe086 100644 --- a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCodeInstallBridge.java +++ b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCodeInstallBridge.java @@ -33,10 +33,9 @@ /** * A helper to pass information for installing code in the compilation client through a Truffle - * compilation. It does not implement {@link InstalledCode} or {@link OptimizedAssumptionDependency} - * in any meaningful way. + * compilation. It does not implement {@link InstalledCode} in any meaningful way. */ -public final class IsolatedCodeInstallBridge extends InstalledCode implements OptimizedAssumptionDependency { +public class IsolatedCodeInstallBridge extends InstalledCode { private final ClientHandle factoryHandle; private ClientHandle installedCodeHandle; @@ -58,7 +57,7 @@ public ClientHandle getSubstrateInstalledCodeH return installedCodeHandle; } - private static final String DO_NOT_CALL_REASON = IsolatedCodeInstallBridge.class.getSimpleName() + + protected static final String DO_NOT_CALL_REASON = IsolatedCodeInstallBridge.class.getSimpleName() + " only acts as an accessor for cross-isolate data. None of the implemented methods may be called."; @Override @@ -86,19 +85,9 @@ public byte[] getCode() { throw VMError.shouldNotReachHere(DO_NOT_CALL_REASON); } - @Override - public void onAssumptionInvalidated(Object source, CharSequence reason) { - throw VMError.shouldNotReachHere(DO_NOT_CALL_REASON); - } - @Override public Object executeVarargs(Object... args) { throw VMError.shouldNotReachHere(DO_NOT_CALL_REASON); } - @Override - public TruffleCompilable getCompilable() { - throw VMError.shouldNotReachHere(DO_NOT_CALL_REASON); - } - } diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java index 91bece15a676..1f11eea59a22 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java @@ -39,7 +39,6 @@ import com.oracle.svm.graal.isolated.ClientIsolateThread; import com.oracle.svm.graal.isolated.CompilerHandle; import com.oracle.svm.graal.isolated.CompilerIsolateThread; -import com.oracle.svm.graal.isolated.IsolatedCodeInstallBridge; import com.oracle.svm.graal.isolated.IsolatedCompileClient; import com.oracle.svm.graal.isolated.IsolatedCompileContext; import com.oracle.svm.graal.isolated.IsolatedObjectConstant; @@ -138,7 +137,7 @@ public SubstrateInstalledCode createSubstrateInstalledCode() { @Override public InstalledCode createPreliminaryInstalledCode() { - return new IsolatedCodeInstallBridge(handle); + return new IsolatedTruffleCodeInstallBridge(handle); } @Override diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCodeInstallBridge.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCodeInstallBridge.java new file mode 100644 index 000000000000..59e59bb66123 --- /dev/null +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCodeInstallBridge.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2022, Red Hat Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.truffle.isolated; + +import com.oracle.svm.core.deopt.SubstrateInstalledCode; +import com.oracle.svm.core.util.VMError; +import com.oracle.svm.graal.isolated.ClientHandle; +import com.oracle.svm.graal.isolated.IsolatedCodeInstallBridge; +import jdk.vm.ci.code.InstalledCode; +import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; +import org.graalvm.compiler.truffle.common.TruffleCompilable; + +/** + * A helper to pass information for installing code in the compilation client through a Truffle + * compilation. It does not implement {@link InstalledCode} or {@link OptimizedAssumptionDependency} + * in any meaningful way. + */ +public final class IsolatedTruffleCodeInstallBridge extends IsolatedCodeInstallBridge implements OptimizedAssumptionDependency { + public IsolatedTruffleCodeInstallBridge(ClientHandle factoryHandle) { + super(factoryHandle); + } + + @Override + public void onAssumptionInvalidated(Object source, CharSequence reason) { + throw VMError.shouldNotReachHere(DO_NOT_CALL_REASON); + } + + @Override + public TruffleCompilable getCompilable() { + throw VMError.shouldNotReachHere(DO_NOT_CALL_REASON); + } +}