Skip to content

Commit

Permalink
make jdk.graal.nativeimage and org.graalvm.nativebridge optional depe…
Browse files Browse the repository at this point in the history
…ndencies of jdk.graal.compiler
  • Loading branch information
dougxc committed Jan 17, 2025
1 parent 94b2b1b commit 641df34
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions compiler/mx.compiler/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,13 @@
# This distribution defines a module.
"moduleInfo" : {
"name" : "jdk.graal.compiler",
"requires" : [
# These dependencies are only required when building libgraal.
# Running jargraal works without them so make them optional
# (i.e., "static") dependencies.
"static jdk.graal.nativeimage",
"static org.graalvm.nativebridge"
],
"exports" : [
"""* to com.oracle.graal.graal_enterprise,
org.graalvm.nativeimage.pointsto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.EconomicSet;
import org.graalvm.collections.MapCursor;
import org.graalvm.nativeimage.ImageInfo;

/**
* This class contains methods for parsing Graal options and matching them against a set of
Expand All @@ -66,9 +67,11 @@ public static LibGraalOptionsInfo create() {

/**
* Compiler options info available in libgraal. This field is only non-null when
* {@link OptionsParser} is loaded by a {@link jdk.graal.nativeimage.LibGraalLoader}.
* {@link OptionsParser} is loaded by a {@link jdk.graal.nativeimage.LibGraalLoader} and
* {@linkplain ImageInfo#inImageBuildtimeCode libgraal is being built}.
*/
public static final LibGraalOptionsInfo libgraalOptions = OptionsParser.class.getClassLoader() instanceof LibGraalLoader ? LibGraalOptionsInfo.create() : null;
public static final LibGraalOptionsInfo libgraalOptions = inImageBuildtimeCode() &&
OptionsParser.class.getClassLoader() instanceof LibGraalLoader ? LibGraalOptionsInfo.create() : null;

/**
* Gets an iterable of available {@link OptionDescriptors}.
Expand All @@ -79,10 +82,10 @@ public static Iterable<OptionDescriptors> getOptionsLoader() {
return List.of(new OptionDescriptorsMap(Objects.requireNonNull(libgraalOptions.descriptors, "missing options")));
}
boolean inLibGraal = libgraalOptions != null;
if (inLibGraal && inImageBuildtimeCode()) {
if (inLibGraal) {
/*
* Graal code is being run is loaded by a LibGraalLoader while building libgraal so use
* the loader to load the OptionDescriptors.
* Graal code being run is loaded by a LibGraalLoader while building libgraal so use the
* loader to load the OptionDescriptors.
*/
ClassLoader myCL = OptionsParser.class.getClassLoader();
return ServiceLoader.load(OptionDescriptors.class, myCL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static void addProviders(String arch, Class<?> service) {

static {
ClassLoader cl = GraalServices.class.getClassLoader();
if (cl instanceof LibGraalLoader libgraalLoader) {
if (inImageBuildtimeCode() && cl instanceof LibGraalLoader libgraalLoader) {
libgraalServices = new HashMap<>();
Set<String> libgraalServicesModules = libgraalLoader.getServicesModules();
Map<String, String> modules = libgraalLoader.getModuleMap();
Expand Down
9 changes: 3 additions & 6 deletions truffle/mx.truffle/mx_truffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,15 +735,12 @@ def _sl_jvm_compiler_on_upgrade_module_path_gate_tests(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')
return
compiler_cp = os.pathsep.join((mx.distribution(name).classpath_repr() for name in (
'compiler:GRAAL',
'compiler:GRAAL_NATIVEIMAGE',
'sdk:NATIVEBRIDGE'
)))
compiler = mx.distribution('compiler:GRAAL')
vm_args = [
'-XX:+UnlockExperimentalVMOptions',
'-XX:+EnableJVMCI',
f'--upgrade-module-path={compiler_cp}',
'-Djdk.graal.CompilationFailureAction=ExitVM',
f'--upgrade-module-path={compiler.classpath_repr()}',
]

def run_jvm_optimized(test_file):
Expand Down

0 comments on commit 641df34

Please sign in to comment.