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 3066 2005-07-19 12:35:37Z 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
162 opt_struct opts[] = {
163 { "classpath", true, OPT_CLASSPATH },
164 { "cp", true, OPT_CLASSPATH },
165 { "D", true, OPT_D },
166 { "Xms", true, OPT_MS },
167 { "Xmx", true, OPT_MX },
168 { "ms", true, OPT_MS },
169 { "mx", true, OPT_MX },
170 { "noasyncgc", false, OPT_IGNORE },
171 { "noverify", false, OPT_NOVERIFY },
172 { "liberalutf", false, OPT_LIBERALUTF },
173 { "ss", true, OPT_IGNORE },
174 { "v", false, OPT_VERBOSE1 },
175 { "verbose", false, OPT_VERBOSE },
176 { "verbose:", true, OPT_VERBOSESPECIFIC },
177 { "verbosecall", false, OPT_VERBOSECALL },
178 { "verboseexception", false, OPT_VERBOSEEXCEPTION },
179 #ifdef TYPECHECK_VERBOSE
180 { "verbosetc", false, OPT_VERBOSETC },
182 #if defined(__ALPHA__)
183 { "noieee", false, OPT_NOIEEE },
185 { "softnull", false, OPT_SOFTNULL },
186 { "time", false, OPT_TIME },
187 #if defined(STATISTICS)
188 { "stat", false, OPT_STAT },
190 { "log", true, OPT_LOG },
191 { "c", true, OPT_CHECK },
192 { "l", false, OPT_LOAD },
193 { "eager", false, OPT_EAGER },
194 { "m", true, OPT_METHOD },
195 { "sig", true, OPT_SIGNATURE },
196 { "s", true, OPT_SHOW },
197 { "all", false, OPT_ALL },
198 { "oloop", false, OPT_OLOOP },
199 { "i", true, OPT_INLINING },
200 #ifdef STATIC_ANALYSIS
201 { "rt", false, OPT_RT },
202 { "xta", false, OPT_XTA },
203 { "vta", false, OPT_VTA },
206 { "lsra", false, OPT_LSRA },
208 { "jar", false, OPT_JAR },
209 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
210 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
211 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
212 { "version", false, OPT_VERSION },
213 { "showversion", false, OPT_SHOWVERSION },
214 { "help", false, OPT_HELP },
215 { "?", false, OPT_HELP },
216 { "X", false, OPT_X },
221 /* usage ***********************************************************************
223 Prints the correct usage syntax to stdout.
225 *******************************************************************************/
227 static void usage(void)
229 printf("Usage: cacao [-options] classname [arguments]\n");
230 printf(" (to run a class file)\n");
231 printf(" cacao [-options] -jar jarfile [arguments]\n");
232 printf(" (to run a standalone jar file)\n\n");
234 printf("Java options:\n");
235 printf(" -cp <path> specify a path to look for classes\n");
236 printf(" -classpath <path> specify a path to look for classes\n");
237 printf(" -D<name>=<value> add an entry to the property list\n");
238 printf(" -verbose[:class|gc|jni] enable specific verbose output\n");
239 printf(" -version print product version and exit\n");
240 printf(" -showversion print product version and continue\n");
241 printf(" -help, -? print this help message\n");
242 printf(" -X print help on non-standard Java options\n\n");
244 printf("CACAO options:\n");
245 printf(" -v write state-information\n");
246 printf(" -verbose write more information\n");
247 printf(" -verbosegc write message for each GC\n");
248 printf(" -verbosecall write message for each call\n");
249 printf(" -verboseexception write message for each step of stack unwinding\n");
250 #ifdef TYPECHECK_VERBOSE
251 printf(" -verbosetc write debug messages while typechecking\n");
253 #if defined(__ALPHA__)
254 printf(" -noieee don't use ieee compliant arithmetic\n");
256 printf(" -noverify don't verify classfiles\n");
257 printf(" -liberalutf don't warn about overlong UTF-8 sequences\n");
258 printf(" -softnull use software nullpointer check\n");
259 printf(" -time measure the runtime\n");
260 #if defined(STATISTICS)
261 printf(" -stat detailed compiler statistics\n");
263 printf(" -log logfile specify a name for the logfile\n");
264 printf(" -c(heck)b(ounds) don't check array bounds\n");
265 printf(" s(ync) don't check for synchronization\n");
266 printf(" -oloop optimize array accesses in loops\n");
267 printf(" -l don't start the class after loading\n");
268 printf(" -eager perform eager class loading and linking\n");
269 printf(" -all compile all methods, no execution\n");
270 printf(" -m compile only a specific method\n");
271 printf(" -sig specify signature for a specific method\n");
272 printf(" -s(how)a(ssembler) show disassembled listing\n");
273 printf(" c(onstants) show the constant pool\n");
274 printf(" d(atasegment) show data segment listing\n");
275 printf(" e(xceptionstubs) show disassembled exception stubs (only with -sa)\n");
276 printf(" i(ntermediate) show intermediate representation\n");
277 printf(" m(ethods) show class fields and methods\n");
278 printf(" n(ative) show disassembled native stubs\n");
279 printf(" u(tf) show the utf - hash\n");
280 printf(" -i n(line) activate inlining\n");
281 printf(" v(irtual) inline virtual methods (uses/turns rt option on)\n");
282 printf(" e(exception) inline methods with exceptions\n");
283 printf(" p(aramopt) optimize argument renaming\n");
284 printf(" o(utsiders) inline methods of foreign classes\n");
285 #ifdef STATIC_ANALYSIS
286 printf(" -rt use rapid type analysis\n");
287 printf(" -xta use x type analysis\n");
288 printf(" -vta use variable type analysis\n");
291 printf(" -lsra use linear scan register allocation\n");
294 /* exit with error code */
300 static void Xusage(void)
302 printf(" -Xbootclasspath:<zip/jar files and directories separated by :>\n");
303 printf(" value is set as bootstrap class path\n");
304 printf(" -Xbootclasspath/a:<zip/jar files and directories separated by :>\n");
305 printf(" value is appended to the bootstrap class path\n");
306 printf(" -Xbootclasspath/p:<zip/jar files and directories separated by :>\n");
307 printf(" value is prepended to the bootstrap class path\n");
308 printf(" -Xms<size> set the initial size of the heap (default: 2M)\n");
309 printf(" -Xmx<size> set the maximum size of the heap (default: 64M)\n");
311 /* exit with error code */
317 /* version *********************************************************************
319 Only prints cacao version information.
321 *******************************************************************************/
323 static void version(void)
325 printf("CACAO version "VERSION"\n");
327 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
328 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
329 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
330 printf("Institut f. Computersprachen - TU Wien\n\n");
332 printf("This program is free software; you can redistribute it and/or\n");
333 printf("modify it under the terms of the GNU General Public License as\n");
334 printf("published by the Free Software Foundation; either version 2, or (at\n");
335 printf("your option) any later version.\n\n");
337 printf("This program is distributed in the hope that it will be useful, but\n");
338 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
339 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
340 printf("General Public License for more details.\n");
344 #ifdef TYPECHECK_STATISTICS
345 void typecheck_print_statistics(FILE *file);
350 /* getmainclassfromjar *********************************************************
352 Gets the name of the main class form a JAR's manifest file.
354 *******************************************************************************/
356 static char *getmainclassnamefromjar(char *mainstring)
359 java_objectheader *o;
363 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
366 throw_main_exception_exit();
368 /* create JarFile object */
373 throw_main_exception_exit();
376 m = class_resolveclassmethod(c,
378 utf_java_lang_String__void,
379 class_java_lang_Object,
383 throw_main_exception_exit();
385 s = javastring_new_char(mainstring);
387 asm_calljavafunction(m, o, s, NULL, NULL);
390 throw_main_exception_exit();
392 /* get manifest object */
394 m = class_resolveclassmethod(c,
395 utf_new_char("getManifest"),
396 utf_new_char("()Ljava/util/jar/Manifest;"),
397 class_java_lang_Object,
401 throw_main_exception_exit();
403 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
406 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
411 /* get Main Attributes */
413 m = class_resolveclassmethod(o->vftbl->class,
414 utf_new_char("getMainAttributes"),
415 utf_new_char("()Ljava/util/jar/Attributes;"),
416 class_java_lang_Object,
420 throw_main_exception_exit();
422 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
425 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
430 /* get property Main-Class */
432 m = class_resolveclassmethod(o->vftbl->class,
433 utf_new_char("getValue"),
434 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
435 class_java_lang_Object,
439 throw_main_exception_exit();
441 s = javastring_new_char("Main-Class");
443 o = asm_calljavafunction(m, o, s, NULL, NULL);
446 throw_main_exception_exit();
448 return javastring_tochar(o);
453 * void exit_handler(void)
454 * -----------------------
455 * The exit_handler function is called upon program termination to shutdown
456 * the various subsystems and release the resources allocated to the VM.
458 void exit_handler(void)
460 /********************* Print debug tables ************************/
462 if (showmethods) class_showmethods(mainclass);
463 if (showconstantpool) class_showconstantpool(mainclass);
464 if (showutf) utf_show();
466 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
467 clear_thread_flags(); /* restores standard file descriptor
471 /************************ Free all resources *******************/
476 MFREE(classpath, u1, strlen(classpath));
478 if (opt_verbose || getcompilingtime || opt_stat) {
479 log_text("CACAO terminated");
481 #if defined(STATISTICS)
484 #ifdef TYPECHECK_STATISTICS
485 typecheck_print_statistics(get_logfile());
489 if (getcompilingtime)
497 /* main ************************************************************************
501 *******************************************************************************/
503 int main(int argc, char **argv)
508 /* local variables ********************************************************/
510 char logfilename[200] = "";
516 char *specificmethodname = NULL;
517 char *specificsignature = NULL;
520 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
521 stackbottom = &dummy;
524 if (atexit(exit_handler))
525 throw_cacao_exception_exit(string_java_lang_InternalError,
526 "Unable to register exit_handler");
529 /************ Collect info from the environment ************************/
531 /* set the bootclasspath */
533 cp = getenv("BOOTCLASSPATH");
535 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
536 strcpy(bootclasspath, cp);
539 #if !defined(WITH_EXTERNAL_CLASSPATH)
540 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_RT_JAR_PATH) +
543 bootclasspath = MNEW(char, cplen);
544 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
545 strcat(bootclasspath, CACAO_RT_JAR_PATH);
547 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_VM_ZIP_PATH) +
549 strlen(EXTERNAL_CLASSPATH_PREFIX) +
550 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
553 bootclasspath = MNEW(char, cplen);
554 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
555 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
556 strcat(bootclasspath, ":");
557 strcat(bootclasspath, EXTERNAL_CLASSPATH_PREFIX);
558 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
563 /* set the classpath */
565 cp = getenv("CLASSPATH");
567 classpath = MNEW(char, strlen(cp) + strlen("0"));
568 strcat(classpath, cp);
571 classpath = MNEW(char, strlen(".") + strlen("0"));
572 strcpy(classpath, ".");
576 /***************** Interpret the command line *****************/
581 heapmaxsize = HEAP_MAXSIZE;
582 heapstartsize = HEAP_STARTSIZE;
585 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
590 case OPT_BOOTCLASSPATH:
591 /* Forget default bootclasspath and set the argument as new boot */
593 MFREE(bootclasspath, char, strlen(bootclasspath));
595 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
596 strcpy(bootclasspath, opt_arg);
599 case OPT_BOOTCLASSPATH_A:
600 /* append to end of bootclasspath */
601 cplen = strlen(bootclasspath);
603 bootclasspath = MREALLOC(bootclasspath,
606 cplen + strlen(":") +
607 strlen(opt_arg) + strlen("0"));
609 strcat(bootclasspath, ":");
610 strcat(bootclasspath, opt_arg);
613 case OPT_BOOTCLASSPATH_P:
614 /* prepend in front of bootclasspath */
618 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
619 cplen + strlen("0"));
621 strcpy(bootclasspath, opt_arg);
622 strcat(bootclasspath, ":");
623 strcat(bootclasspath, cp);
625 MFREE(cp, char, cplen);
629 /* forget old classpath and set the argument as new classpath */
630 MFREE(classpath, char, strlen(classpath));
632 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
633 strcpy(classpath, opt_arg);
642 for (j = 0; j < strlen(opt_arg); j++) {
643 if (opt_arg[j] == '=') {
645 create_property(opt_arg, opt_arg + j + 1);
650 /* if no '=' is given, just create an empty property */
651 create_property(opt_arg, "");
661 c = opt_arg[strlen(opt_arg) - 1];
663 if (c == 'k' || c == 'K') {
664 j = 1024 * atoi(opt_arg);
666 } else if (c == 'm' || c == 'M') {
667 j = 1024 * 1024 * atoi(opt_arg);
669 } else j = atoi(opt_arg);
671 if (i == OPT_MX) heapmaxsize = j;
672 else heapstartsize = j;
685 compileverbose = true;
688 case OPT_VERBOSESPECIFIC:
689 if (strcmp("class", opt_arg) == 0) {
693 } else if (strcmp("gc", opt_arg) == 0) {
694 opt_verbosegc = true;
696 } else if (strcmp("jni", opt_arg) == 0) {
697 opt_verbosejni = true;
701 case OPT_VERBOSEEXCEPTION:
702 verboseexception = true;
705 #ifdef TYPECHECK_VERBOSE
707 typecheckverbose = true;
711 case OPT_VERBOSECALL:
720 case OPT_SHOWVERSION:
733 opt_liberalutf = true;
741 getcompilingtime = true;
742 getloadingtime = true;
745 #if defined(STATISTICS)
752 strcpy(logfilename, opt_arg);
756 for (j = 0; j < strlen(opt_arg); j++) {
757 switch (opt_arg[j]) {
772 makeinitializations = false;
781 specificmethodname = opt_arg;
782 makeinitializations = false;
786 specificsignature = opt_arg;
792 makeinitializations = false;
795 case OPT_SHOW: /* Display options */
796 for (j = 0; j < strlen(opt_arg); j++) {
797 switch (opt_arg[j]) {
799 opt_showdisassemble = true;
800 compileverbose = true;
803 showconstantpool = true;
806 opt_showddatasegment = true;
809 opt_showexceptionstubs = true;
812 opt_showintermediate = true;
813 compileverbose = true;
819 opt_shownativestub = true;
835 for (j = 0; j < strlen(opt_arg); j++) {
836 switch (opt_arg[j]) {
838 /* define in options.h; Used in main.c, jit.c & inline.c */
847 inlinevirtuals = true;
851 inlineexceptions = true;
854 inlineparamopt = true;
857 inlineoutsiders = true;
865 #ifdef STATIC_ANALYSIS
867 opt_rt = true; /* default for inlining */
871 opt_xta = true; /* in test currently */
875 printf("\nVTA is not yet available\n");
877 /***opt_vta = true; not yet **/
896 printf("Unknown option: %s\n", argv[opt_ind]);
905 /* transform dots into slashes in the class name */
907 mainstring = argv[opt_ind++];
910 /* do not mangle jar filename */
912 for (i = strlen(mainstring) - 1; i >= 0; i--) {
913 if (mainstring[i] == '.') mainstring[i] = '/';
917 /* put jarfile in classpath */
921 classpath = MNEW(char, strlen(mainstring) + strlen(":") +
922 strlen(classpath) + strlen("0"));
924 strcpy(classpath, mainstring);
925 strcat(classpath, ":");
926 strcat(classpath, cp);
928 MFREE(cp, char, strlen(cp));
931 /**************************** Program start *****************************/
933 log_init(logfilename);
936 log_text("CACAO started -------------------------------------------------------");
938 /* initialize JavaVM */
940 vm_args.version = 0x00010001; /* New in 1.1.2: VM version */
942 /* Get the default initialization arguments and set the class path */
944 JNI_GetDefaultJavaVMInitArgs(&vm_args);
946 vm_args.minHeapSize = heapstartsize;
947 vm_args.maxHeapSize = heapmaxsize;
949 vm_args.classpath = classpath;
951 /* load and initialize a Java VM, return a JNI interface pointer in env */
953 JNI_CreateJavaVM(&jvm, &env, &vm_args);
955 #if defined(ENABLE_JVMTI)
956 set_jvmti_phase(JVMTI_PHASE_START);
959 /* initialize the garbage collector */
961 gc_init(heapmaxsize, heapstartsize);
965 /* initialize the loader with bootclasspath */
967 suck_init(bootclasspath);
969 cacao_initializing = true;
971 #if defined(USE_THREADS)
972 #if defined(NATIVE_THREADS)
978 /* install architecture dependent signal handler used for exceptions */
982 /* initialize the codegen sub systems */
986 /* initializes jit compiler */
990 /* machine dependent initialization */
994 /* initialize some cacao subsystems */
998 if (!loader_init((u1 *) &dummy))
999 throw_main_exception_exit();
1002 throw_main_exception_exit();
1005 throw_main_exception_exit();
1007 if (!exceptions_init())
1008 throw_main_exception_exit();
1010 if (!builtin_init())
1011 throw_main_exception_exit();
1013 #if defined(USE_THREADS)
1014 initThreads((u1 *) &dummy);
1017 *threadrootmethod = NULL;
1019 /*That's important, otherwise we get into trouble, if the Runtime static
1020 initializer is called before (circular dependency. This is with
1021 classpath 0.09. Another important thing is, that this has to happen
1022 after initThreads!!! */
1024 if (!initialize_class(class_java_lang_System))
1025 throw_main_exception_exit();
1027 cacao_initializing = false;
1030 /* start worker routines **************************************************/
1033 classinfo *mainclass; /* java/lang/Class */
1035 java_objectarray *a;
1038 /* set return value to OK */
1043 /* open jar file with java.util.jar.JarFile */
1044 mainstring = getmainclassnamefromjar(mainstring);
1047 /* load the main class */
1049 if (!(mainclass = load_class_from_sysloader(utf_new_char(mainstring))))
1050 throw_main_exception_exit();
1052 /* error loading class, clear exceptionptr for new exception */
1054 if (*exceptionptr || !mainclass) {
1055 /* *exceptionptr = NULL; */
1057 /* *exceptionptr = */
1058 /* new_exception_message(string_java_lang_NoClassDefFoundError, */
1060 throw_main_exception_exit();
1063 /* find the `main' method of the main class */
1065 m = class_resolveclassmethod(mainclass,
1066 utf_new_char("main"),
1067 utf_new_char("([Ljava/lang/String;)V"),
1068 class_java_lang_Object,
1071 if (*exceptionptr) {
1072 throw_main_exception_exit();
1075 /* there is no main method or it isn't static */
1077 if (!m || !(m->flags & ACC_STATIC)) {
1078 *exceptionptr = NULL;
1081 new_exception_message(string_java_lang_NoSuchMethodError,
1083 throw_main_exception_exit();
1086 /* build argument array */
1088 a = builtin_anewarray(argc - opt_ind, class_java_lang_String);
1089 for (i = opt_ind; i < argc; i++) {
1090 a->data[i - opt_ind] =
1091 (java_objectheader *) javastring_new(utf_new_char(argv[i]));
1094 #ifdef TYPEINFO_DEBUG_TEST
1095 /* test the typeinfo system */
1098 /*class_showmethods(currentThread->group->header.vftbl->class); */
1100 *threadrootmethod = m;
1104 asm_calljavafunction(m, a, NULL, NULL, NULL);
1106 /* exception occurred? */
1107 if (*exceptionptr) {
1108 throw_main_exception();
1112 #if defined(USE_THREADS)
1113 #if defined(NATIVE_THREADS)
1116 killThread(currentThread);
1120 /* now exit the JavaVM */
1122 /* (*jvm)->DestroyJavaVM(jvm); */
1127 /************* If requested, compile all methods ********************/
1134 classcache_name_entry *nmen;
1135 classcache_class_entry *clsen;
1137 /* create all classes found in the classpath */
1138 /* XXX currently only works with zip/jar's */
1140 loader_load_all_classes();
1142 /* link all classes */
1144 for (slot = 0; slot < classcache_hash.size; slot++) {
1145 nmen = (classcache_name_entry *) classcache_hash.ptr[slot];
1147 for (; nmen; nmen = nmen->hashlink) {
1148 /* iterate over all class entries */
1150 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
1151 c = clsen->classobj;
1158 /*utf_fprint_classname(stderr,c->name);fprintf(stderr,"\n");*/
1162 throw_main_exception_exit();
1164 /* compile all class methods */
1165 for (i = 0; i < c->methodscount; i++) {
1166 m = &(c->methods[i]);
1168 /*fprintf(stderr," compiling:");utf_fprint(stderr,m->name);fprintf(stderr,"\n");*/
1169 (void) jit_compile(m);
1178 /******** If requested, compile a specific method ***************/
1180 if (specificmethodname) {
1183 /* create, load and link the main class */
1185 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
1186 throw_main_exception_exit();
1188 if (!link_class(mainclass))
1189 throw_main_exception_exit();
1191 if (specificsignature) {
1192 m = class_resolveclassmethod(mainclass,
1193 utf_new_char(specificmethodname),
1194 utf_new_char(specificsignature),
1198 m = class_resolveclassmethod(mainclass,
1199 utf_new_char(specificmethodname),
1206 char message[MAXLOGTEXT];
1207 sprintf(message, "%s%s", specificmethodname,
1208 specificsignature ? specificsignature : "");
1211 new_exception_message(string_java_lang_NoSuchMethodException,
1214 throw_main_exception_exit();
1222 /* keep compiler happy */
1228 /* cacao_exit ******************************************************************
1230 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1232 *******************************************************************************/
1234 void cacao_exit(s4 status)
1239 assert(class_java_lang_System);
1240 assert(class_java_lang_System->loaded);
1242 if (!link_class(class_java_lang_System))
1243 throw_main_exception_exit();
1245 /* call java.lang.System.exit(I)V */
1247 m = class_resolveclassmethod(class_java_lang_System,
1248 utf_new_char("exit"),
1250 class_java_lang_Object,
1254 throw_main_exception_exit();
1256 /* call the exit function with passed exit status */
1258 /* both inlinevirtual and outsiders not allowed on exit */
1259 /* not sure if permanant or temp restriction */
1260 if (inlinevirtuals) inlineoutsiders = false;
1262 asm_calljavafunction(m, (void *) (ptrint) status, NULL, NULL, NULL);
1264 /* this should never happen */
1267 throw_exception_exit();
1269 throw_cacao_exception_exit(string_java_lang_InternalError,
1270 "System.exit(I)V returned without exception");
1274 /*************************** Shutdown function *********************************
1276 Terminates the system immediately without freeing memory explicitly (to be
1277 used only for abnormal termination)
1279 *******************************************************************************/
1281 void cacao_shutdown(s4 status)
1283 if (opt_verbose || getcompilingtime || opt_stat) {
1284 log_text("CACAO terminated by shutdown");
1285 dolog("Exit status: %d\n", (s4) status);
1293 * These are local overrides for various environment variables in Emacs.
1294 * Please do not remove this and leave it at the end of the file, where
1295 * Emacs will automagically detect them.
1296 * ---------------------------------------------------------------------
1299 * indent-tabs-mode: t