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
29 Changes: Martin Platter
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(ENABLE_THREADS)
49 # include "threads/native/threads.h"
52 #include "vm/classcache.h"
53 #include "vm/exceptions.h"
54 #include "vm/finalizer.h"
55 #include "vm/global.h"
56 #include "vm/initialize.h"
57 #include "vm/options.h"
58 #include "vm/properties.h"
59 #include "vm/signallocal.h"
60 #include "vm/stringlocal.h"
63 #include "vm/jit/jit.h"
64 #include "vm/jit/asmpart.h"
65 #include "vm/jit/profile/profile.h"
66 #include "vm/rt-timing.h"
68 #if defined(ENABLE_JVMTI)
69 #include "native/jvmti/cacaodbg.h"
72 /* Invocation API variables ***************************************************/
74 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
75 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
78 /* global variables ***********************************************************/
80 s4 vms = 0; /* number of VMs created */
82 bool vm_initializing = false;
83 bool vm_exiting = false;
85 #if defined(ENABLE_INTRP)
86 u1 *intrp_main_stack = NULL;
89 char *mainstring = NULL;
90 classinfo *mainclass = NULL;
92 char *specificmethodname = NULL;
93 char *specificsignature = NULL;
98 /* define heap sizes **********************************************************/
100 #define HEAP_MAXSIZE 64 * 1024 * 1024 /* default 64MB */
101 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
102 #define STACK_SIZE 128 * 1024 /* default 128kB */
105 /* define command line options ************************************************/
127 /* Java non-standard options */
148 #if defined(ENABLE_STATISTICS)
161 #if defined(ENABLE_VERIFIER)
163 #if defined(TYPECHECK_VERBOSE)
166 #endif /* defined(ENABLE_VERIFIER) */
169 /* optimization options */
171 #if defined(ENABLE_LOOP)
175 #if defined(ENABLE_IFCONV)
179 #if defined(ENABLE_LSRA)
183 #if defined(ENABLE_INLINING)
187 #if defined(ENABLE_INTRP)
188 /* interpreter options */
211 opt_struct opts[] = {
214 { "jar", false, OPT_JAR },
216 { "d32", false, OPT_D32 },
217 { "d64", false, OPT_D64 },
218 { "client", false, OPT_IGNORE },
219 { "server", false, OPT_IGNORE },
220 { "hotspot", false, OPT_IGNORE },
222 { "classpath", true, OPT_CLASSPATH },
223 { "cp", true, OPT_CLASSPATH },
224 { "D", true, OPT_D },
225 { "version", false, OPT_VERSION },
226 { "showversion", false, OPT_SHOWVERSION },
227 { "fullversion", false, OPT_FULLVERSION },
228 { "help", false, OPT_HELP },
229 { "?", false, OPT_HELP },
230 { "X", false, OPT_X },
232 { "noasyncgc", false, OPT_IGNORE },
233 #if defined(ENABLE_VERIFIER)
234 { "noverify", false, OPT_NOVERIFY },
236 { "v", false, OPT_VERBOSE1 },
237 { "verbose:", true, OPT_VERBOSE },
239 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
240 { "verbosetc", false, OPT_VERBOSETC },
242 #if defined(__ALPHA__)
243 { "noieee", false, OPT_NOIEEE },
245 { "softnull", false, OPT_SOFTNULL },
246 #if defined(ENABLE_STATISTICS)
247 { "time", false, OPT_TIME },
248 { "stat", false, OPT_STAT },
250 { "log", true, OPT_LOG },
251 { "c", true, OPT_CHECK },
252 { "l", false, OPT_LOAD },
253 { "eager", false, OPT_EAGER },
254 { "sig", true, OPT_SIGNATURE },
255 { "all", false, OPT_ALL },
256 #if defined(ENABLE_LOOP)
257 { "oloop", false, OPT_OLOOP },
259 #if defined(ENABLE_IFCONV)
260 { "ifconv", false, OPT_IFCONV },
262 #if defined(ENABLE_LSRA)
263 { "lsra", false, OPT_LSRA },
266 #if defined(ENABLE_INTRP)
267 /* interpreter options */
269 { "trace", false, OPT_TRACE },
270 { "static-supers", true, OPT_STATIC_SUPERS },
271 { "no-dynamic", false, OPT_NO_DYNAMIC },
272 { "no-replication", false, OPT_NO_REPLICATION },
273 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
276 /* JVMTI Agent Command Line Options */
278 { "agentlib:", true, OPT_AGENTLIB },
279 { "agentpath:", true, OPT_AGENTPATH },
282 /* Java non-standard options */
284 { "Xjit", false, OPT_JIT },
285 { "Xint", false, OPT_INTRP },
286 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
287 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
288 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
290 { "Xdebug", false, OPT_DEBUG },
291 { "Xnoagent", false, OPT_NOAGENT },
292 { "Xrunjdwp", true, OPT_XRUNJDWP },
294 { "Xms", true, OPT_MS },
295 { "ms", true, OPT_MS },
296 { "Xmx", true, OPT_MX },
297 { "mx", true, OPT_MX },
298 { "Xss", true, OPT_SS },
299 { "ss", true, OPT_SS },
300 { "Xprof:", true, OPT_PROF_OPTION },
301 { "Xprof", false, OPT_PROF },
303 /* keep these at the end of the list */
305 #if defined(ENABLE_INLINING)
306 { "i", true, OPT_INLINING },
308 { "m", true, OPT_METHOD },
309 { "s", true, OPT_SHOW },
315 /* usage ***********************************************************************
317 Prints the correct usage syntax to stdout.
319 *******************************************************************************/
323 puts("Usage: cacao [-options] classname [arguments]");
324 puts(" (to run a class file)");
325 puts(" or cacao [-options] -jar jarfile [arguments]");
326 puts(" (to run a standalone jar file)\n");
328 puts("Java options:");
329 puts(" -d32 use 32-bit data model if available");
330 puts(" -d64 use 64-bit data model if available");
331 puts(" -client compatibility (currently ignored)");
332 puts(" -server compatibility (currently ignored)");
333 puts(" -hotspot compatibility (currently ignored)\n");
335 puts(" -cp <path> specify a path to look for classes");
336 puts(" -classpath <path> specify a path to look for classes");
337 puts(" -D<name>=<value> add an entry to the property list");
338 puts(" -verbose[:class|gc|jni] enable specific verbose output");
339 puts(" -version print product version and exit");
340 puts(" -fullversion print jpackage-compatible product version and exit");
341 puts(" -showversion print product version and continue");
342 puts(" -help, -? print this help message");
343 puts(" -X print help on non-standard Java options\n");
346 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
347 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
350 puts("CACAO options:\n");
351 puts(" -v write state-information");
352 puts(" -verbose[:call|exception]enable specific verbose output");
353 #ifdef TYPECHECK_VERBOSE
354 puts(" -verbosetc write debug messages while typechecking");
356 #if defined(__ALPHA__)
357 puts(" -noieee don't use ieee compliant arithmetic");
359 #if defined(ENABLE_VERIFIER)
360 puts(" -noverify don't verify classfiles");
362 puts(" -softnull use software nullpointer check");
363 #if defined(ENABLE_STATISTICS)
364 puts(" -time measure the runtime");
365 puts(" -stat detailed compiler statistics");
367 puts(" -log logfile specify a name for the logfile");
368 puts(" -c(heck)b(ounds) don't check array bounds");
369 puts(" s(ync) don't check for synchronization");
370 #if defined(ENABLE_LOOP)
371 puts(" -oloop optimize array accesses in loops");
373 puts(" -l don't start the class after loading");
374 puts(" -eager perform eager class loading and linking");
375 puts(" -all compile all methods, no execution");
376 puts(" -m compile only a specific method");
377 puts(" -sig specify signature for a specific method");
378 puts(" -s(how)a(ssembler) show disassembled listing");
379 puts(" c(onstants) show the constant pool");
380 puts(" d(atasegment) show data segment listing");
381 puts(" e(xceptionstubs) show disassembled exception stubs (only with -sa)");
382 puts(" i(ntermediate) show intermediate representation");
383 puts(" m(ethods) show class fields and methods");
384 puts(" n(ative) show disassembled native stubs");
385 puts(" u(tf) show the utf - hash");
386 #if defined(ENABLE_INLINING)
387 puts(" -i n(line) activate inlining");
388 puts(" v(irtual) inline virtual methods (uses/turns rt option on)");
389 puts(" e(exception) inline methods with exceptions");
390 puts(" p(aramopt) optimize argument renaming");
391 puts(" o(utsiders) inline methods of foreign classes");
392 #endif /* defined(ENABLE_INLINING) */
393 #if defined(ENABLE_IFCONV)
394 puts(" -ifconv use if-conversion");
396 #if defined(ENABLE_LSRA)
397 puts(" -lsra use linear scan register allocation");
400 /* exit with error code */
406 static void Xusage(void)
408 #if defined(ENABLE_JIT)
409 puts(" -Xjit JIT mode execution (default)");
411 #if defined(ENABLE_INTRP)
412 puts(" -Xint interpreter mode execution");
414 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
415 puts(" value is set as bootstrap class path");
416 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
417 puts(" value is appended to the bootstrap class path");
418 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
419 puts(" value is prepended to the bootstrap class path");
420 puts(" -Xms<size> set the initial size of the heap (default: 2MB)");
421 puts(" -Xmx<size> set the maximum size of the heap (default: 64MB)");
422 puts(" -Xss<size> set the thread stack size (default: 128kB)");
423 puts(" -Xprof[:bb] collect and print profiling data");
424 #if defined(ENABLE_JVMTI)
425 /* -Xdebug option depend on gnu classpath JDWP options. options:
426 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
427 puts(" -Xdebug enable remote debugging\n");
428 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
429 puts(" enable remote debugging\n");
432 /* exit with error code */
438 /* version *********************************************************************
440 Only prints cacao version information.
442 *******************************************************************************/
444 static void version(void)
446 puts("java version \""JAVA_VERSION"\"");
447 puts("CACAO version "VERSION"");
449 puts("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,");
450 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
451 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
452 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
454 puts("This program is free software; you can redistribute it and/or");
455 puts("modify it under the terms of the GNU General Public License as");
456 puts("published by the Free Software Foundation; either version 2, or (at");
457 puts("your option) any later version.\n");
459 puts("This program is distributed in the hope that it will be useful, but");
460 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
461 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
462 puts("General Public License for more details.\n");
464 puts("Configure/Build options:\n");
465 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
466 #if defined(__VERSION__)
467 puts(" CC : "VERSION_CC" ("__VERSION__")");
469 puts(" CC : "VERSION_CC"");
471 puts(" CFLAGS : "VERSION_CFLAGS"\n");
473 puts("Default variables:\n");
474 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
475 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
476 printf(" stack size : %d\n", STACK_SIZE);
477 puts(" java.boot.class.path: "CACAO_VM_ZIP_PATH":"CLASSPATH_GLIBJ_ZIP_PATH"");
478 puts(" java.library.path : "CLASSPATH_LIBRARY_PATH"\n");
480 puts("Runtime variables:\n");
481 printf(" maximum heap size : %d\n", opt_heapmaxsize);
482 printf(" initial heap size : %d\n", opt_heapstartsize);
483 printf(" stack size : %d\n", opt_stacksize);
484 printf(" java.boot.class.path: %s\n", bootclasspath);
488 /* fullversion *****************************************************************
490 Prints a Sun compatible version information (required e.g. by
491 jpackage, www.jpackage.org).
493 *******************************************************************************/
495 static void fullversion(void)
497 puts("java full version \"cacao-"JAVA_VERSION"\"");
505 /* vm_create *******************************************************************
507 Creates a JVM. Called by JNI_CreateJavaVM.
509 *******************************************************************************/
511 bool vm_create(JavaVMInitArgs *vm_args)
519 #if defined(ENABLE_JVMTI)
522 bool agentbypath = false;;
527 /* check the JNI version requested */
529 switch (vm_args->version) {
530 case JNI_VERSION_1_1:
532 case JNI_VERSION_1_2:
533 case JNI_VERSION_1_4:
539 /* we only support 1 JVM instance */
545 /* get stuff from the environment *****************************************/
547 #if defined(DISABLE_GC)
548 nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
552 /* set the bootclasspath */
554 cp = getenv("BOOTCLASSPATH");
557 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
558 strcpy(bootclasspath, cp);
561 cplen = strlen(CACAO_VM_ZIP_PATH) +
563 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
566 bootclasspath = MNEW(char, cplen);
567 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
568 strcat(bootclasspath, ":");
569 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
573 /* set the classpath */
575 cp = getenv("CLASSPATH");
578 classpath = MNEW(char, strlen(cp) + strlen("0"));
579 strcat(classpath, cp);
582 classpath = MNEW(char, strlen(".") + strlen("0"));
583 strcpy(classpath, ".");
587 /* interpret the options **************************************************/
592 opt_heapmaxsize = HEAP_MAXSIZE;
593 opt_heapstartsize = HEAP_STARTSIZE;
594 opt_stacksize = STACK_SIZE;
597 #if defined(ENABLE_JVMTI)
598 /* initialize JVMTI related **********************************************/
599 jdwp = jvmti = false;
602 /* initialize properties before commandline handling */
604 if (!properties_init())
605 throw_cacao_exception_exit(string_java_lang_InternalError,
606 "Unable to init properties");
608 /* add some default properties */
610 properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
613 /* iterate over all passed options */
615 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
625 #if SIZEOF_VOID_P == 8
626 puts("Running a 32-bit JVM is not supported on this platform.");
632 #if SIZEOF_VOID_P == 4
633 puts("Running a 64-bit JVM is not supported on this platform.");
639 /* forget old classpath and set the argument as new classpath */
640 MFREE(classpath, char, strlen(classpath));
642 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
643 strcpy(classpath, opt_arg);
647 for (j = 0; j < strlen(opt_arg); j++) {
648 if (opt_arg[j] == '=') {
650 properties_add(opt_arg, opt_arg + j + 1);
655 /* if no '=' is given, just create an empty property */
657 properties_add(opt_arg, "");
662 case OPT_BOOTCLASSPATH:
663 /* Forget default bootclasspath and set the argument as
664 new boot classpath. */
665 MFREE(bootclasspath, char, strlen(bootclasspath));
667 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
668 strcpy(bootclasspath, opt_arg);
671 case OPT_BOOTCLASSPATH_A:
672 /* append to end of bootclasspath */
673 cplen = strlen(bootclasspath);
675 bootclasspath = MREALLOC(bootclasspath,
678 cplen + strlen(":") +
679 strlen(opt_arg) + strlen("0"));
681 strcat(bootclasspath, ":");
682 strcat(bootclasspath, opt_arg);
685 case OPT_BOOTCLASSPATH_P:
686 /* prepend in front of bootclasspath */
690 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
691 cplen + strlen("0"));
693 strcpy(bootclasspath, opt_arg);
694 strcat(bootclasspath, ":");
695 strcat(bootclasspath, cp);
697 MFREE(cp, char, cplen);
700 #if defined(ENABLE_JVMTI)
705 /* I don't know yet what Xnoagent should do. This is only for
706 compatiblity with eclipse - motse */
711 while (transport[j]!='=') j++;
713 while (j<strlen(transport)) {
714 if (strncmp("suspend=",&transport[j],8)==0) {
715 if ((j+8)>=strlen(transport) ||
716 (transport[j+8]!= 'y' && transport[j+8]!= 'n')) {
717 printf("bad Xrunjdwp option: -Xrunjdwp%s\n",transport);
722 suspend = transport[j+8] == 'y';
726 while (transport[j]!=',') j++;
745 c = opt_arg[strlen(opt_arg) - 1];
747 if ((c == 'k') || (c == 'K')) {
748 j = atoi(opt_arg) * 1024;
750 } else if ((c == 'm') || (c == 'M')) {
751 j = atoi(opt_arg) * 1024 * 1024;
758 else if (opt == OPT_MS)
759 opt_heapstartsize = j;
770 if (strcmp("class", opt_arg) == 0)
771 opt_verboseclass = true;
773 else if (strcmp("gc", opt_arg) == 0)
774 opt_verbosegc = true;
776 else if (strcmp("jni", opt_arg) == 0)
777 opt_verbosejni = true;
779 else if (strcmp("call", opt_arg) == 0)
780 opt_verbosecall = true;
782 else if (strcmp("jit", opt_arg) == 0) {
787 compileverbose = true;
789 else if (strcmp("exception", opt_arg) == 0)
790 opt_verboseexception = true;
793 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
795 opt_typecheckverbose = true;
804 case OPT_FULLVERSION:
808 case OPT_SHOWVERSION:
816 #if defined(ENABLE_VERIFIER)
826 #if defined(ENABLE_STATISTICS)
828 opt_getcompilingtime = true;
829 opt_getloadingtime = true;
842 for (j = 0; j < strlen(opt_arg); j++) {
843 switch (opt_arg[j]) {
858 makeinitializations = false;
867 opt_method = opt_arg;
868 makeinitializations = false;
872 opt_signature = opt_arg;
878 makeinitializations = false;
881 case OPT_SHOW: /* Display options */
882 for (j = 0; j < strlen(opt_arg); j++) {
883 switch (opt_arg[j]) {
885 opt_showdisassemble = true;
886 compileverbose = true;
889 showconstantpool = true;
892 opt_showddatasegment = true;
895 opt_showexceptionstubs = true;
898 opt_showintermediate = true;
899 compileverbose = true;
905 opt_shownativestub = true;
916 #if defined(ENABLE_LOOP)
922 #if defined(ENABLE_INLINING)
924 for (j = 0; j < strlen(opt_arg); j++) {
925 switch (opt_arg[j]) {
927 /* define in options.h; Used in main.c, jit.c
928 & inline.c inlining is currently
932 inlinevirtuals = true;
935 inlineexceptions = true;
938 inlineparamopt = true;
941 inlineoutsiders = true;
948 #endif /* defined(ENABLE_INLINING) */
950 #if defined(ENABLE_IFCONV)
956 #if defined(ENABLE_LSRA)
970 case OPT_PROF_OPTION:
971 /* use <= to get the last \0 too */
973 for (j = 0, k = 0; j <= strlen(opt_arg); j++) {
974 if (opt_arg[j] == ',')
977 if (opt_arg[j] == '\0') {
978 if (strcmp("bb", opt_arg + k) == 0)
982 printf("Unknown option: -Xprof:%s\n", opt_arg + k);
986 /* set k to next char */
998 #if defined(ENABLE_JIT)
1001 printf("-Xjit option not enabled.\n");
1007 #if defined(ENABLE_INTRP)
1010 printf("-Xint option not enabled.\n");
1015 #if defined(ENABLE_INTRP)
1016 case OPT_STATIC_SUPERS:
1017 opt_static_supers = atoi(opt_arg);
1020 case OPT_NO_DYNAMIC:
1021 opt_no_dynamic = true;
1024 case OPT_NO_REPLICATION:
1025 opt_no_replication = true;
1028 case OPT_NO_QUICKSUPER:
1029 opt_no_quicksuper = true;
1038 printf("Unknown option: %s\n",
1039 vm_args->options[opt_index].optionString);
1045 /* get the main class *****************************************************/
1047 if (opt_index < vm_args->nOptions) {
1048 mainstring = vm_args->options[opt_index++].optionString;
1050 /* Put the jar file into the classpath (if any). */
1052 if (opt_jar == true) {
1053 /* free old classpath */
1055 MFREE(classpath, char, strlen(classpath));
1057 /* put jarfile into classpath */
1059 classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1061 strcpy(classpath, mainstring);
1064 /* replace .'s with /'s in classname */
1066 for (i = strlen(mainstring) - 1; i >= 0; i--)
1067 if (mainstring[i] == '.')
1068 mainstring[i] = '/';
1072 #if defined(ENABLE_JVMTI)
1074 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1075 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1077 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1081 /* initialize this JVM ****************************************************/
1083 vm_initializing = true;
1085 /* initialize the garbage collector */
1087 gc_init(opt_heapmaxsize, opt_heapstartsize);
1089 #if defined(ENABLE_INTRP)
1090 /* Allocate main thread stack on the Java heap. */
1093 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1094 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1098 #if defined(ENABLE_THREADS)
1102 /* initialize the string hashtable stuff: lock (must be done
1103 _after_ threads_preinit) */
1106 throw_main_exception_exit();
1108 /* initialize the utf8 hashtable stuff: lock, often used utf8
1109 strings (must be done _after_ threads_preinit) */
1112 throw_main_exception_exit();
1114 /* initialize the classcache hashtable stuff: lock, hashtable
1115 (must be done _after_ threads_preinit) */
1117 if (!classcache_init())
1118 throw_main_exception_exit();
1120 /* initialize the loader with bootclasspath (must be done _after_
1124 throw_main_exception_exit();
1126 suck_add_from_property("java.endorsed.dirs");
1127 suck_add(bootclasspath);
1129 /* initialize the memory subsystem (must be done _after_
1133 throw_main_exception_exit();
1135 /* initialize the finalizer stuff (must be done _after_
1138 if (!finalizer_init())
1139 throw_main_exception_exit();
1141 /* install architecture dependent signal handler used for exceptions */
1145 /* initialize the codegen subsystems */
1149 /* initializes jit compiler */
1153 /* machine dependent initialization */
1155 #if defined(ENABLE_JIT)
1156 # if defined(ENABLE_INTRP)
1166 /* initialize the loader subsystems (must be done _after_
1170 throw_main_exception_exit();
1173 throw_main_exception_exit();
1176 throw_main_exception_exit();
1178 if (!exceptions_init())
1179 throw_main_exception_exit();
1181 if (!builtin_init())
1182 throw_main_exception_exit();
1184 /* Initialize the JNI subsystem (must be done _before_
1185 threads_init, as threads_init can call JNI methods
1186 (e.g. NewGlobalRef). */
1189 throw_main_exception_exit();
1191 #if defined(ENABLE_THREADS)
1192 if (!threads_init())
1193 throw_main_exception_exit();
1196 /* That's important, otherwise we get into trouble, if the Runtime
1197 static initializer is called before (circular dependency. This
1198 is with classpath 0.09. Another important thing is, that this
1199 has to happen after initThreads!!! */
1201 if (!initialize_class(class_java_lang_System))
1202 throw_main_exception_exit();
1204 #if defined(ENABLE_PROFILING)
1205 /* initialize profiling */
1207 if (!profile_init())
1208 throw_main_exception_exit();
1211 #if defined(ENABLE_THREADS)
1212 /* finally, start the finalizer thread */
1214 if (!finalizer_start_thread())
1215 throw_main_exception_exit();
1217 /* start the profile sampling thread */
1219 /* if (!profile_start_thread()) */
1220 /* throw_main_exception_exit(); */
1223 #if defined(ENABLE_JVMTI)
1225 /* add agent library to native library hashtable */
1226 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1230 /* increment the number of VMs */
1234 /* initialization is done */
1236 vm_initializing = false;
1238 /* everything's ok */
1244 /* vm_destroy ******************************************************************
1246 Unloads a Java VM and reclaims its resources.
1248 *******************************************************************************/
1250 s4 vm_destroy(JavaVM *vm)
1252 #if defined(ENABLE_THREADS)
1253 threads_join_all_threads();
1256 /* everything's ok */
1262 /* vm_exit *********************************************************************
1264 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1266 *******************************************************************************/
1268 void vm_exit(s4 status)
1272 /* signal that we are exiting */
1276 assert(class_java_lang_System);
1277 assert(class_java_lang_System->state & CLASS_LOADED);
1279 #if defined(ENABLE_JVMTI)
1280 jvmti_set_phase(JVMTI_PHASE_DEAD);
1281 if (jvmti) jvmti_agentunload();
1284 if (!link_class(class_java_lang_System))
1285 throw_main_exception_exit();
1287 /* call java.lang.System.exit(I)V */
1289 m = class_resolveclassmethod(class_java_lang_System,
1290 utf_new_char("exit"),
1292 class_java_lang_Object,
1296 throw_main_exception_exit();
1298 /* call the exit function with passed exit status */
1300 (void) vm_call_method(m, NULL, status);
1302 /* If we had an exception, just ignore the exception and exit with
1305 vm_shutdown(status);
1309 /* vm_shutdown *****************************************************************
1311 Terminates the system immediately without freeing memory explicitly
1312 (to be used only for abnormal termination).
1314 *******************************************************************************/
1316 void vm_shutdown(s4 status)
1319 #if defined(ENABLE_STATISTICS)
1320 || opt_getcompilingtime || opt_stat
1324 log_text("CACAO terminated by shutdown");
1325 dolog("Exit status: %d\n", (s4) status);
1332 /* vm_exit_handler *************************************************************
1334 The exit_handler function is called upon program termination.
1336 ATTENTION: Don't free system resources here! Some threads may still
1337 be running as this is called from VMRuntime.exit(). The OS does the
1340 *******************************************************************************/
1342 void vm_exit_handler(void)
1344 #if !defined(NDEBUG)
1346 class_showmethods(mainclass);
1348 if (showconstantpool)
1349 class_showconstantpool(mainclass);
1354 # if defined(ENABLE_PROFILING)
1356 profile_printstats();
1358 #endif /* !defined(NDEBUG) */
1360 #if defined(ENABLE_RT_TIMING)
1361 rt_timing_print_time_stats(stderr);
1364 #if defined(ENABLE_CYCLES_STATS)
1365 builtin_print_cycles_stats(stderr);
1366 stacktrace_print_cycles_stats(stderr);
1370 #if defined(ENABLE_STATISTICS)
1371 || opt_getcompilingtime || opt_stat
1375 log_text("CACAO terminated");
1377 #if defined(ENABLE_STATISTICS)
1380 #ifdef TYPECHECK_STATISTICS
1381 typecheck_print_statistics(get_logfile());
1387 if (opt_getcompilingtime)
1389 #endif /* defined(ENABLE_STATISTICS) */
1391 /* vm_print_profile(stderr);*/
1395 /* vm_abort ********************************************************************
1397 Prints an error message and aborts the VM.
1399 *******************************************************************************/
1401 void vm_abort(const char *text, ...)
1405 /* print the log message */
1410 log_vprint(text, ap);
1415 /* now abort the VM */
1421 /* vm_vmargs_from_valist *******************************************************
1425 *******************************************************************************/
1427 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
1428 vm_arg *vmargs, va_list ap)
1430 typedesc *paramtypes;
1433 paramtypes = m->parseddesc->paramtypes;
1435 /* if method is non-static fill first block and skip `this' pointer */
1440 /* the `this' pointer */
1441 vmargs[0].type = TYPE_ADR;
1442 vmargs[0].data.l = (u8) (ptrint) o;
1448 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
1449 switch (paramtypes->decltype) {
1450 /* primitive types */
1451 case PRIMITIVETYPE_BOOLEAN:
1452 case PRIMITIVETYPE_BYTE:
1453 case PRIMITIVETYPE_CHAR:
1454 case PRIMITIVETYPE_SHORT:
1455 case PRIMITIVETYPE_INT:
1456 vmargs[i].type = TYPE_INT;
1457 vmargs[i].data.l = (s8) va_arg(ap, s4);
1460 case PRIMITIVETYPE_LONG:
1461 vmargs[i].type = TYPE_LNG;
1462 vmargs[i].data.l = (s8) va_arg(ap, s8);
1465 case PRIMITIVETYPE_FLOAT:
1466 vmargs[i].type = TYPE_FLT;
1467 #if defined(__ALPHA__)
1468 /* this keeps the assembler function much simpler */
1470 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
1472 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
1476 case PRIMITIVETYPE_DOUBLE:
1477 vmargs[i].type = TYPE_DBL;
1478 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
1482 vmargs[i].type = TYPE_ADR;
1483 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
1490 /* vm_vmargs_from_jvalue *******************************************************
1494 *******************************************************************************/
1496 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
1497 vm_arg *vmargs, jvalue *args)
1499 typedesc *paramtypes;
1503 paramtypes = m->parseddesc->paramtypes;
1505 /* if method is non-static fill first block and skip `this' pointer */
1510 /* the `this' pointer */
1511 vmargs[0].type = TYPE_ADR;
1512 vmargs[0].data.l = (u8) (ptrint) o;
1518 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
1519 switch (paramtypes->decltype) {
1520 /* primitive types */
1521 case PRIMITIVETYPE_BOOLEAN:
1522 case PRIMITIVETYPE_BYTE:
1523 case PRIMITIVETYPE_CHAR:
1524 case PRIMITIVETYPE_SHORT:
1525 case PRIMITIVETYPE_INT:
1526 vmargs[i].type = TYPE_INT;
1527 vmargs[i].data.l = (s8) args[j].i;
1530 case PRIMITIVETYPE_LONG:
1531 vmargs[i].type = TYPE_LNG;
1532 vmargs[i].data.l = (s8) args[j].j;
1535 case PRIMITIVETYPE_FLOAT:
1536 vmargs[i].type = TYPE_FLT;
1537 #if defined(__ALPHA__)
1538 /* this keeps the assembler function much simpler */
1540 vmargs[i].data.d = (jdouble) args[j].f;
1542 vmargs[i].data.f = args[j].f;
1546 case PRIMITIVETYPE_DOUBLE:
1547 vmargs[i].type = TYPE_DBL;
1548 vmargs[i].data.d = args[j].d;
1552 vmargs[i].type = TYPE_ADR;
1553 vmargs[i].data.l = (u8) (ptrint) args[j].l;
1560 /* vm_call_method **************************************************************
1562 Calls a Java method with a variable number of arguments and returns
1565 *******************************************************************************/
1567 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
1570 java_objectheader *ro;
1573 ro = vm_call_method_valist(m, o, ap);
1580 /* vm_call_method_valist *******************************************************
1582 Calls a Java method with a variable number of arguments, passed via
1583 a va_list, and returns an address.
1585 *******************************************************************************/
1587 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
1592 java_objectheader *ro;
1595 /* mark start of dump memory area */
1597 dumpsize = dump_size();
1599 /* get number of Java method arguments */
1601 vmargscount = m->parseddesc->paramcount;
1603 /* allocate vm_arg array */
1605 vmargs = DMNEW(vm_arg, vmargscount);
1607 /* fill the vm_arg array from a va_list */
1609 vm_vmargs_from_valist(m, o, vmargs, ap);
1611 /* call the Java method */
1613 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1615 /* release dump area */
1617 dump_release(dumpsize);
1623 /* vm_call_method_jvalue *******************************************************
1625 Calls a Java method with a variable number of arguments, passed via
1626 a jvalue array, and returns an address.
1628 *******************************************************************************/
1630 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
1635 java_objectheader *ro;
1638 /* mark start of dump memory area */
1640 dumpsize = dump_size();
1642 /* get number of Java method arguments */
1644 vmargscount = m->parseddesc->paramcount;
1646 /* allocate vm_arg array */
1648 vmargs = DMNEW(vm_arg, vmargscount);
1650 /* fill the vm_arg array from a va_list */
1652 vm_vmargs_from_jvalue(m, o, vmargs, args);
1654 /* call the Java method */
1656 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1658 /* release dump area */
1660 dump_release(dumpsize);
1666 /* vm_call_method_vmarg ********************************************************
1668 Calls a Java method with a variable number of arguments, passed via
1669 a vm_arg array, and returns an address.
1671 *******************************************************************************/
1673 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
1676 java_objectheader *o;
1678 #if defined(ENABLE_JIT)
1679 # if defined(ENABLE_INTRP)
1681 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1684 o = asm_vm_call_method(m, vmargscount, vmargs);
1686 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1693 /* vm_call_method_int **********************************************************
1695 Calls a Java method with a variable number of arguments and returns
1698 *******************************************************************************/
1700 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
1706 i = vm_call_method_int_valist(m, o, ap);
1713 /* vm_call_method_int_valist ***************************************************
1715 Calls a Java method with a variable number of arguments, passed via
1716 a va_list, and returns an integer (s4).
1718 *******************************************************************************/
1720 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
1727 /* mark start of dump memory area */
1729 dumpsize = dump_size();
1731 /* get number of Java method arguments */
1733 vmargscount = m->parseddesc->paramcount;
1735 /* allocate vm_arg array */
1737 vmargs = DMNEW(vm_arg, vmargscount);
1739 /* fill the vm_arg array from a va_list */
1741 vm_vmargs_from_valist(m, o, vmargs, ap);
1743 /* call the Java method */
1745 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1747 /* release dump area */
1749 dump_release(dumpsize);
1755 /* vm_call_method_int_jvalue ***************************************************
1757 Calls a Java method with a variable number of arguments, passed via
1758 a jvalue array, and returns an integer (s4).
1760 *******************************************************************************/
1762 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1769 /* mark start of dump memory area */
1771 dumpsize = dump_size();
1773 /* get number of Java method arguments */
1775 vmargscount = m->parseddesc->paramcount;
1777 /* allocate vm_arg array */
1779 vmargs = DMNEW(vm_arg, vmargscount);
1781 /* fill the vm_arg array from a va_list */
1783 vm_vmargs_from_jvalue(m, o, vmargs, args);
1785 /* call the Java method */
1787 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1789 /* release dump area */
1791 dump_release(dumpsize);
1797 /* vm_call_method_int_vmarg ****************************************************
1799 Calls a Java method with a variable number of arguments, passed via
1800 a vm_arg array, and returns an integer (s4).
1802 *******************************************************************************/
1804 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1808 #if defined(ENABLE_JIT)
1809 # if defined(ENABLE_INTRP)
1811 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1814 i = asm_vm_call_method_int(m, vmargscount, vmargs);
1816 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1823 /* vm_call_method_long *********************************************************
1825 Calls a Java method with a variable number of arguments and returns
1828 *******************************************************************************/
1830 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
1836 l = vm_call_method_long_valist(m, o, ap);
1843 /* vm_call_method_long_valist **************************************************
1845 Calls a Java method with a variable number of arguments, passed via
1846 a va_list, and returns a long (s8).
1848 *******************************************************************************/
1850 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
1857 /* mark start of dump memory area */
1859 dumpsize = dump_size();
1861 /* get number of Java method arguments */
1863 vmargscount = m->parseddesc->paramcount;
1865 /* allocate vm_arg array */
1867 vmargs = DMNEW(vm_arg, vmargscount);
1869 /* fill the vm_arg array from a va_list */
1871 vm_vmargs_from_valist(m, o, vmargs, ap);
1873 /* call the Java method */
1875 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1877 /* release dump area */
1879 dump_release(dumpsize);
1885 /* vm_call_method_long_jvalue **************************************************
1887 Calls a Java method with a variable number of arguments, passed via
1888 a jvalue array, and returns a long (s8).
1890 *******************************************************************************/
1892 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1899 /* mark start of dump memory area */
1901 dumpsize = dump_size();
1903 /* get number of Java method arguments */
1905 vmargscount = m->parseddesc->paramcount;
1907 /* allocate vm_arg array */
1909 vmargs = DMNEW(vm_arg, vmargscount);
1911 /* fill the vm_arg array from a va_list */
1913 vm_vmargs_from_jvalue(m, o, vmargs, args);
1915 /* call the Java method */
1917 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1919 /* release dump area */
1921 dump_release(dumpsize);
1927 /* vm_call_method_long_vmarg ***************************************************
1929 Calls a Java method with a variable number of arguments, passed via
1930 a vm_arg array, and returns a long (s8).
1932 *******************************************************************************/
1934 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1938 #if defined(ENABLE_JIT)
1939 # if defined(ENABLE_INTRP)
1941 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1944 l = asm_vm_call_method_long(m, vmargscount, vmargs);
1946 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1953 /* vm_call_method_float ********************************************************
1955 Calls a Java method with a variable number of arguments and returns
1958 *******************************************************************************/
1960 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
1966 f = vm_call_method_float_valist(m, o, ap);
1973 /* vm_call_method_float_valist *************************************************
1975 Calls a Java method with a variable number of arguments, passed via
1976 a va_list, and returns a float.
1978 *******************************************************************************/
1980 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
1988 /* mark start of dump memory area */
1990 dumpsize = dump_size();
1992 /* get number of Java method arguments */
1994 vmargscount = m->parseddesc->paramcount;
1996 /* allocate vm_arg array */
1998 vmargs = DMNEW(vm_arg, vmargscount);
2000 /* fill the vm_arg array from a va_list */
2002 vm_vmargs_from_valist(m, o, vmargs, ap);
2004 /* call the Java method */
2006 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2008 /* release dump area */
2010 dump_release(dumpsize);
2016 /* vm_call_method_float_jvalue *************************************************
2018 Calls a Java method with a variable number of arguments, passed via
2019 a jvalue array, and returns a float.
2021 *******************************************************************************/
2023 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2031 /* mark start of dump memory area */
2033 dumpsize = dump_size();
2035 /* get number of Java method arguments */
2037 vmargscount = m->parseddesc->paramcount;
2039 /* allocate vm_arg array */
2041 vmargs = DMNEW(vm_arg, vmargscount);
2043 /* fill the vm_arg array from a va_list */
2045 vm_vmargs_from_jvalue(m, o, vmargs, args);
2047 /* call the Java method */
2049 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2051 /* release dump area */
2053 dump_release(dumpsize);
2059 /* vm_call_method_float_vmarg **************************************************
2061 Calls a Java method with a variable number of arguments and returns
2064 *******************************************************************************/
2066 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2070 #if defined(ENABLE_JIT)
2071 # if defined(ENABLE_INTRP)
2073 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2076 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2078 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2085 /* vm_call_method_double *******************************************************
2087 Calls a Java method with a variable number of arguments and returns
2090 *******************************************************************************/
2092 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2098 d = vm_call_method_double_valist(m, o, ap);
2105 /* vm_call_method_double_valist ************************************************
2107 Calls a Java method with a variable number of arguments, passed via
2108 a va_list, and returns a double.
2110 *******************************************************************************/
2112 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2120 /* mark start of dump memory area */
2122 dumpsize = dump_size();
2124 /* get number of Java method arguments */
2126 vmargscount = m->parseddesc->paramcount;
2128 /* allocate vm_arg array */
2130 vmargs = DMNEW(vm_arg, vmargscount);
2132 /* fill the vm_arg array from a va_list */
2134 vm_vmargs_from_valist(m, o, vmargs, ap);
2136 /* call the Java method */
2138 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2140 /* release dump area */
2142 dump_release(dumpsize);
2148 /* vm_call_method_double_jvalue ************************************************
2150 Calls a Java method with a variable number of arguments, passed via
2151 a jvalue array, and returns a double.
2153 *******************************************************************************/
2155 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2163 /* mark start of dump memory area */
2165 dumpsize = dump_size();
2167 /* get number of Java method arguments */
2169 vmargscount = m->parseddesc->paramcount;
2171 /* allocate vm_arg array */
2173 vmargs = DMNEW(vm_arg, vmargscount);
2175 /* fill the vm_arg array from a va_list */
2177 vm_vmargs_from_jvalue(m, o, vmargs, args);
2179 /* call the Java method */
2181 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2183 /* release dump area */
2185 dump_release(dumpsize);
2191 /* vm_call_method_double_vmarg *************************************************
2193 Calls a Java method with a variable number of arguments and returns
2196 *******************************************************************************/
2198 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
2203 #if defined(ENABLE_JIT)
2204 # if defined(ENABLE_INTRP)
2206 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2209 d = asm_vm_call_method_double(m, vmargscount, vmargs);
2211 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2219 * These are local overrides for various environment variables in Emacs.
2220 * Please do not remove this and leave it at the end of the file, where
2221 * Emacs will automagically detect them.
2222 * ---------------------------------------------------------------------
2225 * indent-tabs-mode: t