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_JAVA_RUNTIME_LIBRARY_OPENJDK)
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/threadlist.h"
63 #include "threads/thread.h"
65 #include "toolbox/logging.h"
69 #if defined(ENABLE_ASSERTION)
70 #include "vm/assertion.h"
73 #include "vm/builtin.h"
74 #include "vm/exceptions.h"
75 #include "vm/finalizer.h"
76 #include "vm/global.h"
77 #include "vm/initialize.h"
78 #include "vm/package.hpp"
79 #include "vm/primitive.hpp"
80 #include "vm/properties.h"
81 #include "vm/signallocal.h"
82 #include "vm/stringlocal.h"
85 #include "vm/jit/argument.h"
86 #include "vm/jit/asmpart.h"
87 #include "vm/jit/code.h"
89 #if defined(ENABLE_DISASSEMBLER)
90 # include "vm/jit/disass.h"
93 #include "vm/jit/jit.h"
94 #include "vm/jit/methodtree.h"
96 #if defined(ENABLE_PROFILING)
97 # include "vm/jit/optimizing/profile.h"
100 #include "vm/jit/optimizing/recompile.h"
102 #if defined(ENABLE_PYTHON)
103 # include "vm/jit/python.h"
106 #include "vm/jit/trap.h"
108 #include "vmcore/classcache.h"
109 #include "vmcore/options.h"
110 #include "vmcore/statistics.h"
111 #include "vmcore/suck.h"
112 #include "vmcore/system.h"
114 #if defined(ENABLE_JVMTI)
115 # include "native/jvmti/cacaodbg.h"
118 #if defined(ENABLE_VMLOG)
119 #include <vmlog_cacao.h>
123 /* Invocation API variables ***************************************************/
125 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
126 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
129 /* global variables ***********************************************************/
131 s4 vms = 0; /* number of VMs created */
133 bool vm_initializing = false;
134 bool vm_created = false;
135 bool vm_exiting = false;
137 static 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(ENABLE_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_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
641 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
642 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
643 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
644 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
645 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_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_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
657 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
658 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
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(char* mainname);
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 #if defined(ENABLE_JVMTI)
1366 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1367 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1370 MFREE(agentarg, char, strlen(agentarg));
1372 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1376 /* initialize this JVM ****************************************************/
1378 vm_initializing = true;
1380 /* initialize the garbage collector */
1382 gc_init(opt_heapmaxsize, opt_heapstartsize);
1384 #if defined(ENABLE_THREADS)
1385 /* BEFORE: threads_preinit */
1389 /* AFTER: gc_init (directly after, as this initializes the
1390 stopworldlock lock */
1396 /* install architecture dependent signal handlers */
1399 vm_abort("vm_create: signal_init failed");
1401 #if defined(ENABLE_INTRP)
1402 /* Allocate main thread stack on the Java heap. */
1405 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1406 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1410 /* AFTER: threads_preinit */
1413 vm_abort("vm_create: string_init failed");
1415 /* AFTER: threads_preinit */
1419 /* AFTER: thread_preinit */
1422 vm_abort("vm_create: suck_init failed");
1424 suck_add_from_property("java.endorsed.dirs");
1426 /* Now we have all options handled and we can print the version
1429 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1434 /* AFTER: utf8_init */
1436 boot_class_path = properties_get("sun.boot.class.path");
1437 suck_add(boot_class_path);
1439 /* initialize the classcache hashtable stuff: lock, hashtable
1440 (must be done _after_ threads_preinit) */
1442 if (!classcache_init())
1443 vm_abort("vm_create: classcache_init failed");
1445 /* Initialize the code memory management. */
1446 /* AFTER: threads_preinit */
1450 /* initialize the finalizer stuff (must be done _after_
1453 if (!finalizer_init())
1454 vm_abort("vm_create: finalizer_init failed");
1456 /* Initialize the JIT compiler. */
1462 #if defined(ENABLE_PYTHON)
1466 /* BEFORE: loader_preinit */
1468 Package_initialize();
1470 /* AFTER: utf8_init, classcache_init */
1475 /* AFTER: loader_preinit, linker_preinit */
1482 /* AFTER: loader_init, linker_init */
1484 primitive_postinit();
1487 #if defined(ENABLE_JIT)
1491 if (!builtin_init())
1492 vm_abort("vm_create: builtin_init failed");
1494 /* Initialize the native subsystem. */
1495 /* BEFORE: threads_init */
1498 vm_abort("vm_create: native_init failed");
1500 /* Register the native methods implemented in the VM. */
1501 /* BEFORE: threads_init */
1505 #if defined(ENABLE_JNI)
1506 /* Initialize the JNI subsystem (must be done _before_
1507 threads_init, as threads_init can call JNI methods
1508 (e.g. NewGlobalRef). */
1511 vm_abort("vm_create: jni_init failed");
1514 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1515 /* Initialize the local reference table for the main thread. */
1516 /* BEFORE: threads_init */
1518 if (!localref_table_init())
1519 vm_abort("vm_create: localref_table_init failed");
1522 /* Iinitialize some important system classes. */
1523 /* BEFORE: threads_init */
1527 #if defined(ENABLE_THREADS)
1531 /* Initialize the native VM subsystem. */
1532 /* AFTER: threads_init (at least for SUN's classes) */
1536 #if defined(ENABLE_PROFILING)
1537 /* initialize profiling */
1539 if (!profile_init())
1540 vm_abort("vm_create: profile_init failed");
1543 #if defined(ENABLE_THREADS)
1544 /* initialize recompilation */
1546 if (!recompile_init())
1547 vm_abort("vm_create: recompile_init failed");
1549 /* start the signal handler thread */
1551 #if defined(__LINUX__)
1552 /* XXX Remove for exact-GC. */
1553 if (threads_pthreads_implementation_nptl)
1555 if (!signal_start_thread())
1556 vm_abort("vm_create: signal_start_thread failed");
1558 /* finally, start the finalizer thread */
1560 if (!finalizer_start_thread())
1561 vm_abort("vm_create: finalizer_start_thread failed");
1563 # if !defined(NDEBUG)
1564 /* start the memory profiling thread */
1566 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1567 if (!memory_start_thread())
1568 vm_abort("vm_create: memory_start_thread failed");
1571 /* start the recompilation thread (must be done before the
1572 profiling thread) */
1574 if (!recompile_start_thread())
1575 vm_abort("vm_create: recompile_start_thread failed");
1577 # if defined(ENABLE_PROFILING)
1578 /* start the profile sampling thread */
1581 /* if (!profile_start_thread()) */
1582 /* vm_abort("vm_create: profile_start_thread failed"); */
1586 #if defined(ENABLE_JVMTI)
1587 # if defined(ENABLE_GC_CACAO)
1588 /* XXX this will not work with the new indirection cells for classloaders!!! */
1592 /* add agent library to native library hashtable */
1593 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1597 /* Increment the number of VMs. */
1601 /* Initialization is done, VM is created.. */
1604 vm_initializing = false;
1606 /* Print the VM configuration after all stuff is set and the VM is
1609 if (opt_PrintConfig)
1612 /* everything's ok */
1618 /* vm_run **********************************************************************
1620 Runs the main-method of the passed class.
1622 *******************************************************************************/
1624 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1630 classinfo *mainclass;
1633 java_handle_objectarray_t *oa;
1640 // Prevent compiler warnings.
1643 #if !defined(NDEBUG)
1650 /* Get the main class plus it's arguments. */
1654 if (opt_index < vm_args->nOptions) {
1655 /* Get main-class argument. */
1657 mainname = vm_args->options[opt_index].optionString;
1659 /* If the main class argument is a jar file, put it into the
1662 if (opt_jar == true) {
1663 p = MNEW(char, strlen(mainname) + strlen("0"));
1665 strcpy(p, mainname);
1667 #if defined(ENABLE_JAVASE)
1668 properties_add("java.class.path", p);
1672 /* Replace dots with slashes in the class name. */
1674 for (i = 0; i < strlen(mainname); i++)
1675 if (mainname[i] == '.')
1679 /* Build argument array. Move index to first argument. */
1683 oalength = vm_args->nOptions - opt_index;
1685 oa = builtin_anewarray(oalength, class_java_lang_String);
1687 for (i = 0; i < oalength; i++) {
1688 option = vm_args->options[opt_index + i].optionString;
1690 u = utf_new_char(option);
1691 s = javastring_new(u);
1693 array_objectarray_element_set(oa, i, s);
1697 /* Do we have a main-class argument? */
1699 if (mainname == NULL)
1702 #if !defined(NDEBUG)
1703 if (opt_method != NULL) {
1704 vm_compile_method(mainname);
1709 /* set return value to OK */
1713 if (opt_jar == true) {
1714 /* open jar file with java.util.jar.JarFile */
1716 mainname = vm_get_mainclass_from_jar(mainname);
1718 if (mainname == NULL)
1722 /* load the main class */
1724 mainutf = utf_new_char(mainname);
1726 #if defined(ENABLE_JAVAME_CLDC1_1)
1727 mainclass = load_class_bootstrap(mainutf);
1729 mainclass = load_class_from_sysloader(mainutf);
1732 /* error loading class */
1734 e = exceptions_get_and_clear_exception();
1736 if ((e != NULL) || (mainclass == NULL)) {
1737 exceptions_throw_noclassdeffounderror_cause(e);
1738 exceptions_print_stacktrace();
1742 if (!link_class(mainclass)) {
1743 exceptions_print_stacktrace();
1747 /* find the `main' method of the main class */
1749 m = class_resolveclassmethod(mainclass,
1750 utf_new_char("main"),
1751 utf_new_char("([Ljava/lang/String;)V"),
1752 class_java_lang_Object,
1755 if (exceptions_get_exception()) {
1756 exceptions_print_stacktrace();
1760 /* there is no main method or it isn't static */
1762 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1763 exceptions_clear_exception();
1764 exceptions_throw_nosuchmethoderror(mainclass,
1765 utf_new_char("main"),
1766 utf_new_char("([Ljava/lang/String;)V"));
1768 exceptions_print_stacktrace();
1772 #ifdef TYPEINFO_DEBUG_TEST
1773 /* test the typeinfo system */
1777 #if defined(ENABLE_JVMTI)
1778 jvmti_set_phase(JVMTI_PHASE_LIVE);
1781 /* set ThreadMXBean variables */
1783 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1784 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1786 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1787 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1788 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1789 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1791 /* start the main thread */
1793 (void) vm_call_method(m, NULL, oa);
1795 /* exception occurred? */
1797 if (exceptions_get_exception()) {
1798 exceptions_print_stacktrace();
1802 #if defined(ENABLE_THREADS)
1803 /* Detach the main thread so that it appears to have ended when
1804 the application's main method exits. */
1806 if (!thread_detach_current_thread())
1807 vm_abort("vm_run: Could not detach main thread.");
1810 /* Destroy the JavaVM. */
1812 (void) vm_destroy(vm);
1820 /* vm_destroy ******************************************************************
1822 Unloads a Java VM and reclaims its resources.
1824 *******************************************************************************/
1826 int vm_destroy(JavaVM *vm)
1828 #if defined(ENABLE_THREADS)
1829 /* Create a a trivial new Java waiter thread called
1832 JavaVMAttachArgs args;
1834 args.name = "DestroyJavaVM";
1837 if (!thread_attach_current_thread(&args, false))
1840 /* Wait until we are the last non-daemon thread. */
1842 threads_join_all_threads();
1849 /* Everything is ok. */
1855 /* vm_exit *********************************************************************
1857 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1859 *******************************************************************************/
1861 void vm_exit(s4 status)
1865 /* signal that we are exiting */
1869 assert(class_java_lang_System);
1870 assert(class_java_lang_System->state & CLASS_LOADED);
1872 #if defined(ENABLE_JVMTI)
1873 if (jvmti || (dbgcom!=NULL)) {
1874 jvmti_set_phase(JVMTI_PHASE_DEAD);
1875 if (jvmti) jvmti_agentunload();
1879 if (!link_class(class_java_lang_System)) {
1880 exceptions_print_stacktrace();
1884 /* call java.lang.System.exit(I)V */
1886 m = class_resolveclassmethod(class_java_lang_System,
1887 utf_new_char("exit"),
1889 class_java_lang_Object,
1893 exceptions_print_stacktrace();
1897 /* call the exit function with passed exit status */
1899 (void) vm_call_method(m, NULL, status);
1901 /* If we had an exception, just ignore the exception and exit with
1904 vm_shutdown(status);
1908 /* vm_shutdown *****************************************************************
1910 Terminates the system immediately without freeing memory explicitly
1911 (to be used only for abnormal termination).
1913 *******************************************************************************/
1915 void vm_shutdown(s4 status)
1918 #if defined(ENABLE_STATISTICS)
1919 || opt_getcompilingtime || opt_stat
1923 log_text("CACAO terminated by shutdown");
1924 dolog("Exit status: %d\n", (s4) status);
1928 #if defined(ENABLE_JVMTI)
1929 # error This should be a JVMTI function.
1930 /* terminate cacaodbgserver */
1932 Mutex_lock(&dbgcomlock);
1934 Mutex_unlock(&dbgcomlock);
1935 jvmti_cacaodbgserver_quit();
1943 /* vm_exit_handler *************************************************************
1945 The exit_handler function is called upon program termination.
1947 ATTENTION: Don't free system resources here! Some threads may still
1948 be running as this is called from VMRuntime.exit(). The OS does the
1951 *******************************************************************************/
1953 void vm_exit_handler(void)
1955 #if !defined(NDEBUG)
1957 class_showmethods(mainclass);
1959 if (showconstantpool)
1960 class_showconstantpool(mainclass);
1965 # if defined(ENABLE_PROFILING)
1967 profile_printstats();
1969 #endif /* !defined(NDEBUG) */
1971 #if defined(ENABLE_RT_TIMING)
1972 rt_timing_print_time_stats(stderr);
1975 #if defined(ENABLE_CYCLES_STATS)
1976 builtin_print_cycles_stats(stderr);
1977 stacktrace_print_cycles_stats(stderr);
1981 #if defined(ENABLE_STATISTICS)
1982 || opt_getcompilingtime || opt_stat
1986 log_text("CACAO terminated");
1988 #if defined(ENABLE_STATISTICS)
1991 #ifdef TYPECHECK_STATISTICS
1992 typecheck_print_statistics(get_logfile());
1996 if (opt_getcompilingtime)
1998 #endif /* defined(ENABLE_STATISTICS) */
2000 /* vm_print_profile(stderr);*/
2004 /* vm_abort ********************************************************************
2006 Prints an error message and aborts the VM.
2009 text ... error message to print
2011 *******************************************************************************/
2013 void vm_abort(const char *text, ...)
2017 /* Print the log message. */
2022 log_vprint(text, ap);
2027 /* Now abort the VM. */
2033 /* vm_abort_errnum *************************************************************
2035 Prints an error message, appends ":" plus the strerror-message of
2036 errnum and aborts the VM.
2039 errnum ... error number
2040 text ..... error message to print
2042 *******************************************************************************/
2044 void vm_abort_errnum(int errnum, const char *text, ...)
2048 /* Print the log message. */
2053 log_vprint(text, ap);
2056 /* Print the strerror-message of errnum. */
2058 log_print(": %s", system_strerror(errnum));
2062 /* Now abort the VM. */
2068 /* vm_abort_errno **************************************************************
2070 Equal to vm_abort_errnum, but uses errno to get the error number.
2073 text ... error message to print
2075 *******************************************************************************/
2077 void vm_abort_errno(const char *text, ...)
2082 vm_abort_errnum(errno, text, ap);
2087 /* vm_abort_disassemble ********************************************************
2089 Prints an error message, disassemble the given code range (if
2090 enabled) and aborts the VM.
2093 pc.......PC to disassemble
2094 count....number of instructions to disassemble
2096 *******************************************************************************/
2098 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2101 #if defined(ENABLE_DISASSEMBLER)
2105 /* Print debug message. */
2110 log_vprint(text, ap);
2117 #if SIZEOF_VOID_P == 8
2118 log_println("PC=0x%016lx", pc);
2120 log_println("PC=0x%08x", pc);
2123 #if defined(ENABLE_DISASSEMBLER)
2124 log_println("machine instructions at PC:");
2126 /* Disassemble the given number of instructions. */
2128 for (i = 0; i < count; i++)
2129 pc = disassinstr(pc);
2132 vm_abort("Aborting...");
2136 /* vm_get_mainclass_from_jar ***************************************************
2138 Gets the name of the main class from a JAR's manifest file.
2140 *******************************************************************************/
2142 static char *vm_get_mainclass_from_jar(char *mainname)
2149 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2152 exceptions_print_stacktrace();
2156 /* create JarFile object */
2161 exceptions_print_stacktrace();
2165 m = class_resolveclassmethod(c,
2167 utf_java_lang_String__void,
2168 class_java_lang_Object,
2172 exceptions_print_stacktrace();
2176 s = javastring_new_from_ascii(mainname);
2178 (void) vm_call_method(m, o, s);
2180 if (exceptions_get_exception()) {
2181 exceptions_print_stacktrace();
2185 /* get manifest object */
2187 m = class_resolveclassmethod(c,
2188 utf_new_char("getManifest"),
2189 utf_new_char("()Ljava/util/jar/Manifest;"),
2190 class_java_lang_Object,
2194 exceptions_print_stacktrace();
2198 o = vm_call_method(m, o);
2201 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2206 /* get Main Attributes */
2208 LLNI_class_get(o, c);
2210 m = class_resolveclassmethod(c,
2211 utf_new_char("getMainAttributes"),
2212 utf_new_char("()Ljava/util/jar/Attributes;"),
2213 class_java_lang_Object,
2217 exceptions_print_stacktrace();
2221 o = vm_call_method(m, o);
2224 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2229 /* get property Main-Class */
2231 LLNI_class_get(o, c);
2233 m = class_resolveclassmethod(c,
2234 utf_new_char("getValue"),
2235 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2236 class_java_lang_Object,
2240 exceptions_print_stacktrace();
2244 s = javastring_new_from_ascii("Main-Class");
2246 o = vm_call_method(m, o, s);
2249 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2250 fprintf(stderr, "%s\n", mainname);
2254 return javastring_tochar(o);
2258 /* vm_compile_all **************************************************************
2260 Compile all methods found in the bootclasspath.
2262 *******************************************************************************/
2264 #if !defined(NDEBUG)
2265 static void vm_compile_all(void)
2270 classcache_name_entry *nmen;
2271 classcache_class_entry *clsen;
2274 /* create all classes found in the bootclasspath */
2275 /* XXX currently only works with zip/jar's */
2277 loader_load_all_classes();
2279 /* link all classes */
2281 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2282 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2284 for (; nmen; nmen = nmen->hashlink) {
2285 /* iterate over all class entries */
2287 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2288 c = clsen->classobj;
2293 if (!(c->state & CLASS_LINKED)) {
2294 if (!link_class(c)) {
2295 fprintf(stderr, "Error linking: ");
2296 utf_fprint_printable_ascii_classname(stderr, c->name);
2297 fprintf(stderr, "\n");
2299 /* print out exception and cause */
2301 exceptions_print_current_exception();
2303 /* goto next class */
2309 /* compile all class methods */
2311 for (i = 0; i < c->methodscount; i++) {
2312 m = &(c->methods[i]);
2314 if (m->jcode != NULL) {
2315 if (!jit_compile(m)) {
2316 fprintf(stderr, "Error compiling: ");
2317 utf_fprint_printable_ascii_classname(stderr, c->name);
2318 fprintf(stderr, ".");
2319 utf_fprint_printable_ascii(stderr, m->name);
2320 utf_fprint_printable_ascii(stderr, m->descriptor);
2321 fprintf(stderr, "\n");
2323 /* print out exception and cause */
2325 exceptions_print_current_exception();
2333 #endif /* !defined(NDEBUG) */
2336 /* vm_compile_method ***********************************************************
2338 Compile a specific method.
2340 *******************************************************************************/
2342 #if !defined(NDEBUG)
2343 static void vm_compile_method(char* mainname)
2347 /* create, load and link the main class */
2349 mainclass = load_class_bootstrap(utf_new_char(mainname));
2351 if (mainclass == NULL)
2352 exceptions_print_stacktrace();
2354 if (!link_class(mainclass))
2355 exceptions_print_stacktrace();
2357 if (opt_signature != NULL) {
2358 m = class_resolveclassmethod(mainclass,
2359 utf_new_char(opt_method),
2360 utf_new_char(opt_signature),
2365 m = class_resolveclassmethod(mainclass,
2366 utf_new_char(opt_method),
2373 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2374 opt_method, opt_signature ? opt_signature : "");
2378 #endif /* !defined(NDEBUG) */
2381 /* vm_call_array ***************************************************************
2383 Calls a Java method with a variable number of arguments, passed via
2386 ATTENTION: This function has to be used outside the nativeworld.
2388 *******************************************************************************/
2390 #define VM_CALL_ARRAY(name, type) \
2391 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2397 assert(m->code != NULL); \
2399 md = m->parseddesc; \
2400 pv = m->code->entrypoint; \
2402 STATISTICS(count_calls_native_to_java++); \
2404 value = asm_vm_call_method##name(pv, array, md->memuse); \
2409 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2415 assert(m->code != NULL);
2418 pv = m->code->entrypoint;
2420 STATISTICS(count_calls_native_to_java++);
2422 o = asm_vm_call_method(pv, array, md->memuse);
2424 if (md->returntype.type == TYPE_VOID)
2427 return LLNI_WRAP(o);
2430 VM_CALL_ARRAY(_int, int32_t)
2431 VM_CALL_ARRAY(_long, int64_t)
2432 VM_CALL_ARRAY(_float, float)
2433 VM_CALL_ARRAY(_double, double)
2436 /* vm_call_method **************************************************************
2438 Calls a Java method with a variable number of arguments.
2440 *******************************************************************************/
2442 #define VM_CALL_METHOD(name, type) \
2443 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2449 value = vm_call_method##name##_valist(m, o, ap); \
2455 VM_CALL_METHOD(, java_handle_t *)
2456 VM_CALL_METHOD(_int, int32_t)
2457 VM_CALL_METHOD(_long, int64_t)
2458 VM_CALL_METHOD(_float, float)
2459 VM_CALL_METHOD(_double, double)
2462 /* vm_call_method_valist *******************************************************
2464 Calls a Java method with a variable number of arguments, passed via
2467 *******************************************************************************/
2469 #define VM_CALL_METHOD_VALIST(name, type) \
2470 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2475 int32_t dumpmarker; \
2477 if (m->code == NULL) \
2478 if (!jit_compile(m)) \
2481 THREAD_NATIVEWORLD_EXIT; \
2484 array = argument_vmarray_from_valist(m, o, ap); \
2485 value = vm_call##name##_array(m, array); \
2488 THREAD_NATIVEWORLD_ENTER; \
2493 VM_CALL_METHOD_VALIST(, java_handle_t *)
2494 VM_CALL_METHOD_VALIST(_int, int32_t)
2495 VM_CALL_METHOD_VALIST(_long, int64_t)
2496 VM_CALL_METHOD_VALIST(_float, float)
2497 VM_CALL_METHOD_VALIST(_double, double)
2500 /* vm_call_method_jvalue *******************************************************
2502 Calls a Java method with a variable number of arguments, passed via
2505 *******************************************************************************/
2507 #define VM_CALL_METHOD_JVALUE(name, type) \
2508 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2509 const jvalue *args) \
2513 int32_t dumpmarker; \
2515 if (m->code == NULL) \
2516 if (!jit_compile(m)) \
2519 THREAD_NATIVEWORLD_EXIT; \
2522 array = argument_vmarray_from_jvalue(m, o, args); \
2523 value = vm_call##name##_array(m, array); \
2526 THREAD_NATIVEWORLD_ENTER; \
2531 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2532 VM_CALL_METHOD_JVALUE(_int, int32_t)
2533 VM_CALL_METHOD_JVALUE(_long, int64_t)
2534 VM_CALL_METHOD_JVALUE(_float, float)
2535 VM_CALL_METHOD_JVALUE(_double, double)
2538 /* vm_call_method_objectarray **************************************************
2540 Calls a Java method with a variable number if arguments, passed via
2541 an objectarray of boxed values. Returns a boxed value.
2543 *******************************************************************************/
2545 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2546 java_handle_objectarray_t *params)
2549 java_handle_t *xptr;
2554 /* Prevent compiler warnings. */
2558 /* compile methods which are not yet compiled */
2560 if (m->code == NULL)
2561 if (!jit_compile(m))
2564 /* leave the nativeworld */
2566 THREAD_NATIVEWORLD_EXIT;
2568 /* mark start of dump memory area */
2572 /* Fill the argument array from a object-array. */
2574 array = argument_vmarray_from_objectarray(m, o, params);
2576 if (array == NULL) {
2577 /* release dump area */
2581 /* enter the nativeworld again */
2583 THREAD_NATIVEWORLD_ENTER;
2585 exceptions_throw_illegalargumentexception();
2590 switch (m->parseddesc->returntype.decltype) {
2591 case PRIMITIVETYPE_VOID:
2592 value.a = vm_call_array(m, array);
2595 case PRIMITIVETYPE_BOOLEAN:
2596 case PRIMITIVETYPE_BYTE:
2597 case PRIMITIVETYPE_CHAR:
2598 case PRIMITIVETYPE_SHORT:
2599 case PRIMITIVETYPE_INT:
2600 value.i = vm_call_int_array(m, array);
2603 case PRIMITIVETYPE_LONG:
2604 value.l = vm_call_long_array(m, array);
2607 case PRIMITIVETYPE_FLOAT:
2608 value.f = vm_call_float_array(m, array);
2611 case PRIMITIVETYPE_DOUBLE:
2612 value.d = vm_call_double_array(m, array);
2616 ro = vm_call_array(m, array);
2620 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2623 /* release dump area */
2627 /* enter the nativeworld again */
2629 THREAD_NATIVEWORLD_ENTER;
2631 /* box the return value if necesarry */
2633 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2634 ro = Primitive_box(m->parseddesc->returntype.decltype, value);
2636 /* check for an exception */
2638 xptr = exceptions_get_exception();
2641 /* clear exception pointer, we are calling JIT code again */
2643 exceptions_clear_exception();
2645 exceptions_throw_invocationtargetexception(xptr);
2653 * These are local overrides for various environment variables in Emacs.
2654 * Please do not remove this and leave it at the end of the file, where
2655 * Emacs will automagically detect them.
2656 * ---------------------------------------------------------------------
2659 * indent-tabs-mode: t
2663 * vim:noexpandtab:sw=4:ts=4: