8296961: [JVMCI] Access to j.l.r.Method/Constructor/Field for ResolvedJavaMethod/ResolvedJavaField

Reviewed-by: never
This commit is contained in:
Doug Simon 2022-11-16 19:58:09 +00:00
parent 4ce4f384d7
commit 5db1b58c86
2 changed files with 37 additions and 3 deletions

View File

@ -283,7 +283,7 @@ final class HotSpotJDKReflection extends HotSpotJVMCIReflection {
* Gets a {@link Method} object corresponding to {@code method}. This method guarantees the same
* {@link Method} object is returned if called twice on the same {@code method} value.
*/
private static Executable getMethod(HotSpotResolvedJavaMethodImpl method) {
static Executable getMethod(HotSpotResolvedJavaMethodImpl method) {
assert !method.isClassInitializer() : method;
if (method.toJavaCache == null) {
synchronized (method) {
@ -303,7 +303,7 @@ final class HotSpotJDKReflection extends HotSpotJVMCIReflection {
* {@code f} and annotation class {@code a}, the same object is returned for each call to
* {@code f.getAnnotation(a)}).
*/
private static Field getField(HotSpotResolvedJavaFieldImpl field) {
static Field getField(HotSpotResolvedJavaFieldImpl field) {
HotSpotResolvedObjectTypeImpl declaringClass = field.getDeclaringClass();
synchronized (declaringClass) {
HashMap<HotSpotResolvedJavaFieldImpl, Field> cache = declaringClass.reflectionFieldCache;

View File

@ -35,6 +35,8 @@ import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.MethodHandle;
import java.lang.ref.WeakReference;
import java.lang.reflect.Executable;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
@ -60,6 +62,8 @@ import jdk.vm.ci.common.JVMCIError;
import jdk.vm.ci.common.NativeImageReinitialize;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.JavaType;
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.UnresolvedJavaType;
import jdk.vm.ci.runtime.JVMCI;
@ -769,7 +773,7 @@ public final class HotSpotJVMCIRuntime implements JVMCIRuntime {
}
/**
* Get the {@link Class} corresponding to {@code type}.
* Gets the {@link Class} corresponding to {@code type}.
*
* @param type the type for which a {@link Class} is requested
* @return the original Java class corresponding to {@code type} or {@code null} if this runtime
@ -783,6 +787,36 @@ public final class HotSpotJVMCIRuntime implements JVMCIRuntime {
return null;
}
/**
* Gets the {@link Executable} corresponding to {@code method}.
*
* @param method the method for which an {@link Executable} is requested
* @return the original Java method or constructor corresponding to {@code method} or
* {@code null} if this runtime does not support mapping {@link ResolvedJavaMethod}
* instances to {@link Executable} instances
*/
public Executable getMirror(ResolvedJavaMethod method) {
if (method instanceof HotSpotResolvedJavaMethodImpl && reflection instanceof HotSpotJDKReflection) {
return HotSpotJDKReflection.getMethod((HotSpotResolvedJavaMethodImpl) method);
}
return null;
}
/**
* Gets the {@link Field} corresponding to {@code field}.
*
* @param field the field for which a {@link Field} is requested
* @return the original Java field corresponding to {@code field} or {@code null} if this
* runtime does not support mapping {@link ResolvedJavaField} instances to {@link Field}
* instances
*/
public Field getMirror(ResolvedJavaField field) {
if (field instanceof HotSpotResolvedJavaFieldImpl && reflection instanceof HotSpotJDKReflection) {
return HotSpotJDKReflection.getField((HotSpotResolvedJavaFieldImpl) field);
}
return null;
}
static class ErrorCreatingCompiler implements JVMCICompiler {
private final RuntimeException t;