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 3242 2005-09-21 14:54:55Z 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 */
83 #define STACK_SIZE 128 * 1024; /* default 128kB */
85 #if defined(ENABLE_INTRP)
90 /* Invocation API variables ***************************************************/
92 JavaVM *jvm; /* denotes a Java VM */
93 JNIEnv *env; /* pointer to native method interface */
95 JDK1_1InitArgs vm_args; /* JDK 1.1 VM initialization arguments */
98 bool cacao_initializing;
100 char *bootclasspath; /* contains the boot classpath */
101 char *classpath; /* contains the classpath */
104 static classinfo *mainclass;
106 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
107 void **stackbottom = 0;
111 /* define command line options ************************************************/
113 #define OPT_CLASSPATH 2
117 #define OPT_VERBOSE1 6
118 #define OPT_VERBOSE 7
119 #define OPT_VERBOSESPECIFIC 8
120 #define OPT_VERBOSECALL 9
121 #define OPT_NOIEEE 10
122 #define OPT_SOFTNULL 11
125 #if defined(STATISTICS)
127 #endif /* defined(STATISTICS) */
132 #define OPT_METHOD 17
133 #define OPT_SIGNATURE 18
137 #define OPT_INLINING 25
139 #define STATIC_ANALYSIS
140 #if defined(STATIC_ANALYSIS)
144 #endif /* defined(STATIC_ANALYSIS) */
146 #define OPT_VERBOSETC 29
147 #define OPT_NOVERIFY 30
148 #define OPT_LIBERALUTF 31
149 #define OPT_VERBOSEEXCEPTION 32
154 #endif /* defined(LSRA) */
157 #define OPT_BOOTCLASSPATH 36
158 #define OPT_BOOTCLASSPATH_A 37
159 #define OPT_BOOTCLASSPATH_P 38
160 #define OPT_VERSION 39
161 #define OPT_SHOWVERSION 40
162 #define OPT_FULLVERSION 41
168 #define OPT_INTRP 103
170 #define OPT_STATIC_SUPERS 104
171 #define OPT_TRACE 105
176 opt_struct opts[] = {
177 { "classpath", true, OPT_CLASSPATH },
178 { "cp", true, OPT_CLASSPATH },
179 { "D", true, OPT_D },
180 { "noasyncgc", false, OPT_IGNORE },
181 { "noverify", false, OPT_NOVERIFY },
182 { "liberalutf", false, OPT_LIBERALUTF },
183 { "v", false, OPT_VERBOSE1 },
184 { "verbose", false, OPT_VERBOSE },
185 { "verbose:", true, OPT_VERBOSESPECIFIC },
186 { "verbosecall", false, OPT_VERBOSECALL },
187 { "verboseexception", false, OPT_VERBOSEEXCEPTION },
188 #ifdef TYPECHECK_VERBOSE
189 { "verbosetc", false, OPT_VERBOSETC },
191 #if defined(__ALPHA__)
192 { "noieee", false, OPT_NOIEEE },
194 { "softnull", false, OPT_SOFTNULL },
195 { "time", false, OPT_TIME },
196 #if defined(STATISTICS)
197 { "stat", false, OPT_STAT },
199 { "log", true, OPT_LOG },
200 { "c", true, OPT_CHECK },
201 { "l", false, OPT_LOAD },
202 { "eager", false, OPT_EAGER },
203 { "m", true, OPT_METHOD },
204 { "sig", true, OPT_SIGNATURE },
205 { "all", false, OPT_ALL },
206 { "oloop", false, OPT_OLOOP },
207 #ifdef STATIC_ANALYSIS
208 { "rt", false, OPT_RT },
209 { "xta", false, OPT_XTA },
210 { "vta", false, OPT_VTA },
213 { "lsra", false, OPT_LSRA },
215 { "jar", false, OPT_JAR },
216 { "version", false, OPT_VERSION },
217 { "showversion", false, OPT_SHOWVERSION },
218 { "fullversion", false, OPT_FULLVERSION },
219 { "help", false, OPT_HELP },
220 { "?", false, OPT_HELP },
222 /* interpreter options */
224 { "trace", false, OPT_TRACE },
225 { "static-supers", true, OPT_STATIC_SUPERS },
229 { "X", false, OPT_X },
230 { "Xjit", false, OPT_JIT },
231 { "Xint", false, OPT_INTRP },
232 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
233 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
234 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
235 { "Xms", true, OPT_MS },
236 { "Xmx", true, OPT_MX },
237 { "Xss", true, OPT_SS },
238 { "ms", true, OPT_MS },
239 { "mx", true, OPT_MX },
240 { "ss", true, OPT_SS },
242 /* keep these at the end of the list */
244 { "i", true, OPT_INLINING },
245 { "s", true, OPT_SHOW },
251 /* usage ***********************************************************************
253 Prints the correct usage syntax to stdout.
255 *******************************************************************************/
257 static void usage(void)
259 printf("Usage: cacao [-options] classname [arguments]\n");
260 printf(" (to run a class file)\n");
261 printf(" cacao [-options] -jar jarfile [arguments]\n");
262 printf(" (to run a standalone jar file)\n\n");
264 printf("Java options:\n");
265 printf(" -cp <path> specify a path to look for classes\n");
266 printf(" -classpath <path> specify a path to look for classes\n");
267 printf(" -D<name>=<value> add an entry to the property list\n");
268 printf(" -verbose[:class|gc|jni] enable specific verbose output\n");
269 printf(" -version print product version and exit\n");
270 printf(" -fullversion print jpackage-compatible product version and exit\n");
271 printf(" -showversion print product version and continue\n");
272 printf(" -help, -? print this help message\n");
273 printf(" -X print help on non-standard Java options\n\n");
275 printf("CACAO options:\n");
276 printf(" -v write state-information\n");
277 printf(" -verbose write more information\n");
278 printf(" -verbosegc write message for each GC\n");
279 printf(" -verbosecall write message for each call\n");
280 printf(" -verboseexception write message for each step of stack unwinding\n");
281 #ifdef TYPECHECK_VERBOSE
282 printf(" -verbosetc write debug messages while typechecking\n");
284 #if defined(__ALPHA__)
285 printf(" -noieee don't use ieee compliant arithmetic\n");
287 printf(" -noverify don't verify classfiles\n");
288 printf(" -liberalutf don't warn about overlong UTF-8 sequences\n");
289 printf(" -softnull use software nullpointer check\n");
290 printf(" -time measure the runtime\n");
291 #if defined(STATISTICS)
292 printf(" -stat detailed compiler statistics\n");
294 printf(" -log logfile specify a name for the logfile\n");
295 printf(" -c(heck)b(ounds) don't check array bounds\n");
296 printf(" s(ync) don't check for synchronization\n");
297 printf(" -oloop optimize array accesses in loops\n");
298 printf(" -l don't start the class after loading\n");
299 printf(" -eager perform eager class loading and linking\n");
300 printf(" -all compile all methods, no execution\n");
301 printf(" -m compile only a specific method\n");
302 printf(" -sig specify signature for a specific method\n");
303 printf(" -s(how)a(ssembler) show disassembled listing\n");
304 printf(" c(onstants) show the constant pool\n");
305 printf(" d(atasegment) show data segment listing\n");
306 printf(" e(xceptionstubs) show disassembled exception stubs (only with -sa)\n");
307 printf(" i(ntermediate) show intermediate representation\n");
308 printf(" m(ethods) show class fields and methods\n");
309 printf(" n(ative) show disassembled native stubs\n");
310 printf(" u(tf) show the utf - hash\n");
311 printf(" -i n(line) activate inlining\n");
312 printf(" v(irtual) inline virtual methods (uses/turns rt option on)\n");
313 printf(" e(exception) inline methods with exceptions\n");
314 printf(" p(aramopt) optimize argument renaming\n");
315 printf(" o(utsiders) inline methods of foreign classes\n");
316 #ifdef STATIC_ANALYSIS
317 printf(" -rt use rapid type analysis\n");
318 printf(" -xta use x type analysis\n");
319 printf(" -vta use variable type analysis\n");
322 printf(" -lsra use linear scan register allocation\n");
325 /* exit with error code */
331 static void Xusage(void)
333 #if defined(ENABLE_JIT)
334 printf(" -Xjit JIT mode execution (default)\n");
336 #if defined(ENABLE_INTRP)
337 printf(" -Xint interpreter mode execution\n");
339 printf(" -Xbootclasspath:<zip/jar files and directories separated by :>\n");
340 printf(" value is set as bootstrap class path\n");
341 printf(" -Xbootclasspath/a:<zip/jar files and directories separated by :>\n");
342 printf(" value is appended to the bootstrap class path\n");
343 printf(" -Xbootclasspath/p:<zip/jar files and directories separated by :>\n");
344 printf(" value is prepended to the bootstrap class path\n");
345 printf(" -Xms<size> set the initial size of the heap (default: 2MB)\n");
346 printf(" -Xmx<size> set the maximum size of the heap (default: 64MB)\n");
347 printf(" -Xss<size> set the thread stack size (default: 128kB)\n");
349 /* exit with error code */
355 /* version *********************************************************************
357 Only prints cacao version information.
359 *******************************************************************************/
361 static void version(void)
363 printf("java version \""JAVA_VERSION"\"\n");
364 printf("CACAO version "VERSION"\n");
366 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
367 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
368 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
369 printf("Institut f. Computersprachen - TU Wien\n\n");
371 printf("This program is free software; you can redistribute it and/or\n");
372 printf("modify it under the terms of the GNU General Public License as\n");
373 printf("published by the Free Software Foundation; either version 2, or (at\n");
374 printf("your option) any later version.\n\n");
376 printf("This program is distributed in the hope that it will be useful, but\n");
377 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
378 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
379 printf("General Public License for more details.\n");
383 /* fullversion *****************************************************************
385 Prints a Sun compatible version information (required e.g. by
386 jpackage, www.jpackage.org).
388 *******************************************************************************/
390 static void fullversion(void)
392 printf("java full version \"cacao-"JAVA_VERSION"\"\n");
400 #ifdef TYPECHECK_STATISTICS
401 void typecheck_print_statistics(FILE *file);
406 /* getmainclassfromjar *********************************************************
408 Gets the name of the main class form a JAR's manifest file.
410 *******************************************************************************/
412 static char *getmainclassnamefromjar(char *mainstring)
415 java_objectheader *o;
419 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
422 throw_main_exception_exit();
424 /* create JarFile object */
429 throw_main_exception_exit();
432 m = class_resolveclassmethod(c,
434 utf_java_lang_String__void,
435 class_java_lang_Object,
439 throw_main_exception_exit();
441 s = javastring_new_char(mainstring);
443 asm_calljavafunction(m, o, s, NULL, NULL);
446 throw_main_exception_exit();
448 /* get manifest object */
450 m = class_resolveclassmethod(c,
451 utf_new_char("getManifest"),
452 utf_new_char("()Ljava/util/jar/Manifest;"),
453 class_java_lang_Object,
457 throw_main_exception_exit();
459 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
462 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
467 /* get Main Attributes */
469 m = class_resolveclassmethod(o->vftbl->class,
470 utf_new_char("getMainAttributes"),
471 utf_new_char("()Ljava/util/jar/Attributes;"),
472 class_java_lang_Object,
476 throw_main_exception_exit();
478 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
481 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
486 /* get property Main-Class */
488 m = class_resolveclassmethod(o->vftbl->class,
489 utf_new_char("getValue"),
490 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
491 class_java_lang_Object,
495 throw_main_exception_exit();
497 s = javastring_new_char("Main-Class");
499 o = asm_calljavafunction(m, o, s, NULL, NULL);
502 throw_main_exception_exit();
504 return javastring_tochar(o);
508 void exit_handler(void);
511 /* main ************************************************************************
515 *******************************************************************************/
517 int main(int argc, char **argv)
522 /* local variables ********************************************************/
524 char logfilename[200] = "";
530 char *specificmethodname = NULL;
531 char *specificsignature = NULL;
534 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
535 stackbottom = &dummy;
538 if (atexit(exit_handler))
539 throw_cacao_exception_exit(string_java_lang_InternalError,
540 "Unable to register exit_handler");
543 /************ Collect info from the environment ************************/
545 /* set the bootclasspath */
547 cp = getenv("BOOTCLASSPATH");
549 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
550 strcpy(bootclasspath, cp);
553 #if !defined(WITH_EXTERNAL_CLASSPATH)
554 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_RT_JAR_PATH) +
557 bootclasspath = MNEW(char, cplen);
558 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
559 strcat(bootclasspath, CACAO_RT_JAR_PATH);
561 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_VM_ZIP_PATH) +
563 strlen(EXTERNAL_CLASSPATH_PREFIX) +
564 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
567 bootclasspath = MNEW(char, cplen);
568 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
569 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
570 strcat(bootclasspath, ":");
571 strcat(bootclasspath, EXTERNAL_CLASSPATH_PREFIX);
572 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
577 /* set the classpath */
579 cp = getenv("CLASSPATH");
581 classpath = MNEW(char, strlen(cp) + strlen("0"));
582 strcat(classpath, cp);
585 classpath = MNEW(char, strlen(".") + strlen("0"));
586 strcpy(classpath, ".");
590 /***************** Interpret the command line *****************/
595 heapmaxsize = HEAP_MAXSIZE;
596 heapstartsize = HEAP_STARTSIZE;
597 opt_stacksize = STACK_SIZE;
599 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
604 case OPT_BOOTCLASSPATH:
605 /* Forget default bootclasspath and set the argument as new boot */
607 MFREE(bootclasspath, char, strlen(bootclasspath));
609 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
610 strcpy(bootclasspath, opt_arg);
613 case OPT_BOOTCLASSPATH_A:
614 /* append to end of bootclasspath */
615 cplen = strlen(bootclasspath);
617 bootclasspath = MREALLOC(bootclasspath,
620 cplen + strlen(":") +
621 strlen(opt_arg) + strlen("0"));
623 strcat(bootclasspath, ":");
624 strcat(bootclasspath, opt_arg);
627 case OPT_BOOTCLASSPATH_P:
628 /* prepend in front of bootclasspath */
632 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
633 cplen + strlen("0"));
635 strcpy(bootclasspath, opt_arg);
636 strcat(bootclasspath, ":");
637 strcat(bootclasspath, cp);
639 MFREE(cp, char, cplen);
643 /* forget old classpath and set the argument as new classpath */
644 MFREE(classpath, char, strlen(classpath));
646 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
647 strcpy(classpath, opt_arg);
656 for (j = 0; j < strlen(opt_arg); j++) {
657 if (opt_arg[j] == '=') {
659 create_property(opt_arg, opt_arg + j + 1);
664 /* if no '=' is given, just create an empty property */
665 create_property(opt_arg, "");
676 c = opt_arg[strlen(opt_arg) - 1];
678 if (c == 'k' || c == 'K') {
679 j = 1024 * atoi(opt_arg);
681 } else if (c == 'm' || c == 'M') {
682 j = 1024 * 1024 * atoi(opt_arg);
689 else if (i == OPT_MS)
705 compileverbose = true;
708 case OPT_VERBOSESPECIFIC:
709 if (strcmp("class", opt_arg) == 0) {
713 } else if (strcmp("gc", opt_arg) == 0) {
714 opt_verbosegc = true;
716 } else if (strcmp("jni", opt_arg) == 0) {
717 opt_verbosejni = true;
721 case OPT_VERBOSEEXCEPTION:
722 verboseexception = true;
725 #ifdef TYPECHECK_VERBOSE
727 typecheckverbose = true;
731 case OPT_VERBOSECALL:
740 case OPT_FULLVERSION:
744 case OPT_SHOWVERSION:
757 opt_liberalutf = true;
765 getcompilingtime = true;
766 getloadingtime = true;
769 #if defined(STATISTICS)
776 strcpy(logfilename, opt_arg);
780 for (j = 0; j < strlen(opt_arg); j++) {
781 switch (opt_arg[j]) {
796 makeinitializations = false;
805 specificmethodname = opt_arg;
806 makeinitializations = false;
810 specificsignature = opt_arg;
816 makeinitializations = false;
819 case OPT_SHOW: /* Display options */
820 for (j = 0; j < strlen(opt_arg); j++) {
821 switch (opt_arg[j]) {
823 opt_showdisassemble = true;
824 compileverbose = true;
827 showconstantpool = true;
830 opt_showddatasegment = true;
833 opt_showexceptionstubs = true;
836 opt_showintermediate = true;
837 compileverbose = true;
843 opt_shownativestub = true;
859 for (j = 0; j < strlen(opt_arg); j++) {
860 switch (opt_arg[j]) {
862 /* define in options.h; Used in main.c, jit.c & inline.c */
871 inlinevirtuals = true;
875 inlineexceptions = true;
878 inlineparamopt = true;
881 inlineoutsiders = true;
889 #ifdef STATIC_ANALYSIS
891 opt_rt = true; /* default for inlining */
895 opt_xta = true; /* in test currently */
899 printf("\nVTA is not yet available\n");
901 /***opt_vta = true; not yet **/
920 #if defined(ENABLE_JIT)
923 printf("-Xjit option not enabled.\n");
929 #if defined(ENABLE_INTRP)
932 printf("-Xint option not enabled.\n");
937 case OPT_STATIC_SUPERS:
938 opt_static_supers = atoi(opt_arg);
946 printf("Unknown option: %s\n", argv[opt_ind]);
955 /* transform dots into slashes in the class name */
957 mainstring = argv[opt_ind++];
960 /* do not mangle jar filename */
962 for (i = strlen(mainstring) - 1; i >= 0; i--) {
963 if (mainstring[i] == '.') mainstring[i] = '/';
967 /* put jarfile in classpath */
971 classpath = MNEW(char, strlen(mainstring) + strlen(":") +
972 strlen(classpath) + strlen("0"));
974 strcpy(classpath, mainstring);
975 strcat(classpath, ":");
976 strcat(classpath, cp);
978 MFREE(cp, char, strlen(cp));
981 /**************************** Program start *****************************/
983 log_init(logfilename);
986 log_text("CACAO started -------------------------------------------------------");
988 /* initialize JavaVM */
990 vm_args.version = 0x00010001; /* New in 1.1.2: VM version */
992 /* Get the default initialization arguments and set the class path */
994 JNI_GetDefaultJavaVMInitArgs(&vm_args);
996 vm_args.minHeapSize = heapstartsize;
997 vm_args.maxHeapSize = heapmaxsize;
999 vm_args.classpath = classpath;
1001 /* load and initialize a Java VM, return a JNI interface pointer in env */
1003 JNI_CreateJavaVM(&jvm, &env, &vm_args);
1005 #if defined(ENABLE_JVMTI)
1006 set_jvmti_phase(JVMTI_PHASE_START);
1009 /* initialize the garbage collector */
1011 gc_init(heapmaxsize, heapstartsize);
1013 #if defined(ENABLE_INTRP)
1014 /* allocate main thread stack */
1017 intrp_main_stack = (u1 *) alloca(opt_stacksize);
1018 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1024 /* initialize the loader with bootclasspath */
1026 suck_init(bootclasspath);
1028 cacao_initializing = true;
1030 #if defined(USE_THREADS)
1031 #if defined(NATIVE_THREADS)
1037 /* install architecture dependent signal handler used for exceptions */
1041 /* initialize the codegen sub systems */
1045 /* initializes jit compiler */
1049 /* machine dependent initialization */
1053 /* initialize some cacao subsystems */
1057 if (!loader_init((u1 *) &dummy))
1058 throw_main_exception_exit();
1061 throw_main_exception_exit();
1064 throw_main_exception_exit();
1066 if (!exceptions_init())
1067 throw_main_exception_exit();
1069 if (!builtin_init())
1070 throw_main_exception_exit();
1072 #if defined(USE_THREADS)
1073 initThreads((u1 *) &dummy);
1076 /* That's important, otherwise we get into trouble, if the Runtime
1077 static initializer is called before (circular dependency. This
1078 is with classpath 0.09. Another important thing is, that this
1079 has to happen after initThreads!!! */
1081 if (!initialize_class(class_java_lang_System))
1082 throw_main_exception_exit();
1084 cacao_initializing = false;
1087 /* start worker routines **************************************************/
1090 classinfo *mainclass; /* java/lang/Class */
1092 java_objectarray *a;
1095 /* set return value to OK */
1100 /* open jar file with java.util.jar.JarFile */
1101 mainstring = getmainclassnamefromjar(mainstring);
1104 /* load the main class */
1106 if (!(mainclass = load_class_from_sysloader(utf_new_char(mainstring))))
1107 throw_main_exception_exit();
1109 /* error loading class, clear exceptionptr for new exception */
1111 if (*exceptionptr || !mainclass) {
1112 /* *exceptionptr = NULL; */
1114 /* *exceptionptr = */
1115 /* new_exception_message(string_java_lang_NoClassDefFoundError, */
1117 throw_main_exception_exit();
1120 /* find the `main' method of the main class */
1122 m = class_resolveclassmethod(mainclass,
1123 utf_new_char("main"),
1124 utf_new_char("([Ljava/lang/String;)V"),
1125 class_java_lang_Object,
1128 if (*exceptionptr) {
1129 throw_main_exception_exit();
1132 /* there is no main method or it isn't static */
1134 if (!m || !(m->flags & ACC_STATIC)) {
1135 *exceptionptr = NULL;
1138 new_exception_message(string_java_lang_NoSuchMethodError,
1140 throw_main_exception_exit();
1143 /* build argument array */
1145 a = builtin_anewarray(argc - opt_ind, class_java_lang_String);
1146 for (i = opt_ind; i < argc; i++) {
1147 a->data[i - opt_ind] =
1148 (java_objectheader *) javastring_new(utf_new_char(argv[i]));
1151 #ifdef TYPEINFO_DEBUG_TEST
1152 /* test the typeinfo system */
1155 /*class_showmethods(currentThread->group->header.vftbl->class); */
1159 asm_calljavafunction(m, a, NULL, NULL, NULL);
1161 /* exception occurred? */
1162 if (*exceptionptr) {
1163 throw_main_exception();
1167 #if defined(USE_THREADS)
1168 #if defined(NATIVE_THREADS)
1171 killThread(currentThread);
1175 /* now exit the JavaVM */
1177 /* (*jvm)->DestroyJavaVM(jvm); */
1182 /************* If requested, compile all methods ********************/
1189 classcache_name_entry *nmen;
1190 classcache_class_entry *clsen;
1192 /* create all classes found in the classpath */
1193 /* XXX currently only works with zip/jar's */
1195 loader_load_all_classes();
1197 /* link all classes */
1199 for (slot = 0; slot < classcache_hash.size; slot++) {
1200 nmen = (classcache_name_entry *) classcache_hash.ptr[slot];
1202 for (; nmen; nmen = nmen->hashlink) {
1203 /* iterate over all class entries */
1205 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
1206 c = clsen->classobj;
1213 /*utf_fprint_classname(stderr,c->name);fprintf(stderr,"\n");*/
1217 throw_main_exception_exit();
1219 /* compile all class methods */
1220 for (i = 0; i < c->methodscount; i++) {
1221 m = &(c->methods[i]);
1223 /*fprintf(stderr," compiling:");utf_fprint(stderr,m->name);fprintf(stderr,"\n");*/
1224 (void) jit_compile(m);
1233 /******** If requested, compile a specific method ***************/
1235 if (specificmethodname) {
1238 /* create, load and link the main class */
1240 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
1241 throw_main_exception_exit();
1243 if (!link_class(mainclass))
1244 throw_main_exception_exit();
1246 if (specificsignature) {
1247 m = class_resolveclassmethod(mainclass,
1248 utf_new_char(specificmethodname),
1249 utf_new_char(specificsignature),
1253 m = class_resolveclassmethod(mainclass,
1254 utf_new_char(specificmethodname),
1261 char message[MAXLOGTEXT];
1262 sprintf(message, "%s%s", specificmethodname,
1263 specificsignature ? specificsignature : "");
1266 new_exception_message(string_java_lang_NoSuchMethodException,
1269 throw_main_exception_exit();
1277 /* keep compiler happy */
1283 /* cacao_exit ******************************************************************
1285 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1287 *******************************************************************************/
1289 void cacao_exit(s4 status)
1294 assert(class_java_lang_System);
1295 assert(class_java_lang_System->loaded);
1297 if (!link_class(class_java_lang_System))
1298 throw_main_exception_exit();
1300 /* call java.lang.System.exit(I)V */
1302 m = class_resolveclassmethod(class_java_lang_System,
1303 utf_new_char("exit"),
1305 class_java_lang_Object,
1309 throw_main_exception_exit();
1311 /* call the exit function with passed exit status */
1313 /* both inlinevirtual and outsiders not allowed on exit */
1314 /* not sure if permanant or temp restriction */
1315 if (inlinevirtuals) inlineoutsiders = false;
1317 asm_calljavafunction(m, (void *) (ptrint) status, NULL, NULL, NULL);
1319 /* this should never happen */
1322 throw_exception_exit();
1324 throw_cacao_exception_exit(string_java_lang_InternalError,
1325 "System.exit(I)V returned without exception");
1329 /*************************** Shutdown function *********************************
1331 Terminates the system immediately without freeing memory explicitly (to be
1332 used only for abnormal termination)
1334 *******************************************************************************/
1336 void cacao_shutdown(s4 status)
1338 if (opt_verbose || getcompilingtime || opt_stat) {
1339 log_text("CACAO terminated by shutdown");
1340 dolog("Exit status: %d\n", (s4) status);
1347 /* exit_handler ****************************************************************
1349 The exit_handler function is called upon program termination.
1351 ATTENTION: Don't free system resources here! Some threads may still
1352 be running as this is called from VMRuntime.exit(). The OS does the
1355 *******************************************************************************/
1357 void exit_handler(void)
1359 /********************* Print debug tables ************************/
1361 if (showmethods) class_showmethods(mainclass);
1362 if (showconstantpool) class_showconstantpool(mainclass);
1363 if (showutf) utf_show();
1365 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
1366 clear_thread_flags(); /* restores standard file descriptor
1370 if (opt_verbose || getcompilingtime || opt_stat) {
1371 log_text("CACAO terminated");
1373 #if defined(STATISTICS)
1376 #ifdef TYPECHECK_STATISTICS
1377 typecheck_print_statistics(get_logfile());
1381 if (getcompilingtime)
1386 /* vm_print_profile(stderr);*/
1391 * These are local overrides for various environment variables in Emacs.
1392 * Please do not remove this and leave it at the end of the file, where
1393 * Emacs will automagically detect them.
1394 * ---------------------------------------------------------------------
1397 * indent-tabs-mode: t