* compile_all_class_methods: Removed.
[cacao.git] / src / vm / linker.c
index 8ecbe2f2fb1e28f06c3b04e0fc5a31504beccd0a..db8ae3f53de067e5b2e0e71978c9107b02869d14 100644 (file)
             Edwin Steiner
             Christian Thalinger
 
-   $Id: linker.c 2788 2005-06-22 16:08:51Z edwin $
+   $Id: linker.c 3685 2005-11-16 13:28:59Z twisti $
 
 */
 
 
 #include <assert.h>
 
+#include "config.h"
+#include "vm/types.h"
+
 #include "mm/memory.h"
 #include "native/native.h"
 #include "vm/builtin.h"
@@ -67,7 +70,7 @@ static s4 classvalue;
    primitive class.
  
    CAUTION: Don't change the order of the types. This table is indexed
-   by the ARRAYTYPE_ constants (expcept ARRAYTYPE_OBJECT).
+   by the ARRAYTYPE_ constants (except ARRAYTYPE_OBJECT).
 
 *******************************************************************************/
 
@@ -168,9 +171,15 @@ bool linker_init(void)
        if (!link_class(class_java_lang_System))
                return false;
 
+       if (!link_class(class_java_lang_Thread))
+               return false;
+
        if (!link_class(class_java_lang_ThreadGroup))
                return false;
 
+       if (!link_class(class_java_lang_VMThread))
+               return false;
+
 
        /* some classes which may be used more often */
 
@@ -214,14 +223,14 @@ bool linker_init(void)
                assert(0);
        }
 
-    if (!link_class(pseudo_class_Arraystub))
+       if (!link_class(pseudo_class_Arraystub))
                return false;
 
-    /* pseudo class representing the null type */
+       /* pseudo class representing the null type */
     
        pseudo_class_Null = class_create_classinfo(utf_new_char("$NULL$"));
        pseudo_class_Null->loaded = true;
-    pseudo_class_Null->super.cls = class_java_lang_Object;
+       pseudo_class_Null->super.cls = class_java_lang_Object;
 
        if (!classcache_store_unique(pseudo_class_Null)) {
                log_text("could not cache pseudo_class_Null");
@@ -231,7 +240,7 @@ bool linker_init(void)
        if (!link_class(pseudo_class_Null))
                return false;
 
-    /* pseudo class representing new uninitialized objects */
+       /* pseudo class representing new uninitialized objects */
     
        pseudo_class_New = class_create_classinfo(utf_new_char("$NEW$"));
        pseudo_class_New->loaded = true;
@@ -279,16 +288,17 @@ static bool link_primitivetype_table(void)
                /* create primitive class */
 
                c = class_create_classinfo(utf_new_char(primitivetype_table[i].name));
+
+               c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT;
                c->classUsed = NOTUSED; /* not used initially CO-RT */
                c->impldBy = NULL;
                
                /* prevent loader from loading primitive class */
 
                c->loaded = true;
-               if (!classcache_store_unique(c)) {
-                       log_text("Could not cache primitive class");
-                       return false;
-               }
+
+               /* INFO: don't put primitive classes into the classcache */
+
                if (!link_class(c))
                        return false;
 
@@ -432,6 +442,16 @@ static classinfo *link_class_intern(classinfo *c)
                throw_cacao_exception_exit(string_java_lang_InternalError,
                                                                   "Trying to link unloaded class");
 
+       /* cache the self-reference of this class                          */
+       /* we do this for cases where the defining loader of the class     */
+       /* has not yet been recorded as an initiating loader for the class */
+       /* this is needed so subsequent code can assume that self-refs     */
+       /* will always resolve lazily                                      */
+       /* No need to do it for the bootloader - it is always registered   */
+       /* as initiating loader for the classes it loads.                  */
+       if (c->classloader)
+               classcache_store(c->classloader,c,false);
+
        /* ok, this class is somewhat linked */
 
        c->linked = true;
@@ -718,21 +738,8 @@ static classinfo *link_class_intern(classinfo *c)
                /* Methods in ABSTRACT classes from interfaces maybe already have a   */
                /* stubroutine.                                                       */
 
-               if (!m->stubroutine) {
-                       if (!(m->flags & ACC_NATIVE)) {
-                               m->stubroutine = createcompilerstub(m);
-
-                       } else {
-                               functionptr f = NULL;
-
-#if defined(STATIC_CLASSPATH)
-                               f = native_findfunction(c->name, m->name, m->descriptor,
-                                                                               (m->flags & ACC_STATIC));
-                               if (f)
-#endif
-                                       m->stubroutine = codegen_createnativestub(f, m);
-                       }
-               }
+               if (!m->stubroutine)
+                       m->stubroutine = createcompilerstub(m);
 
                if (!(m->flags & ACC_STATIC))
                        v->table[m->vftblindex] = (methodptr) (ptrint) m->stubroutine;
@@ -798,12 +805,6 @@ static classinfo *link_class_intern(classinfo *c)
                                                                                           &(m->exceptiontable[j].catchtype.cls)))
                                return NULL;
                }
-
-               for (j = 0; j < m->thrownexceptionscount; j++)
-                       if (!resolve_classref_or_classinfo(NULL, m->thrownexceptions[j],
-                                                                                          resolveEager, true, false,
-                                                                                          &(m->thrownexceptions[j].cls)))
-                               return NULL;
        }
        
        /* final tasks */
@@ -845,14 +846,14 @@ static arraydescriptor *link_array(classinfo *c)
        switch (c->name->text[1]) {
        case '[':
                /* c is an array of arrays. */
-               u = utf_new_intern(c->name->text + 1, namelen - 1);
+               u = utf_new(c->name->text + 1, namelen - 1);
                if (!(comp = load_class_from_classloader(u, c->classloader)))
                        return NULL;
                break;
 
        case 'L':
                /* c is an array of objects. */
-               u = utf_new_intern(c->name->text + 2, namelen - 3);
+               u = utf_new(c->name->text + 2, namelen - 3);
                if (!(comp = load_class_from_classloader(u, c->classloader)))
                        return NULL;
                break;
@@ -953,8 +954,8 @@ static arraydescriptor *link_array(classinfo *c)
                        break;
 
                default:
-                       log_text("Invalid array class name");
-                       assert(0);
+                       *exceptionptr = new_noclassdeffounderror(c->name);
+                       return NULL;
                }
                
                desc->componentvftbl = NULL;