1 /* src/vm/vm.c - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
38 #include "vm/jit/abi-asm.h"
40 #include "mm/codememory.h"
41 #include "mm/gc-common.h"
42 #include "mm/memory.h"
44 #include "native/jni.h"
45 #include "native/llni.h"
46 #include "native/localref.h"
47 #include "native/native.h"
49 #include "native/include/java_lang_Object.h" /* required by j.l.C */
50 #include "native/include/java_lang_String.h" /* required by j.l.C */
52 #if defined(WITH_CLASSPATH_SUN)
53 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
54 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
57 #include "native/include/java_lang_Class.h"
59 #include "native/vm/nativevm.h"
61 #include "threads/lock-common.h"
62 #include "threads/mutex.h"
63 #include "threads/threadlist.h"
64 #include "threads/thread.h"
66 #include "toolbox/logging.h"
70 #if defined(ENABLE_ASSERTION)
71 #include "vm/assertion.h"
74 #include "vm/builtin.h"
75 #include "vm/exceptions.h"
76 #include "vm/finalizer.h"
77 #include "vm/global.h"
78 #include "vm/initialize.h"
79 #include "vm/package.h"
80 #include "vm/primitive.h"
81 #include "vm/properties.h"
82 #include "vm/signallocal.h"
83 #include "vm/stringlocal.h"
86 #include "vm/jit/argument.h"
87 #include "vm/jit/asmpart.h"
88 #include "vm/jit/code.h"
90 #if defined(ENABLE_DISASSEMBLER)
91 # include "vm/jit/disass.h"
94 #include "vm/jit/jit.h"
95 #include "vm/jit/methodtree.h"
97 #if defined(ENABLE_PROFILING)
98 # include "vm/jit/optimizing/profile.h"
101 #include "vm/jit/optimizing/recompile.h"
103 #if defined(ENABLE_PYTHON)
104 # include "vm/jit/python.h"
107 #include "vmcore/classcache.h"
108 #include "vmcore/options.h"
109 #include "vmcore/statistics.h"
110 #include "vmcore/suck.h"
111 #include "vmcore/system.h"
113 #if defined(ENABLE_JVMTI)
114 # include "native/jvmti/cacaodbg.h"
117 #if defined(ENABLE_VMLOG)
118 #include <vmlog_cacao.h>
122 /* Invocation API variables ***************************************************/
124 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
125 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
128 /* global variables ***********************************************************/
130 s4 vms = 0; /* number of VMs created */
132 bool vm_initializing = false;
133 bool vm_created = false;
134 bool vm_exiting = false;
136 char *mainstring = NULL;
137 classinfo *mainclass = NULL;
139 #if defined(ENABLE_INTRP)
140 u1 *intrp_main_stack = NULL;
144 /* define heap sizes **********************************************************/
146 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
147 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
148 #define STACK_SIZE 128 * 1024 /* default 64kB */
151 /* define command line options ************************************************/
185 /* Java non-standard options */
196 #if defined(ENABLE_PROFILING)
209 #if defined(ENABLE_STATISTICS)
226 #if defined(ENABLE_VERIFIER)
228 #if defined(TYPECHECK_VERBOSE)
231 #endif /* defined(ENABLE_VERIFIER) */
233 /* optimization options */
235 #if defined(ENABLE_LOOP)
239 #if defined(ENABLE_IFCONV)
243 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
247 #if defined(ENABLE_INTRP)
248 /* interpreter options */
267 #if defined(ENABLE_DEBUG_FILTER)
268 OPT_FILTER_VERBOSECALL_INCLUDE,
269 OPT_FILTER_VERBOSECALL_EXCLUDE,
270 OPT_FILTER_SHOW_METHOD,
277 opt_struct opts[] = {
278 { "foo", false, OPT_FOO },
282 { "jar", false, OPT_JAR },
284 { "d32", false, OPT_D32 },
285 { "d64", false, OPT_D64 },
286 { "client", false, OPT_IGNORE },
287 { "server", false, OPT_IGNORE },
288 { "jvm", false, OPT_IGNORE },
289 { "hotspot", false, OPT_IGNORE },
291 { "classpath", true, OPT_CLASSPATH },
292 { "cp", true, OPT_CLASSPATH },
293 { "D", true, OPT_D },
294 { "version", false, OPT_VERSION },
295 { "showversion", false, OPT_SHOWVERSION },
296 { "fullversion", false, OPT_FULLVERSION },
297 { "help", false, OPT_HELP },
298 { "?", false, OPT_HELP },
299 { "X", false, OPT_X },
300 { "XX:", true, OPT_XX },
302 { "ea:", true, OPT_EA },
303 { "da:", true, OPT_DA },
304 { "ea", false, OPT_EA_NOARG },
305 { "da", false, OPT_DA_NOARG },
307 { "enableassertions:", true, OPT_EA },
308 { "disableassertions:", true, OPT_DA },
309 { "enableassertions", false, OPT_EA_NOARG },
310 { "disableassertions", false, OPT_DA_NOARG },
312 { "esa", false, OPT_ESA },
313 { "enablesystemassertions", false, OPT_ESA },
314 { "dsa", false, OPT_DSA },
315 { "disablesystemassertions", false, OPT_DSA },
317 { "noasyncgc", false, OPT_IGNORE },
318 #if defined(ENABLE_VERIFIER)
319 { "noverify", false, OPT_NOVERIFY },
320 { "Xverify:none", false, OPT_NOVERIFY },
322 { "v", false, OPT_VERBOSE1 },
323 { "verbose:", true, OPT_VERBOSE },
325 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
326 { "verbosetc", false, OPT_VERBOSETC },
328 #if defined(__ALPHA__)
329 { "noieee", false, OPT_NOIEEE },
331 #if defined(ENABLE_STATISTICS)
332 { "time", false, OPT_TIME },
333 { "stat", false, OPT_STAT },
335 { "log", true, OPT_LOG },
336 { "c", true, OPT_CHECK },
337 { "l", false, OPT_LOAD },
340 { "all", false, OPT_ALL },
341 { "sig", true, OPT_SIGNATURE },
344 #if defined(ENABLE_LOOP)
345 { "oloop", false, OPT_OLOOP },
347 #if defined(ENABLE_IFCONV)
348 { "ifconv", false, OPT_IFCONV },
350 #if defined(ENABLE_LSRA)
351 { "lsra", false, OPT_LSRA },
353 #if defined(ENABLE_SSA)
354 { "lsra", true, OPT_LSRA },
357 #if defined(ENABLE_INTRP)
358 /* interpreter options */
360 { "trace", false, OPT_TRACE },
361 { "static-supers", true, OPT_STATIC_SUPERS },
362 { "no-dynamic", false, OPT_NO_DYNAMIC },
363 { "no-replication", false, OPT_NO_REPLICATION },
364 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
367 /* JVMTI Agent Command Line Options */
369 { "agentlib:", true, OPT_AGENTLIB },
370 { "agentpath:", true, OPT_AGENTPATH },
373 /* Java non-standard options */
375 { "Xjit", false, OPT_JIT },
376 { "Xint", false, OPT_INTRP },
377 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
378 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
379 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
380 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
383 { "Xdebug", false, OPT_DEBUG },
384 { "Xnoagent", false, OPT_NOAGENT },
385 { "Xrunjdwp", true, OPT_XRUNJDWP },
388 { "Xms", true, OPT_MS },
389 { "ms", true, OPT_MS },
390 { "Xmx", true, OPT_MX },
391 { "mx", true, OPT_MX },
392 { "Xss", true, OPT_SS },
393 { "ss", true, OPT_SS },
395 #if defined(ENABLE_PROFILING)
396 { "Xprof:", true, OPT_PROF_OPTION },
397 { "Xprof", false, OPT_PROF },
400 /* keep these at the end of the list */
403 { "m", true, OPT_METHOD },
406 { "s", true, OPT_SHOW },
407 { "debug-color", false, OPT_DEBUGCOLOR },
409 #if defined(ENABLE_DEBUG_FILTER)
410 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
411 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
412 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
419 /* usage ***********************************************************************
421 Prints the correct usage syntax to stdout.
423 *******************************************************************************/
427 puts("Usage: cacao [-options] classname [arguments]");
428 puts(" (to run a class file)");
429 puts(" or cacao [-options] -jar jarfile [arguments]");
430 puts(" (to run a standalone jar file)\n");
432 puts("where options include:");
433 puts(" -d32 use 32-bit data model if available");
434 puts(" -d64 use 64-bit data model if available");
435 puts(" -client compatibility (currently ignored)");
436 puts(" -server compatibility (currently ignored)");
437 puts(" -jvm compatibility (currently ignored)");
438 puts(" -hotspot compatibility (currently ignored)\n");
440 puts(" -cp <path> specify a path to look for classes");
441 puts(" -classpath <path> specify a path to look for classes");
442 puts(" -D<name>=<value> add an entry to the property list");
443 puts(" -verbose[:class|gc|jni] enable specific verbose output");
444 puts(" -version print product version and exit");
445 puts(" -fullversion print jpackage-compatible product version and exit");
446 puts(" -showversion print product version and continue");
447 puts(" -help, -? print this help message");
448 puts(" -X print help on non-standard Java options");
449 puts(" -XX print help on debugging options");
450 puts(" -ea[:<packagename>...|:<classname>]");
451 puts(" -enableassertions[:<packagename>...|:<classname>]");
452 puts(" enable assertions with specified granularity");
453 puts(" -da[:<packagename>...|:<classname>]");
454 puts(" -disableassertions[:<packagename>...|:<classname>]");
455 puts(" disable assertions with specified granularity");
456 puts(" -esa | -enablesystemassertions");
457 puts(" enable system assertions");
458 puts(" -dsa | -disablesystemassertions");
459 puts(" disable system assertions");
462 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
463 puts (" for jdwp help use: -agentlib:jdwp=help");
464 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
467 /* exit with error code */
473 static void Xusage(void)
475 #if defined(ENABLE_JIT)
476 puts(" -Xjit JIT mode execution (default)");
478 #if defined(ENABLE_INTRP)
479 puts(" -Xint interpreter mode execution");
481 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
482 puts(" value is set as bootstrap class path");
483 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
484 puts(" value is appended to the bootstrap class path");
485 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
486 puts(" value is prepended to the bootstrap class path");
487 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
488 puts(" value is used as Java core library, but the");
489 puts(" hardcoded VM interface classes are prepended");
490 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
491 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
492 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
494 #if defined(ENABLE_PROFILING)
495 puts(" -Xprof[:bb] collect and print profiling data");
498 #if defined(ENABLE_JVMTI)
499 /* -Xdebug option depend on gnu classpath JDWP options. options:
500 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
501 puts(" -Xdebug enable remote debugging\n");
502 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
503 puts(" enable remote debugging\n");
506 /* exit with error code */
513 static void XXusage(void)
515 puts(" -v write state-information");
517 puts(" -verbose:jit enable specific verbose output");
518 puts(" -debug-color colored output for ANSI terms");
520 #ifdef TYPECHECK_VERBOSE
521 puts(" -verbosetc write debug messages while typechecking");
523 #if defined(__ALPHA__)
524 puts(" -noieee don't use ieee compliant arithmetic");
526 #if defined(ENABLE_VERIFIER)
527 puts(" -noverify don't verify classfiles");
529 #if defined(ENABLE_STATISTICS)
530 puts(" -time measure the runtime");
531 puts(" -stat detailed compiler statistics");
533 puts(" -log logfile specify a name for the logfile");
534 puts(" -c(heck)b(ounds) don't check array bounds");
535 puts(" s(ync) don't check for synchronization");
536 #if defined(ENABLE_LOOP)
537 puts(" -oloop optimize array accesses in loops");
539 puts(" -l don't start the class after loading");
541 puts(" -all compile all methods, no execution");
542 puts(" -m compile only a specific method");
543 puts(" -sig specify signature for a specific method");
546 puts(" -s... show...");
547 puts(" (c)onstants the constant pool");
548 puts(" (m)ethods class fields and methods");
549 puts(" (u)tf the utf - hash");
550 puts(" (i)ntermediate intermediate representation");
551 #if defined(ENABLE_DISASSEMBLER)
552 puts(" (a)ssembler disassembled listing");
553 puts(" n(o)ps show NOPs in disassembler output");
555 puts(" (d)atasegment data segment listing");
557 #if defined(ENABLE_IFCONV)
558 puts(" -ifconv use if-conversion");
560 #if defined(ENABLE_LSRA)
561 puts(" -lsra use linear scan register allocation");
563 #if defined(ENABLE_SSA)
564 puts(" -lsra:... use linear scan register allocation (with SSA)");
565 puts(" (d)ead code elimination");
566 puts(" (c)opy propagation");
568 #if defined(ENABLE_DEBUG_FILTER)
569 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
570 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
571 puts(" -XXfm <regex> filter for show options");
573 /* exit with error code */
580 /* version *********************************************************************
582 Only prints cacao version information.
584 *******************************************************************************/
586 static void version(bool opt_exit)
588 puts("java version \""JAVA_VERSION"\"");
589 puts("CACAO version "VERSION"\n");
591 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
592 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
593 puts("This is free software; see the source for copying conditions. There is NO");
594 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
596 /* exit normally, if requested */
603 /* fullversion *****************************************************************
605 Prints a Sun compatible version information (required e.g. by
606 jpackage, www.jpackage.org).
608 *******************************************************************************/
610 static void fullversion(void)
612 puts("java full version \"cacao-"JAVA_VERSION"\"");
620 static void vm_printconfig(void)
622 puts("Configure/Build options:\n");
623 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
624 #if defined(__VERSION__)
625 puts(" CC : "VERSION_CC" ("__VERSION__")");
627 puts(" CC : "VERSION_CC"");
629 puts(" CFLAGS : "VERSION_CFLAGS"\n");
631 puts("Default variables:\n");
632 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
633 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
634 printf(" stack size : %d\n", STACK_SIZE);
636 #if defined(WITH_JRE_LAYOUT)
637 /* When we're building with JRE-layout, the default paths are the
638 same as the runtime paths. */
640 # if defined(WITH_CLASSPATH_GNU)
641 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
642 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
643 # elif defined(WITH_CLASSPATH_SUN)
644 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
645 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
651 puts("Runtime variables:\n");
652 printf(" maximum heap size : %d\n", opt_heapmaxsize);
653 printf(" initial heap size : %d\n", opt_heapstartsize);
654 printf(" stack size : %d\n", opt_stacksize);
656 #if defined(WITH_CLASSPATH_GNU)
657 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
658 #elif defined(WITH_CLASSPATH_SUN)
659 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
662 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
663 printf(" java.class.path : %s\n", properties_get("java.class.path"));
667 /* forward declarations *******************************************************/
669 static char *vm_get_mainclass_from_jar(char *mainstring);
671 static void vm_compile_all(void);
672 static void vm_compile_method(void);
676 /* vm_createjvm ****************************************************************
678 Implementation for JNI_CreateJavaVM.
680 *******************************************************************************/
682 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
684 JavaVMInitArgs *_vm_args;
688 /* get the arguments for the new JVM */
690 _vm_args = (JavaVMInitArgs *) vm_args;
692 /* get the VM and Env tables (must be set before vm_create) */
694 env = NEW(_Jv_JNIEnv);
696 #if defined(ENABLE_JNI)
697 env->env = &_Jv_JNINativeInterface;
700 /* XXX Set the global variable. Maybe we should do that differently. */
704 /* create and fill a JavaVM structure */
706 vm = NEW(_Jv_JavaVM);
708 #if defined(ENABLE_JNI)
709 vm->functions = &_Jv_JNIInvokeInterface;
712 /* XXX Set the global variable. Maybe we should do that differently. */
713 /* XXX JVMTI Agents needs a JavaVM */
717 /* actually create the JVM */
719 if (!vm_create(_vm_args))
722 /* now return the values */
724 *p_vm = (JavaVM *) vm;
725 *p_env = (void *) env;
730 /* release allocated memory */
732 FREE(env, _Jv_JNIEnv);
733 FREE(vm, _Jv_JavaVM);
739 /* vm_create *******************************************************************
741 Creates a JVM. Called by vm_createjvm.
743 *******************************************************************************/
745 bool vm_create(JavaVMInitArgs *vm_args)
749 char *boot_class_path;
756 #if defined(ENABLE_JVMTI)
758 char *libname, *agentarg;
759 bool jdwp,agentbypath;
760 jdwp = agentbypath = false;
763 #if defined(ENABLE_JNI)
764 /* Check the JNI version requested. */
766 if (!jni_version_check(vm_args->version))
770 /* We only support 1 JVM instance. */
775 /* Install the exit handler. */
777 if (atexit(vm_exit_handler))
778 vm_abort("atexit failed: %s\n", strerror(errno));
780 /* Set some options. */
787 opt_heapmaxsize = HEAP_MAXSIZE;
788 opt_heapstartsize = HEAP_STARTSIZE;
789 opt_stacksize = STACK_SIZE;
791 /* Initialize the properties list before command-line handling.
792 Otherwise -XX:+PrintConfig crashes. */
796 /* First of all, parse the -XX options. */
798 #if defined(ENABLE_VMLOG)
799 vmlog_cacao_init_options();
804 #if defined(ENABLE_VMLOG)
808 /* We need to check if the actual size of a java.lang.Class object
809 is smaller or equal than the assumption made in
810 src/vmcore/class.h. */
812 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
813 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
815 /* set the VM starttime */
817 _Jv_jvm->starttime = builtin_currenttimemillis();
819 #if defined(ENABLE_JVMTI)
820 /* initialize JVMTI related **********************************************/
824 /* Fill the properties before command-line handling. */
828 /* iterate over all passed options */
830 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
844 #if SIZEOF_VOID_P == 8
845 puts("Running a 32-bit JVM is not supported on this platform.");
851 #if SIZEOF_VOID_P == 4
852 puts("Running a 64-bit JVM is not supported on this platform.");
858 /* Forget old classpath and set the argument as new
861 class_path = properties_get("java.class.path");
863 p = MNEW(char, strlen(opt_arg) + strlen("0"));
867 #if defined(ENABLE_JAVASE)
868 properties_add("java.class.path", p);
871 MFREE(class_path, char, strlen(class_path));
875 for (i = 0; i < strlen(opt_arg); i++) {
876 if (opt_arg[i] == '=') {
878 properties_add(opt_arg, opt_arg + i + 1);
883 /* if no '=' is given, just create an empty property */
885 properties_add(opt_arg, "");
890 case OPT_BOOTCLASSPATH:
891 /* Forget default bootclasspath and set the argument as
892 new boot classpath. */
894 boot_class_path = properties_get("sun.boot.class.path");
896 p = MNEW(char, strlen(opt_arg) + strlen("0"));
900 properties_add("sun.boot.class.path", p);
901 properties_add("java.boot.class.path", p);
903 MFREE(boot_class_path, char, strlen(boot_class_path));
906 case OPT_BOOTCLASSPATH_A:
907 /* Append to bootclasspath. */
909 boot_class_path = properties_get("sun.boot.class.path");
911 len = strlen(boot_class_path);
913 p = MREALLOC(boot_class_path,
917 strlen(opt_arg) + strlen("0"));
922 properties_add("sun.boot.class.path", p);
923 properties_add("java.boot.class.path", p);
926 case OPT_BOOTCLASSPATH_P:
927 /* Prepend to bootclasspath. */
929 boot_class_path = properties_get("sun.boot.class.path");
931 len = strlen(boot_class_path);
933 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
937 strcat(p, boot_class_path);
939 properties_add("sun.boot.class.path", p);
940 properties_add("java.boot.class.path", p);
942 MFREE(boot_class_path, char, len);
945 case OPT_BOOTCLASSPATH_C:
946 /* Use as Java core library, but prepend VM interface
949 boot_class_path = properties_get("sun.boot.class.path");
952 strlen(CACAO_VM_ZIP) +
959 strcpy(p, CACAO_VM_ZIP);
963 properties_add("sun.boot.class.path", p);
964 properties_add("java.boot.class.path", p);
966 MFREE(boot_class_path, char, strlen(boot_class_path));
969 #if defined(ENABLE_JVMTI)
971 /* this option exists only for compatibility reasons */
975 /* I don't know yet what Xnoagent should do. This is only for
976 compatiblity with eclipse - motse */
985 strlen(CACAO_LIBDIR) +
986 strlen("/libjdwp.so=") +
990 agentarg = MNEW(char, len);
992 strcpy(agentarg, CACAO_LIBDIR);
993 strcat(agentarg, "/libjdwp.so=");
994 strcat(agentarg, &opt_arg[1]);
1011 c = opt_arg[strlen(opt_arg) - 1];
1013 if ((c == 'k') || (c == 'K')) {
1014 j = atoi(opt_arg) * 1024;
1016 } else if ((c == 'm') || (c == 'M')) {
1017 j = atoi(opt_arg) * 1024 * 1024;
1023 opt_heapmaxsize = j;
1024 else if (opt == OPT_MS)
1025 opt_heapstartsize = j;
1036 if (strcmp("class", opt_arg) == 0) {
1037 opt_verboseclass = true;
1039 else if (strcmp("gc", opt_arg) == 0) {
1040 opt_verbosegc = true;
1042 else if (strcmp("jni", opt_arg) == 0) {
1043 opt_verbosejni = true;
1045 #if !defined(NDEBUG)
1046 else if (strcmp("jit", opt_arg) == 0) {
1050 compileverbose = true;
1054 printf("Unknown -verbose option: %s\n", opt_arg);
1059 case OPT_DEBUGCOLOR:
1060 opt_debugcolor = true;
1063 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1065 opt_typecheckverbose = true;
1074 case OPT_FULLVERSION:
1078 case OPT_SHOWVERSION:
1086 #if defined(ENABLE_VERIFIER)
1092 #if defined(ENABLE_STATISTICS)
1094 opt_getcompilingtime = true;
1095 opt_getloadingtime = true;
1108 for (i = 0; i < strlen(opt_arg); i++) {
1109 switch (opt_arg[i]) {
1111 checkbounds = false;
1124 makeinitializations = false;
1127 #if !defined(NDEBUG)
1131 makeinitializations = false;
1136 opt_method = opt_arg;
1137 makeinitializations = false;
1141 opt_signature = opt_arg;
1145 case OPT_SHOW: /* Display options */
1146 for (i = 0; i < strlen(opt_arg); i++) {
1147 switch (opt_arg[i]) {
1149 showconstantpool = true;
1161 opt_showintermediate = true;
1162 compileverbose = true;
1165 #if defined(ENABLE_DISASSEMBLER)
1167 opt_showdisassemble = true;
1168 compileverbose = true;
1172 opt_shownops = true;
1177 opt_showddatasegment = true;
1186 #if defined(ENABLE_LOOP)
1192 #if defined(ENABLE_IFCONV)
1198 #if defined(ENABLE_LSRA)
1203 #if defined(ENABLE_SSA)
1206 for (i = 0; i < strlen(opt_arg); i++) {
1207 switch (opt_arg[i]) {
1235 /* Already parsed. */
1239 #if defined(ENABLE_ASSERTION)
1240 assertion_ea_da(opt_arg, true);
1245 #if defined(ENABLE_ASSERTION)
1246 assertion_ea_da(opt_arg, false);
1251 #if defined(ENABLE_ASSERTION)
1252 assertion_user_enabled = true;
1257 #if defined(ENABLE_ASSERTION)
1258 assertion_user_enabled = false;
1263 #if defined(ENABLE_ASSERTION)
1264 assertion_system_enabled = true;
1269 #if defined(ENABLE_ASSERTION)
1270 assertion_system_enabled = false;
1274 #if defined(ENABLE_PROFILING)
1275 case OPT_PROF_OPTION:
1276 /* use <= to get the last \0 too */
1278 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1279 if (opt_arg[i] == ',')
1282 if (opt_arg[i] == '\0') {
1283 if (strcmp("bb", opt_arg + j) == 0)
1287 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1291 /* set k to next char */
1304 #if defined(ENABLE_JIT)
1307 printf("-Xjit option not enabled.\n");
1313 #if defined(ENABLE_INTRP)
1316 printf("-Xint option not enabled.\n");
1321 #if defined(ENABLE_INTRP)
1322 case OPT_STATIC_SUPERS:
1323 opt_static_supers = atoi(opt_arg);
1326 case OPT_NO_DYNAMIC:
1327 opt_no_dynamic = true;
1330 case OPT_NO_REPLICATION:
1331 opt_no_replication = true;
1334 case OPT_NO_QUICKSUPER:
1335 opt_no_quicksuper = true;
1343 #if defined(ENABLE_DEBUG_FILTER)
1344 case OPT_FILTER_VERBOSECALL_INCLUDE:
1345 opt_filter_verbosecall_include = opt_arg;
1348 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1349 opt_filter_verbosecall_exclude = opt_arg;
1352 case OPT_FILTER_SHOW_METHOD:
1353 opt_filter_show_method = opt_arg;
1358 printf("Unknown option: %s\n",
1359 vm_args->options[opt_index].optionString);
1364 /* get the main class *****************************************************/
1366 if (opt_index < vm_args->nOptions) {
1367 mainstring = vm_args->options[opt_index++].optionString;
1369 /* Put the jar file into the classpath (if any). */
1371 if (opt_jar == true) {
1372 /* free old classpath */
1374 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1376 /* put jarfile into classpath */
1378 p = MNEW(char, strlen(mainstring) + strlen("0"));
1380 strcpy(p, mainstring);
1382 #if defined(ENABLE_JAVASE)
1383 properties_add("java.class.path", p);
1387 /* replace .'s with /'s in classname */
1389 for (i = strlen(mainstring) - 1; i >= 0; i--)
1390 if (mainstring[i] == '.')
1391 mainstring[i] = '/';
1395 #if defined(ENABLE_JVMTI)
1397 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1398 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1401 MFREE(agentarg, char, strlen(agentarg));
1403 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1407 /* initialize this JVM ****************************************************/
1409 vm_initializing = true;
1411 /* initialize the garbage collector */
1413 gc_init(opt_heapmaxsize, opt_heapstartsize);
1415 #if defined(ENABLE_THREADS)
1416 /* BEFORE: threads_preinit */
1420 /* AFTER: gc_init (directly after, as this initializes the
1421 stopworldlock lock */
1428 /* install architecture dependent signal handlers */
1431 vm_abort("vm_create: signal_init failed");
1433 #if defined(ENABLE_INTRP)
1434 /* Allocate main thread stack on the Java heap. */
1437 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1438 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1442 /* AFTER: threads_preinit */
1445 vm_abort("vm_create: string_init failed");
1447 /* AFTER: threads_preinit */
1451 /* AFTER: thread_preinit */
1454 vm_abort("vm_create: suck_init failed");
1456 suck_add_from_property("java.endorsed.dirs");
1458 /* Now we have all options handled and we can print the version
1461 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1466 /* AFTER: utf8_init */
1468 boot_class_path = properties_get("sun.boot.class.path");
1469 suck_add(boot_class_path);
1471 /* initialize the classcache hashtable stuff: lock, hashtable
1472 (must be done _after_ threads_preinit) */
1474 if (!classcache_init())
1475 vm_abort("vm_create: classcache_init failed");
1477 /* Initialize the code memory management. */
1478 /* AFTER: threads_preinit */
1482 /* initialize the finalizer stuff (must be done _after_
1485 if (!finalizer_init())
1486 vm_abort("vm_create: finalizer_init failed");
1488 /* Initialize the JIT compiler. */
1494 #if defined(ENABLE_PYTHON)
1498 /* BEFORE: loader_preinit */
1502 /* AFTER: utf8_init, classcache_init */
1507 /* AFTER: loader_preinit, linker_preinit */
1514 /* AFTER: loader_init, linker_init */
1516 primitive_postinit();
1521 if (!builtin_init())
1522 vm_abort("vm_create: builtin_init failed");
1524 /* Initialize the native subsystem. */
1525 /* BEFORE: threads_init */
1528 vm_abort("vm_create: native_init failed");
1530 /* Register the native methods implemented in the VM. */
1531 /* BEFORE: threads_init */
1535 #if defined(ENABLE_JNI)
1536 /* Initialize the JNI subsystem (must be done _before_
1537 threads_init, as threads_init can call JNI methods
1538 (e.g. NewGlobalRef). */
1541 vm_abort("vm_create: jni_init failed");
1544 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1545 /* Initialize the local reference table for the main thread. */
1546 /* BEFORE: threads_init */
1548 if (!localref_table_init())
1549 vm_abort("vm_create: localref_table_init failed");
1552 /* Iinitialize some important system classes. */
1553 /* BEFORE: threads_init */
1557 #if defined(ENABLE_THREADS)
1561 /* Initialize the native VM subsystem. */
1562 /* AFTER: threads_init (at least for SUN's classes) */
1566 #if defined(ENABLE_PROFILING)
1567 /* initialize profiling */
1569 if (!profile_init())
1570 vm_abort("vm_create: profile_init failed");
1573 #if defined(ENABLE_THREADS)
1574 /* initialize recompilation */
1576 if (!recompile_init())
1577 vm_abort("vm_create: recompile_init failed");
1579 /* start the signal handler thread */
1581 #if defined(__LINUX__)
1582 /* XXX Remove for exact-GC. */
1583 if (threads_pthreads_implementation_nptl)
1585 if (!signal_start_thread())
1586 vm_abort("vm_create: signal_start_thread failed");
1588 /* finally, start the finalizer thread */
1590 if (!finalizer_start_thread())
1591 vm_abort("vm_create: finalizer_start_thread failed");
1593 # if !defined(NDEBUG)
1594 /* start the memory profiling thread */
1596 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1597 if (!memory_start_thread())
1598 vm_abort("vm_create: memory_start_thread failed");
1601 /* start the recompilation thread (must be done before the
1602 profiling thread) */
1604 if (!recompile_start_thread())
1605 vm_abort("vm_create: recompile_start_thread failed");
1607 # if defined(ENABLE_PROFILING)
1608 /* start the profile sampling thread */
1611 /* if (!profile_start_thread()) */
1612 /* vm_abort("vm_create: profile_start_thread failed"); */
1616 #if defined(ENABLE_JVMTI)
1617 # if defined(ENABLE_GC_CACAO)
1618 /* XXX this will not work with the new indirection cells for classloaders!!! */
1622 /* add agent library to native library hashtable */
1623 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1627 /* Increment the number of VMs. */
1631 /* Initialization is done, VM is created.. */
1634 vm_initializing = false;
1636 /* Print the VM configuration after all stuff is set and the VM is
1639 if (opt_PrintConfig)
1642 /* everything's ok */
1648 /* vm_run **********************************************************************
1650 Runs the main-method of the passed class.
1652 *******************************************************************************/
1654 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1657 classinfo *mainclass;
1660 java_handle_objectarray_t *oa;
1667 #if defined(ENABLE_THREADS)
1671 #if !defined(NDEBUG)
1677 if (opt_method != NULL) {
1678 vm_compile_method();
1681 #endif /* !defined(NDEBUG) */
1683 /* should we run the main-method? */
1685 if (mainstring == NULL)
1688 /* set return value to OK */
1692 if (opt_jar == true) {
1693 /* open jar file with java.util.jar.JarFile */
1695 mainstring = vm_get_mainclass_from_jar(mainstring);
1697 if (mainstring == NULL)
1701 /* load the main class */
1703 mainutf = utf_new_char(mainstring);
1705 #if defined(ENABLE_JAVAME_CLDC1_1)
1706 mainclass = load_class_bootstrap(mainutf);
1708 mainclass = load_class_from_sysloader(mainutf);
1711 /* error loading class */
1713 e = exceptions_get_and_clear_exception();
1715 if ((e != NULL) || (mainclass == NULL)) {
1716 exceptions_throw_noclassdeffounderror_cause(e);
1717 exceptions_print_stacktrace();
1721 if (!link_class(mainclass)) {
1722 exceptions_print_stacktrace();
1726 /* find the `main' method of the main class */
1728 m = class_resolveclassmethod(mainclass,
1729 utf_new_char("main"),
1730 utf_new_char("([Ljava/lang/String;)V"),
1731 class_java_lang_Object,
1734 if (exceptions_get_exception()) {
1735 exceptions_print_stacktrace();
1739 /* there is no main method or it isn't static */
1741 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1742 exceptions_clear_exception();
1743 exceptions_throw_nosuchmethoderror(mainclass,
1744 utf_new_char("main"),
1745 utf_new_char("([Ljava/lang/String;)V"));
1747 exceptions_print_stacktrace();
1751 /* build argument array */
1753 oalength = vm_args->nOptions - opt_index;
1755 oa = builtin_anewarray(oalength, class_java_lang_String);
1757 for (i = 0; i < oalength; i++) {
1758 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1759 s = javastring_new(u);
1761 array_objectarray_element_set(oa, i, s);
1764 #ifdef TYPEINFO_DEBUG_TEST
1765 /* test the typeinfo system */
1768 /*class_showmethods(currentThread->group->header.vftbl->class); */
1770 #if defined(ENABLE_JVMTI)
1771 jvmti_set_phase(JVMTI_PHASE_LIVE);
1774 /* set ThreadMXBean variables */
1776 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1777 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1779 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1780 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1781 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1782 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1784 /* start the main thread */
1786 (void) vm_call_method(m, NULL, oa);
1788 /* exception occurred? */
1790 if (exceptions_get_exception()) {
1791 exceptions_print_stacktrace();
1795 #if defined(ENABLE_THREADS)
1796 /* Detach the main thread so that it appears to have ended when
1797 the application's main method exits. */
1799 t = thread_get_current();
1801 if (!threads_detach_thread(t))
1802 vm_abort("vm_run: Could not detach main thread.");
1805 /* Destroy the JavaVM. */
1807 (void) vm_destroy(vm);
1815 /* vm_destroy ******************************************************************
1817 Unloads a Java VM and reclaims its resources.
1819 *******************************************************************************/
1821 int vm_destroy(JavaVM *vm)
1823 #if defined(ENABLE_THREADS)
1824 /* Create a a trivial new Java waiter thread called
1827 JavaVMAttachArgs args;
1829 args.name = "DestroyJavaVM";
1832 if (!threads_attach_current_thread(&args, false))
1835 /* Wait until we are the last non-daemon thread. */
1837 threads_join_all_threads();
1844 /* Everything is ok. */
1850 /* vm_exit *********************************************************************
1852 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1854 *******************************************************************************/
1856 void vm_exit(s4 status)
1860 /* signal that we are exiting */
1864 assert(class_java_lang_System);
1865 assert(class_java_lang_System->state & CLASS_LOADED);
1867 #if defined(ENABLE_JVMTI)
1868 if (jvmti || (dbgcom!=NULL)) {
1869 jvmti_set_phase(JVMTI_PHASE_DEAD);
1870 if (jvmti) jvmti_agentunload();
1874 if (!link_class(class_java_lang_System)) {
1875 exceptions_print_stacktrace();
1879 /* call java.lang.System.exit(I)V */
1881 m = class_resolveclassmethod(class_java_lang_System,
1882 utf_new_char("exit"),
1884 class_java_lang_Object,
1888 exceptions_print_stacktrace();
1892 /* call the exit function with passed exit status */
1894 (void) vm_call_method(m, NULL, status);
1896 /* If we had an exception, just ignore the exception and exit with
1899 vm_shutdown(status);
1903 /* vm_shutdown *****************************************************************
1905 Terminates the system immediately without freeing memory explicitly
1906 (to be used only for abnormal termination).
1908 *******************************************************************************/
1910 void vm_shutdown(s4 status)
1913 #if defined(ENABLE_STATISTICS)
1914 || opt_getcompilingtime || opt_stat
1918 log_text("CACAO terminated by shutdown");
1919 dolog("Exit status: %d\n", (s4) status);
1923 #if defined(ENABLE_JVMTI)
1924 /* terminate cacaodbgserver */
1926 mutex_lock(&dbgcomlock);
1928 mutex_unlock(&dbgcomlock);
1929 jvmti_cacaodbgserver_quit();
1937 /* vm_exit_handler *************************************************************
1939 The exit_handler function is called upon program termination.
1941 ATTENTION: Don't free system resources here! Some threads may still
1942 be running as this is called from VMRuntime.exit(). The OS does the
1945 *******************************************************************************/
1947 void vm_exit_handler(void)
1949 #if !defined(NDEBUG)
1951 class_showmethods(mainclass);
1953 if (showconstantpool)
1954 class_showconstantpool(mainclass);
1959 # if defined(ENABLE_PROFILING)
1961 profile_printstats();
1963 #endif /* !defined(NDEBUG) */
1965 #if defined(ENABLE_RT_TIMING)
1966 rt_timing_print_time_stats(stderr);
1969 #if defined(ENABLE_CYCLES_STATS)
1970 builtin_print_cycles_stats(stderr);
1971 stacktrace_print_cycles_stats(stderr);
1975 #if defined(ENABLE_STATISTICS)
1976 || opt_getcompilingtime || opt_stat
1980 log_text("CACAO terminated");
1982 #if defined(ENABLE_STATISTICS)
1985 #ifdef TYPECHECK_STATISTICS
1986 typecheck_print_statistics(get_logfile());
1990 if (opt_getcompilingtime)
1992 #endif /* defined(ENABLE_STATISTICS) */
1994 /* vm_print_profile(stderr);*/
1998 /* vm_abort ********************************************************************
2000 Prints an error message and aborts the VM.
2003 text ... error message to print
2005 *******************************************************************************/
2007 void vm_abort(const char *text, ...)
2011 /* Print the log message. */
2016 log_vprint(text, ap);
2021 /* Now abort the VM. */
2027 /* vm_abort_errnum *************************************************************
2029 Prints an error message, appends ":" plus the strerror-message of
2030 errnum and aborts the VM.
2033 errnum ... error number
2034 text ..... error message to print
2036 *******************************************************************************/
2038 void vm_abort_errnum(int errnum, const char *text, ...)
2042 /* Print the log message. */
2047 log_vprint(text, ap);
2050 /* Print the strerror-message of errnum. */
2052 log_print(": %s", system_strerror(errnum));
2056 /* Now abort the VM. */
2062 /* vm_abort_errno **************************************************************
2064 Equal to vm_abort_errnum, but uses errno to get the error number.
2067 text ... error message to print
2069 *******************************************************************************/
2071 void vm_abort_errno(const char *text, ...)
2076 vm_abort_errnum(errno, text, ap);
2081 /* vm_abort_disassemble ********************************************************
2083 Prints an error message, disassemble the given code range (if
2084 enabled) and aborts the VM.
2087 pc.......PC to disassemble
2088 count....number of instructions to disassemble
2090 *******************************************************************************/
2092 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2095 #if defined(ENABLE_DISASSEMBLER)
2099 /* Print debug message. */
2104 log_vprint(text, ap);
2111 #if SIZEOF_VOID_P == 8
2112 log_println("PC=0x%016lx", pc);
2114 log_println("PC=0x%08x", pc);
2117 #if defined(ENABLE_DISASSEMBLER)
2118 log_println("machine instructions at PC:");
2120 /* Disassemble the given number of instructions. */
2122 for (i = 0; i < count; i++)
2123 pc = disassinstr(pc);
2126 vm_abort("Aborting...");
2130 /* vm_get_mainclass_from_jar ***************************************************
2132 Gets the name of the main class from a JAR's manifest file.
2134 *******************************************************************************/
2136 static char *vm_get_mainclass_from_jar(char *mainstring)
2143 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2146 exceptions_print_stacktrace();
2150 /* create JarFile object */
2155 exceptions_print_stacktrace();
2159 m = class_resolveclassmethod(c,
2161 utf_java_lang_String__void,
2162 class_java_lang_Object,
2166 exceptions_print_stacktrace();
2170 s = javastring_new_from_ascii(mainstring);
2172 (void) vm_call_method(m, o, s);
2174 if (exceptions_get_exception()) {
2175 exceptions_print_stacktrace();
2179 /* get manifest object */
2181 m = class_resolveclassmethod(c,
2182 utf_new_char("getManifest"),
2183 utf_new_char("()Ljava/util/jar/Manifest;"),
2184 class_java_lang_Object,
2188 exceptions_print_stacktrace();
2192 o = vm_call_method(m, o);
2195 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2200 /* get Main Attributes */
2202 LLNI_class_get(o, c);
2204 m = class_resolveclassmethod(c,
2205 utf_new_char("getMainAttributes"),
2206 utf_new_char("()Ljava/util/jar/Attributes;"),
2207 class_java_lang_Object,
2211 exceptions_print_stacktrace();
2215 o = vm_call_method(m, o);
2218 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2223 /* get property Main-Class */
2225 LLNI_class_get(o, c);
2227 m = class_resolveclassmethod(c,
2228 utf_new_char("getValue"),
2229 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2230 class_java_lang_Object,
2234 exceptions_print_stacktrace();
2238 s = javastring_new_from_ascii("Main-Class");
2240 o = vm_call_method(m, o, s);
2243 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2244 fprintf(stderr, "%s\n", mainstring);
2248 return javastring_tochar(o);
2252 /* vm_compile_all **************************************************************
2254 Compile all methods found in the bootclasspath.
2256 *******************************************************************************/
2258 #if !defined(NDEBUG)
2259 static void vm_compile_all(void)
2264 classcache_name_entry *nmen;
2265 classcache_class_entry *clsen;
2268 /* create all classes found in the bootclasspath */
2269 /* XXX currently only works with zip/jar's */
2271 loader_load_all_classes();
2273 /* link all classes */
2275 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2276 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2278 for (; nmen; nmen = nmen->hashlink) {
2279 /* iterate over all class entries */
2281 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2282 c = clsen->classobj;
2287 if (!(c->state & CLASS_LINKED)) {
2288 if (!link_class(c)) {
2289 fprintf(stderr, "Error linking: ");
2290 utf_fprint_printable_ascii_classname(stderr, c->name);
2291 fprintf(stderr, "\n");
2293 /* print out exception and cause */
2295 exceptions_print_current_exception();
2297 /* goto next class */
2303 /* compile all class methods */
2305 for (i = 0; i < c->methodscount; i++) {
2306 m = &(c->methods[i]);
2308 if (m->jcode != NULL) {
2309 if (!jit_compile(m)) {
2310 fprintf(stderr, "Error compiling: ");
2311 utf_fprint_printable_ascii_classname(stderr, c->name);
2312 fprintf(stderr, ".");
2313 utf_fprint_printable_ascii(stderr, m->name);
2314 utf_fprint_printable_ascii(stderr, m->descriptor);
2315 fprintf(stderr, "\n");
2317 /* print out exception and cause */
2319 exceptions_print_current_exception();
2327 #endif /* !defined(NDEBUG) */
2330 /* vm_compile_method ***********************************************************
2332 Compile a specific method.
2334 *******************************************************************************/
2336 #if !defined(NDEBUG)
2337 static void vm_compile_method(void)
2341 /* create, load and link the main class */
2343 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2345 if (mainclass == NULL)
2346 exceptions_print_stacktrace();
2348 if (!link_class(mainclass))
2349 exceptions_print_stacktrace();
2351 if (opt_signature != NULL) {
2352 m = class_resolveclassmethod(mainclass,
2353 utf_new_char(opt_method),
2354 utf_new_char(opt_signature),
2359 m = class_resolveclassmethod(mainclass,
2360 utf_new_char(opt_method),
2367 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2368 opt_method, opt_signature ? opt_signature : "");
2372 #endif /* !defined(NDEBUG) */
2375 /* vm_call_array ***************************************************************
2377 Calls a Java method with a variable number of arguments, passed via
2380 ATTENTION: This function has to be used outside the nativeworld.
2382 *******************************************************************************/
2384 #define VM_CALL_ARRAY(name, type) \
2385 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2391 assert(m->code != NULL); \
2393 md = m->parseddesc; \
2394 pv = m->code->entrypoint; \
2396 STATISTICS(count_calls_native_to_java++); \
2398 value = asm_vm_call_method##name(pv, array, md->memuse); \
2403 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2409 assert(m->code != NULL);
2412 pv = m->code->entrypoint;
2414 STATISTICS(count_calls_native_to_java++);
2416 o = asm_vm_call_method(pv, array, md->memuse);
2418 if (md->returntype.type == TYPE_VOID)
2421 return LLNI_WRAP(o);
2424 VM_CALL_ARRAY(_int, int32_t)
2425 VM_CALL_ARRAY(_long, int64_t)
2426 VM_CALL_ARRAY(_float, float)
2427 VM_CALL_ARRAY(_double, double)
2430 /* vm_call_method **************************************************************
2432 Calls a Java method with a variable number of arguments.
2434 *******************************************************************************/
2436 #define VM_CALL_METHOD(name, type) \
2437 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2443 value = vm_call_method##name##_valist(m, o, ap); \
2449 VM_CALL_METHOD(, java_handle_t *)
2450 VM_CALL_METHOD(_int, int32_t)
2451 VM_CALL_METHOD(_long, int64_t)
2452 VM_CALL_METHOD(_float, float)
2453 VM_CALL_METHOD(_double, double)
2456 /* vm_call_method_valist *******************************************************
2458 Calls a Java method with a variable number of arguments, passed via
2461 *******************************************************************************/
2463 #define VM_CALL_METHOD_VALIST(name, type) \
2464 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2469 int32_t dumpmarker; \
2471 if (m->code == NULL) \
2472 if (!jit_compile(m)) \
2475 THREAD_NATIVEWORLD_EXIT; \
2478 array = argument_vmarray_from_valist(m, o, ap); \
2479 value = vm_call##name##_array(m, array); \
2482 THREAD_NATIVEWORLD_ENTER; \
2487 VM_CALL_METHOD_VALIST(, java_handle_t *)
2488 VM_CALL_METHOD_VALIST(_int, int32_t)
2489 VM_CALL_METHOD_VALIST(_long, int64_t)
2490 VM_CALL_METHOD_VALIST(_float, float)
2491 VM_CALL_METHOD_VALIST(_double, double)
2494 /* vm_call_method_jvalue *******************************************************
2496 Calls a Java method with a variable number of arguments, passed via
2499 *******************************************************************************/
2501 #define VM_CALL_METHOD_JVALUE(name, type) \
2502 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2503 const jvalue *args) \
2507 int32_t dumpmarker; \
2509 if (m->code == NULL) \
2510 if (!jit_compile(m)) \
2513 THREAD_NATIVEWORLD_EXIT; \
2516 array = argument_vmarray_from_jvalue(m, o, args); \
2517 value = vm_call##name##_array(m, array); \
2520 THREAD_NATIVEWORLD_ENTER; \
2525 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2526 VM_CALL_METHOD_JVALUE(_int, int32_t)
2527 VM_CALL_METHOD_JVALUE(_long, int64_t)
2528 VM_CALL_METHOD_JVALUE(_float, float)
2529 VM_CALL_METHOD_JVALUE(_double, double)
2532 /* vm_call_method_objectarray **************************************************
2534 Calls a Java method with a variable number if arguments, passed via
2535 an objectarray of boxed values. Returns a boxed value.
2537 *******************************************************************************/
2539 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2540 java_handle_objectarray_t *params)
2543 java_handle_t *xptr;
2548 /* Prevent compiler warnings. */
2552 /* compile methods which are not yet compiled */
2554 if (m->code == NULL)
2555 if (!jit_compile(m))
2558 /* leave the nativeworld */
2560 THREAD_NATIVEWORLD_EXIT;
2562 /* mark start of dump memory area */
2566 /* Fill the argument array from a object-array. */
2568 array = argument_vmarray_from_objectarray(m, o, params);
2570 if (array == NULL) {
2571 /* release dump area */
2575 /* enter the nativeworld again */
2577 THREAD_NATIVEWORLD_ENTER;
2579 exceptions_throw_illegalargumentexception();
2584 switch (m->parseddesc->returntype.decltype) {
2585 case PRIMITIVETYPE_VOID:
2586 value.a = vm_call_array(m, array);
2589 case PRIMITIVETYPE_BOOLEAN:
2590 case PRIMITIVETYPE_BYTE:
2591 case PRIMITIVETYPE_CHAR:
2592 case PRIMITIVETYPE_SHORT:
2593 case PRIMITIVETYPE_INT:
2594 value.i = vm_call_int_array(m, array);
2597 case PRIMITIVETYPE_LONG:
2598 value.l = vm_call_long_array(m, array);
2601 case PRIMITIVETYPE_FLOAT:
2602 value.f = vm_call_float_array(m, array);
2605 case PRIMITIVETYPE_DOUBLE:
2606 value.d = vm_call_double_array(m, array);
2610 ro = vm_call_array(m, array);
2614 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2617 /* release dump area */
2621 /* enter the nativeworld again */
2623 THREAD_NATIVEWORLD_ENTER;
2625 /* box the return value if necesarry */
2627 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2628 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2630 /* check for an exception */
2632 xptr = exceptions_get_exception();
2635 /* clear exception pointer, we are calling JIT code again */
2637 exceptions_clear_exception();
2639 exceptions_throw_invocationtargetexception(xptr);
2647 * These are local overrides for various environment variables in Emacs.
2648 * Please do not remove this and leave it at the end of the file, where
2649 * Emacs will automagically detect them.
2650 * ---------------------------------------------------------------------
2653 * indent-tabs-mode: t
2657 * vim:noexpandtab:sw=4:ts=4: