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