提交 413b5006 编写于 作者: R rbackman

8009382: Add JVM_Get{Field|Method}TypeAnnotations

Reviewed-by: dcubed, rbackman
Contributed-by: NJoel Borggren-Franck <joel.franck@oracle.com>
上级 823ca349
...@@ -135,6 +135,7 @@ SUNWprivate_1.1 { ...@@ -135,6 +135,7 @@ SUNWprivate_1.1 {
JVM_GetEnclosingMethodInfo; JVM_GetEnclosingMethodInfo;
JVM_GetFieldAnnotations; JVM_GetFieldAnnotations;
JVM_GetFieldIxModifiers; JVM_GetFieldIxModifiers;
JVM_GetFieldTypeAnnotations;
JVM_GetHostName; JVM_GetHostName;
JVM_GetInheritedAccessControlContext; JVM_GetInheritedAccessControlContext;
JVM_GetInterfaceVersion; JVM_GetInterfaceVersion;
...@@ -156,6 +157,7 @@ SUNWprivate_1.1 { ...@@ -156,6 +157,7 @@ SUNWprivate_1.1 {
JVM_GetMethodIxSignatureUTF; JVM_GetMethodIxSignatureUTF;
JVM_GetMethodParameterAnnotations; JVM_GetMethodParameterAnnotations;
JVM_GetMethodParameters; JVM_GetMethodParameters;
JVM_GetMethodTypeAnnotations;
JVM_GetPrimitiveArrayElement; JVM_GetPrimitiveArrayElement;
JVM_GetProtectionDomain; JVM_GetProtectionDomain;
JVM_GetSockName; JVM_GetSockName;
......
...@@ -135,6 +135,7 @@ SUNWprivate_1.1 { ...@@ -135,6 +135,7 @@ SUNWprivate_1.1 {
JVM_GetEnclosingMethodInfo; JVM_GetEnclosingMethodInfo;
JVM_GetFieldAnnotations; JVM_GetFieldAnnotations;
JVM_GetFieldIxModifiers; JVM_GetFieldIxModifiers;
JVM_GetFieldTypeAnnotations;
JVM_GetHostName; JVM_GetHostName;
JVM_GetInheritedAccessControlContext; JVM_GetInheritedAccessControlContext;
JVM_GetInterfaceVersion; JVM_GetInterfaceVersion;
...@@ -156,6 +157,7 @@ SUNWprivate_1.1 { ...@@ -156,6 +157,7 @@ SUNWprivate_1.1 {
JVM_GetMethodIxSignatureUTF; JVM_GetMethodIxSignatureUTF;
JVM_GetMethodParameterAnnotations; JVM_GetMethodParameterAnnotations;
JVM_GetMethodParameters; JVM_GetMethodParameters;
JVM_GetMethodTypeAnnotations;
JVM_GetPrimitiveArrayElement; JVM_GetPrimitiveArrayElement;
JVM_GetProtectionDomain; JVM_GetProtectionDomain;
JVM_GetSockName; JVM_GetSockName;
......
...@@ -131,6 +131,7 @@ SUNWprivate_1.1 { ...@@ -131,6 +131,7 @@ SUNWprivate_1.1 {
JVM_GetEnclosingMethodInfo; JVM_GetEnclosingMethodInfo;
JVM_GetFieldAnnotations; JVM_GetFieldAnnotations;
JVM_GetFieldIxModifiers; JVM_GetFieldIxModifiers;
JVM_GetFieldTypeAnnotations;
JVM_GetHostName; JVM_GetHostName;
JVM_GetInheritedAccessControlContext; JVM_GetInheritedAccessControlContext;
JVM_GetInterfaceVersion; JVM_GetInterfaceVersion;
...@@ -152,6 +153,7 @@ SUNWprivate_1.1 { ...@@ -152,6 +153,7 @@ SUNWprivate_1.1 {
JVM_GetMethodIxSignatureUTF; JVM_GetMethodIxSignatureUTF;
JVM_GetMethodParameterAnnotations; JVM_GetMethodParameterAnnotations;
JVM_GetMethodParameters; JVM_GetMethodParameters;
JVM_GetMethodTypeAnnotations;
JVM_GetPrimitiveArrayElement; JVM_GetPrimitiveArrayElement;
JVM_GetProtectionDomain; JVM_GetProtectionDomain;
JVM_GetSockName; JVM_GetSockName;
......
...@@ -131,6 +131,7 @@ SUNWprivate_1.1 { ...@@ -131,6 +131,7 @@ SUNWprivate_1.1 {
JVM_GetEnclosingMethodInfo; JVM_GetEnclosingMethodInfo;
JVM_GetFieldAnnotations; JVM_GetFieldAnnotations;
JVM_GetFieldIxModifiers; JVM_GetFieldIxModifiers;
JVM_GetFieldTypeAnnotations;
JVM_GetHostName; JVM_GetHostName;
JVM_GetInheritedAccessControlContext; JVM_GetInheritedAccessControlContext;
JVM_GetInterfaceVersion; JVM_GetInterfaceVersion;
...@@ -152,6 +153,7 @@ SUNWprivate_1.1 { ...@@ -152,6 +153,7 @@ SUNWprivate_1.1 {
JVM_GetMethodIxSignatureUTF; JVM_GetMethodIxSignatureUTF;
JVM_GetMethodParameterAnnotations; JVM_GetMethodParameterAnnotations;
JVM_GetMethodParameters; JVM_GetMethodParameters;
JVM_GetMethodTypeAnnotations;
JVM_GetPrimitiveArrayElement; JVM_GetPrimitiveArrayElement;
JVM_GetProtectionDomain; JVM_GetProtectionDomain;
JVM_GetSockName; JVM_GetSockName;
......
...@@ -131,6 +131,7 @@ SUNWprivate_1.1 { ...@@ -131,6 +131,7 @@ SUNWprivate_1.1 {
JVM_GetEnclosingMethodInfo; JVM_GetEnclosingMethodInfo;
JVM_GetFieldAnnotations; JVM_GetFieldAnnotations;
JVM_GetFieldIxModifiers; JVM_GetFieldIxModifiers;
JVM_GetFieldTypeAnnotations;
JVM_GetHostName; JVM_GetHostName;
JVM_GetInheritedAccessControlContext; JVM_GetInheritedAccessControlContext;
JVM_GetInterfaceVersion; JVM_GetInterfaceVersion;
...@@ -152,6 +153,7 @@ SUNWprivate_1.1 { ...@@ -152,6 +153,7 @@ SUNWprivate_1.1 {
JVM_GetMethodIxSignatureUTF; JVM_GetMethodIxSignatureUTF;
JVM_GetMethodParameterAnnotations; JVM_GetMethodParameterAnnotations;
JVM_GetMethodParameters; JVM_GetMethodParameters;
JVM_GetMethodTypeAnnotations;
JVM_GetPrimitiveArrayElement; JVM_GetPrimitiveArrayElement;
JVM_GetProtectionDomain; JVM_GetProtectionDomain;
JVM_GetSockName; JVM_GetSockName;
......
...@@ -1457,7 +1457,7 @@ JVM_END ...@@ -1457,7 +1457,7 @@ JVM_END
JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls)) JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls))
assert (cls != NULL, "illegal class"); assert (cls != NULL, "illegal class");
JVMWrapper("JVM_GetClassAnnotations"); JVMWrapper("JVM_GetClassAnnotations");
ResourceMark rm(THREAD);
// Return null for arrays and primitives // Return null for arrays and primitives
if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
...@@ -1470,20 +1470,15 @@ JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls)) ...@@ -1470,20 +1470,15 @@ JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls))
JVM_END JVM_END
JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field)) static bool jvm_get_field_common(jobject field, fieldDescriptor& fd, TRAPS) {
assert(field != NULL, "illegal field");
JVMWrapper("JVM_GetFieldAnnotations");
// some of this code was adapted from from jni_FromReflectedField // some of this code was adapted from from jni_FromReflectedField
// field is a handle to a java.lang.reflect.Field object
oop reflected = JNIHandles::resolve_non_null(field); oop reflected = JNIHandles::resolve_non_null(field);
oop mirror = java_lang_reflect_Field::clazz(reflected); oop mirror = java_lang_reflect_Field::clazz(reflected);
Klass* k = java_lang_Class::as_Klass(mirror); Klass* k = java_lang_Class::as_Klass(mirror);
int slot = java_lang_reflect_Field::slot(reflected); int slot = java_lang_reflect_Field::slot(reflected);
int modifiers = java_lang_reflect_Field::modifiers(reflected); int modifiers = java_lang_reflect_Field::modifiers(reflected);
fieldDescriptor fd;
KlassHandle kh(THREAD, k); KlassHandle kh(THREAD, k);
intptr_t offset = InstanceKlass::cast(kh())->field_offset(slot); intptr_t offset = InstanceKlass::cast(kh())->field_offset(slot);
...@@ -1491,16 +1486,29 @@ JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field)) ...@@ -1491,16 +1486,29 @@ JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field))
// for static fields we only look in the current class // for static fields we only look in the current class
if (!InstanceKlass::cast(kh())->find_local_field_from_offset(offset, true, &fd)) { if (!InstanceKlass::cast(kh())->find_local_field_from_offset(offset, true, &fd)) {
assert(false, "cannot find static field"); assert(false, "cannot find static field");
return NULL; // robustness return false;
} }
} else { } else {
// for instance fields we start with the current class and work // for instance fields we start with the current class and work
// our way up through the superclass chain // our way up through the superclass chain
if (!InstanceKlass::cast(kh())->find_field_from_offset(offset, false, &fd)) { if (!InstanceKlass::cast(kh())->find_field_from_offset(offset, false, &fd)) {
assert(false, "cannot find instance field"); assert(false, "cannot find instance field");
return NULL; // robustness return false;
} }
} }
return true;
}
JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field))
// field is a handle to a java.lang.reflect.Field object
assert(field != NULL, "illegal field");
JVMWrapper("JVM_GetFieldAnnotations");
fieldDescriptor fd;
bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL);
if (!gotFd) {
return NULL;
}
return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.annotations(), THREAD)); return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.annotations(), THREAD));
JVM_END JVM_END
...@@ -1525,12 +1533,8 @@ static Method* jvm_get_method_common(jobject method) { ...@@ -1525,12 +1533,8 @@ static Method* jvm_get_method_common(jobject method) {
Klass* k = java_lang_Class::as_Klass(mirror); Klass* k = java_lang_Class::as_Klass(mirror);
Method* m = InstanceKlass::cast(k)->method_with_idnum(slot); Method* m = InstanceKlass::cast(k)->method_with_idnum(slot);
if (m == NULL) { assert(m != NULL, "cannot find method");
assert(false, "cannot find method"); return m; // caller has to deal with NULL in product mode
return NULL; // robustness
}
return m;
} }
...@@ -1539,6 +1543,10 @@ JVM_ENTRY(jbyteArray, JVM_GetMethodAnnotations(JNIEnv *env, jobject method)) ...@@ -1539,6 +1543,10 @@ JVM_ENTRY(jbyteArray, JVM_GetMethodAnnotations(JNIEnv *env, jobject method))
// method is a handle to a java.lang.reflect.Method object // method is a handle to a java.lang.reflect.Method object
Method* m = jvm_get_method_common(method); Method* m = jvm_get_method_common(method);
if (m == NULL) {
return NULL;
}
return (jbyteArray) JNIHandles::make_local(env, return (jbyteArray) JNIHandles::make_local(env,
Annotations::make_java_array(m->annotations(), THREAD)); Annotations::make_java_array(m->annotations(), THREAD));
JVM_END JVM_END
...@@ -1549,6 +1557,10 @@ JVM_ENTRY(jbyteArray, JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject m ...@@ -1549,6 +1557,10 @@ JVM_ENTRY(jbyteArray, JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject m
// method is a handle to a java.lang.reflect.Method object // method is a handle to a java.lang.reflect.Method object
Method* m = jvm_get_method_common(method); Method* m = jvm_get_method_common(method);
if (m == NULL) {
return NULL;
}
return (jbyteArray) JNIHandles::make_local(env, return (jbyteArray) JNIHandles::make_local(env,
Annotations::make_java_array(m->annotation_default(), THREAD)); Annotations::make_java_array(m->annotation_default(), THREAD));
JVM_END JVM_END
...@@ -1559,6 +1571,10 @@ JVM_ENTRY(jbyteArray, JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject met ...@@ -1559,6 +1571,10 @@ JVM_ENTRY(jbyteArray, JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject met
// method is a handle to a java.lang.reflect.Method object // method is a handle to a java.lang.reflect.Method object
Method* m = jvm_get_method_common(method); Method* m = jvm_get_method_common(method);
if (m == NULL) {
return NULL;
}
return (jbyteArray) JNIHandles::make_local(env, return (jbyteArray) JNIHandles::make_local(env,
Annotations::make_java_array(m->parameter_annotations(), THREAD)); Annotations::make_java_array(m->parameter_annotations(), THREAD));
JVM_END JVM_END
...@@ -1583,6 +1599,38 @@ JVM_ENTRY(jbyteArray, JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls)) ...@@ -1583,6 +1599,38 @@ JVM_ENTRY(jbyteArray, JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls))
return NULL; return NULL;
JVM_END JVM_END
JVM_ENTRY(jbyteArray, JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method))
assert (method != NULL, "illegal method");
JVMWrapper("JVM_GetMethodTypeAnnotations");
// method is a handle to a java.lang.reflect.Method object
Method* m = jvm_get_method_common(method);
if (m == NULL) {
return NULL;
}
AnnotationArray* type_annotations = m->type_annotations();
if (type_annotations != NULL) {
typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL);
return (jbyteArray) JNIHandles::make_local(env, a);
}
return NULL;
JVM_END
JVM_ENTRY(jbyteArray, JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field))
assert (field != NULL, "illegal field");
JVMWrapper("JVM_GetFieldTypeAnnotations");
fieldDescriptor fd;
bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL);
if (!gotFd) {
return NULL;
}
return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD));
JVM_END
static void bounds_check(constantPoolHandle cp, jint index, TRAPS) { static void bounds_check(constantPoolHandle cp, jint index, TRAPS) {
if (!cp->is_within_bounds(index)) { if (!cp->is_within_bounds(index)) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds"); THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
......
...@@ -523,6 +523,14 @@ JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method); ...@@ -523,6 +523,14 @@ JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method);
JNIEXPORT jbyteArray JNICALL JNIEXPORT jbyteArray JNICALL
JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls); JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls);
// field is a handle to a java.lang.reflect.Field object
JNIEXPORT jbyteArray JNICALL
JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field);
// method is a handle to a java.lang.reflect.Method object
JNIEXPORT jbyteArray JNICALL
JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method);
/* /*
* New (JDK 1.4) reflection implementation * New (JDK 1.4) reflection implementation
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册