1 /* src/vm/vm.c - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
38 #include "vm/jit/abi-asm.h"
40 #include "mm/codememory.h"
41 #include "mm/gc-common.h"
42 #include "mm/memory.h"
44 #include "native/jni.h"
45 #include "native/llni.h"
46 #include "native/localref.h"
47 #include "native/native.h"
49 #include "native/include/java_lang_Object.h" /* required by j.l.C */
50 #include "native/include/java_lang_String.h" /* required by j.l.C */
52 #if defined(WITH_CLASSPATH_SUN)
53 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
54 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
57 #include "native/include/java_lang_Class.h"
59 #include "native/vm/nativevm.h"
61 #include "threads/threads-common.h"
63 #include "toolbox/logging.h"
67 #if defined(ENABLE_ASSERTION)
68 #include "vm/assertion.h"
71 #include "vm/builtin.h"
72 #include "vm/exceptions.h"
73 #include "vm/finalizer.h"
74 #include "vm/global.h"
75 #include "vm/initialize.h"
76 #include "vm/package.h"
77 #include "vm/primitive.h"
78 #include "vm/properties.h"
79 #include "vm/signallocal.h"
80 #include "vm/stringlocal.h"
83 #include "vm/jit/argument.h"
84 #include "vm/jit/asmpart.h"
86 #if defined(ENABLE_DISASSEMBLER)
87 # include "vm/jit/disass.h"
90 #include "vm/jit/jit.h"
92 #if defined(ENABLE_PROFILING)
93 # include "vm/jit/optimizing/profile.h"
96 #include "vm/jit/optimizing/recompile.h"
98 #if defined(ENABLE_PYTHON)
99 # include "vm/jit/python.h"
102 #include "vmcore/classcache.h"
103 #include "vmcore/options.h"
104 #include "vmcore/statistics.h"
105 #include "vmcore/suck.h"
107 #if defined(ENABLE_JVMTI)
108 # include "native/jvmti/cacaodbg.h"
111 #if defined(ENABLE_VMLOG)
112 #include <vmlog_cacao.h>
116 /* Invocation API variables ***************************************************/
118 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
119 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
122 /* global variables ***********************************************************/
124 s4 vms = 0; /* number of VMs created */
126 bool vm_initializing = false;
127 bool vm_exiting = false;
129 char *mainstring = NULL;
130 classinfo *mainclass = NULL;
132 #if defined(ENABLE_INTRP)
133 u1 *intrp_main_stack = NULL;
137 /* define heap sizes **********************************************************/
139 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
140 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
141 #define STACK_SIZE 128 * 1024 /* default 64kB */
144 /* define command line options ************************************************/
178 /* Java non-standard options */
189 #if defined(ENABLE_PROFILING)
202 #if defined(ENABLE_STATISTICS)
219 #if defined(ENABLE_VERIFIER)
221 #if defined(TYPECHECK_VERBOSE)
224 #endif /* defined(ENABLE_VERIFIER) */
226 /* optimization options */
228 #if defined(ENABLE_LOOP)
232 #if defined(ENABLE_IFCONV)
236 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
240 #if defined(ENABLE_INLINING)
245 #if defined(ENABLE_INLINING_DEBUG)
246 OPT_INLINE_DEBUG_ALL,
247 OPT_INLINE_DEBUG_END,
248 OPT_INLINE_DEBUG_MIN,
249 OPT_INLINE_DEBUG_MAX,
250 #endif /* defined(ENABLE_INLINING_DEBUG) */
251 #endif /* defined(ENABLE_INLINING) */
253 #if defined(ENABLE_INTRP)
254 /* interpreter options */
273 #if defined(ENABLE_DEBUG_FILTER)
274 OPT_FILTER_VERBOSECALL_INCLUDE,
275 OPT_FILTER_VERBOSECALL_EXCLUDE,
276 OPT_FILTER_SHOW_METHOD,
283 opt_struct opts[] = {
284 { "foo", false, OPT_FOO },
288 { "jar", false, OPT_JAR },
290 { "d32", false, OPT_D32 },
291 { "d64", false, OPT_D64 },
292 { "client", false, OPT_IGNORE },
293 { "server", false, OPT_IGNORE },
294 { "jvm", false, OPT_IGNORE },
295 { "hotspot", false, OPT_IGNORE },
297 { "classpath", true, OPT_CLASSPATH },
298 { "cp", true, OPT_CLASSPATH },
299 { "D", true, OPT_D },
300 { "version", false, OPT_VERSION },
301 { "showversion", false, OPT_SHOWVERSION },
302 { "fullversion", false, OPT_FULLVERSION },
303 { "help", false, OPT_HELP },
304 { "?", false, OPT_HELP },
305 { "X", false, OPT_X },
306 { "XX:", true, OPT_XX },
308 { "ea:", true, OPT_EA },
309 { "da:", true, OPT_DA },
310 { "ea", false, OPT_EA_NOARG },
311 { "da", false, OPT_DA_NOARG },
313 { "enableassertions:", true, OPT_EA },
314 { "disableassertions:", true, OPT_DA },
315 { "enableassertions", false, OPT_EA_NOARG },
316 { "disableassertions", false, OPT_DA_NOARG },
318 { "esa", false, OPT_ESA },
319 { "enablesystemassertions", false, OPT_ESA },
320 { "dsa", false, OPT_DSA },
321 { "disablesystemassertions", false, OPT_DSA },
323 { "noasyncgc", false, OPT_IGNORE },
324 #if defined(ENABLE_VERIFIER)
325 { "noverify", false, OPT_NOVERIFY },
326 { "Xverify:none", false, OPT_NOVERIFY },
328 { "v", false, OPT_VERBOSE1 },
329 { "verbose:", true, OPT_VERBOSE },
331 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
332 { "verbosetc", false, OPT_VERBOSETC },
334 #if defined(__ALPHA__)
335 { "noieee", false, OPT_NOIEEE },
337 #if defined(ENABLE_STATISTICS)
338 { "time", false, OPT_TIME },
339 { "stat", false, OPT_STAT },
341 { "log", true, OPT_LOG },
342 { "c", true, OPT_CHECK },
343 { "l", false, OPT_LOAD },
346 { "all", false, OPT_ALL },
347 { "sig", true, OPT_SIGNATURE },
350 #if defined(ENABLE_LOOP)
351 { "oloop", false, OPT_OLOOP },
353 #if defined(ENABLE_IFCONV)
354 { "ifconv", false, OPT_IFCONV },
356 #if defined(ENABLE_LSRA)
357 { "lsra", false, OPT_LSRA },
359 #if defined(ENABLE_SSA)
360 { "lsra", true, OPT_LSRA },
363 #if defined(ENABLE_INTRP)
364 /* interpreter options */
366 { "trace", false, OPT_TRACE },
367 { "static-supers", true, OPT_STATIC_SUPERS },
368 { "no-dynamic", false, OPT_NO_DYNAMIC },
369 { "no-replication", false, OPT_NO_REPLICATION },
370 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
373 /* JVMTI Agent Command Line Options */
375 { "agentlib:", true, OPT_AGENTLIB },
376 { "agentpath:", true, OPT_AGENTPATH },
379 /* Java non-standard options */
381 { "Xjit", false, OPT_JIT },
382 { "Xint", false, OPT_INTRP },
383 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
384 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
385 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
386 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
389 { "Xdebug", false, OPT_DEBUG },
390 { "Xnoagent", false, OPT_NOAGENT },
391 { "Xrunjdwp", true, OPT_XRUNJDWP },
394 { "Xms", true, OPT_MS },
395 { "ms", true, OPT_MS },
396 { "Xmx", true, OPT_MX },
397 { "mx", true, OPT_MX },
398 { "Xss", true, OPT_SS },
399 { "ss", true, OPT_SS },
401 #if defined(ENABLE_PROFILING)
402 { "Xprof:", true, OPT_PROF_OPTION },
403 { "Xprof", false, OPT_PROF },
406 /* inlining options */
408 #if defined(ENABLE_INLINING)
409 #if defined(ENABLE_INLINING_DEBUG)
410 { "ia", false, OPT_INLINE_DEBUG_ALL },
411 { "ii", true, OPT_INLINE_DEBUG_MIN },
412 { "im", true, OPT_INLINE_DEBUG_MAX },
413 { "ie", true, OPT_INLINE_DEBUG_END },
414 #endif /* defined(ENABLE_INLINING_DEBUG) */
416 { "il", false, OPT_INLINE_LOG },
418 { "i", false, OPT_INLINING },
419 #endif /* defined(ENABLE_INLINING) */
421 /* keep these at the end of the list */
424 { "m", true, OPT_METHOD },
427 { "s", true, OPT_SHOW },
428 { "debug-color", false, OPT_DEBUGCOLOR },
430 #if defined(ENABLE_DEBUG_FILTER)
431 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
432 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
433 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
440 /* usage ***********************************************************************
442 Prints the correct usage syntax to stdout.
444 *******************************************************************************/
448 puts("Usage: cacao [-options] classname [arguments]");
449 puts(" (to run a class file)");
450 puts(" or cacao [-options] -jar jarfile [arguments]");
451 puts(" (to run a standalone jar file)\n");
453 puts("where options include:");
454 puts(" -d32 use 32-bit data model if available");
455 puts(" -d64 use 64-bit data model if available");
456 puts(" -client compatibility (currently ignored)");
457 puts(" -server compatibility (currently ignored)");
458 puts(" -jvm compatibility (currently ignored)");
459 puts(" -hotspot compatibility (currently ignored)\n");
461 puts(" -cp <path> specify a path to look for classes");
462 puts(" -classpath <path> specify a path to look for classes");
463 puts(" -D<name>=<value> add an entry to the property list");
464 puts(" -verbose[:class|gc|jni] enable specific verbose output");
465 puts(" -version print product version and exit");
466 puts(" -fullversion print jpackage-compatible product version and exit");
467 puts(" -showversion print product version and continue");
468 puts(" -help, -? print this help message");
469 puts(" -X print help on non-standard Java options");
470 puts(" -XX print help on debugging options");
471 puts(" -ea[:<packagename>...|:<classname>]");
472 puts(" -enableassertions[:<packagename>...|:<classname>]");
473 puts(" enable assertions with specified granularity");
474 puts(" -da[:<packagename>...|:<classname>]");
475 puts(" -disableassertions[:<packagename>...|:<classname>]");
476 puts(" disable assertions with specified granularity");
477 puts(" -esa | -enablesystemassertions");
478 puts(" enable system assertions");
479 puts(" -dsa | -disablesystemassertions");
480 puts(" disable system assertions");
483 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
484 puts (" for jdwp help use: -agentlib:jdwp=help");
485 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
488 /* exit with error code */
494 static void Xusage(void)
496 #if defined(ENABLE_JIT)
497 puts(" -Xjit JIT mode execution (default)");
499 #if defined(ENABLE_INTRP)
500 puts(" -Xint interpreter mode execution");
502 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
503 puts(" value is set as bootstrap class path");
504 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
505 puts(" value is appended to the bootstrap class path");
506 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
507 puts(" value is prepended to the bootstrap class path");
508 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
509 puts(" value is used as Java core library, but the");
510 puts(" hardcoded VM interface classes are prepended");
511 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
512 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
513 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
515 #if defined(ENABLE_PROFILING)
516 puts(" -Xprof[:bb] collect and print profiling data");
519 #if defined(ENABLE_JVMTI)
520 /* -Xdebug option depend on gnu classpath JDWP options. options:
521 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
522 puts(" -Xdebug enable remote debugging\n");
523 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
524 puts(" enable remote debugging\n");
527 /* exit with error code */
534 static void XXusage(void)
536 puts(" -v write state-information");
538 puts(" -verbose:jit enable specific verbose output");
539 puts(" -debug-color colored output for ANSI terms");
541 #ifdef TYPECHECK_VERBOSE
542 puts(" -verbosetc write debug messages while typechecking");
544 #if defined(__ALPHA__)
545 puts(" -noieee don't use ieee compliant arithmetic");
547 #if defined(ENABLE_VERIFIER)
548 puts(" -noverify don't verify classfiles");
550 #if defined(ENABLE_STATISTICS)
551 puts(" -time measure the runtime");
552 puts(" -stat detailed compiler statistics");
554 puts(" -log logfile specify a name for the logfile");
555 puts(" -c(heck)b(ounds) don't check array bounds");
556 puts(" s(ync) don't check for synchronization");
557 #if defined(ENABLE_LOOP)
558 puts(" -oloop optimize array accesses in loops");
560 puts(" -l don't start the class after loading");
562 puts(" -all compile all methods, no execution");
563 puts(" -m compile only a specific method");
564 puts(" -sig specify signature for a specific method");
567 puts(" -s... show...");
568 puts(" (c)onstants the constant pool");
569 puts(" (m)ethods class fields and methods");
570 puts(" (u)tf the utf - hash");
571 puts(" (i)ntermediate intermediate representation");
572 #if defined(ENABLE_DISASSEMBLER)
573 puts(" (a)ssembler disassembled listing");
574 puts(" n(o)ps show NOPs in disassembler output");
576 puts(" (d)atasegment data segment listing");
578 #if defined(ENABLE_INLINING)
579 puts(" -i activate inlining");
581 puts(" -il log inlining");
583 #if defined(ENABLE_INLINING_DEBUG)
584 puts(" -ia use inlining for all methods");
585 puts(" -ii <size> set minimum size for inlined result");
586 puts(" -im <size> set maximum size for inlined result");
587 puts(" -ie <number> stop inlining after the given number of roots");
588 #endif /* defined(ENABLE_INLINING_DEBUG) */
589 #endif /* defined(ENABLE_INLINING) */
591 #if defined(ENABLE_IFCONV)
592 puts(" -ifconv use if-conversion");
594 #if defined(ENABLE_LSRA)
595 puts(" -lsra use linear scan register allocation");
597 #if defined(ENABLE_SSA)
598 puts(" -lsra:... use linear scan register allocation (with SSA)");
599 puts(" (d)ead code elimination");
600 puts(" (c)opy propagation");
602 #if defined(ENABLE_DEBUG_FILTER)
603 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
604 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
605 puts(" -XXfm <regex> filter for show options");
607 /* exit with error code */
614 /* version *********************************************************************
616 Only prints cacao version information.
618 *******************************************************************************/
620 static void version(bool opt_exit)
622 puts("java version \""JAVA_VERSION"\"");
623 puts("CACAO version "VERSION"");
625 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
626 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
627 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
628 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
630 puts("This program is free software; you can redistribute it and/or");
631 puts("modify it under the terms of the GNU General Public License as");
632 puts("published by the Free Software Foundation; either version 2, or (at");
633 puts("your option) any later version.\n");
635 puts("This program is distributed in the hope that it will be useful, but");
636 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
637 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
638 puts("General Public License for more details.");
640 /* exit normally, if requested */
647 /* fullversion *****************************************************************
649 Prints a Sun compatible version information (required e.g. by
650 jpackage, www.jpackage.org).
652 *******************************************************************************/
654 static void fullversion(void)
656 puts("java full version \"cacao-"JAVA_VERSION"\"");
664 static void vm_printconfig(void)
666 puts("Configure/Build options:\n");
667 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
668 #if defined(__VERSION__)
669 puts(" CC : "VERSION_CC" ("__VERSION__")");
671 puts(" CC : "VERSION_CC"");
673 puts(" CFLAGS : "VERSION_CFLAGS"\n");
675 puts("Default variables:\n");
676 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
677 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
678 printf(" stack size : %d\n", STACK_SIZE);
680 #if defined(WITH_JRE_LAYOUT)
681 /* When we're building with JRE-layout, the default paths are the
682 same as the runtime paths. */
684 # if defined(WITH_CLASSPATH_GNU)
685 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
686 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
687 # elif defined(WITH_CLASSPATH_SUN)
688 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
689 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
695 puts("Runtime variables:\n");
696 printf(" maximum heap size : %d\n", opt_heapmaxsize);
697 printf(" initial heap size : %d\n", opt_heapstartsize);
698 printf(" stack size : %d\n", opt_stacksize);
700 #if defined(WITH_CLASSPATH_GNU)
701 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
702 #elif defined(WITH_CLASSPATH_SUN)
703 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
706 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
707 printf(" java.class.path : %s\n", properties_get("java.class.path"));
711 /* forward declarations *******************************************************/
713 static char *vm_get_mainclass_from_jar(char *mainstring);
715 static void vm_compile_all(void);
716 static void vm_compile_method(void);
720 /* vm_createjvm ****************************************************************
722 Implementation for JNI_CreateJavaVM.
724 *******************************************************************************/
726 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
728 JavaVMInitArgs *_vm_args;
732 /* get the arguments for the new JVM */
734 _vm_args = (JavaVMInitArgs *) vm_args;
736 /* get the VM and Env tables (must be set before vm_create) */
738 env = NEW(_Jv_JNIEnv);
740 #if defined(ENABLE_JNI)
741 env->env = &_Jv_JNINativeInterface;
744 /* XXX Set the global variable. Maybe we should do that differently. */
748 /* create and fill a JavaVM structure */
750 vm = NEW(_Jv_JavaVM);
752 #if defined(ENABLE_JNI)
753 vm->functions = &_Jv_JNIInvokeInterface;
756 /* XXX Set the global variable. Maybe we should do that differently. */
757 /* XXX JVMTI Agents needs a JavaVM */
761 /* actually create the JVM */
763 if (!vm_create(_vm_args))
766 /* now return the values */
768 *p_vm = (JavaVM *) vm;
769 *p_env = (void *) env;
774 /* release allocated memory */
776 FREE(env, _Jv_JNIEnv);
777 FREE(vm, _Jv_JavaVM);
783 /* vm_create *******************************************************************
785 Creates a JVM. Called by vm_createjvm.
787 *******************************************************************************/
789 bool vm_create(JavaVMInitArgs *vm_args)
793 char *boot_class_path;
800 #if defined(ENABLE_JVMTI)
802 char *libname, *agentarg;
803 bool jdwp,agentbypath;
804 jdwp = agentbypath = false;
807 #if defined(ENABLE_VMLOG)
808 vmlog_cacao_init(vm_args);
811 #if defined(ENABLE_JNI)
812 /* Check the JNI version requested. */
814 if (!jni_version_check(vm_args->version))
818 /* We only support 1 JVM instance. */
823 /* Install the exit handler. */
825 if (atexit(vm_exit_handler))
826 vm_abort("atexit failed: %s\n", strerror(errno));
828 /* Set some options. */
835 opt_heapmaxsize = HEAP_MAXSIZE;
836 opt_heapstartsize = HEAP_STARTSIZE;
837 opt_stacksize = STACK_SIZE;
839 /* Initialize the properties list before command-line handling.
840 Otherwise -XX:+PrintConfig crashes. */
844 /* First of all, parse the -XX options. */
848 /* We need to check if the actual size of a java.lang.Class object
849 is smaller or equal than the assumption made in
850 src/vmcore/class.h. */
852 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
853 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
855 /* set the VM starttime */
857 _Jv_jvm->starttime = builtin_currenttimemillis();
859 #if defined(ENABLE_JVMTI)
860 /* initialize JVMTI related **********************************************/
864 /* Fill the properties before command-line handling. */
868 /* iterate over all passed options */
870 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
884 #if SIZEOF_VOID_P == 8
885 puts("Running a 32-bit JVM is not supported on this platform.");
891 #if SIZEOF_VOID_P == 4
892 puts("Running a 64-bit JVM is not supported on this platform.");
898 /* Forget old classpath and set the argument as new
901 class_path = properties_get("java.class.path");
903 p = MNEW(char, strlen(opt_arg) + strlen("0"));
907 #if defined(ENABLE_JAVASE)
908 properties_add("java.class.path", p);
911 MFREE(class_path, char, strlen(class_path));
915 for (i = 0; i < strlen(opt_arg); i++) {
916 if (opt_arg[i] == '=') {
918 properties_add(opt_arg, opt_arg + i + 1);
923 /* if no '=' is given, just create an empty property */
925 properties_add(opt_arg, "");
930 case OPT_BOOTCLASSPATH:
931 /* Forget default bootclasspath and set the argument as
932 new boot classpath. */
934 boot_class_path = properties_get("sun.boot.class.path");
936 p = MNEW(char, strlen(opt_arg) + strlen("0"));
940 properties_add("sun.boot.class.path", p);
941 properties_add("java.boot.class.path", p);
943 MFREE(boot_class_path, char, strlen(boot_class_path));
946 case OPT_BOOTCLASSPATH_A:
947 /* Append to bootclasspath. */
949 boot_class_path = properties_get("sun.boot.class.path");
951 len = strlen(boot_class_path);
953 p = MREALLOC(boot_class_path,
957 strlen(opt_arg) + strlen("0"));
962 properties_add("sun.boot.class.path", p);
963 properties_add("java.boot.class.path", p);
966 case OPT_BOOTCLASSPATH_P:
967 /* Prepend to bootclasspath. */
969 boot_class_path = properties_get("sun.boot.class.path");
971 len = strlen(boot_class_path);
973 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
977 strcat(p, boot_class_path);
979 properties_add("sun.boot.class.path", p);
980 properties_add("java.boot.class.path", p);
982 MFREE(boot_class_path, char, len);
985 case OPT_BOOTCLASSPATH_C:
986 /* Use as Java core library, but prepend VM interface
989 boot_class_path = properties_get("sun.boot.class.path");
992 strlen(CACAO_VM_ZIP) +
999 strcpy(p, CACAO_VM_ZIP);
1003 properties_add("sun.boot.class.path", p);
1004 properties_add("java.boot.class.path", p);
1006 MFREE(boot_class_path, char, strlen(boot_class_path));
1009 #if defined(ENABLE_JVMTI)
1011 /* this option exists only for compatibility reasons */
1015 /* I don't know yet what Xnoagent should do. This is only for
1016 compatiblity with eclipse - motse */
1025 strlen(CACAO_LIBDIR) +
1026 strlen("/libjdwp.so=") +
1030 agentarg = MNEW(char, len);
1032 strcpy(agentarg, CACAO_LIBDIR);
1033 strcat(agentarg, "/libjdwp.so=");
1034 strcat(agentarg, &opt_arg[1]);
1051 c = opt_arg[strlen(opt_arg) - 1];
1053 if ((c == 'k') || (c == 'K')) {
1054 j = atoi(opt_arg) * 1024;
1056 } else if ((c == 'm') || (c == 'M')) {
1057 j = atoi(opt_arg) * 1024 * 1024;
1063 opt_heapmaxsize = j;
1064 else if (opt == OPT_MS)
1065 opt_heapstartsize = j;
1076 if (strcmp("class", opt_arg) == 0) {
1077 opt_verboseclass = true;
1079 else if (strcmp("gc", opt_arg) == 0) {
1080 opt_verbosegc = true;
1082 else if (strcmp("jni", opt_arg) == 0) {
1083 opt_verbosejni = true;
1085 #if !defined(NDEBUG)
1086 else if (strcmp("jit", opt_arg) == 0) {
1090 compileverbose = true;
1094 printf("Unknown -verbose option: %s\n", opt_arg);
1099 case OPT_DEBUGCOLOR:
1100 opt_debugcolor = true;
1103 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1105 opt_typecheckverbose = true;
1114 case OPT_FULLVERSION:
1118 case OPT_SHOWVERSION:
1126 #if defined(ENABLE_VERIFIER)
1132 #if defined(ENABLE_STATISTICS)
1134 opt_getcompilingtime = true;
1135 opt_getloadingtime = true;
1148 for (i = 0; i < strlen(opt_arg); i++) {
1149 switch (opt_arg[i]) {
1151 checkbounds = false;
1164 makeinitializations = false;
1167 #if !defined(NDEBUG)
1171 makeinitializations = false;
1176 opt_method = opt_arg;
1177 makeinitializations = false;
1181 opt_signature = opt_arg;
1185 case OPT_SHOW: /* Display options */
1186 for (i = 0; i < strlen(opt_arg); i++) {
1187 switch (opt_arg[i]) {
1189 showconstantpool = true;
1201 opt_showintermediate = true;
1202 compileverbose = true;
1205 #if defined(ENABLE_DISASSEMBLER)
1207 opt_showdisassemble = true;
1208 compileverbose = true;
1212 opt_shownops = true;
1217 opt_showddatasegment = true;
1226 #if defined(ENABLE_LOOP)
1232 #if defined(ENABLE_INLINING)
1233 #if defined(ENABLE_INLINING_DEBUG)
1234 case OPT_INLINE_DEBUG_ALL:
1235 opt_inline_debug_all = true;
1237 case OPT_INLINE_DEBUG_END:
1238 opt_inline_debug_end_counter = atoi(opt_arg);
1240 case OPT_INLINE_DEBUG_MIN:
1241 opt_inline_debug_min_size = atoi(opt_arg);
1243 case OPT_INLINE_DEBUG_MAX:
1244 opt_inline_debug_max_size = atoi(opt_arg);
1246 #endif /* defined(ENABLE_INLINING_DEBUG) */
1247 #if !defined(NDEBUG)
1248 case OPT_INLINE_LOG:
1249 opt_inline_debug_log = true;
1251 #endif /* !defined(NDEBUG) */
1254 opt_inlining = true;
1256 #endif /* defined(ENABLE_INLINING) */
1258 #if defined(ENABLE_IFCONV)
1264 #if defined(ENABLE_LSRA)
1269 #if defined(ENABLE_SSA)
1272 for (i = 0; i < strlen(opt_arg); i++) {
1273 switch (opt_arg[i]) {
1301 /* Already parsed. */
1305 #if defined(ENABLE_ASSERTION)
1306 assertion_ea_da(opt_arg, true);
1311 #if defined(ENABLE_ASSERTION)
1312 assertion_ea_da(opt_arg, false);
1317 #if defined(ENABLE_ASSERTION)
1318 assertion_user_enabled = true;
1323 #if defined(ENABLE_ASSERTION)
1324 assertion_user_enabled = false;
1329 #if defined(ENABLE_ASSERTION)
1330 assertion_system_enabled = true;
1335 #if defined(ENABLE_ASSERTION)
1336 assertion_system_enabled = false;
1340 #if defined(ENABLE_PROFILING)
1341 case OPT_PROF_OPTION:
1342 /* use <= to get the last \0 too */
1344 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1345 if (opt_arg[i] == ',')
1348 if (opt_arg[i] == '\0') {
1349 if (strcmp("bb", opt_arg + j) == 0)
1353 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1357 /* set k to next char */
1370 #if defined(ENABLE_JIT)
1373 printf("-Xjit option not enabled.\n");
1379 #if defined(ENABLE_INTRP)
1382 printf("-Xint option not enabled.\n");
1387 #if defined(ENABLE_INTRP)
1388 case OPT_STATIC_SUPERS:
1389 opt_static_supers = atoi(opt_arg);
1392 case OPT_NO_DYNAMIC:
1393 opt_no_dynamic = true;
1396 case OPT_NO_REPLICATION:
1397 opt_no_replication = true;
1400 case OPT_NO_QUICKSUPER:
1401 opt_no_quicksuper = true;
1409 #if defined(ENABLE_DEBUG_FILTER)
1410 case OPT_FILTER_VERBOSECALL_INCLUDE:
1411 opt_filter_verbosecall_include = opt_arg;
1414 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1415 opt_filter_verbosecall_exclude = opt_arg;
1418 case OPT_FILTER_SHOW_METHOD:
1419 opt_filter_show_method = opt_arg;
1424 printf("Unknown option: %s\n",
1425 vm_args->options[opt_index].optionString);
1430 /* get the main class *****************************************************/
1432 if (opt_index < vm_args->nOptions) {
1433 mainstring = vm_args->options[opt_index++].optionString;
1435 /* Put the jar file into the classpath (if any). */
1437 if (opt_jar == true) {
1438 /* free old classpath */
1440 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1442 /* put jarfile into classpath */
1444 p = MNEW(char, strlen(mainstring) + strlen("0"));
1446 strcpy(p, mainstring);
1448 #if defined(ENABLE_JAVASE)
1449 properties_add("java.class.path", p);
1453 /* replace .'s with /'s in classname */
1455 for (i = strlen(mainstring) - 1; i >= 0; i--)
1456 if (mainstring[i] == '.')
1457 mainstring[i] = '/';
1461 #if defined(ENABLE_JVMTI)
1463 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1464 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1467 MFREE(agentarg, char, strlen(agentarg));
1469 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1473 /* initialize this JVM ****************************************************/
1475 vm_initializing = true;
1477 /* initialize the garbage collector */
1479 gc_init(opt_heapmaxsize, opt_heapstartsize);
1481 #if defined(ENABLE_THREADS)
1482 /* AFTER: gc_init (directly after, as this initializes the
1483 stopworldlock lock */
1488 /* install architecture dependent signal handlers */
1491 vm_abort("vm_create: signal_init failed");
1493 #if defined(ENABLE_INTRP)
1494 /* Allocate main thread stack on the Java heap. */
1497 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1498 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1502 /* AFTER: threads_preinit */
1505 vm_abort("vm_create: string_init failed");
1507 /* AFTER: threads_preinit */
1510 vm_abort("vm_create: utf8_init failed");
1512 /* AFTER: thread_preinit */
1515 vm_abort("vm_create: suck_init failed");
1517 suck_add_from_property("java.endorsed.dirs");
1519 /* Now we have all options handled and we can print the version
1522 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1527 /* AFTER: utf8_init */
1529 boot_class_path = properties_get("sun.boot.class.path");
1530 suck_add(boot_class_path);
1532 /* initialize the classcache hashtable stuff: lock, hashtable
1533 (must be done _after_ threads_preinit) */
1535 if (!classcache_init())
1536 vm_abort("vm_create: classcache_init failed");
1538 /* Initialize the code memory management. */
1539 /* AFTER: threads_preinit */
1543 /* initialize the finalizer stuff (must be done _after_
1546 if (!finalizer_init())
1547 vm_abort("vm_create: finalizer_init failed");
1549 /* initializes jit compiler */
1553 #if defined(ENABLE_PYTHON)
1557 /* BEFORE: loader_preinit */
1561 /* AFTER: utf8_init, classcache_init */
1566 /* AFTER: loader_preinit, linker_preinit */
1573 /* AFTER: loader_init, linker_init */
1575 primitive_postinit();
1579 if (!builtin_init())
1580 vm_abort("vm_create: builtin_init failed");
1582 /* Initialize the native subsystem. */
1583 /* BEFORE: threads_init */
1586 vm_abort("vm_create: native_init failed");
1588 /* Register the native methods implemented in the VM. */
1589 /* BEFORE: threads_init */
1591 if (!nativevm_preinit())
1592 vm_abort("vm_create: nativevm_preinit failed");
1594 #if defined(ENABLE_JNI)
1595 /* Initialize the JNI subsystem (must be done _before_
1596 threads_init, as threads_init can call JNI methods
1597 (e.g. NewGlobalRef). */
1600 vm_abort("vm_create: jni_init failed");
1603 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1604 /* Initialize the local reference table for the main thread. */
1605 /* BEFORE: threads_init */
1607 if (!localref_table_init())
1608 vm_abort("vm_create: localref_table_init failed");
1611 #if defined(ENABLE_THREADS)
1612 if (!threads_init())
1613 vm_abort("vm_create: threads_init failed");
1616 /* Initialize the native VM subsystem. */
1617 /* AFTER: threads_init (at least for SUN's classes) */
1619 if (!nativevm_init())
1620 vm_abort("vm_create: nativevm_init failed");
1622 #if defined(ENABLE_PROFILING)
1623 /* initialize profiling */
1625 if (!profile_init())
1626 vm_abort("vm_create: profile_init failed");
1629 #if defined(ENABLE_THREADS)
1630 /* initialize recompilation */
1632 if (!recompile_init())
1633 vm_abort("vm_create: recompile_init failed");
1635 /* start the signal handler thread */
1637 #if defined(__LINUX__)
1638 /* XXX Remove for exact-GC. */
1639 if (threads_pthreads_implementation_nptl)
1641 if (!signal_start_thread())
1642 vm_abort("vm_create: signal_start_thread failed");
1644 /* finally, start the finalizer thread */
1646 if (!finalizer_start_thread())
1647 vm_abort("vm_create: finalizer_start_thread failed");
1649 # if !defined(NDEBUG)
1650 /* start the memory profiling thread */
1652 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1653 if (!memory_start_thread())
1654 vm_abort("vm_create: memory_start_thread failed");
1657 /* start the recompilation thread (must be done before the
1658 profiling thread) */
1660 if (!recompile_start_thread())
1661 vm_abort("vm_create: recompile_start_thread failed");
1663 # if defined(ENABLE_PROFILING)
1664 /* start the profile sampling thread */
1667 /* if (!profile_start_thread()) */
1668 /* vm_abort("vm_create: profile_start_thread failed"); */
1672 #if defined(ENABLE_JVMTI)
1673 # if defined(ENABLE_GC_CACAO)
1674 /* XXX this will not work with the new indirection cells for classloaders!!! */
1678 /* add agent library to native library hashtable */
1679 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1683 /* increment the number of VMs */
1687 /* initialization is done */
1689 vm_initializing = false;
1691 #if !defined(NDEBUG)
1692 /* Print the VM configuration after all stuff is set and the VM is
1695 if (opt_PrintConfig)
1699 /* everything's ok */
1705 /* vm_run **********************************************************************
1707 Runs the main-method of the passed class.
1709 *******************************************************************************/
1711 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1714 classinfo *mainclass;
1717 java_handle_objectarray_t *oa;
1724 #if !defined(NDEBUG)
1730 if (opt_method != NULL) {
1731 vm_compile_method();
1734 #endif /* !defined(NDEBUG) */
1736 /* should we run the main-method? */
1738 if (mainstring == NULL)
1741 /* set return value to OK */
1745 if (opt_jar == true) {
1746 /* open jar file with java.util.jar.JarFile */
1748 mainstring = vm_get_mainclass_from_jar(mainstring);
1750 if (mainstring == NULL)
1754 /* load the main class */
1756 mainutf = utf_new_char(mainstring);
1758 #if defined(ENABLE_JAVAME_CLDC1_1)
1759 mainclass = load_class_bootstrap(mainutf);
1761 mainclass = load_class_from_sysloader(mainutf);
1764 /* error loading class */
1766 e = exceptions_get_and_clear_exception();
1768 if ((e != NULL) || (mainclass == NULL)) {
1769 exceptions_throw_noclassdeffounderror_cause(e);
1770 exceptions_print_stacktrace();
1774 if (!link_class(mainclass)) {
1775 exceptions_print_stacktrace();
1779 /* find the `main' method of the main class */
1781 m = class_resolveclassmethod(mainclass,
1782 utf_new_char("main"),
1783 utf_new_char("([Ljava/lang/String;)V"),
1784 class_java_lang_Object,
1787 if (exceptions_get_exception()) {
1788 exceptions_print_stacktrace();
1792 /* there is no main method or it isn't static */
1794 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1795 exceptions_clear_exception();
1796 exceptions_throw_nosuchmethoderror(mainclass,
1797 utf_new_char("main"),
1798 utf_new_char("([Ljava/lang/String;)V"));
1800 exceptions_print_stacktrace();
1804 /* build argument array */
1806 oalength = vm_args->nOptions - opt_index;
1808 oa = builtin_anewarray(oalength, class_java_lang_String);
1810 for (i = 0; i < oalength; i++) {
1811 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1812 s = javastring_new(u);
1814 array_objectarray_element_set(oa, i, s);
1817 #ifdef TYPEINFO_DEBUG_TEST
1818 /* test the typeinfo system */
1821 /*class_showmethods(currentThread->group->header.vftbl->class); */
1823 #if defined(ENABLE_JVMTI)
1824 jvmti_set_phase(JVMTI_PHASE_LIVE);
1827 /* set ThreadMXBean variables */
1829 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1830 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1832 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1833 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1834 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1835 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1837 /* start the main thread */
1839 (void) vm_call_method(m, NULL, oa);
1841 /* exception occurred? */
1843 if (exceptions_get_exception()) {
1844 exceptions_print_stacktrace();
1848 /* unload the JavaVM */
1850 (void) vm_destroy(vm);
1858 /* vm_destroy ******************************************************************
1860 Unloads a Java VM and reclaims its resources.
1862 *******************************************************************************/
1864 s4 vm_destroy(JavaVM *vm)
1866 #if defined(ENABLE_THREADS)
1867 threads_join_all_threads();
1870 /* everything's ok */
1876 /* vm_exit *********************************************************************
1878 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1880 *******************************************************************************/
1882 void vm_exit(s4 status)
1886 /* signal that we are exiting */
1890 assert(class_java_lang_System);
1891 assert(class_java_lang_System->state & CLASS_LOADED);
1893 #if defined(ENABLE_JVMTI)
1894 if (jvmti || (dbgcom!=NULL)) {
1895 jvmti_set_phase(JVMTI_PHASE_DEAD);
1896 if (jvmti) jvmti_agentunload();
1900 if (!link_class(class_java_lang_System)) {
1901 exceptions_print_stacktrace();
1905 /* call java.lang.System.exit(I)V */
1907 m = class_resolveclassmethod(class_java_lang_System,
1908 utf_new_char("exit"),
1910 class_java_lang_Object,
1914 exceptions_print_stacktrace();
1918 /* call the exit function with passed exit status */
1920 (void) vm_call_method(m, NULL, status);
1922 /* If we had an exception, just ignore the exception and exit with
1925 vm_shutdown(status);
1929 /* vm_shutdown *****************************************************************
1931 Terminates the system immediately without freeing memory explicitly
1932 (to be used only for abnormal termination).
1934 *******************************************************************************/
1936 void vm_shutdown(s4 status)
1939 #if defined(ENABLE_STATISTICS)
1940 || opt_getcompilingtime || opt_stat
1944 log_text("CACAO terminated by shutdown");
1945 dolog("Exit status: %d\n", (s4) status);
1949 #if defined(ENABLE_JVMTI)
1950 /* terminate cacaodbgserver */
1952 pthread_mutex_lock(&dbgcomlock);
1954 pthread_mutex_unlock(&dbgcomlock);
1955 jvmti_cacaodbgserver_quit();
1963 /* vm_exit_handler *************************************************************
1965 The exit_handler function is called upon program termination.
1967 ATTENTION: Don't free system resources here! Some threads may still
1968 be running as this is called from VMRuntime.exit(). The OS does the
1971 *******************************************************************************/
1973 void vm_exit_handler(void)
1975 #if !defined(NDEBUG)
1977 class_showmethods(mainclass);
1979 if (showconstantpool)
1980 class_showconstantpool(mainclass);
1985 # if defined(ENABLE_PROFILING)
1987 profile_printstats();
1989 #endif /* !defined(NDEBUG) */
1991 #if defined(ENABLE_RT_TIMING)
1992 rt_timing_print_time_stats(stderr);
1995 #if defined(ENABLE_CYCLES_STATS)
1996 builtin_print_cycles_stats(stderr);
1997 stacktrace_print_cycles_stats(stderr);
2001 #if defined(ENABLE_STATISTICS)
2002 || opt_getcompilingtime || opt_stat
2006 log_text("CACAO terminated");
2008 #if defined(ENABLE_STATISTICS)
2011 #ifdef TYPECHECK_STATISTICS
2012 typecheck_print_statistics(get_logfile());
2016 if (opt_getcompilingtime)
2018 #endif /* defined(ENABLE_STATISTICS) */
2020 /* vm_print_profile(stderr);*/
2024 /* vm_abort ********************************************************************
2026 Prints an error message and aborts the VM.
2028 *******************************************************************************/
2030 void vm_abort(const char *text, ...)
2034 /* print the log message */
2039 log_vprint(text, ap);
2044 /* now abort the VM */
2050 /* vm_abort_disassemble ********************************************************
2052 Prints an error message, disassemble the given code range (if
2053 enabled) and aborts the VM.
2056 pc.......PC to disassemble
2057 count....number of instructions to disassemble
2059 *******************************************************************************/
2061 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2064 #if defined(ENABLE_DISASSEMBLER)
2068 /* Print debug message. */
2073 log_vprint(text, ap);
2080 #if SIZEOF_VOID_P == 8
2081 log_println("PC=0x%016lx", pc);
2083 log_println("PC=0x%08x", pc);
2086 #if defined(ENABLE_DISASSEMBLER)
2087 log_println("machine instructions at PC:");
2089 /* Disassemble the given number of instructions. */
2091 for (i = 0; i < count; i++)
2092 pc = disassinstr(pc);
2095 vm_abort("Aborting...");
2099 /* vm_get_mainclass_from_jar ***************************************************
2101 Gets the name of the main class from a JAR's manifest file.
2103 *******************************************************************************/
2105 static char *vm_get_mainclass_from_jar(char *mainstring)
2112 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2115 exceptions_print_stacktrace();
2119 /* create JarFile object */
2124 exceptions_print_stacktrace();
2128 m = class_resolveclassmethod(c,
2130 utf_java_lang_String__void,
2131 class_java_lang_Object,
2135 exceptions_print_stacktrace();
2139 s = javastring_new_from_ascii(mainstring);
2141 (void) vm_call_method(m, o, s);
2143 if (exceptions_get_exception()) {
2144 exceptions_print_stacktrace();
2148 /* get manifest object */
2150 m = class_resolveclassmethod(c,
2151 utf_new_char("getManifest"),
2152 utf_new_char("()Ljava/util/jar/Manifest;"),
2153 class_java_lang_Object,
2157 exceptions_print_stacktrace();
2161 o = vm_call_method(m, o);
2164 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2169 /* get Main Attributes */
2171 LLNI_class_get(o, c);
2173 m = class_resolveclassmethod(c,
2174 utf_new_char("getMainAttributes"),
2175 utf_new_char("()Ljava/util/jar/Attributes;"),
2176 class_java_lang_Object,
2180 exceptions_print_stacktrace();
2184 o = vm_call_method(m, o);
2187 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2192 /* get property Main-Class */
2194 LLNI_class_get(o, c);
2196 m = class_resolveclassmethod(c,
2197 utf_new_char("getValue"),
2198 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2199 class_java_lang_Object,
2203 exceptions_print_stacktrace();
2207 s = javastring_new_from_ascii("Main-Class");
2209 o = vm_call_method(m, o, s);
2212 exceptions_print_stacktrace();
2216 return javastring_tochar(o);
2220 /* vm_compile_all **************************************************************
2222 Compile all methods found in the bootclasspath.
2224 *******************************************************************************/
2226 #if !defined(NDEBUG)
2227 static void vm_compile_all(void)
2232 classcache_name_entry *nmen;
2233 classcache_class_entry *clsen;
2236 /* create all classes found in the bootclasspath */
2237 /* XXX currently only works with zip/jar's */
2239 loader_load_all_classes();
2241 /* link all classes */
2243 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2244 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2246 for (; nmen; nmen = nmen->hashlink) {
2247 /* iterate over all class entries */
2249 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2250 c = clsen->classobj;
2255 if (!(c->state & CLASS_LINKED)) {
2256 if (!link_class(c)) {
2257 fprintf(stderr, "Error linking: ");
2258 utf_fprint_printable_ascii_classname(stderr, c->name);
2259 fprintf(stderr, "\n");
2261 /* print out exception and cause */
2263 exceptions_print_current_exception();
2265 /* goto next class */
2271 /* compile all class methods */
2273 for (i = 0; i < c->methodscount; i++) {
2274 m = &(c->methods[i]);
2276 if (m->jcode != NULL) {
2277 if (!jit_compile(m)) {
2278 fprintf(stderr, "Error compiling: ");
2279 utf_fprint_printable_ascii_classname(stderr, c->name);
2280 fprintf(stderr, ".");
2281 utf_fprint_printable_ascii(stderr, m->name);
2282 utf_fprint_printable_ascii(stderr, m->descriptor);
2283 fprintf(stderr, "\n");
2285 /* print out exception and cause */
2287 exceptions_print_current_exception();
2295 #endif /* !defined(NDEBUG) */
2298 /* vm_compile_method ***********************************************************
2300 Compile a specific method.
2302 *******************************************************************************/
2304 #if !defined(NDEBUG)
2305 static void vm_compile_method(void)
2309 /* create, load and link the main class */
2311 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2313 if (mainclass == NULL)
2314 exceptions_print_stacktrace();
2316 if (!link_class(mainclass))
2317 exceptions_print_stacktrace();
2319 if (opt_signature != NULL) {
2320 m = class_resolveclassmethod(mainclass,
2321 utf_new_char(opt_method),
2322 utf_new_char(opt_signature),
2327 m = class_resolveclassmethod(mainclass,
2328 utf_new_char(opt_method),
2335 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2336 opt_method, opt_signature ? opt_signature : "");
2340 #endif /* !defined(NDEBUG) */
2343 /* vm_call_array ***************************************************************
2345 Calls a Java method with a variable number of arguments, passed via
2348 ATTENTION: This function has to be used outside the nativeworld.
2350 *******************************************************************************/
2352 #define VM_CALL_ARRAY(name, type) \
2353 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2359 assert(m->code != NULL); \
2361 md = m->parseddesc; \
2362 pv = m->code->entrypoint; \
2364 STATISTICS(count_calls_native_to_java++); \
2366 value = asm_vm_call_method##name(pv, array, md->memuse); \
2371 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2377 assert(m->code != NULL);
2380 pv = m->code->entrypoint;
2382 STATISTICS(count_calls_native_to_java++);
2384 o = asm_vm_call_method(pv, array, md->memuse);
2386 if (md->returntype.type == TYPE_VOID)
2389 return LLNI_WRAP(o);
2392 VM_CALL_ARRAY(_int, int32_t)
2393 VM_CALL_ARRAY(_long, int64_t)
2394 VM_CALL_ARRAY(_float, float)
2395 VM_CALL_ARRAY(_double, double)
2398 /* vm_call_method **************************************************************
2400 Calls a Java method with a variable number of arguments.
2402 *******************************************************************************/
2404 #define VM_CALL_METHOD(name, type) \
2405 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2411 value = vm_call_method##name##_valist(m, o, ap); \
2417 VM_CALL_METHOD(, java_handle_t *)
2418 VM_CALL_METHOD(_int, int32_t)
2419 VM_CALL_METHOD(_long, int64_t)
2420 VM_CALL_METHOD(_float, float)
2421 VM_CALL_METHOD(_double, double)
2424 /* vm_call_method_valist *******************************************************
2426 Calls a Java method with a variable number of arguments, passed via
2429 *******************************************************************************/
2431 #define VM_CALL_METHOD_VALIST(name, type) \
2432 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2437 int32_t dumpmarker; \
2439 if (m->code == NULL) \
2440 if (!jit_compile(m)) \
2443 THREAD_NATIVEWORLD_EXIT; \
2446 array = argument_vmarray_from_valist(m, o, ap); \
2447 value = vm_call##name##_array(m, array); \
2450 THREAD_NATIVEWORLD_ENTER; \
2455 VM_CALL_METHOD_VALIST(, java_handle_t *)
2456 VM_CALL_METHOD_VALIST(_int, int32_t)
2457 VM_CALL_METHOD_VALIST(_long, int64_t)
2458 VM_CALL_METHOD_VALIST(_float, float)
2459 VM_CALL_METHOD_VALIST(_double, double)
2462 /* vm_call_method_jvalue *******************************************************
2464 Calls a Java method with a variable number of arguments, passed via
2467 *******************************************************************************/
2469 #define VM_CALL_METHOD_JVALUE(name, type) \
2470 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2471 const jvalue *args) \
2475 int32_t dumpmarker; \
2477 if (m->code == NULL) \
2478 if (!jit_compile(m)) \
2481 THREAD_NATIVEWORLD_EXIT; \
2484 array = argument_vmarray_from_jvalue(m, o, args); \
2485 value = vm_call##name##_array(m, array); \
2488 THREAD_NATIVEWORLD_ENTER; \
2493 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2494 VM_CALL_METHOD_JVALUE(_int, int32_t)
2495 VM_CALL_METHOD_JVALUE(_long, int64_t)
2496 VM_CALL_METHOD_JVALUE(_float, float)
2497 VM_CALL_METHOD_JVALUE(_double, double)
2500 /* vm_call_method_objectarray **************************************************
2502 Calls a Java method with a variable number if arguments, passed via
2503 an objectarray of boxed values. Returns a boxed value.
2505 *******************************************************************************/
2507 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2508 java_handle_objectarray_t *params)
2511 java_handle_t *xptr;
2516 /* Prevent compiler warnings. */
2520 /* compile methods which are not yet compiled */
2522 if (m->code == NULL)
2523 if (!jit_compile(m))
2526 /* leave the nativeworld */
2528 THREAD_NATIVEWORLD_EXIT;
2530 /* mark start of dump memory area */
2534 /* Fill the argument array from a object-array. */
2536 array = argument_vmarray_from_objectarray(m, o, params);
2538 if (array == NULL) {
2539 /* release dump area */
2543 /* enter the nativeworld again */
2545 THREAD_NATIVEWORLD_ENTER;
2547 exceptions_throw_illegalargumentexception();
2552 switch (m->parseddesc->returntype.decltype) {
2553 case PRIMITIVETYPE_VOID:
2554 value.a = vm_call_array(m, array);
2557 case PRIMITIVETYPE_BOOLEAN:
2558 case PRIMITIVETYPE_BYTE:
2559 case PRIMITIVETYPE_CHAR:
2560 case PRIMITIVETYPE_SHORT:
2561 case PRIMITIVETYPE_INT:
2562 value.i = vm_call_int_array(m, array);
2565 case PRIMITIVETYPE_LONG:
2566 value.l = vm_call_long_array(m, array);
2569 case PRIMITIVETYPE_FLOAT:
2570 value.f = vm_call_float_array(m, array);
2573 case PRIMITIVETYPE_DOUBLE:
2574 value.d = vm_call_double_array(m, array);
2578 ro = vm_call_array(m, array);
2582 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2585 /* release dump area */
2589 /* enter the nativeworld again */
2591 THREAD_NATIVEWORLD_ENTER;
2593 /* box the return value if necesarry */
2595 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2596 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2598 /* check for an exception */
2600 xptr = exceptions_get_exception();
2603 /* clear exception pointer, we are calling JIT code again */
2605 exceptions_clear_exception();
2607 exceptions_throw_invocationtargetexception(xptr);
2615 * These are local overrides for various environment variables in Emacs.
2616 * Please do not remove this and leave it at the end of the file, where
2617 * Emacs will automagically detect them.
2618 * ---------------------------------------------------------------------
2621 * indent-tabs-mode: t
2625 * vim:noexpandtab:sw=4:ts=4: