Tue, 26 Mar 2013 15:00:34 +0100
8009382: Add JVM_Get{Field|Method}TypeAnnotations
Reviewed-by: dcubed, rbackman
Contributed-by: Joel Borggren-Franck <joel.franck@oracle.com>
1.1 --- a/make/bsd/makefiles/mapfile-vers-debug Mon Mar 25 09:36:15 2013 -0700 1.2 +++ b/make/bsd/makefiles/mapfile-vers-debug Tue Mar 26 15:00:34 2013 +0100 1.3 @@ -135,6 +135,7 @@ 1.4 JVM_GetEnclosingMethodInfo; 1.5 JVM_GetFieldAnnotations; 1.6 JVM_GetFieldIxModifiers; 1.7 + JVM_GetFieldTypeAnnotations; 1.8 JVM_GetHostName; 1.9 JVM_GetInheritedAccessControlContext; 1.10 JVM_GetInterfaceVersion; 1.11 @@ -156,6 +157,7 @@ 1.12 JVM_GetMethodIxSignatureUTF; 1.13 JVM_GetMethodParameterAnnotations; 1.14 JVM_GetMethodParameters; 1.15 + JVM_GetMethodTypeAnnotations; 1.16 JVM_GetPrimitiveArrayElement; 1.17 JVM_GetProtectionDomain; 1.18 JVM_GetSockName;
2.1 --- a/make/bsd/makefiles/mapfile-vers-product Mon Mar 25 09:36:15 2013 -0700 2.2 +++ b/make/bsd/makefiles/mapfile-vers-product Tue Mar 26 15:00:34 2013 +0100 2.3 @@ -135,6 +135,7 @@ 2.4 JVM_GetEnclosingMethodInfo; 2.5 JVM_GetFieldAnnotations; 2.6 JVM_GetFieldIxModifiers; 2.7 + JVM_GetFieldTypeAnnotations; 2.8 JVM_GetHostName; 2.9 JVM_GetInheritedAccessControlContext; 2.10 JVM_GetInterfaceVersion; 2.11 @@ -156,6 +157,7 @@ 2.12 JVM_GetMethodIxSignatureUTF; 2.13 JVM_GetMethodParameterAnnotations; 2.14 JVM_GetMethodParameters; 2.15 + JVM_GetMethodTypeAnnotations; 2.16 JVM_GetPrimitiveArrayElement; 2.17 JVM_GetProtectionDomain; 2.18 JVM_GetSockName;
3.1 --- a/make/linux/makefiles/mapfile-vers-debug Mon Mar 25 09:36:15 2013 -0700 3.2 +++ b/make/linux/makefiles/mapfile-vers-debug Tue Mar 26 15:00:34 2013 +0100 3.3 @@ -131,6 +131,7 @@ 3.4 JVM_GetEnclosingMethodInfo; 3.5 JVM_GetFieldAnnotations; 3.6 JVM_GetFieldIxModifiers; 3.7 + JVM_GetFieldTypeAnnotations; 3.8 JVM_GetHostName; 3.9 JVM_GetInheritedAccessControlContext; 3.10 JVM_GetInterfaceVersion; 3.11 @@ -152,6 +153,7 @@ 3.12 JVM_GetMethodIxSignatureUTF; 3.13 JVM_GetMethodParameterAnnotations; 3.14 JVM_GetMethodParameters; 3.15 + JVM_GetMethodTypeAnnotations; 3.16 JVM_GetPrimitiveArrayElement; 3.17 JVM_GetProtectionDomain; 3.18 JVM_GetSockName;
4.1 --- a/make/linux/makefiles/mapfile-vers-product Mon Mar 25 09:36:15 2013 -0700 4.2 +++ b/make/linux/makefiles/mapfile-vers-product Tue Mar 26 15:00:34 2013 +0100 4.3 @@ -131,6 +131,7 @@ 4.4 JVM_GetEnclosingMethodInfo; 4.5 JVM_GetFieldAnnotations; 4.6 JVM_GetFieldIxModifiers; 4.7 + JVM_GetFieldTypeAnnotations; 4.8 JVM_GetHostName; 4.9 JVM_GetInheritedAccessControlContext; 4.10 JVM_GetInterfaceVersion; 4.11 @@ -152,6 +153,7 @@ 4.12 JVM_GetMethodIxSignatureUTF; 4.13 JVM_GetMethodParameterAnnotations; 4.14 JVM_GetMethodParameters; 4.15 + JVM_GetMethodTypeAnnotations; 4.16 JVM_GetPrimitiveArrayElement; 4.17 JVM_GetProtectionDomain; 4.18 JVM_GetSockName;
5.1 --- a/make/solaris/makefiles/mapfile-vers Mon Mar 25 09:36:15 2013 -0700 5.2 +++ b/make/solaris/makefiles/mapfile-vers Tue Mar 26 15:00:34 2013 +0100 5.3 @@ -131,6 +131,7 @@ 5.4 JVM_GetEnclosingMethodInfo; 5.5 JVM_GetFieldAnnotations; 5.6 JVM_GetFieldIxModifiers; 5.7 + JVM_GetFieldTypeAnnotations; 5.8 JVM_GetHostName; 5.9 JVM_GetInheritedAccessControlContext; 5.10 JVM_GetInterfaceVersion; 5.11 @@ -152,6 +153,7 @@ 5.12 JVM_GetMethodIxSignatureUTF; 5.13 JVM_GetMethodParameterAnnotations; 5.14 JVM_GetMethodParameters; 5.15 + JVM_GetMethodTypeAnnotations; 5.16 JVM_GetPrimitiveArrayElement; 5.17 JVM_GetProtectionDomain; 5.18 JVM_GetSockName;
6.1 --- a/src/share/vm/prims/jvm.cpp Mon Mar 25 09:36:15 2013 -0700 6.2 +++ b/src/share/vm/prims/jvm.cpp Tue Mar 26 15:00:34 2013 +0100 6.3 @@ -1457,7 +1457,7 @@ 6.4 JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls)) 6.5 assert (cls != NULL, "illegal class"); 6.6 JVMWrapper("JVM_GetClassAnnotations"); 6.7 - ResourceMark rm(THREAD); 6.8 + 6.9 // Return null for arrays and primitives 6.10 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { 6.11 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); 6.12 @@ -1470,20 +1470,15 @@ 6.13 JVM_END 6.14 6.15 6.16 -JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field)) 6.17 - assert(field != NULL, "illegal field"); 6.18 - JVMWrapper("JVM_GetFieldAnnotations"); 6.19 - 6.20 +static bool jvm_get_field_common(jobject field, fieldDescriptor& fd, TRAPS) { 6.21 // some of this code was adapted from from jni_FromReflectedField 6.22 6.23 - // field is a handle to a java.lang.reflect.Field object 6.24 oop reflected = JNIHandles::resolve_non_null(field); 6.25 oop mirror = java_lang_reflect_Field::clazz(reflected); 6.26 Klass* k = java_lang_Class::as_Klass(mirror); 6.27 int slot = java_lang_reflect_Field::slot(reflected); 6.28 int modifiers = java_lang_reflect_Field::modifiers(reflected); 6.29 6.30 - fieldDescriptor fd; 6.31 KlassHandle kh(THREAD, k); 6.32 intptr_t offset = InstanceKlass::cast(kh())->field_offset(slot); 6.33 6.34 @@ -1491,16 +1486,29 @@ 6.35 // for static fields we only look in the current class 6.36 if (!InstanceKlass::cast(kh())->find_local_field_from_offset(offset, true, &fd)) { 6.37 assert(false, "cannot find static field"); 6.38 - return NULL; // robustness 6.39 + return false; 6.40 } 6.41 } else { 6.42 // for instance fields we start with the current class and work 6.43 // our way up through the superclass chain 6.44 if (!InstanceKlass::cast(kh())->find_field_from_offset(offset, false, &fd)) { 6.45 assert(false, "cannot find instance field"); 6.46 - return NULL; // robustness 6.47 + return false; 6.48 } 6.49 } 6.50 + return true; 6.51 +} 6.52 + 6.53 +JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field)) 6.54 + // field is a handle to a java.lang.reflect.Field object 6.55 + assert(field != NULL, "illegal field"); 6.56 + JVMWrapper("JVM_GetFieldAnnotations"); 6.57 + 6.58 + fieldDescriptor fd; 6.59 + bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL); 6.60 + if (!gotFd) { 6.61 + return NULL; 6.62 + } 6.63 6.64 return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.annotations(), THREAD)); 6.65 JVM_END 6.66 @@ -1525,12 +1533,8 @@ 6.67 Klass* k = java_lang_Class::as_Klass(mirror); 6.68 6.69 Method* m = InstanceKlass::cast(k)->method_with_idnum(slot); 6.70 - if (m == NULL) { 6.71 - assert(false, "cannot find method"); 6.72 - return NULL; // robustness 6.73 - } 6.74 - 6.75 - return m; 6.76 + assert(m != NULL, "cannot find method"); 6.77 + return m; // caller has to deal with NULL in product mode 6.78 } 6.79 6.80 6.81 @@ -1539,6 +1543,10 @@ 6.82 6.83 // method is a handle to a java.lang.reflect.Method object 6.84 Method* m = jvm_get_method_common(method); 6.85 + if (m == NULL) { 6.86 + return NULL; 6.87 + } 6.88 + 6.89 return (jbyteArray) JNIHandles::make_local(env, 6.90 Annotations::make_java_array(m->annotations(), THREAD)); 6.91 JVM_END 6.92 @@ -1549,6 +1557,10 @@ 6.93 6.94 // method is a handle to a java.lang.reflect.Method object 6.95 Method* m = jvm_get_method_common(method); 6.96 + if (m == NULL) { 6.97 + return NULL; 6.98 + } 6.99 + 6.100 return (jbyteArray) JNIHandles::make_local(env, 6.101 Annotations::make_java_array(m->annotation_default(), THREAD)); 6.102 JVM_END 6.103 @@ -1559,6 +1571,10 @@ 6.104 6.105 // method is a handle to a java.lang.reflect.Method object 6.106 Method* m = jvm_get_method_common(method); 6.107 + if (m == NULL) { 6.108 + return NULL; 6.109 + } 6.110 + 6.111 return (jbyteArray) JNIHandles::make_local(env, 6.112 Annotations::make_java_array(m->parameter_annotations(), THREAD)); 6.113 JVM_END 6.114 @@ -1583,6 +1599,38 @@ 6.115 return NULL; 6.116 JVM_END 6.117 6.118 +JVM_ENTRY(jbyteArray, JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method)) 6.119 + assert (method != NULL, "illegal method"); 6.120 + JVMWrapper("JVM_GetMethodTypeAnnotations"); 6.121 + 6.122 + // method is a handle to a java.lang.reflect.Method object 6.123 + Method* m = jvm_get_method_common(method); 6.124 + if (m == NULL) { 6.125 + return NULL; 6.126 + } 6.127 + 6.128 + AnnotationArray* type_annotations = m->type_annotations(); 6.129 + if (type_annotations != NULL) { 6.130 + typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL); 6.131 + return (jbyteArray) JNIHandles::make_local(env, a); 6.132 + } 6.133 + 6.134 + return NULL; 6.135 +JVM_END 6.136 + 6.137 +JVM_ENTRY(jbyteArray, JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field)) 6.138 + assert (field != NULL, "illegal field"); 6.139 + JVMWrapper("JVM_GetFieldTypeAnnotations"); 6.140 + 6.141 + fieldDescriptor fd; 6.142 + bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL); 6.143 + if (!gotFd) { 6.144 + return NULL; 6.145 + } 6.146 + 6.147 + return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD)); 6.148 +JVM_END 6.149 + 6.150 static void bounds_check(constantPoolHandle cp, jint index, TRAPS) { 6.151 if (!cp->is_within_bounds(index)) { 6.152 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
7.1 --- a/src/share/vm/prims/jvm.h Mon Mar 25 09:36:15 2013 -0700 7.2 +++ b/src/share/vm/prims/jvm.h Tue Mar 26 15:00:34 2013 +0100 7.3 @@ -523,6 +523,14 @@ 7.4 JNIEXPORT jbyteArray JNICALL 7.5 JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls); 7.6 7.7 +// field is a handle to a java.lang.reflect.Field object 7.8 +JNIEXPORT jbyteArray JNICALL 7.9 +JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field); 7.10 + 7.11 +// method is a handle to a java.lang.reflect.Method object 7.12 +JNIEXPORT jbyteArray JNICALL 7.13 +JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method); 7.14 + 7.15 /* 7.16 * New (JDK 1.4) reflection implementation 7.17 */