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