*** empty log message ***
[cacao.git] / main.c
diff --git a/main.c b/main.c
index b1b3bad7f502ab0d1592e5a527ce9cbeb8929bae..0b0d94b1c01a4e3131542c51ed1ace6c022e1bac 100644 (file)
--- a/main.c
+++ b/main.c
@@ -4,20 +4,19 @@
 
        See file COPYRIGHT for information on usage and disclaimer of warranties
 
-       Enthaelt die Funktion main() und die Variablen fuer die 
-       globalen Optionen.
-       Dieser Modul erledigt folgende Aufgaben:
-          - Bearbeiten der command-line-options
-          - Aufrufen aller Initialisierungsroutinen
-          - Aufrufen des Classloaders
-          - Starten der main - Methode
+       Contains main() and variables for the global options.
+       This module does the following tasks:
+          - Command line option handling
+          - Calling initialization routines
+          - Calling the class loader
+          - Running the main method
 
        Authors: Reinhard Grafl      EMAIL: cacao@complang.tuwien.ac.at
        Changes: Andi Krall          EMAIL: cacao@complang.tuwien.ac.at
                 Mark Probst         EMAIL: cacao@complang.tuwien.ac.at
                         Philipp Tomsich     EMAIL: cacao@complang.tuwien.ac.at
 
-       Last Change: $Id: main.c 135 1999-10-04 10:35:09Z roman $
+       Last Change: $Id: main.c 285 2003-05-12 20:05:38Z carolyn $
 
 *******************************************************************************/
 
@@ -90,6 +89,8 @@ void **stackbottom = 0;
 #define OPT_GC2         23
 #endif
 #define OPT_OLOOP       24
+#define OPT_RT          25
+#define OPT_XTA         26 
 
 struct {char *name; bool arg; int value;} opts[] = {
        {"classpath",   true,   OPT_CLASSPATH},
@@ -123,6 +124,8 @@ struct {char *name; bool arg; int value;} opts[] = {
        {"gc2",         false,  OPT_GC2},
 #endif
        {"oloop",       false,  OPT_OLOOP},
+        {"rt",          false,  OPT_RT},
+        {"xta",         false,  OPT_XTA},
        {NULL,  false, 0}
 };
 
@@ -175,9 +178,9 @@ static int get_opt (int argc, char **argv)
 
 
 
-/******************** interne Funktion: print_usage ************************
+/******************** interne Function: print_usage ************************
 
-Gibt die richtige Aufrufsyntax des JavaVM-Compilers auf stdout aus.
+Prints the correct usage syntax to stdout.
 
 ***************************************************************************/
 
@@ -206,7 +209,7 @@ static void print_usage()
 #ifdef OLD_COMPILER
        printf ("          -old ................. use old JIT compiler\n");
 #endif
-#if 0
+#ifdef NEW_GC
        printf ("          -gc1 ................. use the old garbage collector (default)\n");
        printf ("          -gc2 ................. use the new garbage collector\n");
 #endif
@@ -221,13 +224,15 @@ static void print_usage()
        printf ("                 s(tack) ....... show stack for every javaVM-command\n");
 #endif
        printf ("                 u(tf) ......... show the utf - hash\n");
+        printf ("          -rt .................. use rapid type analysis\n");
+        printf ("          -xta ................. use xta\n");
 }   
 
 
 
-/***************************** Funktion: print_times *********************
+/***************************** Function: print_times *********************
 
-       gibt eine Aufstellung der verwendeten CPU-Zeit aus
+       Prints a summary of CPU time usage.
 
 **************************************************************************/
 
@@ -255,7 +260,7 @@ static void print_times()
 
 
 
-/***************************** Funktion: print_stats *********************
+/***************************** Function: print_stats *********************
 
        outputs detailed compiler statistics
 
@@ -412,6 +417,10 @@ static void print_stats()
        dolog();
        sprintf (logtext, "Size of ExTable (Kb):    %10.3f", (float) count_extable_len / 1024);
        dolog();
+       sprintf (logtext, "Number of class loads:   %d", count_class_loads);
+       dolog();
+       sprintf (logtext, "Number of class inits:   %d", count_class_inits);
+       dolog();
        sprintf (logtext, "Number of loaded Methods: %d\n\n", count_all_methods);
        dolog();
 
@@ -422,7 +431,7 @@ static void print_stats()
 }
 
 
-/********** Funktion: class_compile_methods   (nur f"ur Debug-Zwecke) ********/
+/********** Function: class_compile_methods   (debugging only) ********/
 
 void class_compile_methods ()
 {
@@ -458,7 +467,7 @@ void class_compile_methods ()
 
 void exit_handler(void)
 {
-       /********************* Debug-Tabellen ausgeben ************************/
+       /********************* Print debug tables ************************/
                                
        if (showmethods) class_showmethods (topclass);
        if (showconstantpool)  class_showconstantpool (topclass);
@@ -469,7 +478,7 @@ void exit_handler(void)
                                                                   flags */
 #endif
 
-       /************************ Freigeben aller Resourcen *******************/
+       /************************ Free all resources *******************/
 
        heap_close ();                          /* must be called before compiler_close and
                                                                   loader_close because finalization occurs
@@ -491,10 +500,9 @@ void exit_handler(void)
        }
 }
 
-/************************** Funktion: main *******************************
+/************************** Function: main *******************************
 
-   Das Hauptprogramm.
-   Wird vom System zu Programstart aufgerufen (eh klar).
+   The main program.
    
 **************************************************************************/
 
@@ -502,13 +510,13 @@ int main(int argc, char **argv)
 {
        s4 i,j;
        char *cp;
-       java_objectheader *exceptionptr;
+       java_objectheader *local_exceptionptr = 0;
        void *dummy;
        
        /********** interne (nur fuer main relevante Optionen) **************/
    
        char logfilename[200] = "";
-       u4 heapsize = 16000000;
+       u4 heapsize = 64000000;
        u4 heapstartsize = 200000;
        char classpath[500] = ".:/usr/local/lib/java/classes";
        bool startit = true;
@@ -522,14 +530,14 @@ int main(int argc, char **argv)
        if (0 != atexit(exit_handler))
                panic("unable to register exit_handler");
 
-       /************ Infos aus der Environment lesen ************************/
+       /************ Collect info from the environment ************************/
 
        cp = getenv ("CLASSPATH");
        if (cp) {
                strcpy (classpath, cp);
        }
 
-       /***************** Interpretieren der Kommandozeile *****************/
+       /***************** Interpret the command line *****************/
    
        checknull = false;
        checkfloats = false;
@@ -665,7 +673,7 @@ int main(int argc, char **argv)
                        break;
 #endif
                        
-               case OPT_SHOW:       /* Anzeigeoptionen */
+               case OPT_SHOW:       /* Display options */
                        for (j=0; j<strlen(opt_arg); j++) {             
                                switch (opt_arg[j]) {
                                case 'a':  showdisassemble=true; compileverbose=true; break;
@@ -687,6 +695,14 @@ int main(int argc, char **argv)
                        opt_loops = true;
                        break;
 
+               case OPT_RT:
+                        opt_rt = true;
+                        break;
+
+               case OPT_XTA:
+                        opt_xta = true;
+                        break;
+
                default:
                        print_usage();
                        exit(10);
@@ -702,7 +718,7 @@ int main(int argc, char **argv)
        }
 
 
-       /**************************** Programmstart *****************************/
+       /**************************** Program start *****************************/
 
        log_init (logfilename);
        if (verbose) {
@@ -715,25 +731,38 @@ int main(int argc, char **argv)
                
        tables_init();
        heap_init(heapsize, heapstartsize, &dummy);
-       loader_init();
 #ifdef OLD_COMPILER
        compiler_init();
 #endif
        jit_init();
+       loader_init();
 
        native_loadclasses ();
 
 
-       /*********************** JAVA-Klassen laden  ***************************/
+       /*********************** Load JAVA classes  ***************************/
    
        cp = argv[opt_ind++];
-       for (i=strlen(cp)-1; i>=0; i--) {     /* Punkte im Klassennamen */
-               if (cp[i]=='.') cp[i]='/';        /* auf slashes umbauen */
+       for (i=strlen(cp)-1; i>=0; i--) {     /* Transform dots into slashes */
+               if (cp[i]=='.') cp[i]='/';        /* in the class name */
        }
 
        topclass = loader_load ( utf_new_char (cp) );
 
-       loader_compute_subclasses();
+       if (exceptionptr != 0)
+       {
+               printf ("#### Class loader has thrown: ");
+               utf_display (exceptionptr->vftbl->class->name);
+               printf ("\n");
+
+               exceptionptr = 0;
+       }
+
+       if (topclass == 0)
+       {
+               printf("#### Could not find top class - exiting\n");
+               exit(1);
+       }
 
        gc_init();
 
@@ -741,7 +770,7 @@ int main(int argc, char **argv)
        initThreads((u1*)&dummy);                   /* schani */
 #endif
 
-       /************************* Arbeitsroutinen starten ********************/
+       /************************* Start worker routines ********************/
 
        if (startit) {
                methodinfo *mainmethod;
@@ -761,13 +790,19 @@ int main(int argc, char **argv)
                for (i=opt_ind; i<argc; i++) {
                        a->data[i-opt_ind] = javastring_new (utf_new_char (argv[i]) );
                }
-               exceptionptr = asm_calljavamethod (mainmethod, a, NULL,NULL,NULL );
+               local_exceptionptr = asm_calljavamethod (mainmethod, a, NULL,NULL,NULL );
        
-               if (exceptionptr) {
+               if (local_exceptionptr) {
                        printf ("#### Program has thrown: ");
-                       utf_display (exceptionptr->vftbl->class->name);
+                       utf_display (local_exceptionptr->vftbl->class->name);
                        printf ("\n");
                }
+                                        /*RTAprint*/ if ((pCallgraph >= 1) && (opt_rt)) {
+                                        /*RTAprint*/    printCallgraph (); }
+
+                                        /*RTprint*/ if ((pClassHeir >= 1) && (opt_rt)) {
+                                        /*RTprint*/     printf("Last RTA Class Heirarchy -");
+                                        /*RTprint*/     printRThierarchyInfo(mainmethod); }
 
 #ifdef USE_THREADS
                killThread(currentThread);
@@ -775,14 +810,14 @@ int main(int argc, char **argv)
                fprintf(stderr, "still here\n");
        }
 
-       /************* Auf Wunsch alle Methode "ubersetzen ********************/
+       /************* If requested, compile all methods ********************/
 
        if (compileall) {
                class_compile_methods();
        }
 
 
-       /******** Auf Wunsch eine spezielle Methode "ubersetzen ***************/
+       /******** If requested, compile a specific method ***************/
 
        if (specificmethodname) {
                methodinfo *m;
@@ -809,16 +844,22 @@ int main(int argc, char **argv)
 
 
 
-/************************************ SHUTDOWN-Funktion *********************************
+/************************************ Shutdown function *********************************
 
-       Terminiert das System augenblicklich, ohne den Speicher
-       explizit freizugeben (eigentlich nur f"ur abnorme 
-       Programmterminierung)
+       Terminates the system immediately without freeing memory explicitly (to be
+       used only for abnormal termination)
        
 *****************************************************************************************/
 
 void cacao_shutdown(s4 status)
 {
+                                        /*RTAprint*/ if ((pCallgraph >= 1) && (opt_rt)) {
+                                        /*RTAprint*/    printCallgraph (NULL); }
+
+                                        /*RTprint*/ if ((pClassHeir >= 1) && (opt_rt)) {
+                                        /*RTprint*/     printf("Last RTA Class Heirarchy -");
+                                        /*RTprint*/     printRThierarchyInfo(NULL); }
+
        if (verbose || getcompilingtime || statistics) {
                log_text ("CACAO terminated by shutdown");
                if (statistics)