* src/vmcore/annotation.c: Improved comments.
authorMathias Panzenboeck <e0427417@student.tuwien.ac.at>
Tue, 11 Sep 2007 22:27:45 +0000 (00:27 +0200)
committerMathias Panzenboeck <e0427417@student.tuwien.ac.at>
Tue, 11 Sep 2007 22:27:45 +0000 (00:27 +0200)
(annotation_bytearrays_resize),
(annotation_bytearrays_insert),
(annotation_load_method_attribute_annotationdefault),
(annotation_load_method_attribute_runtimevisibleparameterannotations),
(annotation_load_class_attribute_runtimevisibleannotations),
(annotation_load_method_attribute_runtimevisibleannotations),
(annotation_load_field_attribute_runtimevisibleannotations):
Restructured so that when it comes to the point when I have to use LLNI macros
for accessing the java objects I store in classinfo I will have not much to do.

* src/lib/gnu/java/lang/reflect/Constructor.java: Improved comments.
* src/lib/gnu/java/lang/reflect/Field.java: Likewise.
* src/lib/gnu/java/lang/reflect/Method.java: Likewise.
* src/lib/gnu/sun/reflect/annotation/AnnotationParser.java: Likewise.
* src/lib/gnu/sun/reflect/annotation/AnnotationType.java: Likewise.
* src/native/vm/gnu/java_lang_reflect_Constructor.c: Likewise.
* src/native/vm/gnu/java_lang_reflect_Field.c: Likewise.
* src/native/vm/gnu/java_lang_reflect_Method.c: Likewise.
* src/native/vm/gnu/sun_reflect_ConstantPool.c: Likewise.
* src/native/vm/java_lang_Class.c: Likewise.
* src/native/vm/reflect.c: Likewise.
* src/native/vm/sun/jvm.c: Likewise.
* src/vmcore/class.c: Likewise.
* src/vmcore/field.c: Likewise.
* src/vmcore/method.c: Likewise.
* src/vmcore/utf8.c: Likewise.
* tests/regression/MinimalClassReflection.java: Likewise.

18 files changed:
src/lib/gnu/java/lang/reflect/Constructor.java
src/lib/gnu/java/lang/reflect/Field.java
src/lib/gnu/java/lang/reflect/Method.java
src/lib/gnu/sun/reflect/annotation/AnnotationParser.java
src/lib/gnu/sun/reflect/annotation/AnnotationType.java
src/native/vm/gnu/java_lang_reflect_Constructor.c
src/native/vm/gnu/java_lang_reflect_Field.c
src/native/vm/gnu/java_lang_reflect_Method.c
src/native/vm/gnu/sun_reflect_ConstantPool.c
src/native/vm/java_lang_Class.c
src/native/vm/reflect.c
src/native/vm/sun/jvm.c
src/vmcore/annotation.c
src/vmcore/class.c
src/vmcore/field.c
src/vmcore/method.c
src/vmcore/utf8.c
tests/regression/MinimalClassReflection.java

index c990fbc916af231a612c48288a506526bd28a0c7..0f6e1f0038f631fd72b50e8dade67a697d3f1981 100644 (file)
@@ -85,13 +85,29 @@ public final class Constructor<T>
 {
   private Class<T> clazz;
   private int slot;
+
+  /**
+   * Unparsed annotations.
+   */
   private byte[] annotations = null;
+
+  /**
+   * Unparsed parameter annotations.
+   */
   private byte[] parameterAnnotations = null;
+  
+  /**
+   * Annotations get parsed the first time they are
+   * accessed and are then cached it this map.
+   */
   private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations = null;
   
   private static final int CONSTRUCTOR_MODIFIERS
     = Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC;
-    
+  
+  /**
+   * Helper array for creating a new array from a java.util.Container.
+   */
   private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
     new Annotation[0];
 
@@ -420,6 +436,10 @@ public final class Constructor<T>
     return declaredAnnotations().values().toArray(EMPTY_ANNOTATIONS_ARRAY);
   }
 
+  /**
+   * Parses the annotations if they aren't parsed yet and stores them into
+   * the declaredAnnotations map and return this map.
+   */
   private synchronized native Map<Class<? extends Annotation>, Annotation> declaredAnnotations();
   
   /**
index e8889a859d9230edf88c098bcac4884f5df7799e..39856a374d7efcbac9bf31dafb147490ee31a35d 100644 (file)
@@ -85,7 +85,16 @@ extends AccessibleObject implements Member
   private Class clazz;
   private String name;
   private int slot;
+
+  /**
+   * Unparsed annotations.
+   */
   private byte[] annotations = null;
+
+  /**
+   * Annotations get parsed the first time they are
+   * accessed and are then cached it this map.
+   */
   private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations = null;
 
   private static final int FIELD_MODIFIERS
@@ -93,6 +102,9 @@ extends AccessibleObject implements Member
       | Modifier.PUBLIC | Modifier.STATIC | Modifier.TRANSIENT
       | Modifier.VOLATILE;
 
+  /**
+   * Helper array for creating a new array from a java.util.Container.
+   */
   private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
     new Annotation[0];
 
@@ -686,5 +698,9 @@ extends AccessibleObject implements Member
     return declaredAnnotations().values().toArray(EMPTY_ANNOTATIONS_ARRAY);
   }
 
+  /**
+   * Parses the annotations if they aren't parsed yet and stores them into
+   * the declaredAnnotations map and return this map.
+   */
   private synchronized native Map<Class<? extends Annotation>, Annotation> declaredAnnotations();
 }
index a6b9c3241533bdfb750ef7f6fd1f30b69a5f3b41..e705cef40ce31b370f2e2c2f424a115abb8032d8 100644 (file)
@@ -85,9 +85,26 @@ extends AccessibleObject implements Member, GenericDeclaration
   Class clazz;
   String name;
   int slot;
+  
+  /**
+   * Unparsed annotations.
+   */
   private byte[] annotations          = null;
+
+  /**
+   * Unparsed parameter annotations.
+   */
   private byte[] parameterAnnotations = null;
+  
+  /**
+   * Unparsed annotation default value.
+   */
   private byte[] annotationDefault    = null;
+
+  /**
+   * Annotations get parsed the first time they are
+   * accessed and are then cached it this map.
+   */
   private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations = null;
 
   private static final int METHOD_MODIFIERS
@@ -95,6 +112,9 @@ extends AccessibleObject implements Member, GenericDeclaration
       | Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC
       | Modifier.STATIC | Modifier.STRICT | Modifier.SYNCHRONIZED;
 
+  /**
+   * Helper array for creating a new array from a java.util.Container.
+   */
   private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY =
     new Annotation[0];
 
@@ -490,6 +510,10 @@ extends AccessibleObject implements Member, GenericDeclaration
     return declaredAnnotations().values().toArray(EMPTY_ANNOTATIONS_ARRAY);
   }
 
+  /**
+   * Parses the annotations if they aren't parsed yet and stores them into
+   * the declaredAnnotations map and return this map.
+   */
   private synchronized native Map<Class<? extends Annotation>, Annotation> declaredAnnotations();
   
   /**
index fe361fb835b72837b05f93e61fddccceb3689789..8c5aca3652bfe2ec6717691bd6b26720e4e0d764 100644 (file)
@@ -44,11 +44,15 @@ import gnu.java.lang.reflect.FieldSignatureParser;
  */
 public class AnnotationParser {
     /**
-     * Parses the annotations described by the passed byte array.
-     * But return Annotation[] so I don't have to do this in C.
+     * Parses the annotations described by the passed byte array,
+     * but returns Annotation[] so I don't have to do this in C.
      *
      * @author Mathias Panzenböck
      * 
+     * @param rawAnnotations are the unparsed annotations
+     * @param constPool is the constant pool of the declaring class
+     * @param container is the containing class
+     * @return the parsed annotations in an array
      * @throws AnnotationFormatError if an annotation is found to be
      *         malformed.
      */
@@ -65,6 +69,10 @@ public class AnnotationParser {
      * 
      * @author Mathias Panzenböck
      * 
+     * @param parameterAnnotations are the unparsed parameter annotations
+     * @param constPool is the constant pool of the declaring class
+     * @param container is the containing class
+     * @return the parsed parameter annotations in an array 2 dimensional array
      * @throws AnnotationFormatError if an annotation is found to be
      *         malformed.
      */
@@ -93,6 +101,10 @@ public class AnnotationParser {
      * 
      * @author Mathias Panzenböck
      *
+     * @param method represents the method for which the annotation default value has to be parsed
+     * @param annotationDefault is the unparsed annotation default value
+     * @param constPool is the constant pool of the declaring class
+     * @return the parsed annotation default value (boxed, if it's a primitive type)
      * @throws AnnotationFormatError if an annotation is found to be
      *         malformed.
      */
index 2ef7149fd69e7b4515c939678a5f60f791c3b5a7..ea559bbb99178b947377edabb31abc81bb1c6881 100644 (file)
@@ -93,6 +93,7 @@ public class AnnotationType {
        AnnotationType result = sun.misc.SharedSecrets.getJavaLangAccess(). 
             getAnnotationType(annotationClass); 
         */
+       // emulating OpenJDKs SharedSecrets in GNU Classpath:
        AnnotationType result = annotationTypes.get(annotationClass); 
        if (result == null)
             result = new AnnotationType((Class<?>) annotationClass);
@@ -139,7 +140,7 @@ public class AnnotationType {
         sun.misc.SharedSecrets.getJavaLangAccess(). 
             setAnnotationType(annotationClass, this); 
         */
-        
+       // emulating OpenJDKs SharedSecrets in GNU Classpath:
        annotationTypes.put(annotationClass, this);
 
         // Initialize retention, & inherited fields.  Special treatment
index c331a15dcf84568725422400910bf856004918e8..606ab0a4835eac11c250923f3ffca75c5ba35bb2 100644 (file)
@@ -110,16 +110,21 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_construct
  * Class:     java/lang/reflect/Constructor
  * 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_Constructor_declaredAnnotations(JNIEnv *env, java_lang_reflect_Constructor *this)
 {
-       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_ref(this, annotations, annotations);
                LLNI_field_get_ref(this, clazz, declaringClass);
@@ -138,13 +143,16 @@ JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Constructor_decla
  * Class:     java/lang/reflect/Constructor
  * 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_Constructor_getParameterAnnotations(JNIEnv *env, java_lang_reflect_Constructor *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);
index 7e1bbf82fa1534599dab0c365ac0971fda4bf177..d28b25b940221c8b741e7befe4cdc161d99da9c9 100644 (file)
@@ -1252,13 +1252,15 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JN
  */
 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnnotations(JNIEnv *env, java_lang_reflect_Field *this)
 {
-       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_ref(this, annotations, annotations);
                LLNI_field_get_ref(this, clazz, declaringClass);
index 6e0e5784c066172244ee982b92311f68ebfd19f5..17e7fe6bc9b0d2cb7c73c0657bf013931068751f 100644 (file)
@@ -223,16 +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)
 {
-       java_handle_bytearray_t  *annotationDefault          = NULL;
-       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();
@@ -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(
@@ -290,16 +293,21 @@ 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)
 {
-       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_ref(this, annotations, annotations);
                LLNI_field_get_ref(this, clazz, declaringClass);
@@ -318,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);
index e8e68a411d96ffa0a06cf4fe444457a4ea1bd795..66b7ac4500492f5efce03fc80fdde96bd373b6d6 100644 (file)
 
    XXX: The Methods in this file are very redundant to thouse in
         src/native/vm/sun/jvm.c Unless someone has a good idea how to cover
-       such redundancy I leave it how it is.
+        such redundancy I leave it how it is.
+
+  The ConstantPool class represents an interface to the constant pool of a
+  class and is used by the annotations parser (sun.reflect.annotation.
+  AnnotationParser) to get the values of the constants refered by the
+  annotations.
 
 *******************************************************************************/
 
@@ -80,7 +85,7 @@ static JNINativeMethod methods[] = {
 };
 
 
-/* _Jv_sun_reflect_ConstantPool_init ********************************************
+/* _Jv_sun_reflect_ConstantPool_init ******************************************
 
    Register native functions.
 
index 193ff829ab4a047bf2b81c0d1a8d304b2bf3c273..0160f01ff4d86dce774f17bae5df93775f0be6d7 100644 (file)
@@ -552,13 +552,14 @@ void _Jv_java_lang_Class_throwException(java_lang_Throwable *t)
  */
 java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredAnnotations(java_lang_Class* klass)
 {
-       classinfo                *c               = NULL;
-       static methodinfo        *m_parseAnnotationsIntoArray   = NULL;
-       utf                      *utf_parseAnnotationsIntoArray = NULL;
-       utf                      *utf_desc        = NULL;
-       java_handle_bytearray_t  *annotations     = NULL;
-       sun_reflect_ConstantPool *constantPool    = NULL;
-       java_lang_Object         *constantPoolOop = (java_lang_Object*)klass;
+       classinfo                *c               = NULL; /* classinfo for the java.lang.Class object 'klass'       */
+       static methodinfo        *m_parseAnnotationsIntoArray   = NULL; /* parser method (cached, therefore static) */
+       utf                      *utf_parseAnnotationsIntoArray = NULL; /* parser method name     */
+       utf                      *utf_desc        = NULL;               /* parser method descriptor (signature)     */
+       java_handle_bytearray_t  *annotations     = NULL;               /* unparsed annotations   */
+       sun_reflect_ConstantPool *constantPool    = NULL;               /* constant pool of klass */
+       java_lang_Object         *constantPoolOop = (java_lang_Object*)klass; /* constantPoolOop field of */
+                                                                             /* sun.reflect.ConstantPool */
 
        if (klass == NULL) {
                exceptions_throw_nullpointerexception();
@@ -574,14 +575,14 @@ java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredAnnotations(java_lang_
                (sun_reflect_ConstantPool*)native_new_and_init(
                        class_sun_reflect_ConstantPool);
        
-       if(constantPool == NULL) {
+       if (constantPool == NULL) {
                /* out of memory */
                return NULL;
        }
 
        LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop);
 
-       /* only resolve the method the first time */
+       /* only resolve the parser method the first time */
        if (m_parseAnnotationsIntoArray == NULL) {
                utf_parseAnnotationsIntoArray = utf_new_char("parseAnnotationsIntoArray");
                utf_desc = utf_new_char(
index 9f9daa5890fe02c283e4a7388e7616b361dd23fa..6618f6134abac3e97a973f7dd5ce24afc34ed95c 100644 (file)
@@ -267,8 +267,18 @@ java_lang_reflect_Method *reflect_method_new(methodinfo *m)
 #if defined(WITH_CLASSPATH_GNU) && defined(ENABLE_ANNOTATIONS)
 /* reflect_get_declaredannotatios *********************************************
 
-   Returns a java.util.Map<Class<? extends Annotation>, Annotation>
-   of the declared annotations.
+   Calls the annotation parser with the unparsed annotations and returnes
+   the parsed annotations as a map.
+   
+   IN:
+       annotations........the unparsed annotations
+       declaringClass.....the class in which the annotated element is declared
+       referer............the calling class (for the 'referer' parameter of
+                          vm_call_method())
+
+   RETURN VALUE:
+       The parsed annotations as a
+          java.util.Map<Class<? extends Annotation>, Annotation>.
 
 *******************************************************************************/
 
@@ -278,10 +288,16 @@ struct java_util_Map* reflect_get_declaredannotatios(
        classinfo               *referer)
 {
        static methodinfo        *m_parseAnnotations   = NULL;
+                                   /* parser method (chached, therefore static)  */
        utf                      *utf_parseAnnotations = NULL;
+                                   /* parser method name                         */
        utf                      *utf_desc             = NULL;
+                                   /* parser method descriptor (signature)       */
        sun_reflect_ConstantPool *constantPool         = NULL;
+                                   /* constant pool of the declaring class       */
        java_lang_Object         *constantPoolOop      = (java_lang_Object*)declaringClass;
+                                   /* constantPoolOop field of the constant pool */
+                                   /* object (sun.reflect.ConstantPool)          */
 
        constantPool = 
                (sun_reflect_ConstantPool*)native_new_and_init(
@@ -294,7 +310,7 @@ struct java_util_Map* reflect_get_declaredannotatios(
                
        LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop);
                
-       /* only resolve the method the first time */
+       /* only resolve the parser method the first time */
        if (m_parseAnnotations == NULL) {
                utf_parseAnnotations = utf_new_char("parseAnnotations");
                utf_desc = utf_new_char(
@@ -327,7 +343,20 @@ struct java_util_Map* reflect_get_declaredannotatios(
 
 /* reflect_get_parameterannotations *******************************************
 
-   Parses and returns the parameter annotations of a method.
+   Calls the annotation parser with the unparsed parameter annotations of
+   a method and returnes the parsed parameter annotations in a 2 dimensional
+   array.
+   
+   IN:
+       parameterAnnotations....the unparsed parameter annotations
+          slot....................the slot of the method
+       declaringClass..........the class in which the annotated element is
+                                  declared
+       referer.................the calling class (for the 'referer' parameter
+                               of vm_call_method())
+
+   RETURN VALUE:
+       The parsed parameter annotations in a 2 dimensional array.
 
 *******************************************************************************/
 
@@ -344,21 +373,29 @@ java_handle_objectarray_t* reflect_get_parameterannotations(
         * ones).
         *
         * ConstantPool constPool = new ConstantPool();
-        * constPool.constantPoolOop = getDeclaringClass();
+        * constPool.constantPoolOop = method.getDeclaringClass();
         * return sun.reflect.AnnotationParser.parseParameterAnnotations(
-        *      parameterAnnotations,
-        *      constPool,
-        *      getDeclaringClass(),
-        *      getParameterTypes().length);
+        *        parameterAnnotations,
+        *        constPool,
+        *        method.getDeclaringClass(),
+        *        method.getParameterTypes().length);
         */
        static methodinfo        *m_parseParameterAnnotations   = NULL;
+                            /* parser method (cached, therefore static)          */
        utf                      *utf_parseParameterAnnotations = NULL;
+                            /* parser method name                                */
        utf                      *utf_desc        = NULL;
+                            /* parser method descriptor (signature)              */
        sun_reflect_ConstantPool *constantPool    = NULL;
+                            /* constant pool of the declaring class              */
        java_lang_Object         *constantPoolOop = (java_lang_Object*)declaringClass;
+                            /* constantPoolOop field of the constant pool object */
        classinfo                *c               = NULL;
+                            /* classinfo of the decaring class                   */
        methodinfo               *m               = NULL;
+                            /* method info of the annotated method               */
        int32_t                   numParameters   = -1;
+                            /* parameter count of the annotated method           */
 
        /* get parameter count */
 
@@ -385,7 +422,7 @@ java_handle_objectarray_t* reflect_get_parameterannotations(
 
        LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop);
 
-       /* only resolve the method the first time */
+       /* only resolve the parser method the first time */
        if (m_parseParameterAnnotations == NULL) {
                utf_parseParameterAnnotations = utf_new_char("parseParameterAnnotations");
                utf_desc = utf_new_char(
index da2d43ba270a809f5e72226115c9b75826b6771b..c019330c815a0ffaf738cad8eb318ebfd55a3134 100644 (file)
@@ -1102,8 +1102,8 @@ jstring JVM_GetClassSignature(JNIEnv *env, jclass cls)
 
 jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
 {
-       classinfo               *c           = NULL;
-       java_handle_bytearray_t *annotations = NULL;
+       classinfo               *c           = NULL; /* classinfo for 'cls'  */
+       java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
 
        TRACEJVMCALLS("JVM_GetClassAnnotations: cls=%p", cls);
 
@@ -1125,8 +1125,8 @@ jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
 
 jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
 {
-       java_lang_reflect_Field *rf = (java_lang_reflect_Field*)field;
-       java_handle_bytearray_t *ba = NULL;
+       java_lang_reflect_Field *rf = NULL; /* java.lang.reflect.Field for 'field' */
+       java_handle_bytearray_t *ba = NULL; /* unparsed annotations */
 
        TRACEJVMCALLS("JVM_GetFieldAnnotations: field=%p", field);
 
@@ -1135,6 +1135,8 @@ jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
                return NULL;
        }
 
+       rf = (java_lang_reflect_Field*)field;
+
        LLNI_field_get_ref(rf, annotations, ba);
 
        return (jbyteArray)ba;
@@ -1145,8 +1147,8 @@ jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
 
 jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
 {
-       java_lang_reflect_Method *rm = (java_lang_reflect_Method*)method;
-       java_handle_bytearray_t  *ba = NULL;
+       java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
+       java_handle_bytearray_t  *ba = NULL; /* unparsed annotations */
 
        TRACEJVMCALLS("JVM_GetMethodAnnotations: method=%p", method);
 
@@ -1155,6 +1157,8 @@ jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
                return NULL;
        }
 
+       rm = (java_lang_reflect_Method*)method;
+
        LLNI_field_get_ref(rm, annotations, ba);
 
        return (jbyteArray)ba;
@@ -1165,8 +1169,8 @@ jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
 
 jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
 {
-       java_lang_reflect_Method *rm = (java_lang_reflect_Method*)method;
-       java_handle_bytearray_t  *ba = NULL;
+       java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
+       java_handle_bytearray_t  *ba = NULL; /* unparsed annotation default value */
 
        TRACEJVMCALLS("JVM_GetMethodDefaultAnnotationValue: method=%p", method);
 
@@ -1175,6 +1179,8 @@ jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
                return NULL;
        }
 
+       rm = (java_lang_reflect_Method*)method;
+
        LLNI_field_get_ref(rm, annotationDefault, ba);
 
        return (jbyteArray)ba;
@@ -1185,8 +1191,8 @@ jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
 
 jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
 {
-       java_lang_reflect_Method *rm = (java_lang_reflect_Method*)method;
-       java_handle_bytearray_t  *ba = NULL;
+       java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
+       java_handle_bytearray_t  *ba = NULL; /* unparsed parameter annotations */
 
        TRACEJVMCALLS("JVM_GetMethodParameterAnnotations: method=%p", method);
 
@@ -1195,6 +1201,8 @@ jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
                return NULL;
        }
 
+       rm = (java_lang_reflect_Method*)method;
+
        LLNI_field_get_ref(rm, parameterAnnotations, ba);
 
        return (jbyteArray)ba;
@@ -1256,8 +1264,10 @@ jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
 {
 #if defined(ENABLE_ANNOTATIONS)
        sun_reflect_ConstantPool *constantPool    = NULL;
+                     /* constant pool object for the class refered by 'cls' */
        java_lang_Object         *constantPoolOop = (java_lang_Object*)cls;
-       
+                     /* constantPoolOop field of the constant pool object   */
+
        TRACEJVMCALLS("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls);
 
        constantPool = 
@@ -1283,7 +1293,7 @@ jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
 
 jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
 {
-       classinfo *c;
+       classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetSize(env=%p, unused=%p, jcpool=%p)", env, unused, jcpool);
 
@@ -1297,9 +1307,9 @@ jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
 
 jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       constant_classref *ref;
-       classinfo         *c;
-       classinfo         *result;
+       constant_classref *ref;    /* classref to the class at constant pool index 'index' */
+       classinfo         *c;      /* classinfo of the class for which 'this' is the constant pool */
+       classinfo         *result; /* classinfo of the class at constant pool index 'index' */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetClassAt(env=%p, jcpool=%p, index=%d)", env, jcpool, index);
 
@@ -1322,9 +1332,9 @@ jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, j
 
 jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       constant_classref *ref;
-       classinfo         *c;
-       classinfo         *result;
+       constant_classref *ref;    /* classref to the class at constant pool index 'index' */
+       classinfo         *c;      /* classinfo of the class for which 'this' is the constant pool */
+       classinfo         *result; /* classinfo of the class at constant pool index 'index' */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetClassAtIfLoaded(env=%p, unused=%p, jcpool=%p, index=%d)", env, unused, jcpool, index);
 
@@ -1353,11 +1363,12 @@ jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject j
 
 jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       constant_FMIref *ref;
-       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
+       classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
        
        TRACEJVMCALLS("JVM_ConstantPoolGetMethodAt: jcpool=%p, index=%d", jcpool, index);
-
+       
+       cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
        
        if (ref == NULL) {
@@ -1374,12 +1385,13 @@ jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool,
 
 jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       constant_FMIref *ref;
-       classinfo *c = NULL;
-       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
+       classinfo *c = NULL;  /* resolved declaring class of the method */
+       classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetMethodAtIfLoaded: jcpool=%p, index=%d", jcpool, index);
 
+       cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
 
        if (ref == NULL) {
@@ -1403,11 +1415,12 @@ jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject
 
 jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       constant_FMIref *ref;
-       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
+       classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
        
        TRACEJVMCALLS("JVM_ConstantPoolGetFieldAt: jcpool=%p, index=%d", jcpool, index);
 
+       cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
 
        if (ref == NULL) {
@@ -1423,12 +1436,13 @@ jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool,
 
 jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       constant_FMIref *ref;
-       classinfo *c;
-       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
+       classinfo *c;         /* resolved declaring class for the field */
+       classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetFieldAtIfLoaded: jcpool=%p, index=%d", jcpool, index);
 
+       cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
 
        if (ref == NULL) {
@@ -1453,6 +1467,9 @@ jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject
 jobjectArray JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
        log_println("JVM_ConstantPoolGetMemberRefInfoAt: jcpool=%p, index=%d, IMPLEMENT ME!", jcpool, index);
+
+       /* TODO: implement. (this is yet unused be OpenJDK but, so very low priority) */
+
        return NULL;
 }
 
@@ -1461,11 +1478,12 @@ jobjectArray JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, job
 
 jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       constant_integer *ref;
-       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       constant_integer *ref; /* reference to the int value in constant pool at index 'index' */
+       classinfo *cls;        /* classinfo of the class for which 'this' is the constant pool */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetIntAt: jcpool=%p, index=%d", jcpool, index);
 
+       cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_integer*)class_getconstant(cls, index, CONSTANT_Integer);
 
        if (ref == NULL) {
@@ -1481,11 +1499,12 @@ jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint
 
 jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       constant_long *ref;
-       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       constant_long *ref; /* reference to the long value in constant pool at index 'index' */
+       classinfo *cls;     /* classinfo of the class for which 'this' is the constant pool */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetLongAt: jcpool=%p, index=%d", jcpool, index);
 
+       cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_long*)class_getconstant(cls, index, CONSTANT_Long);
 
        if (ref == NULL) {
@@ -1501,11 +1520,12 @@ jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jin
 
 jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       constant_float *ref;
-       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       constant_float *ref; /* reference to the float value in constant pool at index 'index' */
+       classinfo *cls;      /* classinfo of the class for which 'this' is the constant pool */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetFloatAt: jcpool=%p, index=%d", jcpool, index);
 
+       cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_float*)class_getconstant(cls, index, CONSTANT_Float);
 
        if (ref == NULL) {
@@ -1521,11 +1541,12 @@ jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, j
 
 jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       constant_double *ref;
-       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       constant_double *ref; /* reference to the double value in constant pool at index 'index' */
+       classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetDoubleAt: jcpool=%p, index=%d", jcpool, index);
 
+       cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_double*)class_getconstant(cls, index, CONSTANT_Double);
 
        if (ref == NULL) {
@@ -1541,11 +1562,12 @@ jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool,
 
 jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       utf *ref;
-       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       utf *ref;       /* utf object for the string in constant pool at index 'index' */
+       classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetStringAt: jcpool=%p, index=%d", jcpool, index);
        
+       cls = LLNI_classinfo_unwrap(jcpool);
        ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
 
        if (ref == NULL) {
@@ -1562,11 +1584,12 @@ jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool,
 
 jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       utf *ref;
-       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       utf *ref; /* utf object for the utf8 data in constant pool at index 'index' */
+       classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
 
        TRACEJVMCALLS("JVM_ConstantPoolGetUTF8At: jcpool=%p, index=%d", jcpool, index);
 
+       cls = LLNI_classinfo_unwrap(jcpool);
        ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
 
        if (ref == NULL) {
index 1a8533b672af1286a4369b9a62d4de59185f8b25..8c1e4ae8228f9c2c81f65af4cb471eaeaa44263a 100644 (file)
 
    Resize an array of bytearrays.
 
+   IN:
+       bas.....array of bytearrays (bas is short for 'bytearrays')
+       size....new size of the refered array
+   
+   RETURN VALUE:
+       The new array if a resize was neccessarry, the old if the given size
+       equals the current size or NULL if an error occured.
+
 *******************************************************************************/
 
-static bool annotation_bytearrays_resize(java_handle_objectarray_t **bas,
-       uint32_t size)
+static java_handle_objectarray_t *annotation_bytearrays_resize(
+       java_handle_objectarray_t *bas, uint32_t size)
 {
-       java_handle_objectarray_t *newbas = NULL;
-       uint32_t minsize;
-       uint32_t oldsize;
+       java_handle_objectarray_t *newbas = NULL; /* new array     */
+       uint32_t minsize = 0;      /* count of object refs to copy */
+       uint32_t oldsize = 0;      /* size of old array            */
        
-       assert(bas != NULL);
-       
-       if (*bas != NULL) {
-               oldsize = array_length_get((java_handle_t*)*bas);
-
+       if (bas != NULL) {
+               oldsize = array_length_get((java_handle_t*)bas);
+               
                /* if the size already fits do nothing */
                if (size == oldsize) {
-                       return true;
+                       return bas;
                }
        }
-
+       
        newbas = builtin_anewarray(size,
                primitive_arrayclass_get_by_type(PRIMITIVETYPE_BYTE));
        
-       if (newbas == NULL) {
-               /* out of memory */
-               return false;
-       }
-       
        /* is there a old byte array array? */
-       if (*bas != NULL) {
+       if (newbas != NULL && bas != NULL) {
                minsize = size < oldsize ? size : oldsize;
 
-               MCOPY(LLNI_array_data(newbas), LLNI_array_data(*bas),
+               MCOPY(LLNI_array_data(newbas), LLNI_array_data(bas),
                        java_object_t*, minsize);
        }
 
-       *bas = newbas;
-
-       return true;
+       return newbas;
 }
 
 
@@ -101,44 +100,54 @@ static bool annotation_bytearrays_resize(java_handle_objectarray_t **bas,
 
    Insert a bytearray into an array of bytearrays.
 
+   IN:
+       bas........array of bytearrays where 'ba' has to be insertet into at
+                  position 'index'.
+       index......position where 'ba' has to be inserted into 'bas'.
+       ba.........byte array which has to be inserted into 'bas'.
+
+   RETURN VALUE:
+       The new array if a resize was neccessarry, the old if the given size
+       equals the current size or NULL if an error occured.
+
 *******************************************************************************/
 
-static bool annotation_bytearrays_insert(java_handle_objectarray_t **bas,
-       uint32_t index, java_handle_bytearray_t *ba)
+static java_handle_objectarray_t *annotation_bytearrays_insert(
+       java_handle_objectarray_t *bas, uint32_t index, java_handle_bytearray_t *ba)
 {
-       uint32_t size = 0;
-
-       assert(bas != NULL);
+       uint32_t size = 0; /* current size of the array */
 
        /* do nothing if NULL is inserted but no array exists */
-       if (ba == NULL && *bas == NULL) {
-               return true;
+       if (ba == NULL && bas == NULL) {
+               return bas;
        }
 
        /* get lengths if array exists */
-       if (*bas != NULL) {
-               size = array_length_get((java_handle_t*)*bas);
+       if (bas != NULL) {
+               size = array_length_get((java_handle_t*)bas);
        }
 
        if (ba == NULL) {
                /* insert NULL only if array is big enough */
                if (size > index) {
-                       array_objectarray_element_set(*bas, index, NULL);
+                       array_objectarray_element_set(bas, index, NULL);
                }
        }
        else {
                /* resize array if it's not enough for inserted value */
                if (size <= index) {
-                       if (!annotation_bytearrays_resize(bas, index + 1)) {
+                       bas = annotation_bytearrays_resize(bas, index + 1);
+
+                       if (bas == NULL) {
                                /* out of memory */
-                               return false;
+                               return NULL;
                        }
                }
 
-               array_objectarray_element_set(*bas, index, (java_handle_t*)ba);
+               array_objectarray_element_set(bas, index, (java_handle_t*)ba);
        }
        
-       return true;
+       return bas;
 }
 
 
@@ -170,8 +179,8 @@ static bool annotation_bytearrays_insert(java_handle_objectarray_t **bas,
 static bool annotation_load_attribute_body(classbuffer *cb,
        java_handle_bytearray_t **attribute, const char *errormsg_prefix)
 {
-       uint32_t size = 0;
-       java_handle_bytearray_t *ba = NULL;
+       uint32_t                 size = 0;    /* size of the attribute     */
+       java_handle_bytearray_t *ba   = NULL; /* the raw attributes' bytes */
 
        assert(cb != NULL);
        assert(attribute != NULL);
@@ -234,14 +243,20 @@ static bool annotation_load_attribute_body(classbuffer *cb,
 bool annotation_load_method_attribute_annotationdefault(
                classbuffer *cb, methodinfo *m)
 {
-       int                         slot               = 0;
-       java_handle_bytearray_t    *annotationdefault  = NULL;
-       java_handle_objectarray_t **annotationdefaults = NULL;
+       int                        slot               = 0;
+                                  /* the slot of the method                      */
+       java_handle_bytearray_t   *annotationdefault  = NULL;
+                                  /* unparsed annotation defalut value           */
+       java_handle_objectarray_t *annotationdefaults = NULL;
+                                  /* array of unparsed annotation default values */
 
        assert(cb != NULL);
        assert(m != NULL);
 
-       annotationdefaults = &(m->class->method_annotationdefaults);
+       /* XXX: Wait for michis reply if it should be:
+        * LLNI_field_get_ref(m->class, method_annotations, annotationdefaults);
+        */
+       annotationdefaults = m->class->method_annotationdefaults;
 
        if (!annotation_load_attribute_body(
                        cb, &annotationdefault,
@@ -251,11 +266,17 @@ bool annotation_load_method_attribute_annotationdefault(
 
        if (annotationdefault != NULL) {
                slot = m - m->class->methods;
+               annotationdefaults = annotation_bytearrays_insert(
+                               annotationdefaults, slot, annotationdefault);
 
-               if (!annotation_bytearrays_insert(
-                               annotationdefaults, slot, annotationdefault)) {
+               if (annotationdefaults == NULL) {
                        return false;
                }
+
+       /* XXX: Wait for michis reply if it should be:
+        * LLNI_field_set_ref(m->class, method_annotations, annotationdefaults);
+        */
+               m->class->method_annotationdefaults = annotationdefaults;
        }
 
        return true;
@@ -290,14 +311,20 @@ bool annotation_load_method_attribute_annotationdefault(
 bool annotation_load_method_attribute_runtimevisibleparameterannotations(
                classbuffer *cb, methodinfo *m)
 {
-       int                         slot                 = 0;
-       java_handle_bytearray_t    *annotations          = NULL;
-       java_handle_objectarray_t **parameterannotations = NULL;
+       int                        slot                 = 0;
+                                  /* the slot of the method */
+       java_handle_bytearray_t   *annotations          = NULL;
+                                  /* unparsed parameter annotations */
+       java_handle_objectarray_t *parameterannotations = NULL;
+                                  /* array of unparsed parameter annotations */
 
        assert(cb != NULL);
        assert(m != NULL);
 
-       parameterannotations = &(m->class->method_parameterannotations);
+       /* XXX: Wait for michis reply if it should be:
+        * LLNI_field_get_ref(m->class, method_parameterannotations, parameterannotations);
+        */
+       parameterannotations = m->class->method_parameterannotations;
 
        if (!annotation_load_attribute_body(
                        cb, &annotations,
@@ -307,11 +334,17 @@ bool annotation_load_method_attribute_runtimevisibleparameterannotations(
 
        if (annotations != NULL) {
                slot = m - m->class->methods;
+               parameterannotations = annotation_bytearrays_insert(
+                               parameterannotations, slot, annotations);
 
-               if (!annotation_bytearrays_insert(
-                               parameterannotations, slot, annotations)) {
+               if (parameterannotations == NULL) {
                        return false;
                }
+
+       /* XXX: Wait for michis reply if it should be:
+        * LLNI_field_set_ref(m->class, method_parameterannotations, parameterannotations);
+        */
+               m->class->method_parameterannotations = parameterannotations;
        }
 
        return true;
@@ -334,7 +367,7 @@ bool annotation_load_method_attribute_runtimevisibleparameterannotations(
 
    Hotspot loads them into the same bytearray as the runtime visible parameter
    annotations (after the runtime visible parameter annotations). But in J2SE
-   the bytearray will only be parsed as if ther is only one annotation
+   the bytearray will only be parsed as if there is only one annotation
    structure in it, so the runtime invisible parameter annotatios will be
    ignored.
 
@@ -372,14 +405,31 @@ bool annotation_load_method_attribute_runtimeinvisibleparameterannotations(
    
    Load runtime visible annotations of a class.
    
+   IN:
+       cb........the classbuffer from which the attribute has to be loaded.
+
+   RETURN VALUE:
+       true if all went good. false otherwhise.
+
 *******************************************************************************/
 
 bool annotation_load_class_attribute_runtimevisibleannotations(
        classbuffer *cb)
 {
-       return annotation_load_attribute_body(
-               cb, &(cb->class->annotations),
-               "invalid runtime visible annotations class attribute");
+       java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
+       
+       if (!annotation_load_attribute_body(
+                       cb, &annotations,
+                       "invalid runtime visible annotations class attribute")) {
+               return false;
+       }
+
+       /* XXX: Wait for michis reply if it should be:
+        * LLNI_field_set_ref(cb->class, annotations, annotations);
+        */
+       cb->class->annotations = annotations;
+
+       return true;
 }
 
 
@@ -387,6 +437,12 @@ bool annotation_load_class_attribute_runtimevisibleannotations(
    
    Load runtime invisible annotations of a class (just skip them).
    
+   IN:
+       cb........the classbuffer from which the attribute has to be loaded.
+
+   RETURN VALUE:
+       true if all went good. false otherwhise.
+
 *******************************************************************************/
 
 bool annotation_load_class_attribute_runtimeinvisibleannotations(
@@ -399,20 +455,34 @@ bool annotation_load_class_attribute_runtimeinvisibleannotations(
 /* annotation_load_method_attribute_runtimevisibleannotations *****************
    
    Load runtime visible annotations of a method.
-   
+  
+   IN:
+       cb........the classbuffer from which the attribute has to be loaded.
+       m.........the method of which the runtime visible annotations have
+                 to be loaded.
+
+   RETURN VALUE:
+       true if all went good. false otherwhise.
+
 *******************************************************************************/
 
 bool annotation_load_method_attribute_runtimevisibleannotations(
        classbuffer *cb, methodinfo *m)
 {
-       int                         slot               = 0;
-       java_handle_bytearray_t    *annotations        = NULL;
-       java_handle_objectarray_t **method_annotations = NULL;
+       int                        slot               = 0;
+                                  /* slot of the method */
+       java_handle_bytearray_t   *annotations        = NULL;
+                                  /* unparsed annotations */
+       java_handle_objectarray_t *method_annotations = NULL;
+                                  /* array of unparsed method annotations */
 
        assert(cb != NULL);
        assert(m != NULL);
 
-       method_annotations = &(m->class->method_annotations);
+       /* XXX: Wait for michis reply if it should be:
+        * LLNI_field_get_ref(m->class, method_annotations, method_annotations);
+        */
+       method_annotations = m->class->method_annotations;
 
        if (!annotation_load_attribute_body(
                        cb, &annotations,
@@ -422,11 +492,17 @@ bool annotation_load_method_attribute_runtimevisibleannotations(
 
        if (annotations != NULL) {
                slot = m - m->class->methods;
+               method_annotations = annotation_bytearrays_insert(
+                               method_annotations, slot, annotations);
 
-               if (!annotation_bytearrays_insert(
-                               method_annotations, slot, annotations)) {
+               if (method_annotations == NULL) {
                        return false;
                }
+               
+       /* XXX: Wait for michis reply if it should be:
+        * LLNI_field_set_ref(m->class, method_annotations, method_annotations);
+        */
+               m->class->method_annotations = method_annotations;
        }
 
        return true;
@@ -437,6 +513,14 @@ bool annotation_load_method_attribute_runtimevisibleannotations(
    
    Load runtime invisible annotations of a method (just skip them).
    
+   IN:
+       cb........the classbuffer from which the attribute has to be loaded.
+       m.........the method of which the runtime invisible annotations have
+                 to be loaded.
+
+   RETURN VALUE:
+       true if all went good. false otherwhise.
+
 *******************************************************************************/
 
 bool annotation_load_method_attribute_runtimeinvisibleannotations(
@@ -450,19 +534,33 @@ bool annotation_load_method_attribute_runtimeinvisibleannotations(
    
    Load runtime visible annotations of a field.
    
+   IN:
+       cb........the classbuffer from which the attribute has to be loaded.
+       f.........the field of which the runtime visible annotations have
+                 to be loaded.
+
+   RETURN VALUE:
+       true if all went good. false otherwhise.
+
 *******************************************************************************/
 
 bool annotation_load_field_attribute_runtimevisibleannotations(
        classbuffer *cb, fieldinfo *f)
 {
-       int                          slot             = 0;
-       java_handle_bytearray_t    *annotations       = NULL;
-       java_handle_objectarray_t **field_annotations = NULL;
+       int                        slot              = 0;
+                                  /* slot of the field */
+       java_handle_bytearray_t   *annotations       = NULL;
+                                  /* unparsed annotations */
+       java_handle_objectarray_t *field_annotations = NULL;
+                                  /* array of unparsed field annotations */
 
        assert(cb != NULL);
        assert(f != NULL);
 
-       field_annotations = &(f->class->field_annotations);
+       /* XXX: Wait for michis reply if it should be:
+        * LLNI_field_get_ref(f->class, method_annotations, method_annotations);
+        */
+       field_annotations = f->class->field_annotations;
 
        if (!annotation_load_attribute_body(
                        cb, &annotations,
@@ -472,11 +570,17 @@ bool annotation_load_field_attribute_runtimevisibleannotations(
 
        if (annotations != NULL) {
                slot = f - f->class->fields;
+               field_annotations = annotation_bytearrays_insert(
+                               field_annotations, slot, annotations);
 
-               if (!annotation_bytearrays_insert(
-                               field_annotations, slot, annotations)) {
+               if (field_annotations == NULL) {
                        return false;
                }
+
+       /* XXX: Wait for michis reply if it should be:
+        * LLNI_field_set_ref(f->class, method_annotations, method_annotations);
+        */
+               f->class->field_annotations = field_annotations;
        }
 
        return true;
@@ -487,6 +591,14 @@ bool annotation_load_field_attribute_runtimevisibleannotations(
    
    Load runtime invisible annotations of a field (just skip them).
    
+   IN:
+       cb........the classbuffer from which the attribute has to be loaded.
+       f.........the field of which the runtime invisible annotations have
+                 to be loaded.
+
+   RETURN VALUE:
+       true if all went good. false otherwhise.
+
 *******************************************************************************/
 
 bool annotation_load_field_attribute_runtimeinvisibleannotations(
index 4100024f36b3ed80560a38b665039b62d6af57aa..0b5e241c33961891ec2870f33cad018aefdefebe 100644 (file)
@@ -654,21 +654,11 @@ bool class_load_attributes(classbuffer *cb)
 #endif
 
 #if defined(ENABLE_ANNOTATIONS)
-               /* XXX We can't do a release with that enabled */
-
                else if (attribute_name == utf_RuntimeVisibleAnnotations) {
                        /* RuntimeVisibleAnnotations */
                        if (!annotation_load_class_attribute_runtimevisibleannotations(cb))
                                return false;
                }
-               /* XXX RuntimeInvisibleAnnotations should only be loaded
-                * (or returned to Java) if some commandline options says so.
-                * Currently there is no such option available in cacao,
-                * therefore I load them allways (for testing purpose).
-                * Anyway, bytecode for RuntimeInvisibleAnnotations is only
-                * generated if you tell javac to do so. So in most cases
-                * there won't be any.
-                */
                else if (attribute_name == utf_RuntimeInvisibleAnnotations) {
                        /* RuntimeInvisibleAnnotations */
                        if (!annotation_load_class_attribute_runtimeinvisibleannotations(cb))
@@ -1962,8 +1952,15 @@ java_handle_objectarray_t *class_get_interfaces(classinfo *c)
 
 /* class_get_annotations *******************************************************
 
-   Return the unparsed declared annotations in an byte array
-   of the given class (or NULL if there aren't any).
+   Get the unparsed declared annotations in a byte array
+   of the given class.
+
+   IN:
+       c........the class of which the annotations should be returned
+
+   RETURN VALUE:
+       The unparsed declared annotations in a byte array
+       (or NULL if there aren't any).
 
 *******************************************************************************/
 
index f1fb070081c3e85154ad371dc5b8b8a5ec0648eb..31083f1852d26825eebf101f8571c25868727d13 100644 (file)
@@ -385,23 +385,33 @@ void field_free(fieldinfo *f)
 
 /* field_get_annotations ******************************************************
 
-   Gets a fields' annotations (or NULL if none).
+   Gat a fields' unparsed annotations in a byte array.
+
+   IN:
+       f........the field of which the annotations should be returned
+
+   RETURN VALUE:
+       The unparsed annotations in a byte array (or NULL if there aren't any).
 
 *******************************************************************************/
 
 java_handle_bytearray_t *field_get_annotations(fieldinfo *f)
 {
 #if defined(ENABLE_ANNOTATIONS)
-       classinfo               *c;
-       int                      slot;
-       java_handle_bytearray_t *annotations;
-       java_handle_t           *a;
+       classinfo               *c;           /* declaring class           */
+       int                      slot;        /* slot of this field        */
+       java_handle_bytearray_t *annotations; /* unparsed annotations      */
+       java_handle_t           *a;           /* unparsed annotations cast */
+                                             /* into java_handle_t*       */
 
        c           = f->class;
        slot        = f - c->fields;
        annotations = NULL;
        a           = (java_handle_t*)c->field_annotations;
        
+       /* the field_annotations array might be shorter then the field
+        * count if the fields above a certain index have no annotations.
+        */
        if (c->field_annotations != NULL && array_length_get(a) > slot) {
                annotations = (java_handle_bytearray_t*)
                        array_objectarray_element_get(
index 2849fa4262ae326900df854a2eca40c1a0dff61c..011bfc4007ee2b3ea1d8079648e48b9c5af45d60 100644 (file)
@@ -616,20 +616,24 @@ methodinfo *method_vftbl_lookup(vftbl_t *vftbl, methodinfo* m)
    Use the descriptor of a method to determine the number of parameters
    of the method. The this pointer of non-static methods is not counted.
 
-   Returns -1 on error.
+   IN:
+       m........the method of which the parameters should be counted
+
+   RETURN VALUE:
+       The parameter count or -1 on error.
 
 *******************************************************************************/
 
 int32_t method_get_parametercount(methodinfo *m)
 {
-       methoddesc *md;
-       int32_t     paramcount = 0;
+       methoddesc *md;             /* method descriptor of m   */
+       int32_t     paramcount = 0; /* the parameter count of m */
 
        md = m->parseddesc;
        
        /* is the descriptor fully parsed? */
 
-       if (m->parseddesc->params == NULL) {
+       if (md->params == NULL) {
                if (!descriptor_params_from_paramtypes(md, m->flags)) {
                        return -1;
                }
@@ -808,23 +812,33 @@ s4 method_count_implementations(methodinfo *m, classinfo *c, methodinfo **found)
 
 /* method_get_annotations ******************************************************
 
-   Gets a methods' annotations (or NULL if none).
+   Get a methods' unparsed annotations in a byte array.
+
+   IN:
+       m........the method of which the annotations should be returned
+
+   RETURN VALUE:
+       The unparsed annotations in a byte array (or NULL if there aren't any).
 
 *******************************************************************************/
 
 java_handle_bytearray_t *method_get_annotations(methodinfo *m)
 {
 #if defined(ENABLE_ANNOTATIONS)
-       classinfo               *c;
-       int                      slot;
-       java_handle_bytearray_t *annotations;
-       java_handle_t           *a;
+       classinfo               *c;           /* methods' declaring class      */
+       int                      slot;        /* methods' slot                 */
+       java_handle_bytearray_t *annotations; /* methods' unparsed annotations */
+       java_handle_t           *a;           /* methods' unparsed annotations */
+                                             /* cast into a java_handle_t*    */
 
        c           = m->class;
        slot        = m - c->methods;
        annotations = NULL;
        a           = (java_handle_t*)c->method_annotations;
-       
+
+       /* the method_annotations array might be shorter then the method
+        * count if the methods above a certain index have no annotations.
+        */     
        if (c->method_annotations != NULL && array_length_get(a) > slot) {
                annotations = (java_handle_bytearray_t*)array_objectarray_element_get(
                        c->method_annotations, slot);
@@ -839,17 +853,29 @@ java_handle_bytearray_t *method_get_annotations(methodinfo *m)
 
 /* method_get_parameterannotations ********************************************
 
-   Gets a methods' parameter annotations (or NULL if none).
+   Get a methods' unparsed parameter annotations in an array of byte
+   arrays.
+
+   IN:
+       m........the method of which the parameter annotations should be
+                   returned
+
+   RETURN VALUE:
+       The unparsed parameter annotations in a byte array (or NULL if
+          there aren't any).
 
 *******************************************************************************/
 
 java_handle_bytearray_t *method_get_parameterannotations(methodinfo *m)
 {
 #if defined(ENABLE_ANNOTATIONS)
-       classinfo               *c;
-       int                      slot;
-       java_handle_bytearray_t *parameterAnnotations;
-       java_handle_t           *a;
+       classinfo               *c;                  /* methods' declaring class */
+       int                      slot;               /* methods' slot            */
+       java_handle_bytearray_t *parameterAnnotations; /* methods' unparsed      */
+                                                    /* parameter annotations    */
+       java_handle_t           *a;                  /* methods' unparsed        */
+                                                    /* parameter annotations    */
+                                                                                                /* cast into java_handle_t* */
 
        c                    = m->class;
        slot                 = m - c->methods;
@@ -871,17 +897,28 @@ java_handle_bytearray_t *method_get_parameterannotations(methodinfo *m)
 
 /* method_get_annotationdefault ***********************************************
 
-   Gets a methods' annotation default value (or NULL if none).
+   Get a methods' unparsed annotation default value in a byte array.
+   
+   IN:
+       m........the method of which the annotation default value should be
+                   returned
+
+   RETURN VALUE:
+       The unparsed annotation default value in a byte array (or NULL if
+          there isn't one).
 
 *******************************************************************************/
 
 java_handle_bytearray_t *method_get_annotationdefault(methodinfo *m)
 {
 #if defined(ENABLE_ANNOTATIONS)
-       classinfo               *c;
-       int                      slot;
-       java_handle_bytearray_t *annotationDefault;
-       java_handle_t           *a;
+       classinfo               *c;                 /* methods' declaring class */
+       int                      slot;              /* methods' slot            */
+       java_handle_bytearray_t *annotationDefault; /* methods' unparsed        */
+                                                   /* annotation default value */
+       java_handle_t           *a;                 /* methods' unparsed        */
+                                                   /* annotation default value */
+                                                   /* cast into java_handle_t* */
 
        c                 = m->class;
        slot              = m - c->methods;
index 99ccb65439b68e5a750c048c98fe1f9768ac782f..09d691aed748ce3456591cae66015eee3ec9cb90 100644 (file)
@@ -153,11 +153,11 @@ utf *utf_Signature;
 utf *utf_StackMapTable;
 
 #if defined(ENABLE_ANNOTATIONS)
-utf *utf_RuntimeVisibleAnnotations;
-utf *utf_RuntimeInvisibleAnnotations;
-utf *utf_RuntimeVisibleParameterAnnotations;
-utf *utf_RuntimeInvisibleParameterAnnotations;
-utf *utf_AnnotationDefault;
+utf *utf_RuntimeVisibleAnnotations;            /* RuntimeVisibleAnnotations            */
+utf *utf_RuntimeInvisibleAnnotations;          /* RuntimeInvisibleAnnotations          */
+utf *utf_RuntimeVisibleParameterAnnotations;   /* RuntimeVisibleParameterAnnotations   */
+utf *utf_RuntimeInvisibleParameterAnnotations; /* RuntimeInvisibleParameterAnnotations */
+utf *utf_AnnotationDefault;                    /* AnnotationDefault                    */
 #endif
 #endif
 
index 195abf4e29f3096b988aa1ccc75910a399166789..af2ef181bd04b4c7d04026ecca148a810a65d0c5 100644 (file)
 
 */
 
+/**
+ * Test following methos of java.lang.Class for proper function:
+ *  getSuperclass()
+ *  getDeclaringClass()
+ *  getEnclosingClass()
+ *  getEnclosingConstructor()
+ *  getEnclosingMethod()
+ *
+ * I wrote this because getSuperclass() sometimes made problems.
+ */
 import java.lang.reflect.Method;
 import java.lang.reflect.Constructor;