@@ -107,22 +107,57 @@ public class SubstrateAnnotationExtracter implements AnnotationExtracter {
107
107
private static final Method hotSpotJDKReflectionGetMirror ;
108
108
private static final Method hotSpotJDKReflectionGetMethod ;
109
109
private static final Method hotSpotJDKReflectionGetField ;
110
+ private static final boolean isHotSpotJDKReflectionAvailable ;
111
+ private static final Method hotSpotResolvedObjectTypeImplMirror ;
112
+ private static final Method hotSpotResolvedPrimitiveTypeMirror ;
113
+ private static final Method hotSpotResolvedJavaMethodImplToJava ;
114
+ private static final Method hotSpotResolvedJavaFieldImplToJava ;
110
115
111
116
static {
117
+ recordComponentClass = ReflectionUtil .lookupClass (true , "java.lang.reflect.RecordComponent" );
118
+ recordComponentAnnotations = recordComponentClass != null ? ReflectionUtil .lookupField (recordComponentClass , "annotations" ) : null ;
119
+ recordComponentTypeAnnotations = recordComponentClass != null ? ReflectionUtil .lookupField (recordComponentClass , "typeAnnotations" ) : null ;
120
+ recordComponentGetDeclaringRecord = recordComponentClass != null ? ReflectionUtil .lookupMethod (recordComponentClass , "getDeclaringRecord" ) : null ;
121
+
122
+ Object temporaryHotSpotJVMCIRuntimeReflection = null ;
123
+ Method temporaryHotSpotJDKReflectionGetMirror = null ;
124
+ Method temporaryHotSpotJDKReflectionGetMethod = null ;
125
+ Method temporaryHotSpotJDKReflectionGetField = null ;
126
+ boolean temporaryIsHotSpotJDKReflectionAvailable = true ;
127
+
112
128
try {
113
- recordComponentClass = ReflectionUtil .lookupClass (true , "java.lang.reflect.RecordComponent" );
114
- recordComponentAnnotations = recordComponentClass != null ? ReflectionUtil .lookupField (recordComponentClass , "annotations" ) : null ;
115
- recordComponentTypeAnnotations = recordComponentClass != null ? ReflectionUtil .lookupField (recordComponentClass , "typeAnnotations" ) : null ;
116
- recordComponentGetDeclaringRecord = recordComponentClass != null ? ReflectionUtil .lookupMethod (recordComponentClass , "getDeclaringRecord" ) : null ;
117
129
Object hotSpotJVMCIRuntime = ReflectionUtil .lookupMethod (HotSpotJVMCIRuntime .class , "runtime" ).invoke (null );
118
- hotSpotJVMCIRuntimeReflection = ReflectionUtil .lookupMethod (HotSpotJVMCIRuntime .class , "getReflection" ).invoke (hotSpotJVMCIRuntime );
119
- hotSpotJDKReflectionGetMirror = ReflectionUtil .lookupMethod (Class .forName ("jdk.vm.ci.hotspot.HotSpotJDKReflection" ), "getMirror" , HotSpotResolvedJavaType .class );
120
- hotSpotJDKReflectionGetMethod = ReflectionUtil .lookupMethod (Class .forName ("jdk.vm.ci.hotspot.HotSpotJDKReflection" ), "getMethod" ,
121
- Class .forName ("jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl" ));
122
- hotSpotJDKReflectionGetField = ReflectionUtil .lookupMethod (Class .forName ("jdk.vm.ci.hotspot.HotSpotJDKReflection" ), "getField" ,
123
- Class .forName ("jdk.vm.ci.hotspot.HotSpotResolvedJavaFieldImpl" ));
124
- } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException e ) {
125
- throw GraalError .shouldNotReachHere (e );
130
+ temporaryHotSpotJVMCIRuntimeReflection = ReflectionUtil .lookupMethod (HotSpotJVMCIRuntime .class , "getReflection" ).invoke (hotSpotJVMCIRuntime );
131
+ temporaryHotSpotJDKReflectionGetMirror = ReflectionUtil .lookupMethod (Class .forName ("jdk.vm.ci.hotspot.HotSpotJDKReflection" ), "getMirror" , HotSpotResolvedJavaType .class );
132
+ temporaryHotSpotJDKReflectionGetMethod = ReflectionUtil .lookupMethod (Class .forName ("jdk.vm.ci.hotspot.HotSpotJDKReflection" ), "getMethod" ,
133
+ Class .forName ("jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl" ));
134
+ temporaryHotSpotJDKReflectionGetField = ReflectionUtil .lookupMethod (Class .forName ("jdk.vm.ci.hotspot.HotSpotJDKReflection" ), "getField" ,
135
+ Class .forName ("jdk.vm.ci.hotspot.HotSpotResolvedJavaFieldImpl" ));
136
+ } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException |
137
+ ReflectionUtil .ReflectionUtilError ex ) {
138
+ temporaryIsHotSpotJDKReflectionAvailable = false ;
139
+ }
140
+
141
+ isHotSpotJDKReflectionAvailable = temporaryIsHotSpotJDKReflectionAvailable ;
142
+ hotSpotJVMCIRuntimeReflection = temporaryHotSpotJVMCIRuntimeReflection ;
143
+ hotSpotJDKReflectionGetMirror = temporaryHotSpotJDKReflectionGetMirror ;
144
+ hotSpotJDKReflectionGetMethod = temporaryHotSpotJDKReflectionGetMethod ;
145
+ hotSpotJDKReflectionGetField = temporaryHotSpotJDKReflectionGetField ;
146
+
147
+ if (isHotSpotJDKReflectionAvailable ) {
148
+ hotSpotResolvedObjectTypeImplMirror = null ;
149
+ hotSpotResolvedPrimitiveTypeMirror = null ;
150
+ hotSpotResolvedJavaMethodImplToJava = null ;
151
+ hotSpotResolvedJavaFieldImplToJava = null ;
152
+ } else {
153
+ try {
154
+ hotSpotResolvedObjectTypeImplMirror = ReflectionUtil .lookupMethod (Class .forName ("jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl" ), "mirror" );
155
+ hotSpotResolvedPrimitiveTypeMirror = ReflectionUtil .lookupMethod (Class .forName ("jdk.vm.ci.hotspot.HotSpotResolvedPrimitiveType" ), "mirror" );
156
+ hotSpotResolvedJavaMethodImplToJava = ReflectionUtil .lookupMethod (Class .forName ("jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl" ), "toJava" );
157
+ hotSpotResolvedJavaFieldImplToJava = ReflectionUtil .lookupMethod (Class .forName ("jdk.vm.ci.hotspot.HotSpotResolvedJavaFieldImpl" ), "toJava" );
158
+ } catch (ClassNotFoundException e ) {
159
+ throw GraalError .shouldNotReachHere (e );
160
+ }
126
161
}
127
162
}
128
163
@@ -380,14 +415,29 @@ private static AnnotatedElement getRoot(AnnotatedElement element) {
380
415
if (element instanceof Package ) {
381
416
return (Class <?>) packageGetPackageInfo .invoke (element );
382
417
} else if (element instanceof HotSpotResolvedObjectType || element instanceof HotSpotResolvedJavaType ) {
383
- return (AnnotatedElement ) hotSpotJDKReflectionGetMirror .invoke (hotSpotJVMCIRuntimeReflection , element );
418
+ if (isHotSpotJDKReflectionAvailable ) {
419
+ return (AnnotatedElement ) hotSpotJDKReflectionGetMirror .invoke (hotSpotJVMCIRuntimeReflection , element );
420
+ } else {
421
+ if (element instanceof HotSpotResolvedObjectType ) {
422
+ return (AnnotatedElement ) hotSpotResolvedObjectTypeImplMirror .invoke (element );
423
+ }
424
+ return (AnnotatedElement ) hotSpotResolvedPrimitiveTypeMirror .invoke (element );
425
+ }
384
426
} else if (element instanceof HotSpotResolvedJavaMethod ) {
385
427
if (((ResolvedJavaMethod ) element ).isClassInitializer ()) {
386
428
return null ;
387
429
}
388
- return (AnnotatedElement ) hotSpotJDKReflectionGetMethod .invoke (hotSpotJVMCIRuntimeReflection , element );
430
+ if (isHotSpotJDKReflectionAvailable ) {
431
+ return (AnnotatedElement ) hotSpotJDKReflectionGetMethod .invoke (hotSpotJVMCIRuntimeReflection , element );
432
+ } else {
433
+ return (AnnotatedElement ) hotSpotResolvedJavaMethodImplToJava .invoke (element );
434
+ }
389
435
} else if (element instanceof HotSpotResolvedJavaField ) {
390
- return (AnnotatedElement ) hotSpotJDKReflectionGetField .invoke (hotSpotJVMCIRuntimeReflection , element );
436
+ if (isHotSpotJDKReflectionAvailable ) {
437
+ return (AnnotatedElement ) hotSpotJDKReflectionGetField .invoke (hotSpotJVMCIRuntimeReflection , element );
438
+ } else {
439
+ return (AnnotatedElement ) hotSpotResolvedJavaFieldImplToJava .invoke (element );
440
+ }
391
441
} else if (element instanceof AnnotationWrapper ) {
392
442
return getRoot (((AnnotationWrapper ) element ).getAnnotationRoot ());
393
443
}
0 commit comments