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"
45 #include "mm/memory.h"
47 #include "native/jni.h"
48 #include "native/llni.h"
49 #include "native/localref.h"
50 #include "native/native.h"
52 #include "native/vm/nativevm.h"
54 #include "threads/lock-common.h"
55 #include "threads/threadlist.h"
56 #include "threads/thread.hpp"
58 #include "toolbox/logging.h"
62 #if defined(ENABLE_ASSERTION)
63 #include "vm/assertion.h"
66 #include "vm/builtin.h"
67 #include "vm/classcache.h"
68 #include "vm/exceptions.hpp"
69 #include "vm/finalizer.h"
70 #include "vm/global.h"
71 #include "vm/globals.hpp"
72 #include "vm/initialize.h"
73 #include "vm/options.h"
75 #include "vm/package.hpp"
76 #include "vm/primitive.hpp"
77 #include "vm/properties.h"
78 #include "vm/signallocal.h"
79 #include "vm/statistics.h"
80 #include "vm/string.hpp"
84 #include "vm/jit/argument.h"
85 #include "vm/jit/asmpart.h"
86 #include "vm/jit/code.h"
88 #if defined(ENABLE_DISASSEMBLER)
89 # include "vm/jit/disass.h"
92 #include "vm/jit/jit.h"
93 #include "vm/jit/jitcache.h"
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_ instance of the VM.
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 static void vm_printconfig(void)
612 puts("Configure/Build options:\n");
613 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
614 #if defined(__VERSION__)
615 puts(" CC : "VERSION_CC" ("__VERSION__")");
617 puts(" CC : "VERSION_CC"");
619 puts(" CFLAGS : "VERSION_CFLAGS"\n");
621 puts("Default variables:\n");
622 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
623 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
624 printf(" stack size : %d\n", STACK_SIZE);
626 #if defined(ENABLE_JRE_LAYOUT)
627 /* When we're building with JRE-layout, the default paths are the
628 same as the runtime paths. */
630 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
631 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
632 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
633 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
634 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
635 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
641 puts("Runtime variables:\n");
642 printf(" maximum heap size : %d\n", opt_heapmaxsize);
643 printf(" initial heap size : %d\n", opt_heapstartsize);
644 printf(" stack size : %d\n", opt_stacksize);
646 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
647 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
648 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
649 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
652 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
653 printf(" java.class.path : %s\n", properties_get("java.class.path"));
657 /* forward declarations *******************************************************/
659 static char *vm_get_mainclass_from_jar(char *mainstring);
661 static void vm_compile_all(void);
662 static void vm_compile_method(char* mainname);
667 * Implementation for JNI_CreateJavaVM. This function creates a VM
674 * @return true on success, false otherwise.
676 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
678 JavaVMInitArgs* _vm_args;
680 // Get the arguments for the new JVM.
681 _vm_args = (JavaVMInitArgs *) vm_args;
683 // Instantiate a new VM.
685 vm = new VM(_vm_args);
687 catch (std::exception e) {
688 // FIXME How can we delete the resources allocated?
689 // /* release allocated memory */
690 // FREE(env, _Jv_JNIEnv);
691 // FREE(vm, _Jv_JavaVM);
698 // Return the values.
700 *p_vm = vm->get_javavm();
701 *p_env = vm->get_jnienv();
708 * C wrapper for VM::create.
711 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
713 return VM::create(p_vm, p_env, vm_args);
721 VM::VM(JavaVMInitArgs* vm_args)
723 // Very first thing to do: we are initializing.
724 _initializing = true;
726 // Make ourself globally visible.
727 // XXX Is this a good idea?
730 /* create and fill a JavaVM structure */
732 _javavm = new JavaVM();
734 #if defined(ENABLE_JNI)
735 _javavm->functions = &_Jv_JNIInvokeInterface;
738 /* get the VM and Env tables (must be set before vm_create) */
739 /* XXX JVMTI Agents needs a JavaVM */
741 _jnienv = new JNIEnv();
743 #if defined(ENABLE_JNI)
744 _jnienv->functions = &_Jv_JNINativeInterface;
747 /* actually create the JVM */
751 char *boot_class_path;
757 #if defined(ENABLE_JVMTI)
759 char *libname, *agentarg;
760 bool jdwp,agentbypath;
761 jdwp = agentbypath = false;
764 #if defined(ENABLE_JNI)
765 /* Check the JNI version requested. */
767 if (!jni_version_check(vm_args->version))
768 throw std::exception();
771 /* We only support 1 JVM instance. */
774 throw std::exception();
776 /* Install the exit handler. */
778 if (atexit(vm_exit_handler))
779 vm_abort("atexit failed: %s\n", strerror(errno));
781 /* Set some options. */
788 opt_heapmaxsize = HEAP_MAXSIZE;
789 opt_heapstartsize = HEAP_STARTSIZE;
790 opt_stacksize = STACK_SIZE;
792 /* Initialize the properties list before command-line handling.
793 Otherwise -XX:+PrintConfig crashes. */
797 /* First of all, parse the -XX options. */
799 #if defined(ENABLE_VMLOG)
800 vmlog_cacao_init_options();
805 #if defined(ENABLE_VMLOG)
809 /* We need to check if the actual size of a java.lang.Class object
810 is smaller or equal than the assumption made in
813 #warning FIXME We need to check the size of java.lang.Class!!!
814 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
815 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
817 /* set the VM starttime */
819 _starttime = builtin_currenttimemillis();
821 #if defined(ENABLE_JVMTI)
822 /* initialize JVMTI related **********************************************/
826 /* Fill the properties before command-line handling. */
830 /* iterate over all passed options */
832 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
846 #if SIZEOF_VOID_P == 8
847 puts("Running a 32-bit JVM is not supported on this platform.");
853 #if SIZEOF_VOID_P == 4
854 puts("Running a 64-bit JVM is not supported on this platform.");
860 /* Forget old classpath and set the argument as new
863 // FIXME Make class_path const char*.
864 class_path = (char*) properties_get("java.class.path");
866 p = MNEW(char, strlen(opt_arg) + strlen("0"));
870 #if defined(ENABLE_JAVASE)
871 properties_add("java.class.path", p);
874 MFREE(class_path, char, strlen(class_path));
878 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
879 if (opt_arg[i] == '=') {
881 properties_add(opt_arg, opt_arg + i + 1);
886 /* if no '=' is given, just create an empty property */
888 properties_add(opt_arg, "");
893 case OPT_BOOTCLASSPATH:
894 /* Forget default bootclasspath and set the argument as
895 new boot classpath. */
897 // FIXME Make boot_class_path const char*.
898 boot_class_path = (char*) properties_get("sun.boot.class.path");
900 p = MNEW(char, strlen(opt_arg) + strlen("0"));
904 properties_add("sun.boot.class.path", p);
905 properties_add("java.boot.class.path", p);
907 MFREE(boot_class_path, char, strlen(boot_class_path));
910 case OPT_BOOTCLASSPATH_A:
911 /* Append to bootclasspath. */
913 // FIXME Make boot_class_path const char*.
914 boot_class_path = (char*) properties_get("sun.boot.class.path");
916 len = strlen(boot_class_path);
918 // XXX (char*) quick hack
919 p = (char*) MREALLOC(boot_class_path,
923 strlen(opt_arg) + strlen("0"));
928 properties_add("sun.boot.class.path", p);
929 properties_add("java.boot.class.path", p);
932 case OPT_BOOTCLASSPATH_P:
933 /* Prepend to bootclasspath. */
935 // FIXME Make boot_class_path const char*.
936 boot_class_path = (char*) properties_get("sun.boot.class.path");
938 len = strlen(boot_class_path);
940 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
944 strcat(p, boot_class_path);
946 properties_add("sun.boot.class.path", p);
947 properties_add("java.boot.class.path", p);
949 MFREE(boot_class_path, char, len);
952 case OPT_BOOTCLASSPATH_C:
953 /* Use as Java core library, but prepend VM interface
956 // FIXME Make boot_class_path const char*.
957 boot_class_path = (char*) properties_get("sun.boot.class.path");
960 strlen(CACAO_VM_ZIP) +
967 strcpy(p, CACAO_VM_ZIP);
971 properties_add("sun.boot.class.path", p);
972 properties_add("java.boot.class.path", p);
974 MFREE(boot_class_path, char, strlen(boot_class_path));
977 #if defined(ENABLE_JVMTI)
979 /* this option exists only for compatibility reasons */
983 /* I don't know yet what Xnoagent should do. This is only for
984 compatiblity with eclipse - motse */
993 strlen(CACAO_LIBDIR) +
994 strlen("/libjdwp.so=") +
998 agentarg = MNEW(char, len);
1000 strcpy(agentarg, CACAO_LIBDIR);
1001 strcat(agentarg, "/libjdwp.so=");
1002 strcat(agentarg, &opt_arg[1]);
1021 c = opt_arg[strlen(opt_arg) - 1];
1023 if ((c == 'k') || (c == 'K')) {
1024 j = atoi(opt_arg) * 1024;
1026 } else if ((c == 'm') || (c == 'M')) {
1027 j = atoi(opt_arg) * 1024 * 1024;
1033 opt_heapmaxsize = j;
1034 else if (opt == OPT_MS)
1035 opt_heapstartsize = j;
1046 if (strcmp("class", opt_arg) == 0) {
1047 opt_verboseclass = true;
1049 else if (strcmp("gc", opt_arg) == 0) {
1050 opt_verbosegc = true;
1052 else if (strcmp("jni", opt_arg) == 0) {
1053 opt_verbosejni = true;
1055 #if !defined(NDEBUG)
1056 else if (strcmp("jit", opt_arg) == 0) {
1060 compileverbose = true;
1064 printf("Unknown -verbose option: %s\n", opt_arg);
1069 case OPT_DEBUGCOLOR:
1070 opt_debugcolor = true;
1073 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1075 opt_typecheckverbose = true;
1084 case OPT_FULLVERSION:
1088 case OPT_SHOWVERSION:
1096 #if defined(ENABLE_VERIFIER)
1102 #if defined(ENABLE_STATISTICS)
1104 opt_getcompilingtime = true;
1105 opt_getloadingtime = true;
1118 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1119 switch (opt_arg[i]) {
1121 checkbounds = false;
1134 makeinitializations = false;
1137 #if !defined(NDEBUG)
1141 makeinitializations = false;
1146 opt_method = opt_arg;
1147 makeinitializations = false;
1151 opt_signature = opt_arg;
1155 case OPT_SHOW: /* Display options */
1156 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1157 switch (opt_arg[i]) {
1159 showconstantpool = true;
1171 opt_showintermediate = true;
1172 compileverbose = true;
1175 #if defined(ENABLE_DISASSEMBLER)
1177 opt_showdisassemble = true;
1178 compileverbose = true;
1182 opt_shownops = true;
1187 opt_showddatasegment = true;
1196 #if defined(ENABLE_LOOP)
1202 #if defined(ENABLE_IFCONV)
1208 #if defined(ENABLE_LSRA)
1213 #if defined(ENABLE_SSA)
1216 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1217 switch (opt_arg[i]) {
1245 /* Already parsed. */
1249 #if defined(ENABLE_ASSERTION)
1250 assertion_ea_da(opt_arg, true);
1255 #if defined(ENABLE_ASSERTION)
1256 assertion_ea_da(opt_arg, false);
1261 #if defined(ENABLE_ASSERTION)
1262 assertion_user_enabled = true;
1267 #if defined(ENABLE_ASSERTION)
1268 assertion_user_enabled = false;
1273 #if defined(ENABLE_ASSERTION)
1274 assertion_system_enabled = true;
1279 #if defined(ENABLE_ASSERTION)
1280 assertion_system_enabled = false;
1284 #if defined(ENABLE_PROFILING)
1285 case OPT_PROF_OPTION:
1286 /* use <= to get the last \0 too */
1288 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1289 if (opt_arg[i] == ',')
1292 if (opt_arg[i] == '\0') {
1293 if (strcmp("bb", opt_arg + j) == 0)
1297 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1301 /* set k to next char */
1314 #if defined(ENABLE_JIT)
1317 printf("-Xjit option not enabled.\n");
1323 #if defined(ENABLE_INTRP)
1326 printf("-Xint option not enabled.\n");
1331 #if defined(ENABLE_INTRP)
1332 case OPT_STATIC_SUPERS:
1333 opt_static_supers = atoi(opt_arg);
1336 case OPT_NO_DYNAMIC:
1337 opt_no_dynamic = true;
1340 case OPT_NO_REPLICATION:
1341 opt_no_replication = true;
1344 case OPT_NO_QUICKSUPER:
1345 opt_no_quicksuper = true;
1353 #if defined(ENABLE_DEBUG_FILTER)
1354 case OPT_FILTER_VERBOSECALL_INCLUDE:
1355 opt_filter_verbosecall_include = opt_arg;
1358 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1359 opt_filter_verbosecall_exclude = opt_arg;
1362 case OPT_FILTER_SHOW_METHOD:
1363 opt_filter_show_method = opt_arg;
1368 printf("Unknown option: %s\n",
1369 vm_args->options[opt_index].optionString);
1374 #if defined(ENABLE_JVMTI)
1376 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1377 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1380 MFREE(agentarg, char, strlen(agentarg));
1382 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1386 /* initialize the garbage collector */
1388 gc_init(opt_heapmaxsize, opt_heapstartsize);
1390 #if defined(ENABLE_THREADS)
1391 /* BEFORE: threads_preinit */
1395 /* AFTER: gc_init */
1401 /* install architecture dependent signal handlers */
1404 vm_abort("vm_create: signal_init failed");
1406 #if defined(ENABLE_INTRP)
1407 /* Allocate main thread stack on the Java heap. */
1410 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1411 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1415 /* AFTER: threads_preinit */
1418 vm_abort("vm_create: string_init failed");
1420 /* AFTER: threads_preinit */
1424 /* AFTER: thread_preinit */
1427 vm_abort("vm_create: suck_init failed");
1429 suck_add_from_property("java.endorsed.dirs");
1431 /* Now we have all options handled and we can print the version
1434 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1439 /* AFTER: utf8_init */
1441 // FIXME Make boot_class_path const char*.
1442 boot_class_path = (char*) properties_get("sun.boot.class.path");
1443 suck_add(boot_class_path);
1445 /* initialize the classcache hashtable stuff: lock, hashtable
1446 (must be done _after_ threads_preinit) */
1448 if (!classcache_init())
1449 vm_abort("vm_create: classcache_init failed");
1451 /* Initialize the code memory management. */
1452 /* AFTER: threads_preinit */
1456 /* initialize the finalizer stuff (must be done _after_
1459 if (!finalizer_init())
1460 vm_abort("vm_create: finalizer_init failed");
1462 /* Initialize the JIT compiler. */
1468 #if defined(ENABLE_PYTHON)
1472 /* BEFORE: loader_preinit */
1474 Package::initialize();
1476 /* AFTER: utf8_init, classcache_init */
1481 /* AFTER: loader_preinit, linker_preinit */
1488 /* AFTER: loader_init, linker_init */
1490 primitive_postinit();
1493 #if defined(ENABLE_JIT)
1497 if (!builtin_init())
1498 vm_abort("vm_create: builtin_init failed");
1500 /* Initialize the native subsystem. */
1501 /* BEFORE: threads_init */
1504 vm_abort("vm_create: native_init failed");
1506 /* Register the native methods implemented in the VM. */
1507 /* BEFORE: threads_init */
1511 #if defined(ENABLE_JNI)
1512 /* Initialize the JNI subsystem (must be done _before_
1513 threads_init, as threads_init can call JNI methods
1514 (e.g. NewGlobalRef). */
1517 vm_abort("vm_create: jni_init failed");
1520 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1521 /* Initialize the local reference table for the main thread. */
1522 /* BEFORE: threads_init */
1524 if (!localref_table_init())
1525 vm_abort("vm_create: localref_table_init failed");
1528 /* Iinitialize some important system classes. */
1529 /* BEFORE: threads_init */
1533 #if defined(ENABLE_THREADS)
1537 /* Initialize the native VM subsystem. */
1538 /* AFTER: threads_init (at least for SUN's classes) */
1542 #if defined(ENABLE_PROFILING)
1543 /* initialize profiling */
1545 if (!profile_init())
1546 vm_abort("vm_create: profile_init failed");
1549 #if defined(ENABLE_THREADS)
1550 /* initialize recompilation */
1552 if (!recompile_init())
1553 vm_abort("vm_create: recompile_init failed");
1555 /* start the signal handler thread */
1557 #if defined(__LINUX__)
1558 /* XXX Remove for exact-GC. */
1559 if (threads_pthreads_implementation_nptl)
1561 if (!signal_start_thread())
1562 vm_abort("vm_create: signal_start_thread failed");
1564 /* finally, start the finalizer thread */
1566 if (!finalizer_start_thread())
1567 vm_abort("vm_create: finalizer_start_thread failed");
1569 # if !defined(NDEBUG)
1570 /* start the memory profiling thread */
1572 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1573 if (!memory_start_thread())
1574 vm_abort("vm_create: memory_start_thread failed");
1577 /* start the recompilation thread (must be done before the
1578 profiling thread) */
1580 if (!recompile_start_thread())
1581 vm_abort("vm_create: recompile_start_thread failed");
1583 # if defined(ENABLE_PROFILING)
1584 /* start the profile sampling thread */
1587 /* if (!profile_start_thread()) */
1588 /* vm_abort("vm_create: profile_start_thread failed"); */
1592 #if defined(ENABLE_JVMTI)
1593 # if defined(ENABLE_GC_CACAO)
1594 /* XXX this will not work with the new indirection cells for classloaders!!! */
1598 /* add agent library to native library hashtable */
1599 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1603 /* Increment the number of VMs. */
1607 // Initialization is done, VM is created.
1609 _initializing = false;
1611 /* Print the VM configuration after all stuff is set and the VM is
1614 if (opt_PrintConfig)
1619 /* vm_run **********************************************************************
1621 Runs the main-method of the passed class.
1623 *******************************************************************************/
1625 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1631 classinfo *mainclass;
1634 java_handle_objectarray_t *oa;
1640 // Prevent compiler warnings.
1643 #if !defined(NDEBUG)
1650 /* Get the main class plus it's arguments. */
1654 if (opt_index < vm_args->nOptions) {
1655 /* Get main-class argument. */
1657 mainname = vm_args->options[opt_index].optionString;
1659 /* If the main class argument is a jar file, put it into the
1662 if (opt_jar == true) {
1663 p = MNEW(char, strlen(mainname) + strlen("0"));
1665 strcpy(p, mainname);
1667 #if defined(ENABLE_JAVASE)
1668 properties_add("java.class.path", p);
1672 /* Replace dots with slashes in the class name. */
1674 for (unsigned int i = 0; i < strlen(mainname); i++)
1675 if (mainname[i] == '.')
1679 /* Build argument array. Move index to first argument. */
1683 oalength = vm_args->nOptions - opt_index;
1685 oa = builtin_anewarray(oalength, class_java_lang_String);
1687 for (int i = 0; i < oalength; i++) {
1688 option = vm_args->options[opt_index + i].optionString;
1690 u = utf_new_char(option);
1691 s = javastring_new(u);
1693 array_objectarray_element_set(oa, i, s);
1697 /* Do we have a main-class argument? */
1699 if (mainname == NULL)
1702 #if !defined(NDEBUG)
1703 if (opt_method != NULL) {
1704 vm_compile_method(mainname);
1709 /* set return value to OK */
1713 if (opt_jar == true) {
1714 /* open jar file with java.util.jar.JarFile */
1716 mainname = vm_get_mainclass_from_jar(mainname);
1718 if (mainname == NULL)
1722 /* load the main class */
1724 mainutf = utf_new_char(mainname);
1726 #if defined(ENABLE_JAVAME_CLDC1_1)
1727 mainclass = load_class_bootstrap(mainutf);
1729 mainclass = load_class_from_sysloader(mainutf);
1732 /* error loading class */
1734 e = exceptions_get_and_clear_exception();
1736 if ((e != NULL) || (mainclass == NULL)) {
1737 exceptions_throw_noclassdeffounderror_cause(e);
1738 exceptions_print_stacktrace();
1742 if (!link_class(mainclass)) {
1743 exceptions_print_stacktrace();
1747 /* find the `main' method of the main class */
1749 m = class_resolveclassmethod(mainclass,
1750 utf_new_char("main"),
1751 utf_new_char("([Ljava/lang/String;)V"),
1752 class_java_lang_Object,
1755 if (exceptions_get_exception()) {
1756 exceptions_print_stacktrace();
1760 /* there is no main method or it isn't static */
1762 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1763 exceptions_clear_exception();
1764 exceptions_throw_nosuchmethoderror(mainclass,
1765 utf_new_char("main"),
1766 utf_new_char("([Ljava/lang/String;)V"));
1768 exceptions_print_stacktrace();
1772 #ifdef TYPEINFO_DEBUG_TEST
1773 /* test the typeinfo system */
1777 #if defined(ENABLE_JVMTI)
1778 jvmti_set_phase(JVMTI_PHASE_LIVE);
1781 /* set ThreadMXBean variables */
1783 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1784 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1786 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1787 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1788 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1789 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1790 #warning Move to C++
1792 /* start the main thread */
1794 (void) vm_call_method(m, NULL, oa);
1796 /* exception occurred? */
1798 if (exceptions_get_exception()) {
1799 exceptions_print_stacktrace();
1803 #if defined(ENABLE_THREADS)
1804 /* Detach the main thread so that it appears to have ended when
1805 the application's main method exits. */
1807 if (!thread_detach_current_thread())
1808 vm_abort("vm_run: Could not detach main thread.");
1811 /* Destroy the JavaVM. */
1813 (void) vm_destroy(vm);
1821 /* vm_destroy ******************************************************************
1823 Unloads a Java VM and reclaims its resources.
1825 *******************************************************************************/
1827 int vm_destroy(JavaVM *vm)
1829 #if defined(ENABLE_THREADS)
1830 /* Create a a trivial new Java waiter thread called
1833 JavaVMAttachArgs args;
1835 args.name = (char*) "DestroyJavaVM";
1838 if (!thread_attach_current_thread(&args, false))
1841 /* Wait until we are the last non-daemon thread. */
1843 threads_join_all_threads();
1848 // _created = false;
1849 #warning Move to C++
1851 /* Everything is ok. */
1857 /* vm_exit *********************************************************************
1859 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1861 *******************************************************************************/
1863 void vm_exit(s4 status)
1867 /* signal that we are exiting */
1870 #warning Move to C++
1872 assert(class_java_lang_System);
1873 assert(class_java_lang_System->state & CLASS_LOADED);
1875 #if defined(ENABLE_JVMTI)
1876 if (jvmti || (dbgcom!=NULL)) {
1877 jvmti_set_phase(JVMTI_PHASE_DEAD);
1878 if (jvmti) jvmti_agentunload();
1882 if (!link_class(class_java_lang_System)) {
1883 exceptions_print_stacktrace();
1887 /* call java.lang.System.exit(I)V */
1889 m = class_resolveclassmethod(class_java_lang_System,
1890 utf_new_char("exit"),
1892 class_java_lang_Object,
1896 exceptions_print_stacktrace();
1900 /* call the exit function with passed exit status */
1902 (void) vm_call_method(m, NULL, status);
1904 /* If we had an exception, just ignore the exception and exit with
1907 vm_shutdown(status);
1911 /* vm_shutdown *****************************************************************
1913 Terminates the system immediately without freeing memory explicitly
1914 (to be used only for abnormal termination).
1916 *******************************************************************************/
1918 void vm_shutdown(s4 status)
1921 #if defined(ENABLE_STATISTICS)
1922 || opt_getcompilingtime || opt_stat
1926 log_text("CACAO terminated by shutdown");
1927 dolog("Exit status: %d\n", (s4) status);
1931 #if defined(ENABLE_JVMTI)
1932 /* terminate cacaodbgserver */
1934 mutex_lock(&dbgcomlock);
1936 mutex_unlock(&dbgcomlock);
1937 jvmti_cacaodbgserver_quit();
1941 #if defined (ENABLE_JITCACHE)
1949 /* vm_exit_handler *************************************************************
1951 The exit_handler function is called upon program termination.
1953 ATTENTION: Don't free system resources here! Some threads may still
1954 be running as this is called from VMRuntime.exit(). The OS does the
1957 *******************************************************************************/
1959 void vm_exit_handler(void)
1961 #if !defined(NDEBUG)
1963 class_showmethods(mainclass);
1965 if (showconstantpool)
1966 class_showconstantpool(mainclass);
1971 # if defined(ENABLE_PROFILING)
1973 profile_printstats();
1975 #endif /* !defined(NDEBUG) */
1977 #if defined(ENABLE_RT_TIMING)
1978 rt_timing_print_time_stats(stderr);
1981 #if defined(ENABLE_CYCLES_STATS)
1982 builtin_print_cycles_stats(stderr);
1983 stacktrace_print_cycles_stats(stderr);
1987 #if defined(ENABLE_STATISTICS)
1988 || opt_getcompilingtime || opt_stat
1992 log_text("CACAO terminated");
1994 #if defined(ENABLE_STATISTICS)
1997 #ifdef TYPECHECK_STATISTICS
1998 typecheck_print_statistics(get_logfile());
2002 if (opt_getcompilingtime)
2004 #endif /* defined(ENABLE_STATISTICS) */
2006 /* vm_print_profile(stderr);*/
2010 /* vm_abort ********************************************************************
2012 Prints an error message and aborts the VM.
2015 text ... error message to print
2017 *******************************************************************************/
2019 void vm_abort(const char *text, ...)
2023 /* Print the log message. */
2028 log_vprint(text, ap);
2033 /* Now abort the VM. */
2039 /* vm_abort_errnum *************************************************************
2041 Prints an error message, appends ":" plus the strerror-message of
2042 errnum and aborts the VM.
2045 errnum ... error number
2046 text ..... error message to print
2048 *******************************************************************************/
2050 void vm_abort_errnum(int errnum, const char *text, ...)
2054 /* Print the log message. */
2059 log_vprint(text, ap);
2062 /* Print the strerror-message of errnum. */
2064 log_print(": %s", os::strerror(errnum));
2068 /* Now abort the VM. */
2074 /* vm_abort_errno **************************************************************
2076 Equal to vm_abort_errnum, but uses errno to get the error number.
2079 text ... error message to print
2081 *******************************************************************************/
2083 void vm_abort_errno(const char *text, ...)
2088 vm_abort_errnum(errno, text, ap);
2093 /* vm_abort_disassemble ********************************************************
2095 Prints an error message, disassemble the given code range (if
2096 enabled) and aborts the VM.
2099 pc.......PC to disassemble
2100 count....number of instructions to disassemble
2102 *******************************************************************************/
2104 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2107 #if defined(ENABLE_DISASSEMBLER)
2111 /* Print debug message. */
2116 log_vprint(text, ap);
2123 #if SIZEOF_VOID_P == 8
2124 log_println("PC=0x%016lx", pc);
2126 log_println("PC=0x%08x", pc);
2129 #if defined(ENABLE_DISASSEMBLER)
2130 log_println("machine instructions at PC:");
2132 /* Disassemble the given number of instructions. */
2134 for (i = 0; i < count; i++)
2135 // FIXME disassinstr should use void*.
2136 pc = disassinstr((u1*) pc);
2139 vm_abort("Aborting...");
2143 /* vm_get_mainclass_from_jar ***************************************************
2145 Gets the name of the main class from a JAR's manifest file.
2147 *******************************************************************************/
2149 static char *vm_get_mainclass_from_jar(char *mainname)
2156 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2159 exceptions_print_stacktrace();
2163 /* create JarFile object */
2168 exceptions_print_stacktrace();
2172 m = class_resolveclassmethod(c,
2174 utf_java_lang_String__void,
2175 class_java_lang_Object,
2179 exceptions_print_stacktrace();
2183 s = javastring_new_from_ascii(mainname);
2185 (void) vm_call_method(m, o, s);
2187 if (exceptions_get_exception()) {
2188 exceptions_print_stacktrace();
2192 /* get manifest object */
2194 m = class_resolveclassmethod(c,
2195 utf_new_char("getManifest"),
2196 utf_new_char("()Ljava/util/jar/Manifest;"),
2197 class_java_lang_Object,
2201 exceptions_print_stacktrace();
2205 o = vm_call_method(m, o);
2208 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2213 /* get Main Attributes */
2215 LLNI_class_get(o, c);
2217 m = class_resolveclassmethod(c,
2218 utf_new_char("getMainAttributes"),
2219 utf_new_char("()Ljava/util/jar/Attributes;"),
2220 class_java_lang_Object,
2224 exceptions_print_stacktrace();
2228 o = vm_call_method(m, o);
2231 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2236 /* get property Main-Class */
2238 LLNI_class_get(o, c);
2240 m = class_resolveclassmethod(c,
2241 utf_new_char("getValue"),
2242 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2243 class_java_lang_Object,
2247 exceptions_print_stacktrace();
2251 s = javastring_new_from_ascii("Main-Class");
2253 o = vm_call_method(m, o, s);
2256 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2257 fprintf(stderr, "%s\n", mainname);
2261 return javastring_tochar(o);
2265 /* vm_compile_all **************************************************************
2267 Compile all methods found in the bootclasspath.
2269 *******************************************************************************/
2271 #if !defined(NDEBUG)
2272 static void vm_compile_all(void)
2277 classcache_name_entry *nmen;
2278 classcache_class_entry *clsen;
2281 /* create all classes found in the bootclasspath */
2282 /* XXX currently only works with zip/jar's */
2284 loader_load_all_classes();
2286 /* link all classes */
2288 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2289 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2291 for (; nmen; nmen = nmen->hashlink) {
2292 /* iterate over all class entries */
2294 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2295 c = clsen->classobj;
2300 if (!(c->state & CLASS_LINKED)) {
2301 if (!link_class(c)) {
2302 fprintf(stderr, "Error linking: ");
2303 utf_fprint_printable_ascii_classname(stderr, c->name);
2304 fprintf(stderr, "\n");
2306 /* print out exception and cause */
2308 exceptions_print_current_exception();
2310 /* goto next class */
2316 /* compile all class methods */
2318 for (i = 0; i < c->methodscount; i++) {
2319 m = &(c->methods[i]);
2321 if (m->jcode != NULL) {
2322 if (!jit_compile(m)) {
2323 fprintf(stderr, "Error compiling: ");
2324 utf_fprint_printable_ascii_classname(stderr, c->name);
2325 fprintf(stderr, ".");
2326 utf_fprint_printable_ascii(stderr, m->name);
2327 utf_fprint_printable_ascii(stderr, m->descriptor);
2328 fprintf(stderr, "\n");
2330 /* print out exception and cause */
2332 exceptions_print_current_exception();
2340 #endif /* !defined(NDEBUG) */
2343 /* vm_compile_method ***********************************************************
2345 Compile a specific method.
2347 *******************************************************************************/
2349 #if !defined(NDEBUG)
2350 static void vm_compile_method(char* mainname)
2354 /* create, load and link the main class */
2356 mainclass = load_class_bootstrap(utf_new_char(mainname));
2358 if (mainclass == NULL)
2359 exceptions_print_stacktrace();
2361 if (!link_class(mainclass))
2362 exceptions_print_stacktrace();
2364 if (opt_signature != NULL) {
2365 m = class_resolveclassmethod(mainclass,
2366 utf_new_char(opt_method),
2367 utf_new_char(opt_signature),
2372 m = class_resolveclassmethod(mainclass,
2373 utf_new_char(opt_method),
2380 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2381 opt_method, opt_signature ? opt_signature : "");
2385 #endif /* !defined(NDEBUG) */
2388 /* vm_call_array ***************************************************************
2390 Calls a Java method with a variable number of arguments, passed via
2393 ATTENTION: This function has to be used outside the nativeworld.
2395 *******************************************************************************/
2397 #define VM_CALL_ARRAY(name, type) \
2398 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2404 assert(m->code != NULL); \
2406 md = m->parseddesc; \
2407 pv = m->code->entrypoint; \
2409 STATISTICS(count_calls_native_to_java++); \
2411 value = asm_vm_call_method##name(pv, array, md->memuse); \
2416 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2422 assert(m->code != NULL);
2425 pv = m->code->entrypoint;
2427 STATISTICS(count_calls_native_to_java++);
2429 o = asm_vm_call_method(pv, array, md->memuse);
2431 if (md->returntype.type == TYPE_VOID)
2434 return LLNI_WRAP(o);
2437 VM_CALL_ARRAY(_int, int32_t)
2438 VM_CALL_ARRAY(_long, int64_t)
2439 VM_CALL_ARRAY(_float, float)
2440 VM_CALL_ARRAY(_double, double)
2443 /* vm_call_method **************************************************************
2445 Calls a Java method with a variable number of arguments.
2447 *******************************************************************************/
2449 #define VM_CALL_METHOD(name, type) \
2450 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2456 value = vm_call_method##name##_valist(m, o, ap); \
2462 VM_CALL_METHOD(, java_handle_t *)
2463 VM_CALL_METHOD(_int, int32_t)
2464 VM_CALL_METHOD(_long, int64_t)
2465 VM_CALL_METHOD(_float, float)
2466 VM_CALL_METHOD(_double, double)
2469 /* vm_call_method_valist *******************************************************
2471 Calls a Java method with a variable number of arguments, passed via
2474 *******************************************************************************/
2476 #define VM_CALL_METHOD_VALIST(name, type) \
2477 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2482 int32_t dumpmarker; \
2484 if (m->code == NULL) \
2485 if (!jit_compile(m)) \
2488 THREAD_NATIVEWORLD_EXIT; \
2491 array = argument_vmarray_from_valist(m, o, ap); \
2492 value = vm_call##name##_array(m, array); \
2495 THREAD_NATIVEWORLD_ENTER; \
2500 VM_CALL_METHOD_VALIST(, java_handle_t *)
2501 VM_CALL_METHOD_VALIST(_int, int32_t)
2502 VM_CALL_METHOD_VALIST(_long, int64_t)
2503 VM_CALL_METHOD_VALIST(_float, float)
2504 VM_CALL_METHOD_VALIST(_double, double)
2507 /* vm_call_method_jvalue *******************************************************
2509 Calls a Java method with a variable number of arguments, passed via
2512 *******************************************************************************/
2514 #define VM_CALL_METHOD_JVALUE(name, type) \
2515 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2516 const jvalue *args) \
2520 int32_t dumpmarker; \
2522 if (m->code == NULL) \
2523 if (!jit_compile(m)) \
2526 THREAD_NATIVEWORLD_EXIT; \
2529 array = argument_vmarray_from_jvalue(m, o, args); \
2530 value = vm_call##name##_array(m, array); \
2533 THREAD_NATIVEWORLD_ENTER; \
2538 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2539 VM_CALL_METHOD_JVALUE(_int, int32_t)
2540 VM_CALL_METHOD_JVALUE(_long, int64_t)
2541 VM_CALL_METHOD_JVALUE(_float, float)
2542 VM_CALL_METHOD_JVALUE(_double, double)
2545 /* vm_call_method_objectarray **************************************************
2547 Calls a Java method with a variable number if arguments, passed via
2548 an objectarray of boxed values. Returns a boxed value.
2550 *******************************************************************************/
2552 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2553 java_handle_objectarray_t *params)
2556 java_handle_t *xptr;
2561 /* Prevent compiler warnings. */
2565 /* compile methods which are not yet compiled */
2567 if (m->code == NULL)
2568 if (!jit_compile(m))
2571 /* leave the nativeworld */
2573 THREAD_NATIVEWORLD_EXIT;
2575 /* mark start of dump memory area */
2579 /* Fill the argument array from a object-array. */
2581 array = argument_vmarray_from_objectarray(m, o, params);
2583 if (array == NULL) {
2584 /* release dump area */
2588 /* enter the nativeworld again */
2590 THREAD_NATIVEWORLD_ENTER;
2592 exceptions_throw_illegalargumentexception();
2597 switch (m->parseddesc->returntype.primitivetype) {
2598 case PRIMITIVETYPE_VOID:
2599 value.a = vm_call_array(m, array);
2602 case PRIMITIVETYPE_BOOLEAN:
2603 case PRIMITIVETYPE_BYTE:
2604 case PRIMITIVETYPE_CHAR:
2605 case PRIMITIVETYPE_SHORT:
2606 case PRIMITIVETYPE_INT:
2607 value.i = vm_call_int_array(m, array);
2610 case PRIMITIVETYPE_LONG:
2611 value.l = vm_call_long_array(m, array);
2614 case PRIMITIVETYPE_FLOAT:
2615 value.f = vm_call_float_array(m, array);
2618 case PRIMITIVETYPE_DOUBLE:
2619 value.d = vm_call_double_array(m, array);
2623 ro = vm_call_array(m, array);
2627 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2630 /* release dump area */
2634 /* enter the nativeworld again */
2636 THREAD_NATIVEWORLD_ENTER;
2638 /* box the return value if necesarry */
2640 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2641 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2643 /* check for an exception */
2645 xptr = exceptions_get_exception();
2648 /* clear exception pointer, we are calling JIT code again */
2650 exceptions_clear_exception();
2652 exceptions_throw_invocationtargetexception(xptr);
2659 /* Legacy C interface *********************************************************/
2663 JavaVM* VM_get_javavm() { return vm->get_javavm(); }
2664 JNIEnv* VM_get_jnienv() { return vm->get_jnienv(); }
2665 bool VM_is_initializing() { return vm->is_initializing(); }
2666 bool VM_is_created() { return vm->is_created(); }
2667 int64_t VM_get_starttime() { return vm->get_starttime(); }
2673 * These are local overrides for various environment variables in Emacs.
2674 * Please do not remove this and leave it at the end of the file, where
2675 * Emacs will automagically detect them.
2676 * ---------------------------------------------------------------------
2679 * indent-tabs-mode: t
2683 * vim:noexpandtab:sw=4:ts=4: