exception handling and parser bug fixed
[cacao.git] / src / cacao / cacao.c
1 /* main.c **********************************************************************
2
3         Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
4
5         See file COPYRIGHT for information on usage and disclaimer of warranties
6
7         Enthaelt die Funktion main() und die Variablen fuer die 
8         globalen Optionen.
9         Dieser Modul erledigt folgende Aufgaben:
10            - Bearbeiten der command-line-options
11            - Aufrufen aller Initialisierungsroutinen
12            - Aufrufen des Classloaders
13            - Starten der main - Methode
14
15         Authors: Reinhard Grafl      EMAIL: cacao@complang.tuwien.ac.at
16         Changes: Andi Krall          EMAIL: cacao@complang.tuwien.ac.at
17                  Mark Probst         EMAIL: cacao@complang.tuwien.ac.at
18                          Philipp Tomsich     EMAIL: cacao@complang.tuwien.ac.at
19
20         Last Change: $Id: cacao.c 139 1999-11-11 19:21:30Z andi $
21
22 *******************************************************************************/
23
24 #include "global.h"
25
26 #include "tables.h"
27 #include "loader.h"
28 #include "jit.h"
29 #ifdef OLD_COMPILER
30 #include "compiler.h"
31 #endif
32
33 #include "asmpart.h"
34 #include "builtin.h"
35 #include "native.h"
36
37 #include "threads/thread.h"
38
39 bool compileall = false;
40 int  newcompiler = true;                
41 bool verbose =  false;
42 #ifdef NEW_GC
43 bool new_gc = false;
44 #endif
45
46 static bool showmethods = false;
47 static bool showconstantpool = false;
48 static bool showutf = false;
49 static classinfo *topclass;
50
51 #ifndef USE_THREADS
52 void **stackbottom = 0;
53 #endif
54
55
56 /* internal function: get_opt *************************************************
57         
58         decodes the next command line option
59         
60 ******************************************************************************/
61
62 #define OPT_DONE  -1
63 #define OPT_ERROR  0
64 #define OPT_IGNORE 1
65
66 #define OPT_CLASSPATH   2
67 #define OPT_D           3
68 #define OPT_MS          4
69 #define OPT_MX          5
70 #define OPT_VERBOSE1    6
71 #define OPT_VERBOSE     7
72 #define OPT_VERBOSEGC   8
73 #define OPT_VERBOSECALL 9
74 #define OPT_IEEE        10
75 #define OPT_SOFTNULL    11
76 #define OPT_TIME        12
77 #define OPT_STAT        13
78 #define OPT_LOG         14
79 #define OPT_CHECK       15
80 #define OPT_LOAD        16
81 #define OPT_METHOD      17
82 #define OPT_SIGNATURE   18
83 #define OPT_SHOW        19
84 #define OPT_ALL         20
85 #ifdef OLD_COMPILER
86 #define OPT_OLD         21
87 #endif
88 #ifdef NEW_GC
89 #define OPT_GC1         22
90 #define OPT_GC2         23
91 #endif
92 #define OPT_OLOOP       24
93
94 struct {char *name; bool arg; int value;} opts[] = {
95         {"classpath",   true,   OPT_CLASSPATH},
96         {"D",           true,   OPT_D},
97         {"ms",          true,   OPT_MS},
98         {"mx",          true,   OPT_MX},
99         {"noasyncgc",   false,  OPT_IGNORE},
100         {"noverify",    false,  OPT_IGNORE},
101         {"oss",         true,   OPT_IGNORE},
102         {"ss",          true,   OPT_IGNORE},
103         {"v",           false,  OPT_VERBOSE1},
104         {"verbose",     false,  OPT_VERBOSE},
105         {"verbosegc",   false,  OPT_VERBOSEGC},
106         {"verbosecall", false,  OPT_VERBOSECALL},
107         {"ieee",        false,  OPT_IEEE},
108         {"softnull",    false,  OPT_SOFTNULL},
109         {"time",        false,  OPT_TIME},
110         {"stat",        false,  OPT_STAT},
111         {"log",         true,   OPT_LOG},
112         {"c",           true,   OPT_CHECK},
113         {"l",           false,  OPT_LOAD},
114         {"m",           true,   OPT_METHOD},
115         {"sig",         true,   OPT_SIGNATURE},
116         {"s",           true,   OPT_SHOW},
117         {"all",         false,  OPT_ALL},
118 #ifdef OLD_COMPILER
119         {"old",         false,  OPT_OLD},
120 #endif
121 #ifdef NEW_GC
122         {"gc1",         false,  OPT_GC1},
123         {"gc2",         false,  OPT_GC2},
124 #endif
125         {"oloop",       false,  OPT_OLOOP},
126         {NULL,  false, 0}
127 };
128
129 static int opt_ind = 1;
130 static char *opt_arg;
131
132 static int get_opt (int argc, char **argv) 
133 {
134         char *a;
135         int i;
136         
137         if (opt_ind >= argc) return OPT_DONE;
138         
139         a = argv[opt_ind];
140         if (a[0] != '-') return OPT_DONE;
141
142         for (i=0; opts[i].name; i++) {
143                 if (! opts[i].arg) {
144                         if (strcmp(a+1, opts[i].name) == 0) {  /* boolean option found */
145                                 opt_ind++;
146                                 return opts[i].value;
147                         }
148                 }
149                 else {
150                         if (strcmp(a+1, opts[i].name) == 0) { /* parameter option found */
151                                 opt_ind++;
152                                 if (opt_ind < argc) {
153                                         opt_arg = argv[opt_ind];
154                                         opt_ind++;
155                                         return opts[i].value;
156                                 }
157                                 return OPT_ERROR;
158                         }
159                         else {
160                                 size_t l = strlen(opts[i].name);
161                                 if (strlen(a+1) > l) {
162                                         if (memcmp (a+1, opts[i].name, l)==0) {
163                                                 opt_ind++;
164                                                 opt_arg = a+1+l;
165                                                 return opts[i].value;
166                                         }
167                                 }
168                         }
169                 }
170         } /* end for */ 
171
172         return OPT_ERROR;
173 }
174
175
176
177
178 /******************** interne Funktion: print_usage ************************
179
180 Gibt die richtige Aufrufsyntax des JavaVM-Compilers auf stdout aus.
181
182 ***************************************************************************/
183
184 static void print_usage()
185 {
186         printf ("USAGE: cacao [options] classname [program arguments\n");
187         printf ("Options:\n");
188         printf ("          -classpath path ...... specify a path to look for classes\n");
189         printf ("          -Dpropertyname=value . add an entry to the property list\n");
190         printf ("          -mx maxmem[k|m] ...... specify the size for the heap\n");
191         printf ("          -ms initmem[k|m] ..... specify the initial size for the heap\n");
192         printf ("          -v ................... write state-information\n");
193         printf ("          -verbose ............. write more information\n");
194         printf ("          -verbosegc ........... write message for each GC\n");
195         printf ("          -verbosecall ......... write message for each call\n");
196         printf ("          -ieee ................ use ieee compliant arithmetic\n");
197         printf ("          -softnull ............ use software nullpointer check\n");
198         printf ("          -time ................ measure the runtime\n");
199         printf ("          -stat ................ detailed compiler statistics\n");
200         printf ("          -log logfile ......... specify a name for the logfile\n");
201         printf ("          -c(heck)b(ounds) ..... don't check array bounds\n");
202         printf ("                  s(ync) ....... don't check for synchronization\n");
203         printf ("          -oloop ............... optimize array accesses in loops\n"); 
204         printf ("          -l ................... don't start the class after loading\n");
205         printf ("          -all ................. compile all methods, no execution\n");
206 #ifdef OLD_COMPILER
207         printf ("          -old ................. use old JIT compiler\n");
208 #endif
209 #ifdef NEW_GC
210         printf ("          -gc1 ................. use the old garbage collector (default)\n");
211         printf ("          -gc2 ................. use the new garbage collector\n");
212 #endif
213         printf ("          -m ................... compile only a specific method\n");
214         printf ("          -sig ................. specify signature for a specific method\n");
215         printf ("          -s(how)a(ssembler) ... show disassembled listing\n");
216         printf ("                 c(onstants) ... show the constant pool\n");
217         printf ("                 d(atasegment).. show data segment listing\n");
218         printf ("                 i(ntermediate). show intermediate representation\n");
219         printf ("                 m(ethods)...... show class fields and methods\n");
220 #ifdef OLD_COMPILER
221         printf ("                 s(tack) ....... show stack for every javaVM-command\n");
222 #endif
223         printf ("                 u(tf) ......... show the utf - hash\n");
224 }   
225
226
227
228 /***************************** Funktion: print_times *********************
229
230         gibt eine Aufstellung der verwendeten CPU-Zeit aus
231
232 **************************************************************************/
233
234 static void print_times()
235 {
236         long int totaltime = getcputime();
237         long int runtime = totaltime - loadingtime - compilingtime;
238
239         sprintf (logtext, "Time for loading classes: %ld secs, %ld millis",
240              loadingtime / 1000000, (loadingtime % 1000000) / 1000);
241         dolog();
242         sprintf (logtext, "Time for compiling code:  %ld secs, %ld millis",
243              compilingtime / 1000000, (compilingtime % 1000000) / 1000);
244         dolog();
245         sprintf (logtext, "Time for running program: %ld secs, %ld millis",
246              runtime / 1000000, (runtime % 1000000) / 1000);
247         dolog();
248         sprintf (logtext, "Total time: %ld secs, %ld millis",
249              totaltime / 1000000, (totaltime % 1000000) / 1000);
250         dolog();
251 }
252
253
254
255
256
257
258 /***************************** Funktion: print_stats *********************
259
260         outputs detailed compiler statistics
261
262 **************************************************************************/
263
264 static void print_stats()
265 {
266         sprintf (logtext, "Number of JitCompiler Calls: %d", count_jit_calls);
267         dolog();
268         sprintf (logtext, "Number of compiled Methods: %d", count_methods);
269         dolog();
270         sprintf (logtext, "Number of max basic blocks per method: %d", count_max_basic_blocks);
271         dolog();
272         sprintf (logtext, "Number of compiled basic blocks: %d", count_basic_blocks);
273         dolog();
274         sprintf (logtext, "Number of max JavaVM-Instructions per method: %d", count_max_javainstr);
275         dolog();
276         sprintf (logtext, "Number of compiled JavaVM-Instructions: %d", count_javainstr);
277         dolog();
278         sprintf (logtext, "Size of compiled JavaVM-Instructions:   %d(%d)", count_javacodesize,
279                                                       count_javacodesize - count_methods * 18);
280         dolog();
281         sprintf (logtext, "Size of compiled Exception Tables:      %d", count_javaexcsize);
282         dolog();
283         sprintf (logtext, "Value of extended instruction set var:  %d", has_ext_instr_set);
284         dolog();
285         sprintf (logtext, "Number of Alpha-Instructions: %d", count_code_len >> 2);
286         dolog();
287         sprintf (logtext, "Number of Spills: %d", count_spills);
288         dolog();
289         sprintf (logtext, "Number of Activ    Pseudocommands: %5d", count_pcmd_activ);
290         dolog();
291         sprintf (logtext, "Number of Drop     Pseudocommands: %5d", count_pcmd_drop);
292         dolog();
293         sprintf (logtext, "Number of Const    Pseudocommands: %5d (zero:%5d)", count_pcmd_load, count_pcmd_zero);
294         dolog();
295         sprintf (logtext, "Number of ConstAlu Pseudocommands: %5d (cmp: %5d, store:%5d)", count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
296         dolog();
297         sprintf (logtext, "Number of Move     Pseudocommands: %5d", count_pcmd_move);
298         dolog();
299         sprintf (logtext, "Number of Load     Pseudocommands: %5d", count_load_instruction);
300         dolog();
301         sprintf (logtext, "Number of Store    Pseudocommands: %5d (combined: %5d)", count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
302         dolog();
303         sprintf (logtext, "Number of OP       Pseudocommands: %5d", count_pcmd_op);
304         dolog();
305         sprintf (logtext, "Number of DUP      Pseudocommands: %5d", count_dup_instruction);
306         dolog();
307         sprintf (logtext, "Number of Mem      Pseudocommands: %5d", count_pcmd_mem);
308         dolog();
309         sprintf (logtext, "Number of Method   Pseudocommands: %5d", count_pcmd_met);
310         dolog();
311         sprintf (logtext, "Number of Branch   Pseudocommands: %5d (rets:%5d, Xrets: %5d)",
312                           count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
313         dolog();
314         sprintf (logtext, "Number of Table    Pseudocommands: %5d", count_pcmd_table);
315         dolog();
316         sprintf (logtext, "Number of Useful   Pseudocommands: %5d", count_pcmd_table +
317                  count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
318         dolog();
319         sprintf (logtext, "Number of Null Pointer Checks:     %5d", count_check_null);
320         dolog();
321         sprintf (logtext, "Number of Array Bound Checks:      %5d", count_check_bound);
322         dolog();
323         sprintf (logtext, "Number of Try-Blocks: %d", count_tryblocks);
324         dolog();
325         sprintf (logtext, "Maximal count of stack elements:   %d", count_max_new_stack);
326         dolog();
327         sprintf (logtext, "Upper bound of max stack elements: %d", count_upper_bound_new_stack);
328         dolog();
329         sprintf (logtext, "Distribution of stack sizes at block boundary");
330         dolog();
331         sprintf (logtext, "    0    1    2    3    4    5    6    7    8    9    >=10");
332         dolog();
333         sprintf (logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_block_stack[0],
334                 count_block_stack[1],count_block_stack[2],count_block_stack[3],count_block_stack[4],
335                 count_block_stack[5],count_block_stack[6],count_block_stack[7],count_block_stack[8],
336                 count_block_stack[9],count_block_stack[10]);
337         dolog();
338         sprintf (logtext, "Distribution of store stack depth");
339         dolog();
340         sprintf (logtext, "    0    1    2    3    4    5    6    7    8    9    >=10");
341         dolog();
342         sprintf (logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_depth[0],
343                 count_store_depth[1],count_store_depth[2],count_store_depth[3],count_store_depth[4],
344                 count_store_depth[5],count_store_depth[6],count_store_depth[7],count_store_depth[8],
345                 count_store_depth[9],count_store_depth[10]);
346         dolog();
347         sprintf (logtext, "Distribution of store creator chains first part");
348         dolog();
349         sprintf (logtext, "    0    1    2    3    4    5    6    7    8    9  ");
350         dolog();
351         sprintf (logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_length[0],
352                 count_store_length[1],count_store_length[2],count_store_length[3],count_store_length[4],
353                 count_store_length[5],count_store_length[6],count_store_length[7],count_store_length[8],
354                 count_store_length[9]);
355         dolog();
356         sprintf (logtext, "Distribution of store creator chains second part");
357         dolog();
358         sprintf (logtext, "   10   11   12   13   14   15   16   17   18   19  >=20");
359         dolog();
360         sprintf (logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_length[10],
361                 count_store_length[11],count_store_length[12],count_store_length[13],count_store_length[14],
362                 count_store_length[15],count_store_length[16],count_store_length[17],count_store_length[18],
363                 count_store_length[19],count_store_length[20]);
364         dolog();
365         sprintf (logtext, "Distribution of analysis iterations");
366         dolog();
367         sprintf (logtext, "    1    2    3    4    >=5");
368         dolog();
369         sprintf (logtext, "%5d%5d%5d%5d%5d", count_analyse_iterations[0],count_analyse_iterations[1],
370                 count_analyse_iterations[2],count_analyse_iterations[3],count_analyse_iterations[4]);
371         dolog();
372         sprintf (logtext, "Distribution of basic blocks per method");
373         dolog();
374         sprintf (logtext, " <= 5 <=10 <=15 <=20 <=30 <=40 <=50 <=75  >75");
375         dolog();
376         sprintf (logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_method_bb_distribution[0],
377                 count_method_bb_distribution[1],count_method_bb_distribution[2],count_method_bb_distribution[3],
378                 count_method_bb_distribution[4],count_method_bb_distribution[5],count_method_bb_distribution[6],
379                 count_method_bb_distribution[7],count_method_bb_distribution[8]);
380         dolog();
381         sprintf (logtext, "Distribution of basic block sizes");
382         dolog();
383         sprintf (logtext,
384         "  0    1    2    3    4   5   6   7   8   9 <13 <15 <17 <19 <21 <26 <31 >30");
385         dolog();
386         sprintf (logtext, "%3d%5d%5d%5d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d",
387                 count_block_size_distribution[0], count_block_size_distribution[1], count_block_size_distribution[2],
388                 count_block_size_distribution[3], count_block_size_distribution[4], count_block_size_distribution[5],
389                 count_block_size_distribution[6], count_block_size_distribution[7], count_block_size_distribution[8],
390                 count_block_size_distribution[9], count_block_size_distribution[10],count_block_size_distribution[11],
391                 count_block_size_distribution[12],count_block_size_distribution[13],count_block_size_distribution[14],
392                 count_block_size_distribution[15],count_block_size_distribution[16],count_block_size_distribution[17]);
393         dolog();
394         sprintf (logtext, "Size of Code Area (Kb):  %10.3f", (float) count_code_len / 1024);
395         dolog();
396         sprintf (logtext, "Size of data Area (Kb):  %10.3f", (float) count_data_len / 1024);
397         dolog();
398         sprintf (logtext, "Size of Class Infos (Kb):%10.3f", (float) (count_class_infos) / 1024);
399         dolog();
400         sprintf (logtext, "Size of Const Pool (Kb): %10.3f", (float) (count_const_pool_len + count_utf_len) / 1024);
401         dolog();
402         sprintf (logtext, "Size of Vftbl (Kb):      %10.3f", (float) count_vftbl_len / 1024);
403         dolog();
404         sprintf (logtext, "Size of comp stub (Kb):  %10.3f", (float) count_cstub_len / 1024);
405         dolog();
406         sprintf (logtext, "Size of native stub (Kb):%10.3f", (float) count_nstub_len / 1024);
407         dolog();
408         sprintf (logtext, "Size of Utf (Kb):        %10.3f", (float) count_utf_len / 1024);
409         dolog();
410         sprintf (logtext, "Size of VMCode (Kb):     %10.3f(%d)", (float) count_vmcode_len / 1024,
411                                                       count_vmcode_len - 18 * count_all_methods);
412         dolog();
413         sprintf (logtext, "Size of ExTable (Kb):    %10.3f", (float) count_extable_len / 1024);
414         dolog();
415         sprintf (logtext, "Number of class loads:   %d", count_class_loads);
416         dolog();
417         sprintf (logtext, "Number of class inits:   %d", count_class_inits);
418         dolog();
419         sprintf (logtext, "Number of loaded Methods: %d\n\n", count_all_methods);
420         dolog();
421
422         sprintf (logtext, "Calls of utf_new: %22d", count_utf_new);
423         dolog();
424         sprintf (logtext, "Calls of utf_new (element found): %6d\n\n", count_utf_new_found);
425         dolog();
426 }
427
428
429 /********** Funktion: class_compile_methods   (nur f"ur Debug-Zwecke) ********/
430
431 void class_compile_methods ()
432 {
433         int        i;
434         classinfo  *c;
435         methodinfo *m;
436         
437         c = list_first (&linkedclasses);
438         while (c) {
439                 for (i = 0; i < c -> methodscount; i++) {
440                         m = &(c->methods[i]);
441                         if (m->jcode) {
442 #ifdef OLD_COMPILER
443                                 if (newcompiler)
444 #endif
445                                         (void) jit_compile(m);
446 #ifdef OLD_COMPILER
447                                 else
448                                         (void) compiler_compile(m);
449 #endif
450                                 }
451                         }
452                 c = list_next (&linkedclasses, c);
453                 }
454 }
455
456 /*
457  * void exit_handler(void)
458  * -----------------------
459  * The exit_handler function is called upon program termination to shutdown
460  * the various subsystems and release the resources allocated to the VM.
461  */
462
463 void exit_handler(void)
464 {
465         /********************* Debug-Tabellen ausgeben ************************/
466                                 
467         if (showmethods) class_showmethods (topclass);
468         if (showconstantpool)  class_showconstantpool (topclass);
469         if (showutf)           utf_show ();
470
471 #ifdef USE_THREADS
472         clear_thread_flags();           /* restores standard file descriptor
473                                                                    flags */
474 #endif
475
476         /************************ Freigeben aller Resourcen *******************/
477
478         heap_close ();                          /* must be called before compiler_close and
479                                                                    loader_close because finalization occurs
480                                                                    here */
481
482 #ifdef OLD_COMPILER
483         compiler_close ();
484 #endif
485         loader_close ();
486         tables_close ( literalstring_free );
487
488         if (verbose || getcompilingtime || statistics) {
489                 log_text ("CACAO terminated");
490                 if (statistics)
491                         print_stats ();
492                 if (getcompilingtime)
493                         print_times ();
494                 mem_usagelog(1);
495         }
496 }
497
498 /************************** Funktion: main *******************************
499
500    Das Hauptprogramm.
501    Wird vom System zu Programstart aufgerufen (eh klar).
502    
503 **************************************************************************/
504
505 int main(int argc, char **argv)
506 {
507         s4 i,j;
508         char *cp;
509         java_objectheader *exceptionptr;
510         void *dummy;
511         
512         /********** interne (nur fuer main relevante Optionen) **************/
513    
514         char logfilename[200] = "";
515         u4 heapsize = 16000000;
516         u4 heapstartsize = 200000;
517         char classpath[500] = ".:/usr/local/lib/java/classes";
518         bool startit = true;
519         char *specificmethodname = NULL;
520         char *specificsignature = NULL;
521
522 #ifndef USE_THREADS
523         stackbottom = &dummy;
524 #endif
525         
526         if (0 != atexit(exit_handler))
527                 panic("unable to register exit_handler");
528
529         /************ Infos aus der Environment lesen ************************/
530
531         cp = getenv ("CLASSPATH");
532         if (cp) {
533                 strcpy (classpath, cp);
534         }
535
536         /***************** Interpretieren der Kommandozeile *****************/
537    
538         checknull = false;
539         checkfloats = false;
540
541         while ( (i = get_opt(argc,argv)) != OPT_DONE) {
542
543                 switch (i) {
544                 case OPT_IGNORE: break;
545                         
546                 case OPT_CLASSPATH:    
547                         strcpy (classpath + strlen(classpath), ":");
548                         strcpy (classpath + strlen(classpath), opt_arg);
549                         break;
550                                 
551                 case OPT_D:
552                         {
553                                 int n,l=strlen(opt_arg);
554                                 for (n=0; n<l; n++) {
555                                         if (opt_arg[n]=='=') {
556                                                 opt_arg[n] = '\0';
557                                                 attach_property (opt_arg, opt_arg+n+1);
558                                                 goto didit;
559                                         }
560                                 }
561                                 print_usage();
562                                 exit(10);
563                                         
564                         didit: ;
565                         }       
566                 break;
567                                 
568                 case OPT_MS:
569                 case OPT_MX:
570                         if (opt_arg[strlen(opt_arg)-1] == 'k') {
571                                 j = 1024 * atoi(opt_arg);
572                         }
573                         else if (opt_arg[strlen(opt_arg)-1] == 'm') {
574                                 j = 1024 * 1024 * atoi(opt_arg);
575                         }
576                         else j = atoi(opt_arg);
577                                 
578                         if (i==OPT_MX) heapsize = j;
579                         else heapstartsize = j;
580                         break;
581
582                 case OPT_VERBOSE1:
583                         verbose = true;
584                         break;
585                                                                 
586                 case OPT_VERBOSE:
587                         verbose = true;
588                         loadverbose = true;
589                         initverbose = true;
590                         compileverbose = true;
591                         break;
592                                 
593                 case OPT_VERBOSEGC:
594                         collectverbose = true;
595                         break;
596                                 
597                 case OPT_VERBOSECALL:
598                         runverbose = true;
599                         break;
600                                 
601                 case OPT_IEEE:
602                         checkfloats = true;
603                         break;
604
605                 case OPT_SOFTNULL:
606                         checknull = true;
607                         break;
608
609                 case OPT_TIME:
610                         getcompilingtime = true;
611                         getloadingtime = true;
612                         break;
613                                         
614                 case OPT_STAT:
615                         statistics = true;
616                         break;
617                                         
618                 case OPT_LOG:
619                         strcpy (logfilename, opt_arg);
620                         break;
621                         
622                         
623                 case OPT_CHECK:
624                         for (j=0; j<strlen(opt_arg); j++) {
625                                 switch (opt_arg[j]) {
626                                 case 'b': checkbounds=false; break;
627                                 case 's': checksync=false; break;
628                                 default:  print_usage();
629                                         exit(10);
630                                 }
631                         }
632                         break;
633                         
634                 case OPT_LOAD:
635                         startit = false;
636                         makeinitializations = false;
637                         break;
638
639                 case OPT_METHOD:
640                         startit = false;
641                         specificmethodname = opt_arg;                   
642                         makeinitializations = false;
643                         break;
644                         
645                 case OPT_SIGNATURE:
646                         specificsignature = opt_arg;                    
647                         break;
648                         
649                 case OPT_ALL:
650                         compileall = true;              
651                         startit = false;
652                         makeinitializations = false;
653                         break;
654                         
655 #ifdef OLD_COMPILER
656                 case OPT_OLD:
657                         newcompiler = false;                    
658                         checknull = true;
659                         break;
660 #endif
661
662 #ifdef NEW_GC
663                 case OPT_GC2:
664                         new_gc = true;
665                         break;
666
667                 case OPT_GC1:
668                         new_gc = false;
669                         break;
670 #endif
671                         
672                 case OPT_SHOW:       /* Anzeigeoptionen */
673                         for (j=0; j<strlen(opt_arg); j++) {             
674                                 switch (opt_arg[j]) {
675                                 case 'a':  showdisassemble=true; compileverbose=true; break;
676                                 case 'c':  showconstantpool=true; break;
677                                 case 'd':  showddatasegment=true; break;
678                                 case 'i':  showintermediate=true; compileverbose=true; break;
679                                 case 'm':  showmethods=true; break;
680 #ifdef OLD_COMPILER
681                                 case 's':  showstack=true; compileverbose=true; break;
682 #endif
683                                 case 'u':  showutf=true; break;
684                                 default:   print_usage();
685                                         exit(10);
686                                 }
687                         }
688                         break;
689                         
690                 case OPT_OLOOP:
691                         opt_loops = true;
692                         break;
693
694                 default:
695                         print_usage();
696                         exit(10);
697                 }
698                         
699                         
700         }
701    
702    
703         if (opt_ind >= argc) {
704                 print_usage ();
705                 exit(10);
706         }
707
708
709         /**************************** Programmstart *****************************/
710
711         log_init (logfilename);
712         if (verbose) {
713                 log_text (
714                                   "CACAO started -------------------------------------------------------");
715         }
716         
717         suck_init (classpath);
718         native_setclasspath (classpath);
719                 
720         tables_init();
721         heap_init(heapsize, heapstartsize, &dummy);
722         loader_init();
723 #ifdef OLD_COMPILER
724         compiler_init();
725 #endif
726         jit_init();
727
728         native_loadclasses ();
729
730
731         /*********************** JAVA-Klassen laden  ***************************/
732    
733         cp = argv[opt_ind++];
734         for (i=strlen(cp)-1; i>=0; i--) {     /* Punkte im Klassennamen */
735                 if (cp[i]=='.') cp[i]='/';        /* auf slashes umbauen */
736         }
737
738         topclass = loader_load ( utf_new_char (cp) );
739
740         gc_init();
741
742 #ifdef USE_THREADS
743         initThreads((u1*)&dummy);                   /* schani */
744 #endif
745
746         /************************* Arbeitsroutinen starten ********************/
747
748         if (startit) {
749                 methodinfo *mainmethod;
750                 java_objectarray *a; 
751
752                 heap_addreference((void**) &a);
753
754                 mainmethod = class_findmethod (
755                                                                            topclass,
756                                                                            utf_new_char ("main"), 
757                                                                            utf_new_char ("([Ljava/lang/String;)V")
758                                                                            );
759                 if (!mainmethod) panic ("Can not find method 'void main(String[])'");
760                 if ((mainmethod->flags & ACC_STATIC) != ACC_STATIC) panic ("main is not static!");
761                         
762                 a = builtin_anewarray (argc - opt_ind, class_java_lang_String);
763                 for (i=opt_ind; i<argc; i++) {
764                         a->data[i-opt_ind] = javastring_new (utf_new_char (argv[i]) );
765                 }
766                 exceptionptr = asm_calljavamethod (mainmethod, a, NULL,NULL,NULL );
767         
768                 if (exceptionptr) {
769                         printf ("#### Program has thrown: ");
770                         utf_display (exceptionptr->vftbl->class->name);
771                         printf ("\n");
772                 }
773
774 #ifdef USE_THREADS
775                 killThread(currentThread);
776 #endif
777                 fprintf(stderr, "still here\n");
778         }
779
780         /************* Auf Wunsch alle Methode "ubersetzen ********************/
781
782         if (compileall) {
783                 class_compile_methods();
784         }
785
786
787         /******** Auf Wunsch eine spezielle Methode "ubersetzen ***************/
788
789         if (specificmethodname) {
790                 methodinfo *m;
791                 if (specificsignature)
792                         m = class_findmethod(topclass, 
793                                                                  utf_new_char(specificmethodname),
794                                                                  utf_new_char(specificsignature));
795                 else
796                         m = class_findmethod(topclass, 
797                                                                  utf_new_char(specificmethodname), NULL);
798                 if (!m) panic ("Specific method not found");
799 #ifdef OLD_COMPILER
800                 if (newcompiler)
801 #endif
802                         (void) jit_compile(m);
803 #ifdef OLD_COMPILER
804                 else
805                         (void) compiler_compile(m);
806 #endif
807         }
808
809         exit(0);
810 }
811
812
813
814 /************************************ SHUTDOWN-Funktion *********************************
815
816         Terminiert das System augenblicklich, ohne den Speicher
817         explizit freizugeben (eigentlich nur f"ur abnorme 
818         Programmterminierung)
819         
820 *****************************************************************************************/
821
822 void cacao_shutdown(s4 status)
823 {
824         if (verbose || getcompilingtime || statistics) {
825                 log_text ("CACAO terminated by shutdown");
826                 if (statistics)
827                         print_stats ();
828                 if (getcompilingtime)
829                         print_times ();
830                 mem_usagelog(0);
831                 sprintf (logtext, "Exit status: %d\n", (int) status);
832                 dolog();
833                 }
834
835         exit(status);
836 }
837
838
839 /*
840  * These are local overrides for various environment variables in Emacs.
841  * Please do not remove this and leave it at the end of the file, where
842  * Emacs will automagically detect them.
843  * ---------------------------------------------------------------------
844  * Local variables:
845  * mode: c
846  * indent-tabs-mode: t
847  * c-basic-offset: 4
848  * tab-width: 4
849  * End:
850  */