Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use own lookupMethod to avoid dependency on internal GraalVM API #27687

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}