Skip to content

Commit 8798480

Browse files
committed
[GR-58093] Add Truffle gate using oraclejdk.
PullRequest: graal/18795
2 parents a727752 + d46ba14 commit 8798480

File tree

6 files changed

+71
-28
lines changed

6 files changed

+71
-28
lines changed

ci/common.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ local common_json = import "../common.json";
5757
} + {
5858
[name]: jdk_base + common_json.jdks[name] + { jdk_version:: 21 }
5959
for name in ["oraclejdk21"] + variants("labsjdk-ce-21") + variants("labsjdk-ee-21")
60+
} + {
61+
'oraclejdk23': jdk_base + common_json.jdks["oraclejdk23"] + { jdk_version:: 23 },
6062
} + {
6163
[name]: jdk_base + common_json.jdks[name] + { jdk_version:: parse_labsjdk_version(self), jdk_name:: "jdk-latest"}
6264
for name in ["oraclejdk-latest"] + variants("labsjdk-ce-latest") + variants("labsjdk-ee-latest")

common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21.0.2+13-jvmci-23.1-b33-sulong", "platformspecific": true },
4646
"graalvm-ee-21": {"name": "graalvm-java21", "version": "23.1.3", "platformspecific": true },
4747

48+
"oraclejdk23": {"name": "jpg-jdk", "version": "23", "build_id": "jdk-23+37", "platformspecific": true, "extrabundles": ["static-libs"]},
49+
4850
"oraclejdk-latest": {"name": "jpg-jdk", "version": "24", "build_id": "jdk-24+15", "platformspecific": true, "extrabundles": ["static-libs"]},
4951
"labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-24+15-jvmci-b01", "platformspecific": true },
5052
"labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-24+15-jvmci-b01-debug", "platformspecific": true },

sdk/mx.sdk/mx_sdk.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,20 @@ class GraalVMJDKConfig(mx.JDKConfig):
264264
"""
265265
def __init__(self):
266266
default_jdk = mx.get_jdk(tag='default')
267-
if GraalVMJDKConfig._is_graalvm(default_jdk.home):
267+
if GraalVMJDKConfig.is_graalvm(default_jdk.home):
268268
graalvm_home = default_jdk.home
269+
additional_vm_args = []
270+
elif GraalVMJDKConfig.is_libgraal_jdk(default_jdk.home):
271+
# Oracle JDK includes the libjvmci compiler, allowing it to function as GraalVM.
272+
# However, the Graal compiler is disabled by default and must be explicitly enabled using the -XX:+UseJVMCICompiler option.
273+
graalvm_home = default_jdk.home
274+
# GR-58388: Switch '-XX:+UseJVMCINativeLibrary' to '-XX:+UseGraalJIT'
275+
additional_vm_args = ['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCI', '-XX:+UseJVMCINativeLibrary', '-XX:-UnlockExperimentalVMOptions']
269276
else:
270277
graalvm_home = mx_sdk_vm.graalvm_home(fatalIfMissing=True)
278+
additional_vm_args = []
271279
self._home_internal = graalvm_home
280+
self._vm_args = additional_vm_args
272281
mx.JDKConfig.__init__(self, graalvm_home, tag='graalvm')
273282

274283
@property
@@ -279,8 +288,14 @@ def home(self):
279288
def home(self, home):
280289
return
281290

291+
def processArgs(self, args, addDefaultArgs=True):
292+
processed_args = super(GraalVMJDKConfig, self).processArgs(args, addDefaultArgs)
293+
if addDefaultArgs and self._vm_args:
294+
processed_args = self._vm_args + processed_args
295+
return processed_args
296+
282297
@staticmethod
283-
def _is_graalvm(java_home):
298+
def is_graalvm(java_home):
284299
release_file = os.path.join(java_home, 'release')
285300
if not os.path.isfile(release_file):
286301
return False
@@ -290,6 +305,18 @@ def _is_graalvm(java_home):
290305
return True
291306
return False
292307

308+
@staticmethod
309+
def is_libgraal_jdk(java_home):
310+
release_file = os.path.join(java_home, 'release')
311+
if not os.path.isfile(release_file):
312+
return False
313+
with open(release_file, 'r') as file:
314+
for line in file:
315+
if line.startswith('MODULES') and 'jdk.graal.compiler.lib' in line:
316+
# Oracle JDK has libjvmcicompiler
317+
return True
318+
return False
319+
293320
class GraalVMJDK(mx.JDKFactory):
294321

295322
def getJDKConfig(self):

truffle/mx.truffle/mx_truffle.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def apply(self, config):
227227

228228
# Disable VirtualThread warning
229229
vmArgs = vmArgs + ['-Dpolyglot.engine.WarnVirtualThreadSupport=false']
230-
if mx.get_jdk().javaCompliance > '21':
230+
if mx.get_jdk().javaCompliance > '23':
231231
# Ignore illegal native access until is GR-57817 fixed.
232232
vmArgs = vmArgs + ['--illegal-native-access=allow']
233233

@@ -376,7 +376,7 @@ def _sl_command(jdk, vm_args, sl_args, use_optimized_runtime=True, use_enterpris
376376
# revisit once GR-57817 is fixed
377377
vm_args += ["--enable-native-access=org.graalvm.truffle.runtime"]
378378

379-
return [jdk.java] + vm_args + mx.get_runtime_jvm_args(names=dist_names, force_cp=force_cp) + main_class + sl_args
379+
return [jdk.java] + jdk.processArgs(vm_args + mx.get_runtime_jvm_args(names=dist_names, force_cp=force_cp) + main_class + sl_args)
380380

381381

382382
def slnative(args):
@@ -699,7 +699,7 @@ def run_jvm_no_enterprise_jvmci_disabled(test_file):
699699

700700

701701
def _sl_jvm_comiler_on_upgrade_module_path_gate_tests(jdk):
702-
if _is_graalvm(jdk):
702+
if mx_sdk.GraalVMJDKConfig.is_graalvm(jdk.home) or mx_sdk.GraalVMJDKConfig.is_libgraal_jdk(jdk.home):
703703
# Ignore tests for Truffle LTS gate using GraalVM as a base JDK
704704
mx.log(f'Ignoring SL JVM Optimized with Compiler on Upgrade Module Path on {jdk.home} because JDK is GraalVM')
705705
return
@@ -900,16 +900,6 @@ def _truffle_gate_state_bitwidth_tests():
900900
'slnative': [slnative, '[--target-folder <folder>|SL args|@VM options]'],
901901
})
902902

903-
def _is_graalvm(jdk):
904-
releaseFile = os.path.join(jdk.home, "release")
905-
if exists(releaseFile):
906-
with open(releaseFile) as f:
907-
pattern = re.compile('^GRAALVM_VERSION=*')
908-
for line in f.readlines():
909-
if pattern.match(line):
910-
return True
911-
return False
912-
913903
def _collect_distributions(dist_filter, dist_collector):
914904
def import_visitor(suite, suite_import, predicate, collector, seenSuites, **extra_args):
915905
suite_collector(mx.suite(suite_import.name), predicate, collector, seenSuites)
@@ -1135,7 +1125,7 @@ def tck(args):
11351125
jdk = mx.get_jdk(tag='graalvm')
11361126
else:
11371127
jdk = mx.get_jdk()
1138-
if not _is_graalvm(jdk):
1128+
if not mx_sdk.GraalVMJDKConfig.is_graalvm(jdk.home):
11391129
mx.abort("The 'compile' TCK configuration requires graalvm execution, "
11401130
"run with --java-home=<path_to_graalvm> or run with --use-graalvm.")
11411131
compileOptions = [

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/SeparatedClassLoadersTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
import java.net.URLClassLoader;
4747
import java.security.ProtectionDomain;
4848

49+
import org.graalvm.collections.EconomicMap;
50+
import org.graalvm.nativeimage.ImageInfo;
4951
import org.graalvm.polyglot.Engine;
52+
import org.graalvm.word.WordFactory;
5053
import org.junit.After;
5154
import org.junit.Assume;
5255
import org.junit.Before;
@@ -72,18 +75,27 @@ public void storeLoader() {
7275

7376
@Test
7477
public void sdkAndTruffleAPIInSeparateClassLoaders() throws Exception {
75-
final ProtectionDomain sdkDomain = Engine.class.getProtectionDomain();
76-
Assume.assumeNotNull(sdkDomain);
77-
Assume.assumeNotNull(sdkDomain.getCodeSource());
78-
URL sdkURL = sdkDomain.getCodeSource().getLocation();
79-
Assume.assumeNotNull(sdkURL);
78+
final ProtectionDomain polyglotDomain = Engine.class.getProtectionDomain();
79+
Assume.assumeNotNull(polyglotDomain);
80+
Assume.assumeNotNull(polyglotDomain.getCodeSource());
81+
URL polyglotURL = polyglotDomain.getCodeSource().getLocation();
82+
Assume.assumeNotNull(polyglotURL);
83+
84+
URL collectionsURL = EconomicMap.class.getProtectionDomain().getCodeSource().getLocation();
85+
Assume.assumeNotNull(collectionsURL);
86+
87+
URL wordURL = WordFactory.class.getProtectionDomain().getCodeSource().getLocation();
88+
Assume.assumeNotNull(wordURL);
89+
90+
URL nativeURL = ImageInfo.class.getProtectionDomain().getCodeSource().getLocation();
91+
Assume.assumeNotNull(nativeURL);
8092

8193
URL truffleURL = Truffle.class.getProtectionDomain().getCodeSource().getLocation();
8294
Assume.assumeNotNull(truffleURL);
8395

8496
ClassLoader parent = Engine.class.getClassLoader().getParent();
8597

86-
URLClassLoader sdkLoader = new URLClassLoader(new URL[]{sdkURL}, parent);
98+
URLClassLoader sdkLoader = new URLClassLoader(new URL[]{collectionsURL, wordURL, nativeURL, polyglotURL}, parent);
8799
URLClassLoader truffleLoader = new URLClassLoader(new URL[]{truffleURL}, sdkLoader);
88100
Thread.currentThread().setContextClassLoader(truffleLoader);
89101

truffle/src/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLSeparatedClassLoadersTest.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.Map;
4949

5050
import org.graalvm.polyglot.Engine;
51+
import org.graalvm.word.WordFactory;
5152
import org.junit.After;
5253
import org.junit.Assume;
5354
import org.junit.Before;
@@ -66,11 +67,20 @@ public void storeLoader() {
6667

6768
@Test
6869
public void sdkAndTruffleLanguageAPIAndSLInSeparateClassLoaders() throws Exception {
69-
final ProtectionDomain sdkDomain = Engine.class.getProtectionDomain();
70-
Assume.assumeNotNull(sdkDomain);
71-
Assume.assumeNotNull(sdkDomain.getCodeSource());
72-
URL sdkURL = sdkDomain.getCodeSource().getLocation();
73-
Assume.assumeNotNull(sdkURL);
70+
final ProtectionDomain polyglotDomain = Engine.class.getProtectionDomain();
71+
Assume.assumeNotNull(polyglotDomain);
72+
Assume.assumeNotNull(polyglotDomain.getCodeSource());
73+
URL polyglotURL = polyglotDomain.getCodeSource().getLocation();
74+
Assume.assumeNotNull(polyglotURL);
75+
76+
URL collectionsURL = Class.forName("org.graalvm.collections.EconomicMap").getProtectionDomain().getCodeSource().getLocation();
77+
Assume.assumeNotNull(collectionsURL);
78+
79+
URL wordURL = WordFactory.class.getProtectionDomain().getCodeSource().getLocation();
80+
Assume.assumeNotNull(wordURL);
81+
82+
URL nativeURL = Class.forName("org.graalvm.nativeimage.ImageInfo").getProtectionDomain().getCodeSource().getLocation();
83+
Assume.assumeNotNull(nativeURL);
7484

7585
URL truffleURL = Truffle.class.getProtectionDomain().getCodeSource().getLocation();
7686
Assume.assumeNotNull(truffleURL);
@@ -80,7 +90,7 @@ public void sdkAndTruffleLanguageAPIAndSLInSeparateClassLoaders() throws Excepti
8090

8191
ClassLoader parent = Engine.class.getClassLoader().getParent();
8292

83-
URLClassLoader sdkLoader = new URLClassLoader(new URL[]{sdkURL}, parent);
93+
URLClassLoader sdkLoader = new URLClassLoader(new URL[]{collectionsURL, wordURL, nativeURL, polyglotURL}, parent);
8494
boolean sdkLoaderLoadsTruffleLanguage;
8595
try {
8696
Class.forName("com.oracle.truffle.api.TruffleLanguage", false, sdkLoader);

0 commit comments

Comments
 (0)