* src/threads/posix/thread-posix.cpp: Eliminated some easy-to-fix or pointless compil...
[cacao.git] / src / vm / class.cpp
index 35ef8de9057cc1eeff3d1e02c465cbc98029e1c6..066bcfdcf4d220ef2401e4b321045c20b13ed4d4 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/class.cpp - class related functions
 
-   Copyright (C) 1996-2005, 2006, 2007, 2008
+   Copyright (C) 1996-2005, 2006, 2007, 2008, 2010
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
@@ -177,7 +177,7 @@ classinfo *class_create_classinfo(utf *classname)
        if (classname != utf_not_named_yet)
                class_set_packagename(c);
 
-       c->object.header.lockword.init();
+       Lockword(c->object.header.lockword).init();
 
        return c;
 }
@@ -612,7 +612,7 @@ bool class_load_attributes(classbuffer *cb)
 
 static void class_freecpool(classinfo *c)
 {
-       u4 idx;
+       int idx;
        u4 tag;
        void* info;
        
@@ -669,7 +669,7 @@ void* class_getconstant(classinfo *c, u4 pos, u4 ctype)
        /* check index and type of constantpool entry */
        /* (pos == 0 is caught by type comparison) */
 
-       if ((pos >= c->cpcount) || (c->cptags[pos] != ctype)) {
+       if (((int) pos >= c->cpcount) || (c->cptags[pos] != ctype)) {
                exceptions_throw_classformaterror(c, "Illegal constant pool index");
                return NULL;
        }
@@ -688,7 +688,7 @@ void* innerclass_getconstant(classinfo *c, u4 pos, u4 ctype)
 {
        /* invalid position in constantpool */
 
-       if (pos >= c->cpcount) {
+       if ((int) pos >= c->cpcount) {
                exceptions_throw_classformaterror(c, "Illegal constant pool index");
                return NULL;
        }
@@ -1499,32 +1499,33 @@ bool class_isanysubclass(classinfo *sub, classinfo *super)
 bool class_is_arraycompatible(arraydescriptor *desc, arraydescriptor *target)
 {
        if (desc == target)
-               return 1;
+               return true;
 
        if (desc->arraytype != target->arraytype)
-               return 0;
+               return false;
 
        if (desc->arraytype != ARRAYTYPE_OBJECT)
-               return 1;
+               return true;
        
        /* {both arrays are arrays of references} */
 
        if (desc->dimension == target->dimension) {
                if (!desc->elementvftbl)
-                       return 0;
+                       return false;
+
                /* an array which contains elements of interface types is
-           allowed to be casted to Object (JOWENN)*/
+                  allowed to be casted to array of Object (JOWENN) */
 
                if ((desc->elementvftbl->baseval < 0) &&
                        (target->elementvftbl->baseval == 1))
-                       return 1;
+                       return true;
 
                return class_isanysubclass(desc->elementvftbl->clazz,
                                                                   target->elementvftbl->clazz);
        }
 
        if (desc->dimension < target->dimension)
-               return 0;
+               return false;
 
        /* {desc has higher dimension than target} */
 
@@ -1560,7 +1561,7 @@ bool class_is_assignable_from(classinfo *to, classinfo *from)
 
        /* Decide whether we are dealing with array types or object types. */
 
-       if (class_is_array(to))
+       if (class_is_array(to) && class_is_array(from))
                return class_is_arraycompatible(from->vftbl->arraydesc, to->vftbl->arraydesc);
        else
                return class_isanysubclass(from, to);
@@ -1642,7 +1643,6 @@ java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOn
        utf                   *outername;
        int                    declaredclasscount;  /* number of declared classes */
        int                    pos;                     /* current declared class */
-       java_handle_objectarray_t *oa;               /* array of declared classes */
        int                    i;
        classinfo             *ic;
 
@@ -1675,9 +1675,9 @@ java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOn
 
        /* Allocate Class[] and check for OOM. */
 
-       oa = builtin_anewarray(declaredclasscount, class_java_lang_Class);
+       ClassArray declaredclasses(declaredclasscount);
 
-       if (oa == NULL)
+       if (declaredclasses.is_null())
                return NULL;
 
        for (i = 0, pos = 0; i < c->innerclasscount; i++) {
@@ -1709,11 +1709,11 @@ java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOn
                                if (!link_class(ic))
                                        return NULL;
 
-                       LLNI_array_direct(oa, pos++) = (java_object_t *) ic;
+                       declaredclasses.set_element(pos++, ic);
                }
        }
 
-       return oa;
+       return declaredclasses.get_handle();
 }
 
 
@@ -1728,11 +1728,10 @@ java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOn
 #if defined(ENABLE_JAVASE)
 java_handle_objectarray_t *class_get_declaredconstructors(classinfo *c, bool publicOnly)
 {
-       methodinfo*                m;
-       java_handle_objectarray_t* oa;
-       int                        count;
-       int                        index;
-       int                        i;
+       methodinfo* m;
+       int         count;
+       int         index;
+       int         i;
 
        /* Determine number of constructors. */
 
@@ -1748,9 +1747,9 @@ java_handle_objectarray_t *class_get_declaredconstructors(classinfo *c, bool pub
 
        /* Create array of constructors. */
 
-       oa = builtin_anewarray(count, class_java_lang_reflect_Constructor);
+       ObjectArray oa(count, class_java_lang_reflect_Constructor);
 
-       if (oa == NULL)
+       if (oa.is_null())
                return NULL;
 
        /* Get the constructors and store them in the array. */
@@ -1766,12 +1765,12 @@ java_handle_objectarray_t *class_get_declaredconstructors(classinfo *c, bool pub
 
                        /* Store object into array. */
 
-                       array_objectarray_element_set(oa, index, rc.get_handle());
+                       oa.set_element(index, rc.get_handle());
                        index++;
                }
        }
 
-       return oa;
+       return oa.get_handle();
 }
 #endif
 
@@ -1792,11 +1791,10 @@ java_handle_objectarray_t *class_get_declaredconstructors(classinfo *c, bool pub
 #if defined(ENABLE_JAVASE)
 java_handle_objectarray_t *class_get_declaredfields(classinfo *c, bool publicOnly)
 {
-       java_handle_objectarray_t *oa;
-       fieldinfo                 *f;
-       int                        count;
-       int                        index;
-       int                        i;
+       fieldinfo* f;
+       int        count;
+       int        index;
+       int        i;
 
        /* Determine number of fields. */
 
@@ -1808,9 +1806,9 @@ java_handle_objectarray_t *class_get_declaredfields(classinfo *c, bool publicOnl
 
        /* Create array of fields. */
 
-       oa = builtin_anewarray(count, class_java_lang_reflect_Field);
+       ObjectArray oa(count, class_java_lang_reflect_Field);
 
-       if (oa == NULL)
+       if (oa.is_null())
                return NULL;
 
        /* Get the fields and store them in the array. */
@@ -1825,12 +1823,12 @@ java_handle_objectarray_t *class_get_declaredfields(classinfo *c, bool publicOnl
 
                        /* Store object into array. */
 
-                       array_objectarray_element_set(oa, index, rf.get_handle());
+                       oa.set_element(index, rf.get_handle());
                        index++;
                }
        }
 
-       return oa;
+       return oa.get_handle();
 }
 #endif
 
@@ -1851,19 +1849,20 @@ java_handle_objectarray_t *class_get_declaredfields(classinfo *c, bool publicOnl
 #if defined(ENABLE_JAVASE)
 java_handle_objectarray_t *class_get_declaredmethods(classinfo *c, bool publicOnly)
 {
-       java_handle_objectarray_t *oa;         /* result: array of Method-objects */
-       methodinfo                *m;     /* the current method to be represented */
-       int                        count;
-       int                        index;
-       int                        i;
+       methodinfo* m;     /* the current method to be represented */
+       int         count;
+       int         index;
+       int         i;
 
        /* JOWENN: array classes do not declare methods according to mauve
           test.  It should be considered, if we should return to my old
           clone method overriding instead of declaring it as a member
           function. */
 
-       if (class_is_array(c))
-               return builtin_anewarray(0, class_java_lang_reflect_Method);
+       if (class_is_array(c)) {
+               ObjectArray oa(0, class_java_lang_reflect_Method);
+               return oa.get_handle();
+       }
 
        /* Determine number of methods. */
 
@@ -1880,9 +1879,9 @@ java_handle_objectarray_t *class_get_declaredmethods(classinfo *c, bool publicOn
 
        /* Create array of methods. */
 
-       oa = builtin_anewarray(count, class_java_lang_reflect_Method);
+       ObjectArray oa(count, class_java_lang_reflect_Method);
 
-       if (oa == NULL)
+       if (oa.is_null())
                return NULL;
 
        /* Get the methods and store them in the array. */
@@ -1899,12 +1898,12 @@ java_handle_objectarray_t *class_get_declaredmethods(classinfo *c, bool publicOn
 
                        /* Store object into array. */
 
-                       array_objectarray_element_set(oa, index, rm.get_handle());
+                       oa.set_element(index, rm.get_handle());
                        index++;
                }
        }
 
-       return oa;
+       return oa.get_handle();
 }
 #endif
 
@@ -2102,28 +2101,27 @@ java_handle_t* class_get_enclosingmethod(classinfo *c)
 
 *******************************************************************************/
 
-java_handle_objectarray_t *class_get_interfaces(classinfo *c)
+java_handle_objectarray_tclass_get_interfaces(classinfo *c)
 {
-       classinfo                 *ic;
-       java_handle_objectarray_t *oa;
-       u4                         i;
+       classinfo* ic;
+       int        i;
 
        if (!(c->state & CLASS_LINKED))
                if (!link_class(c))
                        return NULL;
 
-       oa = builtin_anewarray(c->interfacescount, class_java_lang_Class);
+       ClassArray interfaces(c->interfacescount);
 
-       if (oa == NULL)
+       if (interfaces.is_null())
                return NULL;
 
        for (i = 0; i < c->interfacescount; i++) {
                ic = c->interfaces[i];
 
-               LLNI_array_direct(oa, i) = (java_object_t *) ic;
+               interfaces.set_element(i, ic);
        }
 
-       return oa;
+       return interfaces.get_handle();
 }
 
 
@@ -2148,7 +2146,7 @@ java_handle_bytearray_t *class_get_annotations(classinfo *c)
 
        LLNI_classinfo_field_get(c, annotations, annotations);
 
-       return (java_handle_bytearray_t*)annotations;
+       return (java_handle_bytearray_t*) annotations;
 #else
        return NULL;
 #endif
@@ -2382,13 +2380,13 @@ void class_classref_or_classinfo_println(classref_or_classinfo c)
 #if !defined(NDEBUG)
 void class_showconstantpool (classinfo *c) 
 {
-       u4 i;
+       int i;
        void* e;
 
        printf ("---- dump of constant pool ----\n");
 
        for (i=0; i<c->cpcount; i++) {
-               printf ("#%d:  ", (int) i);
+               printf ("#%d:  ", i);
                
                e = c -> cpinfos [i];
                if (e) {