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 #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.hpp"
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)
198 #if defined(ENABLE_STATISTICS)
209 #if defined(ENABLE_VERIFIER)
213 #if defined(TYPECHECK_VERBOSE)
216 #endif /* defined(ENABLE_VERIFIER) */
218 /* optimization options */
220 #if defined(ENABLE_LOOP)
224 #if defined(ENABLE_IFCONV)
228 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
232 #if defined(ENABLE_INTRP)
233 /* interpreter options */
252 #if defined(ENABLE_DEBUG_FILTER)
253 OPT_FILTER_VERBOSECALL_INCLUDE,
254 OPT_FILTER_VERBOSECALL_EXCLUDE,
255 OPT_FILTER_SHOW_METHOD,
262 opt_struct opts[] = {
263 { "foo", false, OPT_FOO },
267 { "jar", false, OPT_JAR },
269 { "d32", false, OPT_D32 },
270 { "d64", false, OPT_D64 },
271 { "client", false, OPT_IGNORE },
272 { "server", false, OPT_IGNORE },
273 { "jvm", false, OPT_IGNORE },
274 { "hotspot", false, OPT_IGNORE },
276 { "classpath", true, OPT_CLASSPATH },
277 { "cp", true, OPT_CLASSPATH },
278 { "D", true, OPT_D },
279 { "version", false, OPT_VERSION },
280 { "showversion", false, OPT_SHOWVERSION },
281 { "fullversion", false, OPT_FULLVERSION },
282 { "help", false, OPT_HELP },
283 { "?", false, OPT_HELP },
284 { "X", false, OPT_X },
285 { "XX:", true, OPT_XX },
287 { "ea:", true, OPT_EA },
288 { "da:", true, OPT_DA },
289 { "ea", false, OPT_EA_NOARG },
290 { "da", false, OPT_DA_NOARG },
292 { "enableassertions:", true, OPT_EA },
293 { "disableassertions:", true, OPT_DA },
294 { "enableassertions", false, OPT_EA_NOARG },
295 { "disableassertions", false, OPT_DA_NOARG },
297 { "esa", false, OPT_ESA },
298 { "enablesystemassertions", false, OPT_ESA },
299 { "dsa", false, OPT_DSA },
300 { "disablesystemassertions", false, OPT_DSA },
302 { "noasyncgc", false, OPT_IGNORE },
303 #if defined(ENABLE_VERIFIER)
304 { "noverify", false, OPT_NOVERIFY },
305 { "Xverify:all", false, OPT_XVERIFY_ALL },
306 { "Xverify:none", false, OPT_XVERIFY_NONE },
308 { "v", false, OPT_VERBOSE1 },
309 { "verbose:", true, OPT_VERBOSE },
311 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
312 { "verbosetc", false, OPT_VERBOSETC },
314 #if defined(ENABLE_STATISTICS)
315 { "time", false, OPT_TIME },
316 { "stat", false, OPT_STAT },
318 { "log", true, OPT_LOG },
319 { "c", true, OPT_CHECK },
320 { "l", false, OPT_LOAD },
322 #if defined(ENABLE_LOOP)
323 { "oloop", false, OPT_OLOOP },
325 #if defined(ENABLE_IFCONV)
326 { "ifconv", false, OPT_IFCONV },
328 #if defined(ENABLE_LSRA)
329 { "lsra", false, OPT_LSRA },
331 #if defined(ENABLE_SSA)
332 { "lsra", true, OPT_LSRA },
335 #if defined(ENABLE_INTRP)
336 /* interpreter options */
338 { "trace", false, OPT_TRACE },
339 { "static-supers", true, OPT_STATIC_SUPERS },
340 { "no-dynamic", false, OPT_NO_DYNAMIC },
341 { "no-replication", false, OPT_NO_REPLICATION },
342 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
345 /* JVMTI Agent Command Line Options */
347 { "agentlib:", true, OPT_AGENTLIB },
348 { "agentpath:", true, OPT_AGENTPATH },
351 /* Java non-standard options */
353 { "Xjit", false, OPT_JIT },
354 { "Xint", false, OPT_INTRP },
355 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
356 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
357 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
358 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
361 { "Xdebug", false, OPT_DEBUG },
362 { "Xnoagent", false, OPT_NOAGENT },
363 { "Xrunjdwp", true, OPT_XRUNJDWP },
366 { "Xms", true, OPT_MS },
367 { "ms", true, OPT_MS },
368 { "Xmx", true, OPT_MX },
369 { "mx", true, OPT_MX },
370 { "Xss", true, OPT_SS },
371 { "ss", true, OPT_SS },
373 { "Xcheck:jni", false, OPT_XCHECK_JNI },
375 #if defined(ENABLE_PROFILING)
376 { "Xprof:", true, OPT_PROF_OPTION },
377 { "Xprof", false, OPT_PROF },
380 /* keep these at the end of the list */
382 { "s", true, OPT_SHOW },
383 { "debug-color", false, OPT_DEBUGCOLOR },
385 #if defined(ENABLE_DEBUG_FILTER)
386 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
387 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
388 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
395 /* usage ***********************************************************************
397 Prints the correct usage syntax to stdout.
399 *******************************************************************************/
403 puts("Usage: cacao [-options] classname [arguments]");
404 puts(" (to run a class file)");
405 puts(" or cacao [-options] -jar jarfile [arguments]");
406 puts(" (to run a standalone jar file)\n");
408 puts("where options include:");
409 puts(" -d32 use 32-bit data model if available");
410 puts(" -d64 use 64-bit data model if available");
411 puts(" -client compatibility (currently ignored)");
412 puts(" -server compatibility (currently ignored)");
413 puts(" -jvm compatibility (currently ignored)");
414 puts(" -hotspot compatibility (currently ignored)\n");
416 puts(" -cp <path> specify a path to look for classes");
417 puts(" -classpath <path> specify a path to look for classes");
418 puts(" -D<name>=<value> add an entry to the property list");
419 puts(" -verbose[:class|gc|jni] enable specific verbose output");
420 puts(" -version print product version and exit");
421 puts(" -fullversion print jpackage-compatible product version and exit");
422 puts(" -showversion print product version and continue");
423 puts(" -help, -? print this help message");
424 puts(" -X print help on non-standard Java options");
425 puts(" -XX print help on debugging options");
426 puts(" -ea[:<packagename>...|:<classname>]");
427 puts(" -enableassertions[:<packagename>...|:<classname>]");
428 puts(" enable assertions with specified granularity");
429 puts(" -da[:<packagename>...|:<classname>]");
430 puts(" -disableassertions[:<packagename>...|:<classname>]");
431 puts(" disable assertions with specified granularity");
432 puts(" -esa | -enablesystemassertions");
433 puts(" enable system assertions");
434 puts(" -dsa | -disablesystemassertions");
435 puts(" disable system assertions");
438 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
439 puts (" for jdwp help use: -agentlib:jdwp=help");
440 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
443 /* exit with error code */
449 static void Xusage(void)
451 #if defined(ENABLE_JIT)
452 puts(" -Xjit JIT mode execution (default)");
454 #if defined(ENABLE_INTRP)
455 puts(" -Xint interpreter mode execution");
457 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
458 puts(" value is set as bootstrap class path");
459 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
460 puts(" value is appended to the bootstrap class path");
461 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
462 puts(" value is prepended to the bootstrap class path");
463 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
464 puts(" value is used as Java core library, but the");
465 puts(" hardcoded VM interface classes are prepended");
466 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
467 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
468 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
470 #if defined(ENABLE_PROFILING)
471 puts(" -Xprof[:bb] collect and print profiling data");
474 #if defined(ENABLE_JVMTI)
475 /* -Xdebug option depend on gnu classpath JDWP options. options:
476 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
477 puts(" -Xdebug enable remote debugging\n");
478 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
479 puts(" enable remote debugging\n");
482 /* exit with error code */
489 static void XXusage(void)
491 puts(" -v write state-information");
493 puts(" -verbose:jit enable specific verbose output");
494 puts(" -debug-color colored output for ANSI terms");
496 #ifdef TYPECHECK_VERBOSE
497 puts(" -verbosetc write debug messages while typechecking");
499 #if defined(ENABLE_VERIFIER)
500 puts(" -noverify don't verify classfiles");
502 #if defined(ENABLE_STATISTICS)
503 puts(" -time measure the runtime");
504 puts(" -stat detailed compiler statistics");
506 puts(" -log logfile specify a name for the logfile");
507 puts(" -c(heck)b(ounds) don't check array bounds");
508 puts(" s(ync) don't check for synchronization");
509 #if defined(ENABLE_LOOP)
510 puts(" -oloop optimize array accesses in loops");
512 puts(" -l don't start the class after loading");
514 puts(" -s... show...");
515 puts(" (c)onstants the constant pool");
516 puts(" (m)ethods class fields and methods");
517 puts(" (u)tf the utf - hash");
518 puts(" (i)ntermediate intermediate representation");
519 #if defined(ENABLE_DISASSEMBLER)
520 puts(" (a)ssembler disassembled listing");
521 puts(" n(o)ps show NOPs in disassembler output");
523 puts(" (d)atasegment data segment listing");
525 #if defined(ENABLE_IFCONV)
526 puts(" -ifconv use if-conversion");
528 #if defined(ENABLE_LSRA)
529 puts(" -lsra use linear scan register allocation");
531 #if defined(ENABLE_SSA)
532 puts(" -lsra:... use linear scan register allocation (with SSA)");
533 puts(" (d)ead code elimination");
534 puts(" (c)opy propagation");
536 #if defined(ENABLE_DEBUG_FILTER)
537 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
538 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
539 puts(" -XXfm <regex> filter for show options");
541 /* exit with error code */
548 /* version *********************************************************************
550 Only prints cacao version information.
552 *******************************************************************************/
554 static void version(bool opt_exit)
556 puts("java version \""JAVA_VERSION"\"");
557 puts("CACAO version "VERSION"\n");
559 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
560 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
561 puts("This is free software; see the source for copying conditions. There is NO");
562 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
564 /* exit normally, if requested */
571 /* fullversion *****************************************************************
573 Prints a Sun compatible version information (required e.g. by
574 jpackage, www.jpackage.org).
576 *******************************************************************************/
578 static void fullversion(void)
580 puts("java full version \"cacao-"JAVA_VERSION"\"");
588 /* forward declarations *******************************************************/
590 static char *vm_get_mainclass_from_jar(char *mainstring);
592 static void vm_compile_all(void);
593 static void vm_compile_method(char* mainname);
598 * Implementation for JNI_CreateJavaVM. This function creates a VM
605 * @return true on success, false otherwise.
607 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
609 JavaVMInitArgs* _vm_args;
611 // Get the arguments for the new JVM.
612 _vm_args = (JavaVMInitArgs *) vm_args;
614 // Instantiate a new VM.
616 _vm = new VM(_vm_args);
618 catch (std::exception e) {
619 // FIXME How can we delete the resources allocated?
620 // /* release allocated memory */
621 // FREE(env, _Jv_JNIEnv);
622 // FREE(vm, _Jv_JavaVM);
629 // Return the values.
631 *p_vm = _vm->get_javavm();
632 *p_env = _vm->get_jnienv();
639 * C wrapper for VM::create.
642 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
644 return VM::create(p_vm, p_env, vm_args);
652 VM::VM(JavaVMInitArgs* vm_args)
654 // Very first thing to do: we are initializing.
655 _initializing = true;
657 // Make ourself globally visible.
658 // XXX Is this a good idea?
661 /* create and fill a JavaVM structure */
663 _javavm = new JavaVM();
665 #if defined(ENABLE_JNI)
666 _javavm->functions = &_Jv_JNIInvokeInterface;
669 /* get the VM and Env tables (must be set before vm_create) */
670 /* XXX JVMTI Agents needs a JavaVM */
672 _jnienv = new JNIEnv();
674 #if defined(ENABLE_JNI)
675 _jnienv->functions = &_Jv_JNINativeInterface;
678 /* actually create the JVM */
682 char *boot_class_path;
688 #if defined(ENABLE_JVMTI)
690 char *libname, *agentarg;
691 bool jdwp,agentbypath;
692 jdwp = agentbypath = false;
695 #if defined(ENABLE_JNI)
696 /* Check the JNI version requested. */
698 if (!jni_version_check(vm_args->version))
699 throw std::exception();
702 /* We only support 1 JVM instance. */
705 throw std::exception();
707 /* Install the exit handler. */
709 if (atexit(vm_exit_handler))
710 os::abort("atexit failed: %s\n", strerror(errno));
712 /* Set some options. */
717 opt_heapmaxsize = HEAP_MAXSIZE;
718 opt_heapstartsize = HEAP_STARTSIZE;
719 opt_stacksize = STACK_SIZE;
721 // First of all, parse the -XX options.
723 #if defined(ENABLE_VMLOG)
724 vmlog_cacao_init_options();
729 // After -XX options are parsed, print the build-time
730 // configuration, if requested.
732 print_build_time_config();
734 #if defined(ENABLE_VMLOG)
738 /* We need to check if the actual size of a java.lang.Class object
739 is smaller or equal than the assumption made in
742 #warning FIXME We need to check the size of java.lang.Class!!!
743 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
744 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
746 /* set the VM starttime */
748 _starttime = builtin_currenttimemillis();
750 #if defined(ENABLE_JVMTI)
751 /* initialize JVMTI related **********************************************/
755 /* iterate over all passed options */
757 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
771 #if SIZEOF_VOID_P == 8
772 puts("Running a 32-bit JVM is not supported on this platform.");
778 #if SIZEOF_VOID_P == 4
779 puts("Running a 64-bit JVM is not supported on this platform.");
785 /* Forget old classpath and set the argument as new
788 // FIXME Make class_path const char*.
789 class_path = (char*) _properties.get("java.class.path");
791 p = MNEW(char, strlen(opt_arg) + strlen("0"));
795 #if defined(ENABLE_JAVASE)
796 _properties.put("java.class.path", p);
799 MFREE(class_path, char, strlen(class_path));
803 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
804 if (opt_arg[i] == '=') {
806 _properties.put(opt_arg, opt_arg + i + 1);
811 /* if no '=' is given, just create an empty property */
813 _properties.put(opt_arg, "");
818 case OPT_BOOTCLASSPATH:
819 /* Forget default bootclasspath and set the argument as
820 new boot classpath. */
822 // FIXME Make boot_class_path const char*.
823 boot_class_path = (char*) _properties.get("sun.boot.class.path");
825 p = MNEW(char, strlen(opt_arg) + strlen("0"));
829 _properties.put("sun.boot.class.path", p);
830 _properties.put("java.boot.class.path", p);
832 MFREE(boot_class_path, char, strlen(boot_class_path));
835 case OPT_BOOTCLASSPATH_A:
836 /* Append to bootclasspath. */
838 // FIXME Make boot_class_path const char*.
839 boot_class_path = (char*) _properties.get("sun.boot.class.path");
841 len = strlen(boot_class_path);
843 // XXX (char*) quick hack
844 p = (char*) MREALLOC(boot_class_path,
848 strlen(opt_arg) + strlen("0"));
853 _properties.put("sun.boot.class.path", p);
854 _properties.put("java.boot.class.path", p);
857 case OPT_BOOTCLASSPATH_P:
858 /* Prepend to bootclasspath. */
860 // FIXME Make boot_class_path const char*.
861 boot_class_path = (char*) _properties.get("sun.boot.class.path");
863 len = strlen(boot_class_path);
865 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
869 strcat(p, boot_class_path);
871 _properties.put("sun.boot.class.path", p);
872 _properties.put("java.boot.class.path", p);
874 MFREE(boot_class_path, char, len);
877 case OPT_BOOTCLASSPATH_C:
878 /* Use as Java core library, but prepend VM interface
881 // FIXME Make boot_class_path const char*.
882 boot_class_path = (char*) _properties.get("sun.boot.class.path");
885 strlen(CACAO_VM_ZIP) +
892 strcpy(p, CACAO_VM_ZIP);
896 _properties.put("sun.boot.class.path", p);
897 _properties.put("java.boot.class.path", p);
899 MFREE(boot_class_path, char, strlen(boot_class_path));
902 #if defined(ENABLE_JVMTI)
904 /* this option exists only for compatibility reasons */
908 /* I don't know yet what Xnoagent should do. This is only for
909 compatiblity with eclipse - motse */
918 strlen(CACAO_LIBDIR) +
919 strlen("/libjdwp.so=") +
923 agentarg = MNEW(char, len);
925 strcpy(agentarg, CACAO_LIBDIR);
926 strcat(agentarg, "/libjdwp.so=");
927 strcat(agentarg, &opt_arg[1]);
946 c = opt_arg[strlen(opt_arg) - 1];
948 if ((c == 'k') || (c == 'K')) {
949 j = atoi(opt_arg) * 1024;
951 } else if ((c == 'm') || (c == 'M')) {
952 j = atoi(opt_arg) * 1024 * 1024;
959 else if (opt == OPT_MS)
960 opt_heapstartsize = j;
967 // HotSpot compatibility option.
975 if (strcmp("class", opt_arg) == 0) {
976 opt_verboseclass = true;
978 else if (strcmp("gc", opt_arg) == 0) {
979 opt_verbosegc = true;
981 else if (strcmp("jni", opt_arg) == 0) {
982 opt_verbosejni = true;
985 else if (strcmp("jit", opt_arg) == 0) {
989 compileverbose = true;
993 printf("Unknown -verbose option: %s\n", opt_arg);
999 opt_debugcolor = true;
1002 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1004 opt_typecheckverbose = true;
1013 case OPT_FULLVERSION:
1017 case OPT_SHOWVERSION:
1021 #if defined(ENABLE_VERIFIER)
1022 case OPT_XVERIFY_ALL:
1027 case OPT_XVERIFY_NONE:
1032 #if defined(ENABLE_STATISTICS)
1034 opt_getcompilingtime = true;
1035 opt_getloadingtime = true;
1048 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1049 switch (opt_arg[i]) {
1051 checkbounds = false;
1064 makeinitializations = false;
1067 case OPT_SHOW: /* Display options */
1068 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1069 switch (opt_arg[i]) {
1071 showconstantpool = true;
1083 opt_showintermediate = true;
1084 compileverbose = true;
1087 #if defined(ENABLE_DISASSEMBLER)
1089 opt_showdisassemble = true;
1090 compileverbose = true;
1095 opt_showddatasegment = true;
1104 #if defined(ENABLE_LOOP)
1110 #if defined(ENABLE_IFCONV)
1116 #if defined(ENABLE_LSRA)
1121 #if defined(ENABLE_SSA)
1124 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1125 switch (opt_arg[i]) {
1153 /* Already parsed. */
1157 #if defined(ENABLE_ASSERTION)
1158 assertion_ea_da(opt_arg, true);
1163 #if defined(ENABLE_ASSERTION)
1164 assertion_ea_da(opt_arg, false);
1169 #if defined(ENABLE_ASSERTION)
1170 assertion_user_enabled = true;
1175 #if defined(ENABLE_ASSERTION)
1176 assertion_user_enabled = false;
1181 #if defined(ENABLE_ASSERTION)
1182 assertion_system_enabled = true;
1187 #if defined(ENABLE_ASSERTION)
1188 assertion_system_enabled = false;
1192 #if defined(ENABLE_PROFILING)
1193 case OPT_PROF_OPTION:
1194 /* use <= to get the last \0 too */
1196 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1197 if (opt_arg[i] == ',')
1200 if (opt_arg[i] == '\0') {
1201 if (strcmp("bb", opt_arg + j) == 0)
1205 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1209 /* set k to next char */
1222 #if defined(ENABLE_JIT)
1225 printf("-Xjit option not enabled.\n");
1231 #if defined(ENABLE_INTRP)
1234 printf("-Xint option not enabled.\n");
1239 #if defined(ENABLE_INTRP)
1240 case OPT_STATIC_SUPERS:
1241 opt_static_supers = atoi(opt_arg);
1244 case OPT_NO_DYNAMIC:
1245 opt_no_dynamic = true;
1248 case OPT_NO_REPLICATION:
1249 opt_no_replication = true;
1252 case OPT_NO_QUICKSUPER:
1253 opt_no_quicksuper = true;
1261 #if defined(ENABLE_DEBUG_FILTER)
1262 case OPT_FILTER_VERBOSECALL_INCLUDE:
1263 opt_filter_verbosecall_include = opt_arg;
1266 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1267 opt_filter_verbosecall_exclude = opt_arg;
1270 case OPT_FILTER_SHOW_METHOD:
1271 opt_filter_show_method = opt_arg;
1276 printf("Unknown option: %s\n",
1277 vm_args->options[opt_index].optionString);
1282 // Print the preliminary run-time VM configuration after options
1284 if (opt_PrintConfig)
1285 print_run_time_config();
1287 #if defined(ENABLE_JVMTI)
1289 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1290 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1293 MFREE(agentarg, char, strlen(agentarg));
1295 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1299 /* initialize the garbage collector */
1301 gc_init(opt_heapmaxsize, opt_heapstartsize);
1303 #if defined(ENABLE_THREADS)
1304 /* AFTER: gc_init */
1310 /* install architecture dependent signal handlers */
1313 os::abort("vm_create: signal_init failed");
1315 #if defined(ENABLE_INTRP)
1316 /* Allocate main thread stack on the Java heap. */
1319 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1320 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1324 /* AFTER: threads_preinit */
1327 os::abort("vm_create: string_init failed");
1329 /* AFTER: threads_preinit */
1333 /* AFTER: thread_preinit */
1335 _suckclasspath.add_from_property("java.endorsed.dirs");
1337 /* Now we have all options handled and we can print the version
1340 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1345 /* AFTER: utf8_init */
1347 // FIXME Make boot_class_path const char*.
1348 boot_class_path = (char*) _properties.get("sun.boot.class.path");
1349 _suckclasspath.add(boot_class_path);
1351 /* initialize the classcache hashtable stuff: lock, hashtable
1352 (must be done _after_ threads_preinit) */
1354 if (!classcache_init())
1355 os::abort("vm_create: classcache_init failed");
1357 /* Initialize the code memory management. */
1358 /* AFTER: threads_preinit */
1362 /* initialize the finalizer stuff (must be done _after_
1365 if (!finalizer_init())
1366 os::abort("vm_create: finalizer_init failed");
1368 /* Initialize the JIT compiler. */
1374 #if defined(ENABLE_PYTHON)
1378 /* AFTER: utf8_init, classcache_init */
1383 // AFTER: loader_preinit, linker_preinit
1384 Primitive::initialize_table();
1389 // AFTER: loader_init, linker_init
1390 Primitive::post_initialize_table();
1393 #if defined(ENABLE_JIT)
1397 if (!builtin_init())
1398 os::abort("vm_create: builtin_init failed");
1400 /* Register the native methods implemented in the VM. */
1401 /* BEFORE: threads_init */
1405 #if defined(ENABLE_JNI)
1406 /* Initialize the JNI subsystem (must be done _before_
1407 threads_init, as threads_init can call JNI methods
1408 (e.g. NewGlobalRef). */
1411 os::abort("vm_create: jni_init failed");
1414 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1415 /* Initialize the local reference table for the main thread. */
1416 /* BEFORE: threads_init */
1418 if (!localref_table_init())
1419 os::abort("vm_create: localref_table_init failed");
1422 /* Iinitialize some important system classes. */
1423 /* BEFORE: threads_init */
1427 #if defined(ENABLE_THREADS)
1431 /* Initialize the native VM subsystem. */
1432 /* AFTER: threads_init (at least for SUN's classes) */
1434 if (!nativevm_init())
1435 os::abort("vm_create: nativevm_init failed");
1437 #if defined(ENABLE_PROFILING)
1438 /* initialize profiling */
1440 if (!profile_init())
1441 os::abort("vm_create: profile_init failed");
1444 #if defined(ENABLE_THREADS)
1445 /* start the signal handler thread */
1447 #if defined(__LINUX__)
1448 /* XXX Remove for exact-GC. */
1449 if (threads_pthreads_implementation_nptl)
1451 if (!signal_start_thread())
1452 os::abort("vm_create: signal_start_thread failed");
1454 /* finally, start the finalizer thread */
1456 if (!finalizer_start_thread())
1457 os::abort("vm_create: finalizer_start_thread failed");
1459 # if !defined(NDEBUG)
1460 /* start the memory profiling thread */
1462 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1463 if (!memory_start_thread())
1464 os::abort("vm_create: memory_start_thread failed");
1467 // Start the recompilation thread (must be done before the
1468 // profiling thread).
1469 // FIXME Only works for one recompiler.
1470 _recompiler.start();
1472 # if defined(ENABLE_PROFILING)
1473 /* start the profile sampling thread */
1476 /* if (!profile_start_thread()) */
1477 /* os::abort("vm_create: profile_start_thread failed"); */
1481 #if defined(ENABLE_JVMTI)
1482 # if defined(ENABLE_GC_CACAO)
1483 /* XXX this will not work with the new indirection cells for classloaders!!! */
1487 /* add agent library to native library hashtable */
1488 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1492 /* Increment the number of VMs. */
1496 // Initialization is done, VM is created.
1498 _initializing = false;
1500 // Print the run-time VM configuration after all stuff is set and
1501 // the VM is initialized.
1502 if (opt_PrintConfig)
1503 print_run_time_config();
1508 * Print build-time (default) VM configuration.
1510 void VM::print_build_time_config(void)
1512 puts("CACAO "VERSION" configure/build options:");
1514 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1515 #if defined(__VERSION__)
1516 puts(" CC : "VERSION_CC" ("__VERSION__")");
1517 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1519 puts(" CC : "VERSION_CC"");
1520 puts(" CXX : "VERSION_CXX"");
1522 puts(" CFLAGS : "VERSION_CFLAGS"");
1523 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1527 puts("Build-time (default) variables:\n");
1528 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1529 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1530 printf(" stack size : %d\n", STACK_SIZE);
1532 #if defined(ENABLE_JRE_LAYOUT)
1533 // When we're building with JRE-layout, the default paths are the
1534 // same as the runtime paths.
1536 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1537 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1538 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1539 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1540 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1541 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1550 * Print run-time VM configuration.
1552 void VM::print_run_time_config()
1554 puts("Run-time variables:\n");
1555 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1556 printf(" initial heap size : %d\n", opt_heapstartsize);
1557 printf(" stack size : %d\n", opt_stacksize);
1559 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1560 printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1561 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1562 printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1565 printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1566 printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1572 /* vm_run **********************************************************************
1574 Runs the main-method of the passed class.
1576 *******************************************************************************/
1578 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1584 classinfo *mainclass;
1587 java_handle_objectarray_t *oa;
1593 // Prevent compiler warnings.
1596 #if !defined(NDEBUG)
1597 if (opt_CompileAll) {
1603 /* Get the main class plus it's arguments. */
1607 if (opt_index < vm_args->nOptions) {
1608 /* Get main-class argument. */
1610 mainname = vm_args->options[opt_index].optionString;
1612 /* If the main class argument is a jar file, put it into the
1615 if (opt_jar == true) {
1616 p = MNEW(char, strlen(mainname) + strlen("0"));
1618 strcpy(p, mainname);
1620 #if defined(ENABLE_JAVASE)
1621 VM::get_current()->get_properties().put("java.class.path", p);
1625 /* Replace dots with slashes in the class name. */
1627 for (unsigned int i = 0; i < strlen(mainname); i++)
1628 if (mainname[i] == '.')
1632 /* Build argument array. Move index to first argument. */
1636 oalength = vm_args->nOptions - opt_index;
1638 oa = builtin_anewarray(oalength, class_java_lang_String);
1640 for (int i = 0; i < oalength; i++) {
1641 option = vm_args->options[opt_index + i].optionString;
1643 u = utf_new_char(option);
1644 s = javastring_new(u);
1646 array_objectarray_element_set(oa, i, s);
1650 /* Do we have a main-class argument? */
1652 if (mainname == NULL)
1655 #if !defined(NDEBUG)
1656 if (opt_CompileMethod != NULL) {
1657 vm_compile_method(mainname);
1662 /* set return value to OK */
1666 if (opt_jar == true) {
1667 /* open jar file with java.util.jar.JarFile */
1669 mainname = vm_get_mainclass_from_jar(mainname);
1671 if (mainname == NULL)
1675 /* load the main class */
1677 mainutf = utf_new_char(mainname);
1679 #if defined(ENABLE_JAVAME_CLDC1_1)
1680 mainclass = load_class_bootstrap(mainutf);
1682 mainclass = load_class_from_sysloader(mainutf);
1685 /* error loading class */
1687 e = exceptions_get_and_clear_exception();
1689 if ((e != NULL) || (mainclass == NULL)) {
1690 exceptions_throw_noclassdeffounderror_cause(e);
1691 exceptions_print_stacktrace();
1695 if (!link_class(mainclass)) {
1696 exceptions_print_stacktrace();
1700 /* find the `main' method of the main class */
1702 m = class_resolveclassmethod(mainclass,
1703 utf_new_char("main"),
1704 utf_new_char("([Ljava/lang/String;)V"),
1705 class_java_lang_Object,
1708 if (exceptions_get_exception()) {
1709 exceptions_print_stacktrace();
1713 /* there is no main method or it isn't static */
1715 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1716 exceptions_clear_exception();
1717 exceptions_throw_nosuchmethoderror(mainclass,
1718 utf_new_char("main"),
1719 utf_new_char("([Ljava/lang/String;)V"));
1721 exceptions_print_stacktrace();
1725 #ifdef TYPEINFO_DEBUG_TEST
1726 /* test the typeinfo system */
1730 #if defined(ENABLE_JVMTI)
1731 jvmti_set_phase(JVMTI_PHASE_LIVE);
1734 /* set ThreadMXBean variables */
1736 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1737 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1739 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1740 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1741 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1742 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1743 #warning Move to C++
1745 /* start the main thread */
1747 (void) vm_call_method(m, NULL, oa);
1749 /* exception occurred? */
1751 if (exceptions_get_exception()) {
1752 exceptions_print_stacktrace();
1756 #if defined(ENABLE_THREADS)
1757 /* Detach the main thread so that it appears to have ended when
1758 the application's main method exits. */
1760 if (!thread_detach_current_thread())
1761 os::abort("vm_run: Could not detach main thread.");
1764 /* Destroy the JavaVM. */
1766 (void) vm_destroy(vm);
1774 /* vm_destroy ******************************************************************
1776 Unloads a Java VM and reclaims its resources.
1778 *******************************************************************************/
1780 int vm_destroy(JavaVM *vm)
1782 #if defined(ENABLE_THREADS)
1783 /* Create a a trivial new Java waiter thread called
1786 JavaVMAttachArgs args;
1788 args.name = (char*) "DestroyJavaVM";
1791 if (!thread_attach_current_thread(&args, false))
1794 /* Wait until we are the last non-daemon thread. */
1796 threads_join_all_threads();
1801 // _created = false;
1802 #warning Move to C++
1804 /* Everything is ok. */
1810 /* vm_exit *********************************************************************
1812 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1814 *******************************************************************************/
1816 void vm_exit(s4 status)
1820 /* signal that we are exiting */
1823 #warning Move to C++
1825 assert(class_java_lang_System);
1826 assert(class_java_lang_System->state & CLASS_LOADED);
1828 #if defined(ENABLE_JVMTI)
1829 if (jvmti || (dbgcom!=NULL)) {
1830 jvmti_set_phase(JVMTI_PHASE_DEAD);
1831 if (jvmti) jvmti_agentunload();
1835 if (!link_class(class_java_lang_System)) {
1836 exceptions_print_stacktrace();
1840 /* call java.lang.System.exit(I)V */
1842 m = class_resolveclassmethod(class_java_lang_System,
1843 utf_new_char("exit"),
1845 class_java_lang_Object,
1849 exceptions_print_stacktrace();
1853 /* call the exit function with passed exit status */
1855 (void) vm_call_method(m, NULL, status);
1857 /* If we had an exception, just ignore the exception and exit with
1860 vm_shutdown(status);
1864 /* vm_shutdown *****************************************************************
1866 Terminates the system immediately without freeing memory explicitly
1867 (to be used only for abnormal termination).
1869 *******************************************************************************/
1871 void vm_shutdown(s4 status)
1874 #if defined(ENABLE_STATISTICS)
1875 || opt_getcompilingtime || opt_stat
1879 log_text("CACAO terminated by shutdown");
1880 dolog("Exit status: %d\n", (s4) status);
1884 #if defined(ENABLE_JVMTI)
1885 /* terminate cacaodbgserver */
1887 mutex_lock(&dbgcomlock);
1889 mutex_unlock(&dbgcomlock);
1890 jvmti_cacaodbgserver_quit();
1898 /* vm_exit_handler *************************************************************
1900 The exit_handler function is called upon program termination.
1902 ATTENTION: Don't free system resources here! Some threads may still
1903 be running as this is called from VMRuntime.exit(). The OS does the
1906 *******************************************************************************/
1908 void vm_exit_handler(void)
1910 #if !defined(NDEBUG)
1912 class_showmethods(mainclass);
1914 if (showconstantpool)
1915 class_showconstantpool(mainclass);
1920 # if defined(ENABLE_PROFILING)
1922 profile_printstats();
1924 #endif /* !defined(NDEBUG) */
1926 #if defined(ENABLE_RT_TIMING)
1927 rt_timing_print_time_stats(stderr);
1930 #if defined(ENABLE_CYCLES_STATS)
1931 builtin_print_cycles_stats(stderr);
1932 stacktrace_print_cycles_stats(stderr);
1936 #if defined(ENABLE_STATISTICS)
1937 || opt_getcompilingtime || opt_stat
1941 log_text("CACAO terminated");
1943 #if defined(ENABLE_STATISTICS)
1946 #ifdef TYPECHECK_STATISTICS
1947 typecheck_print_statistics(get_logfile());
1951 if (opt_getcompilingtime)
1953 #endif /* defined(ENABLE_STATISTICS) */
1955 /* vm_print_profile(stderr);*/
1959 /* vm_abort_disassemble ********************************************************
1961 Prints an error message, disassemble the given code range (if
1962 enabled) and aborts the VM.
1965 pc.......PC to disassemble
1966 count....number of instructions to disassemble
1968 *******************************************************************************/
1970 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
1973 #if defined(ENABLE_DISASSEMBLER)
1977 /* Print debug message. */
1982 log_vprint(text, ap);
1989 #if SIZEOF_VOID_P == 8
1990 log_println("PC=0x%016lx", pc);
1992 log_println("PC=0x%08x", pc);
1995 #if defined(ENABLE_DISASSEMBLER)
1996 log_println("machine instructions at PC:");
1998 /* Disassemble the given number of instructions. */
2000 for (i = 0; i < count; i++)
2001 // FIXME disassinstr should use void*.
2002 pc = disassinstr((u1*) pc);
2005 os::abort("Aborting...");
2009 /* vm_get_mainclass_from_jar ***************************************************
2011 Gets the name of the main class from a JAR's manifest file.
2013 *******************************************************************************/
2015 static char *vm_get_mainclass_from_jar(char *mainname)
2022 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2025 exceptions_print_stacktrace();
2029 /* create JarFile object */
2034 exceptions_print_stacktrace();
2038 m = class_resolveclassmethod(c,
2040 utf_java_lang_String__void,
2041 class_java_lang_Object,
2045 exceptions_print_stacktrace();
2049 s = javastring_new_from_ascii(mainname);
2051 (void) vm_call_method(m, o, s);
2053 if (exceptions_get_exception()) {
2054 exceptions_print_stacktrace();
2058 /* get manifest object */
2060 m = class_resolveclassmethod(c,
2061 utf_new_char("getManifest"),
2062 utf_new_char("()Ljava/util/jar/Manifest;"),
2063 class_java_lang_Object,
2067 exceptions_print_stacktrace();
2071 o = vm_call_method(m, o);
2074 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2079 /* get Main Attributes */
2081 LLNI_class_get(o, c);
2083 m = class_resolveclassmethod(c,
2084 utf_new_char("getMainAttributes"),
2085 utf_new_char("()Ljava/util/jar/Attributes;"),
2086 class_java_lang_Object,
2090 exceptions_print_stacktrace();
2094 o = vm_call_method(m, o);
2097 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2102 /* get property Main-Class */
2104 LLNI_class_get(o, c);
2106 m = class_resolveclassmethod(c,
2107 utf_new_char("getValue"),
2108 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2109 class_java_lang_Object,
2113 exceptions_print_stacktrace();
2117 s = javastring_new_from_ascii("Main-Class");
2119 o = vm_call_method(m, o, s);
2122 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2123 fprintf(stderr, "%s\n", mainname);
2127 return javastring_tochar(o);
2131 /* vm_compile_all **************************************************************
2133 Compile all methods found in the bootclasspath.
2135 *******************************************************************************/
2137 #if !defined(NDEBUG)
2138 static void vm_compile_all(void)
2143 classcache_name_entry *nmen;
2144 classcache_class_entry *clsen;
2147 /* create all classes found in the bootclasspath */
2148 /* XXX currently only works with zip/jar's */
2150 loader_load_all_classes();
2152 /* link all classes */
2154 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2155 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2157 for (; nmen; nmen = nmen->hashlink) {
2158 /* iterate over all class entries */
2160 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2161 c = clsen->classobj;
2166 if (!(c->state & CLASS_LINKED)) {
2167 if (!link_class(c)) {
2168 fprintf(stderr, "Error linking: ");
2169 utf_fprint_printable_ascii_classname(stderr, c->name);
2170 fprintf(stderr, "\n");
2172 /* print out exception and cause */
2174 exceptions_print_current_exception();
2176 /* goto next class */
2182 /* compile all class methods */
2184 for (i = 0; i < c->methodscount; i++) {
2185 m = &(c->methods[i]);
2187 if (m->jcode != NULL) {
2188 if (!jit_compile(m)) {
2189 fprintf(stderr, "Error compiling: ");
2190 utf_fprint_printable_ascii_classname(stderr, c->name);
2191 fprintf(stderr, ".");
2192 utf_fprint_printable_ascii(stderr, m->name);
2193 utf_fprint_printable_ascii(stderr, m->descriptor);
2194 fprintf(stderr, "\n");
2196 /* print out exception and cause */
2198 exceptions_print_current_exception();
2206 #endif /* !defined(NDEBUG) */
2209 /* vm_compile_method ***********************************************************
2211 Compile a specific method.
2213 *******************************************************************************/
2215 #if !defined(NDEBUG)
2216 static void vm_compile_method(char* mainname)
2220 /* create, load and link the main class */
2222 mainclass = load_class_bootstrap(utf_new_char(mainname));
2224 if (mainclass == NULL)
2225 exceptions_print_stacktrace();
2227 if (!link_class(mainclass))
2228 exceptions_print_stacktrace();
2230 if (opt_CompileSignature != NULL) {
2231 m = class_resolveclassmethod(mainclass,
2232 utf_new_char(opt_CompileMethod),
2233 utf_new_char(opt_CompileSignature),
2238 m = class_resolveclassmethod(mainclass,
2239 utf_new_char(opt_CompileMethod),
2246 os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2247 opt_CompileMethod, opt_CompileSignature ? opt_CompileSignature : "");
2251 #endif /* !defined(NDEBUG) */
2254 /* vm_call_array ***************************************************************
2256 Calls a Java method with a variable number of arguments, passed via
2259 ATTENTION: This function has to be used outside the nativeworld.
2261 *******************************************************************************/
2263 #define VM_CALL_ARRAY(name, type) \
2264 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2270 assert(m->code != NULL); \
2272 md = m->parseddesc; \
2273 pv = m->code->entrypoint; \
2275 STATISTICS(count_calls_native_to_java++); \
2277 value = asm_vm_call_method##name(pv, array, md->memuse); \
2282 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2288 assert(m->code != NULL);
2291 pv = m->code->entrypoint;
2293 STATISTICS(count_calls_native_to_java++);
2295 o = asm_vm_call_method(pv, array, md->memuse);
2297 if (md->returntype.type == TYPE_VOID)
2300 return LLNI_WRAP(o);
2303 VM_CALL_ARRAY(_int, int32_t)
2304 VM_CALL_ARRAY(_long, int64_t)
2305 VM_CALL_ARRAY(_float, float)
2306 VM_CALL_ARRAY(_double, double)
2309 /* vm_call_method **************************************************************
2311 Calls a Java method with a variable number of arguments.
2313 *******************************************************************************/
2315 #define VM_CALL_METHOD(name, type) \
2316 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2322 value = vm_call_method##name##_valist(m, o, ap); \
2328 VM_CALL_METHOD(, java_handle_t *)
2329 VM_CALL_METHOD(_int, int32_t)
2330 VM_CALL_METHOD(_long, int64_t)
2331 VM_CALL_METHOD(_float, float)
2332 VM_CALL_METHOD(_double, double)
2335 /* vm_call_method_valist *******************************************************
2337 Calls a Java method with a variable number of arguments, passed via
2340 *******************************************************************************/
2342 #define VM_CALL_METHOD_VALIST(name, type) \
2343 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2349 if (m->code == NULL) \
2350 if (!jit_compile(m)) \
2353 THREAD_NATIVEWORLD_EXIT; \
2355 DumpMemoryArea dma; \
2357 array = argument_vmarray_from_valist(m, o, ap); \
2358 value = vm_call##name##_array(m, array); \
2360 THREAD_NATIVEWORLD_ENTER; \
2365 VM_CALL_METHOD_VALIST(, java_handle_t *)
2366 VM_CALL_METHOD_VALIST(_int, int32_t)
2367 VM_CALL_METHOD_VALIST(_long, int64_t)
2368 VM_CALL_METHOD_VALIST(_float, float)
2369 VM_CALL_METHOD_VALIST(_double, double)
2372 /* vm_call_method_jvalue *******************************************************
2374 Calls a Java method with a variable number of arguments, passed via
2377 *******************************************************************************/
2379 #define VM_CALL_METHOD_JVALUE(name, type) \
2380 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2381 const jvalue *args) \
2386 if (m->code == NULL) \
2387 if (!jit_compile(m)) \
2390 THREAD_NATIVEWORLD_EXIT; \
2392 DumpMemoryArea dma; \
2394 array = argument_vmarray_from_jvalue(m, o, args); \
2395 value = vm_call##name##_array(m, array); \
2397 THREAD_NATIVEWORLD_ENTER; \
2402 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2403 VM_CALL_METHOD_JVALUE(_int, int32_t)
2404 VM_CALL_METHOD_JVALUE(_long, int64_t)
2405 VM_CALL_METHOD_JVALUE(_float, float)
2406 VM_CALL_METHOD_JVALUE(_double, double)
2409 /* vm_call_method_objectarray **************************************************
2411 Calls a Java method with a variable number if arguments, passed via
2412 an objectarray of boxed values. Returns a boxed value.
2414 *******************************************************************************/
2416 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2417 java_handle_objectarray_t *params)
2420 java_handle_t *xptr;
2424 /* Prevent compiler warnings. */
2428 /* compile methods which are not yet compiled */
2430 if (m->code == NULL)
2431 if (!jit_compile(m))
2434 /* leave the nativeworld */
2436 THREAD_NATIVEWORLD_EXIT;
2438 // Create new dump memory area.
2441 /* Fill the argument array from a object-array. */
2443 array = argument_vmarray_from_objectarray(m, o, params);
2445 if (array == NULL) {
2446 /* enter the nativeworld again */
2448 THREAD_NATIVEWORLD_ENTER;
2450 exceptions_throw_illegalargumentexception();
2455 switch (m->parseddesc->returntype.primitivetype) {
2456 case PRIMITIVETYPE_VOID:
2457 value.a = vm_call_array(m, array);
2460 case PRIMITIVETYPE_BOOLEAN:
2461 case PRIMITIVETYPE_BYTE:
2462 case PRIMITIVETYPE_CHAR:
2463 case PRIMITIVETYPE_SHORT:
2464 case PRIMITIVETYPE_INT:
2465 value.i = vm_call_int_array(m, array);
2468 case PRIMITIVETYPE_LONG:
2469 value.l = vm_call_long_array(m, array);
2472 case PRIMITIVETYPE_FLOAT:
2473 value.f = vm_call_float_array(m, array);
2476 case PRIMITIVETYPE_DOUBLE:
2477 value.d = vm_call_double_array(m, array);
2481 ro = vm_call_array(m, array);
2485 os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2488 /* enter the nativeworld again */
2490 THREAD_NATIVEWORLD_ENTER;
2492 /* box the return value if necesarry */
2494 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2495 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2497 /* check for an exception */
2499 xptr = exceptions_get_exception();
2502 /* clear exception pointer, we are calling JIT code again */
2504 exceptions_clear_exception();
2506 exceptions_throw_invocationtargetexception(xptr);
2513 /* Legacy C interface *********************************************************/
2517 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2518 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2519 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2520 bool VM_is_created() { return VM::get_current()->is_created(); }
2521 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2523 void vm_abort(const char* text, ...)
2527 log_println("vm_abort: WARNING, port me to C++ and use os::abort() instead.");
2529 // Print the log message.
2533 log_vprint(text, ap);
2538 // Print a backtrace.
2539 os::print_backtrace();
2541 // Now abort the VM.
2549 * These are local overrides for various environment variables in Emacs.
2550 * Please do not remove this and leave it at the end of the file, where
2551 * Emacs will automagically detect them.
2552 * ---------------------------------------------------------------------
2555 * indent-tabs-mode: t
2559 * vim:noexpandtab:sw=4:ts=4: