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 3092 2005-07-21 13:06:50Z 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
157 #define OPT_FULLVERSION 41
163 opt_struct opts[] = {
164 { "classpath", true, OPT_CLASSPATH },
165 { "cp", true, OPT_CLASSPATH },
166 { "D", true, OPT_D },
167 { "Xms", true, OPT_MS },
168 { "Xmx", true, OPT_MX },
169 { "ms", true, OPT_MS },
170 { "mx", true, OPT_MX },
171 { "noasyncgc", false, OPT_IGNORE },
172 { "noverify", false, OPT_NOVERIFY },
173 { "liberalutf", false, OPT_LIBERALUTF },
174 { "ss", true, OPT_IGNORE },
175 { "v", false, OPT_VERBOSE1 },
176 { "verbose", false, OPT_VERBOSE },
177 { "verbose:", true, OPT_VERBOSESPECIFIC },
178 { "verbosecall", false, OPT_VERBOSECALL },
179 { "verboseexception", false, OPT_VERBOSEEXCEPTION },
180 #ifdef TYPECHECK_VERBOSE
181 { "verbosetc", false, OPT_VERBOSETC },
183 #if defined(__ALPHA__)
184 { "noieee", false, OPT_NOIEEE },
186 { "softnull", false, OPT_SOFTNULL },
187 { "time", false, OPT_TIME },
188 #if defined(STATISTICS)
189 { "stat", false, OPT_STAT },
191 { "log", true, OPT_LOG },
192 { "c", true, OPT_CHECK },
193 { "l", false, OPT_LOAD },
194 { "eager", false, OPT_EAGER },
195 { "m", true, OPT_METHOD },
196 { "sig", true, OPT_SIGNATURE },
197 { "s", true, OPT_SHOW },
198 { "all", false, OPT_ALL },
199 { "oloop", false, OPT_OLOOP },
200 { "i", true, OPT_INLINING },
201 #ifdef STATIC_ANALYSIS
202 { "rt", false, OPT_RT },
203 { "xta", false, OPT_XTA },
204 { "vta", false, OPT_VTA },
207 { "lsra", false, OPT_LSRA },
209 { "jar", false, OPT_JAR },
210 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
211 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
212 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
213 { "version", false, OPT_VERSION },
214 { "showversion", false, OPT_SHOWVERSION },
215 { "fullversion", false, OPT_FULLVERSION },
216 { "help", false, OPT_HELP },
217 { "?", false, OPT_HELP },
218 { "X", false, OPT_X },
223 /* usage ***********************************************************************
225 Prints the correct usage syntax to stdout.
227 *******************************************************************************/
229 static void usage(void)
231 printf("Usage: cacao [-options] classname [arguments]\n");
232 printf(" (to run a class file)\n");
233 printf(" cacao [-options] -jar jarfile [arguments]\n");
234 printf(" (to run a standalone jar file)\n\n");
236 printf("Java options:\n");
237 printf(" -cp <path> specify a path to look for classes\n");
238 printf(" -classpath <path> specify a path to look for classes\n");
239 printf(" -D<name>=<value> add an entry to the property list\n");
240 printf(" -verbose[:class|gc|jni] enable specific verbose output\n");
241 printf(" -version print product version and exit\n");
242 printf(" -fullversion print jpackage-compatible product version and exit\n");
243 printf(" -showversion print product version and continue\n");
244 printf(" -help, -? print this help message\n");
245 printf(" -X print help on non-standard Java options\n\n");
247 printf("CACAO options:\n");
248 printf(" -v write state-information\n");
249 printf(" -verbose write more information\n");
250 printf(" -verbosegc write message for each GC\n");
251 printf(" -verbosecall write message for each call\n");
252 printf(" -verboseexception write message for each step of stack unwinding\n");
253 #ifdef TYPECHECK_VERBOSE
254 printf(" -verbosetc write debug messages while typechecking\n");
256 #if defined(__ALPHA__)
257 printf(" -noieee don't use ieee compliant arithmetic\n");
259 printf(" -noverify don't verify classfiles\n");
260 printf(" -liberalutf don't warn about overlong UTF-8 sequences\n");
261 printf(" -softnull use software nullpointer check\n");
262 printf(" -time measure the runtime\n");
263 #if defined(STATISTICS)
264 printf(" -stat detailed compiler statistics\n");
266 printf(" -log logfile specify a name for the logfile\n");
267 printf(" -c(heck)b(ounds) don't check array bounds\n");
268 printf(" s(ync) don't check for synchronization\n");
269 printf(" -oloop optimize array accesses in loops\n");
270 printf(" -l don't start the class after loading\n");
271 printf(" -eager perform eager class loading and linking\n");
272 printf(" -all compile all methods, no execution\n");
273 printf(" -m compile only a specific method\n");
274 printf(" -sig specify signature for a specific method\n");
275 printf(" -s(how)a(ssembler) show disassembled listing\n");
276 printf(" c(onstants) show the constant pool\n");
277 printf(" d(atasegment) show data segment listing\n");
278 printf(" e(xceptionstubs) show disassembled exception stubs (only with -sa)\n");
279 printf(" i(ntermediate) show intermediate representation\n");
280 printf(" m(ethods) show class fields and methods\n");
281 printf(" n(ative) show disassembled native stubs\n");
282 printf(" u(tf) show the utf - hash\n");
283 printf(" -i n(line) activate inlining\n");
284 printf(" v(irtual) inline virtual methods (uses/turns rt option on)\n");
285 printf(" e(exception) inline methods with exceptions\n");
286 printf(" p(aramopt) optimize argument renaming\n");
287 printf(" o(utsiders) inline methods of foreign classes\n");
288 #ifdef STATIC_ANALYSIS
289 printf(" -rt use rapid type analysis\n");
290 printf(" -xta use x type analysis\n");
291 printf(" -vta use variable type analysis\n");
294 printf(" -lsra use linear scan register allocation\n");
297 /* exit with error code */
303 static void Xusage(void)
305 printf(" -Xbootclasspath:<zip/jar files and directories separated by :>\n");
306 printf(" value is set as bootstrap class path\n");
307 printf(" -Xbootclasspath/a:<zip/jar files and directories separated by :>\n");
308 printf(" value is appended to the bootstrap class path\n");
309 printf(" -Xbootclasspath/p:<zip/jar files and directories separated by :>\n");
310 printf(" value is prepended to the bootstrap class path\n");
311 printf(" -Xms<size> set the initial size of the heap (default: 2M)\n");
312 printf(" -Xmx<size> set the maximum size of the heap (default: 64M)\n");
314 /* exit with error code */
320 /* version *********************************************************************
322 Only prints cacao version information.
324 *******************************************************************************/
326 static void version(void)
328 printf("java version \""JAVA_VERSION"\"\n");
329 printf("CACAO version "VERSION"\n");
331 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
332 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
333 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
334 printf("Institut f. Computersprachen - TU Wien\n\n");
336 printf("This program is free software; you can redistribute it and/or\n");
337 printf("modify it under the terms of the GNU General Public License as\n");
338 printf("published by the Free Software Foundation; either version 2, or (at\n");
339 printf("your option) any later version.\n\n");
341 printf("This program is distributed in the hope that it will be useful, but\n");
342 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
343 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
344 printf("General Public License for more details.\n");
348 /* fullversion *****************************************************************
350 Prints a Sun compatible version information (required e.g. by
351 jpackage, www.jpackage.org).
353 *******************************************************************************/
355 static void fullversion(void)
357 printf("java full version \"cacao-"JAVA_VERSION"\"\n");
365 #ifdef TYPECHECK_STATISTICS
366 void typecheck_print_statistics(FILE *file);
371 /* getmainclassfromjar *********************************************************
373 Gets the name of the main class form a JAR's manifest file.
375 *******************************************************************************/
377 static char *getmainclassnamefromjar(char *mainstring)
380 java_objectheader *o;
384 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
387 throw_main_exception_exit();
389 /* create JarFile object */
394 throw_main_exception_exit();
397 m = class_resolveclassmethod(c,
399 utf_java_lang_String__void,
400 class_java_lang_Object,
404 throw_main_exception_exit();
406 s = javastring_new_char(mainstring);
408 asm_calljavafunction(m, o, s, NULL, NULL);
411 throw_main_exception_exit();
413 /* get manifest object */
415 m = class_resolveclassmethod(c,
416 utf_new_char("getManifest"),
417 utf_new_char("()Ljava/util/jar/Manifest;"),
418 class_java_lang_Object,
422 throw_main_exception_exit();
424 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
427 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
432 /* get Main Attributes */
434 m = class_resolveclassmethod(o->vftbl->class,
435 utf_new_char("getMainAttributes"),
436 utf_new_char("()Ljava/util/jar/Attributes;"),
437 class_java_lang_Object,
441 throw_main_exception_exit();
443 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
446 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
451 /* get property Main-Class */
453 m = class_resolveclassmethod(o->vftbl->class,
454 utf_new_char("getValue"),
455 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
456 class_java_lang_Object,
460 throw_main_exception_exit();
462 s = javastring_new_char("Main-Class");
464 o = asm_calljavafunction(m, o, s, NULL, NULL);
467 throw_main_exception_exit();
469 return javastring_tochar(o);
473 /* exit_handler ****************************************************************
475 The exit_handler function is called upon program termination.
477 ATTENTION: Don't free system resources here! Some threads may still
478 be running as this is called from VMRuntime.exit(). The OS does the
481 *******************************************************************************/
483 void exit_handler(void)
485 /********************* Print debug tables ************************/
487 if (showmethods) class_showmethods(mainclass);
488 if (showconstantpool) class_showconstantpool(mainclass);
489 if (showutf) utf_show();
491 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
492 clear_thread_flags(); /* restores standard file descriptor
496 if (opt_verbose || getcompilingtime || opt_stat) {
497 log_text("CACAO terminated");
499 #if defined(STATISTICS)
502 #ifdef TYPECHECK_STATISTICS
503 typecheck_print_statistics(get_logfile());
507 if (getcompilingtime)
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");
547 /************ Collect info from the environment ************************/
549 /* set the bootclasspath */
551 cp = getenv("BOOTCLASSPATH");
553 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
554 strcpy(bootclasspath, cp);
557 #if !defined(WITH_EXTERNAL_CLASSPATH)
558 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_RT_JAR_PATH) +
561 bootclasspath = MNEW(char, cplen);
562 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
563 strcat(bootclasspath, CACAO_RT_JAR_PATH);
565 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_VM_ZIP_PATH) +
567 strlen(EXTERNAL_CLASSPATH_PREFIX) +
568 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
571 bootclasspath = MNEW(char, cplen);
572 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
573 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
574 strcat(bootclasspath, ":");
575 strcat(bootclasspath, EXTERNAL_CLASSPATH_PREFIX);
576 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
581 /* set the classpath */
583 cp = getenv("CLASSPATH");
585 classpath = MNEW(char, strlen(cp) + strlen("0"));
586 strcat(classpath, cp);
589 classpath = MNEW(char, strlen(".") + strlen("0"));
590 strcpy(classpath, ".");
594 /***************** Interpret the command line *****************/
599 heapmaxsize = HEAP_MAXSIZE;
600 heapstartsize = HEAP_STARTSIZE;
603 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
608 case OPT_BOOTCLASSPATH:
609 /* Forget default bootclasspath and set the argument as new boot */
611 MFREE(bootclasspath, char, strlen(bootclasspath));
613 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
614 strcpy(bootclasspath, opt_arg);
617 case OPT_BOOTCLASSPATH_A:
618 /* append to end of bootclasspath */
619 cplen = strlen(bootclasspath);
621 bootclasspath = MREALLOC(bootclasspath,
624 cplen + strlen(":") +
625 strlen(opt_arg) + strlen("0"));
627 strcat(bootclasspath, ":");
628 strcat(bootclasspath, opt_arg);
631 case OPT_BOOTCLASSPATH_P:
632 /* prepend in front of bootclasspath */
636 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
637 cplen + strlen("0"));
639 strcpy(bootclasspath, opt_arg);
640 strcat(bootclasspath, ":");
641 strcat(bootclasspath, cp);
643 MFREE(cp, char, cplen);
647 /* forget old classpath and set the argument as new classpath */
648 MFREE(classpath, char, strlen(classpath));
650 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
651 strcpy(classpath, opt_arg);
660 for (j = 0; j < strlen(opt_arg); j++) {
661 if (opt_arg[j] == '=') {
663 create_property(opt_arg, opt_arg + j + 1);
668 /* if no '=' is given, just create an empty property */
669 create_property(opt_arg, "");
679 c = opt_arg[strlen(opt_arg) - 1];
681 if (c == 'k' || c == 'K') {
682 j = 1024 * atoi(opt_arg);
684 } else if (c == 'm' || c == 'M') {
685 j = 1024 * 1024 * atoi(opt_arg);
687 } else j = atoi(opt_arg);
689 if (i == OPT_MX) heapmaxsize = j;
690 else heapstartsize = j;
703 compileverbose = true;
706 case OPT_VERBOSESPECIFIC:
707 if (strcmp("class", opt_arg) == 0) {
711 } else if (strcmp("gc", opt_arg) == 0) {
712 opt_verbosegc = true;
714 } else if (strcmp("jni", opt_arg) == 0) {
715 opt_verbosejni = true;
719 case OPT_VERBOSEEXCEPTION:
720 verboseexception = true;
723 #ifdef TYPECHECK_VERBOSE
725 typecheckverbose = true;
729 case OPT_VERBOSECALL:
738 case OPT_FULLVERSION:
742 case OPT_SHOWVERSION:
755 opt_liberalutf = true;
763 getcompilingtime = true;
764 getloadingtime = true;
767 #if defined(STATISTICS)
774 strcpy(logfilename, opt_arg);
778 for (j = 0; j < strlen(opt_arg); j++) {
779 switch (opt_arg[j]) {
794 makeinitializations = false;
803 specificmethodname = opt_arg;
804 makeinitializations = false;
808 specificsignature = opt_arg;
814 makeinitializations = false;
817 case OPT_SHOW: /* Display options */
818 for (j = 0; j < strlen(opt_arg); j++) {
819 switch (opt_arg[j]) {
821 opt_showdisassemble = true;
822 compileverbose = true;
825 showconstantpool = true;
828 opt_showddatasegment = true;
831 opt_showexceptionstubs = true;
834 opt_showintermediate = true;
835 compileverbose = true;
841 opt_shownativestub = true;
857 for (j = 0; j < strlen(opt_arg); j++) {
858 switch (opt_arg[j]) {
860 /* define in options.h; Used in main.c, jit.c & inline.c */
869 inlinevirtuals = true;
873 inlineexceptions = true;
876 inlineparamopt = true;
879 inlineoutsiders = true;
887 #ifdef STATIC_ANALYSIS
889 opt_rt = true; /* default for inlining */
893 opt_xta = true; /* in test currently */
897 printf("\nVTA is not yet available\n");
899 /***opt_vta = true; not yet **/
918 printf("Unknown option: %s\n", argv[opt_ind]);
927 /* transform dots into slashes in the class name */
929 mainstring = argv[opt_ind++];
932 /* do not mangle jar filename */
934 for (i = strlen(mainstring) - 1; i >= 0; i--) {
935 if (mainstring[i] == '.') mainstring[i] = '/';
939 /* put jarfile in classpath */
943 classpath = MNEW(char, strlen(mainstring) + strlen(":") +
944 strlen(classpath) + strlen("0"));
946 strcpy(classpath, mainstring);
947 strcat(classpath, ":");
948 strcat(classpath, cp);
950 MFREE(cp, char, strlen(cp));
953 /**************************** Program start *****************************/
955 log_init(logfilename);
958 log_text("CACAO started -------------------------------------------------------");
960 /* initialize JavaVM */
962 vm_args.version = 0x00010001; /* New in 1.1.2: VM version */
964 /* Get the default initialization arguments and set the class path */
966 JNI_GetDefaultJavaVMInitArgs(&vm_args);
968 vm_args.minHeapSize = heapstartsize;
969 vm_args.maxHeapSize = heapmaxsize;
971 vm_args.classpath = classpath;
973 /* load and initialize a Java VM, return a JNI interface pointer in env */
975 JNI_CreateJavaVM(&jvm, &env, &vm_args);
977 #if defined(ENABLE_JVMTI)
978 set_jvmti_phase(JVMTI_PHASE_START);
981 /* initialize the garbage collector */
983 gc_init(heapmaxsize, heapstartsize);
987 /* initialize the loader with bootclasspath */
989 suck_init(bootclasspath);
991 cacao_initializing = true;
993 #if defined(USE_THREADS)
994 #if defined(NATIVE_THREADS)
1000 /* install architecture dependent signal handler used for exceptions */
1004 /* initialize the codegen sub systems */
1008 /* initializes jit compiler */
1012 /* machine dependent initialization */
1016 /* initialize some cacao subsystems */
1020 if (!loader_init((u1 *) &dummy))
1021 throw_main_exception_exit();
1024 throw_main_exception_exit();
1027 throw_main_exception_exit();
1029 if (!exceptions_init())
1030 throw_main_exception_exit();
1032 if (!builtin_init())
1033 throw_main_exception_exit();
1035 #if defined(USE_THREADS)
1036 initThreads((u1 *) &dummy);
1039 *threadrootmethod = NULL;
1041 /*That's important, otherwise we get into trouble, if the Runtime static
1042 initializer is called before (circular dependency. This is with
1043 classpath 0.09. Another important thing is, that this has to happen
1044 after initThreads!!! */
1046 if (!initialize_class(class_java_lang_System))
1047 throw_main_exception_exit();
1049 cacao_initializing = false;
1052 /* start worker routines **************************************************/
1055 classinfo *mainclass; /* java/lang/Class */
1057 java_objectarray *a;
1060 /* set return value to OK */
1065 /* open jar file with java.util.jar.JarFile */
1066 mainstring = getmainclassnamefromjar(mainstring);
1069 /* load the main class */
1071 if (!(mainclass = load_class_from_sysloader(utf_new_char(mainstring))))
1072 throw_main_exception_exit();
1074 /* error loading class, clear exceptionptr for new exception */
1076 if (*exceptionptr || !mainclass) {
1077 /* *exceptionptr = NULL; */
1079 /* *exceptionptr = */
1080 /* new_exception_message(string_java_lang_NoClassDefFoundError, */
1082 throw_main_exception_exit();
1085 /* find the `main' method of the main class */
1087 m = class_resolveclassmethod(mainclass,
1088 utf_new_char("main"),
1089 utf_new_char("([Ljava/lang/String;)V"),
1090 class_java_lang_Object,
1093 if (*exceptionptr) {
1094 throw_main_exception_exit();
1097 /* there is no main method or it isn't static */
1099 if (!m || !(m->flags & ACC_STATIC)) {
1100 *exceptionptr = NULL;
1103 new_exception_message(string_java_lang_NoSuchMethodError,
1105 throw_main_exception_exit();
1108 /* build argument array */
1110 a = builtin_anewarray(argc - opt_ind, class_java_lang_String);
1111 for (i = opt_ind; i < argc; i++) {
1112 a->data[i - opt_ind] =
1113 (java_objectheader *) javastring_new(utf_new_char(argv[i]));
1116 #ifdef TYPEINFO_DEBUG_TEST
1117 /* test the typeinfo system */
1120 /*class_showmethods(currentThread->group->header.vftbl->class); */
1122 *threadrootmethod = m;
1126 asm_calljavafunction(m, a, NULL, NULL, NULL);
1128 /* exception occurred? */
1129 if (*exceptionptr) {
1130 throw_main_exception();
1134 #if defined(USE_THREADS)
1135 #if defined(NATIVE_THREADS)
1138 killThread(currentThread);
1142 /* now exit the JavaVM */
1144 /* (*jvm)->DestroyJavaVM(jvm); */
1149 /************* If requested, compile all methods ********************/
1156 classcache_name_entry *nmen;
1157 classcache_class_entry *clsen;
1159 /* create all classes found in the classpath */
1160 /* XXX currently only works with zip/jar's */
1162 loader_load_all_classes();
1164 /* link all classes */
1166 for (slot = 0; slot < classcache_hash.size; slot++) {
1167 nmen = (classcache_name_entry *) classcache_hash.ptr[slot];
1169 for (; nmen; nmen = nmen->hashlink) {
1170 /* iterate over all class entries */
1172 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
1173 c = clsen->classobj;
1180 /*utf_fprint_classname(stderr,c->name);fprintf(stderr,"\n");*/
1184 throw_main_exception_exit();
1186 /* compile all class methods */
1187 for (i = 0; i < c->methodscount; i++) {
1188 m = &(c->methods[i]);
1190 /*fprintf(stderr," compiling:");utf_fprint(stderr,m->name);fprintf(stderr,"\n");*/
1191 (void) jit_compile(m);
1200 /******** If requested, compile a specific method ***************/
1202 if (specificmethodname) {
1205 /* create, load and link the main class */
1207 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
1208 throw_main_exception_exit();
1210 if (!link_class(mainclass))
1211 throw_main_exception_exit();
1213 if (specificsignature) {
1214 m = class_resolveclassmethod(mainclass,
1215 utf_new_char(specificmethodname),
1216 utf_new_char(specificsignature),
1220 m = class_resolveclassmethod(mainclass,
1221 utf_new_char(specificmethodname),
1228 char message[MAXLOGTEXT];
1229 sprintf(message, "%s%s", specificmethodname,
1230 specificsignature ? specificsignature : "");
1233 new_exception_message(string_java_lang_NoSuchMethodException,
1236 throw_main_exception_exit();
1244 /* keep compiler happy */
1250 /* cacao_exit ******************************************************************
1252 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1254 *******************************************************************************/
1256 void cacao_exit(s4 status)
1261 assert(class_java_lang_System);
1262 assert(class_java_lang_System->loaded);
1264 if (!link_class(class_java_lang_System))
1265 throw_main_exception_exit();
1267 /* call java.lang.System.exit(I)V */
1269 m = class_resolveclassmethod(class_java_lang_System,
1270 utf_new_char("exit"),
1272 class_java_lang_Object,
1276 throw_main_exception_exit();
1278 /* call the exit function with passed exit status */
1280 /* both inlinevirtual and outsiders not allowed on exit */
1281 /* not sure if permanant or temp restriction */
1282 if (inlinevirtuals) inlineoutsiders = false;
1284 asm_calljavafunction(m, (void *) (ptrint) status, NULL, NULL, NULL);
1286 /* this should never happen */
1289 throw_exception_exit();
1291 throw_cacao_exception_exit(string_java_lang_InternalError,
1292 "System.exit(I)V returned without exception");
1296 /*************************** Shutdown function *********************************
1298 Terminates the system immediately without freeing memory explicitly (to be
1299 used only for abnormal termination)
1301 *******************************************************************************/
1303 void cacao_shutdown(s4 status)
1305 if (opt_verbose || getcompilingtime || opt_stat) {
1306 log_text("CACAO terminated by shutdown");
1307 dolog("Exit status: %d\n", (s4) status);
1315 * These are local overrides for various environment variables in Emacs.
1316 * Please do not remove this and leave it at the end of the file, where
1317 * Emacs will automagically detect them.
1318 * ---------------------------------------------------------------------
1321 * indent-tabs-mode: t