* renamed CACAO_TYPECHECK to ENABLE_VERIFIER
[cacao.git] / src / vm / linker.c
index e080a679e051b2757c2f09b7f58631713c85b067..57679c4a6b53846732c2361d4cd97ee248aaebcc 100644 (file)
             Edwin Steiner
             Christian Thalinger
 
-   $Id: linker.c 3292 2005-09-28 10:36:34Z twisti $
+   $Id: linker.c 3803 2005-11-26 19:18:33Z twisti $
 
 */
 
 
 #include <assert.h>
 
+#include "config.h"
+#include "vm/types.h"
+
 #include "mm/memory.h"
 #include "native/native.h"
 #include "vm/builtin.h"
@@ -109,6 +112,19 @@ bool linker_init(void)
 
        interfaceindex = 0;
 
+       /* link java.lang.Class as first class of the system, because we
+       need it's vftbl for all other classes so we can use a class as
+       object */
+
+       if (!link_class(class_java_lang_Class))
+               return false;
+
+       /* now set the header.vftbl of all classes which were created
+       before java.lang.Class was linked */
+
+       class_postset_header_vftbl();
+
+
        /* link important system classes */
 
        if (!link_class(class_java_lang_Object))
@@ -156,9 +172,6 @@ bool linker_init(void)
 
        /* load some other important classes */
 
-       if (!link_class(class_java_lang_Class))
-               return false;
-
        if (!link_class(class_java_lang_ClassLoader))
                return false;
 
@@ -439,6 +452,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;
@@ -701,7 +724,7 @@ static classinfo *link_class_intern(classinfo *c)
                                                          sizeof(methodptr*) * (interfacetablelength - (interfacetablelength > 0)));
        v = (vftbl_t *) (((methodptr *) v) +
                                         (interfacetablelength - 1) * (interfacetablelength > 1));
-       c->header.vftbl = c->vftbl = v;
+       c->vftbl = v;
        v->class = c;
        v->vftbllength = vftbllength;
        v->interfacetablelength = interfacetablelength;
@@ -792,12 +815,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 */
@@ -839,14 +856,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;
@@ -947,7 +964,7 @@ static arraydescriptor *link_array(classinfo *c)
                        break;
 
                default:
-                       *exceptionptr = new_classnotfoundexception(c->name);
+                       *exceptionptr = new_noclassdeffounderror(c->name);
                        return NULL;
                }