[GR-58093] Add Truffle gate using oraclejdk.

PullRequest: graal/18795
This commit is contained in:
Tomáš Zezula 2024-09-24 07:51:34 +00:00
commit 8798480a8c
6 changed files with 71 additions and 28 deletions

View File

@ -57,6 +57,8 @@ local common_json = import "../common.json";
} + { } + {
[name]: jdk_base + common_json.jdks[name] + { jdk_version:: 21 } [name]: jdk_base + common_json.jdks[name] + { jdk_version:: 21 }
for name in ["oraclejdk21"] + variants("labsjdk-ce-21") + variants("labsjdk-ee-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"} [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") for name in ["oraclejdk-latest"] + variants("labsjdk-ce-latest") + variants("labsjdk-ee-latest")

View File

@ -45,6 +45,8 @@
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21.0.2+13-jvmci-23.1-b33-sulong", "platformspecific": true }, "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 }, "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"]}, "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-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 }, "labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-24+15-jvmci-b01-debug", "platformspecific": true },

View File

@ -264,11 +264,20 @@ class GraalVMJDKConfig(mx.JDKConfig):
""" """
def __init__(self): def __init__(self):
default_jdk = mx.get_jdk(tag='default') 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 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: else:
graalvm_home = mx_sdk_vm.graalvm_home(fatalIfMissing=True) graalvm_home = mx_sdk_vm.graalvm_home(fatalIfMissing=True)
additional_vm_args = []
self._home_internal = graalvm_home self._home_internal = graalvm_home
self._vm_args = additional_vm_args
mx.JDKConfig.__init__(self, graalvm_home, tag='graalvm') mx.JDKConfig.__init__(self, graalvm_home, tag='graalvm')
@property @property
@ -279,8 +288,14 @@ class GraalVMJDKConfig(mx.JDKConfig):
def home(self, home): def home(self, home):
return 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 @staticmethod
def _is_graalvm(java_home): def is_graalvm(java_home):
release_file = os.path.join(java_home, 'release') release_file = os.path.join(java_home, 'release')
if not os.path.isfile(release_file): if not os.path.isfile(release_file):
return False return False
@ -290,6 +305,18 @@ class GraalVMJDKConfig(mx.JDKConfig):
return True return True
return False 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): class GraalVMJDK(mx.JDKFactory):
def getJDKConfig(self): def getJDKConfig(self):

View File

@ -227,7 +227,7 @@ class TruffleUnittestConfig(mx_unittest.MxUnittestConfig):
# Disable VirtualThread warning # Disable VirtualThread warning
vmArgs = vmArgs + ['-Dpolyglot.engine.WarnVirtualThreadSupport=false'] 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. # Ignore illegal native access until is GR-57817 fixed.
vmArgs = vmArgs + ['--illegal-native-access=allow'] 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 # revisit once GR-57817 is fixed
vm_args += ["--enable-native-access=org.graalvm.truffle.runtime"] 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): def slnative(args):
@ -699,7 +699,7 @@ def _sl_jvm_gate_tests(jdk, force_cp=False, supports_optimization=True):
def _sl_jvm_comiler_on_upgrade_module_path_gate_tests(jdk): 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 # 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') mx.log(f'Ignoring SL JVM Optimized with Compiler on Upgrade Module Path on {jdk.home} because JDK is GraalVM')
return return
@ -900,16 +900,6 @@ mx.update_commands(_suite, {
'slnative': [slnative, '[--target-folder <folder>|SL args|@VM options]'], 'slnative': [slnative, '[--target-folder <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 _collect_distributions(dist_filter, dist_collector):
def import_visitor(suite, suite_import, predicate, collector, seenSuites, **extra_args): def import_visitor(suite, suite_import, predicate, collector, seenSuites, **extra_args):
suite_collector(mx.suite(suite_import.name), predicate, collector, seenSuites) suite_collector(mx.suite(suite_import.name), predicate, collector, seenSuites)
@ -1135,7 +1125,7 @@ def tck(args):
jdk = mx.get_jdk(tag='graalvm') jdk = mx.get_jdk(tag='graalvm')
else: else:
jdk = mx.get_jdk() 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, " mx.abort("The 'compile' TCK configuration requires graalvm execution, "
"run with --java-home=<path_to_graalvm> or run with --use-graalvm.") "run with --java-home=<path_to_graalvm> or run with --use-graalvm.")
compileOptions = [ compileOptions = [

View File

@ -46,7 +46,10 @@ import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import org.graalvm.collections.EconomicMap;
import org.graalvm.nativeimage.ImageInfo;
import org.graalvm.polyglot.Engine; import org.graalvm.polyglot.Engine;
import org.graalvm.word.WordFactory;
import org.junit.After; import org.junit.After;
import org.junit.Assume; import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
@ -72,18 +75,27 @@ public class SeparatedClassLoadersTest {
@Test @Test
public void sdkAndTruffleAPIInSeparateClassLoaders() throws Exception { public void sdkAndTruffleAPIInSeparateClassLoaders() throws Exception {
final ProtectionDomain sdkDomain = Engine.class.getProtectionDomain(); final ProtectionDomain polyglotDomain = Engine.class.getProtectionDomain();
Assume.assumeNotNull(sdkDomain); Assume.assumeNotNull(polyglotDomain);
Assume.assumeNotNull(sdkDomain.getCodeSource()); Assume.assumeNotNull(polyglotDomain.getCodeSource());
URL sdkURL = sdkDomain.getCodeSource().getLocation(); URL polyglotURL = polyglotDomain.getCodeSource().getLocation();
Assume.assumeNotNull(sdkURL); 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(); URL truffleURL = Truffle.class.getProtectionDomain().getCodeSource().getLocation();
Assume.assumeNotNull(truffleURL); Assume.assumeNotNull(truffleURL);
ClassLoader parent = Engine.class.getClassLoader().getParent(); 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); URLClassLoader truffleLoader = new URLClassLoader(new URL[]{truffleURL}, sdkLoader);
Thread.currentThread().setContextClassLoader(truffleLoader); Thread.currentThread().setContextClassLoader(truffleLoader);

View File

@ -48,6 +48,7 @@ import java.security.ProtectionDomain;
import java.util.Map; import java.util.Map;
import org.graalvm.polyglot.Engine; import org.graalvm.polyglot.Engine;
import org.graalvm.word.WordFactory;
import org.junit.After; import org.junit.After;
import org.junit.Assume; import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
@ -66,11 +67,20 @@ public class SLSeparatedClassLoadersTest {
@Test @Test
public void sdkAndTruffleLanguageAPIAndSLInSeparateClassLoaders() throws Exception { public void sdkAndTruffleLanguageAPIAndSLInSeparateClassLoaders() throws Exception {
final ProtectionDomain sdkDomain = Engine.class.getProtectionDomain(); final ProtectionDomain polyglotDomain = Engine.class.getProtectionDomain();
Assume.assumeNotNull(sdkDomain); Assume.assumeNotNull(polyglotDomain);
Assume.assumeNotNull(sdkDomain.getCodeSource()); Assume.assumeNotNull(polyglotDomain.getCodeSource());
URL sdkURL = sdkDomain.getCodeSource().getLocation(); URL polyglotURL = polyglotDomain.getCodeSource().getLocation();
Assume.assumeNotNull(sdkURL); 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(); URL truffleURL = Truffle.class.getProtectionDomain().getCodeSource().getLocation();
Assume.assumeNotNull(truffleURL); Assume.assumeNotNull(truffleURL);
@ -80,7 +90,7 @@ public class SLSeparatedClassLoadersTest {
ClassLoader parent = Engine.class.getClassLoader().getParent(); 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; boolean sdkLoaderLoadsTruffleLanguage;
try { try {
Class.forName("com.oracle.truffle.api.TruffleLanguage", false, sdkLoader); Class.forName("com.oracle.truffle.api.TruffleLanguage", false, sdkLoader);