Skip to content

Commit

Permalink
[GR-18201] Truffle must declare use of any service it loads on behalf…
Browse files Browse the repository at this point in the history
… of a Truffle client.

PullRequest: graal/4389
  • Loading branch information
dougxc committed Sep 13, 2019
2 parents 1f0187b + f9f5dae commit 39522c2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,11 @@ private static void exportFromTo(Module truffleModule, Module clientModule) {
public static List<Iterable<TruffleRuntimeAccess>> getTruffleRuntimeLoaders() {
return Collections.singletonList(ServiceLoader.load(TruffleRuntimeAccess.class));
}

public static <S> void addUses(Class<S> service) {
Module module = TruffleJDKServices.class.getModule();
if (!module.canUse(service)) {
module.addUses(service);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public static void exportTo(Class<?> client) {
// No need to do anything on JDK 8
}

@SuppressWarnings("unused")
public static <S> void addUses(Class<S> service) {
// No need to do anything on JDK 8
}

/**
* Gets the ordered list of loaders for {@link TruffleRuntimeAccess} providers.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ private static final class Loader {

@SuppressWarnings("unchecked")
static <S> Iterable<S> load(Class<S> service) {
TruffleJDKServices.addUses(service);
if (LOAD_METHOD != null) {
try {
return (Iterable<S>) LOAD_METHOD.invoke(null, service);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,13 @@ public static void exportTo(Class<?> client) {
public static List<Iterable<TruffleRuntimeAccess>> getTruffleRuntimeLoaders() {
throw shouldNotReachHere();
}

/**
* Ensures that the Truffle module declares a use of {@code service}.
*
* @param service a class describing a service about to be loaded by Truffle
*/
public static <S> void addUses(Class<S> service) {
throw shouldNotReachHere();
}
}

0 comments on commit 39522c2

Please sign in to comment.