* Removed all Id tags.
[cacao.git] / src / native / vm / java_lang_Class.c
index bdadefc38ebb21d7412575338e7d3a37f15104eb..12b534177051ddd93da0014e99250609ab47a48b 100644 (file)
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: java_lang_VMClass.c 6131 2006-12-06 22:15:57Z twisti $
-
 */
 
 
 #include "config.h"
 
 #include <assert.h>
+#include <stdint.h>
 #include <string.h>
 
 #include "vm/types.h"
 #include "mm/memory.h"
 
 #include "native/jni.h"
+#include "native/llni.h"
 #include "native/native.h"
 
-#if defined(ENABLE_JAVAME_CLDC1_1)
-# include "native/include/java_lang_String.h"/* required by java_lang_Class.h */
+/* keep this order of the native includes */
+
+#include "native/include/java_lang_String.h"
+
+#if defined(ENABLE_JAVASE)
+# if defined(WITH_CLASSPATH_SUN)
+#  include "native/include/java_nio_ByteBuffer.h"       /* required by j.l.CL */
+# endif
+# include "native/include/java_lang_ClassLoader.h"
 #endif
 
-#include "native/include/java_lang_Class.h"
 #include "native/include/java_lang_Object.h"
+#include "native/include/java_lang_Class.h"
 
 #if defined(ENABLE_JAVASE)
-# include "native/include/java_lang_ClassLoader.h"
 # include "native/include/java_lang_reflect_Constructor.h"
 # include "native/include/java_lang_reflect_Field.h"
 # include "native/include/java_lang_reflect_Method.h"
 
 #include "native/vm/java_lang_Class.h"
 
+#if defined(ENABLE_JAVASE)
+# include "native/vm/reflect.h"
+#endif
+
 #include "toolbox/logging.h"
 
 #include "vm/builtin.h"
 #include "vm/exceptions.h"
 #include "vm/global.h"
 #include "vm/initialize.h"
+#include "vm/primitive.h"
+#include "vm/resolve.h"
 #include "vm/stringlocal.h"
 
 #include "vmcore/class.h"
 #include "vmcore/loader.h"
-#include "vmcore/resolve.h"
 
+#if defined(WITH_CLASSPATH_GNU) && defined(ENABLE_ANNOTATIONS)
+#include "vm/vm.h"
+#include "vmcore/annotation.h"
+#include "native/include/sun_reflect_ConstantPool.h"
+#endif
 
 /*
  * Class:     java/lang/Class
@@ -77,9 +93,10 @@ java_lang_String *_Jv_java_lang_Class_getName(java_lang_Class *klass)
 {
        classinfo        *c;
        java_lang_String *s;
+       java_chararray_t *ca;
        u4                i;
 
-       c = (classinfo *) klass;
+       c = LLNI_classinfo_unwrap(klass);
 
        /* create a java string */
 
@@ -90,9 +107,11 @@ java_lang_String *_Jv_java_lang_Class_getName(java_lang_Class *klass)
 
        /* return string where '/' is replaced by '.' */
 
-       for (i = 0; i < s->value->header.size; i++) {
-               if (s->value->data[i] == '/')
-                       s->value->data[i] = '.';
+       LLNI_field_get_ref(s, value, ca);
+
+       for (i = 0; i < LLNI_array_size(ca); i++) {
+               if (LLNI_array_direct(ca, i) == '/')
+                       LLNI_array_direct(ca, i) = '.';
        }
 
        return s;
@@ -111,18 +130,16 @@ java_lang_Class *_Jv_java_lang_Class_forName(java_lang_String *name)
 #endif
 {
 #if defined(ENABLE_JAVASE)
-       java_objectheader *cl;
+       classloader *cl;
 #endif
-       utf               *ufile;
-       utf               *uname;
-       classinfo         *c;
-       java_objectheader *xptr;
-       classinfo         *xclass;
-       u2                *pos;
-       s4                 i;
+       utf         *ufile;
+       utf         *uname;
+       classinfo   *c;
+       u2          *pos;
+       s4           i;
 
 #if defined(ENABLE_JAVASE)
-       cl = (java_objectheader *) loader;
+       cl = (classloader *) loader;
 #endif
 
        /* illegal argument */
@@ -134,12 +151,12 @@ java_lang_Class *_Jv_java_lang_Class_forName(java_lang_String *name)
 
        /* create utf string in which '.' is replaced by '/' */
 
-       ufile = javastring_toutf(name, true);
-       uname = javastring_toutf(name, false);
+       ufile = javastring_toutf((java_handle_t *) name, true);
+       uname = javastring_toutf((java_handle_t *) name, false);
 
        /* name must not contain '/' (mauve test) */
 
-       for (i = 0, pos = name->value->data + name->offset; i < name->count; i++, pos++) {
+       for (i = 0, pos = LLNI_field_direct(name, value)->data + LLNI_field_direct(name, offset); i < LLNI_field_direct(name, count); i++, pos++) {
                if (*pos == '/') {
                        exceptions_throw_classnotfoundexception(uname);
                        return NULL;
@@ -154,24 +171,8 @@ java_lang_Class *_Jv_java_lang_Class_forName(java_lang_String *name)
        c = load_class_bootstrap(ufile);
 #endif
 
-       if (c == NULL) {
-               xptr = exceptions_get_exception();
-
-               xclass = xptr->vftbl->class;
-
-               /* if the exception is a NoClassDefFoundError, we replace it with a
-                  ClassNotFoundException, otherwise return the exception */
-
-               if (xclass == class_java_lang_NoClassDefFoundError) {
-                       /* clear exceptionptr, because builtin_new checks for 
-                          ExceptionInInitializerError */
-                       exceptions_clear_exception();
-
-                       exceptions_throw_classnotfoundexception(uname);
-               }
-
+       if (c == NULL)
            return NULL;
-       }
 
        /* link, ... */
 
@@ -186,7 +187,7 @@ java_lang_Class *_Jv_java_lang_Class_forName(java_lang_String *name)
                if (!initialize_class(c))
                        return NULL;
 
-       return (java_lang_Class *) c;
+       return LLNI_classinfo_wrap(c);
 }
 
 
@@ -197,11 +198,11 @@ java_lang_Class *_Jv_java_lang_Class_forName(java_lang_String *name)
  */
 s4 _Jv_java_lang_Class_isInstance(java_lang_Class *klass, java_lang_Object *o)
 {
-       classinfo         *c;
-       java_objectheader *ob;
+       classinfo     *c;
+       java_handle_t *ob;
 
-       c = (classinfo *) klass;
-       ob = (java_objectheader *) o;
+       c = LLNI_classinfo_unwrap(klass);
+       ob = (java_handle_t *) o;
 
        if (!(c->state & CLASS_LINKED))
                if (!link_class(c))
@@ -221,8 +222,8 @@ s4 _Jv_java_lang_Class_isAssignableFrom(java_lang_Class *klass, java_lang_Class
        classinfo *kc;
        classinfo *cc;
 
-       kc = (classinfo *) klass;
-       cc = (classinfo *) c;
+       kc = LLNI_classinfo_unwrap(klass);
+       cc = LLNI_classinfo_unwrap(c);
 
        if (cc == NULL) {
                exceptions_throw_nullpointerexception();
@@ -237,9 +238,7 @@ s4 _Jv_java_lang_Class_isAssignableFrom(java_lang_Class *klass, java_lang_Class
                if (!link_class(cc))
                        return 0;
 
-       /* XXX this may be wrong for array classes */
-
-       return builtin_isanysubclass(cc, kc);
+       return class_isanysubclass(cc, kc);
 }
 
 
@@ -248,16 +247,13 @@ s4 _Jv_java_lang_Class_isAssignableFrom(java_lang_Class *klass, java_lang_Class
  * Method:    isInterface
  * Signature: ()Z
  */
-s4 _Jv_java_lang_Class_isInterface(java_lang_Class *klass)
+JNIEXPORT int32_t JNICALL _Jv_java_lang_Class_isInterface(JNIEnv *env, java_lang_Class *this)
 {
        classinfo *c;
 
-       c = (classinfo *) klass;
-
-       if (c->flags & ACC_INTERFACE)
-               return true;
+       c = LLNI_classinfo_unwrap(this);
 
-       return false;
+       return class_is_interface(c);
 }
 
 
@@ -271,17 +267,10 @@ s4 _Jv_java_lang_Class_isInterface(java_lang_Class *klass)
 s4 _Jv_java_lang_Class_isPrimitive(java_lang_Class *klass)
 {
        classinfo *c;
-       s4         i;
-
-       c = (classinfo *) klass;
 
-       /* search table of primitive classes */
+       c = LLNI_classinfo_unwrap(klass);
 
-       for (i = 0; i < PRIMITIVETYPE_COUNT; i++)
-               if (primitivetype_table[i].class_primitive == c)
-                       return true;
-
-       return false;
+       return class_is_primitive(c);
 }
 
 
@@ -293,30 +282,13 @@ s4 _Jv_java_lang_Class_isPrimitive(java_lang_Class *klass)
 java_lang_Class *_Jv_java_lang_Class_getSuperclass(java_lang_Class *klass)
 {
        classinfo *c;
-       classinfo *sc;
-
-       c = (classinfo *) klass;
-
-       /* for java.lang.Object, primitive and Void classes we return NULL */
-
-       if (!c->super.any)
-               return NULL;
-
-       /* for interfaces we also return NULL */
+       classinfo *super;
 
-       if (c->flags & ACC_INTERFACE)
-               return NULL;
-
-       /* we may have to resolve the super class reference */
-
-       if ((sc = resolve_classref_or_classinfo_eager(c->super, true)) == NULL)
-               return NULL;
-
-       /* store the resolution */
+       c = LLNI_classinfo_unwrap(klass);
 
-       c->super.cls = sc;
+       super = class_get_superclass(c);
 
-       return (java_lang_Class *) sc;
+       return LLNI_classinfo_wrap(super);
 }
 
 
@@ -325,68 +297,19 @@ java_lang_Class *_Jv_java_lang_Class_getSuperclass(java_lang_Class *klass)
  * Method:    getInterfaces
  * Signature: ()[Ljava/lang/Class;
  */
-java_objectarray *_Jv_java_lang_Class_getInterfaces(java_lang_Class *klass)
+java_handle_objectarray_t *_Jv_java_lang_Class_getInterfaces(java_lang_Class *klass)
 {
-       classinfo        *c;
-       classinfo        *ic;
-       java_objectarray *oa;
-       u4                i;
-
-       c = (classinfo *) klass;
-
-       if (!(c->state & CLASS_LINKED))
-               if (!link_class(c))
-                       return NULL;
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;
 
-       oa = builtin_anewarray(c->interfacescount, class_java_lang_Class);
+       c = LLNI_classinfo_unwrap(klass);
 
-       if (oa == NULL)
-               return NULL;
-
-       for (i = 0; i < c->interfacescount; i++) {
-               ic = c->interfaces[i].cls;
-
-               oa->data[i] = (java_objectheader *) ic;
-       }
+       oa = class_get_interfaces(c);
 
        return oa;
 }
 
 
-/*
- * Class:     java/lang/Class
- * Method:    getComponentType
- * Signature: ()Ljava/lang/Class;
- */
-java_lang_Class *_Jv_java_lang_Class_getComponentType(java_lang_Class *klass)
-{
-       classinfo       *c;
-       classinfo       *comp;
-       arraydescriptor *desc;
-       
-       c = (classinfo *) klass;
-       
-       /* XXX maybe we could find a way to do this without linking. */
-       /* This way should be safe and easy, however.                */
-
-       if (!(c->state & CLASS_LINKED))
-               if (!link_class(c))
-                       return NULL;
-
-       desc = c->vftbl->arraydesc;
-       
-       if (desc == NULL)
-               return NULL;
-       
-       if (desc->arraytype == ARRAYTYPE_OBJECT)
-               comp = desc->componentvftbl->class;
-       else
-               comp = primitivetype_table[desc->arraytype].class_primitive;
-               
-       return (java_lang_Class *) comp;
-}
-
-
 /*
  * Class:     java/lang/Class
  * Method:    getModifiers
@@ -400,7 +323,7 @@ s4 _Jv_java_lang_Class_getModifiers(java_lang_Class *klass, s4 ignoreInnerClasse
        utf                   *innername;
        s4                     i;
 
-       c = (classinfo *) klass;
+       c = LLNI_classinfo_unwrap(klass);
 
        if (!ignoreInnerClassesAttrib && (c->innerclasscount != 0)) {
                /* search for passed class as inner class */
@@ -441,48 +364,14 @@ s4 _Jv_java_lang_Class_getModifiers(java_lang_Class *klass, s4 ignoreInnerClasse
  */
 java_lang_Class *_Jv_java_lang_Class_getDeclaringClass(java_lang_Class *klass)
 {
-       classinfo             *c;
-       classref_or_classinfo  inner;
-       utf                   *innername;
-       classinfo             *outer;
-       s4                     i;
-
-       c = (classinfo *) klass;
-
-       if (!_Jv_java_lang_Class_isPrimitive(klass) && (c->name->text[0] != '[')) {
-               if (c->innerclasscount == 0)  /* no innerclasses exist */
-                       return NULL;
-    
-               for (i = 0; i < c->innerclasscount; i++) {
-                       inner = c->innerclass[i].inner_class;
-
-                       /* check if inner_class is a classref or a real class and
-               get the class name from the structure */
-
-                       innername = IS_CLASSREF(inner) ? inner.ref->name : inner.cls->name;
-
-                       /* innerclass is this class */
-
-                       if (innername == c->name) {
-                               /* maybe the outer class is not loaded yet */
-
-                               if ((outer = resolve_classref_or_classinfo_eager(
-                                                               c->innerclass[i].outer_class,
-                                                               false)) == NULL)
-                                       return NULL;
-
-                               if (!(outer->state & CLASS_LINKED))
-                                       if (!link_class(outer))
-                                               return NULL;
+       classinfo *c;
+       classinfo *dc;
 
-                               return (java_lang_Class *) outer;
-                       }
-               }
-       }
+       c = LLNI_classinfo_unwrap(klass);
 
-       /* return NULL for arrayclasses and primitive classes */
+       dc = class_get_declaringclass(c);
 
-       return NULL;
+       return LLNI_classinfo_wrap(dc);
 }
 
 
@@ -491,71 +380,14 @@ java_lang_Class *_Jv_java_lang_Class_getDeclaringClass(java_lang_Class *klass)
  * Method:    getDeclaredClasses
  * Signature: (Z)[Ljava/lang/Class;
  */
-java_objectarray *_Jv_java_lang_Class_getDeclaredClasses(java_lang_Class *klass, s4 publicOnly)
+java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredClasses(java_lang_Class *klass, s4 publicOnly)
 {
-       classinfo             *c;
-       classref_or_classinfo  outer;
-       utf                   *outername;
-       s4                     declaredclasscount;  /* number of declared classes */
-       s4                     pos;                     /* current declared class */
-       java_objectarray      *oa;                   /* array of declared classes */
-       s4                     i;
-
-       c = (classinfo *) klass;
-       declaredclasscount = 0;
-
-       if (!_Jv_java_lang_Class_isPrimitive(klass) && (c->name->text[0] != '[')) {
-               /* determine number of declared classes */
-
-               for (i = 0; i < c->innerclasscount; i++) {
-                       outer = c->innerclass[i].outer_class;
-
-                       /* check if outer_class is a classref or a real class and
-               get the class name from the structure */
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;
 
-                       outername = IS_CLASSREF(outer) ? outer.ref->name : outer.cls->name;
+       c = LLNI_classinfo_unwrap(klass);
 
-                       /* outer class is this class */
-
-                       if ((outername == c->name) &&
-                               ((publicOnly == 0) || (c->innerclass[i].flags & ACC_PUBLIC)))
-                               declaredclasscount++;
-               }
-       }
-
-       /* allocate Class[] and check for OOM */
-
-       oa = builtin_anewarray(declaredclasscount, class_java_lang_Class);
-
-       if (oa == NULL)
-               return NULL;
-
-       for (i = 0, pos = 0; i < c->innerclasscount; i++) {
-               outer = c->innerclass[i].outer_class;
-
-               /* check if outer_class is a classref or a real class and
-                  get the class name from the structure */
-
-               outername = IS_CLASSREF(outer) ? outer.ref->name : outer.cls->name;
-
-               /* outer class is this class */
-
-               if ((outername == c->name) &&
-                       ((publicOnly == 0) || (c->innerclass[i].flags & ACC_PUBLIC))) {
-                       classinfo *inner;
-
-                       if ((inner = resolve_classref_or_classinfo_eager(
-                                                                                          c->innerclass[i].inner_class,
-                                                                                          false)) == NULL)
-                               return NULL;
-
-                       if (!(inner->state & CLASS_LINKED))
-                               if (!link_class(inner))
-                                       return NULL;
-
-                       oa->data[pos++] = (java_objectheader *) inner;
-               }
-       }
+       oa = class_get_declaredclasses(c, publicOnly);
 
        return oa;
 }
@@ -566,18 +398,17 @@ java_objectarray *_Jv_java_lang_Class_getDeclaredClasses(java_lang_Class *klass,
  * Method:    getDeclaredFields
  * Signature: (Z)[Ljava/lang/reflect/Field;
  */
-java_objectarray *_Jv_java_lang_Class_getDeclaredFields(java_lang_Class *klass, s4 publicOnly)
+java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredFields(java_lang_Class *klass, s4 publicOnly)
 {
-       classinfo               *c;
-       java_objectarray        *oa;            /* result: array of field-objects */
-       fieldinfo               *f;
-       java_objectheader       *o;
-       java_lang_reflect_Field *rf;
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;          /* result: array of field-objects */
+       fieldinfo                 *f;
+       java_lang_reflect_Field   *rf;
        s4 public_fields;                    /* number of elements in field-array */
        s4 pos;
        s4 i;
 
-       c = (classinfo *) klass;
+       c = LLNI_classinfo_unwrap(klass);
 
        /* determine number of fields */
 
@@ -600,22 +431,12 @@ java_objectarray *_Jv_java_lang_Class_getDeclaredFields(java_lang_Class *klass,
                if ((f->flags & ACC_PUBLIC) || (publicOnly == 0)) {
                        /* create Field object */
 
-                       o = native_new_and_init(class_java_lang_reflect_Field);
-
-                       if (o == NULL)
-                               return NULL;
-
-                       /* initialize instance fields */
-
-                       rf = (java_lang_reflect_Field *) o;
-
-                       rf->declaringClass = (java_lang_Class *) c;
-                       rf->name           = javastring_new(f->name);
-                       rf->slot           = i;
+                       rf = reflect_field_new(f);
 
                        /* store object into array */
 
-                       oa->data[pos++] = o;
+                       LLNI_objectarray_element_set(oa, pos, rf);
+                       pos++;
                }
        }
 
@@ -628,18 +449,18 @@ java_objectarray *_Jv_java_lang_Class_getDeclaredFields(java_lang_Class *klass,
  * Method:    getDeclaredMethods
  * Signature: (Z)[Ljava/lang/reflect/Method;
  */
-java_objectarray *_Jv_java_lang_Class_getDeclaredMethods(java_lang_Class *klass, s4 publicOnly)
+java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredMethods(java_lang_Class *klass, s4 publicOnly)
 {
-       classinfo                *c;
-       java_objectheader        *o;
-       java_lang_reflect_Method *rm;
-       java_objectarray         *oa;          /* result: array of Method-objects */
-       methodinfo               *m;      /* the current method to be represented */
+       classinfo                 *c;
+       java_lang_reflect_Method  *rm;
+       java_handle_objectarray_t *oa;         /* result: array of Method-objects */
+       methodinfo                *m;     /* the current method to be represented */
        s4 public_methods;               /* number of public methods of the class */
        s4 pos;
        s4 i;
 
-       c = (classinfo *) klass;    
+       c = LLNI_classinfo_unwrap(klass);
+
        public_methods = 0;
 
        /* JOWENN: array classes do not declare methods according to mauve
@@ -647,7 +468,7 @@ java_objectarray *_Jv_java_lang_Class_getDeclaredMethods(java_lang_Class *klass,
           clone method overriding instead of declaring it as a member
           function. */
 
-       if (_Jv_java_lang_Class_isArray(klass))
+       if (class_is_array(c))
                return builtin_anewarray(0, class_java_lang_reflect_Method);
 
        /* determine number of methods */
@@ -672,23 +493,14 @@ java_objectarray *_Jv_java_lang_Class_getDeclaredMethods(java_lang_Class *klass,
                if (((m->flags & ACC_PUBLIC) || (publicOnly == false)) && 
                        ((m->name != utf_init) && (m->name != utf_clinit)) &&
                        !(m->flags & ACC_MIRANDA)) {
+                       /* create Method object */
 
-                       o = native_new_and_init(class_java_lang_reflect_Method);
-
-                       if (o == NULL)
-                               return NULL;
-
-                       /* initialize instance fields */
-
-                       rm = (java_lang_reflect_Method *) o;
-
-                       rm->declaringClass = (java_lang_Class *) m->class;
-                       rm->name           = javastring_new(m->name);
-                       rm->slot           = i;
+                       rm = reflect_method_new(m);
 
                        /* store object into array */
 
-                       oa->data[pos++] = o;
+                       LLNI_objectarray_element_set(oa, pos, rm);
+                       pos++;
                }
        }
 
@@ -701,18 +513,17 @@ java_objectarray *_Jv_java_lang_Class_getDeclaredMethods(java_lang_Class *klass,
  * Method:    getDeclaredConstructors
  * Signature: (Z)[Ljava/lang/reflect/Constructor;
  */
-java_objectarray *_Jv_java_lang_Class_getDeclaredConstructors(java_lang_Class *klass, s4 publicOnly)
+java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredConstructors(java_lang_Class *klass, s4 publicOnly)
 {
        classinfo                     *c;
        methodinfo                    *m; /* the current method to be represented */
-       java_objectarray              *oa;     /* result: array of Method-objects */
-       java_objectheader             *o;
+       java_handle_objectarray_t     *oa;     /* result: array of Method-objects */
        java_lang_reflect_Constructor *rc;
        s4 public_methods;               /* number of public methods of the class */
        s4 pos;
        s4 i;
 
-       c = (classinfo *) klass;
+       c = LLNI_classinfo_unwrap(klass);
 
        /* determine number of constructors */
 
@@ -734,22 +545,14 @@ java_objectarray *_Jv_java_lang_Class_getDeclaredConstructors(java_lang_Class *k
 
                if (((m->flags & ACC_PUBLIC) || (publicOnly == 0)) &&
                        (m->name == utf_init)) {
+                       /* create Constructor object */
 
-                       o = native_new_and_init(class_java_lang_reflect_Constructor);
-
-                       if (o == NULL)
-                               return NULL;
-
-                       /* initialize instance fields */
-
-                       rc = (java_lang_reflect_Constructor *) o;
-
-                       rc->clazz = (java_lang_Class *) c;
-                       rc->slot  = i;
+                       rc = reflect_constructor_new(m);
 
                        /* store object into array */
 
-                       oa->data[pos++] = o;
+                       LLNI_objectarray_element_set(oa, pos, rc);
+                       pos++;
                }
        }
 
@@ -766,7 +569,7 @@ java_lang_ClassLoader *_Jv_java_lang_Class_getClassLoader(java_lang_Class *klass
 {
        classinfo *c;
 
-       c = (classinfo *) klass;
+       c = LLNI_classinfo_unwrap(klass);
 
        return (java_lang_ClassLoader *) c->classloader;
 }
@@ -779,17 +582,13 @@ java_lang_ClassLoader *_Jv_java_lang_Class_getClassLoader(java_lang_Class *klass
  * Method:    isArray
  * Signature: ()Z
  */
-s4 _Jv_java_lang_Class_isArray(java_lang_Class *klass)
+JNIEXPORT int32_t JNICALL _Jv_java_lang_Class_isArray(JNIEnv *env, java_lang_Class *this)
 {
        classinfo *c;
 
-       c = (classinfo *) klass;
-
-       if (!(c->state & CLASS_LINKED))
-               if (!link_class(c))
-                       return 0;
+       c = LLNI_classinfo_unwrap(this);
 
-       return (c->vftbl->arraydesc != NULL);
+       return class_is_array(c);
 }
 
 
@@ -802,59 +601,87 @@ s4 _Jv_java_lang_Class_isArray(java_lang_Class *klass)
  */
 void _Jv_java_lang_Class_throwException(java_lang_Throwable *t)
 {
-       java_objectheader *o;
+       java_handle_t *o;
 
-       o = (java_objectheader *) t;
+       o = (java_handle_t *) t;
 
        exceptions_set_exception(o);
 }
 
 
-#if 0
+#if defined(WITH_CLASSPATH_GNU) && defined(ENABLE_ANNOTATIONS)
 /*
  * Class:     java/lang/Class
  * Method:    getDeclaredAnnotations
  * Signature: (Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;
  */
-java_objectarray *_Jv_java_lang_Class_getDeclaredAnnotations(java_lang_Class* klass)
+java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredAnnotations(java_lang_Class* klass)
 {
-}
-#endif
+       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;
+
+       if (klass == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+       
+       c = LLNI_classinfo_unwrap(klass);
 
+       /* get annotations: */
+       annotations = class_get_annotations(c);
 
-/*
- * Class:     java/lang/Class
- * Method:    getEnclosingClass
- * Signature: (Ljava/lang/Class;)Ljava/lang/Class;
- */
-java_lang_Class *_Jv_java_lang_Class_getEnclosingClass(java_lang_Class *klass)
-{
-       classinfo             *c;
-       classref_or_classinfo  cr;
-       classinfo             *ec;
-
-       c = (classinfo *) klass;
+       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;
+       }
 
-       /* get enclosing class */
+       constantPool = 
+               (sun_reflect_ConstantPool*)native_new_and_init(
+                       class_sun_reflect_ConstantPool);
+       
+       if(constantPool == NULL) {
+               /* out of memory */
+               return NULL;
+       }
 
-       cr = c->enclosingclass;
+       LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop);
 
-       if (cr.any == NULL)
-               return NULL;
+       /* only resolve the method the first time */
+       if (m_parseAnnotationsIntoArray == NULL) {
+               utf_parseAnnotationsIntoArray = utf_new_char("parseAnnotationsIntoArray");
+               utf_desc = utf_new_char(
+                       "([BLsun/reflect/ConstantPool;Ljava/lang/Class;)"
+                       "[Ljava/lang/annotation/Annotation;");
 
-       /* resolve the class if necessary */
+               if (utf_parseAnnotationsIntoArray == NULL || utf_desc == NULL) {
+                       /* out of memory */
+                       return NULL;
+               }
 
-       if (IS_CLASSREF(cr)) {
-               ec = resolve_classref_eager(cr.ref);
+               m_parseAnnotationsIntoArray = class_resolveclassmethod(
+                       class_sun_reflect_annotation_AnnotationParser,
+                       utf_parseAnnotationsIntoArray,
+                       utf_desc,
+                       class_java_lang_Class,
+                       true);
 
-               if (ec == NULL)
+               if (m_parseAnnotationsIntoArray == NULL) {
+                       /* method not found */
                        return NULL;
+               }
        }
-       else
-               ec = cr.cls;
 
-       return (java_lang_Class *) ec;
+       return (java_handle_objectarray_t*)vm_call_method(
+               m_parseAnnotationsIntoArray, NULL,
+               annotations, constantPool, klass);
 }
+#endif
 
 
 /* _Jv_java_lang_Class_getEnclosingMethod_intern *******************************
@@ -866,35 +693,23 @@ java_lang_Class *_Jv_java_lang_Class_getEnclosingClass(java_lang_Class *klass)
 
 static methodinfo *_Jv_java_lang_Class_getEnclosingMethod_intern(classinfo *c)
 {
-       classref_or_classinfo     cr;
-       constant_nameandtype     *cn;
-       classinfo                *ec;
-       methodinfo               *m;
+       constant_nameandtype *cn;
+       classinfo            *ec;
+       methodinfo           *m;
 
        /* get enclosing class and method */
 
-       cr = c->enclosingclass;
+       ec = class_get_enclosingclass(c);
        cn = c->enclosingmethod;
 
        /* check for enclosing class and method */
 
-       if (cr.any == NULL)
+       if (ec == NULL)
                return NULL;
 
        if (cn == NULL)
                return NULL;
 
-       /* resolve the class if necessary */
-
-       if (IS_CLASSREF(cr)) {
-               ec = resolve_classref_eager(cr.ref);
-
-               if (ec == NULL)
-                       return NULL;
-       }
-       else
-               ec = cr.cls;
-
        /* find method in enclosing class */
 
        m = class_findmethod(ec, cn->name, cn->descriptor);
@@ -917,10 +732,9 @@ java_lang_reflect_Constructor *_Jv_java_lang_Class_getEnclosingConstructor(java_
 {
        classinfo                     *c;
        methodinfo                    *m;
-       java_objectheader             *o;
        java_lang_reflect_Constructor *rc;
 
-       c = (classinfo *) klass;
+       c = LLNI_classinfo_unwrap(klass);
 
        /* get enclosing method */
 
@@ -934,19 +748,9 @@ java_lang_reflect_Constructor *_Jv_java_lang_Class_getEnclosingConstructor(java_
        if (m->name != utf_init)
                return NULL;
 
-       /* create java.lang.reflect.Constructor object */
-
-       o = native_new_and_init(class_java_lang_reflect_Constructor);
-
-       if (o == NULL)
-               return NULL;
-
-       /* initialize instance fields */
+       /* create Constructor object */
 
-       rc = (java_lang_reflect_Constructor *) o;
-
-       rc->clazz = (java_lang_Class *) m->class;
-       rc->slot  = m - m->class->methods;               /* calculate method slot */
+       rc = reflect_constructor_new(m);
 
        return rc;
 }
@@ -961,10 +765,9 @@ java_lang_reflect_Method *_Jv_java_lang_Class_getEnclosingMethod(java_lang_Class
 {
        classinfo                *c;
        methodinfo               *m;
-       java_objectheader        *o;
        java_lang_reflect_Method *rm;
 
-       c = (classinfo *) klass;
+       c = LLNI_classinfo_unwrap(klass);
 
        /* get enclosing method */
 
@@ -980,18 +783,7 @@ java_lang_reflect_Method *_Jv_java_lang_Class_getEnclosingMethod(java_lang_Class
 
        /* create java.lang.reflect.Method object */
 
-       o = native_new_and_init(class_java_lang_reflect_Method);
-
-       if (o == NULL)
-               return NULL;
-
-       /* initialize instance fields */
-
-       rm = (java_lang_reflect_Method *) o;
-
-       rm->declaringClass = (java_lang_Class *) m->class;
-       rm->name           = javastring_new(m->name);
-       rm->slot           = m - m->class->methods;      /* calculate method slot */
+       rm = reflect_method_new(m);
 
        return rm;
 }
@@ -1004,47 +796,21 @@ java_lang_reflect_Method *_Jv_java_lang_Class_getEnclosingMethod(java_lang_Class
  */
 java_lang_String *_Jv_java_lang_Class_getClassSignature(java_lang_Class* klass)
 {
-       classinfo        *c;
-       java_lang_String *s;
+       classinfo     *c;
+       java_handle_t *o;
 
-       c = (classinfo *) klass;
+       c = LLNI_classinfo_unwrap(klass);
 
        if (c->signature == NULL)
                return NULL;
 
-       s = javastring_new(c->signature);
+       o = javastring_new(c->signature);
 
-       /* in error case, s == NULL */
+       /* in error case o is NULL */
 
-       return s;
+       return (java_lang_String *) o;
 }
 
-
-#if 0
-/*
- * Class:     java/lang/Class
- * Method:    isAnonymousClass
- * Signature: (Ljava/lang/Class;)Z
- */
-s4 _Jv_java_lang_Class_isAnonymousClass(JNIEnv *env, jclass clazz, struct java_lang_Class* par1);
-
-
-/*
- * Class:     java/lang/VMClass
- * Method:    isLocalClass
- * Signature: (Ljava/lang/Class;)Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isLocalClass(JNIEnv *env, jclass clazz, struct java_lang_Class* par1);
-
-
-/*
- * Class:     java/lang/VMClass
- * Method:    isMemberClass
- * Signature: (Ljava/lang/Class;)Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isMemberClass(JNIEnv *env, jclass clazz, struct java_lang_Class* par1);
-#endif
-
 #endif /* ENABLE_JAVASE */