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 2897 2005-07-04 20:39:26Z twisti $
50 #include "cacao/cacao.h"
52 #include "mm/memory.h"
53 #include "native/jni.h"
54 #include "native/native.h"
55 #include "toolbox/logging.h"
56 #include "vm/exceptions.h"
57 #include "vm/global.h"
58 #include "vm/initialize.h"
59 #include "vm/loader.h"
60 #include "vm/options.h"
61 #include "vm/signallocal.h"
62 #include "vm/statistics.h"
63 #include "vm/stringlocal.h"
64 #include "vm/tables.h"
65 #include "vm/classcache.h"
66 #include "vm/jit/asmpart.h"
67 #include "vm/jit/jit.h"
69 #ifdef TYPEINFO_DEBUG_TEST
70 #include "vm/jit/verify/typeinfo.h"
74 /* define heap sizes **********************************************************/
76 #define HEAP_MAXSIZE 64 * 1024 * 1024; /* default 64MB */
77 #define HEAP_STARTSIZE 2 * 1024 * 1024; /* default 2MB */
80 /* Invocation API variables ***************************************************/
82 JavaVM *jvm; /* denotes a Java VM */
83 JNIEnv *env; /* pointer to native method interface */
85 JDK1_1InitArgs vm_args; /* JDK 1.1 VM initialization arguments */
88 bool cacao_initializing;
90 char *bootclasspath; /* contains the boot classpath */
91 char *classpath; /* contains the classpath */
94 static classinfo *mainclass;
96 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
97 void **stackbottom = 0;
101 /* define command line options ************************************************/
103 #define OPT_CLASSPATH 2
107 #define OPT_VERBOSE1 6
108 #define OPT_VERBOSE 7
109 #define OPT_VERBOSESPECIFIC 8
110 #define OPT_VERBOSECALL 9
111 #define OPT_NOIEEE 10
112 #define OPT_SOFTNULL 11
115 #if defined(STATISTICS)
117 #endif /* defined(STATISTICS) */
122 #define OPT_METHOD 17
123 #define OPT_SIGNATURE 18
127 #define OPT_INLINING 25
129 #define STATIC_ANALYSIS
130 #if defined(STATIC_ANALYSIS)
134 #endif /* defined(STATIC_ANALYSIS) */
136 #define OPT_VERBOSETC 29
137 #define OPT_NOVERIFY 30
138 #define OPT_LIBERALUTF 31
139 #define OPT_VERBOSEEXCEPTION 32
144 #endif /* defined(LSRA) */
147 #define OPT_BOOTCLASSPATH 36
148 #define OPT_BOOTCLASSPATH_A 37
149 #define OPT_BOOTCLASSPATH_P 38
150 #define OPT_VERSION 39
151 #define OPT_SHOWVERSION 40
157 opt_struct opts[] = {
158 { "classpath", true, OPT_CLASSPATH },
159 { "cp", true, OPT_CLASSPATH },
160 { "D", true, OPT_D },
161 { "Xms", true, OPT_MS },
162 { "Xmx", true, OPT_MX },
163 { "ms", true, OPT_MS },
164 { "mx", true, OPT_MX },
165 { "noasyncgc", false, OPT_IGNORE },
166 { "noverify", false, OPT_NOVERIFY },
167 { "liberalutf", false, OPT_LIBERALUTF },
168 { "oss", true, OPT_IGNORE },
169 { "ss", true, OPT_IGNORE },
170 { "v", false, OPT_VERBOSE1 },
171 { "verbose", false, OPT_VERBOSE },
172 { "verbose:", true, OPT_VERBOSESPECIFIC },
173 { "verbosecall", false, OPT_VERBOSECALL },
174 { "verboseexception", false, OPT_VERBOSEEXCEPTION },
175 #ifdef TYPECHECK_VERBOSE
176 { "verbosetc", false, OPT_VERBOSETC },
178 #if defined(__ALPHA__)
179 { "noieee", false, OPT_NOIEEE },
181 { "softnull", false, OPT_SOFTNULL },
182 { "time", false, OPT_TIME },
183 #if defined(STATISTICS)
184 { "stat", false, OPT_STAT },
186 { "log", true, OPT_LOG },
187 { "c", true, OPT_CHECK },
188 { "l", false, OPT_LOAD },
189 { "eager", false, OPT_EAGER },
190 { "m", true, OPT_METHOD },
191 { "sig", true, OPT_SIGNATURE },
192 { "s", true, OPT_SHOW },
193 { "all", false, OPT_ALL },
194 { "oloop", false, OPT_OLOOP },
195 { "i", true, OPT_INLINING },
196 #ifdef STATIC_ANALYSIS
197 { "rt", false, OPT_RT },
198 { "xta", false, OPT_XTA },
199 { "vta", false, OPT_VTA },
202 { "lsra", false, OPT_LSRA },
204 { "jar", false, OPT_JAR },
205 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
206 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
207 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
208 { "version", false, OPT_VERSION },
209 { "showversion", false, OPT_SHOWVERSION },
210 { "help", false, OPT_HELP },
211 { "?", false, OPT_HELP },
212 { "X", false, OPT_X },
217 /* usage ***********************************************************************
219 Prints the correct usage syntax to stdout.
221 *******************************************************************************/
223 static void usage(void)
225 printf("Usage: cacao [-options] classname [arguments]\n");
226 printf(" (to run a class file)\n");
227 printf(" cacao [-options] -jar jarfile [arguments]\n");
228 printf(" (to run a standalone jar file)\n\n");
230 printf("Java options:\n");
231 printf(" -cp <path> specify a path to look for classes\n");
232 printf(" -classpath <path> specify a path to look for classes\n");
233 printf(" -D<name>=<value> add an entry to the property list\n");
234 printf(" -verbose[:class|gc|jni] enable specific verbose output\n");
235 printf(" -version print product version and exit\n");
236 printf(" -showversion print product version and continue\n");
237 printf(" -help, -? print this help message\n");
238 printf(" -X print help on non-standard Java options\n\n");
240 printf("CACAO options:\n");
241 printf(" -v write state-information\n");
242 printf(" -verbose write more information\n");
243 printf(" -verbosegc write message for each GC\n");
244 printf(" -verbosecall write message for each call\n");
245 printf(" -verboseexception write message for each step of stack unwinding\n");
246 #ifdef TYPECHECK_VERBOSE
247 printf(" -verbosetc write debug messages while typechecking\n");
249 #if defined(__ALPHA__)
250 printf(" -noieee don't use ieee compliant arithmetic\n");
252 printf(" -noverify don't verify classfiles\n");
253 printf(" -liberalutf don't warn about overlong UTF-8 sequences\n");
254 printf(" -softnull use software nullpointer check\n");
255 printf(" -time measure the runtime\n");
256 #if defined(STATISTICS)
257 printf(" -stat detailed compiler statistics\n");
259 printf(" -log logfile specify a name for the logfile\n");
260 printf(" -c(heck)b(ounds) don't check array bounds\n");
261 printf(" s(ync) don't check for synchronization\n");
262 printf(" -oloop optimize array accesses in loops\n");
263 printf(" -l don't start the class after loading\n");
264 printf(" -eager perform eager class loading and linking\n");
265 printf(" -all compile all methods, no execution\n");
266 printf(" -m compile only a specific method\n");
267 printf(" -sig specify signature for a specific method\n");
268 printf(" -s(how)a(ssembler) show disassembled listing\n");
269 printf(" c(onstants) show the constant pool\n");
270 printf(" d(atasegment) show data segment listing\n");
271 printf(" i(ntermediate) show intermediate representation\n");
272 printf(" m(ethods) show class fields and methods\n");
273 printf(" n(ative) show disassembled native stubs\n");
274 printf(" u(tf) show the utf - hash\n");
275 printf(" -i n(line) activate inlining\n");
276 printf(" v(irtual) inline virtual methods (uses/turns rt option on)\n");
277 printf(" e(exception) inline methods with exceptions\n");
278 printf(" p(aramopt) optimize argument renaming\n");
279 printf(" o(utsiders) inline methods of foreign classes\n");
280 #ifdef STATIC_ANALYSIS
281 printf(" -rt use rapid type analysis\n");
282 printf(" -xta use x type analysis\n");
283 printf(" -vta use variable type analysis\n");
286 printf(" -lsra use linear scan register allocation\n");
289 /* exit with error code */
295 static void Xusage(void)
297 printf(" -Xbootclasspath:<zip/jar files and directories separated by :>\n");
298 printf(" value is set as bootstrap class path\n");
299 printf(" -Xbootclasspath/a:<zip/jar files and directories separated by :>\n");
300 printf(" value is appended to the bootstrap class path\n");
301 printf(" -Xbootclasspath/p:<zip/jar files and directories separated by :>\n");
302 printf(" value is prepended to the bootstrap class path\n");
303 printf(" -Xms<size> set the initial size of the heap (default: 2M)\n");
304 printf(" -Xmx<size> set the maximum size of the heap (default: 64M)\n");
306 /* exit with error code */
312 /* version *********************************************************************
314 Only prints cacao version information.
316 *******************************************************************************/
318 static void version(void)
320 printf("CACAO version "VERSION"\n");
322 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
323 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
324 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
325 printf("Institut f. Computersprachen - TU Wien\n\n");
327 printf("This program is free software; you can redistribute it and/or\n");
328 printf("modify it under the terms of the GNU General Public License as\n");
329 printf("published by the Free Software Foundation; either version 2, or (at\n");
330 printf("your option) any later version.\n\n");
332 printf("This program is distributed in the hope that it will be useful, but\n");
333 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
334 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
335 printf("General Public License for more details.\n");
339 #ifdef TYPECHECK_STATISTICS
340 void typecheck_print_statistics(FILE *file);
345 /* getmainclassfromjar *********************************************************
347 Gets the name of the main class form a JAR's manifest file.
349 *******************************************************************************/
351 static char *getmainclassnamefromjar(char *mainstring)
354 java_objectheader *o;
358 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
361 throw_main_exception_exit();
363 /* create JarFile object */
368 throw_main_exception_exit();
371 m = class_resolveclassmethod(c,
373 utf_java_lang_String__void,
374 class_java_lang_Object,
378 throw_main_exception_exit();
380 s = javastring_new_char(mainstring);
382 asm_calljavafunction(m, o, s, NULL, NULL);
385 throw_main_exception_exit();
387 /* get manifest object */
389 m = class_resolveclassmethod(c,
390 utf_new_char("getManifest"),
391 utf_new_char("()Ljava/util/jar/Manifest;"),
392 class_java_lang_Object,
396 throw_main_exception_exit();
398 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
401 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
406 /* get Main Attributes */
408 m = class_resolveclassmethod(o->vftbl->class,
409 utf_new_char("getMainAttributes"),
410 utf_new_char("()Ljava/util/jar/Attributes;"),
411 class_java_lang_Object,
415 throw_main_exception_exit();
417 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
420 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
425 /* get property Main-Class */
427 m = class_resolveclassmethod(o->vftbl->class,
428 utf_new_char("getValue"),
429 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
430 class_java_lang_Object,
434 throw_main_exception_exit();
436 s = javastring_new_char("Main-Class");
438 o = asm_calljavafunction(m, o, s, NULL, NULL);
441 throw_main_exception_exit();
443 return javastring_tochar(o);
448 * void exit_handler(void)
449 * -----------------------
450 * The exit_handler function is called upon program termination to shutdown
451 * the various subsystems and release the resources allocated to the VM.
453 void exit_handler(void)
455 /********************* Print debug tables ************************/
457 if (showmethods) class_showmethods(mainclass);
458 if (showconstantpool) class_showconstantpool(mainclass);
459 if (showutf) utf_show();
461 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
462 clear_thread_flags(); /* restores standard file descriptor
466 /************************ Free all resources *******************/
471 MFREE(classpath, u1, strlen(classpath));
473 if (opt_verbose || getcompilingtime || opt_stat) {
474 log_text("CACAO terminated");
476 #if defined(STATISTICS)
479 #ifdef TYPECHECK_STATISTICS
480 typecheck_print_statistics(get_logfile());
484 if (getcompilingtime)
492 /* main ************************************************************************
496 *******************************************************************************/
498 int main(int argc, char **argv)
503 /* local variables ********************************************************/
505 char logfilename[200] = "";
511 char *specificmethodname = NULL;
512 char *specificsignature = NULL;
515 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
516 stackbottom = &dummy;
519 if (atexit(exit_handler))
520 throw_cacao_exception_exit(string_java_lang_InternalError,
521 "Unable to register exit_handler");
524 /************ Collect info from the environment ************************/
526 /* set the bootclasspath */
528 cp = getenv("BOOTCLASSPATH");
530 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
531 strcpy(bootclasspath, cp);
534 #if !defined(WITH_EXTERNAL_CLASSPATH)
535 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_RT_JAR_PATH) +
538 bootclasspath = MNEW(char, cplen);
539 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
540 strcat(bootclasspath, CACAO_RT_JAR_PATH);
542 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_VM_ZIP_PATH) +
544 strlen(EXTERNAL_CLASSPATH_PREFIX) +
545 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
548 bootclasspath = MNEW(char, cplen);
549 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
550 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
551 strcat(bootclasspath, ":");
552 strcat(bootclasspath, EXTERNAL_CLASSPATH_PREFIX);
553 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
558 /* set the classpath */
560 cp = getenv("CLASSPATH");
562 classpath = MNEW(char, strlen(cp) + strlen("0"));
563 strcat(classpath, cp);
566 classpath = MNEW(char, strlen(".") + strlen("0"));
567 strcpy(classpath, ".");
571 /***************** Interpret the command line *****************/
576 heapmaxsize = HEAP_MAXSIZE;
577 heapstartsize = HEAP_STARTSIZE;
580 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
585 case OPT_BOOTCLASSPATH:
586 /* Forget default bootclasspath and set the argument as new boot */
588 MFREE(bootclasspath, char, strlen(bootclasspath));
590 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
591 strcpy(bootclasspath, opt_arg);
594 case OPT_BOOTCLASSPATH_A:
595 /* append to end of bootclasspath */
596 cplen = strlen(bootclasspath);
598 bootclasspath = MREALLOC(bootclasspath,
601 cplen + strlen(":") +
602 strlen(opt_arg) + strlen("0"));
604 strcat(bootclasspath, ":");
605 strcat(bootclasspath, opt_arg);
608 case OPT_BOOTCLASSPATH_P:
609 /* prepend in front of bootclasspath */
613 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
614 cplen + strlen("0"));
616 strcpy(bootclasspath, opt_arg);
617 strcat(bootclasspath, ":");
618 strcat(bootclasspath, cp);
620 MFREE(cp, char, cplen);
624 /* forget old classpath and set the argument as new classpath */
625 MFREE(classpath, char, strlen(classpath));
627 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
628 strcpy(classpath, opt_arg);
637 for (j = 0; j < strlen(opt_arg); j++) {
638 if (opt_arg[j] == '=') {
640 create_property(opt_arg, opt_arg + j + 1);
645 /* if no '=' is given, just create an empty property */
646 create_property(opt_arg, "");
656 c = opt_arg[strlen(opt_arg) - 1];
658 if (c == 'k' || c == 'K') {
659 j = 1024 * atoi(opt_arg);
661 } else if (c == 'm' || c == 'M') {
662 j = 1024 * 1024 * atoi(opt_arg);
664 } else j = atoi(opt_arg);
666 if (i == OPT_MX) heapmaxsize = j;
667 else heapstartsize = j;
680 compileverbose = true;
683 case OPT_VERBOSESPECIFIC:
684 if (strcmp("class", opt_arg) == 0) {
688 } else if (strcmp("gc", opt_arg) == 0) {
689 opt_verbosegc = true;
691 } else if (strcmp("jni", opt_arg) == 0) {
692 opt_verbosejni = true;
696 case OPT_VERBOSEEXCEPTION:
697 verboseexception = true;
700 #ifdef TYPECHECK_VERBOSE
702 typecheckverbose = true;
706 case OPT_VERBOSECALL:
715 case OPT_SHOWVERSION:
728 opt_liberalutf = true;
736 getcompilingtime = true;
737 getloadingtime = true;
740 #if defined(STATISTICS)
747 strcpy(logfilename, opt_arg);
751 for (j = 0; j < strlen(opt_arg); j++) {
752 switch (opt_arg[j]) {
767 makeinitializations = false;
776 specificmethodname = opt_arg;
777 makeinitializations = false;
781 specificsignature = opt_arg;
787 makeinitializations = false;
790 case OPT_SHOW: /* Display options */
791 for (j = 0; j < strlen(opt_arg); j++) {
792 switch (opt_arg[j]) {
794 showdisassemble = true;
795 compileverbose = true;
798 showconstantpool = true;
801 showddatasegment = true;
804 showintermediate = true;
805 compileverbose = true;
811 opt_shownativestub = true;
827 for (j = 0; j < strlen(opt_arg); j++) {
828 switch (opt_arg[j]) {
830 /* define in options.h; Used in main.c, jit.c & inline.c */
839 inlinevirtuals = true;
843 inlineexceptions = true;
846 inlineparamopt = true;
849 inlineoutsiders = true;
857 #ifdef STATIC_ANALYSIS
859 opt_rt = true; /* default for inlining */
863 opt_xta = true; /* in test currently */
867 printf("\nVTA is not yet available\n");
869 /***opt_vta = true; not yet **/
888 printf("Unknown option: %s\n", argv[opt_ind]);
897 /* transform dots into slashes in the class name */
899 mainstring = argv[opt_ind++];
902 /* do not mangle jar filename */
904 for (i = strlen(mainstring) - 1; i >= 0; i--) {
905 if (mainstring[i] == '.') mainstring[i] = '/';
909 /* put jarfile in classpath */
913 classpath = MNEW(char, strlen(mainstring) + strlen(":") +
914 strlen(classpath) + strlen("0"));
916 strcpy(classpath, mainstring);
917 strcat(classpath, ":");
918 strcat(classpath, cp);
920 MFREE(cp, char, strlen(cp));
923 /**************************** Program start *****************************/
925 log_init(logfilename);
928 log_text("CACAO started -------------------------------------------------------");
930 /* initialize JavaVM */
932 vm_args.version = 0x00010001; /* New in 1.1.2: VM version */
934 /* Get the default initialization arguments and set the class path */
936 JNI_GetDefaultJavaVMInitArgs(&vm_args);
938 vm_args.minHeapSize = heapstartsize;
939 vm_args.maxHeapSize = heapmaxsize;
941 vm_args.classpath = classpath;
943 /* load and initialize a Java VM, return a JNI interface pointer in env */
945 JNI_CreateJavaVM(&jvm, &env, &vm_args);
948 /* initialize the garbage collector */
950 gc_init(heapmaxsize, heapstartsize);
954 /* initialize the loader with bootclasspath */
956 suck_init(bootclasspath);
958 cacao_initializing = true;
960 #if defined(USE_THREADS)
961 #if defined(NATIVE_THREADS)
967 /* install architecture dependent signal handler used for exceptions */
971 /* initialize the codegen sub systems */
975 /* initializes jit compiler */
979 /* machine dependent initialization */
983 /* initialize some cacao subsystems */
987 if (!loader_init((u1 *) &dummy))
988 throw_main_exception_exit();
991 throw_main_exception_exit();
994 throw_main_exception_exit();
996 if (!exceptions_init())
997 throw_main_exception_exit();
1000 throw_main_exception_exit();
1002 #if defined(USE_THREADS)
1003 initThreads((u1 *) &dummy);
1006 *threadrootmethod = NULL;
1008 /*That's important, otherwise we get into trouble, if the Runtime static
1009 initializer is called before (circular dependency. This is with
1010 classpath 0.09. Another important thing is, that this has to happen
1011 after initThreads!!! */
1013 if (!initialize_class(class_java_lang_System))
1014 throw_main_exception_exit();
1016 cacao_initializing = false;
1019 /* start worker routines **************************************************/
1022 classinfo *mainclass; /* java/lang/Class */
1024 java_objectarray *a;
1027 /* set return value to OK */
1032 /* open jar file with java.util.jar.JarFile */
1033 mainstring = getmainclassnamefromjar(mainstring);
1036 /* load the main class */
1038 if (!(mainclass = load_class_from_sysloader(utf_new_char(mainstring))))
1039 throw_main_exception_exit();
1041 /* error loading class, clear exceptionptr for new exception */
1043 if (*exceptionptr || !mainclass) {
1044 /* *exceptionptr = NULL; */
1046 /* *exceptionptr = */
1047 /* new_exception_message(string_java_lang_NoClassDefFoundError, */
1049 throw_main_exception_exit();
1052 /* find the `main' method of the main class */
1054 m = class_resolveclassmethod(mainclass,
1055 utf_new_char("main"),
1056 utf_new_char("([Ljava/lang/String;)V"),
1057 class_java_lang_Object,
1060 if (*exceptionptr) {
1061 throw_main_exception_exit();
1064 /* there is no main method or it isn't static */
1066 if (!m || !(m->flags & ACC_STATIC)) {
1067 *exceptionptr = NULL;
1070 new_exception_message(string_java_lang_NoSuchMethodError,
1072 throw_main_exception_exit();
1075 /* build argument array */
1077 a = builtin_anewarray(argc - opt_ind, class_java_lang_String);
1078 for (i = opt_ind; i < argc; i++) {
1079 a->data[i - opt_ind] =
1080 (java_objectheader *) javastring_new(utf_new_char(argv[i]));
1083 #ifdef TYPEINFO_DEBUG_TEST
1084 /* test the typeinfo system */
1087 /*class_showmethods(currentThread->group->header.vftbl->class); */
1089 *threadrootmethod = m;
1093 asm_calljavafunction(m, a, NULL, NULL, NULL);
1095 /* exception occurred? */
1096 if (*exceptionptr) {
1097 throw_main_exception();
1101 #if defined(USE_THREADS)
1102 #if defined(NATIVE_THREADS)
1105 killThread(currentThread);
1109 /* now exit the JavaVM */
1111 /* (*jvm)->DestroyJavaVM(jvm); */
1116 /************* If requested, compile all methods ********************/
1123 classcache_name_entry *nmen;
1124 classcache_class_entry *clsen;
1126 /* create all classes found in the classpath */
1127 /* XXX currently only works with zip/jar's */
1129 loader_load_all_classes();
1131 /* link all classes */
1133 for (slot = 0; slot < classcache_hash.size; slot++) {
1134 nmen = (classcache_name_entry *) classcache_hash.ptr[slot];
1136 for (; nmen; nmen = nmen->hashlink) {
1137 /* iterate over all class entries */
1139 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
1140 c = clsen->classobj;
1147 /*utf_fprint_classname(stderr,c->name);fprintf(stderr,"\n");*/
1151 throw_main_exception_exit();
1153 /* compile all class methods */
1154 for (i = 0; i < c->methodscount; i++) {
1155 m = &(c->methods[i]);
1157 /*fprintf(stderr," compiling:");utf_fprint(stderr,m->name);fprintf(stderr,"\n");*/
1158 (void) jit_compile(m);
1167 /******** If requested, compile a specific method ***************/
1169 if (specificmethodname) {
1172 /* create, load and link the main class */
1174 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
1175 throw_main_exception_exit();
1177 if (!link_class(mainclass))
1178 throw_main_exception_exit();
1180 if (specificsignature) {
1181 m = class_resolveclassmethod(mainclass,
1182 utf_new_char(specificmethodname),
1183 utf_new_char(specificsignature),
1187 m = class_resolveclassmethod(mainclass,
1188 utf_new_char(specificmethodname),
1195 char message[MAXLOGTEXT];
1196 sprintf(message, "%s%s", specificmethodname,
1197 specificsignature ? specificsignature : "");
1200 new_exception_message(string_java_lang_NoSuchMethodException,
1203 throw_main_exception_exit();
1211 /* keep compiler happy */
1217 /* cacao_exit ******************************************************************
1219 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1221 *******************************************************************************/
1223 void cacao_exit(s4 status)
1228 assert(class_java_lang_System);
1229 assert(class_java_lang_System->loaded);
1231 if (!link_class(class_java_lang_System))
1232 throw_main_exception_exit();
1234 /* call java.lang.System.exit(I)V */
1236 m = class_resolveclassmethod(class_java_lang_System,
1237 utf_new_char("exit"),
1239 class_java_lang_Object,
1243 throw_main_exception_exit();
1245 /* call the exit function with passed exit status */
1247 /* both inlinevirtual and outsiders not allowed on exit */
1248 /* not sure if permanant or temp restriction */
1249 if (inlinevirtuals) inlineoutsiders = false;
1251 asm_calljavafunction(m, (void *) (ptrint) status, NULL, NULL, NULL);
1253 /* this should never happen */
1256 throw_exception_exit();
1258 throw_cacao_exception_exit(string_java_lang_InternalError,
1259 "System.exit(I)V returned without exception");
1263 /*************************** Shutdown function *********************************
1265 Terminates the system immediately without freeing memory explicitly (to be
1266 used only for abnormal termination)
1268 *******************************************************************************/
1270 void cacao_shutdown(s4 status)
1272 if (opt_verbose || getcompilingtime || opt_stat) {
1273 log_text("CACAO terminated by shutdown");
1274 dolog("Exit status: %d\n", (s4) status);
1282 * These are local overrides for various environment variables in Emacs.
1283 * Please do not remove this and leave it at the end of the file, where
1284 * Emacs will automagically detect them.
1285 * ---------------------------------------------------------------------
1288 * indent-tabs-mode: t