Skip to content
Closed
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 @@ -107,22 +107,56 @@ public class SubstrateAnnotationExtracter implements AnnotationExtracter {
private static final Method hotSpotJDKReflectionGetMirror;
private static final Method hotSpotJDKReflectionGetMethod;
private static final Method hotSpotJDKReflectionGetField;
private static final boolean isHotSpotJDKReflectionAvailable;
private static final Method hotSpotResolvedObjectTypeImplMirror;
private static final Method hotSpotResolvedPrimitiveTypeMirror;
private static final Method hotSpotResolvedJavaMethodImplToJava;
private static final Method hotSpotResolvedJavaFieldImplToJava;

static {
recordComponentClass = ReflectionUtil.lookupClass(true, "java.lang.reflect.RecordComponent");
recordComponentAnnotations = recordComponentClass != null ? ReflectionUtil.lookupField(recordComponentClass, "annotations") : null;
recordComponentTypeAnnotations = recordComponentClass != null ? ReflectionUtil.lookupField(recordComponentClass, "typeAnnotations") : null;
recordComponentGetDeclaringRecord = recordComponentClass != null ? ReflectionUtil.lookupMethod(recordComponentClass, "getDeclaringRecord") : null;

Object temporaryHotSpotJVMCIRuntimeReflection = null;
Method temporaryHotSpotJDKReflectionGetMirror = null;
Method temporaryHotSpotJDKReflectionGetMethod = null;
Method temporaryHotSpotJDKReflectionGetField = null;
boolean temporaryIsHotSpotJDKReflectionAvailable = true;

try {
recordComponentClass = ReflectionUtil.lookupClass(true, "java.lang.reflect.RecordComponent");
recordComponentAnnotations = recordComponentClass != null ? ReflectionUtil.lookupField(recordComponentClass, "annotations") : null;
recordComponentTypeAnnotations = recordComponentClass != null ? ReflectionUtil.lookupField(recordComponentClass, "typeAnnotations") : null;
recordComponentGetDeclaringRecord = recordComponentClass != null ? ReflectionUtil.lookupMethod(recordComponentClass, "getDeclaringRecord") : null;
Object hotSpotJVMCIRuntime = ReflectionUtil.lookupMethod(HotSpotJVMCIRuntime.class, "runtime").invoke(null);
hotSpotJVMCIRuntimeReflection = ReflectionUtil.lookupMethod(HotSpotJVMCIRuntime.class, "getReflection").invoke(hotSpotJVMCIRuntime);
hotSpotJDKReflectionGetMirror = ReflectionUtil.lookupMethod(Class.forName("jdk.vm.ci.hotspot.HotSpotJDKReflection"), "getMirror", HotSpotResolvedJavaType.class);
hotSpotJDKReflectionGetMethod = ReflectionUtil.lookupMethod(Class.forName("jdk.vm.ci.hotspot.HotSpotJDKReflection"), "getMethod",
temporaryHotSpotJVMCIRuntimeReflection = ReflectionUtil.lookupMethod(HotSpotJVMCIRuntime.class, "getReflection").invoke(hotSpotJVMCIRuntime);
temporaryHotSpotJDKReflectionGetMirror = ReflectionUtil.lookupMethod(Class.forName("jdk.vm.ci.hotspot.HotSpotJDKReflection"), "getMirror", HotSpotResolvedJavaType.class);
temporaryHotSpotJDKReflectionGetMethod = ReflectionUtil.lookupMethod(Class.forName("jdk.vm.ci.hotspot.HotSpotJDKReflection"), "getMethod",
Class.forName("jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl"));
hotSpotJDKReflectionGetField = ReflectionUtil.lookupMethod(Class.forName("jdk.vm.ci.hotspot.HotSpotJDKReflection"), "getField",
temporaryHotSpotJDKReflectionGetField = ReflectionUtil.lookupMethod(Class.forName("jdk.vm.ci.hotspot.HotSpotJDKReflection"), "getField",
Class.forName("jdk.vm.ci.hotspot.HotSpotResolvedJavaFieldImpl"));
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException e) {
throw GraalError.shouldNotReachHere(e);
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | ReflectionUtil.ReflectionUtilError ex) {
temporaryIsHotSpotJDKReflectionAvailable = false;
}

isHotSpotJDKReflectionAvailable = temporaryIsHotSpotJDKReflectionAvailable;
hotSpotJVMCIRuntimeReflection = temporaryHotSpotJVMCIRuntimeReflection;
hotSpotJDKReflectionGetMirror = temporaryHotSpotJDKReflectionGetMirror;
hotSpotJDKReflectionGetMethod = temporaryHotSpotJDKReflectionGetMethod;
hotSpotJDKReflectionGetField = temporaryHotSpotJDKReflectionGetField;

if (isHotSpotJDKReflectionAvailable) {
hotSpotResolvedObjectTypeImplMirror = null;
hotSpotResolvedPrimitiveTypeMirror = null;
hotSpotResolvedJavaMethodImplToJava = null;
hotSpotResolvedJavaFieldImplToJava = null;
} else {
try {
hotSpotResolvedObjectTypeImplMirror = ReflectionUtil.lookupMethod(Class.forName("jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl"), "mirror");
hotSpotResolvedPrimitiveTypeMirror = ReflectionUtil.lookupMethod(Class.forName("jdk.vm.ci.hotspot.HotSpotResolvedPrimitiveType"), "mirror");
hotSpotResolvedJavaMethodImplToJava = ReflectionUtil.lookupMethod(Class.forName("jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl"), "toJava");
hotSpotResolvedJavaFieldImplToJava = ReflectionUtil.lookupMethod(Class.forName("jdk.vm.ci.hotspot.HotSpotResolvedJavaFieldImpl"), "toJava");
} catch (ClassNotFoundException e) {
throw GraalError.shouldNotReachHere(e);
}
}
}

Expand Down Expand Up @@ -380,14 +414,29 @@ private static AnnotatedElement getRoot(AnnotatedElement element) {
if (element instanceof Package) {
return (Class<?>) packageGetPackageInfo.invoke(element);
} else if (element instanceof HotSpotResolvedObjectType || element instanceof HotSpotResolvedJavaType) {
return (AnnotatedElement) hotSpotJDKReflectionGetMirror.invoke(hotSpotJVMCIRuntimeReflection, element);
if (isHotSpotJDKReflectionAvailable) {
return (AnnotatedElement) hotSpotJDKReflectionGetMirror.invoke(hotSpotJVMCIRuntimeReflection, element);
} else {
if (element instanceof HotSpotResolvedObjectType) {
return (AnnotatedElement) hotSpotResolvedObjectTypeImplMirror.invoke(element);
}
return (AnnotatedElement) hotSpotResolvedPrimitiveTypeMirror.invoke(element);
}
} else if (element instanceof HotSpotResolvedJavaMethod) {
if (((ResolvedJavaMethod) element).isClassInitializer()) {
return null;
}
return (AnnotatedElement) hotSpotJDKReflectionGetMethod.invoke(hotSpotJVMCIRuntimeReflection, element);
if (isHotSpotJDKReflectionAvailable) {
return (AnnotatedElement) hotSpotJDKReflectionGetMethod.invoke(hotSpotJVMCIRuntimeReflection, element);
} else {
return (AnnotatedElement) hotSpotResolvedJavaMethodImplToJava.invoke(element);
}
} else if (element instanceof HotSpotResolvedJavaField) {
return (AnnotatedElement) hotSpotJDKReflectionGetField.invoke(hotSpotJVMCIRuntimeReflection, element);
if (isHotSpotJDKReflectionAvailable) {
return (AnnotatedElement) hotSpotJDKReflectionGetField.invoke(hotSpotJVMCIRuntimeReflection, element);
} else {
return (AnnotatedElement) hotSpotResolvedJavaFieldImplToJava.invoke(element);
}
} else if (element instanceof AnnotationWrapper) {
return getRoot(((AnnotationWrapper) element).getAnnotationRoot());
}
Expand Down