Skip to content

Commit 2701301

Browse files
committed
removed types parameter from Annotated.getDeclaredAnnotationValues()
1 parent ece77ee commit 2701301

File tree

17 files changed

+71
-199
lines changed

17 files changed

+71
-199
lines changed

src/hotspot/share/classfile/vmSymbols.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ class SerializeClosure;
706706
template(encodeThrowable_signature, "(Ljava/lang/Throwable;JI)I") \
707707
template(decodeAndThrowThrowable_name, "decodeAndThrowThrowable") \
708708
template(encodeAnnotations_name, "encodeAnnotations") \
709-
template(encodeAnnotations_signature, "([BILjava/lang/Class;Ljdk/internal/reflect/ConstantPool;[Ljava/lang/Class;)[B")\
709+
template(encodeAnnotations_signature, "([BILjava/lang/Class;Ljdk/internal/reflect/ConstantPool;)[B")\
710710
template(decodeAndThrowThrowable_signature, "(IJZZ)V") \
711711
template(classRedefinedCount_name, "classRedefinedCount") \
712712
template(classLoader_name, "classLoader") \

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,9 +3014,7 @@ C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAI
30143014
return JNIHandles::make_local(THREAD, reflected);
30153015
C2V_END
30163016

3017-
static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, AnnotationArray* annotations_array,
3018-
jint category,
3019-
jint filter_length, jlong filter_klass_pointers,
3017+
static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, AnnotationArray* annotations_array, jint category,
30203018
JavaThread* THREAD, JVMCI_TRAPS) {
30213019
// Get a ConstantPool object for annotation parsing
30223020
Handle jcp = reflect_ConstantPool::create(CHECK_NULL);
@@ -3034,26 +3032,13 @@ static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, Annotatio
30343032
typeArrayOop annotations_oop = Annotations::make_java_array(annotations_array, CHECK_NULL);
30353033
typeArrayHandle annotations = typeArrayHandle(THREAD, annotations_oop);
30363034

3037-
objArrayHandle filter_classes;
3038-
if (filter_length != 0) {
3039-
InstanceKlass** filter = filter_length == 1 ?
3040-
(InstanceKlass**) &filter_klass_pointers:
3041-
(InstanceKlass**) filter_klass_pointers;
3042-
objArrayOop filter_oop = oopFactory::new_objArray(vmClasses::Class_klass(), filter_length, CHECK_NULL);
3043-
filter_classes = objArrayHandle(THREAD, filter_oop);
3044-
for (int i = 0; i < filter_length; i++) {
3045-
filter_classes->obj_at_put(i, filter[i]->java_mirror());
3046-
}
3047-
}
3048-
30493035
// invoke VMSupport.encodeAnnotations
30503036
JavaValue result(T_OBJECT);
30513037
JavaCallArguments args;
30523038
args.push_oop(annotations);
30533039
args.push_int(category);
30543040
args.push_oop(Handle(THREAD, holder->java_mirror()));
30553041
args.push_oop(jcp);
3056-
args.push_oop(filter_classes);
30573042
Symbol* signature = vmSymbols::encodeAnnotations_signature();
30583043
JavaCalls::call_static(&result,
30593044
vm_support,
@@ -3081,8 +3066,7 @@ static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, Annotatio
30813066
return JVMCIENV->get_jbyteArray(ba_dest);
30823067
}
30833068

3084-
C2V_VMENTRY_NULL(jbyteArray, getEncodedClassAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint category,
3085-
jobject filter, jint filter_length, jlong filter_klass_pointers))
3069+
C2V_VMENTRY_NULL(jbyteArray, getEncodedClassAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint category))
30863070
CompilerThreadCanCallJava canCallJava(thread, true); // Requires Java support
30873071
InstanceKlass* holder = InstanceKlass::cast(UNPACK_PAIR(Klass, klass));
30883072
AnnotationArray* raw_annotations;
@@ -3094,11 +3078,10 @@ C2V_VMENTRY_NULL(jbyteArray, getEncodedClassAnnotationValues, (JNIEnv* env, jobj
30943078
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
30953079
err_msg("%d", category));
30963080
}
3097-
return get_encoded_annotation_values(holder, raw_annotations, category, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
3081+
return get_encoded_annotation_values(holder, raw_annotations, category, THREAD, JVMCIENV);
30983082
C2V_END
30993083

3100-
C2V_VMENTRY_NULL(jbyteArray, getEncodedExecutableAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(method), jint category,
3101-
jobject filter, jint filter_length, jlong filter_klass_pointers))
3084+
C2V_VMENTRY_NULL(jbyteArray, getEncodedExecutableAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(method), jint category))
31023085
CompilerThreadCanCallJava canCallJava(thread, true); // Requires Java support
31033086
methodHandle method(THREAD, UNPACK_PAIR(Method, method));
31043087
AnnotationArray* raw_annotations;
@@ -3111,11 +3094,10 @@ C2V_VMENTRY_NULL(jbyteArray, getEncodedExecutableAnnotationValues, (JNIEnv* env,
31113094
} else {
31123095
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), err_msg("%d", category));
31133096
}
3114-
return get_encoded_annotation_values(method->method_holder(), raw_annotations, category, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
3097+
return get_encoded_annotation_values(method->method_holder(), raw_annotations, category, THREAD, JVMCIENV);
31153098
C2V_END
31163099

3117-
C2V_VMENTRY_NULL(jbyteArray, getEncodedFieldAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index, jint category,
3118-
jobject filter, jint filter_length, jlong filter_klass_pointers))
3100+
C2V_VMENTRY_NULL(jbyteArray, getEncodedFieldAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index, jint category))
31193101
CompilerThreadCanCallJava canCallJava(thread, true); // Requires Java support
31203102
InstanceKlass* holder = check_field(InstanceKlass::cast(UNPACK_PAIR(Klass, klass)), index, JVMCI_CHECK_NULL);
31213103
fieldDescriptor fd(holder, index);
@@ -3128,7 +3110,7 @@ C2V_VMENTRY_NULL(jbyteArray, getEncodedFieldAnnotationValues, (JNIEnv* env, jobj
31283110
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
31293111
err_msg("%d", category));
31303112
}
3131-
return get_encoded_annotation_values(holder, raw_annotations, category, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
3113+
return get_encoded_annotation_values(holder, raw_annotations, category, THREAD, JVMCIENV);
31323114
C2V_END
31333115

31343116
C2V_VMENTRY_NULL(jobjectArray, getFailedSpeculations, (JNIEnv* env, jobject, jlong failed_speculations_address, jobjectArray current))
@@ -3472,9 +3454,9 @@ JNINativeMethod CompilerToVM::methods[] = {
34723454
{CC "getCode", CC "(" HS_INSTALLED_CODE ")[B", FN_PTR(getCode)},
34733455
{CC "asReflectionExecutable", CC "(" HS_METHOD2 ")" REFLECTION_EXECUTABLE, FN_PTR(asReflectionExecutable)},
34743456
{CC "asReflectionField", CC "(" HS_KLASS2 "I)" REFLECTION_FIELD, FN_PTR(asReflectionField)},
3475-
{CC "getEncodedClassAnnotationValues", CC "(" HS_KLASS2 "I" OBJECT "IJ)[B", FN_PTR(getEncodedClassAnnotationValues)},
3476-
{CC "getEncodedExecutableAnnotationValues", CC "(" HS_METHOD2 "I" OBJECT "IJ)[B", FN_PTR(getEncodedExecutableAnnotationValues)},
3477-
{CC "getEncodedFieldAnnotationValues", CC "(" HS_KLASS2 "II" OBJECT "IJ)[B", FN_PTR(getEncodedFieldAnnotationValues)},
3457+
{CC "getEncodedClassAnnotationValues", CC "(" HS_KLASS2 "I)[B", FN_PTR(getEncodedClassAnnotationValues)},
3458+
{CC "getEncodedExecutableAnnotationValues", CC "(" HS_METHOD2 "I)[B", FN_PTR(getEncodedExecutableAnnotationValues)},
3459+
{CC "getEncodedFieldAnnotationValues", CC "(" HS_KLASS2 "II)[B", FN_PTR(getEncodedFieldAnnotationValues)},
34783460
{CC "getFailedSpeculations", CC "(J[[B)[[B", FN_PTR(getFailedSpeculations)},
34793461
{CC "getFailedSpeculationsAddress", CC "(" HS_METHOD2 ")J", FN_PTR(getFailedSpeculationsAddress)},
34803462
{CC "releaseFailedSpeculations", CC "(J)V", FN_PTR(releaseFailedSpeculations)},

src/java.base/share/classes/java/lang/Class.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3674,7 +3674,7 @@ private AnnotationData annotationData() {
36743674

36753675
private AnnotationData createAnnotationData(int classRedefinedCount) {
36763676
Map<Class<? extends Annotation>, Annotation> declaredAnnotations =
3677-
AnnotationParser.parseAnnotations(getRawAnnotations(), getConstantPool(), this);
3677+
AnnotationParser.parseAnnotations(getRawAnnotations(), getConstantPool(), this, true);
36783678
Class<?> superClass = getSuperclass();
36793679
Map<Class<? extends Annotation>, Annotation> annotations = null;
36803680
if (superClass != null) {

src/java.base/share/classes/java/lang/reflect/Executable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
669669
getAnnotationBytes(),
670670
SharedSecrets.getJavaLangAccess().
671671
getConstantPool(getDeclaringClass()),
672-
getDeclaringClass()
673-
);
672+
getDeclaringClass(),
673+
true);
674674
}
675675
declaredAnnotations = declAnnos;
676676
}

src/java.base/share/classes/java/lang/reflect/Field.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
12771277
annotations,
12781278
SharedSecrets.getJavaLangAccess()
12791279
.getConstantPool(getDeclaringClass()),
1280-
getDeclaringClass());
1280+
getDeclaringClass(), true);
12811281
}
12821282
declaredAnnotations = declAnnos;
12831283
}

src/java.base/share/classes/java/lang/reflect/RecordComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
198198
annotations,
199199
SharedSecrets.getJavaLangAccess()
200200
.getConstantPool(getDeclaringRecord()),
201-
getDeclaringRecord());
201+
getDeclaringRecord(), true);
202202
}
203203
declaredAnnotations = declAnnos;
204204
}

src/java.base/share/classes/jdk/internal/vm/VMSupport.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,10 @@ public static int encodeThrowable(Throwable throwable, long buffer, int bufferSi
216216
public static byte[] encodeAnnotations(byte[] rawAnnotations,
217217
int category,
218218
Class<?> declaringClass,
219-
ConstantPool cp,
220-
Class<? extends Annotation>[] selectAnnotationClasses) {
219+
ConstantPool cp) {
221220
return switch (category) {
222-
case DECLARED_ANNOTATIONS -> {
223-
if (selectAnnotationClasses != null) {
224-
if (selectAnnotationClasses.length == 0) {
225-
throw new IllegalArgumentException("annotation class selection must be null or non-empty");
226-
}
227-
for (Class<?> c : selectAnnotationClasses) {
228-
if (!c.isAnnotation()) {
229-
throw new IllegalArgumentException(c + " is not an annotation interface");
230-
}
231-
}
232-
}
233-
yield encodeAnnotations(AnnotationParser.parseSelectAnnotations(rawAnnotations, cp, declaringClass, false, selectAnnotationClasses).values());
234-
}
221+
case DECLARED_ANNOTATIONS ->
222+
encodeAnnotations(AnnotationParser.parseAnnotations(rawAnnotations, cp, declaringClass, false).values());
235223
case PARAMETER_ANNOTATIONS ->
236224
encodeParameterAnnotations(AnnotationParser.parseParameterAnnotations(rawAnnotations, cp, declaringClass));
237225
case TYPE_ANNOTATIONS ->

src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ public class AnnotationParser {
6565
public static Map<Class<? extends Annotation>, Annotation> parseAnnotations(
6666
byte[] rawAnnotations,
6767
ConstantPool constPool,
68-
Class<?> container) {
68+
Class<?> container,
69+
boolean eagerResolution) {
6970
if (rawAnnotations == null)
7071
return Collections.emptyMap();
7172

7273
try {
73-
return parseAnnotations2(rawAnnotations, constPool, container, true, null);
74+
return parseAnnotations2(rawAnnotations, constPool, container, eagerResolution, null);
7475
} catch(BufferUnderflowException e) {
7576
throw new AnnotationFormatError("Unexpected end of annotations.");
7677
} catch(IllegalArgumentException e) {
@@ -80,7 +81,7 @@ public static Map<Class<? extends Annotation>, Annotation> parseAnnotations(
8081
}
8182

8283
/**
83-
* Like {@link #parseAnnotations(byte[], jdk.internal.reflect.ConstantPool, Class)}
84+
* Like {@link #parseAnnotations(byte[], jdk.internal.reflect.ConstantPool, Class, boolean)}
8485
* with an additional parameter {@code selectAnnotationClasses} which selects the
8586
* annotation types to parse (other than selected are quickly skipped).<p>
8687
* This method is used to parse select meta annotations in the construction

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

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,93 +1449,31 @@ native void notifyCompilerInliningEvent(int compileId, HotSpotResolvedJavaMethod
14491449
* Gets the serialized annotation info for {@code type} by calling
14501450
* {@code VMSupport.encodeAnnotations} in the HotSpot heap.
14511451
*/
1452-
byte[] getEncodedClassAnnotationValues(HotSpotResolvedObjectTypeImpl type, int category, ResolvedJavaType[] filter) {
1453-
try (KlassPointers a = new KlassPointers(filter)) {
1454-
return getEncodedClassAnnotationValues(type, type.getKlassPointer(), category,
1455-
a.types, a.length(), a.buffer());
1456-
}
1452+
byte[] getEncodedClassAnnotationValues(HotSpotResolvedObjectTypeImpl type, int category) {
1453+
return getEncodedClassAnnotationValues(type, type.getKlassPointer(), category);
14571454
}
14581455

1459-
native byte[] getEncodedClassAnnotationValues(HotSpotResolvedObjectTypeImpl type, long klassPointer, int category,
1460-
Object filter, int filterLength, long filterKlassPointers);
1456+
native byte[] getEncodedClassAnnotationValues(HotSpotResolvedObjectTypeImpl type, long klassPointer, int category);
14611457

14621458
/**
14631459
* Gets the serialized annotation info for {@code method} by calling
14641460
* {@code VMSupport.encodeAnnotations} in the HotSpot heap.
14651461
*/
1466-
byte[] getEncodedExecutableAnnotationValues(HotSpotResolvedJavaMethodImpl method, int category, ResolvedJavaType[] filter) {
1467-
try (KlassPointers a = new KlassPointers(filter)) {
1468-
return getEncodedExecutableAnnotationValues(method, method.getMethodPointer(), category,
1469-
a.types, a.length(), a.buffer());
1470-
}
1462+
byte[] getEncodedExecutableAnnotationValues(HotSpotResolvedJavaMethodImpl method, int category) {
1463+
return getEncodedExecutableAnnotationValues(method, method.getMethodPointer(), category);
14711464
}
14721465

1473-
native byte[] getEncodedExecutableAnnotationValues(HotSpotResolvedJavaMethodImpl method, long methodPointer, int category,
1474-
Object filter, int filterLength, long filterKlassPointers);
1466+
native byte[] getEncodedExecutableAnnotationValues(HotSpotResolvedJavaMethodImpl method, long methodPointer, int category);
14751467

14761468
/**
14771469
* Gets the serialized annotation info for the field denoted by {@code holder} and
14781470
* {@code fieldIndex} by calling {@code VMSupport.encodeAnnotations} in the HotSpot heap.
14791471
*/
1480-
byte[] getEncodedFieldAnnotationValues(HotSpotResolvedObjectTypeImpl holder, int fieldIndex, int category, ResolvedJavaType[] filter) {
1481-
try (KlassPointers a = new KlassPointers(filter)) {
1482-
return getEncodedFieldAnnotationValues(holder, holder.getKlassPointer(), fieldIndex, category,
1483-
a.types, a.length(), a.buffer());
1484-
}
1472+
byte[] getEncodedFieldAnnotationValues(HotSpotResolvedObjectTypeImpl holder, int fieldIndex, int category) {
1473+
return getEncodedFieldAnnotationValues(holder, holder.getKlassPointer(), fieldIndex, category);
14851474
}
14861475

1487-
native byte[] getEncodedFieldAnnotationValues(HotSpotResolvedObjectTypeImpl holder, long klassPointer, int fieldIndex, int category,
1488-
Object filterTypes, int filterLength, long filterKlassPointers);
1489-
1490-
/**
1491-
* Helper for passing {@code Klass*} values to native code.
1492-
*/
1493-
static final class KlassPointers implements AutoCloseable {
1494-
final ResolvedJavaType[] types;
1495-
long pointersArray;
1496-
final Unsafe unsafe = UnsafeAccess.UNSAFE;
1497-
1498-
KlassPointers(ResolvedJavaType[] types) {
1499-
this.types = types;
1500-
}
1501-
1502-
int length() {
1503-
return types == null ? 0 : types.length;
1504-
}
1505-
1506-
/**
1507-
* Gets the buffer in which to pass the {@code Klass*} values to JNI.
1508-
*
1509-
* @return 0L if {@code types.length == 0}, a {@code Klass*} value if {@code types.length == 1}
1510-
* otherwise the address of a native buffer holding an array of {@code Klass*} values
1511-
*/
1512-
long buffer() {
1513-
long length = length();
1514-
if (length == 0) {
1515-
return 0L;
1516-
}
1517-
if (length == 1) {
1518-
return ((HotSpotResolvedObjectTypeImpl) types[0]).getKlassPointer();
1519-
} else {
1520-
pointersArray = unsafe.allocateMemory(length * Long.BYTES);
1521-
long pos = pointersArray;
1522-
for (ResolvedJavaType type : types) {
1523-
HotSpotResolvedObjectTypeImpl hsType = (HotSpotResolvedObjectTypeImpl) type;
1524-
unsafe.putLong(pos, hsType.getKlassPointer());
1525-
pos += Long.BYTES;
1526-
}
1527-
}
1528-
return pointersArray;
1529-
}
1530-
1531-
@Override
1532-
public void close() {
1533-
if (pointersArray != 0) {
1534-
unsafe.freeMemory(pointersArray);
1535-
pointersArray = 0;
1536-
}
1537-
}
1538-
}
1476+
native byte[] getEncodedFieldAnnotationValues(HotSpotResolvedObjectTypeImpl holder, long klassPointer, int fieldIndex, int category);
15391477

15401478
/**
15411479
* @see HotSpotResolvedJavaMethod#getOopMapAt

0 commit comments

Comments
 (0)