* renamed CACAO_TYPECHECK to ENABLE_VERIFIER
[cacao.git] / src / vm / linker.c
index b10bfd390ff035a2b8d5d2deb3d5cc3ef69a3d95..57679c4a6b53846732c2361d4cd97ee248aaebcc 100644 (file)
@@ -32,7 +32,7 @@
             Edwin Steiner
             Christian Thalinger
 
-   $Id: linker.c 3344 2005-10-04 21:54:28Z twisti $
+   $Id: linker.c 3803 2005-11-26 19:18:33Z twisti $
 
 */
 
@@ -112,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))
@@ -159,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;
 
@@ -442,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;
@@ -704,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;
@@ -836,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;
@@ -944,7 +964,7 @@ static arraydescriptor *link_array(classinfo *c)
                        break;
 
                default:
-                       *exceptionptr = new_classnotfoundexception(c->name);
+                       *exceptionptr = new_noclassdeffounderror(c->name);
                        return NULL;
                }