framework for handbook added
[cacao.git] / loader.c
index ff4e40fa83103af40434c38b9b60ab921f486cd2..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"
 
+#include "toolbox/memory.h"
+
+#include "toolbox/loging.h"
+
 #include "threads/thread.h"
 #include <sys/stat.h>
 
 /* 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;
@@ -43,6 +46,8 @@ int count_vftbl_len = 0;
 int count_all_methods = 0;
 int count_vmcode_len = 0;
 int count_extable_len = 0;
+int count_class_loads = 0;
+int count_class_inits = 0;
 
 bool loadverbose = false;       /* switches for debug messages                */
 bool linkverbose = false;
@@ -76,16 +81,20 @@ static utf *utf_systemclass;                /* java/lang/System        */
 
 classinfo *class_java_lang_Object;
 classinfo *class_java_lang_String;
-classinfo *class_java_lang_ClassCastException;
-classinfo *class_java_lang_NullPointerException;
-classinfo *class_java_lang_ArrayIndexOutOfBoundsException;
-classinfo *class_java_lang_NegativeArraySizeException;
-classinfo *class_java_lang_OutOfMemoryError;
-classinfo *class_java_lang_ArithmeticException;
-classinfo *class_java_lang_ArrayStoreException;
-classinfo *class_java_lang_ThreadDeath;
 classinfo *class_array = NULL;
 
+/* stefan */
+/* These are made static so they cannot be used for throwing in native */
+/* functions.                                                          */
+static classinfo *class_java_lang_ClassCastException;
+static classinfo *class_java_lang_NullPointerException;
+static classinfo *class_java_lang_ArrayIndexOutOfBoundsException;
+static classinfo *class_java_lang_NegativeArraySizeException;
+static classinfo *class_java_lang_OutOfMemoryError;
+static classinfo *class_java_lang_ArithmeticException;
+static classinfo *class_java_lang_ArrayStoreException;
+static classinfo *class_java_lang_ThreadDeath;
+
 
 /******************************************************************************
 
@@ -96,12 +105,12 @@ classinfo *class_array = NULL;
  ******************************************************************************/
  
 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"    }};
@@ -140,13 +149,24 @@ static int classbuffer_size;        /* size of classfile-data                 */
 
 #define skip_nbytes(len) classbuf_pos+=len;
 
-#define suck_u1() (*++classbuf_pos)
+inline u1 suck_u1()
+{
+       return *++classbuf_pos;
+}
+inline u2 suck_u2()
+{
+       u1 a=suck_u1(), b=suck_u1();
+       return ((u2)a<<8)+(u2)b;
+}
+inline u4 suck_u4()
+{
+       u1 a=suck_u1(), b=suck_u1(), c=suck_u1(), d=suck_u1();
+       return ((u4)a<<24)+((u4)b<<16)+((u4)c<<8)+(u4)d;
+}
 #define suck_s8() (s8) suck_u8()
 #define suck_s2() (s2) suck_u2()
 #define suck_s4() (s4) suck_u4()
 #define suck_s1() (s1) suck_u1()
-#define suck_u2() (u2) ((suck_u1()<<8)+suck_u1())
-#define suck_u4() (u4) ((((u4)suck_u1())<<24)+(((u4)suck_u1())<<16)+(((u4)suck_u1())<<8)+((u4)suck_u1()))
 
 
 /* get u8 from classfile data */
@@ -294,8 +314,10 @@ bool suck_start (utf *classname) {
                }
        }
 
-       sprintf (logtext,"Warning: Can not open class file '%s'", filename);
-       dolog();
+       if (verbose) {
+               sprintf (logtext, "Warning: Can not open class file '%s'", filename);
+               dolog();
+       }
 
        return false;
 }
@@ -329,13 +351,28 @@ void suck_stop () {
 }
 
 /******************************************************************************/
-/******************* Einige Support-Funkionen *********************************/
+/******************* Some support functions ***********************************/
 /******************************************************************************/
 
 
-/********** interne Funktion: printflags  (nur zu Debug-Zwecken) **************/
 
-static void printflags (u2 f)
+void fprintflags (FILE *fp, u2 f)
+{
+   if ( f & ACC_PUBLIC )       fprintf (fp," PUBLIC");
+   if ( f & ACC_PRIVATE )      fprintf (fp," PRIVATE");
+   if ( f & ACC_PROTECTED )    fprintf (fp," PROTECTED");
+   if ( f & ACC_STATIC )       fprintf (fp," STATIC");
+   if ( f & ACC_FINAL )        fprintf (fp," FINAL");
+   if ( f & ACC_SYNCHRONIZED ) fprintf (fp," SYNCHRONIZED");
+   if ( f & ACC_VOLATILE )     fprintf (fp," VOLATILE");
+   if ( f & ACC_TRANSIENT )    fprintf (fp," TRANSIENT");
+   if ( f & ACC_NATIVE )       fprintf (fp," NATIVE");
+   if ( f & ACC_INTERFACE )    fprintf (fp," INTERFACE");
+   if ( f & ACC_ABSTRACT )     fprintf (fp," ABSTRACT");
+}
+
+/********** internal function: printflags  (only for debugging) ***************/
+void printflags (u2 f)
 {
    if ( f & ACC_PUBLIC )       printf (" PUBLIC");
    if ( f & ACC_PRIVATE )      printf (" PRIVATE");
@@ -351,9 +388,9 @@ static void printflags (u2 f)
 }
 
 
-/************************* Funktion: skipattribute *****************************
+/************************* Function: skipattribute *****************************
 
-       "uberliest im ClassFile eine (1) 'attribute'-Struktur 
+       skips a (1) 'attribute' structure in the class file
 
 *******************************************************************************/
 
@@ -363,10 +400,10 @@ static void skipattribute ()
        skip_nbytes(suck_u4()); 
 }
 
-/********************** Funktion: skipattributebody ****************************
+/********************** Function: skipattributebody ****************************
 
-       "uberliest im Classfile ein attribut, wobei die 16-bit - attribute_name - 
-       Referenz schon gelesen worden ist.
+       skips an attribute after the 16 bit reference to attribute_name has already
+       been read
        
 *******************************************************************************/
 
@@ -375,9 +412,9 @@ static void skipattributebody ()
        skip_nbytes(suck_u4());
 }
 
-/************************* Funktion: skipattributes ****************************
+/************************* Function: skipattributes ****************************
 
-       "uberliest im ClassFile eine gew"unschte Anzahl von attribute-Strukturen
+       skips num attribute structures
        
 *******************************************************************************/
 
@@ -637,10 +674,10 @@ static void checkmethoddescriptor (utf *d)
 }
 
 
-/******************** Funktion: buildarraydescriptor ***************************
+/******************** Function: buildarraydescriptor ***************************
 
-       erzeugt zu einem namentlich als utf-String vorliegenden Arraytyp eine
-       entsprechende constant_arraydescriptor - Struktur 
+       creates a constant_arraydescriptor structure for the array type named by an
+       utf string
        
 *******************************************************************************/
 
@@ -675,17 +712,19 @@ constant_arraydescriptor * buildarraydescriptor(char *utf_ptr, u4 namelen)
                
        case 'L':
                d -> arraytype = ARRAYTYPE_OBJECT;
+
                d -> objectclass = class_new ( utf_new(utf_ptr+1, namelen-3) );
+                d -> objectclass  -> classUsed = NOTUSED; /* not used initially CO-RT */
+               d -> objectclass  -> impldBy = NULL;
                break;
        }
        return d;
 }
 
 
-/******************* Funktion: freearraydescriptor *****************************
+/******************* Function: freearraydescriptor *****************************
 
-       entfernt eine mit buildarraydescriptor erzeugte Struktur wieder 
-       aus dem Speicher
+       removes a structure created by buildarraydescriptor from memory
        
 *******************************************************************************/
 
@@ -698,7 +737,7 @@ static void freearraydescriptor (constant_arraydescriptor *d)
                }
 }
 
-/*********************** Funktion: displayarraydescriptor *********************/
+/*********************** Function: displayarraydescriptor *********************/
 
 static void displayarraydescriptor (constant_arraydescriptor *d)
 {
@@ -719,16 +758,15 @@ static void displayarraydescriptor (constant_arraydescriptor *d)
 
 
 /******************************************************************************/
-/******************** Funktionen fuer Fields **********************************/
+/**************************  Functions for fields  ****************************/
 /******************************************************************************/
 
 
-/************************ Funktion: field_load *********************************
+/************************ Function: field_load *********************************
 
-       l"adt alle Informationen f"ur eine Feld einer Methode aus dem ClassFile,
-       und f"ullt mit diesen Infos eine schon existierende 'fieldinfo'-Struktur.
-       Bei 'static'-Fields wird auch noch ein Platz auf dem Datensegment
-       reserviert.
+       Load everything about a class field from the class file and fill a
+       'fieldinfo' structure. For static fields, space in the data segment is
+       allocated.
 
 *******************************************************************************/
 
@@ -742,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;
@@ -836,9 +875,9 @@ static void field_free (fieldinfo *f)
 }
 
 
-/************** Funktion: field_display (nur zu Debug-Zwecken) ****************/
+/**************** Function: field_display (debugging only) ********************/
 
-static void field_display (fieldinfo *f)
+void field_display (fieldinfo *f)
 {
        printf ("   ");
        printflags (f -> flags);
@@ -851,17 +890,16 @@ static void field_display (fieldinfo *f)
 
 
 /******************************************************************************/
-/************************* Funktionen f"ur Methods ****************************/ 
+/************************* Functions for methods ******************************/ 
 /******************************************************************************/
 
 
-/*********************** Funktion: method_load *********************************
+/*********************** Function: method_load *********************************
 
-       l"adt die Infos f"ur eine Methode aus dem ClassFile und f"ullt damit 
-       eine schon existierende 'methodinfo'-Struktur aus.
-       Bei allen native-Methoden wird au"serdem gleich der richtige 
-       Funktionszeiger eingetragen, bei JavaVM-Methoden einstweilen ein
-       Zeiger auf den Compiler 
+       Loads a method from the class file and fills an existing 'methodinfo'
+       structure. For native methods, the function pointer field is set to the
+       real function pointer, for JavaVM methods a pointer to the compiler is used
+       preliminarily.
        
 *******************************************************************************/
 
@@ -884,6 +922,12 @@ static void method_load (methodinfo *m, classinfo *c)
        m -> entrypoint = NULL;
        m -> mcode = NULL;
        m -> stubroutine = NULL;
+        m -> methodUsed = NOTUSED;    
+        m -> monoPoly = MONO;    
+       m -> subRedefs = 0;
+       m -> subRedefsUsed = 0;
+
+       m->xta = NULL;
        
        if (! (m->flags & ACC_NATIVE) ) {
                m -> stubroutine = createcompilerstub (m);
@@ -893,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
                        }
                }
        
@@ -953,10 +990,9 @@ static void method_load (methodinfo *m, classinfo *c)
 
 }
 
-/********************* Funktion: method_free ***********************************
+/********************* Function: method_free ***********************************
 
-       gibt allen Speicher, der extra f"ur eine Methode angefordert wurde,
-       wieder frei
+       frees all memory that was allocated for this method
 
 *******************************************************************************/
 
@@ -973,7 +1009,7 @@ static void method_free (methodinfo *m)
 }
 
 
-/************** Funktion: method_display  (nur zu Debug-Zwecken) **************/
+/************** Function: method_display  (debugging only) **************/
 
 void method_display (methodinfo *m)
 {
@@ -987,11 +1023,10 @@ void method_display (methodinfo *m)
 }
 
 
-/******************** Funktion: method_canoverwrite ****************************
+/******************** Function: method_canoverwrite ****************************
 
-       "uberpr"ft, ob eine Methode mit einer anderen typ- und namensidentisch 
-       ist (also mit einer Methodendefinition eine andere "uberschrieben 
-       werden kann).
+       Check if m and old are identical with respect to type and name. This means
+       that old can be overwritten with m.
        
 *******************************************************************************/  
 
@@ -1007,11 +1042,11 @@ static bool method_canoverwrite (methodinfo *m, methodinfo *old)
 
 
 /******************************************************************************/
-/************************ Funktionen fuer Class *******************************/
+/************************ Functions for class *********************************/
 /******************************************************************************/
 
 
-/******************** function: class_getconstant ******************************
+/******************** function:: class_getconstant ******************************
 
        retrieves the value at position 'pos' of the constantpool of a class
        if the type of the value is other than 'ctype' the system is stopped
@@ -1035,10 +1070,9 @@ voidptr class_getconstant (classinfo *c, u4 pos, u4 ctype)
 }
 
 
-/********************* Funktion: class_constanttype ****************************
+/********************* Function: class_constanttype ****************************
 
-       Findet heraus, welchen Typ ein Eintrag in den ConstantPool einer 
-       Klasse hat.
+       Determines the type of a class entry in the ConstantPool
        
 *******************************************************************************/
 
@@ -1371,17 +1405,16 @@ static void class_loadcpool (classinfo *c)
 }
 
 
-/********************** Funktion: class_load ***********************************
-
-       l"adt alle Infos f"ur eine ganze Klasse aus einem ClassFile. Die
-       'classinfo'-Struktur mu"s bereits angelegt worden sein.
-       
-       Die Superklasse und die Interfaces, die diese Klasse implementiert,
-       m"ussen zu diesem Zeitpunkt noch nicht geladen sein, die 
-       Verbindung dazu wird sp"ater in der Funktion 'class_link' hergestellt.
+/********************** Function: class_load ***********************************
        
-       Die gelesene Klasse wird dann aus der Liste 'unloadedclasses' ausgetragen
-       und in die Liste 'unlinkedclasses' eingh"angt.
+       Loads everything interesting about a class from the class file. The
+       'classinfo' structure must have been allocated previously.
+
+       The super class and the interfaces implemented by this class need not be
+       loaded. The link is set later by the function 'class_link'.
+
+       The loaded class is removed from the list 'unloadedclasses' and added to
+       the list 'unlinkedclasses'.
        
 *******************************************************************************/
 
@@ -1390,8 +1423,13 @@ static int class_load (classinfo *c)
        u4 i;
        u4 mi,ma;
 
+#ifdef STATISTICS
+       count_class_loads++;
+#endif
+
        /* output for debugging purposes */
        if (loadverbose) {              
+
                sprintf (logtext, "Loading class: ");
                utf_sprint (logtext+strlen(logtext), c->name );
                dolog();
@@ -1408,19 +1446,18 @@ static int class_load (classinfo *c)
        /* check version */
        mi = suck_u2(); 
        ma = suck_u2();
-       if (ma != MAJOR_VERSION) {
-               sprintf (logtext, "Can only support major version %d, but not %d",
-                                MAJOR_VERSION, (int) ma);
+       if (ma != MAJOR_VERSION && (ma != MAJOR_VERSION+1 || mi != 0)) {
+               sprintf (logtext, "File version %d.%d is not supported",
+                                (int) ma, (int) mi);
                error();
                }
-       if (mi > MINOR_VERSION)  {
-               sprintf (logtext, "Minor version %d is not yet supported.", (int) mi);
-               error();
-               }
 
 
        class_loadcpool (c);
        
+        c -> classUsed = NOTUSED; /* not used initially CO-RT */
+       c -> impldBy = NULL;
+
        /* ACC flags */
        c -> flags = suck_u2 (); 
        /* this class */
@@ -1444,7 +1481,7 @@ static int class_load (classinfo *c)
 
        /* load fields */
        c -> fieldscount = suck_u2 ();
-       c -> fields = MNEW (fieldinfo, c -> fieldscount);
+       c -> fields = GCNEW (fieldinfo, c -> fieldscount);
        for (i=0; i < c -> fieldscount; i++) {
                field_load (&(c->fields[i]), c);
                }
@@ -1478,10 +1515,10 @@ static int class_load (classinfo *c)
 
 
 
-/************** interne Funktion: class_highestinterface ***********************
+/************** internal Function: class_highestinterface ***********************
 
-       wird von der Funktion class_link ben"otigt, um festzustellen, wie gro"s
-       die Interfacetable einer Klasse sein mu"s.
+       Used by the function class_link to determine the amount of memory needed
+       for the interface table.
 
 *******************************************************************************/
 
@@ -1507,9 +1544,8 @@ static s4 class_highestinterface (classinfo *c)
 
 /* class_addinterface **********************************************************
 
-       wird von der Funktion class_link ben"otigt, um eine Virtual Function 
-       Table f"ur ein Interface (und alle weiteren von diesem Interface
-       implementierten Interfaces) in eine Klasse einzutragen.
+       Is needed by class_link for adding a VTBL to a class. All interfaces
+       implemented by ic are added as well.
 
 *******************************************************************************/       
 
@@ -1560,26 +1596,23 @@ static void class_addinterface (classinfo *c, classinfo *ic)
 }
 
 
-/********************** Funktion: class_link ***********************************
+/********************** Function: class_link ***********************************
 
-       versucht, eine Klasse in das System voll zu integrieren (linken). Dazu 
-       m"ussen sowol die Superklasse, als auch alle implementierten
-       Interfaces schon gelinkt sein.
-       Diese Funktion berechnet sowohl die L"ange (in Bytes) einer Instanz 
-       dieser Klasse, als auch die Virtual Function Tables f"ur normale
-       Methoden als auch Interface-Methoden.
+       Tries to link a class. The super class and every implemented interface must
+       already have been linked. The function calculates the length in bytes that
+       an instance of this class requires as well as the VTBL for methods and
+       interface methods.
        
-       Wenn die Klasse erfolgreich gelinkt werden kann, dann wird sie aus
-       der Liste 'unlinkedclasses' ausgeh"angt, und in die Klasse 'linkedclasses'
-       eingetragen.
-       Wenn nicht, dann wird sie ans Ende der Liste 'unlinkedclasses' gestellt.
+       If the class can be linked, it is removed from the list 'unlinkedclasses'
+       and added to 'linkedclasses'. Otherwise, it is moved to the end of
+       'unlinkedclasses'.
 
-       Achtung: Bei zyklischen Klassendefinitionen ger"at das Programm hier in
-                eine Endlosschleife!!  (Da muss ich mir noch was einfallen lassen)
+       Attention: If cyclical class definitions are encountered, the program gets
+       into an infinite loop (we'll have to work that out)
 
 *******************************************************************************/
 
-static void class_link (classinfo *c)
+void class_link (classinfo *c)
 {
        s4 supervftbllength;          /* vftbllegnth of super class               */
        s4 vftbllength;               /* vftbllength of current class             */
@@ -1608,6 +1641,8 @@ static void class_link (classinfo *c)
 
        if (super == NULL) {          /* class java.long.Object */
                c->index = 0;
+        c->classUsed = USED;     /* Object class is always used CO-RT*/
+               c -> impldBy = NULL;
                c->instancesize = sizeof(java_objectheader);
                
                vftbllength = supervftbllength = 0;
@@ -1768,10 +1803,9 @@ foundvftblindex: ;
 }
 
 
-/******************* Funktion: class_freepool **********************************
+/******************* Function: class_freepool **********************************
 
-       Gibt alle Resourcen, die der ConstantPool einer Klasse ben"otigt,
-       wieder frei.
+       Frees all resources used by this classes Constant Pool.
 
 *******************************************************************************/
 
@@ -1819,9 +1853,9 @@ static void class_freecpool (classinfo *c)
 }
 
 
-/*********************** Funktion: class_free **********************************
+/*********************** Function: class_free **********************************
 
-       Gibt alle Resourcen, die eine ganze Klasse ben"otigt, frei
+       Frees all resources used by the class.
 
 *******************************************************************************/
 
@@ -1836,7 +1870,6 @@ static void class_free (classinfo *c)
 
        for (i = 0; i < c->fieldscount; i++)
                field_free(&(c->fields[i]));
-       MFREE (c->fields, fieldinfo, c->fieldscount);
        
        for (i = 0; i < c->methodscount; i++)
                method_free(&(c->methods[i]));
@@ -1859,13 +1892,16 @@ static void class_free (classinfo *c)
        if (c->innerclasscount)
                MFREE (c->innerclass, innerclassinfo, c->innerclasscount);
 
+       if (c->classvftbl)
+               mem_free(c->header.vftbl, sizeof(vftbl) + sizeof(methodptr)*(c->vftbl->vftbllength-1));
+       
        FREE (c, classinfo);
 }
 
-/************************* Funktion: class_findfield ***************************
+/************************* Function: class_findfield ***************************
        
-       sucht in einer 'classinfo'-Struktur nach einem Feld mit gew"unschtem
-       Namen und Typ.
+       Searches a 'classinfo' structure for a field having the given name and
+       type.
 
 *******************************************************************************/
 
@@ -1884,11 +1920,11 @@ fieldinfo *class_findfield (classinfo *c, utf *name, utf *desc)
 }
 
 
-/************************* Funktion: class_findmethod **************************
+/************************* Function: class_findmethod **************************
        
-       sucht in einer 'classinfo'-Struktur nach einer Methode mit gew"unschtem
-       Namen und Typ.
-       Wenn als Typ NULL angegeben wird, dann ist der Typ egal.
+       Searches a 'classinfo' structure for a method having the given name and
+       type.
+       If type is NULL, it is ignored.
 
 *******************************************************************************/
 
@@ -1903,12 +1939,10 @@ methodinfo *class_findmethod (classinfo *c, utf *name, utf *desc)
        return NULL;
 }
 
-/************************* Funktion: class_findmethod_approx ******************
+/************************* Function: class_findmethod_approx ******************
        
-       sucht in einer 'classinfo'-Struktur nach einer Methode mit gew"unschtem
-       Namen und Typ.
-       Wenn als Typ NULL angegeben wird, dann ist der Typ egal.
-       beim Vergleichen des Descriptors wird der R"uckgabewert nicht betrachtet
+       like class_findmethod but ignores the return value when comparing the
+       descriptor.
 
 *******************************************************************************/
 
@@ -1948,10 +1982,10 @@ methodinfo *class_findmethod_approx (classinfo *c, utf *name, utf *desc)
        return NULL;
 }
 
-/***************** Funktion: class_resolvemethod_approx ***********************
+/***************** Function: class_resolvemethod_approx ***********************
        
-       sucht eine Klasse und alle Superklassen ab, um eine Methode zu finden.
-       (ohne Beachtung des R"uckgabewertes)
+       Searches a class and every super class for a method (without paying
+       attention to the return value)
 
 *******************************************************************************/
 
@@ -1969,9 +2003,9 @@ methodinfo *class_resolvemethod_approx (classinfo *c, utf *name, utf *desc)
 }
 
 
-/************************* Funktion: class_resolvemethod ***********************
+/************************* Function: class_resolvemethod ***********************
        
-       sucht eine Klasse und alle Superklassen ab, um eine Methode zu finden.
+       Searches a class and every super class for a method.
 
 *******************************************************************************/
 
@@ -1989,9 +2023,9 @@ methodinfo *class_resolvemethod (classinfo *c, utf *name, utf *desc)
        
 
 
-/************************* Funktion: class_issubclass **************************
+/************************* Function: class_issubclass **************************
 
-       "uberpr"uft, ob eine Klasse von einer anderen Klasse abgeleitet ist.            
+       Checks if sub is a descendant of super.
        
 *******************************************************************************/
 
@@ -2006,12 +2040,11 @@ bool class_issubclass (classinfo *sub, classinfo *super)
 
 
 
-/****************** Initialisierungsfunktion f"ur eine Klasse ******************
+/****************** Initialization function for classes ******************
 
-       In Java kann jede Klasse ein statische Initialisierungsfunktion haben.
-       Diese Funktion mu"s aufgerufen werden, BEVOR irgendwelche Methoden der
-       Klasse aufgerufen werden, oder auf statische Variablen zugegriffen
-       wird.
+       In Java, every class can have a static initialization function. This
+       function has to be called BEFORE calling other methods or accessing static
+       variables.
 
 *******************************************************************************/
 
@@ -2026,16 +2059,23 @@ void class_init (classinfo *c)
        s4 i;
        int b;
 
-       if (!makeinitializations) return;
-       if (c->initialized) return;
+
+       if (!makeinitializations)
+               return;
+       if (c->initialized)
+               return;
        c -> initialized = true;
        
-       if (c->super) class_init (c->super);
-       for (i=0; i < c->interfacescount; i++) class_init(c->interfaces[i]);
+#ifdef STATISTICS
+       count_class_inits++;
+#endif
 
-       m = class_findmethod (c, 
-                             utf_clinit, 
-                             utf_fidesc);
+       if (c->super)
+               class_init (c->super);
+       for (i=0; i < c->interfacescount; i++)
+               class_init(c->interfaces[i]);  /* real */
+
+       m = class_findmethod (c, utf_clinit, utf_fidesc);
        if (!m) {
                if (initverbose) {
                        sprintf (logtext, "Class ");
@@ -2046,7 +2086,8 @@ void class_init (classinfo *c)
                return;
                }
                
-       if (! (m->flags & ACC_STATIC)) panic ("Class initializer is not static!");
+       if (! (m->flags & ACC_STATIC))
+               panic ("Class initializer is not static!");
        
        if (initverbose) {
                sprintf (logtext, "Starting initializer for class: ");
@@ -2059,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) {
@@ -2094,7 +2135,7 @@ void class_init (classinfo *c)
 
                if (!m) {
                        /* no method found */
-                       log("initializeSystemClass failed");
+                       printf("initializeSystemClass failed");
                        return;
                }
 
@@ -2122,7 +2163,128 @@ void class_init (classinfo *c)
 
 
 
-/********* Funktion: class_showconstantpool   (nur f"ur Debug-Zwecke) *********/
+/********* Function: find_class_method_constant *********/
+int find_class_method_constant (classinfo *c, utf * c1, utf* m1, utf* d1)  
+
+{
+       u4 i;
+       voidptr e;
+
+       for (i=0; i<c->cpcount; i++) {
+               
+               e = c -> cpinfos [i];
+               if (e) {
+                       
+                       switch (c -> cptags [i]) {
+                               case CONSTANT_Methodref:
+                                       {
+                                       constant_FMIref *fmi = e;
+                                       if (       (fmi->class->name == c1)  
+                                               && (fmi->name == m1)
+                                               && (fmi->descriptor == d1)) {
+                                       
+                                               return i;
+                                               }
+                                       }
+                                       break;
+                               case CONSTANT_InterfaceMethodref:
+                                       {
+                                       constant_FMIref *fmi = e;
+                                       if (       (fmi->class->name == c1)  
+                                               && (fmi->name == m1)
+                                               && (fmi->descriptor == d1)) {
+
+                                               return i;
+                                               }
+                                   }
+                                       break;
+                               }
+                               
+                       }
+
+               }
+return -1;
+}
+
+void class_showconstanti(classinfo *c, int ii) 
+{
+       u4 i = ii;
+       voidptr e;
+
+               
+e = c -> cpinfos [i];
+printf ("#%d:  ", (int) i);
+if (e) {
+                       switch (c -> cptags [i]) {
+                               case CONSTANT_Class:
+                                       printf ("Classreference -> ");
+                                       utf_display ( ((classinfo*)e) -> name );
+                                       break;
+                               
+                               case CONSTANT_Fieldref:
+                                       printf ("Fieldref -> "); goto displayFMIi;
+                               case CONSTANT_Methodref:
+                                       printf ("Methodref -> "); goto displayFMIi;
+                               case CONSTANT_InterfaceMethodref:
+                                       printf ("InterfaceMethod -> "); goto displayFMIi;
+                                 displayFMIi:
+                                       {
+                                       constant_FMIref *fmi = e;
+                                       utf_display ( fmi->class->name );
+                                       printf (".");
+                                       utf_display ( fmi->name);
+                                       printf (" ");
+                                       utf_display ( fmi->descriptor );
+                                   }
+                                       break;
+
+                               case CONSTANT_String:
+                                       printf ("String -> ");
+                                       utf_display (e);
+                                       break;
+                               case CONSTANT_Integer:
+                                       printf ("Integer -> %d", (int) ( ((constant_integer*)e) -> value) );
+                                       break;
+                               case CONSTANT_Float:
+                                       printf ("Float -> %f", ((constant_float*)e) -> value);
+                                       break;
+                               case CONSTANT_Double:
+                                       printf ("Double -> %f", ((constant_double*)e) -> value);
+                                       break;
+                               case CONSTANT_Long:
+                                       {
+                                       u8 v = ((constant_long*)e) -> value;
+#if U8_AVAILABLE
+                                       printf ("Long -> %ld", (long int) v);
+#else
+                                       printf ("Long -> HI: %ld, LO: %ld\n", 
+                                           (long int) v.high, (long int) v.low);
+#endif 
+                                       }
+                                       break;
+                               case CONSTANT_NameAndType:
+                                       { constant_nameandtype *cnt = e;
+                                         printf ("NameAndType: ");
+                                         utf_display (cnt->name);
+                                         printf (" ");
+                                         utf_display (cnt->descriptor);
+                                       }
+                                       break;
+                               case CONSTANT_Utf8:
+                                       printf ("Utf8 -> ");
+                                       utf_display (e);
+                                       break;
+                               case CONSTANT_Arraydescriptor:  {
+                                       printf ("Arraydescriptor: ");
+                                       displayarraydescriptor (e);
+                                       }
+                                       break;
+                               default: 
+                                       panic ("Invalid type of ConstantPool-Entry");
+                               }  }
+printf("\n");
+
+}
 
 void class_showconstantpool (classinfo *c) 
 {
@@ -2214,7 +2376,7 @@ void class_showconstantpool (classinfo *c)
 
 
 
-/********** Funktion: class_showmethods   (nur f"ur Debug-Zwecke) *************/
+/********** Function: class_showmethods   (debugging only) *************/
 
 void class_showmethods (classinfo *c)
 {
@@ -2261,16 +2423,16 @@ void class_showmethods (classinfo *c)
 
 
 /******************************************************************************/
-/******************* Funktionen fuer den Class-loader generell ****************/
+/******************* General functions for the class loader *******************/
 /******************************************************************************/
 
 static int loader_inited = 0;
 
-/********************* Funktion: loader_load ***********************************
+/********************* Function: loader_load ***********************************
 
-       l"adt und linkt die ge"unschte Klasse und alle davon 
-       referenzierten Klassen und Interfaces
-       Return: Einen Zeiger auf diese Klasse
+       Loads and links the class desired class and each class and interface
+       referenced by it.
+       Returns: a pointer to this class
 
 *******************************************************************************/
 
@@ -2282,7 +2444,8 @@ classinfo *loader_load (utf *topname)
        
        intsDisable();                           /* schani */
 
-       if (getloadingtime) starttime = getcputime();
+       if (getloadingtime)
+               starttime = getcputime();
 
        top = class_new (topname);
 
@@ -2299,15 +2462,15 @@ classinfo *loader_load (utf *topname)
                class_link (c);
                }
 
+       if (loader_inited)
+               loader_compute_subclasses();
+
        /* measure time */
        if (getloadingtime) {
                stoptime = getcputime();
                loadingtime += (stoptime-starttime);
                }
 
-       if (loader_inited)
-               loader_compute_subclasses();
-
        intsRestore();                          /* schani */
 
        return top; 
@@ -2328,7 +2491,9 @@ 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 = NOTUSED; /* not used initially CO-RT */               
+               c -> impldBy = NULL;
+
                /* prevent loader from loading primitive class */
                list_remove (&unloadedclasses, c);
                /* add to unlinked classes */
@@ -2341,6 +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 = NOTUSED; /* not used initially CO-RT */
+               primitivetype_table[i].class_wrap  -> impldBy = NULL;
        }
 }
 
@@ -2364,10 +2531,10 @@ classinfo *create_array_class(utf *u)
        return c;
 }
 
-/********************** Funktion: loader_init **********************************
+/********************** Function: loader_init **********************************
 
-       Initialisiert alle Listen und l"adt alle Klassen, die vom System
-       und vom Compiler direkt ben"otigt werden.
+       Initializes all lists and loads all classes required for the system or the
+       compiler.
 
 *******************************************************************************/
  
@@ -2392,11 +2559,17 @@ void loader_init ()
 
        /* create class for arrays */
        class_array = class_new ( utf_new_char ("The_Array_Class") );
+    class_array -> classUsed = NOTUSED; /* not used initially CO-RT */
+       class_array -> impldBy = 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 = NOTUSED; /* not used initially CO-RT */
+       class_java_lang_String -> impldBy = NULL;
+
        list_remove (&unloadedclasses, class_java_lang_String);
 
        class_java_lang_Object = 
@@ -2472,9 +2645,9 @@ void loader_init ()
 
 
 
-/********************* Funktion: loader_initclasses ****************************
+/********************* Function: loader_initclasses ****************************
 
-       initialisiert alle geladenen aber noch nicht initialisierten Klassen
+       Initializes all loaded but uninitialized classes
 
 *******************************************************************************/
 
@@ -2502,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++)
@@ -2517,7 +2691,7 @@ static void loader_compute_class_values (classinfo *c)
        utf_display(c->name);
        printf("\n");
        }
-*/
+       */
 }
 
 
@@ -2544,7 +2718,6 @@ void loader_compute_subclasses ()
                        }
                c = list_next (&linkedclasses, c);
                }
-
        classvalue = 0;
        loader_compute_class_values(class_java_lang_Object);
 
@@ -2567,9 +2740,9 @@ void classload_buffer(u1 *buf, int len)
 }
 
 
-/******************** Funktion: loader_close ***********************************
+/******************** Function: loader_close ***********************************
 
-       gibt alle Resourcen wieder frei
+       Frees all resources
        
 *******************************************************************************/