Skip to content

Commit

Permalink
Merge pull request #27687 from zakkak/avoid-graalvm-internal-lookupme…
Browse files Browse the repository at this point in the history
…thod

Use own lookupMethod to avoid dependency on internal GraalVM API
  • Loading branch information
gsmet authored Sep 5, 2022
2 parents 7f6a45b + 44b77de commit dc9e119
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Map;
import java.util.Set;

import org.graalvm.home.Version;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.hosted.RuntimeClassInitialization;
Expand Down Expand Up @@ -50,6 +49,7 @@
import io.quarkus.gizmo.MethodDescriptor;
import io.quarkus.gizmo.ResultHandle;
import io.quarkus.gizmo.TryBlock;
import io.quarkus.runtime.ReflectionUtil;
import io.quarkus.runtime.ResourceHelper;
import io.quarkus.runtime.graal.ResourcesFeature;
import io.quarkus.runtime.graal.WeakReflection;
Expand Down Expand Up @@ -82,7 +82,7 @@ public class NativeImageFeatureStep {
String.class);

private static final MethodDescriptor LOOKUP_METHOD = ofMethod(
"com.oracle.svm.util.ReflectionUtil",
ReflectionUtil.class,
"lookupMethod", Method.class, Class.class, String.class, Class[].class);
private static final MethodDescriptor FOR_NAME = ofMethod(
Class.class, "forName", Class.class, String.class, boolean.class, ClassLoader.class);
Expand Down Expand Up @@ -282,8 +282,8 @@ public void write(String s, byte[] bytes) {

/* Resource includes and excludes */
if (!resourcePatterns.isEmpty()) {
// Needed to access LOOKUP_METHOD
exports.produce(new JPMSExportBuildItem("org.graalvm.nativeimage.base", "com.oracle.svm.util",
// Needed to access com.oracle.svm.core.configure.ResourcesRegistry.*
exports.produce(new JPMSExportBuildItem("org.graalvm.nativeimage.builder", "com.oracle.svm.core.configure",
GraalVM.Version.VERSION_22_1_0));

ResultHandle resourcesRegistrySingleton = overallCatch.invokeStaticMethod(IMAGE_SINGLETONS_LOOKUP,
Expand Down Expand Up @@ -506,9 +506,6 @@ public void write(String s, byte[] bytes) {

if (entry.getValue().serialization) {
if (registerSerializationMethod == null) {
// Needed by createRegisterSerializationForClassMethod to access LOOKUP_METHOD
exports.produce(new JPMSExportBuildItem("org.graalvm.nativeimage.base", "com.oracle.svm.util",
GraalVM.Version.VERSION_22_1_0));
registerSerializationMethod = createRegisterSerializationForClassMethod(file);
}

Expand Down
13 changes: 13 additions & 0 deletions core/runtime/src/main/java/io/quarkus/runtime/ReflectionUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.runtime;

import java.lang.reflect.Method;

public class ReflectionUtil {

public static Method lookupMethod(Class<?> declaringClass, String methodName, Class<?>... parameterTypes)
throws NoSuchMethodException {
Method result = declaringClass.getDeclaredMethod(methodName, parameterTypes);
result.setAccessible(true);
return result;
}
}

0 comments on commit dc9e119

Please sign in to comment.