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.h"
68 #include "vm/exceptions.hpp"
69 #include "vm/finalizer.h"
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/jitcache.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)
215 #if defined(TYPECHECK_VERBOSE)
218 #endif /* defined(ENABLE_VERIFIER) */
220 /* optimization options */
222 #if defined(ENABLE_LOOP)
226 #if defined(ENABLE_IFCONV)
230 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
234 #if defined(ENABLE_INTRP)
235 /* interpreter options */
254 #if defined(ENABLE_DEBUG_FILTER)
255 OPT_FILTER_VERBOSECALL_INCLUDE,
256 OPT_FILTER_VERBOSECALL_EXCLUDE,
257 OPT_FILTER_SHOW_METHOD,
264 opt_struct opts[] = {
265 { "foo", false, OPT_FOO },
269 { "jar", false, OPT_JAR },
271 { "d32", false, OPT_D32 },
272 { "d64", false, OPT_D64 },
273 { "client", false, OPT_IGNORE },
274 { "server", false, OPT_IGNORE },
275 { "jvm", false, OPT_IGNORE },
276 { "hotspot", false, OPT_IGNORE },
278 { "classpath", true, OPT_CLASSPATH },
279 { "cp", true, OPT_CLASSPATH },
280 { "D", true, OPT_D },
281 { "version", false, OPT_VERSION },
282 { "showversion", false, OPT_SHOWVERSION },
283 { "fullversion", false, OPT_FULLVERSION },
284 { "help", false, OPT_HELP },
285 { "?", false, OPT_HELP },
286 { "X", false, OPT_X },
287 { "XX:", true, OPT_XX },
289 { "ea:", true, OPT_EA },
290 { "da:", true, OPT_DA },
291 { "ea", false, OPT_EA_NOARG },
292 { "da", false, OPT_DA_NOARG },
294 { "enableassertions:", true, OPT_EA },
295 { "disableassertions:", true, OPT_DA },
296 { "enableassertions", false, OPT_EA_NOARG },
297 { "disableassertions", false, OPT_DA_NOARG },
299 { "esa", false, OPT_ESA },
300 { "enablesystemassertions", false, OPT_ESA },
301 { "dsa", false, OPT_DSA },
302 { "disablesystemassertions", false, OPT_DSA },
304 { "noasyncgc", false, OPT_IGNORE },
305 #if defined(ENABLE_VERIFIER)
306 { "noverify", false, OPT_NOVERIFY },
307 { "Xverify:none", false, OPT_NOVERIFY },
309 { "v", false, OPT_VERBOSE1 },
310 { "verbose:", true, OPT_VERBOSE },
312 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
313 { "verbosetc", false, OPT_VERBOSETC },
315 #if defined(ENABLE_STATISTICS)
316 { "time", false, OPT_TIME },
317 { "stat", false, OPT_STAT },
319 { "log", true, OPT_LOG },
320 { "c", true, OPT_CHECK },
321 { "l", false, OPT_LOAD },
324 { "all", false, OPT_ALL },
325 { "sig", true, OPT_SIGNATURE },
328 #if defined(ENABLE_LOOP)
329 { "oloop", false, OPT_OLOOP },
331 #if defined(ENABLE_IFCONV)
332 { "ifconv", false, OPT_IFCONV },
334 #if defined(ENABLE_LSRA)
335 { "lsra", false, OPT_LSRA },
337 #if defined(ENABLE_SSA)
338 { "lsra", true, OPT_LSRA },
341 #if defined(ENABLE_INTRP)
342 /* interpreter options */
344 { "trace", false, OPT_TRACE },
345 { "static-supers", true, OPT_STATIC_SUPERS },
346 { "no-dynamic", false, OPT_NO_DYNAMIC },
347 { "no-replication", false, OPT_NO_REPLICATION },
348 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
351 /* JVMTI Agent Command Line Options */
353 { "agentlib:", true, OPT_AGENTLIB },
354 { "agentpath:", true, OPT_AGENTPATH },
357 /* Java non-standard options */
359 { "Xjit", false, OPT_JIT },
360 { "Xint", false, OPT_INTRP },
361 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
362 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
363 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
364 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
367 { "Xdebug", false, OPT_DEBUG },
368 { "Xnoagent", false, OPT_NOAGENT },
369 { "Xrunjdwp", true, OPT_XRUNJDWP },
372 { "Xms", true, OPT_MS },
373 { "ms", true, OPT_MS },
374 { "Xmx", true, OPT_MX },
375 { "mx", true, OPT_MX },
376 { "Xss", true, OPT_SS },
377 { "ss", true, OPT_SS },
379 #if defined(ENABLE_PROFILING)
380 { "Xprof:", true, OPT_PROF_OPTION },
381 { "Xprof", false, OPT_PROF },
384 /* keep these at the end of the list */
387 { "m", true, OPT_METHOD },
390 { "s", true, OPT_SHOW },
391 { "debug-color", false, OPT_DEBUGCOLOR },
393 #if defined(ENABLE_DEBUG_FILTER)
394 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
395 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
396 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
403 /* usage ***********************************************************************
405 Prints the correct usage syntax to stdout.
407 *******************************************************************************/
411 puts("Usage: cacao [-options] classname [arguments]");
412 puts(" (to run a class file)");
413 puts(" or cacao [-options] -jar jarfile [arguments]");
414 puts(" (to run a standalone jar file)\n");
416 puts("where options include:");
417 puts(" -d32 use 32-bit data model if available");
418 puts(" -d64 use 64-bit data model if available");
419 puts(" -client compatibility (currently ignored)");
420 puts(" -server compatibility (currently ignored)");
421 puts(" -jvm compatibility (currently ignored)");
422 puts(" -hotspot compatibility (currently ignored)\n");
424 puts(" -cp <path> specify a path to look for classes");
425 puts(" -classpath <path> specify a path to look for classes");
426 puts(" -D<name>=<value> add an entry to the property list");
427 puts(" -verbose[:class|gc|jni] enable specific verbose output");
428 puts(" -version print product version and exit");
429 puts(" -fullversion print jpackage-compatible product version and exit");
430 puts(" -showversion print product version and continue");
431 puts(" -help, -? print this help message");
432 puts(" -X print help on non-standard Java options");
433 puts(" -XX print help on debugging options");
434 puts(" -ea[:<packagename>...|:<classname>]");
435 puts(" -enableassertions[:<packagename>...|:<classname>]");
436 puts(" enable assertions with specified granularity");
437 puts(" -da[:<packagename>...|:<classname>]");
438 puts(" -disableassertions[:<packagename>...|:<classname>]");
439 puts(" disable assertions with specified granularity");
440 puts(" -esa | -enablesystemassertions");
441 puts(" enable system assertions");
442 puts(" -dsa | -disablesystemassertions");
443 puts(" disable system assertions");
446 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
447 puts (" for jdwp help use: -agentlib:jdwp=help");
448 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
451 /* exit with error code */
457 static void Xusage(void)
459 #if defined(ENABLE_JIT)
460 puts(" -Xjit JIT mode execution (default)");
462 #if defined(ENABLE_INTRP)
463 puts(" -Xint interpreter mode execution");
465 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
466 puts(" value is set as bootstrap class path");
467 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
468 puts(" value is appended to the bootstrap class path");
469 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
470 puts(" value is prepended to the bootstrap class path");
471 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
472 puts(" value is used as Java core library, but the");
473 puts(" hardcoded VM interface classes are prepended");
474 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
475 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
476 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
478 #if defined(ENABLE_PROFILING)
479 puts(" -Xprof[:bb] collect and print profiling data");
482 #if defined(ENABLE_JVMTI)
483 /* -Xdebug option depend on gnu classpath JDWP options. options:
484 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
485 puts(" -Xdebug enable remote debugging\n");
486 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
487 puts(" enable remote debugging\n");
490 /* exit with error code */
497 static void XXusage(void)
499 puts(" -v write state-information");
501 puts(" -verbose:jit enable specific verbose output");
502 puts(" -debug-color colored output for ANSI terms");
504 #ifdef TYPECHECK_VERBOSE
505 puts(" -verbosetc write debug messages while typechecking");
507 #if defined(ENABLE_VERIFIER)
508 puts(" -noverify don't verify classfiles");
510 #if defined(ENABLE_STATISTICS)
511 puts(" -time measure the runtime");
512 puts(" -stat detailed compiler statistics");
514 puts(" -log logfile specify a name for the logfile");
515 puts(" -c(heck)b(ounds) don't check array bounds");
516 puts(" s(ync) don't check for synchronization");
517 #if defined(ENABLE_LOOP)
518 puts(" -oloop optimize array accesses in loops");
520 puts(" -l don't start the class after loading");
522 puts(" -all compile all methods, no execution");
523 puts(" -m compile only a specific method");
524 puts(" -sig specify signature for a specific method");
527 puts(" -s... show...");
528 puts(" (c)onstants the constant pool");
529 puts(" (m)ethods class fields and methods");
530 puts(" (u)tf the utf - hash");
531 puts(" (i)ntermediate intermediate representation");
532 #if defined(ENABLE_DISASSEMBLER)
533 puts(" (a)ssembler disassembled listing");
534 puts(" n(o)ps show NOPs in disassembler output");
536 puts(" (d)atasegment data segment listing");
538 #if defined(ENABLE_IFCONV)
539 puts(" -ifconv use if-conversion");
541 #if defined(ENABLE_LSRA)
542 puts(" -lsra use linear scan register allocation");
544 #if defined(ENABLE_SSA)
545 puts(" -lsra:... use linear scan register allocation (with SSA)");
546 puts(" (d)ead code elimination");
547 puts(" (c)opy propagation");
549 #if defined(ENABLE_DEBUG_FILTER)
550 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
551 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
552 puts(" -XXfm <regex> filter for show options");
554 /* exit with error code */
561 /* version *********************************************************************
563 Only prints cacao version information.
565 *******************************************************************************/
567 static void version(bool opt_exit)
569 puts("java version \""JAVA_VERSION"\"");
570 puts("CACAO version "VERSION"\n");
572 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
573 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
574 puts("This is free software; see the source for copying conditions. There is NO");
575 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
577 /* exit normally, if requested */
584 /* fullversion *****************************************************************
586 Prints a Sun compatible version information (required e.g. by
587 jpackage, www.jpackage.org).
589 *******************************************************************************/
591 static void fullversion(void)
593 puts("java full version \"cacao-"JAVA_VERSION"\"");
601 /* forward declarations *******************************************************/
603 static char *vm_get_mainclass_from_jar(char *mainstring);
605 static void vm_compile_all(void);
606 static void vm_compile_method(char* mainname);
611 * Implementation for JNI_CreateJavaVM. This function creates a VM
618 * @return true on success, false otherwise.
620 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
622 JavaVMInitArgs* _vm_args;
624 // Get the arguments for the new JVM.
625 _vm_args = (JavaVMInitArgs *) vm_args;
627 // Instantiate a new VM.
629 _vm = new VM(_vm_args);
631 catch (std::exception e) {
632 // FIXME How can we delete the resources allocated?
633 // /* release allocated memory */
634 // FREE(env, _Jv_JNIEnv);
635 // FREE(vm, _Jv_JavaVM);
642 // Return the values.
644 *p_vm = _vm->get_javavm();
645 *p_env = _vm->get_jnienv();
652 * C wrapper for VM::create.
655 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
657 return VM::create(p_vm, p_env, vm_args);
665 VM::VM(JavaVMInitArgs* vm_args)
667 // Very first thing to do: we are initializing.
668 _initializing = true;
670 // Make ourself globally visible.
671 // XXX Is this a good idea?
674 /* create and fill a JavaVM structure */
676 _javavm = new JavaVM();
678 #if defined(ENABLE_JNI)
679 _javavm->functions = &_Jv_JNIInvokeInterface;
682 /* get the VM and Env tables (must be set before vm_create) */
683 /* XXX JVMTI Agents needs a JavaVM */
685 _jnienv = new JNIEnv();
687 #if defined(ENABLE_JNI)
688 _jnienv->functions = &_Jv_JNINativeInterface;
691 /* actually create the JVM */
695 char *boot_class_path;
701 #if defined(ENABLE_JVMTI)
703 char *libname, *agentarg;
704 bool jdwp,agentbypath;
705 jdwp = agentbypath = false;
708 #if defined(ENABLE_JNI)
709 /* Check the JNI version requested. */
711 if (!jni_version_check(vm_args->version))
712 throw std::exception();
715 /* We only support 1 JVM instance. */
718 throw std::exception();
720 /* Install the exit handler. */
722 if (atexit(vm_exit_handler))
723 os::abort("atexit failed: %s\n", strerror(errno));
725 /* Set some options. */
730 opt_heapmaxsize = HEAP_MAXSIZE;
731 opt_heapstartsize = HEAP_STARTSIZE;
732 opt_stacksize = STACK_SIZE;
734 // First of all, parse the -XX options.
736 #if defined(ENABLE_VMLOG)
737 vmlog_cacao_init_options();
742 // After -XX options are parsed, print the build-time
743 // configuration, if requested.
745 print_build_time_config();
747 #if defined(ENABLE_VMLOG)
751 /* We need to check if the actual size of a java.lang.Class object
752 is smaller or equal than the assumption made in
755 #warning FIXME We need to check the size of java.lang.Class!!!
756 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
757 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
759 /* set the VM starttime */
761 _starttime = builtin_currenttimemillis();
763 #if defined(ENABLE_JVMTI)
764 /* initialize JVMTI related **********************************************/
768 /* iterate over all passed options */
770 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
784 #if SIZEOF_VOID_P == 8
785 puts("Running a 32-bit JVM is not supported on this platform.");
791 #if SIZEOF_VOID_P == 4
792 puts("Running a 64-bit JVM is not supported on this platform.");
798 /* Forget old classpath and set the argument as new
801 // FIXME Make class_path const char*.
802 class_path = (char*) _properties.get("java.class.path");
804 p = MNEW(char, strlen(opt_arg) + strlen("0"));
808 #if defined(ENABLE_JAVASE)
809 _properties.put("java.class.path", p);
812 MFREE(class_path, char, strlen(class_path));
816 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
817 if (opt_arg[i] == '=') {
819 _properties.put(opt_arg, opt_arg + i + 1);
824 /* if no '=' is given, just create an empty property */
826 _properties.put(opt_arg, "");
831 case OPT_BOOTCLASSPATH:
832 /* Forget default bootclasspath and set the argument as
833 new boot classpath. */
835 // FIXME Make boot_class_path const char*.
836 boot_class_path = (char*) _properties.get("sun.boot.class.path");
838 p = MNEW(char, strlen(opt_arg) + strlen("0"));
842 _properties.put("sun.boot.class.path", p);
843 _properties.put("java.boot.class.path", p);
845 MFREE(boot_class_path, char, strlen(boot_class_path));
848 case OPT_BOOTCLASSPATH_A:
849 /* Append to bootclasspath. */
851 // FIXME Make boot_class_path const char*.
852 boot_class_path = (char*) _properties.get("sun.boot.class.path");
854 len = strlen(boot_class_path);
856 // XXX (char*) quick hack
857 p = (char*) MREALLOC(boot_class_path,
861 strlen(opt_arg) + strlen("0"));
866 _properties.put("sun.boot.class.path", p);
867 _properties.put("java.boot.class.path", p);
870 case OPT_BOOTCLASSPATH_P:
871 /* Prepend to bootclasspath. */
873 // FIXME Make boot_class_path const char*.
874 boot_class_path = (char*) _properties.get("sun.boot.class.path");
876 len = strlen(boot_class_path);
878 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
882 strcat(p, boot_class_path);
884 _properties.put("sun.boot.class.path", p);
885 _properties.put("java.boot.class.path", p);
887 MFREE(boot_class_path, char, len);
890 case OPT_BOOTCLASSPATH_C:
891 /* Use as Java core library, but prepend VM interface
894 // FIXME Make boot_class_path const char*.
895 boot_class_path = (char*) _properties.get("sun.boot.class.path");
898 strlen(CACAO_VM_ZIP) +
905 strcpy(p, CACAO_VM_ZIP);
909 _properties.put("sun.boot.class.path", p);
910 _properties.put("java.boot.class.path", p);
912 MFREE(boot_class_path, char, strlen(boot_class_path));
915 #if defined(ENABLE_JVMTI)
917 /* this option exists only for compatibility reasons */
921 /* I don't know yet what Xnoagent should do. This is only for
922 compatiblity with eclipse - motse */
931 strlen(CACAO_LIBDIR) +
932 strlen("/libjdwp.so=") +
936 agentarg = MNEW(char, len);
938 strcpy(agentarg, CACAO_LIBDIR);
939 strcat(agentarg, "/libjdwp.so=");
940 strcat(agentarg, &opt_arg[1]);
959 c = opt_arg[strlen(opt_arg) - 1];
961 if ((c == 'k') || (c == 'K')) {
962 j = atoi(opt_arg) * 1024;
964 } else if ((c == 'm') || (c == 'M')) {
965 j = atoi(opt_arg) * 1024 * 1024;
972 else if (opt == OPT_MS)
973 opt_heapstartsize = j;
984 if (strcmp("class", opt_arg) == 0) {
985 opt_verboseclass = true;
987 else if (strcmp("gc", opt_arg) == 0) {
988 opt_verbosegc = true;
990 else if (strcmp("jni", opt_arg) == 0) {
991 opt_verbosejni = true;
994 else if (strcmp("jit", opt_arg) == 0) {
998 compileverbose = true;
1002 printf("Unknown -verbose option: %s\n", opt_arg);
1007 case OPT_DEBUGCOLOR:
1008 opt_debugcolor = true;
1011 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1013 opt_typecheckverbose = true;
1022 case OPT_FULLVERSION:
1026 case OPT_SHOWVERSION:
1030 #if defined(ENABLE_VERIFIER)
1036 #if defined(ENABLE_STATISTICS)
1038 opt_getcompilingtime = true;
1039 opt_getloadingtime = true;
1052 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1053 switch (opt_arg[i]) {
1055 checkbounds = false;
1068 makeinitializations = false;
1071 #if !defined(NDEBUG)
1075 makeinitializations = false;
1080 opt_method = opt_arg;
1081 makeinitializations = false;
1085 opt_signature = opt_arg;
1089 case OPT_SHOW: /* Display options */
1090 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1091 switch (opt_arg[i]) {
1093 showconstantpool = true;
1105 opt_showintermediate = true;
1106 compileverbose = true;
1109 #if defined(ENABLE_DISASSEMBLER)
1111 opt_showdisassemble = true;
1112 compileverbose = true;
1117 opt_showddatasegment = true;
1126 #if defined(ENABLE_LOOP)
1132 #if defined(ENABLE_IFCONV)
1138 #if defined(ENABLE_LSRA)
1143 #if defined(ENABLE_SSA)
1146 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1147 switch (opt_arg[i]) {
1175 /* Already parsed. */
1179 #if defined(ENABLE_ASSERTION)
1180 assertion_ea_da(opt_arg, true);
1185 #if defined(ENABLE_ASSERTION)
1186 assertion_ea_da(opt_arg, false);
1191 #if defined(ENABLE_ASSERTION)
1192 assertion_user_enabled = true;
1197 #if defined(ENABLE_ASSERTION)
1198 assertion_user_enabled = false;
1203 #if defined(ENABLE_ASSERTION)
1204 assertion_system_enabled = true;
1209 #if defined(ENABLE_ASSERTION)
1210 assertion_system_enabled = false;
1214 #if defined(ENABLE_PROFILING)
1215 case OPT_PROF_OPTION:
1216 /* use <= to get the last \0 too */
1218 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1219 if (opt_arg[i] == ',')
1222 if (opt_arg[i] == '\0') {
1223 if (strcmp("bb", opt_arg + j) == 0)
1227 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1231 /* set k to next char */
1244 #if defined(ENABLE_JIT)
1247 printf("-Xjit option not enabled.\n");
1253 #if defined(ENABLE_INTRP)
1256 printf("-Xint option not enabled.\n");
1261 #if defined(ENABLE_INTRP)
1262 case OPT_STATIC_SUPERS:
1263 opt_static_supers = atoi(opt_arg);
1266 case OPT_NO_DYNAMIC:
1267 opt_no_dynamic = true;
1270 case OPT_NO_REPLICATION:
1271 opt_no_replication = true;
1274 case OPT_NO_QUICKSUPER:
1275 opt_no_quicksuper = true;
1283 #if defined(ENABLE_DEBUG_FILTER)
1284 case OPT_FILTER_VERBOSECALL_INCLUDE:
1285 opt_filter_verbosecall_include = opt_arg;
1288 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1289 opt_filter_verbosecall_exclude = opt_arg;
1292 case OPT_FILTER_SHOW_METHOD:
1293 opt_filter_show_method = opt_arg;
1298 printf("Unknown option: %s\n",
1299 vm_args->options[opt_index].optionString);
1304 // Print the preliminary run-time VM configuration after options
1306 if (opt_PrintConfig)
1307 print_run_time_config();
1309 #if defined(ENABLE_JVMTI)
1311 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1312 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1315 MFREE(agentarg, char, strlen(agentarg));
1317 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1321 /* initialize the garbage collector */
1323 gc_init(opt_heapmaxsize, opt_heapstartsize);
1325 #if defined(ENABLE_THREADS)
1326 /* AFTER: gc_init */
1332 /* install architecture dependent signal handlers */
1335 os::abort("vm_create: signal_init failed");
1337 #if defined(ENABLE_INTRP)
1338 /* Allocate main thread stack on the Java heap. */
1341 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1342 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1346 /* AFTER: threads_preinit */
1349 os::abort("vm_create: string_init failed");
1351 /* AFTER: threads_preinit */
1355 /* AFTER: thread_preinit */
1358 os::abort("vm_create: suck_init failed");
1360 suck_add_from_property("java.endorsed.dirs");
1362 /* Now we have all options handled and we can print the version
1365 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1370 /* AFTER: utf8_init */
1372 // FIXME Make boot_class_path const char*.
1373 boot_class_path = (char*) _properties.get("sun.boot.class.path");
1374 suck_add(boot_class_path);
1376 /* initialize the classcache hashtable stuff: lock, hashtable
1377 (must be done _after_ threads_preinit) */
1379 if (!classcache_init())
1380 os::abort("vm_create: classcache_init failed");
1382 /* Initialize the code memory management. */
1383 /* AFTER: threads_preinit */
1387 /* initialize the finalizer stuff (must be done _after_
1390 if (!finalizer_init())
1391 os::abort("vm_create: finalizer_init failed");
1393 /* Initialize the JIT compiler. */
1399 #if defined(ENABLE_PYTHON)
1403 /* AFTER: utf8_init, classcache_init */
1408 // AFTER: loader_preinit, linker_preinit
1409 Primitive::initialize_table();
1414 // AFTER: loader_init, linker_init
1415 Primitive::post_initialize_table();
1418 #if defined(ENABLE_JIT)
1422 if (!builtin_init())
1423 os::abort("vm_create: builtin_init failed");
1425 /* Register the native methods implemented in the VM. */
1426 /* BEFORE: threads_init */
1430 #if defined(ENABLE_JNI)
1431 /* Initialize the JNI subsystem (must be done _before_
1432 threads_init, as threads_init can call JNI methods
1433 (e.g. NewGlobalRef). */
1436 os::abort("vm_create: jni_init failed");
1439 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1440 /* Initialize the local reference table for the main thread. */
1441 /* BEFORE: threads_init */
1443 if (!localref_table_init())
1444 os::abort("vm_create: localref_table_init failed");
1447 /* Iinitialize some important system classes. */
1448 /* BEFORE: threads_init */
1452 #if defined(ENABLE_THREADS)
1456 /* Initialize the native VM subsystem. */
1457 /* AFTER: threads_init (at least for SUN's classes) */
1461 #if defined(ENABLE_PROFILING)
1462 /* initialize profiling */
1464 if (!profile_init())
1465 os::abort("vm_create: profile_init failed");
1468 #if defined(ENABLE_THREADS)
1469 /* start the signal handler thread */
1471 #if defined(__LINUX__)
1472 /* XXX Remove for exact-GC. */
1473 if (threads_pthreads_implementation_nptl)
1475 if (!signal_start_thread())
1476 os::abort("vm_create: signal_start_thread failed");
1478 /* finally, start the finalizer thread */
1480 if (!finalizer_start_thread())
1481 os::abort("vm_create: finalizer_start_thread failed");
1483 # if !defined(NDEBUG)
1484 /* start the memory profiling thread */
1486 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1487 if (!memory_start_thread())
1488 os::abort("vm_create: memory_start_thread failed");
1491 // Start the recompilation thread (must be done before the
1492 // profiling thread).
1493 // FIXME Only works for one recompiler.
1494 _recompiler.start();
1496 # if defined(ENABLE_PROFILING)
1497 /* start the profile sampling thread */
1500 /* if (!profile_start_thread()) */
1501 /* os::abort("vm_create: profile_start_thread failed"); */
1505 #if defined(ENABLE_JVMTI)
1506 # if defined(ENABLE_GC_CACAO)
1507 /* XXX this will not work with the new indirection cells for classloaders!!! */
1511 /* add agent library to native library hashtable */
1512 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1516 /* Increment the number of VMs. */
1520 // Initialization is done, VM is created.
1522 _initializing = false;
1524 // Print the run-time VM configuration after all stuff is set and
1525 // the VM is initialized.
1526 if (opt_PrintConfig)
1527 print_run_time_config();
1532 * Print build-time (default) VM configuration.
1534 void VM::print_build_time_config(void)
1536 puts("CACAO "VERSION" configure/build options:");
1538 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1539 #if defined(__VERSION__)
1540 puts(" CC : "VERSION_CC" ("__VERSION__")");
1541 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1543 puts(" CC : "VERSION_CC"");
1544 puts(" CXX : "VERSION_CXX"");
1546 puts(" CFLAGS : "VERSION_CFLAGS"");
1547 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1551 puts("Build-time (default) variables:\n");
1552 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1553 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1554 printf(" stack size : %d\n", STACK_SIZE);
1556 #if defined(ENABLE_JRE_LAYOUT)
1557 // When we're building with JRE-layout, the default paths are the
1558 // same as the runtime paths.
1560 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1561 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1562 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1563 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1564 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1565 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1574 * Print run-time VM configuration.
1576 void VM::print_run_time_config()
1578 puts("Run-time variables:\n");
1579 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1580 printf(" initial heap size : %d\n", opt_heapstartsize);
1581 printf(" stack size : %d\n", opt_stacksize);
1583 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1584 printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1585 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1586 printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1589 printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1590 printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1596 /* vm_run **********************************************************************
1598 Runs the main-method of the passed class.
1600 *******************************************************************************/
1602 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1608 classinfo *mainclass;
1611 java_handle_objectarray_t *oa;
1617 // Prevent compiler warnings.
1620 #if !defined(NDEBUG)
1627 /* Get the main class plus it's arguments. */
1631 if (opt_index < vm_args->nOptions) {
1632 /* Get main-class argument. */
1634 mainname = vm_args->options[opt_index].optionString;
1636 /* If the main class argument is a jar file, put it into the
1639 if (opt_jar == true) {
1640 p = MNEW(char, strlen(mainname) + strlen("0"));
1642 strcpy(p, mainname);
1644 #if defined(ENABLE_JAVASE)
1645 VM::get_current()->get_properties().put("java.class.path", p);
1649 /* Replace dots with slashes in the class name. */
1651 for (unsigned int i = 0; i < strlen(mainname); i++)
1652 if (mainname[i] == '.')
1656 /* Build argument array. Move index to first argument. */
1660 oalength = vm_args->nOptions - opt_index;
1662 oa = builtin_anewarray(oalength, class_java_lang_String);
1664 for (int i = 0; i < oalength; i++) {
1665 option = vm_args->options[opt_index + i].optionString;
1667 u = utf_new_char(option);
1668 s = javastring_new(u);
1670 array_objectarray_element_set(oa, i, s);
1674 /* Do we have a main-class argument? */
1676 if (mainname == NULL)
1679 #if !defined(NDEBUG)
1680 if (opt_method != NULL) {
1681 vm_compile_method(mainname);
1686 /* set return value to OK */
1690 if (opt_jar == true) {
1691 /* open jar file with java.util.jar.JarFile */
1693 mainname = vm_get_mainclass_from_jar(mainname);
1695 if (mainname == NULL)
1699 /* load the main class */
1701 mainutf = utf_new_char(mainname);
1703 #if defined(ENABLE_JAVAME_CLDC1_1)
1704 mainclass = load_class_bootstrap(mainutf);
1706 mainclass = load_class_from_sysloader(mainutf);
1709 /* error loading class */
1711 e = exceptions_get_and_clear_exception();
1713 if ((e != NULL) || (mainclass == NULL)) {
1714 exceptions_throw_noclassdeffounderror_cause(e);
1715 exceptions_print_stacktrace();
1719 if (!link_class(mainclass)) {
1720 exceptions_print_stacktrace();
1724 /* find the `main' method of the main class */
1726 m = class_resolveclassmethod(mainclass,
1727 utf_new_char("main"),
1728 utf_new_char("([Ljava/lang/String;)V"),
1729 class_java_lang_Object,
1732 if (exceptions_get_exception()) {
1733 exceptions_print_stacktrace();
1737 /* there is no main method or it isn't static */
1739 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1740 exceptions_clear_exception();
1741 exceptions_throw_nosuchmethoderror(mainclass,
1742 utf_new_char("main"),
1743 utf_new_char("([Ljava/lang/String;)V"));
1745 exceptions_print_stacktrace();
1749 #ifdef TYPEINFO_DEBUG_TEST
1750 /* test the typeinfo system */
1754 #if defined(ENABLE_JVMTI)
1755 jvmti_set_phase(JVMTI_PHASE_LIVE);
1758 /* set ThreadMXBean variables */
1760 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1761 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1763 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1764 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1765 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1766 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1767 #warning Move to C++
1769 /* start the main thread */
1771 (void) vm_call_method(m, NULL, oa);
1773 /* exception occurred? */
1775 if (exceptions_get_exception()) {
1776 exceptions_print_stacktrace();
1780 #if defined(ENABLE_THREADS)
1781 /* Detach the main thread so that it appears to have ended when
1782 the application's main method exits. */
1784 if (!thread_detach_current_thread())
1785 os::abort("vm_run: Could not detach main thread.");
1788 /* Destroy the JavaVM. */
1790 (void) vm_destroy(vm);
1798 /* vm_destroy ******************************************************************
1800 Unloads a Java VM and reclaims its resources.
1802 *******************************************************************************/
1804 int vm_destroy(JavaVM *vm)
1806 #if defined(ENABLE_THREADS)
1807 /* Create a a trivial new Java waiter thread called
1810 JavaVMAttachArgs args;
1812 args.name = (char*) "DestroyJavaVM";
1815 if (!thread_attach_current_thread(&args, false))
1818 /* Wait until we are the last non-daemon thread. */
1820 threads_join_all_threads();
1825 // _created = false;
1826 #warning Move to C++
1828 /* Everything is ok. */
1834 /* vm_exit *********************************************************************
1836 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1838 *******************************************************************************/
1840 void vm_exit(s4 status)
1844 /* signal that we are exiting */
1847 #warning Move to C++
1849 assert(class_java_lang_System);
1850 assert(class_java_lang_System->state & CLASS_LOADED);
1852 #if defined(ENABLE_JVMTI)
1853 if (jvmti || (dbgcom!=NULL)) {
1854 jvmti_set_phase(JVMTI_PHASE_DEAD);
1855 if (jvmti) jvmti_agentunload();
1859 if (!link_class(class_java_lang_System)) {
1860 exceptions_print_stacktrace();
1864 /* call java.lang.System.exit(I)V */
1866 m = class_resolveclassmethod(class_java_lang_System,
1867 utf_new_char("exit"),
1869 class_java_lang_Object,
1873 exceptions_print_stacktrace();
1877 /* call the exit function with passed exit status */
1879 (void) vm_call_method(m, NULL, status);
1881 /* If we had an exception, just ignore the exception and exit with
1884 vm_shutdown(status);
1888 /* vm_shutdown *****************************************************************
1890 Terminates the system immediately without freeing memory explicitly
1891 (to be used only for abnormal termination).
1893 *******************************************************************************/
1895 void vm_shutdown(s4 status)
1898 #if defined(ENABLE_STATISTICS)
1899 || opt_getcompilingtime || opt_stat
1903 log_text("CACAO terminated by shutdown");
1904 dolog("Exit status: %d\n", (s4) status);
1908 #if defined(ENABLE_JVMTI)
1909 /* terminate cacaodbgserver */
1911 mutex_lock(&dbgcomlock);
1913 mutex_unlock(&dbgcomlock);
1914 jvmti_cacaodbgserver_quit();
1918 #if defined (ENABLE_JITCACHE)
1926 /* vm_exit_handler *************************************************************
1928 The exit_handler function is called upon program termination.
1930 ATTENTION: Don't free system resources here! Some threads may still
1931 be running as this is called from VMRuntime.exit(). The OS does the
1934 *******************************************************************************/
1936 void vm_exit_handler(void)
1938 #if !defined(NDEBUG)
1940 class_showmethods(mainclass);
1942 if (showconstantpool)
1943 class_showconstantpool(mainclass);
1948 # if defined(ENABLE_PROFILING)
1950 profile_printstats();
1952 #endif /* !defined(NDEBUG) */
1954 #if defined(ENABLE_RT_TIMING)
1955 rt_timing_print_time_stats(stderr);
1958 #if defined(ENABLE_CYCLES_STATS)
1959 builtin_print_cycles_stats(stderr);
1960 stacktrace_print_cycles_stats(stderr);
1964 #if defined(ENABLE_STATISTICS)
1965 || opt_getcompilingtime || opt_stat
1969 log_text("CACAO terminated");
1971 #if defined(ENABLE_STATISTICS)
1974 #ifdef TYPECHECK_STATISTICS
1975 typecheck_print_statistics(get_logfile());
1979 if (opt_getcompilingtime)
1981 #endif /* defined(ENABLE_STATISTICS) */
1983 /* vm_print_profile(stderr);*/
1987 /* vm_abort_disassemble ********************************************************
1989 Prints an error message, disassemble the given code range (if
1990 enabled) and aborts the VM.
1993 pc.......PC to disassemble
1994 count....number of instructions to disassemble
1996 *******************************************************************************/
1998 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2001 #if defined(ENABLE_DISASSEMBLER)
2005 /* Print debug message. */
2010 log_vprint(text, ap);
2017 #if SIZEOF_VOID_P == 8
2018 log_println("PC=0x%016lx", pc);
2020 log_println("PC=0x%08x", pc);
2023 #if defined(ENABLE_DISASSEMBLER)
2024 log_println("machine instructions at PC:");
2026 /* Disassemble the given number of instructions. */
2028 for (i = 0; i < count; i++)
2029 // FIXME disassinstr should use void*.
2030 pc = disassinstr((u1*) pc);
2033 os::abort("Aborting...");
2037 /* vm_get_mainclass_from_jar ***************************************************
2039 Gets the name of the main class from a JAR's manifest file.
2041 *******************************************************************************/
2043 static char *vm_get_mainclass_from_jar(char *mainname)
2050 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2053 exceptions_print_stacktrace();
2057 /* create JarFile object */
2062 exceptions_print_stacktrace();
2066 m = class_resolveclassmethod(c,
2068 utf_java_lang_String__void,
2069 class_java_lang_Object,
2073 exceptions_print_stacktrace();
2077 s = javastring_new_from_ascii(mainname);
2079 (void) vm_call_method(m, o, s);
2081 if (exceptions_get_exception()) {
2082 exceptions_print_stacktrace();
2086 /* get manifest object */
2088 m = class_resolveclassmethod(c,
2089 utf_new_char("getManifest"),
2090 utf_new_char("()Ljava/util/jar/Manifest;"),
2091 class_java_lang_Object,
2095 exceptions_print_stacktrace();
2099 o = vm_call_method(m, o);
2102 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2107 /* get Main Attributes */
2109 LLNI_class_get(o, c);
2111 m = class_resolveclassmethod(c,
2112 utf_new_char("getMainAttributes"),
2113 utf_new_char("()Ljava/util/jar/Attributes;"),
2114 class_java_lang_Object,
2118 exceptions_print_stacktrace();
2122 o = vm_call_method(m, o);
2125 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2130 /* get property Main-Class */
2132 LLNI_class_get(o, c);
2134 m = class_resolveclassmethod(c,
2135 utf_new_char("getValue"),
2136 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2137 class_java_lang_Object,
2141 exceptions_print_stacktrace();
2145 s = javastring_new_from_ascii("Main-Class");
2147 o = vm_call_method(m, o, s);
2150 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2151 fprintf(stderr, "%s\n", mainname);
2155 return javastring_tochar(o);
2159 /* vm_compile_all **************************************************************
2161 Compile all methods found in the bootclasspath.
2163 *******************************************************************************/
2165 #if !defined(NDEBUG)
2166 static void vm_compile_all(void)
2171 classcache_name_entry *nmen;
2172 classcache_class_entry *clsen;
2175 /* create all classes found in the bootclasspath */
2176 /* XXX currently only works with zip/jar's */
2178 loader_load_all_classes();
2180 /* link all classes */
2182 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2183 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2185 for (; nmen; nmen = nmen->hashlink) {
2186 /* iterate over all class entries */
2188 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2189 c = clsen->classobj;
2194 if (!(c->state & CLASS_LINKED)) {
2195 if (!link_class(c)) {
2196 fprintf(stderr, "Error linking: ");
2197 utf_fprint_printable_ascii_classname(stderr, c->name);
2198 fprintf(stderr, "\n");
2200 /* print out exception and cause */
2202 exceptions_print_current_exception();
2204 /* goto next class */
2210 /* compile all class methods */
2212 for (i = 0; i < c->methodscount; i++) {
2213 m = &(c->methods[i]);
2215 if (m->jcode != NULL) {
2216 if (!jit_compile(m)) {
2217 fprintf(stderr, "Error compiling: ");
2218 utf_fprint_printable_ascii_classname(stderr, c->name);
2219 fprintf(stderr, ".");
2220 utf_fprint_printable_ascii(stderr, m->name);
2221 utf_fprint_printable_ascii(stderr, m->descriptor);
2222 fprintf(stderr, "\n");
2224 /* print out exception and cause */
2226 exceptions_print_current_exception();
2234 #endif /* !defined(NDEBUG) */
2237 /* vm_compile_method ***********************************************************
2239 Compile a specific method.
2241 *******************************************************************************/
2243 #if !defined(NDEBUG)
2244 static void vm_compile_method(char* mainname)
2248 /* create, load and link the main class */
2250 mainclass = load_class_bootstrap(utf_new_char(mainname));
2252 if (mainclass == NULL)
2253 exceptions_print_stacktrace();
2255 if (!link_class(mainclass))
2256 exceptions_print_stacktrace();
2258 if (opt_signature != NULL) {
2259 m = class_resolveclassmethod(mainclass,
2260 utf_new_char(opt_method),
2261 utf_new_char(opt_signature),
2266 m = class_resolveclassmethod(mainclass,
2267 utf_new_char(opt_method),
2274 os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2275 opt_method, opt_signature ? opt_signature : "");
2279 #endif /* !defined(NDEBUG) */
2282 /* vm_call_array ***************************************************************
2284 Calls a Java method with a variable number of arguments, passed via
2287 ATTENTION: This function has to be used outside the nativeworld.
2289 *******************************************************************************/
2291 #define VM_CALL_ARRAY(name, type) \
2292 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2298 assert(m->code != NULL); \
2300 md = m->parseddesc; \
2301 pv = m->code->entrypoint; \
2303 STATISTICS(count_calls_native_to_java++); \
2305 value = asm_vm_call_method##name(pv, array, md->memuse); \
2310 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2316 assert(m->code != NULL);
2319 pv = m->code->entrypoint;
2321 STATISTICS(count_calls_native_to_java++);
2323 o = asm_vm_call_method(pv, array, md->memuse);
2325 if (md->returntype.type == TYPE_VOID)
2328 return LLNI_WRAP(o);
2331 VM_CALL_ARRAY(_int, int32_t)
2332 VM_CALL_ARRAY(_long, int64_t)
2333 VM_CALL_ARRAY(_float, float)
2334 VM_CALL_ARRAY(_double, double)
2337 /* vm_call_method **************************************************************
2339 Calls a Java method with a variable number of arguments.
2341 *******************************************************************************/
2343 #define VM_CALL_METHOD(name, type) \
2344 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2350 value = vm_call_method##name##_valist(m, o, ap); \
2356 VM_CALL_METHOD(, java_handle_t *)
2357 VM_CALL_METHOD(_int, int32_t)
2358 VM_CALL_METHOD(_long, int64_t)
2359 VM_CALL_METHOD(_float, float)
2360 VM_CALL_METHOD(_double, double)
2363 /* vm_call_method_valist *******************************************************
2365 Calls a Java method with a variable number of arguments, passed via
2368 *******************************************************************************/
2370 #define VM_CALL_METHOD_VALIST(name, type) \
2371 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2377 if (m->code == NULL) \
2378 if (!jit_compile(m)) \
2381 THREAD_NATIVEWORLD_EXIT; \
2383 DumpMemoryArea dma; \
2385 array = argument_vmarray_from_valist(m, o, ap); \
2386 value = vm_call##name##_array(m, array); \
2388 THREAD_NATIVEWORLD_ENTER; \
2393 VM_CALL_METHOD_VALIST(, java_handle_t *)
2394 VM_CALL_METHOD_VALIST(_int, int32_t)
2395 VM_CALL_METHOD_VALIST(_long, int64_t)
2396 VM_CALL_METHOD_VALIST(_float, float)
2397 VM_CALL_METHOD_VALIST(_double, double)
2400 /* vm_call_method_jvalue *******************************************************
2402 Calls a Java method with a variable number of arguments, passed via
2405 *******************************************************************************/
2407 #define VM_CALL_METHOD_JVALUE(name, type) \
2408 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2409 const jvalue *args) \
2414 if (m->code == NULL) \
2415 if (!jit_compile(m)) \
2418 THREAD_NATIVEWORLD_EXIT; \
2420 DumpMemoryArea dma; \
2422 array = argument_vmarray_from_jvalue(m, o, args); \
2423 value = vm_call##name##_array(m, array); \
2425 THREAD_NATIVEWORLD_ENTER; \
2430 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2431 VM_CALL_METHOD_JVALUE(_int, int32_t)
2432 VM_CALL_METHOD_JVALUE(_long, int64_t)
2433 VM_CALL_METHOD_JVALUE(_float, float)
2434 VM_CALL_METHOD_JVALUE(_double, double)
2437 /* vm_call_method_objectarray **************************************************
2439 Calls a Java method with a variable number if arguments, passed via
2440 an objectarray of boxed values. Returns a boxed value.
2442 *******************************************************************************/
2444 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2445 java_handle_objectarray_t *params)
2448 java_handle_t *xptr;
2452 /* Prevent compiler warnings. */
2456 /* compile methods which are not yet compiled */
2458 if (m->code == NULL)
2459 if (!jit_compile(m))
2462 /* leave the nativeworld */
2464 THREAD_NATIVEWORLD_EXIT;
2466 // Create new dump memory area.
2469 /* Fill the argument array from a object-array. */
2471 array = argument_vmarray_from_objectarray(m, o, params);
2473 if (array == NULL) {
2474 /* enter the nativeworld again */
2476 THREAD_NATIVEWORLD_ENTER;
2478 exceptions_throw_illegalargumentexception();
2483 switch (m->parseddesc->returntype.primitivetype) {
2484 case PRIMITIVETYPE_VOID:
2485 value.a = vm_call_array(m, array);
2488 case PRIMITIVETYPE_BOOLEAN:
2489 case PRIMITIVETYPE_BYTE:
2490 case PRIMITIVETYPE_CHAR:
2491 case PRIMITIVETYPE_SHORT:
2492 case PRIMITIVETYPE_INT:
2493 value.i = vm_call_int_array(m, array);
2496 case PRIMITIVETYPE_LONG:
2497 value.l = vm_call_long_array(m, array);
2500 case PRIMITIVETYPE_FLOAT:
2501 value.f = vm_call_float_array(m, array);
2504 case PRIMITIVETYPE_DOUBLE:
2505 value.d = vm_call_double_array(m, array);
2509 ro = vm_call_array(m, array);
2513 os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2516 /* enter the nativeworld again */
2518 THREAD_NATIVEWORLD_ENTER;
2520 /* box the return value if necesarry */
2522 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2523 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2525 /* check for an exception */
2527 xptr = exceptions_get_exception();
2530 /* clear exception pointer, we are calling JIT code again */
2532 exceptions_clear_exception();
2534 exceptions_throw_invocationtargetexception(xptr);
2541 /* Legacy C interface *********************************************************/
2545 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2546 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2547 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2548 bool VM_is_created() { return VM::get_current()->is_created(); }
2549 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2551 void vm_abort(const char* text, ...)
2556 os::abort(text, ap);
2560 void vm_abort_errnum(int errnum, const char* text, ...)
2565 os::abort_errnum(errnum, text, ap);
2569 void vm_abort_errno(const char* text, ...)
2574 os::abort_errno(text, ap);
2582 * These are local overrides for various environment variables in Emacs.
2583 * Please do not remove this and leave it at the end of the file, where
2584 * Emacs will automagically detect them.
2585 * ---------------------------------------------------------------------
2588 * indent-tabs-mode: t
2592 * vim:noexpandtab:sw=4:ts=4: