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/methodtree.h"
95 #if defined(ENABLE_PROFILING)
96 # include "vm/jit/optimizing/profile.h"
99 #include "vm/jit/optimizing/recompile.h"
101 #if defined(ENABLE_PYTHON)
102 # include "vm/jit/python.h"
105 #include "vm/jit/trap.h"
107 #if defined(ENABLE_JVMTI)
108 # include "native/jvmti/cacaodbg.h"
111 #if defined(ENABLE_VMLOG)
112 #include <vmlog_cacao.h>
117 * This is _the_ instance of the VM.
122 /* global variables ***********************************************************/
124 s4 vms = 0; /* number of VMs created */
126 static classinfo *mainclass = NULL;
128 #if defined(ENABLE_INTRP)
129 u1 *intrp_main_stack = NULL;
133 /* define heap sizes **********************************************************/
135 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
136 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
137 #define STACK_SIZE 128 * 1024 /* default 64kB */
140 /* define command line options ************************************************/
174 /* Java non-standard options */
185 #if defined(ENABLE_PROFILING)
198 #if defined(ENABLE_STATISTICS)
215 #if defined(ENABLE_VERIFIER)
217 #if defined(TYPECHECK_VERBOSE)
220 #endif /* defined(ENABLE_VERIFIER) */
222 /* optimization options */
224 #if defined(ENABLE_LOOP)
228 #if defined(ENABLE_IFCONV)
232 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
236 #if defined(ENABLE_INTRP)
237 /* interpreter options */
256 #if defined(ENABLE_DEBUG_FILTER)
257 OPT_FILTER_VERBOSECALL_INCLUDE,
258 OPT_FILTER_VERBOSECALL_EXCLUDE,
259 OPT_FILTER_SHOW_METHOD,
266 opt_struct opts[] = {
267 { "foo", false, OPT_FOO },
271 { "jar", false, OPT_JAR },
273 { "d32", false, OPT_D32 },
274 { "d64", false, OPT_D64 },
275 { "client", false, OPT_IGNORE },
276 { "server", false, OPT_IGNORE },
277 { "jvm", false, OPT_IGNORE },
278 { "hotspot", false, OPT_IGNORE },
280 { "classpath", true, OPT_CLASSPATH },
281 { "cp", true, OPT_CLASSPATH },
282 { "D", true, OPT_D },
283 { "version", false, OPT_VERSION },
284 { "showversion", false, OPT_SHOWVERSION },
285 { "fullversion", false, OPT_FULLVERSION },
286 { "help", false, OPT_HELP },
287 { "?", false, OPT_HELP },
288 { "X", false, OPT_X },
289 { "XX:", true, OPT_XX },
291 { "ea:", true, OPT_EA },
292 { "da:", true, OPT_DA },
293 { "ea", false, OPT_EA_NOARG },
294 { "da", false, OPT_DA_NOARG },
296 { "enableassertions:", true, OPT_EA },
297 { "disableassertions:", true, OPT_DA },
298 { "enableassertions", false, OPT_EA_NOARG },
299 { "disableassertions", false, OPT_DA_NOARG },
301 { "esa", false, OPT_ESA },
302 { "enablesystemassertions", false, OPT_ESA },
303 { "dsa", false, OPT_DSA },
304 { "disablesystemassertions", false, OPT_DSA },
306 { "noasyncgc", false, OPT_IGNORE },
307 #if defined(ENABLE_VERIFIER)
308 { "noverify", false, OPT_NOVERIFY },
309 { "Xverify:none", false, OPT_NOVERIFY },
311 { "v", false, OPT_VERBOSE1 },
312 { "verbose:", true, OPT_VERBOSE },
314 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
315 { "verbosetc", false, OPT_VERBOSETC },
317 #if defined(__ALPHA__)
318 { "noieee", false, OPT_NOIEEE },
320 #if defined(ENABLE_STATISTICS)
321 { "time", false, OPT_TIME },
322 { "stat", false, OPT_STAT },
324 { "log", true, OPT_LOG },
325 { "c", true, OPT_CHECK },
326 { "l", false, OPT_LOAD },
329 { "all", false, OPT_ALL },
330 { "sig", true, OPT_SIGNATURE },
333 #if defined(ENABLE_LOOP)
334 { "oloop", false, OPT_OLOOP },
336 #if defined(ENABLE_IFCONV)
337 { "ifconv", false, OPT_IFCONV },
339 #if defined(ENABLE_LSRA)
340 { "lsra", false, OPT_LSRA },
342 #if defined(ENABLE_SSA)
343 { "lsra", true, OPT_LSRA },
346 #if defined(ENABLE_INTRP)
347 /* interpreter options */
349 { "trace", false, OPT_TRACE },
350 { "static-supers", true, OPT_STATIC_SUPERS },
351 { "no-dynamic", false, OPT_NO_DYNAMIC },
352 { "no-replication", false, OPT_NO_REPLICATION },
353 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
356 /* JVMTI Agent Command Line Options */
358 { "agentlib:", true, OPT_AGENTLIB },
359 { "agentpath:", true, OPT_AGENTPATH },
362 /* Java non-standard options */
364 { "Xjit", false, OPT_JIT },
365 { "Xint", false, OPT_INTRP },
366 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
367 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
368 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
369 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
372 { "Xdebug", false, OPT_DEBUG },
373 { "Xnoagent", false, OPT_NOAGENT },
374 { "Xrunjdwp", true, OPT_XRUNJDWP },
377 { "Xms", true, OPT_MS },
378 { "ms", true, OPT_MS },
379 { "Xmx", true, OPT_MX },
380 { "mx", true, OPT_MX },
381 { "Xss", true, OPT_SS },
382 { "ss", true, OPT_SS },
384 #if defined(ENABLE_PROFILING)
385 { "Xprof:", true, OPT_PROF_OPTION },
386 { "Xprof", false, OPT_PROF },
389 /* keep these at the end of the list */
392 { "m", true, OPT_METHOD },
395 { "s", true, OPT_SHOW },
396 { "debug-color", false, OPT_DEBUGCOLOR },
398 #if defined(ENABLE_DEBUG_FILTER)
399 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
400 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
401 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
408 /* usage ***********************************************************************
410 Prints the correct usage syntax to stdout.
412 *******************************************************************************/
416 puts("Usage: cacao [-options] classname [arguments]");
417 puts(" (to run a class file)");
418 puts(" or cacao [-options] -jar jarfile [arguments]");
419 puts(" (to run a standalone jar file)\n");
421 puts("where options include:");
422 puts(" -d32 use 32-bit data model if available");
423 puts(" -d64 use 64-bit data model if available");
424 puts(" -client compatibility (currently ignored)");
425 puts(" -server compatibility (currently ignored)");
426 puts(" -jvm compatibility (currently ignored)");
427 puts(" -hotspot compatibility (currently ignored)\n");
429 puts(" -cp <path> specify a path to look for classes");
430 puts(" -classpath <path> specify a path to look for classes");
431 puts(" -D<name>=<value> add an entry to the property list");
432 puts(" -verbose[:class|gc|jni] enable specific verbose output");
433 puts(" -version print product version and exit");
434 puts(" -fullversion print jpackage-compatible product version and exit");
435 puts(" -showversion print product version and continue");
436 puts(" -help, -? print this help message");
437 puts(" -X print help on non-standard Java options");
438 puts(" -XX print help on debugging options");
439 puts(" -ea[:<packagename>...|:<classname>]");
440 puts(" -enableassertions[:<packagename>...|:<classname>]");
441 puts(" enable assertions with specified granularity");
442 puts(" -da[:<packagename>...|:<classname>]");
443 puts(" -disableassertions[:<packagename>...|:<classname>]");
444 puts(" disable assertions with specified granularity");
445 puts(" -esa | -enablesystemassertions");
446 puts(" enable system assertions");
447 puts(" -dsa | -disablesystemassertions");
448 puts(" disable system assertions");
451 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
452 puts (" for jdwp help use: -agentlib:jdwp=help");
453 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
456 /* exit with error code */
462 static void Xusage(void)
464 #if defined(ENABLE_JIT)
465 puts(" -Xjit JIT mode execution (default)");
467 #if defined(ENABLE_INTRP)
468 puts(" -Xint interpreter mode execution");
470 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
471 puts(" value is set as bootstrap class path");
472 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
473 puts(" value is appended to the bootstrap class path");
474 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
475 puts(" value is prepended to the bootstrap class path");
476 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
477 puts(" value is used as Java core library, but the");
478 puts(" hardcoded VM interface classes are prepended");
479 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
480 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
481 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
483 #if defined(ENABLE_PROFILING)
484 puts(" -Xprof[:bb] collect and print profiling data");
487 #if defined(ENABLE_JVMTI)
488 /* -Xdebug option depend on gnu classpath JDWP options. options:
489 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
490 puts(" -Xdebug enable remote debugging\n");
491 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
492 puts(" enable remote debugging\n");
495 /* exit with error code */
502 static void XXusage(void)
504 puts(" -v write state-information");
506 puts(" -verbose:jit enable specific verbose output");
507 puts(" -debug-color colored output for ANSI terms");
509 #ifdef TYPECHECK_VERBOSE
510 puts(" -verbosetc write debug messages while typechecking");
512 #if defined(__ALPHA__)
513 puts(" -noieee don't use ieee compliant arithmetic");
515 #if defined(ENABLE_VERIFIER)
516 puts(" -noverify don't verify classfiles");
518 #if defined(ENABLE_STATISTICS)
519 puts(" -time measure the runtime");
520 puts(" -stat detailed compiler statistics");
522 puts(" -log logfile specify a name for the logfile");
523 puts(" -c(heck)b(ounds) don't check array bounds");
524 puts(" s(ync) don't check for synchronization");
525 #if defined(ENABLE_LOOP)
526 puts(" -oloop optimize array accesses in loops");
528 puts(" -l don't start the class after loading");
530 puts(" -all compile all methods, no execution");
531 puts(" -m compile only a specific method");
532 puts(" -sig specify signature for a specific method");
535 puts(" -s... show...");
536 puts(" (c)onstants the constant pool");
537 puts(" (m)ethods class fields and methods");
538 puts(" (u)tf the utf - hash");
539 puts(" (i)ntermediate intermediate representation");
540 #if defined(ENABLE_DISASSEMBLER)
541 puts(" (a)ssembler disassembled listing");
542 puts(" n(o)ps show NOPs in disassembler output");
544 puts(" (d)atasegment data segment listing");
546 #if defined(ENABLE_IFCONV)
547 puts(" -ifconv use if-conversion");
549 #if defined(ENABLE_LSRA)
550 puts(" -lsra use linear scan register allocation");
552 #if defined(ENABLE_SSA)
553 puts(" -lsra:... use linear scan register allocation (with SSA)");
554 puts(" (d)ead code elimination");
555 puts(" (c)opy propagation");
557 #if defined(ENABLE_DEBUG_FILTER)
558 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
559 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
560 puts(" -XXfm <regex> filter for show options");
562 /* exit with error code */
569 /* version *********************************************************************
571 Only prints cacao version information.
573 *******************************************************************************/
575 static void version(bool opt_exit)
577 puts("java version \""JAVA_VERSION"\"");
578 puts("CACAO version "VERSION"\n");
580 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
581 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
582 puts("This is free software; see the source for copying conditions. There is NO");
583 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
585 /* exit normally, if requested */
592 /* fullversion *****************************************************************
594 Prints a Sun compatible version information (required e.g. by
595 jpackage, www.jpackage.org).
597 *******************************************************************************/
599 static void fullversion(void)
601 puts("java full version \"cacao-"JAVA_VERSION"\"");
609 static void vm_printconfig(void)
611 puts("Configure/Build options:\n");
612 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
613 #if defined(__VERSION__)
614 puts(" CC : "VERSION_CC" ("__VERSION__")");
616 puts(" CC : "VERSION_CC"");
618 puts(" CFLAGS : "VERSION_CFLAGS"\n");
620 puts("Default variables:\n");
621 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
622 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
623 printf(" stack size : %d\n", STACK_SIZE);
625 #if defined(ENABLE_JRE_LAYOUT)
626 /* When we're building with JRE-layout, the default paths are the
627 same as the runtime paths. */
629 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
630 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
631 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
632 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
633 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
634 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
640 puts("Runtime variables:\n");
641 printf(" maximum heap size : %d\n", opt_heapmaxsize);
642 printf(" initial heap size : %d\n", opt_heapstartsize);
643 printf(" stack size : %d\n", opt_stacksize);
645 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
646 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
647 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
648 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
651 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
652 printf(" java.class.path : %s\n", properties_get("java.class.path"));
656 /* forward declarations *******************************************************/
658 static char *vm_get_mainclass_from_jar(char *mainstring);
660 static void vm_compile_all(void);
661 static void vm_compile_method(char* mainname);
666 * Implementation for JNI_CreateJavaVM. This function creates a VM
673 * @return true on success, false otherwise.
675 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
677 JavaVMInitArgs* _vm_args;
679 // Get the arguments for the new JVM.
680 _vm_args = (JavaVMInitArgs *) vm_args;
682 // Instantiate a new VM.
684 vm = new VM(_vm_args);
686 catch (std::exception e) {
687 // FIXME How can we delete the resources allocated?
688 // /* release allocated memory */
689 // FREE(env, _Jv_JNIEnv);
690 // FREE(vm, _Jv_JavaVM);
697 // Return the values.
699 *p_vm = vm->get_javavm();
700 *p_env = vm->get_jnienv();
707 * C wrapper for VM::create.
710 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
712 return VM::create(p_vm, p_env, vm_args);
720 VM::VM(JavaVMInitArgs* vm_args)
722 // Very first thing to do: we are initializing.
723 _initializing = true;
725 // Make ourself globally visible.
726 // XXX Is this a good idea?
729 /* create and fill a JavaVM structure */
731 _javavm = new JavaVM();
733 #if defined(ENABLE_JNI)
734 _javavm->functions = &_Jv_JNIInvokeInterface;
737 /* get the VM and Env tables (must be set before vm_create) */
738 /* XXX JVMTI Agents needs a JavaVM */
740 _jnienv = new JNIEnv();
742 #if defined(ENABLE_JNI)
743 _jnienv->functions = &_Jv_JNINativeInterface;
746 /* actually create the JVM */
750 char *boot_class_path;
756 #if defined(ENABLE_JVMTI)
758 char *libname, *agentarg;
759 bool jdwp,agentbypath;
760 jdwp = agentbypath = false;
763 #if defined(ENABLE_JNI)
764 /* Check the JNI version requested. */
766 if (!jni_version_check(vm_args->version))
767 throw std::exception();
770 /* We only support 1 JVM instance. */
773 throw std::exception();
775 /* Install the exit handler. */
777 if (atexit(vm_exit_handler))
778 vm_abort("atexit failed: %s\n", strerror(errno));
780 /* Set some options. */
787 opt_heapmaxsize = HEAP_MAXSIZE;
788 opt_heapstartsize = HEAP_STARTSIZE;
789 opt_stacksize = STACK_SIZE;
791 /* Initialize the properties list before command-line handling.
792 Otherwise -XX:+PrintConfig crashes. */
796 /* First of all, parse the -XX options. */
798 #if defined(ENABLE_VMLOG)
799 vmlog_cacao_init_options();
804 #if defined(ENABLE_VMLOG)
808 /* We need to check if the actual size of a java.lang.Class object
809 is smaller or equal than the assumption made in
812 #warning FIXME We need to check the size of java.lang.Class!!!
813 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
814 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
816 /* set the VM starttime */
818 _starttime = builtin_currenttimemillis();
820 #if defined(ENABLE_JVMTI)
821 /* initialize JVMTI related **********************************************/
825 /* Fill the properties before command-line handling. */
829 /* iterate over all passed options */
831 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
845 #if SIZEOF_VOID_P == 8
846 puts("Running a 32-bit JVM is not supported on this platform.");
852 #if SIZEOF_VOID_P == 4
853 puts("Running a 64-bit JVM is not supported on this platform.");
859 /* Forget old classpath and set the argument as new
862 // FIXME Make class_path const char*.
863 class_path = (char*) properties_get("java.class.path");
865 p = MNEW(char, strlen(opt_arg) + strlen("0"));
869 #if defined(ENABLE_JAVASE)
870 properties_add("java.class.path", p);
873 MFREE(class_path, char, strlen(class_path));
877 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
878 if (opt_arg[i] == '=') {
880 properties_add(opt_arg, opt_arg + i + 1);
885 /* if no '=' is given, just create an empty property */
887 properties_add(opt_arg, "");
892 case OPT_BOOTCLASSPATH:
893 /* Forget default bootclasspath and set the argument as
894 new boot classpath. */
896 // FIXME Make boot_class_path const char*.
897 boot_class_path = (char*) properties_get("sun.boot.class.path");
899 p = MNEW(char, strlen(opt_arg) + strlen("0"));
903 properties_add("sun.boot.class.path", p);
904 properties_add("java.boot.class.path", p);
906 MFREE(boot_class_path, char, strlen(boot_class_path));
909 case OPT_BOOTCLASSPATH_A:
910 /* Append to bootclasspath. */
912 // FIXME Make boot_class_path const char*.
913 boot_class_path = (char*) properties_get("sun.boot.class.path");
915 len = strlen(boot_class_path);
917 // XXX (char*) quick hack
918 p = (char*) MREALLOC(boot_class_path,
922 strlen(opt_arg) + strlen("0"));
927 properties_add("sun.boot.class.path", p);
928 properties_add("java.boot.class.path", p);
931 case OPT_BOOTCLASSPATH_P:
932 /* Prepend to bootclasspath. */
934 // FIXME Make boot_class_path const char*.
935 boot_class_path = (char*) properties_get("sun.boot.class.path");
937 len = strlen(boot_class_path);
939 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
943 strcat(p, boot_class_path);
945 properties_add("sun.boot.class.path", p);
946 properties_add("java.boot.class.path", p);
948 MFREE(boot_class_path, char, len);
951 case OPT_BOOTCLASSPATH_C:
952 /* Use as Java core library, but prepend VM interface
955 // FIXME Make boot_class_path const char*.
956 boot_class_path = (char*) properties_get("sun.boot.class.path");
959 strlen(CACAO_VM_ZIP) +
966 strcpy(p, CACAO_VM_ZIP);
970 properties_add("sun.boot.class.path", p);
971 properties_add("java.boot.class.path", p);
973 MFREE(boot_class_path, char, strlen(boot_class_path));
976 #if defined(ENABLE_JVMTI)
978 /* this option exists only for compatibility reasons */
982 /* I don't know yet what Xnoagent should do. This is only for
983 compatiblity with eclipse - motse */
992 strlen(CACAO_LIBDIR) +
993 strlen("/libjdwp.so=") +
997 agentarg = MNEW(char, len);
999 strcpy(agentarg, CACAO_LIBDIR);
1000 strcat(agentarg, "/libjdwp.so=");
1001 strcat(agentarg, &opt_arg[1]);
1020 c = opt_arg[strlen(opt_arg) - 1];
1022 if ((c == 'k') || (c == 'K')) {
1023 j = atoi(opt_arg) * 1024;
1025 } else if ((c == 'm') || (c == 'M')) {
1026 j = atoi(opt_arg) * 1024 * 1024;
1032 opt_heapmaxsize = j;
1033 else if (opt == OPT_MS)
1034 opt_heapstartsize = j;
1045 if (strcmp("class", opt_arg) == 0) {
1046 opt_verboseclass = true;
1048 else if (strcmp("gc", opt_arg) == 0) {
1049 opt_verbosegc = true;
1051 else if (strcmp("jni", opt_arg) == 0) {
1052 opt_verbosejni = true;
1054 #if !defined(NDEBUG)
1055 else if (strcmp("jit", opt_arg) == 0) {
1059 compileverbose = true;
1063 printf("Unknown -verbose option: %s\n", opt_arg);
1068 case OPT_DEBUGCOLOR:
1069 opt_debugcolor = true;
1072 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1074 opt_typecheckverbose = true;
1083 case OPT_FULLVERSION:
1087 case OPT_SHOWVERSION:
1095 #if defined(ENABLE_VERIFIER)
1101 #if defined(ENABLE_STATISTICS)
1103 opt_getcompilingtime = true;
1104 opt_getloadingtime = true;
1117 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1118 switch (opt_arg[i]) {
1120 checkbounds = false;
1133 makeinitializations = false;
1136 #if !defined(NDEBUG)
1140 makeinitializations = false;
1145 opt_method = opt_arg;
1146 makeinitializations = false;
1150 opt_signature = opt_arg;
1154 case OPT_SHOW: /* Display options */
1155 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1156 switch (opt_arg[i]) {
1158 showconstantpool = true;
1170 opt_showintermediate = true;
1171 compileverbose = true;
1174 #if defined(ENABLE_DISASSEMBLER)
1176 opt_showdisassemble = true;
1177 compileverbose = true;
1181 opt_shownops = true;
1186 opt_showddatasegment = true;
1195 #if defined(ENABLE_LOOP)
1201 #if defined(ENABLE_IFCONV)
1207 #if defined(ENABLE_LSRA)
1212 #if defined(ENABLE_SSA)
1215 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1216 switch (opt_arg[i]) {
1244 /* Already parsed. */
1248 #if defined(ENABLE_ASSERTION)
1249 assertion_ea_da(opt_arg, true);
1254 #if defined(ENABLE_ASSERTION)
1255 assertion_ea_da(opt_arg, false);
1260 #if defined(ENABLE_ASSERTION)
1261 assertion_user_enabled = true;
1266 #if defined(ENABLE_ASSERTION)
1267 assertion_user_enabled = false;
1272 #if defined(ENABLE_ASSERTION)
1273 assertion_system_enabled = true;
1278 #if defined(ENABLE_ASSERTION)
1279 assertion_system_enabled = false;
1283 #if defined(ENABLE_PROFILING)
1284 case OPT_PROF_OPTION:
1285 /* use <= to get the last \0 too */
1287 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1288 if (opt_arg[i] == ',')
1291 if (opt_arg[i] == '\0') {
1292 if (strcmp("bb", opt_arg + j) == 0)
1296 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1300 /* set k to next char */
1313 #if defined(ENABLE_JIT)
1316 printf("-Xjit option not enabled.\n");
1322 #if defined(ENABLE_INTRP)
1325 printf("-Xint option not enabled.\n");
1330 #if defined(ENABLE_INTRP)
1331 case OPT_STATIC_SUPERS:
1332 opt_static_supers = atoi(opt_arg);
1335 case OPT_NO_DYNAMIC:
1336 opt_no_dynamic = true;
1339 case OPT_NO_REPLICATION:
1340 opt_no_replication = true;
1343 case OPT_NO_QUICKSUPER:
1344 opt_no_quicksuper = true;
1352 #if defined(ENABLE_DEBUG_FILTER)
1353 case OPT_FILTER_VERBOSECALL_INCLUDE:
1354 opt_filter_verbosecall_include = opt_arg;
1357 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1358 opt_filter_verbosecall_exclude = opt_arg;
1361 case OPT_FILTER_SHOW_METHOD:
1362 opt_filter_show_method = opt_arg;
1367 printf("Unknown option: %s\n",
1368 vm_args->options[opt_index].optionString);
1373 #if defined(ENABLE_JVMTI)
1375 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1376 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1379 MFREE(agentarg, char, strlen(agentarg));
1381 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1385 /* initialize the garbage collector */
1387 gc_init(opt_heapmaxsize, opt_heapstartsize);
1389 #if defined(ENABLE_THREADS)
1390 /* BEFORE: threads_preinit */
1394 /* AFTER: gc_init */
1400 /* install architecture dependent signal handlers */
1403 vm_abort("vm_create: signal_init failed");
1405 #if defined(ENABLE_INTRP)
1406 /* Allocate main thread stack on the Java heap. */
1409 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1410 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1414 /* AFTER: threads_preinit */
1417 vm_abort("vm_create: string_init failed");
1419 /* AFTER: threads_preinit */
1423 /* AFTER: thread_preinit */
1426 vm_abort("vm_create: suck_init failed");
1428 suck_add_from_property("java.endorsed.dirs");
1430 /* Now we have all options handled and we can print the version
1433 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1438 /* AFTER: utf8_init */
1440 // FIXME Make boot_class_path const char*.
1441 boot_class_path = (char*) properties_get("sun.boot.class.path");
1442 suck_add(boot_class_path);
1444 /* initialize the classcache hashtable stuff: lock, hashtable
1445 (must be done _after_ threads_preinit) */
1447 if (!classcache_init())
1448 vm_abort("vm_create: classcache_init failed");
1450 /* Initialize the code memory management. */
1451 /* AFTER: threads_preinit */
1455 /* initialize the finalizer stuff (must be done _after_
1458 if (!finalizer_init())
1459 vm_abort("vm_create: finalizer_init failed");
1461 /* Initialize the JIT compiler. */
1467 #if defined(ENABLE_PYTHON)
1471 /* BEFORE: loader_preinit */
1473 Package::initialize();
1475 /* AFTER: utf8_init, classcache_init */
1480 /* AFTER: loader_preinit, linker_preinit */
1487 /* AFTER: loader_init, linker_init */
1489 primitive_postinit();
1492 #if defined(ENABLE_JIT)
1496 if (!builtin_init())
1497 vm_abort("vm_create: builtin_init failed");
1499 /* Initialize the native subsystem. */
1500 /* BEFORE: threads_init */
1503 vm_abort("vm_create: native_init failed");
1505 /* Register the native methods implemented in the VM. */
1506 /* BEFORE: threads_init */
1510 #if defined(ENABLE_JNI)
1511 /* Initialize the JNI subsystem (must be done _before_
1512 threads_init, as threads_init can call JNI methods
1513 (e.g. NewGlobalRef). */
1516 vm_abort("vm_create: jni_init failed");
1519 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1520 /* Initialize the local reference table for the main thread. */
1521 /* BEFORE: threads_init */
1523 if (!localref_table_init())
1524 vm_abort("vm_create: localref_table_init failed");
1527 /* Iinitialize some important system classes. */
1528 /* BEFORE: threads_init */
1532 #if defined(ENABLE_THREADS)
1536 /* Initialize the native VM subsystem. */
1537 /* AFTER: threads_init (at least for SUN's classes) */
1541 #if defined(ENABLE_PROFILING)
1542 /* initialize profiling */
1544 if (!profile_init())
1545 vm_abort("vm_create: profile_init failed");
1548 #if defined(ENABLE_THREADS)
1549 /* initialize recompilation */
1551 if (!recompile_init())
1552 vm_abort("vm_create: recompile_init failed");
1554 /* start the signal handler thread */
1556 #if defined(__LINUX__)
1557 /* XXX Remove for exact-GC. */
1558 if (threads_pthreads_implementation_nptl)
1560 if (!signal_start_thread())
1561 vm_abort("vm_create: signal_start_thread failed");
1563 /* finally, start the finalizer thread */
1565 if (!finalizer_start_thread())
1566 vm_abort("vm_create: finalizer_start_thread failed");
1568 # if !defined(NDEBUG)
1569 /* start the memory profiling thread */
1571 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1572 if (!memory_start_thread())
1573 vm_abort("vm_create: memory_start_thread failed");
1576 /* start the recompilation thread (must be done before the
1577 profiling thread) */
1579 if (!recompile_start_thread())
1580 vm_abort("vm_create: recompile_start_thread failed");
1582 # if defined(ENABLE_PROFILING)
1583 /* start the profile sampling thread */
1586 /* if (!profile_start_thread()) */
1587 /* vm_abort("vm_create: profile_start_thread failed"); */
1591 #if defined(ENABLE_JVMTI)
1592 # if defined(ENABLE_GC_CACAO)
1593 /* XXX this will not work with the new indirection cells for classloaders!!! */
1597 /* add agent library to native library hashtable */
1598 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1602 /* Increment the number of VMs. */
1606 // Initialization is done, VM is created.
1608 _initializing = false;
1610 /* Print the VM configuration after all stuff is set and the VM is
1613 if (opt_PrintConfig)
1618 /* vm_run **********************************************************************
1620 Runs the main-method of the passed class.
1622 *******************************************************************************/
1624 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1630 classinfo *mainclass;
1633 java_handle_objectarray_t *oa;
1639 // Prevent compiler warnings.
1642 #if !defined(NDEBUG)
1649 /* Get the main class plus it's arguments. */
1653 if (opt_index < vm_args->nOptions) {
1654 /* Get main-class argument. */
1656 mainname = vm_args->options[opt_index].optionString;
1658 /* If the main class argument is a jar file, put it into the
1661 if (opt_jar == true) {
1662 p = MNEW(char, strlen(mainname) + strlen("0"));
1664 strcpy(p, mainname);
1666 #if defined(ENABLE_JAVASE)
1667 properties_add("java.class.path", p);
1671 /* Replace dots with slashes in the class name. */
1673 for (unsigned int i = 0; i < strlen(mainname); i++)
1674 if (mainname[i] == '.')
1678 /* Build argument array. Move index to first argument. */
1682 oalength = vm_args->nOptions - opt_index;
1684 oa = builtin_anewarray(oalength, class_java_lang_String);
1686 for (int i = 0; i < oalength; i++) {
1687 option = vm_args->options[opt_index + i].optionString;
1689 u = utf_new_char(option);
1690 s = javastring_new(u);
1692 array_objectarray_element_set(oa, i, s);
1696 /* Do we have a main-class argument? */
1698 if (mainname == NULL)
1701 #if !defined(NDEBUG)
1702 if (opt_method != NULL) {
1703 vm_compile_method(mainname);
1708 /* set return value to OK */
1712 if (opt_jar == true) {
1713 /* open jar file with java.util.jar.JarFile */
1715 mainname = vm_get_mainclass_from_jar(mainname);
1717 if (mainname == NULL)
1721 /* load the main class */
1723 mainutf = utf_new_char(mainname);
1725 #if defined(ENABLE_JAVAME_CLDC1_1)
1726 mainclass = load_class_bootstrap(mainutf);
1728 mainclass = load_class_from_sysloader(mainutf);
1731 /* error loading class */
1733 e = exceptions_get_and_clear_exception();
1735 if ((e != NULL) || (mainclass == NULL)) {
1736 exceptions_throw_noclassdeffounderror_cause(e);
1737 exceptions_print_stacktrace();
1741 if (!link_class(mainclass)) {
1742 exceptions_print_stacktrace();
1746 /* find the `main' method of the main class */
1748 m = class_resolveclassmethod(mainclass,
1749 utf_new_char("main"),
1750 utf_new_char("([Ljava/lang/String;)V"),
1751 class_java_lang_Object,
1754 if (exceptions_get_exception()) {
1755 exceptions_print_stacktrace();
1759 /* there is no main method or it isn't static */
1761 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1762 exceptions_clear_exception();
1763 exceptions_throw_nosuchmethoderror(mainclass,
1764 utf_new_char("main"),
1765 utf_new_char("([Ljava/lang/String;)V"));
1767 exceptions_print_stacktrace();
1771 #ifdef TYPEINFO_DEBUG_TEST
1772 /* test the typeinfo system */
1776 #if defined(ENABLE_JVMTI)
1777 jvmti_set_phase(JVMTI_PHASE_LIVE);
1780 /* set ThreadMXBean variables */
1782 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1783 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1785 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1786 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1787 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1788 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1789 #warning Move to C++
1791 /* start the main thread */
1793 (void) vm_call_method(m, NULL, oa);
1795 /* exception occurred? */
1797 if (exceptions_get_exception()) {
1798 exceptions_print_stacktrace();
1802 #if defined(ENABLE_THREADS)
1803 /* Detach the main thread so that it appears to have ended when
1804 the application's main method exits. */
1806 if (!thread_detach_current_thread())
1807 vm_abort("vm_run: Could not detach main thread.");
1810 /* Destroy the JavaVM. */
1812 (void) vm_destroy(vm);
1820 /* vm_destroy ******************************************************************
1822 Unloads a Java VM and reclaims its resources.
1824 *******************************************************************************/
1826 int vm_destroy(JavaVM *vm)
1828 #if defined(ENABLE_THREADS)
1829 /* Create a a trivial new Java waiter thread called
1832 JavaVMAttachArgs args;
1834 args.name = (char*) "DestroyJavaVM";
1837 if (!thread_attach_current_thread(&args, false))
1840 /* Wait until we are the last non-daemon thread. */
1842 threads_join_all_threads();
1847 // _created = false;
1848 #warning Move to C++
1850 /* Everything is ok. */
1856 /* vm_exit *********************************************************************
1858 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1860 *******************************************************************************/
1862 void vm_exit(s4 status)
1866 /* signal that we are exiting */
1869 #warning Move to C++
1871 assert(class_java_lang_System);
1872 assert(class_java_lang_System->state & CLASS_LOADED);
1874 #if defined(ENABLE_JVMTI)
1875 if (jvmti || (dbgcom!=NULL)) {
1876 jvmti_set_phase(JVMTI_PHASE_DEAD);
1877 if (jvmti) jvmti_agentunload();
1881 if (!link_class(class_java_lang_System)) {
1882 exceptions_print_stacktrace();
1886 /* call java.lang.System.exit(I)V */
1888 m = class_resolveclassmethod(class_java_lang_System,
1889 utf_new_char("exit"),
1891 class_java_lang_Object,
1895 exceptions_print_stacktrace();
1899 /* call the exit function with passed exit status */
1901 (void) vm_call_method(m, NULL, status);
1903 /* If we had an exception, just ignore the exception and exit with
1906 vm_shutdown(status);
1910 /* vm_shutdown *****************************************************************
1912 Terminates the system immediately without freeing memory explicitly
1913 (to be used only for abnormal termination).
1915 *******************************************************************************/
1917 void vm_shutdown(s4 status)
1920 #if defined(ENABLE_STATISTICS)
1921 || opt_getcompilingtime || opt_stat
1925 log_text("CACAO terminated by shutdown");
1926 dolog("Exit status: %d\n", (s4) status);
1930 #if defined(ENABLE_JVMTI)
1931 /* terminate cacaodbgserver */
1933 mutex_lock(&dbgcomlock);
1935 mutex_unlock(&dbgcomlock);
1936 jvmti_cacaodbgserver_quit();
1944 /* vm_exit_handler *************************************************************
1946 The exit_handler function is called upon program termination.
1948 ATTENTION: Don't free system resources here! Some threads may still
1949 be running as this is called from VMRuntime.exit(). The OS does the
1952 *******************************************************************************/
1954 void vm_exit_handler(void)
1956 #if !defined(NDEBUG)
1958 class_showmethods(mainclass);
1960 if (showconstantpool)
1961 class_showconstantpool(mainclass);
1966 # if defined(ENABLE_PROFILING)
1968 profile_printstats();
1970 #endif /* !defined(NDEBUG) */
1972 #if defined(ENABLE_RT_TIMING)
1973 rt_timing_print_time_stats(stderr);
1976 #if defined(ENABLE_CYCLES_STATS)
1977 builtin_print_cycles_stats(stderr);
1978 stacktrace_print_cycles_stats(stderr);
1982 #if defined(ENABLE_STATISTICS)
1983 || opt_getcompilingtime || opt_stat
1987 log_text("CACAO terminated");
1989 #if defined(ENABLE_STATISTICS)
1992 #ifdef TYPECHECK_STATISTICS
1993 typecheck_print_statistics(get_logfile());
1997 if (opt_getcompilingtime)
1999 #endif /* defined(ENABLE_STATISTICS) */
2001 /* vm_print_profile(stderr);*/
2005 /* vm_abort ********************************************************************
2007 Prints an error message and aborts the VM.
2010 text ... error message to print
2012 *******************************************************************************/
2014 void vm_abort(const char *text, ...)
2018 /* Print the log message. */
2023 log_vprint(text, ap);
2028 /* Now abort the VM. */
2034 /* vm_abort_errnum *************************************************************
2036 Prints an error message, appends ":" plus the strerror-message of
2037 errnum and aborts the VM.
2040 errnum ... error number
2041 text ..... error message to print
2043 *******************************************************************************/
2045 void vm_abort_errnum(int errnum, const char *text, ...)
2049 /* Print the log message. */
2054 log_vprint(text, ap);
2057 /* Print the strerror-message of errnum. */
2059 log_print(": %s", os::strerror(errnum));
2063 /* Now abort the VM. */
2069 /* vm_abort_errno **************************************************************
2071 Equal to vm_abort_errnum, but uses errno to get the error number.
2074 text ... error message to print
2076 *******************************************************************************/
2078 void vm_abort_errno(const char *text, ...)
2083 vm_abort_errnum(errno, text, ap);
2088 /* vm_abort_disassemble ********************************************************
2090 Prints an error message, disassemble the given code range (if
2091 enabled) and aborts the VM.
2094 pc.......PC to disassemble
2095 count....number of instructions to disassemble
2097 *******************************************************************************/
2099 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2102 #if defined(ENABLE_DISASSEMBLER)
2106 /* Print debug message. */
2111 log_vprint(text, ap);
2118 #if SIZEOF_VOID_P == 8
2119 log_println("PC=0x%016lx", pc);
2121 log_println("PC=0x%08x", pc);
2124 #if defined(ENABLE_DISASSEMBLER)
2125 log_println("machine instructions at PC:");
2127 /* Disassemble the given number of instructions. */
2129 for (i = 0; i < count; i++)
2130 // FIXME disassinstr should use void*.
2131 pc = disassinstr((u1*) pc);
2134 vm_abort("Aborting...");
2138 /* vm_get_mainclass_from_jar ***************************************************
2140 Gets the name of the main class from a JAR's manifest file.
2142 *******************************************************************************/
2144 static char *vm_get_mainclass_from_jar(char *mainname)
2151 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2154 exceptions_print_stacktrace();
2158 /* create JarFile object */
2163 exceptions_print_stacktrace();
2167 m = class_resolveclassmethod(c,
2169 utf_java_lang_String__void,
2170 class_java_lang_Object,
2174 exceptions_print_stacktrace();
2178 s = javastring_new_from_ascii(mainname);
2180 (void) vm_call_method(m, o, s);
2182 if (exceptions_get_exception()) {
2183 exceptions_print_stacktrace();
2187 /* get manifest object */
2189 m = class_resolveclassmethod(c,
2190 utf_new_char("getManifest"),
2191 utf_new_char("()Ljava/util/jar/Manifest;"),
2192 class_java_lang_Object,
2196 exceptions_print_stacktrace();
2200 o = vm_call_method(m, o);
2203 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2208 /* get Main Attributes */
2210 LLNI_class_get(o, c);
2212 m = class_resolveclassmethod(c,
2213 utf_new_char("getMainAttributes"),
2214 utf_new_char("()Ljava/util/jar/Attributes;"),
2215 class_java_lang_Object,
2219 exceptions_print_stacktrace();
2223 o = vm_call_method(m, o);
2226 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2231 /* get property Main-Class */
2233 LLNI_class_get(o, c);
2235 m = class_resolveclassmethod(c,
2236 utf_new_char("getValue"),
2237 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2238 class_java_lang_Object,
2242 exceptions_print_stacktrace();
2246 s = javastring_new_from_ascii("Main-Class");
2248 o = vm_call_method(m, o, s);
2251 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2252 fprintf(stderr, "%s\n", mainname);
2256 return javastring_tochar(o);
2260 /* vm_compile_all **************************************************************
2262 Compile all methods found in the bootclasspath.
2264 *******************************************************************************/
2266 #if !defined(NDEBUG)
2267 static void vm_compile_all(void)
2272 classcache_name_entry *nmen;
2273 classcache_class_entry *clsen;
2276 /* create all classes found in the bootclasspath */
2277 /* XXX currently only works with zip/jar's */
2279 loader_load_all_classes();
2281 /* link all classes */
2283 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2284 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2286 for (; nmen; nmen = nmen->hashlink) {
2287 /* iterate over all class entries */
2289 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2290 c = clsen->classobj;
2295 if (!(c->state & CLASS_LINKED)) {
2296 if (!link_class(c)) {
2297 fprintf(stderr, "Error linking: ");
2298 utf_fprint_printable_ascii_classname(stderr, c->name);
2299 fprintf(stderr, "\n");
2301 /* print out exception and cause */
2303 exceptions_print_current_exception();
2305 /* goto next class */
2311 /* compile all class methods */
2313 for (i = 0; i < c->methodscount; i++) {
2314 m = &(c->methods[i]);
2316 if (m->jcode != NULL) {
2317 if (!jit_compile(m)) {
2318 fprintf(stderr, "Error compiling: ");
2319 utf_fprint_printable_ascii_classname(stderr, c->name);
2320 fprintf(stderr, ".");
2321 utf_fprint_printable_ascii(stderr, m->name);
2322 utf_fprint_printable_ascii(stderr, m->descriptor);
2323 fprintf(stderr, "\n");
2325 /* print out exception and cause */
2327 exceptions_print_current_exception();
2335 #endif /* !defined(NDEBUG) */
2338 /* vm_compile_method ***********************************************************
2340 Compile a specific method.
2342 *******************************************************************************/
2344 #if !defined(NDEBUG)
2345 static void vm_compile_method(char* mainname)
2349 /* create, load and link the main class */
2351 mainclass = load_class_bootstrap(utf_new_char(mainname));
2353 if (mainclass == NULL)
2354 exceptions_print_stacktrace();
2356 if (!link_class(mainclass))
2357 exceptions_print_stacktrace();
2359 if (opt_signature != NULL) {
2360 m = class_resolveclassmethod(mainclass,
2361 utf_new_char(opt_method),
2362 utf_new_char(opt_signature),
2367 m = class_resolveclassmethod(mainclass,
2368 utf_new_char(opt_method),
2375 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2376 opt_method, opt_signature ? opt_signature : "");
2380 #endif /* !defined(NDEBUG) */
2383 /* vm_call_array ***************************************************************
2385 Calls a Java method with a variable number of arguments, passed via
2388 ATTENTION: This function has to be used outside the nativeworld.
2390 *******************************************************************************/
2392 #define VM_CALL_ARRAY(name, type) \
2393 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2399 assert(m->code != NULL); \
2401 md = m->parseddesc; \
2402 pv = m->code->entrypoint; \
2404 STATISTICS(count_calls_native_to_java++); \
2406 value = asm_vm_call_method##name(pv, array, md->memuse); \
2411 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2417 assert(m->code != NULL);
2420 pv = m->code->entrypoint;
2422 STATISTICS(count_calls_native_to_java++);
2424 o = asm_vm_call_method(pv, array, md->memuse);
2426 if (md->returntype.type == TYPE_VOID)
2429 return LLNI_WRAP(o);
2432 VM_CALL_ARRAY(_int, int32_t)
2433 VM_CALL_ARRAY(_long, int64_t)
2434 VM_CALL_ARRAY(_float, float)
2435 VM_CALL_ARRAY(_double, double)
2438 /* vm_call_method **************************************************************
2440 Calls a Java method with a variable number of arguments.
2442 *******************************************************************************/
2444 #define VM_CALL_METHOD(name, type) \
2445 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2451 value = vm_call_method##name##_valist(m, o, ap); \
2457 VM_CALL_METHOD(, java_handle_t *)
2458 VM_CALL_METHOD(_int, int32_t)
2459 VM_CALL_METHOD(_long, int64_t)
2460 VM_CALL_METHOD(_float, float)
2461 VM_CALL_METHOD(_double, double)
2464 /* vm_call_method_valist *******************************************************
2466 Calls a Java method with a variable number of arguments, passed via
2469 *******************************************************************************/
2471 #define VM_CALL_METHOD_VALIST(name, type) \
2472 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2477 int32_t dumpmarker; \
2479 if (m->code == NULL) \
2480 if (!jit_compile(m)) \
2483 THREAD_NATIVEWORLD_EXIT; \
2486 array = argument_vmarray_from_valist(m, o, ap); \
2487 value = vm_call##name##_array(m, array); \
2490 THREAD_NATIVEWORLD_ENTER; \
2495 VM_CALL_METHOD_VALIST(, java_handle_t *)
2496 VM_CALL_METHOD_VALIST(_int, int32_t)
2497 VM_CALL_METHOD_VALIST(_long, int64_t)
2498 VM_CALL_METHOD_VALIST(_float, float)
2499 VM_CALL_METHOD_VALIST(_double, double)
2502 /* vm_call_method_jvalue *******************************************************
2504 Calls a Java method with a variable number of arguments, passed via
2507 *******************************************************************************/
2509 #define VM_CALL_METHOD_JVALUE(name, type) \
2510 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2511 const jvalue *args) \
2515 int32_t dumpmarker; \
2517 if (m->code == NULL) \
2518 if (!jit_compile(m)) \
2521 THREAD_NATIVEWORLD_EXIT; \
2524 array = argument_vmarray_from_jvalue(m, o, args); \
2525 value = vm_call##name##_array(m, array); \
2528 THREAD_NATIVEWORLD_ENTER; \
2533 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2534 VM_CALL_METHOD_JVALUE(_int, int32_t)
2535 VM_CALL_METHOD_JVALUE(_long, int64_t)
2536 VM_CALL_METHOD_JVALUE(_float, float)
2537 VM_CALL_METHOD_JVALUE(_double, double)
2540 /* vm_call_method_objectarray **************************************************
2542 Calls a Java method with a variable number if arguments, passed via
2543 an objectarray of boxed values. Returns a boxed value.
2545 *******************************************************************************/
2547 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2548 java_handle_objectarray_t *params)
2551 java_handle_t *xptr;
2556 /* Prevent compiler warnings. */
2560 /* compile methods which are not yet compiled */
2562 if (m->code == NULL)
2563 if (!jit_compile(m))
2566 /* leave the nativeworld */
2568 THREAD_NATIVEWORLD_EXIT;
2570 /* mark start of dump memory area */
2574 /* Fill the argument array from a object-array. */
2576 array = argument_vmarray_from_objectarray(m, o, params);
2578 if (array == NULL) {
2579 /* release dump area */
2583 /* enter the nativeworld again */
2585 THREAD_NATIVEWORLD_ENTER;
2587 exceptions_throw_illegalargumentexception();
2592 switch (m->parseddesc->returntype.primitivetype) {
2593 case PRIMITIVETYPE_VOID:
2594 value.a = vm_call_array(m, array);
2597 case PRIMITIVETYPE_BOOLEAN:
2598 case PRIMITIVETYPE_BYTE:
2599 case PRIMITIVETYPE_CHAR:
2600 case PRIMITIVETYPE_SHORT:
2601 case PRIMITIVETYPE_INT:
2602 value.i = vm_call_int_array(m, array);
2605 case PRIMITIVETYPE_LONG:
2606 value.l = vm_call_long_array(m, array);
2609 case PRIMITIVETYPE_FLOAT:
2610 value.f = vm_call_float_array(m, array);
2613 case PRIMITIVETYPE_DOUBLE:
2614 value.d = vm_call_double_array(m, array);
2618 ro = vm_call_array(m, array);
2622 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2625 /* release dump area */
2629 /* enter the nativeworld again */
2631 THREAD_NATIVEWORLD_ENTER;
2633 /* box the return value if necesarry */
2635 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2636 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2638 /* check for an exception */
2640 xptr = exceptions_get_exception();
2643 /* clear exception pointer, we are calling JIT code again */
2645 exceptions_clear_exception();
2647 exceptions_throw_invocationtargetexception(xptr);
2654 /* Legacy C interface *********************************************************/
2658 JavaVM* VM_get_javavm() { return vm->get_javavm(); }
2659 JNIEnv* VM_get_jnienv() { return vm->get_jnienv(); }
2660 bool VM_is_initializing() { return vm->is_initializing(); }
2661 bool VM_is_created() { return vm->is_created(); }
2662 int64_t VM_get_starttime() { return vm->get_starttime(); }
2668 * These are local overrides for various environment variables in Emacs.
2669 * Please do not remove this and leave it at the end of the file, where
2670 * Emacs will automagically detect them.
2671 * ---------------------------------------------------------------------
2674 * indent-tabs-mode: t
2678 * vim:noexpandtab:sw=4:ts=4: