1 /* src/vm/vm.c - 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
38 #include "vm/jit/abi-asm.h"
40 #include "mm/codememory.h"
41 #include "mm/gc-common.h"
42 #include "mm/memory.h"
44 #include "native/jni.h"
45 #include "native/llni.h"
46 #include "native/localref.h"
47 #include "native/native.h"
49 #include "native/include/java_lang_Object.h" /* required by j.l.C */
50 #include "native/include/java_lang_String.h" /* required by j.l.C */
52 #if defined(WITH_CLASSPATH_SUN)
53 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
54 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
57 #include "native/include/java_lang_Class.h"
59 #include "native/vm/nativevm.h"
61 #include "threads/lock-common.h"
62 #include "threads/threadlist.h"
63 #include "threads/threads-common.h"
65 #include "toolbox/logging.h"
69 #if defined(ENABLE_ASSERTION)
70 #include "vm/assertion.h"
73 #include "vm/builtin.h"
74 #include "vm/exceptions.h"
75 #include "vm/finalizer.h"
76 #include "vm/global.h"
77 #include "vm/initialize.h"
78 #include "vm/package.h"
79 #include "vm/primitive.h"
80 #include "vm/properties.h"
81 #include "vm/signallocal.h"
82 #include "vm/stringlocal.h"
85 #include "vm/jit/argument.h"
86 #include "vm/jit/asmpart.h"
88 #if defined(ENABLE_DISASSEMBLER)
89 # include "vm/jit/disass.h"
92 #include "vm/jit/jit.h"
94 #if defined(ENABLE_PROFILING)
95 # include "vm/jit/optimizing/profile.h"
98 #include "vm/jit/optimizing/recompile.h"
100 #if defined(ENABLE_PYTHON)
101 # include "vm/jit/python.h"
104 #include "vmcore/classcache.h"
105 #include "vmcore/options.h"
106 #include "vmcore/statistics.h"
107 #include "vmcore/suck.h"
108 #include "vmcore/system.h"
110 #if defined(ENABLE_JVMTI)
111 # include "native/jvmti/cacaodbg.h"
114 #if defined(ENABLE_VMLOG)
115 #include <vmlog_cacao.h>
119 /* Invocation API variables ***************************************************/
121 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
122 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
125 /* global variables ***********************************************************/
127 s4 vms = 0; /* number of VMs created */
129 bool vm_initializing = false;
130 bool vm_created = false;
131 bool vm_exiting = false;
133 char *mainstring = NULL;
134 classinfo *mainclass = NULL;
136 #if defined(ENABLE_INTRP)
137 u1 *intrp_main_stack = NULL;
141 /* define heap sizes **********************************************************/
143 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
144 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
145 #define STACK_SIZE 128 * 1024 /* default 64kB */
148 /* define command line options ************************************************/
182 /* Java non-standard options */
193 #if defined(ENABLE_PROFILING)
206 #if defined(ENABLE_STATISTICS)
223 #if defined(ENABLE_VERIFIER)
225 #if defined(TYPECHECK_VERBOSE)
228 #endif /* defined(ENABLE_VERIFIER) */
230 /* optimization options */
232 #if defined(ENABLE_LOOP)
236 #if defined(ENABLE_IFCONV)
240 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
244 #if defined(ENABLE_INTRP)
245 /* interpreter options */
264 #if defined(ENABLE_DEBUG_FILTER)
265 OPT_FILTER_VERBOSECALL_INCLUDE,
266 OPT_FILTER_VERBOSECALL_EXCLUDE,
267 OPT_FILTER_SHOW_METHOD,
274 opt_struct opts[] = {
275 { "foo", false, OPT_FOO },
279 { "jar", false, OPT_JAR },
281 { "d32", false, OPT_D32 },
282 { "d64", false, OPT_D64 },
283 { "client", false, OPT_IGNORE },
284 { "server", false, OPT_IGNORE },
285 { "jvm", false, OPT_IGNORE },
286 { "hotspot", false, OPT_IGNORE },
288 { "classpath", true, OPT_CLASSPATH },
289 { "cp", true, OPT_CLASSPATH },
290 { "D", true, OPT_D },
291 { "version", false, OPT_VERSION },
292 { "showversion", false, OPT_SHOWVERSION },
293 { "fullversion", false, OPT_FULLVERSION },
294 { "help", false, OPT_HELP },
295 { "?", false, OPT_HELP },
296 { "X", false, OPT_X },
297 { "XX:", true, OPT_XX },
299 { "ea:", true, OPT_EA },
300 { "da:", true, OPT_DA },
301 { "ea", false, OPT_EA_NOARG },
302 { "da", false, OPT_DA_NOARG },
304 { "enableassertions:", true, OPT_EA },
305 { "disableassertions:", true, OPT_DA },
306 { "enableassertions", false, OPT_EA_NOARG },
307 { "disableassertions", false, OPT_DA_NOARG },
309 { "esa", false, OPT_ESA },
310 { "enablesystemassertions", false, OPT_ESA },
311 { "dsa", false, OPT_DSA },
312 { "disablesystemassertions", false, OPT_DSA },
314 { "noasyncgc", false, OPT_IGNORE },
315 #if defined(ENABLE_VERIFIER)
316 { "noverify", false, OPT_NOVERIFY },
317 { "Xverify:none", false, OPT_NOVERIFY },
319 { "v", false, OPT_VERBOSE1 },
320 { "verbose:", true, OPT_VERBOSE },
322 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
323 { "verbosetc", false, OPT_VERBOSETC },
325 #if defined(__ALPHA__)
326 { "noieee", false, OPT_NOIEEE },
328 #if defined(ENABLE_STATISTICS)
329 { "time", false, OPT_TIME },
330 { "stat", false, OPT_STAT },
332 { "log", true, OPT_LOG },
333 { "c", true, OPT_CHECK },
334 { "l", false, OPT_LOAD },
337 { "all", false, OPT_ALL },
338 { "sig", true, OPT_SIGNATURE },
341 #if defined(ENABLE_LOOP)
342 { "oloop", false, OPT_OLOOP },
344 #if defined(ENABLE_IFCONV)
345 { "ifconv", false, OPT_IFCONV },
347 #if defined(ENABLE_LSRA)
348 { "lsra", false, OPT_LSRA },
350 #if defined(ENABLE_SSA)
351 { "lsra", true, OPT_LSRA },
354 #if defined(ENABLE_INTRP)
355 /* interpreter options */
357 { "trace", false, OPT_TRACE },
358 { "static-supers", true, OPT_STATIC_SUPERS },
359 { "no-dynamic", false, OPT_NO_DYNAMIC },
360 { "no-replication", false, OPT_NO_REPLICATION },
361 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
364 /* JVMTI Agent Command Line Options */
366 { "agentlib:", true, OPT_AGENTLIB },
367 { "agentpath:", true, OPT_AGENTPATH },
370 /* Java non-standard options */
372 { "Xjit", false, OPT_JIT },
373 { "Xint", false, OPT_INTRP },
374 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
375 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
376 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
377 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
380 { "Xdebug", false, OPT_DEBUG },
381 { "Xnoagent", false, OPT_NOAGENT },
382 { "Xrunjdwp", true, OPT_XRUNJDWP },
385 { "Xms", true, OPT_MS },
386 { "ms", true, OPT_MS },
387 { "Xmx", true, OPT_MX },
388 { "mx", true, OPT_MX },
389 { "Xss", true, OPT_SS },
390 { "ss", true, OPT_SS },
392 #if defined(ENABLE_PROFILING)
393 { "Xprof:", true, OPT_PROF_OPTION },
394 { "Xprof", false, OPT_PROF },
397 /* keep these at the end of the list */
400 { "m", true, OPT_METHOD },
403 { "s", true, OPT_SHOW },
404 { "debug-color", false, OPT_DEBUGCOLOR },
406 #if defined(ENABLE_DEBUG_FILTER)
407 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
408 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
409 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
416 /* usage ***********************************************************************
418 Prints the correct usage syntax to stdout.
420 *******************************************************************************/
424 puts("Usage: cacao [-options] classname [arguments]");
425 puts(" (to run a class file)");
426 puts(" or cacao [-options] -jar jarfile [arguments]");
427 puts(" (to run a standalone jar file)\n");
429 puts("where options include:");
430 puts(" -d32 use 32-bit data model if available");
431 puts(" -d64 use 64-bit data model if available");
432 puts(" -client compatibility (currently ignored)");
433 puts(" -server compatibility (currently ignored)");
434 puts(" -jvm compatibility (currently ignored)");
435 puts(" -hotspot compatibility (currently ignored)\n");
437 puts(" -cp <path> specify a path to look for classes");
438 puts(" -classpath <path> specify a path to look for classes");
439 puts(" -D<name>=<value> add an entry to the property list");
440 puts(" -verbose[:class|gc|jni] enable specific verbose output");
441 puts(" -version print product version and exit");
442 puts(" -fullversion print jpackage-compatible product version and exit");
443 puts(" -showversion print product version and continue");
444 puts(" -help, -? print this help message");
445 puts(" -X print help on non-standard Java options");
446 puts(" -XX print help on debugging options");
447 puts(" -ea[:<packagename>...|:<classname>]");
448 puts(" -enableassertions[:<packagename>...|:<classname>]");
449 puts(" enable assertions with specified granularity");
450 puts(" -da[:<packagename>...|:<classname>]");
451 puts(" -disableassertions[:<packagename>...|:<classname>]");
452 puts(" disable assertions with specified granularity");
453 puts(" -esa | -enablesystemassertions");
454 puts(" enable system assertions");
455 puts(" -dsa | -disablesystemassertions");
456 puts(" disable system assertions");
459 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
460 puts (" for jdwp help use: -agentlib:jdwp=help");
461 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
464 /* exit with error code */
470 static void Xusage(void)
472 #if defined(ENABLE_JIT)
473 puts(" -Xjit JIT mode execution (default)");
475 #if defined(ENABLE_INTRP)
476 puts(" -Xint interpreter mode execution");
478 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
479 puts(" value is set as bootstrap class path");
480 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
481 puts(" value is appended to the bootstrap class path");
482 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
483 puts(" value is prepended to the bootstrap class path");
484 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
485 puts(" value is used as Java core library, but the");
486 puts(" hardcoded VM interface classes are prepended");
487 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
488 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
489 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
491 #if defined(ENABLE_PROFILING)
492 puts(" -Xprof[:bb] collect and print profiling data");
495 #if defined(ENABLE_JVMTI)
496 /* -Xdebug option depend on gnu classpath JDWP options. options:
497 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
498 puts(" -Xdebug enable remote debugging\n");
499 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
500 puts(" enable remote debugging\n");
503 /* exit with error code */
510 static void XXusage(void)
512 puts(" -v write state-information");
514 puts(" -verbose:jit enable specific verbose output");
515 puts(" -debug-color colored output for ANSI terms");
517 #ifdef TYPECHECK_VERBOSE
518 puts(" -verbosetc write debug messages while typechecking");
520 #if defined(__ALPHA__)
521 puts(" -noieee don't use ieee compliant arithmetic");
523 #if defined(ENABLE_VERIFIER)
524 puts(" -noverify don't verify classfiles");
526 #if defined(ENABLE_STATISTICS)
527 puts(" -time measure the runtime");
528 puts(" -stat detailed compiler statistics");
530 puts(" -log logfile specify a name for the logfile");
531 puts(" -c(heck)b(ounds) don't check array bounds");
532 puts(" s(ync) don't check for synchronization");
533 #if defined(ENABLE_LOOP)
534 puts(" -oloop optimize array accesses in loops");
536 puts(" -l don't start the class after loading");
538 puts(" -all compile all methods, no execution");
539 puts(" -m compile only a specific method");
540 puts(" -sig specify signature for a specific method");
543 puts(" -s... show...");
544 puts(" (c)onstants the constant pool");
545 puts(" (m)ethods class fields and methods");
546 puts(" (u)tf the utf - hash");
547 puts(" (i)ntermediate intermediate representation");
548 #if defined(ENABLE_DISASSEMBLER)
549 puts(" (a)ssembler disassembled listing");
550 puts(" n(o)ps show NOPs in disassembler output");
552 puts(" (d)atasegment data segment listing");
554 #if defined(ENABLE_IFCONV)
555 puts(" -ifconv use if-conversion");
557 #if defined(ENABLE_LSRA)
558 puts(" -lsra use linear scan register allocation");
560 #if defined(ENABLE_SSA)
561 puts(" -lsra:... use linear scan register allocation (with SSA)");
562 puts(" (d)ead code elimination");
563 puts(" (c)opy propagation");
565 #if defined(ENABLE_DEBUG_FILTER)
566 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
567 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
568 puts(" -XXfm <regex> filter for show options");
570 /* exit with error code */
577 /* version *********************************************************************
579 Only prints cacao version information.
581 *******************************************************************************/
583 static void version(bool opt_exit)
585 puts("java version \""JAVA_VERSION"\"");
586 puts("CACAO version "VERSION"\n");
588 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
589 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
590 puts("This is free software; see the source for copying conditions. There is NO");
591 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
593 /* exit normally, if requested */
600 /* fullversion *****************************************************************
602 Prints a Sun compatible version information (required e.g. by
603 jpackage, www.jpackage.org).
605 *******************************************************************************/
607 static void fullversion(void)
609 puts("java full version \"cacao-"JAVA_VERSION"\"");
617 static void vm_printconfig(void)
619 puts("Configure/Build options:\n");
620 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
621 #if defined(__VERSION__)
622 puts(" CC : "VERSION_CC" ("__VERSION__")");
624 puts(" CC : "VERSION_CC"");
626 puts(" CFLAGS : "VERSION_CFLAGS"\n");
628 puts("Default variables:\n");
629 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
630 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
631 printf(" stack size : %d\n", STACK_SIZE);
633 #if defined(WITH_JRE_LAYOUT)
634 /* When we're building with JRE-layout, the default paths are the
635 same as the runtime paths. */
637 # if defined(WITH_CLASSPATH_GNU)
638 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
639 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
640 # elif defined(WITH_CLASSPATH_SUN)
641 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
642 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
648 puts("Runtime variables:\n");
649 printf(" maximum heap size : %d\n", opt_heapmaxsize);
650 printf(" initial heap size : %d\n", opt_heapstartsize);
651 printf(" stack size : %d\n", opt_stacksize);
653 #if defined(WITH_CLASSPATH_GNU)
654 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
655 #elif defined(WITH_CLASSPATH_SUN)
656 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
659 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
660 printf(" java.class.path : %s\n", properties_get("java.class.path"));
664 /* forward declarations *******************************************************/
666 static char *vm_get_mainclass_from_jar(char *mainstring);
668 static void vm_compile_all(void);
669 static void vm_compile_method(void);
673 /* vm_createjvm ****************************************************************
675 Implementation for JNI_CreateJavaVM.
677 *******************************************************************************/
679 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
681 JavaVMInitArgs *_vm_args;
685 /* get the arguments for the new JVM */
687 _vm_args = (JavaVMInitArgs *) vm_args;
689 /* get the VM and Env tables (must be set before vm_create) */
691 env = NEW(_Jv_JNIEnv);
693 #if defined(ENABLE_JNI)
694 env->env = &_Jv_JNINativeInterface;
697 /* XXX Set the global variable. Maybe we should do that differently. */
701 /* create and fill a JavaVM structure */
703 vm = NEW(_Jv_JavaVM);
705 #if defined(ENABLE_JNI)
706 vm->functions = &_Jv_JNIInvokeInterface;
709 /* XXX Set the global variable. Maybe we should do that differently. */
710 /* XXX JVMTI Agents needs a JavaVM */
714 /* actually create the JVM */
716 if (!vm_create(_vm_args))
719 /* now return the values */
721 *p_vm = (JavaVM *) vm;
722 *p_env = (void *) env;
727 /* release allocated memory */
729 FREE(env, _Jv_JNIEnv);
730 FREE(vm, _Jv_JavaVM);
736 /* vm_create *******************************************************************
738 Creates a JVM. Called by vm_createjvm.
740 *******************************************************************************/
742 bool vm_create(JavaVMInitArgs *vm_args)
746 char *boot_class_path;
753 #if defined(ENABLE_JVMTI)
755 char *libname, *agentarg;
756 bool jdwp,agentbypath;
757 jdwp = agentbypath = false;
760 #if defined(ENABLE_JNI)
761 /* Check the JNI version requested. */
763 if (!jni_version_check(vm_args->version))
767 /* We only support 1 JVM instance. */
772 /* Install the exit handler. */
774 if (atexit(vm_exit_handler))
775 vm_abort("atexit failed: %s\n", strerror(errno));
777 /* Set some options. */
784 opt_heapmaxsize = HEAP_MAXSIZE;
785 opt_heapstartsize = HEAP_STARTSIZE;
786 opt_stacksize = STACK_SIZE;
788 /* Initialize the properties list before command-line handling.
789 Otherwise -XX:+PrintConfig crashes. */
793 /* First of all, parse the -XX options. */
795 #if defined(ENABLE_VMLOG)
796 vmlog_cacao_init_options();
801 #if defined(ENABLE_VMLOG)
805 /* We need to check if the actual size of a java.lang.Class object
806 is smaller or equal than the assumption made in
807 src/vmcore/class.h. */
809 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
810 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
812 /* set the VM starttime */
814 _Jv_jvm->starttime = builtin_currenttimemillis();
816 #if defined(ENABLE_JVMTI)
817 /* initialize JVMTI related **********************************************/
821 /* Fill the properties before command-line handling. */
825 /* iterate over all passed options */
827 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
841 #if SIZEOF_VOID_P == 8
842 puts("Running a 32-bit JVM is not supported on this platform.");
848 #if SIZEOF_VOID_P == 4
849 puts("Running a 64-bit JVM is not supported on this platform.");
855 /* Forget old classpath and set the argument as new
858 class_path = properties_get("java.class.path");
860 p = MNEW(char, strlen(opt_arg) + strlen("0"));
864 #if defined(ENABLE_JAVASE)
865 properties_add("java.class.path", p);
868 MFREE(class_path, char, strlen(class_path));
872 for (i = 0; i < strlen(opt_arg); i++) {
873 if (opt_arg[i] == '=') {
875 properties_add(opt_arg, opt_arg + i + 1);
880 /* if no '=' is given, just create an empty property */
882 properties_add(opt_arg, "");
887 case OPT_BOOTCLASSPATH:
888 /* Forget default bootclasspath and set the argument as
889 new boot classpath. */
891 boot_class_path = properties_get("sun.boot.class.path");
893 p = MNEW(char, strlen(opt_arg) + strlen("0"));
897 properties_add("sun.boot.class.path", p);
898 properties_add("java.boot.class.path", p);
900 MFREE(boot_class_path, char, strlen(boot_class_path));
903 case OPT_BOOTCLASSPATH_A:
904 /* Append to bootclasspath. */
906 boot_class_path = properties_get("sun.boot.class.path");
908 len = strlen(boot_class_path);
910 p = MREALLOC(boot_class_path,
914 strlen(opt_arg) + strlen("0"));
919 properties_add("sun.boot.class.path", p);
920 properties_add("java.boot.class.path", p);
923 case OPT_BOOTCLASSPATH_P:
924 /* Prepend to bootclasspath. */
926 boot_class_path = properties_get("sun.boot.class.path");
928 len = strlen(boot_class_path);
930 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
934 strcat(p, boot_class_path);
936 properties_add("sun.boot.class.path", p);
937 properties_add("java.boot.class.path", p);
939 MFREE(boot_class_path, char, len);
942 case OPT_BOOTCLASSPATH_C:
943 /* Use as Java core library, but prepend VM interface
946 boot_class_path = properties_get("sun.boot.class.path");
949 strlen(CACAO_VM_ZIP) +
956 strcpy(p, CACAO_VM_ZIP);
960 properties_add("sun.boot.class.path", p);
961 properties_add("java.boot.class.path", p);
963 MFREE(boot_class_path, char, strlen(boot_class_path));
966 #if defined(ENABLE_JVMTI)
968 /* this option exists only for compatibility reasons */
972 /* I don't know yet what Xnoagent should do. This is only for
973 compatiblity with eclipse - motse */
982 strlen(CACAO_LIBDIR) +
983 strlen("/libjdwp.so=") +
987 agentarg = MNEW(char, len);
989 strcpy(agentarg, CACAO_LIBDIR);
990 strcat(agentarg, "/libjdwp.so=");
991 strcat(agentarg, &opt_arg[1]);
1008 c = opt_arg[strlen(opt_arg) - 1];
1010 if ((c == 'k') || (c == 'K')) {
1011 j = atoi(opt_arg) * 1024;
1013 } else if ((c == 'm') || (c == 'M')) {
1014 j = atoi(opt_arg) * 1024 * 1024;
1020 opt_heapmaxsize = j;
1021 else if (opt == OPT_MS)
1022 opt_heapstartsize = j;
1033 if (strcmp("class", opt_arg) == 0) {
1034 opt_verboseclass = true;
1036 else if (strcmp("gc", opt_arg) == 0) {
1037 opt_verbosegc = true;
1039 else if (strcmp("jni", opt_arg) == 0) {
1040 opt_verbosejni = true;
1042 #if !defined(NDEBUG)
1043 else if (strcmp("jit", opt_arg) == 0) {
1047 compileverbose = true;
1051 printf("Unknown -verbose option: %s\n", opt_arg);
1056 case OPT_DEBUGCOLOR:
1057 opt_debugcolor = true;
1060 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1062 opt_typecheckverbose = true;
1071 case OPT_FULLVERSION:
1075 case OPT_SHOWVERSION:
1083 #if defined(ENABLE_VERIFIER)
1089 #if defined(ENABLE_STATISTICS)
1091 opt_getcompilingtime = true;
1092 opt_getloadingtime = true;
1105 for (i = 0; i < strlen(opt_arg); i++) {
1106 switch (opt_arg[i]) {
1108 checkbounds = false;
1121 makeinitializations = false;
1124 #if !defined(NDEBUG)
1128 makeinitializations = false;
1133 opt_method = opt_arg;
1134 makeinitializations = false;
1138 opt_signature = opt_arg;
1142 case OPT_SHOW: /* Display options */
1143 for (i = 0; i < strlen(opt_arg); i++) {
1144 switch (opt_arg[i]) {
1146 showconstantpool = true;
1158 opt_showintermediate = true;
1159 compileverbose = true;
1162 #if defined(ENABLE_DISASSEMBLER)
1164 opt_showdisassemble = true;
1165 compileverbose = true;
1169 opt_shownops = true;
1174 opt_showddatasegment = true;
1183 #if defined(ENABLE_LOOP)
1189 #if defined(ENABLE_IFCONV)
1195 #if defined(ENABLE_LSRA)
1200 #if defined(ENABLE_SSA)
1203 for (i = 0; i < strlen(opt_arg); i++) {
1204 switch (opt_arg[i]) {
1232 /* Already parsed. */
1236 #if defined(ENABLE_ASSERTION)
1237 assertion_ea_da(opt_arg, true);
1242 #if defined(ENABLE_ASSERTION)
1243 assertion_ea_da(opt_arg, false);
1248 #if defined(ENABLE_ASSERTION)
1249 assertion_user_enabled = true;
1254 #if defined(ENABLE_ASSERTION)
1255 assertion_user_enabled = false;
1260 #if defined(ENABLE_ASSERTION)
1261 assertion_system_enabled = true;
1266 #if defined(ENABLE_ASSERTION)
1267 assertion_system_enabled = false;
1271 #if defined(ENABLE_PROFILING)
1272 case OPT_PROF_OPTION:
1273 /* use <= to get the last \0 too */
1275 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1276 if (opt_arg[i] == ',')
1279 if (opt_arg[i] == '\0') {
1280 if (strcmp("bb", opt_arg + j) == 0)
1284 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1288 /* set k to next char */
1301 #if defined(ENABLE_JIT)
1304 printf("-Xjit option not enabled.\n");
1310 #if defined(ENABLE_INTRP)
1313 printf("-Xint option not enabled.\n");
1318 #if defined(ENABLE_INTRP)
1319 case OPT_STATIC_SUPERS:
1320 opt_static_supers = atoi(opt_arg);
1323 case OPT_NO_DYNAMIC:
1324 opt_no_dynamic = true;
1327 case OPT_NO_REPLICATION:
1328 opt_no_replication = true;
1331 case OPT_NO_QUICKSUPER:
1332 opt_no_quicksuper = true;
1340 #if defined(ENABLE_DEBUG_FILTER)
1341 case OPT_FILTER_VERBOSECALL_INCLUDE:
1342 opt_filter_verbosecall_include = opt_arg;
1345 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1346 opt_filter_verbosecall_exclude = opt_arg;
1349 case OPT_FILTER_SHOW_METHOD:
1350 opt_filter_show_method = opt_arg;
1355 printf("Unknown option: %s\n",
1356 vm_args->options[opt_index].optionString);
1361 /* get the main class *****************************************************/
1363 if (opt_index < vm_args->nOptions) {
1364 mainstring = vm_args->options[opt_index++].optionString;
1366 /* Put the jar file into the classpath (if any). */
1368 if (opt_jar == true) {
1369 /* free old classpath */
1371 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1373 /* put jarfile into classpath */
1375 p = MNEW(char, strlen(mainstring) + strlen("0"));
1377 strcpy(p, mainstring);
1379 #if defined(ENABLE_JAVASE)
1380 properties_add("java.class.path", p);
1384 /* replace .'s with /'s in classname */
1386 for (i = strlen(mainstring) - 1; i >= 0; i--)
1387 if (mainstring[i] == '.')
1388 mainstring[i] = '/';
1392 #if defined(ENABLE_JVMTI)
1394 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1395 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1398 MFREE(agentarg, char, strlen(agentarg));
1400 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1404 /* initialize this JVM ****************************************************/
1406 vm_initializing = true;
1408 /* initialize the garbage collector */
1410 gc_init(opt_heapmaxsize, opt_heapstartsize);
1412 #if defined(ENABLE_THREADS)
1413 /* BEFORE: threads_preinit */
1417 /* AFTER: gc_init (directly after, as this initializes the
1418 stopworldlock lock */
1425 /* install architecture dependent signal handlers */
1428 vm_abort("vm_create: signal_init failed");
1430 #if defined(ENABLE_INTRP)
1431 /* Allocate main thread stack on the Java heap. */
1434 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1435 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1439 /* AFTER: threads_preinit */
1442 vm_abort("vm_create: string_init failed");
1444 /* AFTER: threads_preinit */
1448 /* AFTER: thread_preinit */
1451 vm_abort("vm_create: suck_init failed");
1453 suck_add_from_property("java.endorsed.dirs");
1455 /* Now we have all options handled and we can print the version
1458 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1463 /* AFTER: utf8_init */
1465 boot_class_path = properties_get("sun.boot.class.path");
1466 suck_add(boot_class_path);
1468 /* initialize the classcache hashtable stuff: lock, hashtable
1469 (must be done _after_ threads_preinit) */
1471 if (!classcache_init())
1472 vm_abort("vm_create: classcache_init failed");
1474 /* Initialize the code memory management. */
1475 /* AFTER: threads_preinit */
1479 /* initialize the finalizer stuff (must be done _after_
1482 if (!finalizer_init())
1483 vm_abort("vm_create: finalizer_init failed");
1485 /* initializes jit compiler */
1489 #if defined(ENABLE_PYTHON)
1493 /* BEFORE: loader_preinit */
1497 /* AFTER: utf8_init, classcache_init */
1502 /* AFTER: loader_preinit, linker_preinit */
1509 /* AFTER: loader_init, linker_init */
1511 primitive_postinit();
1515 if (!builtin_init())
1516 vm_abort("vm_create: builtin_init failed");
1518 /* Initialize the native subsystem. */
1519 /* BEFORE: threads_init */
1522 vm_abort("vm_create: native_init failed");
1524 /* Register the native methods implemented in the VM. */
1525 /* BEFORE: threads_init */
1527 if (!nativevm_preinit())
1528 vm_abort("vm_create: nativevm_preinit failed");
1530 #if defined(ENABLE_JNI)
1531 /* Initialize the JNI subsystem (must be done _before_
1532 threads_init, as threads_init can call JNI methods
1533 (e.g. NewGlobalRef). */
1536 vm_abort("vm_create: jni_init failed");
1539 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1540 /* Initialize the local reference table for the main thread. */
1541 /* BEFORE: threads_init */
1543 if (!localref_table_init())
1544 vm_abort("vm_create: localref_table_init failed");
1547 #if defined(ENABLE_THREADS)
1551 /* Initialize the native VM subsystem. */
1552 /* AFTER: threads_init (at least for SUN's classes) */
1554 if (!nativevm_init())
1555 vm_abort("vm_create: nativevm_init failed");
1557 #if defined(ENABLE_PROFILING)
1558 /* initialize profiling */
1560 if (!profile_init())
1561 vm_abort("vm_create: profile_init failed");
1564 #if defined(ENABLE_THREADS)
1565 /* initialize recompilation */
1567 if (!recompile_init())
1568 vm_abort("vm_create: recompile_init failed");
1570 /* start the signal handler thread */
1572 #if defined(__LINUX__)
1573 /* XXX Remove for exact-GC. */
1574 if (threads_pthreads_implementation_nptl)
1576 if (!signal_start_thread())
1577 vm_abort("vm_create: signal_start_thread failed");
1579 /* finally, start the finalizer thread */
1581 if (!finalizer_start_thread())
1582 vm_abort("vm_create: finalizer_start_thread failed");
1584 # if !defined(NDEBUG)
1585 /* start the memory profiling thread */
1587 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1588 if (!memory_start_thread())
1589 vm_abort("vm_create: memory_start_thread failed");
1592 /* start the recompilation thread (must be done before the
1593 profiling thread) */
1595 if (!recompile_start_thread())
1596 vm_abort("vm_create: recompile_start_thread failed");
1598 # if defined(ENABLE_PROFILING)
1599 /* start the profile sampling thread */
1602 /* if (!profile_start_thread()) */
1603 /* vm_abort("vm_create: profile_start_thread failed"); */
1607 #if defined(ENABLE_JVMTI)
1608 # if defined(ENABLE_GC_CACAO)
1609 /* XXX this will not work with the new indirection cells for classloaders!!! */
1613 /* add agent library to native library hashtable */
1614 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1618 /* Increment the number of VMs. */
1622 /* Initialization is done, VM is created.. */
1625 vm_initializing = false;
1627 /* Print the VM configuration after all stuff is set and the VM is
1630 if (opt_PrintConfig)
1633 /* everything's ok */
1639 /* vm_run **********************************************************************
1641 Runs the main-method of the passed class.
1643 *******************************************************************************/
1645 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1648 classinfo *mainclass;
1651 java_handle_objectarray_t *oa;
1658 #if !defined(NDEBUG)
1664 if (opt_method != NULL) {
1665 vm_compile_method();
1668 #endif /* !defined(NDEBUG) */
1670 /* should we run the main-method? */
1672 if (mainstring == NULL)
1675 /* set return value to OK */
1679 if (opt_jar == true) {
1680 /* open jar file with java.util.jar.JarFile */
1682 mainstring = vm_get_mainclass_from_jar(mainstring);
1684 if (mainstring == NULL)
1688 /* load the main class */
1690 mainutf = utf_new_char(mainstring);
1692 #if defined(ENABLE_JAVAME_CLDC1_1)
1693 mainclass = load_class_bootstrap(mainutf);
1695 mainclass = load_class_from_sysloader(mainutf);
1698 /* error loading class */
1700 e = exceptions_get_and_clear_exception();
1702 if ((e != NULL) || (mainclass == NULL)) {
1703 exceptions_throw_noclassdeffounderror_cause(e);
1704 exceptions_print_stacktrace();
1708 if (!link_class(mainclass)) {
1709 exceptions_print_stacktrace();
1713 /* find the `main' method of the main class */
1715 m = class_resolveclassmethod(mainclass,
1716 utf_new_char("main"),
1717 utf_new_char("([Ljava/lang/String;)V"),
1718 class_java_lang_Object,
1721 if (exceptions_get_exception()) {
1722 exceptions_print_stacktrace();
1726 /* there is no main method or it isn't static */
1728 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1729 exceptions_clear_exception();
1730 exceptions_throw_nosuchmethoderror(mainclass,
1731 utf_new_char("main"),
1732 utf_new_char("([Ljava/lang/String;)V"));
1734 exceptions_print_stacktrace();
1738 /* build argument array */
1740 oalength = vm_args->nOptions - opt_index;
1742 oa = builtin_anewarray(oalength, class_java_lang_String);
1744 for (i = 0; i < oalength; i++) {
1745 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1746 s = javastring_new(u);
1748 array_objectarray_element_set(oa, i, s);
1751 #ifdef TYPEINFO_DEBUG_TEST
1752 /* test the typeinfo system */
1755 /*class_showmethods(currentThread->group->header.vftbl->class); */
1757 #if defined(ENABLE_JVMTI)
1758 jvmti_set_phase(JVMTI_PHASE_LIVE);
1761 /* set ThreadMXBean variables */
1763 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1764 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1766 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1767 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1768 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1769 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1771 /* start the main thread */
1773 (void) vm_call_method(m, NULL, oa);
1775 /* exception occurred? */
1777 if (exceptions_get_exception()) {
1778 exceptions_print_stacktrace();
1782 /* unload the JavaVM */
1784 (void) vm_destroy(vm);
1792 /* vm_destroy ******************************************************************
1794 Unloads a Java VM and reclaims its resources.
1796 *******************************************************************************/
1798 s4 vm_destroy(JavaVM *vm)
1800 #if defined(ENABLE_THREADS)
1801 threads_join_all_threads();
1808 /* everything's ok */
1814 /* vm_exit *********************************************************************
1816 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1818 *******************************************************************************/
1820 void vm_exit(s4 status)
1824 /* signal that we are exiting */
1828 assert(class_java_lang_System);
1829 assert(class_java_lang_System->state & CLASS_LOADED);
1831 #if defined(ENABLE_JVMTI)
1832 if (jvmti || (dbgcom!=NULL)) {
1833 jvmti_set_phase(JVMTI_PHASE_DEAD);
1834 if (jvmti) jvmti_agentunload();
1838 if (!link_class(class_java_lang_System)) {
1839 exceptions_print_stacktrace();
1843 /* call java.lang.System.exit(I)V */
1845 m = class_resolveclassmethod(class_java_lang_System,
1846 utf_new_char("exit"),
1848 class_java_lang_Object,
1852 exceptions_print_stacktrace();
1856 /* call the exit function with passed exit status */
1858 (void) vm_call_method(m, NULL, status);
1860 /* If we had an exception, just ignore the exception and exit with
1863 vm_shutdown(status);
1867 /* vm_shutdown *****************************************************************
1869 Terminates the system immediately without freeing memory explicitly
1870 (to be used only for abnormal termination).
1872 *******************************************************************************/
1874 void vm_shutdown(s4 status)
1877 #if defined(ENABLE_STATISTICS)
1878 || opt_getcompilingtime || opt_stat
1882 log_text("CACAO terminated by shutdown");
1883 dolog("Exit status: %d\n", (s4) status);
1887 #if defined(ENABLE_JVMTI)
1888 /* terminate cacaodbgserver */
1890 pthread_mutex_lock(&dbgcomlock);
1892 pthread_mutex_unlock(&dbgcomlock);
1893 jvmti_cacaodbgserver_quit();
1901 /* vm_exit_handler *************************************************************
1903 The exit_handler function is called upon program termination.
1905 ATTENTION: Don't free system resources here! Some threads may still
1906 be running as this is called from VMRuntime.exit(). The OS does the
1909 *******************************************************************************/
1911 void vm_exit_handler(void)
1913 #if !defined(NDEBUG)
1915 class_showmethods(mainclass);
1917 if (showconstantpool)
1918 class_showconstantpool(mainclass);
1923 # if defined(ENABLE_PROFILING)
1925 profile_printstats();
1927 #endif /* !defined(NDEBUG) */
1929 #if defined(ENABLE_RT_TIMING)
1930 rt_timing_print_time_stats(stderr);
1933 #if defined(ENABLE_CYCLES_STATS)
1934 builtin_print_cycles_stats(stderr);
1935 stacktrace_print_cycles_stats(stderr);
1939 #if defined(ENABLE_STATISTICS)
1940 || opt_getcompilingtime || opt_stat
1944 log_text("CACAO terminated");
1946 #if defined(ENABLE_STATISTICS)
1949 #ifdef TYPECHECK_STATISTICS
1950 typecheck_print_statistics(get_logfile());
1954 if (opt_getcompilingtime)
1956 #endif /* defined(ENABLE_STATISTICS) */
1958 /* vm_print_profile(stderr);*/
1962 /* vm_abort ********************************************************************
1964 Prints an error message and aborts the VM.
1967 text ... error message to print
1969 *******************************************************************************/
1971 void vm_abort(const char *text, ...)
1975 /* Print the log message. */
1980 log_vprint(text, ap);
1985 /* Now abort the VM. */
1991 /* vm_abort_errnum *************************************************************
1993 Prints an error message, appends ":" plus the strerror-message of
1994 errnum and aborts the VM.
1997 errnum ... error number
1998 text ..... error message to print
2000 *******************************************************************************/
2002 void vm_abort_errnum(int errnum, const char *text, ...)
2006 /* Print the log message. */
2011 log_vprint(text, ap);
2014 /* Print the strerror-message of errnum. */
2016 log_print(": %s", system_strerror(errnum));
2020 /* Now abort the VM. */
2026 /* vm_abort_errno **************************************************************
2028 Equal to vm_abort_errnum, but uses errno to get the error number.
2031 text ... error message to print
2033 *******************************************************************************/
2035 void vm_abort_errno(const char *text, ...)
2040 vm_abort_errnum(errno, text, ap);
2045 /* vm_abort_disassemble ********************************************************
2047 Prints an error message, disassemble the given code range (if
2048 enabled) and aborts the VM.
2051 pc.......PC to disassemble
2052 count....number of instructions to disassemble
2054 *******************************************************************************/
2056 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2059 #if defined(ENABLE_DISASSEMBLER)
2063 /* Print debug message. */
2068 log_vprint(text, ap);
2075 #if SIZEOF_VOID_P == 8
2076 log_println("PC=0x%016lx", pc);
2078 log_println("PC=0x%08x", pc);
2081 #if defined(ENABLE_DISASSEMBLER)
2082 log_println("machine instructions at PC:");
2084 /* Disassemble the given number of instructions. */
2086 for (i = 0; i < count; i++)
2087 pc = disassinstr(pc);
2090 vm_abort("Aborting...");
2094 /* vm_get_mainclass_from_jar ***************************************************
2096 Gets the name of the main class from a JAR's manifest file.
2098 *******************************************************************************/
2100 static char *vm_get_mainclass_from_jar(char *mainstring)
2107 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2110 exceptions_print_stacktrace();
2114 /* create JarFile object */
2119 exceptions_print_stacktrace();
2123 m = class_resolveclassmethod(c,
2125 utf_java_lang_String__void,
2126 class_java_lang_Object,
2130 exceptions_print_stacktrace();
2134 s = javastring_new_from_ascii(mainstring);
2136 (void) vm_call_method(m, o, s);
2138 if (exceptions_get_exception()) {
2139 exceptions_print_stacktrace();
2143 /* get manifest object */
2145 m = class_resolveclassmethod(c,
2146 utf_new_char("getManifest"),
2147 utf_new_char("()Ljava/util/jar/Manifest;"),
2148 class_java_lang_Object,
2152 exceptions_print_stacktrace();
2156 o = vm_call_method(m, o);
2159 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2164 /* get Main Attributes */
2166 LLNI_class_get(o, c);
2168 m = class_resolveclassmethod(c,
2169 utf_new_char("getMainAttributes"),
2170 utf_new_char("()Ljava/util/jar/Attributes;"),
2171 class_java_lang_Object,
2175 exceptions_print_stacktrace();
2179 o = vm_call_method(m, o);
2182 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2187 /* get property Main-Class */
2189 LLNI_class_get(o, c);
2191 m = class_resolveclassmethod(c,
2192 utf_new_char("getValue"),
2193 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2194 class_java_lang_Object,
2198 exceptions_print_stacktrace();
2202 s = javastring_new_from_ascii("Main-Class");
2204 o = vm_call_method(m, o, s);
2207 exceptions_print_stacktrace();
2211 return javastring_tochar(o);
2215 /* vm_compile_all **************************************************************
2217 Compile all methods found in the bootclasspath.
2219 *******************************************************************************/
2221 #if !defined(NDEBUG)
2222 static void vm_compile_all(void)
2227 classcache_name_entry *nmen;
2228 classcache_class_entry *clsen;
2231 /* create all classes found in the bootclasspath */
2232 /* XXX currently only works with zip/jar's */
2234 loader_load_all_classes();
2236 /* link all classes */
2238 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2239 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2241 for (; nmen; nmen = nmen->hashlink) {
2242 /* iterate over all class entries */
2244 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2245 c = clsen->classobj;
2250 if (!(c->state & CLASS_LINKED)) {
2251 if (!link_class(c)) {
2252 fprintf(stderr, "Error linking: ");
2253 utf_fprint_printable_ascii_classname(stderr, c->name);
2254 fprintf(stderr, "\n");
2256 /* print out exception and cause */
2258 exceptions_print_current_exception();
2260 /* goto next class */
2266 /* compile all class methods */
2268 for (i = 0; i < c->methodscount; i++) {
2269 m = &(c->methods[i]);
2271 if (m->jcode != NULL) {
2272 if (!jit_compile(m)) {
2273 fprintf(stderr, "Error compiling: ");
2274 utf_fprint_printable_ascii_classname(stderr, c->name);
2275 fprintf(stderr, ".");
2276 utf_fprint_printable_ascii(stderr, m->name);
2277 utf_fprint_printable_ascii(stderr, m->descriptor);
2278 fprintf(stderr, "\n");
2280 /* print out exception and cause */
2282 exceptions_print_current_exception();
2290 #endif /* !defined(NDEBUG) */
2293 /* vm_compile_method ***********************************************************
2295 Compile a specific method.
2297 *******************************************************************************/
2299 #if !defined(NDEBUG)
2300 static void vm_compile_method(void)
2304 /* create, load and link the main class */
2306 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2308 if (mainclass == NULL)
2309 exceptions_print_stacktrace();
2311 if (!link_class(mainclass))
2312 exceptions_print_stacktrace();
2314 if (opt_signature != NULL) {
2315 m = class_resolveclassmethod(mainclass,
2316 utf_new_char(opt_method),
2317 utf_new_char(opt_signature),
2322 m = class_resolveclassmethod(mainclass,
2323 utf_new_char(opt_method),
2330 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2331 opt_method, opt_signature ? opt_signature : "");
2335 #endif /* !defined(NDEBUG) */
2338 /* vm_call_array ***************************************************************
2340 Calls a Java method with a variable number of arguments, passed via
2343 ATTENTION: This function has to be used outside the nativeworld.
2345 *******************************************************************************/
2347 #define VM_CALL_ARRAY(name, type) \
2348 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2354 assert(m->code != NULL); \
2356 md = m->parseddesc; \
2357 pv = m->code->entrypoint; \
2359 STATISTICS(count_calls_native_to_java++); \
2361 value = asm_vm_call_method##name(pv, array, md->memuse); \
2366 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2372 assert(m->code != NULL);
2375 pv = m->code->entrypoint;
2377 STATISTICS(count_calls_native_to_java++);
2379 o = asm_vm_call_method(pv, array, md->memuse);
2381 if (md->returntype.type == TYPE_VOID)
2384 return LLNI_WRAP(o);
2387 VM_CALL_ARRAY(_int, int32_t)
2388 VM_CALL_ARRAY(_long, int64_t)
2389 VM_CALL_ARRAY(_float, float)
2390 VM_CALL_ARRAY(_double, double)
2393 /* vm_call_method **************************************************************
2395 Calls a Java method with a variable number of arguments.
2397 *******************************************************************************/
2399 #define VM_CALL_METHOD(name, type) \
2400 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2406 value = vm_call_method##name##_valist(m, o, ap); \
2412 VM_CALL_METHOD(, java_handle_t *)
2413 VM_CALL_METHOD(_int, int32_t)
2414 VM_CALL_METHOD(_long, int64_t)
2415 VM_CALL_METHOD(_float, float)
2416 VM_CALL_METHOD(_double, double)
2419 /* vm_call_method_valist *******************************************************
2421 Calls a Java method with a variable number of arguments, passed via
2424 *******************************************************************************/
2426 #define VM_CALL_METHOD_VALIST(name, type) \
2427 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2432 int32_t dumpmarker; \
2434 if (m->code == NULL) \
2435 if (!jit_compile(m)) \
2438 THREAD_NATIVEWORLD_EXIT; \
2441 array = argument_vmarray_from_valist(m, o, ap); \
2442 value = vm_call##name##_array(m, array); \
2445 THREAD_NATIVEWORLD_ENTER; \
2450 VM_CALL_METHOD_VALIST(, java_handle_t *)
2451 VM_CALL_METHOD_VALIST(_int, int32_t)
2452 VM_CALL_METHOD_VALIST(_long, int64_t)
2453 VM_CALL_METHOD_VALIST(_float, float)
2454 VM_CALL_METHOD_VALIST(_double, double)
2457 /* vm_call_method_jvalue *******************************************************
2459 Calls a Java method with a variable number of arguments, passed via
2462 *******************************************************************************/
2464 #define VM_CALL_METHOD_JVALUE(name, type) \
2465 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2466 const jvalue *args) \
2470 int32_t dumpmarker; \
2472 if (m->code == NULL) \
2473 if (!jit_compile(m)) \
2476 THREAD_NATIVEWORLD_EXIT; \
2479 array = argument_vmarray_from_jvalue(m, o, args); \
2480 value = vm_call##name##_array(m, array); \
2483 THREAD_NATIVEWORLD_ENTER; \
2488 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2489 VM_CALL_METHOD_JVALUE(_int, int32_t)
2490 VM_CALL_METHOD_JVALUE(_long, int64_t)
2491 VM_CALL_METHOD_JVALUE(_float, float)
2492 VM_CALL_METHOD_JVALUE(_double, double)
2495 /* vm_call_method_objectarray **************************************************
2497 Calls a Java method with a variable number if arguments, passed via
2498 an objectarray of boxed values. Returns a boxed value.
2500 *******************************************************************************/
2502 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2503 java_handle_objectarray_t *params)
2506 java_handle_t *xptr;
2511 /* Prevent compiler warnings. */
2515 /* compile methods which are not yet compiled */
2517 if (m->code == NULL)
2518 if (!jit_compile(m))
2521 /* leave the nativeworld */
2523 THREAD_NATIVEWORLD_EXIT;
2525 /* mark start of dump memory area */
2529 /* Fill the argument array from a object-array. */
2531 array = argument_vmarray_from_objectarray(m, o, params);
2533 if (array == NULL) {
2534 /* release dump area */
2538 /* enter the nativeworld again */
2540 THREAD_NATIVEWORLD_ENTER;
2542 exceptions_throw_illegalargumentexception();
2547 switch (m->parseddesc->returntype.decltype) {
2548 case PRIMITIVETYPE_VOID:
2549 value.a = vm_call_array(m, array);
2552 case PRIMITIVETYPE_BOOLEAN:
2553 case PRIMITIVETYPE_BYTE:
2554 case PRIMITIVETYPE_CHAR:
2555 case PRIMITIVETYPE_SHORT:
2556 case PRIMITIVETYPE_INT:
2557 value.i = vm_call_int_array(m, array);
2560 case PRIMITIVETYPE_LONG:
2561 value.l = vm_call_long_array(m, array);
2564 case PRIMITIVETYPE_FLOAT:
2565 value.f = vm_call_float_array(m, array);
2568 case PRIMITIVETYPE_DOUBLE:
2569 value.d = vm_call_double_array(m, array);
2573 ro = vm_call_array(m, array);
2577 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2580 /* release dump area */
2584 /* enter the nativeworld again */
2586 THREAD_NATIVEWORLD_ENTER;
2588 /* box the return value if necesarry */
2590 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2591 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2593 /* check for an exception */
2595 xptr = exceptions_get_exception();
2598 /* clear exception pointer, we are calling JIT code again */
2600 exceptions_clear_exception();
2602 exceptions_throw_invocationtargetexception(xptr);
2610 * These are local overrides for various environment variables in Emacs.
2611 * Please do not remove this and leave it at the end of the file, where
2612 * Emacs will automagically detect them.
2613 * ---------------------------------------------------------------------
2616 * indent-tabs-mode: t
2620 * vim:noexpandtab:sw=4:ts=4: