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 // FIXME Make class_path const char*.
872 class_path = (char*) properties_get("java.class.path");
874 p = MNEW(char, strlen(opt_arg) + strlen("0"));
878 #if defined(ENABLE_JAVASE)
879 properties_add("java.class.path", p);
882 MFREE(class_path, char, strlen(class_path));
886 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
887 if (opt_arg[i] == '=') {
889 properties_add(opt_arg, opt_arg + i + 1);
894 /* if no '=' is given, just create an empty property */
896 properties_add(opt_arg, "");
901 case OPT_BOOTCLASSPATH:
902 /* Forget default bootclasspath and set the argument as
903 new boot classpath. */
905 // FIXME Make boot_class_path const char*.
906 boot_class_path = (char*) properties_get("sun.boot.class.path");
908 p = MNEW(char, strlen(opt_arg) + strlen("0"));
912 properties_add("sun.boot.class.path", p);
913 properties_add("java.boot.class.path", p);
915 MFREE(boot_class_path, char, strlen(boot_class_path));
918 case OPT_BOOTCLASSPATH_A:
919 /* Append to bootclasspath. */
921 // FIXME Make boot_class_path const char*.
922 boot_class_path = (char*) properties_get("sun.boot.class.path");
924 len = strlen(boot_class_path);
926 // XXX (char*) quick hack
927 p = (char*) MREALLOC(boot_class_path,
931 strlen(opt_arg) + strlen("0"));
936 properties_add("sun.boot.class.path", p);
937 properties_add("java.boot.class.path", p);
940 case OPT_BOOTCLASSPATH_P:
941 /* Prepend to bootclasspath. */
943 // FIXME Make boot_class_path const char*.
944 boot_class_path = (char*) properties_get("sun.boot.class.path");
946 len = strlen(boot_class_path);
948 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
952 strcat(p, boot_class_path);
954 properties_add("sun.boot.class.path", p);
955 properties_add("java.boot.class.path", p);
957 MFREE(boot_class_path, char, len);
960 case OPT_BOOTCLASSPATH_C:
961 /* Use as Java core library, but prepend VM interface
964 // FIXME Make boot_class_path const char*.
965 boot_class_path = (char*) properties_get("sun.boot.class.path");
968 strlen(CACAO_VM_ZIP) +
975 strcpy(p, CACAO_VM_ZIP);
979 properties_add("sun.boot.class.path", p);
980 properties_add("java.boot.class.path", p);
982 MFREE(boot_class_path, char, strlen(boot_class_path));
985 #if defined(ENABLE_JVMTI)
987 /* this option exists only for compatibility reasons */
991 /* I don't know yet what Xnoagent should do. This is only for
992 compatiblity with eclipse - motse */
1001 strlen(CACAO_LIBDIR) +
1002 strlen("/libjdwp.so=") +
1006 agentarg = MNEW(char, len);
1008 strcpy(agentarg, CACAO_LIBDIR);
1009 strcat(agentarg, "/libjdwp.so=");
1010 strcat(agentarg, &opt_arg[1]);
1029 c = opt_arg[strlen(opt_arg) - 1];
1031 if ((c == 'k') || (c == 'K')) {
1032 j = atoi(opt_arg) * 1024;
1034 } else if ((c == 'm') || (c == 'M')) {
1035 j = atoi(opt_arg) * 1024 * 1024;
1041 opt_heapmaxsize = j;
1042 else if (opt == OPT_MS)
1043 opt_heapstartsize = j;
1054 if (strcmp("class", opt_arg) == 0) {
1055 opt_verboseclass = true;
1057 else if (strcmp("gc", opt_arg) == 0) {
1058 opt_verbosegc = true;
1060 else if (strcmp("jni", opt_arg) == 0) {
1061 opt_verbosejni = true;
1063 #if !defined(NDEBUG)
1064 else if (strcmp("jit", opt_arg) == 0) {
1068 compileverbose = true;
1072 printf("Unknown -verbose option: %s\n", opt_arg);
1077 case OPT_DEBUGCOLOR:
1078 opt_debugcolor = true;
1081 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1083 opt_typecheckverbose = true;
1092 case OPT_FULLVERSION:
1096 case OPT_SHOWVERSION:
1104 #if defined(ENABLE_VERIFIER)
1110 #if defined(ENABLE_STATISTICS)
1112 opt_getcompilingtime = true;
1113 opt_getloadingtime = true;
1126 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1127 switch (opt_arg[i]) {
1129 checkbounds = false;
1142 makeinitializations = false;
1145 #if !defined(NDEBUG)
1149 makeinitializations = false;
1154 opt_method = opt_arg;
1155 makeinitializations = false;
1159 opt_signature = opt_arg;
1163 case OPT_SHOW: /* Display options */
1164 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1165 switch (opt_arg[i]) {
1167 showconstantpool = true;
1179 opt_showintermediate = true;
1180 compileverbose = true;
1183 #if defined(ENABLE_DISASSEMBLER)
1185 opt_showdisassemble = true;
1186 compileverbose = true;
1190 opt_shownops = true;
1195 opt_showddatasegment = true;
1204 #if defined(ENABLE_LOOP)
1210 #if defined(ENABLE_IFCONV)
1216 #if defined(ENABLE_LSRA)
1221 #if defined(ENABLE_SSA)
1224 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1225 switch (opt_arg[i]) {
1253 /* Already parsed. */
1257 #if defined(ENABLE_ASSERTION)
1258 assertion_ea_da(opt_arg, true);
1263 #if defined(ENABLE_ASSERTION)
1264 assertion_ea_da(opt_arg, false);
1269 #if defined(ENABLE_ASSERTION)
1270 assertion_user_enabled = true;
1275 #if defined(ENABLE_ASSERTION)
1276 assertion_user_enabled = false;
1281 #if defined(ENABLE_ASSERTION)
1282 assertion_system_enabled = true;
1287 #if defined(ENABLE_ASSERTION)
1288 assertion_system_enabled = false;
1292 #if defined(ENABLE_PROFILING)
1293 case OPT_PROF_OPTION:
1294 /* use <= to get the last \0 too */
1296 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1297 if (opt_arg[i] == ',')
1300 if (opt_arg[i] == '\0') {
1301 if (strcmp("bb", opt_arg + j) == 0)
1305 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1309 /* set k to next char */
1322 #if defined(ENABLE_JIT)
1325 printf("-Xjit option not enabled.\n");
1331 #if defined(ENABLE_INTRP)
1334 printf("-Xint option not enabled.\n");
1339 #if defined(ENABLE_INTRP)
1340 case OPT_STATIC_SUPERS:
1341 opt_static_supers = atoi(opt_arg);
1344 case OPT_NO_DYNAMIC:
1345 opt_no_dynamic = true;
1348 case OPT_NO_REPLICATION:
1349 opt_no_replication = true;
1352 case OPT_NO_QUICKSUPER:
1353 opt_no_quicksuper = true;
1361 #if defined(ENABLE_DEBUG_FILTER)
1362 case OPT_FILTER_VERBOSECALL_INCLUDE:
1363 opt_filter_verbosecall_include = opt_arg;
1366 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1367 opt_filter_verbosecall_exclude = opt_arg;
1370 case OPT_FILTER_SHOW_METHOD:
1371 opt_filter_show_method = opt_arg;
1376 printf("Unknown option: %s\n",
1377 vm_args->options[opt_index].optionString);
1382 #if defined(ENABLE_JVMTI)
1384 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1385 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1388 MFREE(agentarg, char, strlen(agentarg));
1390 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1394 /* initialize the garbage collector */
1396 gc_init(opt_heapmaxsize, opt_heapstartsize);
1398 #if defined(ENABLE_THREADS)
1399 /* BEFORE: threads_preinit */
1403 /* AFTER: gc_init */
1409 /* install architecture dependent signal handlers */
1412 vm_abort("vm_create: signal_init failed");
1414 #if defined(ENABLE_INTRP)
1415 /* Allocate main thread stack on the Java heap. */
1418 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1419 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1423 /* AFTER: threads_preinit */
1426 vm_abort("vm_create: string_init failed");
1428 /* AFTER: threads_preinit */
1432 /* AFTER: thread_preinit */
1435 vm_abort("vm_create: suck_init failed");
1437 suck_add_from_property("java.endorsed.dirs");
1439 /* Now we have all options handled and we can print the version
1442 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1447 /* AFTER: utf8_init */
1449 // FIXME Make boot_class_path const char*.
1450 boot_class_path = (char*) properties_get("sun.boot.class.path");
1451 suck_add(boot_class_path);
1453 /* initialize the classcache hashtable stuff: lock, hashtable
1454 (must be done _after_ threads_preinit) */
1456 if (!classcache_init())
1457 vm_abort("vm_create: classcache_init failed");
1459 /* Initialize the code memory management. */
1460 /* AFTER: threads_preinit */
1464 /* initialize the finalizer stuff (must be done _after_
1467 if (!finalizer_init())
1468 vm_abort("vm_create: finalizer_init failed");
1470 /* Initialize the JIT compiler. */
1476 #if defined(ENABLE_PYTHON)
1480 /* BEFORE: loader_preinit */
1482 Package::initialize();
1484 /* AFTER: utf8_init, classcache_init */
1489 /* AFTER: loader_preinit, linker_preinit */
1496 /* AFTER: loader_init, linker_init */
1498 primitive_postinit();
1501 #if defined(ENABLE_JIT)
1505 if (!builtin_init())
1506 vm_abort("vm_create: builtin_init failed");
1508 /* Initialize the native subsystem. */
1509 /* BEFORE: threads_init */
1512 vm_abort("vm_create: native_init failed");
1514 /* Register the native methods implemented in the VM. */
1515 /* BEFORE: threads_init */
1519 #if defined(ENABLE_JNI)
1520 /* Initialize the JNI subsystem (must be done _before_
1521 threads_init, as threads_init can call JNI methods
1522 (e.g. NewGlobalRef). */
1525 vm_abort("vm_create: jni_init failed");
1528 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1529 /* Initialize the local reference table for the main thread. */
1530 /* BEFORE: threads_init */
1532 if (!localref_table_init())
1533 vm_abort("vm_create: localref_table_init failed");
1536 /* Iinitialize some important system classes. */
1537 /* BEFORE: threads_init */
1541 #if defined(ENABLE_THREADS)
1545 /* Initialize the native VM subsystem. */
1546 /* AFTER: threads_init (at least for SUN's classes) */
1550 #if defined(ENABLE_PROFILING)
1551 /* initialize profiling */
1553 if (!profile_init())
1554 vm_abort("vm_create: profile_init failed");
1557 #if defined(ENABLE_THREADS)
1558 /* initialize recompilation */
1560 if (!recompile_init())
1561 vm_abort("vm_create: recompile_init failed");
1563 /* start the signal handler thread */
1565 #if defined(__LINUX__)
1566 /* XXX Remove for exact-GC. */
1567 if (threads_pthreads_implementation_nptl)
1569 if (!signal_start_thread())
1570 vm_abort("vm_create: signal_start_thread failed");
1572 /* finally, start the finalizer thread */
1574 if (!finalizer_start_thread())
1575 vm_abort("vm_create: finalizer_start_thread failed");
1577 # if !defined(NDEBUG)
1578 /* start the memory profiling thread */
1580 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1581 if (!memory_start_thread())
1582 vm_abort("vm_create: memory_start_thread failed");
1585 /* start the recompilation thread (must be done before the
1586 profiling thread) */
1588 if (!recompile_start_thread())
1589 vm_abort("vm_create: recompile_start_thread failed");
1591 # if defined(ENABLE_PROFILING)
1592 /* start the profile sampling thread */
1595 /* if (!profile_start_thread()) */
1596 /* vm_abort("vm_create: profile_start_thread failed"); */
1600 #if defined(ENABLE_JVMTI)
1601 # if defined(ENABLE_GC_CACAO)
1602 /* XXX this will not work with the new indirection cells for classloaders!!! */
1606 /* add agent library to native library hashtable */
1607 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1611 /* Increment the number of VMs. */
1615 // Initialization is done, VM is created.
1617 _initializing = false;
1619 /* Print the VM configuration after all stuff is set and the VM is
1622 if (opt_PrintConfig)
1627 /* vm_run **********************************************************************
1629 Runs the main-method of the passed class.
1631 *******************************************************************************/
1633 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1639 classinfo *mainclass;
1642 java_handle_objectarray_t *oa;
1648 // Prevent compiler warnings.
1651 #if !defined(NDEBUG)
1658 /* Get the main class plus it's arguments. */
1662 if (opt_index < vm_args->nOptions) {
1663 /* Get main-class argument. */
1665 mainname = vm_args->options[opt_index].optionString;
1667 /* If the main class argument is a jar file, put it into the
1670 if (opt_jar == true) {
1671 p = MNEW(char, strlen(mainname) + strlen("0"));
1673 strcpy(p, mainname);
1675 #if defined(ENABLE_JAVASE)
1676 properties_add("java.class.path", p);
1680 /* Replace dots with slashes in the class name. */
1682 for (unsigned int i = 0; i < strlen(mainname); i++)
1683 if (mainname[i] == '.')
1687 /* Build argument array. Move index to first argument. */
1691 oalength = vm_args->nOptions - opt_index;
1693 oa = builtin_anewarray(oalength, class_java_lang_String);
1695 for (int i = 0; i < oalength; i++) {
1696 option = vm_args->options[opt_index + i].optionString;
1698 u = utf_new_char(option);
1699 s = javastring_new(u);
1701 array_objectarray_element_set(oa, i, s);
1705 /* Do we have a main-class argument? */
1707 if (mainname == NULL)
1710 #if !defined(NDEBUG)
1711 if (opt_method != NULL) {
1712 vm_compile_method(mainname);
1717 /* set return value to OK */
1721 if (opt_jar == true) {
1722 /* open jar file with java.util.jar.JarFile */
1724 mainname = vm_get_mainclass_from_jar(mainname);
1726 if (mainname == NULL)
1730 /* load the main class */
1732 mainutf = utf_new_char(mainname);
1734 #if defined(ENABLE_JAVAME_CLDC1_1)
1735 mainclass = load_class_bootstrap(mainutf);
1737 mainclass = load_class_from_sysloader(mainutf);
1740 /* error loading class */
1742 e = exceptions_get_and_clear_exception();
1744 if ((e != NULL) || (mainclass == NULL)) {
1745 exceptions_throw_noclassdeffounderror_cause(e);
1746 exceptions_print_stacktrace();
1750 if (!link_class(mainclass)) {
1751 exceptions_print_stacktrace();
1755 /* find the `main' method of the main class */
1757 m = class_resolveclassmethod(mainclass,
1758 utf_new_char("main"),
1759 utf_new_char("([Ljava/lang/String;)V"),
1760 class_java_lang_Object,
1763 if (exceptions_get_exception()) {
1764 exceptions_print_stacktrace();
1768 /* there is no main method or it isn't static */
1770 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1771 exceptions_clear_exception();
1772 exceptions_throw_nosuchmethoderror(mainclass,
1773 utf_new_char("main"),
1774 utf_new_char("([Ljava/lang/String;)V"));
1776 exceptions_print_stacktrace();
1780 #ifdef TYPEINFO_DEBUG_TEST
1781 /* test the typeinfo system */
1785 #if defined(ENABLE_JVMTI)
1786 jvmti_set_phase(JVMTI_PHASE_LIVE);
1789 /* set ThreadMXBean variables */
1791 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1792 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1794 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1795 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1796 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1797 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1798 #warning Move to C++
1800 /* start the main thread */
1802 (void) vm_call_method(m, NULL, oa);
1804 /* exception occurred? */
1806 if (exceptions_get_exception()) {
1807 exceptions_print_stacktrace();
1811 #if defined(ENABLE_THREADS)
1812 /* Detach the main thread so that it appears to have ended when
1813 the application's main method exits. */
1815 if (!thread_detach_current_thread())
1816 vm_abort("vm_run: Could not detach main thread.");
1819 /* Destroy the JavaVM. */
1821 (void) vm_destroy(vm);
1829 /* vm_destroy ******************************************************************
1831 Unloads a Java VM and reclaims its resources.
1833 *******************************************************************************/
1835 int vm_destroy(JavaVM *vm)
1837 #if defined(ENABLE_THREADS)
1838 /* Create a a trivial new Java waiter thread called
1841 JavaVMAttachArgs args;
1843 args.name = (char*) "DestroyJavaVM";
1846 if (!thread_attach_current_thread(&args, false))
1849 /* Wait until we are the last non-daemon thread. */
1851 threads_join_all_threads();
1856 // _created = false;
1857 #warning Move to C++
1859 /* Everything is ok. */
1865 /* vm_exit *********************************************************************
1867 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1869 *******************************************************************************/
1871 void vm_exit(s4 status)
1875 /* signal that we are exiting */
1878 #warning Move to C++
1880 assert(class_java_lang_System);
1881 assert(class_java_lang_System->state & CLASS_LOADED);
1883 #if defined(ENABLE_JVMTI)
1884 if (jvmti || (dbgcom!=NULL)) {
1885 jvmti_set_phase(JVMTI_PHASE_DEAD);
1886 if (jvmti) jvmti_agentunload();
1890 if (!link_class(class_java_lang_System)) {
1891 exceptions_print_stacktrace();
1895 /* call java.lang.System.exit(I)V */
1897 m = class_resolveclassmethod(class_java_lang_System,
1898 utf_new_char("exit"),
1900 class_java_lang_Object,
1904 exceptions_print_stacktrace();
1908 /* call the exit function with passed exit status */
1910 (void) vm_call_method(m, NULL, status);
1912 /* If we had an exception, just ignore the exception and exit with
1915 vm_shutdown(status);
1919 /* vm_shutdown *****************************************************************
1921 Terminates the system immediately without freeing memory explicitly
1922 (to be used only for abnormal termination).
1924 *******************************************************************************/
1926 void vm_shutdown(s4 status)
1929 #if defined(ENABLE_STATISTICS)
1930 || opt_getcompilingtime || opt_stat
1934 log_text("CACAO terminated by shutdown");
1935 dolog("Exit status: %d\n", (s4) status);
1939 #if defined(ENABLE_JVMTI)
1940 /* terminate cacaodbgserver */
1942 mutex_lock(&dbgcomlock);
1944 mutex_unlock(&dbgcomlock);
1945 jvmti_cacaodbgserver_quit();
1953 /* vm_exit_handler *************************************************************
1955 The exit_handler function is called upon program termination.
1957 ATTENTION: Don't free system resources here! Some threads may still
1958 be running as this is called from VMRuntime.exit(). The OS does the
1961 *******************************************************************************/
1963 void vm_exit_handler(void)
1965 #if !defined(NDEBUG)
1967 class_showmethods(mainclass);
1969 if (showconstantpool)
1970 class_showconstantpool(mainclass);
1975 # if defined(ENABLE_PROFILING)
1977 profile_printstats();
1979 #endif /* !defined(NDEBUG) */
1981 #if defined(ENABLE_RT_TIMING)
1982 rt_timing_print_time_stats(stderr);
1985 #if defined(ENABLE_CYCLES_STATS)
1986 builtin_print_cycles_stats(stderr);
1987 stacktrace_print_cycles_stats(stderr);
1991 #if defined(ENABLE_STATISTICS)
1992 || opt_getcompilingtime || opt_stat
1996 log_text("CACAO terminated");
1998 #if defined(ENABLE_STATISTICS)
2001 #ifdef TYPECHECK_STATISTICS
2002 typecheck_print_statistics(get_logfile());
2006 if (opt_getcompilingtime)
2008 #endif /* defined(ENABLE_STATISTICS) */
2010 /* vm_print_profile(stderr);*/
2014 /* vm_abort ********************************************************************
2016 Prints an error message and aborts the VM.
2019 text ... error message to print
2021 *******************************************************************************/
2023 void vm_abort(const char *text, ...)
2027 /* Print the log message. */
2032 log_vprint(text, ap);
2037 /* Now abort the VM. */
2043 /* vm_abort_errnum *************************************************************
2045 Prints an error message, appends ":" plus the strerror-message of
2046 errnum and aborts the VM.
2049 errnum ... error number
2050 text ..... error message to print
2052 *******************************************************************************/
2054 void vm_abort_errnum(int errnum, const char *text, ...)
2058 /* Print the log message. */
2063 log_vprint(text, ap);
2066 /* Print the strerror-message of errnum. */
2068 log_print(": %s", system_strerror(errnum));
2072 /* Now abort the VM. */
2078 /* vm_abort_errno **************************************************************
2080 Equal to vm_abort_errnum, but uses errno to get the error number.
2083 text ... error message to print
2085 *******************************************************************************/
2087 void vm_abort_errno(const char *text, ...)
2092 vm_abort_errnum(errno, text, ap);
2097 /* vm_abort_disassemble ********************************************************
2099 Prints an error message, disassemble the given code range (if
2100 enabled) and aborts the VM.
2103 pc.......PC to disassemble
2104 count....number of instructions to disassemble
2106 *******************************************************************************/
2108 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2111 #if defined(ENABLE_DISASSEMBLER)
2115 /* Print debug message. */
2120 log_vprint(text, ap);
2127 #if SIZEOF_VOID_P == 8
2128 log_println("PC=0x%016lx", pc);
2130 log_println("PC=0x%08x", pc);
2133 #if defined(ENABLE_DISASSEMBLER)
2134 log_println("machine instructions at PC:");
2136 /* Disassemble the given number of instructions. */
2138 for (i = 0; i < count; i++)
2139 // FIXME disassinstr should use void*.
2140 pc = disassinstr((u1*) pc);
2143 vm_abort("Aborting...");
2147 /* vm_get_mainclass_from_jar ***************************************************
2149 Gets the name of the main class from a JAR's manifest file.
2151 *******************************************************************************/
2153 static char *vm_get_mainclass_from_jar(char *mainname)
2160 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2163 exceptions_print_stacktrace();
2167 /* create JarFile object */
2172 exceptions_print_stacktrace();
2176 m = class_resolveclassmethod(c,
2178 utf_java_lang_String__void,
2179 class_java_lang_Object,
2183 exceptions_print_stacktrace();
2187 s = javastring_new_from_ascii(mainname);
2189 (void) vm_call_method(m, o, s);
2191 if (exceptions_get_exception()) {
2192 exceptions_print_stacktrace();
2196 /* get manifest object */
2198 m = class_resolveclassmethod(c,
2199 utf_new_char("getManifest"),
2200 utf_new_char("()Ljava/util/jar/Manifest;"),
2201 class_java_lang_Object,
2205 exceptions_print_stacktrace();
2209 o = vm_call_method(m, o);
2212 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2217 /* get Main Attributes */
2219 LLNI_class_get(o, c);
2221 m = class_resolveclassmethod(c,
2222 utf_new_char("getMainAttributes"),
2223 utf_new_char("()Ljava/util/jar/Attributes;"),
2224 class_java_lang_Object,
2228 exceptions_print_stacktrace();
2232 o = vm_call_method(m, o);
2235 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2240 /* get property Main-Class */
2242 LLNI_class_get(o, c);
2244 m = class_resolveclassmethod(c,
2245 utf_new_char("getValue"),
2246 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2247 class_java_lang_Object,
2251 exceptions_print_stacktrace();
2255 s = javastring_new_from_ascii("Main-Class");
2257 o = vm_call_method(m, o, s);
2260 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2261 fprintf(stderr, "%s\n", mainname);
2265 return javastring_tochar(o);
2269 /* vm_compile_all **************************************************************
2271 Compile all methods found in the bootclasspath.
2273 *******************************************************************************/
2275 #if !defined(NDEBUG)
2276 static void vm_compile_all(void)
2281 classcache_name_entry *nmen;
2282 classcache_class_entry *clsen;
2285 /* create all classes found in the bootclasspath */
2286 /* XXX currently only works with zip/jar's */
2288 loader_load_all_classes();
2290 /* link all classes */
2292 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2293 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2295 for (; nmen; nmen = nmen->hashlink) {
2296 /* iterate over all class entries */
2298 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2299 c = clsen->classobj;
2304 if (!(c->state & CLASS_LINKED)) {
2305 if (!link_class(c)) {
2306 fprintf(stderr, "Error linking: ");
2307 utf_fprint_printable_ascii_classname(stderr, c->name);
2308 fprintf(stderr, "\n");
2310 /* print out exception and cause */
2312 exceptions_print_current_exception();
2314 /* goto next class */
2320 /* compile all class methods */
2322 for (i = 0; i < c->methodscount; i++) {
2323 m = &(c->methods[i]);
2325 if (m->jcode != NULL) {
2326 if (!jit_compile(m)) {
2327 fprintf(stderr, "Error compiling: ");
2328 utf_fprint_printable_ascii_classname(stderr, c->name);
2329 fprintf(stderr, ".");
2330 utf_fprint_printable_ascii(stderr, m->name);
2331 utf_fprint_printable_ascii(stderr, m->descriptor);
2332 fprintf(stderr, "\n");
2334 /* print out exception and cause */
2336 exceptions_print_current_exception();
2344 #endif /* !defined(NDEBUG) */
2347 /* vm_compile_method ***********************************************************
2349 Compile a specific method.
2351 *******************************************************************************/
2353 #if !defined(NDEBUG)
2354 static void vm_compile_method(char* mainname)
2358 /* create, load and link the main class */
2360 mainclass = load_class_bootstrap(utf_new_char(mainname));
2362 if (mainclass == NULL)
2363 exceptions_print_stacktrace();
2365 if (!link_class(mainclass))
2366 exceptions_print_stacktrace();
2368 if (opt_signature != NULL) {
2369 m = class_resolveclassmethod(mainclass,
2370 utf_new_char(opt_method),
2371 utf_new_char(opt_signature),
2376 m = class_resolveclassmethod(mainclass,
2377 utf_new_char(opt_method),
2384 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2385 opt_method, opt_signature ? opt_signature : "");
2389 #endif /* !defined(NDEBUG) */
2392 /* vm_call_array ***************************************************************
2394 Calls a Java method with a variable number of arguments, passed via
2397 ATTENTION: This function has to be used outside the nativeworld.
2399 *******************************************************************************/
2401 #define VM_CALL_ARRAY(name, type) \
2402 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2408 assert(m->code != NULL); \
2410 md = m->parseddesc; \
2411 pv = m->code->entrypoint; \
2413 STATISTICS(count_calls_native_to_java++); \
2415 value = asm_vm_call_method##name(pv, array, md->memuse); \
2420 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2426 assert(m->code != NULL);
2429 pv = m->code->entrypoint;
2431 STATISTICS(count_calls_native_to_java++);
2433 o = asm_vm_call_method(pv, array, md->memuse);
2435 if (md->returntype.type == TYPE_VOID)
2438 return LLNI_WRAP(o);
2441 VM_CALL_ARRAY(_int, int32_t)
2442 VM_CALL_ARRAY(_long, int64_t)
2443 VM_CALL_ARRAY(_float, float)
2444 VM_CALL_ARRAY(_double, double)
2447 /* vm_call_method **************************************************************
2449 Calls a Java method with a variable number of arguments.
2451 *******************************************************************************/
2453 #define VM_CALL_METHOD(name, type) \
2454 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2460 value = vm_call_method##name##_valist(m, o, ap); \
2466 VM_CALL_METHOD(, java_handle_t *)
2467 VM_CALL_METHOD(_int, int32_t)
2468 VM_CALL_METHOD(_long, int64_t)
2469 VM_CALL_METHOD(_float, float)
2470 VM_CALL_METHOD(_double, double)
2473 /* vm_call_method_valist *******************************************************
2475 Calls a Java method with a variable number of arguments, passed via
2478 *******************************************************************************/
2480 #define VM_CALL_METHOD_VALIST(name, type) \
2481 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2486 int32_t dumpmarker; \
2488 if (m->code == NULL) \
2489 if (!jit_compile(m)) \
2492 THREAD_NATIVEWORLD_EXIT; \
2495 array = argument_vmarray_from_valist(m, o, ap); \
2496 value = vm_call##name##_array(m, array); \
2499 THREAD_NATIVEWORLD_ENTER; \
2504 VM_CALL_METHOD_VALIST(, java_handle_t *)
2505 VM_CALL_METHOD_VALIST(_int, int32_t)
2506 VM_CALL_METHOD_VALIST(_long, int64_t)
2507 VM_CALL_METHOD_VALIST(_float, float)
2508 VM_CALL_METHOD_VALIST(_double, double)
2511 /* vm_call_method_jvalue *******************************************************
2513 Calls a Java method with a variable number of arguments, passed via
2516 *******************************************************************************/
2518 #define VM_CALL_METHOD_JVALUE(name, type) \
2519 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2520 const jvalue *args) \
2524 int32_t dumpmarker; \
2526 if (m->code == NULL) \
2527 if (!jit_compile(m)) \
2530 THREAD_NATIVEWORLD_EXIT; \
2533 array = argument_vmarray_from_jvalue(m, o, args); \
2534 value = vm_call##name##_array(m, array); \
2537 THREAD_NATIVEWORLD_ENTER; \
2542 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2543 VM_CALL_METHOD_JVALUE(_int, int32_t)
2544 VM_CALL_METHOD_JVALUE(_long, int64_t)
2545 VM_CALL_METHOD_JVALUE(_float, float)
2546 VM_CALL_METHOD_JVALUE(_double, double)
2549 /* vm_call_method_objectarray **************************************************
2551 Calls a Java method with a variable number if arguments, passed via
2552 an objectarray of boxed values. Returns a boxed value.
2554 *******************************************************************************/
2556 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2557 java_handle_objectarray_t *params)
2560 java_handle_t *xptr;
2565 /* Prevent compiler warnings. */
2569 /* compile methods which are not yet compiled */
2571 if (m->code == NULL)
2572 if (!jit_compile(m))
2575 /* leave the nativeworld */
2577 THREAD_NATIVEWORLD_EXIT;
2579 /* mark start of dump memory area */
2583 /* Fill the argument array from a object-array. */
2585 array = argument_vmarray_from_objectarray(m, o, params);
2587 if (array == NULL) {
2588 /* release dump area */
2592 /* enter the nativeworld again */
2594 THREAD_NATIVEWORLD_ENTER;
2596 exceptions_throw_illegalargumentexception();
2601 switch (m->parseddesc->returntype.decltype) {
2602 case PRIMITIVETYPE_VOID:
2603 value.a = vm_call_array(m, array);
2606 case PRIMITIVETYPE_BOOLEAN:
2607 case PRIMITIVETYPE_BYTE:
2608 case PRIMITIVETYPE_CHAR:
2609 case PRIMITIVETYPE_SHORT:
2610 case PRIMITIVETYPE_INT:
2611 value.i = vm_call_int_array(m, array);
2614 case PRIMITIVETYPE_LONG:
2615 value.l = vm_call_long_array(m, array);
2618 case PRIMITIVETYPE_FLOAT:
2619 value.f = vm_call_float_array(m, array);
2622 case PRIMITIVETYPE_DOUBLE:
2623 value.d = vm_call_double_array(m, array);
2627 ro = vm_call_array(m, array);
2631 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2634 /* release dump area */
2638 /* enter the nativeworld again */
2640 THREAD_NATIVEWORLD_ENTER;
2642 /* box the return value if necesarry */
2644 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2645 ro = Primitive::box(m->parseddesc->returntype.decltype, value);
2647 /* check for an exception */
2649 xptr = exceptions_get_exception();
2652 /* clear exception pointer, we are calling JIT code again */
2654 exceptions_clear_exception();
2656 exceptions_throw_invocationtargetexception(xptr);
2663 /* Legacy C interface *********************************************************/
2667 JavaVM* VM_get_javavm() { return vm->get_javavm(); }
2668 JNIEnv* VM_get_jnienv() { return vm->get_jnienv(); }
2669 bool VM_is_initializing() { return vm->is_initializing(); }
2670 bool VM_is_created() { return vm->is_created(); }
2671 int64_t VM_get_starttime() { return vm->get_starttime(); }
2677 * These are local overrides for various environment variables in Emacs.
2678 * Please do not remove this and leave it at the end of the file, where
2679 * Emacs will automagically detect them.
2680 * ---------------------------------------------------------------------
2683 * indent-tabs-mode: t
2687 * vim:noexpandtab:sw=4:ts=4: