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 /* initialize the codegen subsystems */
1504 /* initializes jit compiler */
1508 /* BEFORE: loader_preinit */
1512 /* AFTER: utf8_init, classcache_init */
1517 /* AFTER: loader_preinit, linker_preinit */
1524 /* AFTER: loader_init, linker_init */
1526 primitive_postinit();
1530 if (!builtin_init())
1531 vm_abort("vm_create: builtin_init failed");
1533 /* Initialize the native subsystem. */
1534 /* BEFORE: threads_init */
1537 vm_abort("vm_create: native_init failed");
1539 /* Register the native methods implemented in the VM. */
1540 /* BEFORE: threads_init */
1542 if (!nativevm_preinit())
1543 vm_abort("vm_create: nativevm_preinit failed");
1545 #if defined(ENABLE_JNI)
1546 /* Initialize the JNI subsystem (must be done _before_
1547 threads_init, as threads_init can call JNI methods
1548 (e.g. NewGlobalRef). */
1551 vm_abort("vm_create: jni_init failed");
1554 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1555 /* Initialize the local reference table for the main thread. */
1556 /* BEFORE: threads_init */
1558 if (!localref_table_init())
1559 vm_abort("vm_create: localref_table_init failed");
1562 #if defined(ENABLE_THREADS)
1563 if (!threads_init())
1564 vm_abort("vm_create: threads_init failed");
1567 /* Initialize the native VM subsystem. */
1568 /* AFTER: threads_init (at least for SUN's classes) */
1570 if (!nativevm_init())
1571 vm_abort("vm_create: nativevm_init failed");
1573 #if defined(ENABLE_PROFILING)
1574 /* initialize profiling */
1576 if (!profile_init())
1577 vm_abort("vm_create: profile_init failed");
1580 #if defined(ENABLE_THREADS)
1581 /* initialize recompilation */
1583 if (!recompile_init())
1584 vm_abort("vm_create: recompile_init failed");
1586 /* start the signal handler thread */
1588 #if defined(__LINUX__)
1589 /* XXX Remove for exact-GC. */
1590 if (threads_pthreads_implementation_nptl)
1592 if (!signal_start_thread())
1593 vm_abort("vm_create: signal_start_thread failed");
1595 /* finally, start the finalizer thread */
1597 if (!finalizer_start_thread())
1598 vm_abort("vm_create: finalizer_start_thread failed");
1600 # if !defined(NDEBUG)
1601 /* start the memory profiling thread */
1603 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1604 if (!memory_start_thread())
1605 vm_abort("vm_create: memory_start_thread failed");
1608 /* start the recompilation thread (must be done before the
1609 profiling thread) */
1611 if (!recompile_start_thread())
1612 vm_abort("vm_create: recompile_start_thread failed");
1614 # if defined(ENABLE_PROFILING)
1615 /* start the profile sampling thread */
1618 /* if (!profile_start_thread()) */
1619 /* vm_abort("vm_create: profile_start_thread failed"); */
1623 #if defined(ENABLE_JVMTI)
1624 # if defined(ENABLE_GC_CACAO)
1625 /* XXX this will not work with the new indirection cells for classloaders!!! */
1629 /* add agent library to native library hashtable */
1630 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1634 /* increment the number of VMs */
1638 /* initialization is done */
1640 vm_initializing = false;
1642 #if !defined(NDEBUG)
1643 /* Print the VM configuration after all stuff is set and the VM is
1646 if (opt_PrintConfig)
1650 /* everything's ok */
1656 /* vm_run **********************************************************************
1658 Runs the main-method of the passed class.
1660 *******************************************************************************/
1662 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1665 classinfo *mainclass;
1668 java_handle_objectarray_t *oa;
1675 #if !defined(NDEBUG)
1681 if (opt_method != NULL) {
1682 vm_compile_method();
1685 #endif /* !defined(NDEBUG) */
1687 /* should we run the main-method? */
1689 if (mainstring == NULL)
1692 /* set return value to OK */
1696 if (opt_jar == true) {
1697 /* open jar file with java.util.jar.JarFile */
1699 mainstring = vm_get_mainclass_from_jar(mainstring);
1701 if (mainstring == NULL)
1705 /* load the main class */
1707 mainutf = utf_new_char(mainstring);
1709 #if defined(ENABLE_JAVAME_CLDC1_1)
1710 mainclass = load_class_bootstrap(mainutf);
1712 mainclass = load_class_from_sysloader(mainutf);
1715 /* error loading class */
1717 e = exceptions_get_and_clear_exception();
1719 if ((e != NULL) || (mainclass == NULL)) {
1720 exceptions_throw_noclassdeffounderror_cause(e);
1721 exceptions_print_stacktrace();
1725 if (!link_class(mainclass)) {
1726 exceptions_print_stacktrace();
1730 /* find the `main' method of the main class */
1732 m = class_resolveclassmethod(mainclass,
1733 utf_new_char("main"),
1734 utf_new_char("([Ljava/lang/String;)V"),
1735 class_java_lang_Object,
1738 if (exceptions_get_exception()) {
1739 exceptions_print_stacktrace();
1743 /* there is no main method or it isn't static */
1745 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1746 exceptions_clear_exception();
1747 exceptions_throw_nosuchmethoderror(mainclass,
1748 utf_new_char("main"),
1749 utf_new_char("([Ljava/lang/String;)V"));
1751 exceptions_print_stacktrace();
1755 /* build argument array */
1757 oalength = vm_args->nOptions - opt_index;
1759 oa = builtin_anewarray(oalength, class_java_lang_String);
1761 for (i = 0; i < oalength; i++) {
1762 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1763 s = javastring_new(u);
1765 array_objectarray_element_set(oa, i, s);
1768 #ifdef TYPEINFO_DEBUG_TEST
1769 /* test the typeinfo system */
1772 /*class_showmethods(currentThread->group->header.vftbl->class); */
1774 #if defined(ENABLE_JVMTI)
1775 jvmti_set_phase(JVMTI_PHASE_LIVE);
1778 /* set ThreadMXBean variables */
1780 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1781 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1783 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1784 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1785 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1786 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1788 /* start the main thread */
1790 (void) vm_call_method(m, NULL, oa);
1792 /* exception occurred? */
1794 if (exceptions_get_exception()) {
1795 exceptions_print_stacktrace();
1799 /* unload the JavaVM */
1801 (void) vm_destroy(vm);
1809 /* vm_destroy ******************************************************************
1811 Unloads a Java VM and reclaims its resources.
1813 *******************************************************************************/
1815 s4 vm_destroy(JavaVM *vm)
1817 #if defined(ENABLE_THREADS)
1818 threads_join_all_threads();
1821 /* everything's ok */
1827 /* vm_exit *********************************************************************
1829 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1831 *******************************************************************************/
1833 void vm_exit(s4 status)
1837 /* signal that we are exiting */
1841 assert(class_java_lang_System);
1842 assert(class_java_lang_System->state & CLASS_LOADED);
1844 #if defined(ENABLE_JVMTI)
1845 if (jvmti || (dbgcom!=NULL)) {
1846 jvmti_set_phase(JVMTI_PHASE_DEAD);
1847 if (jvmti) jvmti_agentunload();
1851 if (!link_class(class_java_lang_System)) {
1852 exceptions_print_stacktrace();
1856 /* call java.lang.System.exit(I)V */
1858 m = class_resolveclassmethod(class_java_lang_System,
1859 utf_new_char("exit"),
1861 class_java_lang_Object,
1865 exceptions_print_stacktrace();
1869 /* call the exit function with passed exit status */
1871 (void) vm_call_method(m, NULL, status);
1873 /* If we had an exception, just ignore the exception and exit with
1876 vm_shutdown(status);
1880 /* vm_shutdown *****************************************************************
1882 Terminates the system immediately without freeing memory explicitly
1883 (to be used only for abnormal termination).
1885 *******************************************************************************/
1887 void vm_shutdown(s4 status)
1890 #if defined(ENABLE_STATISTICS)
1891 || opt_getcompilingtime || opt_stat
1895 log_text("CACAO terminated by shutdown");
1896 dolog("Exit status: %d\n", (s4) status);
1900 #if defined(ENABLE_JVMTI)
1901 /* terminate cacaodbgserver */
1903 pthread_mutex_lock(&dbgcomlock);
1905 pthread_mutex_unlock(&dbgcomlock);
1906 jvmti_cacaodbgserver_quit();
1914 /* vm_exit_handler *************************************************************
1916 The exit_handler function is called upon program termination.
1918 ATTENTION: Don't free system resources here! Some threads may still
1919 be running as this is called from VMRuntime.exit(). The OS does the
1922 *******************************************************************************/
1924 void vm_exit_handler(void)
1926 #if !defined(NDEBUG)
1928 class_showmethods(mainclass);
1930 if (showconstantpool)
1931 class_showconstantpool(mainclass);
1936 # if defined(ENABLE_PROFILING)
1938 profile_printstats();
1940 #endif /* !defined(NDEBUG) */
1942 #if defined(ENABLE_RT_TIMING)
1943 rt_timing_print_time_stats(stderr);
1946 #if defined(ENABLE_CYCLES_STATS)
1947 builtin_print_cycles_stats(stderr);
1948 stacktrace_print_cycles_stats(stderr);
1952 #if defined(ENABLE_STATISTICS)
1953 || opt_getcompilingtime || opt_stat
1957 log_text("CACAO terminated");
1959 #if defined(ENABLE_STATISTICS)
1962 #ifdef TYPECHECK_STATISTICS
1963 typecheck_print_statistics(get_logfile());
1967 if (opt_getcompilingtime)
1969 #endif /* defined(ENABLE_STATISTICS) */
1971 /* vm_print_profile(stderr);*/
1975 /* vm_abort ********************************************************************
1977 Prints an error message and aborts the VM.
1979 *******************************************************************************/
1981 void vm_abort(const char *text, ...)
1985 /* print the log message */
1990 log_vprint(text, ap);
1995 /* now abort the VM */
2001 /* vm_abort_disassemble ********************************************************
2003 Prints an error message, disassemble the given code range (if
2004 enabled) and aborts the VM.
2007 pc.......PC to disassemble
2008 count....number of instructions to disassemble
2010 *******************************************************************************/
2012 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2015 #if defined(ENABLE_DISASSEMBLER)
2019 /* Print debug message. */
2024 log_vprint(text, ap);
2031 #if SIZEOF_VOID_P == 8
2032 log_println("PC=0x%016lx", pc);
2034 log_println("PC=0x%08x", pc);
2037 #if defined(ENABLE_DISASSEMBLER)
2038 log_println("machine instructions at PC:");
2040 /* Disassemble the given number of instructions. */
2042 for (i = 0; i < count; i++)
2043 pc = disassinstr(pc);
2046 vm_abort("Aborting...");
2050 /* vm_get_mainclass_from_jar ***************************************************
2052 Gets the name of the main class from a JAR's manifest file.
2054 *******************************************************************************/
2056 static char *vm_get_mainclass_from_jar(char *mainstring)
2063 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2066 exceptions_print_stacktrace();
2070 /* create JarFile object */
2075 exceptions_print_stacktrace();
2079 m = class_resolveclassmethod(c,
2081 utf_java_lang_String__void,
2082 class_java_lang_Object,
2086 exceptions_print_stacktrace();
2090 s = javastring_new_from_ascii(mainstring);
2092 (void) vm_call_method(m, o, s);
2094 if (exceptions_get_exception()) {
2095 exceptions_print_stacktrace();
2099 /* get manifest object */
2101 m = class_resolveclassmethod(c,
2102 utf_new_char("getManifest"),
2103 utf_new_char("()Ljava/util/jar/Manifest;"),
2104 class_java_lang_Object,
2108 exceptions_print_stacktrace();
2112 o = vm_call_method(m, o);
2115 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2120 /* get Main Attributes */
2122 LLNI_class_get(o, c);
2124 m = class_resolveclassmethod(c,
2125 utf_new_char("getMainAttributes"),
2126 utf_new_char("()Ljava/util/jar/Attributes;"),
2127 class_java_lang_Object,
2131 exceptions_print_stacktrace();
2135 o = vm_call_method(m, o);
2138 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2143 /* get property Main-Class */
2145 LLNI_class_get(o, c);
2147 m = class_resolveclassmethod(c,
2148 utf_new_char("getValue"),
2149 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2150 class_java_lang_Object,
2154 exceptions_print_stacktrace();
2158 s = javastring_new_from_ascii("Main-Class");
2160 o = vm_call_method(m, o, s);
2163 exceptions_print_stacktrace();
2167 return javastring_tochar(o);
2171 /* vm_compile_all **************************************************************
2173 Compile all methods found in the bootclasspath.
2175 *******************************************************************************/
2177 #if !defined(NDEBUG)
2178 static void vm_compile_all(void)
2183 classcache_name_entry *nmen;
2184 classcache_class_entry *clsen;
2187 /* create all classes found in the bootclasspath */
2188 /* XXX currently only works with zip/jar's */
2190 loader_load_all_classes();
2192 /* link all classes */
2194 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2195 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2197 for (; nmen; nmen = nmen->hashlink) {
2198 /* iterate over all class entries */
2200 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2201 c = clsen->classobj;
2206 if (!(c->state & CLASS_LINKED)) {
2207 if (!link_class(c)) {
2208 fprintf(stderr, "Error linking: ");
2209 utf_fprint_printable_ascii_classname(stderr, c->name);
2210 fprintf(stderr, "\n");
2212 /* print out exception and cause */
2214 exceptions_print_current_exception();
2216 /* goto next class */
2222 /* compile all class methods */
2224 for (i = 0; i < c->methodscount; i++) {
2225 m = &(c->methods[i]);
2227 if (m->jcode != NULL) {
2228 if (!jit_compile(m)) {
2229 fprintf(stderr, "Error compiling: ");
2230 utf_fprint_printable_ascii_classname(stderr, c->name);
2231 fprintf(stderr, ".");
2232 utf_fprint_printable_ascii(stderr, m->name);
2233 utf_fprint_printable_ascii(stderr, m->descriptor);
2234 fprintf(stderr, "\n");
2236 /* print out exception and cause */
2238 exceptions_print_current_exception();
2246 #endif /* !defined(NDEBUG) */
2249 /* vm_compile_method ***********************************************************
2251 Compile a specific method.
2253 *******************************************************************************/
2255 #if !defined(NDEBUG)
2256 static void vm_compile_method(void)
2260 /* create, load and link the main class */
2262 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2264 if (mainclass == NULL)
2265 exceptions_print_stacktrace();
2267 if (!link_class(mainclass))
2268 exceptions_print_stacktrace();
2270 if (opt_signature != NULL) {
2271 m = class_resolveclassmethod(mainclass,
2272 utf_new_char(opt_method),
2273 utf_new_char(opt_signature),
2278 m = class_resolveclassmethod(mainclass,
2279 utf_new_char(opt_method),
2286 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2287 opt_method, opt_signature ? opt_signature : "");
2291 #endif /* !defined(NDEBUG) */
2294 /* vm_call_array ***************************************************************
2296 Calls a Java method with a variable number of arguments, passed via
2299 ATTENTION: This function has to be used outside the nativeworld.
2301 *******************************************************************************/
2303 #define VM_CALL_ARRAY(name, type) \
2304 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2310 assert(m->code != NULL); \
2312 md = m->parseddesc; \
2313 pv = m->code->entrypoint; \
2315 STATISTICS(count_calls_native_to_java++); \
2317 value = asm_vm_call_method##name(pv, array, md->memuse); \
2322 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2328 assert(m->code != NULL);
2331 pv = m->code->entrypoint;
2333 STATISTICS(count_calls_native_to_java++);
2335 o = asm_vm_call_method(pv, array, md->memuse);
2337 if (md->returntype.type == TYPE_VOID)
2340 return LLNI_WRAP(o);
2343 VM_CALL_ARRAY(_int, int32_t)
2344 VM_CALL_ARRAY(_long, int64_t)
2345 VM_CALL_ARRAY(_float, float)
2346 VM_CALL_ARRAY(_double, double)
2349 /* vm_call_method **************************************************************
2351 Calls a Java method with a variable number of arguments.
2353 *******************************************************************************/
2355 #define VM_CALL_METHOD(name, type) \
2356 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2362 value = vm_call_method##name##_valist(m, o, ap); \
2368 VM_CALL_METHOD(, java_handle_t *)
2369 VM_CALL_METHOD(_int, int32_t)
2370 VM_CALL_METHOD(_long, int64_t)
2371 VM_CALL_METHOD(_float, float)
2372 VM_CALL_METHOD(_double, double)
2375 /* vm_call_method_valist *******************************************************
2377 Calls a Java method with a variable number of arguments, passed via
2380 *******************************************************************************/
2382 #define VM_CALL_METHOD_VALIST(name, type) \
2383 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2390 if (m->code == NULL) \
2391 if (!jit_compile(m)) \
2394 THREAD_NATIVEWORLD_EXIT; \
2396 dumpsize = dump_size(); \
2397 array = argument_vmarray_from_valist(m, o, ap); \
2398 value = vm_call##name##_array(m, array); \
2399 dump_release(dumpsize); \
2401 THREAD_NATIVEWORLD_ENTER; \
2406 VM_CALL_METHOD_VALIST(, java_handle_t *)
2407 VM_CALL_METHOD_VALIST(_int, int32_t)
2408 VM_CALL_METHOD_VALIST(_long, int64_t)
2409 VM_CALL_METHOD_VALIST(_float, float)
2410 VM_CALL_METHOD_VALIST(_double, double)
2413 /* vm_call_method_jvalue *******************************************************
2415 Calls a Java method with a variable number of arguments, passed via
2418 *******************************************************************************/
2420 #define VM_CALL_METHOD_JVALUE(name, type) \
2421 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2422 const jvalue *args) \
2428 if (m->code == NULL) \
2429 if (!jit_compile(m)) \
2432 THREAD_NATIVEWORLD_EXIT; \
2434 dumpsize = dump_size(); \
2435 array = argument_vmarray_from_jvalue(m, o, args); \
2436 value = vm_call##name##_array(m, array); \
2437 dump_release(dumpsize); \
2439 THREAD_NATIVEWORLD_ENTER; \
2444 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2445 VM_CALL_METHOD_JVALUE(_int, int32_t)
2446 VM_CALL_METHOD_JVALUE(_long, int64_t)
2447 VM_CALL_METHOD_JVALUE(_float, float)
2448 VM_CALL_METHOD_JVALUE(_double, double)
2451 /* vm_call_method_objectarray **************************************************
2453 Calls a Java method with a variable number if arguments, passed via
2454 an objectarray of boxed values. Returns a boxed value.
2456 *******************************************************************************/
2458 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2459 java_handle_objectarray_t *params)
2463 java_handle_t *xptr;
2467 /* compile methods which are not yet compiled */
2469 if (m->code == NULL)
2470 if (!jit_compile(m))
2473 /* leave the nativeworld */
2475 THREAD_NATIVEWORLD_EXIT;
2477 /* mark start of dump memory area */
2479 dumpsize = dump_size();
2481 /* Fill the argument array from a object-array. */
2483 array = argument_vmarray_from_objectarray(m, o, params);
2485 if (array == NULL) {
2486 /* release dump area */
2488 dump_release(dumpsize);
2490 /* enter the nativeworld again */
2492 THREAD_NATIVEWORLD_ENTER;
2494 exceptions_throw_illegalargumentexception();
2499 switch (m->parseddesc->returntype.decltype) {
2500 case PRIMITIVETYPE_VOID:
2501 value.a = vm_call_array(m, array);
2504 case PRIMITIVETYPE_BOOLEAN:
2505 case PRIMITIVETYPE_BYTE:
2506 case PRIMITIVETYPE_CHAR:
2507 case PRIMITIVETYPE_SHORT:
2508 case PRIMITIVETYPE_INT:
2509 value.i = vm_call_int_array(m, array);
2512 case PRIMITIVETYPE_LONG:
2513 value.l = vm_call_long_array(m, array);
2516 case PRIMITIVETYPE_FLOAT:
2517 value.f = vm_call_float_array(m, array);
2520 case PRIMITIVETYPE_DOUBLE:
2521 value.d = vm_call_double_array(m, array);
2525 ro = vm_call_array(m, array);
2529 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2532 /* release dump area */
2534 dump_release(dumpsize);
2536 /* enter the nativeworld again */
2538 THREAD_NATIVEWORLD_ENTER;
2540 /* box the return value if necesarry */
2542 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2543 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2545 /* check for an exception */
2547 xptr = exceptions_get_exception();
2550 /* clear exception pointer, we are calling JIT code again */
2552 exceptions_clear_exception();
2554 exceptions_throw_invocationtargetexception(xptr);
2562 * These are local overrides for various environment variables in Emacs.
2563 * Please do not remove this and leave it at the end of the file, where
2564 * Emacs will automagically detect them.
2565 * ---------------------------------------------------------------------
2568 * indent-tabs-mode: t
2572 * vim:noexpandtab:sw=4:ts=4: