Skip to content

Commit b5f79f3

Browse files
committed
removed AnnotatedElement as super interface of ResolvedJava[Type|Method|Field]
1 parent b806e09 commit b5f79f3

File tree

13 files changed

+152
-572
lines changed

13 files changed

+152
-572
lines changed

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

Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,21 @@
2222
*/
2323
package jdk.vm.ci.hotspot;
2424

25-
import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM;
26-
import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
25+
import jdk.vm.ci.common.JVMCIError;
26+
import jdk.vm.ci.meta.JavaConstant;
27+
import jdk.vm.ci.meta.JavaKind;
28+
import jdk.vm.ci.meta.ResolvedJavaMethod;
29+
import jdk.vm.ci.meta.ResolvedJavaType;
2730

28-
import java.lang.annotation.Annotation;
2931
import java.lang.reflect.Array;
30-
import java.lang.reflect.Constructor;
3132
import java.lang.reflect.Executable;
3233
import java.lang.reflect.Field;
3334
import java.lang.reflect.Method;
3435
import java.lang.reflect.Type;
3536
import java.util.HashMap;
3637

37-
import jdk.vm.ci.common.JVMCIError;
38-
import jdk.vm.ci.meta.JavaConstant;
39-
import jdk.vm.ci.meta.JavaKind;
40-
import jdk.vm.ci.meta.ResolvedJavaMethod;
41-
import jdk.vm.ci.meta.ResolvedJavaType;
38+
import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM;
39+
import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
4240

4341
/**
4442
* Implementation of {@link HotSpotJVMCIReflection} in terms of standard JDK reflection API. This is
@@ -68,24 +66,6 @@ boolean isAssignableFrom(HotSpotResolvedObjectTypeImpl holder, HotSpotResolvedOb
6866

6967
}
7068

71-
@Override
72-
Annotation[] getAnnotations(HotSpotResolvedObjectTypeImpl holder) {
73-
Class<?> javaMirror = getMirror(holder);
74-
return javaMirror.getAnnotations();
75-
}
76-
77-
@Override
78-
Annotation[] getDeclaredAnnotations(HotSpotResolvedObjectTypeImpl holder) {
79-
Class<?> javaMirror = getMirror(holder);
80-
return javaMirror.getDeclaredAnnotations();
81-
}
82-
83-
@Override
84-
<T extends Annotation> T getAnnotation(HotSpotResolvedObjectTypeImpl holder, Class<T> annotationClass) {
85-
Class<?> javaMirror = getMirror(holder);
86-
return javaMirror.getAnnotation(annotationClass);
87-
}
88-
8969
@Override
9070
boolean isLocalClass(HotSpotResolvedObjectTypeImpl holder) {
9171
Class<?> javaMirror = getMirror(holder);
@@ -132,46 +112,11 @@ ResolvedJavaMethod.Parameter[] getParameters(HotSpotResolvedJavaMethodImpl javaM
132112
return res;
133113
}
134114

135-
@Override
136-
Annotation[][] getParameterAnnotations(HotSpotResolvedJavaMethodImpl javaMethod) {
137-
return getMethod(javaMethod).getParameterAnnotations();
138-
}
139-
140115
@Override
141116
Type[] getGenericParameterTypes(HotSpotResolvedJavaMethodImpl javaMethod) {
142117
return getMethod(javaMethod).getGenericParameterTypes();
143118
}
144119

145-
@Override
146-
Annotation[] getFieldAnnotations(HotSpotResolvedJavaFieldImpl javaField) {
147-
return getField(javaField).getAnnotations();
148-
}
149-
150-
@Override
151-
Annotation[] getMethodAnnotations(HotSpotResolvedJavaMethodImpl javaMethod) {
152-
return getMethod(javaMethod).getAnnotations();
153-
}
154-
155-
@Override
156-
Annotation[] getMethodDeclaredAnnotations(HotSpotResolvedJavaMethodImpl javaMethod) {
157-
return getMethod(javaMethod).getDeclaredAnnotations();
158-
}
159-
160-
@Override
161-
Annotation[] getFieldDeclaredAnnotations(HotSpotResolvedJavaFieldImpl javaField) {
162-
return getField(javaField).getDeclaredAnnotations();
163-
}
164-
165-
@Override
166-
<T extends Annotation> T getMethodAnnotation(HotSpotResolvedJavaMethodImpl javaMethod, Class<T> annotationClass) {
167-
return getMethod(javaMethod).getAnnotation(annotationClass);
168-
}
169-
170-
@Override
171-
<T extends Annotation> T getFieldAnnotation(HotSpotResolvedJavaFieldImpl javaField, Class<T> annotationClass) {
172-
return getField(javaField).getAnnotation(annotationClass);
173-
}
174-
175120
@Override
176121
HotSpotResolvedObjectTypeImpl getType(HotSpotObjectConstantImpl object) {
177122
Object value = resolveObject(object);
@@ -191,8 +136,7 @@ String asString(HotSpotObjectConstantImpl object) {
191136
@Override
192137
ResolvedJavaType asJavaType(HotSpotObjectConstantImpl object) {
193138
Object value = resolveObject(object);
194-
if (value instanceof Class) {
195-
Class<?> javaClass = (Class<?>) value;
139+
if (value instanceof Class<?> javaClass) {
196140
return runtime().fromClass(javaClass);
197141
}
198142
if (value instanceof ResolvedJavaType) {
@@ -306,11 +250,7 @@ static Executable getMethod(HotSpotResolvedJavaMethodImpl method) {
306250

307251
/**
308252
* Gets a {@link Field} object corresponding to {@code field}. This method guarantees the same
309-
* {@link Field} object is returned if called twice on the same {@code field} value. This is
310-
* required to ensure the results of {@link HotSpotResolvedJavaFieldImpl#getAnnotations()} and
311-
* {@link HotSpotResolvedJavaFieldImpl#getAnnotation(Class)} are stable (i.e., for a given field
312-
* {@code f} and annotation class {@code a}, the same object is returned for each call to
313-
* {@code f.getAnnotation(a)}).
253+
* {@link Field} object is returned if called twice on the same {@code field} value.
314254
*/
315255
static Field getField(HotSpotResolvedJavaFieldImpl field) {
316256
HotSpotResolvedObjectTypeImpl declaringClass = field.getDeclaringClass();

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
*/
2323
package jdk.vm.ci.hotspot;
2424

25-
import java.lang.annotation.Annotation;
26-
import java.lang.reflect.Type;
27-
2825
import jdk.vm.ci.meta.JavaConstant;
2926
import jdk.vm.ci.meta.ResolvedJavaMethod;
3027
import jdk.vm.ci.meta.ResolvedJavaType;
3128

29+
import java.lang.reflect.Type;
30+
3231
/**
3332
* API for reflecting on the internals of HotSpot JVMCI types and objects.
3433
*/
@@ -38,12 +37,6 @@ abstract class HotSpotJVMCIReflection {
3837

3938
abstract boolean isAssignableFrom(HotSpotResolvedObjectTypeImpl holder, HotSpotResolvedObjectTypeImpl otherType);
4039

41-
abstract Annotation[] getAnnotations(HotSpotResolvedObjectTypeImpl holder);
42-
43-
abstract Annotation[] getDeclaredAnnotations(HotSpotResolvedObjectTypeImpl holder);
44-
45-
abstract <T extends Annotation> T getAnnotation(HotSpotResolvedObjectTypeImpl holder, Class<T> annotationClass);
46-
4740
abstract boolean isLocalClass(HotSpotResolvedObjectTypeImpl holder);
4841

4942
abstract boolean isMemberClass(HotSpotResolvedObjectTypeImpl holder);
@@ -56,20 +49,8 @@ abstract class HotSpotJVMCIReflection {
5649

5750
abstract ResolvedJavaMethod.Parameter[] getParameters(HotSpotResolvedJavaMethodImpl javaMethod);
5851

59-
abstract Annotation[][] getParameterAnnotations(HotSpotResolvedJavaMethodImpl javaMethod);
60-
6152
abstract Type[] getGenericParameterTypes(HotSpotResolvedJavaMethodImpl javaMethod);
6253

63-
abstract Annotation[] getFieldAnnotations(HotSpotResolvedJavaFieldImpl javaMethod);
64-
65-
abstract Annotation[] getMethodAnnotations(HotSpotResolvedJavaMethodImpl javaField);
66-
67-
abstract Annotation[] getMethodDeclaredAnnotations(HotSpotResolvedJavaMethodImpl javaMethod);
68-
69-
abstract Annotation[] getFieldDeclaredAnnotations(HotSpotResolvedJavaFieldImpl javaMethod);
70-
71-
abstract <T extends Annotation> T getMethodAnnotation(HotSpotResolvedJavaMethodImpl javaMethod, Class<T> annotationClass);
72-
7354
abstract HotSpotResolvedObjectTypeImpl getType(HotSpotObjectConstantImpl object);
7455

7556
abstract String asString(HotSpotObjectConstantImpl object);
@@ -95,13 +76,11 @@ abstract class HotSpotJVMCIReflection {
9576

9677
abstract JavaConstant boxPrimitive(JavaConstant source);
9778

98-
abstract <T extends Annotation> T getFieldAnnotation(HotSpotResolvedJavaFieldImpl javaField, Class<T> annotationClass);
99-
10079
/**
10180
* Resolves {@code objectHandle} to a raw object if possible.
10281
*
10382
* @throws HotSpotJVMCIUnsupportedOperationError if {@code objectHandle} refers to an object in
104-
* another heap
83+
* another heap
10584
*/
10685
abstract Object resolveObject(HotSpotObjectConstantImpl objectHandle);
10786
}

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@
2929
import jdk.vm.ci.meta.annotation.AbstractAnnotated;
3030
import jdk.vm.ci.meta.annotation.AnnotationsInfo;
3131

32-
import java.lang.annotation.Annotation;
33-
3432
import static jdk.internal.misc.Unsafe.ADDRESS_SIZE;
3533
import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM;
36-
import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
3734
import static jdk.vm.ci.hotspot.HotSpotVMConfig.config;
3835
import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE;
3936

@@ -109,7 +106,7 @@ public boolean isInternal() {
109106
* Determines if a given object contains this field.
110107
*
111108
* @return true iff this is a non-static field and its declaring class is assignable from
112-
* {@code object}'s class
109+
* {@code object}'s class
113110
*/
114111
@Override
115112
public boolean isInObject(JavaConstant object) {
@@ -204,30 +201,6 @@ private boolean hasAnnotations(boolean typeAnnotations) {
204201
return false;
205202
}
206203

207-
@Override
208-
public Annotation[] getAnnotations() {
209-
if (!hasAnnotations(false)) {
210-
return new Annotation[0];
211-
}
212-
return runtime().reflection.getFieldAnnotations(this);
213-
}
214-
215-
@Override
216-
public Annotation[] getDeclaredAnnotations() {
217-
if (!hasAnnotations(false)) {
218-
return new Annotation[0];
219-
}
220-
return runtime().reflection.getFieldDeclaredAnnotations(this);
221-
}
222-
223-
@Override
224-
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
225-
if (!hasAnnotations(false)) {
226-
return null;
227-
}
228-
return runtime().reflection.getFieldAnnotation(this, annotationClass);
229-
}
230-
231204
@Override
232205
public JavaConstant getConstantValue() {
233206
return holder.getFieldInfo(index).getConstantValue(holder);

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

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import jdk.vm.ci.meta.TriState;
4141
import jdk.vm.ci.meta.annotation.AnnotationsInfo;
4242

43-
import java.lang.annotation.Annotation;
4443
import java.lang.reflect.Executable;
4544
import java.lang.reflect.Modifier;
4645
import java.lang.reflect.Type;
@@ -449,7 +448,6 @@ public boolean hasCompiledCode() {
449448
}
450449

451450
/**
452-
* @param level
453451
* @return true if the currently installed code was generated at {@code level}.
454452
*/
455453
@Override
@@ -506,38 +504,6 @@ public Parameter[] getParameters() {
506504
return runtime().reflection.getParameters(this);
507505
}
508506

509-
@Override
510-
public Annotation[][] getParameterAnnotations() {
511-
if (!hasAnnotations(HotSpotVMConfig.config().constMethodHasParameterAnnotations)) {
512-
return new Annotation[signature.getParameterCount(false)][0];
513-
}
514-
return runtime().reflection.getParameterAnnotations(this);
515-
}
516-
517-
@Override
518-
public Annotation[] getAnnotations() {
519-
if (!hasAnnotations(config().constMethodHasMethodAnnotations)) {
520-
return new Annotation[0];
521-
}
522-
return runtime().reflection.getMethodAnnotations(this);
523-
}
524-
525-
@Override
526-
public Annotation[] getDeclaredAnnotations() {
527-
if (!hasAnnotations(config().constMethodHasMethodAnnotations)) {
528-
return new Annotation[0];
529-
}
530-
return runtime().reflection.getMethodDeclaredAnnotations(this);
531-
}
532-
533-
@Override
534-
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
535-
if (!hasAnnotations(config().constMethodHasMethodAnnotations)) {
536-
return null;
537-
}
538-
return runtime().reflection.getMethodAnnotation(this, annotationClass);
539-
}
540-
541507
/**
542508
* Returns whether this method has annotations in the category specified by {@code category}.
543509
*

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,30 +1023,6 @@ private boolean hasDirectAnnotations(boolean typeAnnotations) {
10231023

10241024
private static final Annotation[] NO_ANNOTATIONS = {};
10251025

1026-
@Override
1027-
public Annotation[] getAnnotations() {
1028-
if (!mayHaveAnnotations(true)) {
1029-
return NO_ANNOTATIONS;
1030-
}
1031-
return runtime().reflection.getAnnotations(this);
1032-
}
1033-
1034-
@Override
1035-
public Annotation[] getDeclaredAnnotations() {
1036-
if (!mayHaveAnnotations(false)) {
1037-
return NO_ANNOTATIONS;
1038-
}
1039-
return runtime().reflection.getDeclaredAnnotations(this);
1040-
}
1041-
1042-
@Override
1043-
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
1044-
if (!mayHaveAnnotations(true)) {
1045-
return null;
1046-
}
1047-
return runtime().reflection.getAnnotation(this, annotationClass);
1048-
}
1049-
10501026
/**
10511027
* Performs a fast-path check that this type is resolved in the context of a given accessing
10521028
* class. A negative result does not mean this type is not resolved with respect to

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import jdk.vm.ci.meta.UnresolvedJavaType;
3535
import jdk.vm.ci.meta.annotation.AnnotationsInfo;
3636

37-
import java.lang.annotation.Annotation;
3837
import java.lang.reflect.Modifier;
3938
import java.util.List;
4039

@@ -254,21 +253,6 @@ public List<? extends ResolvedJavaRecordComponent> getRecordComponents() {
254253
return null;
255254
}
256255

257-
@Override
258-
public Annotation[] getAnnotations() {
259-
return new Annotation[0];
260-
}
261-
262-
@Override
263-
public Annotation[] getDeclaredAnnotations() {
264-
return new Annotation[0];
265-
}
266-
267-
@Override
268-
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
269-
return null;
270-
}
271-
272256
@Override
273257
public AnnotationsInfo getTypeAnnotationInfo() {
274258
return null;

0 commit comments

Comments
 (0)