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)
215 #if defined(ENABLE_VERIFIER)
219 #if defined(TYPECHECK_VERBOSE)
222 #endif /* defined(ENABLE_VERIFIER) */
224 /* optimization options */
226 #if defined(ENABLE_LOOP)
230 #if defined(ENABLE_IFCONV)
234 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
238 #if defined(ENABLE_INTRP)
239 /* interpreter options */
258 #if defined(ENABLE_DEBUG_FILTER)
259 OPT_FILTER_VERBOSECALL_INCLUDE,
260 OPT_FILTER_VERBOSECALL_EXCLUDE,
261 OPT_FILTER_SHOW_METHOD,
268 opt_struct opts[] = {
269 { "foo", false, OPT_FOO },
273 { "jar", false, OPT_JAR },
275 { "d32", false, OPT_D32 },
276 { "d64", false, OPT_D64 },
277 { "client", false, OPT_IGNORE },
278 { "server", false, OPT_IGNORE },
279 { "jvm", false, OPT_IGNORE },
280 { "hotspot", false, OPT_IGNORE },
282 { "classpath", true, OPT_CLASSPATH },
283 { "cp", true, OPT_CLASSPATH },
284 { "D", true, OPT_D },
285 { "version", false, OPT_VERSION },
286 { "showversion", false, OPT_SHOWVERSION },
287 { "fullversion", false, OPT_FULLVERSION },
288 { "help", false, OPT_HELP },
289 { "?", false, OPT_HELP },
290 { "X", false, OPT_X },
291 { "XX:", true, OPT_XX },
293 { "ea:", true, OPT_EA },
294 { "da:", true, OPT_DA },
295 { "ea", false, OPT_EA_NOARG },
296 { "da", false, OPT_DA_NOARG },
298 { "enableassertions:", true, OPT_EA },
299 { "disableassertions:", true, OPT_DA },
300 { "enableassertions", false, OPT_EA_NOARG },
301 { "disableassertions", false, OPT_DA_NOARG },
303 { "esa", false, OPT_ESA },
304 { "enablesystemassertions", false, OPT_ESA },
305 { "dsa", false, OPT_DSA },
306 { "disablesystemassertions", false, OPT_DSA },
308 { "noasyncgc", false, OPT_IGNORE },
309 #if defined(ENABLE_VERIFIER)
310 { "noverify", false, OPT_NOVERIFY },
311 { "Xverify:all", false, OPT_XVERIFY_ALL },
312 { "Xverify:none", false, OPT_XVERIFY_NONE },
314 { "v", false, OPT_VERBOSE1 },
315 { "verbose:", true, OPT_VERBOSE },
317 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
318 { "verbosetc", false, OPT_VERBOSETC },
320 #if defined(ENABLE_STATISTICS)
321 { "time", false, OPT_TIME },
322 { "stat", false, OPT_STAT },
324 { "log", true, OPT_LOG },
325 { "c", true, OPT_CHECK },
326 { "l", false, OPT_LOAD },
329 { "all", false, OPT_ALL },
330 { "sig", true, OPT_SIGNATURE },
333 #if defined(ENABLE_LOOP)
334 { "oloop", false, OPT_OLOOP },
336 #if defined(ENABLE_IFCONV)
337 { "ifconv", false, OPT_IFCONV },
339 #if defined(ENABLE_LSRA)
340 { "lsra", false, OPT_LSRA },
342 #if defined(ENABLE_SSA)
343 { "lsra", true, OPT_LSRA },
346 #if defined(ENABLE_INTRP)
347 /* interpreter options */
349 { "trace", false, OPT_TRACE },
350 { "static-supers", true, OPT_STATIC_SUPERS },
351 { "no-dynamic", false, OPT_NO_DYNAMIC },
352 { "no-replication", false, OPT_NO_REPLICATION },
353 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
356 /* JVMTI Agent Command Line Options */
358 { "agentlib:", true, OPT_AGENTLIB },
359 { "agentpath:", true, OPT_AGENTPATH },
362 /* Java non-standard options */
364 { "Xjit", false, OPT_JIT },
365 { "Xint", false, OPT_INTRP },
366 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
367 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
368 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
369 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
372 { "Xdebug", false, OPT_DEBUG },
373 { "Xnoagent", false, OPT_NOAGENT },
374 { "Xrunjdwp", true, OPT_XRUNJDWP },
377 { "Xms", true, OPT_MS },
378 { "ms", true, OPT_MS },
379 { "Xmx", true, OPT_MX },
380 { "mx", true, OPT_MX },
381 { "Xss", true, OPT_SS },
382 { "ss", true, OPT_SS },
384 { "Xcheck:jni", false, OPT_XCHECK_JNI },
386 #if defined(ENABLE_PROFILING)
387 { "Xprof:", true, OPT_PROF_OPTION },
388 { "Xprof", false, OPT_PROF },
391 /* keep these at the end of the list */
394 { "m", true, OPT_METHOD },
397 { "s", true, OPT_SHOW },
398 { "debug-color", false, OPT_DEBUGCOLOR },
400 #if defined(ENABLE_DEBUG_FILTER)
401 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
402 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
403 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
410 /* usage ***********************************************************************
412 Prints the correct usage syntax to stdout.
414 *******************************************************************************/
418 puts("Usage: cacao [-options] classname [arguments]");
419 puts(" (to run a class file)");
420 puts(" or cacao [-options] -jar jarfile [arguments]");
421 puts(" (to run a standalone jar file)\n");
423 puts("where options include:");
424 puts(" -d32 use 32-bit data model if available");
425 puts(" -d64 use 64-bit data model if available");
426 puts(" -client compatibility (currently ignored)");
427 puts(" -server compatibility (currently ignored)");
428 puts(" -jvm compatibility (currently ignored)");
429 puts(" -hotspot compatibility (currently ignored)\n");
431 puts(" -cp <path> specify a path to look for classes");
432 puts(" -classpath <path> specify a path to look for classes");
433 puts(" -D<name>=<value> add an entry to the property list");
434 puts(" -verbose[:class|gc|jni] enable specific verbose output");
435 puts(" -version print product version and exit");
436 puts(" -fullversion print jpackage-compatible product version and exit");
437 puts(" -showversion print product version and continue");
438 puts(" -help, -? print this help message");
439 puts(" -X print help on non-standard Java options");
440 puts(" -XX print help on debugging options");
441 puts(" -ea[:<packagename>...|:<classname>]");
442 puts(" -enableassertions[:<packagename>...|:<classname>]");
443 puts(" enable assertions with specified granularity");
444 puts(" -da[:<packagename>...|:<classname>]");
445 puts(" -disableassertions[:<packagename>...|:<classname>]");
446 puts(" disable assertions with specified granularity");
447 puts(" -esa | -enablesystemassertions");
448 puts(" enable system assertions");
449 puts(" -dsa | -disablesystemassertions");
450 puts(" disable system assertions");
453 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
454 puts (" for jdwp help use: -agentlib:jdwp=help");
455 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
458 /* exit with error code */
464 static void Xusage(void)
466 #if defined(ENABLE_JIT)
467 puts(" -Xjit JIT mode execution (default)");
469 #if defined(ENABLE_INTRP)
470 puts(" -Xint interpreter mode execution");
472 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
473 puts(" value is set as bootstrap class path");
474 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
475 puts(" value is appended to the bootstrap class path");
476 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
477 puts(" value is prepended to the bootstrap class path");
478 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
479 puts(" value is used as Java core library, but the");
480 puts(" hardcoded VM interface classes are prepended");
481 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
482 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
483 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
485 #if defined(ENABLE_PROFILING)
486 puts(" -Xprof[:bb] collect and print profiling data");
489 #if defined(ENABLE_JVMTI)
490 /* -Xdebug option depend on gnu classpath JDWP options. options:
491 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
492 puts(" -Xdebug enable remote debugging\n");
493 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
494 puts(" enable remote debugging\n");
497 /* exit with error code */
504 static void XXusage(void)
506 puts(" -v write state-information");
508 puts(" -verbose:jit enable specific verbose output");
509 puts(" -debug-color colored output for ANSI terms");
511 #ifdef TYPECHECK_VERBOSE
512 puts(" -verbosetc write debug messages while typechecking");
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. */
737 opt_heapmaxsize = HEAP_MAXSIZE;
738 opt_heapstartsize = HEAP_STARTSIZE;
739 opt_stacksize = STACK_SIZE;
741 // First of all, parse the -XX options.
743 #if defined(ENABLE_VMLOG)
744 vmlog_cacao_init_options();
749 // After -XX options are parsed, print the build-time
750 // configuration, if requested.
752 print_build_time_config();
754 #if defined(ENABLE_VMLOG)
758 /* We need to check if the actual size of a java.lang.Class object
759 is smaller or equal than the assumption made in
762 #warning FIXME We need to check the size of java.lang.Class!!!
763 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
764 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
766 /* set the VM starttime */
768 _starttime = builtin_currenttimemillis();
770 #if defined(ENABLE_JVMTI)
771 /* initialize JVMTI related **********************************************/
775 /* iterate over all passed options */
777 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
791 #if SIZEOF_VOID_P == 8
792 puts("Running a 32-bit JVM is not supported on this platform.");
798 #if SIZEOF_VOID_P == 4
799 puts("Running a 64-bit JVM is not supported on this platform.");
805 /* Forget old classpath and set the argument as new
808 // FIXME Make class_path const char*.
809 class_path = (char*) _properties.get("java.class.path");
811 p = MNEW(char, strlen(opt_arg) + strlen("0"));
815 #if defined(ENABLE_JAVASE)
816 _properties.put("java.class.path", p);
819 MFREE(class_path, char, strlen(class_path));
823 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
824 if (opt_arg[i] == '=') {
826 _properties.put(opt_arg, opt_arg + i + 1);
831 /* if no '=' is given, just create an empty property */
833 _properties.put(opt_arg, "");
838 case OPT_BOOTCLASSPATH:
839 /* Forget default bootclasspath and set the argument as
840 new boot classpath. */
842 // FIXME Make boot_class_path const char*.
843 boot_class_path = (char*) _properties.get("sun.boot.class.path");
845 p = MNEW(char, strlen(opt_arg) + strlen("0"));
849 _properties.put("sun.boot.class.path", p);
850 _properties.put("java.boot.class.path", p);
852 MFREE(boot_class_path, char, strlen(boot_class_path));
855 case OPT_BOOTCLASSPATH_A:
856 /* Append to bootclasspath. */
858 // FIXME Make boot_class_path const char*.
859 boot_class_path = (char*) _properties.get("sun.boot.class.path");
861 len = strlen(boot_class_path);
863 // XXX (char*) quick hack
864 p = (char*) MREALLOC(boot_class_path,
868 strlen(opt_arg) + strlen("0"));
873 _properties.put("sun.boot.class.path", p);
874 _properties.put("java.boot.class.path", p);
877 case OPT_BOOTCLASSPATH_P:
878 /* Prepend to bootclasspath. */
880 // FIXME Make boot_class_path const char*.
881 boot_class_path = (char*) _properties.get("sun.boot.class.path");
883 len = strlen(boot_class_path);
885 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
889 strcat(p, boot_class_path);
891 _properties.put("sun.boot.class.path", p);
892 _properties.put("java.boot.class.path", p);
894 MFREE(boot_class_path, char, len);
897 case OPT_BOOTCLASSPATH_C:
898 /* Use as Java core library, but prepend VM interface
901 // FIXME Make boot_class_path const char*.
902 boot_class_path = (char*) _properties.get("sun.boot.class.path");
905 strlen(CACAO_VM_ZIP) +
912 strcpy(p, CACAO_VM_ZIP);
916 _properties.put("sun.boot.class.path", p);
917 _properties.put("java.boot.class.path", p);
919 MFREE(boot_class_path, char, strlen(boot_class_path));
922 #if defined(ENABLE_JVMTI)
924 /* this option exists only for compatibility reasons */
928 /* I don't know yet what Xnoagent should do. This is only for
929 compatiblity with eclipse - motse */
938 strlen(CACAO_LIBDIR) +
939 strlen("/libjdwp.so=") +
943 agentarg = MNEW(char, len);
945 strcpy(agentarg, CACAO_LIBDIR);
946 strcat(agentarg, "/libjdwp.so=");
947 strcat(agentarg, &opt_arg[1]);
966 c = opt_arg[strlen(opt_arg) - 1];
968 if ((c == 'k') || (c == 'K')) {
969 j = atoi(opt_arg) * 1024;
971 } else if ((c == 'm') || (c == 'M')) {
972 j = atoi(opt_arg) * 1024 * 1024;
979 else if (opt == OPT_MS)
980 opt_heapstartsize = j;
987 // HotSpot compatibility option.
995 if (strcmp("class", opt_arg) == 0) {
996 opt_verboseclass = true;
998 else if (strcmp("gc", opt_arg) == 0) {
999 opt_verbosegc = true;
1001 else if (strcmp("jni", opt_arg) == 0) {
1002 opt_verbosejni = true;
1004 #if !defined(NDEBUG)
1005 else if (strcmp("jit", opt_arg) == 0) {
1009 compileverbose = true;
1013 printf("Unknown -verbose option: %s\n", opt_arg);
1018 case OPT_DEBUGCOLOR:
1019 opt_debugcolor = true;
1022 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1024 opt_typecheckverbose = true;
1033 case OPT_FULLVERSION:
1037 case OPT_SHOWVERSION:
1041 #if defined(ENABLE_VERIFIER)
1042 case OPT_XVERIFY_ALL:
1047 case OPT_XVERIFY_NONE:
1052 #if defined(ENABLE_STATISTICS)
1054 opt_getcompilingtime = true;
1055 opt_getloadingtime = true;
1068 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1069 switch (opt_arg[i]) {
1071 checkbounds = false;
1084 makeinitializations = false;
1087 #if !defined(NDEBUG)
1091 makeinitializations = false;
1096 opt_method = opt_arg;
1097 makeinitializations = false;
1101 opt_signature = opt_arg;
1105 case OPT_SHOW: /* Display options */
1106 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1107 switch (opt_arg[i]) {
1109 showconstantpool = true;
1121 opt_showintermediate = true;
1122 compileverbose = true;
1125 #if defined(ENABLE_DISASSEMBLER)
1127 opt_showdisassemble = true;
1128 compileverbose = true;
1133 opt_showddatasegment = true;
1142 #if defined(ENABLE_LOOP)
1148 #if defined(ENABLE_IFCONV)
1154 #if defined(ENABLE_LSRA)
1159 #if defined(ENABLE_SSA)
1162 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1163 switch (opt_arg[i]) {
1191 /* Already parsed. */
1195 #if defined(ENABLE_ASSERTION)
1196 assertion_ea_da(opt_arg, true);
1201 #if defined(ENABLE_ASSERTION)
1202 assertion_ea_da(opt_arg, false);
1207 #if defined(ENABLE_ASSERTION)
1208 assertion_user_enabled = true;
1213 #if defined(ENABLE_ASSERTION)
1214 assertion_user_enabled = false;
1219 #if defined(ENABLE_ASSERTION)
1220 assertion_system_enabled = true;
1225 #if defined(ENABLE_ASSERTION)
1226 assertion_system_enabled = false;
1230 #if defined(ENABLE_PROFILING)
1231 case OPT_PROF_OPTION:
1232 /* use <= to get the last \0 too */
1234 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1235 if (opt_arg[i] == ',')
1238 if (opt_arg[i] == '\0') {
1239 if (strcmp("bb", opt_arg + j) == 0)
1243 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1247 /* set k to next char */
1260 #if defined(ENABLE_JIT)
1263 printf("-Xjit option not enabled.\n");
1269 #if defined(ENABLE_INTRP)
1272 printf("-Xint option not enabled.\n");
1277 #if defined(ENABLE_INTRP)
1278 case OPT_STATIC_SUPERS:
1279 opt_static_supers = atoi(opt_arg);
1282 case OPT_NO_DYNAMIC:
1283 opt_no_dynamic = true;
1286 case OPT_NO_REPLICATION:
1287 opt_no_replication = true;
1290 case OPT_NO_QUICKSUPER:
1291 opt_no_quicksuper = true;
1299 #if defined(ENABLE_DEBUG_FILTER)
1300 case OPT_FILTER_VERBOSECALL_INCLUDE:
1301 opt_filter_verbosecall_include = opt_arg;
1304 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1305 opt_filter_verbosecall_exclude = opt_arg;
1308 case OPT_FILTER_SHOW_METHOD:
1309 opt_filter_show_method = opt_arg;
1314 printf("Unknown option: %s\n",
1315 vm_args->options[opt_index].optionString);
1320 // Print the preliminary run-time VM configuration after options
1322 if (opt_PrintConfig)
1323 print_run_time_config();
1325 #if defined(ENABLE_JVMTI)
1327 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1328 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1331 MFREE(agentarg, char, strlen(agentarg));
1333 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1337 /* initialize the garbage collector */
1339 gc_init(opt_heapmaxsize, opt_heapstartsize);
1341 #if defined(ENABLE_THREADS)
1342 /* AFTER: gc_init */
1348 /* install architecture dependent signal handlers */
1351 os::abort("vm_create: signal_init failed");
1353 #if defined(ENABLE_INTRP)
1354 /* Allocate main thread stack on the Java heap. */
1357 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1358 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1362 /* AFTER: threads_preinit */
1365 os::abort("vm_create: string_init failed");
1367 /* AFTER: threads_preinit */
1371 /* AFTER: thread_preinit */
1373 _suckclasspath.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 _suckclasspath.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 /* Register the native methods implemented in the VM. */
1439 /* BEFORE: threads_init */
1443 #if defined(ENABLE_JNI)
1444 /* Initialize the JNI subsystem (must be done _before_
1445 threads_init, as threads_init can call JNI methods
1446 (e.g. NewGlobalRef). */
1449 os::abort("vm_create: jni_init failed");
1452 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1453 /* Initialize the local reference table for the main thread. */
1454 /* BEFORE: threads_init */
1456 if (!localref_table_init())
1457 os::abort("vm_create: localref_table_init failed");
1460 /* Iinitialize some important system classes. */
1461 /* BEFORE: threads_init */
1465 #if defined(ENABLE_THREADS)
1469 /* Initialize the native VM subsystem. */
1470 /* AFTER: threads_init (at least for SUN's classes) */
1472 if (!nativevm_init())
1473 os::abort("vm_create: nativevm_init failed");
1475 #if defined(ENABLE_PROFILING)
1476 /* initialize profiling */
1478 if (!profile_init())
1479 os::abort("vm_create: profile_init failed");
1482 #if defined(ENABLE_THREADS)
1483 /* start the signal handler thread */
1485 #if defined(__LINUX__)
1486 /* XXX Remove for exact-GC. */
1487 if (threads_pthreads_implementation_nptl)
1489 if (!signal_start_thread())
1490 os::abort("vm_create: signal_start_thread failed");
1492 /* finally, start the finalizer thread */
1494 if (!finalizer_start_thread())
1495 os::abort("vm_create: finalizer_start_thread failed");
1497 # if !defined(NDEBUG)
1498 /* start the memory profiling thread */
1500 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1501 if (!memory_start_thread())
1502 os::abort("vm_create: memory_start_thread failed");
1505 // Start the recompilation thread (must be done before the
1506 // profiling thread).
1507 // FIXME Only works for one recompiler.
1508 _recompiler.start();
1510 # if defined(ENABLE_PROFILING)
1511 /* start the profile sampling thread */
1514 /* if (!profile_start_thread()) */
1515 /* os::abort("vm_create: profile_start_thread failed"); */
1519 #if defined(ENABLE_JVMTI)
1520 # if defined(ENABLE_GC_CACAO)
1521 /* XXX this will not work with the new indirection cells for classloaders!!! */
1525 /* add agent library to native library hashtable */
1526 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1530 /* Increment the number of VMs. */
1534 // Initialization is done, VM is created.
1536 _initializing = false;
1538 // Print the run-time VM configuration after all stuff is set and
1539 // the VM is initialized.
1540 if (opt_PrintConfig)
1541 print_run_time_config();
1546 * Print build-time (default) VM configuration.
1548 void VM::print_build_time_config(void)
1550 puts("CACAO "VERSION" configure/build options:");
1552 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1553 #if defined(__VERSION__)
1554 puts(" CC : "VERSION_CC" ("__VERSION__")");
1555 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1557 puts(" CC : "VERSION_CC"");
1558 puts(" CXX : "VERSION_CXX"");
1560 puts(" CFLAGS : "VERSION_CFLAGS"");
1561 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1565 puts("Build-time (default) variables:\n");
1566 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1567 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1568 printf(" stack size : %d\n", STACK_SIZE);
1570 #if defined(ENABLE_JRE_LAYOUT)
1571 // When we're building with JRE-layout, the default paths are the
1572 // same as the runtime paths.
1574 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1575 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1576 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1577 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1578 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1579 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1588 * Print run-time VM configuration.
1590 void VM::print_run_time_config()
1592 puts("Run-time variables:\n");
1593 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1594 printf(" initial heap size : %d\n", opt_heapstartsize);
1595 printf(" stack size : %d\n", opt_stacksize);
1597 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1598 printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1599 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1600 printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1603 printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1604 printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1610 /* vm_run **********************************************************************
1612 Runs the main-method of the passed class.
1614 *******************************************************************************/
1616 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1622 classinfo *mainclass;
1625 java_handle_objectarray_t *oa;
1631 // Prevent compiler warnings.
1634 #if !defined(NDEBUG)
1641 /* Get the main class plus it's arguments. */
1645 if (opt_index < vm_args->nOptions) {
1646 /* Get main-class argument. */
1648 mainname = vm_args->options[opt_index].optionString;
1650 /* If the main class argument is a jar file, put it into the
1653 if (opt_jar == true) {
1654 p = MNEW(char, strlen(mainname) + strlen("0"));
1656 strcpy(p, mainname);
1658 #if defined(ENABLE_JAVASE)
1659 VM::get_current()->get_properties().put("java.class.path", p);
1663 /* Replace dots with slashes in the class name. */
1665 for (unsigned int i = 0; i < strlen(mainname); i++)
1666 if (mainname[i] == '.')
1670 /* Build argument array. Move index to first argument. */
1674 oalength = vm_args->nOptions - opt_index;
1676 oa = builtin_anewarray(oalength, class_java_lang_String);
1678 for (int i = 0; i < oalength; i++) {
1679 option = vm_args->options[opt_index + i].optionString;
1681 u = utf_new_char(option);
1682 s = javastring_new(u);
1684 array_objectarray_element_set(oa, i, s);
1688 /* Do we have a main-class argument? */
1690 if (mainname == NULL)
1693 #if !defined(NDEBUG)
1694 if (opt_method != NULL) {
1695 vm_compile_method(mainname);
1700 /* set return value to OK */
1704 if (opt_jar == true) {
1705 /* open jar file with java.util.jar.JarFile */
1707 mainname = vm_get_mainclass_from_jar(mainname);
1709 if (mainname == NULL)
1713 /* load the main class */
1715 mainutf = utf_new_char(mainname);
1717 #if defined(ENABLE_JAVAME_CLDC1_1)
1718 mainclass = load_class_bootstrap(mainutf);
1720 mainclass = load_class_from_sysloader(mainutf);
1723 /* error loading class */
1725 e = exceptions_get_and_clear_exception();
1727 if ((e != NULL) || (mainclass == NULL)) {
1728 exceptions_throw_noclassdeffounderror_cause(e);
1729 exceptions_print_stacktrace();
1733 if (!link_class(mainclass)) {
1734 exceptions_print_stacktrace();
1738 /* find the `main' method of the main class */
1740 m = class_resolveclassmethod(mainclass,
1741 utf_new_char("main"),
1742 utf_new_char("([Ljava/lang/String;)V"),
1743 class_java_lang_Object,
1746 if (exceptions_get_exception()) {
1747 exceptions_print_stacktrace();
1751 /* there is no main method or it isn't static */
1753 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1754 exceptions_clear_exception();
1755 exceptions_throw_nosuchmethoderror(mainclass,
1756 utf_new_char("main"),
1757 utf_new_char("([Ljava/lang/String;)V"));
1759 exceptions_print_stacktrace();
1763 #ifdef TYPEINFO_DEBUG_TEST
1764 /* test the typeinfo system */
1768 #if defined(ENABLE_JVMTI)
1769 jvmti_set_phase(JVMTI_PHASE_LIVE);
1772 /* set ThreadMXBean variables */
1774 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1775 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1777 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1778 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1779 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1780 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1781 #warning Move to C++
1783 /* start the main thread */
1785 (void) vm_call_method(m, NULL, oa);
1787 /* exception occurred? */
1789 if (exceptions_get_exception()) {
1790 exceptions_print_stacktrace();
1794 #if defined(ENABLE_THREADS)
1795 /* Detach the main thread so that it appears to have ended when
1796 the application's main method exits. */
1798 if (!thread_detach_current_thread())
1799 os::abort("vm_run: Could not detach main thread.");
1802 /* Destroy the JavaVM. */
1804 (void) vm_destroy(vm);
1812 /* vm_destroy ******************************************************************
1814 Unloads a Java VM and reclaims its resources.
1816 *******************************************************************************/
1818 int vm_destroy(JavaVM *vm)
1820 #if defined(ENABLE_THREADS)
1821 /* Create a a trivial new Java waiter thread called
1824 JavaVMAttachArgs args;
1826 args.name = (char*) "DestroyJavaVM";
1829 if (!thread_attach_current_thread(&args, false))
1832 /* Wait until we are the last non-daemon thread. */
1834 threads_join_all_threads();
1839 // _created = false;
1840 #warning Move to C++
1842 /* Everything is ok. */
1848 /* vm_exit *********************************************************************
1850 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1852 *******************************************************************************/
1854 void vm_exit(s4 status)
1858 /* signal that we are exiting */
1861 #warning Move to C++
1863 assert(class_java_lang_System);
1864 assert(class_java_lang_System->state & CLASS_LOADED);
1866 #if defined(ENABLE_JVMTI)
1867 if (jvmti || (dbgcom!=NULL)) {
1868 jvmti_set_phase(JVMTI_PHASE_DEAD);
1869 if (jvmti) jvmti_agentunload();
1873 if (!link_class(class_java_lang_System)) {
1874 exceptions_print_stacktrace();
1878 /* call java.lang.System.exit(I)V */
1880 m = class_resolveclassmethod(class_java_lang_System,
1881 utf_new_char("exit"),
1883 class_java_lang_Object,
1887 exceptions_print_stacktrace();
1891 /* call the exit function with passed exit status */
1893 (void) vm_call_method(m, NULL, status);
1895 /* If we had an exception, just ignore the exception and exit with
1898 vm_shutdown(status);
1902 /* vm_shutdown *****************************************************************
1904 Terminates the system immediately without freeing memory explicitly
1905 (to be used only for abnormal termination).
1907 *******************************************************************************/
1909 void vm_shutdown(s4 status)
1912 #if defined(ENABLE_STATISTICS)
1913 || opt_getcompilingtime || opt_stat
1917 log_text("CACAO terminated by shutdown");
1918 dolog("Exit status: %d\n", (s4) status);
1922 #if defined(ENABLE_JVMTI)
1923 /* terminate cacaodbgserver */
1925 mutex_lock(&dbgcomlock);
1927 mutex_unlock(&dbgcomlock);
1928 jvmti_cacaodbgserver_quit();
1936 /* vm_exit_handler *************************************************************
1938 The exit_handler function is called upon program termination.
1940 ATTENTION: Don't free system resources here! Some threads may still
1941 be running as this is called from VMRuntime.exit(). The OS does the
1944 *******************************************************************************/
1946 void vm_exit_handler(void)
1948 #if !defined(NDEBUG)
1950 class_showmethods(mainclass);
1952 if (showconstantpool)
1953 class_showconstantpool(mainclass);
1958 # if defined(ENABLE_PROFILING)
1960 profile_printstats();
1962 #endif /* !defined(NDEBUG) */
1964 #if defined(ENABLE_RT_TIMING)
1965 rt_timing_print_time_stats(stderr);
1968 #if defined(ENABLE_CYCLES_STATS)
1969 builtin_print_cycles_stats(stderr);
1970 stacktrace_print_cycles_stats(stderr);
1974 #if defined(ENABLE_STATISTICS)
1975 || opt_getcompilingtime || opt_stat
1979 log_text("CACAO terminated");
1981 #if defined(ENABLE_STATISTICS)
1984 #ifdef TYPECHECK_STATISTICS
1985 typecheck_print_statistics(get_logfile());
1989 if (opt_getcompilingtime)
1991 #endif /* defined(ENABLE_STATISTICS) */
1993 /* vm_print_profile(stderr);*/
1997 /* vm_abort_disassemble ********************************************************
1999 Prints an error message, disassemble the given code range (if
2000 enabled) and aborts the VM.
2003 pc.......PC to disassemble
2004 count....number of instructions to disassemble
2006 *******************************************************************************/
2008 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2011 #if defined(ENABLE_DISASSEMBLER)
2015 /* Print debug message. */
2020 log_vprint(text, ap);
2027 #if SIZEOF_VOID_P == 8
2028 log_println("PC=0x%016lx", pc);
2030 log_println("PC=0x%08x", pc);
2033 #if defined(ENABLE_DISASSEMBLER)
2034 log_println("machine instructions at PC:");
2036 /* Disassemble the given number of instructions. */
2038 for (i = 0; i < count; i++)
2039 // FIXME disassinstr should use void*.
2040 pc = disassinstr((u1*) pc);
2043 os::abort("Aborting...");
2047 /* vm_get_mainclass_from_jar ***************************************************
2049 Gets the name of the main class from a JAR's manifest file.
2051 *******************************************************************************/
2053 static char *vm_get_mainclass_from_jar(char *mainname)
2060 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2063 exceptions_print_stacktrace();
2067 /* create JarFile object */
2072 exceptions_print_stacktrace();
2076 m = class_resolveclassmethod(c,
2078 utf_java_lang_String__void,
2079 class_java_lang_Object,
2083 exceptions_print_stacktrace();
2087 s = javastring_new_from_ascii(mainname);
2089 (void) vm_call_method(m, o, s);
2091 if (exceptions_get_exception()) {
2092 exceptions_print_stacktrace();
2096 /* get manifest object */
2098 m = class_resolveclassmethod(c,
2099 utf_new_char("getManifest"),
2100 utf_new_char("()Ljava/util/jar/Manifest;"),
2101 class_java_lang_Object,
2105 exceptions_print_stacktrace();
2109 o = vm_call_method(m, o);
2112 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2117 /* get Main Attributes */
2119 LLNI_class_get(o, c);
2121 m = class_resolveclassmethod(c,
2122 utf_new_char("getMainAttributes"),
2123 utf_new_char("()Ljava/util/jar/Attributes;"),
2124 class_java_lang_Object,
2128 exceptions_print_stacktrace();
2132 o = vm_call_method(m, o);
2135 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2140 /* get property Main-Class */
2142 LLNI_class_get(o, c);
2144 m = class_resolveclassmethod(c,
2145 utf_new_char("getValue"),
2146 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2147 class_java_lang_Object,
2151 exceptions_print_stacktrace();
2155 s = javastring_new_from_ascii("Main-Class");
2157 o = vm_call_method(m, o, s);
2160 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2161 fprintf(stderr, "%s\n", mainname);
2165 return javastring_tochar(o);
2169 /* vm_compile_all **************************************************************
2171 Compile all methods found in the bootclasspath.
2173 *******************************************************************************/
2175 #if !defined(NDEBUG)
2176 static void vm_compile_all(void)
2181 classcache_name_entry *nmen;
2182 classcache_class_entry *clsen;
2185 /* create all classes found in the bootclasspath */
2186 /* XXX currently only works with zip/jar's */
2188 loader_load_all_classes();
2190 /* link all classes */
2192 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2193 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2195 for (; nmen; nmen = nmen->hashlink) {
2196 /* iterate over all class entries */
2198 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2199 c = clsen->classobj;
2204 if (!(c->state & CLASS_LINKED)) {
2205 if (!link_class(c)) {
2206 fprintf(stderr, "Error linking: ");
2207 utf_fprint_printable_ascii_classname(stderr, c->name);
2208 fprintf(stderr, "\n");
2210 /* print out exception and cause */
2212 exceptions_print_current_exception();
2214 /* goto next class */
2220 /* compile all class methods */
2222 for (i = 0; i < c->methodscount; i++) {
2223 m = &(c->methods[i]);
2225 if (m->jcode != NULL) {
2226 if (!jit_compile(m)) {
2227 fprintf(stderr, "Error compiling: ");
2228 utf_fprint_printable_ascii_classname(stderr, c->name);
2229 fprintf(stderr, ".");
2230 utf_fprint_printable_ascii(stderr, m->name);
2231 utf_fprint_printable_ascii(stderr, m->descriptor);
2232 fprintf(stderr, "\n");
2234 /* print out exception and cause */
2236 exceptions_print_current_exception();
2244 #endif /* !defined(NDEBUG) */
2247 /* vm_compile_method ***********************************************************
2249 Compile a specific method.
2251 *******************************************************************************/
2253 #if !defined(NDEBUG)
2254 static void vm_compile_method(char* mainname)
2258 /* create, load and link the main class */
2260 mainclass = load_class_bootstrap(utf_new_char(mainname));
2262 if (mainclass == NULL)
2263 exceptions_print_stacktrace();
2265 if (!link_class(mainclass))
2266 exceptions_print_stacktrace();
2268 if (opt_signature != NULL) {
2269 m = class_resolveclassmethod(mainclass,
2270 utf_new_char(opt_method),
2271 utf_new_char(opt_signature),
2276 m = class_resolveclassmethod(mainclass,
2277 utf_new_char(opt_method),
2284 os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2285 opt_method, opt_signature ? opt_signature : "");
2289 #endif /* !defined(NDEBUG) */
2292 /* vm_call_array ***************************************************************
2294 Calls a Java method with a variable number of arguments, passed via
2297 ATTENTION: This function has to be used outside the nativeworld.
2299 *******************************************************************************/
2301 #define VM_CALL_ARRAY(name, type) \
2302 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2308 assert(m->code != NULL); \
2310 md = m->parseddesc; \
2311 pv = m->code->entrypoint; \
2313 STATISTICS(count_calls_native_to_java++); \
2315 value = asm_vm_call_method##name(pv, array, md->memuse); \
2320 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2326 assert(m->code != NULL);
2329 pv = m->code->entrypoint;
2331 STATISTICS(count_calls_native_to_java++);
2333 o = asm_vm_call_method(pv, array, md->memuse);
2335 if (md->returntype.type == TYPE_VOID)
2338 return LLNI_WRAP(o);
2341 VM_CALL_ARRAY(_int, int32_t)
2342 VM_CALL_ARRAY(_long, int64_t)
2343 VM_CALL_ARRAY(_float, float)
2344 VM_CALL_ARRAY(_double, double)
2347 /* vm_call_method **************************************************************
2349 Calls a Java method with a variable number of arguments.
2351 *******************************************************************************/
2353 #define VM_CALL_METHOD(name, type) \
2354 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2360 value = vm_call_method##name##_valist(m, o, ap); \
2366 VM_CALL_METHOD(, java_handle_t *)
2367 VM_CALL_METHOD(_int, int32_t)
2368 VM_CALL_METHOD(_long, int64_t)
2369 VM_CALL_METHOD(_float, float)
2370 VM_CALL_METHOD(_double, double)
2373 /* vm_call_method_valist *******************************************************
2375 Calls a Java method with a variable number of arguments, passed via
2378 *******************************************************************************/
2380 #define VM_CALL_METHOD_VALIST(name, type) \
2381 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2387 if (m->code == NULL) \
2388 if (!jit_compile(m)) \
2391 THREAD_NATIVEWORLD_EXIT; \
2393 DumpMemoryArea dma; \
2395 array = argument_vmarray_from_valist(m, o, ap); \
2396 value = vm_call##name##_array(m, array); \
2398 THREAD_NATIVEWORLD_ENTER; \
2403 VM_CALL_METHOD_VALIST(, java_handle_t *)
2404 VM_CALL_METHOD_VALIST(_int, int32_t)
2405 VM_CALL_METHOD_VALIST(_long, int64_t)
2406 VM_CALL_METHOD_VALIST(_float, float)
2407 VM_CALL_METHOD_VALIST(_double, double)
2410 /* vm_call_method_jvalue *******************************************************
2412 Calls a Java method with a variable number of arguments, passed via
2415 *******************************************************************************/
2417 #define VM_CALL_METHOD_JVALUE(name, type) \
2418 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2419 const jvalue *args) \
2424 if (m->code == NULL) \
2425 if (!jit_compile(m)) \
2428 THREAD_NATIVEWORLD_EXIT; \
2430 DumpMemoryArea dma; \
2432 array = argument_vmarray_from_jvalue(m, o, args); \
2433 value = vm_call##name##_array(m, array); \
2435 THREAD_NATIVEWORLD_ENTER; \
2440 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2441 VM_CALL_METHOD_JVALUE(_int, int32_t)
2442 VM_CALL_METHOD_JVALUE(_long, int64_t)
2443 VM_CALL_METHOD_JVALUE(_float, float)
2444 VM_CALL_METHOD_JVALUE(_double, double)
2447 /* vm_call_method_objectarray **************************************************
2449 Calls a Java method with a variable number if arguments, passed via
2450 an objectarray of boxed values. Returns a boxed value.
2452 *******************************************************************************/
2454 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2455 java_handle_objectarray_t *params)
2458 java_handle_t *xptr;
2462 /* Prevent compiler warnings. */
2466 /* compile methods which are not yet compiled */
2468 if (m->code == NULL)
2469 if (!jit_compile(m))
2472 /* leave the nativeworld */
2474 THREAD_NATIVEWORLD_EXIT;
2476 // Create new dump memory area.
2479 /* Fill the argument array from a object-array. */
2481 array = argument_vmarray_from_objectarray(m, o, params);
2483 if (array == NULL) {
2484 /* enter the nativeworld again */
2486 THREAD_NATIVEWORLD_ENTER;
2488 exceptions_throw_illegalargumentexception();
2493 switch (m->parseddesc->returntype.primitivetype) {
2494 case PRIMITIVETYPE_VOID:
2495 value.a = vm_call_array(m, array);
2498 case PRIMITIVETYPE_BOOLEAN:
2499 case PRIMITIVETYPE_BYTE:
2500 case PRIMITIVETYPE_CHAR:
2501 case PRIMITIVETYPE_SHORT:
2502 case PRIMITIVETYPE_INT:
2503 value.i = vm_call_int_array(m, array);
2506 case PRIMITIVETYPE_LONG:
2507 value.l = vm_call_long_array(m, array);
2510 case PRIMITIVETYPE_FLOAT:
2511 value.f = vm_call_float_array(m, array);
2514 case PRIMITIVETYPE_DOUBLE:
2515 value.d = vm_call_double_array(m, array);
2519 ro = vm_call_array(m, array);
2523 os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2526 /* enter the nativeworld again */
2528 THREAD_NATIVEWORLD_ENTER;
2530 /* box the return value if necesarry */
2532 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2533 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2535 /* check for an exception */
2537 xptr = exceptions_get_exception();
2540 /* clear exception pointer, we are calling JIT code again */
2542 exceptions_clear_exception();
2544 exceptions_throw_invocationtargetexception(xptr);
2551 /* Legacy C interface *********************************************************/
2555 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2556 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2557 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2558 bool VM_is_created() { return VM::get_current()->is_created(); }
2559 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2561 void vm_abort(const char* text, ...)
2565 log_println("vm_abort: WARNING, port me to C++ and use os::abort() instead.");
2567 // Print the log message.
2571 log_vprint(text, ap);
2576 // Print a backtrace.
2577 os::print_backtrace();
2579 // Now abort the VM.
2587 * These are local overrides for various environment variables in Emacs.
2588 * Please do not remove this and leave it at the end of the file, where
2589 * Emacs will automagically detect them.
2590 * ---------------------------------------------------------------------
2593 * indent-tabs-mode: t
2597 * vim:noexpandtab:sw=4:ts=4: