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/package.hpp"
77 #include "vm/primitive.hpp"
78 #include "vm/properties.h"
79 #include "vm/signallocal.h"
80 #include "vm/statistics.h"
81 #include "vm/string.hpp"
85 #include "vm/jit/argument.h"
86 #include "vm/jit/asmpart.h"
87 #include "vm/jit/code.h"
89 #if defined(ENABLE_DISASSEMBLER)
90 # include "vm/jit/disass.h"
93 #include "vm/jit/jit.hpp"
94 #include "vm/jit/methodtree.h"
96 #if defined(ENABLE_PROFILING)
97 # include "vm/jit/optimizing/profile.h"
100 #include "vm/jit/optimizing/recompile.h"
102 #if defined(ENABLE_PYTHON)
103 # include "vm/jit/python.h"
106 #include "vm/jit/trap.h"
108 #if defined(ENABLE_JVMTI)
109 # include "native/jvmti/cacaodbg.h"
112 #if defined(ENABLE_VMLOG)
113 #include <vmlog_cacao.h>
118 * This is _the_ VM instance.
123 /* global variables ***********************************************************/
125 s4 vms = 0; /* number of VMs created */
127 static classinfo *mainclass = NULL;
129 #if defined(ENABLE_INTRP)
130 u1 *intrp_main_stack = NULL;
134 /* define heap sizes **********************************************************/
136 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
137 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
138 #define STACK_SIZE 128 * 1024 /* default 64kB */
141 /* define command line options ************************************************/
175 /* Java non-standard options */
186 #if defined(ENABLE_PROFILING)
199 #if defined(ENABLE_STATISTICS)
216 #if defined(ENABLE_VERIFIER)
218 #if defined(TYPECHECK_VERBOSE)
221 #endif /* defined(ENABLE_VERIFIER) */
223 /* optimization options */
225 #if defined(ENABLE_LOOP)
229 #if defined(ENABLE_IFCONV)
233 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
237 #if defined(ENABLE_INTRP)
238 /* interpreter options */
257 #if defined(ENABLE_DEBUG_FILTER)
258 OPT_FILTER_VERBOSECALL_INCLUDE,
259 OPT_FILTER_VERBOSECALL_EXCLUDE,
260 OPT_FILTER_SHOW_METHOD,
267 opt_struct opts[] = {
268 { "foo", false, OPT_FOO },
272 { "jar", false, OPT_JAR },
274 { "d32", false, OPT_D32 },
275 { "d64", false, OPT_D64 },
276 { "client", false, OPT_IGNORE },
277 { "server", false, OPT_IGNORE },
278 { "jvm", false, OPT_IGNORE },
279 { "hotspot", false, OPT_IGNORE },
281 { "classpath", true, OPT_CLASSPATH },
282 { "cp", true, OPT_CLASSPATH },
283 { "D", true, OPT_D },
284 { "version", false, OPT_VERSION },
285 { "showversion", false, OPT_SHOWVERSION },
286 { "fullversion", false, OPT_FULLVERSION },
287 { "help", false, OPT_HELP },
288 { "?", false, OPT_HELP },
289 { "X", false, OPT_X },
290 { "XX:", true, OPT_XX },
292 { "ea:", true, OPT_EA },
293 { "da:", true, OPT_DA },
294 { "ea", false, OPT_EA_NOARG },
295 { "da", false, OPT_DA_NOARG },
297 { "enableassertions:", true, OPT_EA },
298 { "disableassertions:", true, OPT_DA },
299 { "enableassertions", false, OPT_EA_NOARG },
300 { "disableassertions", false, OPT_DA_NOARG },
302 { "esa", false, OPT_ESA },
303 { "enablesystemassertions", false, OPT_ESA },
304 { "dsa", false, OPT_DSA },
305 { "disablesystemassertions", false, OPT_DSA },
307 { "noasyncgc", false, OPT_IGNORE },
308 #if defined(ENABLE_VERIFIER)
309 { "noverify", false, OPT_NOVERIFY },
310 { "Xverify:none", false, OPT_NOVERIFY },
312 { "v", false, OPT_VERBOSE1 },
313 { "verbose:", true, OPT_VERBOSE },
315 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
316 { "verbosetc", false, OPT_VERBOSETC },
318 #if defined(__ALPHA__)
319 { "noieee", false, OPT_NOIEEE },
321 #if defined(ENABLE_STATISTICS)
322 { "time", false, OPT_TIME },
323 { "stat", false, OPT_STAT },
325 { "log", true, OPT_LOG },
326 { "c", true, OPT_CHECK },
327 { "l", false, OPT_LOAD },
330 { "all", false, OPT_ALL },
331 { "sig", true, OPT_SIGNATURE },
334 #if defined(ENABLE_LOOP)
335 { "oloop", false, OPT_OLOOP },
337 #if defined(ENABLE_IFCONV)
338 { "ifconv", false, OPT_IFCONV },
340 #if defined(ENABLE_LSRA)
341 { "lsra", false, OPT_LSRA },
343 #if defined(ENABLE_SSA)
344 { "lsra", true, OPT_LSRA },
347 #if defined(ENABLE_INTRP)
348 /* interpreter options */
350 { "trace", false, OPT_TRACE },
351 { "static-supers", true, OPT_STATIC_SUPERS },
352 { "no-dynamic", false, OPT_NO_DYNAMIC },
353 { "no-replication", false, OPT_NO_REPLICATION },
354 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
357 /* JVMTI Agent Command Line Options */
359 { "agentlib:", true, OPT_AGENTLIB },
360 { "agentpath:", true, OPT_AGENTPATH },
363 /* Java non-standard options */
365 { "Xjit", false, OPT_JIT },
366 { "Xint", false, OPT_INTRP },
367 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
368 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
369 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
370 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
373 { "Xdebug", false, OPT_DEBUG },
374 { "Xnoagent", false, OPT_NOAGENT },
375 { "Xrunjdwp", true, OPT_XRUNJDWP },
378 { "Xms", true, OPT_MS },
379 { "ms", true, OPT_MS },
380 { "Xmx", true, OPT_MX },
381 { "mx", true, OPT_MX },
382 { "Xss", true, OPT_SS },
383 { "ss", true, OPT_SS },
385 #if defined(ENABLE_PROFILING)
386 { "Xprof:", true, OPT_PROF_OPTION },
387 { "Xprof", false, OPT_PROF },
390 /* keep these at the end of the list */
393 { "m", true, OPT_METHOD },
396 { "s", true, OPT_SHOW },
397 { "debug-color", false, OPT_DEBUGCOLOR },
399 #if defined(ENABLE_DEBUG_FILTER)
400 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
401 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
402 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
409 /* usage ***********************************************************************
411 Prints the correct usage syntax to stdout.
413 *******************************************************************************/
417 puts("Usage: cacao [-options] classname [arguments]");
418 puts(" (to run a class file)");
419 puts(" or cacao [-options] -jar jarfile [arguments]");
420 puts(" (to run a standalone jar file)\n");
422 puts("where options include:");
423 puts(" -d32 use 32-bit data model if available");
424 puts(" -d64 use 64-bit data model if available");
425 puts(" -client compatibility (currently ignored)");
426 puts(" -server compatibility (currently ignored)");
427 puts(" -jvm compatibility (currently ignored)");
428 puts(" -hotspot compatibility (currently ignored)\n");
430 puts(" -cp <path> specify a path to look for classes");
431 puts(" -classpath <path> specify a path to look for classes");
432 puts(" -D<name>=<value> add an entry to the property list");
433 puts(" -verbose[:class|gc|jni] enable specific verbose output");
434 puts(" -version print product version and exit");
435 puts(" -fullversion print jpackage-compatible product version and exit");
436 puts(" -showversion print product version and continue");
437 puts(" -help, -? print this help message");
438 puts(" -X print help on non-standard Java options");
439 puts(" -XX print help on debugging options");
440 puts(" -ea[:<packagename>...|:<classname>]");
441 puts(" -enableassertions[:<packagename>...|:<classname>]");
442 puts(" enable assertions with specified granularity");
443 puts(" -da[:<packagename>...|:<classname>]");
444 puts(" -disableassertions[:<packagename>...|:<classname>]");
445 puts(" disable assertions with specified granularity");
446 puts(" -esa | -enablesystemassertions");
447 puts(" enable system assertions");
448 puts(" -dsa | -disablesystemassertions");
449 puts(" disable system assertions");
452 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
453 puts (" for jdwp help use: -agentlib:jdwp=help");
454 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
457 /* exit with error code */
463 static void Xusage(void)
465 #if defined(ENABLE_JIT)
466 puts(" -Xjit JIT mode execution (default)");
468 #if defined(ENABLE_INTRP)
469 puts(" -Xint interpreter mode execution");
471 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
472 puts(" value is set as bootstrap class path");
473 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
474 puts(" value is appended to the bootstrap class path");
475 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
476 puts(" value is prepended to the bootstrap class path");
477 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
478 puts(" value is used as Java core library, but the");
479 puts(" hardcoded VM interface classes are prepended");
480 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
481 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
482 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
484 #if defined(ENABLE_PROFILING)
485 puts(" -Xprof[:bb] collect and print profiling data");
488 #if defined(ENABLE_JVMTI)
489 /* -Xdebug option depend on gnu classpath JDWP options. options:
490 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
491 puts(" -Xdebug enable remote debugging\n");
492 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
493 puts(" enable remote debugging\n");
496 /* exit with error code */
503 static void XXusage(void)
505 puts(" -v write state-information");
507 puts(" -verbose:jit enable specific verbose output");
508 puts(" -debug-color colored output for ANSI terms");
510 #ifdef TYPECHECK_VERBOSE
511 puts(" -verbosetc write debug messages while typechecking");
513 #if defined(__ALPHA__)
514 puts(" -noieee don't use ieee compliant arithmetic");
516 #if defined(ENABLE_VERIFIER)
517 puts(" -noverify don't verify classfiles");
519 #if defined(ENABLE_STATISTICS)
520 puts(" -time measure the runtime");
521 puts(" -stat detailed compiler statistics");
523 puts(" -log logfile specify a name for the logfile");
524 puts(" -c(heck)b(ounds) don't check array bounds");
525 puts(" s(ync) don't check for synchronization");
526 #if defined(ENABLE_LOOP)
527 puts(" -oloop optimize array accesses in loops");
529 puts(" -l don't start the class after loading");
531 puts(" -all compile all methods, no execution");
532 puts(" -m compile only a specific method");
533 puts(" -sig specify signature for a specific method");
536 puts(" -s... show...");
537 puts(" (c)onstants the constant pool");
538 puts(" (m)ethods class fields and methods");
539 puts(" (u)tf the utf - hash");
540 puts(" (i)ntermediate intermediate representation");
541 #if defined(ENABLE_DISASSEMBLER)
542 puts(" (a)ssembler disassembled listing");
543 puts(" n(o)ps show NOPs in disassembler output");
545 puts(" (d)atasegment data segment listing");
547 #if defined(ENABLE_IFCONV)
548 puts(" -ifconv use if-conversion");
550 #if defined(ENABLE_LSRA)
551 puts(" -lsra use linear scan register allocation");
553 #if defined(ENABLE_SSA)
554 puts(" -lsra:... use linear scan register allocation (with SSA)");
555 puts(" (d)ead code elimination");
556 puts(" (c)opy propagation");
558 #if defined(ENABLE_DEBUG_FILTER)
559 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
560 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
561 puts(" -XXfm <regex> filter for show options");
563 /* exit with error code */
570 /* version *********************************************************************
572 Only prints cacao version information.
574 *******************************************************************************/
576 static void version(bool opt_exit)
578 puts("java version \""JAVA_VERSION"\"");
579 puts("CACAO version "VERSION"\n");
581 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
582 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
583 puts("This is free software; see the source for copying conditions. There is NO");
584 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
586 /* exit normally, if requested */
593 /* fullversion *****************************************************************
595 Prints a Sun compatible version information (required e.g. by
596 jpackage, www.jpackage.org).
598 *******************************************************************************/
600 static void fullversion(void)
602 puts("java full version \"cacao-"JAVA_VERSION"\"");
610 /* forward declarations *******************************************************/
612 static char *vm_get_mainclass_from_jar(char *mainstring);
614 static void vm_compile_all(void);
615 static void vm_compile_method(char* mainname);
620 * Implementation for JNI_CreateJavaVM. This function creates a VM
627 * @return true on success, false otherwise.
629 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
631 JavaVMInitArgs* _vm_args;
633 // Get the arguments for the new JVM.
634 _vm_args = (JavaVMInitArgs *) vm_args;
636 // Instantiate a new VM.
638 _vm = new VM(_vm_args);
640 catch (std::exception e) {
641 // FIXME How can we delete the resources allocated?
642 // /* release allocated memory */
643 // FREE(env, _Jv_JNIEnv);
644 // FREE(vm, _Jv_JavaVM);
651 // Return the values.
653 *p_vm = _vm->get_javavm();
654 *p_env = _vm->get_jnienv();
661 * C wrapper for VM::create.
664 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
666 return VM::create(p_vm, p_env, vm_args);
674 VM::VM(JavaVMInitArgs* vm_args)
676 // Very first thing to do: we are initializing.
677 _initializing = true;
679 // Make ourself globally visible.
680 // XXX Is this a good idea?
683 /* create and fill a JavaVM structure */
685 _javavm = new JavaVM();
687 #if defined(ENABLE_JNI)
688 _javavm->functions = &_Jv_JNIInvokeInterface;
691 /* get the VM and Env tables (must be set before vm_create) */
692 /* XXX JVMTI Agents needs a JavaVM */
694 _jnienv = new JNIEnv();
696 #if defined(ENABLE_JNI)
697 _jnienv->functions = &_Jv_JNINativeInterface;
700 /* actually create the JVM */
704 char *boot_class_path;
710 #if defined(ENABLE_JVMTI)
712 char *libname, *agentarg;
713 bool jdwp,agentbypath;
714 jdwp = agentbypath = false;
717 #if defined(ENABLE_JNI)
718 /* Check the JNI version requested. */
720 if (!jni_version_check(vm_args->version))
721 throw std::exception();
724 /* We only support 1 JVM instance. */
727 throw std::exception();
729 /* Install the exit handler. */
731 if (atexit(vm_exit_handler))
732 VM::get_current()->abort("atexit failed: %s\n", strerror(errno));
734 /* Set some options. */
741 opt_heapmaxsize = HEAP_MAXSIZE;
742 opt_heapstartsize = HEAP_STARTSIZE;
743 opt_stacksize = STACK_SIZE;
745 /* Initialize the properties list before command-line handling.
746 Otherwise -XX:+PrintConfig crashes. */
750 // First of all, parse the -XX options.
752 #if defined(ENABLE_VMLOG)
753 vmlog_cacao_init_options();
758 // After -XX options are parsed, print the build-time
759 // configuration, if requested.
761 print_build_time_config();
763 #if defined(ENABLE_VMLOG)
767 /* We need to check if the actual size of a java.lang.Class object
768 is smaller or equal than the assumption made in
771 #warning FIXME We need to check the size of java.lang.Class!!!
772 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
773 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
775 /* set the VM starttime */
777 _starttime = builtin_currenttimemillis();
779 #if defined(ENABLE_JVMTI)
780 /* initialize JVMTI related **********************************************/
784 /* Fill the properties before command-line handling. */
788 /* iterate over all passed options */
790 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
804 #if SIZEOF_VOID_P == 8
805 puts("Running a 32-bit JVM is not supported on this platform.");
811 #if SIZEOF_VOID_P == 4
812 puts("Running a 64-bit JVM is not supported on this platform.");
818 /* Forget old classpath and set the argument as new
821 // FIXME Make class_path const char*.
822 class_path = (char*) properties_get("java.class.path");
824 p = MNEW(char, strlen(opt_arg) + strlen("0"));
828 #if defined(ENABLE_JAVASE)
829 properties_add("java.class.path", p);
832 MFREE(class_path, char, strlen(class_path));
836 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
837 if (opt_arg[i] == '=') {
839 properties_add(opt_arg, opt_arg + i + 1);
844 /* if no '=' is given, just create an empty property */
846 properties_add(opt_arg, "");
851 case OPT_BOOTCLASSPATH:
852 /* Forget default bootclasspath and set the argument as
853 new boot classpath. */
855 // FIXME Make boot_class_path const char*.
856 boot_class_path = (char*) properties_get("sun.boot.class.path");
858 p = MNEW(char, strlen(opt_arg) + strlen("0"));
862 properties_add("sun.boot.class.path", p);
863 properties_add("java.boot.class.path", p);
865 MFREE(boot_class_path, char, strlen(boot_class_path));
868 case OPT_BOOTCLASSPATH_A:
869 /* Append to bootclasspath. */
871 // FIXME Make boot_class_path const char*.
872 boot_class_path = (char*) properties_get("sun.boot.class.path");
874 len = strlen(boot_class_path);
876 // XXX (char*) quick hack
877 p = (char*) MREALLOC(boot_class_path,
881 strlen(opt_arg) + strlen("0"));
886 properties_add("sun.boot.class.path", p);
887 properties_add("java.boot.class.path", p);
890 case OPT_BOOTCLASSPATH_P:
891 /* Prepend to bootclasspath. */
893 // FIXME Make boot_class_path const char*.
894 boot_class_path = (char*) properties_get("sun.boot.class.path");
896 len = strlen(boot_class_path);
898 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
902 strcat(p, boot_class_path);
904 properties_add("sun.boot.class.path", p);
905 properties_add("java.boot.class.path", p);
907 MFREE(boot_class_path, char, len);
910 case OPT_BOOTCLASSPATH_C:
911 /* Use as Java core library, but prepend VM interface
914 // FIXME Make boot_class_path const char*.
915 boot_class_path = (char*) properties_get("sun.boot.class.path");
918 strlen(CACAO_VM_ZIP) +
925 strcpy(p, CACAO_VM_ZIP);
929 properties_add("sun.boot.class.path", p);
930 properties_add("java.boot.class.path", p);
932 MFREE(boot_class_path, char, strlen(boot_class_path));
935 #if defined(ENABLE_JVMTI)
937 /* this option exists only for compatibility reasons */
941 /* I don't know yet what Xnoagent should do. This is only for
942 compatiblity with eclipse - motse */
951 strlen(CACAO_LIBDIR) +
952 strlen("/libjdwp.so=") +
956 agentarg = MNEW(char, len);
958 strcpy(agentarg, CACAO_LIBDIR);
959 strcat(agentarg, "/libjdwp.so=");
960 strcat(agentarg, &opt_arg[1]);
979 c = opt_arg[strlen(opt_arg) - 1];
981 if ((c == 'k') || (c == 'K')) {
982 j = atoi(opt_arg) * 1024;
984 } else if ((c == 'm') || (c == 'M')) {
985 j = atoi(opt_arg) * 1024 * 1024;
992 else if (opt == OPT_MS)
993 opt_heapstartsize = j;
1004 if (strcmp("class", opt_arg) == 0) {
1005 opt_verboseclass = true;
1007 else if (strcmp("gc", opt_arg) == 0) {
1008 opt_verbosegc = true;
1010 else if (strcmp("jni", opt_arg) == 0) {
1011 opt_verbosejni = true;
1013 #if !defined(NDEBUG)
1014 else if (strcmp("jit", opt_arg) == 0) {
1018 compileverbose = true;
1022 printf("Unknown -verbose option: %s\n", opt_arg);
1027 case OPT_DEBUGCOLOR:
1028 opt_debugcolor = true;
1031 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1033 opt_typecheckverbose = true;
1042 case OPT_FULLVERSION:
1046 case OPT_SHOWVERSION:
1054 #if defined(ENABLE_VERIFIER)
1060 #if defined(ENABLE_STATISTICS)
1062 opt_getcompilingtime = true;
1063 opt_getloadingtime = true;
1076 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1077 switch (opt_arg[i]) {
1079 checkbounds = false;
1092 makeinitializations = false;
1095 #if !defined(NDEBUG)
1099 makeinitializations = false;
1104 opt_method = opt_arg;
1105 makeinitializations = false;
1109 opt_signature = opt_arg;
1113 case OPT_SHOW: /* Display options */
1114 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1115 switch (opt_arg[i]) {
1117 showconstantpool = true;
1129 opt_showintermediate = true;
1130 compileverbose = true;
1133 #if defined(ENABLE_DISASSEMBLER)
1135 opt_showdisassemble = true;
1136 compileverbose = true;
1141 opt_showddatasegment = true;
1150 #if defined(ENABLE_LOOP)
1156 #if defined(ENABLE_IFCONV)
1162 #if defined(ENABLE_LSRA)
1167 #if defined(ENABLE_SSA)
1170 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1171 switch (opt_arg[i]) {
1199 /* Already parsed. */
1203 #if defined(ENABLE_ASSERTION)
1204 assertion_ea_da(opt_arg, true);
1209 #if defined(ENABLE_ASSERTION)
1210 assertion_ea_da(opt_arg, false);
1215 #if defined(ENABLE_ASSERTION)
1216 assertion_user_enabled = true;
1221 #if defined(ENABLE_ASSERTION)
1222 assertion_user_enabled = false;
1227 #if defined(ENABLE_ASSERTION)
1228 assertion_system_enabled = true;
1233 #if defined(ENABLE_ASSERTION)
1234 assertion_system_enabled = false;
1238 #if defined(ENABLE_PROFILING)
1239 case OPT_PROF_OPTION:
1240 /* use <= to get the last \0 too */
1242 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1243 if (opt_arg[i] == ',')
1246 if (opt_arg[i] == '\0') {
1247 if (strcmp("bb", opt_arg + j) == 0)
1251 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1255 /* set k to next char */
1268 #if defined(ENABLE_JIT)
1271 printf("-Xjit option not enabled.\n");
1277 #if defined(ENABLE_INTRP)
1280 printf("-Xint option not enabled.\n");
1285 #if defined(ENABLE_INTRP)
1286 case OPT_STATIC_SUPERS:
1287 opt_static_supers = atoi(opt_arg);
1290 case OPT_NO_DYNAMIC:
1291 opt_no_dynamic = true;
1294 case OPT_NO_REPLICATION:
1295 opt_no_replication = true;
1298 case OPT_NO_QUICKSUPER:
1299 opt_no_quicksuper = true;
1307 #if defined(ENABLE_DEBUG_FILTER)
1308 case OPT_FILTER_VERBOSECALL_INCLUDE:
1309 opt_filter_verbosecall_include = opt_arg;
1312 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1313 opt_filter_verbosecall_exclude = opt_arg;
1316 case OPT_FILTER_SHOW_METHOD:
1317 opt_filter_show_method = opt_arg;
1322 printf("Unknown option: %s\n",
1323 vm_args->options[opt_index].optionString);
1328 // Print the preliminary run-time VM configuration after options
1330 if (opt_PrintConfig)
1331 print_run_time_config();
1333 #if defined(ENABLE_JVMTI)
1335 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1336 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1339 MFREE(agentarg, char, strlen(agentarg));
1341 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1345 /* initialize the garbage collector */
1347 gc_init(opt_heapmaxsize, opt_heapstartsize);
1349 #if defined(ENABLE_THREADS)
1350 /* BEFORE: threads_preinit */
1354 /* AFTER: gc_init */
1360 /* install architecture dependent signal handlers */
1363 VM::get_current()->abort("vm_create: signal_init failed");
1365 #if defined(ENABLE_INTRP)
1366 /* Allocate main thread stack on the Java heap. */
1369 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1370 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1374 /* AFTER: threads_preinit */
1377 VM::get_current()->abort("vm_create: string_init failed");
1379 /* AFTER: threads_preinit */
1383 /* AFTER: thread_preinit */
1386 VM::get_current()->abort("vm_create: suck_init failed");
1388 suck_add_from_property("java.endorsed.dirs");
1390 /* Now we have all options handled and we can print the version
1393 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1398 /* AFTER: utf8_init */
1400 // FIXME Make boot_class_path const char*.
1401 boot_class_path = (char*) properties_get("sun.boot.class.path");
1402 suck_add(boot_class_path);
1404 /* initialize the classcache hashtable stuff: lock, hashtable
1405 (must be done _after_ threads_preinit) */
1407 if (!classcache_init())
1408 VM::get_current()->abort("vm_create: classcache_init failed");
1410 /* Initialize the code memory management. */
1411 /* AFTER: threads_preinit */
1415 /* initialize the finalizer stuff (must be done _after_
1418 if (!finalizer_init())
1419 VM::get_current()->abort("vm_create: finalizer_init failed");
1421 /* Initialize the JIT compiler. */
1427 #if defined(ENABLE_PYTHON)
1431 /* BEFORE: loader_preinit */
1433 Package::initialize();
1435 /* AFTER: utf8_init, classcache_init */
1440 // AFTER: loader_preinit, linker_preinit
1441 Primitive::initialize_table();
1446 // AFTER: loader_init, linker_init
1447 Primitive::post_initialize_table();
1450 #if defined(ENABLE_JIT)
1454 if (!builtin_init())
1455 VM::get_current()->abort("vm_create: builtin_init failed");
1457 /* Initialize the native subsystem. */
1458 /* BEFORE: threads_init */
1461 VM::get_current()->abort("vm_create: native_init failed");
1463 /* Register the native methods implemented in the VM. */
1464 /* BEFORE: threads_init */
1468 #if defined(ENABLE_JNI)
1469 /* Initialize the JNI subsystem (must be done _before_
1470 threads_init, as threads_init can call JNI methods
1471 (e.g. NewGlobalRef). */
1474 VM::get_current()->abort("vm_create: jni_init failed");
1477 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1478 /* Initialize the local reference table for the main thread. */
1479 /* BEFORE: threads_init */
1481 if (!localref_table_init())
1482 VM::get_current()->abort("vm_create: localref_table_init failed");
1485 /* Iinitialize some important system classes. */
1486 /* BEFORE: threads_init */
1490 #if defined(ENABLE_THREADS)
1494 /* Initialize the native VM subsystem. */
1495 /* AFTER: threads_init (at least for SUN's classes) */
1499 #if defined(ENABLE_PROFILING)
1500 /* initialize profiling */
1502 if (!profile_init())
1503 VM::get_current()->abort("vm_create: profile_init failed");
1506 #if defined(ENABLE_THREADS)
1507 /* initialize recompilation */
1509 if (!recompile_init())
1510 VM::get_current()->abort("vm_create: recompile_init failed");
1512 /* start the signal handler thread */
1514 #if defined(__LINUX__)
1515 /* XXX Remove for exact-GC. */
1516 if (threads_pthreads_implementation_nptl)
1518 if (!signal_start_thread())
1519 VM::get_current()->abort("vm_create: signal_start_thread failed");
1521 /* finally, start the finalizer thread */
1523 if (!finalizer_start_thread())
1524 VM::get_current()->abort("vm_create: finalizer_start_thread failed");
1526 # if !defined(NDEBUG)
1527 /* start the memory profiling thread */
1529 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1530 if (!memory_start_thread())
1531 VM::get_current()->abort("vm_create: memory_start_thread failed");
1534 /* start the recompilation thread (must be done before the
1535 profiling thread) */
1537 if (!recompile_start_thread())
1538 VM::get_current()->abort("vm_create: recompile_start_thread failed");
1540 # if defined(ENABLE_PROFILING)
1541 /* start the profile sampling thread */
1544 /* if (!profile_start_thread()) */
1545 /* VM::get_current()->abort("vm_create: profile_start_thread failed"); */
1549 #if defined(ENABLE_JVMTI)
1550 # if defined(ENABLE_GC_CACAO)
1551 /* XXX this will not work with the new indirection cells for classloaders!!! */
1555 /* add agent library to native library hashtable */
1556 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1560 /* Increment the number of VMs. */
1564 // Initialization is done, VM is created.
1566 _initializing = false;
1568 // Print the run-time VM configuration after all stuff is set and
1569 // the VM is initialized.
1570 if (opt_PrintConfig)
1571 print_run_time_config();
1576 * Print build-time (default) VM configuration.
1578 void VM::print_build_time_config(void)
1580 puts("CACAO "VERSION" configure/build options:");
1582 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1583 #if defined(__VERSION__)
1584 puts(" CC : "VERSION_CC" ("__VERSION__")");
1585 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1587 puts(" CC : "VERSION_CC"");
1588 puts(" CXX : "VERSION_CXX"");
1590 puts(" CFLAGS : "VERSION_CFLAGS"");
1591 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1595 puts("Build-time (default) variables:\n");
1596 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1597 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1598 printf(" stack size : %d\n", STACK_SIZE);
1600 #if defined(ENABLE_JRE_LAYOUT)
1601 // When we're building with JRE-layout, the default paths are the
1602 // same as the runtime paths.
1604 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1605 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1606 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1607 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1608 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1609 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1618 * Print run-time VM configuration.
1620 void VM::print_run_time_config(void)
1622 puts("Run-time variables:\n");
1623 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1624 printf(" initial heap size : %d\n", opt_heapstartsize);
1625 printf(" stack size : %d\n", opt_stacksize);
1627 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1628 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
1629 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1630 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
1633 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
1634 printf(" java.class.path : %s\n", properties_get("java.class.path"));
1640 /* vm_run **********************************************************************
1642 Runs the main-method of the passed class.
1644 *******************************************************************************/
1646 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1652 classinfo *mainclass;
1655 java_handle_objectarray_t *oa;
1661 // Prevent compiler warnings.
1664 #if !defined(NDEBUG)
1671 /* Get the main class plus it's arguments. */
1675 if (opt_index < vm_args->nOptions) {
1676 /* Get main-class argument. */
1678 mainname = vm_args->options[opt_index].optionString;
1680 /* If the main class argument is a jar file, put it into the
1683 if (opt_jar == true) {
1684 p = MNEW(char, strlen(mainname) + strlen("0"));
1686 strcpy(p, mainname);
1688 #if defined(ENABLE_JAVASE)
1689 properties_add("java.class.path", p);
1693 /* Replace dots with slashes in the class name. */
1695 for (unsigned int i = 0; i < strlen(mainname); i++)
1696 if (mainname[i] == '.')
1700 /* Build argument array. Move index to first argument. */
1704 oalength = vm_args->nOptions - opt_index;
1706 oa = builtin_anewarray(oalength, class_java_lang_String);
1708 for (int i = 0; i < oalength; i++) {
1709 option = vm_args->options[opt_index + i].optionString;
1711 u = utf_new_char(option);
1712 s = javastring_new(u);
1714 array_objectarray_element_set(oa, i, s);
1718 /* Do we have a main-class argument? */
1720 if (mainname == NULL)
1723 #if !defined(NDEBUG)
1724 if (opt_method != NULL) {
1725 vm_compile_method(mainname);
1730 /* set return value to OK */
1734 if (opt_jar == true) {
1735 /* open jar file with java.util.jar.JarFile */
1737 mainname = vm_get_mainclass_from_jar(mainname);
1739 if (mainname == NULL)
1743 /* load the main class */
1745 mainutf = utf_new_char(mainname);
1747 #if defined(ENABLE_JAVAME_CLDC1_1)
1748 mainclass = load_class_bootstrap(mainutf);
1750 mainclass = load_class_from_sysloader(mainutf);
1753 /* error loading class */
1755 e = exceptions_get_and_clear_exception();
1757 if ((e != NULL) || (mainclass == NULL)) {
1758 exceptions_throw_noclassdeffounderror_cause(e);
1759 exceptions_print_stacktrace();
1763 if (!link_class(mainclass)) {
1764 exceptions_print_stacktrace();
1768 /* find the `main' method of the main class */
1770 m = class_resolveclassmethod(mainclass,
1771 utf_new_char("main"),
1772 utf_new_char("([Ljava/lang/String;)V"),
1773 class_java_lang_Object,
1776 if (exceptions_get_exception()) {
1777 exceptions_print_stacktrace();
1781 /* there is no main method or it isn't static */
1783 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1784 exceptions_clear_exception();
1785 exceptions_throw_nosuchmethoderror(mainclass,
1786 utf_new_char("main"),
1787 utf_new_char("([Ljava/lang/String;)V"));
1789 exceptions_print_stacktrace();
1793 #ifdef TYPEINFO_DEBUG_TEST
1794 /* test the typeinfo system */
1798 #if defined(ENABLE_JVMTI)
1799 jvmti_set_phase(JVMTI_PHASE_LIVE);
1802 /* set ThreadMXBean variables */
1804 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1805 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1807 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1808 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1809 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1810 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1811 #warning Move to C++
1813 /* start the main thread */
1815 (void) vm_call_method(m, NULL, oa);
1817 /* exception occurred? */
1819 if (exceptions_get_exception()) {
1820 exceptions_print_stacktrace();
1824 #if defined(ENABLE_THREADS)
1825 /* Detach the main thread so that it appears to have ended when
1826 the application's main method exits. */
1828 if (!thread_detach_current_thread())
1829 VM::get_current()->abort("vm_run: Could not detach main thread.");
1832 /* Destroy the JavaVM. */
1834 (void) vm_destroy(vm);
1842 /* vm_destroy ******************************************************************
1844 Unloads a Java VM and reclaims its resources.
1846 *******************************************************************************/
1848 int vm_destroy(JavaVM *vm)
1850 #if defined(ENABLE_THREADS)
1851 /* Create a a trivial new Java waiter thread called
1854 JavaVMAttachArgs args;
1856 args.name = (char*) "DestroyJavaVM";
1859 if (!thread_attach_current_thread(&args, false))
1862 /* Wait until we are the last non-daemon thread. */
1864 threads_join_all_threads();
1869 // _created = false;
1870 #warning Move to C++
1872 /* Everything is ok. */
1878 /* vm_exit *********************************************************************
1880 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1882 *******************************************************************************/
1884 void vm_exit(s4 status)
1888 /* signal that we are exiting */
1891 #warning Move to C++
1893 assert(class_java_lang_System);
1894 assert(class_java_lang_System->state & CLASS_LOADED);
1896 #if defined(ENABLE_JVMTI)
1897 if (jvmti || (dbgcom!=NULL)) {
1898 jvmti_set_phase(JVMTI_PHASE_DEAD);
1899 if (jvmti) jvmti_agentunload();
1903 if (!link_class(class_java_lang_System)) {
1904 exceptions_print_stacktrace();
1908 /* call java.lang.System.exit(I)V */
1910 m = class_resolveclassmethod(class_java_lang_System,
1911 utf_new_char("exit"),
1913 class_java_lang_Object,
1917 exceptions_print_stacktrace();
1921 /* call the exit function with passed exit status */
1923 (void) vm_call_method(m, NULL, status);
1925 /* If we had an exception, just ignore the exception and exit with
1928 vm_shutdown(status);
1932 /* vm_shutdown *****************************************************************
1934 Terminates the system immediately without freeing memory explicitly
1935 (to be used only for abnormal termination).
1937 *******************************************************************************/
1939 void vm_shutdown(s4 status)
1942 #if defined(ENABLE_STATISTICS)
1943 || opt_getcompilingtime || opt_stat
1947 log_text("CACAO terminated by shutdown");
1948 dolog("Exit status: %d\n", (s4) status);
1952 #if defined(ENABLE_JVMTI)
1953 /* terminate cacaodbgserver */
1955 mutex_lock(&dbgcomlock);
1957 mutex_unlock(&dbgcomlock);
1958 jvmti_cacaodbgserver_quit();
1966 /* vm_exit_handler *************************************************************
1968 The exit_handler function is called upon program termination.
1970 ATTENTION: Don't free system resources here! Some threads may still
1971 be running as this is called from VMRuntime.exit(). The OS does the
1974 *******************************************************************************/
1976 void vm_exit_handler(void)
1978 #if !defined(NDEBUG)
1980 class_showmethods(mainclass);
1982 if (showconstantpool)
1983 class_showconstantpool(mainclass);
1988 # if defined(ENABLE_PROFILING)
1990 profile_printstats();
1992 #endif /* !defined(NDEBUG) */
1994 #if defined(ENABLE_RT_TIMING)
1995 rt_timing_print_time_stats(stderr);
1998 #if defined(ENABLE_CYCLES_STATS)
1999 builtin_print_cycles_stats(stderr);
2000 stacktrace_print_cycles_stats(stderr);
2004 #if defined(ENABLE_STATISTICS)
2005 || opt_getcompilingtime || opt_stat
2009 log_text("CACAO terminated");
2011 #if defined(ENABLE_STATISTICS)
2014 #ifdef TYPECHECK_STATISTICS
2015 typecheck_print_statistics(get_logfile());
2019 if (opt_getcompilingtime)
2021 #endif /* defined(ENABLE_STATISTICS) */
2023 /* vm_print_profile(stderr);*/
2028 * Prints an error message and aborts the VM.
2030 * @param text Error message to print.
2032 void VM::abort(const char* text, ...)
2036 // Print the log message.
2040 log_vprint(text, ap);
2045 // Print a backtrace.
2046 os::print_backtrace();
2048 // Now abort the VM.
2054 * Prints an error message, appends ":" plus the strerror-message of
2055 * errnum and aborts the VM.
2057 * @param errnum Error number.
2058 * @param text Error message to print.
2060 void VM::abort_errnum(int errnum, const char* text, ...)
2064 // Print the log message.
2068 log_vprint(text, ap);
2071 // Print the strerror-message of errnum.
2072 log_print(": %s", os::strerror(errnum));
2076 // Print a backtrace.
2077 os::print_backtrace();
2079 // Now abort the VM.
2085 * Equal to VM::abort_errnum, but uses errno to get the error number.
2087 * @param text Error message to print.
2089 void VM::abort_errno(const char* text, ...)
2094 abort_errnum(errno, text, ap);
2099 /* vm_abort_disassemble ********************************************************
2101 Prints an error message, disassemble the given code range (if
2102 enabled) and aborts the VM.
2105 pc.......PC to disassemble
2106 count....number of instructions to disassemble
2108 *******************************************************************************/
2110 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2113 #if defined(ENABLE_DISASSEMBLER)
2117 /* Print debug message. */
2122 log_vprint(text, ap);
2129 #if SIZEOF_VOID_P == 8
2130 log_println("PC=0x%016lx", pc);
2132 log_println("PC=0x%08x", pc);
2135 #if defined(ENABLE_DISASSEMBLER)
2136 log_println("machine instructions at PC:");
2138 /* Disassemble the given number of instructions. */
2140 for (i = 0; i < count; i++)
2141 // FIXME disassinstr should use void*.
2142 pc = disassinstr((u1*) pc);
2145 VM::get_current()->abort("Aborting...");
2149 /* vm_get_mainclass_from_jar ***************************************************
2151 Gets the name of the main class from a JAR's manifest file.
2153 *******************************************************************************/
2155 static char *vm_get_mainclass_from_jar(char *mainname)
2162 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2165 exceptions_print_stacktrace();
2169 /* create JarFile object */
2174 exceptions_print_stacktrace();
2178 m = class_resolveclassmethod(c,
2180 utf_java_lang_String__void,
2181 class_java_lang_Object,
2185 exceptions_print_stacktrace();
2189 s = javastring_new_from_ascii(mainname);
2191 (void) vm_call_method(m, o, s);
2193 if (exceptions_get_exception()) {
2194 exceptions_print_stacktrace();
2198 /* get manifest object */
2200 m = class_resolveclassmethod(c,
2201 utf_new_char("getManifest"),
2202 utf_new_char("()Ljava/util/jar/Manifest;"),
2203 class_java_lang_Object,
2207 exceptions_print_stacktrace();
2211 o = vm_call_method(m, o);
2214 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2219 /* get Main Attributes */
2221 LLNI_class_get(o, c);
2223 m = class_resolveclassmethod(c,
2224 utf_new_char("getMainAttributes"),
2225 utf_new_char("()Ljava/util/jar/Attributes;"),
2226 class_java_lang_Object,
2230 exceptions_print_stacktrace();
2234 o = vm_call_method(m, o);
2237 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2242 /* get property Main-Class */
2244 LLNI_class_get(o, c);
2246 m = class_resolveclassmethod(c,
2247 utf_new_char("getValue"),
2248 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2249 class_java_lang_Object,
2253 exceptions_print_stacktrace();
2257 s = javastring_new_from_ascii("Main-Class");
2259 o = vm_call_method(m, o, s);
2262 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2263 fprintf(stderr, "%s\n", mainname);
2267 return javastring_tochar(o);
2271 /* vm_compile_all **************************************************************
2273 Compile all methods found in the bootclasspath.
2275 *******************************************************************************/
2277 #if !defined(NDEBUG)
2278 static void vm_compile_all(void)
2283 classcache_name_entry *nmen;
2284 classcache_class_entry *clsen;
2287 /* create all classes found in the bootclasspath */
2288 /* XXX currently only works with zip/jar's */
2290 loader_load_all_classes();
2292 /* link all classes */
2294 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2295 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2297 for (; nmen; nmen = nmen->hashlink) {
2298 /* iterate over all class entries */
2300 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2301 c = clsen->classobj;
2306 if (!(c->state & CLASS_LINKED)) {
2307 if (!link_class(c)) {
2308 fprintf(stderr, "Error linking: ");
2309 utf_fprint_printable_ascii_classname(stderr, c->name);
2310 fprintf(stderr, "\n");
2312 /* print out exception and cause */
2314 exceptions_print_current_exception();
2316 /* goto next class */
2322 /* compile all class methods */
2324 for (i = 0; i < c->methodscount; i++) {
2325 m = &(c->methods[i]);
2327 if (m->jcode != NULL) {
2328 if (!jit_compile(m)) {
2329 fprintf(stderr, "Error compiling: ");
2330 utf_fprint_printable_ascii_classname(stderr, c->name);
2331 fprintf(stderr, ".");
2332 utf_fprint_printable_ascii(stderr, m->name);
2333 utf_fprint_printable_ascii(stderr, m->descriptor);
2334 fprintf(stderr, "\n");
2336 /* print out exception and cause */
2338 exceptions_print_current_exception();
2346 #endif /* !defined(NDEBUG) */
2349 /* vm_compile_method ***********************************************************
2351 Compile a specific method.
2353 *******************************************************************************/
2355 #if !defined(NDEBUG)
2356 static void vm_compile_method(char* mainname)
2360 /* create, load and link the main class */
2362 mainclass = load_class_bootstrap(utf_new_char(mainname));
2364 if (mainclass == NULL)
2365 exceptions_print_stacktrace();
2367 if (!link_class(mainclass))
2368 exceptions_print_stacktrace();
2370 if (opt_signature != NULL) {
2371 m = class_resolveclassmethod(mainclass,
2372 utf_new_char(opt_method),
2373 utf_new_char(opt_signature),
2378 m = class_resolveclassmethod(mainclass,
2379 utf_new_char(opt_method),
2386 VM::get_current()->abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2387 opt_method, opt_signature ? opt_signature : "");
2391 #endif /* !defined(NDEBUG) */
2394 /* vm_call_array ***************************************************************
2396 Calls a Java method with a variable number of arguments, passed via
2399 ATTENTION: This function has to be used outside the nativeworld.
2401 *******************************************************************************/
2403 #define VM_CALL_ARRAY(name, type) \
2404 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2410 assert(m->code != NULL); \
2412 md = m->parseddesc; \
2413 pv = m->code->entrypoint; \
2415 STATISTICS(count_calls_native_to_java++); \
2417 value = asm_vm_call_method##name(pv, array, md->memuse); \
2422 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2428 assert(m->code != NULL);
2431 pv = m->code->entrypoint;
2433 STATISTICS(count_calls_native_to_java++);
2435 o = asm_vm_call_method(pv, array, md->memuse);
2437 if (md->returntype.type == TYPE_VOID)
2440 return LLNI_WRAP(o);
2443 VM_CALL_ARRAY(_int, int32_t)
2444 VM_CALL_ARRAY(_long, int64_t)
2445 VM_CALL_ARRAY(_float, float)
2446 VM_CALL_ARRAY(_double, double)
2449 /* vm_call_method **************************************************************
2451 Calls a Java method with a variable number of arguments.
2453 *******************************************************************************/
2455 #define VM_CALL_METHOD(name, type) \
2456 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2462 value = vm_call_method##name##_valist(m, o, ap); \
2468 VM_CALL_METHOD(, java_handle_t *)
2469 VM_CALL_METHOD(_int, int32_t)
2470 VM_CALL_METHOD(_long, int64_t)
2471 VM_CALL_METHOD(_float, float)
2472 VM_CALL_METHOD(_double, double)
2475 /* vm_call_method_valist *******************************************************
2477 Calls a Java method with a variable number of arguments, passed via
2480 *******************************************************************************/
2482 #define VM_CALL_METHOD_VALIST(name, type) \
2483 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2489 if (m->code == NULL) \
2490 if (!jit_compile(m)) \
2493 THREAD_NATIVEWORLD_EXIT; \
2495 DumpMemoryArea dma; \
2497 array = argument_vmarray_from_valist(m, o, ap); \
2498 value = vm_call##name##_array(m, array); \
2500 THREAD_NATIVEWORLD_ENTER; \
2505 VM_CALL_METHOD_VALIST(, java_handle_t *)
2506 VM_CALL_METHOD_VALIST(_int, int32_t)
2507 VM_CALL_METHOD_VALIST(_long, int64_t)
2508 VM_CALL_METHOD_VALIST(_float, float)
2509 VM_CALL_METHOD_VALIST(_double, double)
2512 /* vm_call_method_jvalue *******************************************************
2514 Calls a Java method with a variable number of arguments, passed via
2517 *******************************************************************************/
2519 #define VM_CALL_METHOD_JVALUE(name, type) \
2520 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2521 const jvalue *args) \
2526 if (m->code == NULL) \
2527 if (!jit_compile(m)) \
2530 THREAD_NATIVEWORLD_EXIT; \
2532 DumpMemoryArea dma; \
2534 array = argument_vmarray_from_jvalue(m, o, args); \
2535 value = vm_call##name##_array(m, array); \
2537 THREAD_NATIVEWORLD_ENTER; \
2542 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2543 VM_CALL_METHOD_JVALUE(_int, int32_t)
2544 VM_CALL_METHOD_JVALUE(_long, int64_t)
2545 VM_CALL_METHOD_JVALUE(_float, float)
2546 VM_CALL_METHOD_JVALUE(_double, double)
2549 /* vm_call_method_objectarray **************************************************
2551 Calls a Java method with a variable number if arguments, passed via
2552 an objectarray of boxed values. Returns a boxed value.
2554 *******************************************************************************/
2556 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2557 java_handle_objectarray_t *params)
2560 java_handle_t *xptr;
2564 /* Prevent compiler warnings. */
2568 /* compile methods which are not yet compiled */
2570 if (m->code == NULL)
2571 if (!jit_compile(m))
2574 /* leave the nativeworld */
2576 THREAD_NATIVEWORLD_EXIT;
2578 // Create new dump memory area.
2581 /* Fill the argument array from a object-array. */
2583 array = argument_vmarray_from_objectarray(m, o, params);
2585 if (array == NULL) {
2586 /* enter the nativeworld again */
2588 THREAD_NATIVEWORLD_ENTER;
2590 exceptions_throw_illegalargumentexception();
2595 switch (m->parseddesc->returntype.primitivetype) {
2596 case PRIMITIVETYPE_VOID:
2597 value.a = vm_call_array(m, array);
2600 case PRIMITIVETYPE_BOOLEAN:
2601 case PRIMITIVETYPE_BYTE:
2602 case PRIMITIVETYPE_CHAR:
2603 case PRIMITIVETYPE_SHORT:
2604 case PRIMITIVETYPE_INT:
2605 value.i = vm_call_int_array(m, array);
2608 case PRIMITIVETYPE_LONG:
2609 value.l = vm_call_long_array(m, array);
2612 case PRIMITIVETYPE_FLOAT:
2613 value.f = vm_call_float_array(m, array);
2616 case PRIMITIVETYPE_DOUBLE:
2617 value.d = vm_call_double_array(m, array);
2621 ro = vm_call_array(m, array);
2625 VM::get_current()->abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2628 /* enter the nativeworld again */
2630 THREAD_NATIVEWORLD_ENTER;
2632 /* box the return value if necesarry */
2634 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2635 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2637 /* check for an exception */
2639 xptr = exceptions_get_exception();
2642 /* clear exception pointer, we are calling JIT code again */
2644 exceptions_clear_exception();
2646 exceptions_throw_invocationtargetexception(xptr);
2653 /* Legacy C interface *********************************************************/
2657 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2658 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2659 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2660 bool VM_is_created() { return VM::get_current()->is_created(); }
2661 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2663 void vm_abort(const char* text, ...)
2668 VM::get_current()->abort(text, ap);
2672 void vm_abort_errnum(int errnum, const char* text, ...)
2677 VM::get_current()->abort_errnum(errnum, text, ap);
2681 void vm_abort_errno(const char* text, ...)
2686 VM::get_current()->abort_errno(text, ap);
2694 * These are local overrides for various environment variables in Emacs.
2695 * Please do not remove this and leave it at the end of the file, where
2696 * Emacs will automagically detect them.
2697 * ---------------------------------------------------------------------
2700 * indent-tabs-mode: t
2704 * vim:noexpandtab:sw=4:ts=4: