1 /* src/vm/vm.c - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
40 #include "vm/jit/abi-asm.h"
42 #include "mm/gc-common.h"
43 #include "mm/memory.h"
45 #include "native/jni.h"
46 #include "native/llni.h"
47 #include "native/localref.h"
48 #include "native/native.h"
50 #include "native/include/java_lang_Object.h" /* required by j.l.C */
51 #include "native/include/java_lang_String.h" /* required by j.l.C */
53 #if defined(WITH_CLASSPATH_SUN)
54 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
55 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
58 #include "native/include/java_lang_Class.h"
60 #include "native/vm/nativevm.h"
62 #include "threads/threads-common.h"
64 #include "toolbox/logging.h"
68 #if defined(ENABLE_ASSERTION)
69 #include "vm/assertion.h"
72 #include "vm/builtin.h"
73 #include "vm/exceptions.h"
74 #include "vm/finalizer.h"
75 #include "vm/global.h"
76 #include "vm/initialize.h"
77 #include "vm/package.h"
78 #include "vm/primitive.h"
79 #include "vm/properties.h"
80 #include "vm/signallocal.h"
81 #include "vm/stringlocal.h"
84 #include "vm/jit/argument.h"
85 #include "vm/jit/asmpart.h"
87 #if defined(ENABLE_DISASSEMBLER)
88 # include "vm/jit/disass.h"
91 #include "vm/jit/jit.h"
93 #if defined(ENABLE_PROFILING)
94 # include "vm/jit/optimizing/profile.h"
97 #include "vm/jit/optimizing/recompile.h"
99 #if defined(ENABLE_PYTHON)
100 # include "vm/jit/python.h"
103 #include "vmcore/classcache.h"
104 #include "vmcore/options.h"
105 #include "vmcore/statistics.h"
106 #include "vmcore/suck.h"
108 #if defined(ENABLE_JVMTI)
109 # include "native/jvmti/cacaodbg.h"
112 #if defined(ENABLE_VMLOG)
113 #include <vmlog_cacao.h>
117 /* Invocation API variables ***************************************************/
119 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
120 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
123 /* global variables ***********************************************************/
125 s4 vms = 0; /* number of VMs created */
127 bool vm_initializing = false;
128 bool vm_exiting = false;
130 char *mainstring = NULL;
131 classinfo *mainclass = NULL;
133 #if defined(ENABLE_INTRP)
134 u1 *intrp_main_stack = NULL;
138 /* define heap sizes **********************************************************/
140 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
141 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
142 #define STACK_SIZE 128 * 1024 /* default 64kB */
145 /* define command line options ************************************************/
176 /* Java non-standard options */
187 #if defined(ENABLE_PROFILING)
200 #if defined(ENABLE_STATISTICS)
217 #if defined(ENABLE_VERIFIER)
219 #if defined(TYPECHECK_VERBOSE)
222 #endif /* defined(ENABLE_VERIFIER) */
224 /* optimization options */
226 #if defined(ENABLE_LOOP)
230 #if defined(ENABLE_IFCONV)
234 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
238 #if defined(ENABLE_INLINING)
243 #if defined(ENABLE_INLINING_DEBUG)
244 OPT_INLINE_DEBUG_ALL,
245 OPT_INLINE_DEBUG_END,
246 OPT_INLINE_DEBUG_MIN,
247 OPT_INLINE_DEBUG_MAX,
248 #endif /* defined(ENABLE_INLINING_DEBUG) */
249 #endif /* defined(ENABLE_INLINING) */
251 #if defined(ENABLE_INTRP)
252 /* interpreter options */
271 #if defined(ENABLE_DEBUG_FILTER)
272 OPT_FILTER_VERBOSECALL_INCLUDE,
273 OPT_FILTER_VERBOSECALL_EXCLUDE,
274 OPT_FILTER_SHOW_METHOD,
281 opt_struct opts[] = {
282 { "foo", false, OPT_FOO },
286 { "jar", false, OPT_JAR },
288 { "d32", false, OPT_D32 },
289 { "d64", false, OPT_D64 },
290 { "client", false, OPT_IGNORE },
291 { "server", false, OPT_IGNORE },
292 { "jvm", false, OPT_IGNORE },
293 { "hotspot", false, OPT_IGNORE },
295 { "classpath", true, OPT_CLASSPATH },
296 { "cp", true, OPT_CLASSPATH },
297 { "D", true, OPT_D },
298 { "version", false, OPT_VERSION },
299 { "showversion", false, OPT_SHOWVERSION },
300 { "fullversion", false, OPT_FULLVERSION },
301 { "help", false, OPT_HELP },
302 { "?", false, OPT_HELP },
303 { "X", false, OPT_X },
304 { "XX:", true, OPT_XX },
306 { "ea:", true, OPT_EA },
307 { "da:", true, OPT_DA },
308 { "ea", false, OPT_EA },
309 { "da", false, OPT_DA },
311 { "esa", false, OPT_ESA },
312 { "enablesystemassertions", false, OPT_ESA },
313 { "dsa", false, OPT_DSA },
314 { "disablesystemassertions", false, OPT_DSA },
316 { "noasyncgc", false, OPT_IGNORE },
317 #if defined(ENABLE_VERIFIER)
318 { "noverify", false, OPT_NOVERIFY },
319 { "Xverify:none", false, OPT_NOVERIFY },
321 { "v", false, OPT_VERBOSE1 },
322 { "verbose:", true, OPT_VERBOSE },
324 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
325 { "verbosetc", false, OPT_VERBOSETC },
327 #if defined(__ALPHA__)
328 { "noieee", false, OPT_NOIEEE },
330 #if defined(ENABLE_STATISTICS)
331 { "time", false, OPT_TIME },
332 { "stat", false, OPT_STAT },
334 { "log", true, OPT_LOG },
335 { "c", true, OPT_CHECK },
336 { "l", false, OPT_LOAD },
339 { "all", false, OPT_ALL },
340 { "sig", true, OPT_SIGNATURE },
343 #if defined(ENABLE_LOOP)
344 { "oloop", false, OPT_OLOOP },
346 #if defined(ENABLE_IFCONV)
347 { "ifconv", false, OPT_IFCONV },
349 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
350 { "lsra", false, OPT_LSRA },
353 #if defined(ENABLE_INTRP)
354 /* interpreter options */
356 { "trace", false, OPT_TRACE },
357 { "static-supers", true, OPT_STATIC_SUPERS },
358 { "no-dynamic", false, OPT_NO_DYNAMIC },
359 { "no-replication", false, OPT_NO_REPLICATION },
360 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
363 /* JVMTI Agent Command Line Options */
365 { "agentlib:", true, OPT_AGENTLIB },
366 { "agentpath:", true, OPT_AGENTPATH },
369 /* Java non-standard options */
371 { "Xjit", false, OPT_JIT },
372 { "Xint", false, OPT_INTRP },
373 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
374 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
375 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
376 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
379 { "Xdebug", false, OPT_DEBUG },
380 { "Xnoagent", false, OPT_NOAGENT },
381 { "Xrunjdwp", true, OPT_XRUNJDWP },
384 { "Xms", true, OPT_MS },
385 { "ms", true, OPT_MS },
386 { "Xmx", true, OPT_MX },
387 { "mx", true, OPT_MX },
388 { "Xss", true, OPT_SS },
389 { "ss", true, OPT_SS },
391 #if defined(ENABLE_PROFILING)
392 { "Xprof:", true, OPT_PROF_OPTION },
393 { "Xprof", false, OPT_PROF },
396 /* inlining options */
398 #if defined(ENABLE_INLINING)
399 #if defined(ENABLE_INLINING_DEBUG)
400 { "ia", false, OPT_INLINE_DEBUG_ALL },
401 { "ii", true, OPT_INLINE_DEBUG_MIN },
402 { "im", true, OPT_INLINE_DEBUG_MAX },
403 { "ie", true, OPT_INLINE_DEBUG_END },
404 #endif /* defined(ENABLE_INLINING_DEBUG) */
406 { "il", false, OPT_INLINE_LOG },
408 { "i", false, OPT_INLINING },
409 #endif /* defined(ENABLE_INLINING) */
411 /* keep these at the end of the list */
414 { "m", true, OPT_METHOD },
417 { "s", true, OPT_SHOW },
418 { "debug-color", false, OPT_DEBUGCOLOR },
420 #if defined(ENABLE_DEBUG_FILTER)
421 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
422 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
423 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
430 /* usage ***********************************************************************
432 Prints the correct usage syntax to stdout.
434 *******************************************************************************/
438 puts("Usage: cacao [-options] classname [arguments]");
439 puts(" (to run a class file)");
440 puts(" or cacao [-options] -jar jarfile [arguments]");
441 puts(" (to run a standalone jar file)\n");
443 puts("where options include:");
444 puts(" -d32 use 32-bit data model if available");
445 puts(" -d64 use 64-bit data model if available");
446 puts(" -client compatibility (currently ignored)");
447 puts(" -server compatibility (currently ignored)");
448 puts(" -jvm compatibility (currently ignored)");
449 puts(" -hotspot compatibility (currently ignored)\n");
451 puts(" -cp <path> specify a path to look for classes");
452 puts(" -classpath <path> specify a path to look for classes");
453 puts(" -D<name>=<value> add an entry to the property list");
454 puts(" -verbose[:class|gc|jni] enable specific verbose output");
455 puts(" -version print product version and exit");
456 puts(" -fullversion print jpackage-compatible product version and exit");
457 puts(" -showversion print product version and continue");
458 puts(" -help, -? print this help message");
459 puts(" -X print help on non-standard Java options");
460 puts(" -XX print help on debugging options");
461 puts(" -ea[:<packagename>...|:<classname>]");
462 puts(" -enableassertions[:<packagename>...|:<classname>]");
463 puts(" enable assertions with specified granularity");
464 puts(" -da[:<packagename>...|:<classname>]");
465 puts(" -disableassertions[:<packagename>...|:<classname>]");
466 puts(" disable assertions with specified granularity");
467 puts(" -esa | -enablesystemassertions");
468 puts(" enable system assertions");
469 puts(" -dsa | -disablesystemassertions");
470 puts(" disable system assertions");
473 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
474 puts (" for jdwp help use: -agentlib:jdwp=help");
475 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
478 /* exit with error code */
484 static void Xusage(void)
486 #if defined(ENABLE_JIT)
487 puts(" -Xjit JIT mode execution (default)");
489 #if defined(ENABLE_INTRP)
490 puts(" -Xint interpreter mode execution");
492 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
493 puts(" value is set as bootstrap class path");
494 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
495 puts(" value is appended to the bootstrap class path");
496 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
497 puts(" value is prepended to the bootstrap class path");
498 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
499 puts(" value is used as Java core library, but the");
500 puts(" hardcoded VM interface classes are prepended");
501 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
502 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
503 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
505 #if defined(ENABLE_PROFILING)
506 puts(" -Xprof[:bb] collect and print profiling data");
509 #if defined(ENABLE_JVMTI)
510 /* -Xdebug option depend on gnu classpath JDWP options. options:
511 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
512 puts(" -Xdebug enable remote debugging\n");
513 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
514 puts(" enable remote debugging\n");
517 /* exit with error code */
524 static void XXusage(void)
526 puts(" -v write state-information");
528 puts(" -verbose:jit enable specific verbose output");
529 puts(" -debug-color colored output for ANSI terms");
531 #ifdef TYPECHECK_VERBOSE
532 puts(" -verbosetc write debug messages while typechecking");
534 #if defined(__ALPHA__)
535 puts(" -noieee don't use ieee compliant arithmetic");
537 #if defined(ENABLE_VERIFIER)
538 puts(" -noverify don't verify classfiles");
540 #if defined(ENABLE_STATISTICS)
541 puts(" -time measure the runtime");
542 puts(" -stat detailed compiler statistics");
544 puts(" -log logfile specify a name for the logfile");
545 puts(" -c(heck)b(ounds) don't check array bounds");
546 puts(" s(ync) don't check for synchronization");
547 #if defined(ENABLE_LOOP)
548 puts(" -oloop optimize array accesses in loops");
550 puts(" -l don't start the class after loading");
552 puts(" -all compile all methods, no execution");
553 puts(" -m compile only a specific method");
554 puts(" -sig specify signature for a specific method");
557 puts(" -s... show...");
558 puts(" (c)onstants the constant pool");
559 puts(" (m)ethods class fields and methods");
560 puts(" (u)tf the utf - hash");
561 puts(" (i)ntermediate intermediate representation");
562 #if defined(ENABLE_DISASSEMBLER)
563 puts(" (a)ssembler disassembled listing");
564 puts(" n(o)ps show NOPs in disassembler output");
566 puts(" (d)atasegment data segment listing");
568 #if defined(ENABLE_INLINING)
569 puts(" -i activate inlining");
571 puts(" -il log inlining");
573 #if defined(ENABLE_INLINING_DEBUG)
574 puts(" -ia use inlining for all methods");
575 puts(" -ii <size> set minimum size for inlined result");
576 puts(" -im <size> set maximum size for inlined result");
577 puts(" -ie <number> stop inlining after the given number of roots");
578 #endif /* defined(ENABLE_INLINING_DEBUG) */
579 #endif /* defined(ENABLE_INLINING) */
581 #if defined(ENABLE_IFCONV)
582 puts(" -ifconv use if-conversion");
584 #if defined(ENABLE_LSRA)
585 puts(" -lsra use linear scan register allocation");
587 #if defined(ENABLE_SSA)
588 puts(" -lsra use linear scan register allocation (with SSA)");
590 #if defined(ENABLE_DEBUG_FILTER)
591 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
592 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
593 puts(" -XXfm <regex> filter for show options");
595 /* exit with error code */
602 /* version *********************************************************************
604 Only prints cacao version information.
606 *******************************************************************************/
608 static void version(bool opt_exit)
610 puts("java version \""JAVA_VERSION"\"");
611 puts("CACAO version "VERSION"");
613 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
614 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
615 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
616 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
618 puts("This program is free software; you can redistribute it and/or");
619 puts("modify it under the terms of the GNU General Public License as");
620 puts("published by the Free Software Foundation; either version 2, or (at");
621 puts("your option) any later version.\n");
623 puts("This program is distributed in the hope that it will be useful, but");
624 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
625 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
626 puts("General Public License for more details.");
628 /* exit normally, if requested */
635 /* fullversion *****************************************************************
637 Prints a Sun compatible version information (required e.g. by
638 jpackage, www.jpackage.org).
640 *******************************************************************************/
642 static void fullversion(void)
644 puts("java full version \"cacao-"JAVA_VERSION"\"");
652 static void vm_printconfig(void)
654 puts("Configure/Build options:\n");
655 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
656 #if defined(__VERSION__)
657 puts(" CC : "VERSION_CC" ("__VERSION__")");
659 puts(" CC : "VERSION_CC"");
661 puts(" CFLAGS : "VERSION_CFLAGS"\n");
663 puts("Default variables:\n");
664 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
665 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
666 printf(" stack size : %d\n", STACK_SIZE);
668 #if defined(WITH_JRE_LAYOUT)
669 /* When we're building with JRE-layout, the default paths are the
670 same as the runtime paths. */
672 # if defined(WITH_CLASSPATH_GNU)
673 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
674 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
675 # elif defined(WITH_CLASSPATH_SUN)
676 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
677 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
683 puts("Runtime variables:\n");
684 printf(" maximum heap size : %d\n", opt_heapmaxsize);
685 printf(" initial heap size : %d\n", opt_heapstartsize);
686 printf(" stack size : %d\n", opt_stacksize);
688 #if defined(WITH_CLASSPATH_GNU)
689 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
690 #elif defined(WITH_CLASSPATH_SUN)
691 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
694 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
695 printf(" java.class.path : %s\n", properties_get("java.class.path"));
699 /* forward declarations *******************************************************/
701 static char *vm_get_mainclass_from_jar(char *mainstring);
703 static void vm_compile_all(void);
704 static void vm_compile_method(void);
708 /* vm_createjvm ****************************************************************
710 Implementation for JNI_CreateJavaVM.
712 *******************************************************************************/
714 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
716 JavaVMInitArgs *_vm_args;
720 /* get the arguments for the new JVM */
722 _vm_args = (JavaVMInitArgs *) vm_args;
724 /* get the VM and Env tables (must be set before vm_create) */
726 env = NEW(_Jv_JNIEnv);
728 #if defined(ENABLE_JNI)
729 env->env = &_Jv_JNINativeInterface;
732 /* XXX Set the global variable. Maybe we should do that differently. */
736 /* create and fill a JavaVM structure */
738 vm = NEW(_Jv_JavaVM);
740 #if defined(ENABLE_JNI)
741 vm->functions = &_Jv_JNIInvokeInterface;
744 /* XXX Set the global variable. Maybe we should do that differently. */
745 /* XXX JVMTI Agents needs a JavaVM */
749 /* actually create the JVM */
751 if (!vm_create(_vm_args))
754 /* now return the values */
756 *p_vm = (JavaVM *) vm;
757 *p_env = (void *) env;
762 /* release allocated memory */
764 FREE(env, _Jv_JNIEnv);
765 FREE(vm, _Jv_JavaVM);
771 /* vm_create *******************************************************************
773 Creates a JVM. Called by vm_createjvm.
775 *******************************************************************************/
777 bool vm_create(JavaVMInitArgs *vm_args)
781 char *boot_class_path;
788 #if defined(ENABLE_JVMTI)
790 char *libname, *agentarg;
791 bool jdwp,agentbypath;
792 jdwp = agentbypath = false;
795 #if defined(ENABLE_VMLOG)
796 vmlog_cacao_init(vm_args);
799 #if defined(ENABLE_JNI)
800 /* Check the JNI version requested. */
802 if (!jni_version_check(vm_args->version))
806 /* We only support 1 JVM instance. */
811 /* Install the exit handler. */
813 if (atexit(vm_exit_handler))
814 vm_abort("atexit failed: %s\n", strerror(errno));
816 /* Set some options. */
823 opt_heapmaxsize = HEAP_MAXSIZE;
824 opt_heapstartsize = HEAP_STARTSIZE;
825 opt_stacksize = STACK_SIZE;
827 /* Initialize the properties list before command-line handling.
828 Otherwise -XX:+PrintConfig crashes. */
832 /* First of all, parse the -XX options. */
836 /* We need to check if the actual size of a java.lang.Class object
837 is smaller or equal than the assumption made in
838 src/vmcore/class.h. */
840 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
841 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
843 /* set the VM starttime */
845 _Jv_jvm->starttime = builtin_currenttimemillis();
847 #if defined(ENABLE_JVMTI)
848 /* initialize JVMTI related **********************************************/
852 /* Fill the properties before command-line handling. */
856 /* iterate over all passed options */
858 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
872 #if SIZEOF_VOID_P == 8
873 puts("Running a 32-bit JVM is not supported on this platform.");
879 #if SIZEOF_VOID_P == 4
880 puts("Running a 64-bit JVM is not supported on this platform.");
886 /* Forget old classpath and set the argument as new
889 class_path = properties_get("java.class.path");
891 p = MNEW(char, strlen(opt_arg) + strlen("0"));
895 #if defined(ENABLE_JAVASE)
896 properties_add("java.class.path", p);
899 MFREE(class_path, char, strlen(class_path));
903 for (i = 0; i < strlen(opt_arg); i++) {
904 if (opt_arg[i] == '=') {
906 properties_add(opt_arg, opt_arg + i + 1);
911 /* if no '=' is given, just create an empty property */
913 properties_add(opt_arg, "");
918 case OPT_BOOTCLASSPATH:
919 /* Forget default bootclasspath and set the argument as
920 new boot classpath. */
922 boot_class_path = properties_get("sun.boot.class.path");
924 p = MNEW(char, strlen(opt_arg) + strlen("0"));
928 properties_add("sun.boot.class.path", p);
929 properties_add("java.boot.class.path", p);
931 MFREE(boot_class_path, char, strlen(boot_class_path));
934 case OPT_BOOTCLASSPATH_A:
935 /* Append to bootclasspath. */
937 boot_class_path = properties_get("sun.boot.class.path");
939 len = strlen(boot_class_path);
941 p = MREALLOC(boot_class_path,
945 strlen(opt_arg) + strlen("0"));
950 properties_add("sun.boot.class.path", p);
951 properties_add("java.boot.class.path", p);
954 case OPT_BOOTCLASSPATH_P:
955 /* Prepend to bootclasspath. */
957 boot_class_path = properties_get("sun.boot.class.path");
959 len = strlen(boot_class_path);
961 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
965 strcat(p, boot_class_path);
967 properties_add("sun.boot.class.path", p);
968 properties_add("java.boot.class.path", p);
970 MFREE(boot_class_path, char, len);
973 case OPT_BOOTCLASSPATH_C:
974 /* Use as Java core library, but prepend VM interface
977 boot_class_path = properties_get("sun.boot.class.path");
980 strlen(CACAO_VM_ZIP) +
987 strcpy(p, CACAO_VM_ZIP);
991 properties_add("sun.boot.class.path", p);
992 properties_add("java.boot.class.path", p);
994 MFREE(boot_class_path, char, strlen(boot_class_path));
997 #if defined(ENABLE_JVMTI)
999 /* this option exists only for compatibility reasons */
1003 /* I don't know yet what Xnoagent should do. This is only for
1004 compatiblity with eclipse - motse */
1013 strlen(CACAO_LIBDIR) +
1014 strlen("/libjdwp.so=") +
1018 agentarg = MNEW(char, len);
1020 strcpy(agentarg, CACAO_LIBDIR);
1021 strcat(agentarg, "/libjdwp.so=");
1022 strcat(agentarg, &opt_arg[1]);
1039 c = opt_arg[strlen(opt_arg) - 1];
1041 if ((c == 'k') || (c == 'K')) {
1042 j = atoi(opt_arg) * 1024;
1044 } else if ((c == 'm') || (c == 'M')) {
1045 j = atoi(opt_arg) * 1024 * 1024;
1051 opt_heapmaxsize = j;
1052 else if (opt == OPT_MS)
1053 opt_heapstartsize = j;
1064 if (strcmp("class", opt_arg) == 0) {
1065 opt_verboseclass = true;
1067 else if (strcmp("gc", opt_arg) == 0) {
1068 opt_verbosegc = true;
1070 else if (strcmp("jni", opt_arg) == 0) {
1071 opt_verbosejni = true;
1073 #if !defined(NDEBUG)
1074 else if (strcmp("jit", opt_arg) == 0) {
1078 compileverbose = true;
1082 printf("Unknown -verbose option: %s\n", opt_arg);
1087 case OPT_DEBUGCOLOR:
1088 opt_debugcolor = true;
1091 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1093 opt_typecheckverbose = true;
1102 case OPT_FULLVERSION:
1106 case OPT_SHOWVERSION:
1114 #if defined(ENABLE_VERIFIER)
1120 #if defined(ENABLE_STATISTICS)
1122 opt_getcompilingtime = true;
1123 opt_getloadingtime = true;
1136 for (i = 0; i < strlen(opt_arg); i++) {
1137 switch (opt_arg[i]) {
1139 checkbounds = false;
1152 makeinitializations = false;
1155 #if !defined(NDEBUG)
1159 makeinitializations = false;
1164 opt_method = opt_arg;
1165 makeinitializations = false;
1169 opt_signature = opt_arg;
1173 case OPT_SHOW: /* Display options */
1174 for (i = 0; i < strlen(opt_arg); i++) {
1175 switch (opt_arg[i]) {
1177 showconstantpool = true;
1189 opt_showintermediate = true;
1190 compileverbose = true;
1193 #if defined(ENABLE_DISASSEMBLER)
1195 opt_showdisassemble = true;
1196 compileverbose = true;
1200 opt_shownops = true;
1205 opt_showddatasegment = true;
1214 #if defined(ENABLE_LOOP)
1220 #if defined(ENABLE_INLINING)
1221 #if defined(ENABLE_INLINING_DEBUG)
1222 case OPT_INLINE_DEBUG_ALL:
1223 opt_inline_debug_all = true;
1225 case OPT_INLINE_DEBUG_END:
1226 opt_inline_debug_end_counter = atoi(opt_arg);
1228 case OPT_INLINE_DEBUG_MIN:
1229 opt_inline_debug_min_size = atoi(opt_arg);
1231 case OPT_INLINE_DEBUG_MAX:
1232 opt_inline_debug_max_size = atoi(opt_arg);
1234 #endif /* defined(ENABLE_INLINING_DEBUG) */
1235 #if !defined(NDEBUG)
1236 case OPT_INLINE_LOG:
1237 opt_inline_debug_log = true;
1239 #endif /* !defined(NDEBUG) */
1242 opt_inlining = true;
1244 #endif /* defined(ENABLE_INLINING) */
1246 #if defined(ENABLE_IFCONV)
1252 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1267 /* Already parsed. */
1271 #if defined(ENABLE_ASSERTION)
1272 assertion_ea_da(opt_arg, true);
1277 #if defined(ENABLE_ASSERTION)
1278 assertion_ea_da(opt_arg, false);
1283 #if defined(ENABLE_ASSERTION)
1284 assertion_system_enabled = true;
1289 #if defined(ENABLE_ASSERTION)
1290 assertion_system_enabled = false;
1294 #if defined(ENABLE_PROFILING)
1295 case OPT_PROF_OPTION:
1296 /* use <= to get the last \0 too */
1298 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1299 if (opt_arg[i] == ',')
1302 if (opt_arg[i] == '\0') {
1303 if (strcmp("bb", opt_arg + j) == 0)
1307 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1311 /* set k to next char */
1324 #if defined(ENABLE_JIT)
1327 printf("-Xjit option not enabled.\n");
1333 #if defined(ENABLE_INTRP)
1336 printf("-Xint option not enabled.\n");
1341 #if defined(ENABLE_INTRP)
1342 case OPT_STATIC_SUPERS:
1343 opt_static_supers = atoi(opt_arg);
1346 case OPT_NO_DYNAMIC:
1347 opt_no_dynamic = true;
1350 case OPT_NO_REPLICATION:
1351 opt_no_replication = true;
1354 case OPT_NO_QUICKSUPER:
1355 opt_no_quicksuper = true;
1363 #if defined(ENABLE_DEBUG_FILTER)
1364 case OPT_FILTER_VERBOSECALL_INCLUDE:
1365 opt_filter_verbosecall_include = opt_arg;
1368 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1369 opt_filter_verbosecall_exclude = opt_arg;
1372 case OPT_FILTER_SHOW_METHOD:
1373 opt_filter_show_method = opt_arg;
1378 printf("Unknown option: %s\n",
1379 vm_args->options[opt_index].optionString);
1384 /* get the main class *****************************************************/
1386 if (opt_index < vm_args->nOptions) {
1387 mainstring = vm_args->options[opt_index++].optionString;
1389 /* Put the jar file into the classpath (if any). */
1391 if (opt_jar == true) {
1392 /* free old classpath */
1394 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1396 /* put jarfile into classpath */
1398 p = MNEW(char, strlen(mainstring) + strlen("0"));
1400 strcpy(p, mainstring);
1402 #if defined(ENABLE_JAVASE)
1403 properties_add("java.class.path", p);
1407 /* replace .'s with /'s in classname */
1409 for (i = strlen(mainstring) - 1; i >= 0; i--)
1410 if (mainstring[i] == '.')
1411 mainstring[i] = '/';
1415 #if defined(ENABLE_JVMTI)
1417 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1418 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1421 MFREE(agentarg, char, strlen(agentarg));
1423 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1427 /* initialize this JVM ****************************************************/
1429 vm_initializing = true;
1431 /* initialize the garbage collector */
1433 gc_init(opt_heapmaxsize, opt_heapstartsize);
1435 #if defined(ENABLE_THREADS)
1436 /* AFTER: gc_init (directly after, as this initializes the
1437 stopworldlock lock */
1442 /* install architecture dependent signal handlers */
1445 vm_abort("vm_create: signal_init failed");
1447 #if defined(ENABLE_INTRP)
1448 /* Allocate main thread stack on the Java heap. */
1451 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1452 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1456 /* AFTER: threads_preinit */
1459 vm_abort("vm_create: string_init failed");
1461 /* AFTER: threads_preinit */
1464 vm_abort("vm_create: utf8_init failed");
1466 /* AFTER: thread_preinit */
1469 vm_abort("vm_create: suck_init failed");
1471 suck_add_from_property("java.endorsed.dirs");
1473 /* Now we have all options handled and we can print the version
1476 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1481 /* AFTER: utf8_init */
1483 boot_class_path = properties_get("sun.boot.class.path");
1484 suck_add(boot_class_path);
1486 /* initialize the classcache hashtable stuff: lock, hashtable
1487 (must be done _after_ threads_preinit) */
1489 if (!classcache_init())
1490 vm_abort("vm_create: classcache_init failed");
1492 /* initialize the memory subsystem (must be done _after_
1496 vm_abort("vm_create: memory_init failed");
1498 /* initialize the finalizer stuff (must be done _after_
1501 if (!finalizer_init())
1502 vm_abort("vm_create: finalizer_init failed");
1504 /* initializes jit compiler */
1508 #if defined(ENABLE_PYTHON)
1512 /* BEFORE: loader_preinit */
1516 /* AFTER: utf8_init, classcache_init */
1521 /* AFTER: loader_preinit, linker_preinit */
1528 /* AFTER: loader_init, linker_init */
1530 primitive_postinit();
1534 if (!builtin_init())
1535 vm_abort("vm_create: builtin_init failed");
1537 /* Initialize the native subsystem. */
1538 /* BEFORE: threads_init */
1541 vm_abort("vm_create: native_init failed");
1543 /* Register the native methods implemented in the VM. */
1544 /* BEFORE: threads_init */
1546 if (!nativevm_preinit())
1547 vm_abort("vm_create: nativevm_preinit failed");
1549 #if defined(ENABLE_JNI)
1550 /* Initialize the JNI subsystem (must be done _before_
1551 threads_init, as threads_init can call JNI methods
1552 (e.g. NewGlobalRef). */
1555 vm_abort("vm_create: jni_init failed");
1558 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1559 /* Initialize the local reference table for the main thread. */
1560 /* BEFORE: threads_init */
1562 if (!localref_table_init())
1563 vm_abort("vm_create: localref_table_init failed");
1566 #if defined(ENABLE_THREADS)
1567 if (!threads_init())
1568 vm_abort("vm_create: threads_init failed");
1571 /* Initialize the native VM subsystem. */
1572 /* AFTER: threads_init (at least for SUN's classes) */
1574 if (!nativevm_init())
1575 vm_abort("vm_create: nativevm_init failed");
1577 #if defined(ENABLE_PROFILING)
1578 /* initialize profiling */
1580 if (!profile_init())
1581 vm_abort("vm_create: profile_init failed");
1584 #if defined(ENABLE_THREADS)
1585 /* initialize recompilation */
1587 if (!recompile_init())
1588 vm_abort("vm_create: recompile_init failed");
1590 /* start the signal handler thread */
1592 #if defined(__LINUX__)
1593 /* XXX Remove for exact-GC. */
1594 if (threads_pthreads_implementation_nptl)
1596 if (!signal_start_thread())
1597 vm_abort("vm_create: signal_start_thread failed");
1599 /* finally, start the finalizer thread */
1601 if (!finalizer_start_thread())
1602 vm_abort("vm_create: finalizer_start_thread failed");
1604 # if !defined(NDEBUG)
1605 /* start the memory profiling thread */
1607 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1608 if (!memory_start_thread())
1609 vm_abort("vm_create: memory_start_thread failed");
1612 /* start the recompilation thread (must be done before the
1613 profiling thread) */
1615 if (!recompile_start_thread())
1616 vm_abort("vm_create: recompile_start_thread failed");
1618 # if defined(ENABLE_PROFILING)
1619 /* start the profile sampling thread */
1622 /* if (!profile_start_thread()) */
1623 /* vm_abort("vm_create: profile_start_thread failed"); */
1627 #if defined(ENABLE_JVMTI)
1628 # if defined(ENABLE_GC_CACAO)
1629 /* XXX this will not work with the new indirection cells for classloaders!!! */
1633 /* add agent library to native library hashtable */
1634 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1638 /* increment the number of VMs */
1642 /* initialization is done */
1644 vm_initializing = false;
1646 #if !defined(NDEBUG)
1647 /* Print the VM configuration after all stuff is set and the VM is
1650 if (opt_PrintConfig)
1654 /* everything's ok */
1660 /* vm_run **********************************************************************
1662 Runs the main-method of the passed class.
1664 *******************************************************************************/
1666 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1669 classinfo *mainclass;
1672 java_handle_objectarray_t *oa;
1679 #if !defined(NDEBUG)
1685 if (opt_method != NULL) {
1686 vm_compile_method();
1689 #endif /* !defined(NDEBUG) */
1691 /* should we run the main-method? */
1693 if (mainstring == NULL)
1696 /* set return value to OK */
1700 if (opt_jar == true) {
1701 /* open jar file with java.util.jar.JarFile */
1703 mainstring = vm_get_mainclass_from_jar(mainstring);
1705 if (mainstring == NULL)
1709 /* load the main class */
1711 mainutf = utf_new_char(mainstring);
1713 #if defined(ENABLE_JAVAME_CLDC1_1)
1714 mainclass = load_class_bootstrap(mainutf);
1716 mainclass = load_class_from_sysloader(mainutf);
1719 /* error loading class */
1721 e = exceptions_get_and_clear_exception();
1723 if ((e != NULL) || (mainclass == NULL)) {
1724 exceptions_throw_noclassdeffounderror_cause(e);
1725 exceptions_print_stacktrace();
1729 if (!link_class(mainclass)) {
1730 exceptions_print_stacktrace();
1734 /* find the `main' method of the main class */
1736 m = class_resolveclassmethod(mainclass,
1737 utf_new_char("main"),
1738 utf_new_char("([Ljava/lang/String;)V"),
1739 class_java_lang_Object,
1742 if (exceptions_get_exception()) {
1743 exceptions_print_stacktrace();
1747 /* there is no main method or it isn't static */
1749 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1750 exceptions_clear_exception();
1751 exceptions_throw_nosuchmethoderror(mainclass,
1752 utf_new_char("main"),
1753 utf_new_char("([Ljava/lang/String;)V"));
1755 exceptions_print_stacktrace();
1759 /* build argument array */
1761 oalength = vm_args->nOptions - opt_index;
1763 oa = builtin_anewarray(oalength, class_java_lang_String);
1765 for (i = 0; i < oalength; i++) {
1766 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1767 s = javastring_new(u);
1769 array_objectarray_element_set(oa, i, s);
1772 #ifdef TYPEINFO_DEBUG_TEST
1773 /* test the typeinfo system */
1776 /*class_showmethods(currentThread->group->header.vftbl->class); */
1778 #if defined(ENABLE_JVMTI)
1779 jvmti_set_phase(JVMTI_PHASE_LIVE);
1782 /* set ThreadMXBean variables */
1784 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1785 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1787 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1788 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1789 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1790 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1792 /* start the main thread */
1794 (void) vm_call_method(m, NULL, oa);
1796 /* exception occurred? */
1798 if (exceptions_get_exception()) {
1799 exceptions_print_stacktrace();
1803 /* unload the JavaVM */
1805 (void) vm_destroy(vm);
1813 /* vm_destroy ******************************************************************
1815 Unloads a Java VM and reclaims its resources.
1817 *******************************************************************************/
1819 s4 vm_destroy(JavaVM *vm)
1821 #if defined(ENABLE_THREADS)
1822 threads_join_all_threads();
1825 /* everything's ok */
1831 /* vm_exit *********************************************************************
1833 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1835 *******************************************************************************/
1837 void vm_exit(s4 status)
1841 /* signal that we are exiting */
1845 assert(class_java_lang_System);
1846 assert(class_java_lang_System->state & CLASS_LOADED);
1848 #if defined(ENABLE_JVMTI)
1849 if (jvmti || (dbgcom!=NULL)) {
1850 jvmti_set_phase(JVMTI_PHASE_DEAD);
1851 if (jvmti) jvmti_agentunload();
1855 if (!link_class(class_java_lang_System)) {
1856 exceptions_print_stacktrace();
1860 /* call java.lang.System.exit(I)V */
1862 m = class_resolveclassmethod(class_java_lang_System,
1863 utf_new_char("exit"),
1865 class_java_lang_Object,
1869 exceptions_print_stacktrace();
1873 /* call the exit function with passed exit status */
1875 (void) vm_call_method(m, NULL, status);
1877 /* If we had an exception, just ignore the exception and exit with
1880 vm_shutdown(status);
1884 /* vm_shutdown *****************************************************************
1886 Terminates the system immediately without freeing memory explicitly
1887 (to be used only for abnormal termination).
1889 *******************************************************************************/
1891 void vm_shutdown(s4 status)
1894 #if defined(ENABLE_STATISTICS)
1895 || opt_getcompilingtime || opt_stat
1899 log_text("CACAO terminated by shutdown");
1900 dolog("Exit status: %d\n", (s4) status);
1904 #if defined(ENABLE_JVMTI)
1905 /* terminate cacaodbgserver */
1907 pthread_mutex_lock(&dbgcomlock);
1909 pthread_mutex_unlock(&dbgcomlock);
1910 jvmti_cacaodbgserver_quit();
1918 /* vm_exit_handler *************************************************************
1920 The exit_handler function is called upon program termination.
1922 ATTENTION: Don't free system resources here! Some threads may still
1923 be running as this is called from VMRuntime.exit(). The OS does the
1926 *******************************************************************************/
1928 void vm_exit_handler(void)
1930 #if !defined(NDEBUG)
1932 class_showmethods(mainclass);
1934 if (showconstantpool)
1935 class_showconstantpool(mainclass);
1940 # if defined(ENABLE_PROFILING)
1942 profile_printstats();
1944 #endif /* !defined(NDEBUG) */
1946 #if defined(ENABLE_RT_TIMING)
1947 rt_timing_print_time_stats(stderr);
1950 #if defined(ENABLE_CYCLES_STATS)
1951 builtin_print_cycles_stats(stderr);
1952 stacktrace_print_cycles_stats(stderr);
1956 #if defined(ENABLE_STATISTICS)
1957 || opt_getcompilingtime || opt_stat
1961 log_text("CACAO terminated");
1963 #if defined(ENABLE_STATISTICS)
1966 #ifdef TYPECHECK_STATISTICS
1967 typecheck_print_statistics(get_logfile());
1971 if (opt_getcompilingtime)
1973 #endif /* defined(ENABLE_STATISTICS) */
1975 /* vm_print_profile(stderr);*/
1979 /* vm_abort ********************************************************************
1981 Prints an error message and aborts the VM.
1983 *******************************************************************************/
1985 void vm_abort(const char *text, ...)
1989 /* print the log message */
1994 log_vprint(text, ap);
1999 /* now abort the VM */
2005 /* vm_abort_disassemble ********************************************************
2007 Prints an error message, disassemble the given code range (if
2008 enabled) and aborts the VM.
2011 pc.......PC to disassemble
2012 count....number of instructions to disassemble
2014 *******************************************************************************/
2016 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2019 #if defined(ENABLE_DISASSEMBLER)
2023 /* Print debug message. */
2028 log_vprint(text, ap);
2035 #if SIZEOF_VOID_P == 8
2036 log_println("PC=0x%016lx", pc);
2038 log_println("PC=0x%08x", pc);
2041 #if defined(ENABLE_DISASSEMBLER)
2042 log_println("machine instructions at PC:");
2044 /* Disassemble the given number of instructions. */
2046 for (i = 0; i < count; i++)
2047 pc = disassinstr(pc);
2050 vm_abort("Aborting...");
2054 /* vm_get_mainclass_from_jar ***************************************************
2056 Gets the name of the main class from a JAR's manifest file.
2058 *******************************************************************************/
2060 static char *vm_get_mainclass_from_jar(char *mainstring)
2067 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2070 exceptions_print_stacktrace();
2074 /* create JarFile object */
2079 exceptions_print_stacktrace();
2083 m = class_resolveclassmethod(c,
2085 utf_java_lang_String__void,
2086 class_java_lang_Object,
2090 exceptions_print_stacktrace();
2094 s = javastring_new_from_ascii(mainstring);
2096 (void) vm_call_method(m, o, s);
2098 if (exceptions_get_exception()) {
2099 exceptions_print_stacktrace();
2103 /* get manifest object */
2105 m = class_resolveclassmethod(c,
2106 utf_new_char("getManifest"),
2107 utf_new_char("()Ljava/util/jar/Manifest;"),
2108 class_java_lang_Object,
2112 exceptions_print_stacktrace();
2116 o = vm_call_method(m, o);
2119 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2124 /* get Main Attributes */
2126 LLNI_class_get(o, c);
2128 m = class_resolveclassmethod(c,
2129 utf_new_char("getMainAttributes"),
2130 utf_new_char("()Ljava/util/jar/Attributes;"),
2131 class_java_lang_Object,
2135 exceptions_print_stacktrace();
2139 o = vm_call_method(m, o);
2142 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2147 /* get property Main-Class */
2149 LLNI_class_get(o, c);
2151 m = class_resolveclassmethod(c,
2152 utf_new_char("getValue"),
2153 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2154 class_java_lang_Object,
2158 exceptions_print_stacktrace();
2162 s = javastring_new_from_ascii("Main-Class");
2164 o = vm_call_method(m, o, s);
2167 exceptions_print_stacktrace();
2171 return javastring_tochar(o);
2175 /* vm_compile_all **************************************************************
2177 Compile all methods found in the bootclasspath.
2179 *******************************************************************************/
2181 #if !defined(NDEBUG)
2182 static void vm_compile_all(void)
2187 classcache_name_entry *nmen;
2188 classcache_class_entry *clsen;
2191 /* create all classes found in the bootclasspath */
2192 /* XXX currently only works with zip/jar's */
2194 loader_load_all_classes();
2196 /* link all classes */
2198 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2199 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2201 for (; nmen; nmen = nmen->hashlink) {
2202 /* iterate over all class entries */
2204 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2205 c = clsen->classobj;
2210 if (!(c->state & CLASS_LINKED)) {
2211 if (!link_class(c)) {
2212 fprintf(stderr, "Error linking: ");
2213 utf_fprint_printable_ascii_classname(stderr, c->name);
2214 fprintf(stderr, "\n");
2216 /* print out exception and cause */
2218 exceptions_print_current_exception();
2220 /* goto next class */
2226 /* compile all class methods */
2228 for (i = 0; i < c->methodscount; i++) {
2229 m = &(c->methods[i]);
2231 if (m->jcode != NULL) {
2232 if (!jit_compile(m)) {
2233 fprintf(stderr, "Error compiling: ");
2234 utf_fprint_printable_ascii_classname(stderr, c->name);
2235 fprintf(stderr, ".");
2236 utf_fprint_printable_ascii(stderr, m->name);
2237 utf_fprint_printable_ascii(stderr, m->descriptor);
2238 fprintf(stderr, "\n");
2240 /* print out exception and cause */
2242 exceptions_print_current_exception();
2250 #endif /* !defined(NDEBUG) */
2253 /* vm_compile_method ***********************************************************
2255 Compile a specific method.
2257 *******************************************************************************/
2259 #if !defined(NDEBUG)
2260 static void vm_compile_method(void)
2264 /* create, load and link the main class */
2266 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2268 if (mainclass == NULL)
2269 exceptions_print_stacktrace();
2271 if (!link_class(mainclass))
2272 exceptions_print_stacktrace();
2274 if (opt_signature != NULL) {
2275 m = class_resolveclassmethod(mainclass,
2276 utf_new_char(opt_method),
2277 utf_new_char(opt_signature),
2282 m = class_resolveclassmethod(mainclass,
2283 utf_new_char(opt_method),
2290 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2291 opt_method, opt_signature ? opt_signature : "");
2295 #endif /* !defined(NDEBUG) */
2298 /* vm_call_array ***************************************************************
2300 Calls a Java method with a variable number of arguments, passed via
2303 ATTENTION: This function has to be used outside the nativeworld.
2305 *******************************************************************************/
2307 #define VM_CALL_ARRAY(name, type) \
2308 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2314 assert(m->code != NULL); \
2316 md = m->parseddesc; \
2317 pv = m->code->entrypoint; \
2319 STATISTICS(count_calls_native_to_java++); \
2321 value = asm_vm_call_method##name(pv, array, md->memuse); \
2326 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2332 assert(m->code != NULL);
2335 pv = m->code->entrypoint;
2337 STATISTICS(count_calls_native_to_java++);
2339 o = asm_vm_call_method(pv, array, md->memuse);
2341 if (md->returntype.type == TYPE_VOID)
2344 return LLNI_WRAP(o);
2347 VM_CALL_ARRAY(_int, int32_t)
2348 VM_CALL_ARRAY(_long, int64_t)
2349 VM_CALL_ARRAY(_float, float)
2350 VM_CALL_ARRAY(_double, double)
2353 /* vm_call_method **************************************************************
2355 Calls a Java method with a variable number of arguments.
2357 *******************************************************************************/
2359 #define VM_CALL_METHOD(name, type) \
2360 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2366 value = vm_call_method##name##_valist(m, o, ap); \
2372 VM_CALL_METHOD(, java_handle_t *)
2373 VM_CALL_METHOD(_int, int32_t)
2374 VM_CALL_METHOD(_long, int64_t)
2375 VM_CALL_METHOD(_float, float)
2376 VM_CALL_METHOD(_double, double)
2379 /* vm_call_method_valist *******************************************************
2381 Calls a Java method with a variable number of arguments, passed via
2384 *******************************************************************************/
2386 #define VM_CALL_METHOD_VALIST(name, type) \
2387 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2394 if (m->code == NULL) \
2395 if (!jit_compile(m)) \
2398 THREAD_NATIVEWORLD_EXIT; \
2400 dumpsize = dump_size(); \
2401 array = argument_vmarray_from_valist(m, o, ap); \
2402 value = vm_call##name##_array(m, array); \
2403 dump_release(dumpsize); \
2405 THREAD_NATIVEWORLD_ENTER; \
2410 VM_CALL_METHOD_VALIST(, java_handle_t *)
2411 VM_CALL_METHOD_VALIST(_int, int32_t)
2412 VM_CALL_METHOD_VALIST(_long, int64_t)
2413 VM_CALL_METHOD_VALIST(_float, float)
2414 VM_CALL_METHOD_VALIST(_double, double)
2417 /* vm_call_method_jvalue *******************************************************
2419 Calls a Java method with a variable number of arguments, passed via
2422 *******************************************************************************/
2424 #define VM_CALL_METHOD_JVALUE(name, type) \
2425 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2426 const jvalue *args) \
2432 if (m->code == NULL) \
2433 if (!jit_compile(m)) \
2436 THREAD_NATIVEWORLD_EXIT; \
2438 dumpsize = dump_size(); \
2439 array = argument_vmarray_from_jvalue(m, o, args); \
2440 value = vm_call##name##_array(m, array); \
2441 dump_release(dumpsize); \
2443 THREAD_NATIVEWORLD_ENTER; \
2448 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2449 VM_CALL_METHOD_JVALUE(_int, int32_t)
2450 VM_CALL_METHOD_JVALUE(_long, int64_t)
2451 VM_CALL_METHOD_JVALUE(_float, float)
2452 VM_CALL_METHOD_JVALUE(_double, double)
2455 /* vm_call_method_objectarray **************************************************
2457 Calls a Java method with a variable number if arguments, passed via
2458 an objectarray of boxed values. Returns a boxed value.
2460 *******************************************************************************/
2462 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2463 java_handle_objectarray_t *params)
2467 java_handle_t *xptr;
2471 /* compile methods which are not yet compiled */
2473 if (m->code == NULL)
2474 if (!jit_compile(m))
2477 /* leave the nativeworld */
2479 THREAD_NATIVEWORLD_EXIT;
2481 /* mark start of dump memory area */
2483 dumpsize = dump_size();
2485 /* Fill the argument array from a object-array. */
2487 array = argument_vmarray_from_objectarray(m, o, params);
2489 if (array == NULL) {
2490 /* release dump area */
2492 dump_release(dumpsize);
2494 /* enter the nativeworld again */
2496 THREAD_NATIVEWORLD_ENTER;
2498 exceptions_throw_illegalargumentexception();
2503 switch (m->parseddesc->returntype.decltype) {
2504 case PRIMITIVETYPE_VOID:
2505 value.a = vm_call_array(m, array);
2508 case PRIMITIVETYPE_BOOLEAN:
2509 case PRIMITIVETYPE_BYTE:
2510 case PRIMITIVETYPE_CHAR:
2511 case PRIMITIVETYPE_SHORT:
2512 case PRIMITIVETYPE_INT:
2513 value.i = vm_call_int_array(m, array);
2516 case PRIMITIVETYPE_LONG:
2517 value.l = vm_call_long_array(m, array);
2520 case PRIMITIVETYPE_FLOAT:
2521 value.f = vm_call_float_array(m, array);
2524 case PRIMITIVETYPE_DOUBLE:
2525 value.d = vm_call_double_array(m, array);
2529 ro = vm_call_array(m, array);
2533 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2536 /* release dump area */
2538 dump_release(dumpsize);
2540 /* enter the nativeworld again */
2542 THREAD_NATIVEWORLD_ENTER;
2544 /* box the return value if necesarry */
2546 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2547 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2549 /* check for an exception */
2551 xptr = exceptions_get_exception();
2554 /* clear exception pointer, we are calling JIT code again */
2556 exceptions_clear_exception();
2558 exceptions_throw_invocationtargetexception(xptr);
2566 * These are local overrides for various environment variables in Emacs.
2567 * Please do not remove this and leave it at the end of the file, where
2568 * Emacs will automagically detect them.
2569 * ---------------------------------------------------------------------
2572 * indent-tabs-mode: t
2576 * vim:noexpandtab:sw=4:ts=4: