Major file restructuring.
[cacao.git] / loader.c
index 306cf7d5da2c9a0a1b959af3faa17e56e694bc84..a13cd4ed9eda8bb2d4693f3cb2ceff454b2061f4 100644 (file)
--- a/loader.c
+++ b/loader.c
@@ -1,20 +1,38 @@
+/* loader.c - class loader functions
 
-/* loader.c ********************************************************************
+   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
+   M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
+   P. Tomsich, J. Wenninger
 
-       Copyright (c) 1999 A. Krall, R. Grafl, R. Obermaiser, M. Probst
+   This file is part of CACAO.
 
-       See file COPYRIGHT for information on usage and disclaimer of warranties
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
 
-       Contains the functions of the class loader.
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
 
-       Author:  Reinhard Grafl      EMAIL: cacao@complang.tuwien.ac.at
-       Changes: Andreas Krall       EMAIL: cacao@complang.tuwien.ac.at
-                Roman Obermaiser    EMAIL: cacao@complang.tuwien.ac.at
-                Mark Probst         EMAIL: cacao@complang.tuwien.ac.at
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.
 
-       Last Change: 1999/11/08
+   Contact: cacao@complang.tuwien.ac.at
 
-*******************************************************************************/
+   Authors: Reinhard Grafl
+
+   Changes: Andreas Krall
+            Roman Obermaiser
+            Mark Probst
+
+   $Id: loader.c 557 2003-11-02 22:51:59Z twisti $
+
+*/
 
 
 #include <assert.h>
 #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,7 +54,6 @@
 
 /* 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 */
@@ -111,15 +123,16 @@ 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/Byte",      'B', "byte"    },
-               { NULL, NULL, "java/lang/Short",     'S', "short"   },
-               { NULL, NULL, "java/lang/Boolean",   'Z', "boolean" },
-               { NULL, NULL, "java/lang/Void",      'V', "void"    }};
+       { 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"    }
+};
 
 
 /* instances of important system classes **************************************/
@@ -786,10 +799,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 -> fieldUsed   = NOTUSED;  /*XTA*/
-       f -> fldClassType = NULL;    /*XTA*/
-       f -> XTAclassSet = NULL;     /*XTA*/
-       f -> lastRoundChgd = -1;
+       f->xta = NULL;
        
        switch (f->type) {
        case TYPE_INT:        f->value.i = 0; break;
@@ -932,26 +942,11 @@ static void method_load (methodinfo *m, classinfo *c)
        m -> mcode = NULL;
        m -> stubroutine = NULL;
         m -> methodUsed = NOTUSED;    
-        m -> XTAmethodUsed = NOTUSED;    
         m -> monoPoly = MONO;    
        m -> subRedefs = 0;
        m -> subRedefsUsed = 0;
 
-       /* --- XTA --- */
-       /*if (opt_xta) { */
-       m -> XTAclassSet        = NULL;      /*XTA*/
-       m -> paramClassSet      = NULL;      /*XTA*/
-       m -> calls              = NULL;      /*XTA*/
-       m -> calledBy           = NULL;      /*XTA*/
-       m -> chgdSinceLastParse = false; /*XTA*/
-
-       m -> marked       = NULL;      /*XTA*/
-       m -> markedBy     = NULL;      /*XTA*/
-       m -> fldsUsed     = NULL;      /*XTA*/
-       m -> interfaceCalls    = NULL; /*XTA*/
-       m -> lastRoundParsed = -1;
-       m -> interfaceCalls    = NULL;      /*XTA*/
-       /*}*/   
+       m->xta = NULL;
        
        if (! (m->flags & ACC_NATIVE) ) {
                m -> stubroutine = createcompilerstub (m);
@@ -961,14 +956,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
                        }
                }
        
@@ -1512,11 +1500,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);
                }
@@ -1647,7 +1631,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             */
@@ -1676,7 +1660,7 @@ 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->classUsed = USED;     /* Object class is always used CO-RT*/
                c -> impldBy = NULL;
                c->instancesize = sizeof(java_objectheader);
                
@@ -1905,9 +1889,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]));
@@ -2138,26 +2119,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) {
@@ -2236,8 +2217,6 @@ int find_class_method_constant (classinfo *c, utf * c1, utf* m1, utf* d1)
                                                }
                                    }
                                        break;
-                               
-                               default: 
                                }
                                
                        }
@@ -2578,7 +2557,7 @@ classinfo *create_array_class(utf *u)
 
 *******************************************************************************/
  
-void loader_init ()
+void loader_init()
 {
        utf *string_class;
        interfaceindex = 0;
@@ -2599,7 +2578,7 @@ 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 -> classUsed = NOTUSED; /* not used initially CO-RT */
        class_array -> impldBy = NULL;
 
        list_remove (&unloadedclasses, class_array);
@@ -2607,7 +2586,7 @@ void loader_init ()
        /* 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 -> classUsed = NOTUSED; /* not used initially CO-RT */
        class_java_lang_String -> impldBy = NULL;
 
        list_remove (&unloadedclasses, class_java_lang_String);
@@ -2722,8 +2701,7 @@ static void loader_compute_class_values (classinfo *c)
                subs = subs->nextsub;
                }
        c->vftbl->diffval = classvalue - c->vftbl->baseval;
-
-/*
+       /*
        {
        int i;
        for (i = 0; i < c->index; i++)
@@ -2732,7 +2710,7 @@ static void loader_compute_class_values (classinfo *c)
        utf_display(c->name);
        printf("\n");
        }
-*/
+       */
 }
 
 
@@ -2818,4 +2796,3 @@ void loader_close ()
  * tab-width: 4
  * End:
  */
-