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 3148 2005-09-05 20:12:24Z 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 #define OPT_INTRP 103
165 #define OPT_TRACE 104
167 opt_struct opts[] = {
168 { "classpath", true, OPT_CLASSPATH },
169 { "cp", true, OPT_CLASSPATH },
170 { "D", true, OPT_D },
171 { "Xms", true, OPT_MS },
172 { "Xmx", true, OPT_MX },
173 { "ms", true, OPT_MS },
174 { "mx", true, OPT_MX },
175 { "noasyncgc", false, OPT_IGNORE },
176 { "noverify", false, OPT_NOVERIFY },
177 { "liberalutf", false, OPT_LIBERALUTF },
178 { "ss", true, OPT_IGNORE },
179 { "v", false, OPT_VERBOSE1 },
180 { "verbose", false, OPT_VERBOSE },
181 { "verbose:", true, OPT_VERBOSESPECIFIC },
182 { "verbosecall", false, OPT_VERBOSECALL },
183 { "verboseexception", false, OPT_VERBOSEEXCEPTION },
184 #ifdef TYPECHECK_VERBOSE
185 { "verbosetc", false, OPT_VERBOSETC },
187 #if defined(__ALPHA__)
188 { "noieee", false, OPT_NOIEEE },
190 { "softnull", false, OPT_SOFTNULL },
191 { "time", false, OPT_TIME },
192 #if defined(STATISTICS)
193 { "stat", false, OPT_STAT },
195 { "log", true, OPT_LOG },
196 { "c", true, OPT_CHECK },
197 { "l", false, OPT_LOAD },
198 { "eager", false, OPT_EAGER },
199 { "m", true, OPT_METHOD },
200 { "sig", true, OPT_SIGNATURE },
201 { "s", true, OPT_SHOW },
202 { "all", false, OPT_ALL },
203 { "oloop", false, OPT_OLOOP },
204 { "i", true, OPT_INLINING },
205 #ifdef STATIC_ANALYSIS
206 { "rt", false, OPT_RT },
207 { "xta", false, OPT_XTA },
208 { "vta", false, OPT_VTA },
211 { "lsra", false, OPT_LSRA },
213 { "jar", false, OPT_JAR },
214 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
215 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
216 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
217 { "version", false, OPT_VERSION },
218 { "showversion", false, OPT_SHOWVERSION },
219 { "fullversion", false, OPT_FULLVERSION },
220 { "help", false, OPT_HELP },
221 { "?", false, OPT_HELP },
222 { "X", false, OPT_X },
223 { "Xjit", false, OPT_JIT },
224 { "Xint", false, OPT_INTRP },
225 { "t", false, OPT_TRACE },
230 /* usage ***********************************************************************
232 Prints the correct usage syntax to stdout.
234 *******************************************************************************/
236 static void usage(void)
238 printf("Usage: cacao [-options] classname [arguments]\n");
239 printf(" (to run a class file)\n");
240 printf(" cacao [-options] -jar jarfile [arguments]\n");
241 printf(" (to run a standalone jar file)\n\n");
243 printf("Java options:\n");
244 printf(" -cp <path> specify a path to look for classes\n");
245 printf(" -classpath <path> specify a path to look for classes\n");
246 printf(" -D<name>=<value> add an entry to the property list\n");
247 printf(" -verbose[:class|gc|jni] enable specific verbose output\n");
248 printf(" -version print product version and exit\n");
249 printf(" -fullversion print jpackage-compatible product version and exit\n");
250 printf(" -showversion print product version and continue\n");
251 printf(" -help, -? print this help message\n");
252 printf(" -X print help on non-standard Java options\n\n");
254 printf("CACAO options:\n");
255 printf(" -v write state-information\n");
256 printf(" -verbose write more information\n");
257 printf(" -verbosegc write message for each GC\n");
258 printf(" -verbosecall write message for each call\n");
259 printf(" -verboseexception write message for each step of stack unwinding\n");
260 #ifdef TYPECHECK_VERBOSE
261 printf(" -verbosetc write debug messages while typechecking\n");
263 #if defined(__ALPHA__)
264 printf(" -noieee don't use ieee compliant arithmetic\n");
266 printf(" -noverify don't verify classfiles\n");
267 printf(" -liberalutf don't warn about overlong UTF-8 sequences\n");
268 printf(" -softnull use software nullpointer check\n");
269 printf(" -time measure the runtime\n");
270 #if defined(STATISTICS)
271 printf(" -stat detailed compiler statistics\n");
273 printf(" -log logfile specify a name for the logfile\n");
274 printf(" -c(heck)b(ounds) don't check array bounds\n");
275 printf(" s(ync) don't check for synchronization\n");
276 printf(" -oloop optimize array accesses in loops\n");
277 printf(" -l don't start the class after loading\n");
278 printf(" -eager perform eager class loading and linking\n");
279 printf(" -all compile all methods, no execution\n");
280 printf(" -m compile only a specific method\n");
281 printf(" -sig specify signature for a specific method\n");
282 printf(" -s(how)a(ssembler) show disassembled listing\n");
283 printf(" c(onstants) show the constant pool\n");
284 printf(" d(atasegment) show data segment listing\n");
285 printf(" e(xceptionstubs) show disassembled exception stubs (only with -sa)\n");
286 printf(" i(ntermediate) show intermediate representation\n");
287 printf(" m(ethods) show class fields and methods\n");
288 printf(" n(ative) show disassembled native stubs\n");
289 printf(" u(tf) show the utf - hash\n");
290 printf(" -i n(line) activate inlining\n");
291 printf(" v(irtual) inline virtual methods (uses/turns rt option on)\n");
292 printf(" e(exception) inline methods with exceptions\n");
293 printf(" p(aramopt) optimize argument renaming\n");
294 printf(" o(utsiders) inline methods of foreign classes\n");
295 #ifdef STATIC_ANALYSIS
296 printf(" -rt use rapid type analysis\n");
297 printf(" -xta use x type analysis\n");
298 printf(" -vta use variable type analysis\n");
301 printf(" -lsra use linear scan register allocation\n");
304 /* exit with error code */
310 static void Xusage(void)
312 #if defined(ENABLE_JIT)
313 printf(" -Xjit JIT mode execution (default)\n");
315 #if defined(ENABLE_INTRP)
316 printf(" -Xint interpreter mode execution\n");
318 printf(" -Xbootclasspath:<zip/jar files and directories separated by :>\n");
319 printf(" value is set as bootstrap class path\n");
320 printf(" -Xbootclasspath/a:<zip/jar files and directories separated by :>\n");
321 printf(" value is appended to the bootstrap class path\n");
322 printf(" -Xbootclasspath/p:<zip/jar files and directories separated by :>\n");
323 printf(" value is prepended to the bootstrap class path\n");
324 printf(" -Xms<size> set the initial size of the heap (default: 2M)\n");
325 printf(" -Xmx<size> set the maximum size of the heap (default: 64M)\n");
327 /* exit with error code */
333 /* version *********************************************************************
335 Only prints cacao version information.
337 *******************************************************************************/
339 static void version(void)
341 printf("java version \""JAVA_VERSION"\"\n");
342 printf("CACAO version "VERSION"\n");
344 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
345 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
346 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
347 printf("Institut f. Computersprachen - TU Wien\n\n");
349 printf("This program is free software; you can redistribute it and/or\n");
350 printf("modify it under the terms of the GNU General Public License as\n");
351 printf("published by the Free Software Foundation; either version 2, or (at\n");
352 printf("your option) any later version.\n\n");
354 printf("This program is distributed in the hope that it will be useful, but\n");
355 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
356 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
357 printf("General Public License for more details.\n");
361 /* fullversion *****************************************************************
363 Prints a Sun compatible version information (required e.g. by
364 jpackage, www.jpackage.org).
366 *******************************************************************************/
368 static void fullversion(void)
370 printf("java full version \"cacao-"JAVA_VERSION"\"\n");
378 #ifdef TYPECHECK_STATISTICS
379 void typecheck_print_statistics(FILE *file);
384 /* getmainclassfromjar *********************************************************
386 Gets the name of the main class form a JAR's manifest file.
388 *******************************************************************************/
390 static char *getmainclassnamefromjar(char *mainstring)
393 java_objectheader *o;
397 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
400 throw_main_exception_exit();
402 /* create JarFile object */
407 throw_main_exception_exit();
410 m = class_resolveclassmethod(c,
412 utf_java_lang_String__void,
413 class_java_lang_Object,
417 throw_main_exception_exit();
419 s = javastring_new_char(mainstring);
421 asm_calljavafunction(m, o, s, NULL, NULL);
424 throw_main_exception_exit();
426 /* get manifest object */
428 m = class_resolveclassmethod(c,
429 utf_new_char("getManifest"),
430 utf_new_char("()Ljava/util/jar/Manifest;"),
431 class_java_lang_Object,
435 throw_main_exception_exit();
437 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
440 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
445 /* get Main Attributes */
447 m = class_resolveclassmethod(o->vftbl->class,
448 utf_new_char("getMainAttributes"),
449 utf_new_char("()Ljava/util/jar/Attributes;"),
450 class_java_lang_Object,
454 throw_main_exception_exit();
456 o = asm_calljavafunction(m, o, NULL, NULL, NULL);
459 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
464 /* get property Main-Class */
466 m = class_resolveclassmethod(o->vftbl->class,
467 utf_new_char("getValue"),
468 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
469 class_java_lang_Object,
473 throw_main_exception_exit();
475 s = javastring_new_char("Main-Class");
477 o = asm_calljavafunction(m, o, s, NULL, NULL);
480 throw_main_exception_exit();
482 return javastring_tochar(o);
486 /* exit_handler ****************************************************************
488 The exit_handler function is called upon program termination.
490 ATTENTION: Don't free system resources here! Some threads may still
491 be running as this is called from VMRuntime.exit(). The OS does the
494 *******************************************************************************/
496 void exit_handler(void)
498 /********************* Print debug tables ************************/
500 if (showmethods) class_showmethods(mainclass);
501 if (showconstantpool) class_showconstantpool(mainclass);
502 if (showutf) utf_show();
504 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
505 clear_thread_flags(); /* restores standard file descriptor
509 if (opt_verbose || getcompilingtime || opt_stat) {
510 log_text("CACAO terminated");
512 #if defined(STATISTICS)
515 #ifdef TYPECHECK_STATISTICS
516 typecheck_print_statistics(get_logfile());
520 if (getcompilingtime)
528 /* main ************************************************************************
532 *******************************************************************************/
534 int main(int argc, char **argv)
539 /* local variables ********************************************************/
541 char logfilename[200] = "";
547 char *specificmethodname = NULL;
548 char *specificsignature = NULL;
551 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
552 stackbottom = &dummy;
555 if (atexit(exit_handler))
556 throw_cacao_exception_exit(string_java_lang_InternalError,
557 "Unable to register exit_handler");
560 /************ Collect info from the environment ************************/
562 /* set the bootclasspath */
564 cp = getenv("BOOTCLASSPATH");
566 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
567 strcpy(bootclasspath, cp);
570 #if !defined(WITH_EXTERNAL_CLASSPATH)
571 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_RT_JAR_PATH) +
574 bootclasspath = MNEW(char, cplen);
575 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
576 strcat(bootclasspath, CACAO_RT_JAR_PATH);
578 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_VM_ZIP_PATH) +
580 strlen(EXTERNAL_CLASSPATH_PREFIX) +
581 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
584 bootclasspath = MNEW(char, cplen);
585 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
586 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
587 strcat(bootclasspath, ":");
588 strcat(bootclasspath, EXTERNAL_CLASSPATH_PREFIX);
589 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
594 /* set the classpath */
596 cp = getenv("CLASSPATH");
598 classpath = MNEW(char, strlen(cp) + strlen("0"));
599 strcat(classpath, cp);
602 classpath = MNEW(char, strlen(".") + strlen("0"));
603 strcpy(classpath, ".");
607 /***************** Interpret the command line *****************/
612 heapmaxsize = HEAP_MAXSIZE;
613 heapstartsize = HEAP_STARTSIZE;
616 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
621 case OPT_BOOTCLASSPATH:
622 /* Forget default bootclasspath and set the argument as new boot */
624 MFREE(bootclasspath, char, strlen(bootclasspath));
626 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
627 strcpy(bootclasspath, opt_arg);
630 case OPT_BOOTCLASSPATH_A:
631 /* append to end of bootclasspath */
632 cplen = strlen(bootclasspath);
634 bootclasspath = MREALLOC(bootclasspath,
637 cplen + strlen(":") +
638 strlen(opt_arg) + strlen("0"));
640 strcat(bootclasspath, ":");
641 strcat(bootclasspath, opt_arg);
644 case OPT_BOOTCLASSPATH_P:
645 /* prepend in front of bootclasspath */
649 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
650 cplen + strlen("0"));
652 strcpy(bootclasspath, opt_arg);
653 strcat(bootclasspath, ":");
654 strcat(bootclasspath, cp);
656 MFREE(cp, char, cplen);
660 /* forget old classpath and set the argument as new classpath */
661 MFREE(classpath, char, strlen(classpath));
663 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
664 strcpy(classpath, opt_arg);
673 for (j = 0; j < strlen(opt_arg); j++) {
674 if (opt_arg[j] == '=') {
676 create_property(opt_arg, opt_arg + j + 1);
681 /* if no '=' is given, just create an empty property */
682 create_property(opt_arg, "");
692 c = opt_arg[strlen(opt_arg) - 1];
694 if (c == 'k' || c == 'K') {
695 j = 1024 * atoi(opt_arg);
697 } else if (c == 'm' || c == 'M') {
698 j = 1024 * 1024 * atoi(opt_arg);
700 } else j = atoi(opt_arg);
702 if (i == OPT_MX) heapmaxsize = j;
703 else heapstartsize = j;
716 compileverbose = true;
719 case OPT_VERBOSESPECIFIC:
720 if (strcmp("class", opt_arg) == 0) {
724 } else if (strcmp("gc", opt_arg) == 0) {
725 opt_verbosegc = true;
727 } else if (strcmp("jni", opt_arg) == 0) {
728 opt_verbosejni = true;
732 case OPT_VERBOSEEXCEPTION:
733 verboseexception = true;
736 #ifdef TYPECHECK_VERBOSE
738 typecheckverbose = true;
742 case OPT_VERBOSECALL:
751 case OPT_FULLVERSION:
755 case OPT_SHOWVERSION:
768 opt_liberalutf = true;
776 getcompilingtime = true;
777 getloadingtime = true;
780 #if defined(STATISTICS)
787 strcpy(logfilename, opt_arg);
791 for (j = 0; j < strlen(opt_arg); j++) {
792 switch (opt_arg[j]) {
807 makeinitializations = false;
816 specificmethodname = opt_arg;
817 makeinitializations = false;
821 specificsignature = opt_arg;
827 makeinitializations = false;
830 case OPT_SHOW: /* Display options */
831 for (j = 0; j < strlen(opt_arg); j++) {
832 switch (opt_arg[j]) {
834 opt_showdisassemble = true;
835 compileverbose = true;
838 showconstantpool = true;
841 opt_showddatasegment = true;
844 opt_showexceptionstubs = true;
847 opt_showintermediate = true;
848 compileverbose = true;
854 opt_shownativestub = true;
870 for (j = 0; j < strlen(opt_arg); j++) {
871 switch (opt_arg[j]) {
873 /* define in options.h; Used in main.c, jit.c & inline.c */
882 inlinevirtuals = true;
886 inlineexceptions = true;
889 inlineparamopt = true;
892 inlineoutsiders = true;
900 #ifdef STATIC_ANALYSIS
902 opt_rt = true; /* default for inlining */
906 opt_xta = true; /* in test currently */
910 printf("\nVTA is not yet available\n");
912 /***opt_vta = true; not yet **/
931 #if defined(ENABLE_JIT)
934 printf("-Xjit option not enabled.\n");
940 #if defined(ENABLE_INTRP)
943 printf("-Xint option not enabled.\n");
953 printf("Unknown option: %s\n", argv[opt_ind]);
962 /* transform dots into slashes in the class name */
964 mainstring = argv[opt_ind++];
967 /* do not mangle jar filename */
969 for (i = strlen(mainstring) - 1; i >= 0; i--) {
970 if (mainstring[i] == '.') mainstring[i] = '/';
974 /* put jarfile in classpath */
978 classpath = MNEW(char, strlen(mainstring) + strlen(":") +
979 strlen(classpath) + strlen("0"));
981 strcpy(classpath, mainstring);
982 strcat(classpath, ":");
983 strcat(classpath, cp);
985 MFREE(cp, char, strlen(cp));
988 /**************************** Program start *****************************/
990 log_init(logfilename);
993 log_text("CACAO started -------------------------------------------------------");
995 /* initialize JavaVM */
997 vm_args.version = 0x00010001; /* New in 1.1.2: VM version */
999 /* Get the default initialization arguments and set the class path */
1001 JNI_GetDefaultJavaVMInitArgs(&vm_args);
1003 vm_args.minHeapSize = heapstartsize;
1004 vm_args.maxHeapSize = heapmaxsize;
1006 vm_args.classpath = classpath;
1008 /* load and initialize a Java VM, return a JNI interface pointer in env */
1010 JNI_CreateJavaVM(&jvm, &env, &vm_args);
1012 #if defined(ENABLE_JVMTI)
1013 set_jvmti_phase(JVMTI_PHASE_START);
1016 /* initialize the garbage collector */
1018 gc_init(heapmaxsize, heapstartsize);
1022 /* initialize the loader with bootclasspath */
1024 suck_init(bootclasspath);
1026 cacao_initializing = true;
1028 #if defined(USE_THREADS)
1029 #if defined(NATIVE_THREADS)
1035 /* install architecture dependent signal handler used for exceptions */
1039 /* initialize the codegen sub systems */
1043 /* initializes jit compiler */
1047 /* machine dependent initialization */
1051 /* initialize some cacao subsystems */
1055 if (!loader_init((u1 *) &dummy))
1056 throw_main_exception_exit();
1059 throw_main_exception_exit();
1062 throw_main_exception_exit();
1064 if (!exceptions_init())
1065 throw_main_exception_exit();
1067 if (!builtin_init())
1068 throw_main_exception_exit();
1070 #if defined(USE_THREADS)
1071 initThreads((u1 *) &dummy);
1074 *threadrootmethod = NULL;
1076 /*That's important, otherwise we get into trouble, if the Runtime static
1077 initializer is called before (circular dependency. This is with
1078 classpath 0.09. Another important thing is, that this has to happen
1079 after initThreads!!! */
1081 if (!initialize_class(class_java_lang_System))
1082 throw_main_exception_exit();
1084 cacao_initializing = false;
1087 /* start worker routines **************************************************/
1090 classinfo *mainclass; /* java/lang/Class */
1092 java_objectarray *a;
1095 /* set return value to OK */
1100 /* open jar file with java.util.jar.JarFile */
1101 mainstring = getmainclassnamefromjar(mainstring);
1104 /* load the main class */
1106 if (!(mainclass = load_class_from_sysloader(utf_new_char(mainstring))))
1107 throw_main_exception_exit();
1109 /* error loading class, clear exceptionptr for new exception */
1111 if (*exceptionptr || !mainclass) {
1112 /* *exceptionptr = NULL; */
1114 /* *exceptionptr = */
1115 /* new_exception_message(string_java_lang_NoClassDefFoundError, */
1117 throw_main_exception_exit();
1120 /* find the `main' method of the main class */
1122 m = class_resolveclassmethod(mainclass,
1123 utf_new_char("main"),
1124 utf_new_char("([Ljava/lang/String;)V"),
1125 class_java_lang_Object,
1128 if (*exceptionptr) {
1129 throw_main_exception_exit();
1132 /* there is no main method or it isn't static */
1134 if (!m || !(m->flags & ACC_STATIC)) {
1135 *exceptionptr = NULL;
1138 new_exception_message(string_java_lang_NoSuchMethodError,
1140 throw_main_exception_exit();
1143 /* build argument array */
1145 a = builtin_anewarray(argc - opt_ind, class_java_lang_String);
1146 for (i = opt_ind; i < argc; i++) {
1147 a->data[i - opt_ind] =
1148 (java_objectheader *) javastring_new(utf_new_char(argv[i]));
1151 #ifdef TYPEINFO_DEBUG_TEST
1152 /* test the typeinfo system */
1155 /*class_showmethods(currentThread->group->header.vftbl->class); */
1157 *threadrootmethod = m;
1161 asm_calljavafunction(m, a, NULL, NULL, NULL);
1163 /* exception occurred? */
1164 if (*exceptionptr) {
1165 throw_main_exception();
1169 #if defined(USE_THREADS)
1170 #if defined(NATIVE_THREADS)
1173 killThread(currentThread);
1177 /* now exit the JavaVM */
1179 /* (*jvm)->DestroyJavaVM(jvm); */
1184 /************* If requested, compile all methods ********************/
1191 classcache_name_entry *nmen;
1192 classcache_class_entry *clsen;
1194 /* create all classes found in the classpath */
1195 /* XXX currently only works with zip/jar's */
1197 loader_load_all_classes();
1199 /* link all classes */
1201 for (slot = 0; slot < classcache_hash.size; slot++) {
1202 nmen = (classcache_name_entry *) classcache_hash.ptr[slot];
1204 for (; nmen; nmen = nmen->hashlink) {
1205 /* iterate over all class entries */
1207 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
1208 c = clsen->classobj;
1215 /*utf_fprint_classname(stderr,c->name);fprintf(stderr,"\n");*/
1219 throw_main_exception_exit();
1221 /* compile all class methods */
1222 for (i = 0; i < c->methodscount; i++) {
1223 m = &(c->methods[i]);
1225 /*fprintf(stderr," compiling:");utf_fprint(stderr,m->name);fprintf(stderr,"\n");*/
1226 (void) jit_compile(m);
1235 /******** If requested, compile a specific method ***************/
1237 if (specificmethodname) {
1240 /* create, load and link the main class */
1242 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
1243 throw_main_exception_exit();
1245 if (!link_class(mainclass))
1246 throw_main_exception_exit();
1248 if (specificsignature) {
1249 m = class_resolveclassmethod(mainclass,
1250 utf_new_char(specificmethodname),
1251 utf_new_char(specificsignature),
1255 m = class_resolveclassmethod(mainclass,
1256 utf_new_char(specificmethodname),
1263 char message[MAXLOGTEXT];
1264 sprintf(message, "%s%s", specificmethodname,
1265 specificsignature ? specificsignature : "");
1268 new_exception_message(string_java_lang_NoSuchMethodException,
1271 throw_main_exception_exit();
1279 /* keep compiler happy */
1285 /* cacao_exit ******************************************************************
1287 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1289 *******************************************************************************/
1291 void cacao_exit(s4 status)
1296 assert(class_java_lang_System);
1297 assert(class_java_lang_System->loaded);
1299 if (!link_class(class_java_lang_System))
1300 throw_main_exception_exit();
1302 /* call java.lang.System.exit(I)V */
1304 m = class_resolveclassmethod(class_java_lang_System,
1305 utf_new_char("exit"),
1307 class_java_lang_Object,
1311 throw_main_exception_exit();
1313 /* call the exit function with passed exit status */
1315 /* both inlinevirtual and outsiders not allowed on exit */
1316 /* not sure if permanant or temp restriction */
1317 if (inlinevirtuals) inlineoutsiders = false;
1319 asm_calljavafunction(m, (void *) (ptrint) status, NULL, NULL, NULL);
1321 /* this should never happen */
1324 throw_exception_exit();
1326 throw_cacao_exception_exit(string_java_lang_InternalError,
1327 "System.exit(I)V returned without exception");
1331 /*************************** Shutdown function *********************************
1333 Terminates the system immediately without freeing memory explicitly (to be
1334 used only for abnormal termination)
1336 *******************************************************************************/
1338 void cacao_shutdown(s4 status)
1340 if (opt_verbose || getcompilingtime || opt_stat) {
1341 log_text("CACAO terminated by shutdown");
1342 dolog("Exit status: %d\n", (s4) status);
1350 * These are local overrides for various environment variables in Emacs.
1351 * Please do not remove this and leave it at the end of the file, where
1352 * Emacs will automagically detect them.
1353 * ---------------------------------------------------------------------
1356 * indent-tabs-mode: t