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