Skip to content

Commit 2e1ae42

Browse files
committed
Avoid reflection in getCompilerVersion() to improve startup.
1 parent f8aee21 commit 2e1ae42

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotTruffleRuntimeAccess.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,19 @@ private static String verifyJVMCIVersion(Class<?> hotspotCompilationSupport) {
242242
* using reflection. If the method is unavailable, a fallback version of 23.1.1 is returned.
243243
*/
244244
public static Version getCompilerVersion(TruffleCompilationSupport compilationSupport) {
245-
/*
246-
* The TruffleCompilationSupport is present in both the maven artifact
247-
* org.graalvm.truffle/truffle-compiler and the JDK org.graalvm.truffle.compiler module. The
248-
* JDK version of TruffleCompilationSupport may be outdated and lack the getCompilerVersion
249-
* method. To address this, we use reflection.
250-
*/
251-
String compilerVersionString = null;
245+
Version version = null;
252246
try {
253-
Method getCompilerVersion = compilationSupport.getClass().getMethod("getCompilerVersion");
254-
compilerVersionString = (String) getCompilerVersion.invoke(compilationSupport);
255-
} catch (NoSuchMethodException noMethod) {
256-
// pass with compilerVersionString set to null
257-
} catch (ReflectiveOperationException e) {
258-
throw new InternalError(e);
247+
version = Version.parse(compilationSupport.getCompilerVersion());
248+
} catch (NoSuchMethodError noMethod) {
249+
/*
250+
* The TruffleCompilationSupport is present in both the maven artifact
251+
* org.graalvm.truffle/truffle-compiler and the JDK org.graalvm.truffle.compiler module.
252+
* The JDK version of TruffleCompilationSupport may be outdated and lack the
253+
* getCompilerVersion method. To address this, we use reflection.
254+
*/
255+
version = Version.create(23, 1, 1);
259256
}
260-
return compilerVersionString != null ? Version.parse(compilerVersionString) : Version.create(23, 1, 1);
257+
return version;
261258
}
262259

263260
private static Version stripUpdateVersion(Version version) {

0 commit comments

Comments
 (0)