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 3377 2005-10-06 13:13:08Z 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 /* CACAO related stuff ********************************************************/
92 bool cacao_initializing;
96 /* Invocation API variables ***************************************************/
98 JavaVM *jvm; /* denotes a Java VM */
99 JNIEnv *env; /* pointer to native method interface */
101 JDK1_1InitArgs vm_args; /* JDK 1.1 VM initialization arguments */
104 char *bootclasspath; /* contains the boot classpath */
105 char *classpath; /* contains the classpath */
108 static classinfo *mainclass;
110 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
111 void **stackbottom = 0;
115 /* define command line options ************************************************/
117 #define OPT_CLASSPATH 2
121 #define OPT_VERBOSE1 6
122 #define OPT_VERBOSE 7
123 #define OPT_VERBOSESPECIFIC 8
124 #define OPT_VERBOSECALL 9
125 #define OPT_NOIEEE 10
126 #define OPT_SOFTNULL 11
129 #if defined(STATISTICS)
131 #endif /* defined(STATISTICS) */
136 #define OPT_METHOD 17
137 #define OPT_SIGNATURE 18
141 #define OPT_INLINING 25
143 #define STATIC_ANALYSIS
144 #if defined(STATIC_ANALYSIS)
148 #endif /* defined(STATIC_ANALYSIS) */
150 #define OPT_VERBOSETC 29
151 #define OPT_NOVERIFY 30
152 #define OPT_LIBERALUTF 31
153 #define OPT_VERBOSEEXCEPTION 32
158 #endif /* defined(LSRA) */
161 #define OPT_BOOTCLASSPATH 36
162 #define OPT_BOOTCLASSPATH_A 37
163 #define OPT_BOOTCLASSPATH_P 38
164 #define OPT_VERSION 39
165 #define OPT_SHOWVERSION 40
166 #define OPT_FULLVERSION 41
172 #define OPT_INTRP 103
174 #define OPT_STATIC_SUPERS 104
175 #define OPT_TRACE 105
180 opt_struct opts[] = {
181 { "classpath", true, OPT_CLASSPATH },
182 { "cp", true, OPT_CLASSPATH },
183 { "D", true, OPT_D },
184 { "noasyncgc", false, OPT_IGNORE },
185 { "noverify", false, OPT_NOVERIFY },
186 { "liberalutf", false, OPT_LIBERALUTF },
187 { "v", false, OPT_VERBOSE1 },
188 { "verbose", false, OPT_VERBOSE },
189 { "verbose:", true, OPT_VERBOSESPECIFIC },
190 { "verbosecall", false, OPT_VERBOSECALL },
191 { "verboseexception", false, OPT_VERBOSEEXCEPTION },
192 #ifdef TYPECHECK_VERBOSE
193 { "verbosetc", false, OPT_VERBOSETC },
195 #if defined(__ALPHA__)
196 { "noieee", false, OPT_NOIEEE },
198 { "softnull", false, OPT_SOFTNULL },
199 { "time", false, OPT_TIME },
200 #if defined(STATISTICS)
201 { "stat", false, OPT_STAT },
203 { "log", true, OPT_LOG },
204 { "c", true, OPT_CHECK },
205 { "l", false, OPT_LOAD },
206 { "eager", false, OPT_EAGER },
207 { "m", true, OPT_METHOD },
208 { "sig", true, OPT_SIGNATURE },
209 { "all", false, OPT_ALL },
210 { "oloop", false, OPT_OLOOP },
211 #ifdef STATIC_ANALYSIS
212 { "rt", false, OPT_RT },
213 { "xta", false, OPT_XTA },
214 { "vta", false, OPT_VTA },
217 { "lsra", false, OPT_LSRA },
219 { "jar", false, OPT_JAR },
220 { "version", false, OPT_VERSION },
221 { "showversion", false, OPT_SHOWVERSION },
222 { "fullversion", false, OPT_FULLVERSION },
223 { "help", false, OPT_HELP },
224 { "?", false, OPT_HELP },
226 /* interpreter options */
228 { "trace", false, OPT_TRACE },
229 { "static-supers", true, OPT_STATIC_SUPERS },
233 { "X", false, OPT_X },
234 { "Xjit", false, OPT_JIT },
235 { "Xint", false, OPT_INTRP },
236 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
237 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
238 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
239 { "Xms", true, OPT_MS },
240 { "Xmx", true, OPT_MX },
241 { "Xss", true, OPT_SS },
242 { "ms", true, OPT_MS },
243 { "mx", true, OPT_MX },
244 { "ss", true, OPT_SS },
246 /* keep these at the end of the list */
248 { "i", true, OPT_INLINING },
249 { "s", true, OPT_SHOW },
255 /* usage ***********************************************************************
257 Prints the correct usage syntax to stdout.
259 *******************************************************************************/
261 static void usage(void)
263 printf("Usage: cacao [-options] classname [arguments]\n");
264 printf(" (to run a class file)\n");
265 printf(" cacao [-options] -jar jarfile [arguments]\n");
266 printf(" (to run a standalone jar file)\n\n");
268 printf("Java options:\n");
269 printf(" -cp <path> specify a path to look for classes\n");
270 printf(" -classpath <path> specify a path to look for classes\n");
271 printf(" -D<name>=<value> add an entry to the property list\n");
272 printf(" -verbose[:class|gc|jni] enable specific verbose output\n");
273 printf(" -version print product version and exit\n");
274 printf(" -fullversion print jpackage-compatible product version and exit\n");
275 printf(" -showversion print product version and continue\n");
276 printf(" -help, -? print this help message\n");
277 printf(" -X print help on non-standard Java options\n\n");
279 printf("CACAO options:\n");
280 printf(" -v write state-information\n");
281 printf(" -verbose write more information\n");
282 printf(" -verbosegc write message for each GC\n");
283 printf(" -verbosecall write message for each call\n");
284 printf(" -verboseexception write message for each step of stack unwinding\n");
285 #ifdef TYPECHECK_VERBOSE
286 printf(" -verbosetc write debug messages while typechecking\n");
288 #if defined(__ALPHA__)
289 printf(" -noieee don't use ieee compliant arithmetic\n");
291 printf(" -noverify don't verify classfiles\n");
292 printf(" -liberalutf don't warn about overlong UTF-8 sequences\n");
293 printf(" -softnull use software nullpointer check\n");
294 printf(" -time measure the runtime\n");
295 #if defined(STATISTICS)
296 printf(" -stat detailed compiler statistics\n");
298 printf(" -log logfile specify a name for the logfile\n");
299 printf(" -c(heck)b(ounds) don't check array bounds\n");
300 printf(" s(ync) don't check for synchronization\n");
301 printf(" -oloop optimize array accesses in loops\n");
302 printf(" -l don't start the class after loading\n");
303 printf(" -eager perform eager class loading and linking\n");
304 printf(" -all compile all methods, no execution\n");
305 printf(" -m compile only a specific method\n");
306 printf(" -sig specify signature for a specific method\n");
307 printf(" -s(how)a(ssembler) show disassembled listing\n");
308 printf(" c(onstants) show the constant pool\n");
309 printf(" d(atasegment) show data segment listing\n");
310 printf(" e(xceptionstubs) show disassembled exception stubs (only with -sa)\n");
311 printf(" i(ntermediate) show intermediate representation\n");
312 printf(" m(ethods) show class fields and methods\n");
313 printf(" n(ative) show disassembled native stubs\n");
314 printf(" u(tf) show the utf - hash\n");
315 printf(" -i n(line) activate inlining\n");
316 printf(" v(irtual) inline virtual methods (uses/turns rt option on)\n");
317 printf(" e(exception) inline methods with exceptions\n");
318 printf(" p(aramopt) optimize argument renaming\n");
319 printf(" o(utsiders) inline methods of foreign classes\n");
320 #ifdef STATIC_ANALYSIS
321 printf(" -rt use rapid type analysis\n");
322 printf(" -xta use x type analysis\n");
323 printf(" -vta use variable type analysis\n");
326 printf(" -lsra use linear scan register allocation\n");
329 /* exit with error code */
335 static void Xusage(void)
337 #if defined(ENABLE_JIT)
338 printf(" -Xjit JIT mode execution (default)\n");
340 #if defined(ENABLE_INTRP)
341 printf(" -Xint interpreter mode execution\n");
343 printf(" -Xbootclasspath:<zip/jar files and directories separated by :>\n");
344 printf(" value is set as bootstrap class path\n");
345 printf(" -Xbootclasspath/a:<zip/jar files and directories separated by :>\n");
346 printf(" value is appended to the bootstrap class path\n");
347 printf(" -Xbootclasspath/p:<zip/jar files and directories separated by :>\n");
348 printf(" value is prepended to the bootstrap class path\n");
349 printf(" -Xms<size> set the initial size of the heap (default: 2MB)\n");
350 printf(" -Xmx<size> set the maximum size of the heap (default: 64MB)\n");
351 printf(" -Xss<size> set the thread stack size (default: 128kB)\n");
353 /* exit with error code */
359 /* version *********************************************************************
361 Only prints cacao version information.
363 *******************************************************************************/
365 static void version(void)
367 printf("java version \""JAVA_VERSION"\"\n");
368 printf("CACAO version "VERSION"\n");
370 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
371 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
372 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
373 printf("Institut f. Computersprachen - TU Wien\n\n");
375 printf("This program is free software; you can redistribute it and/or\n");
376 printf("modify it under the terms of the GNU General Public License as\n");
377 printf("published by the Free Software Foundation; either version 2, or (at\n");
378 printf("your option) any later version.\n\n");
380 printf("This program is distributed in the hope that it will be useful, but\n");
381 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
382 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
383 printf("General Public License for more details.\n");
387 /* fullversion *****************************************************************
389 Prints a Sun compatible version information (required e.g. by
390 jpackage, www.jpackage.org).
392 *******************************************************************************/
394 static void fullversion(void)
396 printf("java full version \"cacao-"JAVA_VERSION"\"\n");
404 #ifdef TYPECHECK_STATISTICS
405 void typecheck_print_statistics(FILE *file);
410 /* getmainclassfromjar *********************************************************
412 Gets the name of the main class form a JAR's manifest file.
414 *******************************************************************************/
416 static char *getmainclassnamefromjar(char *mainstring)
419 java_objectheader *o;
423 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
426 throw_main_exception_exit();
428 /* create JarFile object */
433 throw_main_exception_exit();
436 m = class_resolveclassmethod(c,
438 utf_java_lang_String__void,
439 class_java_lang_Object,
443 throw_main_exception_exit();
445 s = javastring_new_char(mainstring);
447 asm_calljavafunction(m, o, s, NULL, NULL);
450 throw_main_exception_exit();
452 /* get manifest object */
454 m = class_resolveclassmethod(c,
455 utf_new_char("getManifest"),
456 utf_new_char("()Ljava/util/jar/Manifest;"),
457 class_java_lang_Object,
461 throw_main_exception_exit();
463 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
466 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
471 /* get Main Attributes */
473 m = class_resolveclassmethod(o->vftbl->class,
474 utf_new_char("getMainAttributes"),
475 utf_new_char("()Ljava/util/jar/Attributes;"),
476 class_java_lang_Object,
480 throw_main_exception_exit();
482 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
485 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
490 /* get property Main-Class */
492 m = class_resolveclassmethod(o->vftbl->class,
493 utf_new_char("getValue"),
494 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
495 class_java_lang_Object,
499 throw_main_exception_exit();
501 s = javastring_new_char("Main-Class");
503 o = asm_calljavafunction(m, o, s, NULL, NULL);
506 throw_main_exception_exit();
508 return javastring_tochar(o);
512 void exit_handler(void);
515 /* main ************************************************************************
519 *******************************************************************************/
521 int main(int argc, char **argv)
526 /* local variables ********************************************************/
528 char logfilename[200] = "";
534 char *specificmethodname = NULL;
535 char *specificsignature = NULL;
538 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
539 stackbottom = &dummy;
542 if (atexit(exit_handler))
543 throw_cacao_exception_exit(string_java_lang_InternalError,
544 "Unable to register exit_handler");
546 /* initialize global variables */
548 cacao_exiting = false;
551 /************ Collect info from the environment ************************/
553 /* set the bootclasspath */
555 cp = getenv("BOOTCLASSPATH");
557 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
558 strcpy(bootclasspath, cp);
561 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_VM_ZIP_PATH) +
563 strlen(CLASSPATH_INSTALL_DIR) +
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, CLASSPATH_INSTALL_DIR);
572 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
576 /* set the classpath */
578 cp = getenv("CLASSPATH");
580 classpath = MNEW(char, strlen(cp) + strlen("0"));
581 strcat(classpath, cp);
584 classpath = MNEW(char, strlen(".") + strlen("0"));
585 strcpy(classpath, ".");
589 /***************** Interpret the command line *****************/
594 heapmaxsize = HEAP_MAXSIZE;
595 heapstartsize = HEAP_STARTSIZE;
596 opt_stacksize = STACK_SIZE;
598 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
603 case OPT_BOOTCLASSPATH:
604 /* Forget default bootclasspath and set the argument as new boot */
606 MFREE(bootclasspath, char, strlen(bootclasspath));
608 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
609 strcpy(bootclasspath, opt_arg);
612 case OPT_BOOTCLASSPATH_A:
613 /* append to end of bootclasspath */
614 cplen = strlen(bootclasspath);
616 bootclasspath = MREALLOC(bootclasspath,
619 cplen + strlen(":") +
620 strlen(opt_arg) + strlen("0"));
622 strcat(bootclasspath, ":");
623 strcat(bootclasspath, opt_arg);
626 case OPT_BOOTCLASSPATH_P:
627 /* prepend in front of bootclasspath */
631 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
632 cplen + strlen("0"));
634 strcpy(bootclasspath, opt_arg);
635 strcat(bootclasspath, ":");
636 strcat(bootclasspath, cp);
638 MFREE(cp, char, cplen);
642 /* forget old classpath and set the argument as new classpath */
643 MFREE(classpath, char, strlen(classpath));
645 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
646 strcpy(classpath, opt_arg);
655 for (j = 0; j < strlen(opt_arg); j++) {
656 if (opt_arg[j] == '=') {
658 create_property(opt_arg, opt_arg + j + 1);
663 /* if no '=' is given, just create an empty property */
664 create_property(opt_arg, "");
675 c = opt_arg[strlen(opt_arg) - 1];
677 if (c == 'k' || c == 'K') {
678 j = 1024 * atoi(opt_arg);
680 } else if (c == 'm' || c == 'M') {
681 j = 1024 * 1024 * atoi(opt_arg);
688 else if (i == OPT_MS)
704 compileverbose = true;
707 case OPT_VERBOSESPECIFIC:
708 if (strcmp("class", opt_arg) == 0)
709 opt_verboseclass = true;
711 else if (strcmp("gc", opt_arg) == 0)
712 opt_verbosegc = true;
714 else if (strcmp("jni", opt_arg) == 0)
715 opt_verbosejni = true;
718 case OPT_VERBOSEEXCEPTION:
719 opt_verboseexception = true;
722 #ifdef TYPECHECK_VERBOSE
724 typecheckverbose = true;
728 case OPT_VERBOSECALL:
737 case OPT_FULLVERSION:
741 case OPT_SHOWVERSION:
754 opt_liberalutf = true;
762 getcompilingtime = true;
763 getloadingtime = true;
766 #if defined(STATISTICS)
773 strcpy(logfilename, opt_arg);
777 for (j = 0; j < strlen(opt_arg); j++) {
778 switch (opt_arg[j]) {
793 makeinitializations = false;
802 specificmethodname = opt_arg;
803 makeinitializations = false;
807 specificsignature = opt_arg;
813 makeinitializations = false;
816 case OPT_SHOW: /* Display options */
817 for (j = 0; j < strlen(opt_arg); j++) {
818 switch (opt_arg[j]) {
820 opt_showdisassemble = true;
821 compileverbose = true;
824 showconstantpool = true;
827 opt_showddatasegment = true;
830 opt_showexceptionstubs = true;
833 opt_showintermediate = true;
834 compileverbose = true;
840 opt_shownativestub = true;
856 for (j = 0; j < strlen(opt_arg); j++) {
857 switch (opt_arg[j]) {
859 /* define in options.h; Used in main.c, jit.c & inline.c */
868 inlinevirtuals = true;
872 inlineexceptions = true;
875 inlineparamopt = true;
878 inlineoutsiders = true;
886 #ifdef STATIC_ANALYSIS
888 opt_rt = true; /* default for inlining */
892 opt_xta = true; /* in test currently */
896 printf("\nVTA is not yet available\n");
898 /***opt_vta = true; not yet **/
917 #if defined(ENABLE_JIT)
920 printf("-Xjit option not enabled.\n");
926 #if defined(ENABLE_INTRP)
929 printf("-Xint option not enabled.\n");
934 case OPT_STATIC_SUPERS:
935 opt_static_supers = atoi(opt_arg);
943 printf("Unknown option: %s\n", argv[opt_ind]);
952 /* transform dots into slashes in the class name */
954 mainstring = argv[opt_ind++];
957 /* do not mangle jar filename */
959 for (i = strlen(mainstring) - 1; i >= 0; i--) {
960 if (mainstring[i] == '.') mainstring[i] = '/';
964 /* put jarfile in classpath */
968 classpath = MNEW(char, strlen(mainstring) + strlen(":") +
969 strlen(classpath) + strlen("0"));
971 strcpy(classpath, mainstring);
972 strcat(classpath, ":");
973 strcat(classpath, cp);
975 MFREE(cp, char, strlen(cp));
978 /**************************** Program start *****************************/
980 log_init(logfilename);
983 log_text("CACAO started -------------------------------------------------------");
985 /* initialize JavaVM */
987 vm_args.version = 0x00010001; /* New in 1.1.2: VM version */
989 /* Get the default initialization arguments and set the class path */
991 JNI_GetDefaultJavaVMInitArgs(&vm_args);
993 vm_args.minHeapSize = heapstartsize;
994 vm_args.maxHeapSize = heapmaxsize;
996 vm_args.classpath = classpath;
998 /* load and initialize a Java VM, return a JNI interface pointer in env */
1000 JNI_CreateJavaVM(&jvm, &env, &vm_args);
1002 #if defined(ENABLE_JVMTI)
1003 set_jvmti_phase(JVMTI_PHASE_START);
1006 /* initialize the garbage collector */
1008 gc_init(heapmaxsize, heapstartsize);
1010 #if defined(ENABLE_INTRP)
1011 /* allocate main thread stack */
1014 intrp_main_stack = (u1 *) alloca(opt_stacksize);
1015 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1021 /* initialize the loader with bootclasspath */
1023 suck_init(bootclasspath);
1025 cacao_initializing = true;
1027 #if defined(USE_THREADS)
1028 #if defined(NATIVE_THREADS)
1034 /* install architecture dependent signal handler used for exceptions */
1038 /* initialize the codegen sub systems */
1042 /* initializes jit compiler */
1046 /* machine dependent initialization */
1050 /* initialize some cacao subsystems */
1054 if (!loader_init((u1 *) &dummy))
1055 throw_main_exception_exit();
1058 throw_main_exception_exit();
1061 throw_main_exception_exit();
1063 if (!exceptions_init())
1064 throw_main_exception_exit();
1066 if (!builtin_init())
1067 throw_main_exception_exit();
1069 #if defined(USE_THREADS)
1070 initThreads((u1 *) &dummy);
1073 /* That's important, otherwise we get into trouble, if the Runtime
1074 static initializer is called before (circular dependency. This
1075 is with classpath 0.09. Another important thing is, that this
1076 has to happen after initThreads!!! */
1078 if (!initialize_class(class_java_lang_System))
1079 throw_main_exception_exit();
1081 cacao_initializing = false;
1084 /* start worker routines **************************************************/
1087 classinfo *mainclass; /* java/lang/Class */
1089 java_objectarray *a;
1092 /* set return value to OK */
1097 /* open jar file with java.util.jar.JarFile */
1098 mainstring = getmainclassnamefromjar(mainstring);
1101 /* load the main class */
1103 if (!(mainclass = load_class_from_sysloader(utf_new_char(mainstring))))
1104 throw_main_exception_exit();
1106 /* error loading class, clear exceptionptr for new exception */
1108 if (*exceptionptr || !mainclass) {
1109 /* *exceptionptr = NULL; */
1111 /* *exceptionptr = */
1112 /* new_exception_message(string_java_lang_NoClassDefFoundError, */
1114 throw_main_exception_exit();
1117 /* find the `main' method of the main class */
1119 m = class_resolveclassmethod(mainclass,
1120 utf_new_char("main"),
1121 utf_new_char("([Ljava/lang/String;)V"),
1122 class_java_lang_Object,
1125 if (*exceptionptr) {
1126 throw_main_exception_exit();
1129 /* there is no main method or it isn't static */
1131 if (!m || !(m->flags & ACC_STATIC)) {
1132 *exceptionptr = NULL;
1135 new_exception_message(string_java_lang_NoSuchMethodError,
1137 throw_main_exception_exit();
1140 /* build argument array */
1142 a = builtin_anewarray(argc - opt_ind, class_java_lang_String);
1143 for (i = opt_ind; i < argc; i++) {
1144 a->data[i - opt_ind] =
1145 (java_objectheader *) javastring_new(utf_new_char(argv[i]));
1148 #ifdef TYPEINFO_DEBUG_TEST
1149 /* test the typeinfo system */
1152 /*class_showmethods(currentThread->group->header.vftbl->class); */
1156 asm_calljavafunction(m, a, NULL, NULL, NULL);
1158 /* exception occurred? */
1159 if (*exceptionptr) {
1160 throw_main_exception();
1164 #if defined(USE_THREADS)
1165 #if defined(NATIVE_THREADS)
1168 killThread(currentThread);
1172 /* now exit the JavaVM */
1174 /* (*jvm)->DestroyJavaVM(jvm); */
1179 /************* If requested, compile all methods ********************/
1186 classcache_name_entry *nmen;
1187 classcache_class_entry *clsen;
1189 /* create all classes found in the classpath */
1190 /* XXX currently only works with zip/jar's */
1192 loader_load_all_classes();
1194 /* link all classes */
1196 for (slot = 0; slot < classcache_hash.size; slot++) {
1197 nmen = (classcache_name_entry *) classcache_hash.ptr[slot];
1199 for (; nmen; nmen = nmen->hashlink) {
1200 /* iterate over all class entries */
1202 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
1203 c = clsen->classobj;
1210 /*utf_fprint_classname(stderr,c->name);fprintf(stderr,"\n");*/
1214 throw_main_exception_exit();
1216 /* compile all class methods */
1217 for (i = 0; i < c->methodscount; i++) {
1218 m = &(c->methods[i]);
1220 /*fprintf(stderr," compiling:");utf_fprint(stderr,m->name);fprintf(stderr,"\n");*/
1221 (void) jit_compile(m);
1230 /******** If requested, compile a specific method ***************/
1232 if (specificmethodname) {
1235 /* create, load and link the main class */
1237 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
1238 throw_main_exception_exit();
1240 if (!link_class(mainclass))
1241 throw_main_exception_exit();
1243 if (specificsignature) {
1244 m = class_resolveclassmethod(mainclass,
1245 utf_new_char(specificmethodname),
1246 utf_new_char(specificsignature),
1250 m = class_resolveclassmethod(mainclass,
1251 utf_new_char(specificmethodname),
1258 char message[MAXLOGTEXT];
1259 sprintf(message, "%s%s", specificmethodname,
1260 specificsignature ? specificsignature : "");
1263 new_exception_message(string_java_lang_NoSuchMethodException,
1266 throw_main_exception_exit();
1274 /* keep compiler happy */
1280 /* cacao_exit ******************************************************************
1282 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1284 *******************************************************************************/
1286 void cacao_exit(s4 status)
1290 assert(class_java_lang_System);
1291 assert(class_java_lang_System->loaded);
1293 if (!link_class(class_java_lang_System))
1294 throw_main_exception_exit();
1296 /* signal that we are exiting */
1298 cacao_exiting = true;
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