* src/vm/jit/i386/darwin/md-asm.h: Repaired --enable-cycles-stats.
[cacao.git] / src / native / vm / gnu / java_lang_reflect_Method.c
index 3882c4f29a2160f464c4e4ce5bafa3a3b992f20c..75f03b11d53eb5c610094760028347dc1b3f3e0e 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: java_lang_reflect_Method.c 8321 2007-08-16 11:37:25Z michi $
-
 */
 
 
@@ -46,6 +44,7 @@
 #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
@@ -135,7 +134,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(J
 
        result = method_returntype_get(m);
 
-       return (java_lang_Class *) result;
+       return LLNI_classinfo_wrap(result);
 }
 
 
@@ -186,7 +185,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Method_invokeNative(J
 {
        /* just to be sure */
 
-       assert(LLNI_field_direct(this, clazz) == clazz);
+       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);
@@ -224,15 +223,19 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Method_getSignature(J
  * 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)
 {
-       static methodinfo        *m_parseAnnotationDefault   = NULL;
-       utf                      *utf_parseAnnotationDefault = NULL;
-       utf                      *utf_desc        = NULL;
-       sun_reflect_ConstantPool *constantPool    = NULL;
-       java_handle_t            *o               = (java_handle_t*)this;
-       java_lang_Class          *constantPoolOop = 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();
@@ -243,7 +246,7 @@ JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Method_getDefa
                (sun_reflect_ConstantPool*)native_new_and_init(
                        class_sun_reflect_ConstantPool);
        
-       if(constantPool == NULL) {
+       if (constantPool == NULL) {
                /* out of memory */
                return NULL;
        }
@@ -251,7 +254,7 @@ JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Method_getDefa
        LLNI_field_get_ref(this, clazz, constantPoolOop);
        LLNI_field_set_ref(constantPool, constantPoolOop, (java_lang_Object*)constantPoolOop);
 
-       /* only resolve the method the first time */
+       /* only resolve the parser method the first time */
        if (m_parseAnnotationDefault == NULL) {
                utf_parseAnnotationDefault = utf_new_char("parseAnnotationDefault");
                utf_desc = utf_new_char(
@@ -263,23 +266,26 @@ JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Method_getDefa
                        return NULL;
                }
 
+               LLNI_class_get(this, referer);
+
                m_parseAnnotationDefault = class_resolveclassmethod(
                        class_sun_reflect_annotation_AnnotationParser,
                        utf_parseAnnotationDefault,
                        utf_desc,
-                       o->vftbl->class,
+                       referer,
                        true);
 
-               if (m_parseAnnotationDefault == NULL)
-               {
+               if (m_parseAnnotationDefault == NULL) {
                        /* method not found */
                        return NULL;
                }
        }
 
+       LLNI_field_get_ref(this, annotationDefault, annotationDefault);
+
        return (java_lang_Object*)vm_call_method(
                m_parseAnnotationDefault, NULL,
-               this, this->annotationDefault, constantPool);
+               this, annotationDefault, constantPool);
 }
 
 
@@ -287,26 +293,27 @@ JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Method_getDefa
  * 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, struct java_lang_reflect_Method* this)
+JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Method_declaredAnnotations(JNIEnv *env, java_lang_reflect_Method *this)
 {
-       java_handle_t        *o                   = (java_handle_t*)this;
-       struct java_util_Map *declaredAnnotations = NULL;
-       java_bytearray       *annotations         = NULL;
-       java_lang_Class      *declaringClass      = NULL;
-
-       if (this == NULL) {
-               exceptions_throw_nullpointerexception();
-               return NULL;
-       }
+       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_val(this, annotations, annotations);
+               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, o->vftbl->class);
+               declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
 
                LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
        }
@@ -319,24 +326,23 @@ JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Method_declaredAn
  * 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, struct java_lang_reflect_Method* this)
+JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Method_getParameterAnnotations(JNIEnv *env, java_lang_reflect_Method *this)
 {
-       java_handle_t   *o                    = (java_handle_t*)this;
-       java_bytearray  *parameterAnnotations = NULL;
-       int32_t          slot                 = -1;
-       java_lang_Class *declaringClass       = NULL;
-
-       if (this == NULL) {
-               exceptions_throw_nullpointerexception();
-               return NULL;
-       }
+       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, o->vftbl->class);
+       return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, slot, declaringClass, referer);
 }
 #endif