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();
1520 if (!builtin_init())
1521 vm_abort("vm_create: builtin_init failed");
1523 /* Initialize the native subsystem. */
1524 /* BEFORE: threads_init */
1527 vm_abort("vm_create: native_init failed");
1529 /* Register the native methods implemented in the VM. */
1530 /* BEFORE: threads_init */
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 /* Iinitialize some important system classes. */
1552 /* BEFORE: threads_init */
1556 #if defined(ENABLE_THREADS)
1560 /* Initialize the native VM subsystem. */
1561 /* AFTER: threads_init (at least for SUN's classes) */
1565 #if defined(ENABLE_PROFILING)
1566 /* initialize profiling */
1568 if (!profile_init())
1569 vm_abort("vm_create: profile_init failed");
1572 #if defined(ENABLE_THREADS)
1573 /* initialize recompilation */
1575 if (!recompile_init())
1576 vm_abort("vm_create: recompile_init failed");
1578 /* start the signal handler thread */
1580 #if defined(__LINUX__)
1581 /* XXX Remove for exact-GC. */
1582 if (threads_pthreads_implementation_nptl)
1584 if (!signal_start_thread())
1585 vm_abort("vm_create: signal_start_thread failed");
1587 /* finally, start the finalizer thread */
1589 if (!finalizer_start_thread())
1590 vm_abort("vm_create: finalizer_start_thread failed");
1592 # if !defined(NDEBUG)
1593 /* start the memory profiling thread */
1595 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1596 if (!memory_start_thread())
1597 vm_abort("vm_create: memory_start_thread failed");
1600 /* start the recompilation thread (must be done before the
1601 profiling thread) */
1603 if (!recompile_start_thread())
1604 vm_abort("vm_create: recompile_start_thread failed");
1606 # if defined(ENABLE_PROFILING)
1607 /* start the profile sampling thread */
1610 /* if (!profile_start_thread()) */
1611 /* vm_abort("vm_create: profile_start_thread failed"); */
1615 #if defined(ENABLE_JVMTI)
1616 # if defined(ENABLE_GC_CACAO)
1617 /* XXX this will not work with the new indirection cells for classloaders!!! */
1621 /* add agent library to native library hashtable */
1622 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1626 /* Increment the number of VMs. */
1630 /* Initialization is done, VM is created.. */
1633 vm_initializing = false;
1635 /* Print the VM configuration after all stuff is set and the VM is
1638 if (opt_PrintConfig)
1641 /* everything's ok */
1647 /* vm_run **********************************************************************
1649 Runs the main-method of the passed class.
1651 *******************************************************************************/
1653 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1656 classinfo *mainclass;
1659 java_handle_objectarray_t *oa;
1667 #if !defined(NDEBUG)
1673 if (opt_method != NULL) {
1674 vm_compile_method();
1677 #endif /* !defined(NDEBUG) */
1679 /* should we run the main-method? */
1681 if (mainstring == NULL)
1684 /* set return value to OK */
1688 if (opt_jar == true) {
1689 /* open jar file with java.util.jar.JarFile */
1691 mainstring = vm_get_mainclass_from_jar(mainstring);
1693 if (mainstring == NULL)
1697 /* load the main class */
1699 mainutf = utf_new_char(mainstring);
1701 #if defined(ENABLE_JAVAME_CLDC1_1)
1702 mainclass = load_class_bootstrap(mainutf);
1704 mainclass = load_class_from_sysloader(mainutf);
1707 /* error loading class */
1709 e = exceptions_get_and_clear_exception();
1711 if ((e != NULL) || (mainclass == NULL)) {
1712 exceptions_throw_noclassdeffounderror_cause(e);
1713 exceptions_print_stacktrace();
1717 if (!link_class(mainclass)) {
1718 exceptions_print_stacktrace();
1722 /* find the `main' method of the main class */
1724 m = class_resolveclassmethod(mainclass,
1725 utf_new_char("main"),
1726 utf_new_char("([Ljava/lang/String;)V"),
1727 class_java_lang_Object,
1730 if (exceptions_get_exception()) {
1731 exceptions_print_stacktrace();
1735 /* there is no main method or it isn't static */
1737 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1738 exceptions_clear_exception();
1739 exceptions_throw_nosuchmethoderror(mainclass,
1740 utf_new_char("main"),
1741 utf_new_char("([Ljava/lang/String;)V"));
1743 exceptions_print_stacktrace();
1747 /* build argument array */
1749 oalength = vm_args->nOptions - opt_index;
1751 oa = builtin_anewarray(oalength, class_java_lang_String);
1753 for (i = 0; i < oalength; i++) {
1754 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1755 s = javastring_new(u);
1757 array_objectarray_element_set(oa, i, s);
1760 #ifdef TYPEINFO_DEBUG_TEST
1761 /* test the typeinfo system */
1764 /*class_showmethods(currentThread->group->header.vftbl->class); */
1766 #if defined(ENABLE_JVMTI)
1767 jvmti_set_phase(JVMTI_PHASE_LIVE);
1770 /* set ThreadMXBean variables */
1772 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1773 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1775 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1776 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1777 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1778 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1780 /* start the main thread */
1782 (void) vm_call_method(m, NULL, oa);
1784 /* exception occurred? */
1786 if (exceptions_get_exception()) {
1787 exceptions_print_stacktrace();
1791 /* Detach the main thread so that it appears to have ended when
1792 the application's main method exits. */
1794 t = thread_get_current();
1796 if (!threads_detach_thread(t))
1797 vm_abort("vm_run: Could not detach main thread.");
1799 /* Destroy the JavaVM. */
1801 (void) vm_destroy(vm);
1809 /* vm_destroy ******************************************************************
1811 Unloads a Java VM and reclaims its resources.
1813 *******************************************************************************/
1815 int vm_destroy(JavaVM *vm)
1817 #if defined(ENABLE_THREADS)
1818 /* Create a a trivial new Java waiter thread called
1821 JavaVMAttachArgs args;
1823 args.name = "DestroyJavaVM";
1826 if (!threads_attach_current_thread(&args, false))
1829 /* Wait until we are the last non-daemon thread. */
1831 threads_join_all_threads();
1838 /* Everything is ok. */
1844 /* vm_exit *********************************************************************
1846 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1848 *******************************************************************************/
1850 void vm_exit(s4 status)
1854 /* signal that we are exiting */
1858 assert(class_java_lang_System);
1859 assert(class_java_lang_System->state & CLASS_LOADED);
1861 #if defined(ENABLE_JVMTI)
1862 if (jvmti || (dbgcom!=NULL)) {
1863 jvmti_set_phase(JVMTI_PHASE_DEAD);
1864 if (jvmti) jvmti_agentunload();
1868 if (!link_class(class_java_lang_System)) {
1869 exceptions_print_stacktrace();
1873 /* call java.lang.System.exit(I)V */
1875 m = class_resolveclassmethod(class_java_lang_System,
1876 utf_new_char("exit"),
1878 class_java_lang_Object,
1882 exceptions_print_stacktrace();
1886 /* call the exit function with passed exit status */
1888 (void) vm_call_method(m, NULL, status);
1890 /* If we had an exception, just ignore the exception and exit with
1893 vm_shutdown(status);
1897 /* vm_shutdown *****************************************************************
1899 Terminates the system immediately without freeing memory explicitly
1900 (to be used only for abnormal termination).
1902 *******************************************************************************/
1904 void vm_shutdown(s4 status)
1907 #if defined(ENABLE_STATISTICS)
1908 || opt_getcompilingtime || opt_stat
1912 log_text("CACAO terminated by shutdown");
1913 dolog("Exit status: %d\n", (s4) status);
1917 #if defined(ENABLE_JVMTI)
1918 /* terminate cacaodbgserver */
1920 pthread_mutex_lock(&dbgcomlock);
1922 pthread_mutex_unlock(&dbgcomlock);
1923 jvmti_cacaodbgserver_quit();
1931 /* vm_exit_handler *************************************************************
1933 The exit_handler function is called upon program termination.
1935 ATTENTION: Don't free system resources here! Some threads may still
1936 be running as this is called from VMRuntime.exit(). The OS does the
1939 *******************************************************************************/
1941 void vm_exit_handler(void)
1943 #if !defined(NDEBUG)
1945 class_showmethods(mainclass);
1947 if (showconstantpool)
1948 class_showconstantpool(mainclass);
1953 # if defined(ENABLE_PROFILING)
1955 profile_printstats();
1957 #endif /* !defined(NDEBUG) */
1959 #if defined(ENABLE_RT_TIMING)
1960 rt_timing_print_time_stats(stderr);
1963 #if defined(ENABLE_CYCLES_STATS)
1964 builtin_print_cycles_stats(stderr);
1965 stacktrace_print_cycles_stats(stderr);
1969 #if defined(ENABLE_STATISTICS)
1970 || opt_getcompilingtime || opt_stat
1974 log_text("CACAO terminated");
1976 #if defined(ENABLE_STATISTICS)
1979 #ifdef TYPECHECK_STATISTICS
1980 typecheck_print_statistics(get_logfile());
1984 if (opt_getcompilingtime)
1986 #endif /* defined(ENABLE_STATISTICS) */
1988 /* vm_print_profile(stderr);*/
1992 /* vm_abort ********************************************************************
1994 Prints an error message and aborts the VM.
1997 text ... error message to print
1999 *******************************************************************************/
2001 void vm_abort(const char *text, ...)
2005 /* Print the log message. */
2010 log_vprint(text, ap);
2015 /* Now abort the VM. */
2021 /* vm_abort_errnum *************************************************************
2023 Prints an error message, appends ":" plus the strerror-message of
2024 errnum and aborts the VM.
2027 errnum ... error number
2028 text ..... error message to print
2030 *******************************************************************************/
2032 void vm_abort_errnum(int errnum, const char *text, ...)
2036 /* Print the log message. */
2041 log_vprint(text, ap);
2044 /* Print the strerror-message of errnum. */
2046 log_print(": %s", system_strerror(errnum));
2050 /* Now abort the VM. */
2056 /* vm_abort_errno **************************************************************
2058 Equal to vm_abort_errnum, but uses errno to get the error number.
2061 text ... error message to print
2063 *******************************************************************************/
2065 void vm_abort_errno(const char *text, ...)
2070 vm_abort_errnum(errno, text, ap);
2075 /* vm_abort_disassemble ********************************************************
2077 Prints an error message, disassemble the given code range (if
2078 enabled) and aborts the VM.
2081 pc.......PC to disassemble
2082 count....number of instructions to disassemble
2084 *******************************************************************************/
2086 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2089 #if defined(ENABLE_DISASSEMBLER)
2093 /* Print debug message. */
2098 log_vprint(text, ap);
2105 #if SIZEOF_VOID_P == 8
2106 log_println("PC=0x%016lx", pc);
2108 log_println("PC=0x%08x", pc);
2111 #if defined(ENABLE_DISASSEMBLER)
2112 log_println("machine instructions at PC:");
2114 /* Disassemble the given number of instructions. */
2116 for (i = 0; i < count; i++)
2117 pc = disassinstr(pc);
2120 vm_abort("Aborting...");
2124 /* vm_get_mainclass_from_jar ***************************************************
2126 Gets the name of the main class from a JAR's manifest file.
2128 *******************************************************************************/
2130 static char *vm_get_mainclass_from_jar(char *mainstring)
2137 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2140 exceptions_print_stacktrace();
2144 /* create JarFile object */
2149 exceptions_print_stacktrace();
2153 m = class_resolveclassmethod(c,
2155 utf_java_lang_String__void,
2156 class_java_lang_Object,
2160 exceptions_print_stacktrace();
2164 s = javastring_new_from_ascii(mainstring);
2166 (void) vm_call_method(m, o, s);
2168 if (exceptions_get_exception()) {
2169 exceptions_print_stacktrace();
2173 /* get manifest object */
2175 m = class_resolveclassmethod(c,
2176 utf_new_char("getManifest"),
2177 utf_new_char("()Ljava/util/jar/Manifest;"),
2178 class_java_lang_Object,
2182 exceptions_print_stacktrace();
2186 o = vm_call_method(m, o);
2189 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2194 /* get Main Attributes */
2196 LLNI_class_get(o, c);
2198 m = class_resolveclassmethod(c,
2199 utf_new_char("getMainAttributes"),
2200 utf_new_char("()Ljava/util/jar/Attributes;"),
2201 class_java_lang_Object,
2205 exceptions_print_stacktrace();
2209 o = vm_call_method(m, o);
2212 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2217 /* get property Main-Class */
2219 LLNI_class_get(o, c);
2221 m = class_resolveclassmethod(c,
2222 utf_new_char("getValue"),
2223 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2224 class_java_lang_Object,
2228 exceptions_print_stacktrace();
2232 s = javastring_new_from_ascii("Main-Class");
2234 o = vm_call_method(m, o, s);
2237 exceptions_print_stacktrace();
2241 return javastring_tochar(o);
2245 /* vm_compile_all **************************************************************
2247 Compile all methods found in the bootclasspath.
2249 *******************************************************************************/
2251 #if !defined(NDEBUG)
2252 static void vm_compile_all(void)
2257 classcache_name_entry *nmen;
2258 classcache_class_entry *clsen;
2261 /* create all classes found in the bootclasspath */
2262 /* XXX currently only works with zip/jar's */
2264 loader_load_all_classes();
2266 /* link all classes */
2268 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2269 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2271 for (; nmen; nmen = nmen->hashlink) {
2272 /* iterate over all class entries */
2274 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2275 c = clsen->classobj;
2280 if (!(c->state & CLASS_LINKED)) {
2281 if (!link_class(c)) {
2282 fprintf(stderr, "Error linking: ");
2283 utf_fprint_printable_ascii_classname(stderr, c->name);
2284 fprintf(stderr, "\n");
2286 /* print out exception and cause */
2288 exceptions_print_current_exception();
2290 /* goto next class */
2296 /* compile all class methods */
2298 for (i = 0; i < c->methodscount; i++) {
2299 m = &(c->methods[i]);
2301 if (m->jcode != NULL) {
2302 if (!jit_compile(m)) {
2303 fprintf(stderr, "Error compiling: ");
2304 utf_fprint_printable_ascii_classname(stderr, c->name);
2305 fprintf(stderr, ".");
2306 utf_fprint_printable_ascii(stderr, m->name);
2307 utf_fprint_printable_ascii(stderr, m->descriptor);
2308 fprintf(stderr, "\n");
2310 /* print out exception and cause */
2312 exceptions_print_current_exception();
2320 #endif /* !defined(NDEBUG) */
2323 /* vm_compile_method ***********************************************************
2325 Compile a specific method.
2327 *******************************************************************************/
2329 #if !defined(NDEBUG)
2330 static void vm_compile_method(void)
2334 /* create, load and link the main class */
2336 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2338 if (mainclass == NULL)
2339 exceptions_print_stacktrace();
2341 if (!link_class(mainclass))
2342 exceptions_print_stacktrace();
2344 if (opt_signature != NULL) {
2345 m = class_resolveclassmethod(mainclass,
2346 utf_new_char(opt_method),
2347 utf_new_char(opt_signature),
2352 m = class_resolveclassmethod(mainclass,
2353 utf_new_char(opt_method),
2360 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2361 opt_method, opt_signature ? opt_signature : "");
2365 #endif /* !defined(NDEBUG) */
2368 /* vm_call_array ***************************************************************
2370 Calls a Java method with a variable number of arguments, passed via
2373 ATTENTION: This function has to be used outside the nativeworld.
2375 *******************************************************************************/
2377 #define VM_CALL_ARRAY(name, type) \
2378 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2384 assert(m->code != NULL); \
2386 md = m->parseddesc; \
2387 pv = m->code->entrypoint; \
2389 STATISTICS(count_calls_native_to_java++); \
2391 value = asm_vm_call_method##name(pv, array, md->memuse); \
2396 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2402 assert(m->code != NULL);
2405 pv = m->code->entrypoint;
2407 STATISTICS(count_calls_native_to_java++);
2409 o = asm_vm_call_method(pv, array, md->memuse);
2411 if (md->returntype.type == TYPE_VOID)
2414 return LLNI_WRAP(o);
2417 VM_CALL_ARRAY(_int, int32_t)
2418 VM_CALL_ARRAY(_long, int64_t)
2419 VM_CALL_ARRAY(_float, float)
2420 VM_CALL_ARRAY(_double, double)
2423 /* vm_call_method **************************************************************
2425 Calls a Java method with a variable number of arguments.
2427 *******************************************************************************/
2429 #define VM_CALL_METHOD(name, type) \
2430 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2436 value = vm_call_method##name##_valist(m, o, ap); \
2442 VM_CALL_METHOD(, java_handle_t *)
2443 VM_CALL_METHOD(_int, int32_t)
2444 VM_CALL_METHOD(_long, int64_t)
2445 VM_CALL_METHOD(_float, float)
2446 VM_CALL_METHOD(_double, double)
2449 /* vm_call_method_valist *******************************************************
2451 Calls a Java method with a variable number of arguments, passed via
2454 *******************************************************************************/
2456 #define VM_CALL_METHOD_VALIST(name, type) \
2457 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2462 int32_t dumpmarker; \
2464 if (m->code == NULL) \
2465 if (!jit_compile(m)) \
2468 THREAD_NATIVEWORLD_EXIT; \
2471 array = argument_vmarray_from_valist(m, o, ap); \
2472 value = vm_call##name##_array(m, array); \
2475 THREAD_NATIVEWORLD_ENTER; \
2480 VM_CALL_METHOD_VALIST(, java_handle_t *)
2481 VM_CALL_METHOD_VALIST(_int, int32_t)
2482 VM_CALL_METHOD_VALIST(_long, int64_t)
2483 VM_CALL_METHOD_VALIST(_float, float)
2484 VM_CALL_METHOD_VALIST(_double, double)
2487 /* vm_call_method_jvalue *******************************************************
2489 Calls a Java method with a variable number of arguments, passed via
2492 *******************************************************************************/
2494 #define VM_CALL_METHOD_JVALUE(name, type) \
2495 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2496 const jvalue *args) \
2500 int32_t dumpmarker; \
2502 if (m->code == NULL) \
2503 if (!jit_compile(m)) \
2506 THREAD_NATIVEWORLD_EXIT; \
2509 array = argument_vmarray_from_jvalue(m, o, args); \
2510 value = vm_call##name##_array(m, array); \
2513 THREAD_NATIVEWORLD_ENTER; \
2518 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2519 VM_CALL_METHOD_JVALUE(_int, int32_t)
2520 VM_CALL_METHOD_JVALUE(_long, int64_t)
2521 VM_CALL_METHOD_JVALUE(_float, float)
2522 VM_CALL_METHOD_JVALUE(_double, double)
2525 /* vm_call_method_objectarray **************************************************
2527 Calls a Java method with a variable number if arguments, passed via
2528 an objectarray of boxed values. Returns a boxed value.
2530 *******************************************************************************/
2532 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2533 java_handle_objectarray_t *params)
2536 java_handle_t *xptr;
2541 /* Prevent compiler warnings. */
2545 /* compile methods which are not yet compiled */
2547 if (m->code == NULL)
2548 if (!jit_compile(m))
2551 /* leave the nativeworld */
2553 THREAD_NATIVEWORLD_EXIT;
2555 /* mark start of dump memory area */
2559 /* Fill the argument array from a object-array. */
2561 array = argument_vmarray_from_objectarray(m, o, params);
2563 if (array == NULL) {
2564 /* release dump area */
2568 /* enter the nativeworld again */
2570 THREAD_NATIVEWORLD_ENTER;
2572 exceptions_throw_illegalargumentexception();
2577 switch (m->parseddesc->returntype.decltype) {
2578 case PRIMITIVETYPE_VOID:
2579 value.a = vm_call_array(m, array);
2582 case PRIMITIVETYPE_BOOLEAN:
2583 case PRIMITIVETYPE_BYTE:
2584 case PRIMITIVETYPE_CHAR:
2585 case PRIMITIVETYPE_SHORT:
2586 case PRIMITIVETYPE_INT:
2587 value.i = vm_call_int_array(m, array);
2590 case PRIMITIVETYPE_LONG:
2591 value.l = vm_call_long_array(m, array);
2594 case PRIMITIVETYPE_FLOAT:
2595 value.f = vm_call_float_array(m, array);
2598 case PRIMITIVETYPE_DOUBLE:
2599 value.d = vm_call_double_array(m, array);
2603 ro = vm_call_array(m, array);
2607 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2610 /* release dump area */
2614 /* enter the nativeworld again */
2616 THREAD_NATIVEWORLD_ENTER;
2618 /* box the return value if necesarry */
2620 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2621 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2623 /* check for an exception */
2625 xptr = exceptions_get_exception();
2628 /* clear exception pointer, we are calling JIT code again */
2630 exceptions_clear_exception();
2632 exceptions_throw_invocationtargetexception(xptr);
2640 * These are local overrides for various environment variables in Emacs.
2641 * Please do not remove this and leave it at the end of the file, where
2642 * Emacs will automagically detect them.
2643 * ---------------------------------------------------------------------
2646 * indent-tabs-mode: t
2650 * vim:noexpandtab:sw=4:ts=4: