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.hpp"
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.hpp"
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.hpp"
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 #include "vm/jit/optimizing/profile.hpp"
95 #include "vm/jit/optimizing/recompiler.hpp"
97 #if defined(ENABLE_PYTHON)
98 # include "vm/jit/python.h"
101 #include "vm/jit/trap.hpp"
103 #if defined(ENABLE_JVMTI)
104 # include "native/jvmti/cacaodbg.h"
107 #if defined(ENABLE_VMLOG)
108 #include <vmlog_cacao.h>
113 * This is _the_ VM instance.
118 /* global variables ***********************************************************/
120 s4 vms = 0; /* number of VMs created */
122 static classinfo *mainclass = NULL;
124 #if defined(ENABLE_INTRP)
125 u1 *intrp_main_stack = NULL;
129 /* define heap sizes **********************************************************/
131 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
132 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
133 #define STACK_SIZE 128 * 1024 /* default 64kB */
136 /* define command line options ************************************************/
170 /* Java non-standard options */
181 #if defined(ENABLE_PROFILING)
195 #if defined(ENABLE_STATISTICS)
206 #if defined(ENABLE_VERIFIER)
210 #if defined(TYPECHECK_VERBOSE)
213 #endif /* defined(ENABLE_VERIFIER) */
215 /* optimization options */
217 #if defined(ENABLE_LOOP)
221 #if defined(ENABLE_IFCONV)
225 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
229 #if defined(ENABLE_INTRP)
230 /* interpreter options */
249 #if defined(ENABLE_DEBUG_FILTER)
250 OPT_FILTER_VERBOSECALL_INCLUDE,
251 OPT_FILTER_VERBOSECALL_EXCLUDE,
252 OPT_FILTER_SHOW_METHOD,
259 opt_struct opts[] = {
260 { "foo", false, OPT_FOO },
264 { "jar", false, OPT_JAR },
266 { "d32", false, OPT_D32 },
267 { "d64", false, OPT_D64 },
268 { "client", false, OPT_IGNORE },
269 { "server", false, OPT_IGNORE },
270 { "jvm", false, OPT_IGNORE },
271 { "hotspot", false, OPT_IGNORE },
273 { "classpath", true, OPT_CLASSPATH },
274 { "cp", true, OPT_CLASSPATH },
275 { "D", true, OPT_D },
276 { "version", false, OPT_VERSION },
277 { "showversion", false, OPT_SHOWVERSION },
278 { "fullversion", false, OPT_FULLVERSION },
279 { "help", false, OPT_HELP },
280 { "?", false, OPT_HELP },
281 { "X", false, OPT_X },
282 { "XX:", true, OPT_XX },
284 { "ea:", true, OPT_EA },
285 { "da:", true, OPT_DA },
286 { "ea", false, OPT_EA_NOARG },
287 { "da", false, OPT_DA_NOARG },
289 { "enableassertions:", true, OPT_EA },
290 { "disableassertions:", true, OPT_DA },
291 { "enableassertions", false, OPT_EA_NOARG },
292 { "disableassertions", false, OPT_DA_NOARG },
294 { "esa", false, OPT_ESA },
295 { "enablesystemassertions", false, OPT_ESA },
296 { "dsa", false, OPT_DSA },
297 { "disablesystemassertions", false, OPT_DSA },
299 { "noasyncgc", false, OPT_IGNORE },
300 #if defined(ENABLE_VERIFIER)
301 { "noverify", false, OPT_NOVERIFY },
302 { "Xverify:all", false, OPT_XVERIFY_ALL },
303 { "Xverify:none", false, OPT_XVERIFY_NONE },
305 { "v", false, OPT_VERBOSE1 },
306 { "verbose:", true, OPT_VERBOSE },
308 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
309 { "verbosetc", false, OPT_VERBOSETC },
311 #if defined(ENABLE_STATISTICS)
312 { "time", false, OPT_TIME },
313 { "stat", false, OPT_STAT },
315 { "log", true, OPT_LOG },
316 { "c", true, OPT_CHECK },
317 { "l", false, OPT_LOAD },
319 #if defined(ENABLE_LOOP)
320 { "oloop", false, OPT_OLOOP },
322 #if defined(ENABLE_IFCONV)
323 { "ifconv", false, OPT_IFCONV },
325 #if defined(ENABLE_LSRA)
326 { "lsra", false, OPT_LSRA },
328 #if defined(ENABLE_SSA)
329 { "lsra", true, OPT_LSRA },
332 #if defined(ENABLE_INTRP)
333 /* interpreter options */
335 { "trace", false, OPT_TRACE },
336 { "static-supers", true, OPT_STATIC_SUPERS },
337 { "no-dynamic", false, OPT_NO_DYNAMIC },
338 { "no-replication", false, OPT_NO_REPLICATION },
339 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
342 /* JVMTI Agent Command Line Options */
344 { "agentlib:", true, OPT_AGENTLIB },
345 { "agentpath:", true, OPT_AGENTPATH },
348 /* Java non-standard options */
350 { "Xjit", false, OPT_JIT },
351 { "Xint", false, OPT_INTRP },
352 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
353 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
354 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
355 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
358 { "Xdebug", false, OPT_DEBUG },
359 { "Xnoagent", false, OPT_NOAGENT },
360 { "Xrunjdwp", true, OPT_XRUNJDWP },
363 { "Xms", true, OPT_MS },
364 { "ms", true, OPT_MS },
365 { "Xmx", true, OPT_MX },
366 { "mx", true, OPT_MX },
367 { "Xss", true, OPT_SS },
368 { "ss", true, OPT_SS },
370 { "Xcheck:jni", false, OPT_XCHECK_JNI },
372 #if defined(ENABLE_PROFILING)
373 { "Xprof:", true, OPT_PROF_OPTION },
374 { "Xprof", false, OPT_PROF },
377 /* keep these at the end of the list */
379 { "s", true, OPT_SHOW },
380 { "debug-color", false, OPT_DEBUGCOLOR },
382 #if defined(ENABLE_DEBUG_FILTER)
383 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
384 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
385 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
392 /* usage ***********************************************************************
394 Prints the correct usage syntax to stdout.
396 *******************************************************************************/
400 puts("Usage: cacao [-options] classname [arguments]");
401 puts(" (to run a class file)");
402 puts(" or cacao [-options] -jar jarfile [arguments]");
403 puts(" (to run a standalone jar file)\n");
405 puts("where options include:");
406 puts(" -d32 use 32-bit data model if available");
407 puts(" -d64 use 64-bit data model if available");
408 puts(" -client compatibility (currently ignored)");
409 puts(" -server compatibility (currently ignored)");
410 puts(" -jvm compatibility (currently ignored)");
411 puts(" -hotspot compatibility (currently ignored)\n");
413 puts(" -cp <path> specify a path to look for classes");
414 puts(" -classpath <path> specify a path to look for classes");
415 puts(" -D<name>=<value> add an entry to the property list");
416 puts(" -verbose[:class|gc|jni] enable specific verbose output");
417 puts(" -version print product version and exit");
418 puts(" -fullversion print jpackage-compatible product version and exit");
419 puts(" -showversion print product version and continue");
420 puts(" -help, -? print this help message");
421 puts(" -X print help on non-standard Java options");
422 puts(" -XX print help on debugging options");
423 puts(" -ea[:<packagename>...|:<classname>]");
424 puts(" -enableassertions[:<packagename>...|:<classname>]");
425 puts(" enable assertions with specified granularity");
426 puts(" -da[:<packagename>...|:<classname>]");
427 puts(" -disableassertions[:<packagename>...|:<classname>]");
428 puts(" disable assertions with specified granularity");
429 puts(" -esa | -enablesystemassertions");
430 puts(" enable system assertions");
431 puts(" -dsa | -disablesystemassertions");
432 puts(" disable system assertions");
435 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
436 puts (" for jdwp help use: -agentlib:jdwp=help");
437 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
440 /* exit with error code */
446 static void Xusage(void)
448 #if defined(ENABLE_JIT)
449 puts(" -Xjit JIT mode execution (default)");
451 #if defined(ENABLE_INTRP)
452 puts(" -Xint interpreter mode execution");
454 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
455 puts(" value is set as bootstrap class path");
456 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
457 puts(" value is appended to the bootstrap class path");
458 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
459 puts(" value is prepended to the bootstrap class path");
460 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
461 puts(" value is used as Java core library, but the");
462 puts(" hardcoded VM interface classes are prepended");
463 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
464 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
465 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
467 #if defined(ENABLE_PROFILING)
468 puts(" -Xprof[:bb] collect and print profiling data");
471 #if defined(ENABLE_JVMTI)
472 /* -Xdebug option depend on gnu classpath JDWP options. options:
473 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
474 puts(" -Xdebug enable remote debugging\n");
475 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
476 puts(" enable remote debugging\n");
479 /* exit with error code */
486 static void XXusage(void)
488 puts(" -v write state-information");
490 puts(" -verbose:jit enable specific verbose output");
491 puts(" -debug-color colored output for ANSI terms");
493 #ifdef TYPECHECK_VERBOSE
494 puts(" -verbosetc write debug messages while typechecking");
496 #if defined(ENABLE_VERIFIER)
497 puts(" -noverify don't verify classfiles");
499 #if defined(ENABLE_STATISTICS)
500 puts(" -time measure the runtime");
501 puts(" -stat detailed compiler statistics");
503 puts(" -log logfile specify a name for the logfile");
504 puts(" -c(heck)b(ounds) don't check array bounds");
505 puts(" s(ync) don't check for synchronization");
506 #if defined(ENABLE_LOOP)
507 puts(" -oloop optimize array accesses in loops");
509 puts(" -l don't start the class after loading");
511 puts(" -s... show...");
512 puts(" (c)onstants the constant pool");
513 puts(" (m)ethods class fields and methods");
514 puts(" (u)tf the utf - hash");
515 puts(" (i)ntermediate intermediate representation");
516 #if defined(ENABLE_DISASSEMBLER)
517 puts(" (a)ssembler disassembled listing");
518 puts(" n(o)ps show NOPs in disassembler output");
520 puts(" (d)atasegment data segment listing");
522 #if defined(ENABLE_IFCONV)
523 puts(" -ifconv use if-conversion");
525 #if defined(ENABLE_LSRA)
526 puts(" -lsra use linear scan register allocation");
528 #if defined(ENABLE_SSA)
529 puts(" -lsra:... use linear scan register allocation (with SSA)");
530 puts(" (d)ead code elimination");
531 puts(" (c)opy propagation");
533 #if defined(ENABLE_DEBUG_FILTER)
534 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
535 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
536 puts(" -XXfm <regex> filter for show options");
538 /* exit with error code */
545 /* version *********************************************************************
547 Only prints cacao version information.
549 *******************************************************************************/
551 static void version(bool opt_exit)
553 puts("java version \""JAVA_VERSION"\"");
554 puts("CACAO version "VERSION"\n");
556 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
557 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
558 puts("This is free software; see the source for copying conditions. There is NO");
559 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
561 /* exit normally, if requested */
568 /* fullversion *****************************************************************
570 Prints a Sun compatible version information (required e.g. by
571 jpackage, www.jpackage.org).
573 *******************************************************************************/
575 static void fullversion(void)
577 puts("java full version \"cacao-"JAVA_VERSION"\"");
585 /* forward declarations *******************************************************/
587 static char *vm_get_mainclass_from_jar(char *mainstring);
589 static void vm_compile_all(void);
590 static void vm_compile_method(char* mainname);
595 * Implementation for JNI_CreateJavaVM. This function creates a VM
602 * @return true on success, false otherwise.
604 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
606 JavaVMInitArgs* _vm_args;
608 // Get the arguments for the new JVM.
609 _vm_args = (JavaVMInitArgs *) vm_args;
611 // Instantiate a new VM.
613 _vm = new VM(_vm_args);
615 catch (std::exception e) {
616 // FIXME How can we delete the resources allocated?
617 // /* release allocated memory */
618 // FREE(env, _Jv_JNIEnv);
619 // FREE(vm, _Jv_JavaVM);
626 // Return the values.
628 *p_vm = _vm->get_javavm();
629 *p_env = _vm->get_jnienv();
636 * C wrapper for VM::create.
639 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
641 return VM::create(p_vm, p_env, vm_args);
649 VM::VM(JavaVMInitArgs* vm_args)
651 // Very first thing to do: we are initializing.
652 _initializing = true;
654 // Make ourself globally visible.
655 // XXX Is this a good idea?
658 /* create and fill a JavaVM structure */
660 _javavm = new JavaVM();
662 #if defined(ENABLE_JNI)
663 _javavm->functions = &_Jv_JNIInvokeInterface;
666 /* get the VM and Env tables (must be set before vm_create) */
667 /* XXX JVMTI Agents needs a JavaVM */
669 _jnienv = new JNIEnv();
671 #if defined(ENABLE_JNI)
672 _jnienv->functions = &_Jv_JNINativeInterface;
675 /* actually create the JVM */
679 char *boot_class_path;
685 #if defined(ENABLE_JVMTI)
687 char *libname, *agentarg;
688 bool jdwp,agentbypath;
689 jdwp = agentbypath = false;
692 #if defined(ENABLE_JNI)
693 /* Check the JNI version requested. */
695 if (!jni_version_check(vm_args->version))
696 throw std::exception();
699 /* We only support 1 JVM instance. */
702 throw std::exception();
704 /* Install the exit handler. */
706 if (atexit(vm_exit_handler))
707 os::abort("atexit failed: %s\n", strerror(errno));
709 /* Set some options. */
714 opt_heapmaxsize = HEAP_MAXSIZE;
715 opt_heapstartsize = HEAP_STARTSIZE;
716 opt_stacksize = STACK_SIZE;
718 // First of all, parse the -XX options.
720 #if defined(ENABLE_VMLOG)
721 vmlog_cacao_init_options();
726 // After -XX options are parsed, print the build-time
727 // configuration, if requested.
729 print_build_time_config();
731 #if defined(ENABLE_VMLOG)
735 /* We need to check if the actual size of a java.lang.Class object
736 is smaller or equal than the assumption made in
739 #warning FIXME We need to check the size of java.lang.Class!!!
740 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
741 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
743 /* set the VM starttime */
745 _starttime = builtin_currenttimemillis();
747 #if defined(ENABLE_JVMTI)
748 /* initialize JVMTI related **********************************************/
752 /* iterate over all passed options */
754 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
768 #if SIZEOF_VOID_P == 8
769 puts("Running a 32-bit JVM is not supported on this platform.");
775 #if SIZEOF_VOID_P == 4
776 puts("Running a 64-bit JVM is not supported on this platform.");
782 /* Forget old classpath and set the argument as new
785 // FIXME Make class_path const char*.
786 class_path = (char*) _properties.get("java.class.path");
788 p = MNEW(char, strlen(opt_arg) + strlen("0"));
792 #if defined(ENABLE_JAVASE)
793 _properties.put("java.class.path", p);
796 MFREE(class_path, char, strlen(class_path));
800 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
801 if (opt_arg[i] == '=') {
803 _properties.put(opt_arg, opt_arg + i + 1);
808 /* if no '=' is given, just create an empty property */
810 _properties.put(opt_arg, "");
815 case OPT_BOOTCLASSPATH:
816 /* Forget default bootclasspath and set the argument as
817 new boot classpath. */
819 // FIXME Make boot_class_path const char*.
820 boot_class_path = (char*) _properties.get("sun.boot.class.path");
822 p = MNEW(char, strlen(opt_arg) + strlen("0"));
826 _properties.put("sun.boot.class.path", p);
827 _properties.put("java.boot.class.path", p);
829 MFREE(boot_class_path, char, strlen(boot_class_path));
832 case OPT_BOOTCLASSPATH_A:
833 /* Append to bootclasspath. */
835 // FIXME Make boot_class_path const char*.
836 boot_class_path = (char*) _properties.get("sun.boot.class.path");
838 len = strlen(boot_class_path);
840 // XXX (char*) quick hack
841 p = (char*) MREALLOC(boot_class_path,
845 strlen(opt_arg) + strlen("0"));
850 _properties.put("sun.boot.class.path", p);
851 _properties.put("java.boot.class.path", p);
854 case OPT_BOOTCLASSPATH_P:
855 /* Prepend to bootclasspath. */
857 // FIXME Make boot_class_path const char*.
858 boot_class_path = (char*) _properties.get("sun.boot.class.path");
860 len = strlen(boot_class_path);
862 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
866 strcat(p, boot_class_path);
868 _properties.put("sun.boot.class.path", p);
869 _properties.put("java.boot.class.path", p);
871 MFREE(boot_class_path, char, len);
874 case OPT_BOOTCLASSPATH_C:
875 /* Use as Java core library, but prepend VM interface
878 // FIXME Make boot_class_path const char*.
879 boot_class_path = (char*) _properties.get("sun.boot.class.path");
882 strlen(CACAO_VM_ZIP) +
889 strcpy(p, CACAO_VM_ZIP);
893 _properties.put("sun.boot.class.path", p);
894 _properties.put("java.boot.class.path", p);
896 MFREE(boot_class_path, char, strlen(boot_class_path));
899 #if defined(ENABLE_JVMTI)
901 /* this option exists only for compatibility reasons */
905 /* I don't know yet what Xnoagent should do. This is only for
906 compatiblity with eclipse - motse */
915 strlen(CACAO_LIBDIR) +
916 strlen("/libjdwp.so=") +
920 agentarg = MNEW(char, len);
922 strcpy(agentarg, CACAO_LIBDIR);
923 strcat(agentarg, "/libjdwp.so=");
924 strcat(agentarg, &opt_arg[1]);
943 c = opt_arg[strlen(opt_arg) - 1];
945 if ((c == 'k') || (c == 'K')) {
946 j = atoi(opt_arg) * 1024;
948 } else if ((c == 'm') || (c == 'M')) {
949 j = atoi(opt_arg) * 1024 * 1024;
956 else if (opt == OPT_MS)
957 opt_heapstartsize = j;
964 // HotSpot compatibility option.
972 if (strcmp("class", opt_arg) == 0) {
973 opt_verboseclass = true;
975 else if (strcmp("gc", opt_arg) == 0) {
976 opt_verbosegc = true;
978 else if (strcmp("jni", opt_arg) == 0) {
979 opt_verbosejni = true;
982 else if (strcmp("jit", opt_arg) == 0) {
986 compileverbose = true;
990 printf("Unknown -verbose option: %s\n", opt_arg);
996 opt_debugcolor = true;
999 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1001 opt_typecheckverbose = true;
1010 case OPT_FULLVERSION:
1014 case OPT_SHOWVERSION:
1018 #if defined(ENABLE_VERIFIER)
1019 case OPT_XVERIFY_ALL:
1024 case OPT_XVERIFY_NONE:
1029 #if defined(ENABLE_STATISTICS)
1031 opt_getcompilingtime = true;
1032 opt_getloadingtime = true;
1045 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1046 switch (opt_arg[i]) {
1048 checkbounds = false;
1061 makeinitializations = false;
1064 case OPT_SHOW: /* Display options */
1065 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1066 switch (opt_arg[i]) {
1068 showconstantpool = true;
1080 opt_showintermediate = true;
1081 compileverbose = true;
1084 #if defined(ENABLE_DISASSEMBLER)
1086 opt_showdisassemble = true;
1087 compileverbose = true;
1092 opt_showddatasegment = true;
1101 #if defined(ENABLE_LOOP)
1107 #if defined(ENABLE_IFCONV)
1113 #if defined(ENABLE_LSRA)
1118 #if defined(ENABLE_SSA)
1121 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1122 switch (opt_arg[i]) {
1150 /* Already parsed. */
1154 #if defined(ENABLE_ASSERTION)
1155 assertion_ea_da(opt_arg, true);
1160 #if defined(ENABLE_ASSERTION)
1161 assertion_ea_da(opt_arg, false);
1166 #if defined(ENABLE_ASSERTION)
1167 assertion_user_enabled = true;
1172 #if defined(ENABLE_ASSERTION)
1173 assertion_user_enabled = false;
1178 #if defined(ENABLE_ASSERTION)
1179 assertion_system_enabled = true;
1184 #if defined(ENABLE_ASSERTION)
1185 assertion_system_enabled = false;
1189 #if defined(ENABLE_PROFILING)
1190 case OPT_PROF_OPTION:
1191 /* use <= to get the last \0 too */
1193 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1194 if (opt_arg[i] == ',')
1197 if (opt_arg[i] == '\0') {
1198 if (strcmp("bb", opt_arg + j) == 0)
1202 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1206 /* set k to next char */
1219 #if defined(ENABLE_JIT)
1222 printf("-Xjit option not enabled.\n");
1228 #if defined(ENABLE_INTRP)
1231 printf("-Xint option not enabled.\n");
1236 #if defined(ENABLE_INTRP)
1237 case OPT_STATIC_SUPERS:
1238 opt_static_supers = atoi(opt_arg);
1241 case OPT_NO_DYNAMIC:
1242 opt_no_dynamic = true;
1245 case OPT_NO_REPLICATION:
1246 opt_no_replication = true;
1249 case OPT_NO_QUICKSUPER:
1250 opt_no_quicksuper = true;
1258 #if defined(ENABLE_DEBUG_FILTER)
1259 case OPT_FILTER_VERBOSECALL_INCLUDE:
1260 opt_filter_verbosecall_include = opt_arg;
1263 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1264 opt_filter_verbosecall_exclude = opt_arg;
1267 case OPT_FILTER_SHOW_METHOD:
1268 opt_filter_show_method = opt_arg;
1273 printf("Unknown option: %s\n",
1274 vm_args->options[opt_index].optionString);
1279 // Print the preliminary run-time VM configuration after options
1281 if (opt_PrintConfig)
1282 print_run_time_config();
1284 #if defined(ENABLE_JVMTI)
1286 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1287 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1290 MFREE(agentarg, char, strlen(agentarg));
1292 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1296 /* initialize the garbage collector */
1298 gc_init(opt_heapmaxsize, opt_heapstartsize);
1300 #if defined(ENABLE_THREADS)
1301 /* AFTER: gc_init */
1307 /* install architecture dependent signal handlers */
1310 os::abort("vm_create: signal_init failed");
1312 #if defined(ENABLE_INTRP)
1313 /* Allocate main thread stack on the Java heap. */
1316 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1317 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1321 /* AFTER: threads_preinit */
1324 os::abort("vm_create: string_init failed");
1326 /* AFTER: threads_preinit */
1330 /* AFTER: thread_preinit */
1332 _suckclasspath.add_from_property("java.endorsed.dirs");
1334 /* Now we have all options handled and we can print the version
1337 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1342 /* AFTER: utf8_init */
1344 // FIXME Make boot_class_path const char*.
1345 boot_class_path = (char*) _properties.get("sun.boot.class.path");
1346 _suckclasspath.add(boot_class_path);
1348 /* initialize the classcache hashtable stuff: lock, hashtable
1349 (must be done _after_ threads_preinit) */
1351 if (!classcache_init())
1352 os::abort("vm_create: classcache_init failed");
1354 /* Initialize the code memory management. */
1355 /* AFTER: threads_preinit */
1359 /* initialize the finalizer stuff (must be done _after_
1362 if (!finalizer_init())
1363 os::abort("vm_create: finalizer_init failed");
1365 /* Initialize the JIT compiler. */
1371 #if defined(ENABLE_PYTHON)
1375 /* AFTER: utf8_init, classcache_init */
1380 // AFTER: loader_preinit, linker_preinit
1381 Primitive::initialize_table();
1386 // AFTER: loader_init, linker_init
1387 Primitive::post_initialize_table();
1390 #if defined(ENABLE_JIT)
1394 if (!builtin_init())
1395 os::abort("vm_create: builtin_init failed");
1397 /* Register the native methods implemented in the VM. */
1398 /* BEFORE: threads_init */
1402 #if defined(ENABLE_JNI)
1403 /* Initialize the JNI subsystem (must be done _before_
1404 threads_init, as threads_init can call JNI methods
1405 (e.g. NewGlobalRef). */
1408 os::abort("vm_create: jni_init failed");
1411 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1412 /* Initialize the local reference table for the main thread. */
1413 /* BEFORE: threads_init */
1415 if (!localref_table_init())
1416 os::abort("vm_create: localref_table_init failed");
1419 /* Iinitialize some important system classes. */
1420 /* BEFORE: threads_init */
1424 #if defined(ENABLE_THREADS)
1428 /* Initialize the native VM subsystem. */
1429 /* AFTER: threads_init (at least for SUN's classes) */
1431 if (!nativevm_init())
1432 os::abort("vm_create: nativevm_init failed");
1434 #if defined(ENABLE_PROFILING)
1435 /* initialize profiling */
1437 if (!profile_init())
1438 os::abort("vm_create: profile_init failed");
1441 #if defined(ENABLE_THREADS)
1442 /* start the signal handler thread */
1444 #if defined(__LINUX__)
1445 /* XXX Remove for exact-GC. */
1446 if (threads_pthreads_implementation_nptl)
1448 if (!signal_start_thread())
1449 os::abort("vm_create: signal_start_thread failed");
1451 /* finally, start the finalizer thread */
1453 if (!finalizer_start_thread())
1454 os::abort("vm_create: finalizer_start_thread failed");
1456 # if !defined(NDEBUG)
1457 /* start the memory profiling thread */
1459 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1460 if (!memory_start_thread())
1461 os::abort("vm_create: memory_start_thread failed");
1464 // Start the recompilation thread (must be done before the
1465 // profiling thread).
1466 // FIXME Only works for one recompiler.
1467 _recompiler.start();
1469 # if defined(ENABLE_PROFILING)
1470 /* start the profile sampling thread */
1473 /* if (!profile_start_thread()) */
1474 /* os::abort("vm_create: profile_start_thread failed"); */
1478 #if defined(ENABLE_JVMTI)
1479 # if defined(ENABLE_GC_CACAO)
1480 /* XXX this will not work with the new indirection cells for classloaders!!! */
1484 /* add agent library to native library hashtable */
1485 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1489 /* Increment the number of VMs. */
1493 // Initialization is done, VM is created.
1495 _initializing = false;
1497 // Print the run-time VM configuration after all stuff is set and
1498 // the VM is initialized.
1499 if (opt_PrintConfig)
1500 print_run_time_config();
1505 * Print build-time (default) VM configuration.
1507 void VM::print_build_time_config(void)
1509 puts("CACAO "VERSION" configure/build options:");
1511 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1512 #if defined(__VERSION__)
1513 puts(" CC : "VERSION_CC" ("__VERSION__")");
1514 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1516 puts(" CC : "VERSION_CC"");
1517 puts(" CXX : "VERSION_CXX"");
1519 puts(" CFLAGS : "VERSION_CFLAGS"");
1520 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1524 puts("Build-time (default) variables:\n");
1525 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1526 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1527 printf(" stack size : %d\n", STACK_SIZE);
1529 #if defined(ENABLE_JRE_LAYOUT)
1530 // When we're building with JRE-layout, the default paths are the
1531 // same as the runtime paths.
1533 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1534 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1535 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1536 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1537 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1538 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1547 * Print run-time VM configuration.
1549 void VM::print_run_time_config()
1551 puts("Run-time variables:\n");
1552 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1553 printf(" initial heap size : %d\n", opt_heapstartsize);
1554 printf(" stack size : %d\n", opt_stacksize);
1556 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1557 printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1558 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1559 printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1562 printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1563 printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1569 /* vm_run **********************************************************************
1571 Runs the main-method of the passed class.
1573 *******************************************************************************/
1575 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1580 #if !defined(NDEBUG)
1581 if (opt_CompileAll) {
1587 /* Get the main class or jar file argument. */
1589 char* mainname = NULL;
1591 if (opt_index < vm_args->nOptions) {
1592 /* Get main-class argument. */
1594 mainname = vm_args->options[opt_index].optionString;
1596 /* If the main class argument is a jar file, put it into the
1599 if (opt_jar == true) {
1600 char* p = MNEW(char, strlen(mainname) + strlen("0"));
1602 strcpy(p, mainname);
1604 #if defined(ENABLE_JAVASE)
1605 VM::get_current()->get_properties().put("java.class.path", p);
1609 /* Replace dots with slashes in the class name. */
1611 for (unsigned int i = 0; i < strlen(mainname); i++)
1612 if (mainname[i] == '.')
1616 /* Move index to first argument. */
1621 /* Do we have a main-class argument? */
1623 if (mainname == NULL)
1626 #if !defined(NDEBUG)
1627 if (opt_CompileMethod != NULL) {
1628 vm_compile_method(mainname);
1633 /* Build argument array. */
1635 int32_t oalength = vm_args->nOptions - opt_index;
1637 ObjectArray oa(oalength, class_java_lang_String);
1642 for (int i = 0; i < oalength; i++) {
1643 char* option = vm_args->options[opt_index + i].optionString;
1645 utf* u = utf_new_char(option);
1646 java_handle_t* s = javastring_new(u);
1648 oa.set_element(i, s);
1651 /* set return value to OK */
1655 if (opt_jar == true) {
1656 /* open jar file with java.util.jar.JarFile */
1658 mainname = vm_get_mainclass_from_jar(mainname);
1660 if (mainname == NULL)
1664 /* load the main class */
1666 utf* mainutf = utf_new_char(mainname);
1668 #if defined(ENABLE_JAVAME_CLDC1_1)
1669 classinfo* mainclass = load_class_bootstrap(mainutf);
1671 classinfo* mainclass = load_class_from_sysloader(mainutf);
1674 /* error loading class */
1676 java_handle_t* e = exceptions_get_and_clear_exception();
1678 if ((e != NULL) || (mainclass == NULL)) {
1679 exceptions_throw_noclassdeffounderror_cause(e);
1680 exceptions_print_stacktrace();
1684 if (!link_class(mainclass)) {
1685 exceptions_print_stacktrace();
1689 /* find the `main' method of the main class */
1691 m = class_resolveclassmethod(mainclass,
1692 utf_new_char("main"),
1693 utf_new_char("([Ljava/lang/String;)V"),
1694 class_java_lang_Object,
1697 if (exceptions_get_exception()) {
1698 exceptions_print_stacktrace();
1702 /* there is no main method or it isn't static */
1704 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1705 exceptions_clear_exception();
1706 exceptions_throw_nosuchmethoderror(mainclass,
1707 utf_new_char("main"),
1708 utf_new_char("([Ljava/lang/String;)V"));
1710 exceptions_print_stacktrace();
1714 #ifdef TYPEINFO_DEBUG_TEST
1715 /* test the typeinfo system */
1719 #if defined(ENABLE_JVMTI)
1720 jvmti_set_phase(JVMTI_PHASE_LIVE);
1723 /* set ThreadMXBean variables */
1725 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1726 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1728 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1729 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1730 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1731 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1732 #warning Move to C++
1734 /* start the main thread */
1736 (void) vm_call_method(m, NULL, oa.get_handle());
1738 /* exception occurred? */
1740 if (exceptions_get_exception()) {
1741 exceptions_print_stacktrace();
1745 #if defined(ENABLE_THREADS)
1746 /* Detach the main thread so that it appears to have ended when
1747 the application's main method exits. */
1749 if (!thread_detach_current_thread())
1750 os::abort("vm_run: Could not detach main thread.");
1753 /* Destroy the JavaVM. */
1755 (void) vm_destroy(vm);
1763 /* vm_destroy ******************************************************************
1765 Unloads a Java VM and reclaims its resources.
1767 *******************************************************************************/
1769 int vm_destroy(JavaVM *vm)
1771 #if defined(ENABLE_THREADS)
1772 /* Create a a trivial new Java waiter thread called
1775 JavaVMAttachArgs args;
1777 args.name = (char*) "DestroyJavaVM";
1780 if (!thread_attach_current_thread(&args, false))
1783 /* Wait until we are the last non-daemon thread. */
1785 threads_join_all_threads();
1790 // _created = false;
1791 #warning Move to C++
1793 /* Everything is ok. */
1799 /* vm_exit *********************************************************************
1801 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1803 *******************************************************************************/
1805 void vm_exit(s4 status)
1809 /* signal that we are exiting */
1812 #warning Move to C++
1814 assert(class_java_lang_System);
1815 assert(class_java_lang_System->state & CLASS_LOADED);
1817 #if defined(ENABLE_JVMTI)
1818 if (jvmti || (dbgcom!=NULL)) {
1819 jvmti_set_phase(JVMTI_PHASE_DEAD);
1820 if (jvmti) jvmti_agentunload();
1824 if (!link_class(class_java_lang_System)) {
1825 exceptions_print_stacktrace();
1829 /* call java.lang.System.exit(I)V */
1831 m = class_resolveclassmethod(class_java_lang_System,
1832 utf_new_char("exit"),
1834 class_java_lang_Object,
1838 exceptions_print_stacktrace();
1842 /* call the exit function with passed exit status */
1844 (void) vm_call_method(m, NULL, status);
1846 /* If we had an exception, just ignore the exception and exit with
1849 vm_shutdown(status);
1853 /* vm_shutdown *****************************************************************
1855 Terminates the system immediately without freeing memory explicitly
1856 (to be used only for abnormal termination).
1858 *******************************************************************************/
1860 void vm_shutdown(s4 status)
1863 #if defined(ENABLE_STATISTICS)
1864 || opt_getcompilingtime || opt_stat
1868 log_text("CACAO terminated by shutdown");
1869 dolog("Exit status: %d\n", (s4) status);
1873 #if defined(ENABLE_JVMTI)
1874 /* terminate cacaodbgserver */
1876 mutex_lock(&dbgcomlock);
1878 mutex_unlock(&dbgcomlock);
1879 jvmti_cacaodbgserver_quit();
1887 /* vm_exit_handler *************************************************************
1889 The exit_handler function is called upon program termination.
1891 ATTENTION: Don't free system resources here! Some threads may still
1892 be running as this is called from VMRuntime.exit(). The OS does the
1895 *******************************************************************************/
1897 void vm_exit_handler(void)
1899 #if !defined(NDEBUG)
1901 class_showmethods(mainclass);
1903 if (showconstantpool)
1904 class_showconstantpool(mainclass);
1909 # if defined(ENABLE_PROFILING)
1911 profile_printstats();
1913 #endif /* !defined(NDEBUG) */
1915 #if defined(ENABLE_RT_TIMING)
1916 rt_timing_print_time_stats(stderr);
1919 #if defined(ENABLE_CYCLES_STATS)
1920 builtin_print_cycles_stats(stderr);
1921 stacktrace_print_cycles_stats(stderr);
1925 #if defined(ENABLE_STATISTICS)
1926 || opt_getcompilingtime || opt_stat
1930 log_text("CACAO terminated");
1932 #if defined(ENABLE_STATISTICS)
1935 #ifdef TYPECHECK_STATISTICS
1936 typecheck_print_statistics(get_logfile());
1940 if (opt_getcompilingtime)
1942 #endif /* defined(ENABLE_STATISTICS) */
1944 /* vm_print_profile(stderr);*/
1948 /* vm_abort_disassemble ********************************************************
1950 Prints an error message, disassemble the given code range (if
1951 enabled) and aborts the VM.
1954 pc.......PC to disassemble
1955 count....number of instructions to disassemble
1957 *******************************************************************************/
1959 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
1962 #if defined(ENABLE_DISASSEMBLER)
1966 /* Print debug message. */
1971 log_vprint(text, ap);
1978 #if SIZEOF_VOID_P == 8
1979 log_println("PC=0x%016lx", pc);
1981 log_println("PC=0x%08x", pc);
1984 #if defined(ENABLE_DISASSEMBLER)
1985 log_println("machine instructions at PC:");
1987 /* Disassemble the given number of instructions. */
1989 for (i = 0; i < count; i++)
1990 // FIXME disassinstr should use void*.
1991 pc = disassinstr((u1*) pc);
1994 os::abort("Aborting...");
1998 /* vm_get_mainclass_from_jar ***************************************************
2000 Gets the name of the main class from a JAR's manifest file.
2002 *******************************************************************************/
2004 static char *vm_get_mainclass_from_jar(char *mainname)
2011 #if defined(ENABLE_JAVAME_CLDC1_1)
2012 c = load_class_bootstrap(utf_new_char("java/util/jar/JarFile"));
2014 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2018 exceptions_print_stacktrace();
2022 /* create JarFile object */
2027 exceptions_print_stacktrace();
2031 m = class_resolveclassmethod(c,
2033 utf_java_lang_String__void,
2034 class_java_lang_Object,
2038 exceptions_print_stacktrace();
2042 s = javastring_new_from_ascii(mainname);
2044 (void) vm_call_method(m, o, s);
2046 if (exceptions_get_exception()) {
2047 exceptions_print_stacktrace();
2051 /* get manifest object */
2053 m = class_resolveclassmethod(c,
2054 utf_new_char("getManifest"),
2055 utf_new_char("()Ljava/util/jar/Manifest;"),
2056 class_java_lang_Object,
2060 exceptions_print_stacktrace();
2064 o = vm_call_method(m, o);
2067 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2072 /* get Main Attributes */
2074 LLNI_class_get(o, c);
2076 m = class_resolveclassmethod(c,
2077 utf_new_char("getMainAttributes"),
2078 utf_new_char("()Ljava/util/jar/Attributes;"),
2079 class_java_lang_Object,
2083 exceptions_print_stacktrace();
2087 o = vm_call_method(m, o);
2090 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2095 /* get property Main-Class */
2097 LLNI_class_get(o, c);
2099 m = class_resolveclassmethod(c,
2100 utf_new_char("getValue"),
2101 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2102 class_java_lang_Object,
2106 exceptions_print_stacktrace();
2110 s = javastring_new_from_ascii("Main-Class");
2112 o = vm_call_method(m, o, s);
2115 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2116 fprintf(stderr, "%s\n", mainname);
2120 return javastring_tochar(o);
2124 /* vm_compile_all **************************************************************
2126 Compile all methods found in the bootclasspath.
2128 *******************************************************************************/
2130 #if !defined(NDEBUG)
2131 static void vm_compile_all(void)
2136 classcache_name_entry *nmen;
2137 classcache_class_entry *clsen;
2140 /* create all classes found in the bootclasspath */
2141 /* XXX currently only works with zip/jar's */
2143 loader_load_all_classes();
2145 /* link all classes */
2147 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2148 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2150 for (; nmen; nmen = nmen->hashlink) {
2151 /* iterate over all class entries */
2153 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2154 c = clsen->classobj;
2159 if (!(c->state & CLASS_LINKED)) {
2160 if (!link_class(c)) {
2161 fprintf(stderr, "Error linking: ");
2162 utf_fprint_printable_ascii_classname(stderr, c->name);
2163 fprintf(stderr, "\n");
2165 /* print out exception and cause */
2167 exceptions_print_current_exception();
2169 /* goto next class */
2175 /* compile all class methods */
2177 for (i = 0; i < c->methodscount; i++) {
2178 m = &(c->methods[i]);
2180 if (m->jcode != NULL) {
2181 if (!jit_compile(m)) {
2182 fprintf(stderr, "Error compiling: ");
2183 utf_fprint_printable_ascii_classname(stderr, c->name);
2184 fprintf(stderr, ".");
2185 utf_fprint_printable_ascii(stderr, m->name);
2186 utf_fprint_printable_ascii(stderr, m->descriptor);
2187 fprintf(stderr, "\n");
2189 /* print out exception and cause */
2191 exceptions_print_current_exception();
2199 #endif /* !defined(NDEBUG) */
2202 /* vm_compile_method ***********************************************************
2204 Compile a specific method.
2206 *******************************************************************************/
2208 #if !defined(NDEBUG)
2209 static void vm_compile_method(char* mainname)
2213 /* create, load and link the main class */
2215 mainclass = load_class_bootstrap(utf_new_char(mainname));
2217 if (mainclass == NULL)
2218 exceptions_print_stacktrace();
2220 if (!link_class(mainclass))
2221 exceptions_print_stacktrace();
2223 if (opt_CompileSignature != NULL) {
2224 m = class_resolveclassmethod(mainclass,
2225 utf_new_char(opt_CompileMethod),
2226 utf_new_char(opt_CompileSignature),
2231 m = class_resolveclassmethod(mainclass,
2232 utf_new_char(opt_CompileMethod),
2239 os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2240 opt_CompileMethod, opt_CompileSignature ? opt_CompileSignature : "");
2244 #endif /* !defined(NDEBUG) */
2247 /* vm_call_array ***************************************************************
2249 Calls a Java method with a variable number of arguments, passed via
2252 ATTENTION: This function has to be used outside the nativeworld.
2254 *******************************************************************************/
2256 #define VM_CALL_ARRAY(name, type) \
2257 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2263 assert(m->code != NULL); \
2265 md = m->parseddesc; \
2266 pv = m->code->entrypoint; \
2268 STATISTICS(count_calls_native_to_java++); \
2270 value = asm_vm_call_method##name(pv, array, md->memuse); \
2275 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2281 assert(m->code != NULL);
2284 pv = m->code->entrypoint;
2286 STATISTICS(count_calls_native_to_java++);
2288 o = asm_vm_call_method(pv, array, md->memuse);
2290 if (md->returntype.type == TYPE_VOID)
2293 return LLNI_WRAP(o);
2296 VM_CALL_ARRAY(_int, int32_t)
2297 VM_CALL_ARRAY(_long, int64_t)
2298 VM_CALL_ARRAY(_float, float)
2299 VM_CALL_ARRAY(_double, double)
2302 /* vm_call_method **************************************************************
2304 Calls a Java method with a variable number of arguments.
2306 *******************************************************************************/
2308 #define VM_CALL_METHOD(name, type) \
2309 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2315 value = vm_call_method##name##_valist(m, o, ap); \
2321 VM_CALL_METHOD(, java_handle_t *)
2322 VM_CALL_METHOD(_int, int32_t)
2323 VM_CALL_METHOD(_long, int64_t)
2324 VM_CALL_METHOD(_float, float)
2325 VM_CALL_METHOD(_double, double)
2328 /* vm_call_method_valist *******************************************************
2330 Calls a Java method with a variable number of arguments, passed via
2333 *******************************************************************************/
2335 #define VM_CALL_METHOD_VALIST(name, type) \
2336 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2342 if (m->code == NULL) \
2343 if (!jit_compile(m)) \
2346 THREAD_NATIVEWORLD_EXIT; \
2348 DumpMemoryArea dma; \
2350 array = argument_vmarray_from_valist(m, o, ap); \
2351 value = vm_call##name##_array(m, array); \
2353 THREAD_NATIVEWORLD_ENTER; \
2358 VM_CALL_METHOD_VALIST(, java_handle_t *)
2359 VM_CALL_METHOD_VALIST(_int, int32_t)
2360 VM_CALL_METHOD_VALIST(_long, int64_t)
2361 VM_CALL_METHOD_VALIST(_float, float)
2362 VM_CALL_METHOD_VALIST(_double, double)
2365 /* vm_call_method_jvalue *******************************************************
2367 Calls a Java method with a variable number of arguments, passed via
2370 *******************************************************************************/
2372 #define VM_CALL_METHOD_JVALUE(name, type) \
2373 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2374 const jvalue *args) \
2379 if (m->code == NULL) \
2380 if (!jit_compile(m)) \
2383 THREAD_NATIVEWORLD_EXIT; \
2385 DumpMemoryArea dma; \
2387 array = argument_vmarray_from_jvalue(m, o, args); \
2388 value = vm_call##name##_array(m, array); \
2390 THREAD_NATIVEWORLD_ENTER; \
2395 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2396 VM_CALL_METHOD_JVALUE(_int, int32_t)
2397 VM_CALL_METHOD_JVALUE(_long, int64_t)
2398 VM_CALL_METHOD_JVALUE(_float, float)
2399 VM_CALL_METHOD_JVALUE(_double, double)
2402 /* vm_call_method_objectarray **************************************************
2404 Calls a Java method with a variable number if arguments, passed via
2405 an objectarray of boxed values. Returns a boxed value.
2407 *******************************************************************************/
2409 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2410 java_handle_objectarray_t *params)
2413 java_handle_t *xptr;
2417 /* Prevent compiler warnings. */
2421 /* compile methods which are not yet compiled */
2423 if (m->code == NULL)
2424 if (!jit_compile(m))
2427 /* leave the nativeworld */
2429 THREAD_NATIVEWORLD_EXIT;
2431 // Create new dump memory area.
2434 /* Fill the argument array from a object-array. */
2436 array = argument_vmarray_from_objectarray(m, o, params);
2438 if (array == NULL) {
2439 /* enter the nativeworld again */
2441 THREAD_NATIVEWORLD_ENTER;
2443 exceptions_throw_illegalargumentexception();
2448 switch (m->parseddesc->returntype.primitivetype) {
2449 case PRIMITIVETYPE_VOID:
2450 value.a = vm_call_array(m, array);
2453 case PRIMITIVETYPE_BOOLEAN:
2454 case PRIMITIVETYPE_BYTE:
2455 case PRIMITIVETYPE_CHAR:
2456 case PRIMITIVETYPE_SHORT:
2457 case PRIMITIVETYPE_INT:
2458 value.i = vm_call_int_array(m, array);
2461 case PRIMITIVETYPE_LONG:
2462 value.l = vm_call_long_array(m, array);
2465 case PRIMITIVETYPE_FLOAT:
2466 value.f = vm_call_float_array(m, array);
2469 case PRIMITIVETYPE_DOUBLE:
2470 value.d = vm_call_double_array(m, array);
2474 ro = vm_call_array(m, array);
2478 os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2481 /* enter the nativeworld again */
2483 THREAD_NATIVEWORLD_ENTER;
2485 /* box the return value if necesarry */
2487 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2488 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2490 /* check for an exception */
2492 xptr = exceptions_get_exception();
2495 /* clear exception pointer, we are calling JIT code again */
2497 exceptions_clear_exception();
2499 exceptions_throw_invocationtargetexception(xptr);
2506 /* Legacy C interface *********************************************************/
2510 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2511 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2512 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2513 bool VM_is_created() { return VM::get_current()->is_created(); }
2514 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2516 void vm_abort(const char* text, ...)
2520 log_println("vm_abort: WARNING, port me to C++ and use os::abort() instead.");
2522 // Print the log message.
2526 log_vprint(text, ap);
2531 // Print a backtrace.
2532 os::print_backtrace();
2534 // Now abort the VM.
2542 * These are local overrides for various environment variables in Emacs.
2543 * Please do not remove this and leave it at the end of the file, where
2544 * Emacs will automagically detect them.
2545 * ---------------------------------------------------------------------
2548 * indent-tabs-mode: t
2552 * vim:noexpandtab:sw=4:ts=4: