1 /* src/vm/vm.cpp - 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
41 #include "vm/jit/abi-asm.h"
43 #include "mm/codememory.h"
45 #include "mm/memory.h"
47 #include "native/jni.h"
48 #include "native/llni.h"
49 #include "native/localref.h"
50 #include "native/native.h"
52 #include "native/include/java_lang_Object.h" /* required by j.l.C */
53 #include "native/include/java_lang_String.h" /* required by j.l.C */
55 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
56 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
57 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
60 #include "native/include/java_lang_Class.h"
62 #include "native/vm/nativevm.h"
64 #include "threads/lock-common.h"
65 #include "threads/threadlist.h"
66 #include "threads/thread.h"
68 #include "toolbox/logging.h"
72 #if defined(ENABLE_ASSERTION)
73 #include "vm/assertion.h"
76 #include "vm/builtin.h"
77 #include "vm/exceptions.h"
78 #include "vm/finalizer.h"
79 #include "vm/global.h"
80 #include "vm/initialize.h"
81 #include "vm/package.hpp"
82 #include "vm/primitive.hpp"
83 #include "vm/properties.h"
84 #include "vm/signallocal.h"
85 #include "vm/stringlocal.h"
88 #include "vm/jit/argument.h"
89 #include "vm/jit/asmpart.h"
90 #include "vm/jit/code.h"
92 #if defined(ENABLE_DISASSEMBLER)
93 # include "vm/jit/disass.h"
96 #include "vm/jit/jit.h"
97 #include "vm/jit/methodtree.h"
99 #if defined(ENABLE_PROFILING)
100 # include "vm/jit/optimizing/profile.h"
103 #include "vm/jit/optimizing/recompile.h"
105 #if defined(ENABLE_PYTHON)
106 # include "vm/jit/python.h"
109 #include "vm/jit/trap.h"
111 #include "vmcore/classcache.h"
112 #include "vmcore/options.h"
113 #include "vmcore/statistics.h"
114 #include "vmcore/suck.h"
115 #include "vmcore/system.h"
117 #if defined(ENABLE_JVMTI)
118 # include "native/jvmti/cacaodbg.h"
121 #if defined(ENABLE_VMLOG)
122 #include <vmlog_cacao.h>
127 * This is _the_ instance of the VM.
132 /* global variables ***********************************************************/
134 s4 vms = 0; /* number of VMs created */
136 static classinfo *mainclass = NULL;
138 #if defined(ENABLE_INTRP)
139 u1 *intrp_main_stack = NULL;
143 /* define heap sizes **********************************************************/
145 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
146 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
147 #define STACK_SIZE 128 * 1024 /* default 64kB */
150 /* define command line options ************************************************/
184 /* Java non-standard options */
195 #if defined(ENABLE_PROFILING)
208 #if defined(ENABLE_STATISTICS)
225 #if defined(ENABLE_VERIFIER)
227 #if defined(TYPECHECK_VERBOSE)
230 #endif /* defined(ENABLE_VERIFIER) */
232 /* optimization options */
234 #if defined(ENABLE_LOOP)
238 #if defined(ENABLE_IFCONV)
242 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
246 #if defined(ENABLE_INTRP)
247 /* interpreter options */
266 #if defined(ENABLE_DEBUG_FILTER)
267 OPT_FILTER_VERBOSECALL_INCLUDE,
268 OPT_FILTER_VERBOSECALL_EXCLUDE,
269 OPT_FILTER_SHOW_METHOD,
276 opt_struct opts[] = {
277 { "foo", false, OPT_FOO },
281 { "jar", false, OPT_JAR },
283 { "d32", false, OPT_D32 },
284 { "d64", false, OPT_D64 },
285 { "client", false, OPT_IGNORE },
286 { "server", false, OPT_IGNORE },
287 { "jvm", false, OPT_IGNORE },
288 { "hotspot", false, OPT_IGNORE },
290 { "classpath", true, OPT_CLASSPATH },
291 { "cp", true, OPT_CLASSPATH },
292 { "D", true, OPT_D },
293 { "version", false, OPT_VERSION },
294 { "showversion", false, OPT_SHOWVERSION },
295 { "fullversion", false, OPT_FULLVERSION },
296 { "help", false, OPT_HELP },
297 { "?", false, OPT_HELP },
298 { "X", false, OPT_X },
299 { "XX:", true, OPT_XX },
301 { "ea:", true, OPT_EA },
302 { "da:", true, OPT_DA },
303 { "ea", false, OPT_EA_NOARG },
304 { "da", false, OPT_DA_NOARG },
306 { "enableassertions:", true, OPT_EA },
307 { "disableassertions:", true, OPT_DA },
308 { "enableassertions", false, OPT_EA_NOARG },
309 { "disableassertions", false, OPT_DA_NOARG },
311 { "esa", false, OPT_ESA },
312 { "enablesystemassertions", false, OPT_ESA },
313 { "dsa", false, OPT_DSA },
314 { "disablesystemassertions", false, OPT_DSA },
316 { "noasyncgc", false, OPT_IGNORE },
317 #if defined(ENABLE_VERIFIER)
318 { "noverify", false, OPT_NOVERIFY },
319 { "Xverify:none", false, OPT_NOVERIFY },
321 { "v", false, OPT_VERBOSE1 },
322 { "verbose:", true, OPT_VERBOSE },
324 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
325 { "verbosetc", false, OPT_VERBOSETC },
327 #if defined(__ALPHA__)
328 { "noieee", false, OPT_NOIEEE },
330 #if defined(ENABLE_STATISTICS)
331 { "time", false, OPT_TIME },
332 { "stat", false, OPT_STAT },
334 { "log", true, OPT_LOG },
335 { "c", true, OPT_CHECK },
336 { "l", false, OPT_LOAD },
339 { "all", false, OPT_ALL },
340 { "sig", true, OPT_SIGNATURE },
343 #if defined(ENABLE_LOOP)
344 { "oloop", false, OPT_OLOOP },
346 #if defined(ENABLE_IFCONV)
347 { "ifconv", false, OPT_IFCONV },
349 #if defined(ENABLE_LSRA)
350 { "lsra", false, OPT_LSRA },
352 #if defined(ENABLE_SSA)
353 { "lsra", true, OPT_LSRA },
356 #if defined(ENABLE_INTRP)
357 /* interpreter options */
359 { "trace", false, OPT_TRACE },
360 { "static-supers", true, OPT_STATIC_SUPERS },
361 { "no-dynamic", false, OPT_NO_DYNAMIC },
362 { "no-replication", false, OPT_NO_REPLICATION },
363 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
366 /* JVMTI Agent Command Line Options */
368 { "agentlib:", true, OPT_AGENTLIB },
369 { "agentpath:", true, OPT_AGENTPATH },
372 /* Java non-standard options */
374 { "Xjit", false, OPT_JIT },
375 { "Xint", false, OPT_INTRP },
376 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
377 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
378 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
379 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
382 { "Xdebug", false, OPT_DEBUG },
383 { "Xnoagent", false, OPT_NOAGENT },
384 { "Xrunjdwp", true, OPT_XRUNJDWP },
387 { "Xms", true, OPT_MS },
388 { "ms", true, OPT_MS },
389 { "Xmx", true, OPT_MX },
390 { "mx", true, OPT_MX },
391 { "Xss", true, OPT_SS },
392 { "ss", true, OPT_SS },
394 #if defined(ENABLE_PROFILING)
395 { "Xprof:", true, OPT_PROF_OPTION },
396 { "Xprof", false, OPT_PROF },
399 /* keep these at the end of the list */
402 { "m", true, OPT_METHOD },
405 { "s", true, OPT_SHOW },
406 { "debug-color", false, OPT_DEBUGCOLOR },
408 #if defined(ENABLE_DEBUG_FILTER)
409 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
410 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
411 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
418 /* usage ***********************************************************************
420 Prints the correct usage syntax to stdout.
422 *******************************************************************************/
426 puts("Usage: cacao [-options] classname [arguments]");
427 puts(" (to run a class file)");
428 puts(" or cacao [-options] -jar jarfile [arguments]");
429 puts(" (to run a standalone jar file)\n");
431 puts("where options include:");
432 puts(" -d32 use 32-bit data model if available");
433 puts(" -d64 use 64-bit data model if available");
434 puts(" -client compatibility (currently ignored)");
435 puts(" -server compatibility (currently ignored)");
436 puts(" -jvm compatibility (currently ignored)");
437 puts(" -hotspot compatibility (currently ignored)\n");
439 puts(" -cp <path> specify a path to look for classes");
440 puts(" -classpath <path> specify a path to look for classes");
441 puts(" -D<name>=<value> add an entry to the property list");
442 puts(" -verbose[:class|gc|jni] enable specific verbose output");
443 puts(" -version print product version and exit");
444 puts(" -fullversion print jpackage-compatible product version and exit");
445 puts(" -showversion print product version and continue");
446 puts(" -help, -? print this help message");
447 puts(" -X print help on non-standard Java options");
448 puts(" -XX print help on debugging options");
449 puts(" -ea[:<packagename>...|:<classname>]");
450 puts(" -enableassertions[:<packagename>...|:<classname>]");
451 puts(" enable assertions with specified granularity");
452 puts(" -da[:<packagename>...|:<classname>]");
453 puts(" -disableassertions[:<packagename>...|:<classname>]");
454 puts(" disable assertions with specified granularity");
455 puts(" -esa | -enablesystemassertions");
456 puts(" enable system assertions");
457 puts(" -dsa | -disablesystemassertions");
458 puts(" disable system assertions");
461 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
462 puts (" for jdwp help use: -agentlib:jdwp=help");
463 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
466 /* exit with error code */
472 static void Xusage(void)
474 #if defined(ENABLE_JIT)
475 puts(" -Xjit JIT mode execution (default)");
477 #if defined(ENABLE_INTRP)
478 puts(" -Xint interpreter mode execution");
480 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
481 puts(" value is set as bootstrap class path");
482 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
483 puts(" value is appended to the bootstrap class path");
484 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
485 puts(" value is prepended to the bootstrap class path");
486 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
487 puts(" value is used as Java core library, but the");
488 puts(" hardcoded VM interface classes are prepended");
489 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
490 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
491 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
493 #if defined(ENABLE_PROFILING)
494 puts(" -Xprof[:bb] collect and print profiling data");
497 #if defined(ENABLE_JVMTI)
498 /* -Xdebug option depend on gnu classpath JDWP options. options:
499 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
500 puts(" -Xdebug enable remote debugging\n");
501 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
502 puts(" enable remote debugging\n");
505 /* exit with error code */
512 static void XXusage(void)
514 puts(" -v write state-information");
516 puts(" -verbose:jit enable specific verbose output");
517 puts(" -debug-color colored output for ANSI terms");
519 #ifdef TYPECHECK_VERBOSE
520 puts(" -verbosetc write debug messages while typechecking");
522 #if defined(__ALPHA__)
523 puts(" -noieee don't use ieee compliant arithmetic");
525 #if defined(ENABLE_VERIFIER)
526 puts(" -noverify don't verify classfiles");
528 #if defined(ENABLE_STATISTICS)
529 puts(" -time measure the runtime");
530 puts(" -stat detailed compiler statistics");
532 puts(" -log logfile specify a name for the logfile");
533 puts(" -c(heck)b(ounds) don't check array bounds");
534 puts(" s(ync) don't check for synchronization");
535 #if defined(ENABLE_LOOP)
536 puts(" -oloop optimize array accesses in loops");
538 puts(" -l don't start the class after loading");
540 puts(" -all compile all methods, no execution");
541 puts(" -m compile only a specific method");
542 puts(" -sig specify signature for a specific method");
545 puts(" -s... show...");
546 puts(" (c)onstants the constant pool");
547 puts(" (m)ethods class fields and methods");
548 puts(" (u)tf the utf - hash");
549 puts(" (i)ntermediate intermediate representation");
550 #if defined(ENABLE_DISASSEMBLER)
551 puts(" (a)ssembler disassembled listing");
552 puts(" n(o)ps show NOPs in disassembler output");
554 puts(" (d)atasegment data segment listing");
556 #if defined(ENABLE_IFCONV)
557 puts(" -ifconv use if-conversion");
559 #if defined(ENABLE_LSRA)
560 puts(" -lsra use linear scan register allocation");
562 #if defined(ENABLE_SSA)
563 puts(" -lsra:... use linear scan register allocation (with SSA)");
564 puts(" (d)ead code elimination");
565 puts(" (c)opy propagation");
567 #if defined(ENABLE_DEBUG_FILTER)
568 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
569 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
570 puts(" -XXfm <regex> filter for show options");
572 /* exit with error code */
579 /* version *********************************************************************
581 Only prints cacao version information.
583 *******************************************************************************/
585 static void version(bool opt_exit)
587 puts("java version \""JAVA_VERSION"\"");
588 puts("CACAO version "VERSION"\n");
590 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
591 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
592 puts("This is free software; see the source for copying conditions. There is NO");
593 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
595 /* exit normally, if requested */
602 /* fullversion *****************************************************************
604 Prints a Sun compatible version information (required e.g. by
605 jpackage, www.jpackage.org).
607 *******************************************************************************/
609 static void fullversion(void)
611 puts("java full version \"cacao-"JAVA_VERSION"\"");
619 static void vm_printconfig(void)
621 puts("Configure/Build options:\n");
622 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
623 #if defined(__VERSION__)
624 puts(" CC : "VERSION_CC" ("__VERSION__")");
626 puts(" CC : "VERSION_CC"");
628 puts(" CFLAGS : "VERSION_CFLAGS"\n");
630 puts("Default variables:\n");
631 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
632 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
633 printf(" stack size : %d\n", STACK_SIZE);
635 #if defined(ENABLE_JRE_LAYOUT)
636 /* When we're building with JRE-layout, the default paths are the
637 same as the runtime paths. */
639 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
640 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
641 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
642 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
643 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
644 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
650 puts("Runtime variables:\n");
651 printf(" maximum heap size : %d\n", opt_heapmaxsize);
652 printf(" initial heap size : %d\n", opt_heapstartsize);
653 printf(" stack size : %d\n", opt_stacksize);
655 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
656 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
657 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
658 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
661 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
662 printf(" java.class.path : %s\n", properties_get("java.class.path"));
666 /* forward declarations *******************************************************/
668 static char *vm_get_mainclass_from_jar(char *mainstring);
670 static void vm_compile_all(void);
671 static void vm_compile_method(char* mainname);
676 * Implementation for JNI_CreateJavaVM. This function creates a VM
683 * @return true on success, false otherwise.
685 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
687 JavaVMInitArgs* _vm_args;
689 // Get the arguments for the new JVM.
690 _vm_args = (JavaVMInitArgs *) vm_args;
692 // Instantiate a new VM.
694 vm = new VM(_vm_args);
696 catch (std::exception e) {
697 // FIXME How can we delete the resources allocated?
698 // /* release allocated memory */
699 // FREE(env, _Jv_JNIEnv);
700 // FREE(vm, _Jv_JavaVM);
707 // Return the values.
709 *p_vm = vm->get_javavm();
710 *p_env = vm->get_jnienv();
717 * C wrapper for VM::create.
720 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
722 return VM::create(p_vm, p_env, vm_args);
730 VM::VM(JavaVMInitArgs* vm_args)
732 // Very first thing to do: we are initializing.
733 _initializing = true;
735 // Make ourself globally visible.
736 // XXX Is this a good idea?
739 /* create and fill a JavaVM structure */
741 _javavm = new JavaVM();
743 #if defined(ENABLE_JNI)
744 _javavm->functions = &_Jv_JNIInvokeInterface;
747 /* get the VM and Env tables (must be set before vm_create) */
748 /* XXX JVMTI Agents needs a JavaVM */
750 _jnienv = new JNIEnv();
752 #if defined(ENABLE_JNI)
753 _jnienv->functions = &_Jv_JNINativeInterface;
756 /* actually create the JVM */
760 char *boot_class_path;
766 #if defined(ENABLE_JVMTI)
768 char *libname, *agentarg;
769 bool jdwp,agentbypath;
770 jdwp = agentbypath = false;
773 #if defined(ENABLE_JNI)
774 /* Check the JNI version requested. */
776 if (!jni_version_check(vm_args->version))
777 throw std::exception();
780 /* We only support 1 JVM instance. */
783 throw std::exception();
785 /* Install the exit handler. */
787 if (atexit(vm_exit_handler))
788 vm_abort("atexit failed: %s\n", strerror(errno));
790 /* Set some options. */
797 opt_heapmaxsize = HEAP_MAXSIZE;
798 opt_heapstartsize = HEAP_STARTSIZE;
799 opt_stacksize = STACK_SIZE;
801 /* Initialize the properties list before command-line handling.
802 Otherwise -XX:+PrintConfig crashes. */
806 /* First of all, parse the -XX options. */
808 #if defined(ENABLE_VMLOG)
809 vmlog_cacao_init_options();
814 #if defined(ENABLE_VMLOG)
818 /* We need to check if the actual size of a java.lang.Class object
819 is smaller or equal than the assumption made in
820 src/vmcore/class.h. */
822 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
823 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
825 /* set the VM starttime */
827 _starttime = builtin_currenttimemillis();
829 #if defined(ENABLE_JVMTI)
830 /* initialize JVMTI related **********************************************/
834 /* Fill the properties before command-line handling. */
838 /* iterate over all passed options */
840 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
854 #if SIZEOF_VOID_P == 8
855 puts("Running a 32-bit JVM is not supported on this platform.");
861 #if SIZEOF_VOID_P == 4
862 puts("Running a 64-bit JVM is not supported on this platform.");
868 /* Forget old classpath and set the argument as new
871 class_path = properties_get("java.class.path");
873 p = MNEW(char, strlen(opt_arg) + strlen("0"));
877 #if defined(ENABLE_JAVASE)
878 properties_add("java.class.path", p);
881 MFREE(class_path, char, strlen(class_path));
885 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
886 if (opt_arg[i] == '=') {
888 properties_add(opt_arg, opt_arg + i + 1);
893 /* if no '=' is given, just create an empty property */
895 properties_add(opt_arg, "");
900 case OPT_BOOTCLASSPATH:
901 /* Forget default bootclasspath and set the argument as
902 new boot classpath. */
904 boot_class_path = properties_get("sun.boot.class.path");
906 p = MNEW(char, strlen(opt_arg) + strlen("0"));
910 properties_add("sun.boot.class.path", p);
911 properties_add("java.boot.class.path", p);
913 MFREE(boot_class_path, char, strlen(boot_class_path));
916 case OPT_BOOTCLASSPATH_A:
917 /* Append to bootclasspath. */
919 boot_class_path = properties_get("sun.boot.class.path");
921 len = strlen(boot_class_path);
923 // XXX (char*) quick hack
924 p = (char*) MREALLOC(boot_class_path,
928 strlen(opt_arg) + strlen("0"));
933 properties_add("sun.boot.class.path", p);
934 properties_add("java.boot.class.path", p);
937 case OPT_BOOTCLASSPATH_P:
938 /* Prepend to bootclasspath. */
940 boot_class_path = properties_get("sun.boot.class.path");
942 len = strlen(boot_class_path);
944 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
948 strcat(p, boot_class_path);
950 properties_add("sun.boot.class.path", p);
951 properties_add("java.boot.class.path", p);
953 MFREE(boot_class_path, char, len);
956 case OPT_BOOTCLASSPATH_C:
957 /* Use as Java core library, but prepend VM interface
960 boot_class_path = properties_get("sun.boot.class.path");
963 strlen(CACAO_VM_ZIP) +
970 strcpy(p, CACAO_VM_ZIP);
974 properties_add("sun.boot.class.path", p);
975 properties_add("java.boot.class.path", p);
977 MFREE(boot_class_path, char, strlen(boot_class_path));
980 #if defined(ENABLE_JVMTI)
982 /* this option exists only for compatibility reasons */
986 /* I don't know yet what Xnoagent should do. This is only for
987 compatiblity with eclipse - motse */
996 strlen(CACAO_LIBDIR) +
997 strlen("/libjdwp.so=") +
1001 agentarg = MNEW(char, len);
1003 strcpy(agentarg, CACAO_LIBDIR);
1004 strcat(agentarg, "/libjdwp.so=");
1005 strcat(agentarg, &opt_arg[1]);
1024 c = opt_arg[strlen(opt_arg) - 1];
1026 if ((c == 'k') || (c == 'K')) {
1027 j = atoi(opt_arg) * 1024;
1029 } else if ((c == 'm') || (c == 'M')) {
1030 j = atoi(opt_arg) * 1024 * 1024;
1036 opt_heapmaxsize = j;
1037 else if (opt == OPT_MS)
1038 opt_heapstartsize = j;
1049 if (strcmp("class", opt_arg) == 0) {
1050 opt_verboseclass = true;
1052 else if (strcmp("gc", opt_arg) == 0) {
1053 opt_verbosegc = true;
1055 else if (strcmp("jni", opt_arg) == 0) {
1056 opt_verbosejni = true;
1058 #if !defined(NDEBUG)
1059 else if (strcmp("jit", opt_arg) == 0) {
1063 compileverbose = true;
1067 printf("Unknown -verbose option: %s\n", opt_arg);
1072 case OPT_DEBUGCOLOR:
1073 opt_debugcolor = true;
1076 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1078 opt_typecheckverbose = true;
1087 case OPT_FULLVERSION:
1091 case OPT_SHOWVERSION:
1099 #if defined(ENABLE_VERIFIER)
1105 #if defined(ENABLE_STATISTICS)
1107 opt_getcompilingtime = true;
1108 opt_getloadingtime = true;
1121 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1122 switch (opt_arg[i]) {
1124 checkbounds = false;
1137 makeinitializations = false;
1140 #if !defined(NDEBUG)
1144 makeinitializations = false;
1149 opt_method = opt_arg;
1150 makeinitializations = false;
1154 opt_signature = opt_arg;
1158 case OPT_SHOW: /* Display options */
1159 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1160 switch (opt_arg[i]) {
1162 showconstantpool = true;
1174 opt_showintermediate = true;
1175 compileverbose = true;
1178 #if defined(ENABLE_DISASSEMBLER)
1180 opt_showdisassemble = true;
1181 compileverbose = true;
1185 opt_shownops = true;
1190 opt_showddatasegment = true;
1199 #if defined(ENABLE_LOOP)
1205 #if defined(ENABLE_IFCONV)
1211 #if defined(ENABLE_LSRA)
1216 #if defined(ENABLE_SSA)
1219 for (i = 0; i < strlen(opt_arg); i++) {
1220 switch (opt_arg[i]) {
1248 /* Already parsed. */
1252 #if defined(ENABLE_ASSERTION)
1253 assertion_ea_da(opt_arg, true);
1258 #if defined(ENABLE_ASSERTION)
1259 assertion_ea_da(opt_arg, false);
1264 #if defined(ENABLE_ASSERTION)
1265 assertion_user_enabled = true;
1270 #if defined(ENABLE_ASSERTION)
1271 assertion_user_enabled = false;
1276 #if defined(ENABLE_ASSERTION)
1277 assertion_system_enabled = true;
1282 #if defined(ENABLE_ASSERTION)
1283 assertion_system_enabled = false;
1287 #if defined(ENABLE_PROFILING)
1288 case OPT_PROF_OPTION:
1289 /* use <= to get the last \0 too */
1291 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1292 if (opt_arg[i] == ',')
1295 if (opt_arg[i] == '\0') {
1296 if (strcmp("bb", opt_arg + j) == 0)
1300 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1304 /* set k to next char */
1317 #if defined(ENABLE_JIT)
1320 printf("-Xjit option not enabled.\n");
1326 #if defined(ENABLE_INTRP)
1329 printf("-Xint option not enabled.\n");
1334 #if defined(ENABLE_INTRP)
1335 case OPT_STATIC_SUPERS:
1336 opt_static_supers = atoi(opt_arg);
1339 case OPT_NO_DYNAMIC:
1340 opt_no_dynamic = true;
1343 case OPT_NO_REPLICATION:
1344 opt_no_replication = true;
1347 case OPT_NO_QUICKSUPER:
1348 opt_no_quicksuper = true;
1356 #if defined(ENABLE_DEBUG_FILTER)
1357 case OPT_FILTER_VERBOSECALL_INCLUDE:
1358 opt_filter_verbosecall_include = opt_arg;
1361 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1362 opt_filter_verbosecall_exclude = opt_arg;
1365 case OPT_FILTER_SHOW_METHOD:
1366 opt_filter_show_method = opt_arg;
1371 printf("Unknown option: %s\n",
1372 vm_args->options[opt_index].optionString);
1377 #if defined(ENABLE_JVMTI)
1379 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1380 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1383 MFREE(agentarg, char, strlen(agentarg));
1385 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1389 /* initialize the garbage collector */
1391 gc_init(opt_heapmaxsize, opt_heapstartsize);
1393 #if defined(ENABLE_THREADS)
1394 /* BEFORE: threads_preinit */
1398 /* AFTER: gc_init */
1404 /* install architecture dependent signal handlers */
1407 vm_abort("vm_create: signal_init failed");
1409 #if defined(ENABLE_INTRP)
1410 /* Allocate main thread stack on the Java heap. */
1413 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1414 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1418 /* AFTER: threads_preinit */
1421 vm_abort("vm_create: string_init failed");
1423 /* AFTER: threads_preinit */
1427 /* AFTER: thread_preinit */
1430 vm_abort("vm_create: suck_init failed");
1432 suck_add_from_property("java.endorsed.dirs");
1434 /* Now we have all options handled and we can print the version
1437 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1442 /* AFTER: utf8_init */
1444 boot_class_path = properties_get("sun.boot.class.path");
1445 suck_add(boot_class_path);
1447 /* initialize the classcache hashtable stuff: lock, hashtable
1448 (must be done _after_ threads_preinit) */
1450 if (!classcache_init())
1451 vm_abort("vm_create: classcache_init failed");
1453 /* Initialize the code memory management. */
1454 /* AFTER: threads_preinit */
1458 /* initialize the finalizer stuff (must be done _after_
1461 if (!finalizer_init())
1462 vm_abort("vm_create: finalizer_init failed");
1464 /* Initialize the JIT compiler. */
1470 #if defined(ENABLE_PYTHON)
1474 /* BEFORE: loader_preinit */
1476 Package::initialize();
1478 /* AFTER: utf8_init, classcache_init */
1483 /* AFTER: loader_preinit, linker_preinit */
1490 /* AFTER: loader_init, linker_init */
1492 primitive_postinit();
1495 #if defined(ENABLE_JIT)
1499 if (!builtin_init())
1500 vm_abort("vm_create: builtin_init failed");
1502 /* Initialize the native subsystem. */
1503 /* BEFORE: threads_init */
1506 vm_abort("vm_create: native_init failed");
1508 /* Register the native methods implemented in the VM. */
1509 /* BEFORE: threads_init */
1513 #if defined(ENABLE_JNI)
1514 /* Initialize the JNI subsystem (must be done _before_
1515 threads_init, as threads_init can call JNI methods
1516 (e.g. NewGlobalRef). */
1519 vm_abort("vm_create: jni_init failed");
1522 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1523 /* Initialize the local reference table for the main thread. */
1524 /* BEFORE: threads_init */
1526 if (!localref_table_init())
1527 vm_abort("vm_create: localref_table_init failed");
1530 /* Iinitialize some important system classes. */
1531 /* BEFORE: threads_init */
1535 #if defined(ENABLE_THREADS)
1539 /* Initialize the native VM subsystem. */
1540 /* AFTER: threads_init (at least for SUN's classes) */
1544 #if defined(ENABLE_PROFILING)
1545 /* initialize profiling */
1547 if (!profile_init())
1548 vm_abort("vm_create: profile_init failed");
1551 #if defined(ENABLE_THREADS)
1552 /* initialize recompilation */
1554 if (!recompile_init())
1555 vm_abort("vm_create: recompile_init failed");
1557 /* start the signal handler thread */
1559 #if defined(__LINUX__)
1560 /* XXX Remove for exact-GC. */
1561 if (threads_pthreads_implementation_nptl)
1563 if (!signal_start_thread())
1564 vm_abort("vm_create: signal_start_thread failed");
1566 /* finally, start the finalizer thread */
1568 if (!finalizer_start_thread())
1569 vm_abort("vm_create: finalizer_start_thread failed");
1571 # if !defined(NDEBUG)
1572 /* start the memory profiling thread */
1574 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1575 if (!memory_start_thread())
1576 vm_abort("vm_create: memory_start_thread failed");
1579 /* start the recompilation thread (must be done before the
1580 profiling thread) */
1582 if (!recompile_start_thread())
1583 vm_abort("vm_create: recompile_start_thread failed");
1585 # if defined(ENABLE_PROFILING)
1586 /* start the profile sampling thread */
1589 /* if (!profile_start_thread()) */
1590 /* vm_abort("vm_create: profile_start_thread failed"); */
1594 #if defined(ENABLE_JVMTI)
1595 # if defined(ENABLE_GC_CACAO)
1596 /* XXX this will not work with the new indirection cells for classloaders!!! */
1600 /* add agent library to native library hashtable */
1601 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1605 /* Increment the number of VMs. */
1609 // Initialization is done, VM is created.
1611 _initializing = false;
1613 /* Print the VM configuration after all stuff is set and the VM is
1616 if (opt_PrintConfig)
1621 /* vm_run **********************************************************************
1623 Runs the main-method of the passed class.
1625 *******************************************************************************/
1627 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1633 classinfo *mainclass;
1636 java_handle_objectarray_t *oa;
1642 // Prevent compiler warnings.
1645 #if !defined(NDEBUG)
1652 /* Get the main class plus it's arguments. */
1656 if (opt_index < vm_args->nOptions) {
1657 /* Get main-class argument. */
1659 mainname = vm_args->options[opt_index].optionString;
1661 /* If the main class argument is a jar file, put it into the
1664 if (opt_jar == true) {
1665 p = MNEW(char, strlen(mainname) + strlen("0"));
1667 strcpy(p, mainname);
1669 #if defined(ENABLE_JAVASE)
1670 properties_add("java.class.path", p);
1674 /* Replace dots with slashes in the class name. */
1676 for (unsigned int i = 0; i < strlen(mainname); i++)
1677 if (mainname[i] == '.')
1681 /* Build argument array. Move index to first argument. */
1685 oalength = vm_args->nOptions - opt_index;
1687 oa = builtin_anewarray(oalength, class_java_lang_String);
1689 for (int i = 0; i < oalength; i++) {
1690 option = vm_args->options[opt_index + i].optionString;
1692 u = utf_new_char(option);
1693 s = javastring_new(u);
1695 array_objectarray_element_set(oa, i, s);
1699 /* Do we have a main-class argument? */
1701 if (mainname == NULL)
1704 #if !defined(NDEBUG)
1705 if (opt_method != NULL) {
1706 vm_compile_method(mainname);
1711 /* set return value to OK */
1715 if (opt_jar == true) {
1716 /* open jar file with java.util.jar.JarFile */
1718 mainname = vm_get_mainclass_from_jar(mainname);
1720 if (mainname == NULL)
1724 /* load the main class */
1726 mainutf = utf_new_char(mainname);
1728 #if defined(ENABLE_JAVAME_CLDC1_1)
1729 mainclass = load_class_bootstrap(mainutf);
1731 mainclass = load_class_from_sysloader(mainutf);
1734 /* error loading class */
1736 e = exceptions_get_and_clear_exception();
1738 if ((e != NULL) || (mainclass == NULL)) {
1739 exceptions_throw_noclassdeffounderror_cause(e);
1740 exceptions_print_stacktrace();
1744 if (!link_class(mainclass)) {
1745 exceptions_print_stacktrace();
1749 /* find the `main' method of the main class */
1751 m = class_resolveclassmethod(mainclass,
1752 utf_new_char("main"),
1753 utf_new_char("([Ljava/lang/String;)V"),
1754 class_java_lang_Object,
1757 if (exceptions_get_exception()) {
1758 exceptions_print_stacktrace();
1762 /* there is no main method or it isn't static */
1764 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1765 exceptions_clear_exception();
1766 exceptions_throw_nosuchmethoderror(mainclass,
1767 utf_new_char("main"),
1768 utf_new_char("([Ljava/lang/String;)V"));
1770 exceptions_print_stacktrace();
1774 #ifdef TYPEINFO_DEBUG_TEST
1775 /* test the typeinfo system */
1779 #if defined(ENABLE_JVMTI)
1780 jvmti_set_phase(JVMTI_PHASE_LIVE);
1783 /* set ThreadMXBean variables */
1785 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1786 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1788 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1789 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1790 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1791 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1792 #warning Move to C++
1794 /* start the main thread */
1796 (void) vm_call_method(m, NULL, oa);
1798 /* exception occurred? */
1800 if (exceptions_get_exception()) {
1801 exceptions_print_stacktrace();
1805 #if defined(ENABLE_THREADS)
1806 /* Detach the main thread so that it appears to have ended when
1807 the application's main method exits. */
1809 if (!thread_detach_current_thread())
1810 vm_abort("vm_run: Could not detach main thread.");
1813 /* Destroy the JavaVM. */
1815 (void) vm_destroy(vm);
1823 /* vm_destroy ******************************************************************
1825 Unloads a Java VM and reclaims its resources.
1827 *******************************************************************************/
1829 int vm_destroy(JavaVM *vm)
1831 #if defined(ENABLE_THREADS)
1832 /* Create a a trivial new Java waiter thread called
1835 JavaVMAttachArgs args;
1837 args.name = "DestroyJavaVM";
1840 if (!thread_attach_current_thread(&args, false))
1843 /* Wait until we are the last non-daemon thread. */
1845 threads_join_all_threads();
1850 // _created = false;
1851 #warning Move to C++
1853 /* Everything is ok. */
1859 /* vm_exit *********************************************************************
1861 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1863 *******************************************************************************/
1865 void vm_exit(s4 status)
1869 /* signal that we are exiting */
1872 #warning Move to C++
1874 assert(class_java_lang_System);
1875 assert(class_java_lang_System->state & CLASS_LOADED);
1877 #if defined(ENABLE_JVMTI)
1878 if (jvmti || (dbgcom!=NULL)) {
1879 jvmti_set_phase(JVMTI_PHASE_DEAD);
1880 if (jvmti) jvmti_agentunload();
1884 if (!link_class(class_java_lang_System)) {
1885 exceptions_print_stacktrace();
1889 /* call java.lang.System.exit(I)V */
1891 m = class_resolveclassmethod(class_java_lang_System,
1892 utf_new_char("exit"),
1894 class_java_lang_Object,
1898 exceptions_print_stacktrace();
1902 /* call the exit function with passed exit status */
1904 (void) vm_call_method(m, NULL, status);
1906 /* If we had an exception, just ignore the exception and exit with
1909 vm_shutdown(status);
1913 /* vm_shutdown *****************************************************************
1915 Terminates the system immediately without freeing memory explicitly
1916 (to be used only for abnormal termination).
1918 *******************************************************************************/
1920 void vm_shutdown(s4 status)
1923 #if defined(ENABLE_STATISTICS)
1924 || opt_getcompilingtime || opt_stat
1928 log_text("CACAO terminated by shutdown");
1929 dolog("Exit status: %d\n", (s4) status);
1933 #if defined(ENABLE_JVMTI)
1934 /* terminate cacaodbgserver */
1936 mutex_lock(&dbgcomlock);
1938 mutex_unlock(&dbgcomlock);
1939 jvmti_cacaodbgserver_quit();
1947 /* vm_exit_handler *************************************************************
1949 The exit_handler function is called upon program termination.
1951 ATTENTION: Don't free system resources here! Some threads may still
1952 be running as this is called from VMRuntime.exit(). The OS does the
1955 *******************************************************************************/
1957 void vm_exit_handler(void)
1959 #if !defined(NDEBUG)
1961 class_showmethods(mainclass);
1963 if (showconstantpool)
1964 class_showconstantpool(mainclass);
1969 # if defined(ENABLE_PROFILING)
1971 profile_printstats();
1973 #endif /* !defined(NDEBUG) */
1975 #if defined(ENABLE_RT_TIMING)
1976 rt_timing_print_time_stats(stderr);
1979 #if defined(ENABLE_CYCLES_STATS)
1980 builtin_print_cycles_stats(stderr);
1981 stacktrace_print_cycles_stats(stderr);
1985 #if defined(ENABLE_STATISTICS)
1986 || opt_getcompilingtime || opt_stat
1990 log_text("CACAO terminated");
1992 #if defined(ENABLE_STATISTICS)
1995 #ifdef TYPECHECK_STATISTICS
1996 typecheck_print_statistics(get_logfile());
2000 if (opt_getcompilingtime)
2002 #endif /* defined(ENABLE_STATISTICS) */
2004 /* vm_print_profile(stderr);*/
2008 /* vm_abort ********************************************************************
2010 Prints an error message and aborts the VM.
2013 text ... error message to print
2015 *******************************************************************************/
2017 void vm_abort(const char *text, ...)
2021 /* Print the log message. */
2026 log_vprint(text, ap);
2031 /* Now abort the VM. */
2037 /* vm_abort_errnum *************************************************************
2039 Prints an error message, appends ":" plus the strerror-message of
2040 errnum and aborts the VM.
2043 errnum ... error number
2044 text ..... error message to print
2046 *******************************************************************************/
2048 void vm_abort_errnum(int errnum, const char *text, ...)
2052 /* Print the log message. */
2057 log_vprint(text, ap);
2060 /* Print the strerror-message of errnum. */
2062 log_print(": %s", system_strerror(errnum));
2066 /* Now abort the VM. */
2072 /* vm_abort_errno **************************************************************
2074 Equal to vm_abort_errnum, but uses errno to get the error number.
2077 text ... error message to print
2079 *******************************************************************************/
2081 void vm_abort_errno(const char *text, ...)
2086 vm_abort_errnum(errno, text, ap);
2091 /* vm_abort_disassemble ********************************************************
2093 Prints an error message, disassemble the given code range (if
2094 enabled) and aborts the VM.
2097 pc.......PC to disassemble
2098 count....number of instructions to disassemble
2100 *******************************************************************************/
2102 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2105 #if defined(ENABLE_DISASSEMBLER)
2109 /* Print debug message. */
2114 log_vprint(text, ap);
2121 #if SIZEOF_VOID_P == 8
2122 log_println("PC=0x%016lx", pc);
2124 log_println("PC=0x%08x", pc);
2127 #if defined(ENABLE_DISASSEMBLER)
2128 log_println("machine instructions at PC:");
2130 /* Disassemble the given number of instructions. */
2132 for (i = 0; i < count; i++)
2133 pc = disassinstr(pc);
2136 vm_abort("Aborting...");
2140 /* vm_get_mainclass_from_jar ***************************************************
2142 Gets the name of the main class from a JAR's manifest file.
2144 *******************************************************************************/
2146 static char *vm_get_mainclass_from_jar(char *mainname)
2153 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2156 exceptions_print_stacktrace();
2160 /* create JarFile object */
2165 exceptions_print_stacktrace();
2169 m = class_resolveclassmethod(c,
2171 utf_java_lang_String__void,
2172 class_java_lang_Object,
2176 exceptions_print_stacktrace();
2180 s = javastring_new_from_ascii(mainname);
2182 (void) vm_call_method(m, o, s);
2184 if (exceptions_get_exception()) {
2185 exceptions_print_stacktrace();
2189 /* get manifest object */
2191 m = class_resolveclassmethod(c,
2192 utf_new_char("getManifest"),
2193 utf_new_char("()Ljava/util/jar/Manifest;"),
2194 class_java_lang_Object,
2198 exceptions_print_stacktrace();
2202 o = vm_call_method(m, o);
2205 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2210 /* get Main Attributes */
2212 LLNI_class_get(o, c);
2214 m = class_resolveclassmethod(c,
2215 utf_new_char("getMainAttributes"),
2216 utf_new_char("()Ljava/util/jar/Attributes;"),
2217 class_java_lang_Object,
2221 exceptions_print_stacktrace();
2225 o = vm_call_method(m, o);
2228 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2233 /* get property Main-Class */
2235 LLNI_class_get(o, c);
2237 m = class_resolveclassmethod(c,
2238 utf_new_char("getValue"),
2239 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2240 class_java_lang_Object,
2244 exceptions_print_stacktrace();
2248 s = javastring_new_from_ascii("Main-Class");
2250 o = vm_call_method(m, o, s);
2253 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2254 fprintf(stderr, "%s\n", mainname);
2258 return javastring_tochar(o);
2262 /* vm_compile_all **************************************************************
2264 Compile all methods found in the bootclasspath.
2266 *******************************************************************************/
2268 #if !defined(NDEBUG)
2269 static void vm_compile_all(void)
2274 classcache_name_entry *nmen;
2275 classcache_class_entry *clsen;
2278 /* create all classes found in the bootclasspath */
2279 /* XXX currently only works with zip/jar's */
2281 loader_load_all_classes();
2283 /* link all classes */
2285 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2286 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2288 for (; nmen; nmen = nmen->hashlink) {
2289 /* iterate over all class entries */
2291 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2292 c = clsen->classobj;
2297 if (!(c->state & CLASS_LINKED)) {
2298 if (!link_class(c)) {
2299 fprintf(stderr, "Error linking: ");
2300 utf_fprint_printable_ascii_classname(stderr, c->name);
2301 fprintf(stderr, "\n");
2303 /* print out exception and cause */
2305 exceptions_print_current_exception();
2307 /* goto next class */
2313 /* compile all class methods */
2315 for (i = 0; i < c->methodscount; i++) {
2316 m = &(c->methods[i]);
2318 if (m->jcode != NULL) {
2319 if (!jit_compile(m)) {
2320 fprintf(stderr, "Error compiling: ");
2321 utf_fprint_printable_ascii_classname(stderr, c->name);
2322 fprintf(stderr, ".");
2323 utf_fprint_printable_ascii(stderr, m->name);
2324 utf_fprint_printable_ascii(stderr, m->descriptor);
2325 fprintf(stderr, "\n");
2327 /* print out exception and cause */
2329 exceptions_print_current_exception();
2337 #endif /* !defined(NDEBUG) */
2340 /* vm_compile_method ***********************************************************
2342 Compile a specific method.
2344 *******************************************************************************/
2346 #if !defined(NDEBUG)
2347 static void vm_compile_method(char* mainname)
2351 /* create, load and link the main class */
2353 mainclass = load_class_bootstrap(utf_new_char(mainname));
2355 if (mainclass == NULL)
2356 exceptions_print_stacktrace();
2358 if (!link_class(mainclass))
2359 exceptions_print_stacktrace();
2361 if (opt_signature != NULL) {
2362 m = class_resolveclassmethod(mainclass,
2363 utf_new_char(opt_method),
2364 utf_new_char(opt_signature),
2369 m = class_resolveclassmethod(mainclass,
2370 utf_new_char(opt_method),
2377 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2378 opt_method, opt_signature ? opt_signature : "");
2382 #endif /* !defined(NDEBUG) */
2385 /* vm_call_array ***************************************************************
2387 Calls a Java method with a variable number of arguments, passed via
2390 ATTENTION: This function has to be used outside the nativeworld.
2392 *******************************************************************************/
2394 #define VM_CALL_ARRAY(name, type) \
2395 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2401 assert(m->code != NULL); \
2403 md = m->parseddesc; \
2404 pv = m->code->entrypoint; \
2406 STATISTICS(count_calls_native_to_java++); \
2408 value = asm_vm_call_method##name(pv, array, md->memuse); \
2413 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2419 assert(m->code != NULL);
2422 pv = m->code->entrypoint;
2424 STATISTICS(count_calls_native_to_java++);
2426 o = asm_vm_call_method(pv, array, md->memuse);
2428 if (md->returntype.type == TYPE_VOID)
2431 return LLNI_WRAP(o);
2434 VM_CALL_ARRAY(_int, int32_t)
2435 VM_CALL_ARRAY(_long, int64_t)
2436 VM_CALL_ARRAY(_float, float)
2437 VM_CALL_ARRAY(_double, double)
2440 /* vm_call_method **************************************************************
2442 Calls a Java method with a variable number of arguments.
2444 *******************************************************************************/
2446 #define VM_CALL_METHOD(name, type) \
2447 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2453 value = vm_call_method##name##_valist(m, o, ap); \
2459 VM_CALL_METHOD(, java_handle_t *)
2460 VM_CALL_METHOD(_int, int32_t)
2461 VM_CALL_METHOD(_long, int64_t)
2462 VM_CALL_METHOD(_float, float)
2463 VM_CALL_METHOD(_double, double)
2466 /* vm_call_method_valist *******************************************************
2468 Calls a Java method with a variable number of arguments, passed via
2471 *******************************************************************************/
2473 #define VM_CALL_METHOD_VALIST(name, type) \
2474 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2479 int32_t dumpmarker; \
2481 if (m->code == NULL) \
2482 if (!jit_compile(m)) \
2485 THREAD_NATIVEWORLD_EXIT; \
2488 array = argument_vmarray_from_valist(m, o, ap); \
2489 value = vm_call##name##_array(m, array); \
2492 THREAD_NATIVEWORLD_ENTER; \
2497 VM_CALL_METHOD_VALIST(, java_handle_t *)
2498 VM_CALL_METHOD_VALIST(_int, int32_t)
2499 VM_CALL_METHOD_VALIST(_long, int64_t)
2500 VM_CALL_METHOD_VALIST(_float, float)
2501 VM_CALL_METHOD_VALIST(_double, double)
2504 /* vm_call_method_jvalue *******************************************************
2506 Calls a Java method with a variable number of arguments, passed via
2509 *******************************************************************************/
2511 #define VM_CALL_METHOD_JVALUE(name, type) \
2512 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2513 const jvalue *args) \
2517 int32_t dumpmarker; \
2519 if (m->code == NULL) \
2520 if (!jit_compile(m)) \
2523 THREAD_NATIVEWORLD_EXIT; \
2526 array = argument_vmarray_from_jvalue(m, o, args); \
2527 value = vm_call##name##_array(m, array); \
2530 THREAD_NATIVEWORLD_ENTER; \
2535 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2536 VM_CALL_METHOD_JVALUE(_int, int32_t)
2537 VM_CALL_METHOD_JVALUE(_long, int64_t)
2538 VM_CALL_METHOD_JVALUE(_float, float)
2539 VM_CALL_METHOD_JVALUE(_double, double)
2542 /* vm_call_method_objectarray **************************************************
2544 Calls a Java method with a variable number if arguments, passed via
2545 an objectarray of boxed values. Returns a boxed value.
2547 *******************************************************************************/
2549 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2550 java_handle_objectarray_t *params)
2553 java_handle_t *xptr;
2558 /* Prevent compiler warnings. */
2562 /* compile methods which are not yet compiled */
2564 if (m->code == NULL)
2565 if (!jit_compile(m))
2568 /* leave the nativeworld */
2570 THREAD_NATIVEWORLD_EXIT;
2572 /* mark start of dump memory area */
2576 /* Fill the argument array from a object-array. */
2578 array = argument_vmarray_from_objectarray(m, o, params);
2580 if (array == NULL) {
2581 /* release dump area */
2585 /* enter the nativeworld again */
2587 THREAD_NATIVEWORLD_ENTER;
2589 exceptions_throw_illegalargumentexception();
2594 switch (m->parseddesc->returntype.decltype) {
2595 case PRIMITIVETYPE_VOID:
2596 value.a = vm_call_array(m, array);
2599 case PRIMITIVETYPE_BOOLEAN:
2600 case PRIMITIVETYPE_BYTE:
2601 case PRIMITIVETYPE_CHAR:
2602 case PRIMITIVETYPE_SHORT:
2603 case PRIMITIVETYPE_INT:
2604 value.i = vm_call_int_array(m, array);
2607 case PRIMITIVETYPE_LONG:
2608 value.l = vm_call_long_array(m, array);
2611 case PRIMITIVETYPE_FLOAT:
2612 value.f = vm_call_float_array(m, array);
2615 case PRIMITIVETYPE_DOUBLE:
2616 value.d = vm_call_double_array(m, array);
2620 ro = vm_call_array(m, array);
2624 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2627 /* release dump area */
2631 /* enter the nativeworld again */
2633 THREAD_NATIVEWORLD_ENTER;
2635 /* box the return value if necesarry */
2637 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2638 ro = Primitive::box(m->parseddesc->returntype.decltype, value);
2640 /* check for an exception */
2642 xptr = exceptions_get_exception();
2645 /* clear exception pointer, we are calling JIT code again */
2647 exceptions_clear_exception();
2649 exceptions_throw_invocationtargetexception(xptr);
2656 /* Legacy C interface *********************************************************/
2660 JavaVM* VM_get_javavm() { return vm->get_javavm(); }
2661 JNIEnv* VM_get_jnienv() { return vm->get_jnienv(); }
2662 bool VM_is_initializing() { return vm->is_initializing(); }
2663 bool VM_is_created() { return vm->is_created(); }
2664 int64_t VM_get_starttime() { return vm->get_starttime(); }
2670 * These are local overrides for various environment variables in Emacs.
2671 * Please do not remove this and leave it at the end of the file, where
2672 * Emacs will automagically detect them.
2673 * ---------------------------------------------------------------------
2676 * indent-tabs-mode: t
2680 * vim:noexpandtab:sw=4:ts=4: