Skip to content

Commit

Permalink
[GR-18295] Remove dependency from c.o.truffle.api.jdk* to c.o.truffle…
Browse files Browse the repository at this point in the history
….api.

PullRequest: graal/4410
  • Loading branch information
dougxc committed Sep 18, 2019
2 parents 3cf3df4 + 8b4deec commit 8451d19
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
10 changes: 3 additions & 7 deletions truffle/mx.truffle/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# SOFTWARE.
#
suite = {
"mxversion" : "5.233.5",
"mxversion" : "5.235.0",
"name" : "truffle",
"version" : "19.3.0",
"release" : False,
Expand Down Expand Up @@ -131,10 +131,8 @@
"com.oracle.truffle.api.jdk8" : {
"subDir" : "src",
"sourceDirs" : ["src"],
"dependencies" : [
"com.oracle.truffle.api",
],
"overlayTarget" : "com.oracle.truffle.api",
"checkPackagePrefix" : "false",
"checkstyle" : "com.oracle.truffle.api",
"javaCompliance" : "8",
"workingSets" : "API,Truffle",
Expand All @@ -143,10 +141,8 @@
"com.oracle.truffle.api.jdk11" : {
"subDir" : "src",
"sourceDirs" : ["src"],
"dependencies" : [
"com.oracle.truffle.api",
],
"overlayTarget" : "com.oracle.truffle.api",
"checkPackagePrefix" : "false",
"multiReleaseJarVersion" : "11",
"checkstyle" : "com.oracle.truffle.api",
"javaCompliance" : "11+",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
import java.util.ServiceLoader;
import java.util.Set;

import com.oracle.truffle.api.TruffleRuntimeAccess;

/**
* JDK 11+ implementation of {@code TruffleJDKServices}.
*/
Expand Down Expand Up @@ -81,8 +79,8 @@ private static void exportFromTo(Module truffleModule, Module clientModule) {
}
}

public static List<Iterable<TruffleRuntimeAccess>> getTruffleRuntimeLoaders() {
return Collections.singletonList(ServiceLoader.load(TruffleRuntimeAccess.class));
public static <Service> List<Iterable<Service>> getTruffleRuntimeLoaders(Class<Service> serviceClass) {
return Collections.singletonList(ServiceLoader.load(serviceClass));
}

public static <S> void addUses(Class<S> service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
import java.util.List;
import java.util.ServiceLoader;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleRuntimeAccess;

/**
* JDK 8 implementation of {@code TruffleJDKServices}.
*/
Expand All @@ -72,21 +69,22 @@ public static <S> void addUses(Class<S> service) {
/**
* Gets the ordered list of loaders for {@link TruffleRuntimeAccess} providers.
*/
public static List<Iterable<TruffleRuntimeAccess>> getTruffleRuntimeLoaders() {
Iterable<TruffleRuntimeAccess> jvmciProviders = getJVMCIProviders();
public static <Service> List<Iterable<Service>> getTruffleRuntimeLoaders(Class<Service> serviceClass) {
// public static List<Iterable<TruffleRuntimeAccess>> getTruffleRuntimeLoaders() {
Iterable<Service> jvmciProviders = getJVMCIProviders(serviceClass);
if (Boolean.getBoolean("truffle.TrustAllTruffleRuntimeProviders")) {
ServiceLoader<TruffleRuntimeAccess> standardProviders = ServiceLoader.load(TruffleRuntimeAccess.class);
ServiceLoader<Service> standardProviders = ServiceLoader.load(serviceClass);
return Arrays.asList(jvmciProviders, standardProviders);
} else {
return Collections.singletonList(jvmciProviders);
}
}

/**
* Gets the {@link TruffleRuntimeAccess} providers available on the JVMCI class path.
* Gets the providers of {@code Service} available on the JVMCI class path.
*/
private static Iterable<TruffleRuntimeAccess> getJVMCIProviders() {
ClassLoader cl = Truffle.class.getClassLoader();
private static <Service> Iterable<Service> getJVMCIProviders(Class<Service> serviceClass) {
ClassLoader cl = TruffleJDKServices.class.getClassLoader();
ClassLoader scl = ClassLoader.getSystemClassLoader();
while (cl != null) {
if (cl == scl) {
Expand All @@ -102,24 +100,24 @@ private static Iterable<TruffleRuntimeAccess> getJVMCIProviders() {
cl = cl.getParent();
}

Class<?> servicesClass;
Class<?> jvmciServicesClass;
try {
// Access JVMCI via reflection to avoid a hard
// dependency on JVMCI from Truffle.
servicesClass = Class.forName("jdk.vm.ci.services.Services");
jvmciServicesClass = Class.forName("jdk.vm.ci.services.Services");
} catch (ClassNotFoundException e) {
// JVMCI is unavailable so the default TruffleRuntime will be used
return null;
}

return reflectiveServiceLoaderLoad(servicesClass);
return reflectiveServiceLoaderLoad(jvmciServicesClass, serviceClass);
}

@SuppressWarnings("unchecked")
private static Iterable<TruffleRuntimeAccess> reflectiveServiceLoaderLoad(Class<?> servicesClass) {
private static <Service> Iterable<Service> reflectiveServiceLoaderLoad(Class<?> servicesClass, Class<Service> serviceClass) {
try {
Method m = servicesClass.getDeclaredMethod("load", Class.class);
return (Iterable<TruffleRuntimeAccess>) m.invoke(null, TruffleRuntimeAccess.class);
return (Iterable<Service>) m.invoke(null, serviceClass);
} catch (Throwable e) {
throw (InternalError) new InternalError().initCause(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public TruffleRuntime run() {
}
}

List<Iterable<TruffleRuntimeAccess>> loaders = TruffleJDKServices.getTruffleRuntimeLoaders();
List<Iterable<TruffleRuntimeAccess>> loaders = TruffleJDKServices.getTruffleRuntimeLoaders(TruffleRuntimeAccess.class);
TruffleRuntimeAccess access = selectTruffleRuntimeAccess(loaders);

if (access != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

import java.util.List;

import com.oracle.truffle.api.TruffleRuntimeAccess;

/**
* JDK version independent interface to JDK services used by Truffle.
*/
Expand Down Expand Up @@ -77,9 +75,11 @@ public static void exportTo(Class<?> client) {
}

/**
* Gets the ordered list of loaders for {@link TruffleRuntimeAccess} providers.
* Gets the ordered list of loaders for {@link Service} providers.
*
* @param serviceClass defines service class
*/
public static List<Iterable<TruffleRuntimeAccess>> getTruffleRuntimeLoaders() {
public static <Service> List<Iterable<Service>> getTruffleRuntimeLoaders(Class<Service> serviceClass) {
throw shouldNotReachHere();
}

Expand Down

0 comments on commit 8451d19

Please sign in to comment.