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 "vm/jit/trap.h"
109 #include "vmcore/classcache.h"
110 #include "vmcore/options.h"
111 #include "vmcore/statistics.h"
112 #include "vmcore/suck.h"
113 #include "vmcore/system.h"
115 #if defined(ENABLE_JVMTI)
116 # include "native/jvmti/cacaodbg.h"
119 #if defined(ENABLE_VMLOG)
120 #include <vmlog_cacao.h>
124 /* Invocation API variables ***************************************************/
126 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
127 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
130 /* global variables ***********************************************************/
132 s4 vms = 0; /* number of VMs created */
134 bool vm_initializing = false;
135 bool vm_created = false;
136 bool vm_exiting = false;
138 char *mainstring = NULL;
139 classinfo *mainclass = NULL;
141 #if defined(ENABLE_INTRP)
142 u1 *intrp_main_stack = NULL;
146 /* define heap sizes **********************************************************/
148 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
149 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
150 #define STACK_SIZE 128 * 1024 /* default 64kB */
153 /* define command line options ************************************************/
187 /* Java non-standard options */
198 #if defined(ENABLE_PROFILING)
211 #if defined(ENABLE_STATISTICS)
228 #if defined(ENABLE_VERIFIER)
230 #if defined(TYPECHECK_VERBOSE)
233 #endif /* defined(ENABLE_VERIFIER) */
235 /* optimization options */
237 #if defined(ENABLE_LOOP)
241 #if defined(ENABLE_IFCONV)
245 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
249 #if defined(ENABLE_INTRP)
250 /* interpreter options */
269 #if defined(ENABLE_DEBUG_FILTER)
270 OPT_FILTER_VERBOSECALL_INCLUDE,
271 OPT_FILTER_VERBOSECALL_EXCLUDE,
272 OPT_FILTER_SHOW_METHOD,
279 opt_struct opts[] = {
280 { "foo", false, OPT_FOO },
284 { "jar", false, OPT_JAR },
286 { "d32", false, OPT_D32 },
287 { "d64", false, OPT_D64 },
288 { "client", false, OPT_IGNORE },
289 { "server", false, OPT_IGNORE },
290 { "jvm", false, OPT_IGNORE },
291 { "hotspot", false, OPT_IGNORE },
293 { "classpath", true, OPT_CLASSPATH },
294 { "cp", true, OPT_CLASSPATH },
295 { "D", true, OPT_D },
296 { "version", false, OPT_VERSION },
297 { "showversion", false, OPT_SHOWVERSION },
298 { "fullversion", false, OPT_FULLVERSION },
299 { "help", false, OPT_HELP },
300 { "?", false, OPT_HELP },
301 { "X", false, OPT_X },
302 { "XX:", true, OPT_XX },
304 { "ea:", true, OPT_EA },
305 { "da:", true, OPT_DA },
306 { "ea", false, OPT_EA_NOARG },
307 { "da", false, OPT_DA_NOARG },
309 { "enableassertions:", true, OPT_EA },
310 { "disableassertions:", true, OPT_DA },
311 { "enableassertions", false, OPT_EA_NOARG },
312 { "disableassertions", false, OPT_DA_NOARG },
314 { "esa", false, OPT_ESA },
315 { "enablesystemassertions", false, OPT_ESA },
316 { "dsa", false, OPT_DSA },
317 { "disablesystemassertions", false, OPT_DSA },
319 { "noasyncgc", false, OPT_IGNORE },
320 #if defined(ENABLE_VERIFIER)
321 { "noverify", false, OPT_NOVERIFY },
322 { "Xverify:none", false, OPT_NOVERIFY },
324 { "v", false, OPT_VERBOSE1 },
325 { "verbose:", true, OPT_VERBOSE },
327 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
328 { "verbosetc", false, OPT_VERBOSETC },
330 #if defined(__ALPHA__)
331 { "noieee", false, OPT_NOIEEE },
333 #if defined(ENABLE_STATISTICS)
334 { "time", false, OPT_TIME },
335 { "stat", false, OPT_STAT },
337 { "log", true, OPT_LOG },
338 { "c", true, OPT_CHECK },
339 { "l", false, OPT_LOAD },
342 { "all", false, OPT_ALL },
343 { "sig", true, OPT_SIGNATURE },
346 #if defined(ENABLE_LOOP)
347 { "oloop", false, OPT_OLOOP },
349 #if defined(ENABLE_IFCONV)
350 { "ifconv", false, OPT_IFCONV },
352 #if defined(ENABLE_LSRA)
353 { "lsra", false, OPT_LSRA },
355 #if defined(ENABLE_SSA)
356 { "lsra", true, OPT_LSRA },
359 #if defined(ENABLE_INTRP)
360 /* interpreter options */
362 { "trace", false, OPT_TRACE },
363 { "static-supers", true, OPT_STATIC_SUPERS },
364 { "no-dynamic", false, OPT_NO_DYNAMIC },
365 { "no-replication", false, OPT_NO_REPLICATION },
366 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
369 /* JVMTI Agent Command Line Options */
371 { "agentlib:", true, OPT_AGENTLIB },
372 { "agentpath:", true, OPT_AGENTPATH },
375 /* Java non-standard options */
377 { "Xjit", false, OPT_JIT },
378 { "Xint", false, OPT_INTRP },
379 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
380 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
381 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
382 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
385 { "Xdebug", false, OPT_DEBUG },
386 { "Xnoagent", false, OPT_NOAGENT },
387 { "Xrunjdwp", true, OPT_XRUNJDWP },
390 { "Xms", true, OPT_MS },
391 { "ms", true, OPT_MS },
392 { "Xmx", true, OPT_MX },
393 { "mx", true, OPT_MX },
394 { "Xss", true, OPT_SS },
395 { "ss", true, OPT_SS },
397 #if defined(ENABLE_PROFILING)
398 { "Xprof:", true, OPT_PROF_OPTION },
399 { "Xprof", false, OPT_PROF },
402 /* keep these at the end of the list */
405 { "m", true, OPT_METHOD },
408 { "s", true, OPT_SHOW },
409 { "debug-color", false, OPT_DEBUGCOLOR },
411 #if defined(ENABLE_DEBUG_FILTER)
412 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
413 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
414 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
421 /* usage ***********************************************************************
423 Prints the correct usage syntax to stdout.
425 *******************************************************************************/
429 puts("Usage: cacao [-options] classname [arguments]");
430 puts(" (to run a class file)");
431 puts(" or cacao [-options] -jar jarfile [arguments]");
432 puts(" (to run a standalone jar file)\n");
434 puts("where options include:");
435 puts(" -d32 use 32-bit data model if available");
436 puts(" -d64 use 64-bit data model if available");
437 puts(" -client compatibility (currently ignored)");
438 puts(" -server compatibility (currently ignored)");
439 puts(" -jvm compatibility (currently ignored)");
440 puts(" -hotspot compatibility (currently ignored)\n");
442 puts(" -cp <path> specify a path to look for classes");
443 puts(" -classpath <path> specify a path to look for classes");
444 puts(" -D<name>=<value> add an entry to the property list");
445 puts(" -verbose[:class|gc|jni] enable specific verbose output");
446 puts(" -version print product version and exit");
447 puts(" -fullversion print jpackage-compatible product version and exit");
448 puts(" -showversion print product version and continue");
449 puts(" -help, -? print this help message");
450 puts(" -X print help on non-standard Java options");
451 puts(" -XX print help on debugging options");
452 puts(" -ea[:<packagename>...|:<classname>]");
453 puts(" -enableassertions[:<packagename>...|:<classname>]");
454 puts(" enable assertions with specified granularity");
455 puts(" -da[:<packagename>...|:<classname>]");
456 puts(" -disableassertions[:<packagename>...|:<classname>]");
457 puts(" disable assertions with specified granularity");
458 puts(" -esa | -enablesystemassertions");
459 puts(" enable system assertions");
460 puts(" -dsa | -disablesystemassertions");
461 puts(" disable system assertions");
464 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
465 puts (" for jdwp help use: -agentlib:jdwp=help");
466 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
469 /* exit with error code */
475 static void Xusage(void)
477 #if defined(ENABLE_JIT)
478 puts(" -Xjit JIT mode execution (default)");
480 #if defined(ENABLE_INTRP)
481 puts(" -Xint interpreter mode execution");
483 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
484 puts(" value is set as bootstrap class path");
485 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
486 puts(" value is appended to the bootstrap class path");
487 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
488 puts(" value is prepended to the bootstrap class path");
489 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
490 puts(" value is used as Java core library, but the");
491 puts(" hardcoded VM interface classes are prepended");
492 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
493 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
494 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
496 #if defined(ENABLE_PROFILING)
497 puts(" -Xprof[:bb] collect and print profiling data");
500 #if defined(ENABLE_JVMTI)
501 /* -Xdebug option depend on gnu classpath JDWP options. options:
502 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
503 puts(" -Xdebug enable remote debugging\n");
504 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
505 puts(" enable remote debugging\n");
508 /* exit with error code */
515 static void XXusage(void)
517 puts(" -v write state-information");
519 puts(" -verbose:jit enable specific verbose output");
520 puts(" -debug-color colored output for ANSI terms");
522 #ifdef TYPECHECK_VERBOSE
523 puts(" -verbosetc write debug messages while typechecking");
525 #if defined(__ALPHA__)
526 puts(" -noieee don't use ieee compliant arithmetic");
528 #if defined(ENABLE_VERIFIER)
529 puts(" -noverify don't verify classfiles");
531 #if defined(ENABLE_STATISTICS)
532 puts(" -time measure the runtime");
533 puts(" -stat detailed compiler statistics");
535 puts(" -log logfile specify a name for the logfile");
536 puts(" -c(heck)b(ounds) don't check array bounds");
537 puts(" s(ync) don't check for synchronization");
538 #if defined(ENABLE_LOOP)
539 puts(" -oloop optimize array accesses in loops");
541 puts(" -l don't start the class after loading");
543 puts(" -all compile all methods, no execution");
544 puts(" -m compile only a specific method");
545 puts(" -sig specify signature for a specific method");
548 puts(" -s... show...");
549 puts(" (c)onstants the constant pool");
550 puts(" (m)ethods class fields and methods");
551 puts(" (u)tf the utf - hash");
552 puts(" (i)ntermediate intermediate representation");
553 #if defined(ENABLE_DISASSEMBLER)
554 puts(" (a)ssembler disassembled listing");
555 puts(" n(o)ps show NOPs in disassembler output");
557 puts(" (d)atasegment data segment listing");
559 #if defined(ENABLE_IFCONV)
560 puts(" -ifconv use if-conversion");
562 #if defined(ENABLE_LSRA)
563 puts(" -lsra use linear scan register allocation");
565 #if defined(ENABLE_SSA)
566 puts(" -lsra:... use linear scan register allocation (with SSA)");
567 puts(" (d)ead code elimination");
568 puts(" (c)opy propagation");
570 #if defined(ENABLE_DEBUG_FILTER)
571 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
572 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
573 puts(" -XXfm <regex> filter for show options");
575 /* exit with error code */
582 /* version *********************************************************************
584 Only prints cacao version information.
586 *******************************************************************************/
588 static void version(bool opt_exit)
590 puts("java version \""JAVA_VERSION"\"");
591 puts("CACAO version "VERSION"\n");
593 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
594 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
595 puts("This is free software; see the source for copying conditions. There is NO");
596 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
598 /* exit normally, if requested */
605 /* fullversion *****************************************************************
607 Prints a Sun compatible version information (required e.g. by
608 jpackage, www.jpackage.org).
610 *******************************************************************************/
612 static void fullversion(void)
614 puts("java full version \"cacao-"JAVA_VERSION"\"");
622 static void vm_printconfig(void)
624 puts("Configure/Build options:\n");
625 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
626 #if defined(__VERSION__)
627 puts(" CC : "VERSION_CC" ("__VERSION__")");
629 puts(" CC : "VERSION_CC"");
631 puts(" CFLAGS : "VERSION_CFLAGS"\n");
633 puts("Default variables:\n");
634 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
635 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
636 printf(" stack size : %d\n", STACK_SIZE);
638 #if defined(ENABLE_JRE_LAYOUT)
639 /* When we're building with JRE-layout, the default paths are the
640 same as the runtime paths. */
642 # if defined(WITH_CLASSPATH_GNU)
643 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
644 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
645 # elif defined(WITH_CLASSPATH_SUN)
646 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
647 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
653 puts("Runtime variables:\n");
654 printf(" maximum heap size : %d\n", opt_heapmaxsize);
655 printf(" initial heap size : %d\n", opt_heapstartsize);
656 printf(" stack size : %d\n", opt_stacksize);
658 #if defined(WITH_CLASSPATH_GNU)
659 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
660 #elif defined(WITH_CLASSPATH_SUN)
661 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
664 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
665 printf(" java.class.path : %s\n", properties_get("java.class.path"));
669 /* forward declarations *******************************************************/
671 static char *vm_get_mainclass_from_jar(char *mainstring);
673 static void vm_compile_all(void);
674 static void vm_compile_method(void);
678 /* vm_createjvm ****************************************************************
680 Implementation for JNI_CreateJavaVM.
682 *******************************************************************************/
684 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
686 JavaVMInitArgs *_vm_args;
690 /* get the arguments for the new JVM */
692 _vm_args = (JavaVMInitArgs *) vm_args;
694 /* get the VM and Env tables (must be set before vm_create) */
696 env = NEW(_Jv_JNIEnv);
698 #if defined(ENABLE_JNI)
699 env->env = &_Jv_JNINativeInterface;
702 /* XXX Set the global variable. Maybe we should do that differently. */
706 /* create and fill a JavaVM structure */
708 vm = NEW(_Jv_JavaVM);
710 #if defined(ENABLE_JNI)
711 vm->functions = &_Jv_JNIInvokeInterface;
714 /* XXX Set the global variable. Maybe we should do that differently. */
715 /* XXX JVMTI Agents needs a JavaVM */
719 /* actually create the JVM */
721 if (!vm_create(_vm_args))
724 /* now return the values */
726 *p_vm = (JavaVM *) vm;
727 *p_env = (void *) env;
732 /* release allocated memory */
734 FREE(env, _Jv_JNIEnv);
735 FREE(vm, _Jv_JavaVM);
741 /* vm_create *******************************************************************
743 Creates a JVM. Called by vm_createjvm.
745 *******************************************************************************/
747 bool vm_create(JavaVMInitArgs *vm_args)
751 char *boot_class_path;
758 #if defined(ENABLE_JVMTI)
760 char *libname, *agentarg;
761 bool jdwp,agentbypath;
762 jdwp = agentbypath = false;
765 #if defined(ENABLE_JNI)
766 /* Check the JNI version requested. */
768 if (!jni_version_check(vm_args->version))
772 /* We only support 1 JVM instance. */
777 /* Install the exit handler. */
779 if (atexit(vm_exit_handler))
780 vm_abort("atexit failed: %s\n", strerror(errno));
782 /* Set some options. */
789 opt_heapmaxsize = HEAP_MAXSIZE;
790 opt_heapstartsize = HEAP_STARTSIZE;
791 opt_stacksize = STACK_SIZE;
793 /* Initialize the properties list before command-line handling.
794 Otherwise -XX:+PrintConfig crashes. */
798 /* First of all, parse the -XX options. */
800 #if defined(ENABLE_VMLOG)
801 vmlog_cacao_init_options();
806 #if defined(ENABLE_VMLOG)
810 /* We need to check if the actual size of a java.lang.Class object
811 is smaller or equal than the assumption made in
812 src/vmcore/class.h. */
814 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
815 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
817 /* set the VM starttime */
819 _Jv_jvm->starttime = builtin_currenttimemillis();
821 #if defined(ENABLE_JVMTI)
822 /* initialize JVMTI related **********************************************/
826 /* Fill the properties before command-line handling. */
830 /* iterate over all passed options */
832 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
846 #if SIZEOF_VOID_P == 8
847 puts("Running a 32-bit JVM is not supported on this platform.");
853 #if SIZEOF_VOID_P == 4
854 puts("Running a 64-bit JVM is not supported on this platform.");
860 /* Forget old classpath and set the argument as new
863 class_path = properties_get("java.class.path");
865 p = MNEW(char, strlen(opt_arg) + strlen("0"));
869 #if defined(ENABLE_JAVASE)
870 properties_add("java.class.path", p);
873 MFREE(class_path, char, strlen(class_path));
877 for (i = 0; i < strlen(opt_arg); i++) {
878 if (opt_arg[i] == '=') {
880 properties_add(opt_arg, opt_arg + i + 1);
885 /* if no '=' is given, just create an empty property */
887 properties_add(opt_arg, "");
892 case OPT_BOOTCLASSPATH:
893 /* Forget default bootclasspath and set the argument as
894 new boot classpath. */
896 boot_class_path = properties_get("sun.boot.class.path");
898 p = MNEW(char, strlen(opt_arg) + strlen("0"));
902 properties_add("sun.boot.class.path", p);
903 properties_add("java.boot.class.path", p);
905 MFREE(boot_class_path, char, strlen(boot_class_path));
908 case OPT_BOOTCLASSPATH_A:
909 /* Append to bootclasspath. */
911 boot_class_path = properties_get("sun.boot.class.path");
913 len = strlen(boot_class_path);
915 p = MREALLOC(boot_class_path,
919 strlen(opt_arg) + strlen("0"));
924 properties_add("sun.boot.class.path", p);
925 properties_add("java.boot.class.path", p);
928 case OPT_BOOTCLASSPATH_P:
929 /* Prepend to bootclasspath. */
931 boot_class_path = properties_get("sun.boot.class.path");
933 len = strlen(boot_class_path);
935 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
939 strcat(p, boot_class_path);
941 properties_add("sun.boot.class.path", p);
942 properties_add("java.boot.class.path", p);
944 MFREE(boot_class_path, char, len);
947 case OPT_BOOTCLASSPATH_C:
948 /* Use as Java core library, but prepend VM interface
951 boot_class_path = properties_get("sun.boot.class.path");
954 strlen(CACAO_VM_ZIP) +
961 strcpy(p, CACAO_VM_ZIP);
965 properties_add("sun.boot.class.path", p);
966 properties_add("java.boot.class.path", p);
968 MFREE(boot_class_path, char, strlen(boot_class_path));
971 #if defined(ENABLE_JVMTI)
973 /* this option exists only for compatibility reasons */
977 /* I don't know yet what Xnoagent should do. This is only for
978 compatiblity with eclipse - motse */
987 strlen(CACAO_LIBDIR) +
988 strlen("/libjdwp.so=") +
992 agentarg = MNEW(char, len);
994 strcpy(agentarg, CACAO_LIBDIR);
995 strcat(agentarg, "/libjdwp.so=");
996 strcat(agentarg, &opt_arg[1]);
1013 c = opt_arg[strlen(opt_arg) - 1];
1015 if ((c == 'k') || (c == 'K')) {
1016 j = atoi(opt_arg) * 1024;
1018 } else if ((c == 'm') || (c == 'M')) {
1019 j = atoi(opt_arg) * 1024 * 1024;
1025 opt_heapmaxsize = j;
1026 else if (opt == OPT_MS)
1027 opt_heapstartsize = j;
1038 if (strcmp("class", opt_arg) == 0) {
1039 opt_verboseclass = true;
1041 else if (strcmp("gc", opt_arg) == 0) {
1042 opt_verbosegc = true;
1044 else if (strcmp("jni", opt_arg) == 0) {
1045 opt_verbosejni = true;
1047 #if !defined(NDEBUG)
1048 else if (strcmp("jit", opt_arg) == 0) {
1052 compileverbose = true;
1056 printf("Unknown -verbose option: %s\n", opt_arg);
1061 case OPT_DEBUGCOLOR:
1062 opt_debugcolor = true;
1065 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1067 opt_typecheckverbose = true;
1076 case OPT_FULLVERSION:
1080 case OPT_SHOWVERSION:
1088 #if defined(ENABLE_VERIFIER)
1094 #if defined(ENABLE_STATISTICS)
1096 opt_getcompilingtime = true;
1097 opt_getloadingtime = true;
1110 for (i = 0; i < strlen(opt_arg); i++) {
1111 switch (opt_arg[i]) {
1113 checkbounds = false;
1126 makeinitializations = false;
1129 #if !defined(NDEBUG)
1133 makeinitializations = false;
1138 opt_method = opt_arg;
1139 makeinitializations = false;
1143 opt_signature = opt_arg;
1147 case OPT_SHOW: /* Display options */
1148 for (i = 0; i < strlen(opt_arg); i++) {
1149 switch (opt_arg[i]) {
1151 showconstantpool = true;
1163 opt_showintermediate = true;
1164 compileverbose = true;
1167 #if defined(ENABLE_DISASSEMBLER)
1169 opt_showdisassemble = true;
1170 compileverbose = true;
1174 opt_shownops = true;
1179 opt_showddatasegment = true;
1188 #if defined(ENABLE_LOOP)
1194 #if defined(ENABLE_IFCONV)
1200 #if defined(ENABLE_LSRA)
1205 #if defined(ENABLE_SSA)
1208 for (i = 0; i < strlen(opt_arg); i++) {
1209 switch (opt_arg[i]) {
1237 /* Already parsed. */
1241 #if defined(ENABLE_ASSERTION)
1242 assertion_ea_da(opt_arg, true);
1247 #if defined(ENABLE_ASSERTION)
1248 assertion_ea_da(opt_arg, false);
1253 #if defined(ENABLE_ASSERTION)
1254 assertion_user_enabled = true;
1259 #if defined(ENABLE_ASSERTION)
1260 assertion_user_enabled = false;
1265 #if defined(ENABLE_ASSERTION)
1266 assertion_system_enabled = true;
1271 #if defined(ENABLE_ASSERTION)
1272 assertion_system_enabled = false;
1276 #if defined(ENABLE_PROFILING)
1277 case OPT_PROF_OPTION:
1278 /* use <= to get the last \0 too */
1280 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1281 if (opt_arg[i] == ',')
1284 if (opt_arg[i] == '\0') {
1285 if (strcmp("bb", opt_arg + j) == 0)
1289 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1293 /* set k to next char */
1306 #if defined(ENABLE_JIT)
1309 printf("-Xjit option not enabled.\n");
1315 #if defined(ENABLE_INTRP)
1318 printf("-Xint option not enabled.\n");
1323 #if defined(ENABLE_INTRP)
1324 case OPT_STATIC_SUPERS:
1325 opt_static_supers = atoi(opt_arg);
1328 case OPT_NO_DYNAMIC:
1329 opt_no_dynamic = true;
1332 case OPT_NO_REPLICATION:
1333 opt_no_replication = true;
1336 case OPT_NO_QUICKSUPER:
1337 opt_no_quicksuper = true;
1345 #if defined(ENABLE_DEBUG_FILTER)
1346 case OPT_FILTER_VERBOSECALL_INCLUDE:
1347 opt_filter_verbosecall_include = opt_arg;
1350 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1351 opt_filter_verbosecall_exclude = opt_arg;
1354 case OPT_FILTER_SHOW_METHOD:
1355 opt_filter_show_method = opt_arg;
1360 printf("Unknown option: %s\n",
1361 vm_args->options[opt_index].optionString);
1366 /* get the main class *****************************************************/
1368 if (opt_index < vm_args->nOptions) {
1369 mainstring = vm_args->options[opt_index++].optionString;
1371 /* Put the jar file into the classpath (if any). */
1373 if (opt_jar == true) {
1374 /* free old classpath */
1376 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1378 /* put jarfile into classpath */
1380 p = MNEW(char, strlen(mainstring) + strlen("0"));
1382 strcpy(p, mainstring);
1384 #if defined(ENABLE_JAVASE)
1385 properties_add("java.class.path", p);
1389 /* replace .'s with /'s in classname */
1391 for (i = strlen(mainstring) - 1; i >= 0; i--)
1392 if (mainstring[i] == '.')
1393 mainstring[i] = '/';
1397 #if defined(ENABLE_JVMTI)
1399 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1400 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1403 MFREE(agentarg, char, strlen(agentarg));
1405 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1409 /* initialize this JVM ****************************************************/
1411 vm_initializing = true;
1413 /* initialize the garbage collector */
1415 gc_init(opt_heapmaxsize, opt_heapstartsize);
1417 #if defined(ENABLE_THREADS)
1418 /* BEFORE: threads_preinit */
1422 /* AFTER: gc_init (directly after, as this initializes the
1423 stopworldlock lock */
1430 /* install architecture dependent signal handlers */
1433 vm_abort("vm_create: signal_init failed");
1435 #if defined(ENABLE_INTRP)
1436 /* Allocate main thread stack on the Java heap. */
1439 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1440 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1444 /* AFTER: threads_preinit */
1447 vm_abort("vm_create: string_init failed");
1449 /* AFTER: threads_preinit */
1453 /* AFTER: thread_preinit */
1456 vm_abort("vm_create: suck_init failed");
1458 suck_add_from_property("java.endorsed.dirs");
1460 /* Now we have all options handled and we can print the version
1463 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1468 /* AFTER: utf8_init */
1470 boot_class_path = properties_get("sun.boot.class.path");
1471 suck_add(boot_class_path);
1473 /* initialize the classcache hashtable stuff: lock, hashtable
1474 (must be done _after_ threads_preinit) */
1476 if (!classcache_init())
1477 vm_abort("vm_create: classcache_init failed");
1479 /* Initialize the code memory management. */
1480 /* AFTER: threads_preinit */
1484 /* initialize the finalizer stuff (must be done _after_
1487 if (!finalizer_init())
1488 vm_abort("vm_create: finalizer_init failed");
1490 /* Initialize the JIT compiler. */
1496 #if defined(ENABLE_PYTHON)
1500 /* BEFORE: loader_preinit */
1504 /* AFTER: utf8_init, classcache_init */
1509 /* AFTER: loader_preinit, linker_preinit */
1516 /* AFTER: loader_init, linker_init */
1518 primitive_postinit();
1521 #if defined(ENABLE_JIT)
1525 if (!builtin_init())
1526 vm_abort("vm_create: builtin_init failed");
1528 /* Initialize the native subsystem. */
1529 /* BEFORE: threads_init */
1532 vm_abort("vm_create: native_init failed");
1534 /* Register the native methods implemented in the VM. */
1535 /* BEFORE: threads_init */
1539 #if defined(ENABLE_JNI)
1540 /* Initialize the JNI subsystem (must be done _before_
1541 threads_init, as threads_init can call JNI methods
1542 (e.g. NewGlobalRef). */
1545 vm_abort("vm_create: jni_init failed");
1548 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1549 /* Initialize the local reference table for the main thread. */
1550 /* BEFORE: threads_init */
1552 if (!localref_table_init())
1553 vm_abort("vm_create: localref_table_init failed");
1556 /* Iinitialize some important system classes. */
1557 /* BEFORE: threads_init */
1561 #if defined(ENABLE_THREADS)
1565 /* Initialize the native VM subsystem. */
1566 /* AFTER: threads_init (at least for SUN's classes) */
1570 #if defined(ENABLE_PROFILING)
1571 /* initialize profiling */
1573 if (!profile_init())
1574 vm_abort("vm_create: profile_init failed");
1577 #if defined(ENABLE_THREADS)
1578 /* initialize recompilation */
1580 if (!recompile_init())
1581 vm_abort("vm_create: recompile_init failed");
1583 /* start the signal handler thread */
1585 #if defined(__LINUX__)
1586 /* XXX Remove for exact-GC. */
1587 if (threads_pthreads_implementation_nptl)
1589 if (!signal_start_thread())
1590 vm_abort("vm_create: signal_start_thread failed");
1592 /* finally, start the finalizer thread */
1594 if (!finalizer_start_thread())
1595 vm_abort("vm_create: finalizer_start_thread failed");
1597 # if !defined(NDEBUG)
1598 /* start the memory profiling thread */
1600 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1601 if (!memory_start_thread())
1602 vm_abort("vm_create: memory_start_thread failed");
1605 /* start the recompilation thread (must be done before the
1606 profiling thread) */
1608 if (!recompile_start_thread())
1609 vm_abort("vm_create: recompile_start_thread failed");
1611 # if defined(ENABLE_PROFILING)
1612 /* start the profile sampling thread */
1615 /* if (!profile_start_thread()) */
1616 /* vm_abort("vm_create: profile_start_thread failed"); */
1620 #if defined(ENABLE_JVMTI)
1621 # if defined(ENABLE_GC_CACAO)
1622 /* XXX this will not work with the new indirection cells for classloaders!!! */
1626 /* add agent library to native library hashtable */
1627 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1631 /* Increment the number of VMs. */
1635 /* Initialization is done, VM is created.. */
1638 vm_initializing = false;
1640 /* Print the VM configuration after all stuff is set and the VM is
1643 if (opt_PrintConfig)
1646 /* everything's ok */
1652 /* vm_run **********************************************************************
1654 Runs the main-method of the passed class.
1656 *******************************************************************************/
1658 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1661 classinfo *mainclass;
1664 java_handle_objectarray_t *oa;
1671 #if defined(ENABLE_THREADS)
1675 #if !defined(NDEBUG)
1681 if (opt_method != NULL) {
1682 vm_compile_method();
1685 #endif /* !defined(NDEBUG) */
1687 /* should we run the main-method? */
1689 if (mainstring == NULL)
1692 /* set return value to OK */
1696 if (opt_jar == true) {
1697 /* open jar file with java.util.jar.JarFile */
1699 mainstring = vm_get_mainclass_from_jar(mainstring);
1701 if (mainstring == NULL)
1705 /* load the main class */
1707 mainutf = utf_new_char(mainstring);
1709 #if defined(ENABLE_JAVAME_CLDC1_1)
1710 mainclass = load_class_bootstrap(mainutf);
1712 mainclass = load_class_from_sysloader(mainutf);
1715 /* error loading class */
1717 e = exceptions_get_and_clear_exception();
1719 if ((e != NULL) || (mainclass == NULL)) {
1720 exceptions_throw_noclassdeffounderror_cause(e);
1721 exceptions_print_stacktrace();
1725 if (!link_class(mainclass)) {
1726 exceptions_print_stacktrace();
1730 /* find the `main' method of the main class */
1732 m = class_resolveclassmethod(mainclass,
1733 utf_new_char("main"),
1734 utf_new_char("([Ljava/lang/String;)V"),
1735 class_java_lang_Object,
1738 if (exceptions_get_exception()) {
1739 exceptions_print_stacktrace();
1743 /* there is no main method or it isn't static */
1745 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1746 exceptions_clear_exception();
1747 exceptions_throw_nosuchmethoderror(mainclass,
1748 utf_new_char("main"),
1749 utf_new_char("([Ljava/lang/String;)V"));
1751 exceptions_print_stacktrace();
1755 /* build argument array */
1757 oalength = vm_args->nOptions - opt_index;
1759 oa = builtin_anewarray(oalength, class_java_lang_String);
1761 for (i = 0; i < oalength; i++) {
1762 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1763 s = javastring_new(u);
1765 array_objectarray_element_set(oa, i, s);
1768 #ifdef TYPEINFO_DEBUG_TEST
1769 /* test the typeinfo system */
1772 /*class_showmethods(currentThread->group->header.vftbl->class); */
1774 #if defined(ENABLE_JVMTI)
1775 jvmti_set_phase(JVMTI_PHASE_LIVE);
1778 /* set ThreadMXBean variables */
1780 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1781 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1783 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1784 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1785 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1786 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1788 /* start the main thread */
1790 (void) vm_call_method(m, NULL, oa);
1792 /* exception occurred? */
1794 if (exceptions_get_exception()) {
1795 exceptions_print_stacktrace();
1799 #if defined(ENABLE_THREADS)
1800 /* Detach the main thread so that it appears to have ended when
1801 the application's main method exits. */
1803 t = thread_get_current();
1805 if (!threads_detach_thread(t))
1806 vm_abort("vm_run: Could not detach main thread.");
1809 /* Destroy the JavaVM. */
1811 (void) vm_destroy(vm);
1819 /* vm_destroy ******************************************************************
1821 Unloads a Java VM and reclaims its resources.
1823 *******************************************************************************/
1825 int vm_destroy(JavaVM *vm)
1827 #if defined(ENABLE_THREADS)
1828 /* Create a a trivial new Java waiter thread called
1831 JavaVMAttachArgs args;
1833 args.name = "DestroyJavaVM";
1836 if (!threads_attach_current_thread(&args, false))
1839 /* Wait until we are the last non-daemon thread. */
1841 threads_join_all_threads();
1848 /* Everything is ok. */
1854 /* vm_exit *********************************************************************
1856 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1858 *******************************************************************************/
1860 void vm_exit(s4 status)
1864 /* signal that we are exiting */
1868 assert(class_java_lang_System);
1869 assert(class_java_lang_System->state & CLASS_LOADED);
1871 #if defined(ENABLE_JVMTI)
1872 if (jvmti || (dbgcom!=NULL)) {
1873 jvmti_set_phase(JVMTI_PHASE_DEAD);
1874 if (jvmti) jvmti_agentunload();
1878 if (!link_class(class_java_lang_System)) {
1879 exceptions_print_stacktrace();
1883 /* call java.lang.System.exit(I)V */
1885 m = class_resolveclassmethod(class_java_lang_System,
1886 utf_new_char("exit"),
1888 class_java_lang_Object,
1892 exceptions_print_stacktrace();
1896 /* call the exit function with passed exit status */
1898 (void) vm_call_method(m, NULL, status);
1900 /* If we had an exception, just ignore the exception and exit with
1903 vm_shutdown(status);
1907 /* vm_shutdown *****************************************************************
1909 Terminates the system immediately without freeing memory explicitly
1910 (to be used only for abnormal termination).
1912 *******************************************************************************/
1914 void vm_shutdown(s4 status)
1917 #if defined(ENABLE_STATISTICS)
1918 || opt_getcompilingtime || opt_stat
1922 log_text("CACAO terminated by shutdown");
1923 dolog("Exit status: %d\n", (s4) status);
1927 #if defined(ENABLE_JVMTI)
1928 /* terminate cacaodbgserver */
1930 mutex_lock(&dbgcomlock);
1932 mutex_unlock(&dbgcomlock);
1933 jvmti_cacaodbgserver_quit();
1941 /* vm_exit_handler *************************************************************
1943 The exit_handler function is called upon program termination.
1945 ATTENTION: Don't free system resources here! Some threads may still
1946 be running as this is called from VMRuntime.exit(). The OS does the
1949 *******************************************************************************/
1951 void vm_exit_handler(void)
1953 #if !defined(NDEBUG)
1955 class_showmethods(mainclass);
1957 if (showconstantpool)
1958 class_showconstantpool(mainclass);
1963 # if defined(ENABLE_PROFILING)
1965 profile_printstats();
1967 #endif /* !defined(NDEBUG) */
1969 #if defined(ENABLE_RT_TIMING)
1970 rt_timing_print_time_stats(stderr);
1973 #if defined(ENABLE_CYCLES_STATS)
1974 builtin_print_cycles_stats(stderr);
1975 stacktrace_print_cycles_stats(stderr);
1979 #if defined(ENABLE_STATISTICS)
1980 || opt_getcompilingtime || opt_stat
1984 log_text("CACAO terminated");
1986 #if defined(ENABLE_STATISTICS)
1989 #ifdef TYPECHECK_STATISTICS
1990 typecheck_print_statistics(get_logfile());
1994 if (opt_getcompilingtime)
1996 #endif /* defined(ENABLE_STATISTICS) */
1998 /* vm_print_profile(stderr);*/
2002 /* vm_abort ********************************************************************
2004 Prints an error message and aborts the VM.
2007 text ... error message to print
2009 *******************************************************************************/
2011 void vm_abort(const char *text, ...)
2015 /* Print the log message. */
2020 log_vprint(text, ap);
2025 /* Now abort the VM. */
2031 /* vm_abort_errnum *************************************************************
2033 Prints an error message, appends ":" plus the strerror-message of
2034 errnum and aborts the VM.
2037 errnum ... error number
2038 text ..... error message to print
2040 *******************************************************************************/
2042 void vm_abort_errnum(int errnum, const char *text, ...)
2046 /* Print the log message. */
2051 log_vprint(text, ap);
2054 /* Print the strerror-message of errnum. */
2056 log_print(": %s", system_strerror(errnum));
2060 /* Now abort the VM. */
2066 /* vm_abort_errno **************************************************************
2068 Equal to vm_abort_errnum, but uses errno to get the error number.
2071 text ... error message to print
2073 *******************************************************************************/
2075 void vm_abort_errno(const char *text, ...)
2080 vm_abort_errnum(errno, text, ap);
2085 /* vm_abort_disassemble ********************************************************
2087 Prints an error message, disassemble the given code range (if
2088 enabled) and aborts the VM.
2091 pc.......PC to disassemble
2092 count....number of instructions to disassemble
2094 *******************************************************************************/
2096 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2099 #if defined(ENABLE_DISASSEMBLER)
2103 /* Print debug message. */
2108 log_vprint(text, ap);
2115 #if SIZEOF_VOID_P == 8
2116 log_println("PC=0x%016lx", pc);
2118 log_println("PC=0x%08x", pc);
2121 #if defined(ENABLE_DISASSEMBLER)
2122 log_println("machine instructions at PC:");
2124 /* Disassemble the given number of instructions. */
2126 for (i = 0; i < count; i++)
2127 pc = disassinstr(pc);
2130 vm_abort("Aborting...");
2134 /* vm_get_mainclass_from_jar ***************************************************
2136 Gets the name of the main class from a JAR's manifest file.
2138 *******************************************************************************/
2140 static char *vm_get_mainclass_from_jar(char *mainstring)
2147 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2150 exceptions_print_stacktrace();
2154 /* create JarFile object */
2159 exceptions_print_stacktrace();
2163 m = class_resolveclassmethod(c,
2165 utf_java_lang_String__void,
2166 class_java_lang_Object,
2170 exceptions_print_stacktrace();
2174 s = javastring_new_from_ascii(mainstring);
2176 (void) vm_call_method(m, o, s);
2178 if (exceptions_get_exception()) {
2179 exceptions_print_stacktrace();
2183 /* get manifest object */
2185 m = class_resolveclassmethod(c,
2186 utf_new_char("getManifest"),
2187 utf_new_char("()Ljava/util/jar/Manifest;"),
2188 class_java_lang_Object,
2192 exceptions_print_stacktrace();
2196 o = vm_call_method(m, o);
2199 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2204 /* get Main Attributes */
2206 LLNI_class_get(o, c);
2208 m = class_resolveclassmethod(c,
2209 utf_new_char("getMainAttributes"),
2210 utf_new_char("()Ljava/util/jar/Attributes;"),
2211 class_java_lang_Object,
2215 exceptions_print_stacktrace();
2219 o = vm_call_method(m, o);
2222 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2227 /* get property Main-Class */
2229 LLNI_class_get(o, c);
2231 m = class_resolveclassmethod(c,
2232 utf_new_char("getValue"),
2233 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2234 class_java_lang_Object,
2238 exceptions_print_stacktrace();
2242 s = javastring_new_from_ascii("Main-Class");
2244 o = vm_call_method(m, o, s);
2247 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2248 fprintf(stderr, "%s\n", mainstring);
2252 return javastring_tochar(o);
2256 /* vm_compile_all **************************************************************
2258 Compile all methods found in the bootclasspath.
2260 *******************************************************************************/
2262 #if !defined(NDEBUG)
2263 static void vm_compile_all(void)
2268 classcache_name_entry *nmen;
2269 classcache_class_entry *clsen;
2272 /* create all classes found in the bootclasspath */
2273 /* XXX currently only works with zip/jar's */
2275 loader_load_all_classes();
2277 /* link all classes */
2279 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2280 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2282 for (; nmen; nmen = nmen->hashlink) {
2283 /* iterate over all class entries */
2285 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2286 c = clsen->classobj;
2291 if (!(c->state & CLASS_LINKED)) {
2292 if (!link_class(c)) {
2293 fprintf(stderr, "Error linking: ");
2294 utf_fprint_printable_ascii_classname(stderr, c->name);
2295 fprintf(stderr, "\n");
2297 /* print out exception and cause */
2299 exceptions_print_current_exception();
2301 /* goto next class */
2307 /* compile all class methods */
2309 for (i = 0; i < c->methodscount; i++) {
2310 m = &(c->methods[i]);
2312 if (m->jcode != NULL) {
2313 if (!jit_compile(m)) {
2314 fprintf(stderr, "Error compiling: ");
2315 utf_fprint_printable_ascii_classname(stderr, c->name);
2316 fprintf(stderr, ".");
2317 utf_fprint_printable_ascii(stderr, m->name);
2318 utf_fprint_printable_ascii(stderr, m->descriptor);
2319 fprintf(stderr, "\n");
2321 /* print out exception and cause */
2323 exceptions_print_current_exception();
2331 #endif /* !defined(NDEBUG) */
2334 /* vm_compile_method ***********************************************************
2336 Compile a specific method.
2338 *******************************************************************************/
2340 #if !defined(NDEBUG)
2341 static void vm_compile_method(void)
2345 /* create, load and link the main class */
2347 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2349 if (mainclass == NULL)
2350 exceptions_print_stacktrace();
2352 if (!link_class(mainclass))
2353 exceptions_print_stacktrace();
2355 if (opt_signature != NULL) {
2356 m = class_resolveclassmethod(mainclass,
2357 utf_new_char(opt_method),
2358 utf_new_char(opt_signature),
2363 m = class_resolveclassmethod(mainclass,
2364 utf_new_char(opt_method),
2371 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2372 opt_method, opt_signature ? opt_signature : "");
2376 #endif /* !defined(NDEBUG) */
2379 /* vm_call_array ***************************************************************
2381 Calls a Java method with a variable number of arguments, passed via
2384 ATTENTION: This function has to be used outside the nativeworld.
2386 *******************************************************************************/
2388 #define VM_CALL_ARRAY(name, type) \
2389 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2395 assert(m->code != NULL); \
2397 md = m->parseddesc; \
2398 pv = m->code->entrypoint; \
2400 STATISTICS(count_calls_native_to_java++); \
2402 value = asm_vm_call_method##name(pv, array, md->memuse); \
2407 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2413 assert(m->code != NULL);
2416 pv = m->code->entrypoint;
2418 STATISTICS(count_calls_native_to_java++);
2420 o = asm_vm_call_method(pv, array, md->memuse);
2422 if (md->returntype.type == TYPE_VOID)
2425 return LLNI_WRAP(o);
2428 VM_CALL_ARRAY(_int, int32_t)
2429 VM_CALL_ARRAY(_long, int64_t)
2430 VM_CALL_ARRAY(_float, float)
2431 VM_CALL_ARRAY(_double, double)
2434 /* vm_call_method **************************************************************
2436 Calls a Java method with a variable number of arguments.
2438 *******************************************************************************/
2440 #define VM_CALL_METHOD(name, type) \
2441 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2447 value = vm_call_method##name##_valist(m, o, ap); \
2453 VM_CALL_METHOD(, java_handle_t *)
2454 VM_CALL_METHOD(_int, int32_t)
2455 VM_CALL_METHOD(_long, int64_t)
2456 VM_CALL_METHOD(_float, float)
2457 VM_CALL_METHOD(_double, double)
2460 /* vm_call_method_valist *******************************************************
2462 Calls a Java method with a variable number of arguments, passed via
2465 *******************************************************************************/
2467 #define VM_CALL_METHOD_VALIST(name, type) \
2468 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2473 int32_t dumpmarker; \
2475 if (m->code == NULL) \
2476 if (!jit_compile(m)) \
2479 THREAD_NATIVEWORLD_EXIT; \
2482 array = argument_vmarray_from_valist(m, o, ap); \
2483 value = vm_call##name##_array(m, array); \
2486 THREAD_NATIVEWORLD_ENTER; \
2491 VM_CALL_METHOD_VALIST(, java_handle_t *)
2492 VM_CALL_METHOD_VALIST(_int, int32_t)
2493 VM_CALL_METHOD_VALIST(_long, int64_t)
2494 VM_CALL_METHOD_VALIST(_float, float)
2495 VM_CALL_METHOD_VALIST(_double, double)
2498 /* vm_call_method_jvalue *******************************************************
2500 Calls a Java method with a variable number of arguments, passed via
2503 *******************************************************************************/
2505 #define VM_CALL_METHOD_JVALUE(name, type) \
2506 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2507 const jvalue *args) \
2511 int32_t dumpmarker; \
2513 if (m->code == NULL) \
2514 if (!jit_compile(m)) \
2517 THREAD_NATIVEWORLD_EXIT; \
2520 array = argument_vmarray_from_jvalue(m, o, args); \
2521 value = vm_call##name##_array(m, array); \
2524 THREAD_NATIVEWORLD_ENTER; \
2529 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2530 VM_CALL_METHOD_JVALUE(_int, int32_t)
2531 VM_CALL_METHOD_JVALUE(_long, int64_t)
2532 VM_CALL_METHOD_JVALUE(_float, float)
2533 VM_CALL_METHOD_JVALUE(_double, double)
2536 /* vm_call_method_objectarray **************************************************
2538 Calls a Java method with a variable number if arguments, passed via
2539 an objectarray of boxed values. Returns a boxed value.
2541 *******************************************************************************/
2543 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2544 java_handle_objectarray_t *params)
2547 java_handle_t *xptr;
2552 /* Prevent compiler warnings. */
2556 /* compile methods which are not yet compiled */
2558 if (m->code == NULL)
2559 if (!jit_compile(m))
2562 /* leave the nativeworld */
2564 THREAD_NATIVEWORLD_EXIT;
2566 /* mark start of dump memory area */
2570 /* Fill the argument array from a object-array. */
2572 array = argument_vmarray_from_objectarray(m, o, params);
2574 if (array == NULL) {
2575 /* release dump area */
2579 /* enter the nativeworld again */
2581 THREAD_NATIVEWORLD_ENTER;
2583 exceptions_throw_illegalargumentexception();
2588 switch (m->parseddesc->returntype.decltype) {
2589 case PRIMITIVETYPE_VOID:
2590 value.a = vm_call_array(m, array);
2593 case PRIMITIVETYPE_BOOLEAN:
2594 case PRIMITIVETYPE_BYTE:
2595 case PRIMITIVETYPE_CHAR:
2596 case PRIMITIVETYPE_SHORT:
2597 case PRIMITIVETYPE_INT:
2598 value.i = vm_call_int_array(m, array);
2601 case PRIMITIVETYPE_LONG:
2602 value.l = vm_call_long_array(m, array);
2605 case PRIMITIVETYPE_FLOAT:
2606 value.f = vm_call_float_array(m, array);
2609 case PRIMITIVETYPE_DOUBLE:
2610 value.d = vm_call_double_array(m, array);
2614 ro = vm_call_array(m, array);
2618 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2621 /* release dump area */
2625 /* enter the nativeworld again */
2627 THREAD_NATIVEWORLD_ENTER;
2629 /* box the return value if necesarry */
2631 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2632 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2634 /* check for an exception */
2636 xptr = exceptions_get_exception();
2639 /* clear exception pointer, we are calling JIT code again */
2641 exceptions_clear_exception();
2643 exceptions_throw_invocationtargetexception(xptr);
2651 * These are local overrides for various environment variables in Emacs.
2652 * Please do not remove this and leave it at the end of the file, where
2653 * Emacs will automagically detect them.
2654 * ---------------------------------------------------------------------
2657 * indent-tabs-mode: t
2661 * vim:noexpandtab:sw=4:ts=4: