1 /* main.c - contains main() and variables for the global options
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,
9 This file is part of CACAO.
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.
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.
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
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Reinhard Grafl
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
40 $Id: cacao.c 1094 2004-05-27 15:52:27Z twisti $
56 #include "threads/thread.h"
57 #include "toolbox/logging.h"
58 #include "toolbox/memory.h"
59 #include "parseRTstats.h"
60 #include "nat/java_lang_Throwable.h"
62 #ifdef TYPEINFO_DEBUG_TEST
66 /* command line option */
69 bool compileall = false;
70 bool runverbose = false; /* trace all method invocation */
71 bool verboseexception = false;
72 bool collectverbose = false;
74 bool loadverbose = false;
75 bool linkverbose = false;
76 bool initverbose = false;
78 bool opt_rt = false; /* true if RTA parse should be used RT-CO */
79 bool opt_xta = false; /* true if XTA parse should be used XTA-CO */
80 bool opt_vta = false; /* true if VTA parse should be used VTA-CO */
82 bool opt_liberalutf = false; /* Don't check overlong UTF-8 sequences */
84 bool showmethods = false;
85 bool showconstantpool = false;
88 bool compileverbose = false; /* trace compiler actions */
89 bool showstack = false;
90 bool showdisassemble = false; /* generate disassembler listing */
91 bool showddatasegment = false; /* generate data segment listing */
92 bool showintermediate = false; /* generate intermediate code listing */
94 bool useinlining = false; /* use method inlining */
95 bool inlinevirtuals = false; /* inline unique virtual methods */
96 bool inlineexceptions = false; /* inline methods, that contain excptions */
97 bool inlineparamopt = false; /* optimize parameter passing to inlined methods */
98 bool inlineoutsiders = false; /* inline methods, that are not member of the invoker's class */
100 bool checkbounds = true; /* check array bounds */
101 bool checknull = true; /* check null pointers */
102 bool opt_noieee = false; /* don't implement ieee compliant floats */
103 bool checksync = true; /* do synchronization */
104 bool opt_loops = false; /* optimize array accesses in loops */
106 bool makeinitializations = true;
108 bool getloadingtime = false; /* to measure the runtime */
111 bool getcompilingtime = false; /* compute compile time */
112 s8 compilingtime = 0; /* accumulated compile time */
114 int has_ext_instr_set = 0; /* has instruction set extensions */
116 bool opt_stat = false;
118 bool opt_verify = true; /* true if classfiles should be verified */
120 bool opt_eager = false;
123 static classinfo *mainclass;
125 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
126 void **stackbottom = 0;
130 /* internal function: get_opt *************************************************
132 decodes the next command line option
134 ******************************************************************************/
140 #define OPT_CLASSPATH 2
144 #define OPT_VERBOSE1 6
145 #define OPT_VERBOSE 7
146 #define OPT_VERBOSEGC 8
147 #define OPT_VERBOSECALL 9
148 #define OPT_NOIEEE 10
149 #define OPT_SOFTNULL 11
155 #define OPT_METHOD 17
156 #define OPT_SIGNATURE 18
160 #define OPT_INLINING 25
164 #define OPT_VERBOSETC 29
165 #define OPT_NOVERIFY 30
166 #define OPT_LIBERALUTF 31
167 #define OPT_VERBOSEEXCEPTION 32
171 struct {char *name; bool arg; int value;} opts[] = {
172 {"classpath", true, OPT_CLASSPATH},
174 {"ms", true, OPT_MS},
175 {"mx", true, OPT_MX},
176 {"noasyncgc", false, OPT_IGNORE},
177 {"noverify", false, OPT_NOVERIFY},
178 {"liberalutf", false, OPT_LIBERALUTF},
179 {"oss", true, OPT_IGNORE},
180 {"ss", true, OPT_IGNORE},
181 {"v", false, OPT_VERBOSE1},
182 {"verbose", false, OPT_VERBOSE},
183 {"verbosegc", false, OPT_VERBOSEGC},
184 {"verbosecall", false, OPT_VERBOSECALL},
185 {"verboseexception", false, OPT_VERBOSEEXCEPTION},
186 #ifdef TYPECHECK_VERBOSE
187 {"verbosetc", false, OPT_VERBOSETC},
189 #if defined(__ALPHA__)
190 {"noieee", false, OPT_NOIEEE},
192 {"softnull", false, OPT_SOFTNULL},
193 {"time", false, OPT_TIME},
194 {"stat", false, OPT_STAT},
195 {"log", true, OPT_LOG},
196 {"c", true, OPT_CHECK},
197 {"l", false, OPT_LOAD},
198 { "eager", false, OPT_EAGER },
199 {"m", true, OPT_METHOD},
200 {"sig", true, OPT_SIGNATURE},
201 {"s", true, OPT_SHOW},
202 {"all", false, OPT_ALL},
203 {"oloop", false, OPT_OLOOP},
204 {"i", true, OPT_INLINING},
205 {"rt", false, OPT_RT},
206 {"xta", false, OPT_XTA},
207 {"vta", false, OPT_VTA},
211 static int opt_ind = 1;
212 static char *opt_arg;
215 static int get_opt(int argc, char **argv)
220 if (opt_ind >= argc) return OPT_DONE;
223 if (a[0] != '-') return OPT_DONE;
225 for (i = 0; opts[i].name; i++) {
227 if (strcmp(a + 1, opts[i].name) == 0) { /* boolean option found */
229 return opts[i].value;
233 if (strcmp(a + 1, opts[i].name) == 0) { /* parameter option found */
235 if (opt_ind < argc) {
236 opt_arg = argv[opt_ind];
238 return opts[i].value;
243 size_t l = strlen(opts[i].name);
244 if (strlen(a + 1) > l) {
245 if (memcmp(a + 1, opts[i].name, l) == 0) {
248 return opts[i].value;
259 /******************** interne Function: print_usage ************************
261 Prints the correct usage syntax to stdout.
263 ***************************************************************************/
265 static void print_usage()
267 printf("USAGE: cacao [options] classname [program arguments]\n");
268 printf("Options:\n");
269 printf(" -classpath path ...... specify a path to look for classes\n");
270 printf(" -Dpropertyname=value . add an entry to the property list\n");
271 printf(" -mx maxmem[k|m] ...... specify the size for the heap\n");
272 printf(" -ms initmem[k|m] ..... specify the initial size for the heap\n");
273 printf(" -v ................... write state-information\n");
274 printf(" -verbose ............. write more information\n");
275 printf(" -verbosegc ........... write message for each GC\n");
276 printf(" -verbosecall ......... write message for each call\n");
277 printf(" -verboseexception .... write message for each step of stack unwinding\n");
278 #ifdef TYPECHECK_VERBOSE
279 printf(" -verbosetc ........... write debug messages while typechecking\n");
281 #if defined(__ALPHA__)
282 printf(" -noieee .............. don't use ieee compliant arithmetic\n");
284 printf(" -noverify ............ don't verify classfiles\n");
285 printf(" -liberalutf........... don't warn about overlong UTF-8 sequences\n");
286 printf(" -softnull ............ use software nullpointer check\n");
287 printf(" -time ................ measure the runtime\n");
288 printf(" -stat ................ detailed compiler statistics\n");
289 printf(" -log logfile ......... specify a name for the logfile\n");
290 printf(" -c(heck)b(ounds) ..... don't check array bounds\n");
291 printf(" s(ync) ....... don't check for synchronization\n");
292 printf(" -oloop ............... optimize array accesses in loops\n");
293 printf(" -l ................... don't start the class after loading\n");
294 printf(" -eager perform eager class loading and linking\n");
295 printf(" -all ................. compile all methods, no execution\n");
296 printf(" -m ................... compile only a specific method\n");
297 printf(" -sig ................. specify signature for a specific method\n");
298 printf(" -s(how)a(ssembler) ... show disassembled listing\n");
299 printf(" c(onstants) ... show the constant pool\n");
300 printf(" d(atasegment).. show data segment listing\n");
301 printf(" i(ntermediate). show intermediate representation\n");
302 printf(" m(ethods)...... show class fields and methods\n");
303 printf(" u(tf) ......... show the utf - hash\n");
304 printf(" -i n ............. activate inlining\n");
305 printf(" v ............. inline virtual methods\n");
306 printf(" e ............. inline methods with exceptions\n");
307 printf(" p ............. optimize argument renaming\n");
308 printf(" o ............. inline methods of foreign classes\n");
309 printf(" -rt .................. use rapid type analysis\n");
310 printf(" -xta ................. use x type analysis\n");
311 printf(" -vta ................. use variable type analysis\n");
315 /***************************** Function: print_times *********************
317 Prints a summary of CPU time usage.
319 **************************************************************************/
321 static void print_times()
323 s8 totaltime = getcputime();
324 s8 runtime = totaltime - loadingtime - compilingtime;
325 char logtext[MAXLOGTEXT];
327 #if defined(__I386__) || defined(__POWERPC__)
328 sprintf(logtext, "Time for loading classes: %lld secs, %lld millis",
330 sprintf(logtext, "Time for loading classes: %ld secs, %ld millis",
332 loadingtime / 1000000, (loadingtime % 1000000) / 1000);
335 #if defined(__I386__) || defined(__POWERPC__)
336 sprintf(logtext, "Time for compiling code: %lld secs, %lld millis",
338 sprintf(logtext, "Time for compiling code: %ld secs, %ld millis",
340 compilingtime / 1000000, (compilingtime % 1000000) / 1000);
343 #if defined(__I386__) || defined(__POWERPC__)
344 sprintf(logtext, "Time for running program: %lld secs, %lld millis",
346 sprintf(logtext, "Time for running program: %ld secs, %ld millis",
348 runtime / 1000000, (runtime % 1000000) / 1000);
351 #if defined(__I386__) || defined(__POWERPC__)
352 sprintf(logtext, "Total time: %lld secs, %lld millis",
354 sprintf(logtext, "Total time: %ld secs, %ld millis",
356 totaltime / 1000000, (totaltime % 1000000) / 1000);
361 /***************************** Function: print_stats *********************
363 outputs detailed compiler statistics
365 **************************************************************************/
367 static void print_stats()
369 char logtext[MAXLOGTEXT];
371 sprintf(logtext, "Number of JitCompiler Calls: %d", count_jit_calls);
373 sprintf(logtext, "Number of compiled Methods: %d", count_methods);
375 sprintf(logtext, "Number of max basic blocks per method: %d", count_max_basic_blocks);
377 sprintf(logtext, "Number of compiled basic blocks: %d", count_basic_blocks);
379 sprintf(logtext, "Number of max JavaVM-Instructions per method: %d", count_max_javainstr);
381 sprintf(logtext, "Number of compiled JavaVM-Instructions: %d", count_javainstr);
383 sprintf(logtext, "Size of compiled JavaVM-Instructions: %d(%d)", count_javacodesize,
384 count_javacodesize - count_methods * 18);
386 sprintf(logtext, "Size of compiled Exception Tables: %d", count_javaexcsize);
388 sprintf(logtext, "Value of extended instruction set var: %d", has_ext_instr_set);
390 sprintf(logtext, "Number of Machine-Instructions: %d", count_code_len >> 2);
392 sprintf(logtext, "Number of Spills: %d", count_spills);
394 sprintf(logtext, "Number of Activ Pseudocommands: %5d", count_pcmd_activ);
396 sprintf(logtext, "Number of Drop Pseudocommands: %5d", count_pcmd_drop);
398 sprintf(logtext, "Number of Const Pseudocommands: %5d (zero:%5d)", count_pcmd_load, count_pcmd_zero);
400 sprintf(logtext, "Number of ConstAlu Pseudocommands: %5d (cmp: %5d, store:%5d)", count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
402 sprintf(logtext, "Number of Move Pseudocommands: %5d", count_pcmd_move);
404 sprintf(logtext, "Number of Load Pseudocommands: %5d", count_load_instruction);
406 sprintf(logtext, "Number of Store Pseudocommands: %5d (combined: %5d)", count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
408 sprintf(logtext, "Number of OP Pseudocommands: %5d", count_pcmd_op);
410 sprintf(logtext, "Number of DUP Pseudocommands: %5d", count_dup_instruction);
412 sprintf(logtext, "Number of Mem Pseudocommands: %5d", count_pcmd_mem);
414 sprintf(logtext, "Number of Method Pseudocommands: %5d", count_pcmd_met);
416 sprintf(logtext, "Number of Branch Pseudocommands: %5d (rets:%5d, Xrets: %5d)",
417 count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
419 sprintf(logtext, "Number of Table Pseudocommands: %5d", count_pcmd_table);
421 sprintf(logtext, "Number of Useful Pseudocommands: %5d", count_pcmd_table +
422 count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
424 sprintf(logtext, "Number of Null Pointer Checks: %5d", count_check_null);
426 sprintf(logtext, "Number of Array Bound Checks: %5d", count_check_bound);
428 sprintf(logtext, "Number of Try-Blocks: %d", count_tryblocks);
430 sprintf(logtext, "Maximal count of stack elements: %d", count_max_new_stack);
432 sprintf(logtext, "Upper bound of max stack elements: %d", count_upper_bound_new_stack);
434 sprintf(logtext, "Distribution of stack sizes at block boundary");
436 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 >=10");
438 sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_block_stack[0],
439 count_block_stack[1], count_block_stack[2], count_block_stack[3], count_block_stack[4],
440 count_block_stack[5], count_block_stack[6], count_block_stack[7], count_block_stack[8],
441 count_block_stack[9], count_block_stack[10]);
443 sprintf(logtext, "Distribution of store stack depth");
445 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 >=10");
447 sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_depth[0],
448 count_store_depth[1], count_store_depth[2], count_store_depth[3], count_store_depth[4],
449 count_store_depth[5], count_store_depth[6], count_store_depth[7], count_store_depth[8],
450 count_store_depth[9], count_store_depth[10]);
452 sprintf(logtext, "Distribution of store creator chains first part");
454 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 ");
456 sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_length[0],
457 count_store_length[1], count_store_length[2], count_store_length[3], count_store_length[4],
458 count_store_length[5], count_store_length[6], count_store_length[7], count_store_length[8],
459 count_store_length[9]);
461 sprintf(logtext, "Distribution of store creator chains second part");
463 sprintf(logtext, " 10 11 12 13 14 15 16 17 18 19 >=20");
465 sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_length[10],
466 count_store_length[11], count_store_length[12], count_store_length[13], count_store_length[14],
467 count_store_length[15], count_store_length[16], count_store_length[17], count_store_length[18],
468 count_store_length[19], count_store_length[20]);
470 sprintf(logtext, "Distribution of analysis iterations");
472 sprintf(logtext, " 1 2 3 4 >=5");
474 sprintf(logtext, "%5d%5d%5d%5d%5d", count_analyse_iterations[0], count_analyse_iterations[1],
475 count_analyse_iterations[2], count_analyse_iterations[3], count_analyse_iterations[4]);
477 sprintf(logtext, "Distribution of basic blocks per method");
479 sprintf(logtext, " <= 5 <=10 <=15 <=20 <=30 <=40 <=50 <=75 >75");
481 sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_method_bb_distribution[0],
482 count_method_bb_distribution[1], count_method_bb_distribution[2], count_method_bb_distribution[3],
483 count_method_bb_distribution[4], count_method_bb_distribution[5], count_method_bb_distribution[6],
484 count_method_bb_distribution[7], count_method_bb_distribution[8]);
486 sprintf(logtext, "Distribution of basic block sizes");
489 " 0 1 2 3 4 5 6 7 8 9 <13 <15 <17 <19 <21 <26 <31 >30");
491 sprintf(logtext, "%3d%5d%5d%5d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d",
492 count_block_size_distribution[0], count_block_size_distribution[1], count_block_size_distribution[2],
493 count_block_size_distribution[3], count_block_size_distribution[4], count_block_size_distribution[5],
494 count_block_size_distribution[6], count_block_size_distribution[7], count_block_size_distribution[8],
495 count_block_size_distribution[9], count_block_size_distribution[10], count_block_size_distribution[11],
496 count_block_size_distribution[12], count_block_size_distribution[13], count_block_size_distribution[14],
497 count_block_size_distribution[15], count_block_size_distribution[16], count_block_size_distribution[17]);
499 sprintf(logtext, "Size of Code Area (Kb): %10.3f", (float) count_code_len / 1024);
501 sprintf(logtext, "Size of data Area (Kb): %10.3f", (float) count_data_len / 1024);
503 sprintf(logtext, "Size of Class Infos (Kb):%10.3f", (float) (count_class_infos) / 1024);
505 sprintf(logtext, "Size of Const Pool (Kb): %10.3f", (float) (count_const_pool_len + count_utf_len) / 1024);
507 sprintf(logtext, "Size of Vftbl (Kb): %10.3f", (float) count_vftbl_len / 1024);
509 sprintf(logtext, "Size of comp stub (Kb): %10.3f", (float) count_cstub_len / 1024);
511 sprintf(logtext, "Size of native stub (Kb):%10.3f", (float) count_nstub_len / 1024);
513 sprintf(logtext, "Size of Utf (Kb): %10.3f", (float) count_utf_len / 1024);
515 sprintf(logtext, "Size of VMCode (Kb): %10.3f(%d)", (float) count_vmcode_len / 1024,
516 count_vmcode_len - 18 * count_all_methods);
518 sprintf(logtext, "Size of ExTable (Kb): %10.3f", (float) count_extable_len / 1024);
520 sprintf(logtext, "Number of class loads: %d", count_class_loads);
522 sprintf(logtext, "Number of class inits: %d", count_class_inits);
524 sprintf(logtext, "Number of loaded Methods: %d\n\n", count_all_methods);
527 sprintf(logtext, "Calls of utf_new: %22d", count_utf_new);
529 sprintf(logtext, "Calls of utf_new (element found): %6d\n\n", count_utf_new_found);
534 #ifdef TYPECHECK_STATISTICS
535 void typecheck_print_statistics(FILE *file);
540 * void exit_handler(void)
541 * -----------------------
542 * The exit_handler function is called upon program termination to shutdown
543 * the various subsystems and release the resources allocated to the VM.
545 void exit_handler(void)
547 /********************* Print debug tables ************************/
549 if (showmethods) class_showmethods(mainclass);
550 if (showconstantpool) class_showconstantpool(mainclass);
551 if (showutf) utf_show();
553 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
554 clear_thread_flags(); /* restores standard file descriptor
558 /************************ Free all resources *******************/
560 /*heap_close();*/ /* must be called before compiler_close and
561 loader_close because finalization occurs
565 tables_close(literalstring_free);
567 if (verbose || getcompilingtime || opt_stat) {
568 log_text("CACAO terminated");
571 #ifdef TYPECHECK_STATISTICS
572 typecheck_print_statistics(get_logfile());
575 if (getcompilingtime)
582 /************************** Function: main *******************************
586 **************************************************************************/
588 int main(int argc, char **argv)
593 /********** interne (nur fuer main relevante Optionen) **************/
595 char logfilename[200] = "";
596 u4 heapmaxsize = 64 * 1024 * 1024;
597 u4 heapstartsize = 200 * 1024;
599 char classpath[500] = ".";
601 char *specificmethodname = NULL;
602 char *specificsignature = NULL;
604 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
605 stackbottom = &dummy;
608 if (0 != atexit(exit_handler))
609 throw_cacao_exception_exit(string_java_lang_InternalError,
610 "unable to register exit_handler");
613 /************ Collect info from the environment ************************/
615 cp = getenv("CLASSPATH");
617 strcpy(classpath, cp);
620 /***************** Interpret the command line *****************/
625 while ((i = get_opt(argc, argv)) != OPT_DONE) {
627 case OPT_IGNORE: break;
630 strcpy(classpath + strlen(classpath), ":");
631 strcpy(classpath + strlen(classpath), opt_arg);
637 int l = strlen(opt_arg);
638 for (n = 0; n < l; n++) {
639 if (opt_arg[n] == '=') {
641 attach_property(opt_arg, opt_arg + n + 1);
654 if (opt_arg[strlen(opt_arg) - 1] == 'k') {
655 j = 1024 * atoi(opt_arg);
657 } else if (opt_arg[strlen(opt_arg) - 1] == 'm') {
658 j = 1024 * 1024 * atoi(opt_arg);
660 } else j = atoi(opt_arg);
662 if (i == OPT_MX) heapmaxsize = j;
663 else heapstartsize = j;
675 compileverbose = true;
678 case OPT_VERBOSEEXCEPTION:
679 verboseexception = true;
683 collectverbose = true;
686 #ifdef TYPECHECK_VERBOSE
688 typecheckverbose = true;
692 case OPT_VERBOSECALL:
705 opt_liberalutf = true;
713 getcompilingtime = true;
714 getloadingtime = true;
722 strcpy(logfilename, opt_arg);
726 for (j = 0; j < strlen(opt_arg); j++) {
727 switch (opt_arg[j]) {
743 makeinitializations = false;
752 specificmethodname = opt_arg;
753 makeinitializations = false;
757 specificsignature = opt_arg;
763 makeinitializations = false;
766 case OPT_SHOW: /* Display options */
767 for (j = 0; j < strlen(opt_arg); j++) {
768 switch (opt_arg[j]) {
770 showdisassemble = true;
774 showconstantpool = true;
777 showddatasegment = true;
780 showintermediate = true;
781 compileverbose = true;
801 for (j = 0; j < strlen(opt_arg); j++) {
802 switch (opt_arg[j]) {
807 inlinevirtuals = true;
810 inlineexceptions = true;
813 inlineparamopt = true;
816 inlineoutsiders = true;
830 opt_xta = false; /**not yet **/
834 /***opt_vta = true; not yet **/
844 if (opt_ind >= argc) {
849 mainstring = argv[opt_ind++];
850 for (i = strlen(mainstring) - 1; i >= 0; i--) { /* Transform dots into slashes */
851 if (mainstring[i] == '.') mainstring[i] = '/'; /* in the class name */
855 /**************************** Program start *****************************/
856 log_init(logfilename);
858 log_text("CACAO started -------------------------------------------------------");
861 /* initialize the garbage collector */
862 gc_init(heapmaxsize, heapstartsize);
864 native_setclasspath(classpath);
867 suck_init(classpath);
869 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
873 loader_init((u1 *) &dummy);
875 native_loadclasses();
879 #if defined(USE_THREADS)
880 initThreads((u1*) &dummy);
884 /************************* Start worker routines ********************/
887 methodinfo *mainmethod;
890 /* create, load and link the main class */
891 mainclass = class_new(utf_new_char(mainstring));
893 if (!class_load(mainclass))
894 throw_exception_exit();
896 if (!class_link(mainclass))
897 throw_exception_exit();
899 mainmethod = class_resolveclassmethod(mainclass,
900 utf_new_char("main"),
901 utf_new_char("([Ljava/lang/String;)V"),
905 /* problems with main method? */
906 /* if (*exceptionptr) */
907 /* throw_exception_exit(); */
909 /* there is no main method or it isn't static */
910 if (!mainmethod || !(mainmethod->flags & ACC_STATIC)) {
912 new_exception_message(string_java_lang_NoSuchMethodError,
914 throw_exception_exit();
917 a = builtin_anewarray(argc - opt_ind, class_java_lang_String);
918 for (i = opt_ind; i < argc; i++) {
919 a->data[i - opt_ind] =
920 (java_objectheader *) javastring_new(utf_new_char(argv[i]));
923 #ifdef TYPEINFO_DEBUG_TEST
924 /* test the typeinfo system */
927 /*class_showmethods(currentThread->group->header.vftbl->class); */
929 *threadrootmethod = mainmethod;
932 asm_calljavafunction(mainmethod, a, NULL, NULL, NULL);
934 /* exception occurred? */
936 throw_exception_exit();
938 #if defined(USE_THREADS)
939 #if defined(NATIVE_THREADS)
942 killThread(currentThread);
943 fprintf(stderr, "still here\n");
949 /************* If requested, compile all methods ********************/
957 /* create all classes found in the classpath */
958 /* XXX currently only works with zip/jar's */
959 create_all_classes();
961 /* load and link all classes */
962 for (slot = 0; slot < class_hash.size; slot++) {
963 c = class_hash.ptr[slot];
972 /* compile all class methods */
973 for (i = 0; i < c->methodscount; i++) {
974 m = &(c->methods[i]);
976 (void) jit_compile(m);
986 /******** If requested, compile a specific method ***************/
988 if (specificmethodname) {
991 /* create, load and link the main class */
992 mainclass = class_new(utf_new_char(mainstring));
993 class_load(mainclass);
996 throw_exception_exit();
998 class_link(mainclass);
1001 throw_exception_exit();
1003 if (specificsignature) {
1004 m = class_resolveclassmethod(mainclass,
1005 utf_new_char(specificmethodname),
1006 utf_new_char(specificsignature),
1010 m = class_resolveclassmethod(mainclass,
1011 utf_new_char(specificmethodname),
1018 char message[MAXLOGTEXT];
1019 sprintf(message, "%s%s", specificmethodname,
1020 specificmethodname ? specificmethodname : "");
1023 new_exception_message(string_java_lang_NoSuchMethodException,
1026 throw_exception_exit();
1037 /*************************** Shutdown function *********************************
1039 Terminates the system immediately without freeing memory explicitly (to be
1040 used only for abnormal termination)
1042 *******************************************************************************/
1044 void cacao_shutdown(s4 status)
1048 if (verbose || getcompilingtime || opt_stat) {
1049 log_text ("CACAO terminated by shutdown");
1052 if (getcompilingtime)
1055 dolog("Exit status: %d\n", (int) status);
1063 * These are local overrides for various environment variables in Emacs.
1064 * Please do not remove this and leave it at the end of the file, where
1065 * Emacs will automagically detect them.
1066 * ---------------------------------------------------------------------
1069 * indent-tabs-mode: t