Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: java_lang_reflect_Method.c 8249 2007-07-31 12:59:03Z panzi $
-
*/
#include "vm/types.h"
#include "native/jni.h"
+#include "native/llni.h"
#include "native/native.h"
#include "native/include/java_lang_Object.h"
#include "native/include/java_lang_String.h"
#if defined(ENABLE_ANNOTATIONS)
+#include "native/include/java_util_Map.h"
#include "native/include/sun_reflect_ConstantPool.h"
+#include "native/vm/reflect.h"
#endif
#include "native/include/java_lang_reflect_Method.h"
/* native methods implemented by this file ************************************/
static JNINativeMethod methods[] = {
- { "getModifiersInternal", "()I", (void *) (ptrint) &Java_java_lang_reflect_Method_getModifiersInternal },
- { "getReturnType", "()Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getReturnType },
- { "getParameterTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getParameterTypes },
- { "getExceptionTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getExceptionTypes },
- { "invokeNative", "(Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_invokeNative },
- { "getSignature", "()Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_reflect_Method_getSignature },
+ { "getModifiersInternal", "()I", (void *) (ptrint) &Java_java_lang_reflect_Method_getModifiersInternal },
+ { "getReturnType", "()Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getReturnType },
+ { "getParameterTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getParameterTypes },
+ { "getExceptionTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getExceptionTypes },
+ { "invokeNative", "(Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_invokeNative },
+ { "getSignature", "()Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_reflect_Method_getSignature },
#if defined(ENABLE_ANNOTATIONS)
- { "getDefaultValue", "()Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_getDefaultValue },
+ { "getDefaultValue", "()Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_getDefaultValue },
+ { "declaredAnnotations", "()Ljava/util/Map;", (void *) (ptrint) &Java_java_lang_reflect_Method_declaredAnnotations },
+ { "getParameterAnnotations", "()[[Ljava/lang/annotation/Annotation;", (void *) (ptrint) &Java_java_lang_reflect_Method_getParameterAnnotations },
#endif
};
{
classinfo *c;
methodinfo *m;
+ int32_t slot;
- c = (classinfo *) this->clazz;
- m = &(c->methods[this->slot]);
+ LLNI_field_get_cls(this, clazz, c);
+ LLNI_field_get_val(this, slot , slot);
+ m = &(c->methods[slot]);
return m->flags;
}
classinfo *c;
methodinfo *m;
classinfo *result;
+ int32_t slot;
- c = (classinfo *) this->clazz;
- m = &(c->methods[this->slot]);
+ LLNI_field_get_cls(this, clazz, c);
+ LLNI_field_get_val(this, slot , slot);
+ m = &(c->methods[slot]);
result = method_returntype_get(m);
- return (java_lang_Class *) result;
+ return LLNI_classinfo_wrap(result);
}
* Method: getParameterTypes
* Signature: ()[Ljava/lang/Class;
*/
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
+JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
{
classinfo *c;
methodinfo *m;
+ int32_t slot;
- c = (classinfo *) this->clazz;
- m = &(c->methods[this->slot]);
+ LLNI_field_get_cls(this, clazz, c);
+ LLNI_field_get_val(this, slot , slot);
+ m = &(c->methods[slot]);
return method_get_parametertypearray(m);
}
* Method: getExceptionTypes
* Signature: ()[Ljava/lang/Class;
*/
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
+JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
{
classinfo *c;
methodinfo *m;
+ int32_t slot;
- c = (classinfo *) this->clazz;
- m = &(c->methods[this->slot]);
+ LLNI_field_get_cls(this, clazz, c);
+ LLNI_field_get_val(this, slot , slot);
+ m = &(c->methods[slot]);
return method_get_exceptionarray(m);
}
* Method: invokeNative
* Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
*/
-JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Method_invokeNative(JNIEnv *env, java_lang_reflect_Method *this, java_lang_Object *o, java_objectarray *args, java_lang_Class *clazz, s4 slot)
+JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Method_invokeNative(JNIEnv *env, java_lang_reflect_Method *this, java_lang_Object *o, java_handle_objectarray_t *args, java_lang_Class *clazz, s4 slot)
{
/* just to be sure */
- assert(this->clazz == clazz);
- assert(this->slot == slot);
+ assert(LLNI_field_direct(this, clazz) == LLNI_DIRECT(clazz));
+ assert(LLNI_field_direct(this, slot) == slot);
return _Jv_java_lang_reflect_Method_invoke(this, o, args);
}
*/
JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Method_getSignature(JNIEnv *env, java_lang_reflect_Method* this)
{
- classinfo *c;
- methodinfo *m;
- java_objectheader *o;
+ classinfo *c;
+ methodinfo *m;
+ java_handle_t *o;
+ int32_t slot;
- c = (classinfo *) this->clazz;
- m = &(c->methods[this->slot]);
+ LLNI_field_get_cls(this, clazz, c);
+ LLNI_field_get_val(this, slot , slot);
+ m = &(c->methods[slot]);
if (m->signature == NULL)
return NULL;
* Class: java/lang/reflect/Method
* Method: getDefaultValue
* Signature: ()Ljava/lang/Object;
+ *
+ * Parses the annotation default value and returnes it (boxed, if it's a primitive).
*/
JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Method_getDefaultValue(JNIEnv *env, struct java_lang_reflect_Method* this)
{
- methodinfo *m = NULL;
- utf *utf_parseAnnotationDefault = NULL;
- utf *utf_desc = NULL;
- sun_reflect_ConstantPool *constantPool = NULL;
+ java_handle_bytearray_t *annotationDefault = NULL; /* unparsed annotation default value */
+ static methodinfo *m_parseAnnotationDefault = NULL; /* parser method (will be chached, therefore static) */
+ utf *utf_parseAnnotationDefault = NULL; /* parser method name */
+ utf *utf_desc = NULL; /* parser method descriptor (signature) */
+ sun_reflect_ConstantPool *constantPool = NULL; /* constant pool object to use */
+ java_lang_Class *constantPoolOop = NULL; /* methods declaring class */
+ classinfo *referer = NULL; /* class, which calles the annotation parser */
+ /* (for the parameter 'referer' of vm_call_method()) */
if (this == NULL) {
exceptions_throw_nullpointerexception();
(sun_reflect_ConstantPool*)native_new_and_init(
class_sun_reflect_ConstantPool);
- if(constantPool == NULL) {
+ if (constantPool == NULL) {
/* out of memory */
return NULL;
}
- constantPool->constantPoolOop = (java_lang_Object*)this->clazz;
+ LLNI_field_get_ref(this, clazz, constantPoolOop);
+ LLNI_field_set_ref(constantPool, constantPoolOop, (java_lang_Object*)constantPoolOop);
+
+ /* only resolve the parser method the first time */
+ if (m_parseAnnotationDefault == NULL) {
+ utf_parseAnnotationDefault = utf_new_char("parseAnnotationDefault");
+ utf_desc = utf_new_char(
+ "(Ljava/lang/reflect/Method;[BLsun/reflect/ConstantPool;)"
+ "Ljava/lang/Object;");
+
+ if (utf_parseAnnotationDefault == NULL || utf_desc == NULL) {
+ /* out of memory */
+ return NULL;
+ }
+
+ LLNI_class_get(this, referer);
+
+ m_parseAnnotationDefault = class_resolveclassmethod(
+ class_sun_reflect_annotation_AnnotationParser,
+ utf_parseAnnotationDefault,
+ utf_desc,
+ referer,
+ true);
+
+ if (m_parseAnnotationDefault == NULL) {
+ /* method not found */
+ return NULL;
+ }
+ }
- utf_parseAnnotationDefault = utf_new_char("parseAnnotationDefault");
- utf_desc = utf_new_char(
- "(Ljava/lang/reflect/Method;[BLsun/reflect/ConstantPool;Ljava/lang/Class;)Ljava/lang/Object;");
+ LLNI_field_get_ref(this, annotationDefault, annotationDefault);
- if (utf_parseAnnotationDefault == NULL || utf_desc == NULL) {
- /* out of memory */
- return NULL;
- }
+ return (java_lang_Object*)vm_call_method(
+ m_parseAnnotationDefault, NULL,
+ this, annotationDefault, constantPool);
+}
- m = class_resolveclassmethod(
- class_sun_reflect_annotation_AnnotationParser,
- utf_parseAnnotationDefault,
- utf_desc,
- ((java_objectheader*)this)->vftbl->class,
- true);
- if (m == NULL)
- {
- /* method not found */
- return NULL;
+/*
+ * Class: java/lang/reflect/Method
+ * Method: declaredAnnotations
+ * Signature: ()Ljava/util/Map;
+ *
+ * Parses the annotations (if they aren't parsed yet) and stores them into
+ * the declaredAnnotations map and return this map.
+ */
+JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Method_declaredAnnotations(JNIEnv *env, java_lang_reflect_Method *this)
+{
+ java_util_Map *declaredAnnotations = NULL; /* parsed annotations */
+ java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
+ java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */
+ classinfo *referer = NULL; /* class, which calles the annotation parser */
+ /* (for the parameter 'referer' of vm_call_method()) */
+
+ LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
+
+ /* are the annotations parsed yet? */
+ if (declaredAnnotations == NULL) {
+ LLNI_field_get_ref(this, annotations, annotations);
+ LLNI_field_get_ref(this, clazz, declaringClass);
+ LLNI_class_get(this, referer);
+
+ declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
+
+ LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
}
- return (java_lang_Object*)vm_call_method(m, NULL, this, this->annotationDefault, constantPool, this->clazz);
+ return declaredAnnotations;
+}
+
+
+/*
+ * Class: java/lang/reflect/Method
+ * Method: getParameterAnnotations
+ * Signature: ()[[Ljava/lang/annotation/Annotation;
+ *
+ * Parses the parameter annotations and returns them in an 2 dimensional array.
+ */
+JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Method_getParameterAnnotations(JNIEnv *env, java_lang_reflect_Method *this)
+{
+ java_handle_bytearray_t *parameterAnnotations = NULL; /* unparsed parameter annotations */
+ int32_t slot = -1; /* slot of the method */
+ java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */
+ classinfo *referer = NULL; /* class, which calles the annotation parser */
+ /* (for the parameter 'referer' of vm_call_method()) */
+
+ LLNI_field_get_ref(this, parameterAnnotations, parameterAnnotations);
+ LLNI_field_get_val(this, slot, slot);
+ LLNI_field_get_ref(this, clazz, declaringClass);
+ LLNI_class_get(this, referer);
+
+ return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, slot, declaringClass, referer);
}
#endif
+
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where