1 /* src/vm/vm.c - VM startup and shutdown functions
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: vm.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 128 * 1024 * 1024 /* default 128MB */
101 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
102 #define STACK_SIZE 64 * 1024 /* default 64kB */
105 /* define command line options ************************************************/
127 /* Java non-standard options */
150 #if defined(ENABLE_STATISTICS)
163 #if defined(ENABLE_VERIFIER)
165 #if defined(TYPECHECK_VERBOSE)
168 #endif /* defined(ENABLE_VERIFIER) */
171 /* optimization options */
173 #if defined(ENABLE_LOOP)
177 #if defined(ENABLE_IFCONV)
181 #if defined(ENABLE_LSRA)
185 #if defined(ENABLE_INLINING)
189 #if defined(ENABLE_INTRP)
190 /* interpreter options */
213 opt_struct opts[] = {
216 { "jar", false, OPT_JAR },
218 { "d32", false, OPT_D32 },
219 { "d64", false, OPT_D64 },
220 { "client", false, OPT_IGNORE },
221 { "server", false, OPT_IGNORE },
222 { "jvm", false, OPT_IGNORE },
223 { "hotspot", false, OPT_IGNORE },
225 { "classpath", true, OPT_CLASSPATH },
226 { "cp", true, OPT_CLASSPATH },
227 { "D", true, OPT_D },
228 { "version", false, OPT_VERSION },
229 { "showversion", false, OPT_SHOWVERSION },
230 { "fullversion", false, OPT_FULLVERSION },
231 { "help", false, OPT_HELP },
232 { "?", false, OPT_HELP },
233 { "X", false, OPT_X },
235 { "noasyncgc", false, OPT_IGNORE },
236 #if defined(ENABLE_VERIFIER)
237 { "noverify", false, OPT_NOVERIFY },
239 { "v", false, OPT_VERBOSE1 },
240 { "verbose:", true, OPT_VERBOSE },
242 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
243 { "verbosetc", false, OPT_VERBOSETC },
245 #if defined(__ALPHA__)
246 { "noieee", false, OPT_NOIEEE },
248 { "softnull", false, OPT_SOFTNULL },
249 #if defined(ENABLE_STATISTICS)
250 { "time", false, OPT_TIME },
251 { "stat", false, OPT_STAT },
253 { "log", true, OPT_LOG },
254 { "c", true, OPT_CHECK },
255 { "l", false, OPT_LOAD },
256 { "eager", false, OPT_EAGER },
257 { "sig", true, OPT_SIGNATURE },
258 { "all", false, OPT_ALL },
259 #if defined(ENABLE_LOOP)
260 { "oloop", false, OPT_OLOOP },
262 #if defined(ENABLE_IFCONV)
263 { "ifconv", false, OPT_IFCONV },
265 #if defined(ENABLE_LSRA)
266 { "lsra", false, OPT_LSRA },
269 #if defined(ENABLE_INTRP)
270 /* interpreter options */
272 { "trace", false, OPT_TRACE },
273 { "static-supers", true, OPT_STATIC_SUPERS },
274 { "no-dynamic", false, OPT_NO_DYNAMIC },
275 { "no-replication", false, OPT_NO_REPLICATION },
276 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
279 /* JVMTI Agent Command Line Options */
281 { "agentlib:", true, OPT_AGENTLIB },
282 { "agentpath:", true, OPT_AGENTPATH },
285 /* Java non-standard options */
287 { "Xjit", false, OPT_JIT },
288 { "Xint", false, OPT_INTRP },
289 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
290 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
291 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
292 { "Xglibj:", true, OPT_GLIBJ },
295 { "Xdebug", false, OPT_DEBUG },
296 { "Xnoagent", false, OPT_NOAGENT },
297 { "Xrunjdwp", true, OPT_XRUNJDWP },
300 { "Xms", true, OPT_MS },
301 { "ms", true, OPT_MS },
302 { "Xmx", true, OPT_MX },
303 { "mx", true, OPT_MX },
304 { "Xss", true, OPT_SS },
305 { "ss", true, OPT_SS },
306 { "Xprof:", true, OPT_PROF_OPTION },
307 { "Xprof", false, OPT_PROF },
309 /* keep these at the end of the list */
311 #if defined(ENABLE_INLINING)
312 { "i", true, OPT_INLINING },
314 { "m", true, OPT_METHOD },
315 { "s", true, OPT_SHOW },
321 /* usage ***********************************************************************
323 Prints the correct usage syntax to stdout.
325 *******************************************************************************/
329 puts("Usage: cacao [-options] classname [arguments]");
330 puts(" (to run a class file)");
331 puts(" or cacao [-options] -jar jarfile [arguments]");
332 puts(" (to run a standalone jar file)\n");
334 puts("Java options:");
335 puts(" -d32 use 32-bit data model if available");
336 puts(" -d64 use 64-bit data model if available");
337 puts(" -client compatibility (currently ignored)");
338 puts(" -server compatibility (currently ignored)");
339 puts(" -jvm compatibility (currently ignored)");
340 puts(" -hotspot compatibility (currently ignored)\n");
342 puts(" -cp <path> specify a path to look for classes");
343 puts(" -classpath <path> specify a path to look for classes");
344 puts(" -D<name>=<value> add an entry to the property list");
345 puts(" -verbose[:class|gc|jni] enable specific verbose output");
346 puts(" -version print product version and exit");
347 puts(" -fullversion print jpackage-compatible product version and exit");
348 puts(" -showversion print product version and continue");
349 puts(" -help, -? print this help message");
350 puts(" -X print help on non-standard Java options\n");
353 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
354 puts (" for jdwp help use: -agentlib:jdwp=help");
355 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
358 puts("CACAO options:");
359 puts(" -v write state-information");
360 puts(" -verbose[:call|exception|jit]");
361 puts(" enable specific verbose output");
362 #ifdef TYPECHECK_VERBOSE
363 puts(" -verbosetc write debug messages while typechecking");
365 #if defined(__ALPHA__)
366 puts(" -noieee don't use ieee compliant arithmetic");
368 #if defined(ENABLE_VERIFIER)
369 puts(" -noverify don't verify classfiles");
371 puts(" -softnull use software nullpointer check");
372 #if defined(ENABLE_STATISTICS)
373 puts(" -time measure the runtime");
374 puts(" -stat detailed compiler statistics");
376 puts(" -log logfile specify a name for the logfile");
377 puts(" -c(heck)b(ounds) don't check array bounds");
378 puts(" s(ync) don't check for synchronization");
379 #if defined(ENABLE_LOOP)
380 puts(" -oloop optimize array accesses in loops");
382 puts(" -l don't start the class after loading");
383 puts(" -eager perform eager class loading and linking");
384 puts(" -all compile all methods, no execution");
385 puts(" -m compile only a specific method");
386 puts(" -sig specify signature for a specific method");
387 puts(" -s(how)a(ssembler) show disassembled listing");
388 puts(" c(onstants) show the constant pool");
389 puts(" d(atasegment) show data segment listing");
390 puts(" e(xceptionstubs) show disassembled exception stubs (only with -sa)");
391 puts(" i(ntermediate) show intermediate representation");
392 puts(" m(ethods) show class fields and methods");
393 puts(" n(ative) show disassembled native stubs");
394 puts(" u(tf) show the utf - hash");
395 #if defined(ENABLE_INLINING)
396 puts(" -i n(line) activate inlining");
397 puts(" v(irtual) inline virtual methods (uses/turns rt option on)");
398 puts(" e(exception) inline methods with exceptions");
399 puts(" p(aramopt) optimize argument renaming");
400 puts(" o(utsiders) inline methods of foreign classes");
401 #endif /* defined(ENABLE_INLINING) */
402 #if defined(ENABLE_IFCONV)
403 puts(" -ifconv use if-conversion");
405 #if defined(ENABLE_LSRA)
406 puts(" -lsra use linear scan register allocation");
409 /* exit with error code */
415 static void Xusage(void)
417 #if defined(ENABLE_JIT)
418 puts(" -Xjit JIT mode execution (default)");
420 #if defined(ENABLE_INTRP)
421 puts(" -Xint interpreter mode execution");
423 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
424 puts(" value is set as bootstrap class path");
425 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
426 puts(" value is appended to the bootstrap class path");
427 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
428 puts(" value is prepended to the bootstrap class path");
429 puts(" -Xglibj:<zip/jar files and directories separated by :>");
430 puts(" value is used as Java core library, but the");
431 puts(" hardcoded VM interface classes are prepended");
432 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
433 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
434 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
435 puts(" -Xprof[:bb] collect and print profiling data");
436 #if defined(ENABLE_JVMTI)
437 /* -Xdebug option depend on gnu classpath JDWP options. options:
438 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
439 puts(" -Xdebug enable remote debugging\n");
440 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
441 puts(" enable remote debugging\n");
444 /* exit with error code */
450 /* version *********************************************************************
452 Only prints cacao version information.
454 *******************************************************************************/
456 static void version(bool opt_exit)
458 puts("java version \""JAVA_VERSION"\"");
459 puts("CACAO version "VERSION"");
461 puts("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,");
462 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
463 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
464 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
466 puts("This program is free software; you can redistribute it and/or");
467 puts("modify it under the terms of the GNU General Public License as");
468 puts("published by the Free Software Foundation; either version 2, or (at");
469 puts("your option) any later version.\n");
471 puts("This program is distributed in the hope that it will be useful, but");
472 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
473 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
474 puts("General Public License for more details.\n");
476 puts("Configure/Build options:\n");
477 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
478 #if defined(__VERSION__)
479 puts(" CC : "VERSION_CC" ("__VERSION__")");
481 puts(" CC : "VERSION_CC"");
483 puts(" CFLAGS : "VERSION_CFLAGS"\n");
485 puts("Default variables:\n");
486 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
487 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
488 printf(" stack size : %d\n", STACK_SIZE);
489 puts(" java.boot.class.path: "CACAO_VM_ZIP":"CLASSPATH_GLIBJ_ZIP"");
490 puts(" java.library.path : "CLASSPATH_LIBRARY_PATH"\n");
492 puts("Runtime variables:\n");
493 printf(" maximum heap size : %d\n", opt_heapmaxsize);
494 printf(" initial heap size : %d\n", opt_heapstartsize);
495 printf(" stack size : %d\n", opt_stacksize);
496 printf(" java.boot.class.path: %s\n", bootclasspath);
498 /* exit normally, if requested */
505 /* fullversion *****************************************************************
507 Prints a Sun compatible version information (required e.g. by
508 jpackage, www.jpackage.org).
510 *******************************************************************************/
512 static void fullversion(void)
514 puts("java full version \"cacao-"JAVA_VERSION"\"");
522 /* vm_create *******************************************************************
524 Creates a JVM. Called by JNI_CreateJavaVM.
526 *******************************************************************************/
528 bool vm_create(JavaVMInitArgs *vm_args)
537 #if defined(ENABLE_JVMTI)
539 char *libname, *agentarg;
540 bool jdwp,agentbypath;
541 jdwp = agentbypath = false;
544 /* check the JNI version requested */
546 switch (vm_args->version) {
547 case JNI_VERSION_1_1:
549 case JNI_VERSION_1_2:
550 case JNI_VERSION_1_4:
556 /* we only support 1 JVM instance */
561 /* get stuff from the environment *****************************************/
563 #if defined(DISABLE_GC)
564 nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
567 /* set the bootclasspath */
569 cp = getenv("BOOTCLASSPATH");
572 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
573 strcpy(bootclasspath, cp);
576 cplen = strlen(CACAO_VM_ZIP) +
578 strlen(CLASSPATH_GLIBJ_ZIP) +
581 bootclasspath = MNEW(char, cplen);
582 strcat(bootclasspath, CACAO_VM_ZIP);
583 strcat(bootclasspath, ":");
584 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP);
587 /* set the classpath */
589 cp = getenv("CLASSPATH");
592 classpath = MNEW(char, strlen(cp) + strlen("0"));
593 strcat(classpath, cp);
596 classpath = MNEW(char, strlen(".") + strlen("0"));
597 strcpy(classpath, ".");
601 /* interpret the options **************************************************/
609 opt_heapmaxsize = HEAP_MAXSIZE;
610 opt_heapstartsize = HEAP_STARTSIZE;
611 opt_stacksize = STACK_SIZE;
614 #if defined(ENABLE_JVMTI)
615 /* initialize JVMTI related **********************************************/
619 /* initialize properties before commandline handling */
621 if (!properties_init())
622 throw_cacao_exception_exit(string_java_lang_InternalError,
623 "Unable to init properties");
625 /* add some default properties */
627 properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
630 /* iterate over all passed options */
632 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
642 #if SIZEOF_VOID_P == 8
643 puts("Running a 32-bit JVM is not supported on this platform.");
649 #if SIZEOF_VOID_P == 4
650 puts("Running a 64-bit JVM is not supported on this platform.");
656 /* forget old classpath and set the argument as new classpath */
657 MFREE(classpath, char, strlen(classpath));
659 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
660 strcpy(classpath, opt_arg);
664 for (j = 0; j < strlen(opt_arg); j++) {
665 if (opt_arg[j] == '=') {
667 properties_add(opt_arg, opt_arg + j + 1);
672 /* if no '=' is given, just create an empty property */
674 properties_add(opt_arg, "");
679 case OPT_BOOTCLASSPATH:
680 /* Forget default bootclasspath and set the argument as
681 new boot classpath. */
683 MFREE(bootclasspath, char, strlen(bootclasspath));
685 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
686 strcpy(bootclasspath, opt_arg);
689 case OPT_BOOTCLASSPATH_A:
690 /* append to end of bootclasspath */
692 cplen = strlen(bootclasspath);
694 bootclasspath = MREALLOC(bootclasspath,
697 cplen + strlen(":") +
698 strlen(opt_arg) + strlen("0"));
700 strcat(bootclasspath, ":");
701 strcat(bootclasspath, opt_arg);
704 case OPT_BOOTCLASSPATH_P:
705 /* prepend in front of bootclasspath */
710 bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
711 cplen + strlen("0"));
713 strcpy(bootclasspath, opt_arg);
714 strcat(bootclasspath, ":");
715 strcat(bootclasspath, cp);
717 MFREE(cp, char, cplen);
721 /* use as Java core library, but prepend VM interface classes */
723 MFREE(bootclasspath, char, strlen(bootclasspath));
725 cplen = strlen(CACAO_VM_ZIP) +
730 bootclasspath = MNEW(char, cplen);
732 strcpy(bootclasspath, CACAO_VM_ZIP);
733 strcat(bootclasspath, ":");
734 strcat(bootclasspath, opt_arg);
737 #if defined(ENABLE_JVMTI)
739 /* this option exists only for compatibility reasons */
742 /* I don't know yet what Xnoagent should do. This is only for
743 compatiblity with eclipse - motse */
746 agentbypath=jvmti=jdwp=true;
747 i = strlen(opt_arg)+33;
748 agentarg = MNEW(char,i);
749 /* XXX how can I get the <prefix>/lib directory ? */
750 snprintf(agentarg,i,"/usr/local/cacao/lib/libjdwp.so=%s",&opt_arg[1]);
765 c = opt_arg[strlen(opt_arg) - 1];
767 if ((c == 'k') || (c == 'K')) {
768 j = atoi(opt_arg) * 1024;
770 } else if ((c == 'm') || (c == 'M')) {
771 j = atoi(opt_arg) * 1024 * 1024;
778 else if (opt == OPT_MS)
779 opt_heapstartsize = j;
790 if (strcmp("class", opt_arg) == 0)
791 opt_verboseclass = true;
793 else if (strcmp("gc", opt_arg) == 0)
794 opt_verbosegc = true;
796 else if (strcmp("jni", opt_arg) == 0)
797 opt_verbosejni = true;
799 else if (strcmp("call", opt_arg) == 0)
800 opt_verbosecall = true;
802 else if (strcmp("jit", opt_arg) == 0) {
807 compileverbose = true;
809 else if (strcmp("exception", opt_arg) == 0)
810 opt_verboseexception = true;
813 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
815 opt_typecheckverbose = true;
824 case OPT_FULLVERSION:
828 case OPT_SHOWVERSION:
836 #if defined(ENABLE_VERIFIER)
846 #if defined(ENABLE_STATISTICS)
848 opt_getcompilingtime = true;
849 opt_getloadingtime = true;
862 for (j = 0; j < strlen(opt_arg); j++) {
863 switch (opt_arg[j]) {
878 makeinitializations = false;
887 opt_method = opt_arg;
888 makeinitializations = false;
892 opt_signature = opt_arg;
898 makeinitializations = false;
901 case OPT_SHOW: /* Display options */
902 for (j = 0; j < strlen(opt_arg); j++) {
903 switch (opt_arg[j]) {
905 opt_showdisassemble = true;
906 compileverbose = true;
909 showconstantpool = true;
912 opt_showddatasegment = true;
915 opt_showexceptionstubs = true;
918 opt_showintermediate = true;
919 compileverbose = true;
925 opt_shownativestub = true;
936 #if defined(ENABLE_LOOP)
942 #if defined(ENABLE_INLINING)
944 for (j = 0; j < strlen(opt_arg); j++) {
945 switch (opt_arg[j]) {
947 /* define in options.h; Used in main.c, jit.c
948 & inline.c inlining is currently
952 inlinevirtuals = true;
955 inlineexceptions = true;
958 inlineparamopt = true;
961 inlineoutsiders = true;
968 #endif /* defined(ENABLE_INLINING) */
970 #if defined(ENABLE_IFCONV)
976 #if defined(ENABLE_LSRA)
990 case OPT_PROF_OPTION:
991 /* use <= to get the last \0 too */
993 for (j = 0, k = 0; j <= strlen(opt_arg); j++) {
994 if (opt_arg[j] == ',')
997 if (opt_arg[j] == '\0') {
998 if (strcmp("bb", opt_arg + k) == 0)
1002 printf("Unknown option: -Xprof:%s\n", opt_arg + k);
1006 /* set k to next char */
1018 #if defined(ENABLE_JIT)
1021 printf("-Xjit option not enabled.\n");
1027 #if defined(ENABLE_INTRP)
1030 printf("-Xint option not enabled.\n");
1035 #if defined(ENABLE_INTRP)
1036 case OPT_STATIC_SUPERS:
1037 opt_static_supers = atoi(opt_arg);
1040 case OPT_NO_DYNAMIC:
1041 opt_no_dynamic = true;
1044 case OPT_NO_REPLICATION:
1045 opt_no_replication = true;
1048 case OPT_NO_QUICKSUPER:
1049 opt_no_quicksuper = true;
1058 printf("Unknown option: %s\n",
1059 vm_args->options[opt_index].optionString);
1065 /* Now we have all options handled and we can print the version
1072 /* get the main class *****************************************************/
1074 if (opt_index < vm_args->nOptions) {
1075 mainstring = vm_args->options[opt_index++].optionString;
1077 /* Put the jar file into the classpath (if any). */
1079 if (opt_jar == true) {
1080 /* free old classpath */
1082 MFREE(classpath, char, strlen(classpath));
1084 /* put jarfile into classpath */
1086 classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1088 strcpy(classpath, mainstring);
1091 /* replace .'s with /'s in classname */
1093 for (i = strlen(mainstring) - 1; i >= 0; i--)
1094 if (mainstring[i] == '.')
1095 mainstring[i] = '/';
1099 #if defined(ENABLE_JVMTI)
1101 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1102 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1103 if (jdwp) MFREE(agentarg,char,strlen(agentarg));
1104 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1110 /* initialize this JVM ****************************************************/
1112 vm_initializing = true;
1114 /* initialize the garbage collector */
1116 gc_init(opt_heapmaxsize, opt_heapstartsize);
1118 #if defined(ENABLE_INTRP)
1119 /* Allocate main thread stack on the Java heap. */
1122 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1123 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1127 #if defined(ENABLE_THREADS)
1131 /* initialize the string hashtable stuff: lock (must be done
1132 _after_ threads_preinit) */
1135 throw_main_exception_exit();
1137 /* initialize the utf8 hashtable stuff: lock, often used utf8
1138 strings (must be done _after_ threads_preinit) */
1141 throw_main_exception_exit();
1143 /* initialize the classcache hashtable stuff: lock, hashtable
1144 (must be done _after_ threads_preinit) */
1146 if (!classcache_init())
1147 throw_main_exception_exit();
1149 /* initialize the loader with bootclasspath (must be done _after_
1153 throw_main_exception_exit();
1155 suck_add_from_property("java.endorsed.dirs");
1156 suck_add(bootclasspath);
1158 /* initialize the memory subsystem (must be done _after_
1162 throw_main_exception_exit();
1164 /* initialize the finalizer stuff (must be done _after_
1167 if (!finalizer_init())
1168 throw_main_exception_exit();
1170 /* install architecture dependent signal handler used for exceptions */
1174 /* initialize the codegen subsystems */
1178 /* initializes jit compiler */
1182 /* machine dependent initialization */
1184 #if defined(ENABLE_JIT)
1185 # if defined(ENABLE_INTRP)
1195 /* initialize the loader subsystems (must be done _after_
1199 throw_main_exception_exit();
1202 throw_main_exception_exit();
1205 throw_main_exception_exit();
1207 if (!exceptions_init())
1208 throw_main_exception_exit();
1210 if (!builtin_init())
1211 throw_main_exception_exit();
1213 /* Initialize the JNI subsystem (must be done _before_
1214 threads_init, as threads_init can call JNI methods
1215 (e.g. NewGlobalRef). */
1218 throw_main_exception_exit();
1220 #if defined(ENABLE_THREADS)
1221 if (!threads_init())
1222 throw_main_exception_exit();
1225 /* That's important, otherwise we get into trouble, if the Runtime
1226 static initializer is called before (circular dependency. This
1227 is with classpath 0.09. Another important thing is, that this
1228 has to happen after initThreads!!! */
1230 if (!initialize_class(class_java_lang_System))
1231 throw_main_exception_exit();
1233 #if defined(ENABLE_PROFILING)
1234 /* initialize profiling */
1236 if (!profile_init())
1237 throw_main_exception_exit();
1240 #if defined(ENABLE_THREADS)
1241 /* finally, start the finalizer thread */
1243 if (!finalizer_start_thread())
1244 throw_main_exception_exit();
1246 /* start the profile sampling thread */
1248 /* if (!profile_start_thread()) */
1249 /* throw_main_exception_exit(); */
1252 #if defined(ENABLE_JVMTI)
1254 /* add agent library to native library hashtable */
1255 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1259 /* increment the number of VMs */
1263 /* initialization is done */
1265 vm_initializing = false;
1267 /* everything's ok */
1273 /* vm_destroy ******************************************************************
1275 Unloads a Java VM and reclaims its resources.
1277 *******************************************************************************/
1279 s4 vm_destroy(JavaVM *vm)
1281 #if defined(ENABLE_THREADS)
1282 threads_join_all_threads();
1285 /* everything's ok */
1291 /* vm_exit *********************************************************************
1293 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1295 *******************************************************************************/
1297 void vm_exit(s4 status)
1301 /* signal that we are exiting */
1305 assert(class_java_lang_System);
1306 assert(class_java_lang_System->state & CLASS_LOADED);
1308 #if defined(ENABLE_JVMTI)
1309 if (jvmti || (dbgcom!=NULL)) {
1310 jvmti_set_phase(JVMTI_PHASE_DEAD);
1311 if (jvmti) jvmti_agentunload();
1315 if (!link_class(class_java_lang_System))
1316 throw_main_exception_exit();
1318 /* call java.lang.System.exit(I)V */
1320 m = class_resolveclassmethod(class_java_lang_System,
1321 utf_new_char("exit"),
1323 class_java_lang_Object,
1327 throw_main_exception_exit();
1329 /* call the exit function with passed exit status */
1331 (void) vm_call_method(m, NULL, status);
1333 /* If we had an exception, just ignore the exception and exit with
1336 vm_shutdown(status);
1340 /* vm_shutdown *****************************************************************
1342 Terminates the system immediately without freeing memory explicitly
1343 (to be used only for abnormal termination).
1345 *******************************************************************************/
1347 void vm_shutdown(s4 status)
1350 #if defined(ENABLE_STATISTICS)
1351 || opt_getcompilingtime || opt_stat
1355 log_text("CACAO terminated by shutdown");
1356 dolog("Exit status: %d\n", (s4) status);
1360 #if defined(ENABLE_JVMTI)
1361 /* terminate cacaodbgserver */
1363 pthread_mutex_lock(&dbgcomlock);
1365 pthread_mutex_unlock(&dbgcomlock);
1366 jvmti_cacaodbgserver_quit();
1374 /* vm_exit_handler *************************************************************
1376 The exit_handler function is called upon program termination.
1378 ATTENTION: Don't free system resources here! Some threads may still
1379 be running as this is called from VMRuntime.exit(). The OS does the
1382 *******************************************************************************/
1384 void vm_exit_handler(void)
1386 #if !defined(NDEBUG)
1388 class_showmethods(mainclass);
1390 if (showconstantpool)
1391 class_showconstantpool(mainclass);
1396 # if defined(ENABLE_PROFILING)
1398 profile_printstats();
1400 #endif /* !defined(NDEBUG) */
1402 #if defined(ENABLE_RT_TIMING)
1403 rt_timing_print_time_stats(stderr);
1406 #if defined(ENABLE_CYCLES_STATS)
1407 builtin_print_cycles_stats(stderr);
1408 stacktrace_print_cycles_stats(stderr);
1412 #if defined(ENABLE_STATISTICS)
1413 || opt_getcompilingtime || opt_stat
1417 log_text("CACAO terminated");
1419 #if defined(ENABLE_STATISTICS)
1422 #ifdef TYPECHECK_STATISTICS
1423 typecheck_print_statistics(get_logfile());
1429 if (opt_getcompilingtime)
1431 #endif /* defined(ENABLE_STATISTICS) */
1433 /* vm_print_profile(stderr);*/
1437 /* vm_abort ********************************************************************
1439 Prints an error message and aborts the VM.
1441 *******************************************************************************/
1443 void vm_abort(const char *text, ...)
1447 /* print the log message */
1452 log_vprint(text, ap);
1457 /* now abort the VM */
1463 /* vm_vmargs_from_valist *******************************************************
1467 *******************************************************************************/
1469 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
1470 vm_arg *vmargs, va_list ap)
1472 typedesc *paramtypes;
1475 paramtypes = m->parseddesc->paramtypes;
1477 /* if method is non-static fill first block and skip `this' pointer */
1482 /* the `this' pointer */
1483 vmargs[0].type = TYPE_ADR;
1484 vmargs[0].data.l = (u8) (ptrint) o;
1490 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
1491 switch (paramtypes->decltype) {
1492 /* primitive types */
1493 case PRIMITIVETYPE_BOOLEAN:
1494 case PRIMITIVETYPE_BYTE:
1495 case PRIMITIVETYPE_CHAR:
1496 case PRIMITIVETYPE_SHORT:
1497 case PRIMITIVETYPE_INT:
1498 vmargs[i].type = TYPE_INT;
1499 vmargs[i].data.l = (s8) va_arg(ap, s4);
1502 case PRIMITIVETYPE_LONG:
1503 vmargs[i].type = TYPE_LNG;
1504 vmargs[i].data.l = (s8) va_arg(ap, s8);
1507 case PRIMITIVETYPE_FLOAT:
1508 vmargs[i].type = TYPE_FLT;
1509 #if defined(__ALPHA__)
1510 /* this keeps the assembler function much simpler */
1512 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
1514 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
1518 case PRIMITIVETYPE_DOUBLE:
1519 vmargs[i].type = TYPE_DBL;
1520 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
1524 vmargs[i].type = TYPE_ADR;
1525 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
1532 /* vm_vmargs_from_jvalue *******************************************************
1536 *******************************************************************************/
1538 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
1539 vm_arg *vmargs, jvalue *args)
1541 typedesc *paramtypes;
1545 paramtypes = m->parseddesc->paramtypes;
1547 /* if method is non-static fill first block and skip `this' pointer */
1552 /* the `this' pointer */
1553 vmargs[0].type = TYPE_ADR;
1554 vmargs[0].data.l = (u8) (ptrint) o;
1560 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
1561 switch (paramtypes->decltype) {
1562 /* primitive types */
1563 case PRIMITIVETYPE_BOOLEAN:
1564 case PRIMITIVETYPE_BYTE:
1565 case PRIMITIVETYPE_CHAR:
1566 case PRIMITIVETYPE_SHORT:
1567 case PRIMITIVETYPE_INT:
1568 vmargs[i].type = TYPE_INT;
1569 vmargs[i].data.l = (s8) args[j].i;
1572 case PRIMITIVETYPE_LONG:
1573 vmargs[i].type = TYPE_LNG;
1574 vmargs[i].data.l = (s8) args[j].j;
1577 case PRIMITIVETYPE_FLOAT:
1578 vmargs[i].type = TYPE_FLT;
1579 #if defined(__ALPHA__)
1580 /* this keeps the assembler function much simpler */
1582 vmargs[i].data.d = (jdouble) args[j].f;
1584 vmargs[i].data.f = args[j].f;
1588 case PRIMITIVETYPE_DOUBLE:
1589 vmargs[i].type = TYPE_DBL;
1590 vmargs[i].data.d = args[j].d;
1594 vmargs[i].type = TYPE_ADR;
1595 vmargs[i].data.l = (u8) (ptrint) args[j].l;
1602 /* vm_call_method **************************************************************
1604 Calls a Java method with a variable number of arguments and returns
1607 *******************************************************************************/
1609 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
1612 java_objectheader *ro;
1615 ro = vm_call_method_valist(m, o, ap);
1622 /* vm_call_method_valist *******************************************************
1624 Calls a Java method with a variable number of arguments, passed via
1625 a va_list, and returns an address.
1627 *******************************************************************************/
1629 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
1634 java_objectheader *ro;
1637 /* mark start of dump memory area */
1639 dumpsize = dump_size();
1641 /* get number of Java method arguments */
1643 vmargscount = m->parseddesc->paramcount;
1645 /* allocate vm_arg array */
1647 vmargs = DMNEW(vm_arg, vmargscount);
1649 /* fill the vm_arg array from a va_list */
1651 vm_vmargs_from_valist(m, o, vmargs, ap);
1653 /* call the Java method */
1655 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1657 /* release dump area */
1659 dump_release(dumpsize);
1665 /* vm_call_method_jvalue *******************************************************
1667 Calls a Java method with a variable number of arguments, passed via
1668 a jvalue array, and returns an address.
1670 *******************************************************************************/
1672 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
1677 java_objectheader *ro;
1680 /* mark start of dump memory area */
1682 dumpsize = dump_size();
1684 /* get number of Java method arguments */
1686 vmargscount = m->parseddesc->paramcount;
1688 /* allocate vm_arg array */
1690 vmargs = DMNEW(vm_arg, vmargscount);
1692 /* fill the vm_arg array from a va_list */
1694 vm_vmargs_from_jvalue(m, o, vmargs, args);
1696 /* call the Java method */
1698 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
1700 /* release dump area */
1702 dump_release(dumpsize);
1708 /* vm_call_method_vmarg ********************************************************
1710 Calls a Java method with a variable number of arguments, passed via
1711 a vm_arg array, and returns an address.
1713 *******************************************************************************/
1715 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
1718 java_objectheader *o;
1720 #if defined(ENABLE_JIT)
1721 # if defined(ENABLE_INTRP)
1723 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1726 o = asm_vm_call_method(m, vmargscount, vmargs);
1728 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
1735 /* vm_call_method_int **********************************************************
1737 Calls a Java method with a variable number of arguments and returns
1740 *******************************************************************************/
1742 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
1748 i = vm_call_method_int_valist(m, o, ap);
1755 /* vm_call_method_int_valist ***************************************************
1757 Calls a Java method with a variable number of arguments, passed via
1758 a va_list, and returns an integer (s4).
1760 *******************************************************************************/
1762 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
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_valist(m, o, vmargs, ap);
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_jvalue ***************************************************
1799 Calls a Java method with a variable number of arguments, passed via
1800 a jvalue array, and returns an integer (s4).
1802 *******************************************************************************/
1804 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1811 /* mark start of dump memory area */
1813 dumpsize = dump_size();
1815 /* get number of Java method arguments */
1817 vmargscount = m->parseddesc->paramcount;
1819 /* allocate vm_arg array */
1821 vmargs = DMNEW(vm_arg, vmargscount);
1823 /* fill the vm_arg array from a va_list */
1825 vm_vmargs_from_jvalue(m, o, vmargs, args);
1827 /* call the Java method */
1829 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
1831 /* release dump area */
1833 dump_release(dumpsize);
1839 /* vm_call_method_int_vmarg ****************************************************
1841 Calls a Java method with a variable number of arguments, passed via
1842 a vm_arg array, and returns an integer (s4).
1844 *******************************************************************************/
1846 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1850 #if defined(ENABLE_JIT)
1851 # if defined(ENABLE_INTRP)
1853 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1856 i = asm_vm_call_method_int(m, vmargscount, vmargs);
1858 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
1865 /* vm_call_method_long *********************************************************
1867 Calls a Java method with a variable number of arguments and returns
1870 *******************************************************************************/
1872 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
1878 l = vm_call_method_long_valist(m, o, ap);
1885 /* vm_call_method_long_valist **************************************************
1887 Calls a Java method with a variable number of arguments, passed via
1888 a va_list, and returns a long (s8).
1890 *******************************************************************************/
1892 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
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_valist(m, o, vmargs, ap);
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_jvalue **************************************************
1929 Calls a Java method with a variable number of arguments, passed via
1930 a jvalue array, and returns a long (s8).
1932 *******************************************************************************/
1934 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
1941 /* mark start of dump memory area */
1943 dumpsize = dump_size();
1945 /* get number of Java method arguments */
1947 vmargscount = m->parseddesc->paramcount;
1949 /* allocate vm_arg array */
1951 vmargs = DMNEW(vm_arg, vmargscount);
1953 /* fill the vm_arg array from a va_list */
1955 vm_vmargs_from_jvalue(m, o, vmargs, args);
1957 /* call the Java method */
1959 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
1961 /* release dump area */
1963 dump_release(dumpsize);
1969 /* vm_call_method_long_vmarg ***************************************************
1971 Calls a Java method with a variable number of arguments, passed via
1972 a vm_arg array, and returns a long (s8).
1974 *******************************************************************************/
1976 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
1980 #if defined(ENABLE_JIT)
1981 # if defined(ENABLE_INTRP)
1983 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1986 l = asm_vm_call_method_long(m, vmargscount, vmargs);
1988 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
1995 /* vm_call_method_float ********************************************************
1997 Calls a Java method with a variable number of arguments and returns
2000 *******************************************************************************/
2002 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2008 f = vm_call_method_float_valist(m, o, ap);
2015 /* vm_call_method_float_valist *************************************************
2017 Calls a Java method with a variable number of arguments, passed via
2018 a va_list, and returns a float.
2020 *******************************************************************************/
2022 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2030 /* mark start of dump memory area */
2032 dumpsize = dump_size();
2034 /* get number of Java method arguments */
2036 vmargscount = m->parseddesc->paramcount;
2038 /* allocate vm_arg array */
2040 vmargs = DMNEW(vm_arg, vmargscount);
2042 /* fill the vm_arg array from a va_list */
2044 vm_vmargs_from_valist(m, o, vmargs, ap);
2046 /* call the Java method */
2048 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2050 /* release dump area */
2052 dump_release(dumpsize);
2058 /* vm_call_method_float_jvalue *************************************************
2060 Calls a Java method with a variable number of arguments, passed via
2061 a jvalue array, and returns a float.
2063 *******************************************************************************/
2065 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2073 /* mark start of dump memory area */
2075 dumpsize = dump_size();
2077 /* get number of Java method arguments */
2079 vmargscount = m->parseddesc->paramcount;
2081 /* allocate vm_arg array */
2083 vmargs = DMNEW(vm_arg, vmargscount);
2085 /* fill the vm_arg array from a va_list */
2087 vm_vmargs_from_jvalue(m, o, vmargs, args);
2089 /* call the Java method */
2091 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2093 /* release dump area */
2095 dump_release(dumpsize);
2101 /* vm_call_method_float_vmarg **************************************************
2103 Calls a Java method with a variable number of arguments and returns
2106 *******************************************************************************/
2108 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2112 #if defined(ENABLE_JIT)
2113 # if defined(ENABLE_INTRP)
2115 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2118 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2120 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2127 /* vm_call_method_double *******************************************************
2129 Calls a Java method with a variable number of arguments and returns
2132 *******************************************************************************/
2134 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2140 d = vm_call_method_double_valist(m, o, ap);
2147 /* vm_call_method_double_valist ************************************************
2149 Calls a Java method with a variable number of arguments, passed via
2150 a va_list, and returns a double.
2152 *******************************************************************************/
2154 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2162 /* mark start of dump memory area */
2164 dumpsize = dump_size();
2166 /* get number of Java method arguments */
2168 vmargscount = m->parseddesc->paramcount;
2170 /* allocate vm_arg array */
2172 vmargs = DMNEW(vm_arg, vmargscount);
2174 /* fill the vm_arg array from a va_list */
2176 vm_vmargs_from_valist(m, o, vmargs, ap);
2178 /* call the Java method */
2180 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2182 /* release dump area */
2184 dump_release(dumpsize);
2190 /* vm_call_method_double_jvalue ************************************************
2192 Calls a Java method with a variable number of arguments, passed via
2193 a jvalue array, and returns a double.
2195 *******************************************************************************/
2197 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2205 /* mark start of dump memory area */
2207 dumpsize = dump_size();
2209 /* get number of Java method arguments */
2211 vmargscount = m->parseddesc->paramcount;
2213 /* allocate vm_arg array */
2215 vmargs = DMNEW(vm_arg, vmargscount);
2217 /* fill the vm_arg array from a va_list */
2219 vm_vmargs_from_jvalue(m, o, vmargs, args);
2221 /* call the Java method */
2223 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2225 /* release dump area */
2227 dump_release(dumpsize);
2233 /* vm_call_method_double_vmarg *************************************************
2235 Calls a Java method with a variable number of arguments and returns
2238 *******************************************************************************/
2240 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
2245 #if defined(ENABLE_JIT)
2246 # if defined(ENABLE_INTRP)
2248 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2251 d = asm_vm_call_method_double(m, vmargscount, vmargs);
2253 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2261 * These are local overrides for various environment variables in Emacs.
2262 * Please do not remove this and leave it at the end of the file, where
2263 * Emacs will automagically detect them.
2264 * ---------------------------------------------------------------------
2267 * indent-tabs-mode: t