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)
1583 #if !defined(NDEBUG)
1584 if (opt_CompileAll) {
1590 /* Get the main class or jar file argument. */
1592 char* mainname = NULL;
1594 if (opt_index < vm_args->nOptions) {
1595 /* Get main-class argument. */
1597 mainname = vm_args->options[opt_index].optionString;
1599 /* If the main class argument is a jar file, put it into the
1602 if (opt_jar == true) {
1603 char* p = MNEW(char, strlen(mainname) + strlen("0"));
1605 strcpy(p, mainname);
1607 #if defined(ENABLE_JAVASE)
1608 VM::get_current()->get_properties().put("java.class.path", p);
1612 /* Replace dots with slashes in the class name. */
1614 for (unsigned int i = 0; i < strlen(mainname); i++)
1615 if (mainname[i] == '.')
1619 /* Move index to first argument. */
1624 /* Do we have a main-class argument? */
1626 if (mainname == NULL)
1629 #if !defined(NDEBUG)
1630 if (opt_CompileMethod != NULL) {
1631 vm_compile_method(mainname);
1636 /* Build argument array. */
1638 int32_t oalength = vm_args->nOptions - opt_index;
1640 ObjectArray oa(oalength, class_java_lang_String);
1645 for (int i = 0; i < oalength; i++) {
1646 char* option = vm_args->options[opt_index + i].optionString;
1648 utf* u = utf_new_char(option);
1649 java_handle_t* s = javastring_new(u);
1651 oa.set_element(i, s);
1654 /* set return value to OK */
1658 if (opt_jar == true) {
1659 /* open jar file with java.util.jar.JarFile */
1661 mainname = vm_get_mainclass_from_jar(mainname);
1663 if (mainname == NULL)
1667 /* load the main class */
1669 utf* mainutf = utf_new_char(mainname);
1671 #if defined(ENABLE_JAVAME_CLDC1_1)
1672 classinfo* mainclass = load_class_bootstrap(mainutf);
1674 classinfo* mainclass = load_class_from_sysloader(mainutf);
1677 /* error loading class */
1679 java_handle_t* e = exceptions_get_and_clear_exception();
1681 if ((e != NULL) || (mainclass == NULL)) {
1682 exceptions_throw_noclassdeffounderror_cause(e);
1683 exceptions_print_stacktrace();
1687 if (!link_class(mainclass)) {
1688 exceptions_print_stacktrace();
1692 /* find the `main' method of the main class */
1694 m = class_resolveclassmethod(mainclass,
1695 utf_new_char("main"),
1696 utf_new_char("([Ljava/lang/String;)V"),
1697 class_java_lang_Object,
1700 if (exceptions_get_exception()) {
1701 exceptions_print_stacktrace();
1705 /* there is no main method or it isn't static */
1707 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1708 exceptions_clear_exception();
1709 exceptions_throw_nosuchmethoderror(mainclass,
1710 utf_new_char("main"),
1711 utf_new_char("([Ljava/lang/String;)V"));
1713 exceptions_print_stacktrace();
1717 #ifdef TYPEINFO_DEBUG_TEST
1718 /* test the typeinfo system */
1722 #if defined(ENABLE_JVMTI)
1723 jvmti_set_phase(JVMTI_PHASE_LIVE);
1726 /* set ThreadMXBean variables */
1728 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1729 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1731 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1732 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1733 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1734 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1735 #warning Move to C++
1737 /* start the main thread */
1739 (void) vm_call_method(m, NULL, oa.get_handle());
1741 /* exception occurred? */
1743 if (exceptions_get_exception()) {
1744 exceptions_print_stacktrace();
1748 #if defined(ENABLE_THREADS)
1749 /* Detach the main thread so that it appears to have ended when
1750 the application's main method exits. */
1752 if (!thread_detach_current_thread())
1753 os::abort("vm_run: Could not detach main thread.");
1756 /* Destroy the JavaVM. */
1758 (void) vm_destroy(vm);
1766 /* vm_destroy ******************************************************************
1768 Unloads a Java VM and reclaims its resources.
1770 *******************************************************************************/
1772 int vm_destroy(JavaVM *vm)
1774 #if defined(ENABLE_THREADS)
1775 /* Create a a trivial new Java waiter thread called
1778 JavaVMAttachArgs args;
1780 args.name = (char*) "DestroyJavaVM";
1783 if (!thread_attach_current_thread(&args, false))
1786 /* Wait until we are the last non-daemon thread. */
1788 threads_join_all_threads();
1793 // _created = false;
1794 #warning Move to C++
1796 /* Everything is ok. */
1802 /* vm_exit *********************************************************************
1804 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1806 *******************************************************************************/
1808 void vm_exit(s4 status)
1812 /* signal that we are exiting */
1815 #warning Move to C++
1817 assert(class_java_lang_System);
1818 assert(class_java_lang_System->state & CLASS_LOADED);
1820 #if defined(ENABLE_JVMTI)
1821 if (jvmti || (dbgcom!=NULL)) {
1822 jvmti_set_phase(JVMTI_PHASE_DEAD);
1823 if (jvmti) jvmti_agentunload();
1827 if (!link_class(class_java_lang_System)) {
1828 exceptions_print_stacktrace();
1832 /* call java.lang.System.exit(I)V */
1834 m = class_resolveclassmethod(class_java_lang_System,
1835 utf_new_char("exit"),
1837 class_java_lang_Object,
1841 exceptions_print_stacktrace();
1845 /* call the exit function with passed exit status */
1847 (void) vm_call_method(m, NULL, status);
1849 /* If we had an exception, just ignore the exception and exit with
1852 vm_shutdown(status);
1856 /* vm_shutdown *****************************************************************
1858 Terminates the system immediately without freeing memory explicitly
1859 (to be used only for abnormal termination).
1861 *******************************************************************************/
1863 void vm_shutdown(s4 status)
1866 #if defined(ENABLE_STATISTICS)
1867 || opt_getcompilingtime || opt_stat
1871 log_text("CACAO terminated by shutdown");
1872 dolog("Exit status: %d\n", (s4) status);
1876 #if defined(ENABLE_JVMTI)
1877 /* terminate cacaodbgserver */
1879 mutex_lock(&dbgcomlock);
1881 mutex_unlock(&dbgcomlock);
1882 jvmti_cacaodbgserver_quit();
1890 /* vm_exit_handler *************************************************************
1892 The exit_handler function is called upon program termination.
1894 ATTENTION: Don't free system resources here! Some threads may still
1895 be running as this is called from VMRuntime.exit(). The OS does the
1898 *******************************************************************************/
1900 void vm_exit_handler(void)
1902 #if !defined(NDEBUG)
1904 class_showmethods(mainclass);
1906 if (showconstantpool)
1907 class_showconstantpool(mainclass);
1912 # if defined(ENABLE_PROFILING)
1914 profile_printstats();
1916 #endif /* !defined(NDEBUG) */
1918 #if defined(ENABLE_RT_TIMING)
1919 rt_timing_print_time_stats(stderr);
1922 #if defined(ENABLE_CYCLES_STATS)
1923 builtin_print_cycles_stats(stderr);
1924 stacktrace_print_cycles_stats(stderr);
1928 #if defined(ENABLE_STATISTICS)
1929 || opt_getcompilingtime || opt_stat
1933 log_text("CACAO terminated");
1935 #if defined(ENABLE_STATISTICS)
1938 #ifdef TYPECHECK_STATISTICS
1939 typecheck_print_statistics(get_logfile());
1943 if (opt_getcompilingtime)
1945 #endif /* defined(ENABLE_STATISTICS) */
1947 /* vm_print_profile(stderr);*/
1951 /* vm_abort_disassemble ********************************************************
1953 Prints an error message, disassemble the given code range (if
1954 enabled) and aborts the VM.
1957 pc.......PC to disassemble
1958 count....number of instructions to disassemble
1960 *******************************************************************************/
1962 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
1965 #if defined(ENABLE_DISASSEMBLER)
1969 /* Print debug message. */
1974 log_vprint(text, ap);
1981 #if SIZEOF_VOID_P == 8
1982 log_println("PC=0x%016lx", pc);
1984 log_println("PC=0x%08x", pc);
1987 #if defined(ENABLE_DISASSEMBLER)
1988 log_println("machine instructions at PC:");
1990 /* Disassemble the given number of instructions. */
1992 for (i = 0; i < count; i++)
1993 // FIXME disassinstr should use void*.
1994 pc = disassinstr((u1*) pc);
1997 os::abort("Aborting...");
2001 /* vm_get_mainclass_from_jar ***************************************************
2003 Gets the name of the main class from a JAR's manifest file.
2005 *******************************************************************************/
2007 static char *vm_get_mainclass_from_jar(char *mainname)
2014 #if defined(ENABLE_JAVAME_CLDC1_1)
2015 c = load_class_bootstrap(utf_new_char("java/util/jar/JarFile"));
2017 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2021 exceptions_print_stacktrace();
2025 /* create JarFile object */
2030 exceptions_print_stacktrace();
2034 m = class_resolveclassmethod(c,
2036 utf_java_lang_String__void,
2037 class_java_lang_Object,
2041 exceptions_print_stacktrace();
2045 s = javastring_new_from_ascii(mainname);
2047 (void) vm_call_method(m, o, s);
2049 if (exceptions_get_exception()) {
2050 exceptions_print_stacktrace();
2054 /* get manifest object */
2056 m = class_resolveclassmethod(c,
2057 utf_new_char("getManifest"),
2058 utf_new_char("()Ljava/util/jar/Manifest;"),
2059 class_java_lang_Object,
2063 exceptions_print_stacktrace();
2067 o = vm_call_method(m, o);
2070 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2075 /* get Main Attributes */
2077 LLNI_class_get(o, c);
2079 m = class_resolveclassmethod(c,
2080 utf_new_char("getMainAttributes"),
2081 utf_new_char("()Ljava/util/jar/Attributes;"),
2082 class_java_lang_Object,
2086 exceptions_print_stacktrace();
2090 o = vm_call_method(m, o);
2093 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2098 /* get property Main-Class */
2100 LLNI_class_get(o, c);
2102 m = class_resolveclassmethod(c,
2103 utf_new_char("getValue"),
2104 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2105 class_java_lang_Object,
2109 exceptions_print_stacktrace();
2113 s = javastring_new_from_ascii("Main-Class");
2115 o = vm_call_method(m, o, s);
2118 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2119 fprintf(stderr, "%s\n", mainname);
2123 return javastring_tochar(o);
2127 /* vm_compile_all **************************************************************
2129 Compile all methods found in the bootclasspath.
2131 *******************************************************************************/
2133 #if !defined(NDEBUG)
2134 static void vm_compile_all(void)
2139 classcache_name_entry *nmen;
2140 classcache_class_entry *clsen;
2143 /* create all classes found in the bootclasspath */
2144 /* XXX currently only works with zip/jar's */
2146 loader_load_all_classes();
2148 /* link all classes */
2150 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2151 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2153 for (; nmen; nmen = nmen->hashlink) {
2154 /* iterate over all class entries */
2156 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2157 c = clsen->classobj;
2162 if (!(c->state & CLASS_LINKED)) {
2163 if (!link_class(c)) {
2164 fprintf(stderr, "Error linking: ");
2165 utf_fprint_printable_ascii_classname(stderr, c->name);
2166 fprintf(stderr, "\n");
2168 /* print out exception and cause */
2170 exceptions_print_current_exception();
2172 /* goto next class */
2178 /* compile all class methods */
2180 for (i = 0; i < c->methodscount; i++) {
2181 m = &(c->methods[i]);
2183 if (m->jcode != NULL) {
2184 if (!jit_compile(m)) {
2185 fprintf(stderr, "Error compiling: ");
2186 utf_fprint_printable_ascii_classname(stderr, c->name);
2187 fprintf(stderr, ".");
2188 utf_fprint_printable_ascii(stderr, m->name);
2189 utf_fprint_printable_ascii(stderr, m->descriptor);
2190 fprintf(stderr, "\n");
2192 /* print out exception and cause */
2194 exceptions_print_current_exception();
2202 #endif /* !defined(NDEBUG) */
2205 /* vm_compile_method ***********************************************************
2207 Compile a specific method.
2209 *******************************************************************************/
2211 #if !defined(NDEBUG)
2212 static void vm_compile_method(char* mainname)
2216 /* create, load and link the main class */
2218 mainclass = load_class_bootstrap(utf_new_char(mainname));
2220 if (mainclass == NULL)
2221 exceptions_print_stacktrace();
2223 if (!link_class(mainclass))
2224 exceptions_print_stacktrace();
2226 if (opt_CompileSignature != NULL) {
2227 m = class_resolveclassmethod(mainclass,
2228 utf_new_char(opt_CompileMethod),
2229 utf_new_char(opt_CompileSignature),
2234 m = class_resolveclassmethod(mainclass,
2235 utf_new_char(opt_CompileMethod),
2242 os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2243 opt_CompileMethod, opt_CompileSignature ? opt_CompileSignature : "");
2247 #endif /* !defined(NDEBUG) */
2250 /* vm_call_array ***************************************************************
2252 Calls a Java method with a variable number of arguments, passed via
2255 ATTENTION: This function has to be used outside the nativeworld.
2257 *******************************************************************************/
2259 #define VM_CALL_ARRAY(name, type) \
2260 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2266 assert(m->code != NULL); \
2268 md = m->parseddesc; \
2269 pv = m->code->entrypoint; \
2271 STATISTICS(count_calls_native_to_java++); \
2273 value = asm_vm_call_method##name(pv, array, md->memuse); \
2278 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2284 assert(m->code != NULL);
2287 pv = m->code->entrypoint;
2289 STATISTICS(count_calls_native_to_java++);
2291 o = asm_vm_call_method(pv, array, md->memuse);
2293 if (md->returntype.type == TYPE_VOID)
2296 return LLNI_WRAP(o);
2299 VM_CALL_ARRAY(_int, int32_t)
2300 VM_CALL_ARRAY(_long, int64_t)
2301 VM_CALL_ARRAY(_float, float)
2302 VM_CALL_ARRAY(_double, double)
2305 /* vm_call_method **************************************************************
2307 Calls a Java method with a variable number of arguments.
2309 *******************************************************************************/
2311 #define VM_CALL_METHOD(name, type) \
2312 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2318 value = vm_call_method##name##_valist(m, o, ap); \
2324 VM_CALL_METHOD(, java_handle_t *)
2325 VM_CALL_METHOD(_int, int32_t)
2326 VM_CALL_METHOD(_long, int64_t)
2327 VM_CALL_METHOD(_float, float)
2328 VM_CALL_METHOD(_double, double)
2331 /* vm_call_method_valist *******************************************************
2333 Calls a Java method with a variable number of arguments, passed via
2336 *******************************************************************************/
2338 #define VM_CALL_METHOD_VALIST(name, type) \
2339 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2345 if (m->code == NULL) \
2346 if (!jit_compile(m)) \
2349 THREAD_NATIVEWORLD_EXIT; \
2351 DumpMemoryArea dma; \
2353 array = argument_vmarray_from_valist(m, o, ap); \
2354 value = vm_call##name##_array(m, array); \
2356 THREAD_NATIVEWORLD_ENTER; \
2361 VM_CALL_METHOD_VALIST(, java_handle_t *)
2362 VM_CALL_METHOD_VALIST(_int, int32_t)
2363 VM_CALL_METHOD_VALIST(_long, int64_t)
2364 VM_CALL_METHOD_VALIST(_float, float)
2365 VM_CALL_METHOD_VALIST(_double, double)
2368 /* vm_call_method_jvalue *******************************************************
2370 Calls a Java method with a variable number of arguments, passed via
2373 *******************************************************************************/
2375 #define VM_CALL_METHOD_JVALUE(name, type) \
2376 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2377 const jvalue *args) \
2382 if (m->code == NULL) \
2383 if (!jit_compile(m)) \
2386 THREAD_NATIVEWORLD_EXIT; \
2388 DumpMemoryArea dma; \
2390 array = argument_vmarray_from_jvalue(m, o, args); \
2391 value = vm_call##name##_array(m, array); \
2393 THREAD_NATIVEWORLD_ENTER; \
2398 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2399 VM_CALL_METHOD_JVALUE(_int, int32_t)
2400 VM_CALL_METHOD_JVALUE(_long, int64_t)
2401 VM_CALL_METHOD_JVALUE(_float, float)
2402 VM_CALL_METHOD_JVALUE(_double, double)
2405 /* vm_call_method_objectarray **************************************************
2407 Calls a Java method with a variable number if arguments, passed via
2408 an objectarray of boxed values. Returns a boxed value.
2410 *******************************************************************************/
2412 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2413 java_handle_objectarray_t *params)
2416 java_handle_t *xptr;
2420 /* Prevent compiler warnings. */
2424 /* compile methods which are not yet compiled */
2426 if (m->code == NULL)
2427 if (!jit_compile(m))
2430 /* leave the nativeworld */
2432 THREAD_NATIVEWORLD_EXIT;
2434 // Create new dump memory area.
2437 /* Fill the argument array from a object-array. */
2439 array = argument_vmarray_from_objectarray(m, o, params);
2441 if (array == NULL) {
2442 /* enter the nativeworld again */
2444 THREAD_NATIVEWORLD_ENTER;
2446 exceptions_throw_illegalargumentexception();
2451 switch (m->parseddesc->returntype.primitivetype) {
2452 case PRIMITIVETYPE_VOID:
2453 value.a = vm_call_array(m, array);
2456 case PRIMITIVETYPE_BOOLEAN:
2457 case PRIMITIVETYPE_BYTE:
2458 case PRIMITIVETYPE_CHAR:
2459 case PRIMITIVETYPE_SHORT:
2460 case PRIMITIVETYPE_INT:
2461 value.i = vm_call_int_array(m, array);
2464 case PRIMITIVETYPE_LONG:
2465 value.l = vm_call_long_array(m, array);
2468 case PRIMITIVETYPE_FLOAT:
2469 value.f = vm_call_float_array(m, array);
2472 case PRIMITIVETYPE_DOUBLE:
2473 value.d = vm_call_double_array(m, array);
2477 ro = vm_call_array(m, array);
2481 os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2484 /* enter the nativeworld again */
2486 THREAD_NATIVEWORLD_ENTER;
2488 /* box the return value if necesarry */
2490 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2491 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2493 /* check for an exception */
2495 xptr = exceptions_get_exception();
2498 /* clear exception pointer, we are calling JIT code again */
2500 exceptions_clear_exception();
2502 exceptions_throw_invocationtargetexception(xptr);
2509 /* Legacy C interface *********************************************************/
2513 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2514 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2515 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2516 bool VM_is_created() { return VM::get_current()->is_created(); }
2517 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2519 void vm_abort(const char* text, ...)
2523 log_println("vm_abort: WARNING, port me to C++ and use os::abort() instead.");
2525 // Print the log message.
2529 log_vprint(text, ap);
2534 // Print a backtrace.
2535 os::print_backtrace();
2537 // Now abort the VM.
2545 * These are local overrides for various environment variables in Emacs.
2546 * Please do not remove this and leave it at the end of the file, where
2547 * Emacs will automagically detect them.
2548 * ---------------------------------------------------------------------
2551 * indent-tabs-mode: t
2555 * vim:noexpandtab:sw=4:ts=4: