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 classpath variables:\n");
474 puts(" java.boot.class.path : "CACAO_VM_ZIP_PATH":"CLASSPATH_GLIBJ_ZIP_PATH"");
475 puts(" java.library.path : "CLASSPATH_LIBRARY_PATH"\n");
477 puts("Runtime classpath variables:\n");
478 printf(" java.boot.class.path : %s\n", bootclasspath);
482 /* fullversion *****************************************************************
484 Prints a Sun compatible version information (required e.g. by
485 jpackage, www.jpackage.org).
487 *******************************************************************************/
489 static void fullversion(void)
491 puts("java full version \"cacao-"JAVA_VERSION"\"");
499 /* vm_create *******************************************************************
501 Creates a JVM. Called by JNI_CreateJavaVM.
503 *******************************************************************************/
505 bool vm_create(JavaVMInitArgs *vm_args)
515 #if defined(ENABLE_JVMTI)
518 bool agentbypath = false;;
523 /* check the JNI version requested */
525 switch (vm_args->version) {
526 case JNI_VERSION_1_1:
528 case JNI_VERSION_1_2:
529 case JNI_VERSION_1_4:
535 /* we only support 1 JVM instance */
541 /* get stuff from the environment *****************************************/
543 #if defined(DISABLE_GC)
544 nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
548 /* set the bootclasspath */
550 cp = getenv("BOOTCLASSPATH");
553 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
554 strcpy(bootclasspath, cp);
557 cplen = strlen(CACAO_VM_ZIP_PATH) +
559 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
562 bootclasspath = MNEW(char, cplen);
563 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
564 strcat(bootclasspath, ":");
565 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
569 /* set the classpath */
571 cp = getenv("CLASSPATH");
574 classpath = MNEW(char, strlen(cp) + strlen("0"));
575 strcat(classpath, cp);
578 classpath = MNEW(char, strlen(".") + strlen("0"));
579 strcpy(classpath, ".");
583 /* interpret the options **************************************************/
588 heapmaxsize = HEAP_MAXSIZE;
589 heapstartsize = HEAP_STARTSIZE;
590 opt_stacksize = STACK_SIZE;
593 #if defined(ENABLE_JVMTI)
594 /* initialize JVMTI related **********************************************/
595 jdwp = jvmti = false;
598 /* initialize properties before commandline handling */
600 if (!properties_init())
601 throw_cacao_exception_exit(string_java_lang_InternalError,
602 "Unable to init properties");
604 /* add some default properties */
606 properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
609 /* iterate over all passed options */
611 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
621 #if SIZEOF_VOID_P == 8
622 puts("Running a 32-bit JVM is not supported on this platform.");
628 #if SIZEOF_VOID_P == 4
629 puts("Running a 64-bit JVM is not supported on this platform.");
635 /* forget old classpath and set the argument as new classpath */
636 MFREE(classpath, char, strlen(classpath));
638 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
639 strcpy(classpath, opt_arg);
643 for (j = 0; j < strlen(opt_arg); j++) {
644 if (opt_arg[j] == '=') {
646 properties_add(opt_arg, opt_arg + j + 1);
651 /* if no '=' is given, just create an empty property */
653 properties_add(opt_arg, "");
658 case OPT_BOOTCLASSPATH:
659 /* Forget default bootclasspath and set the argument as
660 new boot classpath. */
661 MFREE(bootclasspath, char, strlen(bootclasspath));
663 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
664 strcpy(bootclasspath, opt_arg);
667 case OPT_BOOTCLASSPATH_A:
668 /* append to end of bootclasspath */
669 cplen = strlen(bootclasspath);
671 bootclasspath = MREALLOC(bootclasspath,
674 cplen + strlen(":") +
675 strlen(opt_arg) + strlen("0"));
677 strcat(bootclasspath, ":");
678 strcat(bootclasspath, opt_arg);
681 case OPT_BOOTCLASSPATH_P:
682 /* prepend in front of bootclasspath */
686 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
687 cplen + strlen("0"));
689 strcpy(bootclasspath, opt_arg);
690 strcat(bootclasspath, ":");
691 strcat(bootclasspath, cp);
693 MFREE(cp, char, cplen);
696 #if defined(ENABLE_JVMTI)
701 /* I don't know yet what Xnoagent should do. This is only for
702 compatiblity with eclipse - motse */
707 while (transport[j]!='=') j++;
709 while (j<strlen(transport)) {
710 if (strncmp("suspend=",&transport[j],8)==0) {
711 if ((j+8)>=strlen(transport) ||
712 (transport[j+8]!= 'y' && transport[j+8]!= 'n')) {
713 printf("bad Xrunjdwp option: -Xrunjdwp%s\n",transport);
718 suspend = transport[j+8] == 'y';
722 while (transport[j]!=',') j++;
741 c = opt_arg[strlen(opt_arg) - 1];
743 if ((c == 'k') || (c == 'K')) {
744 j = atoi(opt_arg) * 1024;
746 } else if ((c == 'm') || (c == 'M')) {
747 j = atoi(opt_arg) * 1024 * 1024;
754 else if (opt == OPT_MS)
766 if (strcmp("class", opt_arg) == 0)
767 opt_verboseclass = true;
769 else if (strcmp("gc", opt_arg) == 0)
770 opt_verbosegc = true;
772 else if (strcmp("jni", opt_arg) == 0)
773 opt_verbosejni = true;
775 else if (strcmp("call", opt_arg) == 0)
776 opt_verbosecall = true;
778 else if (strcmp("jit", opt_arg) == 0) {
783 compileverbose = true;
785 else if (strcmp("exception", opt_arg) == 0)
786 opt_verboseexception = true;
789 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
791 opt_typecheckverbose = true;
800 case OPT_FULLVERSION:
804 case OPT_SHOWVERSION:
812 #if defined(ENABLE_VERIFIER)
822 #if defined(ENABLE_STATISTICS)
824 opt_getcompilingtime = true;
825 opt_getloadingtime = true;
838 for (j = 0; j < strlen(opt_arg); j++) {
839 switch (opt_arg[j]) {
854 makeinitializations = false;
863 opt_method = opt_arg;
864 makeinitializations = false;
868 opt_signature = opt_arg;
874 makeinitializations = false;
877 case OPT_SHOW: /* Display options */
878 for (j = 0; j < strlen(opt_arg); j++) {
879 switch (opt_arg[j]) {
881 opt_showdisassemble = true;
882 compileverbose = true;
885 showconstantpool = true;
888 opt_showddatasegment = true;
891 opt_showexceptionstubs = true;
894 opt_showintermediate = true;
895 compileverbose = true;
901 opt_shownativestub = true;
912 #if defined(ENABLE_LOOP)
918 #if defined(ENABLE_INLINING)
920 for (j = 0; j < strlen(opt_arg); j++) {
921 switch (opt_arg[j]) {
923 /* define in options.h; Used in main.c, jit.c
924 & inline.c inlining is currently
928 inlinevirtuals = true;
931 inlineexceptions = true;
934 inlineparamopt = true;
937 inlineoutsiders = true;
944 #endif /* defined(ENABLE_INLINING) */
946 #if defined(ENABLE_IFCONV)
952 #if defined(ENABLE_LSRA)
966 case OPT_PROF_OPTION:
967 /* use <= to get the last \0 too */
969 for (j = 0, k = 0; j <= strlen(opt_arg); j++) {
970 if (opt_arg[j] == ',')
973 if (opt_arg[j] == '\0') {
974 if (strcmp("bb", opt_arg + k) == 0)
978 printf("Unknown option: -Xprof:%s\n", opt_arg + k);
982 /* set k to next char */
994 #if defined(ENABLE_JIT)
997 printf("-Xjit option not enabled.\n");
1003 #if defined(ENABLE_INTRP)
1006 printf("-Xint option not enabled.\n");
1011 #if defined(ENABLE_INTRP)
1012 case OPT_STATIC_SUPERS:
1013 opt_static_supers = atoi(opt_arg);
1016 case OPT_NO_DYNAMIC:
1017 opt_no_dynamic = true;
1020 case OPT_NO_REPLICATION:
1021 opt_no_replication = true;
1024 case OPT_NO_QUICKSUPER:
1025 opt_no_quicksuper = true;
1034 printf("Unknown option: %s\n",
1035 vm_args->options[opt_index].optionString);
1041 /* get the main class *****************************************************/
1043 if (opt_index < vm_args->nOptions) {
1044 mainstring = vm_args->options[opt_index++].optionString;
1046 /* Put the jar file into the classpath (if any). */
1048 if (opt_jar == true) {
1049 /* free old classpath */
1051 MFREE(classpath, char, strlen(classpath));
1053 /* put jarfile into classpath */
1055 classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1057 strcpy(classpath, mainstring);
1060 /* replace .'s with /'s in classname */
1062 for (i = strlen(mainstring) - 1; i >= 0; i--)
1063 if (mainstring[i] == '.')
1064 mainstring[i] = '/';
1068 #if defined(ENABLE_JVMTI)
1070 set_jvmti_phase(JVMTI_PHASE_ONLOAD);
1071 agentload(agentarg, agentbypath, &handle, &libname);
1073 set_jvmti_phase(JVMTI_PHASE_PRIMORDIAL);
1077 /* initialize this JVM ****************************************************/
1079 vm_initializing = true;
1081 /* initialize the garbage collector */
1083 gc_init(heapmaxsize, heapstartsize);
1085 #if defined(ENABLE_INTRP)
1086 /* Allocate main thread stack on the Java heap. */
1089 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1090 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1094 #if defined(ENABLE_THREADS)
1098 /* initialize the string hashtable stuff: lock (must be done
1099 _after_ threads_preinit) */
1102 throw_main_exception_exit();
1104 /* initialize the utf8 hashtable stuff: lock, often used utf8
1105 strings (must be done _after_ threads_preinit) */
1108 throw_main_exception_exit();
1110 /* initialize the classcache hashtable stuff: lock, hashtable
1111 (must be done _after_ threads_preinit) */
1113 if (!classcache_init())
1114 throw_main_exception_exit();
1116 /* initialize the loader with bootclasspath (must be done _after_
1120 throw_main_exception_exit();
1122 suck_add_from_property("java.endorsed.dirs");
1123 suck_add(bootclasspath);
1125 /* initialize the memory subsystem (must be done _after_
1129 throw_main_exception_exit();
1131 /* initialize the finalizer stuff (must be done _after_
1134 if (!finalizer_init())
1135 throw_main_exception_exit();
1137 /* install architecture dependent signal handler used for exceptions */
1141 /* initialize the codegen subsystems */
1145 /* initializes jit compiler */
1149 /* machine dependent initialization */
1151 #if defined(ENABLE_JIT)
1152 # if defined(ENABLE_INTRP)
1162 /* initialize the loader subsystems (must be done _after_
1166 throw_main_exception_exit();
1169 throw_main_exception_exit();
1172 throw_main_exception_exit();
1174 if (!exceptions_init())
1175 throw_main_exception_exit();
1177 if (!builtin_init())
1178 throw_main_exception_exit();
1180 /* Initialize the JNI subsystem (must be done _before_
1181 threads_init, as threads_init can call JNI methods
1182 (e.g. NewGlobalRef). */
1185 throw_main_exception_exit();
1187 #if defined(ENABLE_THREADS)
1188 if (!threads_init())
1189 throw_main_exception_exit();
1192 /* That's important, otherwise we get into trouble, if the Runtime
1193 static initializer is called before (circular dependency. This
1194 is with classpath 0.09. Another important thing is, that this
1195 has to happen after initThreads!!! */
1197 if (!initialize_class(class_java_lang_System))
1198 throw_main_exception_exit();
1200 #if defined(ENABLE_PROFILING)
1201 /* initialize profiling */
1203 if (!profile_init())
1204 throw_main_exception_exit();
1207 #if defined(ENABLE_THREADS)
1208 /* finally, start the finalizer thread */
1210 if (!finalizer_start_thread())
1211 throw_main_exception_exit();
1213 /* start the profile sampling thread */
1215 /* if (!profile_start_thread()) */
1216 /* throw_main_exception_exit(); */
1219 #if defined(ENABLE_JVMTI)
1221 /* add agent library to native library hashtable */
1222 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1226 /* increment the number of VMs */
1230 /* initialization is done */
1232 vm_initializing = false;
1234 /* everything's ok */
1240 /* vm_destroy ******************************************************************
1242 Unloads a Java VM and reclaims its resources.
1244 *******************************************************************************/
1246 s4 vm_destroy(JavaVM *vm)
1248 #if defined(ENABLE_THREADS)
1249 threads_join_all_threads();
1252 /* everything's ok */
1258 /* vm_exit *********************************************************************
1260 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1262 *******************************************************************************/
1264 void vm_exit(s4 status)
1268 /* signal that we are exiting */
1272 assert(class_java_lang_System);
1273 assert(class_java_lang_System->state & CLASS_LOADED);
1275 #if defined(ENABLE_JVMTI)
1276 set_jvmti_phase(JVMTI_PHASE_DEAD);
1277 if (jvmti) agentunload();
1280 if (!link_class(class_java_lang_System))
1281 throw_main_exception_exit();
1283 /* call java.lang.System.exit(I)V */
1285 m = class_resolveclassmethod(class_java_lang_System,
1286 utf_new_char("exit"),
1288 class_java_lang_Object,
1292 throw_main_exception_exit();
1294 /* call the exit function with passed exit status */
1296 (void) vm_call_method(m, NULL, status);
1298 /* If we had an exception, just ignore the exception and exit with
1301 vm_shutdown(status);
1305 /* vm_shutdown *****************************************************************
1307 Terminates the system immediately without freeing memory explicitly
1308 (to be used only for abnormal termination).
1310 *******************************************************************************/
1312 void vm_shutdown(s4 status)
1315 #if defined(ENABLE_STATISTICS)
1316 || opt_getcompilingtime || opt_stat
1320 log_text("CACAO terminated by shutdown");
1321 dolog("Exit status: %d\n", (s4) status);
1328 /* vm_exit_handler *************************************************************
1330 The exit_handler function is called upon program termination.
1332 ATTENTION: Don't free system resources here! Some threads may still
1333 be running as this is called from VMRuntime.exit(). The OS does the
1336 *******************************************************************************/
1338 void vm_exit_handler(void)
1340 #if !defined(NDEBUG)
1342 class_showmethods(mainclass);
1344 if (showconstantpool)
1345 class_showconstantpool(mainclass);
1350 # if defined(ENABLE_PROFILING)
1352 profile_printstats();
1354 #endif /* !defined(NDEBUG) */
1356 #if defined(ENABLE_RT_TIMING)
1357 rt_timing_print_time_stats(stderr);
1360 #if defined(ENABLE_CYCLES_STATS)
1361 builtin_print_cycles_stats(stderr);
1362 stacktrace_print_cycles_stats(stderr);
1366 #if defined(ENABLE_STATISTICS)
1367 || opt_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 (opt_getcompilingtime)
1385 #endif /* defined(ENABLE_STATISTICS) */
1387 /* vm_print_profile(stderr);*/
1391 /* vm_abort ********************************************************************
1393 Prints an error message and aborts the VM.
1395 *******************************************************************************/
1397 void vm_abort(const char *text, ...)
1401 /* print the log message */
1406 log_vprint(text, ap);
1411 /* now abort the VM */
1417 /* vm_vmargs_from_valist *******************************************************
1421 *******************************************************************************/
1423 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
1424 vm_arg *vmargs, va_list ap)
1426 typedesc *paramtypes;
1429 paramtypes = m->parseddesc->paramtypes;
1431 /* if method is non-static fill first block and skip `this' pointer */
1436 /* the `this' pointer */
1437 vmargs[0].type = TYPE_ADR;
1438 vmargs[0].data.l = (u8) (ptrint) o;
1444 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
1445 switch (paramtypes->decltype) {
1446 /* primitive types */
1447 case PRIMITIVETYPE_BOOLEAN:
1448 case PRIMITIVETYPE_BYTE:
1449 case PRIMITIVETYPE_CHAR:
1450 case PRIMITIVETYPE_SHORT:
1451 case PRIMITIVETYPE_INT:
1452 vmargs[i].type = TYPE_INT;
1453 vmargs[i].data.l = (s8) va_arg(ap, s4);
1456 case PRIMITIVETYPE_LONG:
1457 vmargs[i].type = TYPE_LNG;
1458 vmargs[i].data.l = (s8) va_arg(ap, s8);
1461 case PRIMITIVETYPE_FLOAT:
1462 vmargs[i].type = TYPE_FLT;
1463 #if defined(__ALPHA__)
1464 /* this keeps the assembler function much simpler */
1466 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
1468 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
1472 case PRIMITIVETYPE_DOUBLE:
1473 vmargs[i].type = TYPE_DBL;
1474 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
1478 vmargs[i].type = TYPE_ADR;
1479 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
1486 /* vm_vmargs_from_jvalue *******************************************************
1490 *******************************************************************************/
1492 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
1493 vm_arg *vmargs, jvalue *args)
1495 typedesc *paramtypes;
1499 paramtypes = m->parseddesc->paramtypes;
1501 /* if method is non-static fill first block and skip `this' pointer */
1506 /* the `this' pointer */
1507 vmargs[0].type = TYPE_ADR;
1508 vmargs[0].data.l = (u8) (ptrint) o;
1514 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
1515 switch (paramtypes->decltype) {
1516 /* primitive types */
1517 case PRIMITIVETYPE_BOOLEAN:
1518 case PRIMITIVETYPE_BYTE:
1519 case PRIMITIVETYPE_CHAR:
1520 case PRIMITIVETYPE_SHORT:
1521 case PRIMITIVETYPE_INT:
1522 vmargs[i].type = TYPE_INT;
1523 vmargs[i].data.l = (s8) args[j].i;
1526 case PRIMITIVETYPE_LONG:
1527 vmargs[i].type = TYPE_LNG;
1528 vmargs[i].data.l = (s8) args[j].j;
1531 case PRIMITIVETYPE_FLOAT:
1532 vmargs[i].type = TYPE_FLT;
1533 #if defined(__ALPHA__)
1534 /* this keeps the assembler function much simpler */
1536 vmargs[i].data.d = (jdouble) args[j].f;
1538 vmargs[i].data.f = args[j].f;
1542 case PRIMITIVETYPE_DOUBLE:
1543 vmargs[i].type = TYPE_DBL;
1544 vmargs[i].data.d = args[j].d;
1548 vmargs[i].type = TYPE_ADR;
1549 vmargs[i].data.l = (u8) (ptrint) args[j].l;
1556 /* vm_call_method **************************************************************
1558 Calls a Java method with a variable number of arguments and returns
1561 *******************************************************************************/
1563 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
1566 java_objectheader *ro;
1569 ro = vm_call_method_valist(m, o, ap);
1576 /* vm_call_method_valist *******************************************************
1578 Calls a Java method with a variable number of arguments, passed via
1579 a va_list, and returns an address.
1581 *******************************************************************************/
1583 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
1588 java_objectheader *ro;
1591 /* mark start of dump memory area */
1593 dumpsize = dump_size();
1595 /* get number of Java method arguments */
1597 vmargscount = m->parseddesc->paramcount;
1599 /* allocate vm_arg array */
1601 vmargs = DMNEW(vm_arg, vmargscount);
1603 /* fill the vm_arg array from a va_list */
1605 vm_vmargs_from_valist(m, o, vmargs, ap);
1607 /* call the Java method */
1609 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1611 /* release dump area */
1613 dump_release(dumpsize);
1619 /* vm_call_method_jvalue *******************************************************
1621 Calls a Java method with a variable number of arguments, passed via
1622 a jvalue array, and returns an address.
1624 *******************************************************************************/
1626 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
1631 java_objectheader *ro;
1634 /* mark start of dump memory area */
1636 dumpsize = dump_size();
1638 /* get number of Java method arguments */
1640 vmargscount = m->parseddesc->paramcount;
1642 /* allocate vm_arg array */
1644 vmargs = DMNEW(vm_arg, vmargscount);
1646 /* fill the vm_arg array from a va_list */
1648 vm_vmargs_from_jvalue(m, o, vmargs, args);
1650 /* call the Java method */
1652 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1654 /* release dump area */
1656 dump_release(dumpsize);
1662 /* vm_call_method_vmarg ********************************************************
1664 Calls a Java method with a variable number of arguments, passed via
1665 a vm_arg array, and returns an address.
1667 *******************************************************************************/
1669 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
1672 java_objectheader *o;
1674 #if defined(ENABLE_JIT)
1675 # if defined(ENABLE_INTRP)
1677 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1680 o = asm_vm_call_method(m, vmargscount, vmargs);
1682 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1689 /* vm_call_method_int **********************************************************
1691 Calls a Java method with a variable number of arguments and returns
1694 *******************************************************************************/
1696 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
1702 i = vm_call_method_int_valist(m, o, ap);
1709 /* vm_call_method_int_valist ***************************************************
1711 Calls a Java method with a variable number of arguments, passed via
1712 a va_list, and returns an integer (s4).
1714 *******************************************************************************/
1716 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
1723 /* mark start of dump memory area */
1725 dumpsize = dump_size();
1727 /* get number of Java method arguments */
1729 vmargscount = m->parseddesc->paramcount;
1731 /* allocate vm_arg array */
1733 vmargs = DMNEW(vm_arg, vmargscount);
1735 /* fill the vm_arg array from a va_list */
1737 vm_vmargs_from_valist(m, o, vmargs, ap);
1739 /* call the Java method */
1741 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1743 /* release dump area */
1745 dump_release(dumpsize);
1751 /* vm_call_method_int_jvalue ***************************************************
1753 Calls a Java method with a variable number of arguments, passed via
1754 a jvalue array, and returns an integer (s4).
1756 *******************************************************************************/
1758 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1765 /* mark start of dump memory area */
1767 dumpsize = dump_size();
1769 /* get number of Java method arguments */
1771 vmargscount = m->parseddesc->paramcount;
1773 /* allocate vm_arg array */
1775 vmargs = DMNEW(vm_arg, vmargscount);
1777 /* fill the vm_arg array from a va_list */
1779 vm_vmargs_from_jvalue(m, o, vmargs, args);
1781 /* call the Java method */
1783 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1785 /* release dump area */
1787 dump_release(dumpsize);
1793 /* vm_call_method_int_vmarg ****************************************************
1795 Calls a Java method with a variable number of arguments, passed via
1796 a vm_arg array, and returns an integer (s4).
1798 *******************************************************************************/
1800 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1804 #if defined(ENABLE_JIT)
1805 # if defined(ENABLE_INTRP)
1807 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1810 i = asm_vm_call_method_int(m, vmargscount, vmargs);
1812 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1819 /* vm_call_method_long *********************************************************
1821 Calls a Java method with a variable number of arguments and returns
1824 *******************************************************************************/
1826 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
1832 l = vm_call_method_long_valist(m, o, ap);
1839 /* vm_call_method_long_valist **************************************************
1841 Calls a Java method with a variable number of arguments, passed via
1842 a va_list, and returns a long (s8).
1844 *******************************************************************************/
1846 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
1853 /* mark start of dump memory area */
1855 dumpsize = dump_size();
1857 /* get number of Java method arguments */
1859 vmargscount = m->parseddesc->paramcount;
1861 /* allocate vm_arg array */
1863 vmargs = DMNEW(vm_arg, vmargscount);
1865 /* fill the vm_arg array from a va_list */
1867 vm_vmargs_from_valist(m, o, vmargs, ap);
1869 /* call the Java method */
1871 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1873 /* release dump area */
1875 dump_release(dumpsize);
1881 /* vm_call_method_long_jvalue **************************************************
1883 Calls a Java method with a variable number of arguments, passed via
1884 a jvalue array, and returns a long (s8).
1886 *******************************************************************************/
1888 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1895 /* mark start of dump memory area */
1897 dumpsize = dump_size();
1899 /* get number of Java method arguments */
1901 vmargscount = m->parseddesc->paramcount;
1903 /* allocate vm_arg array */
1905 vmargs = DMNEW(vm_arg, vmargscount);
1907 /* fill the vm_arg array from a va_list */
1909 vm_vmargs_from_jvalue(m, o, vmargs, args);
1911 /* call the Java method */
1913 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1915 /* release dump area */
1917 dump_release(dumpsize);
1923 /* vm_call_method_long_vmarg ***************************************************
1925 Calls a Java method with a variable number of arguments, passed via
1926 a vm_arg array, and returns a long (s8).
1928 *******************************************************************************/
1930 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1934 #if defined(ENABLE_JIT)
1935 # if defined(ENABLE_INTRP)
1937 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1940 l = asm_vm_call_method_long(m, vmargscount, vmargs);
1942 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1949 /* vm_call_method_float ********************************************************
1951 Calls a Java method with a variable number of arguments and returns
1954 *******************************************************************************/
1956 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
1962 f = vm_call_method_float_valist(m, o, ap);
1969 /* vm_call_method_float_valist *************************************************
1971 Calls a Java method with a variable number of arguments, passed via
1972 a va_list, and returns a float.
1974 *******************************************************************************/
1976 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
1984 /* mark start of dump memory area */
1986 dumpsize = dump_size();
1988 /* get number of Java method arguments */
1990 vmargscount = m->parseddesc->paramcount;
1992 /* allocate vm_arg array */
1994 vmargs = DMNEW(vm_arg, vmargscount);
1996 /* fill the vm_arg array from a va_list */
1998 vm_vmargs_from_valist(m, o, vmargs, ap);
2000 /* call the Java method */
2002 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2004 /* release dump area */
2006 dump_release(dumpsize);
2012 /* vm_call_method_float_jvalue *************************************************
2014 Calls a Java method with a variable number of arguments, passed via
2015 a jvalue array, and returns a float.
2017 *******************************************************************************/
2019 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2027 /* mark start of dump memory area */
2029 dumpsize = dump_size();
2031 /* get number of Java method arguments */
2033 vmargscount = m->parseddesc->paramcount;
2035 /* allocate vm_arg array */
2037 vmargs = DMNEW(vm_arg, vmargscount);
2039 /* fill the vm_arg array from a va_list */
2041 vm_vmargs_from_jvalue(m, o, vmargs, args);
2043 /* call the Java method */
2045 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2047 /* release dump area */
2049 dump_release(dumpsize);
2055 /* vm_call_method_float_vmarg **************************************************
2057 Calls a Java method with a variable number of arguments and returns
2060 *******************************************************************************/
2062 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2066 #if defined(ENABLE_JIT)
2067 # if defined(ENABLE_INTRP)
2069 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2072 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2074 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2081 /* vm_call_method_double *******************************************************
2083 Calls a Java method with a variable number of arguments and returns
2086 *******************************************************************************/
2088 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2094 d = vm_call_method_double_valist(m, o, ap);
2101 /* vm_call_method_double_valist ************************************************
2103 Calls a Java method with a variable number of arguments, passed via
2104 a va_list, and returns a double.
2106 *******************************************************************************/
2108 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2116 /* mark start of dump memory area */
2118 dumpsize = dump_size();
2120 /* get number of Java method arguments */
2122 vmargscount = m->parseddesc->paramcount;
2124 /* allocate vm_arg array */
2126 vmargs = DMNEW(vm_arg, vmargscount);
2128 /* fill the vm_arg array from a va_list */
2130 vm_vmargs_from_valist(m, o, vmargs, ap);
2132 /* call the Java method */
2134 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2136 /* release dump area */
2138 dump_release(dumpsize);
2144 /* vm_call_method_double_jvalue ************************************************
2146 Calls a Java method with a variable number of arguments, passed via
2147 a jvalue array, and returns a double.
2149 *******************************************************************************/
2151 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2159 /* mark start of dump memory area */
2161 dumpsize = dump_size();
2163 /* get number of Java method arguments */
2165 vmargscount = m->parseddesc->paramcount;
2167 /* allocate vm_arg array */
2169 vmargs = DMNEW(vm_arg, vmargscount);
2171 /* fill the vm_arg array from a va_list */
2173 vm_vmargs_from_jvalue(m, o, vmargs, args);
2175 /* call the Java method */
2177 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2179 /* release dump area */
2181 dump_release(dumpsize);
2187 /* vm_call_method_double_vmarg *************************************************
2189 Calls a Java method with a variable number of arguments and returns
2192 *******************************************************************************/
2194 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
2199 #if defined(ENABLE_JIT)
2200 # if defined(ENABLE_INTRP)
2202 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2205 d = asm_vm_call_method_double(m, vmargscount, vmargs);
2207 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2215 * These are local overrides for various environment variables in Emacs.
2216 * Please do not remove this and leave it at the end of the file, where
2217 * Emacs will automagically detect them.
2218 * ---------------------------------------------------------------------
2221 * indent-tabs-mode: t