1 /* src/cacao/cacao.c - contains main() of cacao
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 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 3090 2005-07-21 11:29:43Z twisti $
50 #include "cacao/cacao.h"
52 #include "mm/memory.h"
53 #include "native/jni.h"
54 #include "native/native.h"
56 #if defined(ENABLE_JVMTI)
57 # include "native/jvmti/jvmti.h"
60 #include "toolbox/logging.h"
61 #include "vm/exceptions.h"
62 #include "vm/global.h"
63 #include "vm/initialize.h"
64 #include "vm/loader.h"
65 #include "vm/options.h"
66 #include "vm/signallocal.h"
67 #include "vm/statistics.h"
68 #include "vm/stringlocal.h"
69 #include "vm/tables.h"
70 #include "vm/classcache.h"
71 #include "vm/jit/asmpart.h"
72 #include "vm/jit/jit.h"
74 #ifdef TYPEINFO_DEBUG_TEST
75 #include "vm/jit/verify/typeinfo.h"
79 /* define heap sizes **********************************************************/
81 #define HEAP_MAXSIZE 64 * 1024 * 1024; /* default 64MB */
82 #define HEAP_STARTSIZE 2 * 1024 * 1024; /* default 2MB */
85 /* Invocation API variables ***************************************************/
87 JavaVM *jvm; /* denotes a Java VM */
88 JNIEnv *env; /* pointer to native method interface */
90 JDK1_1InitArgs vm_args; /* JDK 1.1 VM initialization arguments */
93 bool cacao_initializing;
95 char *bootclasspath; /* contains the boot classpath */
96 char *classpath; /* contains the classpath */
99 static classinfo *mainclass;
101 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
102 void **stackbottom = 0;
106 /* define command line options ************************************************/
108 #define OPT_CLASSPATH 2
112 #define OPT_VERBOSE1 6
113 #define OPT_VERBOSE 7
114 #define OPT_VERBOSESPECIFIC 8
115 #define OPT_VERBOSECALL 9
116 #define OPT_NOIEEE 10
117 #define OPT_SOFTNULL 11
120 #if defined(STATISTICS)
122 #endif /* defined(STATISTICS) */
127 #define OPT_METHOD 17
128 #define OPT_SIGNATURE 18
132 #define OPT_INLINING 25
134 #define STATIC_ANALYSIS
135 #if defined(STATIC_ANALYSIS)
139 #endif /* defined(STATIC_ANALYSIS) */
141 #define OPT_VERBOSETC 29
142 #define OPT_NOVERIFY 30
143 #define OPT_LIBERALUTF 31
144 #define OPT_VERBOSEEXCEPTION 32
149 #endif /* defined(LSRA) */
152 #define OPT_BOOTCLASSPATH 36
153 #define OPT_BOOTCLASSPATH_A 37
154 #define OPT_BOOTCLASSPATH_P 38
155 #define OPT_VERSION 39
156 #define OPT_SHOWVERSION 40
157 #define OPT_FULLVERSION 41
163 opt_struct opts[] = {
164 { "classpath", true, OPT_CLASSPATH },
165 { "cp", true, OPT_CLASSPATH },
166 { "D", true, OPT_D },
167 { "Xms", true, OPT_MS },
168 { "Xmx", true, OPT_MX },
169 { "ms", true, OPT_MS },
170 { "mx", true, OPT_MX },
171 { "noasyncgc", false, OPT_IGNORE },
172 { "noverify", false, OPT_NOVERIFY },
173 { "liberalutf", false, OPT_LIBERALUTF },
174 { "ss", true, OPT_IGNORE },
175 { "v", false, OPT_VERBOSE1 },
176 { "verbose", false, OPT_VERBOSE },
177 { "verbose:", true, OPT_VERBOSESPECIFIC },
178 { "verbosecall", false, OPT_VERBOSECALL },
179 { "verboseexception", false, OPT_VERBOSEEXCEPTION },
180 #ifdef TYPECHECK_VERBOSE
181 { "verbosetc", false, OPT_VERBOSETC },
183 #if defined(__ALPHA__)
184 { "noieee", false, OPT_NOIEEE },
186 { "softnull", false, OPT_SOFTNULL },
187 { "time", false, OPT_TIME },
188 #if defined(STATISTICS)
189 { "stat", false, OPT_STAT },
191 { "log", true, OPT_LOG },
192 { "c", true, OPT_CHECK },
193 { "l", false, OPT_LOAD },
194 { "eager", false, OPT_EAGER },
195 { "m", true, OPT_METHOD },
196 { "sig", true, OPT_SIGNATURE },
197 { "s", true, OPT_SHOW },
198 { "all", false, OPT_ALL },
199 { "oloop", false, OPT_OLOOP },
200 { "i", true, OPT_INLINING },
201 #ifdef STATIC_ANALYSIS
202 { "rt", false, OPT_RT },
203 { "xta", false, OPT_XTA },
204 { "vta", false, OPT_VTA },
207 { "lsra", false, OPT_LSRA },
209 { "jar", false, OPT_JAR },
210 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
211 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
212 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
213 { "version", false, OPT_VERSION },
214 { "showversion", false, OPT_SHOWVERSION },
215 { "fullversion", false, OPT_FULLVERSION },
216 { "help", false, OPT_HELP },
217 { "?", false, OPT_HELP },
218 { "X", false, OPT_X },
223 /* usage ***********************************************************************
225 Prints the correct usage syntax to stdout.
227 *******************************************************************************/
229 static void usage(void)
231 printf("Usage: cacao [-options] classname [arguments]\n");
232 printf(" (to run a class file)\n");
233 printf(" cacao [-options] -jar jarfile [arguments]\n");
234 printf(" (to run a standalone jar file)\n\n");
236 printf("Java options:\n");
237 printf(" -cp <path> specify a path to look for classes\n");
238 printf(" -classpath <path> specify a path to look for classes\n");
239 printf(" -D<name>=<value> add an entry to the property list\n");
240 printf(" -verbose[:class|gc|jni] enable specific verbose output\n");
241 printf(" -version print product version and exit\n");
242 printf(" -fullversion print jpackage-compatible product version and exit\n");
243 printf(" -showversion print product version and continue\n");
244 printf(" -help, -? print this help message\n");
245 printf(" -X print help on non-standard Java options\n\n");
247 printf("CACAO options:\n");
248 printf(" -v write state-information\n");
249 printf(" -verbose write more information\n");
250 printf(" -verbosegc write message for each GC\n");
251 printf(" -verbosecall write message for each call\n");
252 printf(" -verboseexception write message for each step of stack unwinding\n");
253 #ifdef TYPECHECK_VERBOSE
254 printf(" -verbosetc write debug messages while typechecking\n");
256 #if defined(__ALPHA__)
257 printf(" -noieee don't use ieee compliant arithmetic\n");
259 printf(" -noverify don't verify classfiles\n");
260 printf(" -liberalutf don't warn about overlong UTF-8 sequences\n");
261 printf(" -softnull use software nullpointer check\n");
262 printf(" -time measure the runtime\n");
263 #if defined(STATISTICS)
264 printf(" -stat detailed compiler statistics\n");
266 printf(" -log logfile specify a name for the logfile\n");
267 printf(" -c(heck)b(ounds) don't check array bounds\n");
268 printf(" s(ync) don't check for synchronization\n");
269 printf(" -oloop optimize array accesses in loops\n");
270 printf(" -l don't start the class after loading\n");
271 printf(" -eager perform eager class loading and linking\n");
272 printf(" -all compile all methods, no execution\n");
273 printf(" -m compile only a specific method\n");
274 printf(" -sig specify signature for a specific method\n");
275 printf(" -s(how)a(ssembler) show disassembled listing\n");
276 printf(" c(onstants) show the constant pool\n");
277 printf(" d(atasegment) show data segment listing\n");
278 printf(" e(xceptionstubs) show disassembled exception stubs (only with -sa)\n");
279 printf(" i(ntermediate) show intermediate representation\n");
280 printf(" m(ethods) show class fields and methods\n");
281 printf(" n(ative) show disassembled native stubs\n");
282 printf(" u(tf) show the utf - hash\n");
283 printf(" -i n(line) activate inlining\n");
284 printf(" v(irtual) inline virtual methods (uses/turns rt option on)\n");
285 printf(" e(exception) inline methods with exceptions\n");
286 printf(" p(aramopt) optimize argument renaming\n");
287 printf(" o(utsiders) inline methods of foreign classes\n");
288 #ifdef STATIC_ANALYSIS
289 printf(" -rt use rapid type analysis\n");
290 printf(" -xta use x type analysis\n");
291 printf(" -vta use variable type analysis\n");
294 printf(" -lsra use linear scan register allocation\n");
297 /* exit with error code */
303 static void Xusage(void)
305 printf(" -Xbootclasspath:<zip/jar files and directories separated by :>\n");
306 printf(" value is set as bootstrap class path\n");
307 printf(" -Xbootclasspath/a:<zip/jar files and directories separated by :>\n");
308 printf(" value is appended to the bootstrap class path\n");
309 printf(" -Xbootclasspath/p:<zip/jar files and directories separated by :>\n");
310 printf(" value is prepended to the bootstrap class path\n");
311 printf(" -Xms<size> set the initial size of the heap (default: 2M)\n");
312 printf(" -Xmx<size> set the maximum size of the heap (default: 64M)\n");
314 /* exit with error code */
320 /* version *********************************************************************
322 Only prints cacao version information.
324 *******************************************************************************/
326 static void version(void)
328 printf("java version \""JAVA_VERSION"\"\n");
329 printf("CACAO version "VERSION"\n");
331 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
332 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
333 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
334 printf("Institut f. Computersprachen - TU Wien\n\n");
336 printf("This program is free software; you can redistribute it and/or\n");
337 printf("modify it under the terms of the GNU General Public License as\n");
338 printf("published by the Free Software Foundation; either version 2, or (at\n");
339 printf("your option) any later version.\n\n");
341 printf("This program is distributed in the hope that it will be useful, but\n");
342 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
343 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
344 printf("General Public License for more details.\n");
348 /* fullversion *****************************************************************
350 Prints a Sun compatible version information (required e.g. by
351 jpackage, www.jpackage.org).
353 *******************************************************************************/
355 static void fullversion(void)
357 printf("java full version \"cacao-"JAVA_VERSION"\"\n");
365 #ifdef TYPECHECK_STATISTICS
366 void typecheck_print_statistics(FILE *file);
371 /* getmainclassfromjar *********************************************************
373 Gets the name of the main class form a JAR's manifest file.
375 *******************************************************************************/
377 static char *getmainclassnamefromjar(char *mainstring)
380 java_objectheader *o;
384 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
387 throw_main_exception_exit();
389 /* create JarFile object */
394 throw_main_exception_exit();
397 m = class_resolveclassmethod(c,
399 utf_java_lang_String__void,
400 class_java_lang_Object,
404 throw_main_exception_exit();
406 s = javastring_new_char(mainstring);
408 asm_calljavafunction(m, o, s, NULL, NULL);
411 throw_main_exception_exit();
413 /* get manifest object */
415 m = class_resolveclassmethod(c,
416 utf_new_char("getManifest"),
417 utf_new_char("()Ljava/util/jar/Manifest;"),
418 class_java_lang_Object,
422 throw_main_exception_exit();
424 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
427 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
432 /* get Main Attributes */
434 m = class_resolveclassmethod(o->vftbl->class,
435 utf_new_char("getMainAttributes"),
436 utf_new_char("()Ljava/util/jar/Attributes;"),
437 class_java_lang_Object,
441 throw_main_exception_exit();
443 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
446 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
451 /* get property Main-Class */
453 m = class_resolveclassmethod(o->vftbl->class,
454 utf_new_char("getValue"),
455 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
456 class_java_lang_Object,
460 throw_main_exception_exit();
462 s = javastring_new_char("Main-Class");
464 o = asm_calljavafunction(m, o, s, NULL, NULL);
467 throw_main_exception_exit();
469 return javastring_tochar(o);
474 * void exit_handler(void)
475 * -----------------------
476 * The exit_handler function is called upon program termination to shutdown
477 * the various subsystems and release the resources allocated to the VM.
479 void exit_handler(void)
481 /********************* Print debug tables ************************/
483 if (showmethods) class_showmethods(mainclass);
484 if (showconstantpool) class_showconstantpool(mainclass);
485 if (showutf) utf_show();
487 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
488 clear_thread_flags(); /* restores standard file descriptor
492 /************************ Free all resources *******************/
497 MFREE(classpath, u1, strlen(classpath));
499 if (opt_verbose || getcompilingtime || opt_stat) {
500 log_text("CACAO terminated");
502 #if defined(STATISTICS)
505 #ifdef TYPECHECK_STATISTICS
506 typecheck_print_statistics(get_logfile());
510 if (getcompilingtime)
518 /* main ************************************************************************
522 *******************************************************************************/
524 int main(int argc, char **argv)
529 /* local variables ********************************************************/
531 char logfilename[200] = "";
537 char *specificmethodname = NULL;
538 char *specificsignature = NULL;
541 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
542 stackbottom = &dummy;
545 if (atexit(exit_handler))
546 throw_cacao_exception_exit(string_java_lang_InternalError,
547 "Unable to register exit_handler");
550 /************ Collect info from the environment ************************/
552 /* set the bootclasspath */
554 cp = getenv("BOOTCLASSPATH");
556 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
557 strcpy(bootclasspath, cp);
560 #if !defined(WITH_EXTERNAL_CLASSPATH)
561 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_RT_JAR_PATH) +
564 bootclasspath = MNEW(char, cplen);
565 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
566 strcat(bootclasspath, CACAO_RT_JAR_PATH);
568 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_VM_ZIP_PATH) +
570 strlen(EXTERNAL_CLASSPATH_PREFIX) +
571 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
574 bootclasspath = MNEW(char, cplen);
575 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
576 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
577 strcat(bootclasspath, ":");
578 strcat(bootclasspath, EXTERNAL_CLASSPATH_PREFIX);
579 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
584 /* set the classpath */
586 cp = getenv("CLASSPATH");
588 classpath = MNEW(char, strlen(cp) + strlen("0"));
589 strcat(classpath, cp);
592 classpath = MNEW(char, strlen(".") + strlen("0"));
593 strcpy(classpath, ".");
597 /***************** Interpret the command line *****************/
602 heapmaxsize = HEAP_MAXSIZE;
603 heapstartsize = HEAP_STARTSIZE;
606 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
611 case OPT_BOOTCLASSPATH:
612 /* Forget default bootclasspath and set the argument as new boot */
614 MFREE(bootclasspath, char, strlen(bootclasspath));
616 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
617 strcpy(bootclasspath, opt_arg);
620 case OPT_BOOTCLASSPATH_A:
621 /* append to end of bootclasspath */
622 cplen = strlen(bootclasspath);
624 bootclasspath = MREALLOC(bootclasspath,
627 cplen + strlen(":") +
628 strlen(opt_arg) + strlen("0"));
630 strcat(bootclasspath, ":");
631 strcat(bootclasspath, opt_arg);
634 case OPT_BOOTCLASSPATH_P:
635 /* prepend in front of bootclasspath */
639 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
640 cplen + strlen("0"));
642 strcpy(bootclasspath, opt_arg);
643 strcat(bootclasspath, ":");
644 strcat(bootclasspath, cp);
646 MFREE(cp, char, cplen);
650 /* forget old classpath and set the argument as new classpath */
651 MFREE(classpath, char, strlen(classpath));
653 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
654 strcpy(classpath, opt_arg);
663 for (j = 0; j < strlen(opt_arg); j++) {
664 if (opt_arg[j] == '=') {
666 create_property(opt_arg, opt_arg + j + 1);
671 /* if no '=' is given, just create an empty property */
672 create_property(opt_arg, "");
682 c = opt_arg[strlen(opt_arg) - 1];
684 if (c == 'k' || c == 'K') {
685 j = 1024 * atoi(opt_arg);
687 } else if (c == 'm' || c == 'M') {
688 j = 1024 * 1024 * atoi(opt_arg);
690 } else j = atoi(opt_arg);
692 if (i == OPT_MX) heapmaxsize = j;
693 else heapstartsize = j;
706 compileverbose = true;
709 case OPT_VERBOSESPECIFIC:
710 if (strcmp("class", opt_arg) == 0) {
714 } else if (strcmp("gc", opt_arg) == 0) {
715 opt_verbosegc = true;
717 } else if (strcmp("jni", opt_arg) == 0) {
718 opt_verbosejni = true;
722 case OPT_VERBOSEEXCEPTION:
723 verboseexception = true;
726 #ifdef TYPECHECK_VERBOSE
728 typecheckverbose = true;
732 case OPT_VERBOSECALL:
741 case OPT_FULLVERSION:
745 case OPT_SHOWVERSION:
758 opt_liberalutf = true;
766 getcompilingtime = true;
767 getloadingtime = true;
770 #if defined(STATISTICS)
777 strcpy(logfilename, opt_arg);
781 for (j = 0; j < strlen(opt_arg); j++) {
782 switch (opt_arg[j]) {
797 makeinitializations = false;
806 specificmethodname = opt_arg;
807 makeinitializations = false;
811 specificsignature = opt_arg;
817 makeinitializations = false;
820 case OPT_SHOW: /* Display options */
821 for (j = 0; j < strlen(opt_arg); j++) {
822 switch (opt_arg[j]) {
824 opt_showdisassemble = true;
825 compileverbose = true;
828 showconstantpool = true;
831 opt_showddatasegment = true;
834 opt_showexceptionstubs = true;
837 opt_showintermediate = true;
838 compileverbose = true;
844 opt_shownativestub = true;
860 for (j = 0; j < strlen(opt_arg); j++) {
861 switch (opt_arg[j]) {
863 /* define in options.h; Used in main.c, jit.c & inline.c */
872 inlinevirtuals = true;
876 inlineexceptions = true;
879 inlineparamopt = true;
882 inlineoutsiders = true;
890 #ifdef STATIC_ANALYSIS
892 opt_rt = true; /* default for inlining */
896 opt_xta = true; /* in test currently */
900 printf("\nVTA is not yet available\n");
902 /***opt_vta = true; not yet **/
921 printf("Unknown option: %s\n", argv[opt_ind]);
930 /* transform dots into slashes in the class name */
932 mainstring = argv[opt_ind++];
935 /* do not mangle jar filename */
937 for (i = strlen(mainstring) - 1; i >= 0; i--) {
938 if (mainstring[i] == '.') mainstring[i] = '/';
942 /* put jarfile in classpath */
946 classpath = MNEW(char, strlen(mainstring) + strlen(":") +
947 strlen(classpath) + strlen("0"));
949 strcpy(classpath, mainstring);
950 strcat(classpath, ":");
951 strcat(classpath, cp);
953 MFREE(cp, char, strlen(cp));
956 /**************************** Program start *****************************/
958 log_init(logfilename);
961 log_text("CACAO started -------------------------------------------------------");
963 /* initialize JavaVM */
965 vm_args.version = 0x00010001; /* New in 1.1.2: VM version */
967 /* Get the default initialization arguments and set the class path */
969 JNI_GetDefaultJavaVMInitArgs(&vm_args);
971 vm_args.minHeapSize = heapstartsize;
972 vm_args.maxHeapSize = heapmaxsize;
974 vm_args.classpath = classpath;
976 /* load and initialize a Java VM, return a JNI interface pointer in env */
978 JNI_CreateJavaVM(&jvm, &env, &vm_args);
980 #if defined(ENABLE_JVMTI)
981 set_jvmti_phase(JVMTI_PHASE_START);
984 /* initialize the garbage collector */
986 gc_init(heapmaxsize, heapstartsize);
990 /* initialize the loader with bootclasspath */
992 suck_init(bootclasspath);
994 cacao_initializing = true;
996 #if defined(USE_THREADS)
997 #if defined(NATIVE_THREADS)
1003 /* install architecture dependent signal handler used for exceptions */
1007 /* initialize the codegen sub systems */
1011 /* initializes jit compiler */
1015 /* machine dependent initialization */
1019 /* initialize some cacao subsystems */
1023 if (!loader_init((u1 *) &dummy))
1024 throw_main_exception_exit();
1027 throw_main_exception_exit();
1030 throw_main_exception_exit();
1032 if (!exceptions_init())
1033 throw_main_exception_exit();
1035 if (!builtin_init())
1036 throw_main_exception_exit();
1038 #if defined(USE_THREADS)
1039 initThreads((u1 *) &dummy);
1042 *threadrootmethod = NULL;
1044 /*That's important, otherwise we get into trouble, if the Runtime static
1045 initializer is called before (circular dependency. This is with
1046 classpath 0.09. Another important thing is, that this has to happen
1047 after initThreads!!! */
1049 if (!initialize_class(class_java_lang_System))
1050 throw_main_exception_exit();
1052 cacao_initializing = false;
1055 /* start worker routines **************************************************/
1058 classinfo *mainclass; /* java/lang/Class */
1060 java_objectarray *a;
1063 /* set return value to OK */
1068 /* open jar file with java.util.jar.JarFile */
1069 mainstring = getmainclassnamefromjar(mainstring);
1072 /* load the main class */
1074 if (!(mainclass = load_class_from_sysloader(utf_new_char(mainstring))))
1075 throw_main_exception_exit();
1077 /* error loading class, clear exceptionptr for new exception */
1079 if (*exceptionptr || !mainclass) {
1080 /* *exceptionptr = NULL; */
1082 /* *exceptionptr = */
1083 /* new_exception_message(string_java_lang_NoClassDefFoundError, */
1085 throw_main_exception_exit();
1088 /* find the `main' method of the main class */
1090 m = class_resolveclassmethod(mainclass,
1091 utf_new_char("main"),
1092 utf_new_char("([Ljava/lang/String;)V"),
1093 class_java_lang_Object,
1096 if (*exceptionptr) {
1097 throw_main_exception_exit();
1100 /* there is no main method or it isn't static */
1102 if (!m || !(m->flags & ACC_STATIC)) {
1103 *exceptionptr = NULL;
1106 new_exception_message(string_java_lang_NoSuchMethodError,
1108 throw_main_exception_exit();
1111 /* build argument array */
1113 a = builtin_anewarray(argc - opt_ind, class_java_lang_String);
1114 for (i = opt_ind; i < argc; i++) {
1115 a->data[i - opt_ind] =
1116 (java_objectheader *) javastring_new(utf_new_char(argv[i]));
1119 #ifdef TYPEINFO_DEBUG_TEST
1120 /* test the typeinfo system */
1123 /*class_showmethods(currentThread->group->header.vftbl->class); */
1125 *threadrootmethod = m;
1129 asm_calljavafunction(m, a, NULL, NULL, NULL);
1131 /* exception occurred? */
1132 if (*exceptionptr) {
1133 throw_main_exception();
1137 #if defined(USE_THREADS)
1138 #if defined(NATIVE_THREADS)
1141 killThread(currentThread);
1145 /* now exit the JavaVM */
1147 /* (*jvm)->DestroyJavaVM(jvm); */
1152 /************* If requested, compile all methods ********************/
1159 classcache_name_entry *nmen;
1160 classcache_class_entry *clsen;
1162 /* create all classes found in the classpath */
1163 /* XXX currently only works with zip/jar's */
1165 loader_load_all_classes();
1167 /* link all classes */
1169 for (slot = 0; slot < classcache_hash.size; slot++) {
1170 nmen = (classcache_name_entry *) classcache_hash.ptr[slot];
1172 for (; nmen; nmen = nmen->hashlink) {
1173 /* iterate over all class entries */
1175 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
1176 c = clsen->classobj;
1183 /*utf_fprint_classname(stderr,c->name);fprintf(stderr,"\n");*/
1187 throw_main_exception_exit();
1189 /* compile all class methods */
1190 for (i = 0; i < c->methodscount; i++) {
1191 m = &(c->methods[i]);
1193 /*fprintf(stderr," compiling:");utf_fprint(stderr,m->name);fprintf(stderr,"\n");*/
1194 (void) jit_compile(m);
1203 /******** If requested, compile a specific method ***************/
1205 if (specificmethodname) {
1208 /* create, load and link the main class */
1210 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
1211 throw_main_exception_exit();
1213 if (!link_class(mainclass))
1214 throw_main_exception_exit();
1216 if (specificsignature) {
1217 m = class_resolveclassmethod(mainclass,
1218 utf_new_char(specificmethodname),
1219 utf_new_char(specificsignature),
1223 m = class_resolveclassmethod(mainclass,
1224 utf_new_char(specificmethodname),
1231 char message[MAXLOGTEXT];
1232 sprintf(message, "%s%s", specificmethodname,
1233 specificsignature ? specificsignature : "");
1236 new_exception_message(string_java_lang_NoSuchMethodException,
1239 throw_main_exception_exit();
1247 /* keep compiler happy */
1253 /* cacao_exit ******************************************************************
1255 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1257 *******************************************************************************/
1259 void cacao_exit(s4 status)
1264 assert(class_java_lang_System);
1265 assert(class_java_lang_System->loaded);
1267 if (!link_class(class_java_lang_System))
1268 throw_main_exception_exit();
1270 /* call java.lang.System.exit(I)V */
1272 m = class_resolveclassmethod(class_java_lang_System,
1273 utf_new_char("exit"),
1275 class_java_lang_Object,
1279 throw_main_exception_exit();
1281 /* call the exit function with passed exit status */
1283 /* both inlinevirtual and outsiders not allowed on exit */
1284 /* not sure if permanant or temp restriction */
1285 if (inlinevirtuals) inlineoutsiders = false;
1287 asm_calljavafunction(m, (void *) (ptrint) status, NULL, NULL, NULL);
1289 /* this should never happen */
1292 throw_exception_exit();
1294 throw_cacao_exception_exit(string_java_lang_InternalError,
1295 "System.exit(I)V returned without exception");
1299 /*************************** Shutdown function *********************************
1301 Terminates the system immediately without freeing memory explicitly (to be
1302 used only for abnormal termination)
1304 *******************************************************************************/
1306 void cacao_shutdown(s4 status)
1308 if (opt_verbose || getcompilingtime || opt_stat) {
1309 log_text("CACAO terminated by shutdown");
1310 dolog("Exit status: %d\n", (s4) status);
1318 * These are local overrides for various environment variables in Emacs.
1319 * Please do not remove this and leave it at the end of the file, where
1320 * Emacs will automagically detect them.
1321 * ---------------------------------------------------------------------
1324 * indent-tabs-mode: t