1 /* src/vm/vm.c - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zu Foerderung der freien virtuellen Machine 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 ************************************************/
175 /* Java non-standard options */
186 #if defined(ENABLE_PROFILING)
199 #if defined(ENABLE_STATISTICS)
216 #if defined(ENABLE_VERIFIER)
218 #if defined(TYPECHECK_VERBOSE)
221 #endif /* defined(ENABLE_VERIFIER) */
223 /* optimization options */
225 #if defined(ENABLE_LOOP)
229 #if defined(ENABLE_IFCONV)
233 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
237 #if defined(ENABLE_INLINING)
242 #if defined(ENABLE_INLINING_DEBUG)
243 OPT_INLINE_DEBUG_ALL,
244 OPT_INLINE_DEBUG_END,
245 OPT_INLINE_DEBUG_MIN,
246 OPT_INLINE_DEBUG_MAX,
247 #endif /* defined(ENABLE_INLINING_DEBUG) */
248 #endif /* defined(ENABLE_INLINING) */
250 #if defined(ENABLE_INTRP)
251 /* interpreter options */
270 #if defined(ENABLE_DEBUG_FILTER)
271 OPT_FILTER_VERBOSECALL_INCLUDE,
272 OPT_FILTER_VERBOSECALL_EXCLUDE,
273 OPT_FILTER_SHOW_METHOD,
280 opt_struct opts[] = {
281 { "foo", false, OPT_FOO },
285 { "jar", false, OPT_JAR },
287 { "d32", false, OPT_D32 },
288 { "d64", false, OPT_D64 },
289 { "client", false, OPT_IGNORE },
290 { "server", false, OPT_IGNORE },
291 { "jvm", false, OPT_IGNORE },
292 { "hotspot", false, OPT_IGNORE },
294 { "classpath", true, OPT_CLASSPATH },
295 { "cp", true, OPT_CLASSPATH },
296 { "D", true, OPT_D },
297 { "version", false, OPT_VERSION },
298 { "showversion", false, OPT_SHOWVERSION },
299 { "fullversion", false, OPT_FULLVERSION },
300 { "help", false, OPT_HELP },
301 { "?", false, OPT_HELP },
302 { "X", false, OPT_X },
303 { "XX:", true, OPT_XX },
305 { "ea:", true, OPT_EA },
306 { "da:", true, OPT_DA },
307 { "ea", false, OPT_EA },
308 { "da", false, OPT_DA },
310 { "esa", false, OPT_ESA },
311 { "enablesystemassertions", false, OPT_ESA },
312 { "dsa", false, OPT_DSA },
313 { "disablesystemassertions", false, OPT_DSA },
315 { "noasyncgc", false, OPT_IGNORE },
316 #if defined(ENABLE_VERIFIER)
317 { "noverify", false, OPT_NOVERIFY },
318 { "Xverify:none", false, OPT_NOVERIFY },
320 { "v", false, OPT_VERBOSE1 },
321 { "verbose:", true, OPT_VERBOSE },
323 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
324 { "verbosetc", false, OPT_VERBOSETC },
326 #if defined(__ALPHA__)
327 { "noieee", false, OPT_NOIEEE },
329 #if defined(ENABLE_STATISTICS)
330 { "time", false, OPT_TIME },
331 { "stat", false, OPT_STAT },
333 { "log", true, OPT_LOG },
334 { "c", true, OPT_CHECK },
335 { "l", false, OPT_LOAD },
338 { "all", false, OPT_ALL },
339 { "sig", true, OPT_SIGNATURE },
342 #if defined(ENABLE_LOOP)
343 { "oloop", false, OPT_OLOOP },
345 #if defined(ENABLE_IFCONV)
346 { "ifconv", false, OPT_IFCONV },
348 #if defined(ENABLE_LSRA)
349 { "lsra", false, OPT_LSRA },
351 #if defined(ENABLE_SSA)
352 { "lsra", true, OPT_LSRA },
355 #if defined(ENABLE_INTRP)
356 /* interpreter options */
358 { "trace", false, OPT_TRACE },
359 { "static-supers", true, OPT_STATIC_SUPERS },
360 { "no-dynamic", false, OPT_NO_DYNAMIC },
361 { "no-replication", false, OPT_NO_REPLICATION },
362 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
365 /* JVMTI Agent Command Line Options */
367 { "agentlib:", true, OPT_AGENTLIB },
368 { "agentpath:", true, OPT_AGENTPATH },
371 /* Java non-standard options */
373 { "Xjit", false, OPT_JIT },
374 { "Xint", false, OPT_INTRP },
375 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
376 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
377 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
378 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
381 { "Xdebug", false, OPT_DEBUG },
382 { "Xnoagent", false, OPT_NOAGENT },
383 { "Xrunjdwp", true, OPT_XRUNJDWP },
386 { "Xms", true, OPT_MS },
387 { "ms", true, OPT_MS },
388 { "Xmx", true, OPT_MX },
389 { "mx", true, OPT_MX },
390 { "Xss", true, OPT_SS },
391 { "ss", true, OPT_SS },
393 #if defined(ENABLE_PROFILING)
394 { "Xprof:", true, OPT_PROF_OPTION },
395 { "Xprof", false, OPT_PROF },
398 /* inlining options */
400 #if defined(ENABLE_INLINING)
401 #if defined(ENABLE_INLINING_DEBUG)
402 { "ia", false, OPT_INLINE_DEBUG_ALL },
403 { "ii", true, OPT_INLINE_DEBUG_MIN },
404 { "im", true, OPT_INLINE_DEBUG_MAX },
405 { "ie", true, OPT_INLINE_DEBUG_END },
406 #endif /* defined(ENABLE_INLINING_DEBUG) */
408 { "il", false, OPT_INLINE_LOG },
410 { "i", false, OPT_INLINING },
411 #endif /* defined(ENABLE_INLINING) */
413 /* keep these at the end of the list */
416 { "m", true, OPT_METHOD },
419 { "s", true, OPT_SHOW },
420 { "debug-color", false, OPT_DEBUGCOLOR },
422 #if defined(ENABLE_DEBUG_FILTER)
423 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
424 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
425 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
432 /* usage ***********************************************************************
434 Prints the correct usage syntax to stdout.
436 *******************************************************************************/
440 puts("Usage: cacao [-options] classname [arguments]");
441 puts(" (to run a class file)");
442 puts(" or cacao [-options] -jar jarfile [arguments]");
443 puts(" (to run a standalone jar file)\n");
445 puts("where options include:");
446 puts(" -d32 use 32-bit data model if available");
447 puts(" -d64 use 64-bit data model if available");
448 puts(" -client compatibility (currently ignored)");
449 puts(" -server compatibility (currently ignored)");
450 puts(" -jvm compatibility (currently ignored)");
451 puts(" -hotspot compatibility (currently ignored)\n");
453 puts(" -cp <path> specify a path to look for classes");
454 puts(" -classpath <path> specify a path to look for classes");
455 puts(" -D<name>=<value> add an entry to the property list");
456 puts(" -verbose[:class|gc|jni] enable specific verbose output");
457 puts(" -version print product version and exit");
458 puts(" -fullversion print jpackage-compatible product version and exit");
459 puts(" -showversion print product version and continue");
460 puts(" -help, -? print this help message");
461 puts(" -X print help on non-standard Java options");
462 puts(" -XX print help on debugging options");
463 puts(" -ea[:<packagename>...|:<classname>]");
464 puts(" -enableassertions[:<packagename>...|:<classname>]");
465 puts(" enable assertions with specified granularity");
466 puts(" -da[:<packagename>...|:<classname>]");
467 puts(" -disableassertions[:<packagename>...|:<classname>]");
468 puts(" disable assertions with specified granularity");
469 puts(" -esa | -enablesystemassertions");
470 puts(" enable system assertions");
471 puts(" -dsa | -disablesystemassertions");
472 puts(" disable system assertions");
475 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
476 puts (" for jdwp help use: -agentlib:jdwp=help");
477 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
480 /* exit with error code */
486 static void Xusage(void)
488 #if defined(ENABLE_JIT)
489 puts(" -Xjit JIT mode execution (default)");
491 #if defined(ENABLE_INTRP)
492 puts(" -Xint interpreter mode execution");
494 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
495 puts(" value is set as bootstrap class path");
496 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
497 puts(" value is appended to the bootstrap class path");
498 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
499 puts(" value is prepended to the bootstrap class path");
500 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
501 puts(" value is used as Java core library, but the");
502 puts(" hardcoded VM interface classes are prepended");
503 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
504 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
505 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
507 #if defined(ENABLE_PROFILING)
508 puts(" -Xprof[:bb] collect and print profiling data");
511 #if defined(ENABLE_JVMTI)
512 /* -Xdebug option depend on gnu classpath JDWP options. options:
513 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
514 puts(" -Xdebug enable remote debugging\n");
515 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
516 puts(" enable remote debugging\n");
519 /* exit with error code */
526 static void XXusage(void)
528 puts(" -v write state-information");
530 puts(" -verbose:jit enable specific verbose output");
531 puts(" -debug-color colored output for ANSI terms");
533 #ifdef TYPECHECK_VERBOSE
534 puts(" -verbosetc write debug messages while typechecking");
536 #if defined(__ALPHA__)
537 puts(" -noieee don't use ieee compliant arithmetic");
539 #if defined(ENABLE_VERIFIER)
540 puts(" -noverify don't verify classfiles");
542 #if defined(ENABLE_STATISTICS)
543 puts(" -time measure the runtime");
544 puts(" -stat detailed compiler statistics");
546 puts(" -log logfile specify a name for the logfile");
547 puts(" -c(heck)b(ounds) don't check array bounds");
548 puts(" s(ync) don't check for synchronization");
549 #if defined(ENABLE_LOOP)
550 puts(" -oloop optimize array accesses in loops");
552 puts(" -l don't start the class after loading");
554 puts(" -all compile all methods, no execution");
555 puts(" -m compile only a specific method");
556 puts(" -sig specify signature for a specific method");
559 puts(" -s... show...");
560 puts(" (c)onstants the constant pool");
561 puts(" (m)ethods class fields and methods");
562 puts(" (u)tf the utf - hash");
563 puts(" (i)ntermediate intermediate representation");
564 #if defined(ENABLE_DISASSEMBLER)
565 puts(" (a)ssembler disassembled listing");
566 puts(" n(o)ps show NOPs in disassembler output");
568 puts(" (d)atasegment data segment listing");
570 #if defined(ENABLE_INLINING)
571 puts(" -i activate inlining");
573 puts(" -il log inlining");
575 #if defined(ENABLE_INLINING_DEBUG)
576 puts(" -ia use inlining for all methods");
577 puts(" -ii <size> set minimum size for inlined result");
578 puts(" -im <size> set maximum size for inlined result");
579 puts(" -ie <number> stop inlining after the given number of roots");
580 #endif /* defined(ENABLE_INLINING_DEBUG) */
581 #endif /* defined(ENABLE_INLINING) */
583 #if defined(ENABLE_IFCONV)
584 puts(" -ifconv use if-conversion");
586 #if defined(ENABLE_LSRA)
587 puts(" -lsra use linear scan register allocation");
589 #if defined(ENABLE_SSA)
590 puts(" -lsra:... use linear scan register allocation (with SSA)");
591 puts(" (d)ead code elimination");
592 puts(" (c)opy propagation");
594 #if defined(ENABLE_DEBUG_FILTER)
595 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
596 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
597 puts(" -XXfm <regex> filter for show options");
599 /* exit with error code */
606 /* version *********************************************************************
608 Only prints cacao version information.
610 *******************************************************************************/
612 static void version(bool opt_exit)
614 puts("java version \""JAVA_VERSION"\"");
615 puts("CACAO version "VERSION"");
617 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
618 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
619 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
620 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
622 puts("This program is free software; you can redistribute it and/or");
623 puts("modify it under the terms of the GNU General Public License as");
624 puts("published by the Free Software Foundation; either version 2, or (at");
625 puts("your option) any later version.\n");
627 puts("This program is distributed in the hope that it will be useful, but");
628 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
629 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
630 puts("General Public License for more details.");
632 /* exit normally, if requested */
639 /* fullversion *****************************************************************
641 Prints a Sun compatible version information (required e.g. by
642 jpackage, www.jpackage.org).
644 *******************************************************************************/
646 static void fullversion(void)
648 puts("java full version \"cacao-"JAVA_VERSION"\"");
656 static void vm_printconfig(void)
658 puts("Configure/Build options:\n");
659 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
660 #if defined(__VERSION__)
661 puts(" CC : "VERSION_CC" ("__VERSION__")");
663 puts(" CC : "VERSION_CC"");
665 puts(" CFLAGS : "VERSION_CFLAGS"\n");
667 puts("Default variables:\n");
668 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
669 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
670 printf(" stack size : %d\n", STACK_SIZE);
672 #if defined(WITH_JRE_LAYOUT)
673 /* When we're building with JRE-layout, the default paths are the
674 same as the runtime paths. */
676 # if defined(WITH_CLASSPATH_GNU)
677 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
678 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
679 # elif defined(WITH_CLASSPATH_SUN)
680 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
681 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
687 puts("Runtime variables:\n");
688 printf(" maximum heap size : %d\n", opt_heapmaxsize);
689 printf(" initial heap size : %d\n", opt_heapstartsize);
690 printf(" stack size : %d\n", opt_stacksize);
692 #if defined(WITH_CLASSPATH_GNU)
693 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
694 #elif defined(WITH_CLASSPATH_SUN)
695 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
698 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
699 printf(" java.class.path : %s\n", properties_get("java.class.path"));
703 /* forward declarations *******************************************************/
705 static char *vm_get_mainclass_from_jar(char *mainstring);
707 static void vm_compile_all(void);
708 static void vm_compile_method(void);
712 /* vm_createjvm ****************************************************************
714 Implementation for JNI_CreateJavaVM.
716 *******************************************************************************/
718 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
720 JavaVMInitArgs *_vm_args;
724 /* get the arguments for the new JVM */
726 _vm_args = (JavaVMInitArgs *) vm_args;
728 /* get the VM and Env tables (must be set before vm_create) */
730 env = NEW(_Jv_JNIEnv);
732 #if defined(ENABLE_JNI)
733 env->env = &_Jv_JNINativeInterface;
736 /* XXX Set the global variable. Maybe we should do that differently. */
740 /* create and fill a JavaVM structure */
742 vm = NEW(_Jv_JavaVM);
744 #if defined(ENABLE_JNI)
745 vm->functions = &_Jv_JNIInvokeInterface;
748 /* XXX Set the global variable. Maybe we should do that differently. */
749 /* XXX JVMTI Agents needs a JavaVM */
753 /* actually create the JVM */
755 if (!vm_create(_vm_args))
758 /* now return the values */
760 *p_vm = (JavaVM *) vm;
761 *p_env = (void *) env;
766 /* release allocated memory */
768 FREE(env, _Jv_JNIEnv);
769 FREE(vm, _Jv_JavaVM);
775 /* vm_create *******************************************************************
777 Creates a JVM. Called by vm_createjvm.
779 *******************************************************************************/
781 bool vm_create(JavaVMInitArgs *vm_args)
785 char *boot_class_path;
792 #if defined(ENABLE_JVMTI)
794 char *libname, *agentarg;
795 bool jdwp,agentbypath;
796 jdwp = agentbypath = false;
799 #if defined(ENABLE_VMLOG)
800 vmlog_cacao_init(vm_args);
803 #if defined(ENABLE_JNI)
804 /* Check the JNI version requested. */
806 if (!jni_version_check(vm_args->version))
810 /* We only support 1 JVM instance. */
815 /* Install the exit handler. */
817 if (atexit(vm_exit_handler))
818 vm_abort("atexit failed: %s\n", strerror(errno));
820 /* Set some options. */
827 opt_heapmaxsize = HEAP_MAXSIZE;
828 opt_heapstartsize = HEAP_STARTSIZE;
829 opt_stacksize = STACK_SIZE;
831 /* Initialize the properties list before command-line handling.
832 Otherwise -XX:+PrintConfig crashes. */
836 /* First of all, parse the -XX options. */
840 /* We need to check if the actual size of a java.lang.Class object
841 is smaller or equal than the assumption made in
842 src/vmcore/class.h. */
844 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
845 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
847 /* set the VM starttime */
849 _Jv_jvm->starttime = builtin_currenttimemillis();
851 #if defined(ENABLE_JVMTI)
852 /* initialize JVMTI related **********************************************/
856 /* Fill the properties before command-line handling. */
860 /* iterate over all passed options */
862 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
876 #if SIZEOF_VOID_P == 8
877 puts("Running a 32-bit JVM is not supported on this platform.");
883 #if SIZEOF_VOID_P == 4
884 puts("Running a 64-bit JVM is not supported on this platform.");
890 /* Forget old classpath and set the argument as new
893 class_path = properties_get("java.class.path");
895 p = MNEW(char, strlen(opt_arg) + strlen("0"));
899 #if defined(ENABLE_JAVASE)
900 properties_add("java.class.path", p);
903 MFREE(class_path, char, strlen(class_path));
907 for (i = 0; i < strlen(opt_arg); i++) {
908 if (opt_arg[i] == '=') {
910 properties_add(opt_arg, opt_arg + i + 1);
915 /* if no '=' is given, just create an empty property */
917 properties_add(opt_arg, "");
922 case OPT_BOOTCLASSPATH:
923 /* Forget default bootclasspath and set the argument as
924 new boot classpath. */
926 boot_class_path = properties_get("sun.boot.class.path");
928 p = MNEW(char, strlen(opt_arg) + strlen("0"));
932 properties_add("sun.boot.class.path", p);
933 properties_add("java.boot.class.path", p);
935 MFREE(boot_class_path, char, strlen(boot_class_path));
938 case OPT_BOOTCLASSPATH_A:
939 /* Append to bootclasspath. */
941 boot_class_path = properties_get("sun.boot.class.path");
943 len = strlen(boot_class_path);
945 p = MREALLOC(boot_class_path,
949 strlen(opt_arg) + strlen("0"));
954 properties_add("sun.boot.class.path", p);
955 properties_add("java.boot.class.path", p);
958 case OPT_BOOTCLASSPATH_P:
959 /* Prepend to bootclasspath. */
961 boot_class_path = properties_get("sun.boot.class.path");
963 len = strlen(boot_class_path);
965 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
969 strcat(p, boot_class_path);
971 properties_add("sun.boot.class.path", p);
972 properties_add("java.boot.class.path", p);
974 MFREE(boot_class_path, char, len);
977 case OPT_BOOTCLASSPATH_C:
978 /* Use as Java core library, but prepend VM interface
981 boot_class_path = properties_get("sun.boot.class.path");
984 strlen(CACAO_VM_ZIP) +
991 strcpy(p, CACAO_VM_ZIP);
995 properties_add("sun.boot.class.path", p);
996 properties_add("java.boot.class.path", p);
998 MFREE(boot_class_path, char, strlen(boot_class_path));
1001 #if defined(ENABLE_JVMTI)
1003 /* this option exists only for compatibility reasons */
1007 /* I don't know yet what Xnoagent should do. This is only for
1008 compatiblity with eclipse - motse */
1017 strlen(CACAO_LIBDIR) +
1018 strlen("/libjdwp.so=") +
1022 agentarg = MNEW(char, len);
1024 strcpy(agentarg, CACAO_LIBDIR);
1025 strcat(agentarg, "/libjdwp.so=");
1026 strcat(agentarg, &opt_arg[1]);
1043 c = opt_arg[strlen(opt_arg) - 1];
1045 if ((c == 'k') || (c == 'K')) {
1046 j = atoi(opt_arg) * 1024;
1048 } else if ((c == 'm') || (c == 'M')) {
1049 j = atoi(opt_arg) * 1024 * 1024;
1055 opt_heapmaxsize = j;
1056 else if (opt == OPT_MS)
1057 opt_heapstartsize = j;
1068 if (strcmp("class", opt_arg) == 0) {
1069 opt_verboseclass = true;
1071 else if (strcmp("gc", opt_arg) == 0) {
1072 opt_verbosegc = true;
1074 else if (strcmp("jni", opt_arg) == 0) {
1075 opt_verbosejni = true;
1077 #if !defined(NDEBUG)
1078 else if (strcmp("jit", opt_arg) == 0) {
1082 compileverbose = true;
1086 printf("Unknown -verbose option: %s\n", opt_arg);
1091 case OPT_DEBUGCOLOR:
1092 opt_debugcolor = true;
1095 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1097 opt_typecheckverbose = true;
1106 case OPT_FULLVERSION:
1110 case OPT_SHOWVERSION:
1118 #if defined(ENABLE_VERIFIER)
1124 #if defined(ENABLE_STATISTICS)
1126 opt_getcompilingtime = true;
1127 opt_getloadingtime = true;
1140 for (i = 0; i < strlen(opt_arg); i++) {
1141 switch (opt_arg[i]) {
1143 checkbounds = false;
1156 makeinitializations = false;
1159 #if !defined(NDEBUG)
1163 makeinitializations = false;
1168 opt_method = opt_arg;
1169 makeinitializations = false;
1173 opt_signature = opt_arg;
1177 case OPT_SHOW: /* Display options */
1178 for (i = 0; i < strlen(opt_arg); i++) {
1179 switch (opt_arg[i]) {
1181 showconstantpool = true;
1193 opt_showintermediate = true;
1194 compileverbose = true;
1197 #if defined(ENABLE_DISASSEMBLER)
1199 opt_showdisassemble = true;
1200 compileverbose = true;
1204 opt_shownops = true;
1209 opt_showddatasegment = true;
1218 #if defined(ENABLE_LOOP)
1224 #if defined(ENABLE_INLINING)
1225 #if defined(ENABLE_INLINING_DEBUG)
1226 case OPT_INLINE_DEBUG_ALL:
1227 opt_inline_debug_all = true;
1229 case OPT_INLINE_DEBUG_END:
1230 opt_inline_debug_end_counter = atoi(opt_arg);
1232 case OPT_INLINE_DEBUG_MIN:
1233 opt_inline_debug_min_size = atoi(opt_arg);
1235 case OPT_INLINE_DEBUG_MAX:
1236 opt_inline_debug_max_size = atoi(opt_arg);
1238 #endif /* defined(ENABLE_INLINING_DEBUG) */
1239 #if !defined(NDEBUG)
1240 case OPT_INLINE_LOG:
1241 opt_inline_debug_log = true;
1243 #endif /* !defined(NDEBUG) */
1246 opt_inlining = true;
1248 #endif /* defined(ENABLE_INLINING) */
1250 #if defined(ENABLE_IFCONV)
1256 #if defined(ENABLE_LSRA)
1261 #if defined(ENABLE_SSA)
1264 for (i = 0; i < strlen(opt_arg); i++) {
1265 switch (opt_arg[i]) {
1293 /* Already parsed. */
1297 #if defined(ENABLE_ASSERTION)
1298 assertion_ea_da(opt_arg, true);
1303 #if defined(ENABLE_ASSERTION)
1304 assertion_ea_da(opt_arg, false);
1309 #if defined(ENABLE_ASSERTION)
1310 assertion_system_enabled = true;
1315 #if defined(ENABLE_ASSERTION)
1316 assertion_system_enabled = false;
1320 #if defined(ENABLE_PROFILING)
1321 case OPT_PROF_OPTION:
1322 /* use <= to get the last \0 too */
1324 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1325 if (opt_arg[i] == ',')
1328 if (opt_arg[i] == '\0') {
1329 if (strcmp("bb", opt_arg + j) == 0)
1333 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1337 /* set k to next char */
1350 #if defined(ENABLE_JIT)
1353 printf("-Xjit option not enabled.\n");
1359 #if defined(ENABLE_INTRP)
1362 printf("-Xint option not enabled.\n");
1367 #if defined(ENABLE_INTRP)
1368 case OPT_STATIC_SUPERS:
1369 opt_static_supers = atoi(opt_arg);
1372 case OPT_NO_DYNAMIC:
1373 opt_no_dynamic = true;
1376 case OPT_NO_REPLICATION:
1377 opt_no_replication = true;
1380 case OPT_NO_QUICKSUPER:
1381 opt_no_quicksuper = true;
1389 #if defined(ENABLE_DEBUG_FILTER)
1390 case OPT_FILTER_VERBOSECALL_INCLUDE:
1391 opt_filter_verbosecall_include = opt_arg;
1394 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1395 opt_filter_verbosecall_exclude = opt_arg;
1398 case OPT_FILTER_SHOW_METHOD:
1399 opt_filter_show_method = opt_arg;
1404 printf("Unknown option: %s\n",
1405 vm_args->options[opt_index].optionString);
1410 /* get the main class *****************************************************/
1412 if (opt_index < vm_args->nOptions) {
1413 mainstring = vm_args->options[opt_index++].optionString;
1415 /* Put the jar file into the classpath (if any). */
1417 if (opt_jar == true) {
1418 /* free old classpath */
1420 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1422 /* put jarfile into classpath */
1424 p = MNEW(char, strlen(mainstring) + strlen("0"));
1426 strcpy(p, mainstring);
1428 #if defined(ENABLE_JAVASE)
1429 properties_add("java.class.path", p);
1433 /* replace .'s with /'s in classname */
1435 for (i = strlen(mainstring) - 1; i >= 0; i--)
1436 if (mainstring[i] == '.')
1437 mainstring[i] = '/';
1441 #if defined(ENABLE_JVMTI)
1443 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1444 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1447 MFREE(agentarg, char, strlen(agentarg));
1449 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1453 /* initialize this JVM ****************************************************/
1455 vm_initializing = true;
1457 /* initialize the garbage collector */
1459 gc_init(opt_heapmaxsize, opt_heapstartsize);
1461 #if defined(ENABLE_THREADS)
1462 /* AFTER: gc_init (directly after, as this initializes the
1463 stopworldlock lock */
1468 /* install architecture dependent signal handlers */
1471 vm_abort("vm_create: signal_init failed");
1473 #if defined(ENABLE_INTRP)
1474 /* Allocate main thread stack on the Java heap. */
1477 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1478 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1482 /* AFTER: threads_preinit */
1485 vm_abort("vm_create: string_init failed");
1487 /* AFTER: threads_preinit */
1490 vm_abort("vm_create: utf8_init failed");
1492 /* AFTER: thread_preinit */
1495 vm_abort("vm_create: suck_init failed");
1497 suck_add_from_property("java.endorsed.dirs");
1499 /* Now we have all options handled and we can print the version
1502 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1507 /* AFTER: utf8_init */
1509 boot_class_path = properties_get("sun.boot.class.path");
1510 suck_add(boot_class_path);
1512 /* initialize the classcache hashtable stuff: lock, hashtable
1513 (must be done _after_ threads_preinit) */
1515 if (!classcache_init())
1516 vm_abort("vm_create: classcache_init failed");
1518 /* Initialize the code memory management. */
1519 /* AFTER: threads_preinit */
1523 /* initialize the finalizer stuff (must be done _after_
1526 if (!finalizer_init())
1527 vm_abort("vm_create: finalizer_init failed");
1529 /* initializes jit compiler */
1533 #if defined(ENABLE_PYTHON)
1537 /* BEFORE: loader_preinit */
1541 /* AFTER: utf8_init, classcache_init */
1546 /* AFTER: loader_preinit, linker_preinit */
1553 /* AFTER: loader_init, linker_init */
1555 primitive_postinit();
1559 if (!builtin_init())
1560 vm_abort("vm_create: builtin_init failed");
1562 /* Initialize the native subsystem. */
1563 /* BEFORE: threads_init */
1566 vm_abort("vm_create: native_init failed");
1568 /* Register the native methods implemented in the VM. */
1569 /* BEFORE: threads_init */
1571 if (!nativevm_preinit())
1572 vm_abort("vm_create: nativevm_preinit failed");
1574 #if defined(ENABLE_JNI)
1575 /* Initialize the JNI subsystem (must be done _before_
1576 threads_init, as threads_init can call JNI methods
1577 (e.g. NewGlobalRef). */
1580 vm_abort("vm_create: jni_init failed");
1583 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1584 /* Initialize the local reference table for the main thread. */
1585 /* BEFORE: threads_init */
1587 if (!localref_table_init())
1588 vm_abort("vm_create: localref_table_init failed");
1591 #if defined(ENABLE_THREADS)
1592 if (!threads_init())
1593 vm_abort("vm_create: threads_init failed");
1596 /* Initialize the native VM subsystem. */
1597 /* AFTER: threads_init (at least for SUN's classes) */
1599 if (!nativevm_init())
1600 vm_abort("vm_create: nativevm_init failed");
1602 #if defined(ENABLE_PROFILING)
1603 /* initialize profiling */
1605 if (!profile_init())
1606 vm_abort("vm_create: profile_init failed");
1609 #if defined(ENABLE_THREADS)
1610 /* initialize recompilation */
1612 if (!recompile_init())
1613 vm_abort("vm_create: recompile_init failed");
1615 /* start the signal handler thread */
1617 #if defined(__LINUX__)
1618 /* XXX Remove for exact-GC. */
1619 if (threads_pthreads_implementation_nptl)
1621 if (!signal_start_thread())
1622 vm_abort("vm_create: signal_start_thread failed");
1624 /* finally, start the finalizer thread */
1626 if (!finalizer_start_thread())
1627 vm_abort("vm_create: finalizer_start_thread failed");
1629 # if !defined(NDEBUG)
1630 /* start the memory profiling thread */
1632 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1633 if (!memory_start_thread())
1634 vm_abort("vm_create: memory_start_thread failed");
1637 /* start the recompilation thread (must be done before the
1638 profiling thread) */
1640 if (!recompile_start_thread())
1641 vm_abort("vm_create: recompile_start_thread failed");
1643 # if defined(ENABLE_PROFILING)
1644 /* start the profile sampling thread */
1647 /* if (!profile_start_thread()) */
1648 /* vm_abort("vm_create: profile_start_thread failed"); */
1652 #if defined(ENABLE_JVMTI)
1653 # if defined(ENABLE_GC_CACAO)
1654 /* XXX this will not work with the new indirection cells for classloaders!!! */
1658 /* add agent library to native library hashtable */
1659 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1663 /* increment the number of VMs */
1667 /* initialization is done */
1669 vm_initializing = false;
1671 #if !defined(NDEBUG)
1672 /* Print the VM configuration after all stuff is set and the VM is
1675 if (opt_PrintConfig)
1679 /* everything's ok */
1685 /* vm_run **********************************************************************
1687 Runs the main-method of the passed class.
1689 *******************************************************************************/
1691 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1694 classinfo *mainclass;
1697 java_handle_objectarray_t *oa;
1704 #if !defined(NDEBUG)
1710 if (opt_method != NULL) {
1711 vm_compile_method();
1714 #endif /* !defined(NDEBUG) */
1716 /* should we run the main-method? */
1718 if (mainstring == NULL)
1721 /* set return value to OK */
1725 if (opt_jar == true) {
1726 /* open jar file with java.util.jar.JarFile */
1728 mainstring = vm_get_mainclass_from_jar(mainstring);
1730 if (mainstring == NULL)
1734 /* load the main class */
1736 mainutf = utf_new_char(mainstring);
1738 #if defined(ENABLE_JAVAME_CLDC1_1)
1739 mainclass = load_class_bootstrap(mainutf);
1741 mainclass = load_class_from_sysloader(mainutf);
1744 /* error loading class */
1746 e = exceptions_get_and_clear_exception();
1748 if ((e != NULL) || (mainclass == NULL)) {
1749 exceptions_throw_noclassdeffounderror_cause(e);
1750 exceptions_print_stacktrace();
1754 if (!link_class(mainclass)) {
1755 exceptions_print_stacktrace();
1759 /* find the `main' method of the main class */
1761 m = class_resolveclassmethod(mainclass,
1762 utf_new_char("main"),
1763 utf_new_char("([Ljava/lang/String;)V"),
1764 class_java_lang_Object,
1767 if (exceptions_get_exception()) {
1768 exceptions_print_stacktrace();
1772 /* there is no main method or it isn't static */
1774 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1775 exceptions_clear_exception();
1776 exceptions_throw_nosuchmethoderror(mainclass,
1777 utf_new_char("main"),
1778 utf_new_char("([Ljava/lang/String;)V"));
1780 exceptions_print_stacktrace();
1784 /* build argument array */
1786 oalength = vm_args->nOptions - opt_index;
1788 oa = builtin_anewarray(oalength, class_java_lang_String);
1790 for (i = 0; i < oalength; i++) {
1791 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1792 s = javastring_new(u);
1794 array_objectarray_element_set(oa, i, s);
1797 #ifdef TYPEINFO_DEBUG_TEST
1798 /* test the typeinfo system */
1801 /*class_showmethods(currentThread->group->header.vftbl->class); */
1803 #if defined(ENABLE_JVMTI)
1804 jvmti_set_phase(JVMTI_PHASE_LIVE);
1807 /* set ThreadMXBean variables */
1809 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1810 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1812 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1813 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1814 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1815 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1817 /* start the main thread */
1819 (void) vm_call_method(m, NULL, oa);
1821 /* exception occurred? */
1823 if (exceptions_get_exception()) {
1824 exceptions_print_stacktrace();
1828 /* unload the JavaVM */
1830 (void) vm_destroy(vm);
1838 /* vm_destroy ******************************************************************
1840 Unloads a Java VM and reclaims its resources.
1842 *******************************************************************************/
1844 s4 vm_destroy(JavaVM *vm)
1846 #if defined(ENABLE_THREADS)
1847 threads_join_all_threads();
1850 /* everything's ok */
1856 /* vm_exit *********************************************************************
1858 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1860 *******************************************************************************/
1862 void vm_exit(s4 status)
1866 /* signal that we are exiting */
1870 assert(class_java_lang_System);
1871 assert(class_java_lang_System->state & CLASS_LOADED);
1873 #if defined(ENABLE_JVMTI)
1874 if (jvmti || (dbgcom!=NULL)) {
1875 jvmti_set_phase(JVMTI_PHASE_DEAD);
1876 if (jvmti) jvmti_agentunload();
1880 if (!link_class(class_java_lang_System)) {
1881 exceptions_print_stacktrace();
1885 /* call java.lang.System.exit(I)V */
1887 m = class_resolveclassmethod(class_java_lang_System,
1888 utf_new_char("exit"),
1890 class_java_lang_Object,
1894 exceptions_print_stacktrace();
1898 /* call the exit function with passed exit status */
1900 (void) vm_call_method(m, NULL, status);
1902 /* If we had an exception, just ignore the exception and exit with
1905 vm_shutdown(status);
1909 /* vm_shutdown *****************************************************************
1911 Terminates the system immediately without freeing memory explicitly
1912 (to be used only for abnormal termination).
1914 *******************************************************************************/
1916 void vm_shutdown(s4 status)
1919 #if defined(ENABLE_STATISTICS)
1920 || opt_getcompilingtime || opt_stat
1924 log_text("CACAO terminated by shutdown");
1925 dolog("Exit status: %d\n", (s4) status);
1929 #if defined(ENABLE_JVMTI)
1930 /* terminate cacaodbgserver */
1932 pthread_mutex_lock(&dbgcomlock);
1934 pthread_mutex_unlock(&dbgcomlock);
1935 jvmti_cacaodbgserver_quit();
1943 /* vm_exit_handler *************************************************************
1945 The exit_handler function is called upon program termination.
1947 ATTENTION: Don't free system resources here! Some threads may still
1948 be running as this is called from VMRuntime.exit(). The OS does the
1951 *******************************************************************************/
1953 void vm_exit_handler(void)
1955 #if !defined(NDEBUG)
1957 class_showmethods(mainclass);
1959 if (showconstantpool)
1960 class_showconstantpool(mainclass);
1965 # if defined(ENABLE_PROFILING)
1967 profile_printstats();
1969 #endif /* !defined(NDEBUG) */
1971 #if defined(ENABLE_RT_TIMING)
1972 rt_timing_print_time_stats(stderr);
1975 #if defined(ENABLE_CYCLES_STATS)
1976 builtin_print_cycles_stats(stderr);
1977 stacktrace_print_cycles_stats(stderr);
1981 #if defined(ENABLE_STATISTICS)
1982 || opt_getcompilingtime || opt_stat
1986 log_text("CACAO terminated");
1988 #if defined(ENABLE_STATISTICS)
1991 #ifdef TYPECHECK_STATISTICS
1992 typecheck_print_statistics(get_logfile());
1996 if (opt_getcompilingtime)
1998 #endif /* defined(ENABLE_STATISTICS) */
2000 /* vm_print_profile(stderr);*/
2004 /* vm_abort ********************************************************************
2006 Prints an error message and aborts the VM.
2008 *******************************************************************************/
2010 void vm_abort(const char *text, ...)
2014 /* print the log message */
2019 log_vprint(text, ap);
2024 /* now abort the VM */
2030 /* vm_abort_disassemble ********************************************************
2032 Prints an error message, disassemble the given code range (if
2033 enabled) and aborts the VM.
2036 pc.......PC to disassemble
2037 count....number of instructions to disassemble
2039 *******************************************************************************/
2041 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2044 #if defined(ENABLE_DISASSEMBLER)
2048 /* Print debug message. */
2053 log_vprint(text, ap);
2060 #if SIZEOF_VOID_P == 8
2061 log_println("PC=0x%016lx", pc);
2063 log_println("PC=0x%08x", pc);
2066 #if defined(ENABLE_DISASSEMBLER)
2067 log_println("machine instructions at PC:");
2069 /* Disassemble the given number of instructions. */
2071 for (i = 0; i < count; i++)
2072 pc = disassinstr(pc);
2075 vm_abort("Aborting...");
2079 /* vm_get_mainclass_from_jar ***************************************************
2081 Gets the name of the main class from a JAR's manifest file.
2083 *******************************************************************************/
2085 static char *vm_get_mainclass_from_jar(char *mainstring)
2092 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2095 exceptions_print_stacktrace();
2099 /* create JarFile object */
2104 exceptions_print_stacktrace();
2108 m = class_resolveclassmethod(c,
2110 utf_java_lang_String__void,
2111 class_java_lang_Object,
2115 exceptions_print_stacktrace();
2119 s = javastring_new_from_ascii(mainstring);
2121 (void) vm_call_method(m, o, s);
2123 if (exceptions_get_exception()) {
2124 exceptions_print_stacktrace();
2128 /* get manifest object */
2130 m = class_resolveclassmethod(c,
2131 utf_new_char("getManifest"),
2132 utf_new_char("()Ljava/util/jar/Manifest;"),
2133 class_java_lang_Object,
2137 exceptions_print_stacktrace();
2141 o = vm_call_method(m, o);
2144 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2149 /* get Main Attributes */
2151 LLNI_class_get(o, c);
2153 m = class_resolveclassmethod(c,
2154 utf_new_char("getMainAttributes"),
2155 utf_new_char("()Ljava/util/jar/Attributes;"),
2156 class_java_lang_Object,
2160 exceptions_print_stacktrace();
2164 o = vm_call_method(m, o);
2167 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2172 /* get property Main-Class */
2174 LLNI_class_get(o, c);
2176 m = class_resolveclassmethod(c,
2177 utf_new_char("getValue"),
2178 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2179 class_java_lang_Object,
2183 exceptions_print_stacktrace();
2187 s = javastring_new_from_ascii("Main-Class");
2189 o = vm_call_method(m, o, s);
2192 exceptions_print_stacktrace();
2196 return javastring_tochar(o);
2200 /* vm_compile_all **************************************************************
2202 Compile all methods found in the bootclasspath.
2204 *******************************************************************************/
2206 #if !defined(NDEBUG)
2207 static void vm_compile_all(void)
2212 classcache_name_entry *nmen;
2213 classcache_class_entry *clsen;
2216 /* create all classes found in the bootclasspath */
2217 /* XXX currently only works with zip/jar's */
2219 loader_load_all_classes();
2221 /* link all classes */
2223 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2224 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2226 for (; nmen; nmen = nmen->hashlink) {
2227 /* iterate over all class entries */
2229 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2230 c = clsen->classobj;
2235 if (!(c->state & CLASS_LINKED)) {
2236 if (!link_class(c)) {
2237 fprintf(stderr, "Error linking: ");
2238 utf_fprint_printable_ascii_classname(stderr, c->name);
2239 fprintf(stderr, "\n");
2241 /* print out exception and cause */
2243 exceptions_print_current_exception();
2245 /* goto next class */
2251 /* compile all class methods */
2253 for (i = 0; i < c->methodscount; i++) {
2254 m = &(c->methods[i]);
2256 if (m->jcode != NULL) {
2257 if (!jit_compile(m)) {
2258 fprintf(stderr, "Error compiling: ");
2259 utf_fprint_printable_ascii_classname(stderr, c->name);
2260 fprintf(stderr, ".");
2261 utf_fprint_printable_ascii(stderr, m->name);
2262 utf_fprint_printable_ascii(stderr, m->descriptor);
2263 fprintf(stderr, "\n");
2265 /* print out exception and cause */
2267 exceptions_print_current_exception();
2275 #endif /* !defined(NDEBUG) */
2278 /* vm_compile_method ***********************************************************
2280 Compile a specific method.
2282 *******************************************************************************/
2284 #if !defined(NDEBUG)
2285 static void vm_compile_method(void)
2289 /* create, load and link the main class */
2291 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2293 if (mainclass == NULL)
2294 exceptions_print_stacktrace();
2296 if (!link_class(mainclass))
2297 exceptions_print_stacktrace();
2299 if (opt_signature != NULL) {
2300 m = class_resolveclassmethod(mainclass,
2301 utf_new_char(opt_method),
2302 utf_new_char(opt_signature),
2307 m = class_resolveclassmethod(mainclass,
2308 utf_new_char(opt_method),
2315 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2316 opt_method, opt_signature ? opt_signature : "");
2320 #endif /* !defined(NDEBUG) */
2323 /* vm_call_array ***************************************************************
2325 Calls a Java method with a variable number of arguments, passed via
2328 ATTENTION: This function has to be used outside the nativeworld.
2330 *******************************************************************************/
2332 #define VM_CALL_ARRAY(name, type) \
2333 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2339 assert(m->code != NULL); \
2341 md = m->parseddesc; \
2342 pv = m->code->entrypoint; \
2344 STATISTICS(count_calls_native_to_java++); \
2346 value = asm_vm_call_method##name(pv, array, md->memuse); \
2351 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2357 assert(m->code != NULL);
2360 pv = m->code->entrypoint;
2362 STATISTICS(count_calls_native_to_java++);
2364 o = asm_vm_call_method(pv, array, md->memuse);
2366 if (md->returntype.type == TYPE_VOID)
2369 return LLNI_WRAP(o);
2372 VM_CALL_ARRAY(_int, int32_t)
2373 VM_CALL_ARRAY(_long, int64_t)
2374 VM_CALL_ARRAY(_float, float)
2375 VM_CALL_ARRAY(_double, double)
2378 /* vm_call_method **************************************************************
2380 Calls a Java method with a variable number of arguments.
2382 *******************************************************************************/
2384 #define VM_CALL_METHOD(name, type) \
2385 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2391 value = vm_call_method##name##_valist(m, o, ap); \
2397 VM_CALL_METHOD(, java_handle_t *)
2398 VM_CALL_METHOD(_int, int32_t)
2399 VM_CALL_METHOD(_long, int64_t)
2400 VM_CALL_METHOD(_float, float)
2401 VM_CALL_METHOD(_double, double)
2404 /* vm_call_method_valist *******************************************************
2406 Calls a Java method with a variable number of arguments, passed via
2409 *******************************************************************************/
2411 #define VM_CALL_METHOD_VALIST(name, type) \
2412 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2417 int32_t dumpmarker; \
2419 if (m->code == NULL) \
2420 if (!jit_compile(m)) \
2423 THREAD_NATIVEWORLD_EXIT; \
2426 array = argument_vmarray_from_valist(m, o, ap); \
2427 value = vm_call##name##_array(m, array); \
2430 THREAD_NATIVEWORLD_ENTER; \
2435 VM_CALL_METHOD_VALIST(, java_handle_t *)
2436 VM_CALL_METHOD_VALIST(_int, int32_t)
2437 VM_CALL_METHOD_VALIST(_long, int64_t)
2438 VM_CALL_METHOD_VALIST(_float, float)
2439 VM_CALL_METHOD_VALIST(_double, double)
2442 /* vm_call_method_jvalue *******************************************************
2444 Calls a Java method with a variable number of arguments, passed via
2447 *******************************************************************************/
2449 #define VM_CALL_METHOD_JVALUE(name, type) \
2450 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2451 const jvalue *args) \
2455 int32_t dumpmarker; \
2457 if (m->code == NULL) \
2458 if (!jit_compile(m)) \
2461 THREAD_NATIVEWORLD_EXIT; \
2464 array = argument_vmarray_from_jvalue(m, o, args); \
2465 value = vm_call##name##_array(m, array); \
2468 THREAD_NATIVEWORLD_ENTER; \
2473 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2474 VM_CALL_METHOD_JVALUE(_int, int32_t)
2475 VM_CALL_METHOD_JVALUE(_long, int64_t)
2476 VM_CALL_METHOD_JVALUE(_float, float)
2477 VM_CALL_METHOD_JVALUE(_double, double)
2480 /* vm_call_method_objectarray **************************************************
2482 Calls a Java method with a variable number if arguments, passed via
2483 an objectarray of boxed values. Returns a boxed value.
2485 *******************************************************************************/
2487 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2488 java_handle_objectarray_t *params)
2491 java_handle_t *xptr;
2496 /* compile methods which are not yet compiled */
2498 if (m->code == NULL)
2499 if (!jit_compile(m))
2502 /* leave the nativeworld */
2504 THREAD_NATIVEWORLD_EXIT;
2506 /* mark start of dump memory area */
2510 /* Fill the argument array from a object-array. */
2512 array = argument_vmarray_from_objectarray(m, o, params);
2514 if (array == NULL) {
2515 /* release dump area */
2519 /* enter the nativeworld again */
2521 THREAD_NATIVEWORLD_ENTER;
2523 exceptions_throw_illegalargumentexception();
2528 switch (m->parseddesc->returntype.decltype) {
2529 case PRIMITIVETYPE_VOID:
2530 value.a = vm_call_array(m, array);
2533 case PRIMITIVETYPE_BOOLEAN:
2534 case PRIMITIVETYPE_BYTE:
2535 case PRIMITIVETYPE_CHAR:
2536 case PRIMITIVETYPE_SHORT:
2537 case PRIMITIVETYPE_INT:
2538 value.i = vm_call_int_array(m, array);
2541 case PRIMITIVETYPE_LONG:
2542 value.l = vm_call_long_array(m, array);
2545 case PRIMITIVETYPE_FLOAT:
2546 value.f = vm_call_float_array(m, array);
2549 case PRIMITIVETYPE_DOUBLE:
2550 value.d = vm_call_double_array(m, array);
2554 ro = vm_call_array(m, array);
2558 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2561 /* release dump area */
2565 /* enter the nativeworld again */
2567 THREAD_NATIVEWORLD_ENTER;
2569 /* box the return value if necesarry */
2571 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2572 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2574 /* check for an exception */
2576 xptr = exceptions_get_exception();
2579 /* clear exception pointer, we are calling JIT code again */
2581 exceptions_clear_exception();
2583 exceptions_throw_invocationtargetexception(xptr);
2591 * These are local overrides for various environment variables in Emacs.
2592 * Please do not remove this and leave it at the end of the file, where
2593 * Emacs will automagically detect them.
2594 * ---------------------------------------------------------------------
2597 * indent-tabs-mode: t
2601 * vim:noexpandtab:sw=4:ts=4: