Skip to content

Commit

Permalink
only add export to the EE module if it exists in the boot layer
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Sep 27, 2024
1 parent 0895a05 commit 589514c
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
*/
package com.oracle.svm.graal.hotspot;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -65,6 +67,35 @@ public class GetCompilerConfig {
public record Result(String encodedConfig, Map<String, Set<String>> opens) {
}

/**
* Tests whether {@code module} is in the boot layer.
*
* @param javaExe java executable
* @param module name of the module to test
*/
private static boolean isInBootLayer(Path javaExe, String module) {
String search = "jrt:/" + module;
String[] command = {javaExe.toString(), "--show-module-resolution", "--version"};
try {
Process p = new ProcessBuilder(command).start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
boolean found = false;
while ((line = reader.readLine()) != null) {
if (line.contains(search)) {
found = true;
}
}
int exitValue = p.waitFor();
if (exitValue != 0) {
throw new GraalError("Command finished with exit value %d: %s", exitValue, String.join(" ", command));
}
return found;
} catch (Exception e) {
throw new GraalError(e, "Error running command: %s", String.join(" ", command));
}
}

/**
* Launches the JVM in {@code javaHome} to run {@link CompilerConfig}.
*
Expand All @@ -81,12 +112,18 @@ public static Result from(Path javaHome, OptionValues options) {
// java.util.ImmutableCollections.EMPTY
"java.base", Set.of("java.util"));

// Only modules in the boot layer can be the target of --add-exports
String addExports = "--add-exports=java.base/jdk.internal.misc=jdk.graal.compiler";
if (isInBootLayer(javaExe, "com.oracle.graal.graal_enterprise")) {
addExports += ",com.oracle.graal.graal_enterprise";
}

List<String> command = new ArrayList<>(List.of(
javaExe.toFile().getAbsolutePath(),
"-XX:+UnlockExperimentalVMOptions",
"-XX:+EnableJVMCI",
"-XX:-UseJVMCICompiler", // avoid deadlock with jargraal
"--add-exports=java.base/jdk.internal.misc=jdk.graal.compiler,com.oracle.graal.graal_enterprise",
addExports,
"-Djdk.vm.ci.services.aot=true"));

Module module = ObjectCopier.class.getModule();
Expand Down

0 comments on commit 589514c

Please sign in to comment.