1 /* src/vm/vm.c - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
40 #include "vm/jit/abi-asm.h"
42 #include "mm/gc-common.h"
43 #include "mm/memory.h"
45 #include "native/jni.h"
46 #include "native/llni.h"
47 #include "native/localref.h"
48 #include "native/native.h"
50 #include "native/include/java_lang_Object.h" /* required by j.l.C */
51 #include "native/include/java_lang_String.h" /* required by j.l.C */
53 #if defined(WITH_CLASSPATH_SUN)
54 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
55 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
58 #include "native/include/java_lang_Class.h"
60 #include "native/vm/nativevm.h"
62 #include "threads/threads-common.h"
64 #include "toolbox/logging.h"
68 #if defined(ENABLE_ASSERTION)
69 #include "vm/assertion.h"
72 #include "vm/builtin.h"
73 #include "vm/exceptions.h"
74 #include "vm/finalizer.h"
75 #include "vm/global.h"
76 #include "vm/initialize.h"
77 #include "vm/package.h"
78 #include "vm/primitive.h"
79 #include "vm/properties.h"
80 #include "vm/signallocal.h"
81 #include "vm/stringlocal.h"
84 #include "vm/jit/argument.h"
85 #include "vm/jit/asmpart.h"
87 #if defined(ENABLE_DISASSEMBLER)
88 # include "vm/jit/disass.h"
91 #include "vm/jit/jit.h"
93 #if defined(ENABLE_PROFILING)
94 # include "vm/jit/optimizing/profile.h"
97 #include "vm/jit/optimizing/recompile.h"
99 #include "vmcore/classcache.h"
100 #include "vmcore/options.h"
101 #include "vmcore/statistics.h"
102 #include "vmcore/suck.h"
104 #if defined(ENABLE_JVMTI)
105 # include "native/jvmti/cacaodbg.h"
108 #if defined(ENABLE_VMLOG)
109 #include <vmlog_cacao.h>
113 /* Invocation API variables ***************************************************/
115 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
116 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
119 /* global variables ***********************************************************/
121 s4 vms = 0; /* number of VMs created */
123 bool vm_initializing = false;
124 bool vm_exiting = false;
126 char *mainstring = NULL;
127 classinfo *mainclass = NULL;
129 #if defined(ENABLE_INTRP)
130 u1 *intrp_main_stack = NULL;
134 /* define heap sizes **********************************************************/
136 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
137 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
138 #define STACK_SIZE 128 * 1024 /* default 64kB */
141 /* define command line options ************************************************/
172 /* Java non-standard options */
183 #if defined(ENABLE_PROFILING)
196 #if defined(ENABLE_STATISTICS)
213 #if defined(ENABLE_VERIFIER)
215 #if defined(TYPECHECK_VERBOSE)
218 #endif /* defined(ENABLE_VERIFIER) */
220 /* optimization options */
222 #if defined(ENABLE_LOOP)
226 #if defined(ENABLE_IFCONV)
230 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
234 #if defined(ENABLE_INLINING)
239 #if defined(ENABLE_INLINING_DEBUG)
240 OPT_INLINE_DEBUG_ALL,
241 OPT_INLINE_DEBUG_END,
242 OPT_INLINE_DEBUG_MIN,
243 OPT_INLINE_DEBUG_MAX,
244 #endif /* defined(ENABLE_INLINING_DEBUG) */
245 #endif /* defined(ENABLE_INLINING) */
247 #if defined(ENABLE_INTRP)
248 /* interpreter options */
267 #if defined(ENABLE_DEBUG_FILTER)
268 OPT_FILTER_VERBOSECALL_INCLUDE,
269 OPT_FILTER_VERBOSECALL_EXCLUDE,
270 OPT_FILTER_SHOW_METHOD,
277 opt_struct opts[] = {
278 { "foo", false, OPT_FOO },
282 { "jar", false, OPT_JAR },
284 { "d32", false, OPT_D32 },
285 { "d64", false, OPT_D64 },
286 { "client", false, OPT_IGNORE },
287 { "server", false, OPT_IGNORE },
288 { "jvm", false, OPT_IGNORE },
289 { "hotspot", false, OPT_IGNORE },
291 { "classpath", true, OPT_CLASSPATH },
292 { "cp", true, OPT_CLASSPATH },
293 { "D", true, OPT_D },
294 { "version", false, OPT_VERSION },
295 { "showversion", false, OPT_SHOWVERSION },
296 { "fullversion", false, OPT_FULLVERSION },
297 { "help", false, OPT_HELP },
298 { "?", false, OPT_HELP },
299 { "X", false, OPT_X },
300 { "XX:", true, OPT_XX },
302 { "ea:", true, OPT_EA },
303 { "da:", true, OPT_DA },
304 { "ea", false, OPT_EA },
305 { "da", false, OPT_DA },
307 { "esa", false, OPT_ESA },
308 { "enablesystemassertions", false, OPT_ESA },
309 { "dsa", false, OPT_DSA },
310 { "disablesystemassertions", false, OPT_DSA },
312 { "noasyncgc", false, OPT_IGNORE },
313 #if defined(ENABLE_VERIFIER)
314 { "noverify", false, OPT_NOVERIFY },
315 { "Xverify:none", false, OPT_NOVERIFY },
317 { "v", false, OPT_VERBOSE1 },
318 { "verbose:", true, OPT_VERBOSE },
320 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
321 { "verbosetc", false, OPT_VERBOSETC },
323 #if defined(__ALPHA__)
324 { "noieee", false, OPT_NOIEEE },
326 #if defined(ENABLE_STATISTICS)
327 { "time", false, OPT_TIME },
328 { "stat", false, OPT_STAT },
330 { "log", true, OPT_LOG },
331 { "c", true, OPT_CHECK },
332 { "l", false, OPT_LOAD },
335 { "all", false, OPT_ALL },
336 { "sig", true, OPT_SIGNATURE },
339 #if defined(ENABLE_LOOP)
340 { "oloop", false, OPT_OLOOP },
342 #if defined(ENABLE_IFCONV)
343 { "ifconv", false, OPT_IFCONV },
345 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
346 { "lsra", false, OPT_LSRA },
349 #if defined(ENABLE_INTRP)
350 /* interpreter options */
352 { "trace", false, OPT_TRACE },
353 { "static-supers", true, OPT_STATIC_SUPERS },
354 { "no-dynamic", false, OPT_NO_DYNAMIC },
355 { "no-replication", false, OPT_NO_REPLICATION },
356 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
359 /* JVMTI Agent Command Line Options */
361 { "agentlib:", true, OPT_AGENTLIB },
362 { "agentpath:", true, OPT_AGENTPATH },
365 /* Java non-standard options */
367 { "Xjit", false, OPT_JIT },
368 { "Xint", false, OPT_INTRP },
369 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
370 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
371 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
372 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
375 { "Xdebug", false, OPT_DEBUG },
376 { "Xnoagent", false, OPT_NOAGENT },
377 { "Xrunjdwp", true, OPT_XRUNJDWP },
380 { "Xms", true, OPT_MS },
381 { "ms", true, OPT_MS },
382 { "Xmx", true, OPT_MX },
383 { "mx", true, OPT_MX },
384 { "Xss", true, OPT_SS },
385 { "ss", true, OPT_SS },
387 #if defined(ENABLE_PROFILING)
388 { "Xprof:", true, OPT_PROF_OPTION },
389 { "Xprof", false, OPT_PROF },
392 /* inlining options */
394 #if defined(ENABLE_INLINING)
395 #if defined(ENABLE_INLINING_DEBUG)
396 { "ia", false, OPT_INLINE_DEBUG_ALL },
397 { "ii", true, OPT_INLINE_DEBUG_MIN },
398 { "im", true, OPT_INLINE_DEBUG_MAX },
399 { "ie", true, OPT_INLINE_DEBUG_END },
400 #endif /* defined(ENABLE_INLINING_DEBUG) */
402 { "il", false, OPT_INLINE_LOG },
404 { "i", false, OPT_INLINING },
405 #endif /* defined(ENABLE_INLINING) */
407 /* keep these at the end of the list */
410 { "m", true, OPT_METHOD },
413 { "s", true, OPT_SHOW },
414 { "debug-color", false, OPT_DEBUGCOLOR },
416 #if defined(ENABLE_DEBUG_FILTER)
417 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
418 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
419 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
426 /* usage ***********************************************************************
428 Prints the correct usage syntax to stdout.
430 *******************************************************************************/
434 puts("Usage: cacao [-options] classname [arguments]");
435 puts(" (to run a class file)");
436 puts(" or cacao [-options] -jar jarfile [arguments]");
437 puts(" (to run a standalone jar file)\n");
439 puts("where options include:");
440 puts(" -d32 use 32-bit data model if available");
441 puts(" -d64 use 64-bit data model if available");
442 puts(" -client compatibility (currently ignored)");
443 puts(" -server compatibility (currently ignored)");
444 puts(" -jvm compatibility (currently ignored)");
445 puts(" -hotspot compatibility (currently ignored)\n");
447 puts(" -cp <path> specify a path to look for classes");
448 puts(" -classpath <path> specify a path to look for classes");
449 puts(" -D<name>=<value> add an entry to the property list");
450 puts(" -verbose[:class|gc|jni] enable specific verbose output");
451 puts(" -version print product version and exit");
452 puts(" -fullversion print jpackage-compatible product version and exit");
453 puts(" -showversion print product version and continue");
454 puts(" -help, -? print this help message");
455 puts(" -X print help on non-standard Java options");
456 puts(" -XX print help on debugging options");
457 puts(" -ea[:<packagename>...|:<classname>]");
458 puts(" -enableassertions[:<packagename>...|:<classname>]");
459 puts(" enable assertions with specified granularity");
460 puts(" -da[:<packagename>...|:<classname>]");
461 puts(" -disableassertions[:<packagename>...|:<classname>]");
462 puts(" disable assertions with specified granularity");
463 puts(" -esa | -enablesystemassertions");
464 puts(" enable system assertions");
465 puts(" -dsa | -disablesystemassertions");
466 puts(" disable system assertions");
469 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
470 puts (" for jdwp help use: -agentlib:jdwp=help");
471 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
474 /* exit with error code */
480 static void Xusage(void)
482 #if defined(ENABLE_JIT)
483 puts(" -Xjit JIT mode execution (default)");
485 #if defined(ENABLE_INTRP)
486 puts(" -Xint interpreter mode execution");
488 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
489 puts(" value is set as bootstrap class path");
490 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
491 puts(" value is appended to the bootstrap class path");
492 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
493 puts(" value is prepended to the bootstrap class path");
494 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
495 puts(" value is used as Java core library, but the");
496 puts(" hardcoded VM interface classes are prepended");
497 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
498 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
499 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
501 #if defined(ENABLE_PROFILING)
502 puts(" -Xprof[:bb] collect and print profiling data");
505 #if defined(ENABLE_JVMTI)
506 /* -Xdebug option depend on gnu classpath JDWP options. options:
507 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
508 puts(" -Xdebug enable remote debugging\n");
509 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
510 puts(" enable remote debugging\n");
513 /* exit with error code */
520 static void XXusage(void)
522 puts(" -v write state-information");
524 puts(" -verbose:jit enable specific verbose output");
525 puts(" -debug-color colored output for ANSI terms");
527 #ifdef TYPECHECK_VERBOSE
528 puts(" -verbosetc write debug messages while typechecking");
530 #if defined(__ALPHA__)
531 puts(" -noieee don't use ieee compliant arithmetic");
533 #if defined(ENABLE_VERIFIER)
534 puts(" -noverify don't verify classfiles");
536 #if defined(ENABLE_STATISTICS)
537 puts(" -time measure the runtime");
538 puts(" -stat detailed compiler statistics");
540 puts(" -log logfile specify a name for the logfile");
541 puts(" -c(heck)b(ounds) don't check array bounds");
542 puts(" s(ync) don't check for synchronization");
543 #if defined(ENABLE_LOOP)
544 puts(" -oloop optimize array accesses in loops");
546 puts(" -l don't start the class after loading");
548 puts(" -all compile all methods, no execution");
549 puts(" -m compile only a specific method");
550 puts(" -sig specify signature for a specific method");
553 puts(" -s... show...");
554 puts(" (c)onstants the constant pool");
555 puts(" (m)ethods class fields and methods");
556 puts(" (u)tf the utf - hash");
557 puts(" (i)ntermediate intermediate representation");
558 #if defined(ENABLE_DISASSEMBLER)
559 puts(" (a)ssembler disassembled listing");
560 puts(" n(o)ps show NOPs in disassembler output");
562 puts(" (d)atasegment data segment listing");
564 #if defined(ENABLE_INLINING)
565 puts(" -i activate inlining");
567 puts(" -il log inlining");
569 #if defined(ENABLE_INLINING_DEBUG)
570 puts(" -ia use inlining for all methods");
571 puts(" -ii <size> set minimum size for inlined result");
572 puts(" -im <size> set maximum size for inlined result");
573 puts(" -ie <number> stop inlining after the given number of roots");
574 #endif /* defined(ENABLE_INLINING_DEBUG) */
575 #endif /* defined(ENABLE_INLINING) */
577 #if defined(ENABLE_IFCONV)
578 puts(" -ifconv use if-conversion");
580 #if defined(ENABLE_LSRA)
581 puts(" -lsra use linear scan register allocation");
583 #if defined(ENABLE_SSA)
584 puts(" -lsra use linear scan register allocation (with SSA)");
586 #if defined(ENABLE_DEBUG_FILTER)
587 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
588 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
589 puts(" -XXfm <regex> filter for show options");
591 /* exit with error code */
598 /* version *********************************************************************
600 Only prints cacao version information.
602 *******************************************************************************/
604 static void version(bool opt_exit)
606 puts("java version \""JAVA_VERSION"\"");
607 puts("CACAO version "VERSION"");
609 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
610 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
611 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
612 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
614 puts("This program is free software; you can redistribute it and/or");
615 puts("modify it under the terms of the GNU General Public License as");
616 puts("published by the Free Software Foundation; either version 2, or (at");
617 puts("your option) any later version.\n");
619 puts("This program is distributed in the hope that it will be useful, but");
620 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
621 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
622 puts("General Public License for more details.");
624 /* exit normally, if requested */
631 /* fullversion *****************************************************************
633 Prints a Sun compatible version information (required e.g. by
634 jpackage, www.jpackage.org).
636 *******************************************************************************/
638 static void fullversion(void)
640 puts("java full version \"cacao-"JAVA_VERSION"\"");
648 static void vm_printconfig(void)
650 puts("Configure/Build options:\n");
651 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
652 #if defined(__VERSION__)
653 puts(" CC : "VERSION_CC" ("__VERSION__")");
655 puts(" CC : "VERSION_CC"");
657 puts(" CFLAGS : "VERSION_CFLAGS"\n");
659 puts("Default variables:\n");
660 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
661 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
662 printf(" stack size : %d\n", STACK_SIZE);
664 #if defined(WITH_JRE_LAYOUT)
665 /* When we're building with JRE-layout, the default paths are the
666 same as the runtime paths. */
668 # if defined(WITH_CLASSPATH_GNU)
669 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
670 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
671 # elif defined(WITH_CLASSPATH_SUN)
672 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
673 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
679 puts("Runtime variables:\n");
680 printf(" maximum heap size : %d\n", opt_heapmaxsize);
681 printf(" initial heap size : %d\n", opt_heapstartsize);
682 printf(" stack size : %d\n", opt_stacksize);
684 #if defined(WITH_CLASSPATH_GNU)
685 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
686 #elif defined(WITH_CLASSPATH_SUN)
687 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
690 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
691 printf(" java.class.path : %s\n", properties_get("java.class.path"));
695 /* forward declarations *******************************************************/
697 static char *vm_get_mainclass_from_jar(char *mainstring);
699 static void vm_compile_all(void);
700 static void vm_compile_method(void);
704 /* vm_createjvm ****************************************************************
706 Implementation for JNI_CreateJavaVM.
708 *******************************************************************************/
710 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
712 JavaVMInitArgs *_vm_args;
716 /* get the arguments for the new JVM */
718 _vm_args = (JavaVMInitArgs *) vm_args;
720 /* get the VM and Env tables (must be set before vm_create) */
722 env = NEW(_Jv_JNIEnv);
724 #if defined(ENABLE_JNI)
725 env->env = &_Jv_JNINativeInterface;
728 /* XXX Set the global variable. Maybe we should do that differently. */
732 /* create and fill a JavaVM structure */
734 vm = NEW(_Jv_JavaVM);
736 #if defined(ENABLE_JNI)
737 vm->functions = &_Jv_JNIInvokeInterface;
740 /* XXX Set the global variable. Maybe we should do that differently. */
741 /* XXX JVMTI Agents needs a JavaVM */
745 /* actually create the JVM */
747 if (!vm_create(_vm_args))
750 /* now return the values */
752 *p_vm = (JavaVM *) vm;
753 *p_env = (void *) env;
758 /* release allocated memory */
760 FREE(env, _Jv_JNIEnv);
761 FREE(vm, _Jv_JavaVM);
767 /* vm_create *******************************************************************
769 Creates a JVM. Called by vm_createjvm.
771 *******************************************************************************/
773 bool vm_create(JavaVMInitArgs *vm_args)
777 char *boot_class_path;
784 #if defined(ENABLE_JVMTI)
786 char *libname, *agentarg;
787 bool jdwp,agentbypath;
788 jdwp = agentbypath = false;
791 #if defined(ENABLE_VMLOG)
792 vmlog_cacao_init(vm_args);
795 #if defined(ENABLE_JNI)
796 /* Check the JNI version requested. */
798 if (!jni_version_check(vm_args->version))
802 /* We only support 1 JVM instance. */
807 /* Install the exit handler. */
809 if (atexit(vm_exit_handler))
810 vm_abort("atexit failed: %s\n", strerror(errno));
812 /* Set some options. */
819 opt_heapmaxsize = HEAP_MAXSIZE;
820 opt_heapstartsize = HEAP_STARTSIZE;
821 opt_stacksize = STACK_SIZE;
823 /* Initialize the properties list before command-line handling.
824 Otherwise -XX:+PrintConfig crashes. */
828 /* First of all, parse the -XX options. */
832 /* We need to check if the actual size of a java.lang.Class object
833 is smaller or equal than the assumption made in
834 src/vmcore/class.h. */
836 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
837 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
839 /* set the VM starttime */
841 _Jv_jvm->starttime = builtin_currenttimemillis();
843 #if defined(ENABLE_JVMTI)
844 /* initialize JVMTI related **********************************************/
848 /* Fill the properties before command-line handling. */
852 /* iterate over all passed options */
854 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
868 #if SIZEOF_VOID_P == 8
869 puts("Running a 32-bit JVM is not supported on this platform.");
875 #if SIZEOF_VOID_P == 4
876 puts("Running a 64-bit JVM is not supported on this platform.");
882 /* Forget old classpath and set the argument as new
885 class_path = properties_get("java.class.path");
887 p = MNEW(char, strlen(opt_arg) + strlen("0"));
891 #if defined(ENABLE_JAVASE)
892 properties_add("java.class.path", p);
895 MFREE(class_path, char, strlen(class_path));
899 for (i = 0; i < strlen(opt_arg); i++) {
900 if (opt_arg[i] == '=') {
902 properties_add(opt_arg, opt_arg + i + 1);
907 /* if no '=' is given, just create an empty property */
909 properties_add(opt_arg, "");
914 case OPT_BOOTCLASSPATH:
915 /* Forget default bootclasspath and set the argument as
916 new boot classpath. */
918 boot_class_path = properties_get("sun.boot.class.path");
920 p = MNEW(char, strlen(opt_arg) + strlen("0"));
924 properties_add("sun.boot.class.path", p);
925 properties_add("java.boot.class.path", p);
927 MFREE(boot_class_path, char, strlen(boot_class_path));
930 case OPT_BOOTCLASSPATH_A:
931 /* Append to bootclasspath. */
933 boot_class_path = properties_get("sun.boot.class.path");
935 len = strlen(boot_class_path);
937 p = MREALLOC(boot_class_path,
941 strlen(opt_arg) + strlen("0"));
946 properties_add("sun.boot.class.path", p);
947 properties_add("java.boot.class.path", p);
950 case OPT_BOOTCLASSPATH_P:
951 /* Prepend to bootclasspath. */
953 boot_class_path = properties_get("sun.boot.class.path");
955 len = strlen(boot_class_path);
957 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
961 strcat(p, boot_class_path);
963 properties_add("sun.boot.class.path", p);
964 properties_add("java.boot.class.path", p);
966 MFREE(boot_class_path, char, len);
969 case OPT_BOOTCLASSPATH_C:
970 /* Use as Java core library, but prepend VM interface
973 boot_class_path = properties_get("sun.boot.class.path");
976 strlen(CACAO_VM_ZIP) +
983 strcpy(p, CACAO_VM_ZIP);
987 properties_add("sun.boot.class.path", p);
988 properties_add("java.boot.class.path", p);
990 MFREE(boot_class_path, char, strlen(boot_class_path));
993 #if defined(ENABLE_JVMTI)
995 /* this option exists only for compatibility reasons */
999 /* I don't know yet what Xnoagent should do. This is only for
1000 compatiblity with eclipse - motse */
1009 strlen(CACAO_LIBDIR) +
1010 strlen("/libjdwp.so=") +
1014 agentarg = MNEW(char, len);
1016 strcpy(agentarg, CACAO_LIBDIR);
1017 strcat(agentarg, "/libjdwp.so=");
1018 strcat(agentarg, &opt_arg[1]);
1035 c = opt_arg[strlen(opt_arg) - 1];
1037 if ((c == 'k') || (c == 'K')) {
1038 j = atoi(opt_arg) * 1024;
1040 } else if ((c == 'm') || (c == 'M')) {
1041 j = atoi(opt_arg) * 1024 * 1024;
1047 opt_heapmaxsize = j;
1048 else if (opt == OPT_MS)
1049 opt_heapstartsize = j;
1060 if (strcmp("class", opt_arg) == 0) {
1061 opt_verboseclass = true;
1063 else if (strcmp("gc", opt_arg) == 0) {
1064 opt_verbosegc = true;
1066 else if (strcmp("jni", opt_arg) == 0) {
1067 opt_verbosejni = true;
1069 #if !defined(NDEBUG)
1070 else if (strcmp("jit", opt_arg) == 0) {
1074 compileverbose = true;
1078 printf("Unknown -verbose option: %s\n", opt_arg);
1083 case OPT_DEBUGCOLOR:
1084 opt_debugcolor = true;
1087 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1089 opt_typecheckverbose = true;
1098 case OPT_FULLVERSION:
1102 case OPT_SHOWVERSION:
1110 #if defined(ENABLE_VERIFIER)
1116 #if defined(ENABLE_STATISTICS)
1118 opt_getcompilingtime = true;
1119 opt_getloadingtime = true;
1132 for (i = 0; i < strlen(opt_arg); i++) {
1133 switch (opt_arg[i]) {
1135 checkbounds = false;
1148 makeinitializations = false;
1151 #if !defined(NDEBUG)
1155 makeinitializations = false;
1160 opt_method = opt_arg;
1161 makeinitializations = false;
1165 opt_signature = opt_arg;
1169 case OPT_SHOW: /* Display options */
1170 for (i = 0; i < strlen(opt_arg); i++) {
1171 switch (opt_arg[i]) {
1173 showconstantpool = true;
1185 opt_showintermediate = true;
1186 compileverbose = true;
1189 #if defined(ENABLE_DISASSEMBLER)
1191 opt_showdisassemble = true;
1192 compileverbose = true;
1196 opt_shownops = true;
1201 opt_showddatasegment = true;
1210 #if defined(ENABLE_LOOP)
1216 #if defined(ENABLE_INLINING)
1217 #if defined(ENABLE_INLINING_DEBUG)
1218 case OPT_INLINE_DEBUG_ALL:
1219 opt_inline_debug_all = true;
1221 case OPT_INLINE_DEBUG_END:
1222 opt_inline_debug_end_counter = atoi(opt_arg);
1224 case OPT_INLINE_DEBUG_MIN:
1225 opt_inline_debug_min_size = atoi(opt_arg);
1227 case OPT_INLINE_DEBUG_MAX:
1228 opt_inline_debug_max_size = atoi(opt_arg);
1230 #endif /* defined(ENABLE_INLINING_DEBUG) */
1231 #if !defined(NDEBUG)
1232 case OPT_INLINE_LOG:
1233 opt_inline_debug_log = true;
1235 #endif /* !defined(NDEBUG) */
1238 opt_inlining = true;
1240 #endif /* defined(ENABLE_INLINING) */
1242 #if defined(ENABLE_IFCONV)
1248 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1263 /* Already parsed. */
1267 #if defined(ENABLE_ASSERTION)
1268 assertion_ea_da(opt_arg, true);
1273 #if defined(ENABLE_ASSERTION)
1274 assertion_ea_da(opt_arg, false);
1279 #if defined(ENABLE_ASSERTION)
1280 assertion_system_enabled = true;
1285 #if defined(ENABLE_ASSERTION)
1286 assertion_system_enabled = false;
1290 #if defined(ENABLE_PROFILING)
1291 case OPT_PROF_OPTION:
1292 /* use <= to get the last \0 too */
1294 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1295 if (opt_arg[i] == ',')
1298 if (opt_arg[i] == '\0') {
1299 if (strcmp("bb", opt_arg + j) == 0)
1303 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1307 /* set k to next char */
1320 #if defined(ENABLE_JIT)
1323 printf("-Xjit option not enabled.\n");
1329 #if defined(ENABLE_INTRP)
1332 printf("-Xint option not enabled.\n");
1337 #if defined(ENABLE_INTRP)
1338 case OPT_STATIC_SUPERS:
1339 opt_static_supers = atoi(opt_arg);
1342 case OPT_NO_DYNAMIC:
1343 opt_no_dynamic = true;
1346 case OPT_NO_REPLICATION:
1347 opt_no_replication = true;
1350 case OPT_NO_QUICKSUPER:
1351 opt_no_quicksuper = true;
1359 #if defined(ENABLE_DEBUG_FILTER)
1360 case OPT_FILTER_VERBOSECALL_INCLUDE:
1361 opt_filter_verbosecall_include = opt_arg;
1364 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1365 opt_filter_verbosecall_exclude = opt_arg;
1368 case OPT_FILTER_SHOW_METHOD:
1369 opt_filter_show_method = opt_arg;
1374 printf("Unknown option: %s\n",
1375 vm_args->options[opt_index].optionString);
1380 /* get the main class *****************************************************/
1382 if (opt_index < vm_args->nOptions) {
1383 mainstring = vm_args->options[opt_index++].optionString;
1385 /* Put the jar file into the classpath (if any). */
1387 if (opt_jar == true) {
1388 /* free old classpath */
1390 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1392 /* put jarfile into classpath */
1394 p = MNEW(char, strlen(mainstring) + strlen("0"));
1396 strcpy(p, mainstring);
1398 #if defined(ENABLE_JAVASE)
1399 properties_add("java.class.path", p);
1403 /* replace .'s with /'s in classname */
1405 for (i = strlen(mainstring) - 1; i >= 0; i--)
1406 if (mainstring[i] == '.')
1407 mainstring[i] = '/';
1411 #if defined(ENABLE_JVMTI)
1413 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1414 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1417 MFREE(agentarg, char, strlen(agentarg));
1419 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1423 /* initialize this JVM ****************************************************/
1425 vm_initializing = true;
1427 /* initialize the garbage collector */
1429 gc_init(opt_heapmaxsize, opt_heapstartsize);
1431 #if defined(ENABLE_THREADS)
1432 /* AFTER: gc_init (directly after, as this initializes the
1433 stopworldlock lock */
1438 /* install architecture dependent signal handlers */
1441 vm_abort("vm_create: signal_init failed");
1443 #if defined(ENABLE_INTRP)
1444 /* Allocate main thread stack on the Java heap. */
1447 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1448 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1452 /* AFTER: threads_preinit */
1455 vm_abort("vm_create: string_init failed");
1457 /* AFTER: threads_preinit */
1460 vm_abort("vm_create: utf8_init failed");
1462 /* AFTER: thread_preinit */
1465 vm_abort("vm_create: suck_init failed");
1467 suck_add_from_property("java.endorsed.dirs");
1469 /* Now we have all options handled and we can print the version
1472 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1477 /* AFTER: utf8_init */
1479 boot_class_path = properties_get("sun.boot.class.path");
1480 suck_add(boot_class_path);
1482 /* initialize the classcache hashtable stuff: lock, hashtable
1483 (must be done _after_ threads_preinit) */
1485 if (!classcache_init())
1486 vm_abort("vm_create: classcache_init failed");
1488 /* initialize the memory subsystem (must be done _after_
1492 vm_abort("vm_create: memory_init failed");
1494 /* initialize the finalizer stuff (must be done _after_
1497 if (!finalizer_init())
1498 vm_abort("vm_create: finalizer_init failed");
1500 /* initializes jit compiler */
1504 /* BEFORE: loader_preinit */
1508 /* AFTER: utf8_init, classcache_init */
1513 /* AFTER: loader_preinit, linker_preinit */
1520 /* AFTER: loader_init, linker_init */
1522 primitive_postinit();
1526 if (!builtin_init())
1527 vm_abort("vm_create: builtin_init failed");
1529 /* Initialize the native subsystem. */
1530 /* BEFORE: threads_init */
1533 vm_abort("vm_create: native_init failed");
1535 /* Register the native methods implemented in the VM. */
1536 /* BEFORE: threads_init */
1538 if (!nativevm_preinit())
1539 vm_abort("vm_create: nativevm_preinit failed");
1541 #if defined(ENABLE_JNI)
1542 /* Initialize the JNI subsystem (must be done _before_
1543 threads_init, as threads_init can call JNI methods
1544 (e.g. NewGlobalRef). */
1547 vm_abort("vm_create: jni_init failed");
1550 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1551 /* Initialize the local reference table for the main thread. */
1552 /* BEFORE: threads_init */
1554 if (!localref_table_init())
1555 vm_abort("vm_create: localref_table_init failed");
1558 #if defined(ENABLE_THREADS)
1559 if (!threads_init())
1560 vm_abort("vm_create: threads_init failed");
1563 /* Initialize the native VM subsystem. */
1564 /* AFTER: threads_init (at least for SUN's classes) */
1566 if (!nativevm_init())
1567 vm_abort("vm_create: nativevm_init failed");
1569 #if defined(ENABLE_PROFILING)
1570 /* initialize profiling */
1572 if (!profile_init())
1573 vm_abort("vm_create: profile_init failed");
1576 #if defined(ENABLE_THREADS)
1577 /* initialize recompilation */
1579 if (!recompile_init())
1580 vm_abort("vm_create: recompile_init failed");
1582 /* start the signal handler thread */
1584 #if defined(__LINUX__)
1585 /* XXX Remove for exact-GC. */
1586 if (threads_pthreads_implementation_nptl)
1588 if (!signal_start_thread())
1589 vm_abort("vm_create: signal_start_thread failed");
1591 /* finally, start the finalizer thread */
1593 if (!finalizer_start_thread())
1594 vm_abort("vm_create: finalizer_start_thread failed");
1596 # if !defined(NDEBUG)
1597 /* start the memory profiling thread */
1599 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1600 if (!memory_start_thread())
1601 vm_abort("vm_create: memory_start_thread failed");
1604 /* start the recompilation thread (must be done before the
1605 profiling thread) */
1607 if (!recompile_start_thread())
1608 vm_abort("vm_create: recompile_start_thread failed");
1610 # if defined(ENABLE_PROFILING)
1611 /* start the profile sampling thread */
1614 /* if (!profile_start_thread()) */
1615 /* vm_abort("vm_create: profile_start_thread failed"); */
1619 #if defined(ENABLE_JVMTI)
1620 # if defined(ENABLE_GC_CACAO)
1621 /* XXX this will not work with the new indirection cells for classloaders!!! */
1625 /* add agent library to native library hashtable */
1626 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1630 /* increment the number of VMs */
1634 /* initialization is done */
1636 vm_initializing = false;
1638 #if !defined(NDEBUG)
1639 /* Print the VM configuration after all stuff is set and the VM is
1642 if (opt_PrintConfig)
1646 /* everything's ok */
1652 /* vm_run **********************************************************************
1654 Runs the main-method of the passed class.
1656 *******************************************************************************/
1658 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1661 classinfo *mainclass;
1664 java_handle_objectarray_t *oa;
1671 #if !defined(NDEBUG)
1677 if (opt_method != NULL) {
1678 vm_compile_method();
1681 #endif /* !defined(NDEBUG) */
1683 /* should we run the main-method? */
1685 if (mainstring == NULL)
1688 /* set return value to OK */
1692 if (opt_jar == true) {
1693 /* open jar file with java.util.jar.JarFile */
1695 mainstring = vm_get_mainclass_from_jar(mainstring);
1697 if (mainstring == NULL)
1701 /* load the main class */
1703 mainutf = utf_new_char(mainstring);
1705 #if defined(ENABLE_JAVAME_CLDC1_1)
1706 mainclass = load_class_bootstrap(mainutf);
1708 mainclass = load_class_from_sysloader(mainutf);
1711 /* error loading class */
1713 e = exceptions_get_and_clear_exception();
1715 if ((e != NULL) || (mainclass == NULL)) {
1716 exceptions_throw_noclassdeffounderror_cause(e);
1717 exceptions_print_stacktrace();
1721 if (!link_class(mainclass)) {
1722 exceptions_print_stacktrace();
1726 /* find the `main' method of the main class */
1728 m = class_resolveclassmethod(mainclass,
1729 utf_new_char("main"),
1730 utf_new_char("([Ljava/lang/String;)V"),
1731 class_java_lang_Object,
1734 if (exceptions_get_exception()) {
1735 exceptions_print_stacktrace();
1739 /* there is no main method or it isn't static */
1741 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1742 exceptions_clear_exception();
1743 exceptions_throw_nosuchmethoderror(mainclass,
1744 utf_new_char("main"),
1745 utf_new_char("([Ljava/lang/String;)V"));
1747 exceptions_print_stacktrace();
1751 /* build argument array */
1753 oalength = vm_args->nOptions - opt_index;
1755 oa = builtin_anewarray(oalength, class_java_lang_String);
1757 for (i = 0; i < oalength; i++) {
1758 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1759 s = javastring_new(u);
1761 array_objectarray_element_set(oa, i, s);
1764 #ifdef TYPEINFO_DEBUG_TEST
1765 /* test the typeinfo system */
1768 /*class_showmethods(currentThread->group->header.vftbl->class); */
1770 #if defined(ENABLE_JVMTI)
1771 jvmti_set_phase(JVMTI_PHASE_LIVE);
1774 /* set ThreadMXBean variables */
1776 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1777 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1779 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1780 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1781 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1782 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1784 /* start the main thread */
1786 (void) vm_call_method(m, NULL, oa);
1788 /* exception occurred? */
1790 if (exceptions_get_exception()) {
1791 exceptions_print_stacktrace();
1795 /* unload the JavaVM */
1797 (void) vm_destroy(vm);
1805 /* vm_destroy ******************************************************************
1807 Unloads a Java VM and reclaims its resources.
1809 *******************************************************************************/
1811 s4 vm_destroy(JavaVM *vm)
1813 #if defined(ENABLE_THREADS)
1814 threads_join_all_threads();
1817 /* everything's ok */
1823 /* vm_exit *********************************************************************
1825 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1827 *******************************************************************************/
1829 void vm_exit(s4 status)
1833 /* signal that we are exiting */
1837 assert(class_java_lang_System);
1838 assert(class_java_lang_System->state & CLASS_LOADED);
1840 #if defined(ENABLE_JVMTI)
1841 if (jvmti || (dbgcom!=NULL)) {
1842 jvmti_set_phase(JVMTI_PHASE_DEAD);
1843 if (jvmti) jvmti_agentunload();
1847 if (!link_class(class_java_lang_System)) {
1848 exceptions_print_stacktrace();
1852 /* call java.lang.System.exit(I)V */
1854 m = class_resolveclassmethod(class_java_lang_System,
1855 utf_new_char("exit"),
1857 class_java_lang_Object,
1861 exceptions_print_stacktrace();
1865 /* call the exit function with passed exit status */
1867 (void) vm_call_method(m, NULL, status);
1869 /* If we had an exception, just ignore the exception and exit with
1872 vm_shutdown(status);
1876 /* vm_shutdown *****************************************************************
1878 Terminates the system immediately without freeing memory explicitly
1879 (to be used only for abnormal termination).
1881 *******************************************************************************/
1883 void vm_shutdown(s4 status)
1886 #if defined(ENABLE_STATISTICS)
1887 || opt_getcompilingtime || opt_stat
1891 log_text("CACAO terminated by shutdown");
1892 dolog("Exit status: %d\n", (s4) status);
1896 #if defined(ENABLE_JVMTI)
1897 /* terminate cacaodbgserver */
1899 pthread_mutex_lock(&dbgcomlock);
1901 pthread_mutex_unlock(&dbgcomlock);
1902 jvmti_cacaodbgserver_quit();
1910 /* vm_exit_handler *************************************************************
1912 The exit_handler function is called upon program termination.
1914 ATTENTION: Don't free system resources here! Some threads may still
1915 be running as this is called from VMRuntime.exit(). The OS does the
1918 *******************************************************************************/
1920 void vm_exit_handler(void)
1922 #if !defined(NDEBUG)
1924 class_showmethods(mainclass);
1926 if (showconstantpool)
1927 class_showconstantpool(mainclass);
1932 # if defined(ENABLE_PROFILING)
1934 profile_printstats();
1936 #endif /* !defined(NDEBUG) */
1938 #if defined(ENABLE_RT_TIMING)
1939 rt_timing_print_time_stats(stderr);
1942 #if defined(ENABLE_CYCLES_STATS)
1943 builtin_print_cycles_stats(stderr);
1944 stacktrace_print_cycles_stats(stderr);
1948 #if defined(ENABLE_STATISTICS)
1949 || opt_getcompilingtime || opt_stat
1953 log_text("CACAO terminated");
1955 #if defined(ENABLE_STATISTICS)
1958 #ifdef TYPECHECK_STATISTICS
1959 typecheck_print_statistics(get_logfile());
1963 if (opt_getcompilingtime)
1965 #endif /* defined(ENABLE_STATISTICS) */
1967 /* vm_print_profile(stderr);*/
1971 /* vm_abort ********************************************************************
1973 Prints an error message and aborts the VM.
1975 *******************************************************************************/
1977 void vm_abort(const char *text, ...)
1981 /* print the log message */
1986 log_vprint(text, ap);
1991 /* now abort the VM */
1997 /* vm_abort_disassemble ********************************************************
1999 Prints an error message, disassemble the given code range (if
2000 enabled) and aborts the VM.
2003 pc.......PC to disassemble
2004 count....number of instructions to disassemble
2006 *******************************************************************************/
2008 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2011 #if defined(ENABLE_DISASSEMBLER)
2015 /* Print debug message. */
2020 log_vprint(text, ap);
2027 #if SIZEOF_VOID_P == 8
2028 log_println("PC=0x%016lx", pc);
2030 log_println("PC=0x%08x", pc);
2033 #if defined(ENABLE_DISASSEMBLER)
2034 log_println("machine instructions at PC:");
2036 /* Disassemble the given number of instructions. */
2038 for (i = 0; i < count; i++)
2039 pc = disassinstr(pc);
2042 vm_abort("Aborting...");
2046 /* vm_get_mainclass_from_jar ***************************************************
2048 Gets the name of the main class from a JAR's manifest file.
2050 *******************************************************************************/
2052 static char *vm_get_mainclass_from_jar(char *mainstring)
2059 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2062 exceptions_print_stacktrace();
2066 /* create JarFile object */
2071 exceptions_print_stacktrace();
2075 m = class_resolveclassmethod(c,
2077 utf_java_lang_String__void,
2078 class_java_lang_Object,
2082 exceptions_print_stacktrace();
2086 s = javastring_new_from_ascii(mainstring);
2088 (void) vm_call_method(m, o, s);
2090 if (exceptions_get_exception()) {
2091 exceptions_print_stacktrace();
2095 /* get manifest object */
2097 m = class_resolveclassmethod(c,
2098 utf_new_char("getManifest"),
2099 utf_new_char("()Ljava/util/jar/Manifest;"),
2100 class_java_lang_Object,
2104 exceptions_print_stacktrace();
2108 o = vm_call_method(m, o);
2111 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2116 /* get Main Attributes */
2118 LLNI_class_get(o, c);
2120 m = class_resolveclassmethod(c,
2121 utf_new_char("getMainAttributes"),
2122 utf_new_char("()Ljava/util/jar/Attributes;"),
2123 class_java_lang_Object,
2127 exceptions_print_stacktrace();
2131 o = vm_call_method(m, o);
2134 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2139 /* get property Main-Class */
2141 LLNI_class_get(o, c);
2143 m = class_resolveclassmethod(c,
2144 utf_new_char("getValue"),
2145 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2146 class_java_lang_Object,
2150 exceptions_print_stacktrace();
2154 s = javastring_new_from_ascii("Main-Class");
2156 o = vm_call_method(m, o, s);
2159 exceptions_print_stacktrace();
2163 return javastring_tochar(o);
2167 /* vm_compile_all **************************************************************
2169 Compile all methods found in the bootclasspath.
2171 *******************************************************************************/
2173 #if !defined(NDEBUG)
2174 static void vm_compile_all(void)
2179 classcache_name_entry *nmen;
2180 classcache_class_entry *clsen;
2183 /* create all classes found in the bootclasspath */
2184 /* XXX currently only works with zip/jar's */
2186 loader_load_all_classes();
2188 /* link all classes */
2190 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2191 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2193 for (; nmen; nmen = nmen->hashlink) {
2194 /* iterate over all class entries */
2196 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2197 c = clsen->classobj;
2202 if (!(c->state & CLASS_LINKED)) {
2203 if (!link_class(c)) {
2204 fprintf(stderr, "Error linking: ");
2205 utf_fprint_printable_ascii_classname(stderr, c->name);
2206 fprintf(stderr, "\n");
2208 /* print out exception and cause */
2210 exceptions_print_current_exception();
2212 /* goto next class */
2218 /* compile all class methods */
2220 for (i = 0; i < c->methodscount; i++) {
2221 m = &(c->methods[i]);
2223 if (m->jcode != NULL) {
2224 if (!jit_compile(m)) {
2225 fprintf(stderr, "Error compiling: ");
2226 utf_fprint_printable_ascii_classname(stderr, c->name);
2227 fprintf(stderr, ".");
2228 utf_fprint_printable_ascii(stderr, m->name);
2229 utf_fprint_printable_ascii(stderr, m->descriptor);
2230 fprintf(stderr, "\n");
2232 /* print out exception and cause */
2234 exceptions_print_current_exception();
2242 #endif /* !defined(NDEBUG) */
2245 /* vm_compile_method ***********************************************************
2247 Compile a specific method.
2249 *******************************************************************************/
2251 #if !defined(NDEBUG)
2252 static void vm_compile_method(void)
2256 /* create, load and link the main class */
2258 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2260 if (mainclass == NULL)
2261 exceptions_print_stacktrace();
2263 if (!link_class(mainclass))
2264 exceptions_print_stacktrace();
2266 if (opt_signature != NULL) {
2267 m = class_resolveclassmethod(mainclass,
2268 utf_new_char(opt_method),
2269 utf_new_char(opt_signature),
2274 m = class_resolveclassmethod(mainclass,
2275 utf_new_char(opt_method),
2282 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2283 opt_method, opt_signature ? opt_signature : "");
2287 #endif /* !defined(NDEBUG) */
2290 /* vm_call_array ***************************************************************
2292 Calls a Java method with a variable number of arguments, passed via
2295 ATTENTION: This function has to be used outside the nativeworld.
2297 *******************************************************************************/
2299 #define VM_CALL_ARRAY(name, type) \
2300 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2306 assert(m->code != NULL); \
2308 md = m->parseddesc; \
2309 pv = m->code->entrypoint; \
2311 STATISTICS(count_calls_native_to_java++); \
2313 value = asm_vm_call_method##name(pv, array, md->memuse); \
2318 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2324 assert(m->code != NULL);
2327 pv = m->code->entrypoint;
2329 STATISTICS(count_calls_native_to_java++);
2331 o = asm_vm_call_method(pv, array, md->memuse);
2333 if (md->returntype.type == TYPE_VOID)
2336 return LLNI_WRAP(o);
2339 VM_CALL_ARRAY(_int, int32_t)
2340 VM_CALL_ARRAY(_long, int64_t)
2341 VM_CALL_ARRAY(_float, float)
2342 VM_CALL_ARRAY(_double, double)
2345 /* vm_call_method **************************************************************
2347 Calls a Java method with a variable number of arguments.
2349 *******************************************************************************/
2351 #define VM_CALL_METHOD(name, type) \
2352 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2358 value = vm_call_method##name##_valist(m, o, ap); \
2364 VM_CALL_METHOD(, java_handle_t *)
2365 VM_CALL_METHOD(_int, int32_t)
2366 VM_CALL_METHOD(_long, int64_t)
2367 VM_CALL_METHOD(_float, float)
2368 VM_CALL_METHOD(_double, double)
2371 /* vm_call_method_valist *******************************************************
2373 Calls a Java method with a variable number of arguments, passed via
2376 *******************************************************************************/
2378 #define VM_CALL_METHOD_VALIST(name, type) \
2379 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2386 if (m->code == NULL) \
2387 if (!jit_compile(m)) \
2390 THREAD_NATIVEWORLD_EXIT; \
2392 dumpsize = dump_size(); \
2393 array = argument_vmarray_from_valist(m, o, ap); \
2394 value = vm_call##name##_array(m, array); \
2395 dump_release(dumpsize); \
2397 THREAD_NATIVEWORLD_ENTER; \
2402 VM_CALL_METHOD_VALIST(, java_handle_t *)
2403 VM_CALL_METHOD_VALIST(_int, int32_t)
2404 VM_CALL_METHOD_VALIST(_long, int64_t)
2405 VM_CALL_METHOD_VALIST(_float, float)
2406 VM_CALL_METHOD_VALIST(_double, double)
2409 /* vm_call_method_jvalue *******************************************************
2411 Calls a Java method with a variable number of arguments, passed via
2414 *******************************************************************************/
2416 #define VM_CALL_METHOD_JVALUE(name, type) \
2417 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2418 const jvalue *args) \
2424 if (m->code == NULL) \
2425 if (!jit_compile(m)) \
2428 THREAD_NATIVEWORLD_EXIT; \
2430 dumpsize = dump_size(); \
2431 array = argument_vmarray_from_jvalue(m, o, args); \
2432 value = vm_call##name##_array(m, array); \
2433 dump_release(dumpsize); \
2435 THREAD_NATIVEWORLD_ENTER; \
2440 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2441 VM_CALL_METHOD_JVALUE(_int, int32_t)
2442 VM_CALL_METHOD_JVALUE(_long, int64_t)
2443 VM_CALL_METHOD_JVALUE(_float, float)
2444 VM_CALL_METHOD_JVALUE(_double, double)
2447 /* vm_call_method_objectarray **************************************************
2449 Calls a Java method with a variable number if arguments, passed via
2450 an objectarray of boxed values. Returns a boxed value.
2452 *******************************************************************************/
2454 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2455 java_handle_objectarray_t *params)
2459 java_handle_t *xptr;
2463 /* compile methods which are not yet compiled */
2465 if (m->code == NULL)
2466 if (!jit_compile(m))
2469 /* leave the nativeworld */
2471 THREAD_NATIVEWORLD_EXIT;
2473 /* mark start of dump memory area */
2475 dumpsize = dump_size();
2477 /* Fill the argument array from a object-array. */
2479 array = argument_vmarray_from_objectarray(m, o, params);
2481 if (array == NULL) {
2482 /* release dump area */
2484 dump_release(dumpsize);
2486 /* enter the nativeworld again */
2488 THREAD_NATIVEWORLD_ENTER;
2490 exceptions_throw_illegalargumentexception();
2495 switch (m->parseddesc->returntype.decltype) {
2496 case PRIMITIVETYPE_VOID:
2497 value.a = vm_call_array(m, array);
2500 case PRIMITIVETYPE_BOOLEAN:
2501 case PRIMITIVETYPE_BYTE:
2502 case PRIMITIVETYPE_CHAR:
2503 case PRIMITIVETYPE_SHORT:
2504 case PRIMITIVETYPE_INT:
2505 value.i = vm_call_int_array(m, array);
2508 case PRIMITIVETYPE_LONG:
2509 value.l = vm_call_long_array(m, array);
2512 case PRIMITIVETYPE_FLOAT:
2513 value.f = vm_call_float_array(m, array);
2516 case PRIMITIVETYPE_DOUBLE:
2517 value.d = vm_call_double_array(m, array);
2521 ro = vm_call_array(m, array);
2525 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2528 /* release dump area */
2530 dump_release(dumpsize);
2532 /* enter the nativeworld again */
2534 THREAD_NATIVEWORLD_ENTER;
2536 /* box the return value if necesarry */
2538 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2539 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2541 /* check for an exception */
2543 xptr = exceptions_get_exception();
2546 /* clear exception pointer, we are calling JIT code again */
2548 exceptions_clear_exception();
2550 exceptions_throw_invocationtargetexception(xptr);
2558 * These are local overrides for various environment variables in Emacs.
2559 * Please do not remove this and leave it at the end of the file, where
2560 * Emacs will automagically detect them.
2561 * ---------------------------------------------------------------------
2564 * indent-tabs-mode: t
2568 * vim:noexpandtab:sw=4:ts=4: