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"
67 #include "vm/builtin.h"
68 #include "vm/exceptions.h"
69 #include "vm/finalizer.h"
70 #include "vm/global.h"
71 #include "vm/initialize.h"
72 #include "vm/package.h"
73 #include "vm/primitive.h"
74 #include "vm/properties.h"
75 #include "vm/signallocal.h"
76 #include "vm/stringlocal.h"
79 #include "vm/jit/argument.h"
80 #include "vm/jit/asmpart.h"
82 #if defined(ENABLE_DISASSEMBLER)
83 # include "vm/jit/disass.h"
86 #include "vm/jit/jit.h"
87 #include "vm/jit/md.h"
89 #if defined(ENABLE_PROFILING)
90 # include "vm/jit/optimizing/profile.h"
93 #include "vm/jit/optimizing/recompile.h"
95 #include "vmcore/classcache.h"
96 #include "vmcore/options.h"
97 #include "vmcore/statistics.h"
98 #include "vmcore/suck.h"
100 #if defined(ENABLE_JVMTI)
101 # include "native/jvmti/cacaodbg.h"
104 #if defined(ENABLE_VMLOG)
105 #include <vmlog_cacao.h>
109 /* Invocation API variables ***************************************************/
111 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
112 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
115 /* global variables ***********************************************************/
117 s4 vms = 0; /* number of VMs created */
119 bool vm_initializing = false;
120 bool vm_exiting = false;
122 char *mainstring = NULL;
123 classinfo *mainclass = NULL;
125 #if defined(ENABLE_INTRP)
126 u1 *intrp_main_stack = NULL;
130 /* define heap sizes **********************************************************/
132 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
133 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
134 #define STACK_SIZE 128 * 1024 /* default 64kB */
137 /* define command line options ************************************************/
168 /* Java non-standard options */
179 #if defined(ENABLE_PROFILING)
192 #if defined(ENABLE_STATISTICS)
209 #if defined(ENABLE_VERIFIER)
211 #if defined(TYPECHECK_VERBOSE)
214 #endif /* defined(ENABLE_VERIFIER) */
216 /* optimization options */
218 #if defined(ENABLE_LOOP)
222 #if defined(ENABLE_IFCONV)
226 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
230 #if defined(ENABLE_INLINING)
235 #if defined(ENABLE_INLINING_DEBUG)
236 OPT_INLINE_DEBUG_ALL,
237 OPT_INLINE_DEBUG_END,
238 OPT_INLINE_DEBUG_MIN,
239 OPT_INLINE_DEBUG_MAX,
240 #endif /* defined(ENABLE_INLINING_DEBUG) */
241 #endif /* defined(ENABLE_INLINING) */
243 #if defined(ENABLE_INTRP)
244 /* interpreter options */
263 #if defined(ENABLE_DEBUG_FILTER)
264 OPT_FILTER_VERBOSECALL_INCLUDE,
265 OPT_FILTER_VERBOSECALL_EXCLUDE,
266 OPT_FILTER_SHOW_METHOD,
273 opt_struct opts[] = {
274 { "foo", false, OPT_FOO },
278 { "jar", false, OPT_JAR },
280 { "d32", false, OPT_D32 },
281 { "d64", false, OPT_D64 },
282 { "client", false, OPT_IGNORE },
283 { "server", false, OPT_IGNORE },
284 { "jvm", false, OPT_IGNORE },
285 { "hotspot", false, OPT_IGNORE },
287 { "classpath", true, OPT_CLASSPATH },
288 { "cp", true, OPT_CLASSPATH },
289 { "D", true, OPT_D },
290 { "version", false, OPT_VERSION },
291 { "showversion", false, OPT_SHOWVERSION },
292 { "fullversion", false, OPT_FULLVERSION },
293 { "help", false, OPT_HELP },
294 { "?", false, OPT_HELP },
295 { "X", false, OPT_X },
296 { "XX:", true, OPT_XX },
298 { "ea:", true, OPT_EA },
299 { "da:", true, OPT_DA },
300 { "ea", false, OPT_EA },
301 { "da", false, OPT_DA },
303 { "esa", false, OPT_ESA },
304 { "enablesystemassertions", false, OPT_ESA },
305 { "dsa", false, OPT_DSA },
306 { "disablesystemassertions", false, OPT_DSA },
308 { "noasyncgc", false, OPT_IGNORE },
309 #if defined(ENABLE_VERIFIER)
310 { "noverify", false, OPT_NOVERIFY },
311 { "Xverify:none", false, OPT_NOVERIFY },
313 { "v", false, OPT_VERBOSE1 },
314 { "verbose:", true, OPT_VERBOSE },
316 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
317 { "verbosetc", false, OPT_VERBOSETC },
319 #if defined(__ALPHA__)
320 { "noieee", false, OPT_NOIEEE },
322 #if defined(ENABLE_STATISTICS)
323 { "time", false, OPT_TIME },
324 { "stat", false, OPT_STAT },
326 { "log", true, OPT_LOG },
327 { "c", true, OPT_CHECK },
328 { "l", false, OPT_LOAD },
331 { "all", false, OPT_ALL },
332 { "sig", true, OPT_SIGNATURE },
335 #if defined(ENABLE_LOOP)
336 { "oloop", false, OPT_OLOOP },
338 #if defined(ENABLE_IFCONV)
339 { "ifconv", false, OPT_IFCONV },
341 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
342 { "lsra", false, OPT_LSRA },
345 #if defined(ENABLE_INTRP)
346 /* interpreter options */
348 { "trace", false, OPT_TRACE },
349 { "static-supers", true, OPT_STATIC_SUPERS },
350 { "no-dynamic", false, OPT_NO_DYNAMIC },
351 { "no-replication", false, OPT_NO_REPLICATION },
352 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
355 /* JVMTI Agent Command Line Options */
357 { "agentlib:", true, OPT_AGENTLIB },
358 { "agentpath:", true, OPT_AGENTPATH },
361 /* Java non-standard options */
363 { "Xjit", false, OPT_JIT },
364 { "Xint", false, OPT_INTRP },
365 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
366 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
367 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
368 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
371 { "Xdebug", false, OPT_DEBUG },
372 { "Xnoagent", false, OPT_NOAGENT },
373 { "Xrunjdwp", true, OPT_XRUNJDWP },
376 { "Xms", true, OPT_MS },
377 { "ms", true, OPT_MS },
378 { "Xmx", true, OPT_MX },
379 { "mx", true, OPT_MX },
380 { "Xss", true, OPT_SS },
381 { "ss", true, OPT_SS },
383 #if defined(ENABLE_PROFILING)
384 { "Xprof:", true, OPT_PROF_OPTION },
385 { "Xprof", false, OPT_PROF },
388 /* inlining options */
390 #if defined(ENABLE_INLINING)
391 #if defined(ENABLE_INLINING_DEBUG)
392 { "ia", false, OPT_INLINE_DEBUG_ALL },
393 { "ii", true, OPT_INLINE_DEBUG_MIN },
394 { "im", true, OPT_INLINE_DEBUG_MAX },
395 { "ie", true, OPT_INLINE_DEBUG_END },
396 #endif /* defined(ENABLE_INLINING_DEBUG) */
398 { "il", false, OPT_INLINE_LOG },
400 { "i", false, OPT_INLINING },
401 #endif /* defined(ENABLE_INLINING) */
403 /* keep these at the end of the list */
406 { "m", true, OPT_METHOD },
409 { "s", true, OPT_SHOW },
410 { "debug-color", false, OPT_DEBUGCOLOR },
412 #if defined(ENABLE_DEBUG_FILTER)
413 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
414 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
415 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
422 /* usage ***********************************************************************
424 Prints the correct usage syntax to stdout.
426 *******************************************************************************/
430 puts("Usage: cacao [-options] classname [arguments]");
431 puts(" (to run a class file)");
432 puts(" or cacao [-options] -jar jarfile [arguments]");
433 puts(" (to run a standalone jar file)\n");
435 puts("where options include:");
436 puts(" -d32 use 32-bit data model if available");
437 puts(" -d64 use 64-bit data model if available");
438 puts(" -client compatibility (currently ignored)");
439 puts(" -server compatibility (currently ignored)");
440 puts(" -jvm compatibility (currently ignored)");
441 puts(" -hotspot compatibility (currently ignored)\n");
443 puts(" -cp <path> specify a path to look for classes");
444 puts(" -classpath <path> specify a path to look for classes");
445 puts(" -D<name>=<value> add an entry to the property list");
446 puts(" -verbose[:class|gc|jni] enable specific verbose output");
447 puts(" -version print product version and exit");
448 puts(" -fullversion print jpackage-compatible product version and exit");
449 puts(" -showversion print product version and continue");
450 puts(" -help, -? print this help message");
451 puts(" -X print help on non-standard Java options");
452 puts(" -XX print help on debugging options");
453 puts(" -ea[:<packagename>...|:<classname>]");
454 puts(" -enableassertions[:<packagename>...|:<classname>]");
455 puts(" enable assertions with specified granularity");
456 puts(" -da[:<packagename>...|:<classname>]");
457 puts(" -disableassertions[:<packagename>...|:<classname>]");
458 puts(" disable assertions with specified granularity");
459 puts(" -esa | -enablesystemassertions");
460 puts(" enable system assertions");
461 puts(" -dsa | -disablesystemassertions");
462 puts(" disable system assertions");
465 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
466 puts (" for jdwp help use: -agentlib:jdwp=help");
467 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
470 /* exit with error code */
476 static void Xusage(void)
478 #if defined(ENABLE_JIT)
479 puts(" -Xjit JIT mode execution (default)");
481 #if defined(ENABLE_INTRP)
482 puts(" -Xint interpreter mode execution");
484 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
485 puts(" value is set as bootstrap class path");
486 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
487 puts(" value is appended to the bootstrap class path");
488 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
489 puts(" value is prepended to the bootstrap class path");
490 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
491 puts(" value is used as Java core library, but the");
492 puts(" hardcoded VM interface classes are prepended");
493 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
494 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
495 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
497 #if defined(ENABLE_PROFILING)
498 puts(" -Xprof[:bb] collect and print profiling data");
501 #if defined(ENABLE_JVMTI)
502 /* -Xdebug option depend on gnu classpath JDWP options. options:
503 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
504 puts(" -Xdebug enable remote debugging\n");
505 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
506 puts(" enable remote debugging\n");
509 /* exit with error code */
516 static void XXusage(void)
518 puts(" -v write state-information");
520 puts(" -verbose:jit enable specific verbose output");
521 puts(" -debug-color colored output for ANSI terms");
523 #ifdef TYPECHECK_VERBOSE
524 puts(" -verbosetc write debug messages while typechecking");
526 #if defined(__ALPHA__)
527 puts(" -noieee don't use ieee compliant arithmetic");
529 #if defined(ENABLE_VERIFIER)
530 puts(" -noverify don't verify classfiles");
532 #if defined(ENABLE_STATISTICS)
533 puts(" -time measure the runtime");
534 puts(" -stat detailed compiler statistics");
536 puts(" -log logfile specify a name for the logfile");
537 puts(" -c(heck)b(ounds) don't check array bounds");
538 puts(" s(ync) don't check for synchronization");
539 #if defined(ENABLE_LOOP)
540 puts(" -oloop optimize array accesses in loops");
542 puts(" -l don't start the class after loading");
544 puts(" -all compile all methods, no execution");
545 puts(" -m compile only a specific method");
546 puts(" -sig specify signature for a specific method");
549 puts(" -s... show...");
550 puts(" (c)onstants the constant pool");
551 puts(" (m)ethods class fields and methods");
552 puts(" (u)tf the utf - hash");
553 puts(" (i)ntermediate intermediate representation");
554 #if defined(ENABLE_DISASSEMBLER)
555 puts(" (a)ssembler disassembled listing");
556 puts(" n(o)ps show NOPs in disassembler output");
558 puts(" (d)atasegment data segment listing");
560 #if defined(ENABLE_INLINING)
561 puts(" -i activate inlining");
563 puts(" -il log inlining");
565 #if defined(ENABLE_INLINING_DEBUG)
566 puts(" -ia use inlining for all methods");
567 puts(" -ii <size> set minimum size for inlined result");
568 puts(" -im <size> set maximum size for inlined result");
569 puts(" -ie <number> stop inlining after the given number of roots");
570 #endif /* defined(ENABLE_INLINING_DEBUG) */
571 #endif /* defined(ENABLE_INLINING) */
573 #if defined(ENABLE_IFCONV)
574 puts(" -ifconv use if-conversion");
576 #if defined(ENABLE_LSRA)
577 puts(" -lsra use linear scan register allocation");
579 #if defined(ENABLE_SSA)
580 puts(" -lsra use linear scan register allocation (with SSA)");
582 #if defined(ENABLE_DEBUG_FILTER)
583 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
584 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
585 puts(" -XXfm <regex> filter for show options");
587 /* exit with error code */
594 /* version *********************************************************************
596 Only prints cacao version information.
598 *******************************************************************************/
600 static void version(bool opt_exit)
602 puts("java version \""JAVA_VERSION"\"");
603 puts("CACAO version "VERSION"");
605 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
606 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
607 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
608 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
610 puts("This program is free software; you can redistribute it and/or");
611 puts("modify it under the terms of the GNU General Public License as");
612 puts("published by the Free Software Foundation; either version 2, or (at");
613 puts("your option) any later version.\n");
615 puts("This program is distributed in the hope that it will be useful, but");
616 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
617 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
618 puts("General Public License for more details.");
620 /* exit normally, if requested */
627 /* fullversion *****************************************************************
629 Prints a Sun compatible version information (required e.g. by
630 jpackage, www.jpackage.org).
632 *******************************************************************************/
634 static void fullversion(void)
636 puts("java full version \"cacao-"JAVA_VERSION"\"");
644 static void vm_printconfig(void)
646 puts("Configure/Build options:\n");
647 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
648 #if defined(__VERSION__)
649 puts(" CC : "VERSION_CC" ("__VERSION__")");
651 puts(" CC : "VERSION_CC"");
653 puts(" CFLAGS : "VERSION_CFLAGS"\n");
655 puts("Default variables:\n");
656 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
657 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
658 printf(" stack size : %d\n", STACK_SIZE);
660 #if defined(WITH_JRE_LAYOUT)
661 /* When we're building with JRE-layout, the default paths are the
662 same as the runtime paths. */
664 # if defined(WITH_CLASSPATH_GNU)
665 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
666 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
667 # elif defined(WITH_CLASSPATH_SUN)
668 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
669 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
675 puts("Runtime variables:\n");
676 printf(" maximum heap size : %d\n", opt_heapmaxsize);
677 printf(" initial heap size : %d\n", opt_heapstartsize);
678 printf(" stack size : %d\n", opt_stacksize);
680 #if defined(WITH_CLASSPATH_GNU)
681 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
682 #elif defined(WITH_CLASSPATH_SUN)
683 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
686 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
687 printf(" java.class.path : %s\n", properties_get("java.class.path"));
691 /* forward declarations *******************************************************/
693 static char *vm_get_mainclass_from_jar(char *mainstring);
695 static void vm_compile_all(void);
696 static void vm_compile_method(void);
700 /* vm_createjvm ****************************************************************
702 Implementation for JNI_CreateJavaVM.
704 *******************************************************************************/
706 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
708 JavaVMInitArgs *_vm_args;
712 /* get the arguments for the new JVM */
714 _vm_args = (JavaVMInitArgs *) vm_args;
716 /* get the VM and Env tables (must be set before vm_create) */
718 env = NEW(_Jv_JNIEnv);
720 #if defined(ENABLE_JNI)
721 env->env = &_Jv_JNINativeInterface;
724 /* XXX Set the global variable. Maybe we should do that differently. */
728 /* create and fill a JavaVM structure */
730 vm = NEW(_Jv_JavaVM);
732 #if defined(ENABLE_JNI)
733 vm->functions = &_Jv_JNIInvokeInterface;
736 /* XXX Set the global variable. Maybe we should do that differently. */
737 /* XXX JVMTI Agents needs a JavaVM */
741 /* actually create the JVM */
743 if (!vm_create(_vm_args))
746 /* now return the values */
748 *p_vm = (JavaVM *) vm;
749 *p_env = (void *) env;
754 /* release allocated memory */
756 FREE(env, _Jv_JNIEnv);
757 FREE(vm, _Jv_JavaVM);
763 /* vm_create *******************************************************************
765 Creates a JVM. Called by vm_createjvm.
767 *******************************************************************************/
769 bool vm_create(JavaVMInitArgs *vm_args)
773 char *boot_class_path;
780 #if defined(ENABLE_JVMTI)
782 char *libname, *agentarg;
783 bool jdwp,agentbypath;
784 jdwp = agentbypath = false;
787 #if defined(ENABLE_VMLOG)
788 vmlog_cacao_init(vm_args);
791 #if defined(ENABLE_JNI)
792 /* Check the JNI version requested. */
794 if (!jni_version_check(vm_args->version))
798 /* We only support 1 JVM instance. */
803 /* Install the exit handler. */
805 if (atexit(vm_exit_handler))
806 vm_abort("atexit failed: %s\n", strerror(errno));
808 /* Set some options. */
815 opt_heapmaxsize = HEAP_MAXSIZE;
816 opt_heapstartsize = HEAP_STARTSIZE;
817 opt_stacksize = STACK_SIZE;
819 /* Initialize the properties list before command-line handling.
820 Otherwise -XX:+PrintConfig crashes. */
824 /* First of all, parse the -XX options. */
828 /* We need to check if the actual size of a java.lang.Class object
829 is smaller or equal than the assumption made in
830 src/vmcore/class.h. */
832 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
833 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
835 /* set the VM starttime */
837 _Jv_jvm->starttime = builtin_currenttimemillis();
839 #if defined(ENABLE_JVMTI)
840 /* initialize JVMTI related **********************************************/
844 /* Fill the properties before command-line handling. */
848 /* iterate over all passed options */
850 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
864 #if SIZEOF_VOID_P == 8
865 puts("Running a 32-bit JVM is not supported on this platform.");
871 #if SIZEOF_VOID_P == 4
872 puts("Running a 64-bit JVM is not supported on this platform.");
878 /* Forget old classpath and set the argument as new
881 class_path = properties_get("java.class.path");
883 p = MNEW(char, strlen(opt_arg) + strlen("0"));
887 #if defined(ENABLE_JAVASE)
888 properties_add("java.class.path", p);
891 MFREE(class_path, char, strlen(class_path));
895 for (i = 0; i < strlen(opt_arg); i++) {
896 if (opt_arg[i] == '=') {
898 properties_add(opt_arg, opt_arg + i + 1);
903 /* if no '=' is given, just create an empty property */
905 properties_add(opt_arg, "");
910 case OPT_BOOTCLASSPATH:
911 /* Forget default bootclasspath and set the argument as
912 new boot classpath. */
914 boot_class_path = properties_get("sun.boot.class.path");
916 p = MNEW(char, strlen(opt_arg) + strlen("0"));
920 properties_add("sun.boot.class.path", p);
921 properties_add("java.boot.class.path", p);
923 MFREE(boot_class_path, char, strlen(boot_class_path));
926 case OPT_BOOTCLASSPATH_A:
927 /* Append to bootclasspath. */
929 boot_class_path = properties_get("sun.boot.class.path");
931 len = strlen(boot_class_path);
933 p = MREALLOC(boot_class_path,
937 strlen(opt_arg) + strlen("0"));
942 properties_add("sun.boot.class.path", p);
943 properties_add("java.boot.class.path", p);
946 case OPT_BOOTCLASSPATH_P:
947 /* Prepend to bootclasspath. */
949 boot_class_path = properties_get("sun.boot.class.path");
951 len = strlen(boot_class_path);
953 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
957 strcat(p, boot_class_path);
959 properties_add("sun.boot.class.path", p);
960 properties_add("java.boot.class.path", p);
962 MFREE(boot_class_path, char, len);
965 case OPT_BOOTCLASSPATH_C:
966 /* Use as Java core library, but prepend VM interface
969 boot_class_path = properties_get("sun.boot.class.path");
972 strlen(CACAO_VM_ZIP) +
979 strcpy(p, CACAO_VM_ZIP);
983 properties_add("sun.boot.class.path", p);
984 properties_add("java.boot.class.path", p);
986 MFREE(boot_class_path, char, strlen(boot_class_path));
989 #if defined(ENABLE_JVMTI)
991 /* this option exists only for compatibility reasons */
995 /* I don't know yet what Xnoagent should do. This is only for
996 compatiblity with eclipse - motse */
1005 strlen(CACAO_LIBDIR) +
1006 strlen("/libjdwp.so=") +
1010 agentarg = MNEW(char, len);
1012 strcpy(agentarg, CACAO_LIBDIR);
1013 strcat(agentarg, "/libjdwp.so=");
1014 strcat(agentarg, &opt_arg[1]);
1031 c = opt_arg[strlen(opt_arg) - 1];
1033 if ((c == 'k') || (c == 'K')) {
1034 j = atoi(opt_arg) * 1024;
1036 } else if ((c == 'm') || (c == 'M')) {
1037 j = atoi(opt_arg) * 1024 * 1024;
1043 opt_heapmaxsize = j;
1044 else if (opt == OPT_MS)
1045 opt_heapstartsize = j;
1056 if (strcmp("class", opt_arg) == 0) {
1057 opt_verboseclass = true;
1059 else if (strcmp("gc", opt_arg) == 0) {
1060 opt_verbosegc = true;
1062 else if (strcmp("jni", opt_arg) == 0) {
1063 opt_verbosejni = true;
1065 #if !defined(NDEBUG)
1066 else if (strcmp("jit", opt_arg) == 0) {
1070 compileverbose = true;
1074 printf("Unknown -verbose option: %s\n", opt_arg);
1079 case OPT_DEBUGCOLOR:
1080 opt_debugcolor = true;
1083 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1085 opt_typecheckverbose = true;
1094 case OPT_FULLVERSION:
1098 case OPT_SHOWVERSION:
1106 #if defined(ENABLE_VERIFIER)
1112 #if defined(ENABLE_STATISTICS)
1114 opt_getcompilingtime = true;
1115 opt_getloadingtime = true;
1128 for (i = 0; i < strlen(opt_arg); i++) {
1129 switch (opt_arg[i]) {
1131 checkbounds = false;
1144 makeinitializations = false;
1147 #if !defined(NDEBUG)
1151 makeinitializations = false;
1156 opt_method = opt_arg;
1157 makeinitializations = false;
1161 opt_signature = opt_arg;
1165 case OPT_SHOW: /* Display options */
1166 for (i = 0; i < strlen(opt_arg); i++) {
1167 switch (opt_arg[i]) {
1169 showconstantpool = true;
1181 opt_showintermediate = true;
1182 compileverbose = true;
1185 #if defined(ENABLE_DISASSEMBLER)
1187 opt_showdisassemble = true;
1188 compileverbose = true;
1192 opt_shownops = true;
1197 opt_showddatasegment = true;
1206 #if defined(ENABLE_LOOP)
1212 #if defined(ENABLE_INLINING)
1213 #if defined(ENABLE_INLINING_DEBUG)
1214 case OPT_INLINE_DEBUG_ALL:
1215 opt_inline_debug_all = true;
1217 case OPT_INLINE_DEBUG_END:
1218 opt_inline_debug_end_counter = atoi(opt_arg);
1220 case OPT_INLINE_DEBUG_MIN:
1221 opt_inline_debug_min_size = atoi(opt_arg);
1223 case OPT_INLINE_DEBUG_MAX:
1224 opt_inline_debug_max_size = atoi(opt_arg);
1226 #endif /* defined(ENABLE_INLINING_DEBUG) */
1227 #if !defined(NDEBUG)
1228 case OPT_INLINE_LOG:
1229 opt_inline_debug_log = true;
1231 #endif /* !defined(NDEBUG) */
1234 opt_inlining = true;
1236 #endif /* defined(ENABLE_INLINING) */
1238 #if defined(ENABLE_IFCONV)
1244 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1259 /* Already parsed. */
1263 /* currently ignored */
1267 /* currently ignored */
1271 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1275 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1278 #if defined(ENABLE_PROFILING)
1279 case OPT_PROF_OPTION:
1280 /* use <= to get the last \0 too */
1282 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1283 if (opt_arg[i] == ',')
1286 if (opt_arg[i] == '\0') {
1287 if (strcmp("bb", opt_arg + j) == 0)
1291 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1295 /* set k to next char */
1308 #if defined(ENABLE_JIT)
1311 printf("-Xjit option not enabled.\n");
1317 #if defined(ENABLE_INTRP)
1320 printf("-Xint option not enabled.\n");
1325 #if defined(ENABLE_INTRP)
1326 case OPT_STATIC_SUPERS:
1327 opt_static_supers = atoi(opt_arg);
1330 case OPT_NO_DYNAMIC:
1331 opt_no_dynamic = true;
1334 case OPT_NO_REPLICATION:
1335 opt_no_replication = true;
1338 case OPT_NO_QUICKSUPER:
1339 opt_no_quicksuper = true;
1347 #if defined(ENABLE_DEBUG_FILTER)
1348 case OPT_FILTER_VERBOSECALL_INCLUDE:
1349 opt_filter_verbosecall_include = opt_arg;
1352 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1353 opt_filter_verbosecall_exclude = opt_arg;
1356 case OPT_FILTER_SHOW_METHOD:
1357 opt_filter_show_method = opt_arg;
1362 printf("Unknown option: %s\n",
1363 vm_args->options[opt_index].optionString);
1368 /* get the main class *****************************************************/
1370 if (opt_index < vm_args->nOptions) {
1371 mainstring = vm_args->options[opt_index++].optionString;
1373 /* Put the jar file into the classpath (if any). */
1375 if (opt_jar == true) {
1376 /* free old classpath */
1378 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1380 /* put jarfile into classpath */
1382 p = MNEW(char, strlen(mainstring) + strlen("0"));
1384 strcpy(p, mainstring);
1386 #if defined(ENABLE_JAVASE)
1387 properties_add("java.class.path", p);
1391 /* replace .'s with /'s in classname */
1393 for (i = strlen(mainstring) - 1; i >= 0; i--)
1394 if (mainstring[i] == '.')
1395 mainstring[i] = '/';
1399 #if defined(ENABLE_JVMTI)
1401 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1402 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1405 MFREE(agentarg, char, strlen(agentarg));
1407 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1411 /* initialize this JVM ****************************************************/
1413 vm_initializing = true;
1415 /* initialize the garbage collector */
1417 gc_init(opt_heapmaxsize, opt_heapstartsize);
1419 #if defined(ENABLE_THREADS)
1420 /* AFTER: gc_init (directly after, as this initializes the
1421 stopworldlock lock */
1426 /* install architecture dependent signal handlers */
1429 vm_abort("vm_create: signal_init failed");
1431 #if defined(ENABLE_INTRP)
1432 /* Allocate main thread stack on the Java heap. */
1435 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1436 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1440 /* AFTER: threads_preinit */
1443 vm_abort("vm_create: string_init failed");
1445 /* AFTER: threads_preinit */
1448 vm_abort("vm_create: utf8_init failed");
1450 /* AFTER: thread_preinit */
1453 vm_abort("vm_create: suck_init failed");
1455 suck_add_from_property("java.endorsed.dirs");
1457 /* Now we have all options handled and we can print the version
1460 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1465 /* AFTER: utf8_init */
1467 boot_class_path = properties_get("sun.boot.class.path");
1468 suck_add(boot_class_path);
1470 /* initialize the classcache hashtable stuff: lock, hashtable
1471 (must be done _after_ threads_preinit) */
1473 if (!classcache_init())
1474 vm_abort("vm_create: classcache_init failed");
1476 /* initialize the memory subsystem (must be done _after_
1480 vm_abort("vm_create: memory_init failed");
1482 /* initialize the finalizer stuff (must be done _after_
1485 if (!finalizer_init())
1486 vm_abort("vm_create: finalizer_init failed");
1488 /* initialize the codegen subsystems */
1492 /* initializes jit compiler */
1496 /* machine dependent initialization */
1498 #if defined(ENABLE_JIT)
1499 # if defined(ENABLE_INTRP)
1509 /* BEFORE: loader_preinit */
1513 /* AFTER: utf8_init, classcache_init */
1518 /* AFTER: loader_preinit, linker_preinit */
1525 /* AFTER: loader_init, linker_init */
1527 primitive_postinit();
1531 if (!builtin_init())
1532 vm_abort("vm_create: builtin_init failed");
1534 /* Initialize the native subsystem. */
1535 /* BEFORE: threads_init */
1538 vm_abort("vm_create: native_init failed");
1540 /* Register the native methods implemented in the VM. */
1541 /* BEFORE: threads_init */
1543 if (!nativevm_preinit())
1544 vm_abort("vm_create: nativevm_preinit failed");
1546 #if defined(ENABLE_JNI)
1547 /* Initialize the JNI subsystem (must be done _before_
1548 threads_init, as threads_init can call JNI methods
1549 (e.g. NewGlobalRef). */
1552 vm_abort("vm_create: jni_init failed");
1555 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1556 /* Initialize the local reference table for the main thread. */
1557 /* BEFORE: threads_init */
1559 if (!localref_table_init())
1560 vm_abort("vm_create: localref_table_init failed");
1563 #if defined(ENABLE_THREADS)
1564 if (!threads_init())
1565 vm_abort("vm_create: threads_init failed");
1568 /* Initialize the native VM subsystem. */
1569 /* AFTER: threads_init (at least for SUN's classes) */
1571 if (!nativevm_init())
1572 vm_abort("vm_create: nativevm_init failed");
1574 #if defined(ENABLE_PROFILING)
1575 /* initialize profiling */
1577 if (!profile_init())
1578 vm_abort("vm_create: profile_init failed");
1581 #if defined(ENABLE_THREADS)
1582 /* initialize recompilation */
1584 if (!recompile_init())
1585 vm_abort("vm_create: recompile_init failed");
1587 /* start the signal handler thread */
1589 #if defined(__LINUX__)
1590 /* XXX Remove for exact-GC. */
1591 if (threads_pthreads_implementation_nptl)
1593 if (!signal_start_thread())
1594 vm_abort("vm_create: signal_start_thread failed");
1596 /* finally, start the finalizer thread */
1598 if (!finalizer_start_thread())
1599 vm_abort("vm_create: finalizer_start_thread failed");
1601 # if !defined(NDEBUG)
1602 /* start the memory profiling thread */
1604 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1605 if (!memory_start_thread())
1606 vm_abort("vm_create: memory_start_thread failed");
1609 /* start the recompilation thread (must be done before the
1610 profiling thread) */
1612 if (!recompile_start_thread())
1613 vm_abort("vm_create: recompile_start_thread failed");
1615 # if defined(ENABLE_PROFILING)
1616 /* start the profile sampling thread */
1619 /* if (!profile_start_thread()) */
1620 /* vm_abort("vm_create: profile_start_thread failed"); */
1624 #if defined(ENABLE_JVMTI)
1625 # if defined(ENABLE_GC_CACAO)
1626 /* XXX this will not work with the new indirection cells for classloaders!!! */
1630 /* add agent library to native library hashtable */
1631 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1635 /* increment the number of VMs */
1639 /* initialization is done */
1641 vm_initializing = false;
1643 #if !defined(NDEBUG)
1644 /* Print the VM configuration after all stuff is set and the VM is
1647 if (opt_PrintConfig)
1651 /* everything's ok */
1657 /* vm_run **********************************************************************
1659 Runs the main-method of the passed class.
1661 *******************************************************************************/
1663 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1666 classinfo *mainclass;
1669 java_handle_objectarray_t *oa;
1676 #if !defined(NDEBUG)
1682 if (opt_method != NULL) {
1683 vm_compile_method();
1686 #endif /* !defined(NDEBUG) */
1688 /* should we run the main-method? */
1690 if (mainstring == NULL)
1693 /* set return value to OK */
1697 if (opt_jar == true) {
1698 /* open jar file with java.util.jar.JarFile */
1700 mainstring = vm_get_mainclass_from_jar(mainstring);
1702 if (mainstring == NULL)
1706 /* load the main class */
1708 mainutf = utf_new_char(mainstring);
1710 #if defined(ENABLE_JAVAME_CLDC1_1)
1711 mainclass = load_class_bootstrap(mainutf);
1713 mainclass = load_class_from_sysloader(mainutf);
1716 /* error loading class */
1718 e = exceptions_get_and_clear_exception();
1720 if ((e != NULL) || (mainclass == NULL)) {
1721 exceptions_throw_noclassdeffounderror_cause(e);
1722 exceptions_print_stacktrace();
1726 if (!link_class(mainclass)) {
1727 exceptions_print_stacktrace();
1731 /* find the `main' method of the main class */
1733 m = class_resolveclassmethod(mainclass,
1734 utf_new_char("main"),
1735 utf_new_char("([Ljava/lang/String;)V"),
1736 class_java_lang_Object,
1739 if (exceptions_get_exception()) {
1740 exceptions_print_stacktrace();
1744 /* there is no main method or it isn't static */
1746 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1747 exceptions_clear_exception();
1748 exceptions_throw_nosuchmethoderror(mainclass,
1749 utf_new_char("main"),
1750 utf_new_char("([Ljava/lang/String;)V"));
1752 exceptions_print_stacktrace();
1756 /* build argument array */
1758 oalength = vm_args->nOptions - opt_index;
1760 oa = builtin_anewarray(oalength, class_java_lang_String);
1762 for (i = 0; i < oalength; i++) {
1763 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1764 s = javastring_new(u);
1766 array_objectarray_element_set(oa, i, s);
1769 #ifdef TYPEINFO_DEBUG_TEST
1770 /* test the typeinfo system */
1773 /*class_showmethods(currentThread->group->header.vftbl->class); */
1775 #if defined(ENABLE_JVMTI)
1776 jvmti_set_phase(JVMTI_PHASE_LIVE);
1779 /* set ThreadMXBean variables */
1781 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1782 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1784 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1785 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1786 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1787 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1789 /* start the main thread */
1791 (void) vm_call_method(m, NULL, oa);
1793 /* exception occurred? */
1795 if (exceptions_get_exception()) {
1796 exceptions_print_stacktrace();
1800 /* unload the JavaVM */
1802 (void) vm_destroy(vm);
1810 /* vm_destroy ******************************************************************
1812 Unloads a Java VM and reclaims its resources.
1814 *******************************************************************************/
1816 s4 vm_destroy(JavaVM *vm)
1818 #if defined(ENABLE_THREADS)
1819 threads_join_all_threads();
1822 /* everything's ok */
1828 /* vm_exit *********************************************************************
1830 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1832 *******************************************************************************/
1834 void vm_exit(s4 status)
1838 /* signal that we are exiting */
1842 assert(class_java_lang_System);
1843 assert(class_java_lang_System->state & CLASS_LOADED);
1845 #if defined(ENABLE_JVMTI)
1846 if (jvmti || (dbgcom!=NULL)) {
1847 jvmti_set_phase(JVMTI_PHASE_DEAD);
1848 if (jvmti) jvmti_agentunload();
1852 if (!link_class(class_java_lang_System)) {
1853 exceptions_print_stacktrace();
1857 /* call java.lang.System.exit(I)V */
1859 m = class_resolveclassmethod(class_java_lang_System,
1860 utf_new_char("exit"),
1862 class_java_lang_Object,
1866 exceptions_print_stacktrace();
1870 /* call the exit function with passed exit status */
1872 (void) vm_call_method(m, NULL, status);
1874 /* If we had an exception, just ignore the exception and exit with
1877 vm_shutdown(status);
1881 /* vm_shutdown *****************************************************************
1883 Terminates the system immediately without freeing memory explicitly
1884 (to be used only for abnormal termination).
1886 *******************************************************************************/
1888 void vm_shutdown(s4 status)
1891 #if defined(ENABLE_STATISTICS)
1892 || opt_getcompilingtime || opt_stat
1896 log_text("CACAO terminated by shutdown");
1897 dolog("Exit status: %d\n", (s4) status);
1901 #if defined(ENABLE_JVMTI)
1902 /* terminate cacaodbgserver */
1904 pthread_mutex_lock(&dbgcomlock);
1906 pthread_mutex_unlock(&dbgcomlock);
1907 jvmti_cacaodbgserver_quit();
1915 /* vm_exit_handler *************************************************************
1917 The exit_handler function is called upon program termination.
1919 ATTENTION: Don't free system resources here! Some threads may still
1920 be running as this is called from VMRuntime.exit(). The OS does the
1923 *******************************************************************************/
1925 void vm_exit_handler(void)
1927 #if !defined(NDEBUG)
1929 class_showmethods(mainclass);
1931 if (showconstantpool)
1932 class_showconstantpool(mainclass);
1937 # if defined(ENABLE_PROFILING)
1939 profile_printstats();
1941 #endif /* !defined(NDEBUG) */
1943 #if defined(ENABLE_RT_TIMING)
1944 rt_timing_print_time_stats(stderr);
1947 #if defined(ENABLE_CYCLES_STATS)
1948 builtin_print_cycles_stats(stderr);
1949 stacktrace_print_cycles_stats(stderr);
1953 #if defined(ENABLE_STATISTICS)
1954 || opt_getcompilingtime || opt_stat
1958 log_text("CACAO terminated");
1960 #if defined(ENABLE_STATISTICS)
1963 #ifdef TYPECHECK_STATISTICS
1964 typecheck_print_statistics(get_logfile());
1968 if (opt_getcompilingtime)
1970 #endif /* defined(ENABLE_STATISTICS) */
1972 /* vm_print_profile(stderr);*/
1976 /* vm_abort ********************************************************************
1978 Prints an error message and aborts the VM.
1980 *******************************************************************************/
1982 void vm_abort(const char *text, ...)
1986 /* print the log message */
1991 log_vprint(text, ap);
1996 /* now abort the VM */
2002 /* vm_abort_disassemble ********************************************************
2004 Prints an error message, disassemble the given code range (if
2005 enabled) and aborts the VM.
2008 pc.......PC to disassemble
2009 count....number of instructions to disassemble
2011 *******************************************************************************/
2013 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2016 #if defined(ENABLE_DISASSEMBLER)
2020 /* Print debug message. */
2025 log_vprint(text, ap);
2032 #if SIZEOF_VOID_P == 8
2033 log_println("PC=0x%016lx", pc);
2035 log_println("PC=0x%08x", pc);
2038 #if defined(ENABLE_DISASSEMBLER)
2039 log_println("machine instructions at PC:");
2041 /* Disassemble the given number of instructions. */
2043 for (i = 0; i < count; i++)
2044 pc = disassinstr(pc);
2047 vm_abort("Aborting...");
2051 /* vm_get_mainclass_from_jar ***************************************************
2053 Gets the name of the main class from a JAR's manifest file.
2055 *******************************************************************************/
2057 static char *vm_get_mainclass_from_jar(char *mainstring)
2064 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2067 exceptions_print_stacktrace();
2071 /* create JarFile object */
2076 exceptions_print_stacktrace();
2080 m = class_resolveclassmethod(c,
2082 utf_java_lang_String__void,
2083 class_java_lang_Object,
2087 exceptions_print_stacktrace();
2091 s = javastring_new_from_ascii(mainstring);
2093 (void) vm_call_method(m, o, s);
2095 if (exceptions_get_exception()) {
2096 exceptions_print_stacktrace();
2100 /* get manifest object */
2102 m = class_resolveclassmethod(c,
2103 utf_new_char("getManifest"),
2104 utf_new_char("()Ljava/util/jar/Manifest;"),
2105 class_java_lang_Object,
2109 exceptions_print_stacktrace();
2113 o = vm_call_method(m, o);
2116 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2121 /* get Main Attributes */
2123 LLNI_class_get(o, c);
2125 m = class_resolveclassmethod(c,
2126 utf_new_char("getMainAttributes"),
2127 utf_new_char("()Ljava/util/jar/Attributes;"),
2128 class_java_lang_Object,
2132 exceptions_print_stacktrace();
2136 o = vm_call_method(m, o);
2139 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2144 /* get property Main-Class */
2146 LLNI_class_get(o, c);
2148 m = class_resolveclassmethod(c,
2149 utf_new_char("getValue"),
2150 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2151 class_java_lang_Object,
2155 exceptions_print_stacktrace();
2159 s = javastring_new_from_ascii("Main-Class");
2161 o = vm_call_method(m, o, s);
2164 exceptions_print_stacktrace();
2168 return javastring_tochar(o);
2172 /* vm_compile_all **************************************************************
2174 Compile all methods found in the bootclasspath.
2176 *******************************************************************************/
2178 #if !defined(NDEBUG)
2179 static void vm_compile_all(void)
2184 classcache_name_entry *nmen;
2185 classcache_class_entry *clsen;
2188 /* create all classes found in the bootclasspath */
2189 /* XXX currently only works with zip/jar's */
2191 loader_load_all_classes();
2193 /* link all classes */
2195 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2196 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2198 for (; nmen; nmen = nmen->hashlink) {
2199 /* iterate over all class entries */
2201 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2202 c = clsen->classobj;
2207 if (!(c->state & CLASS_LINKED)) {
2208 if (!link_class(c)) {
2209 fprintf(stderr, "Error linking: ");
2210 utf_fprint_printable_ascii_classname(stderr, c->name);
2211 fprintf(stderr, "\n");
2213 /* print out exception and cause */
2215 exceptions_print_current_exception();
2217 /* goto next class */
2223 /* compile all class methods */
2225 for (i = 0; i < c->methodscount; i++) {
2226 m = &(c->methods[i]);
2228 if (m->jcode != NULL) {
2229 if (!jit_compile(m)) {
2230 fprintf(stderr, "Error compiling: ");
2231 utf_fprint_printable_ascii_classname(stderr, c->name);
2232 fprintf(stderr, ".");
2233 utf_fprint_printable_ascii(stderr, m->name);
2234 utf_fprint_printable_ascii(stderr, m->descriptor);
2235 fprintf(stderr, "\n");
2237 /* print out exception and cause */
2239 exceptions_print_current_exception();
2247 #endif /* !defined(NDEBUG) */
2250 /* vm_compile_method ***********************************************************
2252 Compile a specific method.
2254 *******************************************************************************/
2256 #if !defined(NDEBUG)
2257 static void vm_compile_method(void)
2261 /* create, load and link the main class */
2263 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2265 if (mainclass == NULL)
2266 exceptions_print_stacktrace();
2268 if (!link_class(mainclass))
2269 exceptions_print_stacktrace();
2271 if (opt_signature != NULL) {
2272 m = class_resolveclassmethod(mainclass,
2273 utf_new_char(opt_method),
2274 utf_new_char(opt_signature),
2279 m = class_resolveclassmethod(mainclass,
2280 utf_new_char(opt_method),
2287 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2288 opt_method, opt_signature ? opt_signature : "");
2292 #endif /* !defined(NDEBUG) */
2295 /* vm_call_array ***************************************************************
2297 Calls a Java method with a variable number of arguments, passed via
2300 ATTENTION: This function has to be used outside the nativeworld.
2302 *******************************************************************************/
2304 #define VM_CALL_ARRAY(name, type) \
2305 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2311 assert(m->code != NULL); \
2313 md = m->parseddesc; \
2314 pv = m->code->entrypoint; \
2316 STATISTICS(count_calls_native_to_java++); \
2318 value = asm_vm_call_method##name(pv, array, md->memuse); \
2323 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2329 assert(m->code != NULL);
2332 pv = m->code->entrypoint;
2334 STATISTICS(count_calls_native_to_java++);
2336 o = asm_vm_call_method(pv, array, md->memuse);
2338 if (md->returntype.type == TYPE_VOID)
2341 return LLNI_WRAP(o);
2344 VM_CALL_ARRAY(_int, int32_t)
2345 VM_CALL_ARRAY(_long, int64_t)
2346 VM_CALL_ARRAY(_float, float)
2347 VM_CALL_ARRAY(_double, double)
2350 /* vm_call_method **************************************************************
2352 Calls a Java method with a variable number of arguments.
2354 *******************************************************************************/
2356 #define VM_CALL_METHOD(name, type) \
2357 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2363 value = vm_call_method##name##_valist(m, o, ap); \
2369 VM_CALL_METHOD(, java_handle_t *)
2370 VM_CALL_METHOD(_int, int32_t)
2371 VM_CALL_METHOD(_long, int64_t)
2372 VM_CALL_METHOD(_float, float)
2373 VM_CALL_METHOD(_double, double)
2376 /* vm_call_method_valist *******************************************************
2378 Calls a Java method with a variable number of arguments, passed via
2381 *******************************************************************************/
2383 #define VM_CALL_METHOD_VALIST(name, type) \
2384 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2391 if (m->code == NULL) \
2392 if (!jit_compile(m)) \
2395 THREAD_NATIVEWORLD_EXIT; \
2397 dumpsize = dump_size(); \
2398 array = argument_vmarray_from_valist(m, o, ap); \
2399 value = vm_call##name##_array(m, array); \
2400 dump_release(dumpsize); \
2402 THREAD_NATIVEWORLD_ENTER; \
2407 VM_CALL_METHOD_VALIST(, java_handle_t *)
2408 VM_CALL_METHOD_VALIST(_int, int32_t)
2409 VM_CALL_METHOD_VALIST(_long, int64_t)
2410 VM_CALL_METHOD_VALIST(_float, float)
2411 VM_CALL_METHOD_VALIST(_double, double)
2414 /* vm_call_method_jvalue *******************************************************
2416 Calls a Java method with a variable number of arguments, passed via
2419 *******************************************************************************/
2421 #define VM_CALL_METHOD_JVALUE(name, type) \
2422 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2423 const jvalue *args) \
2429 if (m->code == NULL) \
2430 if (!jit_compile(m)) \
2433 THREAD_NATIVEWORLD_EXIT; \
2435 dumpsize = dump_size(); \
2436 array = argument_vmarray_from_jvalue(m, o, args); \
2437 value = vm_call##name##_array(m, array); \
2438 dump_release(dumpsize); \
2440 THREAD_NATIVEWORLD_ENTER; \
2445 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2446 VM_CALL_METHOD_JVALUE(_int, int32_t)
2447 VM_CALL_METHOD_JVALUE(_long, int64_t)
2448 VM_CALL_METHOD_JVALUE(_float, float)
2449 VM_CALL_METHOD_JVALUE(_double, double)
2452 /* vm_call_method_objectarray **************************************************
2454 Calls a Java method with a variable number if arguments, passed via
2455 an objectarray of boxed values. Returns a boxed value.
2457 *******************************************************************************/
2459 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2460 java_handle_objectarray_t *params)
2464 java_handle_t *xptr;
2468 /* compile methods which are not yet compiled */
2470 if (m->code == NULL)
2471 if (!jit_compile(m))
2474 /* leave the nativeworld */
2476 THREAD_NATIVEWORLD_EXIT;
2478 /* mark start of dump memory area */
2480 dumpsize = dump_size();
2482 /* Fill the argument array from a object-array. */
2484 array = argument_vmarray_from_objectarray(m, o, params);
2486 if (array == NULL) {
2487 /* release dump area */
2489 dump_release(dumpsize);
2491 /* enter the nativeworld again */
2493 THREAD_NATIVEWORLD_ENTER;
2495 exceptions_throw_illegalargumentexception();
2500 switch (m->parseddesc->returntype.decltype) {
2501 case PRIMITIVETYPE_VOID:
2502 value.a = vm_call_array(m, array);
2505 case PRIMITIVETYPE_BOOLEAN:
2506 case PRIMITIVETYPE_BYTE:
2507 case PRIMITIVETYPE_CHAR:
2508 case PRIMITIVETYPE_SHORT:
2509 case PRIMITIVETYPE_INT:
2510 value.i = vm_call_int_array(m, array);
2513 case PRIMITIVETYPE_LONG:
2514 value.l = vm_call_long_array(m, array);
2517 case PRIMITIVETYPE_FLOAT:
2518 value.f = vm_call_float_array(m, array);
2521 case PRIMITIVETYPE_DOUBLE:
2522 value.d = vm_call_double_array(m, array);
2526 ro = vm_call_array(m, array);
2530 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2533 /* release dump area */
2535 dump_release(dumpsize);
2537 /* enter the nativeworld again */
2539 THREAD_NATIVEWORLD_ENTER;
2541 /* box the return value if necesarry */
2543 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2544 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2546 /* check for an exception */
2548 xptr = exceptions_get_exception();
2551 /* clear exception pointer, we are calling JIT code again */
2553 exceptions_clear_exception();
2555 exceptions_throw_invocationtargetexception(xptr);
2563 * These are local overrides for various environment variables in Emacs.
2564 * Please do not remove this and leave it at the end of the file, where
2565 * Emacs will automagically detect them.
2566 * ---------------------------------------------------------------------
2569 * indent-tabs-mode: t
2573 * vim:noexpandtab:sw=4:ts=4: