* src/vm/jit/i386/darwin/md-asm.h: Repaired --enable-cycles-stats.
[cacao.git] / src / native / vm / gnu / java_lang_reflect_Method.c
index 61b7ea0dd25e71befcacf215f4084f8f7e8e9858..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 8285 2007-08-10 09:20:04Z 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);
 }
 
 
@@ -144,7 +143,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(J
  * 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;
@@ -163,7 +162,7 @@ JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTy
  * 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;
@@ -182,11 +181,11 @@ JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTy
  * 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(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);
@@ -200,10 +199,10 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Method_invokeNative(J
  */
 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;
-       int32_t            slot;
+       classinfo     *c;
+       methodinfo    *m;
+       java_handle_t *o;
+       int32_t        slot;
 
        LLNI_field_get_cls(this, clazz, c);
        LLNI_field_get_val(this, slot , slot);
@@ -224,14 +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_objectheader        *o            = (java_objectheader*)this;
+       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();
@@ -242,14 +246,15 @@ 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;
        }
 
-       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 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(
@@ -261,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);
 }
 
 
@@ -285,17 +293,32 @@ 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_objectheader *o = (java_objectheader*)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()) */
 
-       if (this == NULL) {
-               exceptions_throw_nullpointerexception();
-               return NULL;
+       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 reflect_get_declaredannotatios(&(this->declaredAnnotations), this->annotations, this->clazz, o->vftbl->class);
+       return declaredAnnotations;
 }
 
 
@@ -303,17 +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_objectarray* 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_objectheader *o = (java_objectheader*)this;
-
-       if (this == NULL) {
-               exceptions_throw_nullpointerexception();
-               return NULL;
-       }
-
-       return reflect_get_parameterannotations((java_objectheader*)this->parameterAnnotations, this->slot, this->clazz, o->vftbl->class);
+       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