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"
44 #include "mm/dumpmemory.hpp"
46 #include "mm/memory.h"
48 #include "native/jni.hpp"
49 #include "native/llni.h"
50 #include "native/localref.hpp"
51 #include "native/native.hpp"
53 #include "native/vm/nativevm.hpp"
55 #include "threads/lock.hpp"
56 #include "threads/thread.hpp"
58 #include "toolbox/logging.h"
60 #include "vm/array.hpp"
62 #if defined(ENABLE_ASSERTION)
63 #include "vm/assertion.hpp"
66 #include "vm/jit/builtin.hpp"
67 #include "vm/classcache.hpp"
68 #include "vm/exceptions.hpp"
69 #include "vm/finalizer.hpp"
70 #include "vm/global.h"
71 #include "vm/globals.hpp"
72 #include "vm/initialize.hpp"
73 #include "vm/options.h"
75 #include "vm/primitive.hpp"
76 #include "vm/properties.hpp"
77 #include "vm/signallocal.h"
78 #include "vm/statistics.h"
79 #include "vm/string.hpp"
80 #include "vm/suck.hpp"
83 #include "vm/jit/argument.hpp"
84 #include "vm/jit/asmpart.h"
85 #include "vm/jit/code.hpp"
87 #if defined(ENABLE_DISASSEMBLER)
88 # include "vm/jit/disass.h"
91 #include "vm/jit/jit.hpp"
92 #include "vm/jit/methodtree.h"
94 #if defined(ENABLE_PROFILING)
95 # include "vm/jit/optimizing/profile.h"
98 #include "vm/jit/optimizing/recompiler.hpp"
100 #if defined(ENABLE_PYTHON)
101 # include "vm/jit/python.h"
104 #include "vm/jit/trap.h"
106 #if defined(ENABLE_JVMTI)
107 # include "native/jvmti/cacaodbg.h"
110 #if defined(ENABLE_VMLOG)
111 #include <vmlog_cacao.h>
116 * This is _the_ VM instance.
121 /* global variables ***********************************************************/
123 s4 vms = 0; /* number of VMs created */
125 static classinfo *mainclass = NULL;
127 #if defined(ENABLE_INTRP)
128 u1 *intrp_main_stack = NULL;
132 /* define heap sizes **********************************************************/
134 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
135 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
136 #define STACK_SIZE 128 * 1024 /* default 64kB */
139 /* define command line options ************************************************/
173 /* Java non-standard options */
184 #if defined(ENABLE_PROFILING)
196 #if defined(ENABLE_STATISTICS)
213 #if defined(ENABLE_VERIFIER)
217 #if defined(TYPECHECK_VERBOSE)
220 #endif /* defined(ENABLE_VERIFIER) */
222 /* optimization options */
224 #if defined(ENABLE_LOOP)
228 #if defined(ENABLE_IFCONV)
232 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
236 #if defined(ENABLE_INTRP)
237 /* interpreter options */
256 #if defined(ENABLE_DEBUG_FILTER)
257 OPT_FILTER_VERBOSECALL_INCLUDE,
258 OPT_FILTER_VERBOSECALL_EXCLUDE,
259 OPT_FILTER_SHOW_METHOD,
266 opt_struct opts[] = {
267 { "foo", false, OPT_FOO },
271 { "jar", false, OPT_JAR },
273 { "d32", false, OPT_D32 },
274 { "d64", false, OPT_D64 },
275 { "client", false, OPT_IGNORE },
276 { "server", false, OPT_IGNORE },
277 { "jvm", false, OPT_IGNORE },
278 { "hotspot", false, OPT_IGNORE },
280 { "classpath", true, OPT_CLASSPATH },
281 { "cp", true, OPT_CLASSPATH },
282 { "D", true, OPT_D },
283 { "version", false, OPT_VERSION },
284 { "showversion", false, OPT_SHOWVERSION },
285 { "fullversion", false, OPT_FULLVERSION },
286 { "help", false, OPT_HELP },
287 { "?", false, OPT_HELP },
288 { "X", false, OPT_X },
289 { "XX:", true, OPT_XX },
291 { "ea:", true, OPT_EA },
292 { "da:", true, OPT_DA },
293 { "ea", false, OPT_EA_NOARG },
294 { "da", false, OPT_DA_NOARG },
296 { "enableassertions:", true, OPT_EA },
297 { "disableassertions:", true, OPT_DA },
298 { "enableassertions", false, OPT_EA_NOARG },
299 { "disableassertions", false, OPT_DA_NOARG },
301 { "esa", false, OPT_ESA },
302 { "enablesystemassertions", false, OPT_ESA },
303 { "dsa", false, OPT_DSA },
304 { "disablesystemassertions", false, OPT_DSA },
306 { "noasyncgc", false, OPT_IGNORE },
307 #if defined(ENABLE_VERIFIER)
308 { "noverify", false, OPT_NOVERIFY },
309 { "Xverify:all", false, OPT_XVERIFY_ALL },
310 { "Xverify:none", false, OPT_XVERIFY_NONE },
312 { "v", false, OPT_VERBOSE1 },
313 { "verbose:", true, OPT_VERBOSE },
315 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
316 { "verbosetc", false, OPT_VERBOSETC },
318 #if defined(ENABLE_STATISTICS)
319 { "time", false, OPT_TIME },
320 { "stat", false, OPT_STAT },
322 { "log", true, OPT_LOG },
323 { "c", true, OPT_CHECK },
324 { "l", false, OPT_LOAD },
327 { "all", false, OPT_ALL },
328 { "sig", true, OPT_SIGNATURE },
331 #if defined(ENABLE_LOOP)
332 { "oloop", false, OPT_OLOOP },
334 #if defined(ENABLE_IFCONV)
335 { "ifconv", false, OPT_IFCONV },
337 #if defined(ENABLE_LSRA)
338 { "lsra", false, OPT_LSRA },
340 #if defined(ENABLE_SSA)
341 { "lsra", true, OPT_LSRA },
344 #if defined(ENABLE_INTRP)
345 /* interpreter options */
347 { "trace", false, OPT_TRACE },
348 { "static-supers", true, OPT_STATIC_SUPERS },
349 { "no-dynamic", false, OPT_NO_DYNAMIC },
350 { "no-replication", false, OPT_NO_REPLICATION },
351 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
354 /* JVMTI Agent Command Line Options */
356 { "agentlib:", true, OPT_AGENTLIB },
357 { "agentpath:", true, OPT_AGENTPATH },
360 /* Java non-standard options */
362 { "Xjit", false, OPT_JIT },
363 { "Xint", false, OPT_INTRP },
364 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
365 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
366 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
367 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
370 { "Xdebug", false, OPT_DEBUG },
371 { "Xnoagent", false, OPT_NOAGENT },
372 { "Xrunjdwp", true, OPT_XRUNJDWP },
375 { "Xms", true, OPT_MS },
376 { "ms", true, OPT_MS },
377 { "Xmx", true, OPT_MX },
378 { "mx", true, OPT_MX },
379 { "Xss", true, OPT_SS },
380 { "ss", true, OPT_SS },
382 #if defined(ENABLE_PROFILING)
383 { "Xprof:", true, OPT_PROF_OPTION },
384 { "Xprof", false, OPT_PROF },
387 /* keep these at the end of the list */
390 { "m", true, OPT_METHOD },
393 { "s", true, OPT_SHOW },
394 { "debug-color", false, OPT_DEBUGCOLOR },
396 #if defined(ENABLE_DEBUG_FILTER)
397 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
398 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
399 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
406 /* usage ***********************************************************************
408 Prints the correct usage syntax to stdout.
410 *******************************************************************************/
414 puts("Usage: cacao [-options] classname [arguments]");
415 puts(" (to run a class file)");
416 puts(" or cacao [-options] -jar jarfile [arguments]");
417 puts(" (to run a standalone jar file)\n");
419 puts("where options include:");
420 puts(" -d32 use 32-bit data model if available");
421 puts(" -d64 use 64-bit data model if available");
422 puts(" -client compatibility (currently ignored)");
423 puts(" -server compatibility (currently ignored)");
424 puts(" -jvm compatibility (currently ignored)");
425 puts(" -hotspot compatibility (currently ignored)\n");
427 puts(" -cp <path> specify a path to look for classes");
428 puts(" -classpath <path> specify a path to look for classes");
429 puts(" -D<name>=<value> add an entry to the property list");
430 puts(" -verbose[:class|gc|jni] enable specific verbose output");
431 puts(" -version print product version and exit");
432 puts(" -fullversion print jpackage-compatible product version and exit");
433 puts(" -showversion print product version and continue");
434 puts(" -help, -? print this help message");
435 puts(" -X print help on non-standard Java options");
436 puts(" -XX print help on debugging options");
437 puts(" -ea[:<packagename>...|:<classname>]");
438 puts(" -enableassertions[:<packagename>...|:<classname>]");
439 puts(" enable assertions with specified granularity");
440 puts(" -da[:<packagename>...|:<classname>]");
441 puts(" -disableassertions[:<packagename>...|:<classname>]");
442 puts(" disable assertions with specified granularity");
443 puts(" -esa | -enablesystemassertions");
444 puts(" enable system assertions");
445 puts(" -dsa | -disablesystemassertions");
446 puts(" disable system assertions");
449 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
450 puts (" for jdwp help use: -agentlib:jdwp=help");
451 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
454 /* exit with error code */
460 static void Xusage(void)
462 #if defined(ENABLE_JIT)
463 puts(" -Xjit JIT mode execution (default)");
465 #if defined(ENABLE_INTRP)
466 puts(" -Xint interpreter mode execution");
468 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
469 puts(" value is set as bootstrap class path");
470 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
471 puts(" value is appended to the bootstrap class path");
472 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
473 puts(" value is prepended to the bootstrap class path");
474 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
475 puts(" value is used as Java core library, but the");
476 puts(" hardcoded VM interface classes are prepended");
477 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
478 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
479 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
481 #if defined(ENABLE_PROFILING)
482 puts(" -Xprof[:bb] collect and print profiling data");
485 #if defined(ENABLE_JVMTI)
486 /* -Xdebug option depend on gnu classpath JDWP options. options:
487 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
488 puts(" -Xdebug enable remote debugging\n");
489 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
490 puts(" enable remote debugging\n");
493 /* exit with error code */
500 static void XXusage(void)
502 puts(" -v write state-information");
504 puts(" -verbose:jit enable specific verbose output");
505 puts(" -debug-color colored output for ANSI terms");
507 #ifdef TYPECHECK_VERBOSE
508 puts(" -verbosetc write debug messages while typechecking");
510 #if defined(ENABLE_VERIFIER)
511 puts(" -noverify don't verify classfiles");
513 #if defined(ENABLE_STATISTICS)
514 puts(" -time measure the runtime");
515 puts(" -stat detailed compiler statistics");
517 puts(" -log logfile specify a name for the logfile");
518 puts(" -c(heck)b(ounds) don't check array bounds");
519 puts(" s(ync) don't check for synchronization");
520 #if defined(ENABLE_LOOP)
521 puts(" -oloop optimize array accesses in loops");
523 puts(" -l don't start the class after loading");
525 puts(" -all compile all methods, no execution");
526 puts(" -m compile only a specific method");
527 puts(" -sig specify signature for a specific method");
530 puts(" -s... show...");
531 puts(" (c)onstants the constant pool");
532 puts(" (m)ethods class fields and methods");
533 puts(" (u)tf the utf - hash");
534 puts(" (i)ntermediate intermediate representation");
535 #if defined(ENABLE_DISASSEMBLER)
536 puts(" (a)ssembler disassembled listing");
537 puts(" n(o)ps show NOPs in disassembler output");
539 puts(" (d)atasegment data segment listing");
541 #if defined(ENABLE_IFCONV)
542 puts(" -ifconv use if-conversion");
544 #if defined(ENABLE_LSRA)
545 puts(" -lsra use linear scan register allocation");
547 #if defined(ENABLE_SSA)
548 puts(" -lsra:... use linear scan register allocation (with SSA)");
549 puts(" (d)ead code elimination");
550 puts(" (c)opy propagation");
552 #if defined(ENABLE_DEBUG_FILTER)
553 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
554 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
555 puts(" -XXfm <regex> filter for show options");
557 /* exit with error code */
564 /* version *********************************************************************
566 Only prints cacao version information.
568 *******************************************************************************/
570 static void version(bool opt_exit)
572 puts("java version \""JAVA_VERSION"\"");
573 puts("CACAO version "VERSION"\n");
575 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
576 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
577 puts("This is free software; see the source for copying conditions. There is NO");
578 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
580 /* exit normally, if requested */
587 /* fullversion *****************************************************************
589 Prints a Sun compatible version information (required e.g. by
590 jpackage, www.jpackage.org).
592 *******************************************************************************/
594 static void fullversion(void)
596 puts("java full version \"cacao-"JAVA_VERSION"\"");
604 /* forward declarations *******************************************************/
606 static char *vm_get_mainclass_from_jar(char *mainstring);
608 static void vm_compile_all(void);
609 static void vm_compile_method(char* mainname);
614 * Implementation for JNI_CreateJavaVM. This function creates a VM
621 * @return true on success, false otherwise.
623 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
625 JavaVMInitArgs* _vm_args;
627 // Get the arguments for the new JVM.
628 _vm_args = (JavaVMInitArgs *) vm_args;
630 // Instantiate a new VM.
632 _vm = new VM(_vm_args);
634 catch (std::exception e) {
635 // FIXME How can we delete the resources allocated?
636 // /* release allocated memory */
637 // FREE(env, _Jv_JNIEnv);
638 // FREE(vm, _Jv_JavaVM);
645 // Return the values.
647 *p_vm = _vm->get_javavm();
648 *p_env = _vm->get_jnienv();
655 * C wrapper for VM::create.
658 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
660 return VM::create(p_vm, p_env, vm_args);
668 VM::VM(JavaVMInitArgs* vm_args)
670 // Very first thing to do: we are initializing.
671 _initializing = true;
673 // Make ourself globally visible.
674 // XXX Is this a good idea?
677 /* create and fill a JavaVM structure */
679 _javavm = new JavaVM();
681 #if defined(ENABLE_JNI)
682 _javavm->functions = &_Jv_JNIInvokeInterface;
685 /* get the VM and Env tables (must be set before vm_create) */
686 /* XXX JVMTI Agents needs a JavaVM */
688 _jnienv = new JNIEnv();
690 #if defined(ENABLE_JNI)
691 _jnienv->functions = &_Jv_JNINativeInterface;
694 /* actually create the JVM */
698 char *boot_class_path;
704 #if defined(ENABLE_JVMTI)
706 char *libname, *agentarg;
707 bool jdwp,agentbypath;
708 jdwp = agentbypath = false;
711 #if defined(ENABLE_JNI)
712 /* Check the JNI version requested. */
714 if (!jni_version_check(vm_args->version))
715 throw std::exception();
718 /* We only support 1 JVM instance. */
721 throw std::exception();
723 /* Install the exit handler. */
725 if (atexit(vm_exit_handler))
726 os::abort("atexit failed: %s\n", strerror(errno));
728 /* Set some options. */
733 opt_heapmaxsize = HEAP_MAXSIZE;
734 opt_heapstartsize = HEAP_STARTSIZE;
735 opt_stacksize = STACK_SIZE;
737 // First of all, parse the -XX options.
739 #if defined(ENABLE_VMLOG)
740 vmlog_cacao_init_options();
745 // After -XX options are parsed, print the build-time
746 // configuration, if requested.
748 print_build_time_config();
750 #if defined(ENABLE_VMLOG)
754 /* We need to check if the actual size of a java.lang.Class object
755 is smaller or equal than the assumption made in
758 #warning FIXME We need to check the size of java.lang.Class!!!
759 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
760 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
762 /* set the VM starttime */
764 _starttime = builtin_currenttimemillis();
766 #if defined(ENABLE_JVMTI)
767 /* initialize JVMTI related **********************************************/
771 /* iterate over all passed options */
773 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
787 #if SIZEOF_VOID_P == 8
788 puts("Running a 32-bit JVM is not supported on this platform.");
794 #if SIZEOF_VOID_P == 4
795 puts("Running a 64-bit JVM is not supported on this platform.");
801 /* Forget old classpath and set the argument as new
804 // FIXME Make class_path const char*.
805 class_path = (char*) _properties.get("java.class.path");
807 p = MNEW(char, strlen(opt_arg) + strlen("0"));
811 #if defined(ENABLE_JAVASE)
812 _properties.put("java.class.path", p);
815 MFREE(class_path, char, strlen(class_path));
819 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
820 if (opt_arg[i] == '=') {
822 _properties.put(opt_arg, opt_arg + i + 1);
827 /* if no '=' is given, just create an empty property */
829 _properties.put(opt_arg, "");
834 case OPT_BOOTCLASSPATH:
835 /* Forget default bootclasspath and set the argument as
836 new boot classpath. */
838 // FIXME Make boot_class_path const char*.
839 boot_class_path = (char*) _properties.get("sun.boot.class.path");
841 p = MNEW(char, strlen(opt_arg) + strlen("0"));
845 _properties.put("sun.boot.class.path", p);
846 _properties.put("java.boot.class.path", p);
848 MFREE(boot_class_path, char, strlen(boot_class_path));
851 case OPT_BOOTCLASSPATH_A:
852 /* Append to bootclasspath. */
854 // FIXME Make boot_class_path const char*.
855 boot_class_path = (char*) _properties.get("sun.boot.class.path");
857 len = strlen(boot_class_path);
859 // XXX (char*) quick hack
860 p = (char*) MREALLOC(boot_class_path,
864 strlen(opt_arg) + strlen("0"));
869 _properties.put("sun.boot.class.path", p);
870 _properties.put("java.boot.class.path", p);
873 case OPT_BOOTCLASSPATH_P:
874 /* Prepend to bootclasspath. */
876 // FIXME Make boot_class_path const char*.
877 boot_class_path = (char*) _properties.get("sun.boot.class.path");
879 len = strlen(boot_class_path);
881 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
885 strcat(p, boot_class_path);
887 _properties.put("sun.boot.class.path", p);
888 _properties.put("java.boot.class.path", p);
890 MFREE(boot_class_path, char, len);
893 case OPT_BOOTCLASSPATH_C:
894 /* Use as Java core library, but prepend VM interface
897 // FIXME Make boot_class_path const char*.
898 boot_class_path = (char*) _properties.get("sun.boot.class.path");
901 strlen(CACAO_VM_ZIP) +
908 strcpy(p, CACAO_VM_ZIP);
912 _properties.put("sun.boot.class.path", p);
913 _properties.put("java.boot.class.path", p);
915 MFREE(boot_class_path, char, strlen(boot_class_path));
918 #if defined(ENABLE_JVMTI)
920 /* this option exists only for compatibility reasons */
924 /* I don't know yet what Xnoagent should do. This is only for
925 compatiblity with eclipse - motse */
934 strlen(CACAO_LIBDIR) +
935 strlen("/libjdwp.so=") +
939 agentarg = MNEW(char, len);
941 strcpy(agentarg, CACAO_LIBDIR);
942 strcat(agentarg, "/libjdwp.so=");
943 strcat(agentarg, &opt_arg[1]);
962 c = opt_arg[strlen(opt_arg) - 1];
964 if ((c == 'k') || (c == 'K')) {
965 j = atoi(opt_arg) * 1024;
967 } else if ((c == 'm') || (c == 'M')) {
968 j = atoi(opt_arg) * 1024 * 1024;
975 else if (opt == OPT_MS)
976 opt_heapstartsize = j;
987 if (strcmp("class", opt_arg) == 0) {
988 opt_verboseclass = true;
990 else if (strcmp("gc", opt_arg) == 0) {
991 opt_verbosegc = true;
993 else if (strcmp("jni", opt_arg) == 0) {
994 opt_verbosejni = true;
997 else if (strcmp("jit", opt_arg) == 0) {
1001 compileverbose = true;
1005 printf("Unknown -verbose option: %s\n", opt_arg);
1010 case OPT_DEBUGCOLOR:
1011 opt_debugcolor = true;
1014 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1016 opt_typecheckverbose = true;
1025 case OPT_FULLVERSION:
1029 case OPT_SHOWVERSION:
1033 #if defined(ENABLE_VERIFIER)
1034 case OPT_XVERIFY_ALL:
1039 case OPT_XVERIFY_NONE:
1044 #if defined(ENABLE_STATISTICS)
1046 opt_getcompilingtime = true;
1047 opt_getloadingtime = true;
1060 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1061 switch (opt_arg[i]) {
1063 checkbounds = false;
1076 makeinitializations = false;
1079 #if !defined(NDEBUG)
1083 makeinitializations = false;
1088 opt_method = opt_arg;
1089 makeinitializations = false;
1093 opt_signature = opt_arg;
1097 case OPT_SHOW: /* Display options */
1098 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1099 switch (opt_arg[i]) {
1101 showconstantpool = true;
1113 opt_showintermediate = true;
1114 compileverbose = true;
1117 #if defined(ENABLE_DISASSEMBLER)
1119 opt_showdisassemble = true;
1120 compileverbose = true;
1125 opt_showddatasegment = true;
1134 #if defined(ENABLE_LOOP)
1140 #if defined(ENABLE_IFCONV)
1146 #if defined(ENABLE_LSRA)
1151 #if defined(ENABLE_SSA)
1154 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1155 switch (opt_arg[i]) {
1183 /* Already parsed. */
1187 #if defined(ENABLE_ASSERTION)
1188 assertion_ea_da(opt_arg, true);
1193 #if defined(ENABLE_ASSERTION)
1194 assertion_ea_da(opt_arg, false);
1199 #if defined(ENABLE_ASSERTION)
1200 assertion_user_enabled = true;
1205 #if defined(ENABLE_ASSERTION)
1206 assertion_user_enabled = false;
1211 #if defined(ENABLE_ASSERTION)
1212 assertion_system_enabled = true;
1217 #if defined(ENABLE_ASSERTION)
1218 assertion_system_enabled = false;
1222 #if defined(ENABLE_PROFILING)
1223 case OPT_PROF_OPTION:
1224 /* use <= to get the last \0 too */
1226 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1227 if (opt_arg[i] == ',')
1230 if (opt_arg[i] == '\0') {
1231 if (strcmp("bb", opt_arg + j) == 0)
1235 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1239 /* set k to next char */
1252 #if defined(ENABLE_JIT)
1255 printf("-Xjit option not enabled.\n");
1261 #if defined(ENABLE_INTRP)
1264 printf("-Xint option not enabled.\n");
1269 #if defined(ENABLE_INTRP)
1270 case OPT_STATIC_SUPERS:
1271 opt_static_supers = atoi(opt_arg);
1274 case OPT_NO_DYNAMIC:
1275 opt_no_dynamic = true;
1278 case OPT_NO_REPLICATION:
1279 opt_no_replication = true;
1282 case OPT_NO_QUICKSUPER:
1283 opt_no_quicksuper = true;
1291 #if defined(ENABLE_DEBUG_FILTER)
1292 case OPT_FILTER_VERBOSECALL_INCLUDE:
1293 opt_filter_verbosecall_include = opt_arg;
1296 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1297 opt_filter_verbosecall_exclude = opt_arg;
1300 case OPT_FILTER_SHOW_METHOD:
1301 opt_filter_show_method = opt_arg;
1306 printf("Unknown option: %s\n",
1307 vm_args->options[opt_index].optionString);
1312 // Print the preliminary run-time VM configuration after options
1314 if (opt_PrintConfig)
1315 print_run_time_config();
1317 #if defined(ENABLE_JVMTI)
1319 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1320 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1323 MFREE(agentarg, char, strlen(agentarg));
1325 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1329 /* initialize the garbage collector */
1331 gc_init(opt_heapmaxsize, opt_heapstartsize);
1333 #if defined(ENABLE_THREADS)
1334 /* AFTER: gc_init */
1340 /* install architecture dependent signal handlers */
1343 os::abort("vm_create: signal_init failed");
1345 #if defined(ENABLE_INTRP)
1346 /* Allocate main thread stack on the Java heap. */
1349 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1350 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1354 /* AFTER: threads_preinit */
1357 os::abort("vm_create: string_init failed");
1359 /* AFTER: threads_preinit */
1363 /* AFTER: thread_preinit */
1366 os::abort("vm_create: suck_init failed");
1368 suck_add_from_property("java.endorsed.dirs");
1370 /* Now we have all options handled and we can print the version
1373 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1378 /* AFTER: utf8_init */
1380 // FIXME Make boot_class_path const char*.
1381 boot_class_path = (char*) _properties.get("sun.boot.class.path");
1382 suck_add(boot_class_path);
1384 /* initialize the classcache hashtable stuff: lock, hashtable
1385 (must be done _after_ threads_preinit) */
1387 if (!classcache_init())
1388 os::abort("vm_create: classcache_init failed");
1390 /* Initialize the code memory management. */
1391 /* AFTER: threads_preinit */
1395 /* initialize the finalizer stuff (must be done _after_
1398 if (!finalizer_init())
1399 os::abort("vm_create: finalizer_init failed");
1401 /* Initialize the JIT compiler. */
1407 #if defined(ENABLE_PYTHON)
1411 /* AFTER: utf8_init, classcache_init */
1416 // AFTER: loader_preinit, linker_preinit
1417 Primitive::initialize_table();
1422 // AFTER: loader_init, linker_init
1423 Primitive::post_initialize_table();
1426 #if defined(ENABLE_JIT)
1430 if (!builtin_init())
1431 os::abort("vm_create: builtin_init failed");
1433 /* Register the native methods implemented in the VM. */
1434 /* BEFORE: threads_init */
1438 #if defined(ENABLE_JNI)
1439 /* Initialize the JNI subsystem (must be done _before_
1440 threads_init, as threads_init can call JNI methods
1441 (e.g. NewGlobalRef). */
1444 os::abort("vm_create: jni_init failed");
1447 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1448 /* Initialize the local reference table for the main thread. */
1449 /* BEFORE: threads_init */
1451 if (!localref_table_init())
1452 os::abort("vm_create: localref_table_init failed");
1455 /* Iinitialize some important system classes. */
1456 /* BEFORE: threads_init */
1460 #if defined(ENABLE_THREADS)
1464 /* Initialize the native VM subsystem. */
1465 /* AFTER: threads_init (at least for SUN's classes) */
1469 #if defined(ENABLE_PROFILING)
1470 /* initialize profiling */
1472 if (!profile_init())
1473 os::abort("vm_create: profile_init failed");
1476 #if defined(ENABLE_THREADS)
1477 /* start the signal handler thread */
1479 #if defined(__LINUX__)
1480 /* XXX Remove for exact-GC. */
1481 if (threads_pthreads_implementation_nptl)
1483 if (!signal_start_thread())
1484 os::abort("vm_create: signal_start_thread failed");
1486 /* finally, start the finalizer thread */
1488 if (!finalizer_start_thread())
1489 os::abort("vm_create: finalizer_start_thread failed");
1491 # if !defined(NDEBUG)
1492 /* start the memory profiling thread */
1494 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1495 if (!memory_start_thread())
1496 os::abort("vm_create: memory_start_thread failed");
1499 // Start the recompilation thread (must be done before the
1500 // profiling thread).
1501 // FIXME Only works for one recompiler.
1502 _recompiler.start();
1504 # if defined(ENABLE_PROFILING)
1505 /* start the profile sampling thread */
1508 /* if (!profile_start_thread()) */
1509 /* os::abort("vm_create: profile_start_thread failed"); */
1513 #if defined(ENABLE_JVMTI)
1514 # if defined(ENABLE_GC_CACAO)
1515 /* XXX this will not work with the new indirection cells for classloaders!!! */
1519 /* add agent library to native library hashtable */
1520 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1524 /* Increment the number of VMs. */
1528 // Initialization is done, VM is created.
1530 _initializing = false;
1532 // Print the run-time VM configuration after all stuff is set and
1533 // the VM is initialized.
1534 if (opt_PrintConfig)
1535 print_run_time_config();
1540 * Print build-time (default) VM configuration.
1542 void VM::print_build_time_config(void)
1544 puts("CACAO "VERSION" configure/build options:");
1546 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1547 #if defined(__VERSION__)
1548 puts(" CC : "VERSION_CC" ("__VERSION__")");
1549 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1551 puts(" CC : "VERSION_CC"");
1552 puts(" CXX : "VERSION_CXX"");
1554 puts(" CFLAGS : "VERSION_CFLAGS"");
1555 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1559 puts("Build-time (default) variables:\n");
1560 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1561 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1562 printf(" stack size : %d\n", STACK_SIZE);
1564 #if defined(ENABLE_JRE_LAYOUT)
1565 // When we're building with JRE-layout, the default paths are the
1566 // same as the runtime paths.
1568 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1569 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1570 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1571 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1572 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1573 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1582 * Print run-time VM configuration.
1584 void VM::print_run_time_config()
1586 puts("Run-time variables:\n");
1587 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1588 printf(" initial heap size : %d\n", opt_heapstartsize);
1589 printf(" stack size : %d\n", opt_stacksize);
1591 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1592 printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1593 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1594 printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1597 printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1598 printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1604 /* vm_run **********************************************************************
1606 Runs the main-method of the passed class.
1608 *******************************************************************************/
1610 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1616 classinfo *mainclass;
1619 java_handle_objectarray_t *oa;
1625 // Prevent compiler warnings.
1628 #if !defined(NDEBUG)
1635 /* Get the main class plus it's arguments. */
1639 if (opt_index < vm_args->nOptions) {
1640 /* Get main-class argument. */
1642 mainname = vm_args->options[opt_index].optionString;
1644 /* If the main class argument is a jar file, put it into the
1647 if (opt_jar == true) {
1648 p = MNEW(char, strlen(mainname) + strlen("0"));
1650 strcpy(p, mainname);
1652 #if defined(ENABLE_JAVASE)
1653 VM::get_current()->get_properties().put("java.class.path", p);
1657 /* Replace dots with slashes in the class name. */
1659 for (unsigned int i = 0; i < strlen(mainname); i++)
1660 if (mainname[i] == '.')
1664 /* Build argument array. Move index to first argument. */
1668 oalength = vm_args->nOptions - opt_index;
1670 oa = builtin_anewarray(oalength, class_java_lang_String);
1672 for (int i = 0; i < oalength; i++) {
1673 option = vm_args->options[opt_index + i].optionString;
1675 u = utf_new_char(option);
1676 s = javastring_new(u);
1678 array_objectarray_element_set(oa, i, s);
1682 /* Do we have a main-class argument? */
1684 if (mainname == NULL)
1687 #if !defined(NDEBUG)
1688 if (opt_method != NULL) {
1689 vm_compile_method(mainname);
1694 /* set return value to OK */
1698 if (opt_jar == true) {
1699 /* open jar file with java.util.jar.JarFile */
1701 mainname = vm_get_mainclass_from_jar(mainname);
1703 if (mainname == NULL)
1707 /* load the main class */
1709 mainutf = utf_new_char(mainname);
1711 #if defined(ENABLE_JAVAME_CLDC1_1)
1712 mainclass = load_class_bootstrap(mainutf);
1714 mainclass = load_class_from_sysloader(mainutf);
1717 /* error loading class */
1719 e = exceptions_get_and_clear_exception();
1721 if ((e != NULL) || (mainclass == NULL)) {
1722 exceptions_throw_noclassdeffounderror_cause(e);
1723 exceptions_print_stacktrace();
1727 if (!link_class(mainclass)) {
1728 exceptions_print_stacktrace();
1732 /* find the `main' method of the main class */
1734 m = class_resolveclassmethod(mainclass,
1735 utf_new_char("main"),
1736 utf_new_char("([Ljava/lang/String;)V"),
1737 class_java_lang_Object,
1740 if (exceptions_get_exception()) {
1741 exceptions_print_stacktrace();
1745 /* there is no main method or it isn't static */
1747 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1748 exceptions_clear_exception();
1749 exceptions_throw_nosuchmethoderror(mainclass,
1750 utf_new_char("main"),
1751 utf_new_char("([Ljava/lang/String;)V"));
1753 exceptions_print_stacktrace();
1757 #ifdef TYPEINFO_DEBUG_TEST
1758 /* test the typeinfo system */
1762 #if defined(ENABLE_JVMTI)
1763 jvmti_set_phase(JVMTI_PHASE_LIVE);
1766 /* set ThreadMXBean variables */
1768 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1769 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1771 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1772 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1773 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1774 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1775 #warning Move to C++
1777 /* start the main thread */
1779 (void) vm_call_method(m, NULL, oa);
1781 /* exception occurred? */
1783 if (exceptions_get_exception()) {
1784 exceptions_print_stacktrace();
1788 #if defined(ENABLE_THREADS)
1789 /* Detach the main thread so that it appears to have ended when
1790 the application's main method exits. */
1792 if (!thread_detach_current_thread())
1793 os::abort("vm_run: Could not detach main thread.");
1796 /* Destroy the JavaVM. */
1798 (void) vm_destroy(vm);
1806 /* vm_destroy ******************************************************************
1808 Unloads a Java VM and reclaims its resources.
1810 *******************************************************************************/
1812 int vm_destroy(JavaVM *vm)
1814 #if defined(ENABLE_THREADS)
1815 /* Create a a trivial new Java waiter thread called
1818 JavaVMAttachArgs args;
1820 args.name = (char*) "DestroyJavaVM";
1823 if (!thread_attach_current_thread(&args, false))
1826 /* Wait until we are the last non-daemon thread. */
1828 threads_join_all_threads();
1833 // _created = false;
1834 #warning Move to C++
1836 /* Everything is ok. */
1842 /* vm_exit *********************************************************************
1844 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1846 *******************************************************************************/
1848 void vm_exit(s4 status)
1852 /* signal that we are exiting */
1855 #warning Move to C++
1857 assert(class_java_lang_System);
1858 assert(class_java_lang_System->state & CLASS_LOADED);
1860 #if defined(ENABLE_JVMTI)
1861 if (jvmti || (dbgcom!=NULL)) {
1862 jvmti_set_phase(JVMTI_PHASE_DEAD);
1863 if (jvmti) jvmti_agentunload();
1867 if (!link_class(class_java_lang_System)) {
1868 exceptions_print_stacktrace();
1872 /* call java.lang.System.exit(I)V */
1874 m = class_resolveclassmethod(class_java_lang_System,
1875 utf_new_char("exit"),
1877 class_java_lang_Object,
1881 exceptions_print_stacktrace();
1885 /* call the exit function with passed exit status */
1887 (void) vm_call_method(m, NULL, status);
1889 /* If we had an exception, just ignore the exception and exit with
1892 vm_shutdown(status);
1896 /* vm_shutdown *****************************************************************
1898 Terminates the system immediately without freeing memory explicitly
1899 (to be used only for abnormal termination).
1901 *******************************************************************************/
1903 void vm_shutdown(s4 status)
1906 #if defined(ENABLE_STATISTICS)
1907 || opt_getcompilingtime || opt_stat
1911 log_text("CACAO terminated by shutdown");
1912 dolog("Exit status: %d\n", (s4) status);
1916 #if defined(ENABLE_JVMTI)
1917 /* terminate cacaodbgserver */
1919 mutex_lock(&dbgcomlock);
1921 mutex_unlock(&dbgcomlock);
1922 jvmti_cacaodbgserver_quit();
1930 /* vm_exit_handler *************************************************************
1932 The exit_handler function is called upon program termination.
1934 ATTENTION: Don't free system resources here! Some threads may still
1935 be running as this is called from VMRuntime.exit(). The OS does the
1938 *******************************************************************************/
1940 void vm_exit_handler(void)
1942 #if !defined(NDEBUG)
1944 class_showmethods(mainclass);
1946 if (showconstantpool)
1947 class_showconstantpool(mainclass);
1952 # if defined(ENABLE_PROFILING)
1954 profile_printstats();
1956 #endif /* !defined(NDEBUG) */
1958 #if defined(ENABLE_RT_TIMING)
1959 rt_timing_print_time_stats(stderr);
1962 #if defined(ENABLE_CYCLES_STATS)
1963 builtin_print_cycles_stats(stderr);
1964 stacktrace_print_cycles_stats(stderr);
1968 #if defined(ENABLE_STATISTICS)
1969 || opt_getcompilingtime || opt_stat
1973 log_text("CACAO terminated");
1975 #if defined(ENABLE_STATISTICS)
1978 #ifdef TYPECHECK_STATISTICS
1979 typecheck_print_statistics(get_logfile());
1983 if (opt_getcompilingtime)
1985 #endif /* defined(ENABLE_STATISTICS) */
1987 /* vm_print_profile(stderr);*/
1991 /* vm_abort_disassemble ********************************************************
1993 Prints an error message, disassemble the given code range (if
1994 enabled) and aborts the VM.
1997 pc.......PC to disassemble
1998 count....number of instructions to disassemble
2000 *******************************************************************************/
2002 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2005 #if defined(ENABLE_DISASSEMBLER)
2009 /* Print debug message. */
2014 log_vprint(text, ap);
2021 #if SIZEOF_VOID_P == 8
2022 log_println("PC=0x%016lx", pc);
2024 log_println("PC=0x%08x", pc);
2027 #if defined(ENABLE_DISASSEMBLER)
2028 log_println("machine instructions at PC:");
2030 /* Disassemble the given number of instructions. */
2032 for (i = 0; i < count; i++)
2033 // FIXME disassinstr should use void*.
2034 pc = disassinstr((u1*) pc);
2037 os::abort("Aborting...");
2041 /* vm_get_mainclass_from_jar ***************************************************
2043 Gets the name of the main class from a JAR's manifest file.
2045 *******************************************************************************/
2047 static char *vm_get_mainclass_from_jar(char *mainname)
2054 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2057 exceptions_print_stacktrace();
2061 /* create JarFile object */
2066 exceptions_print_stacktrace();
2070 m = class_resolveclassmethod(c,
2072 utf_java_lang_String__void,
2073 class_java_lang_Object,
2077 exceptions_print_stacktrace();
2081 s = javastring_new_from_ascii(mainname);
2083 (void) vm_call_method(m, o, s);
2085 if (exceptions_get_exception()) {
2086 exceptions_print_stacktrace();
2090 /* get manifest object */
2092 m = class_resolveclassmethod(c,
2093 utf_new_char("getManifest"),
2094 utf_new_char("()Ljava/util/jar/Manifest;"),
2095 class_java_lang_Object,
2099 exceptions_print_stacktrace();
2103 o = vm_call_method(m, o);
2106 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2111 /* get Main Attributes */
2113 LLNI_class_get(o, c);
2115 m = class_resolveclassmethod(c,
2116 utf_new_char("getMainAttributes"),
2117 utf_new_char("()Ljava/util/jar/Attributes;"),
2118 class_java_lang_Object,
2122 exceptions_print_stacktrace();
2126 o = vm_call_method(m, o);
2129 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2134 /* get property Main-Class */
2136 LLNI_class_get(o, c);
2138 m = class_resolveclassmethod(c,
2139 utf_new_char("getValue"),
2140 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2141 class_java_lang_Object,
2145 exceptions_print_stacktrace();
2149 s = javastring_new_from_ascii("Main-Class");
2151 o = vm_call_method(m, o, s);
2154 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2155 fprintf(stderr, "%s\n", mainname);
2159 return javastring_tochar(o);
2163 /* vm_compile_all **************************************************************
2165 Compile all methods found in the bootclasspath.
2167 *******************************************************************************/
2169 #if !defined(NDEBUG)
2170 static void vm_compile_all(void)
2175 classcache_name_entry *nmen;
2176 classcache_class_entry *clsen;
2179 /* create all classes found in the bootclasspath */
2180 /* XXX currently only works with zip/jar's */
2182 loader_load_all_classes();
2184 /* link all classes */
2186 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2187 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2189 for (; nmen; nmen = nmen->hashlink) {
2190 /* iterate over all class entries */
2192 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2193 c = clsen->classobj;
2198 if (!(c->state & CLASS_LINKED)) {
2199 if (!link_class(c)) {
2200 fprintf(stderr, "Error linking: ");
2201 utf_fprint_printable_ascii_classname(stderr, c->name);
2202 fprintf(stderr, "\n");
2204 /* print out exception and cause */
2206 exceptions_print_current_exception();
2208 /* goto next class */
2214 /* compile all class methods */
2216 for (i = 0; i < c->methodscount; i++) {
2217 m = &(c->methods[i]);
2219 if (m->jcode != NULL) {
2220 if (!jit_compile(m)) {
2221 fprintf(stderr, "Error compiling: ");
2222 utf_fprint_printable_ascii_classname(stderr, c->name);
2223 fprintf(stderr, ".");
2224 utf_fprint_printable_ascii(stderr, m->name);
2225 utf_fprint_printable_ascii(stderr, m->descriptor);
2226 fprintf(stderr, "\n");
2228 /* print out exception and cause */
2230 exceptions_print_current_exception();
2238 #endif /* !defined(NDEBUG) */
2241 /* vm_compile_method ***********************************************************
2243 Compile a specific method.
2245 *******************************************************************************/
2247 #if !defined(NDEBUG)
2248 static void vm_compile_method(char* mainname)
2252 /* create, load and link the main class */
2254 mainclass = load_class_bootstrap(utf_new_char(mainname));
2256 if (mainclass == NULL)
2257 exceptions_print_stacktrace();
2259 if (!link_class(mainclass))
2260 exceptions_print_stacktrace();
2262 if (opt_signature != NULL) {
2263 m = class_resolveclassmethod(mainclass,
2264 utf_new_char(opt_method),
2265 utf_new_char(opt_signature),
2270 m = class_resolveclassmethod(mainclass,
2271 utf_new_char(opt_method),
2278 os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2279 opt_method, opt_signature ? opt_signature : "");
2283 #endif /* !defined(NDEBUG) */
2286 /* vm_call_array ***************************************************************
2288 Calls a Java method with a variable number of arguments, passed via
2291 ATTENTION: This function has to be used outside the nativeworld.
2293 *******************************************************************************/
2295 #define VM_CALL_ARRAY(name, type) \
2296 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2302 assert(m->code != NULL); \
2304 md = m->parseddesc; \
2305 pv = m->code->entrypoint; \
2307 STATISTICS(count_calls_native_to_java++); \
2309 value = asm_vm_call_method##name(pv, array, md->memuse); \
2314 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2320 assert(m->code != NULL);
2323 pv = m->code->entrypoint;
2325 STATISTICS(count_calls_native_to_java++);
2327 o = asm_vm_call_method(pv, array, md->memuse);
2329 if (md->returntype.type == TYPE_VOID)
2332 return LLNI_WRAP(o);
2335 VM_CALL_ARRAY(_int, int32_t)
2336 VM_CALL_ARRAY(_long, int64_t)
2337 VM_CALL_ARRAY(_float, float)
2338 VM_CALL_ARRAY(_double, double)
2341 /* vm_call_method **************************************************************
2343 Calls a Java method with a variable number of arguments.
2345 *******************************************************************************/
2347 #define VM_CALL_METHOD(name, type) \
2348 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2354 value = vm_call_method##name##_valist(m, o, ap); \
2360 VM_CALL_METHOD(, java_handle_t *)
2361 VM_CALL_METHOD(_int, int32_t)
2362 VM_CALL_METHOD(_long, int64_t)
2363 VM_CALL_METHOD(_float, float)
2364 VM_CALL_METHOD(_double, double)
2367 /* vm_call_method_valist *******************************************************
2369 Calls a Java method with a variable number of arguments, passed via
2372 *******************************************************************************/
2374 #define VM_CALL_METHOD_VALIST(name, type) \
2375 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2381 if (m->code == NULL) \
2382 if (!jit_compile(m)) \
2385 THREAD_NATIVEWORLD_EXIT; \
2387 DumpMemoryArea dma; \
2389 array = argument_vmarray_from_valist(m, o, ap); \
2390 value = vm_call##name##_array(m, array); \
2392 THREAD_NATIVEWORLD_ENTER; \
2397 VM_CALL_METHOD_VALIST(, java_handle_t *)
2398 VM_CALL_METHOD_VALIST(_int, int32_t)
2399 VM_CALL_METHOD_VALIST(_long, int64_t)
2400 VM_CALL_METHOD_VALIST(_float, float)
2401 VM_CALL_METHOD_VALIST(_double, double)
2404 /* vm_call_method_jvalue *******************************************************
2406 Calls a Java method with a variable number of arguments, passed via
2409 *******************************************************************************/
2411 #define VM_CALL_METHOD_JVALUE(name, type) \
2412 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2413 const jvalue *args) \
2418 if (m->code == NULL) \
2419 if (!jit_compile(m)) \
2422 THREAD_NATIVEWORLD_EXIT; \
2424 DumpMemoryArea dma; \
2426 array = argument_vmarray_from_jvalue(m, o, args); \
2427 value = vm_call##name##_array(m, array); \
2429 THREAD_NATIVEWORLD_ENTER; \
2434 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2435 VM_CALL_METHOD_JVALUE(_int, int32_t)
2436 VM_CALL_METHOD_JVALUE(_long, int64_t)
2437 VM_CALL_METHOD_JVALUE(_float, float)
2438 VM_CALL_METHOD_JVALUE(_double, double)
2441 /* vm_call_method_objectarray **************************************************
2443 Calls a Java method with a variable number if arguments, passed via
2444 an objectarray of boxed values. Returns a boxed value.
2446 *******************************************************************************/
2448 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2449 java_handle_objectarray_t *params)
2452 java_handle_t *xptr;
2456 /* Prevent compiler warnings. */
2460 /* compile methods which are not yet compiled */
2462 if (m->code == NULL)
2463 if (!jit_compile(m))
2466 /* leave the nativeworld */
2468 THREAD_NATIVEWORLD_EXIT;
2470 // Create new dump memory area.
2473 /* Fill the argument array from a object-array. */
2475 array = argument_vmarray_from_objectarray(m, o, params);
2477 if (array == NULL) {
2478 /* enter the nativeworld again */
2480 THREAD_NATIVEWORLD_ENTER;
2482 exceptions_throw_illegalargumentexception();
2487 switch (m->parseddesc->returntype.primitivetype) {
2488 case PRIMITIVETYPE_VOID:
2489 value.a = vm_call_array(m, array);
2492 case PRIMITIVETYPE_BOOLEAN:
2493 case PRIMITIVETYPE_BYTE:
2494 case PRIMITIVETYPE_CHAR:
2495 case PRIMITIVETYPE_SHORT:
2496 case PRIMITIVETYPE_INT:
2497 value.i = vm_call_int_array(m, array);
2500 case PRIMITIVETYPE_LONG:
2501 value.l = vm_call_long_array(m, array);
2504 case PRIMITIVETYPE_FLOAT:
2505 value.f = vm_call_float_array(m, array);
2508 case PRIMITIVETYPE_DOUBLE:
2509 value.d = vm_call_double_array(m, array);
2513 ro = vm_call_array(m, array);
2517 os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2520 /* enter the nativeworld again */
2522 THREAD_NATIVEWORLD_ENTER;
2524 /* box the return value if necesarry */
2526 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2527 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2529 /* check for an exception */
2531 xptr = exceptions_get_exception();
2534 /* clear exception pointer, we are calling JIT code again */
2536 exceptions_clear_exception();
2538 exceptions_throw_invocationtargetexception(xptr);
2545 /* Legacy C interface *********************************************************/
2549 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2550 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2551 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2552 bool VM_is_created() { return VM::get_current()->is_created(); }
2553 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2555 void vm_abort(const char* text, ...)
2560 os::abort(text, ap);
2564 void vm_abort_errnum(int errnum, const char* text, ...)
2569 os::abort_errnum(errnum, text, ap);
2573 void vm_abort_errno(const char* text, ...)
2578 os::abort_errno(text, ap);
2586 * These are local overrides for various environment variables in Emacs.
2587 * Please do not remove this and leave it at the end of the file, where
2588 * Emacs will automagically detect them.
2589 * ---------------------------------------------------------------------
2592 * indent-tabs-mode: t
2596 * vim:noexpandtab:sw=4:ts=4: