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/threads-common.h"
63 #include "toolbox/logging.h"
67 #if defined(ENABLE_ASSERTION)
68 #include "vm/assertion.h"
71 #include "vm/builtin.h"
72 #include "vm/exceptions.h"
73 #include "vm/finalizer.h"
74 #include "vm/global.h"
75 #include "vm/initialize.h"
76 #include "vm/package.h"
77 #include "vm/primitive.h"
78 #include "vm/properties.h"
79 #include "vm/signallocal.h"
80 #include "vm/stringlocal.h"
83 #include "vm/jit/argument.h"
84 #include "vm/jit/asmpart.h"
86 #if defined(ENABLE_DISASSEMBLER)
87 # include "vm/jit/disass.h"
90 #include "vm/jit/jit.h"
92 #if defined(ENABLE_PROFILING)
93 # include "vm/jit/optimizing/profile.h"
96 #include "vm/jit/optimizing/recompile.h"
98 #if defined(ENABLE_PYTHON)
99 # include "vm/jit/python.h"
102 #include "vmcore/classcache.h"
103 #include "vmcore/options.h"
104 #include "vmcore/statistics.h"
105 #include "vmcore/suck.h"
107 #if defined(ENABLE_JVMTI)
108 # include "native/jvmti/cacaodbg.h"
111 #if defined(ENABLE_VMLOG)
112 #include <vmlog_cacao.h>
116 /* Invocation API variables ***************************************************/
118 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
119 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
122 /* global variables ***********************************************************/
124 s4 vms = 0; /* number of VMs created */
126 bool vm_initializing = false;
127 bool vm_exiting = false;
129 char *mainstring = NULL;
130 classinfo *mainclass = NULL;
132 #if defined(ENABLE_INTRP)
133 u1 *intrp_main_stack = NULL;
137 /* define heap sizes **********************************************************/
139 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
140 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
141 #define STACK_SIZE 128 * 1024 /* default 64kB */
144 /* define command line options ************************************************/
178 /* Java non-standard options */
189 #if defined(ENABLE_PROFILING)
202 #if defined(ENABLE_STATISTICS)
219 #if defined(ENABLE_VERIFIER)
221 #if defined(TYPECHECK_VERBOSE)
224 #endif /* defined(ENABLE_VERIFIER) */
226 /* optimization options */
228 #if defined(ENABLE_LOOP)
232 #if defined(ENABLE_IFCONV)
236 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
240 #if defined(ENABLE_INLINING)
245 #if defined(ENABLE_INLINING_DEBUG)
246 OPT_INLINE_DEBUG_ALL,
247 OPT_INLINE_DEBUG_END,
248 OPT_INLINE_DEBUG_MIN,
249 OPT_INLINE_DEBUG_MAX,
250 #endif /* defined(ENABLE_INLINING_DEBUG) */
251 #endif /* defined(ENABLE_INLINING) */
253 #if defined(ENABLE_INTRP)
254 /* interpreter options */
273 #if defined(ENABLE_DEBUG_FILTER)
274 OPT_FILTER_VERBOSECALL_INCLUDE,
275 OPT_FILTER_VERBOSECALL_EXCLUDE,
276 OPT_FILTER_SHOW_METHOD,
283 opt_struct opts[] = {
284 { "foo", false, OPT_FOO },
288 { "jar", false, OPT_JAR },
290 { "d32", false, OPT_D32 },
291 { "d64", false, OPT_D64 },
292 { "client", false, OPT_IGNORE },
293 { "server", false, OPT_IGNORE },
294 { "jvm", false, OPT_IGNORE },
295 { "hotspot", false, OPT_IGNORE },
297 { "classpath", true, OPT_CLASSPATH },
298 { "cp", true, OPT_CLASSPATH },
299 { "D", true, OPT_D },
300 { "version", false, OPT_VERSION },
301 { "showversion", false, OPT_SHOWVERSION },
302 { "fullversion", false, OPT_FULLVERSION },
303 { "help", false, OPT_HELP },
304 { "?", false, OPT_HELP },
305 { "X", false, OPT_X },
306 { "XX:", true, OPT_XX },
308 { "ea:", true, OPT_EA },
309 { "da:", true, OPT_DA },
310 { "ea", false, OPT_EA_NOARG },
311 { "da", false, OPT_DA_NOARG },
313 { "enableassertions:", true, OPT_EA },
314 { "disableassertions:", true, OPT_DA },
315 { "enableassertions", false, OPT_EA_NOARG },
316 { "disableassertions", false, OPT_DA_NOARG },
318 { "esa", false, OPT_ESA },
319 { "enablesystemassertions", false, OPT_ESA },
320 { "dsa", false, OPT_DSA },
321 { "disablesystemassertions", false, OPT_DSA },
323 { "noasyncgc", false, OPT_IGNORE },
324 #if defined(ENABLE_VERIFIER)
325 { "noverify", false, OPT_NOVERIFY },
326 { "Xverify:none", false, OPT_NOVERIFY },
328 { "v", false, OPT_VERBOSE1 },
329 { "verbose:", true, OPT_VERBOSE },
331 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
332 { "verbosetc", false, OPT_VERBOSETC },
334 #if defined(__ALPHA__)
335 { "noieee", false, OPT_NOIEEE },
337 #if defined(ENABLE_STATISTICS)
338 { "time", false, OPT_TIME },
339 { "stat", false, OPT_STAT },
341 { "log", true, OPT_LOG },
342 { "c", true, OPT_CHECK },
343 { "l", false, OPT_LOAD },
346 { "all", false, OPT_ALL },
347 { "sig", true, OPT_SIGNATURE },
350 #if defined(ENABLE_LOOP)
351 { "oloop", false, OPT_OLOOP },
353 #if defined(ENABLE_IFCONV)
354 { "ifconv", false, OPT_IFCONV },
356 #if defined(ENABLE_LSRA)
357 { "lsra", false, OPT_LSRA },
359 #if defined(ENABLE_SSA)
360 { "lsra", true, OPT_LSRA },
363 #if defined(ENABLE_INTRP)
364 /* interpreter options */
366 { "trace", false, OPT_TRACE },
367 { "static-supers", true, OPT_STATIC_SUPERS },
368 { "no-dynamic", false, OPT_NO_DYNAMIC },
369 { "no-replication", false, OPT_NO_REPLICATION },
370 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
373 /* JVMTI Agent Command Line Options */
375 { "agentlib:", true, OPT_AGENTLIB },
376 { "agentpath:", true, OPT_AGENTPATH },
379 /* Java non-standard options */
381 { "Xjit", false, OPT_JIT },
382 { "Xint", false, OPT_INTRP },
383 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
384 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
385 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
386 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
389 { "Xdebug", false, OPT_DEBUG },
390 { "Xnoagent", false, OPT_NOAGENT },
391 { "Xrunjdwp", true, OPT_XRUNJDWP },
394 { "Xms", true, OPT_MS },
395 { "ms", true, OPT_MS },
396 { "Xmx", true, OPT_MX },
397 { "mx", true, OPT_MX },
398 { "Xss", true, OPT_SS },
399 { "ss", true, OPT_SS },
401 #if defined(ENABLE_PROFILING)
402 { "Xprof:", true, OPT_PROF_OPTION },
403 { "Xprof", false, OPT_PROF },
406 /* inlining options */
408 #if defined(ENABLE_INLINING)
409 #if defined(ENABLE_INLINING_DEBUG)
410 { "ia", false, OPT_INLINE_DEBUG_ALL },
411 { "ii", true, OPT_INLINE_DEBUG_MIN },
412 { "im", true, OPT_INLINE_DEBUG_MAX },
413 { "ie", true, OPT_INLINE_DEBUG_END },
414 #endif /* defined(ENABLE_INLINING_DEBUG) */
416 { "il", false, OPT_INLINE_LOG },
418 { "i", false, OPT_INLINING },
419 #endif /* defined(ENABLE_INLINING) */
421 /* keep these at the end of the list */
424 { "m", true, OPT_METHOD },
427 { "s", true, OPT_SHOW },
428 { "debug-color", false, OPT_DEBUGCOLOR },
430 #if defined(ENABLE_DEBUG_FILTER)
431 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
432 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
433 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
440 /* usage ***********************************************************************
442 Prints the correct usage syntax to stdout.
444 *******************************************************************************/
448 puts("Usage: cacao [-options] classname [arguments]");
449 puts(" (to run a class file)");
450 puts(" or cacao [-options] -jar jarfile [arguments]");
451 puts(" (to run a standalone jar file)\n");
453 puts("where options include:");
454 puts(" -d32 use 32-bit data model if available");
455 puts(" -d64 use 64-bit data model if available");
456 puts(" -client compatibility (currently ignored)");
457 puts(" -server compatibility (currently ignored)");
458 puts(" -jvm compatibility (currently ignored)");
459 puts(" -hotspot compatibility (currently ignored)\n");
461 puts(" -cp <path> specify a path to look for classes");
462 puts(" -classpath <path> specify a path to look for classes");
463 puts(" -D<name>=<value> add an entry to the property list");
464 puts(" -verbose[:class|gc|jni] enable specific verbose output");
465 puts(" -version print product version and exit");
466 puts(" -fullversion print jpackage-compatible product version and exit");
467 puts(" -showversion print product version and continue");
468 puts(" -help, -? print this help message");
469 puts(" -X print help on non-standard Java options");
470 puts(" -XX print help on debugging options");
471 puts(" -ea[:<packagename>...|:<classname>]");
472 puts(" -enableassertions[:<packagename>...|:<classname>]");
473 puts(" enable assertions with specified granularity");
474 puts(" -da[:<packagename>...|:<classname>]");
475 puts(" -disableassertions[:<packagename>...|:<classname>]");
476 puts(" disable assertions with specified granularity");
477 puts(" -esa | -enablesystemassertions");
478 puts(" enable system assertions");
479 puts(" -dsa | -disablesystemassertions");
480 puts(" disable system assertions");
483 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
484 puts (" for jdwp help use: -agentlib:jdwp=help");
485 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
488 /* exit with error code */
494 static void Xusage(void)
496 #if defined(ENABLE_JIT)
497 puts(" -Xjit JIT mode execution (default)");
499 #if defined(ENABLE_INTRP)
500 puts(" -Xint interpreter mode execution");
502 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
503 puts(" value is set as bootstrap class path");
504 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
505 puts(" value is appended to the bootstrap class path");
506 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
507 puts(" value is prepended to the bootstrap class path");
508 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
509 puts(" value is used as Java core library, but the");
510 puts(" hardcoded VM interface classes are prepended");
511 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
512 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
513 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
515 #if defined(ENABLE_PROFILING)
516 puts(" -Xprof[:bb] collect and print profiling data");
519 #if defined(ENABLE_JVMTI)
520 /* -Xdebug option depend on gnu classpath JDWP options. options:
521 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
522 puts(" -Xdebug enable remote debugging\n");
523 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
524 puts(" enable remote debugging\n");
527 /* exit with error code */
534 static void XXusage(void)
536 puts(" -v write state-information");
538 puts(" -verbose:jit enable specific verbose output");
539 puts(" -debug-color colored output for ANSI terms");
541 #ifdef TYPECHECK_VERBOSE
542 puts(" -verbosetc write debug messages while typechecking");
544 #if defined(__ALPHA__)
545 puts(" -noieee don't use ieee compliant arithmetic");
547 #if defined(ENABLE_VERIFIER)
548 puts(" -noverify don't verify classfiles");
550 #if defined(ENABLE_STATISTICS)
551 puts(" -time measure the runtime");
552 puts(" -stat detailed compiler statistics");
554 puts(" -log logfile specify a name for the logfile");
555 puts(" -c(heck)b(ounds) don't check array bounds");
556 puts(" s(ync) don't check for synchronization");
557 #if defined(ENABLE_LOOP)
558 puts(" -oloop optimize array accesses in loops");
560 puts(" -l don't start the class after loading");
562 puts(" -all compile all methods, no execution");
563 puts(" -m compile only a specific method");
564 puts(" -sig specify signature for a specific method");
567 puts(" -s... show...");
568 puts(" (c)onstants the constant pool");
569 puts(" (m)ethods class fields and methods");
570 puts(" (u)tf the utf - hash");
571 puts(" (i)ntermediate intermediate representation");
572 #if defined(ENABLE_DISASSEMBLER)
573 puts(" (a)ssembler disassembled listing");
574 puts(" n(o)ps show NOPs in disassembler output");
576 puts(" (d)atasegment data segment listing");
578 #if defined(ENABLE_INLINING)
579 puts(" -i activate inlining");
581 puts(" -il log inlining");
583 #if defined(ENABLE_INLINING_DEBUG)
584 puts(" -ia use inlining for all methods");
585 puts(" -ii <size> set minimum size for inlined result");
586 puts(" -im <size> set maximum size for inlined result");
587 puts(" -ie <number> stop inlining after the given number of roots");
588 #endif /* defined(ENABLE_INLINING_DEBUG) */
589 #endif /* defined(ENABLE_INLINING) */
591 #if defined(ENABLE_IFCONV)
592 puts(" -ifconv use if-conversion");
594 #if defined(ENABLE_LSRA)
595 puts(" -lsra use linear scan register allocation");
597 #if defined(ENABLE_SSA)
598 puts(" -lsra:... use linear scan register allocation (with SSA)");
599 puts(" (d)ead code elimination");
600 puts(" (c)opy propagation");
602 #if defined(ENABLE_DEBUG_FILTER)
603 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
604 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
605 puts(" -XXfm <regex> filter for show options");
607 /* exit with error code */
614 /* version *********************************************************************
616 Only prints cacao version information.
618 *******************************************************************************/
620 static void version(bool opt_exit)
622 puts("java version \""JAVA_VERSION"\"");
623 puts("CACAO version "VERSION"\n");
625 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
626 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
627 puts("This is free software; see the source for copying conditions. There is NO");
628 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
630 /* exit normally, if requested */
637 /* fullversion *****************************************************************
639 Prints a Sun compatible version information (required e.g. by
640 jpackage, www.jpackage.org).
642 *******************************************************************************/
644 static void fullversion(void)
646 puts("java full version \"cacao-"JAVA_VERSION"\"");
654 static void vm_printconfig(void)
656 puts("Configure/Build options:\n");
657 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
658 #if defined(__VERSION__)
659 puts(" CC : "VERSION_CC" ("__VERSION__")");
661 puts(" CC : "VERSION_CC"");
663 puts(" CFLAGS : "VERSION_CFLAGS"\n");
665 puts("Default variables:\n");
666 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
667 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
668 printf(" stack size : %d\n", STACK_SIZE);
670 #if defined(WITH_JRE_LAYOUT)
671 /* When we're building with JRE-layout, the default paths are the
672 same as the runtime paths. */
674 # if defined(WITH_CLASSPATH_GNU)
675 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
676 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
677 # elif defined(WITH_CLASSPATH_SUN)
678 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
679 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
685 puts("Runtime variables:\n");
686 printf(" maximum heap size : %d\n", opt_heapmaxsize);
687 printf(" initial heap size : %d\n", opt_heapstartsize);
688 printf(" stack size : %d\n", opt_stacksize);
690 #if defined(WITH_CLASSPATH_GNU)
691 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
692 #elif defined(WITH_CLASSPATH_SUN)
693 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
696 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
697 printf(" java.class.path : %s\n", properties_get("java.class.path"));
701 /* forward declarations *******************************************************/
703 static char *vm_get_mainclass_from_jar(char *mainstring);
705 static void vm_compile_all(void);
706 static void vm_compile_method(void);
710 /* vm_createjvm ****************************************************************
712 Implementation for JNI_CreateJavaVM.
714 *******************************************************************************/
716 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
718 JavaVMInitArgs *_vm_args;
722 /* get the arguments for the new JVM */
724 _vm_args = (JavaVMInitArgs *) vm_args;
726 /* get the VM and Env tables (must be set before vm_create) */
728 env = NEW(_Jv_JNIEnv);
730 #if defined(ENABLE_JNI)
731 env->env = &_Jv_JNINativeInterface;
734 /* XXX Set the global variable. Maybe we should do that differently. */
738 /* create and fill a JavaVM structure */
740 vm = NEW(_Jv_JavaVM);
742 #if defined(ENABLE_JNI)
743 vm->functions = &_Jv_JNIInvokeInterface;
746 /* XXX Set the global variable. Maybe we should do that differently. */
747 /* XXX JVMTI Agents needs a JavaVM */
751 /* actually create the JVM */
753 if (!vm_create(_vm_args))
756 /* now return the values */
758 *p_vm = (JavaVM *) vm;
759 *p_env = (void *) env;
764 /* release allocated memory */
766 FREE(env, _Jv_JNIEnv);
767 FREE(vm, _Jv_JavaVM);
773 /* vm_create *******************************************************************
775 Creates a JVM. Called by vm_createjvm.
777 *******************************************************************************/
779 bool vm_create(JavaVMInitArgs *vm_args)
783 char *boot_class_path;
790 #if defined(ENABLE_JVMTI)
792 char *libname, *agentarg;
793 bool jdwp,agentbypath;
794 jdwp = agentbypath = false;
797 #if defined(ENABLE_VMLOG)
798 vmlog_cacao_init(vm_args);
801 #if defined(ENABLE_JNI)
802 /* Check the JNI version requested. */
804 if (!jni_version_check(vm_args->version))
808 /* We only support 1 JVM instance. */
813 /* Install the exit handler. */
815 if (atexit(vm_exit_handler))
816 vm_abort("atexit failed: %s\n", strerror(errno));
818 /* Set some options. */
825 opt_heapmaxsize = HEAP_MAXSIZE;
826 opt_heapstartsize = HEAP_STARTSIZE;
827 opt_stacksize = STACK_SIZE;
829 /* Initialize the properties list before command-line handling.
830 Otherwise -XX:+PrintConfig crashes. */
834 /* First of all, parse the -XX options. */
838 /* We need to check if the actual size of a java.lang.Class object
839 is smaller or equal than the assumption made in
840 src/vmcore/class.h. */
842 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
843 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
845 /* set the VM starttime */
847 _Jv_jvm->starttime = builtin_currenttimemillis();
849 #if defined(ENABLE_JVMTI)
850 /* initialize JVMTI related **********************************************/
854 /* Fill the properties before command-line handling. */
858 /* iterate over all passed options */
860 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
874 #if SIZEOF_VOID_P == 8
875 puts("Running a 32-bit JVM is not supported on this platform.");
881 #if SIZEOF_VOID_P == 4
882 puts("Running a 64-bit JVM is not supported on this platform.");
888 /* Forget old classpath and set the argument as new
891 class_path = properties_get("java.class.path");
893 p = MNEW(char, strlen(opt_arg) + strlen("0"));
897 #if defined(ENABLE_JAVASE)
898 properties_add("java.class.path", p);
901 MFREE(class_path, char, strlen(class_path));
905 for (i = 0; i < strlen(opt_arg); i++) {
906 if (opt_arg[i] == '=') {
908 properties_add(opt_arg, opt_arg + i + 1);
913 /* if no '=' is given, just create an empty property */
915 properties_add(opt_arg, "");
920 case OPT_BOOTCLASSPATH:
921 /* Forget default bootclasspath and set the argument as
922 new boot classpath. */
924 boot_class_path = properties_get("sun.boot.class.path");
926 p = MNEW(char, strlen(opt_arg) + strlen("0"));
930 properties_add("sun.boot.class.path", p);
931 properties_add("java.boot.class.path", p);
933 MFREE(boot_class_path, char, strlen(boot_class_path));
936 case OPT_BOOTCLASSPATH_A:
937 /* Append to bootclasspath. */
939 boot_class_path = properties_get("sun.boot.class.path");
941 len = strlen(boot_class_path);
943 p = MREALLOC(boot_class_path,
947 strlen(opt_arg) + strlen("0"));
952 properties_add("sun.boot.class.path", p);
953 properties_add("java.boot.class.path", p);
956 case OPT_BOOTCLASSPATH_P:
957 /* Prepend to bootclasspath. */
959 boot_class_path = properties_get("sun.boot.class.path");
961 len = strlen(boot_class_path);
963 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
967 strcat(p, boot_class_path);
969 properties_add("sun.boot.class.path", p);
970 properties_add("java.boot.class.path", p);
972 MFREE(boot_class_path, char, len);
975 case OPT_BOOTCLASSPATH_C:
976 /* Use as Java core library, but prepend VM interface
979 boot_class_path = properties_get("sun.boot.class.path");
982 strlen(CACAO_VM_ZIP) +
989 strcpy(p, CACAO_VM_ZIP);
993 properties_add("sun.boot.class.path", p);
994 properties_add("java.boot.class.path", p);
996 MFREE(boot_class_path, char, strlen(boot_class_path));
999 #if defined(ENABLE_JVMTI)
1001 /* this option exists only for compatibility reasons */
1005 /* I don't know yet what Xnoagent should do. This is only for
1006 compatiblity with eclipse - motse */
1015 strlen(CACAO_LIBDIR) +
1016 strlen("/libjdwp.so=") +
1020 agentarg = MNEW(char, len);
1022 strcpy(agentarg, CACAO_LIBDIR);
1023 strcat(agentarg, "/libjdwp.so=");
1024 strcat(agentarg, &opt_arg[1]);
1041 c = opt_arg[strlen(opt_arg) - 1];
1043 if ((c == 'k') || (c == 'K')) {
1044 j = atoi(opt_arg) * 1024;
1046 } else if ((c == 'm') || (c == 'M')) {
1047 j = atoi(opt_arg) * 1024 * 1024;
1053 opt_heapmaxsize = j;
1054 else if (opt == OPT_MS)
1055 opt_heapstartsize = j;
1066 if (strcmp("class", opt_arg) == 0) {
1067 opt_verboseclass = true;
1069 else if (strcmp("gc", opt_arg) == 0) {
1070 opt_verbosegc = true;
1072 else if (strcmp("jni", opt_arg) == 0) {
1073 opt_verbosejni = true;
1075 #if !defined(NDEBUG)
1076 else if (strcmp("jit", opt_arg) == 0) {
1080 compileverbose = true;
1084 printf("Unknown -verbose option: %s\n", opt_arg);
1089 case OPT_DEBUGCOLOR:
1090 opt_debugcolor = true;
1093 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1095 opt_typecheckverbose = true;
1104 case OPT_FULLVERSION:
1108 case OPT_SHOWVERSION:
1116 #if defined(ENABLE_VERIFIER)
1122 #if defined(ENABLE_STATISTICS)
1124 opt_getcompilingtime = true;
1125 opt_getloadingtime = true;
1138 for (i = 0; i < strlen(opt_arg); i++) {
1139 switch (opt_arg[i]) {
1141 checkbounds = false;
1154 makeinitializations = false;
1157 #if !defined(NDEBUG)
1161 makeinitializations = false;
1166 opt_method = opt_arg;
1167 makeinitializations = false;
1171 opt_signature = opt_arg;
1175 case OPT_SHOW: /* Display options */
1176 for (i = 0; i < strlen(opt_arg); i++) {
1177 switch (opt_arg[i]) {
1179 showconstantpool = true;
1191 opt_showintermediate = true;
1192 compileverbose = true;
1195 #if defined(ENABLE_DISASSEMBLER)
1197 opt_showdisassemble = true;
1198 compileverbose = true;
1202 opt_shownops = true;
1207 opt_showddatasegment = true;
1216 #if defined(ENABLE_LOOP)
1222 #if defined(ENABLE_INLINING)
1223 #if defined(ENABLE_INLINING_DEBUG)
1224 case OPT_INLINE_DEBUG_ALL:
1225 opt_inline_debug_all = true;
1227 case OPT_INLINE_DEBUG_END:
1228 opt_inline_debug_end_counter = atoi(opt_arg);
1230 case OPT_INLINE_DEBUG_MIN:
1231 opt_inline_debug_min_size = atoi(opt_arg);
1233 case OPT_INLINE_DEBUG_MAX:
1234 opt_inline_debug_max_size = atoi(opt_arg);
1236 #endif /* defined(ENABLE_INLINING_DEBUG) */
1237 #if !defined(NDEBUG)
1238 case OPT_INLINE_LOG:
1239 opt_inline_debug_log = true;
1241 #endif /* !defined(NDEBUG) */
1244 opt_inlining = true;
1246 #endif /* defined(ENABLE_INLINING) */
1248 #if defined(ENABLE_IFCONV)
1254 #if defined(ENABLE_LSRA)
1259 #if defined(ENABLE_SSA)
1262 for (i = 0; i < strlen(opt_arg); i++) {
1263 switch (opt_arg[i]) {
1291 /* Already parsed. */
1295 #if defined(ENABLE_ASSERTION)
1296 assertion_ea_da(opt_arg, true);
1301 #if defined(ENABLE_ASSERTION)
1302 assertion_ea_da(opt_arg, false);
1307 #if defined(ENABLE_ASSERTION)
1308 assertion_user_enabled = true;
1313 #if defined(ENABLE_ASSERTION)
1314 assertion_user_enabled = false;
1319 #if defined(ENABLE_ASSERTION)
1320 assertion_system_enabled = true;
1325 #if defined(ENABLE_ASSERTION)
1326 assertion_system_enabled = false;
1330 #if defined(ENABLE_PROFILING)
1331 case OPT_PROF_OPTION:
1332 /* use <= to get the last \0 too */
1334 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1335 if (opt_arg[i] == ',')
1338 if (opt_arg[i] == '\0') {
1339 if (strcmp("bb", opt_arg + j) == 0)
1343 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1347 /* set k to next char */
1360 #if defined(ENABLE_JIT)
1363 printf("-Xjit option not enabled.\n");
1369 #if defined(ENABLE_INTRP)
1372 printf("-Xint option not enabled.\n");
1377 #if defined(ENABLE_INTRP)
1378 case OPT_STATIC_SUPERS:
1379 opt_static_supers = atoi(opt_arg);
1382 case OPT_NO_DYNAMIC:
1383 opt_no_dynamic = true;
1386 case OPT_NO_REPLICATION:
1387 opt_no_replication = true;
1390 case OPT_NO_QUICKSUPER:
1391 opt_no_quicksuper = true;
1399 #if defined(ENABLE_DEBUG_FILTER)
1400 case OPT_FILTER_VERBOSECALL_INCLUDE:
1401 opt_filter_verbosecall_include = opt_arg;
1404 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1405 opt_filter_verbosecall_exclude = opt_arg;
1408 case OPT_FILTER_SHOW_METHOD:
1409 opt_filter_show_method = opt_arg;
1414 printf("Unknown option: %s\n",
1415 vm_args->options[opt_index].optionString);
1420 /* get the main class *****************************************************/
1422 if (opt_index < vm_args->nOptions) {
1423 mainstring = vm_args->options[opt_index++].optionString;
1425 /* Put the jar file into the classpath (if any). */
1427 if (opt_jar == true) {
1428 /* free old classpath */
1430 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1432 /* put jarfile into classpath */
1434 p = MNEW(char, strlen(mainstring) + strlen("0"));
1436 strcpy(p, mainstring);
1438 #if defined(ENABLE_JAVASE)
1439 properties_add("java.class.path", p);
1443 /* replace .'s with /'s in classname */
1445 for (i = strlen(mainstring) - 1; i >= 0; i--)
1446 if (mainstring[i] == '.')
1447 mainstring[i] = '/';
1451 #if defined(ENABLE_JVMTI)
1453 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1454 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1457 MFREE(agentarg, char, strlen(agentarg));
1459 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1463 /* initialize this JVM ****************************************************/
1465 vm_initializing = true;
1467 /* initialize the garbage collector */
1469 gc_init(opt_heapmaxsize, opt_heapstartsize);
1471 #if defined(ENABLE_THREADS)
1472 /* AFTER: gc_init (directly after, as this initializes the
1473 stopworldlock lock */
1478 /* install architecture dependent signal handlers */
1481 vm_abort("vm_create: signal_init failed");
1483 #if defined(ENABLE_INTRP)
1484 /* Allocate main thread stack on the Java heap. */
1487 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1488 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1492 /* AFTER: threads_preinit */
1495 vm_abort("vm_create: string_init failed");
1497 /* AFTER: threads_preinit */
1500 vm_abort("vm_create: utf8_init failed");
1502 /* AFTER: thread_preinit */
1505 vm_abort("vm_create: suck_init failed");
1507 suck_add_from_property("java.endorsed.dirs");
1509 /* Now we have all options handled and we can print the version
1512 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1517 /* AFTER: utf8_init */
1519 boot_class_path = properties_get("sun.boot.class.path");
1520 suck_add(boot_class_path);
1522 /* initialize the classcache hashtable stuff: lock, hashtable
1523 (must be done _after_ threads_preinit) */
1525 if (!classcache_init())
1526 vm_abort("vm_create: classcache_init failed");
1528 /* Initialize the code memory management. */
1529 /* AFTER: threads_preinit */
1533 /* initialize the finalizer stuff (must be done _after_
1536 if (!finalizer_init())
1537 vm_abort("vm_create: finalizer_init failed");
1539 /* initializes jit compiler */
1543 #if defined(ENABLE_PYTHON)
1547 /* BEFORE: loader_preinit */
1551 /* AFTER: utf8_init, classcache_init */
1556 /* AFTER: loader_preinit, linker_preinit */
1563 /* AFTER: loader_init, linker_init */
1565 primitive_postinit();
1569 if (!builtin_init())
1570 vm_abort("vm_create: builtin_init failed");
1572 /* Initialize the native subsystem. */
1573 /* BEFORE: threads_init */
1576 vm_abort("vm_create: native_init failed");
1578 /* Register the native methods implemented in the VM. */
1579 /* BEFORE: threads_init */
1581 if (!nativevm_preinit())
1582 vm_abort("vm_create: nativevm_preinit failed");
1584 #if defined(ENABLE_JNI)
1585 /* Initialize the JNI subsystem (must be done _before_
1586 threads_init, as threads_init can call JNI methods
1587 (e.g. NewGlobalRef). */
1590 vm_abort("vm_create: jni_init failed");
1593 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1594 /* Initialize the local reference table for the main thread. */
1595 /* BEFORE: threads_init */
1597 if (!localref_table_init())
1598 vm_abort("vm_create: localref_table_init failed");
1601 #if defined(ENABLE_THREADS)
1602 if (!threads_init())
1603 vm_abort("vm_create: threads_init failed");
1606 /* Initialize the native VM subsystem. */
1607 /* AFTER: threads_init (at least for SUN's classes) */
1609 if (!nativevm_init())
1610 vm_abort("vm_create: nativevm_init failed");
1612 #if defined(ENABLE_PROFILING)
1613 /* initialize profiling */
1615 if (!profile_init())
1616 vm_abort("vm_create: profile_init failed");
1619 #if defined(ENABLE_THREADS)
1620 /* initialize recompilation */
1622 if (!recompile_init())
1623 vm_abort("vm_create: recompile_init failed");
1625 /* start the signal handler thread */
1627 #if defined(__LINUX__)
1628 /* XXX Remove for exact-GC. */
1629 if (threads_pthreads_implementation_nptl)
1631 if (!signal_start_thread())
1632 vm_abort("vm_create: signal_start_thread failed");
1634 /* finally, start the finalizer thread */
1636 if (!finalizer_start_thread())
1637 vm_abort("vm_create: finalizer_start_thread failed");
1639 # if !defined(NDEBUG)
1640 /* start the memory profiling thread */
1642 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1643 if (!memory_start_thread())
1644 vm_abort("vm_create: memory_start_thread failed");
1647 /* start the recompilation thread (must be done before the
1648 profiling thread) */
1650 if (!recompile_start_thread())
1651 vm_abort("vm_create: recompile_start_thread failed");
1653 # if defined(ENABLE_PROFILING)
1654 /* start the profile sampling thread */
1657 /* if (!profile_start_thread()) */
1658 /* vm_abort("vm_create: profile_start_thread failed"); */
1662 #if defined(ENABLE_JVMTI)
1663 # if defined(ENABLE_GC_CACAO)
1664 /* XXX this will not work with the new indirection cells for classloaders!!! */
1668 /* add agent library to native library hashtable */
1669 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1673 /* increment the number of VMs */
1677 /* initialization is done */
1679 vm_initializing = false;
1681 #if !defined(NDEBUG)
1682 /* Print the VM configuration after all stuff is set and the VM is
1685 if (opt_PrintConfig)
1689 /* everything's ok */
1695 /* vm_run **********************************************************************
1697 Runs the main-method of the passed class.
1699 *******************************************************************************/
1701 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1704 classinfo *mainclass;
1707 java_handle_objectarray_t *oa;
1714 #if !defined(NDEBUG)
1720 if (opt_method != NULL) {
1721 vm_compile_method();
1724 #endif /* !defined(NDEBUG) */
1726 /* should we run the main-method? */
1728 if (mainstring == NULL)
1731 /* set return value to OK */
1735 if (opt_jar == true) {
1736 /* open jar file with java.util.jar.JarFile */
1738 mainstring = vm_get_mainclass_from_jar(mainstring);
1740 if (mainstring == NULL)
1744 /* load the main class */
1746 mainutf = utf_new_char(mainstring);
1748 #if defined(ENABLE_JAVAME_CLDC1_1)
1749 mainclass = load_class_bootstrap(mainutf);
1751 mainclass = load_class_from_sysloader(mainutf);
1754 /* error loading class */
1756 e = exceptions_get_and_clear_exception();
1758 if ((e != NULL) || (mainclass == NULL)) {
1759 exceptions_throw_noclassdeffounderror_cause(e);
1760 exceptions_print_stacktrace();
1764 if (!link_class(mainclass)) {
1765 exceptions_print_stacktrace();
1769 /* find the `main' method of the main class */
1771 m = class_resolveclassmethod(mainclass,
1772 utf_new_char("main"),
1773 utf_new_char("([Ljava/lang/String;)V"),
1774 class_java_lang_Object,
1777 if (exceptions_get_exception()) {
1778 exceptions_print_stacktrace();
1782 /* there is no main method or it isn't static */
1784 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1785 exceptions_clear_exception();
1786 exceptions_throw_nosuchmethoderror(mainclass,
1787 utf_new_char("main"),
1788 utf_new_char("([Ljava/lang/String;)V"));
1790 exceptions_print_stacktrace();
1794 /* build argument array */
1796 oalength = vm_args->nOptions - opt_index;
1798 oa = builtin_anewarray(oalength, class_java_lang_String);
1800 for (i = 0; i < oalength; i++) {
1801 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1802 s = javastring_new(u);
1804 array_objectarray_element_set(oa, i, s);
1807 #ifdef TYPEINFO_DEBUG_TEST
1808 /* test the typeinfo system */
1811 /*class_showmethods(currentThread->group->header.vftbl->class); */
1813 #if defined(ENABLE_JVMTI)
1814 jvmti_set_phase(JVMTI_PHASE_LIVE);
1817 /* set ThreadMXBean variables */
1819 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1820 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1822 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1823 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1824 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1825 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1827 /* start the main thread */
1829 (void) vm_call_method(m, NULL, oa);
1831 /* exception occurred? */
1833 if (exceptions_get_exception()) {
1834 exceptions_print_stacktrace();
1838 /* unload the JavaVM */
1840 (void) vm_destroy(vm);
1848 /* vm_destroy ******************************************************************
1850 Unloads a Java VM and reclaims its resources.
1852 *******************************************************************************/
1854 s4 vm_destroy(JavaVM *vm)
1856 #if defined(ENABLE_THREADS)
1857 threads_join_all_threads();
1860 /* everything's ok */
1866 /* vm_exit *********************************************************************
1868 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1870 *******************************************************************************/
1872 void vm_exit(s4 status)
1876 /* signal that we are exiting */
1880 assert(class_java_lang_System);
1881 assert(class_java_lang_System->state & CLASS_LOADED);
1883 #if defined(ENABLE_JVMTI)
1884 if (jvmti || (dbgcom!=NULL)) {
1885 jvmti_set_phase(JVMTI_PHASE_DEAD);
1886 if (jvmti) jvmti_agentunload();
1890 if (!link_class(class_java_lang_System)) {
1891 exceptions_print_stacktrace();
1895 /* call java.lang.System.exit(I)V */
1897 m = class_resolveclassmethod(class_java_lang_System,
1898 utf_new_char("exit"),
1900 class_java_lang_Object,
1904 exceptions_print_stacktrace();
1908 /* call the exit function with passed exit status */
1910 (void) vm_call_method(m, NULL, status);
1912 /* If we had an exception, just ignore the exception and exit with
1915 vm_shutdown(status);
1919 /* vm_shutdown *****************************************************************
1921 Terminates the system immediately without freeing memory explicitly
1922 (to be used only for abnormal termination).
1924 *******************************************************************************/
1926 void vm_shutdown(s4 status)
1929 #if defined(ENABLE_STATISTICS)
1930 || opt_getcompilingtime || opt_stat
1934 log_text("CACAO terminated by shutdown");
1935 dolog("Exit status: %d\n", (s4) status);
1939 #if defined(ENABLE_JVMTI)
1940 /* terminate cacaodbgserver */
1942 pthread_mutex_lock(&dbgcomlock);
1944 pthread_mutex_unlock(&dbgcomlock);
1945 jvmti_cacaodbgserver_quit();
1953 /* vm_exit_handler *************************************************************
1955 The exit_handler function is called upon program termination.
1957 ATTENTION: Don't free system resources here! Some threads may still
1958 be running as this is called from VMRuntime.exit(). The OS does the
1961 *******************************************************************************/
1963 void vm_exit_handler(void)
1965 #if !defined(NDEBUG)
1967 class_showmethods(mainclass);
1969 if (showconstantpool)
1970 class_showconstantpool(mainclass);
1975 # if defined(ENABLE_PROFILING)
1977 profile_printstats();
1979 #endif /* !defined(NDEBUG) */
1981 #if defined(ENABLE_RT_TIMING)
1982 rt_timing_print_time_stats(stderr);
1985 #if defined(ENABLE_CYCLES_STATS)
1986 builtin_print_cycles_stats(stderr);
1987 stacktrace_print_cycles_stats(stderr);
1991 #if defined(ENABLE_STATISTICS)
1992 || opt_getcompilingtime || opt_stat
1996 log_text("CACAO terminated");
1998 #if defined(ENABLE_STATISTICS)
2001 #ifdef TYPECHECK_STATISTICS
2002 typecheck_print_statistics(get_logfile());
2006 if (opt_getcompilingtime)
2008 #endif /* defined(ENABLE_STATISTICS) */
2010 /* vm_print_profile(stderr);*/
2014 /* vm_abort ********************************************************************
2016 Prints an error message and aborts the VM.
2018 *******************************************************************************/
2020 void vm_abort(const char *text, ...)
2024 /* print the log message */
2029 log_vprint(text, ap);
2034 /* now abort the VM */
2040 /* vm_abort_disassemble ********************************************************
2042 Prints an error message, disassemble the given code range (if
2043 enabled) and aborts the VM.
2046 pc.......PC to disassemble
2047 count....number of instructions to disassemble
2049 *******************************************************************************/
2051 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2054 #if defined(ENABLE_DISASSEMBLER)
2058 /* Print debug message. */
2063 log_vprint(text, ap);
2070 #if SIZEOF_VOID_P == 8
2071 log_println("PC=0x%016lx", pc);
2073 log_println("PC=0x%08x", pc);
2076 #if defined(ENABLE_DISASSEMBLER)
2077 log_println("machine instructions at PC:");
2079 /* Disassemble the given number of instructions. */
2081 for (i = 0; i < count; i++)
2082 pc = disassinstr(pc);
2085 vm_abort("Aborting...");
2089 /* vm_get_mainclass_from_jar ***************************************************
2091 Gets the name of the main class from a JAR's manifest file.
2093 *******************************************************************************/
2095 static char *vm_get_mainclass_from_jar(char *mainstring)
2102 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2105 exceptions_print_stacktrace();
2109 /* create JarFile object */
2114 exceptions_print_stacktrace();
2118 m = class_resolveclassmethod(c,
2120 utf_java_lang_String__void,
2121 class_java_lang_Object,
2125 exceptions_print_stacktrace();
2129 s = javastring_new_from_ascii(mainstring);
2131 (void) vm_call_method(m, o, s);
2133 if (exceptions_get_exception()) {
2134 exceptions_print_stacktrace();
2138 /* get manifest object */
2140 m = class_resolveclassmethod(c,
2141 utf_new_char("getManifest"),
2142 utf_new_char("()Ljava/util/jar/Manifest;"),
2143 class_java_lang_Object,
2147 exceptions_print_stacktrace();
2151 o = vm_call_method(m, o);
2154 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2159 /* get Main Attributes */
2161 LLNI_class_get(o, c);
2163 m = class_resolveclassmethod(c,
2164 utf_new_char("getMainAttributes"),
2165 utf_new_char("()Ljava/util/jar/Attributes;"),
2166 class_java_lang_Object,
2170 exceptions_print_stacktrace();
2174 o = vm_call_method(m, o);
2177 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2182 /* get property Main-Class */
2184 LLNI_class_get(o, c);
2186 m = class_resolveclassmethod(c,
2187 utf_new_char("getValue"),
2188 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2189 class_java_lang_Object,
2193 exceptions_print_stacktrace();
2197 s = javastring_new_from_ascii("Main-Class");
2199 o = vm_call_method(m, o, s);
2202 exceptions_print_stacktrace();
2206 return javastring_tochar(o);
2210 /* vm_compile_all **************************************************************
2212 Compile all methods found in the bootclasspath.
2214 *******************************************************************************/
2216 #if !defined(NDEBUG)
2217 static void vm_compile_all(void)
2222 classcache_name_entry *nmen;
2223 classcache_class_entry *clsen;
2226 /* create all classes found in the bootclasspath */
2227 /* XXX currently only works with zip/jar's */
2229 loader_load_all_classes();
2231 /* link all classes */
2233 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2234 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2236 for (; nmen; nmen = nmen->hashlink) {
2237 /* iterate over all class entries */
2239 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2240 c = clsen->classobj;
2245 if (!(c->state & CLASS_LINKED)) {
2246 if (!link_class(c)) {
2247 fprintf(stderr, "Error linking: ");
2248 utf_fprint_printable_ascii_classname(stderr, c->name);
2249 fprintf(stderr, "\n");
2251 /* print out exception and cause */
2253 exceptions_print_current_exception();
2255 /* goto next class */
2261 /* compile all class methods */
2263 for (i = 0; i < c->methodscount; i++) {
2264 m = &(c->methods[i]);
2266 if (m->jcode != NULL) {
2267 if (!jit_compile(m)) {
2268 fprintf(stderr, "Error compiling: ");
2269 utf_fprint_printable_ascii_classname(stderr, c->name);
2270 fprintf(stderr, ".");
2271 utf_fprint_printable_ascii(stderr, m->name);
2272 utf_fprint_printable_ascii(stderr, m->descriptor);
2273 fprintf(stderr, "\n");
2275 /* print out exception and cause */
2277 exceptions_print_current_exception();
2285 #endif /* !defined(NDEBUG) */
2288 /* vm_compile_method ***********************************************************
2290 Compile a specific method.
2292 *******************************************************************************/
2294 #if !defined(NDEBUG)
2295 static void vm_compile_method(void)
2299 /* create, load and link the main class */
2301 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2303 if (mainclass == NULL)
2304 exceptions_print_stacktrace();
2306 if (!link_class(mainclass))
2307 exceptions_print_stacktrace();
2309 if (opt_signature != NULL) {
2310 m = class_resolveclassmethod(mainclass,
2311 utf_new_char(opt_method),
2312 utf_new_char(opt_signature),
2317 m = class_resolveclassmethod(mainclass,
2318 utf_new_char(opt_method),
2325 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2326 opt_method, opt_signature ? opt_signature : "");
2330 #endif /* !defined(NDEBUG) */
2333 /* vm_call_array ***************************************************************
2335 Calls a Java method with a variable number of arguments, passed via
2338 ATTENTION: This function has to be used outside the nativeworld.
2340 *******************************************************************************/
2342 #define VM_CALL_ARRAY(name, type) \
2343 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2349 assert(m->code != NULL); \
2351 md = m->parseddesc; \
2352 pv = m->code->entrypoint; \
2354 STATISTICS(count_calls_native_to_java++); \
2356 value = asm_vm_call_method##name(pv, array, md->memuse); \
2361 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2367 assert(m->code != NULL);
2370 pv = m->code->entrypoint;
2372 STATISTICS(count_calls_native_to_java++);
2374 o = asm_vm_call_method(pv, array, md->memuse);
2376 if (md->returntype.type == TYPE_VOID)
2379 return LLNI_WRAP(o);
2382 VM_CALL_ARRAY(_int, int32_t)
2383 VM_CALL_ARRAY(_long, int64_t)
2384 VM_CALL_ARRAY(_float, float)
2385 VM_CALL_ARRAY(_double, double)
2388 /* vm_call_method **************************************************************
2390 Calls a Java method with a variable number of arguments.
2392 *******************************************************************************/
2394 #define VM_CALL_METHOD(name, type) \
2395 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2401 value = vm_call_method##name##_valist(m, o, ap); \
2407 VM_CALL_METHOD(, java_handle_t *)
2408 VM_CALL_METHOD(_int, int32_t)
2409 VM_CALL_METHOD(_long, int64_t)
2410 VM_CALL_METHOD(_float, float)
2411 VM_CALL_METHOD(_double, double)
2414 /* vm_call_method_valist *******************************************************
2416 Calls a Java method with a variable number of arguments, passed via
2419 *******************************************************************************/
2421 #define VM_CALL_METHOD_VALIST(name, type) \
2422 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2427 int32_t dumpmarker; \
2429 if (m->code == NULL) \
2430 if (!jit_compile(m)) \
2433 THREAD_NATIVEWORLD_EXIT; \
2436 array = argument_vmarray_from_valist(m, o, ap); \
2437 value = vm_call##name##_array(m, array); \
2440 THREAD_NATIVEWORLD_ENTER; \
2445 VM_CALL_METHOD_VALIST(, java_handle_t *)
2446 VM_CALL_METHOD_VALIST(_int, int32_t)
2447 VM_CALL_METHOD_VALIST(_long, int64_t)
2448 VM_CALL_METHOD_VALIST(_float, float)
2449 VM_CALL_METHOD_VALIST(_double, double)
2452 /* vm_call_method_jvalue *******************************************************
2454 Calls a Java method with a variable number of arguments, passed via
2457 *******************************************************************************/
2459 #define VM_CALL_METHOD_JVALUE(name, type) \
2460 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2461 const jvalue *args) \
2465 int32_t dumpmarker; \
2467 if (m->code == NULL) \
2468 if (!jit_compile(m)) \
2471 THREAD_NATIVEWORLD_EXIT; \
2474 array = argument_vmarray_from_jvalue(m, o, args); \
2475 value = vm_call##name##_array(m, array); \
2478 THREAD_NATIVEWORLD_ENTER; \
2483 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2484 VM_CALL_METHOD_JVALUE(_int, int32_t)
2485 VM_CALL_METHOD_JVALUE(_long, int64_t)
2486 VM_CALL_METHOD_JVALUE(_float, float)
2487 VM_CALL_METHOD_JVALUE(_double, double)
2490 /* vm_call_method_objectarray **************************************************
2492 Calls a Java method with a variable number if arguments, passed via
2493 an objectarray of boxed values. Returns a boxed value.
2495 *******************************************************************************/
2497 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2498 java_handle_objectarray_t *params)
2501 java_handle_t *xptr;
2506 /* Prevent compiler warnings. */
2510 /* compile methods which are not yet compiled */
2512 if (m->code == NULL)
2513 if (!jit_compile(m))
2516 /* leave the nativeworld */
2518 THREAD_NATIVEWORLD_EXIT;
2520 /* mark start of dump memory area */
2524 /* Fill the argument array from a object-array. */
2526 array = argument_vmarray_from_objectarray(m, o, params);
2528 if (array == NULL) {
2529 /* release dump area */
2533 /* enter the nativeworld again */
2535 THREAD_NATIVEWORLD_ENTER;
2537 exceptions_throw_illegalargumentexception();
2542 switch (m->parseddesc->returntype.decltype) {
2543 case PRIMITIVETYPE_VOID:
2544 value.a = vm_call_array(m, array);
2547 case PRIMITIVETYPE_BOOLEAN:
2548 case PRIMITIVETYPE_BYTE:
2549 case PRIMITIVETYPE_CHAR:
2550 case PRIMITIVETYPE_SHORT:
2551 case PRIMITIVETYPE_INT:
2552 value.i = vm_call_int_array(m, array);
2555 case PRIMITIVETYPE_LONG:
2556 value.l = vm_call_long_array(m, array);
2559 case PRIMITIVETYPE_FLOAT:
2560 value.f = vm_call_float_array(m, array);
2563 case PRIMITIVETYPE_DOUBLE:
2564 value.d = vm_call_double_array(m, array);
2568 ro = vm_call_array(m, array);
2572 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2575 /* release dump area */
2579 /* enter the nativeworld again */
2581 THREAD_NATIVEWORLD_ENTER;
2583 /* box the return value if necesarry */
2585 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2586 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2588 /* check for an exception */
2590 xptr = exceptions_get_exception();
2593 /* clear exception pointer, we are calling JIT code again */
2595 exceptions_clear_exception();
2597 exceptions_throw_invocationtargetexception(xptr);
2605 * These are local overrides for various environment variables in Emacs.
2606 * Please do not remove this and leave it at the end of the file, where
2607 * Emacs will automagically detect them.
2608 * ---------------------------------------------------------------------
2611 * indent-tabs-mode: t
2615 * vim:noexpandtab:sw=4:ts=4: