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.h"
51 #include "native/native.h"
53 #include "native/vm/nativevm.h"
55 #include "threads/lock-common.h"
56 #include "threads/threadlist.h"
57 #include "threads/thread.hpp"
59 #include "toolbox/logging.h"
63 #if defined(ENABLE_ASSERTION)
64 #include "vm/assertion.h"
67 #include "vm/jit/builtin.hpp"
68 #include "vm/classcache.h"
69 #include "vm/exceptions.hpp"
70 #include "vm/finalizer.h"
71 #include "vm/global.h"
72 #include "vm/globals.hpp"
73 #include "vm/initialize.h"
74 #include "vm/options.h"
76 #include "vm/primitive.hpp"
77 #include "vm/properties.hpp"
78 #include "vm/signallocal.h"
79 #include "vm/statistics.h"
80 #include "vm/string.hpp"
81 #include "vm/suck.hpp"
84 #include "vm/jit/argument.h"
85 #include "vm/jit/asmpart.h"
86 #include "vm/jit/code.hpp"
88 #if defined(ENABLE_DISASSEMBLER)
89 # include "vm/jit/disass.h"
92 #include "vm/jit/jit.hpp"
93 #include "vm/jit/methodtree.h"
95 #if defined(ENABLE_PROFILING)
96 # include "vm/jit/optimizing/profile.h"
99 #include "vm/jit/optimizing/recompile.h"
101 #if defined(ENABLE_PYTHON)
102 # include "vm/jit/python.h"
105 #include "vm/jit/trap.h"
107 #if defined(ENABLE_JVMTI)
108 # include "native/jvmti/cacaodbg.h"
111 #if defined(ENABLE_VMLOG)
112 #include <vmlog_cacao.h>
117 * This is _the_ VM instance.
122 /* global variables ***********************************************************/
124 s4 vms = 0; /* number of VMs created */
126 static classinfo *mainclass = NULL;
128 #if defined(ENABLE_INTRP)
129 u1 *intrp_main_stack = NULL;
133 /* define heap sizes **********************************************************/
135 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
136 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
137 #define STACK_SIZE 128 * 1024 /* default 64kB */
140 /* define command line options ************************************************/
174 /* Java non-standard options */
185 #if defined(ENABLE_PROFILING)
198 #if defined(ENABLE_STATISTICS)
215 #if defined(ENABLE_VERIFIER)
217 #if defined(TYPECHECK_VERBOSE)
220 #endif /* defined(ENABLE_VERIFIER) */
222 /* optimization options */
224 #if defined(ENABLE_LOOP)
228 #if defined(ENABLE_IFCONV)
232 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
236 #if defined(ENABLE_INTRP)
237 /* interpreter options */
256 #if defined(ENABLE_DEBUG_FILTER)
257 OPT_FILTER_VERBOSECALL_INCLUDE,
258 OPT_FILTER_VERBOSECALL_EXCLUDE,
259 OPT_FILTER_SHOW_METHOD,
266 opt_struct opts[] = {
267 { "foo", false, OPT_FOO },
271 { "jar", false, OPT_JAR },
273 { "d32", false, OPT_D32 },
274 { "d64", false, OPT_D64 },
275 { "client", false, OPT_IGNORE },
276 { "server", false, OPT_IGNORE },
277 { "jvm", false, OPT_IGNORE },
278 { "hotspot", false, OPT_IGNORE },
280 { "classpath", true, OPT_CLASSPATH },
281 { "cp", true, OPT_CLASSPATH },
282 { "D", true, OPT_D },
283 { "version", false, OPT_VERSION },
284 { "showversion", false, OPT_SHOWVERSION },
285 { "fullversion", false, OPT_FULLVERSION },
286 { "help", false, OPT_HELP },
287 { "?", false, OPT_HELP },
288 { "X", false, OPT_X },
289 { "XX:", true, OPT_XX },
291 { "ea:", true, OPT_EA },
292 { "da:", true, OPT_DA },
293 { "ea", false, OPT_EA_NOARG },
294 { "da", false, OPT_DA_NOARG },
296 { "enableassertions:", true, OPT_EA },
297 { "disableassertions:", true, OPT_DA },
298 { "enableassertions", false, OPT_EA_NOARG },
299 { "disableassertions", false, OPT_DA_NOARG },
301 { "esa", false, OPT_ESA },
302 { "enablesystemassertions", false, OPT_ESA },
303 { "dsa", false, OPT_DSA },
304 { "disablesystemassertions", false, OPT_DSA },
306 { "noasyncgc", false, OPT_IGNORE },
307 #if defined(ENABLE_VERIFIER)
308 { "noverify", false, OPT_NOVERIFY },
309 { "Xverify:none", false, OPT_NOVERIFY },
311 { "v", false, OPT_VERBOSE1 },
312 { "verbose:", true, OPT_VERBOSE },
314 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
315 { "verbosetc", false, OPT_VERBOSETC },
317 #if defined(__ALPHA__)
318 { "noieee", false, OPT_NOIEEE },
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 #if defined(ENABLE_PROFILING)
385 { "Xprof:", true, OPT_PROF_OPTION },
386 { "Xprof", false, OPT_PROF },
389 /* keep these at the end of the list */
392 { "m", true, OPT_METHOD },
395 { "s", true, OPT_SHOW },
396 { "debug-color", false, OPT_DEBUGCOLOR },
398 #if defined(ENABLE_DEBUG_FILTER)
399 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
400 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
401 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
408 /* usage ***********************************************************************
410 Prints the correct usage syntax to stdout.
412 *******************************************************************************/
416 puts("Usage: cacao [-options] classname [arguments]");
417 puts(" (to run a class file)");
418 puts(" or cacao [-options] -jar jarfile [arguments]");
419 puts(" (to run a standalone jar file)\n");
421 puts("where options include:");
422 puts(" -d32 use 32-bit data model if available");
423 puts(" -d64 use 64-bit data model if available");
424 puts(" -client compatibility (currently ignored)");
425 puts(" -server compatibility (currently ignored)");
426 puts(" -jvm compatibility (currently ignored)");
427 puts(" -hotspot compatibility (currently ignored)\n");
429 puts(" -cp <path> specify a path to look for classes");
430 puts(" -classpath <path> specify a path to look for classes");
431 puts(" -D<name>=<value> add an entry to the property list");
432 puts(" -verbose[:class|gc|jni] enable specific verbose output");
433 puts(" -version print product version and exit");
434 puts(" -fullversion print jpackage-compatible product version and exit");
435 puts(" -showversion print product version and continue");
436 puts(" -help, -? print this help message");
437 puts(" -X print help on non-standard Java options");
438 puts(" -XX print help on debugging options");
439 puts(" -ea[:<packagename>...|:<classname>]");
440 puts(" -enableassertions[:<packagename>...|:<classname>]");
441 puts(" enable assertions with specified granularity");
442 puts(" -da[:<packagename>...|:<classname>]");
443 puts(" -disableassertions[:<packagename>...|:<classname>]");
444 puts(" disable assertions with specified granularity");
445 puts(" -esa | -enablesystemassertions");
446 puts(" enable system assertions");
447 puts(" -dsa | -disablesystemassertions");
448 puts(" disable system assertions");
451 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
452 puts (" for jdwp help use: -agentlib:jdwp=help");
453 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
456 /* exit with error code */
462 static void Xusage(void)
464 #if defined(ENABLE_JIT)
465 puts(" -Xjit JIT mode execution (default)");
467 #if defined(ENABLE_INTRP)
468 puts(" -Xint interpreter mode execution");
470 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
471 puts(" value is set as bootstrap class path");
472 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
473 puts(" value is appended to the bootstrap class path");
474 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
475 puts(" value is prepended to the bootstrap class path");
476 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
477 puts(" value is used as Java core library, but the");
478 puts(" hardcoded VM interface classes are prepended");
479 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
480 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
481 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
483 #if defined(ENABLE_PROFILING)
484 puts(" -Xprof[:bb] collect and print profiling data");
487 #if defined(ENABLE_JVMTI)
488 /* -Xdebug option depend on gnu classpath JDWP options. options:
489 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
490 puts(" -Xdebug enable remote debugging\n");
491 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
492 puts(" enable remote debugging\n");
495 /* exit with error code */
502 static void XXusage(void)
504 puts(" -v write state-information");
506 puts(" -verbose:jit enable specific verbose output");
507 puts(" -debug-color colored output for ANSI terms");
509 #ifdef TYPECHECK_VERBOSE
510 puts(" -verbosetc write debug messages while typechecking");
512 #if defined(__ALPHA__)
513 puts(" -noieee don't use ieee compliant arithmetic");
515 #if defined(ENABLE_VERIFIER)
516 puts(" -noverify don't verify classfiles");
518 #if defined(ENABLE_STATISTICS)
519 puts(" -time measure the runtime");
520 puts(" -stat detailed compiler statistics");
522 puts(" -log logfile specify a name for the logfile");
523 puts(" -c(heck)b(ounds) don't check array bounds");
524 puts(" s(ync) don't check for synchronization");
525 #if defined(ENABLE_LOOP)
526 puts(" -oloop optimize array accesses in loops");
528 puts(" -l don't start the class after loading");
530 puts(" -all compile all methods, no execution");
531 puts(" -m compile only a specific method");
532 puts(" -sig specify signature for a specific method");
535 puts(" -s... show...");
536 puts(" (c)onstants the constant pool");
537 puts(" (m)ethods class fields and methods");
538 puts(" (u)tf the utf - hash");
539 puts(" (i)ntermediate intermediate representation");
540 #if defined(ENABLE_DISASSEMBLER)
541 puts(" (a)ssembler disassembled listing");
542 puts(" n(o)ps show NOPs in disassembler output");
544 puts(" (d)atasegment data segment listing");
546 #if defined(ENABLE_IFCONV)
547 puts(" -ifconv use if-conversion");
549 #if defined(ENABLE_LSRA)
550 puts(" -lsra use linear scan register allocation");
552 #if defined(ENABLE_SSA)
553 puts(" -lsra:... use linear scan register allocation (with SSA)");
554 puts(" (d)ead code elimination");
555 puts(" (c)opy propagation");
557 #if defined(ENABLE_DEBUG_FILTER)
558 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
559 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
560 puts(" -XXfm <regex> filter for show options");
562 /* exit with error code */
569 /* version *********************************************************************
571 Only prints cacao version information.
573 *******************************************************************************/
575 static void version(bool opt_exit)
577 puts("java version \""JAVA_VERSION"\"");
578 puts("CACAO version "VERSION"\n");
580 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
581 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
582 puts("This is free software; see the source for copying conditions. There is NO");
583 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
585 /* exit normally, if requested */
592 /* fullversion *****************************************************************
594 Prints a Sun compatible version information (required e.g. by
595 jpackage, www.jpackage.org).
597 *******************************************************************************/
599 static void fullversion(void)
601 puts("java full version \"cacao-"JAVA_VERSION"\"");
609 /* forward declarations *******************************************************/
611 static char *vm_get_mainclass_from_jar(char *mainstring);
613 static void vm_compile_all(void);
614 static void vm_compile_method(char* mainname);
619 * Implementation for JNI_CreateJavaVM. This function creates a VM
626 * @return true on success, false otherwise.
628 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
630 JavaVMInitArgs* _vm_args;
632 // Get the arguments for the new JVM.
633 _vm_args = (JavaVMInitArgs *) vm_args;
635 // Instantiate a new VM.
637 _vm = new VM(_vm_args);
639 catch (std::exception e) {
640 // FIXME How can we delete the resources allocated?
641 // /* release allocated memory */
642 // FREE(env, _Jv_JNIEnv);
643 // FREE(vm, _Jv_JavaVM);
650 // Return the values.
652 *p_vm = _vm->get_javavm();
653 *p_env = _vm->get_jnienv();
660 * C wrapper for VM::create.
663 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
665 return VM::create(p_vm, p_env, vm_args);
673 VM::VM(JavaVMInitArgs* vm_args)
675 // Very first thing to do: we are initializing.
676 _initializing = true;
678 // Make ourself globally visible.
679 // XXX Is this a good idea?
682 /* create and fill a JavaVM structure */
684 _javavm = new JavaVM();
686 #if defined(ENABLE_JNI)
687 _javavm->functions = &_Jv_JNIInvokeInterface;
690 /* get the VM and Env tables (must be set before vm_create) */
691 /* XXX JVMTI Agents needs a JavaVM */
693 _jnienv = new JNIEnv();
695 #if defined(ENABLE_JNI)
696 _jnienv->functions = &_Jv_JNINativeInterface;
699 /* actually create the JVM */
703 char *boot_class_path;
709 #if defined(ENABLE_JVMTI)
711 char *libname, *agentarg;
712 bool jdwp,agentbypath;
713 jdwp = agentbypath = false;
716 #if defined(ENABLE_JNI)
717 /* Check the JNI version requested. */
719 if (!jni_version_check(vm_args->version))
720 throw std::exception();
723 /* We only support 1 JVM instance. */
726 throw std::exception();
728 /* Install the exit handler. */
730 if (atexit(vm_exit_handler))
731 VM::get_current()->abort("atexit failed: %s\n", strerror(errno));
733 /* Set some options. */
740 opt_heapmaxsize = HEAP_MAXSIZE;
741 opt_heapstartsize = HEAP_STARTSIZE;
742 opt_stacksize = STACK_SIZE;
744 // First of all, parse the -XX options.
746 #if defined(ENABLE_VMLOG)
747 vmlog_cacao_init_options();
752 // After -XX options are parsed, print the build-time
753 // configuration, if requested.
755 print_build_time_config();
757 #if defined(ENABLE_VMLOG)
761 /* We need to check if the actual size of a java.lang.Class object
762 is smaller or equal than the assumption made in
765 #warning FIXME We need to check the size of java.lang.Class!!!
766 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
767 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
769 /* set the VM starttime */
771 _starttime = builtin_currenttimemillis();
773 #if defined(ENABLE_JVMTI)
774 /* initialize JVMTI related **********************************************/
778 /* iterate over all passed options */
780 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
794 #if SIZEOF_VOID_P == 8
795 puts("Running a 32-bit JVM is not supported on this platform.");
801 #if SIZEOF_VOID_P == 4
802 puts("Running a 64-bit JVM is not supported on this platform.");
808 /* Forget old classpath and set the argument as new
811 // FIXME Make class_path const char*.
812 class_path = (char*) _properties.get("java.class.path");
814 p = MNEW(char, strlen(opt_arg) + strlen("0"));
818 #if defined(ENABLE_JAVASE)
819 _properties.put("java.class.path", p);
822 MFREE(class_path, char, strlen(class_path));
826 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
827 if (opt_arg[i] == '=') {
829 _properties.put(opt_arg, opt_arg + i + 1);
834 /* if no '=' is given, just create an empty property */
836 _properties.put(opt_arg, "");
841 case OPT_BOOTCLASSPATH:
842 /* Forget default bootclasspath and set the argument as
843 new boot classpath. */
845 // FIXME Make boot_class_path const char*.
846 boot_class_path = (char*) _properties.get("sun.boot.class.path");
848 p = MNEW(char, strlen(opt_arg) + strlen("0"));
852 _properties.put("sun.boot.class.path", p);
853 _properties.put("java.boot.class.path", p);
855 MFREE(boot_class_path, char, strlen(boot_class_path));
858 case OPT_BOOTCLASSPATH_A:
859 /* Append to bootclasspath. */
861 // FIXME Make boot_class_path const char*.
862 boot_class_path = (char*) _properties.get("sun.boot.class.path");
864 len = strlen(boot_class_path);
866 // XXX (char*) quick hack
867 p = (char*) MREALLOC(boot_class_path,
871 strlen(opt_arg) + strlen("0"));
876 _properties.put("sun.boot.class.path", p);
877 _properties.put("java.boot.class.path", p);
880 case OPT_BOOTCLASSPATH_P:
881 /* Prepend to bootclasspath. */
883 // FIXME Make boot_class_path const char*.
884 boot_class_path = (char*) _properties.get("sun.boot.class.path");
886 len = strlen(boot_class_path);
888 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
892 strcat(p, boot_class_path);
894 _properties.put("sun.boot.class.path", p);
895 _properties.put("java.boot.class.path", p);
897 MFREE(boot_class_path, char, len);
900 case OPT_BOOTCLASSPATH_C:
901 /* Use as Java core library, but prepend VM interface
904 // FIXME Make boot_class_path const char*.
905 boot_class_path = (char*) _properties.get("sun.boot.class.path");
908 strlen(CACAO_VM_ZIP) +
915 strcpy(p, CACAO_VM_ZIP);
919 _properties.put("sun.boot.class.path", p);
920 _properties.put("java.boot.class.path", p);
922 MFREE(boot_class_path, char, strlen(boot_class_path));
925 #if defined(ENABLE_JVMTI)
927 /* this option exists only for compatibility reasons */
931 /* I don't know yet what Xnoagent should do. This is only for
932 compatiblity with eclipse - motse */
941 strlen(CACAO_LIBDIR) +
942 strlen("/libjdwp.so=") +
946 agentarg = MNEW(char, len);
948 strcpy(agentarg, CACAO_LIBDIR);
949 strcat(agentarg, "/libjdwp.so=");
950 strcat(agentarg, &opt_arg[1]);
969 c = opt_arg[strlen(opt_arg) - 1];
971 if ((c == 'k') || (c == 'K')) {
972 j = atoi(opt_arg) * 1024;
974 } else if ((c == 'm') || (c == 'M')) {
975 j = atoi(opt_arg) * 1024 * 1024;
982 else if (opt == OPT_MS)
983 opt_heapstartsize = j;
994 if (strcmp("class", opt_arg) == 0) {
995 opt_verboseclass = true;
997 else if (strcmp("gc", opt_arg) == 0) {
998 opt_verbosegc = true;
1000 else if (strcmp("jni", opt_arg) == 0) {
1001 opt_verbosejni = true;
1003 #if !defined(NDEBUG)
1004 else if (strcmp("jit", opt_arg) == 0) {
1008 compileverbose = true;
1012 printf("Unknown -verbose option: %s\n", opt_arg);
1017 case OPT_DEBUGCOLOR:
1018 opt_debugcolor = true;
1021 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1023 opt_typecheckverbose = true;
1032 case OPT_FULLVERSION:
1036 case OPT_SHOWVERSION:
1044 #if defined(ENABLE_VERIFIER)
1050 #if defined(ENABLE_STATISTICS)
1052 opt_getcompilingtime = true;
1053 opt_getloadingtime = true;
1066 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1067 switch (opt_arg[i]) {
1069 checkbounds = false;
1082 makeinitializations = false;
1085 #if !defined(NDEBUG)
1089 makeinitializations = false;
1094 opt_method = opt_arg;
1095 makeinitializations = false;
1099 opt_signature = opt_arg;
1103 case OPT_SHOW: /* Display options */
1104 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1105 switch (opt_arg[i]) {
1107 showconstantpool = true;
1119 opt_showintermediate = true;
1120 compileverbose = true;
1123 #if defined(ENABLE_DISASSEMBLER)
1125 opt_showdisassemble = true;
1126 compileverbose = true;
1131 opt_showddatasegment = true;
1140 #if defined(ENABLE_LOOP)
1146 #if defined(ENABLE_IFCONV)
1152 #if defined(ENABLE_LSRA)
1157 #if defined(ENABLE_SSA)
1160 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1161 switch (opt_arg[i]) {
1189 /* Already parsed. */
1193 #if defined(ENABLE_ASSERTION)
1194 assertion_ea_da(opt_arg, true);
1199 #if defined(ENABLE_ASSERTION)
1200 assertion_ea_da(opt_arg, false);
1205 #if defined(ENABLE_ASSERTION)
1206 assertion_user_enabled = true;
1211 #if defined(ENABLE_ASSERTION)
1212 assertion_user_enabled = false;
1217 #if defined(ENABLE_ASSERTION)
1218 assertion_system_enabled = true;
1223 #if defined(ENABLE_ASSERTION)
1224 assertion_system_enabled = false;
1228 #if defined(ENABLE_PROFILING)
1229 case OPT_PROF_OPTION:
1230 /* use <= to get the last \0 too */
1232 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1233 if (opt_arg[i] == ',')
1236 if (opt_arg[i] == '\0') {
1237 if (strcmp("bb", opt_arg + j) == 0)
1241 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1245 /* set k to next char */
1258 #if defined(ENABLE_JIT)
1261 printf("-Xjit option not enabled.\n");
1267 #if defined(ENABLE_INTRP)
1270 printf("-Xint option not enabled.\n");
1275 #if defined(ENABLE_INTRP)
1276 case OPT_STATIC_SUPERS:
1277 opt_static_supers = atoi(opt_arg);
1280 case OPT_NO_DYNAMIC:
1281 opt_no_dynamic = true;
1284 case OPT_NO_REPLICATION:
1285 opt_no_replication = true;
1288 case OPT_NO_QUICKSUPER:
1289 opt_no_quicksuper = true;
1297 #if defined(ENABLE_DEBUG_FILTER)
1298 case OPT_FILTER_VERBOSECALL_INCLUDE:
1299 opt_filter_verbosecall_include = opt_arg;
1302 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1303 opt_filter_verbosecall_exclude = opt_arg;
1306 case OPT_FILTER_SHOW_METHOD:
1307 opt_filter_show_method = opt_arg;
1312 printf("Unknown option: %s\n",
1313 vm_args->options[opt_index].optionString);
1318 // Print the preliminary run-time VM configuration after options
1320 if (opt_PrintConfig)
1321 print_run_time_config();
1323 #if defined(ENABLE_JVMTI)
1325 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1326 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1329 MFREE(agentarg, char, strlen(agentarg));
1331 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1335 /* initialize the garbage collector */
1337 gc_init(opt_heapmaxsize, opt_heapstartsize);
1339 #if defined(ENABLE_THREADS)
1340 /* BEFORE: threads_preinit */
1344 /* AFTER: gc_init */
1350 /* install architecture dependent signal handlers */
1353 VM::get_current()->abort("vm_create: signal_init failed");
1355 #if defined(ENABLE_INTRP)
1356 /* Allocate main thread stack on the Java heap. */
1359 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1360 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1364 /* AFTER: threads_preinit */
1367 VM::get_current()->abort("vm_create: string_init failed");
1369 /* AFTER: threads_preinit */
1373 /* AFTER: thread_preinit */
1376 VM::get_current()->abort("vm_create: suck_init failed");
1378 suck_add_from_property("java.endorsed.dirs");
1380 /* Now we have all options handled and we can print the version
1383 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1388 /* AFTER: utf8_init */
1390 // FIXME Make boot_class_path const char*.
1391 boot_class_path = (char*) _properties.get("sun.boot.class.path");
1392 suck_add(boot_class_path);
1394 /* initialize the classcache hashtable stuff: lock, hashtable
1395 (must be done _after_ threads_preinit) */
1397 if (!classcache_init())
1398 VM::get_current()->abort("vm_create: classcache_init failed");
1400 /* Initialize the code memory management. */
1401 /* AFTER: threads_preinit */
1405 /* initialize the finalizer stuff (must be done _after_
1408 if (!finalizer_init())
1409 VM::get_current()->abort("vm_create: finalizer_init failed");
1411 /* Initialize the JIT compiler. */
1417 #if defined(ENABLE_PYTHON)
1421 /* AFTER: utf8_init, classcache_init */
1426 // AFTER: loader_preinit, linker_preinit
1427 Primitive::initialize_table();
1432 // AFTER: loader_init, linker_init
1433 Primitive::post_initialize_table();
1436 #if defined(ENABLE_JIT)
1440 if (!builtin_init())
1441 VM::get_current()->abort("vm_create: builtin_init failed");
1443 /* Initialize the native subsystem. */
1444 /* BEFORE: threads_init */
1447 VM::get_current()->abort("vm_create: native_init failed");
1449 /* Register the native methods implemented in the VM. */
1450 /* BEFORE: threads_init */
1454 #if defined(ENABLE_JNI)
1455 /* Initialize the JNI subsystem (must be done _before_
1456 threads_init, as threads_init can call JNI methods
1457 (e.g. NewGlobalRef). */
1460 VM::get_current()->abort("vm_create: jni_init failed");
1463 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1464 /* Initialize the local reference table for the main thread. */
1465 /* BEFORE: threads_init */
1467 if (!localref_table_init())
1468 VM::get_current()->abort("vm_create: localref_table_init failed");
1471 /* Iinitialize some important system classes. */
1472 /* BEFORE: threads_init */
1476 #if defined(ENABLE_THREADS)
1480 /* Initialize the native VM subsystem. */
1481 /* AFTER: threads_init (at least for SUN's classes) */
1485 #if defined(ENABLE_PROFILING)
1486 /* initialize profiling */
1488 if (!profile_init())
1489 VM::get_current()->abort("vm_create: profile_init failed");
1492 #if defined(ENABLE_THREADS)
1493 /* initialize recompilation */
1495 if (!recompile_init())
1496 VM::get_current()->abort("vm_create: recompile_init failed");
1498 /* start the signal handler thread */
1500 #if defined(__LINUX__)
1501 /* XXX Remove for exact-GC. */
1502 if (threads_pthreads_implementation_nptl)
1504 if (!signal_start_thread())
1505 VM::get_current()->abort("vm_create: signal_start_thread failed");
1507 /* finally, start the finalizer thread */
1509 if (!finalizer_start_thread())
1510 VM::get_current()->abort("vm_create: finalizer_start_thread failed");
1512 # if !defined(NDEBUG)
1513 /* start the memory profiling thread */
1515 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1516 if (!memory_start_thread())
1517 VM::get_current()->abort("vm_create: memory_start_thread failed");
1520 /* start the recompilation thread (must be done before the
1521 profiling thread) */
1523 if (!recompile_start_thread())
1524 VM::get_current()->abort("vm_create: recompile_start_thread failed");
1526 # if defined(ENABLE_PROFILING)
1527 /* start the profile sampling thread */
1530 /* if (!profile_start_thread()) */
1531 /* VM::get_current()->abort("vm_create: profile_start_thread failed"); */
1535 #if defined(ENABLE_JVMTI)
1536 # if defined(ENABLE_GC_CACAO)
1537 /* XXX this will not work with the new indirection cells for classloaders!!! */
1541 /* add agent library to native library hashtable */
1542 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1546 /* Increment the number of VMs. */
1550 // Initialization is done, VM is created.
1552 _initializing = false;
1554 // Print the run-time VM configuration after all stuff is set and
1555 // the VM is initialized.
1556 if (opt_PrintConfig)
1557 print_run_time_config();
1562 * Print build-time (default) VM configuration.
1564 void VM::print_build_time_config(void)
1566 puts("CACAO "VERSION" configure/build options:");
1568 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1569 #if defined(__VERSION__)
1570 puts(" CC : "VERSION_CC" ("__VERSION__")");
1571 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1573 puts(" CC : "VERSION_CC"");
1574 puts(" CXX : "VERSION_CXX"");
1576 puts(" CFLAGS : "VERSION_CFLAGS"");
1577 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1581 puts("Build-time (default) variables:\n");
1582 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1583 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1584 printf(" stack size : %d\n", STACK_SIZE);
1586 #if defined(ENABLE_JRE_LAYOUT)
1587 // When we're building with JRE-layout, the default paths are the
1588 // same as the runtime paths.
1590 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1591 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1592 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1593 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1594 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1595 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1604 * Print run-time VM configuration.
1606 void VM::print_run_time_config()
1608 puts("Run-time variables:\n");
1609 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1610 printf(" initial heap size : %d\n", opt_heapstartsize);
1611 printf(" stack size : %d\n", opt_stacksize);
1613 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1614 printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1615 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1616 printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1619 printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1620 printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1626 /* vm_run **********************************************************************
1628 Runs the main-method of the passed class.
1630 *******************************************************************************/
1632 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1638 classinfo *mainclass;
1641 java_handle_objectarray_t *oa;
1647 // Prevent compiler warnings.
1650 #if !defined(NDEBUG)
1657 /* Get the main class plus it's arguments. */
1661 if (opt_index < vm_args->nOptions) {
1662 /* Get main-class argument. */
1664 mainname = vm_args->options[opt_index].optionString;
1666 /* If the main class argument is a jar file, put it into the
1669 if (opt_jar == true) {
1670 p = MNEW(char, strlen(mainname) + strlen("0"));
1672 strcpy(p, mainname);
1674 #if defined(ENABLE_JAVASE)
1675 VM::get_current()->get_properties().put("java.class.path", p);
1679 /* Replace dots with slashes in the class name. */
1681 for (unsigned int i = 0; i < strlen(mainname); i++)
1682 if (mainname[i] == '.')
1686 /* Build argument array. Move index to first argument. */
1690 oalength = vm_args->nOptions - opt_index;
1692 oa = builtin_anewarray(oalength, class_java_lang_String);
1694 for (int i = 0; i < oalength; i++) {
1695 option = vm_args->options[opt_index + i].optionString;
1697 u = utf_new_char(option);
1698 s = javastring_new(u);
1700 array_objectarray_element_set(oa, i, s);
1704 /* Do we have a main-class argument? */
1706 if (mainname == NULL)
1709 #if !defined(NDEBUG)
1710 if (opt_method != NULL) {
1711 vm_compile_method(mainname);
1716 /* set return value to OK */
1720 if (opt_jar == true) {
1721 /* open jar file with java.util.jar.JarFile */
1723 mainname = vm_get_mainclass_from_jar(mainname);
1725 if (mainname == NULL)
1729 /* load the main class */
1731 mainutf = utf_new_char(mainname);
1733 #if defined(ENABLE_JAVAME_CLDC1_1)
1734 mainclass = load_class_bootstrap(mainutf);
1736 mainclass = load_class_from_sysloader(mainutf);
1739 /* error loading class */
1741 e = exceptions_get_and_clear_exception();
1743 if ((e != NULL) || (mainclass == NULL)) {
1744 exceptions_throw_noclassdeffounderror_cause(e);
1745 exceptions_print_stacktrace();
1749 if (!link_class(mainclass)) {
1750 exceptions_print_stacktrace();
1754 /* find the `main' method of the main class */
1756 m = class_resolveclassmethod(mainclass,
1757 utf_new_char("main"),
1758 utf_new_char("([Ljava/lang/String;)V"),
1759 class_java_lang_Object,
1762 if (exceptions_get_exception()) {
1763 exceptions_print_stacktrace();
1767 /* there is no main method or it isn't static */
1769 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1770 exceptions_clear_exception();
1771 exceptions_throw_nosuchmethoderror(mainclass,
1772 utf_new_char("main"),
1773 utf_new_char("([Ljava/lang/String;)V"));
1775 exceptions_print_stacktrace();
1779 #ifdef TYPEINFO_DEBUG_TEST
1780 /* test the typeinfo system */
1784 #if defined(ENABLE_JVMTI)
1785 jvmti_set_phase(JVMTI_PHASE_LIVE);
1788 /* set ThreadMXBean variables */
1790 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1791 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1793 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1794 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1795 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1796 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1797 #warning Move to C++
1799 /* start the main thread */
1801 (void) vm_call_method(m, NULL, oa);
1803 /* exception occurred? */
1805 if (exceptions_get_exception()) {
1806 exceptions_print_stacktrace();
1810 #if defined(ENABLE_THREADS)
1811 /* Detach the main thread so that it appears to have ended when
1812 the application's main method exits. */
1814 if (!thread_detach_current_thread())
1815 VM::get_current()->abort("vm_run: Could not detach main thread.");
1818 /* Destroy the JavaVM. */
1820 (void) vm_destroy(vm);
1828 /* vm_destroy ******************************************************************
1830 Unloads a Java VM and reclaims its resources.
1832 *******************************************************************************/
1834 int vm_destroy(JavaVM *vm)
1836 #if defined(ENABLE_THREADS)
1837 /* Create a a trivial new Java waiter thread called
1840 JavaVMAttachArgs args;
1842 args.name = (char*) "DestroyJavaVM";
1845 if (!thread_attach_current_thread(&args, false))
1848 /* Wait until we are the last non-daemon thread. */
1850 threads_join_all_threads();
1855 // _created = false;
1856 #warning Move to C++
1858 /* Everything is ok. */
1864 /* vm_exit *********************************************************************
1866 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1868 *******************************************************************************/
1870 void vm_exit(s4 status)
1874 /* signal that we are exiting */
1877 #warning Move to C++
1879 assert(class_java_lang_System);
1880 assert(class_java_lang_System->state & CLASS_LOADED);
1882 #if defined(ENABLE_JVMTI)
1883 if (jvmti || (dbgcom!=NULL)) {
1884 jvmti_set_phase(JVMTI_PHASE_DEAD);
1885 if (jvmti) jvmti_agentunload();
1889 if (!link_class(class_java_lang_System)) {
1890 exceptions_print_stacktrace();
1894 /* call java.lang.System.exit(I)V */
1896 m = class_resolveclassmethod(class_java_lang_System,
1897 utf_new_char("exit"),
1899 class_java_lang_Object,
1903 exceptions_print_stacktrace();
1907 /* call the exit function with passed exit status */
1909 (void) vm_call_method(m, NULL, status);
1911 /* If we had an exception, just ignore the exception and exit with
1914 vm_shutdown(status);
1918 /* vm_shutdown *****************************************************************
1920 Terminates the system immediately without freeing memory explicitly
1921 (to be used only for abnormal termination).
1923 *******************************************************************************/
1925 void vm_shutdown(s4 status)
1928 #if defined(ENABLE_STATISTICS)
1929 || opt_getcompilingtime || opt_stat
1933 log_text("CACAO terminated by shutdown");
1934 dolog("Exit status: %d\n", (s4) status);
1938 #if defined(ENABLE_JVMTI)
1939 /* terminate cacaodbgserver */
1941 mutex_lock(&dbgcomlock);
1943 mutex_unlock(&dbgcomlock);
1944 jvmti_cacaodbgserver_quit();
1952 /* vm_exit_handler *************************************************************
1954 The exit_handler function is called upon program termination.
1956 ATTENTION: Don't free system resources here! Some threads may still
1957 be running as this is called from VMRuntime.exit(). The OS does the
1960 *******************************************************************************/
1962 void vm_exit_handler(void)
1964 #if !defined(NDEBUG)
1966 class_showmethods(mainclass);
1968 if (showconstantpool)
1969 class_showconstantpool(mainclass);
1974 # if defined(ENABLE_PROFILING)
1976 profile_printstats();
1978 #endif /* !defined(NDEBUG) */
1980 #if defined(ENABLE_RT_TIMING)
1981 rt_timing_print_time_stats(stderr);
1984 #if defined(ENABLE_CYCLES_STATS)
1985 builtin_print_cycles_stats(stderr);
1986 stacktrace_print_cycles_stats(stderr);
1990 #if defined(ENABLE_STATISTICS)
1991 || opt_getcompilingtime || opt_stat
1995 log_text("CACAO terminated");
1997 #if defined(ENABLE_STATISTICS)
2000 #ifdef TYPECHECK_STATISTICS
2001 typecheck_print_statistics(get_logfile());
2005 if (opt_getcompilingtime)
2007 #endif /* defined(ENABLE_STATISTICS) */
2009 /* vm_print_profile(stderr);*/
2014 * Prints an error message and aborts the VM.
2016 * @param text Error message to print.
2018 void VM::abort(const char* text, ...)
2022 // Print the log message.
2026 log_vprint(text, ap);
2031 // Print a backtrace.
2032 os::print_backtrace();
2034 // Now abort the VM.
2040 * Prints an error message, appends ":" plus the strerror-message of
2041 * errnum and aborts the VM.
2043 * @param errnum Error number.
2044 * @param text Error message to print.
2046 void VM::abort_errnum(int errnum, const char* text, ...)
2050 // Print the log message.
2054 log_vprint(text, ap);
2057 // Print the strerror-message of errnum.
2058 log_print(": %s", os::strerror(errnum));
2062 // Print a backtrace.
2063 os::print_backtrace();
2065 // Now abort the VM.
2071 * Equal to VM::abort_errnum, but uses errno to get the error number.
2073 * @param text Error message to print.
2075 void VM::abort_errno(const char* text, ...)
2080 abort_errnum(errno, text, ap);
2085 /* vm_abort_disassemble ********************************************************
2087 Prints an error message, disassemble the given code range (if
2088 enabled) and aborts the VM.
2091 pc.......PC to disassemble
2092 count....number of instructions to disassemble
2094 *******************************************************************************/
2096 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2099 #if defined(ENABLE_DISASSEMBLER)
2103 /* Print debug message. */
2108 log_vprint(text, ap);
2115 #if SIZEOF_VOID_P == 8
2116 log_println("PC=0x%016lx", pc);
2118 log_println("PC=0x%08x", pc);
2121 #if defined(ENABLE_DISASSEMBLER)
2122 log_println("machine instructions at PC:");
2124 /* Disassemble the given number of instructions. */
2126 for (i = 0; i < count; i++)
2127 // FIXME disassinstr should use void*.
2128 pc = disassinstr((u1*) pc);
2131 VM::get_current()->abort("Aborting...");
2135 /* vm_get_mainclass_from_jar ***************************************************
2137 Gets the name of the main class from a JAR's manifest file.
2139 *******************************************************************************/
2141 static char *vm_get_mainclass_from_jar(char *mainname)
2148 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2151 exceptions_print_stacktrace();
2155 /* create JarFile object */
2160 exceptions_print_stacktrace();
2164 m = class_resolveclassmethod(c,
2166 utf_java_lang_String__void,
2167 class_java_lang_Object,
2171 exceptions_print_stacktrace();
2175 s = javastring_new_from_ascii(mainname);
2177 (void) vm_call_method(m, o, s);
2179 if (exceptions_get_exception()) {
2180 exceptions_print_stacktrace();
2184 /* get manifest object */
2186 m = class_resolveclassmethod(c,
2187 utf_new_char("getManifest"),
2188 utf_new_char("()Ljava/util/jar/Manifest;"),
2189 class_java_lang_Object,
2193 exceptions_print_stacktrace();
2197 o = vm_call_method(m, o);
2200 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2205 /* get Main Attributes */
2207 LLNI_class_get(o, c);
2209 m = class_resolveclassmethod(c,
2210 utf_new_char("getMainAttributes"),
2211 utf_new_char("()Ljava/util/jar/Attributes;"),
2212 class_java_lang_Object,
2216 exceptions_print_stacktrace();
2220 o = vm_call_method(m, o);
2223 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2228 /* get property Main-Class */
2230 LLNI_class_get(o, c);
2232 m = class_resolveclassmethod(c,
2233 utf_new_char("getValue"),
2234 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2235 class_java_lang_Object,
2239 exceptions_print_stacktrace();
2243 s = javastring_new_from_ascii("Main-Class");
2245 o = vm_call_method(m, o, s);
2248 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2249 fprintf(stderr, "%s\n", mainname);
2253 return javastring_tochar(o);
2257 /* vm_compile_all **************************************************************
2259 Compile all methods found in the bootclasspath.
2261 *******************************************************************************/
2263 #if !defined(NDEBUG)
2264 static void vm_compile_all(void)
2269 classcache_name_entry *nmen;
2270 classcache_class_entry *clsen;
2273 /* create all classes found in the bootclasspath */
2274 /* XXX currently only works with zip/jar's */
2276 loader_load_all_classes();
2278 /* link all classes */
2280 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2281 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2283 for (; nmen; nmen = nmen->hashlink) {
2284 /* iterate over all class entries */
2286 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2287 c = clsen->classobj;
2292 if (!(c->state & CLASS_LINKED)) {
2293 if (!link_class(c)) {
2294 fprintf(stderr, "Error linking: ");
2295 utf_fprint_printable_ascii_classname(stderr, c->name);
2296 fprintf(stderr, "\n");
2298 /* print out exception and cause */
2300 exceptions_print_current_exception();
2302 /* goto next class */
2308 /* compile all class methods */
2310 for (i = 0; i < c->methodscount; i++) {
2311 m = &(c->methods[i]);
2313 if (m->jcode != NULL) {
2314 if (!jit_compile(m)) {
2315 fprintf(stderr, "Error compiling: ");
2316 utf_fprint_printable_ascii_classname(stderr, c->name);
2317 fprintf(stderr, ".");
2318 utf_fprint_printable_ascii(stderr, m->name);
2319 utf_fprint_printable_ascii(stderr, m->descriptor);
2320 fprintf(stderr, "\n");
2322 /* print out exception and cause */
2324 exceptions_print_current_exception();
2332 #endif /* !defined(NDEBUG) */
2335 /* vm_compile_method ***********************************************************
2337 Compile a specific method.
2339 *******************************************************************************/
2341 #if !defined(NDEBUG)
2342 static void vm_compile_method(char* mainname)
2346 /* create, load and link the main class */
2348 mainclass = load_class_bootstrap(utf_new_char(mainname));
2350 if (mainclass == NULL)
2351 exceptions_print_stacktrace();
2353 if (!link_class(mainclass))
2354 exceptions_print_stacktrace();
2356 if (opt_signature != NULL) {
2357 m = class_resolveclassmethod(mainclass,
2358 utf_new_char(opt_method),
2359 utf_new_char(opt_signature),
2364 m = class_resolveclassmethod(mainclass,
2365 utf_new_char(opt_method),
2372 VM::get_current()->abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2373 opt_method, opt_signature ? opt_signature : "");
2377 #endif /* !defined(NDEBUG) */
2380 /* vm_call_array ***************************************************************
2382 Calls a Java method with a variable number of arguments, passed via
2385 ATTENTION: This function has to be used outside the nativeworld.
2387 *******************************************************************************/
2389 #define VM_CALL_ARRAY(name, type) \
2390 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2396 assert(m->code != NULL); \
2398 md = m->parseddesc; \
2399 pv = m->code->entrypoint; \
2401 STATISTICS(count_calls_native_to_java++); \
2403 value = asm_vm_call_method##name(pv, array, md->memuse); \
2408 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2414 assert(m->code != NULL);
2417 pv = m->code->entrypoint;
2419 STATISTICS(count_calls_native_to_java++);
2421 o = asm_vm_call_method(pv, array, md->memuse);
2423 if (md->returntype.type == TYPE_VOID)
2426 return LLNI_WRAP(o);
2429 VM_CALL_ARRAY(_int, int32_t)
2430 VM_CALL_ARRAY(_long, int64_t)
2431 VM_CALL_ARRAY(_float, float)
2432 VM_CALL_ARRAY(_double, double)
2435 /* vm_call_method **************************************************************
2437 Calls a Java method with a variable number of arguments.
2439 *******************************************************************************/
2441 #define VM_CALL_METHOD(name, type) \
2442 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2448 value = vm_call_method##name##_valist(m, o, ap); \
2454 VM_CALL_METHOD(, java_handle_t *)
2455 VM_CALL_METHOD(_int, int32_t)
2456 VM_CALL_METHOD(_long, int64_t)
2457 VM_CALL_METHOD(_float, float)
2458 VM_CALL_METHOD(_double, double)
2461 /* vm_call_method_valist *******************************************************
2463 Calls a Java method with a variable number of arguments, passed via
2466 *******************************************************************************/
2468 #define VM_CALL_METHOD_VALIST(name, type) \
2469 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2475 if (m->code == NULL) \
2476 if (!jit_compile(m)) \
2479 THREAD_NATIVEWORLD_EXIT; \
2481 DumpMemoryArea dma; \
2483 array = argument_vmarray_from_valist(m, o, ap); \
2484 value = vm_call##name##_array(m, array); \
2486 THREAD_NATIVEWORLD_ENTER; \
2491 VM_CALL_METHOD_VALIST(, java_handle_t *)
2492 VM_CALL_METHOD_VALIST(_int, int32_t)
2493 VM_CALL_METHOD_VALIST(_long, int64_t)
2494 VM_CALL_METHOD_VALIST(_float, float)
2495 VM_CALL_METHOD_VALIST(_double, double)
2498 /* vm_call_method_jvalue *******************************************************
2500 Calls a Java method with a variable number of arguments, passed via
2503 *******************************************************************************/
2505 #define VM_CALL_METHOD_JVALUE(name, type) \
2506 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2507 const jvalue *args) \
2512 if (m->code == NULL) \
2513 if (!jit_compile(m)) \
2516 THREAD_NATIVEWORLD_EXIT; \
2518 DumpMemoryArea dma; \
2520 array = argument_vmarray_from_jvalue(m, o, args); \
2521 value = vm_call##name##_array(m, array); \
2523 THREAD_NATIVEWORLD_ENTER; \
2528 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2529 VM_CALL_METHOD_JVALUE(_int, int32_t)
2530 VM_CALL_METHOD_JVALUE(_long, int64_t)
2531 VM_CALL_METHOD_JVALUE(_float, float)
2532 VM_CALL_METHOD_JVALUE(_double, double)
2535 /* vm_call_method_objectarray **************************************************
2537 Calls a Java method with a variable number if arguments, passed via
2538 an objectarray of boxed values. Returns a boxed value.
2540 *******************************************************************************/
2542 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2543 java_handle_objectarray_t *params)
2546 java_handle_t *xptr;
2550 /* Prevent compiler warnings. */
2554 /* compile methods which are not yet compiled */
2556 if (m->code == NULL)
2557 if (!jit_compile(m))
2560 /* leave the nativeworld */
2562 THREAD_NATIVEWORLD_EXIT;
2564 // Create new dump memory area.
2567 /* Fill the argument array from a object-array. */
2569 array = argument_vmarray_from_objectarray(m, o, params);
2571 if (array == NULL) {
2572 /* enter the nativeworld again */
2574 THREAD_NATIVEWORLD_ENTER;
2576 exceptions_throw_illegalargumentexception();
2581 switch (m->parseddesc->returntype.primitivetype) {
2582 case PRIMITIVETYPE_VOID:
2583 value.a = vm_call_array(m, array);
2586 case PRIMITIVETYPE_BOOLEAN:
2587 case PRIMITIVETYPE_BYTE:
2588 case PRIMITIVETYPE_CHAR:
2589 case PRIMITIVETYPE_SHORT:
2590 case PRIMITIVETYPE_INT:
2591 value.i = vm_call_int_array(m, array);
2594 case PRIMITIVETYPE_LONG:
2595 value.l = vm_call_long_array(m, array);
2598 case PRIMITIVETYPE_FLOAT:
2599 value.f = vm_call_float_array(m, array);
2602 case PRIMITIVETYPE_DOUBLE:
2603 value.d = vm_call_double_array(m, array);
2607 ro = vm_call_array(m, array);
2611 VM::get_current()->abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2614 /* enter the nativeworld again */
2616 THREAD_NATIVEWORLD_ENTER;
2618 /* box the return value if necesarry */
2620 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2621 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2623 /* check for an exception */
2625 xptr = exceptions_get_exception();
2628 /* clear exception pointer, we are calling JIT code again */
2630 exceptions_clear_exception();
2632 exceptions_throw_invocationtargetexception(xptr);
2639 /* Legacy C interface *********************************************************/
2643 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2644 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2645 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2646 bool VM_is_created() { return VM::get_current()->is_created(); }
2647 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2649 void vm_abort(const char* text, ...)
2654 VM::get_current()->abort(text, ap);
2658 void vm_abort_errnum(int errnum, const char* text, ...)
2663 VM::get_current()->abort_errnum(errnum, text, ap);
2667 void vm_abort_errno(const char* text, ...)
2672 VM::get_current()->abort_errno(text, ap);
2680 * These are local overrides for various environment variables in Emacs.
2681 * Please do not remove this and leave it at the end of the file, where
2682 * Emacs will automagically detect them.
2683 * ---------------------------------------------------------------------
2686 * indent-tabs-mode: t
2690 * vim:noexpandtab:sw=4:ts=4: