1 /* src/vm/finalizer.c - finalizer linked list and thread
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
31 $Id: finalizer.c 4357 2006-01-22 23:33:38Z twisti $
44 #include "mm/memory.h"
45 #include "native/jni.h"
46 #include "native/native.h"
48 #if defined(USE_THREADS)
49 # if defined(NATIVE_THREADS)
50 # include "threads/native/threads.h"
52 # include "threads/green/threads.h"
53 # include "threads/green/locks.h"
57 #include "vm/classcache.h"
58 #include "vm/exceptions.h"
59 #include "vm/finalizer.h"
60 #include "vm/global.h"
61 #include "vm/initialize.h"
62 #include "vm/options.h"
63 #include "vm/properties.h"
64 #include "vm/signallocal.h"
65 #include "vm/stringlocal.h"
68 #include "vm/jit/jit.h"
69 #include "vm/jit/asmpart.h"
70 #include "vm/jit/profile/profile.h"
71 #include "vm/rt-timing.h"
73 #if defined(ENABLE_JVMTI)
74 #include "native/jvmti/cacaodbg.h"
77 /* Invocation API variables ***************************************************/
79 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
80 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
83 /* global variables ***********************************************************/
85 s4 vms = 0; /* number of VMs created */
87 bool vm_initializing = false;
88 bool vm_exiting = false;
90 #if defined(ENABLE_INTRP)
91 u1 *intrp_main_stack = NULL;
94 void **stackbottom = NULL;
96 char *mainstring = NULL;
97 classinfo *mainclass = NULL;
99 char *specificmethodname = NULL;
100 char *specificsignature = NULL;
105 /* define heap sizes **********************************************************/
107 #define HEAP_MAXSIZE 64 * 1024 * 1024 /* default 64MB */
108 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
109 #define STACK_SIZE 128 * 1024 /* default 128kB */
112 /* define command line options ************************************************/
134 /* Java non-standard options */
156 #if defined(ENABLE_STATISTICS)
169 #if defined(ENABLE_VERIFIER)
174 /* optimization options */
176 #if defined(ENABLE_LOOP)
180 #if defined(ENABLE_IFCONV)
184 #if defined(ENABLE_LSRA)
188 #if defined(ENABLE_INLINING)
192 #if defined(ENABLE_INTRP)
193 /* interpreter options */
216 opt_struct opts[] = {
219 { "jar", false, OPT_JAR },
221 { "d32", false, OPT_D32 },
222 { "d64", false, OPT_D64 },
223 { "client", false, OPT_IGNORE },
224 { "server", false, OPT_IGNORE },
225 { "hotspot", false, OPT_IGNORE },
227 { "classpath", true, OPT_CLASSPATH },
228 { "cp", true, OPT_CLASSPATH },
229 { "D", true, OPT_D },
230 { "version", false, OPT_VERSION },
231 { "showversion", false, OPT_SHOWVERSION },
232 { "fullversion", false, OPT_FULLVERSION },
233 { "help", false, OPT_HELP },
234 { "?", false, OPT_HELP },
235 { "X", false, OPT_X },
237 { "noasyncgc", false, OPT_IGNORE },
238 #if defined(ENABLE_VERIFIER)
239 { "noverify", false, OPT_NOVERIFY },
241 { "v", false, OPT_VERBOSE1 },
242 { "verbose:", true, OPT_VERBOSE },
244 #ifdef TYPECHECK_VERBOSE
245 { "verbosetc", false, OPT_VERBOSETC },
247 #if defined(__ALPHA__)
248 { "noieee", false, OPT_NOIEEE },
250 { "softnull", false, OPT_SOFTNULL },
251 { "time", false, OPT_TIME },
252 #if defined(ENABLE_STATISTICS)
253 { "stat", false, OPT_STAT },
255 { "log", true, OPT_LOG },
256 { "c", true, OPT_CHECK },
257 { "l", false, OPT_LOAD },
258 { "eager", false, OPT_EAGER },
259 { "sig", true, OPT_SIGNATURE },
260 { "all", false, OPT_ALL },
261 #if defined(ENABLE_LOOP)
262 { "oloop", false, OPT_OLOOP },
264 #if defined(ENABLE_IFCONV)
265 { "ifconv", false, OPT_IFCONV },
267 #if defined(ENABLE_LSRA)
268 { "lsra", false, OPT_LSRA },
271 #if defined(ENABLE_INTRP)
272 /* interpreter options */
274 { "trace", false, OPT_TRACE },
275 { "static-supers", true, OPT_STATIC_SUPERS },
276 { "no-dynamic", false, OPT_NO_DYNAMIC },
277 { "no-replication", false, OPT_NO_REPLICATION },
278 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
281 /* JVMTI Agent Command Line Options */
283 { "agentlib:", true, OPT_AGENTLIB },
284 { "agentpath:", true, OPT_AGENTPATH },
287 /* Java non-standard options */
289 { "Xjit", false, OPT_JIT },
290 { "Xint", false, OPT_INTRP },
291 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
292 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
293 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
295 { "Xdebug", false, OPT_DEBUG },
296 { "Xnoagent", false, OPT_NOAGENT },
297 { "Xrunjdwp", true, OPT_XRUNJDWP },
299 { "Xms", true, OPT_MS },
300 { "ms", true, OPT_MS },
301 { "Xmx", true, OPT_MX },
302 { "mx", true, OPT_MX },
303 { "Xss", true, OPT_SS },
304 { "ss", true, OPT_SS },
305 { "Xprof:", true, OPT_PROF_OPTION },
306 { "Xprof", false, OPT_PROF },
308 /* keep these at the end of the list */
310 #if defined(ENABLE_INLINING)
311 { "i", true, OPT_INLINING },
313 { "m", true, OPT_METHOD },
314 { "s", true, OPT_SHOW },
320 /* usage ***********************************************************************
322 Prints the correct usage syntax to stdout.
324 *******************************************************************************/
328 puts("Usage: cacao [-options] classname [arguments]");
329 puts(" (to run a class file)");
330 puts(" or cacao [-options] -jar jarfile [arguments]");
331 puts(" (to run a standalone jar file)\n");
333 puts("Java options:");
334 puts(" -d32 use 32-bit data model if available");
335 puts(" -d64 use 64-bit data model if available");
336 puts(" -client compatibility (currently ignored)");
337 puts(" -server compatibility (currently ignored)");
338 puts(" -hotspot compatibility (currently ignored)\n");
340 puts(" -cp <path> specify a path to look for classes");
341 puts(" -classpath <path> specify a path to look for classes");
342 puts(" -D<name>=<value> add an entry to the property list");
343 puts(" -verbose[:class|gc|jni] enable specific verbose output");
344 puts(" -version print product version and exit");
345 puts(" -fullversion print jpackage-compatible product version and exit");
346 puts(" -showversion print product version and continue");
347 puts(" -help, -? print this help message");
348 puts(" -X print help on non-standard Java options\n");
351 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
352 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
355 puts("CACAO options:\n");
356 puts(" -v write state-information");
357 puts(" -verbose[:call|exception]enable specific verbose output");
358 #ifdef TYPECHECK_VERBOSE
359 puts(" -verbosetc write debug messages while typechecking");
361 #if defined(__ALPHA__)
362 puts(" -noieee don't use ieee compliant arithmetic");
364 #if defined(ENABLE_VERIFIER)
365 puts(" -noverify don't verify classfiles");
367 puts(" -softnull use software nullpointer check");
368 puts(" -time measure the runtime");
369 #if defined(ENABLE_STATISTICS)
370 puts(" -stat detailed compiler statistics");
372 puts(" -log logfile specify a name for the logfile");
373 puts(" -c(heck)b(ounds) don't check array bounds");
374 puts(" s(ync) don't check for synchronization");
375 #if defined(ENABLE_LOOP)
376 puts(" -oloop optimize array accesses in loops");
378 puts(" -l don't start the class after loading");
379 puts(" -eager perform eager class loading and linking");
380 puts(" -all compile all methods, no execution");
381 puts(" -m compile only a specific method");
382 puts(" -sig specify signature for a specific method");
383 puts(" -s(how)a(ssembler) show disassembled listing");
384 puts(" c(onstants) show the constant pool");
385 puts(" d(atasegment) show data segment listing");
386 puts(" e(xceptionstubs) show disassembled exception stubs (only with -sa)");
387 puts(" i(ntermediate) show intermediate representation");
388 puts(" m(ethods) show class fields and methods");
389 puts(" n(ative) show disassembled native stubs");
390 puts(" u(tf) show the utf - hash");
391 #if defined(ENABLE_INLINING)
392 puts(" -i n(line) activate inlining");
393 puts(" v(irtual) inline virtual methods (uses/turns rt option on)");
394 puts(" e(exception) inline methods with exceptions");
395 puts(" p(aramopt) optimize argument renaming");
396 puts(" o(utsiders) inline methods of foreign classes");
397 #endif /* defined(ENABLE_INLINING) */
398 #if defined(ENABLE_IFCONV)
399 puts(" -ifconv use if-conversion");
401 #if defined(ENABLE_LSRA)
402 puts(" -lsra use linear scan register allocation");
405 /* exit with error code */
411 static void Xusage(void)
413 #if defined(ENABLE_JIT)
414 puts(" -Xjit JIT mode execution (default)");
416 #if defined(ENABLE_INTRP)
417 puts(" -Xint interpreter mode execution");
419 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
420 puts(" value is set as bootstrap class path");
421 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
422 puts(" value is appended to the bootstrap class path");
423 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
424 puts(" value is prepended to the bootstrap class path");
425 puts(" -Xms<size> set the initial size of the heap (default: 2MB)");
426 puts(" -Xmx<size> set the maximum size of the heap (default: 64MB)");
427 puts(" -Xss<size> set the thread stack size (default: 128kB)");
428 puts(" -Xprof[:bb] collect and print profiling data");
429 #if defined(ENABLE_JVMTI)
430 /* -Xdebug option depend on gnu classpath JDWP options. options:
431 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
432 puts(" -Xdebug enable remote debugging\n");
433 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
434 puts(" enable remote debugging\n");
437 /* exit with error code */
443 /* version *********************************************************************
445 Only prints cacao version information.
447 *******************************************************************************/
449 static void version(void)
451 puts("java version \""JAVA_VERSION"\"");
452 puts("CACAO version "VERSION"");
454 puts("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,");
455 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
456 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
457 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
459 puts("This program is free software; you can redistribute it and/or");
460 puts("modify it under the terms of the GNU General Public License as");
461 puts("published by the Free Software Foundation; either version 2, or (at");
462 puts("your option) any later version.\n");
464 puts("This program is distributed in the hope that it will be useful, but");
465 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
466 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
467 puts("General Public License for more details.\n");
469 puts("Configure/Build options:\n");
470 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
471 #if defined(__VERSION__)
472 puts(" CC : "VERSION_CC" ("__VERSION__")");
474 puts(" CC : "VERSION_CC"");
476 puts(" CFLAGS : "VERSION_CFLAGS"");
480 /* fullversion *****************************************************************
482 Prints a Sun compatible version information (required e.g. by
483 jpackage, www.jpackage.org).
485 *******************************************************************************/
487 static void fullversion(void)
489 puts("java full version \"cacao-"JAVA_VERSION"\"");
497 /* vm_create *******************************************************************
499 Creates a JVM. Called by JNI_CreateJavaVM.
501 *******************************************************************************/
503 bool vm_create(JavaVMInitArgs *vm_args)
512 /* check the JNI version requested */
514 switch (vm_args->version) {
515 case JNI_VERSION_1_1:
517 case JNI_VERSION_1_2:
518 case JNI_VERSION_1_4:
524 /* we only support 1 JVM instance */
530 /* get stuff from the environment *****************************************/
532 #if defined(DISABLE_GC)
533 nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
537 /* set the bootclasspath */
539 cp = getenv("BOOTCLASSPATH");
542 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
543 strcpy(bootclasspath, cp);
546 cplen = strlen(CACAO_VM_ZIP_PATH) +
548 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
551 bootclasspath = MNEW(char, cplen);
552 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
553 strcat(bootclasspath, ":");
554 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
558 /* set the classpath */
560 cp = getenv("CLASSPATH");
563 classpath = MNEW(char, strlen(cp) + strlen("0"));
564 strcat(classpath, cp);
567 classpath = MNEW(char, strlen(".") + strlen("0"));
568 strcpy(classpath, ".");
572 /* interpret the options **************************************************/
577 heapmaxsize = HEAP_MAXSIZE;
578 heapstartsize = HEAP_STARTSIZE;
579 opt_stacksize = STACK_SIZE;
582 #if defined(ENABLE_JVMTI)
583 /* initialize JVMTI related **********************************************/
587 jdwp = jvmti = dbgprocess = false;
590 /* initialize properties before commandline handling */
592 if (!properties_init())
593 throw_cacao_exception_exit(string_java_lang_InternalError,
594 "Unable to init properties");
596 /* iterate over all passed options */
598 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
608 #if SIZEOF_VOID_P == 8
609 puts("Running a 32-bit JVM is not supported on this platform.");
615 #if SIZEOF_VOID_P == 4
616 puts("Running a 64-bit JVM is not supported on this platform.");
622 /* forget old classpath and set the argument as new classpath */
623 MFREE(classpath, char, strlen(classpath));
625 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
626 strcpy(classpath, opt_arg);
630 for (j = 0; j < strlen(opt_arg); j++) {
631 if (opt_arg[j] == '=') {
633 properties_add(opt_arg, opt_arg + j + 1);
638 /* if no '=' is given, just create an empty property */
640 properties_add(opt_arg, "");
645 case OPT_BOOTCLASSPATH:
646 /* Forget default bootclasspath and set the argument as
647 new boot classpath. */
648 MFREE(bootclasspath, char, strlen(bootclasspath));
650 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
651 strcpy(bootclasspath, opt_arg);
654 case OPT_BOOTCLASSPATH_A:
655 /* append to end of bootclasspath */
656 cplen = strlen(bootclasspath);
658 bootclasspath = MREALLOC(bootclasspath,
661 cplen + strlen(":") +
662 strlen(opt_arg) + strlen("0"));
664 strcat(bootclasspath, ":");
665 strcat(bootclasspath, opt_arg);
668 case OPT_BOOTCLASSPATH_P:
669 /* prepend in front of bootclasspath */
673 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
674 cplen + strlen("0"));
676 strcpy(bootclasspath, opt_arg);
677 strcat(bootclasspath, ":");
678 strcat(bootclasspath, cp);
680 MFREE(cp, char, cplen);
683 #if defined(ENABLE_JVMTI)
688 /* I don't know yet what Xnoagent should do. This is only for
689 compatiblity with eclipse - motse */
694 while (transport[j]!='=') j++;
696 while (j<strlen(transport)) {
697 if (strncmp("suspend=",&transport[j],8)==0) {
698 if ((j+8)>=strlen(transport) ||
699 (transport[j+8]!= 'y' && transport[j+8]!= 'n')) {
700 printf("bad Xrunjdwp option: -Xrunjdwp%s\n",transport);
705 suspend = transport[j+8] == 'y';
709 while (transport[j]!=',') j++;
726 c = opt_arg[strlen(opt_arg) - 1];
728 if ((c == 'k') || (c == 'K')) {
729 j = atoi(opt_arg) * 1024;
731 } else if ((c == 'm') || (c == 'M')) {
732 j = atoi(opt_arg) * 1024 * 1024;
739 else if (opt == OPT_MS)
751 if (strcmp("class", opt_arg) == 0)
752 opt_verboseclass = true;
754 else if (strcmp("gc", opt_arg) == 0)
755 opt_verbosegc = true;
757 else if (strcmp("jni", opt_arg) == 0)
758 opt_verbosejni = true;
760 else if (strcmp("call", opt_arg) == 0)
761 opt_verbosecall = true;
763 else if (strcmp("jit", opt_arg) == 0) {
768 compileverbose = true;
770 else if (strcmp("exception", opt_arg) == 0)
771 opt_verboseexception = true;
774 #ifdef TYPECHECK_VERBOSE
776 typecheckverbose = true;
785 case OPT_FULLVERSION:
789 case OPT_SHOWVERSION:
797 #if defined(ENABLE_VERIFIER)
808 getcompilingtime = true;
809 getloadingtime = true;
812 #if defined(ENABLE_STATISTICS)
823 for (j = 0; j < strlen(opt_arg); j++) {
824 switch (opt_arg[j]) {
839 makeinitializations = false;
848 opt_method = opt_arg;
849 makeinitializations = false;
853 opt_signature = opt_arg;
859 makeinitializations = false;
862 case OPT_SHOW: /* Display options */
863 for (j = 0; j < strlen(opt_arg); j++) {
864 switch (opt_arg[j]) {
866 opt_showdisassemble = true;
867 compileverbose = true;
870 showconstantpool = true;
873 opt_showddatasegment = true;
876 opt_showexceptionstubs = true;
879 opt_showintermediate = true;
880 compileverbose = true;
886 opt_shownativestub = true;
897 #if defined(ENABLE_LOOP)
903 #if defined(ENABLE_INLINING)
905 for (j = 0; j < strlen(opt_arg); j++) {
906 switch (opt_arg[j]) {
908 /* define in options.h; Used in main.c, jit.c
909 & inline.c inlining is currently
913 inlinevirtuals = true;
916 inlineexceptions = true;
919 inlineparamopt = true;
922 inlineoutsiders = true;
929 #endif /* defined(ENABLE_INLINING) */
931 #if defined(ENABLE_IFCONV)
937 #if defined(ENABLE_LSRA)
951 case OPT_PROF_OPTION:
952 /* use <= to get the last \0 too */
954 for (j = 0, k = 0; j <= strlen(opt_arg); j++) {
955 if (opt_arg[j] == ',')
958 if (opt_arg[j] == '\0') {
959 if (strcmp("bb", opt_arg + k) == 0)
963 printf("Unknown option: -Xprof:%s\n", opt_arg + k);
967 /* set k to next char */
979 #if defined(ENABLE_JIT)
982 printf("-Xjit option not enabled.\n");
988 #if defined(ENABLE_INTRP)
991 printf("-Xint option not enabled.\n");
996 #if defined(ENABLE_INTRP)
997 case OPT_STATIC_SUPERS:
998 opt_static_supers = atoi(opt_arg);
1001 case OPT_NO_DYNAMIC:
1002 opt_no_dynamic = true;
1005 case OPT_NO_REPLICATION:
1006 opt_no_replication = true;
1009 case OPT_NO_QUICKSUPER:
1010 opt_no_quicksuper = true;
1019 printf("Unknown option: %s\n",
1020 vm_args->options[opt_index].optionString);
1026 /* get the main class *****************************************************/
1028 if (opt_index < vm_args->nOptions) {
1029 mainstring = vm_args->options[opt_index++].optionString;
1031 /* Put the jar file into the classpath (if any). */
1033 if (opt_jar == true) {
1034 /* free old classpath */
1036 MFREE(classpath, char, strlen(classpath));
1038 /* put jarfile into classpath */
1040 classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1042 strcpy(classpath, mainstring);
1045 /* replace .'s with /'s in classname */
1047 for (i = strlen(mainstring) - 1; i >= 0; i--)
1048 if (mainstring[i] == '.')
1049 mainstring[i] = '/';
1053 #if defined(ENABLE_JVMTI)
1054 /* The fork has to occure before threads a created because threads are
1055 not forked correctly (see man pthread_atfork). Varibale dbgprocess
1056 stores information whether this is the debugger or debuggee process. */
1057 if (jvmti || jdwp) {
1058 set_jvmti_phase(JVMTI_PHASE_ONLOAD);
1059 dbgprocess = cacaodbgfork();
1062 if (dbgprocess && jvmti) { /* is this the parent/debugger process ? */
1063 agentload(agentarg);
1064 set_jvmti_phase(JVMTI_PHASE_PRIMORDIAL);
1069 /* initialize this JVM ****************************************************/
1071 vm_initializing = true;
1073 /* initialize the garbage collector */
1075 gc_init(heapmaxsize, heapstartsize);
1077 #if defined(ENABLE_INTRP)
1078 /* Allocate main thread stack on the Java heap. */
1081 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1082 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1086 #if defined(USE_THREADS)
1087 #if defined(NATIVE_THREADS)
1093 /* initialize the string hashtable stuff: lock (must be done
1094 _after_ threads_preinit) */
1097 throw_main_exception_exit();
1099 /* initialize the utf8 hashtable stuff: lock, often used utf8
1100 strings (must be done _after_ threads_preinit) */
1103 throw_main_exception_exit();
1105 /* initialize the classcache hashtable stuff: lock, hashtable
1106 (must be done _after_ threads_preinit) */
1108 if (!classcache_init())
1109 throw_main_exception_exit();
1111 /* initialize the loader with bootclasspath (must be done _after_
1115 throw_main_exception_exit();
1117 suck_add_from_property("java.endorsed.dirs");
1118 suck_add(bootclasspath);
1120 /* initialize the memory subsystem (must be done _after_
1124 throw_main_exception_exit();
1126 /* initialize the finalizer stuff (must be done _after_
1129 if (!finalizer_init())
1130 throw_main_exception_exit();
1132 /* install architecture dependent signal handler used for exceptions */
1136 /* initialize the codegen subsystems */
1140 /* initializes jit compiler */
1144 /* machine dependent initialization */
1146 #if defined(ENABLE_JIT)
1147 # if defined(ENABLE_INTRP)
1157 /* initialize the loader subsystems (must be done _after_
1160 if (!loader_init((u1 *) stackbottom))
1161 throw_main_exception_exit();
1164 throw_main_exception_exit();
1167 throw_main_exception_exit();
1169 if (!exceptions_init())
1170 throw_main_exception_exit();
1172 if (!builtin_init())
1173 throw_main_exception_exit();
1175 #if defined(USE_THREADS)
1176 if (!threads_init((u1 *) stackbottom))
1177 throw_main_exception_exit();
1180 /* That's important, otherwise we get into trouble, if the Runtime
1181 static initializer is called before (circular dependency. This
1182 is with classpath 0.09. Another important thing is, that this
1183 has to happen after initThreads!!! */
1185 if (!initialize_class(class_java_lang_System))
1186 throw_main_exception_exit();
1188 /* JNI init creates a Java object (this means running Java code) */
1191 throw_main_exception_exit();
1193 #if defined(ENABLE_PROFILING)
1194 /* initialize profiling */
1196 if (!profile_init())
1197 throw_main_exception_exit();
1200 #if defined(USE_THREADS)
1201 /* finally, start the finalizer thread */
1203 if (!finalizer_start_thread())
1204 throw_main_exception_exit();
1206 /* start the profile sampling thread */
1208 /* if (!profile_start_thread()) */
1209 /* throw_main_exception_exit(); */
1212 /* increment the number of VMs */
1216 /* initialization is done */
1218 vm_initializing = false;
1220 /* everything's ok */
1226 /* vm_destroy ******************************************************************
1228 Unloads a Java VM and reclaims its resources.
1230 *******************************************************************************/
1232 s4 vm_destroy(JavaVM *vm)
1234 #if defined(USE_THREADS)
1235 #if defined(NATIVE_THREADS)
1238 killThread(currentThread);
1242 /* everything's ok */
1248 /* vm_exit *********************************************************************
1250 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1252 *******************************************************************************/
1254 void vm_exit(s4 status)
1258 /* signal that we are exiting */
1262 assert(class_java_lang_System);
1263 assert(class_java_lang_System->state & CLASS_LOADED);
1265 #if defined(ENABLE_JVMTI)
1267 set_jvmti_phase(JVMTI_PHASE_DEAD);
1268 if (jvmti) agentunload();
1272 if (!link_class(class_java_lang_System))
1273 throw_main_exception_exit();
1275 /* call java.lang.System.exit(I)V */
1277 m = class_resolveclassmethod(class_java_lang_System,
1278 utf_new_char("exit"),
1280 class_java_lang_Object,
1284 throw_main_exception_exit();
1286 /* call the exit function with passed exit status */
1288 (void) vm_call_method(m, NULL, status);
1290 /* If we had an exception, just ignore the exception and exit with
1293 vm_shutdown(status);
1297 /* vm_shutdown *****************************************************************
1299 Terminates the system immediately without freeing memory explicitly
1300 (to be used only for abnormal termination).
1302 *******************************************************************************/
1304 void vm_shutdown(s4 status)
1306 #if defined(ENABLE_JVMTI)
1308 set_jvmti_phase(JVMTI_PHASE_DEAD);
1309 if (jvmti) agentunload();
1313 if (opt_verbose || getcompilingtime || opt_stat) {
1314 log_text("CACAO terminated by shutdown");
1315 dolog("Exit status: %d\n", (s4) status);
1322 /* vm_exit_handler *************************************************************
1324 The exit_handler function is called upon program termination.
1326 ATTENTION: Don't free system resources here! Some threads may still
1327 be running as this is called from VMRuntime.exit(). The OS does the
1330 *******************************************************************************/
1332 void vm_exit_handler(void)
1334 #if defined(ENABLE_JVMTI)
1335 if (jvmti && jdwp) set_jvmti_phase(JVMTI_PHASE_DEAD);
1336 if (jvmti) agentunload();
1340 #if !defined(NDEBUG)
1342 class_showmethods(mainclass);
1344 if (showconstantpool)
1345 class_showconstantpool(mainclass);
1350 # if defined(ENABLE_PROFILING)
1352 profile_printstats();
1356 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
1357 clear_thread_flags(); /* restores standard file descriptor
1361 #if defined(ENABLE_RT_TIMING)
1362 rt_timing_print_time_stats(stderr);
1365 #if defined(ENABLE_CYCLES_STATS)
1366 builtin_print_cycles_stats(stderr);
1367 stacktrace_print_cycles_stats(stderr);
1370 if (opt_verbose || getcompilingtime || opt_stat) {
1371 log_text("CACAO terminated");
1373 #if defined(ENABLE_STATISTICS)
1376 #ifdef TYPECHECK_STATISTICS
1377 typecheck_print_statistics(get_logfile());
1383 if (getcompilingtime)
1387 /* vm_print_profile(stderr);*/
1391 /* vm_vmargs_from_valist *******************************************************
1395 *******************************************************************************/
1397 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
1398 vm_arg *vmargs, va_list ap)
1400 typedesc *paramtypes;
1403 paramtypes = m->parseddesc->paramtypes;
1405 /* if method is non-static fill first block and skip `this' pointer */
1410 /* the `this' pointer */
1411 vmargs[0].type = TYPE_ADR;
1412 vmargs[0].data = (u8) (ptrint) o;
1418 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
1419 switch (paramtypes->decltype) {
1420 /* primitive types */
1421 case PRIMITIVETYPE_BOOLEAN:
1422 case PRIMITIVETYPE_BYTE:
1423 case PRIMITIVETYPE_CHAR:
1424 case PRIMITIVETYPE_SHORT:
1425 case PRIMITIVETYPE_INT:
1426 vmargs[i].type = TYPE_INT;
1427 vmargs[i].data = (s8) va_arg(ap, s4);
1430 case PRIMITIVETYPE_LONG:
1431 vmargs[i].type = TYPE_LNG;
1432 vmargs[i].data = (s8) va_arg(ap, s8);
1435 case PRIMITIVETYPE_FLOAT:
1436 vmargs[i].type = TYPE_FLT;
1437 #if defined(__ALPHA__)
1438 /* this keeps the assembler function much simpler */
1440 *((jdouble *) (&vmargs[i].data)) = (jdouble) va_arg(ap, jdouble);
1442 *((jfloat *) (&vmargs[i].data)) = (jfloat) va_arg(ap, jdouble);
1446 case PRIMITIVETYPE_DOUBLE:
1447 vmargs[i].type = TYPE_DBL;
1448 *((jdouble *) (&vmargs[i].data)) = (jdouble) va_arg(ap, jdouble);
1452 vmargs[i].type = TYPE_ADR;
1453 vmargs[i].data = (u8) (ptrint) va_arg(ap, void*);
1460 /* vm_vmargs_from_jvalue *******************************************************
1464 *******************************************************************************/
1466 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
1467 vm_arg *vmargs, jvalue *args)
1469 typedesc *paramtypes;
1473 paramtypes = m->parseddesc->paramtypes;
1475 /* if method is non-static fill first block and skip `this' pointer */
1480 /* the `this' pointer */
1481 vmargs[0].type = TYPE_ADR;
1482 vmargs[0].data = (u8) (ptrint) o;
1488 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
1489 switch (paramtypes->decltype) {
1490 /* primitive types */
1491 case PRIMITIVETYPE_BOOLEAN:
1492 case PRIMITIVETYPE_BYTE:
1493 case PRIMITIVETYPE_CHAR:
1494 case PRIMITIVETYPE_SHORT:
1495 case PRIMITIVETYPE_INT:
1496 vmargs[i].type = TYPE_INT;
1497 vmargs[i].data = (s8) args[j].i;
1500 case PRIMITIVETYPE_LONG:
1501 vmargs[i].type = TYPE_LNG;
1502 vmargs[i].data = (s8) args[j].j;
1505 case PRIMITIVETYPE_FLOAT:
1506 vmargs[i].type = TYPE_FLT;
1507 #if defined(__ALPHA__)
1508 /* this keeps the assembler function much simpler */
1510 *((jdouble *) (&vmargs[i].data)) = (jdouble) args[j].f;
1512 *((jfloat *) (&vmargs[i].data)) = args[j].f;
1516 case PRIMITIVETYPE_DOUBLE:
1517 vmargs[i].type = TYPE_DBL;
1518 *((jdouble *) (&vmargs[i].data)) = args[j].d;
1522 vmargs[i].type = TYPE_ADR;
1523 vmargs[i].data = (u8) (ptrint) args[j].l;
1530 /* vm_call_method **************************************************************
1532 Calls a Java method with a variable number of arguments and returns
1535 *******************************************************************************/
1537 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
1540 java_objectheader *ro;
1543 ro = vm_call_method_valist(m, o, ap);
1550 /* vm_call_method_valist *******************************************************
1552 Calls a Java method with a variable number of arguments, passed via
1553 a va_list, and returns an address.
1555 *******************************************************************************/
1557 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
1562 java_objectheader *ro;
1565 /* mark start of dump memory area */
1567 dumpsize = dump_size();
1569 /* get number of Java method arguments */
1571 vmargscount = m->parseddesc->paramcount;
1573 /* allocate vm_arg array */
1575 vmargs = DMNEW(vm_arg, vmargscount);
1577 /* fill the vm_arg array from a va_list */
1579 vm_vmargs_from_valist(m, o, vmargs, ap);
1581 /* call the Java method */
1583 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1585 /* release dump area */
1587 dump_release(dumpsize);
1593 /* vm_call_method_jvalue *******************************************************
1595 Calls a Java method with a variable number of arguments, passed via
1596 a jvalue array, and returns an address.
1598 *******************************************************************************/
1600 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
1605 java_objectheader *ro;
1608 /* mark start of dump memory area */
1610 dumpsize = dump_size();
1612 /* get number of Java method arguments */
1614 vmargscount = m->parseddesc->paramcount;
1616 /* allocate vm_arg array */
1618 vmargs = DMNEW(vm_arg, vmargscount);
1620 /* fill the vm_arg array from a va_list */
1622 vm_vmargs_from_jvalue(m, o, vmargs, args);
1624 /* call the Java method */
1626 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1628 /* release dump area */
1630 dump_release(dumpsize);
1636 /* vm_call_method_vmarg ********************************************************
1638 Calls a Java method with a variable number of arguments, passed via
1639 a vm_arg array, and returns an address.
1641 *******************************************************************************/
1643 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
1646 java_objectheader *o;
1648 #if defined(ENABLE_JIT)
1649 # if defined(ENABLE_INTRP)
1651 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1654 o = asm_vm_call_method(m, vmargscount, vmargs);
1656 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1663 /* vm_call_method_int **********************************************************
1665 Calls a Java method with a variable number of arguments and returns
1668 *******************************************************************************/
1670 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
1676 i = vm_call_method_int_valist(m, o, ap);
1683 /* vm_call_method_int_valist ***************************************************
1685 Calls a Java method with a variable number of arguments, passed via
1686 a va_list, and returns an integer (s4).
1688 *******************************************************************************/
1690 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
1697 /* mark start of dump memory area */
1699 dumpsize = dump_size();
1701 /* get number of Java method arguments */
1703 vmargscount = m->parseddesc->paramcount;
1705 /* allocate vm_arg array */
1707 vmargs = DMNEW(vm_arg, vmargscount);
1709 /* fill the vm_arg array from a va_list */
1711 vm_vmargs_from_valist(m, o, vmargs, ap);
1713 /* call the Java method */
1715 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1717 /* release dump area */
1719 dump_release(dumpsize);
1725 /* vm_call_method_int_jvalue ***************************************************
1727 Calls a Java method with a variable number of arguments, passed via
1728 a jvalue array, and returns an integer (s4).
1730 *******************************************************************************/
1732 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1739 /* mark start of dump memory area */
1741 dumpsize = dump_size();
1743 /* get number of Java method arguments */
1745 vmargscount = m->parseddesc->paramcount;
1747 /* allocate vm_arg array */
1749 vmargs = DMNEW(vm_arg, vmargscount);
1751 /* fill the vm_arg array from a va_list */
1753 vm_vmargs_from_jvalue(m, o, vmargs, args);
1755 /* call the Java method */
1757 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1759 /* release dump area */
1761 dump_release(dumpsize);
1767 /* vm_call_method_int_vmarg ****************************************************
1769 Calls a Java method with a variable number of arguments, passed via
1770 a vm_arg array, and returns an integer (s4).
1772 *******************************************************************************/
1774 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1778 #if defined(ENABLE_JIT)
1779 # if defined(ENABLE_INTRP)
1781 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1784 i = asm_vm_call_method_int(m, vmargscount, vmargs);
1786 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1793 /* vm_call_method_long *********************************************************
1795 Calls a Java method with a variable number of arguments and returns
1798 *******************************************************************************/
1800 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
1806 l = vm_call_method_long_valist(m, o, ap);
1813 /* vm_call_method_long_valist **************************************************
1815 Calls a Java method with a variable number of arguments, passed via
1816 a va_list, and returns a long (s8).
1818 *******************************************************************************/
1820 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
1827 /* mark start of dump memory area */
1829 dumpsize = dump_size();
1831 /* get number of Java method arguments */
1833 vmargscount = m->parseddesc->paramcount;
1835 /* allocate vm_arg array */
1837 vmargs = DMNEW(vm_arg, vmargscount);
1839 /* fill the vm_arg array from a va_list */
1841 vm_vmargs_from_valist(m, o, vmargs, ap);
1843 /* call the Java method */
1845 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1847 /* release dump area */
1849 dump_release(dumpsize);
1855 /* vm_call_method_long_jvalue **************************************************
1857 Calls a Java method with a variable number of arguments, passed via
1858 a jvalue array, and returns a long (s8).
1860 *******************************************************************************/
1862 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1869 /* mark start of dump memory area */
1871 dumpsize = dump_size();
1873 /* get number of Java method arguments */
1875 vmargscount = m->parseddesc->paramcount;
1877 /* allocate vm_arg array */
1879 vmargs = DMNEW(vm_arg, vmargscount);
1881 /* fill the vm_arg array from a va_list */
1883 vm_vmargs_from_jvalue(m, o, vmargs, args);
1885 /* call the Java method */
1887 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1889 /* release dump area */
1891 dump_release(dumpsize);
1897 /* vm_call_method_long_vmarg ***************************************************
1899 Calls a Java method with a variable number of arguments, passed via
1900 a vm_arg array, and returns a long (s8).
1902 *******************************************************************************/
1904 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1908 #if defined(ENABLE_JIT)
1909 # if defined(ENABLE_INTRP)
1911 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1914 l = asm_vm_call_method_long(m, vmargscount, vmargs);
1916 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1923 /* vm_call_method_float ********************************************************
1925 Calls a Java method with a variable number of arguments and returns
1928 *******************************************************************************/
1930 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
1936 f = vm_call_method_float_valist(m, o, ap);
1943 /* vm_call_method_float_valist *************************************************
1945 Calls a Java method with a variable number of arguments, passed via
1946 a va_list, and returns a float.
1948 *******************************************************************************/
1950 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
1958 /* mark start of dump memory area */
1960 dumpsize = dump_size();
1962 /* get number of Java method arguments */
1964 vmargscount = m->parseddesc->paramcount;
1966 /* allocate vm_arg array */
1968 vmargs = DMNEW(vm_arg, vmargscount);
1970 /* fill the vm_arg array from a va_list */
1972 vm_vmargs_from_valist(m, o, vmargs, ap);
1974 /* call the Java method */
1976 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
1978 /* release dump area */
1980 dump_release(dumpsize);
1986 /* vm_call_method_float_jvalue *************************************************
1988 Calls a Java method with a variable number of arguments, passed via
1989 a jvalue array, and returns a float.
1991 *******************************************************************************/
1993 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2001 /* mark start of dump memory area */
2003 dumpsize = dump_size();
2005 /* get number of Java method arguments */
2007 vmargscount = m->parseddesc->paramcount;
2009 /* allocate vm_arg array */
2011 vmargs = DMNEW(vm_arg, vmargscount);
2013 /* fill the vm_arg array from a va_list */
2015 vm_vmargs_from_jvalue(m, o, vmargs, args);
2017 /* call the Java method */
2019 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2021 /* release dump area */
2023 dump_release(dumpsize);
2029 /* vm_call_method_float_vmarg **************************************************
2031 Calls a Java method with a variable number of arguments and returns
2034 *******************************************************************************/
2036 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2040 #if defined(ENABLE_JIT)
2041 # if defined(ENABLE_INTRP)
2043 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2046 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2048 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2055 /* vm_call_method_double *******************************************************
2057 Calls a Java method with a variable number of arguments and returns
2060 *******************************************************************************/
2062 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2068 d = vm_call_method_double_valist(m, o, ap);
2075 /* vm_call_method_double_valist ************************************************
2077 Calls a Java method with a variable number of arguments, passed via
2078 a va_list, and returns a double.
2080 *******************************************************************************/
2082 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2090 /* mark start of dump memory area */
2092 dumpsize = dump_size();
2094 /* get number of Java method arguments */
2096 vmargscount = m->parseddesc->paramcount;
2098 /* allocate vm_arg array */
2100 vmargs = DMNEW(vm_arg, vmargscount);
2102 /* fill the vm_arg array from a va_list */
2104 vm_vmargs_from_valist(m, o, vmargs, ap);
2106 /* call the Java method */
2108 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2110 /* release dump area */
2112 dump_release(dumpsize);
2118 /* vm_call_method_double_jvalue ************************************************
2120 Calls a Java method with a variable number of arguments, passed via
2121 a jvalue array, and returns a double.
2123 *******************************************************************************/
2125 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2133 /* mark start of dump memory area */
2135 dumpsize = dump_size();
2137 /* get number of Java method arguments */
2139 vmargscount = m->parseddesc->paramcount;
2141 /* allocate vm_arg array */
2143 vmargs = DMNEW(vm_arg, vmargscount);
2145 /* fill the vm_arg array from a va_list */
2147 vm_vmargs_from_jvalue(m, o, vmargs, args);
2149 /* call the Java method */
2151 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2153 /* release dump area */
2155 dump_release(dumpsize);
2161 /* vm_call_method_double_vmarg *************************************************
2163 Calls a Java method with a variable number of arguments and returns
2166 *******************************************************************************/
2168 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
2173 #if defined(ENABLE_JIT)
2174 # if defined(ENABLE_INTRP)
2176 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2179 d = asm_vm_call_method_double(m, vmargscount, vmargs);
2181 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2189 * These are local overrides for various environment variables in Emacs.
2190 * Please do not remove this and leave it at the end of the file, where
2191 * Emacs will automagically detect them.
2192 * ---------------------------------------------------------------------
2195 * indent-tabs-mode: t