src/share/vm/prims/jvm.cpp
Print this page
@@ -1455,11 +1455,11 @@
JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls))
assert (cls != NULL, "illegal class");
JVMWrapper("JVM_GetClassAnnotations");
- ResourceMark rm(THREAD);
+
// Return null for arrays and primitives
if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
if (k->oop_is_instance()) {
typeArrayOop a = Annotations::make_java_array(InstanceKlass::cast(k)->class_annotations(), CHECK_NULL);
@@ -1468,40 +1468,48 @@
}
return NULL;
JVM_END
-JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field))
- assert(field != NULL, "illegal field");
- JVMWrapper("JVM_GetFieldAnnotations");
-
+static bool jvm_get_field_common(jobject field, fieldDescriptor& fd, TRAPS) {
// 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 mirror = java_lang_reflect_Field::clazz(reflected);
Klass* k = java_lang_Class::as_Klass(mirror);
int slot = java_lang_reflect_Field::slot(reflected);
int modifiers = java_lang_reflect_Field::modifiers(reflected);
- fieldDescriptor fd;
KlassHandle kh(THREAD, k);
intptr_t offset = InstanceKlass::cast(kh())->field_offset(slot);
if (modifiers & JVM_ACC_STATIC) {
// for static fields we only look in the current class
if (!InstanceKlass::cast(kh())->find_local_field_from_offset(offset, true, &fd)) {
assert(false, "cannot find static field");
- return NULL; // robustness
+ return false;
}
} else {
// for instance fields we start with the current class and work
// our way up through the superclass chain
if (!InstanceKlass::cast(kh())->find_field_from_offset(offset, false, &fd)) {
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));
JVM_END
@@ -1523,44 +1531,52 @@
slot = java_lang_reflect_Method::slot(reflected);
}
Klass* k = java_lang_Class::as_Klass(mirror);
Method* m = InstanceKlass::cast(k)->method_with_idnum(slot);
- if (m == NULL) {
- assert(false, "cannot find method");
- return NULL; // robustness
- }
-
- return m;
+ assert(m != NULL, "cannot find method");
+ return m; // caller has to deal with NULL in product mode
}
JVM_ENTRY(jbyteArray, JVM_GetMethodAnnotations(JNIEnv *env, jobject method))
JVMWrapper("JVM_GetMethodAnnotations");
// method is a handle to a java.lang.reflect.Method object
Method* m = jvm_get_method_common(method);
+ if (m == NULL) {
+ return NULL;
+ }
+
return (jbyteArray) JNIHandles::make_local(env,
Annotations::make_java_array(m->annotations(), THREAD));
JVM_END
JVM_ENTRY(jbyteArray, JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method))
JVMWrapper("JVM_GetMethodDefaultAnnotationValue");
// method is a handle to a java.lang.reflect.Method object
Method* m = jvm_get_method_common(method);
+ if (m == NULL) {
+ return NULL;
+ }
+
return (jbyteArray) JNIHandles::make_local(env,
Annotations::make_java_array(m->annotation_default(), THREAD));
JVM_END
JVM_ENTRY(jbyteArray, JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method))
JVMWrapper("JVM_GetMethodParameterAnnotations");
// method is a handle to a java.lang.reflect.Method object
Method* m = jvm_get_method_common(method);
+ if (m == NULL) {
+ return NULL;
+ }
+
return (jbyteArray) JNIHandles::make_local(env,
Annotations::make_java_array(m->parameter_annotations(), THREAD));
JVM_END
/* Type use annotations support (JDK 1.8) */
@@ -1581,10 +1597,42 @@
}
}
return NULL;
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) {
if (!cp->is_within_bounds(index)) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
}
}