Linear Scan Register Allocator disabled. (with #ifdef LSRA\...\#endif)
[cacao.git] / src / cacao / cacao.c
1 /* cacao/cacao.c - contains main() of cacao
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 1641 2004-12-01 13:13:31Z christian $
41
42 */
43
44
45 #include <stdlib.h>
46 #include <string.h>
47
48 #include "cacao/cacao.h"
49 #include "mm/boehm.h"
50 #include "mm/memory.h"
51 #include "native/native.h"
52 #include "toolbox/logging.h"
53 #include "vm/exceptions.h"
54 #include "vm/global.h"
55 #include "vm/loader.h"
56 #include "vm/options.h"
57 #include "vm/statistics.h"
58 #include "vm/tables.h"
59 #include "vm/jit/asmpart.h"
60 #include "vm/jit/jit.h"
61
62 #ifdef TYPEINFO_DEBUG_TEST
63 #include "typeinfo.h"
64 #endif
65
66
67 bool cacao_initializing;
68
69 char *classpath;                        /* contains classpath                 */
70 char *mainstring;
71 static classinfo *mainclass;
72
73 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
74 void **stackbottom = 0;
75 #endif
76
77 /* define command line options ************************************************/
78
79 #define OPT_CLASSPATH   2
80 #define OPT_D           3
81 #define OPT_MS          4
82 #define OPT_MX          5
83 #define OPT_VERBOSE1    6
84 #define OPT_VERBOSE     7
85 #define OPT_VERBOSEGC   8
86 #define OPT_VERBOSECALL 9
87 #define OPT_NOIEEE      10
88 #define OPT_SOFTNULL    11
89 #define OPT_TIME        12
90 #define OPT_STAT        13
91 #define OPT_LOG         14
92 #define OPT_CHECK       15
93 #define OPT_LOAD        16
94 #define OPT_METHOD      17
95 #define OPT_SIGNATURE   18
96 #define OPT_SHOW        19
97 #define OPT_ALL         20
98 #define OPT_OLOOP       24
99 #define OPT_INLINING    25
100 #ifdef STATIC_ANALYSIS
101 #define OPT_RT          26
102 #define OPT_XTA         27 
103 #define OPT_VTA         28
104 #endif
105 #define OPT_VERBOSETC   29
106 #define OPT_NOVERIFY    30
107 #define OPT_LIBERALUTF  31
108 #define OPT_VERBOSEEXCEPTION 32
109 #define OPT_EAGER            33
110 #ifdef LSRA
111 #define OPT_LSRA 34
112 #endif
113
114 opt_struct opts[] = {
115         {"classpath",        true,   OPT_CLASSPATH},
116         {"cp",               true,   OPT_CLASSPATH},
117         {"D",                true,   OPT_D},
118         {"Xms",              true,   OPT_MS},
119         {"Xmx",              true,   OPT_MX},
120         {"ms",               true,   OPT_MS},
121         {"mx",               true,   OPT_MX},
122         {"noasyncgc",        false,  OPT_IGNORE},
123         {"noverify",         false,  OPT_NOVERIFY},
124         {"liberalutf",       false,  OPT_LIBERALUTF},
125         {"oss",              true,   OPT_IGNORE},
126         {"ss",               true,   OPT_IGNORE},
127         {"v",                false,  OPT_VERBOSE1},
128         {"verbose",          false,  OPT_VERBOSE},
129         {"verbosegc",        false,  OPT_VERBOSEGC},
130         {"verbosecall",      false,  OPT_VERBOSECALL},
131         {"verboseexception", false,  OPT_VERBOSEEXCEPTION},
132 #ifdef TYPECHECK_VERBOSE
133         {"verbosetc",        false,  OPT_VERBOSETC},
134 #endif
135 #if defined(__ALPHA__)
136         {"noieee",           false,  OPT_NOIEEE},
137 #endif
138         {"softnull",         false,  OPT_SOFTNULL},
139         {"time",             false,  OPT_TIME},
140         {"stat",             false,  OPT_STAT},
141         {"log",              true,   OPT_LOG},
142         {"c",                true,   OPT_CHECK},
143         {"l",                false,  OPT_LOAD},
144     { "eager",            false,  OPT_EAGER },
145         {"m",                true,   OPT_METHOD},
146         {"sig",              true,   OPT_SIGNATURE},
147         {"s",                true,   OPT_SHOW},
148         {"all",              false,  OPT_ALL},
149         {"oloop",            false,  OPT_OLOOP},
150         {"i",                    true,   OPT_INLINING},
151 #ifdef STATIC_ANALYSIS
152         {"rt",               false,  OPT_RT},
153         {"xta",              false,  OPT_XTA},
154         {"vta",              false,  OPT_VTA},
155 #endif
156 #ifdef LSRA
157         {"lsra", false, OPT_LSRA},
158 #endif
159         {NULL,               false,  0}
160 };
161
162
163 /******************** interne Function: print_usage ************************
164
165 Prints the correct usage syntax to stdout.
166
167 ***************************************************************************/
168
169 static void usage()
170 {
171         printf("USAGE: cacao [options] classname [program arguments]\n");
172         printf("Options:\n");
173         printf("          -cp path ............. specify a path to look for classes\n");
174         printf("          -classpath path ...... specify a path to look for classes\n");
175         printf("          -Dpropertyname=value . add an entry to the property list\n");
176         printf("          -Xmx maxmem[kK|mM] ... specify the size for the heap\n");
177         printf("          -Xms initmem[kK|mM] .. specify the initial size for the heap\n");
178         printf("          -mx maxmem[kK|mM] .... specify the size for the heap\n");
179         printf("          -ms initmem[kK|mM] ... specify the initial size for the heap\n");
180         printf("          -v ................... write state-information\n");
181         printf("          -verbose ............. write more information\n");
182         printf("          -verbosegc ........... write message for each GC\n");
183         printf("          -verbosecall ......... write message for each call\n");
184         printf("          -verboseexception .... write message for each step of stack unwinding\n");
185 #ifdef TYPECHECK_VERBOSE
186         printf("          -verbosetc ........... write debug messages while typechecking\n");
187 #endif
188 #if defined(__ALPHA__)
189         printf("          -noieee .............. don't use ieee compliant arithmetic\n");
190 #endif
191         printf("          -noverify ............ don't verify classfiles\n");
192         printf("          -liberalutf........... don't warn about overlong UTF-8 sequences\n");
193         printf("          -softnull ............ use software nullpointer check\n");
194         printf("          -time ................ measure the runtime\n");
195         printf("          -stat ................ detailed compiler statistics\n");
196         printf("          -log logfile ......... specify a name for the logfile\n");
197         printf("          -c(heck)b(ounds) ..... don't check array bounds\n");
198         printf("                  s(ync) ....... don't check for synchronization\n");
199         printf("          -oloop ............... optimize array accesses in loops\n"); 
200         printf("          -l ................... don't start the class after loading\n");
201         printf("          -eager ............... perform eager class loading and linking\n");
202         printf("          -all ................. compile all methods, no execution\n");
203         printf("          -m ................... compile only a specific method\n");
204         printf("          -sig ................. specify signature for a specific method\n");
205         printf("          -s(how)a(ssembler) ... show disassembled listing\n");
206         printf("                 c(onstants) ... show the constant pool\n");
207         printf("                 d(atasegment).. show data segment listing\n");
208         printf("                 i(ntermediate). show intermediate representation\n");
209         printf("                 m(ethods)...... show class fields and methods\n");
210         printf("                 u(tf) ......... show the utf - hash\n");
211         printf("          -i     n ............. activate inlining\n");
212         printf("                 v ............. inline virtual methods\n");
213         printf("                                 uses/turns rt option on\n");
214         printf("                 e ............. inline methods with exceptions\n");
215         printf("                 p ............. optimize argument renaming\n");
216         printf("                 o ............. inline methods of foreign classes\n");
217 #ifdef STATIC_ANALYSIS
218         printf("          -rt .................. use rapid type analysis\n");
219         printf("          -xta ................. use x type analysis\n");
220         printf("          -vta ................. use variable type analysis\n");
221 #endif
222 #ifdef LSRA
223         printf("          -lsra ................ use linear scan register allocation\n");
224 #endif
225
226         /* exit with error code */
227
228         exit(1);
229 }   
230
231
232 #ifdef TYPECHECK_STATISTICS
233 void typecheck_print_statistics(FILE *file);
234 #endif
235
236
237 /*
238  * void exit_handler(void)
239  * -----------------------
240  * The exit_handler function is called upon program termination to shutdown
241  * the various subsystems and release the resources allocated to the VM.
242  */
243 void exit_handler(void)
244 {
245         /********************* Print debug tables ************************/
246                                 
247         if (showmethods) class_showmethods(mainclass);
248         if (showconstantpool) class_showconstantpool(mainclass);
249         if (showutf) utf_show();
250
251 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
252         clear_thread_flags();           /* restores standard file descriptor
253                                        flags */
254 #endif
255
256         /************************ Free all resources *******************/
257
258         loader_close();
259         tables_close();
260
261         MFREE(classpath, u1, strlen(classpath));
262
263         if (opt_verbose || getcompilingtime || opt_stat) {
264                 log_text("CACAO terminated");
265                 if (opt_stat) {
266                         print_stats();
267 #ifdef TYPECHECK_STATISTICS
268                         typecheck_print_statistics(get_logfile());
269 #endif
270                 }
271                 if (getcompilingtime)
272                         print_times();
273                 mem_usagelog(1);
274         }
275 }
276
277
278 /************************** Function: main *******************************
279
280    The main program.
281    
282 **************************************************************************/
283
284 int main(int argc, char **argv)
285 {
286         s4 i, j;
287         void *dummy;
288         
289         /********** interne (nur fuer main relevante Optionen) **************/
290    
291         char logfilename[200] = "";
292         u4 heapmaxsize = 64 * 1024 * 1024;
293         u4 heapstartsize = 200 * 1024;
294         char *cp;
295         bool startit = true;
296         char *specificmethodname = NULL;
297         char *specificsignature = NULL;
298
299 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
300         stackbottom = &dummy;
301 #endif
302         
303         if (atexit(exit_handler))
304                 throw_cacao_exception_exit(string_java_lang_InternalError,
305                                                                    "Unable to register exit_handler");
306
307
308         /************ Collect info from the environment ************************/
309
310         /* set an initial, minimal classpath */
311         classpath = MNEW(char, 2);
312         strcpy(classpath, ".");
313
314         /* get classpath environment */
315         cp = getenv("CLASSPATH");
316         if (cp) {
317                 classpath = MREALLOC(classpath,
318                                                          char,
319                                                          strlen(classpath),
320                                                          strlen(classpath) + 1 + strlen(cp) + 1);
321                 strcat(classpath, ":");
322                 strcat(classpath, cp);
323         }
324
325         /***************** Interpret the command line *****************/
326    
327         checknull = false;
328         opt_noieee = false;
329
330         while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
331                 switch (i) {
332                 case OPT_IGNORE:
333                         break;
334                         
335                 case OPT_CLASSPATH:
336                         /* forget old classpath and set the argument as new classpath */
337                         MFREE(classpath, char, strlen(classpath));
338
339                         classpath = MNEW(char, strlen(opt_arg) + 1);
340                         strcpy(classpath, opt_arg);
341                         break;
342                                 
343                 case OPT_D:
344                         {
345                                 int n;
346                                 int l = strlen(opt_arg);
347                                 for (n = 0; n < l; n++) {
348                                         if (opt_arg[n] == '=') {
349                                                 opt_arg[n] = '\0';
350                                                 create_property(opt_arg, opt_arg + n + 1);
351                                                 goto didit;
352                                         }
353                                 }
354                                 usage();
355                                         
356                         didit: ;
357                         }       
358                         break;
359
360                 case OPT_MS:
361                 case OPT_MX:
362                         {
363                                 char c;
364                                 c = opt_arg[strlen(opt_arg) - 1];
365
366                                 if (c == 'k' || c == 'K') {
367                                         j = 1024 * atoi(opt_arg);
368
369                                 } else if (c == 'm' || c == 'M') {
370                                         j = 1024 * 1024 * atoi(opt_arg);
371
372                                 } else j = atoi(opt_arg);
373
374                                 if (i == OPT_MX) heapmaxsize = j;
375                                 else heapstartsize = j;
376                         }
377                         break;
378
379                 case OPT_VERBOSE1:
380                         opt_verbose = true;
381                         break;
382
383                 case OPT_VERBOSE:
384                         opt_verbose = true;
385                         loadverbose = true;
386                         linkverbose = true;
387                         initverbose = true;
388                         compileverbose = true;
389                         break;
390
391                 case OPT_VERBOSEEXCEPTION:
392                         verboseexception = true;
393                         break;
394
395                 case OPT_VERBOSEGC:
396                         collectverbose = true;
397                         break;
398
399 #ifdef TYPECHECK_VERBOSE
400                 case OPT_VERBOSETC:
401                         typecheckverbose = true;
402                         break;
403 #endif
404                                 
405                 case OPT_VERBOSECALL:
406                         runverbose = true;
407                         break;
408                                 
409                 case OPT_NOIEEE:
410                         opt_noieee = true;
411                         break;
412
413                 case OPT_NOVERIFY:
414                         opt_verify = false;
415                         break;
416
417                 case OPT_LIBERALUTF:
418                         opt_liberalutf = true;
419                         break;
420
421                 case OPT_SOFTNULL:
422                         checknull = true;
423                         break;
424
425                 case OPT_TIME:
426                         getcompilingtime = true;
427                         getloadingtime = true;
428                         break;
429                                         
430                 case OPT_STAT:
431                         opt_stat = true;
432                         break;
433                                         
434                 case OPT_LOG:
435                         strcpy(logfilename, opt_arg);
436                         break;
437                         
438                 case OPT_CHECK:
439                         for (j = 0; j < strlen(opt_arg); j++) {
440                                 switch (opt_arg[j]) {
441                                 case 'b':
442                                         checkbounds = false;
443                                         break;
444                                 case 's':
445                                         checksync = false;
446                                         break;
447                                 default:
448                                         usage();
449                                 }
450                         }
451                         break;
452                         
453                 case OPT_LOAD:
454                         startit = false;
455                         makeinitializations = false;
456                         break;
457
458                 case OPT_EAGER:
459                         opt_eager = true;
460                         break;
461
462                 case OPT_METHOD:
463                         startit = false;
464                         specificmethodname = opt_arg;
465                         makeinitializations = false;
466                         break;
467                         
468                 case OPT_SIGNATURE:
469                         specificsignature = opt_arg;
470                         break;
471                         
472                 case OPT_ALL:
473                         compileall = true;
474                         startit = false;
475                         makeinitializations = false;
476                         break;
477                         
478                 case OPT_SHOW:       /* Display options */
479                         for (j = 0; j < strlen(opt_arg); j++) {         
480                                 switch (opt_arg[j]) {
481                                 case 'a':
482                                         showdisassemble = true;
483                                         compileverbose = true;
484                                         break;
485                                 case 'c':
486                                         showconstantpool = true;
487                                         break;
488                                 case 'd':
489                                         showddatasegment = true;
490                                         break;
491                                 case 'i':
492                                         showintermediate = true;
493                                         compileverbose = true;
494                                         break;
495                                 case 'm':
496                                         showmethods = true;
497                                         break;
498                                 case 'u':
499                                         showutf = true;
500                                         break;
501                                 default:
502                                         usage();
503                                 }
504                         }
505                         break;
506                         
507                 case OPT_OLOOP:
508                         opt_loops = true;
509                         break;
510
511                 case OPT_INLINING:
512                         for (j = 0; j < strlen(opt_arg); j++) {         
513                                 switch (opt_arg[j]) {
514                                 case 'n':
515                                      /* define in options.h; Used in main.c, jit.c & inline.c */
516                                      #ifdef INAFTERMAIN
517                                         useinliningm = true;
518                                         useinlining = false;
519                                      #else
520                                         useinlining = true;
521                                      #endif
522                                         break;
523                                 case 'v':
524                                         inlinevirtuals = true;
525                                         opt_rt = true;
526                                         break;
527                                 case 'e':
528                                         inlineexceptions = true;
529                                         break;
530                                 case 'p':
531                                         inlineparamopt = true;
532                                         break;
533                                 case 'o':
534                                         inlineoutsiders = true;
535                                         break;
536                                 default:
537                                         usage();
538                                 }
539                         }
540                         break;
541
542 #ifdef STATIC_ANALYSIS
543                 case OPT_RT:
544                         opt_rt = true;
545                         break;
546
547                 case OPT_XTA:
548                         opt_xta = false; /**not yet **/
549                         break;
550
551                 case OPT_VTA:
552                         /***opt_vta = true; not yet **/
553                         break;
554 #endif
555
556 #ifdef LSRA
557                 case OPT_LSRA:
558 #if defined(__I386__) || defined(__ALPHA__)
559                         opt_lsra = true;
560 #else
561                         printf("LSRA not available for this architecture\n");
562                         opt_lsra = false;
563 #endif
564                         break;
565 #endif
566
567                 default:
568                         usage();
569                 }
570         }
571
572         if (opt_ind >= argc)
573                 usage();
574
575 #if 0
576         {
577                 char *gnucp = "/home/twisti/src/cacao/cacaodev/classpath/lib/:";
578                 cp = classpath;
579
580                 classpath = MNEW(char, strlen(cp) + strlen(classpath) + 1);
581                 strcpy(classpath, gnucp);
582                 strcat(classpath, cp);
583
584                 MFREE(cp, char, strlen(cp));
585         }
586 #endif
587
588         mainstring = argv[opt_ind++];
589         for (i = strlen(mainstring) - 1; i >= 0; i--) {     /* Transform dots into slashes */
590                 if (mainstring[i] == '.') mainstring[i] = '/';  /* in the class name */
591         }
592
593
594         /**************************** Program start *****************************/
595
596         log_init(logfilename);
597         if (opt_verbose)
598                 log_text("CACAO started -------------------------------------------------------");
599
600         /* initialize the garbage collector */
601         gc_init(heapmaxsize, heapstartsize);
602
603         tables_init();
604         suck_init(classpath);
605
606         cacao_initializing = true;
607
608 #if defined(USE_THREADS)
609 #if defined(NATIVE_THREADS)
610         initThreadsEarly();
611 #endif
612         initLocks();
613 #endif
614
615         /* install architecture dependent signal handler used for exceptions */
616         init_exceptions();
617
618         /* initializes jit compiler and codegen stuff */
619         jit_init();
620
621         loader_init((u1 *) &dummy);
622
623         /* initialize exceptions used in the system */
624         if (!init_system_exceptions())
625                 throw_main_exception_exit();
626
627         native_loadclasses();
628
629 #if defined(USE_THREADS)
630         initThreads((u1 *) &dummy);
631 #endif
632
633         *threadrootmethod = NULL;
634
635         /*That's important, otherwise we get into trouble, if the Runtime static
636           initializer is called before (circular dependency. This is with
637           classpath 0.09. Another important thing is, that this has to happen
638           after initThreads!!! */
639
640         if (!class_init(class_new(utf_new_char("java/lang/System"))))
641                 throw_main_exception_exit();
642
643         
644         
645 /*        jni_init(); */
646         cacao_initializing = false;
647
648         /************************* Start worker routines ********************/
649
650         if (startit) {
651                 methodinfo *mainmethod;
652                 java_objectarray *a; 
653                 s4 status;
654
655                 /* set return value to OK */
656                 status = 0;
657
658                 /* create, load and link the main class */
659                 mainclass = class_new(utf_new_char(mainstring));
660
661                 if (!class_load(mainclass))
662                         throw_main_exception_exit();
663
664                 if (!class_link(mainclass))
665                         throw_main_exception_exit();
666
667                 mainmethod = class_resolveclassmethod(mainclass,
668                                                                                           utf_new_char("main"), 
669                                                                                           utf_new_char("([Ljava/lang/String;)V"),
670                                                                                           mainclass,
671                                                                                           false);
672
673                 /* problems with main method? */
674 /*              if (*exceptionptr) */
675 /*                      throw_exception_exit(); */
676
677                 /* there is no main method or it isn't static */
678                 if (!mainmethod || !(mainmethod->flags & ACC_STATIC)) {
679                         *exceptionptr =
680                                 new_exception_message(string_java_lang_NoSuchMethodError,
681                                                                           "main");
682                         throw_main_exception_exit();
683                 }
684
685                 a = builtin_anewarray(argc - opt_ind, class_java_lang_String);
686                 for (i = opt_ind; i < argc; i++) {
687                         a->data[i - opt_ind] = 
688                                 (java_objectheader *) javastring_new(utf_new_char(argv[i]));
689                 }
690
691 #ifdef TYPEINFO_DEBUG_TEST
692                 /* test the typeinfo system */
693                 typeinfo_test();
694 #endif
695                 /*class_showmethods(currentThread->group->header.vftbl->class); */
696
697                 *threadrootmethod = mainmethod;
698
699
700                 /* here we go... */
701                 asm_calljavafunction(mainmethod, a, NULL, NULL, NULL);
702
703                 /* exception occurred? */
704                 if (*exceptionptr) {
705                         throw_main_exception();
706                         status = 1;
707                 }
708
709 #if defined(USE_THREADS)
710 #if defined(NATIVE_THREADS)
711                 joinAllThreads();
712 #else
713                 killThread(currentThread);
714 #endif
715 #endif
716
717                 /* now exit the JavaVM */
718
719                 cacao_exit(status);
720         }
721
722         /************* If requested, compile all methods ********************/
723
724         if (compileall) {
725                 classinfo *c;
726                 methodinfo *m;
727                 u4 slot;
728                 s4 i;
729
730                 /* create all classes found in the classpath */
731                 /* XXX currently only works with zip/jar's */
732                 create_all_classes();
733
734                 /* load and link all classes */
735                 for (slot = 0; slot < class_hash.size; slot++) {
736                         c = class_hash.ptr[slot];
737
738                         while (c) {
739                                 if (!c->loaded)
740                                         if (!class_load(c))
741                                                 throw_main_exception_exit();
742
743                                 if (!c->linked)
744                                         if (!class_link(c))
745                                                 throw_main_exception_exit();
746
747                                 /* compile all class methods */
748                                 for (i = 0; i < c->methodscount; i++) {
749                                         m = &(c->methods[i]);
750                                         if (m->jcode) {
751                                                 (void) jit_compile(m);
752                                         }
753                                 }
754
755                                 c = c->hashlink;
756                         }
757                 }
758         }
759
760
761         /******** If requested, compile a specific method ***************/
762
763         if (specificmethodname) {
764                 methodinfo *m;
765
766                 /* create, load and link the main class */
767                 mainclass = class_new(utf_new_char(mainstring));
768
769                 if (!class_load(mainclass))
770                         throw_main_exception_exit();
771
772                 if (!class_link(mainclass))
773                         throw_main_exception_exit();
774
775                 if (specificsignature) {
776                         m = class_resolveclassmethod(mainclass,
777                                                                                  utf_new_char(specificmethodname),
778                                                                                  utf_new_char(specificsignature),
779                                                                                  mainclass,
780                                                                                  false);
781                 } else {
782                         m = class_resolveclassmethod(mainclass,
783                                                                                  utf_new_char(specificmethodname),
784                                                                                  NULL,
785                                                                                  mainclass,
786                                                                                  false);
787                 }
788
789                 if (!m) {
790                         char message[MAXLOGTEXT];
791                         sprintf(message, "%s%s", specificmethodname,
792                                         specificsignature ? specificsignature : "");
793
794                         *exceptionptr =
795                                 new_exception_message(string_java_lang_NoSuchMethodException,
796                                                                           message);
797                                                                                  
798                         throw_main_exception_exit();
799                 }
800                 
801                 jit_compile(m);
802         }
803
804         cacao_shutdown(0);
805
806         /* keep compiler happy */
807
808         return 0;
809 }
810
811
812 /* cacao_exit ******************************************************************
813
814    Calls java.lang.Runtime.exit(I)V to exit the JavaVM correctly.
815
816 *******************************************************************************/
817
818 void cacao_exit(s4 status)
819 {
820         classinfo *c;
821         methodinfo *m;
822
823         /* class should already be loaded, but who knows... */
824
825         c = class_new(utf_new_char("java/lang/System"));
826
827         if (!class_load(c))
828                 throw_main_exception_exit();
829
830         if (!class_link(c))
831                 throw_main_exception_exit();
832
833         /* call System.exit(I)V */
834
835         m = class_resolveclassmethod(c,
836                                                                  utf_new_char("exit"),
837                                                                  utf_new_char("(I)V"),
838                                                                  class_java_lang_Object,
839                                                                  true);
840         
841         if (!m)
842                 throw_main_exception_exit();
843
844         /* call the exit function with passed exit status */
845
846         asm_calljavafunction(m,
847 #if POINTERSIZE == 8
848                                                  (void *) (s8) status,
849 #else
850                                                  (void *) status,
851 #endif
852                                                  NULL,
853                                                  NULL,
854                                                  NULL);
855
856         /* this should never happen */
857
858         if (*exceptionptr)
859                 throw_exception_exit();
860
861         throw_cacao_exception_exit(string_java_lang_InternalError,
862                                                            "System.exit(I)V returned without exception");
863 }
864
865
866 /*************************** Shutdown function *********************************
867
868         Terminates the system immediately without freeing memory explicitly (to be
869         used only for abnormal termination)
870         
871 *******************************************************************************/
872
873 void cacao_shutdown(s4 status)
874 {
875         if (opt_verbose || getcompilingtime || opt_stat) {
876                 log_text("CACAO terminated by shutdown");
877                 dolog("Exit status: %d\n", (s4) status);
878         }
879
880         exit(status);
881 }
882
883
884 /*
885  * These are local overrides for various environment variables in Emacs.
886  * Please do not remove this and leave it at the end of the file, where
887  * Emacs will automagically detect them.
888  * ---------------------------------------------------------------------
889  * Local variables:
890  * mode: c
891  * indent-tabs-mode: t
892  * c-basic-offset: 4
893  * tab-width: 4
894  * End:
895  */