Skip to content

Commit 20f2218

Browse files
committed
8296961: [JVMCI] Access to j.l.r.Method/Constructor/Field for ResolvedJavaMethod/ResolvedJavaField
Backport-of: 5db1b58c867608573a9e7cc57ca2ba22c9dd80d4
1 parent 4c87089 commit 20f2218

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJDKReflection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ JavaConstant boxPrimitive(JavaConstant source) {
283283
* Gets a {@link Method} object corresponding to {@code method}. This method guarantees the same
284284
* {@link Method} object is returned if called twice on the same {@code method} value.
285285
*/
286-
private static Executable getMethod(HotSpotResolvedJavaMethodImpl method) {
286+
static Executable getMethod(HotSpotResolvedJavaMethodImpl method) {
287287
assert !method.isClassInitializer() : method;
288288
if (method.toJavaCache == null) {
289289
synchronized (method) {
@@ -303,7 +303,7 @@ private static Executable getMethod(HotSpotResolvedJavaMethodImpl method) {
303303
* {@code f} and annotation class {@code a}, the same object is returned for each call to
304304
* {@code f.getAnnotation(a)}).
305305
*/
306-
private static Field getField(HotSpotResolvedJavaFieldImpl field) {
306+
static Field getField(HotSpotResolvedJavaFieldImpl field) {
307307
HotSpotResolvedObjectTypeImpl declaringClass = field.getDeclaringClass();
308308
synchronized (declaringClass) {
309309
HashMap<HotSpotResolvedJavaFieldImpl, Field> cache = declaringClass.reflectionFieldCache;

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import java.lang.invoke.ConstantCallSite;
3636
import java.lang.invoke.MethodHandle;
3737
import java.lang.ref.WeakReference;
38+
import java.lang.reflect.Executable;
39+
import java.lang.reflect.Field;
3840
import java.nio.ByteBuffer;
3941
import java.nio.ByteOrder;
4042
import java.util.ArrayList;
@@ -60,6 +62,8 @@
6062
import jdk.vm.ci.common.NativeImageReinitialize;
6163
import jdk.vm.ci.meta.JavaKind;
6264
import jdk.vm.ci.meta.JavaType;
65+
import jdk.vm.ci.meta.ResolvedJavaField;
66+
import jdk.vm.ci.meta.ResolvedJavaMethod;
6367
import jdk.vm.ci.meta.ResolvedJavaType;
6468
import jdk.vm.ci.meta.UnresolvedJavaType;
6569
import jdk.vm.ci.runtime.JVMCI;
@@ -767,7 +771,7 @@ public boolean test(ResolvedJavaType type) {
767771
}
768772

769773
/**
770-
* Get the {@link Class} corresponding to {@code type}.
774+
* Gets the {@link Class} corresponding to {@code type}.
771775
*
772776
* @param type the type for which a {@link Class} is requested
773777
* @return the original Java class corresponding to {@code type} or {@code null} if this runtime
@@ -781,6 +785,36 @@ public Class<?> getMirror(ResolvedJavaType type) {
781785
return null;
782786
}
783787

788+
/**
789+
* Gets the {@link Executable} corresponding to {@code method}.
790+
*
791+
* @param method the method for which an {@link Executable} is requested
792+
* @return the original Java method or constructor corresponding to {@code method} or
793+
* {@code null} if this runtime does not support mapping {@link ResolvedJavaMethod}
794+
* instances to {@link Executable} instances
795+
*/
796+
public Executable getMirror(ResolvedJavaMethod method) {
797+
if (method instanceof HotSpotResolvedJavaMethodImpl && reflection instanceof HotSpotJDKReflection) {
798+
return HotSpotJDKReflection.getMethod((HotSpotResolvedJavaMethodImpl) method);
799+
}
800+
return null;
801+
}
802+
803+
/**
804+
* Gets the {@link Field} corresponding to {@code field}.
805+
*
806+
* @param field the field for which a {@link Field} is requested
807+
* @return the original Java field corresponding to {@code field} or {@code null} if this
808+
* runtime does not support mapping {@link ResolvedJavaField} instances to {@link Field}
809+
* instances
810+
*/
811+
public Field getMirror(ResolvedJavaField field) {
812+
if (field instanceof HotSpotResolvedJavaFieldImpl && reflection instanceof HotSpotJDKReflection) {
813+
return HotSpotJDKReflection.getField((HotSpotResolvedJavaFieldImpl) field);
814+
}
815+
return null;
816+
}
817+
784818
static class ErrorCreatingCompiler implements JVMCICompiler {
785819
private final RuntimeException t;
786820

0 commit comments

Comments
 (0)