* src/vm/jit/i386/darwin/md-asm.h: Repaired --enable-cycles-stats.
[cacao.git] / src / native / vm / gnu / java_lang_reflect_Method.c
index 32d84d545d775e6bdeac5d5fef3061d4c939cc3a..75f03b11d53eb5c610094760028347dc1b3f3e0e 100644 (file)
@@ -44,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
@@ -184,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);
@@ -222,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_lang_Class          *constantPoolOop = NULL;
-       classinfo                *referer         = 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();
@@ -241,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;
        }
@@ -249,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(
@@ -276,9 +281,11 @@ JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Method_getDefa
                }
        }
 
+       LLNI_field_get_ref(this, annotationDefault, annotationDefault);
+
        return (java_lang_Object*)vm_call_method(
                m_parseAnnotationDefault, NULL,
-               this, this->annotationDefault, constantPool);
+               this, annotationDefault, constantPool);
 }
 
 
@@ -286,18 +293,23 @@ 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, java_lang_reflect_Method *this)
 {
-       struct java_util_Map    *declaredAnnotations = NULL;
-       java_handle_bytearray_t *annotations         = NULL;
-       java_lang_Class         *declaringClass      = NULL;
-       classinfo               *referer             = 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);
 
@@ -314,13 +326,16 @@ 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, java_lang_reflect_Method *this)
 {
-       java_handle_bytearray_t *parameterAnnotations = NULL;
-       int32_t                  slot                 = -1;
-       java_lang_Class         *declaringClass       = NULL;
-       classinfo               *referer              = 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);