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"
87 #include "vm/jit/code.h"
89 #if defined(ENABLE_DISASSEMBLER)
90 # include "vm/jit/disass.h"
93 #include "vm/jit/jit.h"
94 #include "vm/jit/methodtree.h"
96 #if defined(ENABLE_PROFILING)
97 # include "vm/jit/optimizing/profile.h"
100 #include "vm/jit/optimizing/recompile.h"
102 #if defined(ENABLE_PYTHON)
103 # include "vm/jit/python.h"
106 #include "vmcore/classcache.h"
107 #include "vmcore/options.h"
108 #include "vmcore/statistics.h"
109 #include "vmcore/suck.h"
110 #include "vmcore/system.h"
112 #if defined(ENABLE_JVMTI)
113 # include "native/jvmti/cacaodbg.h"
116 #if defined(ENABLE_VMLOG)
117 #include <vmlog_cacao.h>
121 /* Invocation API variables ***************************************************/
123 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
124 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
127 /* global variables ***********************************************************/
129 s4 vms = 0; /* number of VMs created */
131 bool vm_initializing = false;
132 bool vm_created = false;
133 bool vm_exiting = false;
135 char *mainstring = NULL;
136 classinfo *mainclass = NULL;
138 #if defined(ENABLE_INTRP)
139 u1 *intrp_main_stack = NULL;
143 /* define heap sizes **********************************************************/
145 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
146 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
147 #define STACK_SIZE 128 * 1024 /* default 64kB */
150 /* define command line options ************************************************/
184 /* Java non-standard options */
195 #if defined(ENABLE_PROFILING)
208 #if defined(ENABLE_STATISTICS)
225 #if defined(ENABLE_VERIFIER)
227 #if defined(TYPECHECK_VERBOSE)
230 #endif /* defined(ENABLE_VERIFIER) */
232 /* optimization options */
234 #if defined(ENABLE_LOOP)
238 #if defined(ENABLE_IFCONV)
242 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
246 #if defined(ENABLE_INTRP)
247 /* interpreter options */
266 #if defined(ENABLE_DEBUG_FILTER)
267 OPT_FILTER_VERBOSECALL_INCLUDE,
268 OPT_FILTER_VERBOSECALL_EXCLUDE,
269 OPT_FILTER_SHOW_METHOD,
276 opt_struct opts[] = {
277 { "foo", false, OPT_FOO },
281 { "jar", false, OPT_JAR },
283 { "d32", false, OPT_D32 },
284 { "d64", false, OPT_D64 },
285 { "client", false, OPT_IGNORE },
286 { "server", false, OPT_IGNORE },
287 { "jvm", false, OPT_IGNORE },
288 { "hotspot", false, OPT_IGNORE },
290 { "classpath", true, OPT_CLASSPATH },
291 { "cp", true, OPT_CLASSPATH },
292 { "D", true, OPT_D },
293 { "version", false, OPT_VERSION },
294 { "showversion", false, OPT_SHOWVERSION },
295 { "fullversion", false, OPT_FULLVERSION },
296 { "help", false, OPT_HELP },
297 { "?", false, OPT_HELP },
298 { "X", false, OPT_X },
299 { "XX:", true, OPT_XX },
301 { "ea:", true, OPT_EA },
302 { "da:", true, OPT_DA },
303 { "ea", false, OPT_EA_NOARG },
304 { "da", false, OPT_DA_NOARG },
306 { "enableassertions:", true, OPT_EA },
307 { "disableassertions:", true, OPT_DA },
308 { "enableassertions", false, OPT_EA_NOARG },
309 { "disableassertions", false, OPT_DA_NOARG },
311 { "esa", false, OPT_ESA },
312 { "enablesystemassertions", false, OPT_ESA },
313 { "dsa", false, OPT_DSA },
314 { "disablesystemassertions", false, OPT_DSA },
316 { "noasyncgc", false, OPT_IGNORE },
317 #if defined(ENABLE_VERIFIER)
318 { "noverify", false, OPT_NOVERIFY },
319 { "Xverify:none", false, OPT_NOVERIFY },
321 { "v", false, OPT_VERBOSE1 },
322 { "verbose:", true, OPT_VERBOSE },
324 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
325 { "verbosetc", false, OPT_VERBOSETC },
327 #if defined(__ALPHA__)
328 { "noieee", false, OPT_NOIEEE },
330 #if defined(ENABLE_STATISTICS)
331 { "time", false, OPT_TIME },
332 { "stat", false, OPT_STAT },
334 { "log", true, OPT_LOG },
335 { "c", true, OPT_CHECK },
336 { "l", false, OPT_LOAD },
339 { "all", false, OPT_ALL },
340 { "sig", true, OPT_SIGNATURE },
343 #if defined(ENABLE_LOOP)
344 { "oloop", false, OPT_OLOOP },
346 #if defined(ENABLE_IFCONV)
347 { "ifconv", false, OPT_IFCONV },
349 #if defined(ENABLE_LSRA)
350 { "lsra", false, OPT_LSRA },
352 #if defined(ENABLE_SSA)
353 { "lsra", true, OPT_LSRA },
356 #if defined(ENABLE_INTRP)
357 /* interpreter options */
359 { "trace", false, OPT_TRACE },
360 { "static-supers", true, OPT_STATIC_SUPERS },
361 { "no-dynamic", false, OPT_NO_DYNAMIC },
362 { "no-replication", false, OPT_NO_REPLICATION },
363 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
366 /* JVMTI Agent Command Line Options */
368 { "agentlib:", true, OPT_AGENTLIB },
369 { "agentpath:", true, OPT_AGENTPATH },
372 /* Java non-standard options */
374 { "Xjit", false, OPT_JIT },
375 { "Xint", false, OPT_INTRP },
376 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
377 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
378 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
379 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
382 { "Xdebug", false, OPT_DEBUG },
383 { "Xnoagent", false, OPT_NOAGENT },
384 { "Xrunjdwp", true, OPT_XRUNJDWP },
387 { "Xms", true, OPT_MS },
388 { "ms", true, OPT_MS },
389 { "Xmx", true, OPT_MX },
390 { "mx", true, OPT_MX },
391 { "Xss", true, OPT_SS },
392 { "ss", true, OPT_SS },
394 #if defined(ENABLE_PROFILING)
395 { "Xprof:", true, OPT_PROF_OPTION },
396 { "Xprof", false, OPT_PROF },
399 /* keep these at the end of the list */
402 { "m", true, OPT_METHOD },
405 { "s", true, OPT_SHOW },
406 { "debug-color", false, OPT_DEBUGCOLOR },
408 #if defined(ENABLE_DEBUG_FILTER)
409 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
410 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
411 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
418 /* usage ***********************************************************************
420 Prints the correct usage syntax to stdout.
422 *******************************************************************************/
426 puts("Usage: cacao [-options] classname [arguments]");
427 puts(" (to run a class file)");
428 puts(" or cacao [-options] -jar jarfile [arguments]");
429 puts(" (to run a standalone jar file)\n");
431 puts("where options include:");
432 puts(" -d32 use 32-bit data model if available");
433 puts(" -d64 use 64-bit data model if available");
434 puts(" -client compatibility (currently ignored)");
435 puts(" -server compatibility (currently ignored)");
436 puts(" -jvm compatibility (currently ignored)");
437 puts(" -hotspot compatibility (currently ignored)\n");
439 puts(" -cp <path> specify a path to look for classes");
440 puts(" -classpath <path> specify a path to look for classes");
441 puts(" -D<name>=<value> add an entry to the property list");
442 puts(" -verbose[:class|gc|jni] enable specific verbose output");
443 puts(" -version print product version and exit");
444 puts(" -fullversion print jpackage-compatible product version and exit");
445 puts(" -showversion print product version and continue");
446 puts(" -help, -? print this help message");
447 puts(" -X print help on non-standard Java options");
448 puts(" -XX print help on debugging options");
449 puts(" -ea[:<packagename>...|:<classname>]");
450 puts(" -enableassertions[:<packagename>...|:<classname>]");
451 puts(" enable assertions with specified granularity");
452 puts(" -da[:<packagename>...|:<classname>]");
453 puts(" -disableassertions[:<packagename>...|:<classname>]");
454 puts(" disable assertions with specified granularity");
455 puts(" -esa | -enablesystemassertions");
456 puts(" enable system assertions");
457 puts(" -dsa | -disablesystemassertions");
458 puts(" disable system assertions");
461 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
462 puts (" for jdwp help use: -agentlib:jdwp=help");
463 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
466 /* exit with error code */
472 static void Xusage(void)
474 #if defined(ENABLE_JIT)
475 puts(" -Xjit JIT mode execution (default)");
477 #if defined(ENABLE_INTRP)
478 puts(" -Xint interpreter mode execution");
480 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
481 puts(" value is set as bootstrap class path");
482 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
483 puts(" value is appended to the bootstrap class path");
484 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
485 puts(" value is prepended to the bootstrap class path");
486 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
487 puts(" value is used as Java core library, but the");
488 puts(" hardcoded VM interface classes are prepended");
489 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
490 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
491 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
493 #if defined(ENABLE_PROFILING)
494 puts(" -Xprof[:bb] collect and print profiling data");
497 #if defined(ENABLE_JVMTI)
498 /* -Xdebug option depend on gnu classpath JDWP options. options:
499 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
500 puts(" -Xdebug enable remote debugging\n");
501 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
502 puts(" enable remote debugging\n");
505 /* exit with error code */
512 static void XXusage(void)
514 puts(" -v write state-information");
516 puts(" -verbose:jit enable specific verbose output");
517 puts(" -debug-color colored output for ANSI terms");
519 #ifdef TYPECHECK_VERBOSE
520 puts(" -verbosetc write debug messages while typechecking");
522 #if defined(__ALPHA__)
523 puts(" -noieee don't use ieee compliant arithmetic");
525 #if defined(ENABLE_VERIFIER)
526 puts(" -noverify don't verify classfiles");
528 #if defined(ENABLE_STATISTICS)
529 puts(" -time measure the runtime");
530 puts(" -stat detailed compiler statistics");
532 puts(" -log logfile specify a name for the logfile");
533 puts(" -c(heck)b(ounds) don't check array bounds");
534 puts(" s(ync) don't check for synchronization");
535 #if defined(ENABLE_LOOP)
536 puts(" -oloop optimize array accesses in loops");
538 puts(" -l don't start the class after loading");
540 puts(" -all compile all methods, no execution");
541 puts(" -m compile only a specific method");
542 puts(" -sig specify signature for a specific method");
545 puts(" -s... show...");
546 puts(" (c)onstants the constant pool");
547 puts(" (m)ethods class fields and methods");
548 puts(" (u)tf the utf - hash");
549 puts(" (i)ntermediate intermediate representation");
550 #if defined(ENABLE_DISASSEMBLER)
551 puts(" (a)ssembler disassembled listing");
552 puts(" n(o)ps show NOPs in disassembler output");
554 puts(" (d)atasegment data segment listing");
556 #if defined(ENABLE_IFCONV)
557 puts(" -ifconv use if-conversion");
559 #if defined(ENABLE_LSRA)
560 puts(" -lsra use linear scan register allocation");
562 #if defined(ENABLE_SSA)
563 puts(" -lsra:... use linear scan register allocation (with SSA)");
564 puts(" (d)ead code elimination");
565 puts(" (c)opy propagation");
567 #if defined(ENABLE_DEBUG_FILTER)
568 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
569 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
570 puts(" -XXfm <regex> filter for show options");
572 /* exit with error code */
579 /* version *********************************************************************
581 Only prints cacao version information.
583 *******************************************************************************/
585 static void version(bool opt_exit)
587 puts("java version \""JAVA_VERSION"\"");
588 puts("CACAO version "VERSION"\n");
590 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
591 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
592 puts("This is free software; see the source for copying conditions. There is NO");
593 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
595 /* exit normally, if requested */
602 /* fullversion *****************************************************************
604 Prints a Sun compatible version information (required e.g. by
605 jpackage, www.jpackage.org).
607 *******************************************************************************/
609 static void fullversion(void)
611 puts("java full version \"cacao-"JAVA_VERSION"\"");
619 static void vm_printconfig(void)
621 puts("Configure/Build options:\n");
622 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
623 #if defined(__VERSION__)
624 puts(" CC : "VERSION_CC" ("__VERSION__")");
626 puts(" CC : "VERSION_CC"");
628 puts(" CFLAGS : "VERSION_CFLAGS"\n");
630 puts("Default variables:\n");
631 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
632 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
633 printf(" stack size : %d\n", STACK_SIZE);
635 #if defined(WITH_JRE_LAYOUT)
636 /* When we're building with JRE-layout, the default paths are the
637 same as the runtime paths. */
639 # if defined(WITH_CLASSPATH_GNU)
640 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
641 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
642 # elif defined(WITH_CLASSPATH_SUN)
643 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
644 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
650 puts("Runtime variables:\n");
651 printf(" maximum heap size : %d\n", opt_heapmaxsize);
652 printf(" initial heap size : %d\n", opt_heapstartsize);
653 printf(" stack size : %d\n", opt_stacksize);
655 #if defined(WITH_CLASSPATH_GNU)
656 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
657 #elif defined(WITH_CLASSPATH_SUN)
658 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
661 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
662 printf(" java.class.path : %s\n", properties_get("java.class.path"));
666 /* forward declarations *******************************************************/
668 static char *vm_get_mainclass_from_jar(char *mainstring);
670 static void vm_compile_all(void);
671 static void vm_compile_method(void);
675 /* vm_createjvm ****************************************************************
677 Implementation for JNI_CreateJavaVM.
679 *******************************************************************************/
681 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
683 JavaVMInitArgs *_vm_args;
687 /* get the arguments for the new JVM */
689 _vm_args = (JavaVMInitArgs *) vm_args;
691 /* get the VM and Env tables (must be set before vm_create) */
693 env = NEW(_Jv_JNIEnv);
695 #if defined(ENABLE_JNI)
696 env->env = &_Jv_JNINativeInterface;
699 /* XXX Set the global variable. Maybe we should do that differently. */
703 /* create and fill a JavaVM structure */
705 vm = NEW(_Jv_JavaVM);
707 #if defined(ENABLE_JNI)
708 vm->functions = &_Jv_JNIInvokeInterface;
711 /* XXX Set the global variable. Maybe we should do that differently. */
712 /* XXX JVMTI Agents needs a JavaVM */
716 /* actually create the JVM */
718 if (!vm_create(_vm_args))
721 /* now return the values */
723 *p_vm = (JavaVM *) vm;
724 *p_env = (void *) env;
729 /* release allocated memory */
731 FREE(env, _Jv_JNIEnv);
732 FREE(vm, _Jv_JavaVM);
738 /* vm_create *******************************************************************
740 Creates a JVM. Called by vm_createjvm.
742 *******************************************************************************/
744 bool vm_create(JavaVMInitArgs *vm_args)
748 char *boot_class_path;
755 #if defined(ENABLE_JVMTI)
757 char *libname, *agentarg;
758 bool jdwp,agentbypath;
759 jdwp = agentbypath = false;
762 #if defined(ENABLE_JNI)
763 /* Check the JNI version requested. */
765 if (!jni_version_check(vm_args->version))
769 /* We only support 1 JVM instance. */
774 /* Install the exit handler. */
776 if (atexit(vm_exit_handler))
777 vm_abort("atexit failed: %s\n", strerror(errno));
779 /* Set some options. */
786 opt_heapmaxsize = HEAP_MAXSIZE;
787 opt_heapstartsize = HEAP_STARTSIZE;
788 opt_stacksize = STACK_SIZE;
790 /* Initialize the properties list before command-line handling.
791 Otherwise -XX:+PrintConfig crashes. */
795 /* First of all, parse the -XX options. */
797 #if defined(ENABLE_VMLOG)
798 vmlog_cacao_init_options();
803 #if defined(ENABLE_VMLOG)
807 /* We need to check if the actual size of a java.lang.Class object
808 is smaller or equal than the assumption made in
809 src/vmcore/class.h. */
811 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
812 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
814 /* set the VM starttime */
816 _Jv_jvm->starttime = builtin_currenttimemillis();
818 #if defined(ENABLE_JVMTI)
819 /* initialize JVMTI related **********************************************/
823 /* Fill the properties before command-line handling. */
827 /* iterate over all passed options */
829 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
843 #if SIZEOF_VOID_P == 8
844 puts("Running a 32-bit JVM is not supported on this platform.");
850 #if SIZEOF_VOID_P == 4
851 puts("Running a 64-bit JVM is not supported on this platform.");
857 /* Forget old classpath and set the argument as new
860 class_path = properties_get("java.class.path");
862 p = MNEW(char, strlen(opt_arg) + strlen("0"));
866 #if defined(ENABLE_JAVASE)
867 properties_add("java.class.path", p);
870 MFREE(class_path, char, strlen(class_path));
874 for (i = 0; i < strlen(opt_arg); i++) {
875 if (opt_arg[i] == '=') {
877 properties_add(opt_arg, opt_arg + i + 1);
882 /* if no '=' is given, just create an empty property */
884 properties_add(opt_arg, "");
889 case OPT_BOOTCLASSPATH:
890 /* Forget default bootclasspath and set the argument as
891 new boot classpath. */
893 boot_class_path = properties_get("sun.boot.class.path");
895 p = MNEW(char, strlen(opt_arg) + strlen("0"));
899 properties_add("sun.boot.class.path", p);
900 properties_add("java.boot.class.path", p);
902 MFREE(boot_class_path, char, strlen(boot_class_path));
905 case OPT_BOOTCLASSPATH_A:
906 /* Append to bootclasspath. */
908 boot_class_path = properties_get("sun.boot.class.path");
910 len = strlen(boot_class_path);
912 p = MREALLOC(boot_class_path,
916 strlen(opt_arg) + strlen("0"));
921 properties_add("sun.boot.class.path", p);
922 properties_add("java.boot.class.path", p);
925 case OPT_BOOTCLASSPATH_P:
926 /* Prepend to bootclasspath. */
928 boot_class_path = properties_get("sun.boot.class.path");
930 len = strlen(boot_class_path);
932 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
936 strcat(p, boot_class_path);
938 properties_add("sun.boot.class.path", p);
939 properties_add("java.boot.class.path", p);
941 MFREE(boot_class_path, char, len);
944 case OPT_BOOTCLASSPATH_C:
945 /* Use as Java core library, but prepend VM interface
948 boot_class_path = properties_get("sun.boot.class.path");
951 strlen(CACAO_VM_ZIP) +
958 strcpy(p, CACAO_VM_ZIP);
962 properties_add("sun.boot.class.path", p);
963 properties_add("java.boot.class.path", p);
965 MFREE(boot_class_path, char, strlen(boot_class_path));
968 #if defined(ENABLE_JVMTI)
970 /* this option exists only for compatibility reasons */
974 /* I don't know yet what Xnoagent should do. This is only for
975 compatiblity with eclipse - motse */
984 strlen(CACAO_LIBDIR) +
985 strlen("/libjdwp.so=") +
989 agentarg = MNEW(char, len);
991 strcpy(agentarg, CACAO_LIBDIR);
992 strcat(agentarg, "/libjdwp.so=");
993 strcat(agentarg, &opt_arg[1]);
1010 c = opt_arg[strlen(opt_arg) - 1];
1012 if ((c == 'k') || (c == 'K')) {
1013 j = atoi(opt_arg) * 1024;
1015 } else if ((c == 'm') || (c == 'M')) {
1016 j = atoi(opt_arg) * 1024 * 1024;
1022 opt_heapmaxsize = j;
1023 else if (opt == OPT_MS)
1024 opt_heapstartsize = j;
1035 if (strcmp("class", opt_arg) == 0) {
1036 opt_verboseclass = true;
1038 else if (strcmp("gc", opt_arg) == 0) {
1039 opt_verbosegc = true;
1041 else if (strcmp("jni", opt_arg) == 0) {
1042 opt_verbosejni = true;
1044 #if !defined(NDEBUG)
1045 else if (strcmp("jit", opt_arg) == 0) {
1049 compileverbose = true;
1053 printf("Unknown -verbose option: %s\n", opt_arg);
1058 case OPT_DEBUGCOLOR:
1059 opt_debugcolor = true;
1062 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1064 opt_typecheckverbose = true;
1073 case OPT_FULLVERSION:
1077 case OPT_SHOWVERSION:
1085 #if defined(ENABLE_VERIFIER)
1091 #if defined(ENABLE_STATISTICS)
1093 opt_getcompilingtime = true;
1094 opt_getloadingtime = true;
1107 for (i = 0; i < strlen(opt_arg); i++) {
1108 switch (opt_arg[i]) {
1110 checkbounds = false;
1123 makeinitializations = false;
1126 #if !defined(NDEBUG)
1130 makeinitializations = false;
1135 opt_method = opt_arg;
1136 makeinitializations = false;
1140 opt_signature = opt_arg;
1144 case OPT_SHOW: /* Display options */
1145 for (i = 0; i < strlen(opt_arg); i++) {
1146 switch (opt_arg[i]) {
1148 showconstantpool = true;
1160 opt_showintermediate = true;
1161 compileverbose = true;
1164 #if defined(ENABLE_DISASSEMBLER)
1166 opt_showdisassemble = true;
1167 compileverbose = true;
1171 opt_shownops = true;
1176 opt_showddatasegment = true;
1185 #if defined(ENABLE_LOOP)
1191 #if defined(ENABLE_IFCONV)
1197 #if defined(ENABLE_LSRA)
1202 #if defined(ENABLE_SSA)
1205 for (i = 0; i < strlen(opt_arg); i++) {
1206 switch (opt_arg[i]) {
1234 /* Already parsed. */
1238 #if defined(ENABLE_ASSERTION)
1239 assertion_ea_da(opt_arg, true);
1244 #if defined(ENABLE_ASSERTION)
1245 assertion_ea_da(opt_arg, false);
1250 #if defined(ENABLE_ASSERTION)
1251 assertion_user_enabled = true;
1256 #if defined(ENABLE_ASSERTION)
1257 assertion_user_enabled = false;
1262 #if defined(ENABLE_ASSERTION)
1263 assertion_system_enabled = true;
1268 #if defined(ENABLE_ASSERTION)
1269 assertion_system_enabled = false;
1273 #if defined(ENABLE_PROFILING)
1274 case OPT_PROF_OPTION:
1275 /* use <= to get the last \0 too */
1277 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1278 if (opt_arg[i] == ',')
1281 if (opt_arg[i] == '\0') {
1282 if (strcmp("bb", opt_arg + j) == 0)
1286 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1290 /* set k to next char */
1303 #if defined(ENABLE_JIT)
1306 printf("-Xjit option not enabled.\n");
1312 #if defined(ENABLE_INTRP)
1315 printf("-Xint option not enabled.\n");
1320 #if defined(ENABLE_INTRP)
1321 case OPT_STATIC_SUPERS:
1322 opt_static_supers = atoi(opt_arg);
1325 case OPT_NO_DYNAMIC:
1326 opt_no_dynamic = true;
1329 case OPT_NO_REPLICATION:
1330 opt_no_replication = true;
1333 case OPT_NO_QUICKSUPER:
1334 opt_no_quicksuper = true;
1342 #if defined(ENABLE_DEBUG_FILTER)
1343 case OPT_FILTER_VERBOSECALL_INCLUDE:
1344 opt_filter_verbosecall_include = opt_arg;
1347 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1348 opt_filter_verbosecall_exclude = opt_arg;
1351 case OPT_FILTER_SHOW_METHOD:
1352 opt_filter_show_method = opt_arg;
1357 printf("Unknown option: %s\n",
1358 vm_args->options[opt_index].optionString);
1363 /* get the main class *****************************************************/
1365 if (opt_index < vm_args->nOptions) {
1366 mainstring = vm_args->options[opt_index++].optionString;
1368 /* Put the jar file into the classpath (if any). */
1370 if (opt_jar == true) {
1371 /* free old classpath */
1373 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1375 /* put jarfile into classpath */
1377 p = MNEW(char, strlen(mainstring) + strlen("0"));
1379 strcpy(p, mainstring);
1381 #if defined(ENABLE_JAVASE)
1382 properties_add("java.class.path", p);
1386 /* replace .'s with /'s in classname */
1388 for (i = strlen(mainstring) - 1; i >= 0; i--)
1389 if (mainstring[i] == '.')
1390 mainstring[i] = '/';
1394 #if defined(ENABLE_JVMTI)
1396 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1397 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1400 MFREE(agentarg, char, strlen(agentarg));
1402 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1406 /* initialize this JVM ****************************************************/
1408 vm_initializing = true;
1410 /* initialize the garbage collector */
1412 gc_init(opt_heapmaxsize, opt_heapstartsize);
1414 #if defined(ENABLE_THREADS)
1415 /* BEFORE: threads_preinit */
1419 /* AFTER: gc_init (directly after, as this initializes the
1420 stopworldlock lock */
1427 /* install architecture dependent signal handlers */
1430 vm_abort("vm_create: signal_init failed");
1432 #if defined(ENABLE_INTRP)
1433 /* Allocate main thread stack on the Java heap. */
1436 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1437 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1441 /* AFTER: threads_preinit */
1444 vm_abort("vm_create: string_init failed");
1446 /* AFTER: threads_preinit */
1450 /* AFTER: thread_preinit */
1453 vm_abort("vm_create: suck_init failed");
1455 suck_add_from_property("java.endorsed.dirs");
1457 /* Now we have all options handled and we can print the version
1460 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1465 /* AFTER: utf8_init */
1467 boot_class_path = properties_get("sun.boot.class.path");
1468 suck_add(boot_class_path);
1470 /* initialize the classcache hashtable stuff: lock, hashtable
1471 (must be done _after_ threads_preinit) */
1473 if (!classcache_init())
1474 vm_abort("vm_create: classcache_init failed");
1476 /* Initialize the code memory management. */
1477 /* AFTER: threads_preinit */
1481 /* initialize the finalizer stuff (must be done _after_
1484 if (!finalizer_init())
1485 vm_abort("vm_create: finalizer_init failed");
1487 /* Initialize the JIT compiler. */
1493 #if defined(ENABLE_PYTHON)
1497 /* BEFORE: loader_preinit */
1501 /* AFTER: utf8_init, classcache_init */
1506 /* AFTER: loader_preinit, linker_preinit */
1513 /* AFTER: loader_init, linker_init */
1515 primitive_postinit();
1519 if (!builtin_init())
1520 vm_abort("vm_create: builtin_init failed");
1522 /* Initialize the native subsystem. */
1523 /* BEFORE: threads_init */
1526 vm_abort("vm_create: native_init failed");
1528 /* Register the native methods implemented in the VM. */
1529 /* BEFORE: threads_init */
1531 if (!nativevm_preinit())
1532 vm_abort("vm_create: nativevm_preinit failed");
1534 #if defined(ENABLE_JNI)
1535 /* Initialize the JNI subsystem (must be done _before_
1536 threads_init, as threads_init can call JNI methods
1537 (e.g. NewGlobalRef). */
1540 vm_abort("vm_create: jni_init failed");
1543 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1544 /* Initialize the local reference table for the main thread. */
1545 /* BEFORE: threads_init */
1547 if (!localref_table_init())
1548 vm_abort("vm_create: localref_table_init failed");
1551 #if defined(ENABLE_THREADS)
1555 /* Initialize the native VM subsystem. */
1556 /* AFTER: threads_init (at least for SUN's classes) */
1558 if (!nativevm_init())
1559 vm_abort("vm_create: nativevm_init failed");
1561 #if defined(ENABLE_PROFILING)
1562 /* initialize profiling */
1564 if (!profile_init())
1565 vm_abort("vm_create: profile_init failed");
1568 #if defined(ENABLE_THREADS)
1569 /* initialize recompilation */
1571 if (!recompile_init())
1572 vm_abort("vm_create: recompile_init failed");
1574 /* start the signal handler thread */
1576 #if defined(__LINUX__)
1577 /* XXX Remove for exact-GC. */
1578 if (threads_pthreads_implementation_nptl)
1580 if (!signal_start_thread())
1581 vm_abort("vm_create: signal_start_thread failed");
1583 /* finally, start the finalizer thread */
1585 if (!finalizer_start_thread())
1586 vm_abort("vm_create: finalizer_start_thread failed");
1588 # if !defined(NDEBUG)
1589 /* start the memory profiling thread */
1591 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1592 if (!memory_start_thread())
1593 vm_abort("vm_create: memory_start_thread failed");
1596 /* start the recompilation thread (must be done before the
1597 profiling thread) */
1599 if (!recompile_start_thread())
1600 vm_abort("vm_create: recompile_start_thread failed");
1602 # if defined(ENABLE_PROFILING)
1603 /* start the profile sampling thread */
1606 /* if (!profile_start_thread()) */
1607 /* vm_abort("vm_create: profile_start_thread failed"); */
1611 #if defined(ENABLE_JVMTI)
1612 # if defined(ENABLE_GC_CACAO)
1613 /* XXX this will not work with the new indirection cells for classloaders!!! */
1617 /* add agent library to native library hashtable */
1618 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1622 /* Increment the number of VMs. */
1626 /* Initialization is done, VM is created.. */
1629 vm_initializing = false;
1631 /* Print the VM configuration after all stuff is set and the VM is
1634 if (opt_PrintConfig)
1637 /* everything's ok */
1643 /* vm_run **********************************************************************
1645 Runs the main-method of the passed class.
1647 *******************************************************************************/
1649 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1652 classinfo *mainclass;
1655 java_handle_objectarray_t *oa;
1662 #if !defined(NDEBUG)
1668 if (opt_method != NULL) {
1669 vm_compile_method();
1672 #endif /* !defined(NDEBUG) */
1674 /* should we run the main-method? */
1676 if (mainstring == NULL)
1679 /* set return value to OK */
1683 if (opt_jar == true) {
1684 /* open jar file with java.util.jar.JarFile */
1686 mainstring = vm_get_mainclass_from_jar(mainstring);
1688 if (mainstring == NULL)
1692 /* load the main class */
1694 mainutf = utf_new_char(mainstring);
1696 #if defined(ENABLE_JAVAME_CLDC1_1)
1697 mainclass = load_class_bootstrap(mainutf);
1699 mainclass = load_class_from_sysloader(mainutf);
1702 /* error loading class */
1704 e = exceptions_get_and_clear_exception();
1706 if ((e != NULL) || (mainclass == NULL)) {
1707 exceptions_throw_noclassdeffounderror_cause(e);
1708 exceptions_print_stacktrace();
1712 if (!link_class(mainclass)) {
1713 exceptions_print_stacktrace();
1717 /* find the `main' method of the main class */
1719 m = class_resolveclassmethod(mainclass,
1720 utf_new_char("main"),
1721 utf_new_char("([Ljava/lang/String;)V"),
1722 class_java_lang_Object,
1725 if (exceptions_get_exception()) {
1726 exceptions_print_stacktrace();
1730 /* there is no main method or it isn't static */
1732 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1733 exceptions_clear_exception();
1734 exceptions_throw_nosuchmethoderror(mainclass,
1735 utf_new_char("main"),
1736 utf_new_char("([Ljava/lang/String;)V"));
1738 exceptions_print_stacktrace();
1742 /* build argument array */
1744 oalength = vm_args->nOptions - opt_index;
1746 oa = builtin_anewarray(oalength, class_java_lang_String);
1748 for (i = 0; i < oalength; i++) {
1749 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1750 s = javastring_new(u);
1752 array_objectarray_element_set(oa, i, s);
1755 #ifdef TYPEINFO_DEBUG_TEST
1756 /* test the typeinfo system */
1759 /*class_showmethods(currentThread->group->header.vftbl->class); */
1761 #if defined(ENABLE_JVMTI)
1762 jvmti_set_phase(JVMTI_PHASE_LIVE);
1765 /* set ThreadMXBean variables */
1767 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1768 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1770 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1771 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1772 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1773 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1775 /* start the main thread */
1777 (void) vm_call_method(m, NULL, oa);
1779 /* exception occurred? */
1781 if (exceptions_get_exception()) {
1782 exceptions_print_stacktrace();
1786 /* unload the JavaVM */
1788 (void) vm_destroy(vm);
1796 /* vm_destroy ******************************************************************
1798 Unloads a Java VM and reclaims its resources.
1800 *******************************************************************************/
1802 s4 vm_destroy(JavaVM *vm)
1804 #if defined(ENABLE_THREADS)
1805 threads_join_all_threads();
1812 /* everything's ok */
1818 /* vm_exit *********************************************************************
1820 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1822 *******************************************************************************/
1824 void vm_exit(s4 status)
1828 /* signal that we are exiting */
1832 assert(class_java_lang_System);
1833 assert(class_java_lang_System->state & CLASS_LOADED);
1835 #if defined(ENABLE_JVMTI)
1836 if (jvmti || (dbgcom!=NULL)) {
1837 jvmti_set_phase(JVMTI_PHASE_DEAD);
1838 if (jvmti) jvmti_agentunload();
1842 if (!link_class(class_java_lang_System)) {
1843 exceptions_print_stacktrace();
1847 /* call java.lang.System.exit(I)V */
1849 m = class_resolveclassmethod(class_java_lang_System,
1850 utf_new_char("exit"),
1852 class_java_lang_Object,
1856 exceptions_print_stacktrace();
1860 /* call the exit function with passed exit status */
1862 (void) vm_call_method(m, NULL, status);
1864 /* If we had an exception, just ignore the exception and exit with
1867 vm_shutdown(status);
1871 /* vm_shutdown *****************************************************************
1873 Terminates the system immediately without freeing memory explicitly
1874 (to be used only for abnormal termination).
1876 *******************************************************************************/
1878 void vm_shutdown(s4 status)
1881 #if defined(ENABLE_STATISTICS)
1882 || opt_getcompilingtime || opt_stat
1886 log_text("CACAO terminated by shutdown");
1887 dolog("Exit status: %d\n", (s4) status);
1891 #if defined(ENABLE_JVMTI)
1892 /* terminate cacaodbgserver */
1894 pthread_mutex_lock(&dbgcomlock);
1896 pthread_mutex_unlock(&dbgcomlock);
1897 jvmti_cacaodbgserver_quit();
1905 /* vm_exit_handler *************************************************************
1907 The exit_handler function is called upon program termination.
1909 ATTENTION: Don't free system resources here! Some threads may still
1910 be running as this is called from VMRuntime.exit(). The OS does the
1913 *******************************************************************************/
1915 void vm_exit_handler(void)
1917 #if !defined(NDEBUG)
1919 class_showmethods(mainclass);
1921 if (showconstantpool)
1922 class_showconstantpool(mainclass);
1927 # if defined(ENABLE_PROFILING)
1929 profile_printstats();
1931 #endif /* !defined(NDEBUG) */
1933 #if defined(ENABLE_RT_TIMING)
1934 rt_timing_print_time_stats(stderr);
1937 #if defined(ENABLE_CYCLES_STATS)
1938 builtin_print_cycles_stats(stderr);
1939 stacktrace_print_cycles_stats(stderr);
1943 #if defined(ENABLE_STATISTICS)
1944 || opt_getcompilingtime || opt_stat
1948 log_text("CACAO terminated");
1950 #if defined(ENABLE_STATISTICS)
1953 #ifdef TYPECHECK_STATISTICS
1954 typecheck_print_statistics(get_logfile());
1958 if (opt_getcompilingtime)
1960 #endif /* defined(ENABLE_STATISTICS) */
1962 /* vm_print_profile(stderr);*/
1966 /* vm_abort ********************************************************************
1968 Prints an error message and aborts the VM.
1971 text ... error message to print
1973 *******************************************************************************/
1975 void vm_abort(const char *text, ...)
1979 /* Print the log message. */
1984 log_vprint(text, ap);
1989 /* Now abort the VM. */
1995 /* vm_abort_errnum *************************************************************
1997 Prints an error message, appends ":" plus the strerror-message of
1998 errnum and aborts the VM.
2001 errnum ... error number
2002 text ..... error message to print
2004 *******************************************************************************/
2006 void vm_abort_errnum(int errnum, const char *text, ...)
2010 /* Print the log message. */
2015 log_vprint(text, ap);
2018 /* Print the strerror-message of errnum. */
2020 log_print(": %s", system_strerror(errnum));
2024 /* Now abort the VM. */
2030 /* vm_abort_errno **************************************************************
2032 Equal to vm_abort_errnum, but uses errno to get the error number.
2035 text ... error message to print
2037 *******************************************************************************/
2039 void vm_abort_errno(const char *text, ...)
2044 vm_abort_errnum(errno, text, ap);
2049 /* vm_abort_disassemble ********************************************************
2051 Prints an error message, disassemble the given code range (if
2052 enabled) and aborts the VM.
2055 pc.......PC to disassemble
2056 count....number of instructions to disassemble
2058 *******************************************************************************/
2060 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2063 #if defined(ENABLE_DISASSEMBLER)
2067 /* Print debug message. */
2072 log_vprint(text, ap);
2079 #if SIZEOF_VOID_P == 8
2080 log_println("PC=0x%016lx", pc);
2082 log_println("PC=0x%08x", pc);
2085 #if defined(ENABLE_DISASSEMBLER)
2086 log_println("machine instructions at PC:");
2088 /* Disassemble the given number of instructions. */
2090 for (i = 0; i < count; i++)
2091 pc = disassinstr(pc);
2094 vm_abort("Aborting...");
2098 /* vm_get_mainclass_from_jar ***************************************************
2100 Gets the name of the main class from a JAR's manifest file.
2102 *******************************************************************************/
2104 static char *vm_get_mainclass_from_jar(char *mainstring)
2111 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2114 exceptions_print_stacktrace();
2118 /* create JarFile object */
2123 exceptions_print_stacktrace();
2127 m = class_resolveclassmethod(c,
2129 utf_java_lang_String__void,
2130 class_java_lang_Object,
2134 exceptions_print_stacktrace();
2138 s = javastring_new_from_ascii(mainstring);
2140 (void) vm_call_method(m, o, s);
2142 if (exceptions_get_exception()) {
2143 exceptions_print_stacktrace();
2147 /* get manifest object */
2149 m = class_resolveclassmethod(c,
2150 utf_new_char("getManifest"),
2151 utf_new_char("()Ljava/util/jar/Manifest;"),
2152 class_java_lang_Object,
2156 exceptions_print_stacktrace();
2160 o = vm_call_method(m, o);
2163 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2168 /* get Main Attributes */
2170 LLNI_class_get(o, c);
2172 m = class_resolveclassmethod(c,
2173 utf_new_char("getMainAttributes"),
2174 utf_new_char("()Ljava/util/jar/Attributes;"),
2175 class_java_lang_Object,
2179 exceptions_print_stacktrace();
2183 o = vm_call_method(m, o);
2186 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2191 /* get property Main-Class */
2193 LLNI_class_get(o, c);
2195 m = class_resolveclassmethod(c,
2196 utf_new_char("getValue"),
2197 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2198 class_java_lang_Object,
2202 exceptions_print_stacktrace();
2206 s = javastring_new_from_ascii("Main-Class");
2208 o = vm_call_method(m, o, s);
2211 exceptions_print_stacktrace();
2215 return javastring_tochar(o);
2219 /* vm_compile_all **************************************************************
2221 Compile all methods found in the bootclasspath.
2223 *******************************************************************************/
2225 #if !defined(NDEBUG)
2226 static void vm_compile_all(void)
2231 classcache_name_entry *nmen;
2232 classcache_class_entry *clsen;
2235 /* create all classes found in the bootclasspath */
2236 /* XXX currently only works with zip/jar's */
2238 loader_load_all_classes();
2240 /* link all classes */
2242 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2243 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2245 for (; nmen; nmen = nmen->hashlink) {
2246 /* iterate over all class entries */
2248 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2249 c = clsen->classobj;
2254 if (!(c->state & CLASS_LINKED)) {
2255 if (!link_class(c)) {
2256 fprintf(stderr, "Error linking: ");
2257 utf_fprint_printable_ascii_classname(stderr, c->name);
2258 fprintf(stderr, "\n");
2260 /* print out exception and cause */
2262 exceptions_print_current_exception();
2264 /* goto next class */
2270 /* compile all class methods */
2272 for (i = 0; i < c->methodscount; i++) {
2273 m = &(c->methods[i]);
2275 if (m->jcode != NULL) {
2276 if (!jit_compile(m)) {
2277 fprintf(stderr, "Error compiling: ");
2278 utf_fprint_printable_ascii_classname(stderr, c->name);
2279 fprintf(stderr, ".");
2280 utf_fprint_printable_ascii(stderr, m->name);
2281 utf_fprint_printable_ascii(stderr, m->descriptor);
2282 fprintf(stderr, "\n");
2284 /* print out exception and cause */
2286 exceptions_print_current_exception();
2294 #endif /* !defined(NDEBUG) */
2297 /* vm_compile_method ***********************************************************
2299 Compile a specific method.
2301 *******************************************************************************/
2303 #if !defined(NDEBUG)
2304 static void vm_compile_method(void)
2308 /* create, load and link the main class */
2310 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2312 if (mainclass == NULL)
2313 exceptions_print_stacktrace();
2315 if (!link_class(mainclass))
2316 exceptions_print_stacktrace();
2318 if (opt_signature != NULL) {
2319 m = class_resolveclassmethod(mainclass,
2320 utf_new_char(opt_method),
2321 utf_new_char(opt_signature),
2326 m = class_resolveclassmethod(mainclass,
2327 utf_new_char(opt_method),
2334 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2335 opt_method, opt_signature ? opt_signature : "");
2339 #endif /* !defined(NDEBUG) */
2342 /* vm_call_array ***************************************************************
2344 Calls a Java method with a variable number of arguments, passed via
2347 ATTENTION: This function has to be used outside the nativeworld.
2349 *******************************************************************************/
2351 #define VM_CALL_ARRAY(name, type) \
2352 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2358 assert(m->code != NULL); \
2360 md = m->parseddesc; \
2361 pv = m->code->entrypoint; \
2363 STATISTICS(count_calls_native_to_java++); \
2365 value = asm_vm_call_method##name(pv, array, md->memuse); \
2370 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2376 assert(m->code != NULL);
2379 pv = m->code->entrypoint;
2381 STATISTICS(count_calls_native_to_java++);
2383 o = asm_vm_call_method(pv, array, md->memuse);
2385 if (md->returntype.type == TYPE_VOID)
2388 return LLNI_WRAP(o);
2391 VM_CALL_ARRAY(_int, int32_t)
2392 VM_CALL_ARRAY(_long, int64_t)
2393 VM_CALL_ARRAY(_float, float)
2394 VM_CALL_ARRAY(_double, double)
2397 /* vm_call_method **************************************************************
2399 Calls a Java method with a variable number of arguments.
2401 *******************************************************************************/
2403 #define VM_CALL_METHOD(name, type) \
2404 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2410 value = vm_call_method##name##_valist(m, o, ap); \
2416 VM_CALL_METHOD(, java_handle_t *)
2417 VM_CALL_METHOD(_int, int32_t)
2418 VM_CALL_METHOD(_long, int64_t)
2419 VM_CALL_METHOD(_float, float)
2420 VM_CALL_METHOD(_double, double)
2423 /* vm_call_method_valist *******************************************************
2425 Calls a Java method with a variable number of arguments, passed via
2428 *******************************************************************************/
2430 #define VM_CALL_METHOD_VALIST(name, type) \
2431 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2436 int32_t dumpmarker; \
2438 if (m->code == NULL) \
2439 if (!jit_compile(m)) \
2442 THREAD_NATIVEWORLD_EXIT; \
2445 array = argument_vmarray_from_valist(m, o, ap); \
2446 value = vm_call##name##_array(m, array); \
2449 THREAD_NATIVEWORLD_ENTER; \
2454 VM_CALL_METHOD_VALIST(, java_handle_t *)
2455 VM_CALL_METHOD_VALIST(_int, int32_t)
2456 VM_CALL_METHOD_VALIST(_long, int64_t)
2457 VM_CALL_METHOD_VALIST(_float, float)
2458 VM_CALL_METHOD_VALIST(_double, double)
2461 /* vm_call_method_jvalue *******************************************************
2463 Calls a Java method with a variable number of arguments, passed via
2466 *******************************************************************************/
2468 #define VM_CALL_METHOD_JVALUE(name, type) \
2469 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2470 const jvalue *args) \
2474 int32_t dumpmarker; \
2476 if (m->code == NULL) \
2477 if (!jit_compile(m)) \
2480 THREAD_NATIVEWORLD_EXIT; \
2483 array = argument_vmarray_from_jvalue(m, o, args); \
2484 value = vm_call##name##_array(m, array); \
2487 THREAD_NATIVEWORLD_ENTER; \
2492 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2493 VM_CALL_METHOD_JVALUE(_int, int32_t)
2494 VM_CALL_METHOD_JVALUE(_long, int64_t)
2495 VM_CALL_METHOD_JVALUE(_float, float)
2496 VM_CALL_METHOD_JVALUE(_double, double)
2499 /* vm_call_method_objectarray **************************************************
2501 Calls a Java method with a variable number if arguments, passed via
2502 an objectarray of boxed values. Returns a boxed value.
2504 *******************************************************************************/
2506 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2507 java_handle_objectarray_t *params)
2510 java_handle_t *xptr;
2515 /* Prevent compiler warnings. */
2519 /* compile methods which are not yet compiled */
2521 if (m->code == NULL)
2522 if (!jit_compile(m))
2525 /* leave the nativeworld */
2527 THREAD_NATIVEWORLD_EXIT;
2529 /* mark start of dump memory area */
2533 /* Fill the argument array from a object-array. */
2535 array = argument_vmarray_from_objectarray(m, o, params);
2537 if (array == NULL) {
2538 /* release dump area */
2542 /* enter the nativeworld again */
2544 THREAD_NATIVEWORLD_ENTER;
2546 exceptions_throw_illegalargumentexception();
2551 switch (m->parseddesc->returntype.decltype) {
2552 case PRIMITIVETYPE_VOID:
2553 value.a = vm_call_array(m, array);
2556 case PRIMITIVETYPE_BOOLEAN:
2557 case PRIMITIVETYPE_BYTE:
2558 case PRIMITIVETYPE_CHAR:
2559 case PRIMITIVETYPE_SHORT:
2560 case PRIMITIVETYPE_INT:
2561 value.i = vm_call_int_array(m, array);
2564 case PRIMITIVETYPE_LONG:
2565 value.l = vm_call_long_array(m, array);
2568 case PRIMITIVETYPE_FLOAT:
2569 value.f = vm_call_float_array(m, array);
2572 case PRIMITIVETYPE_DOUBLE:
2573 value.d = vm_call_double_array(m, array);
2577 ro = vm_call_array(m, array);
2581 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2584 /* release dump area */
2588 /* enter the nativeworld again */
2590 THREAD_NATIVEWORLD_ENTER;
2592 /* box the return value if necesarry */
2594 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2595 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2597 /* check for an exception */
2599 xptr = exceptions_get_exception();
2602 /* clear exception pointer, we are calling JIT code again */
2604 exceptions_clear_exception();
2606 exceptions_throw_invocationtargetexception(xptr);
2614 * These are local overrides for various environment variables in Emacs.
2615 * Please do not remove this and leave it at the end of the file, where
2616 * Emacs will automagically detect them.
2617 * ---------------------------------------------------------------------
2620 * indent-tabs-mode: t
2624 * vim:noexpandtab:sw=4:ts=4: