Skip to content

Commit

Permalink
[GR-58093] Add Truffle gate using oraclejdk.
Browse files Browse the repository at this point in the history
PullRequest: graal/18795
  • Loading branch information
tzezula committed Sep 24, 2024
2 parents a727752 + d46ba14 commit 8798480
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 28 deletions.
2 changes: 2 additions & 0 deletions ci/common.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
31 changes: 29 additions & 2 deletions sdk/mx.sdk/mx_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down
18 changes: 4 additions & 14 deletions truffle/mx.truffle/mx_truffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -900,16 +900,6 @@ def _truffle_gate_state_bitwidth_tests():
'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 import_visitor(suite, suite_import, predicate, collector, seenSuites, **extra_args):
suite_collector(mx.suite(suite_import.name), predicate, collector, seenSuites)
Expand Down Expand Up @@ -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=<path_to_graalvm> or run with --use-graalvm.")
compileOptions = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 8798480

Please sign in to comment.