* src/vmcore/class.h
authorpanzi <none@none>
Wed, 22 Aug 2007 13:12:46 +0000 (13:12 +0000)
committerpanzi <none@none>
Wed, 22 Aug 2007 13:12:46 +0000 (13:12 +0000)
(class_get_annotations): Added. This function encapsulates the access to the
annotations field of the classinfo struct. It is defined even if
ENABLE_ANNOTATIONS is not, but just returns NULL in that case.

* src/vmcore/class.c
(class_get_annotations): Added.

* src/native/vm/java_lang_Class.c
(_Jv_java_lang_Class_getDeclaredAnnotations): Now uses class_get_annotations().

* src/native/vm/sun/jvm.c
(JVM_GetClassAnnotations): Now uses class_get_annotations().

src/native/vm/java_lang_Class.c
src/native/vm/sun/jvm.c
src/vmcore/class.c
src/vmcore/class.h

index d36e4a406496e8c6a6a87e9cbd32dc861c4ce898..30dccafce59c147e535099958bd3a59988ab63a5 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: java_lang_Class.c 8357 2007-08-19 22:59:43Z twisti $
+   $Id: java_lang_Class.c 8395 2007-08-22 13:12:46Z panzi $
 
 */
 
@@ -619,32 +619,28 @@ 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               = LLNI_classinfo_unwrap(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;
-       uint32_t                  size            = 0;
        java_lang_Object         *constantPoolOop = (java_lang_Object*)klass;
 
-       if (c == NULL) {
+       if (klass == NULL) {
                exceptions_throw_nullpointerexception();
                return NULL;
        }
        
-       /* Return null for arrays and primitives: */
-       if (class_is_primitive(c) || class_is_array(c)) {
-               return NULL;
-       }
+       c = LLNI_classinfo_unwrap(klass);
 
-       if (c->annotations != NULL) {
-               size        = c->annotations->size;
-               annotations = builtin_newarray_byte(size);
+       /* get annotations: */
+       annotations = class_get_annotations(c);
 
-               if(annotations != NULL) {
-                       MCOPY(annotations->data, c->annotations->data, uint8_t, size);
-               }
+       if (exceptions_get_exception() != NULL) {
+               /* the only exception possible here should be a out of memory exception
+                * raised by copying the annotations into a java bytearray */
+               return NULL;
        }
 
        constantPool = 
index b39e63ee64e469c26777579cbcf2771ceacc9eaa..34d66a8549ba002e0733f15fd23bbc8b6e42c097 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: jvm.c 8393 2007-08-22 01:10:09Z panzi $
+   $Id: jvm.c 8395 2007-08-22 13:12:46Z panzi $
 
 */
 
@@ -1067,8 +1067,7 @@ jstring JVM_GetClassSignature(JNIEnv *env, jclass cls)
 
 jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
 {
-#if defined(ENABLE_ANNOTATIONS)
-       classinfo *c = LLNI_classinfo_unwrap(cls);
+       classinfo               *c           = NULL;
        java_handle_bytearray_t *annotations = NULL;
 
        TRACEJVMCALLS("JVM_GetClassAnnotations: cls=%p", cls);
@@ -1077,29 +1076,13 @@ jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
                exceptions_throw_nullpointerexception();
                return NULL;
        }
+       
+       c = LLNI_classinfo_unwrap(cls);
 
-       /* Return null for arrays and primitives: */
-       if(class_is_primitive(c) || class_is_array(c))
-       {
-               return NULL;
-       }
-
-       if(c->annotations != NULL)
-       {
-               uint32_t size = c->annotations->size;
-               annotations = builtin_newarray_byte(size);
-
-               if(annotations != NULL)
-               {
-                       MCOPY(annotations->data, c->annotations->data, uint8_t, size);
-               }
-       }
+       /* get annotations: */
+       annotations = class_get_annotations(c);
 
        return (jbyteArray)annotations;
-#else
-       log_println("JVM_GetClassAnnotations: cls=%p, not implemented in this configuration!", cls);
-       return NULL;
-#endif
 }
 
 
index e0676a3707f42da4b76cbd3f06d614908deeec87..4a5a0385ca01a210c33f164285ab9a94b4d41030 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: class.c 8387 2007-08-21 15:37:47Z twisti $
+   $Id: class.c 8395 2007-08-22 13:12:46Z panzi $
 
 */
 
@@ -1987,6 +1987,41 @@ 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).
+
+*******************************************************************************/
+
+java_handle_bytearray_t *class_get_annotations(classinfo *c)
+{
+#if defined(ENABLE_ANNOTATIONS)
+       java_handle_bytearray_t  *annotations = NULL;
+       uint32_t                  size        = 0;
+       
+       /* Return null for arrays and primitives: */
+       if (class_is_primitive(c) || class_is_array(c)) {
+               return NULL;
+       }
+
+       /* copy the annotations into a java byte array: */
+       if (c->annotations != NULL) {
+               size        = c->annotations->size;
+               annotations = builtin_newarray_byte(size);
+
+               if(annotations != NULL) {
+                       MCOPY(annotations->data, c->annotations->data, uint8_t, size);
+               }
+       }
+
+       return annotations;
+#else
+       return NULL;
+#endif
+}
+
+
 /* class_get_signature *********************************************************
 
    Return the signature of the given class.  For array and primitive
index 6a812ef3ba176333c70d13fd11655e3d1515095e..62f3026b6327fa2a35255cfee27345fb33b27b6f 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: class.h 8393 2007-08-22 01:10:09Z panzi $
+   $Id: class.h 8395 2007-08-22 13:12:46Z panzi $
 
 */
 
@@ -385,6 +385,7 @@ java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOn
 classinfo                 *class_get_declaringclass(classinfo *c);
 classinfo                 *class_get_enclosingclass(classinfo *c);
 java_handle_objectarray_t *class_get_interfaces(classinfo *c);
+java_handle_bytearray_t   *class_get_annotations(classinfo *c);
 
 #if defined(ENABLE_JAVASE)
 utf                       *class_get_signature(classinfo *c);