From d46ba14b15a14d946eb70b79a68c3be1d1beb703 Mon Sep 17 00:00:00 2001 From: Tomas Zezula Date: Wed, 11 Sep 2024 15:43:46 +0200 Subject: [PATCH] [GR-58093] Add Truffle gate using oraclejdk. --- ci/common.jsonnet | 2 ++ common.json | 2 ++ sdk/mx.sdk/mx_sdk.py | 31 +++++++++++++++++-- truffle/mx.truffle/mx_truffle.py | 18 +++-------- .../polyglot/SeparatedClassLoadersTest.java | 24 ++++++++++---- .../sl/test/SLSeparatedClassLoadersTest.java | 22 +++++++++---- 6 files changed, 71 insertions(+), 28 deletions(-) diff --git a/ci/common.jsonnet b/ci/common.jsonnet index 81c47e572007..33b535209c9f 100644 --- a/ci/common.jsonnet +++ b/ci/common.jsonnet @@ -57,6 +57,8 @@ local common_json = import "../common.json"; } + { [name]: jdk_base + common_json.jdks[name] + { jdk_version:: 21 } for name in ["oraclejdk21"] + variants("labsjdk-ce-21") + variants("labsjdk-ee-21") + } + { + 'oraclejdk23': jdk_base + common_json.jdks["oraclejdk23"] + { jdk_version:: 23 }, } + { [name]: jdk_base + common_json.jdks[name] + { jdk_version:: parse_labsjdk_version(self), jdk_name:: "jdk-latest"} for name in ["oraclejdk-latest"] + variants("labsjdk-ce-latest") + variants("labsjdk-ee-latest") diff --git a/common.json b/common.json index 63a86b4d4460..e10a1a48cd24 100644 --- a/common.json +++ b/common.json @@ -45,6 +45,8 @@ "labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21.0.2+13-jvmci-23.1-b33-sulong", "platformspecific": true }, "graalvm-ee-21": {"name": "graalvm-java21", "version": "23.1.3", "platformspecific": true }, + "oraclejdk23": {"name": "jpg-jdk", "version": "23", "build_id": "jdk-23+37", "platformspecific": true, "extrabundles": ["static-libs"]}, + "oraclejdk-latest": {"name": "jpg-jdk", "version": "24", "build_id": "jdk-24+15", "platformspecific": true, "extrabundles": ["static-libs"]}, "labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-24+15-jvmci-b01", "platformspecific": true }, "labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-24+15-jvmci-b01-debug", "platformspecific": true }, diff --git a/sdk/mx.sdk/mx_sdk.py b/sdk/mx.sdk/mx_sdk.py index b2808b2f2619..677669bc82a9 100644 --- a/sdk/mx.sdk/mx_sdk.py +++ b/sdk/mx.sdk/mx_sdk.py @@ -264,11 +264,20 @@ class GraalVMJDKConfig(mx.JDKConfig): """ def __init__(self): default_jdk = mx.get_jdk(tag='default') - if GraalVMJDKConfig._is_graalvm(default_jdk.home): + if GraalVMJDKConfig.is_graalvm(default_jdk.home): graalvm_home = default_jdk.home + additional_vm_args = [] + elif GraalVMJDKConfig.is_libgraal_jdk(default_jdk.home): + # Oracle JDK includes the libjvmci compiler, allowing it to function as GraalVM. + # However, the Graal compiler is disabled by default and must be explicitly enabled using the -XX:+UseJVMCICompiler option. + graalvm_home = default_jdk.home + # GR-58388: Switch '-XX:+UseJVMCINativeLibrary' to '-XX:+UseGraalJIT' + additional_vm_args = ['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCI', '-XX:+UseJVMCINativeLibrary', '-XX:-UnlockExperimentalVMOptions'] else: graalvm_home = mx_sdk_vm.graalvm_home(fatalIfMissing=True) + additional_vm_args = [] self._home_internal = graalvm_home + self._vm_args = additional_vm_args mx.JDKConfig.__init__(self, graalvm_home, tag='graalvm') @property @@ -279,8 +288,14 @@ def home(self): def home(self, home): return + def processArgs(self, args, addDefaultArgs=True): + processed_args = super(GraalVMJDKConfig, self).processArgs(args, addDefaultArgs) + if addDefaultArgs and self._vm_args: + processed_args = self._vm_args + processed_args + return processed_args + @staticmethod - def _is_graalvm(java_home): + def is_graalvm(java_home): release_file = os.path.join(java_home, 'release') if not os.path.isfile(release_file): return False @@ -290,6 +305,18 @@ def _is_graalvm(java_home): return True return False + @staticmethod + def is_libgraal_jdk(java_home): + release_file = os.path.join(java_home, 'release') + if not os.path.isfile(release_file): + return False + with open(release_file, 'r') as file: + for line in file: + if line.startswith('MODULES') and 'jdk.graal.compiler.lib' in line: + # Oracle JDK has libjvmcicompiler + return True + return False + class GraalVMJDK(mx.JDKFactory): def getJDKConfig(self): diff --git a/truffle/mx.truffle/mx_truffle.py b/truffle/mx.truffle/mx_truffle.py index 1dcaf21e64af..d4050dd5a6dc 100644 --- a/truffle/mx.truffle/mx_truffle.py +++ b/truffle/mx.truffle/mx_truffle.py @@ -227,7 +227,7 @@ def apply(self, config): # Disable VirtualThread warning vmArgs = vmArgs + ['-Dpolyglot.engine.WarnVirtualThreadSupport=false'] - if mx.get_jdk().javaCompliance > '21': + if mx.get_jdk().javaCompliance > '23': # Ignore illegal native access until is GR-57817 fixed. vmArgs = vmArgs + ['--illegal-native-access=allow'] @@ -376,7 +376,7 @@ def _sl_command(jdk, vm_args, sl_args, use_optimized_runtime=True, use_enterpris # revisit once GR-57817 is fixed vm_args += ["--enable-native-access=org.graalvm.truffle.runtime"] - return [jdk.java] + vm_args + mx.get_runtime_jvm_args(names=dist_names, force_cp=force_cp) + main_class + sl_args + return [jdk.java] + jdk.processArgs(vm_args + mx.get_runtime_jvm_args(names=dist_names, force_cp=force_cp) + main_class + sl_args) def slnative(args): @@ -699,7 +699,7 @@ def run_jvm_no_enterprise_jvmci_disabled(test_file): def _sl_jvm_comiler_on_upgrade_module_path_gate_tests(jdk): - if _is_graalvm(jdk): + if mx_sdk.GraalVMJDKConfig.is_graalvm(jdk.home) or mx_sdk.GraalVMJDKConfig.is_libgraal_jdk(jdk.home): # Ignore tests for Truffle LTS gate using GraalVM as a base JDK mx.log(f'Ignoring SL JVM Optimized with Compiler on Upgrade Module Path on {jdk.home} because JDK is GraalVM') return @@ -900,16 +900,6 @@ def _truffle_gate_state_bitwidth_tests(): 'slnative': [slnative, '[--target-folder |SL args|@VM options]'], }) -def _is_graalvm(jdk): - releaseFile = os.path.join(jdk.home, "release") - if exists(releaseFile): - with open(releaseFile) as f: - pattern = re.compile('^GRAALVM_VERSION=*') - for line in f.readlines(): - if pattern.match(line): - return True - return False - def _collect_distributions(dist_filter, dist_collector): def import_visitor(suite, suite_import, predicate, collector, seenSuites, **extra_args): suite_collector(mx.suite(suite_import.name), predicate, collector, seenSuites) @@ -1135,7 +1125,7 @@ def tck(args): jdk = mx.get_jdk(tag='graalvm') else: jdk = mx.get_jdk() - if not _is_graalvm(jdk): + if not mx_sdk.GraalVMJDKConfig.is_graalvm(jdk.home): mx.abort("The 'compile' TCK configuration requires graalvm execution, " "run with --java-home= or run with --use-graalvm.") compileOptions = [ diff --git a/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/SeparatedClassLoadersTest.java b/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/SeparatedClassLoadersTest.java index cc2169328034..745b0aafc1b6 100644 --- a/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/SeparatedClassLoadersTest.java +++ b/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/SeparatedClassLoadersTest.java @@ -46,7 +46,10 @@ import java.net.URLClassLoader; import java.security.ProtectionDomain; +import org.graalvm.collections.EconomicMap; +import org.graalvm.nativeimage.ImageInfo; import org.graalvm.polyglot.Engine; +import org.graalvm.word.WordFactory; import org.junit.After; import org.junit.Assume; import org.junit.Before; @@ -72,18 +75,27 @@ public void storeLoader() { @Test public void sdkAndTruffleAPIInSeparateClassLoaders() throws Exception { - final ProtectionDomain sdkDomain = Engine.class.getProtectionDomain(); - Assume.assumeNotNull(sdkDomain); - Assume.assumeNotNull(sdkDomain.getCodeSource()); - URL sdkURL = sdkDomain.getCodeSource().getLocation(); - Assume.assumeNotNull(sdkURL); + final ProtectionDomain polyglotDomain = Engine.class.getProtectionDomain(); + Assume.assumeNotNull(polyglotDomain); + Assume.assumeNotNull(polyglotDomain.getCodeSource()); + URL polyglotURL = polyglotDomain.getCodeSource().getLocation(); + Assume.assumeNotNull(polyglotURL); + + URL collectionsURL = EconomicMap.class.getProtectionDomain().getCodeSource().getLocation(); + Assume.assumeNotNull(collectionsURL); + + URL wordURL = WordFactory.class.getProtectionDomain().getCodeSource().getLocation(); + Assume.assumeNotNull(wordURL); + + URL nativeURL = ImageInfo.class.getProtectionDomain().getCodeSource().getLocation(); + Assume.assumeNotNull(nativeURL); URL truffleURL = Truffle.class.getProtectionDomain().getCodeSource().getLocation(); Assume.assumeNotNull(truffleURL); ClassLoader parent = Engine.class.getClassLoader().getParent(); - URLClassLoader sdkLoader = new URLClassLoader(new URL[]{sdkURL}, parent); + URLClassLoader sdkLoader = new URLClassLoader(new URL[]{collectionsURL, wordURL, nativeURL, polyglotURL}, parent); URLClassLoader truffleLoader = new URLClassLoader(new URL[]{truffleURL}, sdkLoader); Thread.currentThread().setContextClassLoader(truffleLoader); diff --git a/truffle/src/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLSeparatedClassLoadersTest.java b/truffle/src/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLSeparatedClassLoadersTest.java index 0a650ea29096..571b6945d924 100644 --- a/truffle/src/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLSeparatedClassLoadersTest.java +++ b/truffle/src/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLSeparatedClassLoadersTest.java @@ -48,6 +48,7 @@ import java.util.Map; import org.graalvm.polyglot.Engine; +import org.graalvm.word.WordFactory; import org.junit.After; import org.junit.Assume; import org.junit.Before; @@ -66,11 +67,20 @@ public void storeLoader() { @Test public void sdkAndTruffleLanguageAPIAndSLInSeparateClassLoaders() throws Exception { - final ProtectionDomain sdkDomain = Engine.class.getProtectionDomain(); - Assume.assumeNotNull(sdkDomain); - Assume.assumeNotNull(sdkDomain.getCodeSource()); - URL sdkURL = sdkDomain.getCodeSource().getLocation(); - Assume.assumeNotNull(sdkURL); + final ProtectionDomain polyglotDomain = Engine.class.getProtectionDomain(); + Assume.assumeNotNull(polyglotDomain); + Assume.assumeNotNull(polyglotDomain.getCodeSource()); + URL polyglotURL = polyglotDomain.getCodeSource().getLocation(); + Assume.assumeNotNull(polyglotURL); + + URL collectionsURL = Class.forName("org.graalvm.collections.EconomicMap").getProtectionDomain().getCodeSource().getLocation(); + Assume.assumeNotNull(collectionsURL); + + URL wordURL = WordFactory.class.getProtectionDomain().getCodeSource().getLocation(); + Assume.assumeNotNull(wordURL); + + URL nativeURL = Class.forName("org.graalvm.nativeimage.ImageInfo").getProtectionDomain().getCodeSource().getLocation(); + Assume.assumeNotNull(nativeURL); URL truffleURL = Truffle.class.getProtectionDomain().getCodeSource().getLocation(); Assume.assumeNotNull(truffleURL); @@ -80,7 +90,7 @@ public void sdkAndTruffleLanguageAPIAndSLInSeparateClassLoaders() throws Excepti ClassLoader parent = Engine.class.getClassLoader().getParent(); - URLClassLoader sdkLoader = new URLClassLoader(new URL[]{sdkURL}, parent); + URLClassLoader sdkLoader = new URLClassLoader(new URL[]{collectionsURL, wordURL, nativeURL, polyglotURL}, parent); boolean sdkLoaderLoadsTruffleLanguage; try { Class.forName("com.oracle.truffle.api.TruffleLanguage", false, sdkLoader);