More tests
[cacao.git] / src / cacao / cacao.c
index 9d5c2eae768992b1f115be02959cb9f93ddc02cc..1c1f715fca10cd2b5229f10890ca294df27cce89 100644 (file)
@@ -4,19 +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: 1997/10/29
+       Last Change: $Id: cacao.c 474 2003-10-04 18:55:10Z stefan $
 
 *******************************************************************************/
 
@@ -44,7 +44,7 @@ bool new_gc = false;
 
 static bool showmethods = false;
 static bool showconstantpool = false;
-static bool showunicode = false;
+static bool showutf = false;
 static classinfo *topclass;
 
 #ifndef USE_THREADS
@@ -88,6 +88,12 @@ void **stackbottom = 0;
 #define OPT_GC1         22
 #define OPT_GC2         23
 #endif
+#define OPT_OLOOP       24
+#define OPT_INLINING   25
+#define OPT_RT          26
+#define OPT_XTA         27 
+#define OPT_VTA         28 
+
 
 struct {char *name; bool arg; int value;} opts[] = {
        {"classpath",   true,   OPT_CLASSPATH},
@@ -120,6 +126,11 @@ struct {char *name; bool arg; int value;} opts[] = {
        {"gc1",         false,  OPT_GC1},
        {"gc2",         false,  OPT_GC2},
 #endif
+       {"oloop",       false,  OPT_OLOOP},
+       {"i",               true,  OPT_INLINING},
+       {"rt",          false,  OPT_RT},
+       {"xta",         false,  OPT_XTA},
+        {"vta",         false,  OPT_VTA},
        {NULL,  false, 0}
 };
 
@@ -172,15 +183,15 @@ 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.
 
 ***************************************************************************/
 
 static void print_usage()
 {
-       printf ("USAGE: cacao [options] classname [program arguments\n");
+       printf ("USAGE: cacao [options] classname [program arguments]\n");
        printf ("Options:\n");
        printf ("          -classpath path ...... specify a path to look for classes\n");
        printf ("          -Dpropertyname=value . add an entry to the property list\n");
@@ -195,8 +206,9 @@ static void print_usage()
        printf ("          -time ................ measure the runtime\n");
        printf ("          -stat ................ detailed compiler statistics\n");
        printf ("          -log logfile ......... specify a name for the logfile\n");
-       printf ("          -c(heck) b(ounds...... don't check array bounds\n");
-       printf ("                   s(ync) ...... don't check for synchronization\n");
+       printf ("          -c(heck)b(ounds) ..... don't check array bounds\n");
+       printf ("                  s(ync) ....... don't check for synchronization\n");
+       printf ("          -oloop ............... optimize array accesses in loops\n"); 
        printf ("          -l ................... don't start the class after loading\n");
        printf ("          -all ................. compile all methods, no execution\n");
 #ifdef OLD_COMPILER
@@ -208,8 +220,7 @@ static void print_usage()
 #endif
        printf ("          -m ................... compile only a specific method\n");
        printf ("          -sig ................. specify signature for a specific method\n");
-       printf ("          -s(how)m(ethods) ..... show all methods&fields of a class\n");
-       printf ("                 a(ssembler) ... show disassembled listing\n");
+       printf ("          -s(how)a(ssembler) ... show disassembled listing\n");
        printf ("                 c(onstants) ... show the constant pool\n");
        printf ("                 d(atasegment).. show data segment listing\n");
        printf ("                 i(ntermediate). show intermediate representation\n");
@@ -217,14 +228,22 @@ static void print_usage()
 #ifdef OLD_COMPILER
        printf ("                 s(tack) ....... show stack for every javaVM-command\n");
 #endif
-       printf ("                 u(nicode) ..... show the unicode - hash\n");
+       printf ("                 u(tf) ......... show the utf - hash\n");
+       printf ("          -i     n ............. activate inlining\n");
+       printf ("                 v ............. inline virtual methods\n");
+       printf ("                 e ............. inline methods with exceptions\n");
+       printf ("                 p ............. optimize argument renaming\n");
+       printf ("                 o ............. inline methods of foreign classes\n");
+        printf ("          -rt .................. use rapid type analysis\n");
+        printf ("          -xta ................. use x type analysis\n");
+        printf ("          -vta ................. use variable type analysis\n");
 }   
 
 
 
-/***************************** Funktion: print_times *********************
+/***************************** Function: print_times *********************
 
-       gibt eine Aufstellung der verwendeten CPU-Zeit aus
+       Prints a summary of CPU time usage.
 
 **************************************************************************/
 
@@ -252,7 +271,7 @@ static void print_times()
 
 
 
-/***************************** Funktion: print_stats *********************
+/***************************** Function: print_stats *********************
 
        outputs detailed compiler statistics
 
@@ -279,7 +298,7 @@ static void print_stats()
        dolog();
        sprintf (logtext, "Value of extended instruction set var:  %d", has_ext_instr_set);
        dolog();
-       sprintf (logtext, "Number of Alpha-Instructions: %d", count_code_len >> 2);
+       sprintf (logtext, "Number of Machine-Instructions: %d", count_code_len >> 2);
        dolog();
        sprintf (logtext, "Number of Spills: %d", count_spills);
        dolog();
@@ -378,7 +397,7 @@ static void print_stats()
        sprintf (logtext, "Distribution of basic block sizes");
        dolog();
        sprintf (logtext,
-       "  1    2    3    4   5   6   7   8   9  10 <13 <15 <17 <19 <21 <26 <31 >30");
+       "  0    1    2    3    4   5   6   7   8   9 <13 <15 <17 <19 <21 <26 <31 >30");
        dolog();
        sprintf (logtext, "%3d%5d%5d%5d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d",
                count_block_size_distribution[0], count_block_size_distribution[1], count_block_size_distribution[2],
@@ -394,7 +413,7 @@ static void print_stats()
        dolog();
        sprintf (logtext, "Size of Class Infos (Kb):%10.3f", (float) (count_class_infos) / 1024);
        dolog();
-       sprintf (logtext, "Size of Const Pool (Kb): %10.3f", (float) (count_const_pool_len + count_unicode_len) / 1024);
+       sprintf (logtext, "Size of Const Pool (Kb): %10.3f", (float) (count_const_pool_len + count_utf_len) / 1024);
        dolog();
        sprintf (logtext, "Size of Vftbl (Kb):      %10.3f", (float) count_vftbl_len / 1024);
        dolog();
@@ -402,19 +421,28 @@ static void print_stats()
        dolog();
        sprintf (logtext, "Size of native stub (Kb):%10.3f", (float) count_nstub_len / 1024);
        dolog();
-       sprintf (logtext, "Size of Unicode (Kb):    %10.3f", (float) count_unicode_len / 1024);
+       sprintf (logtext, "Size of Utf (Kb):        %10.3f", (float) count_utf_len / 1024);
        dolog();
        sprintf (logtext, "Size of VMCode (Kb):     %10.3f(%d)", (float) count_vmcode_len / 1024,
                                                      count_vmcode_len - 18 * count_all_methods);
        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();
+
+       sprintf (logtext, "Calls of utf_new: %22d", count_utf_new);
+       dolog();
+       sprintf (logtext, "Calls of utf_new (element found): %6d\n\n", count_utf_new_found);
+       dolog();
 }
 
 
-/********** Funktion: class_compile_methods   (nur f"ur Debug-Zwecke) ********/
+/********** Function: class_compile_methods   (debugging only) ********/
 
 void class_compile_methods ()
 {
@@ -450,18 +478,18 @@ void class_compile_methods ()
 
 void exit_handler(void)
 {
-       /********************* Debug-Tabellen ausgeben ************************/
+       /********************* Print debug tables ************************/
                                
        if (showmethods) class_showmethods (topclass);
        if (showconstantpool)  class_showconstantpool (topclass);
-       if (showunicode)       unicode_show ();
+       if (showutf)           utf_show ();
 
 #ifdef USE_THREADS
        clear_thread_flags();           /* restores standard file descriptor
                                                                   flags */
 #endif
 
-       /************************ Freigeben aller Resourcen *******************/
+       /************************ Free all resources *******************/
 
        heap_close ();                          /* must be called before compiler_close and
                                                                   loader_close because finalization occurs
@@ -471,7 +499,7 @@ void exit_handler(void)
        compiler_close ();
 #endif
        loader_close ();
-       unicode_close ( literalstring_free );
+       tables_close ( literalstring_free );
 
        if (verbose || getcompilingtime || statistics) {
                log_text ("CACAO terminated");
@@ -483,10 +511,9 @@ void exit_handler(void)
        }
 }
 
-/************************** Funktion: main *******************************
+/************************** Function: main *******************************
 
-   Das Hauptprogramm.
-   Wird vom System zu Programstart aufgerufen (eh klar).
+   The main program.
    
 **************************************************************************/
 
@@ -494,13 +521,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;
@@ -514,14 +541,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;
@@ -657,7 +684,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;
@@ -668,13 +695,45 @@ int main(int argc, char **argv)
 #ifdef OLD_COMPILER
                                case 's':  showstack=true; compileverbose=true; break;
 #endif
-                               case 'u':  showunicode=true; break;
+                               case 'u':  showutf=true; break;
                                default:   print_usage();
                                        exit(10);
                                }
                        }
                        break;
                        
+               case OPT_OLOOP:
+                       opt_loops = true;
+                       break;
+
+       
+               case OPT_INLINING:
+                       for (j=0; j<strlen(opt_arg); j++) {             
+                               switch (opt_arg[j]) {
+                               case 'n':  useinlining = true; break;
+                               case 'v':  inlinevirtuals = true; break;
+                               case 'e':  inlineexceptions = true; break;
+                               case 'p':  inlineparamopt = true; break;
+                               case 'o':  inlineoutsiders = true; break;
+                               default:   print_usage();
+                                       exit(10);
+                               }
+                       }
+                       break;
+
+
+               case OPT_RT:
+                        opt_rt = true;
+                        break;
+
+               case OPT_XTA:
+                        /***opt_xta = true; not yet **/
+                        break;
+
+               case OPT_VTA:
+                        /***opt_vta = true; not yet **/
+                        break;
+
                default:
                        print_usage();
                        exit(10);
@@ -690,7 +749,7 @@ int main(int argc, char **argv)
        }
 
 
-       /**************************** Programmstart *****************************/
+       /**************************** Program start *****************************/
 
        log_init (logfilename);
        if (verbose) {
@@ -701,27 +760,40 @@ int main(int argc, char **argv)
        suck_init (classpath);
        native_setclasspath (classpath);
                
-       unicode_init();
+       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 ( unicode_new_char (cp) );
+       topclass = loader_load ( utf_new_char (cp) );
+
+       if (exceptionptr != 0)
+       {
+               printf ("#### Class loader has thrown: ");
+               utf_display (exceptionptr->vftbl->class->name);
+               printf ("\n");
 
-       loader_compute_subclasses();
+               exceptionptr = 0;
+       }
+
+       if (topclass == 0)
+       {
+               printf("#### Could not find top class - exiting\n");
+               exit(1);
+       }
 
        gc_init();
 
@@ -729,7 +801,7 @@ int main(int argc, char **argv)
        initThreads((u1*)&dummy);                   /* schani */
 #endif
 
-       /************************* Arbeitsroutinen starten ********************/
+       /************************* Start worker routines ********************/
 
        if (startit) {
                methodinfo *mainmethod;
@@ -739,46 +811,54 @@ int main(int argc, char **argv)
 
                mainmethod = class_findmethod (
                                                                           topclass,
-                                                                          unicode_new_char ("main"), 
-                                                                          unicode_new_char ("([Ljava/lang/String;)V")
+                                                                          utf_new_char ("main"), 
+                                                                          utf_new_char ("([Ljava/lang/String;)V")
                                                                           );
                if (!mainmethod) panic ("Can not find method 'void main(String[])'");
                if ((mainmethod->flags & ACC_STATIC) != ACC_STATIC) panic ("main is not static!");
                        
                a = builtin_anewarray (argc - opt_ind, class_java_lang_String);
                for (i=opt_ind; i<argc; i++) {
-                       a->data[i-opt_ind] = javastring_new (unicode_new_char (argv[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: ");
-                       unicode_display (exceptionptr->vftbl->class->name);
+                       utf_display (local_exceptionptr->vftbl->class->name);
                        printf ("\n");
                }
 
+                                        /*RTprint*/ if ((pClassHeir >= 1) && (opt_rt)) {
+                                        /*RTprint*/     printf("Last RTA Info -");
+                                        /*RTprint*/     printRThierarchyInfo(mainmethod); 
+                                       /*RTprint*/     }
+                                       /*RTprint*/     printObjectClassHeirarchy1( );
+
+#ifdef USE_THREADS
                killThread(currentThread);
+#endif
                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;
                if (specificsignature)
                        m = class_findmethod(topclass, 
-                                                                unicode_new_char(specificmethodname),
-                                                                unicode_new_char(specificsignature));
+                                                                utf_new_char(specificmethodname),
+                                                                utf_new_char(specificsignature));
                else
                        m = class_findmethod(topclass, 
-                                                                unicode_new_char(specificmethodname), NULL);
+                                                                utf_new_char(specificmethodname), NULL);
                if (!m) panic ("Specific method not found");
 #ifdef OLD_COMPILER
                if (newcompiler)
@@ -795,16 +875,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("RTA Information -");
+                                        /*RTprint*/     printRThierarchyInfo(NULL); }
+
        if (verbose || getcompilingtime || statistics) {
                log_text ("CACAO terminated by shutdown");
                if (statistics)