Removed gc function definitions.
[cacao.git] / main.c
diff --git a/main.c b/main.c
index 05aac765ea9d5ab18dcb23c6392b555dca14fd12..20e7d8f0909c7aa2e8357ede388b46ed9a6f6f05 100644 (file)
--- a/main.c
+++ b/main.c
@@ -37,7 +37,7 @@
      - Calling the class loader
      - Running the main method
 
-   $Id: main.c 1359 2004-07-28 10:48:36Z twisti $
+   $Id: main.c 1505 2004-11-14 14:15:58Z jowenn $
 
 */
 
@@ -263,6 +263,7 @@ static void print_usage()
        printf("                 u(tf) ......... show the utf - hash\n");
        printf("          -i     n ............. activate inlining\n");
        printf("                 v ............. inline virtual methods\n");
+       printf("                                 uses/turns rt option on\n");
        printf("                 e ............. inline methods with exceptions\n");
        printf("                 p ............. optimize argument renaming\n");
        printf("                 o ............. inline methods of foreign classes\n");
@@ -350,18 +351,19 @@ int main(int argc, char **argv)
 
        /************ Collect info from the environment ************************/
 
-       classpath = MNEW(u1, 2);
+       /* set an initial, minimal classpath */
+       classpath = MNEW(char, 2);
        strcpy(classpath, ".");
 
        /* get classpath environment */
        cp = getenv("CLASSPATH");
        if (cp) {
                classpath = MREALLOC(classpath,
-                                                        u1,
+                                                        char,
                                                         strlen(classpath),
                                                         strlen(classpath) + 1 + strlen(cp) + 1);
                strcat(classpath, ":");
-               strncat(classpath, cp, strlen(cp));
+               strcat(classpath, cp);
        }
 
        /***************** Interpret the command line *****************/
@@ -374,12 +376,11 @@ int main(int argc, char **argv)
                case OPT_IGNORE: break;
                        
                case OPT_CLASSPATH:
-                       classpath = MREALLOC(classpath,
-                                                                u1,
-                                                                strlen(classpath),
-                                                                strlen(classpath) + 1 + strlen(opt_arg) + 1);
-                       strcat(classpath, ":");
-                       strncat(classpath, opt_arg, strlen(opt_arg));
+                       /* forget old classpath and set the argument as new classpath */
+                       MFREE(classpath, char, strlen(classpath));
+
+                       classpath = MNEW(char, strlen(opt_arg) + 1);
+                       strcpy(classpath, opt_arg);
                        break;
                                
                case OPT_D:
@@ -389,7 +390,7 @@ int main(int argc, char **argv)
                                for (n = 0; n < l; n++) {
                                        if (opt_arg[n] == '=') {
                                                opt_arg[n] = '\0';
-                                               attach_property(opt_arg, opt_arg + n + 1);
+                                               create_property(opt_arg, opt_arg + n + 1);
                                                goto didit;
                                        }
                                }
@@ -557,10 +558,17 @@ int main(int argc, char **argv)
                        for (j = 0; j < strlen(opt_arg); j++) {         
                                switch (opt_arg[j]) {
                                case 'n':
+                                    /* define in options.h; Used in main.c, jit.c & inline.c */
+                                    #ifdef INAFTERMAIN
+                                       useinliningm = true;
+                                       useinlining = false;
+                                    #else
                                        useinlining = true;
+                                    #endif
                                        break;
                                case 'v':
                                        inlinevirtuals = true;
+                                       opt_rt = true;
                                        break;
                                case 'e':
                                        inlineexceptions = true;
@@ -595,8 +603,7 @@ int main(int argc, char **argv)
                        exit(10);
                }
        }
-   
-   
+
        if (opt_ind >= argc) {
                print_usage();
                exit(10);
@@ -622,9 +629,12 @@ int main(int argc, char **argv)
 
        cacao_initializing = true;
 
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+#if defined(USE_THREADS)
+#if defined(NATIVE_THREADS)
        initThreadsEarly();
 #endif
+       initLocks();
+#endif
 
        /* install architecture dependent signal handler used for exceptions */
        init_exceptions();
@@ -637,7 +647,8 @@ int main(int argc, char **argv)
        jit_init();
 
        /* initialize exceptions used in the system */
-       init_system_exceptions();
+       if (!init_system_exceptions())
+               throw_main_exception_exit();
 
        native_loadclasses();
 
@@ -655,13 +666,17 @@ int main(int argc, char **argv)
        if (!class_init(class_new(utf_new_char("java/lang/System"))))
                throw_main_exception_exit();
 
+       
+       
+/*        jni_init(); */
        cacao_initializing = false;
 
        /************************* Start worker routines ********************/
 
        if (startit) {
                methodinfo *mainmethod;
-               java_objectarray *a; 
+               java_objectarray *a;
+                s4 result=0; 
 
                /* create, load and link the main class */
                mainclass = class_new(utf_new_char(mainstring));
@@ -709,8 +724,10 @@ int main(int argc, char **argv)
                asm_calljavafunction(mainmethod, a, NULL, NULL, NULL);
 
                /* exception occurred? */
-               if (*exceptionptr)
+               if (*exceptionptr) {
+                        result=1;
                        throw_main_exception();
+                }
 
 #if defined(USE_THREADS)
 #if defined(NATIVE_THREADS)
@@ -722,7 +739,7 @@ int main(int argc, char **argv)
 
                /* now exit the JavaVM */
 
-               cacao_exit(0);
+               cacao_exit(result);
        }
 
        /************* If requested, compile all methods ********************/
@@ -870,7 +887,7 @@ void cacao_exit(s4 status)
        if (!m)
                throw_main_exception_exit();
 
-       asm_calljavafunction(m, rt, (void *) 0, NULL, NULL);
+       asm_calljavafunction(m, rt, (void *) status, NULL, NULL);
 
        /* this should never happen */
 
@@ -888,16 +905,9 @@ void cacao_exit(s4 status)
 
 void cacao_shutdown(s4 status)
 {
-       /**** RTAprint ***/
-
        if (verbose || getcompilingtime || opt_stat) {
                log_text("CACAO terminated by shutdown");
-               if (opt_stat)
-                       print_stats();
-               if (getcompilingtime)
-                       print_times();
-               mem_usagelog(0);
-               dolog("Exit status: %d\n", (int) status);
+               dolog("Exit status: %d\n", (s4) status);
        }
 
        exit(status);