Had commented out a real stmt in xtaMarkSubs
[cacao.git] / loader.c
index 621d862658e62d5cc7e6b4431910335ea48cd149..016054bb82500aaa8fafbcfca66f2fa2a4b2f120 100644 (file)
--- a/loader.c
+++ b/loader.c
 #include "tables.h"
 #include "builtin.h"
 #include "jit.h"
-#ifdef OLD_COMPILER
-#include "compiler.h"
-#endif
 #include "asmpart.h"
 
-#ifdef USE_BOEHM
 #include "toolbox/memory.h"
-#endif
 
 #include "toolbox/loging.h"
 
@@ -41,9 +36,9 @@
 
 /* global variables ***********************************************************/
 
-extern bool newcompiler;        /* true if new compiler is used               */               
 bool opt_rt = false;            /* true if RTA parse should be used     RT-CO */
 bool opt_xta = false;           /* true if XTA parse should be used    XTA-CO */
+bool opt_vta = false;           /* true if VTA parse should be used    VTA-CO */
 
 int count_class_infos = 0;      /* variables for measurements                 */
 int count_const_pool_len = 0;
@@ -110,12 +105,12 @@ static classinfo *class_java_lang_ThreadDeath;
  ******************************************************************************/
  
 primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT] = { 
-               { NULL, NULL, "java/lang/Double",    'D', "double"  },
-               { NULL, NULL, "java/lang/Float",     'F', "float"   },
-               { NULL, NULL, "java/lang/Character", 'C', "char"    },
                { NULL, NULL, "java/lang/Integer",   'I', "int"     },
                { NULL, NULL, "java/lang/Long",      'J', "long"    },
+               { NULL, NULL, "java/lang/Float",     'F', "float"   },
+               { NULL, NULL, "java/lang/Double",    'D', "double"  },
                { NULL, NULL, "java/lang/Byte",      'B', "byte"    },
+               { NULL, NULL, "java/lang/Character", 'C', "char"    },
                { NULL, NULL, "java/lang/Short",     'S', "short"   },
                { NULL, NULL, "java/lang/Boolean",   'Z', "boolean" },
                { NULL, NULL, "java/lang/Void",      'V', "void"    }};
@@ -719,9 +714,8 @@ constant_arraydescriptor * buildarraydescriptor(char *utf_ptr, u4 namelen)
                d -> arraytype = ARRAYTYPE_OBJECT;
 
                d -> objectclass = class_new ( utf_new(utf_ptr+1, namelen-3) );
-                d -> objectclass  -> classUsed = 0; /* not used initially CO-RT */
+                d -> objectclass  -> classUsed = NOTUSED; /* not used initially CO-RT */
                d -> objectclass  -> impldBy = NULL;
-               d -> objectclass  -> nextimpldBy = NULL;
                break;
        }
        return d;
@@ -786,6 +780,7 @@ static void field_load (fieldinfo *f, classinfo *c)
        f -> descriptor = class_getconstant (c, suck_u2(), CONSTANT_Utf8); /* JavaVM descriptor           */
        f -> type = jtype = desc_to_type (f->descriptor);                  /* data type                   */
        f -> offset = 0;                                                   /* offset from start of object */
+       f->xta = NULL;
        
        switch (f->type) {
        case TYPE_INT:        f->value.i = 0; break;
@@ -927,9 +922,12 @@ static void method_load (methodinfo *m, classinfo *c)
        m -> entrypoint = NULL;
        m -> mcode = NULL;
        m -> stubroutine = NULL;
-        m -> methodUsed = 0;    
-       m -> XTAclasscount = 0; 
-        m -> numSubDefs = 0;    
+        m -> methodUsed = NOTUSED;    
+        m -> monoPoly = MONO;    
+       m -> subRedefs = 0;
+       m -> subRedefsUsed = 0;
+
+       m->xta = NULL;
        
        if (! (m->flags & ACC_NATIVE) ) {
                m -> stubroutine = createcompilerstub (m);
@@ -939,14 +937,7 @@ static void method_load (methodinfo *m, classinfo *c)
                functionptr f = native_findfunction 
                       (c->name, m->name, m->descriptor, (m->flags & ACC_STATIC) != 0);
                if (f) {
-#ifdef OLD_COMPILER
-               if (newcompiler)
-#endif
                        m -> stubroutine = createnativestub (f, m);
-#ifdef OLD_COMPILER
-               else
-                       m -> stubroutine = oldcreatenativestub (f, m);
-#endif
                        }
                }
        
@@ -1464,9 +1455,8 @@ static int class_load (classinfo *c)
 
        class_loadcpool (c);
        
-        c -> classUsed = 0; /* not used initially CO-RT */
+        c -> classUsed = NOTUSED; /* not used initially CO-RT */
        c -> impldBy = NULL;
-       c -> nextimpldBy = NULL;
 
        /* ACC flags */
        c -> flags = suck_u2 (); 
@@ -1491,11 +1481,7 @@ static int class_load (classinfo *c)
 
        /* load fields */
        c -> fieldscount = suck_u2 ();
-#ifdef USE_BOEHM
        c -> fields = GCNEW (fieldinfo, c -> fieldscount);
-#else
-       c -> fields = MNEW (fieldinfo, c -> fieldscount);
-#endif
        for (i=0; i < c -> fieldscount; i++) {
                field_load (&(c->fields[i]), c);
                }
@@ -1626,7 +1612,7 @@ static void class_addinterface (classinfo *c, classinfo *ic)
 
 *******************************************************************************/
 
-static void class_link (classinfo *c)
+void class_link (classinfo *c)
 {
        s4 supervftbllength;          /* vftbllegnth of super class               */
        s4 vftbllength;               /* vftbllength of current class             */
@@ -1655,9 +1641,8 @@ static void class_link (classinfo *c)
 
        if (super == NULL) {          /* class java.long.Object */
                c->index = 0;
-                c->classUsed = 1;     /* Object class is always used CO-RT*/
+        c->classUsed = USED;     /* Object class is always used CO-RT*/
                c -> impldBy = NULL;
-               c -> nextimpldBy = NULL;
                c->instancesize = sizeof(java_objectheader);
                
                vftbllength = supervftbllength = 0;
@@ -1885,9 +1870,6 @@ static void class_free (classinfo *c)
 
        for (i = 0; i < c->fieldscount; i++)
                field_free(&(c->fields[i]));
-#ifndef USE_BOEHM
-       MFREE (c->fields, fieldinfo, c->fieldscount);
-#endif
        
        for (i = 0; i < c->methodscount; i++)
                method_free(&(c->methods[i]));
@@ -2091,7 +2073,7 @@ void class_init (classinfo *c)
        if (c->super)
                class_init (c->super);
        for (i=0; i < c->interfacescount; i++)
-               class_init(c->interfaces[i]);  // real
+               class_init(c->interfaces[i]);  /* real */
 
        m = class_findmethod (c, utf_clinit, utf_fidesc);
        if (!m) {
@@ -2118,26 +2100,26 @@ void class_init (classinfo *c)
        blockInts = 0;
 #endif
 
-       exceptionptr = asm_calljavamethod (m, NULL,NULL,NULL,NULL);
+       exceptionptr = asm_calljavamethod(m, NULL, NULL, NULL, NULL);
 
 #ifdef USE_THREADS
        assert(blockInts == 0);
        blockInts = b;
 #endif
 
-       if (exceptionptr) {     
-               printf ("#### Initializer of ");
-               utf_display (c->name);
-               printf (" has thrown: ");
-               utf_display (exceptionptr->vftbl->class->name);
-               printf ("\n");
-               fflush (stdout);
-               }
+       if (exceptionptr) {
+               printf("#### Initializer of ");
+               utf_display(c->name);
+               printf(" has thrown: ");
+               utf_display(exceptionptr->vftbl->class->name);
+               printf("\n");
+               fflush(stdout);
+       }
 
        if (initverbose) {
-               sprintf (logtext, "Finished initializer for class: ");
-               utf_sprint (logtext+strlen(logtext), c->name);
-               dolog ();
+               sprintf(logtext, "Finished initializer for class: ");
+               utf_sprint(logtext+strlen(logtext), c->name);
+               dolog();
        }
 
        if (c->name == utf_systemclass) {
@@ -2189,7 +2171,6 @@ int find_class_method_constant (classinfo *c, utf * c1, utf* m1, utf* d1)
        voidptr e;
 
        for (i=0; i<c->cpcount; i++) {
-               //printf ("#%d:  ", (int) i);
                
                e = c -> cpinfos [i];
                if (e) {
@@ -2217,8 +2198,6 @@ int find_class_method_constant (classinfo *c, utf * c1, utf* m1, utf* d1)
                                                }
                                    }
                                        break;
-                               
-                               default: 
                                }
                                
                        }
@@ -2232,9 +2211,9 @@ void class_showconstanti(classinfo *c, int ii)
        u4 i = ii;
        voidptr e;
 
-printf ("#%d:  ", (int) i);
                
 e = c -> cpinfos [i];
+printf ("#%d:  ", (int) i);
 if (e) {
                        switch (c -> cptags [i]) {
                                case CONSTANT_Class:
@@ -2512,9 +2491,8 @@ void create_primitive_classes()
        for (i=0;i<PRIMITIVETYPE_COUNT;i++) {
                /* create primitive class */
                classinfo *c = class_new ( utf_new_char(primitivetype_table[i].name) );
-                c -> classUsed = 0; /* not used initially CO-RT */             
+                c -> classUsed = NOTUSED; /* not used initially CO-RT */               
                c -> impldBy = NULL;
-               c -> nextimpldBy = NULL;
 
                /* prevent loader from loading primitive class */
                list_remove (&unloadedclasses, c);
@@ -2528,9 +2506,8 @@ void create_primitive_classes()
                /* create class for wrapping the primitive type */
                primitivetype_table[i].class_wrap =
                        class_new( utf_new_char(primitivetype_table[i].wrapname) );
-                primitivetype_table[i].class_wrap -> classUsed = 0; /* not used initially CO-RT */
+                primitivetype_table[i].class_wrap -> classUsed = NOTUSED; /* not used initially CO-RT */
                primitivetype_table[i].class_wrap  -> impldBy = NULL;
-               primitivetype_table[i].class_wrap  -> nextimpldBy = NULL;
        }
 }
 
@@ -2582,18 +2559,16 @@ void loader_init ()
 
        /* create class for arrays */
        class_array = class_new ( utf_new_char ("The_Array_Class") );
-        class_array -> classUsed = 0; /* not used initially CO-RT */
+    class_array -> classUsed = NOTUSED; /* not used initially CO-RT */
        class_array -> impldBy = NULL;
-       class_array -> nextimpldBy = NULL;
 
        list_remove (&unloadedclasses, class_array);
 
        /* create class for strings, load it after class Object was loaded */
        string_class = utf_new_char ("java/lang/String");
        class_java_lang_String = class_new(string_class);
-        class_java_lang_String -> classUsed = 0; /* not used initially CO-RT */
+    class_java_lang_String -> classUsed = NOTUSED; /* not used initially CO-RT */
        class_java_lang_String -> impldBy = NULL;
-       class_java_lang_String -> nextimpldBy = NULL;
 
        list_remove (&unloadedclasses, class_java_lang_String);
 
@@ -2700,13 +2675,14 @@ static void loader_compute_class_values (classinfo *c)
        classinfo *subs;
 
        c->vftbl->baseval = ++classvalue;
+
        subs = c->sub;
        while (subs != NULL) {
                loader_compute_class_values(subs);
                subs = subs->nextsub;
                }
        c->vftbl->diffval = classvalue - c->vftbl->baseval;
-/*
+       /*
        {
        int i;
        for (i = 0; i < c->index; i++)
@@ -2715,7 +2691,7 @@ static void loader_compute_class_values (classinfo *c)
        utf_display(c->name);
        printf("\n");
        }
-*/
+       */
 }