* ICMD_INLINE_START: -si display reformatted
[cacao.git] / src / vm / loader.c
index 01c349929dd4b7d137b5c7ac2b64e7534cde2702..1b0ce1614e93e82cdd33bae92aa95d9ed382055b 100644 (file)
@@ -32,7 +32,7 @@
             Edwin Steiner
             Christian Thalinger
 
-   $Id: loader.c 2571 2005-06-06 15:34:32Z twisti $
+   $Id: loader.c 2996 2005-07-12 01:42:38Z michi $
 
 */
 
@@ -136,76 +136,102 @@ bool loader_init(u1 *stackbottom)
 
        /* load some important classes */
 
-       if (!load_class_bootstrap(utf_java_lang_Object, &class_java_lang_Object))
+       if (!(class_java_lang_Object = load_class_bootstrap(utf_java_lang_Object)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_String, &class_java_lang_String))
+       if (!(class_java_lang_String = load_class_bootstrap(utf_java_lang_String)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_Cloneable, &class_java_lang_Cloneable))
+       if (!(class_java_lang_Cloneable =
+                 load_class_bootstrap(utf_java_lang_Cloneable)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_io_Serializable, &class_java_io_Serializable))
+       if (!(class_java_io_Serializable =
+                 load_class_bootstrap(utf_java_io_Serializable)))
                return false;
 
 
        /* load classes for wrapping primitive types */
 
-       if (!load_class_bootstrap(utf_java_lang_Void, &class_java_lang_Void))
+       if (!(class_java_lang_Void = load_class_bootstrap(utf_java_lang_Void)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_Boolean, &class_java_lang_Boolean))
+       if (!(class_java_lang_Boolean =
+                 load_class_bootstrap(utf_java_lang_Boolean)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_Byte, &class_java_lang_Byte))
+       if (!(class_java_lang_Byte = load_class_bootstrap(utf_java_lang_Byte)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_Character, &class_java_lang_Character))
+       if (!(class_java_lang_Character =
+                 load_class_bootstrap(utf_java_lang_Character)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_Short, &class_java_lang_Short))
+       if (!(class_java_lang_Short = load_class_bootstrap(utf_java_lang_Short)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_Integer, &class_java_lang_Integer))
+       if (!(class_java_lang_Integer =
+                 load_class_bootstrap(utf_java_lang_Integer)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_Long, &class_java_lang_Long))
+       if (!(class_java_lang_Long = load_class_bootstrap(utf_java_lang_Long)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_Float, &class_java_lang_Float))
+       if (!(class_java_lang_Float = load_class_bootstrap(utf_java_lang_Float)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_Double, &class_java_lang_Double))
+       if (!(class_java_lang_Double = load_class_bootstrap(utf_java_lang_Double)))
                return false;
 
 
        /* load some other important classes */
 
-       if (!load_class_bootstrap(utf_java_lang_Class, &class_java_lang_Class))
+       if (!(class_java_lang_Class = load_class_bootstrap(utf_java_lang_Class)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_ClassLoader, &class_java_lang_ClassLoader))
+       if (!(class_java_lang_ClassLoader =
+                 load_class_bootstrap(utf_java_lang_ClassLoader)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_SecurityManager, &class_java_lang_SecurityManager))
+       if (!(class_java_lang_SecurityManager =
+                 load_class_bootstrap(utf_java_lang_SecurityManager)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_System, &class_java_lang_System))
+       if (!(class_java_lang_System = load_class_bootstrap(utf_java_lang_System)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_ThreadGroup, &class_java_lang_ThreadGroup))
+       if (!(class_java_lang_ThreadGroup =
+                 load_class_bootstrap(utf_java_lang_ThreadGroup)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_util_Vector, &class_java_util_Vector))
+
+       /* some classes which may be used more often */
+
+       if (!(class_java_lang_StackTraceElement =
+                 load_class_bootstrap(utf_java_lang_StackTraceElement)))
+               return false;
+
+       if (!(class_java_lang_reflect_Constructor =
+                 load_class_bootstrap(utf_java_lang_reflect_Constructor)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_reflect_Constructor, &class_java_lang_reflect_Constructor))
+       if (!(class_java_lang_reflect_Field =
+                 load_class_bootstrap(utf_java_lang_reflect_Field)))
                return false;
 
-       if (!load_class_bootstrap(utf_java_lang_reflect_Method, &class_java_lang_reflect_Method))
+       if (!(class_java_lang_reflect_Method =
+                 load_class_bootstrap(utf_java_lang_reflect_Method)))
                return false;
 
-       if (!load_class_bootstrap(utf_new_char("[Ljava/lang/Object;"), &arrayclass_java_lang_Object))
+       if (!(class_java_security_PrivilegedAction =
+                 load_class_bootstrap(utf_new_char("java/security/PrivilegedAction"))))
+               return false;
+
+       if (!(class_java_util_Vector = load_class_bootstrap(utf_java_util_Vector)))
+               return false;
+
+       if (!(arrayclass_java_lang_Object =
+                 load_class_bootstrap(utf_new_char("[Ljava/lang/Object;"))))
                return false;
 
 #if defined(USE_THREADS)
@@ -505,7 +531,7 @@ void suck_init(char *classpath)
 void loader_load_all_classes(void)
 {
        classpath_info *cpi;
-       classinfo *c;
+       classinfo      *c;
 
        for (cpi = classpath_entries; cpi != 0; cpi = cpi->next) {
 #if defined(USE_ZLIB)
@@ -517,10 +543,11 @@ void loader_load_all_classes(void)
                        ce = s->cacao_dir_list;
                                
                        while (ce) {
-                               /* check for .properties files */
+                               /* skip all entries in META-INF and .properties files */
 
-                               if (!strstr(ce->name->text, ".properties"))
-                                       load_class_bootstrap(ce->name, &c);
+                               if (strncmp(ce->name->text, "META-INF", strlen("META-INF")) &&
+                                       !strstr(ce->name->text, ".properties"))
+                                       c = load_class_bootstrap(ce->name);
 
                                ce = ce->next;
                        }
@@ -654,9 +681,17 @@ classbuffer *suck_start(classinfo *c)
        }
 
        if (opt_verbose)
-               if (!found)
+               if (!found) {
                        dolog("Warning: Can not open class file '%s'", filename);
 
+                       if (strcmp(filename, "org/mortbay/util/MultiException.class") == 0) {
+                               static int i = 0;
+                               i++;
+                               if (i == 3)
+                                       assert(0);
+                       }
+               }
+
        MFREE(filename, char, filenamelen);
 
        return cb;
@@ -1088,6 +1123,18 @@ static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
                        return false;
 
                cptags[forward_classes->thisindex] = CONSTANT_Class;
+
+               if (opt_eager) {
+                       classinfo *tc;
+
+                       if (!(tc = load_class_bootstrap(name)))
+                               return false;
+
+                       /* link the class later, because we cannot link the class currently
+                          loading */
+                       list_addfirst(&unlinkedclasses, tc);
+               }
+
                /* the classref is created later */
                cpinfos[forward_classes->thisindex] = name;
 
@@ -1806,28 +1853,25 @@ static bool load_attributes(classbuffer *cb, u4 num)
        return true;
 }
 
+
 /* load_class_from_sysloader ***************************************************
 
    Load the class with the given name using the system class loader
 
    IN:
        name.............the classname
-          
-
-   OUT:
-       *result..........set to the loaded class
 
    RETURN VALUE:
-       true.............everything ok
-          false............an exception has been thrown
+       the loaded class, or
+          NULL if an exception has been thrown
 
 *******************************************************************************/
 
-bool load_class_from_sysloader(utf *name,classinfo **result)
+classinfo *load_class_from_sysloader(utf *name)
 {
-       methodinfo *m;
+       methodinfo        *m;
        java_objectheader *cl;
-       bool success;
+       classinfo         *r;
 
 #ifdef LOADER_VERBOSE
        char logtext[MAXLOGTEXT];
@@ -1842,22 +1886,23 @@ bool load_class_from_sysloader(utf *name,classinfo **result)
        LOADER_ASSERT(class_java_lang_ClassLoader->linked);
        
        m = class_resolveclassmethod(class_java_lang_ClassLoader,
-                                                                utf_new_char("getSystemClassLoader"), /* XXX use variable */
-                                                                utf_new_char("()Ljava/lang/ClassLoader;"), /* XXX use variable */
+                                                                utf_getSystemClassLoader,
+                                                                utf_void__java_lang_ClassLoader,
                                                                 class_java_lang_Object,
                                                                 false);
 
        if (!m)
-               return false; /* exception */
+               return false;
 
        cl = (java_objectheader *) asm_calljavafunction(m, NULL, NULL, NULL, NULL);
        if (!cl)
-               return false; /* exception */
+               return false;
 
        LOADER_INC();
-       success = load_class_from_classloader(name,cl,result);
+       r = load_class_from_classloader(name, cl);
        LOADER_DEC();
-       return success;
+
+       return r;
 }
 
 /* load_class_from_classloader *************************************************
@@ -1868,20 +1913,15 @@ bool load_class_from_sysloader(utf *name,classinfo **result)
        name.............the classname
           cl...............user-defined class loader
           
-
-   OUT:
-       *result..........set to the loaded class
-
    RETURN VALUE:
-       true.............everything ok
-          false............an exception has been thrown
+       the loaded class, or
+          NULL if an exception has been thrown
 
 *******************************************************************************/
 
-bool load_class_from_classloader(utf *name,java_objectheader *cl,classinfo **result)
+classinfo *load_class_from_classloader(utf *name, java_objectheader *cl)
 {
        classinfo *r;
-       bool success;
 
 #ifdef LOADER_VERBOSE
        char logtext[MAXLOGTEXT];
@@ -1896,17 +1936,18 @@ bool load_class_from_classloader(utf *name,java_objectheader *cl,classinfo **res
 #endif
 
        LOADER_ASSERT(name);
-       LOADER_ASSERT(result);
 
        /* lookup if this class has already been loaded */
-       *result = classcache_lookup(cl,name);
+
+       r = classcache_lookup(cl, name);
+
 #ifdef LOADER_VERBOSE
-       if (*result)
-               dolog("        cached -> %p",(void*)(*result));
+       if (r)
+               dolog("        cached -> %p",(void*)r);
 #endif
 
-       if (*result)
-               return true;
+       if (r)
+               return r;
 
        /* if other class loader than bootstrap, call it */
 
@@ -1915,32 +1956,38 @@ bool load_class_from_classloader(utf *name,java_objectheader *cl,classinfo **res
 
                /* handle array classes */
                if (name->text[0] == '[') {
-                       char *utf_ptr = name->text + 1;
-                       int len = name->blength - 1;
+                       char      *utf_ptr;
+                       s4         len;
                        classinfo *comp;
+                       utf       *u;
+
+                       utf_ptr = name->text + 1;
+                       len = name->blength - 1;
+
                        switch (*utf_ptr) {
-                               case 'L':
-                                       utf_ptr++;
-                                       len -= 2;
-                                       /* FALLTHROUGH */
-                               case '[':
-                                       /* load the component class */
-                                       LOADER_INC();
-                                       if (!load_class_from_classloader(utf_new(utf_ptr,len),cl,&comp)) {
-                                               LOADER_DEC();
-                                               return false;
-                                       }
-                                       LOADER_DEC();
-                                       /* create the array class */
-                                       *result = class_array_of(comp,false);
-                                       return (*result != 0);
-                                       break;
-                               default:
-                                       /* primitive array classes are loaded by the bootstrap loader */
-                                       LOADER_INC();
-                                       success = load_class_bootstrap(name,result);
+                       case 'L':
+                               utf_ptr++;
+                               len -= 2;
+                               /* FALLTHROUGH */
+                       case '[':
+                               /* load the component class */
+                               u = utf_new(utf_ptr, len);
+                               LOADER_INC();
+                               if (!(comp = load_class_from_classloader(u, cl))) {
                                        LOADER_DEC();
-                                       return success;
+                                       return false;
+                               }
+                               LOADER_DEC();
+                               /* create the array class */
+                               r = class_array_of(comp, false);
+                               return r;
+                               break;
+                       default:
+                               /* primitive array classes are loaded by the bootstrap loader */
+                               LOADER_INC();
+                               r = load_class_bootstrap(name);
+                               LOADER_DEC();
+                               return r;
                        }
                }
                
@@ -1962,21 +2009,30 @@ bool load_class_from_classloader(utf *name,java_objectheader *cl,classinfo **res
                                                                                           NULL, NULL);
                LOADER_DEC();
 
-               /* store this class in the loaded class cache */
-               if (r && !classcache_store(cl,r)) {
-                       r->loaded = false;
-                       class_free(r);
-                       r = NULL; /* exception */
+               if (r) {
+                       /* store this class in the loaded class cache */
+                       /* If another class with the same (initloader,name) pair has been */
+                       /* stored earlier it will be returned by classcache_store         */
+                       /* In this case classcache_store may not free the class because it*/
+                       /* has already been exposed to Java code which may have kept      */
+                       /* references to that class.                                      */
+                   classinfo *c = classcache_store(cl,r,false);
+                       if (c == NULL) {
+                               /* exception, free the loaded class */
+                               r->loaded = false;
+                               class_free(r);
+                       }
+                       r = c;
                }
 
-               *result = r;
-               return (r != NULL);
+               return r;
        } 
 
        LOADER_INC();
-       success = load_class_bootstrap(name,result);
+       r = load_class_bootstrap(name);
        LOADER_DEC();
-       return success;
+
+       return r;
 }
 
 
@@ -1987,12 +2043,9 @@ bool load_class_from_classloader(utf *name,java_objectheader *cl,classinfo **res
    IN:
        name.............the classname
 
-   OUT:
-       *result..........set to the loaded class
-
    RETURN VALUE:
-       true.............everything ok
-          false............an exception has been thrown
+       loaded classinfo, or
+          NULL if an exception has been thrown
 
    SYNCHRONIZATION:
        load_class_bootstrap is synchronized. It can be treated as an
@@ -2000,31 +2053,23 @@ bool load_class_from_classloader(utf *name,java_objectheader *cl,classinfo **res
 
 *******************************************************************************/
 
-bool load_class_bootstrap(utf *name, classinfo **result)
+classinfo *load_class_bootstrap(utf *name)
 {
        classbuffer *cb;
-       classinfo *c;
-       classinfo *r;
+       classinfo   *c;
+       classinfo   *r;
 #ifdef LOADER_VERBOSE
        char logtext[MAXLOGTEXT];
 #endif
 
        /* for debugging */
+
        LOADER_ASSERT(name);
-       LOADER_ASSERT(result);
        LOADER_INC();
 
-       /* synchronize */
-       LOADER_LOCK();
-
        /* lookup if this class has already been loaded */
-       *result = classcache_lookup(NULL, name);
-       if (*result)
-               goto success;
 
-       /* check if this class has already been defined */
-       *result = classcache_lookup_defined(NULL, name);
-       if (*result)
+       if ((r = classcache_lookup(NULL, name)))
                goto success;
 
 #ifdef LOADER_VERBOSE
@@ -2035,19 +2080,23 @@ bool load_class_bootstrap(utf *name, classinfo **result)
 #endif
 
        /* create the classinfo */
+
        c = class_create_classinfo(name);
        
        /* handle array classes */
+
        if (name->text[0] == '[') {
-               if (!load_newly_created_array(c, NULL))
+               c = load_newly_created_array(c, NULL);
+               if (c == NULL)
                        goto return_exception;
                LOADER_ASSERT(c->loaded);
-               *result = c;
+               r = c;
                goto success;
        }
 
 #if defined(STATISTICS)
        /* measure time */
+
        if (getcompilingtime)
                compilingtime_stop();
 
@@ -2058,7 +2107,8 @@ bool load_class_bootstrap(utf *name, classinfo **result)
        /* load classdata, throw exception on error */
 
        if ((cb = suck_start(c)) == NULL) {
-               /* this means, the classpath was not set properly */
+               /* this normally means, the classpath was not set properly */
+
                if (name == utf_java_lang_Object)
                        throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
                                                                           "java/lang/Object");
@@ -2070,13 +2120,16 @@ bool load_class_bootstrap(utf *name, classinfo **result)
        }
        
        /* load the class from the buffer */
+
        r = load_class_from_classbuffer(cb);
 
        /* free memory */
+
        suck_stop(cb);
 
 #if defined(STATISTICS)
        /* measure time */
+
        if (getloadingtime)
                loadingtime_stop();
 
@@ -2086,31 +2139,34 @@ bool load_class_bootstrap(utf *name, classinfo **result)
 
        if (!r) {
                /* the class could not be loaded, free the classinfo struct */
-               class_free(c);
-       }
 
-       /* store this class in the loaded class cache    */
-       /* this step also checks the loading constraints */
-       if (r && !classcache_store(NULL, c)) {
                class_free(c);
-               r = NULL; /* exception */
+       }
+       else {
+               /* store this class in the loaded class cache    */
+               /* this step also checks the loading constraints */
+               /* If the class has been loaded before, the      */
+               /* earlier loaded class is returned.             */
+               classinfo *res = classcache_store(NULL,c,true);
+               if (!res) {
+                       /* exception */
+                       class_free(c);
+               }
+               r = res;
        }
 
        if (!r)
                goto return_exception;
 
-       *result = r;
-
 success:
-       LOADER_UNLOCK();
        LOADER_DEC();
-       return true;
+
+       return r;
 
 return_exception:
-       *result = NULL;
-       LOADER_UNLOCK();
        LOADER_DEC();
-       return false;
+
+       return NULL;
 }
 
 
@@ -2438,7 +2494,7 @@ classinfo *load_class_from_classbuffer(classbuffer *cb)
                methodinfo *m = &c->methods[i];
                m->parseddesc =
                        descriptor_pool_parse_method_descriptor(descpool, m->descriptor,
-                                                                                                       m->flags);
+                                                                                                       m->flags, class_get_self_classref(m->class));
                if (!m->parseddesc)
                        goto return_exception;
 
@@ -2484,18 +2540,19 @@ classinfo *load_class_from_classbuffer(classbuffer *cb)
                case CONSTANT_Methodref:
                case CONSTANT_InterfaceMethodref:
                        fmi = (constant_FMIref *) c->cpinfos[i];
-                       fmi->parseddesc.md =
-                               descriptor_pool_parse_method_descriptor(descpool,
-                                                                                                               fmi->descriptor,
-                                                                                                               ACC_UNDEF);
-                       if (!fmi->parseddesc.md)
-                               goto return_exception;
                        index = (int) (size_t) fmi->classref;
                        fmi->classref =
                                (constant_classref *) class_getconstant(c, index,
                                                                                                                CONSTANT_Class);
                        if (!fmi->classref)
                                goto return_exception;
+                       fmi->parseddesc.md =
+                               descriptor_pool_parse_method_descriptor(descpool,
+                                                                                                               fmi->descriptor,
+                                                                                                               ACC_UNDEF,
+                                                                                                               fmi->classref);
+                       if (!fmi->parseddesc.md)
+                               goto return_exception;
                        break;
                }
        }
@@ -2650,10 +2707,15 @@ return_exception:
 }
 
 
-
 /* load_newly_created_array ****************************************************
 
-    Load a newly created array class.
+   Load a newly created array class.
+
+       RETURN VALUE:
+           c....................the array class C has been loaded
+               other classinfo......the array class was found in the class cache, 
+                                    C has been freed
+           NULL.................an exception has been thrown
 
        Note:
                This is an internal function. Do not use it unless you know exactly
@@ -2663,14 +2725,15 @@ return_exception:
 
 *******************************************************************************/
 
-bool load_newly_created_array(classinfo *c,java_objectheader *loader)
+classinfo * load_newly_created_array(classinfo *c,java_objectheader *loader)
 {
-       classinfo *comp = NULL;
-       methodinfo *clone;
-       methoddesc *clonedesc;
+       classinfo         *comp = NULL;
+       methodinfo        *clone;
+       methoddesc        *clonedesc;
        constant_classref *classrefs;
-       int namelen;
+       s4                 namelen;
        java_objectheader *definingloader = NULL;
+       utf               *u;
 
 #ifdef LOADER_VERBOSE
        char logtext[MAXLOGTEXT];
@@ -2681,30 +2744,30 @@ bool load_newly_created_array(classinfo *c,java_objectheader *loader)
 #endif
 
        /* Check array class name */
+
        namelen = c->name->blength;
        if (namelen < 2 || c->name->text[0] != '[') {
                *exceptionptr = new_internalerror("Invalid array class name");
-               return false;
+               return NULL;
        }
 
        /* Check the component type */
+
        switch (c->name->text[1]) {
        case '[':
                /* c is an array of arrays. We have to create the component class. */
+
+               u = utf_new_intern(c->name->text + 1, namelen - 1);
                LOADER_INC();
-               if (!load_class_from_classloader(utf_new_intern(c->name->text + 1,
-                                                                                                               namelen - 1),
-                                                                                loader,
-                                                                                &comp)) 
-               {
+               if (!(comp = load_class_from_classloader(u, loader))) {
                        LOADER_DEC();
-                       return false;
+                       return NULL;
                }
                LOADER_DEC();
                LOADER_ASSERT(comp->loaded);
                if (opt_eager)
                        if (!link_class(c))
-                               return false;
+                               return NULL;
                definingloader = comp->classloader;
                break;
 
@@ -2712,23 +2775,21 @@ bool load_newly_created_array(classinfo *c,java_objectheader *loader)
                /* c is an array of objects. */
                if (namelen < 4 || c->name->text[namelen - 1] != ';') {
                        *exceptionptr = new_internalerror("Invalid array class name");
-                       return false;
+                       return NULL;
                }
 
+               u = utf_new_intern(c->name->text + 2, namelen - 3);
+
                LOADER_INC();
-               if (!load_class_from_classloader(utf_new_intern(c->name->text + 2,
-                                                                                                               namelen - 3),
-                                                                                loader,
-                                                                                &comp)) 
-               {
+               if (!(comp = load_class_from_classloader(u, loader))) {
                        LOADER_DEC();
-                       return false;
+                       return NULL;
                }
                LOADER_DEC();
                LOADER_ASSERT(comp->loaded);
                if (opt_eager)
                        if (!link_class(c))
-                               return false;
+                               return NULL;
                definingloader = comp->classloader;
                break;
        }
@@ -2738,6 +2799,7 @@ bool load_newly_created_array(classinfo *c,java_objectheader *loader)
        LOADER_ASSERT(class_java_io_Serializable);
 
        /* Setup the array class */
+
        c->super.cls = class_java_lang_Object;
        c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT;
 
@@ -2765,15 +2827,19 @@ bool load_newly_created_array(classinfo *c,java_objectheader *loader)
        c->methodscount = 1;
        c->methods = MNEW(methodinfo, c->methodscount);
 
-       classrefs = MNEW(constant_classref, 1);
-       CLASSREF_INIT(classrefs[0], c, utf_java_lang_Object);
+       classrefs = MNEW(constant_classref, 2);
+       CLASSREF_INIT(classrefs[0], c, c->name);
+       CLASSREF_INIT(classrefs[1], c, utf_java_lang_Object);
 
+       /* create descriptor for clone method */
+       /* we need one paramslot which is reserved for the 'this' parameter */
        clonedesc = NEW(methoddesc);
        clonedesc->returntype.type = TYPE_ADDRESS;
-       clonedesc->returntype.classref = classrefs;
+       clonedesc->returntype.classref = classrefs + 1;
        clonedesc->returntype.arraydim = 0;
        clonedesc->paramcount = 0;
        clonedesc->paramslots = 0;
+       clonedesc->paramtypes[0].classref = classrefs + 0;
 
        /* parse the descriptor to get the register allocation */
 
@@ -2788,12 +2854,13 @@ bool load_newly_created_array(classinfo *c,java_objectheader *loader)
        clone->parseddesc = clonedesc;
        clone->class = c;
        clone->stubroutine =
-               createnativestub((functionptr) &builtin_clone_array, clone);
+               codegen_createnativestub((functionptr) &builtin_clone_array, clone);
        clone->monoPoly = MONO;
 
        /* XXX: field: length? */
 
        /* array classes are not loaded from class files */
+
        c->loaded = true;
        c->parseddescs = (u1*) clonedesc;
        c->parseddescsize = sizeof(methodinfo);
@@ -2802,10 +2869,8 @@ bool load_newly_created_array(classinfo *c,java_objectheader *loader)
        c->classloader = definingloader;
 
        /* insert class into the loaded class cache */
-       if (!classcache_store(loader,c))
-               return false;
-
-       return true;
+       /* XXX free classinfo if NULL returned? */
+       return classcache_store(loader,c,true);
 }
 
 
@@ -2919,7 +2984,7 @@ fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc,
 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc)
 {
        methodinfo *m;
-       s4 i;
+       s4          i;
 
        for (i = 0; i < c->methodscount; i++) {
                m = &(c->methods[i]);
@@ -2981,8 +3046,8 @@ methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc)
                                char *desc_utf_ptr = desc->text;      
                                char *meth_utf_ptr = meth_descr->text;                                    
                                /* points behind utf strings */
-                               char *desc_end = utf_end(desc);         
-                               char *meth_end = utf_end(meth_descr);   
+                               char *desc_end = UTF_END(desc);         
+                               char *meth_end = UTF_END(meth_descr);   
                                char ch;
 
                                /* compare argument types */
@@ -2992,7 +3057,7 @@ methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc)
                                                break; /* no match */
 
                                        if (ch == ')')
-                                               return &(c->methods[i]);   /* all parameter types equal */
+                                               return &(c->methods[i]); /* all parameter types equal */
                                }
                        }
                }
@@ -3057,7 +3122,7 @@ static methodinfo *class_resolveinterfacemethod_intern(classinfo *c,
                                                                                                           utf *name, utf *desc)
 {
        methodinfo *m;
-       s4 i;
+       s4          i;
        
        m = class_findmethod(c, name, desc);
 
@@ -3067,7 +3132,8 @@ static methodinfo *class_resolveinterfacemethod_intern(classinfo *c,
        /* try the superinterfaces */
 
        for (i = 0; i < c->interfacescount; i++) {
-               m = class_resolveinterfacemethod_intern(c->interfaces[i].cls, name, desc);
+               m = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
+                                                                                               name, desc);
 
                if (m)
                        return m;
@@ -3108,7 +3174,7 @@ methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *desc,
                return mi;
 
        /* try class java.lang.Object */
-       LOADER_ASSERT(class_java_lang_Object);
+
        mi = class_findmethod(class_java_lang_Object, name, desc);
 
        if (mi)
@@ -3124,11 +3190,11 @@ methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *desc,
 
 /* class_resolveclassmethod ****************************************************
        
-    Resolves a reference from REFERER to a method with NAME and DESC in
-    class C.
+   Resolves a reference from REFERER to a method with NAME and DESC in
+   class C.
 
-    If the method cannot be resolved the return value is NULL. If EXCEPT is
-    true *exceptionptr is set, too.
+   If the method cannot be resolved the return value is NULL. If
+   EXCEPT is true *exceptionptr is set, too.
 
 *******************************************************************************/
 
@@ -3167,7 +3233,8 @@ methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *desc,
        /* try the superinterfaces */
 
        for (i = 0; i < c->interfacescount; i++) {
-               mi = class_resolveinterfacemethod_intern(c->interfaces[i].cls, name, desc);
+               mi = class_resolveinterfacemethod_intern(c->interfaces[i].cls,
+                                                                                                name, desc);
 
                if (mi)
                        goto found;