Skip to content

Commit 56c5c4c

Browse files
committed
[GR-8913] Revert to using reflection to access Services.load method.
PullRequest: graal/1194
2 parents 895ef73 + c144177 commit 56c5c4c

File tree

1 file changed

+16
-1
lines changed
  • compiler/src/org.graalvm.compiler.serviceprovider/src/org/graalvm/compiler/serviceprovider

1 file changed

+16
-1
lines changed

compiler/src/org.graalvm.compiler.serviceprovider/src/org/graalvm/compiler/serviceprovider/GraalServices.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.IOException;
2626
import java.io.InputStream;
27+
import java.lang.reflect.Method;
2728
import java.util.Iterator;
2829
import java.util.ServiceConfigurationError;
2930

@@ -63,11 +64,25 @@ private GraalServices() {
6364
* @throws SecurityException if on JDK8 and a security manager is present and it denies
6465
* {@link JVMCIPermission}
6566
*/
67+
@SuppressWarnings("unchecked")
6668
public static <S> Iterable<S> load(Class<S> service) {
6769
assert !service.getName().startsWith("jdk.vm.ci") : "JVMCI services must be loaded via " + Services.class.getName();
68-
return Services.load(service);
70+
try {
71+
if (loadMethod == null) {
72+
loadMethod = Services.class.getMethod("load", Class.class);
73+
}
74+
return (Iterable<S>) loadMethod.invoke(null, service);
75+
} catch (Exception e) {
76+
throw new InternalError(e);
77+
}
6978
}
7079

80+
/**
81+
* {@code Services.load(Class)} is only defined in JVMCI-8 so we use reflection to simplify
82+
* compiling with javac on JDK 9 or later.
83+
*/
84+
private static volatile Method loadMethod;
85+
7186
/**
7287
* Gets the provider for a given service for which at most one provider must be available.
7388
*

0 commit comments

Comments
 (0)