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 2950 2005-07-09 13:37:29Z 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 { "ss", true, OPT_IGNORE },
169 { "v", false, OPT_VERBOSE1 },
170 { "verbose", false, OPT_VERBOSE },
171 { "verbose:", true, OPT_VERBOSESPECIFIC },
172 { "verbosecall", false, OPT_VERBOSECALL },
173 { "verboseexception", false, OPT_VERBOSEEXCEPTION },
174 #ifdef TYPECHECK_VERBOSE
175 { "verbosetc", false, OPT_VERBOSETC },
177 #if defined(__ALPHA__)
178 { "noieee", false, OPT_NOIEEE },
180 { "softnull", false, OPT_SOFTNULL },
181 { "time", false, OPT_TIME },
182 #if defined(STATISTICS)
183 { "stat", false, OPT_STAT },
185 { "log", true, OPT_LOG },
186 { "c", true, OPT_CHECK },
187 { "l", false, OPT_LOAD },
188 { "eager", false, OPT_EAGER },
189 { "m", true, OPT_METHOD },
190 { "sig", true, OPT_SIGNATURE },
191 { "s", true, OPT_SHOW },
192 { "all", false, OPT_ALL },
193 { "oloop", false, OPT_OLOOP },
194 { "i", true, OPT_INLINING },
195 #ifdef STATIC_ANALYSIS
196 { "rt", false, OPT_RT },
197 { "xta", false, OPT_XTA },
198 { "vta", false, OPT_VTA },
201 { "lsra", false, OPT_LSRA },
203 { "jar", false, OPT_JAR },
204 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
205 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
206 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
207 { "version", false, OPT_VERSION },
208 { "showversion", false, OPT_SHOWVERSION },
209 { "help", false, OPT_HELP },
210 { "?", false, OPT_HELP },
211 { "X", false, OPT_X },
216 /* usage ***********************************************************************
218 Prints the correct usage syntax to stdout.
220 *******************************************************************************/
222 static void usage(void)
224 printf("Usage: cacao [-options] classname [arguments]\n");
225 printf(" (to run a class file)\n");
226 printf(" cacao [-options] -jar jarfile [arguments]\n");
227 printf(" (to run a standalone jar file)\n\n");
229 printf("Java options:\n");
230 printf(" -cp <path> specify a path to look for classes\n");
231 printf(" -classpath <path> specify a path to look for classes\n");
232 printf(" -D<name>=<value> add an entry to the property list\n");
233 printf(" -verbose[:class|gc|jni] enable specific verbose output\n");
234 printf(" -version print product version and exit\n");
235 printf(" -showversion print product version and continue\n");
236 printf(" -help, -? print this help message\n");
237 printf(" -X print help on non-standard Java options\n\n");
239 printf("CACAO options:\n");
240 printf(" -v write state-information\n");
241 printf(" -verbose write more information\n");
242 printf(" -verbosegc write message for each GC\n");
243 printf(" -verbosecall write message for each call\n");
244 printf(" -verboseexception write message for each step of stack unwinding\n");
245 #ifdef TYPECHECK_VERBOSE
246 printf(" -verbosetc write debug messages while typechecking\n");
248 #if defined(__ALPHA__)
249 printf(" -noieee don't use ieee compliant arithmetic\n");
251 printf(" -noverify don't verify classfiles\n");
252 printf(" -liberalutf don't warn about overlong UTF-8 sequences\n");
253 printf(" -softnull use software nullpointer check\n");
254 printf(" -time measure the runtime\n");
255 #if defined(STATISTICS)
256 printf(" -stat detailed compiler statistics\n");
258 printf(" -log logfile specify a name for the logfile\n");
259 printf(" -c(heck)b(ounds) don't check array bounds\n");
260 printf(" s(ync) don't check for synchronization\n");
261 printf(" -oloop optimize array accesses in loops\n");
262 printf(" -l don't start the class after loading\n");
263 printf(" -eager perform eager class loading and linking\n");
264 printf(" -all compile all methods, no execution\n");
265 printf(" -m compile only a specific method\n");
266 printf(" -sig specify signature for a specific method\n");
267 printf(" -s(how)a(ssembler) show disassembled listing\n");
268 printf(" c(onstants) show the constant pool\n");
269 printf(" d(atasegment) show data segment listing\n");
270 printf(" e(xceptionstubs) show disassembled exception stubs (only with -sa)\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 opt_showdisassemble = true;
795 compileverbose = true;
798 showconstantpool = true;
801 opt_showddatasegment = true;
804 opt_showexceptionstubs = true;
807 opt_showintermediate = true;
808 compileverbose = true;
814 opt_shownativestub = true;
830 for (j = 0; j < strlen(opt_arg); j++) {
831 switch (opt_arg[j]) {
833 /* define in options.h; Used in main.c, jit.c & inline.c */
842 inlinevirtuals = true;
846 inlineexceptions = true;
849 inlineparamopt = true;
852 inlineoutsiders = true;
860 #ifdef STATIC_ANALYSIS
862 opt_rt = true; /* default for inlining */
866 opt_xta = true; /* in test currently */
870 printf("\nVTA is not yet available\n");
872 /***opt_vta = true; not yet **/
891 printf("Unknown option: %s\n", argv[opt_ind]);
900 /* transform dots into slashes in the class name */
902 mainstring = argv[opt_ind++];
905 /* do not mangle jar filename */
907 for (i = strlen(mainstring) - 1; i >= 0; i--) {
908 if (mainstring[i] == '.') mainstring[i] = '/';
912 /* put jarfile in classpath */
916 classpath = MNEW(char, strlen(mainstring) + strlen(":") +
917 strlen(classpath) + strlen("0"));
919 strcpy(classpath, mainstring);
920 strcat(classpath, ":");
921 strcat(classpath, cp);
923 MFREE(cp, char, strlen(cp));
926 /**************************** Program start *****************************/
928 log_init(logfilename);
931 log_text("CACAO started -------------------------------------------------------");
933 /* initialize JavaVM */
935 vm_args.version = 0x00010001; /* New in 1.1.2: VM version */
937 /* Get the default initialization arguments and set the class path */
939 JNI_GetDefaultJavaVMInitArgs(&vm_args);
941 vm_args.minHeapSize = heapstartsize;
942 vm_args.maxHeapSize = heapmaxsize;
944 vm_args.classpath = classpath;
946 /* load and initialize a Java VM, return a JNI interface pointer in env */
948 JNI_CreateJavaVM(&jvm, &env, &vm_args);
951 /* initialize the garbage collector */
953 gc_init(heapmaxsize, heapstartsize);
957 /* initialize the loader with bootclasspath */
959 suck_init(bootclasspath);
961 cacao_initializing = true;
963 #if defined(USE_THREADS)
964 #if defined(NATIVE_THREADS)
970 /* install architecture dependent signal handler used for exceptions */
974 /* initialize the codegen sub systems */
978 /* initializes jit compiler */
982 /* machine dependent initialization */
986 /* initialize some cacao subsystems */
990 if (!loader_init((u1 *) &dummy))
991 throw_main_exception_exit();
994 throw_main_exception_exit();
997 throw_main_exception_exit();
999 if (!exceptions_init())
1000 throw_main_exception_exit();
1002 if (!builtin_init())
1003 throw_main_exception_exit();
1005 #if defined(USE_THREADS)
1006 initThreads((u1 *) &dummy);
1009 *threadrootmethod = NULL;
1011 /*That's important, otherwise we get into trouble, if the Runtime static
1012 initializer is called before (circular dependency. This is with
1013 classpath 0.09. Another important thing is, that this has to happen
1014 after initThreads!!! */
1016 if (!initialize_class(class_java_lang_System))
1017 throw_main_exception_exit();
1019 cacao_initializing = false;
1022 /* start worker routines **************************************************/
1025 classinfo *mainclass; /* java/lang/Class */
1027 java_objectarray *a;
1030 /* set return value to OK */
1035 /* open jar file with java.util.jar.JarFile */
1036 mainstring = getmainclassnamefromjar(mainstring);
1039 /* load the main class */
1041 if (!(mainclass = load_class_from_sysloader(utf_new_char(mainstring))))
1042 throw_main_exception_exit();
1044 /* error loading class, clear exceptionptr for new exception */
1046 if (*exceptionptr || !mainclass) {
1047 /* *exceptionptr = NULL; */
1049 /* *exceptionptr = */
1050 /* new_exception_message(string_java_lang_NoClassDefFoundError, */
1052 throw_main_exception_exit();
1055 /* find the `main' method of the main class */
1057 m = class_resolveclassmethod(mainclass,
1058 utf_new_char("main"),
1059 utf_new_char("([Ljava/lang/String;)V"),
1060 class_java_lang_Object,
1063 if (*exceptionptr) {
1064 throw_main_exception_exit();
1067 /* there is no main method or it isn't static */
1069 if (!m || !(m->flags & ACC_STATIC)) {
1070 *exceptionptr = NULL;
1073 new_exception_message(string_java_lang_NoSuchMethodError,
1075 throw_main_exception_exit();
1078 /* build argument array */
1080 a = builtin_anewarray(argc - opt_ind, class_java_lang_String);
1081 for (i = opt_ind; i < argc; i++) {
1082 a->data[i - opt_ind] =
1083 (java_objectheader *) javastring_new(utf_new_char(argv[i]));
1086 #ifdef TYPEINFO_DEBUG_TEST
1087 /* test the typeinfo system */
1090 /*class_showmethods(currentThread->group->header.vftbl->class); */
1092 *threadrootmethod = m;
1096 asm_calljavafunction(m, a, NULL, NULL, NULL);
1098 /* exception occurred? */
1099 if (*exceptionptr) {
1100 throw_main_exception();
1104 #if defined(USE_THREADS)
1105 #if defined(NATIVE_THREADS)
1108 killThread(currentThread);
1112 /* now exit the JavaVM */
1114 /* (*jvm)->DestroyJavaVM(jvm); */
1119 /************* If requested, compile all methods ********************/
1126 classcache_name_entry *nmen;
1127 classcache_class_entry *clsen;
1129 /* create all classes found in the classpath */
1130 /* XXX currently only works with zip/jar's */
1132 loader_load_all_classes();
1134 /* link all classes */
1136 for (slot = 0; slot < classcache_hash.size; slot++) {
1137 nmen = (classcache_name_entry *) classcache_hash.ptr[slot];
1139 for (; nmen; nmen = nmen->hashlink) {
1140 /* iterate over all class entries */
1142 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
1143 c = clsen->classobj;
1150 /*utf_fprint_classname(stderr,c->name);fprintf(stderr,"\n");*/
1154 throw_main_exception_exit();
1156 /* compile all class methods */
1157 for (i = 0; i < c->methodscount; i++) {
1158 m = &(c->methods[i]);
1160 /*fprintf(stderr," compiling:");utf_fprint(stderr,m->name);fprintf(stderr,"\n");*/
1161 (void) jit_compile(m);
1170 /******** If requested, compile a specific method ***************/
1172 if (specificmethodname) {
1175 /* create, load and link the main class */
1177 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
1178 throw_main_exception_exit();
1180 if (!link_class(mainclass))
1181 throw_main_exception_exit();
1183 if (specificsignature) {
1184 m = class_resolveclassmethod(mainclass,
1185 utf_new_char(specificmethodname),
1186 utf_new_char(specificsignature),
1190 m = class_resolveclassmethod(mainclass,
1191 utf_new_char(specificmethodname),
1198 char message[MAXLOGTEXT];
1199 sprintf(message, "%s%s", specificmethodname,
1200 specificsignature ? specificsignature : "");
1203 new_exception_message(string_java_lang_NoSuchMethodException,
1206 throw_main_exception_exit();
1214 /* keep compiler happy */
1220 /* cacao_exit ******************************************************************
1222 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1224 *******************************************************************************/
1226 void cacao_exit(s4 status)
1231 assert(class_java_lang_System);
1232 assert(class_java_lang_System->loaded);
1234 if (!link_class(class_java_lang_System))
1235 throw_main_exception_exit();
1237 /* call java.lang.System.exit(I)V */
1239 m = class_resolveclassmethod(class_java_lang_System,
1240 utf_new_char("exit"),
1242 class_java_lang_Object,
1246 throw_main_exception_exit();
1248 /* call the exit function with passed exit status */
1250 /* both inlinevirtual and outsiders not allowed on exit */
1251 /* not sure if permanant or temp restriction */
1252 if (inlinevirtuals) inlineoutsiders = false;
1254 asm_calljavafunction(m, (void *) (ptrint) status, NULL, NULL, NULL);
1256 /* this should never happen */
1259 throw_exception_exit();
1261 throw_cacao_exception_exit(string_java_lang_InternalError,
1262 "System.exit(I)V returned without exception");
1266 /*************************** Shutdown function *********************************
1268 Terminates the system immediately without freeing memory explicitly (to be
1269 used only for abnormal termination)
1271 *******************************************************************************/
1273 void cacao_shutdown(s4 status)
1275 if (opt_verbose || getcompilingtime || opt_stat) {
1276 log_text("CACAO terminated by shutdown");
1277 dolog("Exit status: %d\n", (s4) status);
1285 * These are local overrides for various environment variables in Emacs.
1286 * Please do not remove this and leave it at the end of the file, where
1287 * Emacs will automagically detect them.
1288 * ---------------------------------------------------------------------
1291 * indent-tabs-mode: t