1 /* src/vm/vm.cpp - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
41 #include "vm/jit/abi-asm.h"
43 #include "mm/codememory.h"
44 #include "mm/dumpmemory.hpp"
46 #include "mm/memory.h"
48 #include "native/jni.hpp"
49 #include "native/llni.h"
50 #include "native/localref.hpp"
51 #include "native/native.hpp"
53 #include "native/vm/nativevm.h"
55 #include "threads/lock.hpp"
56 #include "threads/thread.hpp"
58 #include "toolbox/logging.h"
60 #include "vm/array.hpp"
62 #if defined(ENABLE_ASSERTION)
63 #include "vm/assertion.hpp"
66 #include "vm/jit/builtin.hpp"
67 #include "vm/classcache.h"
68 #include "vm/exceptions.hpp"
69 #include "vm/finalizer.h"
70 #include "vm/global.h"
71 #include "vm/globals.hpp"
72 #include "vm/initialize.h"
73 #include "vm/options.h"
75 #include "vm/primitive.hpp"
76 #include "vm/properties.hpp"
77 #include "vm/signallocal.h"
78 #include "vm/statistics.h"
79 #include "vm/string.hpp"
80 #include "vm/suck.hpp"
83 #include "vm/jit/argument.hpp"
84 #include "vm/jit/asmpart.h"
85 #include "vm/jit/code.hpp"
87 #if defined(ENABLE_DISASSEMBLER)
88 # include "vm/jit/disass.h"
91 #include "vm/jit/jit.hpp"
92 #include "vm/jit/methodtree.h"
94 #if defined(ENABLE_PROFILING)
95 # include "vm/jit/optimizing/profile.h"
98 #include "vm/jit/optimizing/recompiler.hpp"
100 #if defined(ENABLE_PYTHON)
101 # include "vm/jit/python.h"
104 #include "vm/jit/trap.h"
106 #if defined(ENABLE_JVMTI)
107 # include "native/jvmti/cacaodbg.h"
110 #if defined(ENABLE_VMLOG)
111 #include <vmlog_cacao.h>
116 * This is _the_ VM instance.
121 /* global variables ***********************************************************/
123 s4 vms = 0; /* number of VMs created */
125 static classinfo *mainclass = NULL;
127 #if defined(ENABLE_INTRP)
128 u1 *intrp_main_stack = NULL;
132 /* define heap sizes **********************************************************/
134 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
135 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
136 #define STACK_SIZE 128 * 1024 /* default 64kB */
139 /* define command line options ************************************************/
173 /* Java non-standard options */
184 #if defined(ENABLE_PROFILING)
197 #if defined(ENABLE_STATISTICS)
214 #if defined(ENABLE_VERIFIER)
216 #if defined(TYPECHECK_VERBOSE)
219 #endif /* defined(ENABLE_VERIFIER) */
221 /* optimization options */
223 #if defined(ENABLE_LOOP)
227 #if defined(ENABLE_IFCONV)
231 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
235 #if defined(ENABLE_INTRP)
236 /* interpreter options */
255 #if defined(ENABLE_DEBUG_FILTER)
256 OPT_FILTER_VERBOSECALL_INCLUDE,
257 OPT_FILTER_VERBOSECALL_EXCLUDE,
258 OPT_FILTER_SHOW_METHOD,
265 opt_struct opts[] = {
266 { "foo", false, OPT_FOO },
270 { "jar", false, OPT_JAR },
272 { "d32", false, OPT_D32 },
273 { "d64", false, OPT_D64 },
274 { "client", false, OPT_IGNORE },
275 { "server", false, OPT_IGNORE },
276 { "jvm", false, OPT_IGNORE },
277 { "hotspot", false, OPT_IGNORE },
279 { "classpath", true, OPT_CLASSPATH },
280 { "cp", true, OPT_CLASSPATH },
281 { "D", true, OPT_D },
282 { "version", false, OPT_VERSION },
283 { "showversion", false, OPT_SHOWVERSION },
284 { "fullversion", false, OPT_FULLVERSION },
285 { "help", false, OPT_HELP },
286 { "?", false, OPT_HELP },
287 { "X", false, OPT_X },
288 { "XX:", true, OPT_XX },
290 { "ea:", true, OPT_EA },
291 { "da:", true, OPT_DA },
292 { "ea", false, OPT_EA_NOARG },
293 { "da", false, OPT_DA_NOARG },
295 { "enableassertions:", true, OPT_EA },
296 { "disableassertions:", true, OPT_DA },
297 { "enableassertions", false, OPT_EA_NOARG },
298 { "disableassertions", false, OPT_DA_NOARG },
300 { "esa", false, OPT_ESA },
301 { "enablesystemassertions", false, OPT_ESA },
302 { "dsa", false, OPT_DSA },
303 { "disablesystemassertions", false, OPT_DSA },
305 { "noasyncgc", false, OPT_IGNORE },
306 #if defined(ENABLE_VERIFIER)
307 { "noverify", false, OPT_NOVERIFY },
308 { "Xverify:none", false, OPT_NOVERIFY },
310 { "v", false, OPT_VERBOSE1 },
311 { "verbose:", true, OPT_VERBOSE },
313 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
314 { "verbosetc", false, OPT_VERBOSETC },
316 #if defined(__ALPHA__)
317 { "noieee", false, OPT_NOIEEE },
319 #if defined(ENABLE_STATISTICS)
320 { "time", false, OPT_TIME },
321 { "stat", false, OPT_STAT },
323 { "log", true, OPT_LOG },
324 { "c", true, OPT_CHECK },
325 { "l", false, OPT_LOAD },
328 { "all", false, OPT_ALL },
329 { "sig", true, OPT_SIGNATURE },
332 #if defined(ENABLE_LOOP)
333 { "oloop", false, OPT_OLOOP },
335 #if defined(ENABLE_IFCONV)
336 { "ifconv", false, OPT_IFCONV },
338 #if defined(ENABLE_LSRA)
339 { "lsra", false, OPT_LSRA },
341 #if defined(ENABLE_SSA)
342 { "lsra", true, OPT_LSRA },
345 #if defined(ENABLE_INTRP)
346 /* interpreter options */
348 { "trace", false, OPT_TRACE },
349 { "static-supers", true, OPT_STATIC_SUPERS },
350 { "no-dynamic", false, OPT_NO_DYNAMIC },
351 { "no-replication", false, OPT_NO_REPLICATION },
352 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
355 /* JVMTI Agent Command Line Options */
357 { "agentlib:", true, OPT_AGENTLIB },
358 { "agentpath:", true, OPT_AGENTPATH },
361 /* Java non-standard options */
363 { "Xjit", false, OPT_JIT },
364 { "Xint", false, OPT_INTRP },
365 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
366 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
367 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
368 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
371 { "Xdebug", false, OPT_DEBUG },
372 { "Xnoagent", false, OPT_NOAGENT },
373 { "Xrunjdwp", true, OPT_XRUNJDWP },
376 { "Xms", true, OPT_MS },
377 { "ms", true, OPT_MS },
378 { "Xmx", true, OPT_MX },
379 { "mx", true, OPT_MX },
380 { "Xss", true, OPT_SS },
381 { "ss", true, OPT_SS },
383 #if defined(ENABLE_PROFILING)
384 { "Xprof:", true, OPT_PROF_OPTION },
385 { "Xprof", false, OPT_PROF },
388 /* keep these at the end of the list */
391 { "m", true, OPT_METHOD },
394 { "s", true, OPT_SHOW },
395 { "debug-color", false, OPT_DEBUGCOLOR },
397 #if defined(ENABLE_DEBUG_FILTER)
398 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
399 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
400 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
407 /* usage ***********************************************************************
409 Prints the correct usage syntax to stdout.
411 *******************************************************************************/
415 puts("Usage: cacao [-options] classname [arguments]");
416 puts(" (to run a class file)");
417 puts(" or cacao [-options] -jar jarfile [arguments]");
418 puts(" (to run a standalone jar file)\n");
420 puts("where options include:");
421 puts(" -d32 use 32-bit data model if available");
422 puts(" -d64 use 64-bit data model if available");
423 puts(" -client compatibility (currently ignored)");
424 puts(" -server compatibility (currently ignored)");
425 puts(" -jvm compatibility (currently ignored)");
426 puts(" -hotspot compatibility (currently ignored)\n");
428 puts(" -cp <path> specify a path to look for classes");
429 puts(" -classpath <path> specify a path to look for classes");
430 puts(" -D<name>=<value> add an entry to the property list");
431 puts(" -verbose[:class|gc|jni] enable specific verbose output");
432 puts(" -version print product version and exit");
433 puts(" -fullversion print jpackage-compatible product version and exit");
434 puts(" -showversion print product version and continue");
435 puts(" -help, -? print this help message");
436 puts(" -X print help on non-standard Java options");
437 puts(" -XX print help on debugging options");
438 puts(" -ea[:<packagename>...|:<classname>]");
439 puts(" -enableassertions[:<packagename>...|:<classname>]");
440 puts(" enable assertions with specified granularity");
441 puts(" -da[:<packagename>...|:<classname>]");
442 puts(" -disableassertions[:<packagename>...|:<classname>]");
443 puts(" disable assertions with specified granularity");
444 puts(" -esa | -enablesystemassertions");
445 puts(" enable system assertions");
446 puts(" -dsa | -disablesystemassertions");
447 puts(" disable system assertions");
450 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
451 puts (" for jdwp help use: -agentlib:jdwp=help");
452 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
455 /* exit with error code */
461 static void Xusage(void)
463 #if defined(ENABLE_JIT)
464 puts(" -Xjit JIT mode execution (default)");
466 #if defined(ENABLE_INTRP)
467 puts(" -Xint interpreter mode execution");
469 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
470 puts(" value is set as bootstrap class path");
471 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
472 puts(" value is appended to the bootstrap class path");
473 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
474 puts(" value is prepended to the bootstrap class path");
475 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
476 puts(" value is used as Java core library, but the");
477 puts(" hardcoded VM interface classes are prepended");
478 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
479 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
480 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
482 #if defined(ENABLE_PROFILING)
483 puts(" -Xprof[:bb] collect and print profiling data");
486 #if defined(ENABLE_JVMTI)
487 /* -Xdebug option depend on gnu classpath JDWP options. options:
488 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
489 puts(" -Xdebug enable remote debugging\n");
490 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
491 puts(" enable remote debugging\n");
494 /* exit with error code */
501 static void XXusage(void)
503 puts(" -v write state-information");
505 puts(" -verbose:jit enable specific verbose output");
506 puts(" -debug-color colored output for ANSI terms");
508 #ifdef TYPECHECK_VERBOSE
509 puts(" -verbosetc write debug messages while typechecking");
511 #if defined(__ALPHA__)
512 puts(" -noieee don't use ieee compliant arithmetic");
514 #if defined(ENABLE_VERIFIER)
515 puts(" -noverify don't verify classfiles");
517 #if defined(ENABLE_STATISTICS)
518 puts(" -time measure the runtime");
519 puts(" -stat detailed compiler statistics");
521 puts(" -log logfile specify a name for the logfile");
522 puts(" -c(heck)b(ounds) don't check array bounds");
523 puts(" s(ync) don't check for synchronization");
524 #if defined(ENABLE_LOOP)
525 puts(" -oloop optimize array accesses in loops");
527 puts(" -l don't start the class after loading");
529 puts(" -all compile all methods, no execution");
530 puts(" -m compile only a specific method");
531 puts(" -sig specify signature for a specific method");
534 puts(" -s... show...");
535 puts(" (c)onstants the constant pool");
536 puts(" (m)ethods class fields and methods");
537 puts(" (u)tf the utf - hash");
538 puts(" (i)ntermediate intermediate representation");
539 #if defined(ENABLE_DISASSEMBLER)
540 puts(" (a)ssembler disassembled listing");
541 puts(" n(o)ps show NOPs in disassembler output");
543 puts(" (d)atasegment data segment listing");
545 #if defined(ENABLE_IFCONV)
546 puts(" -ifconv use if-conversion");
548 #if defined(ENABLE_LSRA)
549 puts(" -lsra use linear scan register allocation");
551 #if defined(ENABLE_SSA)
552 puts(" -lsra:... use linear scan register allocation (with SSA)");
553 puts(" (d)ead code elimination");
554 puts(" (c)opy propagation");
556 #if defined(ENABLE_DEBUG_FILTER)
557 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
558 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
559 puts(" -XXfm <regex> filter for show options");
561 /* exit with error code */
568 /* version *********************************************************************
570 Only prints cacao version information.
572 *******************************************************************************/
574 static void version(bool opt_exit)
576 puts("java version \""JAVA_VERSION"\"");
577 puts("CACAO version "VERSION"\n");
579 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
580 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
581 puts("This is free software; see the source for copying conditions. There is NO");
582 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
584 /* exit normally, if requested */
591 /* fullversion *****************************************************************
593 Prints a Sun compatible version information (required e.g. by
594 jpackage, www.jpackage.org).
596 *******************************************************************************/
598 static void fullversion(void)
600 puts("java full version \"cacao-"JAVA_VERSION"\"");
608 /* forward declarations *******************************************************/
610 static char *vm_get_mainclass_from_jar(char *mainstring);
612 static void vm_compile_all(void);
613 static void vm_compile_method(char* mainname);
618 * Implementation for JNI_CreateJavaVM. This function creates a VM
625 * @return true on success, false otherwise.
627 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
629 JavaVMInitArgs* _vm_args;
631 // Get the arguments for the new JVM.
632 _vm_args = (JavaVMInitArgs *) vm_args;
634 // Instantiate a new VM.
636 _vm = new VM(_vm_args);
638 catch (std::exception e) {
639 // FIXME How can we delete the resources allocated?
640 // /* release allocated memory */
641 // FREE(env, _Jv_JNIEnv);
642 // FREE(vm, _Jv_JavaVM);
649 // Return the values.
651 *p_vm = _vm->get_javavm();
652 *p_env = _vm->get_jnienv();
659 * C wrapper for VM::create.
662 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
664 return VM::create(p_vm, p_env, vm_args);
672 VM::VM(JavaVMInitArgs* vm_args)
674 // Very first thing to do: we are initializing.
675 _initializing = true;
677 // Make ourself globally visible.
678 // XXX Is this a good idea?
681 /* create and fill a JavaVM structure */
683 _javavm = new JavaVM();
685 #if defined(ENABLE_JNI)
686 _javavm->functions = &_Jv_JNIInvokeInterface;
689 /* get the VM and Env tables (must be set before vm_create) */
690 /* XXX JVMTI Agents needs a JavaVM */
692 _jnienv = new JNIEnv();
694 #if defined(ENABLE_JNI)
695 _jnienv->functions = &_Jv_JNINativeInterface;
698 /* actually create the JVM */
702 char *boot_class_path;
708 #if defined(ENABLE_JVMTI)
710 char *libname, *agentarg;
711 bool jdwp,agentbypath;
712 jdwp = agentbypath = false;
715 #if defined(ENABLE_JNI)
716 /* Check the JNI version requested. */
718 if (!jni_version_check(vm_args->version))
719 throw std::exception();
722 /* We only support 1 JVM instance. */
725 throw std::exception();
727 /* Install the exit handler. */
729 if (atexit(vm_exit_handler))
730 os::abort("atexit failed: %s\n", strerror(errno));
732 /* Set some options. */
739 opt_heapmaxsize = HEAP_MAXSIZE;
740 opt_heapstartsize = HEAP_STARTSIZE;
741 opt_stacksize = STACK_SIZE;
743 // First of all, parse the -XX options.
745 #if defined(ENABLE_VMLOG)
746 vmlog_cacao_init_options();
751 // After -XX options are parsed, print the build-time
752 // configuration, if requested.
754 print_build_time_config();
756 #if defined(ENABLE_VMLOG)
760 /* We need to check if the actual size of a java.lang.Class object
761 is smaller or equal than the assumption made in
764 #warning FIXME We need to check the size of java.lang.Class!!!
765 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
766 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
768 /* set the VM starttime */
770 _starttime = builtin_currenttimemillis();
772 #if defined(ENABLE_JVMTI)
773 /* initialize JVMTI related **********************************************/
777 /* iterate over all passed options */
779 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
793 #if SIZEOF_VOID_P == 8
794 puts("Running a 32-bit JVM is not supported on this platform.");
800 #if SIZEOF_VOID_P == 4
801 puts("Running a 64-bit JVM is not supported on this platform.");
807 /* Forget old classpath and set the argument as new
810 // FIXME Make class_path const char*.
811 class_path = (char*) _properties.get("java.class.path");
813 p = MNEW(char, strlen(opt_arg) + strlen("0"));
817 #if defined(ENABLE_JAVASE)
818 _properties.put("java.class.path", p);
821 MFREE(class_path, char, strlen(class_path));
825 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
826 if (opt_arg[i] == '=') {
828 _properties.put(opt_arg, opt_arg + i + 1);
833 /* if no '=' is given, just create an empty property */
835 _properties.put(opt_arg, "");
840 case OPT_BOOTCLASSPATH:
841 /* Forget default bootclasspath and set the argument as
842 new boot classpath. */
844 // FIXME Make boot_class_path const char*.
845 boot_class_path = (char*) _properties.get("sun.boot.class.path");
847 p = MNEW(char, strlen(opt_arg) + strlen("0"));
851 _properties.put("sun.boot.class.path", p);
852 _properties.put("java.boot.class.path", p);
854 MFREE(boot_class_path, char, strlen(boot_class_path));
857 case OPT_BOOTCLASSPATH_A:
858 /* Append 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 // XXX (char*) quick hack
866 p = (char*) MREALLOC(boot_class_path,
870 strlen(opt_arg) + strlen("0"));
875 _properties.put("sun.boot.class.path", p);
876 _properties.put("java.boot.class.path", p);
879 case OPT_BOOTCLASSPATH_P:
880 /* Prepend to bootclasspath. */
882 // FIXME Make boot_class_path const char*.
883 boot_class_path = (char*) _properties.get("sun.boot.class.path");
885 len = strlen(boot_class_path);
887 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
891 strcat(p, boot_class_path);
893 _properties.put("sun.boot.class.path", p);
894 _properties.put("java.boot.class.path", p);
896 MFREE(boot_class_path, char, len);
899 case OPT_BOOTCLASSPATH_C:
900 /* Use as Java core library, but prepend VM interface
903 // FIXME Make boot_class_path const char*.
904 boot_class_path = (char*) _properties.get("sun.boot.class.path");
907 strlen(CACAO_VM_ZIP) +
914 strcpy(p, CACAO_VM_ZIP);
918 _properties.put("sun.boot.class.path", p);
919 _properties.put("java.boot.class.path", p);
921 MFREE(boot_class_path, char, strlen(boot_class_path));
924 #if defined(ENABLE_JVMTI)
926 /* this option exists only for compatibility reasons */
930 /* I don't know yet what Xnoagent should do. This is only for
931 compatiblity with eclipse - motse */
940 strlen(CACAO_LIBDIR) +
941 strlen("/libjdwp.so=") +
945 agentarg = MNEW(char, len);
947 strcpy(agentarg, CACAO_LIBDIR);
948 strcat(agentarg, "/libjdwp.so=");
949 strcat(agentarg, &opt_arg[1]);
968 c = opt_arg[strlen(opt_arg) - 1];
970 if ((c == 'k') || (c == 'K')) {
971 j = atoi(opt_arg) * 1024;
973 } else if ((c == 'm') || (c == 'M')) {
974 j = atoi(opt_arg) * 1024 * 1024;
981 else if (opt == OPT_MS)
982 opt_heapstartsize = j;
993 if (strcmp("class", opt_arg) == 0) {
994 opt_verboseclass = true;
996 else if (strcmp("gc", opt_arg) == 0) {
997 opt_verbosegc = true;
999 else if (strcmp("jni", opt_arg) == 0) {
1000 opt_verbosejni = true;
1002 #if !defined(NDEBUG)
1003 else if (strcmp("jit", opt_arg) == 0) {
1007 compileverbose = true;
1011 printf("Unknown -verbose option: %s\n", opt_arg);
1016 case OPT_DEBUGCOLOR:
1017 opt_debugcolor = true;
1020 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1022 opt_typecheckverbose = true;
1031 case OPT_FULLVERSION:
1035 case OPT_SHOWVERSION:
1043 #if defined(ENABLE_VERIFIER)
1049 #if defined(ENABLE_STATISTICS)
1051 opt_getcompilingtime = true;
1052 opt_getloadingtime = true;
1065 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1066 switch (opt_arg[i]) {
1068 checkbounds = false;
1081 makeinitializations = false;
1084 #if !defined(NDEBUG)
1088 makeinitializations = false;
1093 opt_method = opt_arg;
1094 makeinitializations = false;
1098 opt_signature = opt_arg;
1102 case OPT_SHOW: /* Display options */
1103 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1104 switch (opt_arg[i]) {
1106 showconstantpool = true;
1118 opt_showintermediate = true;
1119 compileverbose = true;
1122 #if defined(ENABLE_DISASSEMBLER)
1124 opt_showdisassemble = true;
1125 compileverbose = true;
1130 opt_showddatasegment = true;
1139 #if defined(ENABLE_LOOP)
1145 #if defined(ENABLE_IFCONV)
1151 #if defined(ENABLE_LSRA)
1156 #if defined(ENABLE_SSA)
1159 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1160 switch (opt_arg[i]) {
1188 /* Already parsed. */
1192 #if defined(ENABLE_ASSERTION)
1193 assertion_ea_da(opt_arg, true);
1198 #if defined(ENABLE_ASSERTION)
1199 assertion_ea_da(opt_arg, false);
1204 #if defined(ENABLE_ASSERTION)
1205 assertion_user_enabled = true;
1210 #if defined(ENABLE_ASSERTION)
1211 assertion_user_enabled = false;
1216 #if defined(ENABLE_ASSERTION)
1217 assertion_system_enabled = true;
1222 #if defined(ENABLE_ASSERTION)
1223 assertion_system_enabled = false;
1227 #if defined(ENABLE_PROFILING)
1228 case OPT_PROF_OPTION:
1229 /* use <= to get the last \0 too */
1231 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1232 if (opt_arg[i] == ',')
1235 if (opt_arg[i] == '\0') {
1236 if (strcmp("bb", opt_arg + j) == 0)
1240 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1244 /* set k to next char */
1257 #if defined(ENABLE_JIT)
1260 printf("-Xjit option not enabled.\n");
1266 #if defined(ENABLE_INTRP)
1269 printf("-Xint option not enabled.\n");
1274 #if defined(ENABLE_INTRP)
1275 case OPT_STATIC_SUPERS:
1276 opt_static_supers = atoi(opt_arg);
1279 case OPT_NO_DYNAMIC:
1280 opt_no_dynamic = true;
1283 case OPT_NO_REPLICATION:
1284 opt_no_replication = true;
1287 case OPT_NO_QUICKSUPER:
1288 opt_no_quicksuper = true;
1296 #if defined(ENABLE_DEBUG_FILTER)
1297 case OPT_FILTER_VERBOSECALL_INCLUDE:
1298 opt_filter_verbosecall_include = opt_arg;
1301 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1302 opt_filter_verbosecall_exclude = opt_arg;
1305 case OPT_FILTER_SHOW_METHOD:
1306 opt_filter_show_method = opt_arg;
1311 printf("Unknown option: %s\n",
1312 vm_args->options[opt_index].optionString);
1317 // Print the preliminary run-time VM configuration after options
1319 if (opt_PrintConfig)
1320 print_run_time_config();
1322 #if defined(ENABLE_JVMTI)
1324 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1325 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1328 MFREE(agentarg, char, strlen(agentarg));
1330 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1334 /* initialize the garbage collector */
1336 gc_init(opt_heapmaxsize, opt_heapstartsize);
1338 #if defined(ENABLE_THREADS)
1339 /* AFTER: gc_init */
1345 /* install architecture dependent signal handlers */
1348 os::abort("vm_create: signal_init failed");
1350 #if defined(ENABLE_INTRP)
1351 /* Allocate main thread stack on the Java heap. */
1354 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1355 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1359 /* AFTER: threads_preinit */
1362 os::abort("vm_create: string_init failed");
1364 /* AFTER: threads_preinit */
1368 /* AFTER: thread_preinit */
1371 os::abort("vm_create: suck_init failed");
1373 suck_add_from_property("java.endorsed.dirs");
1375 /* Now we have all options handled and we can print the version
1378 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1383 /* AFTER: utf8_init */
1385 // FIXME Make boot_class_path const char*.
1386 boot_class_path = (char*) _properties.get("sun.boot.class.path");
1387 suck_add(boot_class_path);
1389 /* initialize the classcache hashtable stuff: lock, hashtable
1390 (must be done _after_ threads_preinit) */
1392 if (!classcache_init())
1393 os::abort("vm_create: classcache_init failed");
1395 /* Initialize the code memory management. */
1396 /* AFTER: threads_preinit */
1400 /* initialize the finalizer stuff (must be done _after_
1403 if (!finalizer_init())
1404 os::abort("vm_create: finalizer_init failed");
1406 /* Initialize the JIT compiler. */
1412 #if defined(ENABLE_PYTHON)
1416 /* AFTER: utf8_init, classcache_init */
1421 // AFTER: loader_preinit, linker_preinit
1422 Primitive::initialize_table();
1427 // AFTER: loader_init, linker_init
1428 Primitive::post_initialize_table();
1431 #if defined(ENABLE_JIT)
1435 if (!builtin_init())
1436 os::abort("vm_create: builtin_init failed");
1438 /* Initialize the native subsystem. */
1439 /* BEFORE: threads_init */
1442 os::abort("vm_create: native_init failed");
1444 /* Register the native methods implemented in the VM. */
1445 /* BEFORE: threads_init */
1449 #if defined(ENABLE_JNI)
1450 /* Initialize the JNI subsystem (must be done _before_
1451 threads_init, as threads_init can call JNI methods
1452 (e.g. NewGlobalRef). */
1455 os::abort("vm_create: jni_init failed");
1458 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1459 /* Initialize the local reference table for the main thread. */
1460 /* BEFORE: threads_init */
1462 if (!localref_table_init())
1463 os::abort("vm_create: localref_table_init failed");
1466 /* Iinitialize some important system classes. */
1467 /* BEFORE: threads_init */
1471 #if defined(ENABLE_THREADS)
1475 /* Initialize the native VM subsystem. */
1476 /* AFTER: threads_init (at least for SUN's classes) */
1480 #if defined(ENABLE_PROFILING)
1481 /* initialize profiling */
1483 if (!profile_init())
1484 os::abort("vm_create: profile_init failed");
1487 #if defined(ENABLE_THREADS)
1488 /* start the signal handler thread */
1490 #if defined(__LINUX__)
1491 /* XXX Remove for exact-GC. */
1492 if (threads_pthreads_implementation_nptl)
1494 if (!signal_start_thread())
1495 os::abort("vm_create: signal_start_thread failed");
1497 /* finally, start the finalizer thread */
1499 if (!finalizer_start_thread())
1500 os::abort("vm_create: finalizer_start_thread failed");
1502 # if !defined(NDEBUG)
1503 /* start the memory profiling thread */
1505 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1506 if (!memory_start_thread())
1507 os::abort("vm_create: memory_start_thread failed");
1510 // Start the recompilation thread (must be done before the
1511 // profiling thread).
1512 // FIXME Only works for one recompiler.
1513 _recompiler.start();
1515 # if defined(ENABLE_PROFILING)
1516 /* start the profile sampling thread */
1519 /* if (!profile_start_thread()) */
1520 /* os::abort("vm_create: profile_start_thread failed"); */
1524 #if defined(ENABLE_JVMTI)
1525 # if defined(ENABLE_GC_CACAO)
1526 /* XXX this will not work with the new indirection cells for classloaders!!! */
1530 /* add agent library to native library hashtable */
1531 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1535 /* Increment the number of VMs. */
1539 // Initialization is done, VM is created.
1541 _initializing = false;
1543 // Print the run-time VM configuration after all stuff is set and
1544 // the VM is initialized.
1545 if (opt_PrintConfig)
1546 print_run_time_config();
1551 * Print build-time (default) VM configuration.
1553 void VM::print_build_time_config(void)
1555 puts("CACAO "VERSION" configure/build options:");
1557 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1558 #if defined(__VERSION__)
1559 puts(" CC : "VERSION_CC" ("__VERSION__")");
1560 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1562 puts(" CC : "VERSION_CC"");
1563 puts(" CXX : "VERSION_CXX"");
1565 puts(" CFLAGS : "VERSION_CFLAGS"");
1566 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1570 puts("Build-time (default) variables:\n");
1571 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1572 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1573 printf(" stack size : %d\n", STACK_SIZE);
1575 #if defined(ENABLE_JRE_LAYOUT)
1576 // When we're building with JRE-layout, the default paths are the
1577 // same as the runtime paths.
1579 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1580 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1581 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1582 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1583 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1584 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1593 * Print run-time VM configuration.
1595 void VM::print_run_time_config()
1597 puts("Run-time variables:\n");
1598 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1599 printf(" initial heap size : %d\n", opt_heapstartsize);
1600 printf(" stack size : %d\n", opt_stacksize);
1602 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1603 printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1604 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1605 printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1608 printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1609 printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1615 /* vm_run **********************************************************************
1617 Runs the main-method of the passed class.
1619 *******************************************************************************/
1621 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1627 classinfo *mainclass;
1630 java_handle_objectarray_t *oa;
1636 // Prevent compiler warnings.
1639 #if !defined(NDEBUG)
1646 /* Get the main class plus it's arguments. */
1650 if (opt_index < vm_args->nOptions) {
1651 /* Get main-class argument. */
1653 mainname = vm_args->options[opt_index].optionString;
1655 /* If the main class argument is a jar file, put it into the
1658 if (opt_jar == true) {
1659 p = MNEW(char, strlen(mainname) + strlen("0"));
1661 strcpy(p, mainname);
1663 #if defined(ENABLE_JAVASE)
1664 VM::get_current()->get_properties().put("java.class.path", p);
1668 /* Replace dots with slashes in the class name. */
1670 for (unsigned int i = 0; i < strlen(mainname); i++)
1671 if (mainname[i] == '.')
1675 /* Build argument array. Move index to first argument. */
1679 oalength = vm_args->nOptions - opt_index;
1681 oa = builtin_anewarray(oalength, class_java_lang_String);
1683 for (int i = 0; i < oalength; i++) {
1684 option = vm_args->options[opt_index + i].optionString;
1686 u = utf_new_char(option);
1687 s = javastring_new(u);
1689 array_objectarray_element_set(oa, i, s);
1693 /* Do we have a main-class argument? */
1695 if (mainname == NULL)
1698 #if !defined(NDEBUG)
1699 if (opt_method != NULL) {
1700 vm_compile_method(mainname);
1705 /* set return value to OK */
1709 if (opt_jar == true) {
1710 /* open jar file with java.util.jar.JarFile */
1712 mainname = vm_get_mainclass_from_jar(mainname);
1714 if (mainname == NULL)
1718 /* load the main class */
1720 mainutf = utf_new_char(mainname);
1722 #if defined(ENABLE_JAVAME_CLDC1_1)
1723 mainclass = load_class_bootstrap(mainutf);
1725 mainclass = load_class_from_sysloader(mainutf);
1728 /* error loading class */
1730 e = exceptions_get_and_clear_exception();
1732 if ((e != NULL) || (mainclass == NULL)) {
1733 exceptions_throw_noclassdeffounderror_cause(e);
1734 exceptions_print_stacktrace();
1738 if (!link_class(mainclass)) {
1739 exceptions_print_stacktrace();
1743 /* find the `main' method of the main class */
1745 m = class_resolveclassmethod(mainclass,
1746 utf_new_char("main"),
1747 utf_new_char("([Ljava/lang/String;)V"),
1748 class_java_lang_Object,
1751 if (exceptions_get_exception()) {
1752 exceptions_print_stacktrace();
1756 /* there is no main method or it isn't static */
1758 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1759 exceptions_clear_exception();
1760 exceptions_throw_nosuchmethoderror(mainclass,
1761 utf_new_char("main"),
1762 utf_new_char("([Ljava/lang/String;)V"));
1764 exceptions_print_stacktrace();
1768 #ifdef TYPEINFO_DEBUG_TEST
1769 /* test the typeinfo system */
1773 #if defined(ENABLE_JVMTI)
1774 jvmti_set_phase(JVMTI_PHASE_LIVE);
1777 /* set ThreadMXBean variables */
1779 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1780 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1782 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1783 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1784 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1785 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1786 #warning Move to C++
1788 /* start the main thread */
1790 (void) vm_call_method(m, NULL, oa);
1792 /* exception occurred? */
1794 if (exceptions_get_exception()) {
1795 exceptions_print_stacktrace();
1799 #if defined(ENABLE_THREADS)
1800 /* Detach the main thread so that it appears to have ended when
1801 the application's main method exits. */
1803 if (!thread_detach_current_thread())
1804 os::abort("vm_run: Could not detach main thread.");
1807 /* Destroy the JavaVM. */
1809 (void) vm_destroy(vm);
1817 /* vm_destroy ******************************************************************
1819 Unloads a Java VM and reclaims its resources.
1821 *******************************************************************************/
1823 int vm_destroy(JavaVM *vm)
1825 #if defined(ENABLE_THREADS)
1826 /* Create a a trivial new Java waiter thread called
1829 JavaVMAttachArgs args;
1831 args.name = (char*) "DestroyJavaVM";
1834 if (!thread_attach_current_thread(&args, false))
1837 /* Wait until we are the last non-daemon thread. */
1839 threads_join_all_threads();
1844 // _created = false;
1845 #warning Move to C++
1847 /* Everything is ok. */
1853 /* vm_exit *********************************************************************
1855 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1857 *******************************************************************************/
1859 void vm_exit(s4 status)
1863 /* signal that we are exiting */
1866 #warning Move to C++
1868 assert(class_java_lang_System);
1869 assert(class_java_lang_System->state & CLASS_LOADED);
1871 #if defined(ENABLE_JVMTI)
1872 if (jvmti || (dbgcom!=NULL)) {
1873 jvmti_set_phase(JVMTI_PHASE_DEAD);
1874 if (jvmti) jvmti_agentunload();
1878 if (!link_class(class_java_lang_System)) {
1879 exceptions_print_stacktrace();
1883 /* call java.lang.System.exit(I)V */
1885 m = class_resolveclassmethod(class_java_lang_System,
1886 utf_new_char("exit"),
1888 class_java_lang_Object,
1892 exceptions_print_stacktrace();
1896 /* call the exit function with passed exit status */
1898 (void) vm_call_method(m, NULL, status);
1900 /* If we had an exception, just ignore the exception and exit with
1903 vm_shutdown(status);
1907 /* vm_shutdown *****************************************************************
1909 Terminates the system immediately without freeing memory explicitly
1910 (to be used only for abnormal termination).
1912 *******************************************************************************/
1914 void vm_shutdown(s4 status)
1917 #if defined(ENABLE_STATISTICS)
1918 || opt_getcompilingtime || opt_stat
1922 log_text("CACAO terminated by shutdown");
1923 dolog("Exit status: %d\n", (s4) status);
1927 #if defined(ENABLE_JVMTI)
1928 /* terminate cacaodbgserver */
1930 mutex_lock(&dbgcomlock);
1932 mutex_unlock(&dbgcomlock);
1933 jvmti_cacaodbgserver_quit();
1941 /* vm_exit_handler *************************************************************
1943 The exit_handler function is called upon program termination.
1945 ATTENTION: Don't free system resources here! Some threads may still
1946 be running as this is called from VMRuntime.exit(). The OS does the
1949 *******************************************************************************/
1951 void vm_exit_handler(void)
1953 #if !defined(NDEBUG)
1955 class_showmethods(mainclass);
1957 if (showconstantpool)
1958 class_showconstantpool(mainclass);
1963 # if defined(ENABLE_PROFILING)
1965 profile_printstats();
1967 #endif /* !defined(NDEBUG) */
1969 #if defined(ENABLE_RT_TIMING)
1970 rt_timing_print_time_stats(stderr);
1973 #if defined(ENABLE_CYCLES_STATS)
1974 builtin_print_cycles_stats(stderr);
1975 stacktrace_print_cycles_stats(stderr);
1979 #if defined(ENABLE_STATISTICS)
1980 || opt_getcompilingtime || opt_stat
1984 log_text("CACAO terminated");
1986 #if defined(ENABLE_STATISTICS)
1989 #ifdef TYPECHECK_STATISTICS
1990 typecheck_print_statistics(get_logfile());
1994 if (opt_getcompilingtime)
1996 #endif /* defined(ENABLE_STATISTICS) */
1998 /* vm_print_profile(stderr);*/
2002 /* vm_abort_disassemble ********************************************************
2004 Prints an error message, disassemble the given code range (if
2005 enabled) and aborts the VM.
2008 pc.......PC to disassemble
2009 count....number of instructions to disassemble
2011 *******************************************************************************/
2013 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2016 #if defined(ENABLE_DISASSEMBLER)
2020 /* Print debug message. */
2025 log_vprint(text, ap);
2032 #if SIZEOF_VOID_P == 8
2033 log_println("PC=0x%016lx", pc);
2035 log_println("PC=0x%08x", pc);
2038 #if defined(ENABLE_DISASSEMBLER)
2039 log_println("machine instructions at PC:");
2041 /* Disassemble the given number of instructions. */
2043 for (i = 0; i < count; i++)
2044 // FIXME disassinstr should use void*.
2045 pc = disassinstr((u1*) pc);
2048 os::abort("Aborting...");
2052 /* vm_get_mainclass_from_jar ***************************************************
2054 Gets the name of the main class from a JAR's manifest file.
2056 *******************************************************************************/
2058 static char *vm_get_mainclass_from_jar(char *mainname)
2065 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2068 exceptions_print_stacktrace();
2072 /* create JarFile object */
2077 exceptions_print_stacktrace();
2081 m = class_resolveclassmethod(c,
2083 utf_java_lang_String__void,
2084 class_java_lang_Object,
2088 exceptions_print_stacktrace();
2092 s = javastring_new_from_ascii(mainname);
2094 (void) vm_call_method(m, o, s);
2096 if (exceptions_get_exception()) {
2097 exceptions_print_stacktrace();
2101 /* get manifest object */
2103 m = class_resolveclassmethod(c,
2104 utf_new_char("getManifest"),
2105 utf_new_char("()Ljava/util/jar/Manifest;"),
2106 class_java_lang_Object,
2110 exceptions_print_stacktrace();
2114 o = vm_call_method(m, o);
2117 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2122 /* get Main Attributes */
2124 LLNI_class_get(o, c);
2126 m = class_resolveclassmethod(c,
2127 utf_new_char("getMainAttributes"),
2128 utf_new_char("()Ljava/util/jar/Attributes;"),
2129 class_java_lang_Object,
2133 exceptions_print_stacktrace();
2137 o = vm_call_method(m, o);
2140 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2145 /* get property Main-Class */
2147 LLNI_class_get(o, c);
2149 m = class_resolveclassmethod(c,
2150 utf_new_char("getValue"),
2151 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2152 class_java_lang_Object,
2156 exceptions_print_stacktrace();
2160 s = javastring_new_from_ascii("Main-Class");
2162 o = vm_call_method(m, o, s);
2165 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2166 fprintf(stderr, "%s\n", mainname);
2170 return javastring_tochar(o);
2174 /* vm_compile_all **************************************************************
2176 Compile all methods found in the bootclasspath.
2178 *******************************************************************************/
2180 #if !defined(NDEBUG)
2181 static void vm_compile_all(void)
2186 classcache_name_entry *nmen;
2187 classcache_class_entry *clsen;
2190 /* create all classes found in the bootclasspath */
2191 /* XXX currently only works with zip/jar's */
2193 loader_load_all_classes();
2195 /* link all classes */
2197 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2198 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2200 for (; nmen; nmen = nmen->hashlink) {
2201 /* iterate over all class entries */
2203 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2204 c = clsen->classobj;
2209 if (!(c->state & CLASS_LINKED)) {
2210 if (!link_class(c)) {
2211 fprintf(stderr, "Error linking: ");
2212 utf_fprint_printable_ascii_classname(stderr, c->name);
2213 fprintf(stderr, "\n");
2215 /* print out exception and cause */
2217 exceptions_print_current_exception();
2219 /* goto next class */
2225 /* compile all class methods */
2227 for (i = 0; i < c->methodscount; i++) {
2228 m = &(c->methods[i]);
2230 if (m->jcode != NULL) {
2231 if (!jit_compile(m)) {
2232 fprintf(stderr, "Error compiling: ");
2233 utf_fprint_printable_ascii_classname(stderr, c->name);
2234 fprintf(stderr, ".");
2235 utf_fprint_printable_ascii(stderr, m->name);
2236 utf_fprint_printable_ascii(stderr, m->descriptor);
2237 fprintf(stderr, "\n");
2239 /* print out exception and cause */
2241 exceptions_print_current_exception();
2249 #endif /* !defined(NDEBUG) */
2252 /* vm_compile_method ***********************************************************
2254 Compile a specific method.
2256 *******************************************************************************/
2258 #if !defined(NDEBUG)
2259 static void vm_compile_method(char* mainname)
2263 /* create, load and link the main class */
2265 mainclass = load_class_bootstrap(utf_new_char(mainname));
2267 if (mainclass == NULL)
2268 exceptions_print_stacktrace();
2270 if (!link_class(mainclass))
2271 exceptions_print_stacktrace();
2273 if (opt_signature != NULL) {
2274 m = class_resolveclassmethod(mainclass,
2275 utf_new_char(opt_method),
2276 utf_new_char(opt_signature),
2281 m = class_resolveclassmethod(mainclass,
2282 utf_new_char(opt_method),
2289 os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2290 opt_method, opt_signature ? opt_signature : "");
2294 #endif /* !defined(NDEBUG) */
2297 /* vm_call_array ***************************************************************
2299 Calls a Java method with a variable number of arguments, passed via
2302 ATTENTION: This function has to be used outside the nativeworld.
2304 *******************************************************************************/
2306 #define VM_CALL_ARRAY(name, type) \
2307 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2313 assert(m->code != NULL); \
2315 md = m->parseddesc; \
2316 pv = m->code->entrypoint; \
2318 STATISTICS(count_calls_native_to_java++); \
2320 value = asm_vm_call_method##name(pv, array, md->memuse); \
2325 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2331 assert(m->code != NULL);
2334 pv = m->code->entrypoint;
2336 STATISTICS(count_calls_native_to_java++);
2338 o = asm_vm_call_method(pv, array, md->memuse);
2340 if (md->returntype.type == TYPE_VOID)
2343 return LLNI_WRAP(o);
2346 VM_CALL_ARRAY(_int, int32_t)
2347 VM_CALL_ARRAY(_long, int64_t)
2348 VM_CALL_ARRAY(_float, float)
2349 VM_CALL_ARRAY(_double, double)
2352 /* vm_call_method **************************************************************
2354 Calls a Java method with a variable number of arguments.
2356 *******************************************************************************/
2358 #define VM_CALL_METHOD(name, type) \
2359 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2365 value = vm_call_method##name##_valist(m, o, ap); \
2371 VM_CALL_METHOD(, java_handle_t *)
2372 VM_CALL_METHOD(_int, int32_t)
2373 VM_CALL_METHOD(_long, int64_t)
2374 VM_CALL_METHOD(_float, float)
2375 VM_CALL_METHOD(_double, double)
2378 /* vm_call_method_valist *******************************************************
2380 Calls a Java method with a variable number of arguments, passed via
2383 *******************************************************************************/
2385 #define VM_CALL_METHOD_VALIST(name, type) \
2386 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2392 if (m->code == NULL) \
2393 if (!jit_compile(m)) \
2396 THREAD_NATIVEWORLD_EXIT; \
2398 DumpMemoryArea dma; \
2400 array = argument_vmarray_from_valist(m, o, ap); \
2401 value = vm_call##name##_array(m, array); \
2403 THREAD_NATIVEWORLD_ENTER; \
2408 VM_CALL_METHOD_VALIST(, java_handle_t *)
2409 VM_CALL_METHOD_VALIST(_int, int32_t)
2410 VM_CALL_METHOD_VALIST(_long, int64_t)
2411 VM_CALL_METHOD_VALIST(_float, float)
2412 VM_CALL_METHOD_VALIST(_double, double)
2415 /* vm_call_method_jvalue *******************************************************
2417 Calls a Java method with a variable number of arguments, passed via
2420 *******************************************************************************/
2422 #define VM_CALL_METHOD_JVALUE(name, type) \
2423 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2424 const jvalue *args) \
2429 if (m->code == NULL) \
2430 if (!jit_compile(m)) \
2433 THREAD_NATIVEWORLD_EXIT; \
2435 DumpMemoryArea dma; \
2437 array = argument_vmarray_from_jvalue(m, o, args); \
2438 value = vm_call##name##_array(m, array); \
2440 THREAD_NATIVEWORLD_ENTER; \
2445 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2446 VM_CALL_METHOD_JVALUE(_int, int32_t)
2447 VM_CALL_METHOD_JVALUE(_long, int64_t)
2448 VM_CALL_METHOD_JVALUE(_float, float)
2449 VM_CALL_METHOD_JVALUE(_double, double)
2452 /* vm_call_method_objectarray **************************************************
2454 Calls a Java method with a variable number if arguments, passed via
2455 an objectarray of boxed values. Returns a boxed value.
2457 *******************************************************************************/
2459 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2460 java_handle_objectarray_t *params)
2463 java_handle_t *xptr;
2467 /* Prevent compiler warnings. */
2471 /* compile methods which are not yet compiled */
2473 if (m->code == NULL)
2474 if (!jit_compile(m))
2477 /* leave the nativeworld */
2479 THREAD_NATIVEWORLD_EXIT;
2481 // Create new dump memory area.
2484 /* Fill the argument array from a object-array. */
2486 array = argument_vmarray_from_objectarray(m, o, params);
2488 if (array == NULL) {
2489 /* enter the nativeworld again */
2491 THREAD_NATIVEWORLD_ENTER;
2493 exceptions_throw_illegalargumentexception();
2498 switch (m->parseddesc->returntype.primitivetype) {
2499 case PRIMITIVETYPE_VOID:
2500 value.a = vm_call_array(m, array);
2503 case PRIMITIVETYPE_BOOLEAN:
2504 case PRIMITIVETYPE_BYTE:
2505 case PRIMITIVETYPE_CHAR:
2506 case PRIMITIVETYPE_SHORT:
2507 case PRIMITIVETYPE_INT:
2508 value.i = vm_call_int_array(m, array);
2511 case PRIMITIVETYPE_LONG:
2512 value.l = vm_call_long_array(m, array);
2515 case PRIMITIVETYPE_FLOAT:
2516 value.f = vm_call_float_array(m, array);
2519 case PRIMITIVETYPE_DOUBLE:
2520 value.d = vm_call_double_array(m, array);
2524 ro = vm_call_array(m, array);
2528 os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2531 /* enter the nativeworld again */
2533 THREAD_NATIVEWORLD_ENTER;
2535 /* box the return value if necesarry */
2537 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2538 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2540 /* check for an exception */
2542 xptr = exceptions_get_exception();
2545 /* clear exception pointer, we are calling JIT code again */
2547 exceptions_clear_exception();
2549 exceptions_throw_invocationtargetexception(xptr);
2556 /* Legacy C interface *********************************************************/
2560 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2561 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2562 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2563 bool VM_is_created() { return VM::get_current()->is_created(); }
2564 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2566 void vm_abort(const char* text, ...)
2571 os::abort(text, ap);
2575 void vm_abort_errnum(int errnum, const char* text, ...)
2580 os::abort_errnum(errnum, text, ap);
2584 void vm_abort_errno(const char* text, ...)
2589 os::abort_errno(text, ap);
2597 * These are local overrides for various environment variables in Emacs.
2598 * Please do not remove this and leave it at the end of the file, where
2599 * Emacs will automagically detect them.
2600 * ---------------------------------------------------------------------
2603 * indent-tabs-mode: t
2607 * vim:noexpandtab:sw=4:ts=4: