narray first check in
[cacao.git] / src / cacao / cacao.c
index e49362c9d337979bfc7453c654a773ab43d90237..82ce1e0783fd23de1e6030ca6767adfb337c3156 100644 (file)
@@ -15,8 +15,9 @@
        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 132 1999-09-27 15:54:42Z chris $
 
 *******************************************************************************/
 
@@ -33,7 +34,7 @@
 #include "builtin.h"
 #include "native.h"
 
-#include "threads/thread.h"            /* schani */
+#include "threads/thread.h"
 
 bool compileall = false;
 int  newcompiler = true;               
@@ -42,6 +43,11 @@ bool verbose =  false;
 bool new_gc = false;
 #endif
 
+static bool showmethods = false;
+static bool showconstantpool = false;
+static bool showunicode = false;
+static classinfo *topclass;
+
 #ifndef USE_THREADS
 void **stackbottom = 0;
 #endif
@@ -83,6 +89,7 @@ void **stackbottom = 0;
 #define OPT_GC1         22
 #define OPT_GC2         23
 #endif
+#define OPT_OLOOP       24
 
 struct {char *name; bool arg; int value;} opts[] = {
        {"classpath",   true,   OPT_CLASSPATH},
@@ -115,6 +122,7 @@ struct {char *name; bool arg; int value;} opts[] = {
        {"gc1",         false,  OPT_GC1},
        {"gc2",         false,  OPT_GC2},
 #endif
+       {"oloop",       false,  OPT_OLOOP},
        {NULL,  false, 0}
 };
 
@@ -190,21 +198,21 @@ 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
        printf ("          -old ................. use old JIT compiler\n");
 #endif
-#ifdef NEW_GC
+#if 0
        printf ("          -gc1 ................. use the old garbage collector (default)\n");
        printf ("          -gc2 ................. use the new garbage collector\n");
 #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");
@@ -436,6 +444,47 @@ void class_compile_methods ()
                }
 }
 
+/*
+ * void exit_handler(void)
+ * -----------------------
+ * The exit_handler function is called upon program termination to shutdown
+ * the various subsystems and release the resources allocated to the VM.
+ */
+
+void exit_handler(void)
+{
+       /********************* Debug-Tabellen ausgeben ************************/
+                               
+       if (showmethods) class_showmethods (topclass);
+       if (showconstantpool)  class_showconstantpool (topclass);
+       if (showunicode)       unicode_show ();
+
+#ifdef USE_THREADS
+       clear_thread_flags();           /* restores standard file descriptor
+                                                                  flags */
+#endif
+
+       /************************ Freigeben aller Resourcen *******************/
+
+       heap_close ();                          /* must be called before compiler_close and
+                                                                  loader_close because finalization occurs
+                                                                  here */
+
+#ifdef OLD_COMPILER
+       compiler_close ();
+#endif
+       loader_close ();
+       unicode_close ( literalstring_free );
+
+       if (verbose || getcompilingtime || statistics) {
+               log_text ("CACAO terminated");
+               if (statistics)
+                       print_stats ();
+               if (getcompilingtime)
+                       print_times ();
+               mem_usagelog(1);
+       }
+}
 
 /************************** Funktion: main *******************************
 
@@ -444,12 +493,10 @@ void class_compile_methods ()
    
 **************************************************************************/
 
-
 int main(int argc, char **argv)
 {
        s4 i,j;
        char *cp;
-       classinfo *topclass;
        java_objectheader *exceptionptr;
        void *dummy;
        
@@ -459,9 +506,6 @@ int main(int argc, char **argv)
        u4 heapsize = 16000000;
        u4 heapstartsize = 200000;
        char classpath[500] = ".:/usr/local/lib/java/classes";
-       bool showmethods = false;
-       bool showconstantpool = false;
-       bool showunicode = false;
        bool startit = true;
        char *specificmethodname = NULL;
        char *specificsignature = NULL;
@@ -469,11 +513,9 @@ int main(int argc, char **argv)
 #ifndef USE_THREADS
        stackbottom = &dummy;
 #endif
-
-
-#ifdef USE_THREADS
-       atexit(clear_thread_flags);
-#endif
+       
+       if (0 != atexit(exit_handler))
+               panic("unable to register exit_handler");
 
        /************ Infos aus der Environment lesen ************************/
 
@@ -636,6 +678,10 @@ int main(int argc, char **argv)
                        }
                        break;
                        
+               case OPT_OLOOP:
+                       opt_loops = true;
+                       break;
+
                default:
                        print_usage();
                        exit(10);
@@ -718,8 +764,10 @@ int main(int argc, char **argv)
                        printf ("\n");
                }
 
-               /*              killThread(currentThread); */
-
+#ifdef USE_THREADS
+               killThread(currentThread);
+#endif
+               fprintf(stderr, "still here\n");
        }
 
        /************* Auf Wunsch alle Methode "ubersetzen ********************/
@@ -751,39 +799,7 @@ int main(int argc, char **argv)
 #endif
        }
 
-       /********************* Debug-Tabellen ausgeben ************************/
-                               
-       if (showmethods) class_showmethods (topclass);
-       if (showconstantpool)  class_showconstantpool (topclass);
-       if (showunicode)       unicode_show ();
-
-   
-
-       /************************ Freigeben aller Resourcen *******************/
-
-       heap_close ();                          /* must be called before compiler_close and
-                                                                  loader_close because finalization occurs
-                                                                  here */
-#ifdef OLD_COMPILER
-       compiler_close ();
-#endif
-       loader_close ();
-       unicode_close ( literalstring_free );
-
-
-       /* Endemeldung ausgeben und mit entsprechendem exit-Status terminieren */
-
-       if (verbose || getcompilingtime || statistics) {
-               log_text ("CACAO terminated");
-               if (statistics)
-                       print_stats ();
-               if (getcompilingtime)
-                       print_times ();
-               mem_usagelog(1);
-       }
-               
        exit(0);
-       return 1;
 }
 
 
@@ -808,7 +824,7 @@ void cacao_shutdown(s4 status)
                sprintf (logtext, "Exit status: %d\n", (int) status);
                dolog();
                }
-               
+
        exit(status);
 }