some words for intro and overview by andi
[cacao.git] / main.c
diff --git a/main.c b/main.c
index b1f3ad3ab18cf20135545fd4678563f7c57e9378..db5e48b7764e84f7c74702248c913f5450372579 100644 (file)
--- a/main.c
+++ b/main.c
@@ -37,7 +37,7 @@
      - Calling the class loader
      - Running the main method
 
-   $Id: main.c 964 2004-03-15 14:52:43Z jowenn $
+   $Id: main.c 1009 2004-03-31 22:44:07Z edwin $
 
 */
 
@@ -614,7 +614,7 @@ int main(int argc, char **argv)
        /********** interne (nur fuer main relevante Optionen) **************/
    
        char logfilename[200] = "";
-       u4 heapsize = 64000000;
+       u4 heapmaxsize = 64000000;
        u4 heapstartsize = 200000;
        char classpath[500] = ".";
        bool startit = true;
@@ -677,7 +677,7 @@ int main(int argc, char **argv)
                        }
                        else j = atoi(opt_arg);
                                
-                       if (i == OPT_MX) heapsize = j;
+                       if (i == OPT_MX) heapmaxsize = j;
                        else heapstartsize = j;
                        break;
 
@@ -873,19 +873,30 @@ int main(int argc, char **argv)
                log_text("CACAO started -------------------------------------------------------");
        }
 
+       /* initalize the gc heap */
+       heap_init(heapmaxsize, heapstartsize);
+
        native_setclasspath(classpath);
                
        tables_init();
        suck_init(classpath);
 
-       heap_init(heapsize, heapstartsize, &dummy);
-
        jit_init();
 
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+       initThreadsEarly();
+#endif
+
        loader_init((u1 *) &dummy);
 
        native_loadclasses();
 
+       /* initialize the garbage collector */
+       gc_init();
+
+#if defined(USE_THREADS)
+       initThreads((u1*) &dummy);
+#endif
 
        /*********************** Load JAVA classes  ***************************/
    
@@ -894,18 +905,7 @@ int main(int argc, char **argv)
        /*class_showmethods(topclass);  */
 
        if (*exceptionptr) {
-               printf("Exception in thread \"main\" ");
-               utf_display_classname((*exceptionptr)->vftbl->class->name);
-               printf(": ");
-               utf_display(javastring_toutf(((java_lang_Throwable *) *exceptionptr)->detailMessage, false));
-               printf("\n");
-
-               *exceptionptr = NULL;
-       }
-
-       if (topclass == 0) {
-               /* should we print something out? we already have the exception */
-               exit(1);
+               throw_exception_exit();
        }
 
        /* initialize the garbage collector */
@@ -924,9 +924,11 @@ int main(int argc, char **argv)
 
 /*             heap_addreference((void**) &a); */
 
-               mainmethod = class_findmethod(topclass,
+               mainmethod = class_resolveclassmethod(topclass,
                                                                          utf_new_char("main"), 
-                                                                         utf_new_char("([Ljava/lang/String;)V")
+                                                                         utf_new_char("([Ljava/lang/String;)V"),
+                                                                               topclass,
+                                                                               true
                                                                          );
 
                /* there is no main method or it isn't static */
@@ -947,35 +949,45 @@ int main(int argc, char **argv)
 #endif
                /*class_showmethods(currentThread->group->header.vftbl->class); */
 
-               *threadrootmethod=mainmethod;
+               *threadrootmethod = mainmethod;
+
                /* here we go... */
                asm_calljavafunction(mainmethod, a, NULL, NULL, NULL);
        
                if (*exceptionptr) {
-                       methodinfo *main_unhandled_print=class_resolvemethod_approx((*exceptionptr)->vftbl->class,
-                               utf_new_char("printStackTrace"),
-                               utf_new_char("()V"));
+                       methodinfo *main_unhandled_print =
+                               class_resolvemethod_approx((*exceptionptr)->vftbl->class,
+                                                                                  utf_new_char("printStackTrace"),
+                                                                                  utf_new_char("()V"));
+
                        if (main_unhandled_print) {
-                               java_objectheader *exo=*exceptionptr;
-                               *exceptionptr=0;
-                               asm_calljavafunction(main_unhandled_print,exo,NULL,NULL,NULL);
+                               java_objectheader *exo = *exceptionptr;
+                               *exceptionptr = NULL;
+                               asm_calljavafunction(main_unhandled_print, exo, NULL, NULL, NULL);
+
                        } else {
+                               java_lang_String *msg;
+
                                printf("Exception in thread \"main\" ");
                                utf_display_classname((*exceptionptr)->vftbl->class->name);
 
                                /* do we have a detail message? */
-                               if (((java_lang_Throwable *) *exceptionptr)->detailMessage) {
+                               msg = ((java_lang_Throwable *) *exceptionptr)->detailMessage;
+                               if (msg) {
                                        printf(": ");
-                               utf_display(javastring_toutf(((java_lang_Throwable *) *exceptionptr)->detailMessage, false));
+                                       utf_display(javastring_toutf(msg, false));
                                }
                                printf("\n");
                        }
                }
 
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
+#if defined(USE_THREADS)
+#if defined(NATIVE_THREADS)
+               joinAllThreads();
+#else
                killThread(currentThread);
                fprintf(stderr, "still here\n");
-
+#endif
 #endif
                exit(0);
        }