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
25 $Id: vm.c 4357 2006-01-22 23:33:38Z twisti $
36 #if defined(WITH_JRE_LAYOUT)
43 #include "mm/gc-common.h"
44 #include "mm/memory.h"
46 #include "native/jni.h"
47 #include "native/native.h"
48 #include "native/include/java_lang_Class.h"
49 #include "native/include/java_lang_String.h"
51 #if defined(ENABLE_THREADS)
52 # include "threads/native/threads.h"
55 #include "toolbox/logging.h"
57 #include "vm/builtin.h"
58 #include "vm/exceptions.h"
59 #include "vm/finalizer.h"
60 #include "vm/global.h"
61 #include "vm/initialize.h"
62 #include "vm/properties.h"
63 #include "vm/signallocal.h"
64 #include "vm/stringlocal.h"
67 #include "vm/jit/jit.h"
68 #include "vm/jit/md.h"
69 #include "vm/jit/asmpart.h"
71 #if defined(ENABLE_PROFILING)
72 # include "vm/jit/optimizing/profile.h"
75 #include "vm/jit/optimizing/recompile.h"
77 #include "vmcore/classcache.h"
78 #include "vmcore/options.h"
79 #include "vmcore/suck.h"
81 #if defined(ENABLE_JVMTI)
82 # include "native/jvmti/cacaodbg.h"
86 /* Invocation API variables ***************************************************/
88 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
89 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
92 /* global variables ***********************************************************/
94 s4 vms = 0; /* number of VMs created */
96 bool vm_initializing = false;
97 bool vm_exiting = false;
99 char *cacao_prefix = NULL;
100 char *cacao_libjvm = NULL;
101 char *classpath_libdir = NULL;
103 char *_Jv_bootclasspath; /* contains the boot classpath */
104 char *_Jv_classpath; /* contains the classpath */
105 char *_Jv_java_library_path;
107 char *mainstring = NULL;
108 classinfo *mainclass = NULL;
110 char *specificmethodname = NULL;
111 char *specificsignature = NULL;
115 #if defined(ENABLE_INTRP)
116 u1 *intrp_main_stack = NULL;
120 /* define heap sizes **********************************************************/
122 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
123 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
124 #define STACK_SIZE 64 * 1024 /* default 64kB */
127 /* define command line options ************************************************/
155 /* Java non-standard options */
166 #if defined(ENABLE_PROFILING)
180 #if defined(ENABLE_STATISTICS)
197 #if defined(ENABLE_VERIFIER)
199 #if defined(TYPECHECK_VERBOSE)
202 #endif /* defined(ENABLE_VERIFIER) */
205 /* optimization options */
207 #if defined(ENABLE_LOOP)
211 #if defined(ENABLE_IFCONV)
215 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
219 #if defined(ENABLE_INLINING)
224 #if defined(ENABLE_INLINING_DEBUG)
225 OPT_INLINE_DEBUG_ALL,
226 OPT_INLINE_DEBUG_END,
227 OPT_INLINE_DEBUG_MIN,
228 OPT_INLINE_DEBUG_MAX,
229 OPT_INLINE_REPLACE_VERBOSE,
230 OPT_INLINE_REPLACE_VERBOSE2,
231 #endif /* defined(ENABLE_INLINING_DEBUG) */
232 #endif /* defined(ENABLE_INLINING) */
234 #if defined(ENABLE_INTRP)
235 /* interpreter options */
258 opt_struct opts[] = {
259 { "foo", false, OPT_FOO },
263 { "jar", false, OPT_JAR },
265 { "d32", false, OPT_D32 },
266 { "d64", false, OPT_D64 },
267 { "client", false, OPT_IGNORE },
268 { "server", false, OPT_IGNORE },
269 { "jvm", false, OPT_IGNORE },
270 { "hotspot", false, OPT_IGNORE },
272 { "classpath", true, OPT_CLASSPATH },
273 { "cp", true, OPT_CLASSPATH },
274 { "D", true, OPT_D },
275 { "version", false, OPT_VERSION },
276 { "showversion", false, OPT_SHOWVERSION },
277 { "fullversion", false, OPT_FULLVERSION },
278 { "help", false, OPT_HELP },
279 { "?", false, OPT_HELP },
280 { "X", false, OPT_X },
281 { "XX", false, OPT_XX },
283 { "esa", false, OPT_ESA },
284 { "enablesystemassertions", false, OPT_ESA },
285 { "dsa", false, OPT_DSA },
286 { "disablesystemassertions", false, OPT_DSA },
288 { "noasyncgc", false, OPT_IGNORE },
289 #if defined(ENABLE_VERIFIER)
290 { "noverify", false, OPT_NOVERIFY },
292 { "v", false, OPT_VERBOSE1 },
293 { "verbose:", true, OPT_VERBOSE },
295 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
296 { "verbosetc", false, OPT_VERBOSETC },
298 #if defined(__ALPHA__)
299 { "noieee", false, OPT_NOIEEE },
301 { "softnull", false, OPT_SOFTNULL },
302 #if defined(ENABLE_STATISTICS)
303 { "time", false, OPT_TIME },
304 { "stat", false, OPT_STAT },
306 { "log", true, OPT_LOG },
307 { "c", true, OPT_CHECK },
308 { "l", false, OPT_LOAD },
309 { "eager", false, OPT_EAGER },
312 { "all", false, OPT_ALL },
313 { "sig", true, OPT_SIGNATURE },
316 #if defined(ENABLE_LOOP)
317 { "oloop", false, OPT_OLOOP },
319 #if defined(ENABLE_IFCONV)
320 { "ifconv", false, OPT_IFCONV },
322 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
323 { "lsra", false, OPT_LSRA },
326 #if defined(ENABLE_INTRP)
327 /* interpreter options */
329 { "trace", false, OPT_TRACE },
330 { "static-supers", true, OPT_STATIC_SUPERS },
331 { "no-dynamic", false, OPT_NO_DYNAMIC },
332 { "no-replication", false, OPT_NO_REPLICATION },
333 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
336 /* JVMTI Agent Command Line Options */
338 { "agentlib:", true, OPT_AGENTLIB },
339 { "agentpath:", true, OPT_AGENTPATH },
342 /* Java non-standard options */
344 { "Xjit", false, OPT_JIT },
345 { "Xint", false, OPT_INTRP },
346 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
347 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
348 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
349 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
352 { "Xdebug", false, OPT_DEBUG },
353 { "Xnoagent", false, OPT_NOAGENT },
354 { "Xrunjdwp", true, OPT_XRUNJDWP },
357 { "Xms", true, OPT_MS },
358 { "ms", true, OPT_MS },
359 { "Xmx", true, OPT_MX },
360 { "mx", true, OPT_MX },
361 { "Xss", true, OPT_SS },
362 { "ss", true, OPT_SS },
364 #if defined(ENABLE_PROFILING)
365 { "Xprof:", true, OPT_PROF_OPTION },
366 { "Xprof", false, OPT_PROF },
369 /* inlining options */
371 #if defined(ENABLE_INLINING)
372 #if defined(ENABLE_INLINING_DEBUG)
373 { "ia", false, OPT_INLINE_DEBUG_ALL },
374 { "ii", true, OPT_INLINE_DEBUG_MIN },
375 { "im", true, OPT_INLINE_DEBUG_MAX },
376 { "ie", true, OPT_INLINE_DEBUG_END },
377 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
378 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
379 #endif /* defined(ENABLE_INLINING_DEBUG) */
381 { "il", false, OPT_INLINE_LOG },
383 { "i", false, OPT_INLINING },
384 #endif /* defined(ENABLE_INLINING) */
386 /* keep these at the end of the list */
389 { "m", true, OPT_METHOD },
392 { "s", true, OPT_SHOW },
393 { "debug-color", false, OPT_DEBUGCOLOR },
399 /* usage ***********************************************************************
401 Prints the correct usage syntax to stdout.
403 *******************************************************************************/
407 puts("Usage: cacao [-options] classname [arguments]");
408 puts(" (to run a class file)");
409 puts(" or cacao [-options] -jar jarfile [arguments]");
410 puts(" (to run a standalone jar file)\n");
412 puts("where options include:");
413 puts(" -d32 use 32-bit data model if available");
414 puts(" -d64 use 64-bit data model if available");
415 puts(" -client compatibility (currently ignored)");
416 puts(" -server compatibility (currently ignored)");
417 puts(" -jvm compatibility (currently ignored)");
418 puts(" -hotspot compatibility (currently ignored)\n");
420 puts(" -cp <path> specify a path to look for classes");
421 puts(" -classpath <path> specify a path to look for classes");
422 puts(" -D<name>=<value> add an entry to the property list");
423 puts(" -verbose[:class|gc|jni] enable specific verbose output");
424 puts(" -version print product version and exit");
425 puts(" -fullversion print jpackage-compatible product version and exit");
426 puts(" -showversion print product version and continue");
427 puts(" -help, -? print this help message");
428 puts(" -X print help on non-standard Java options");
429 puts(" -XX print help on CACAO options");
430 puts(" -esa | -enablesystemassertions");
431 puts(" enable system assertions");
432 puts(" -dsa | -disablesystemassertions");
433 puts(" disable system assertions");
436 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
437 puts (" for jdwp help use: -agentlib:jdwp=help");
438 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
441 /* exit with error code */
447 static void Xusage(void)
449 #if defined(ENABLE_JIT)
450 puts(" -Xjit JIT mode execution (default)");
452 #if defined(ENABLE_INTRP)
453 puts(" -Xint interpreter mode execution");
455 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
456 puts(" value is set as bootstrap class path");
457 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
458 puts(" value is appended to the bootstrap class path");
459 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
460 puts(" value is prepended to the bootstrap class path");
461 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
462 puts(" value is used as Java core library, but the");
463 puts(" hardcoded VM interface classes are prepended");
464 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
465 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
466 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
468 #if defined(ENABLE_PROFILING)
469 puts(" -Xprof[:bb] collect and print profiling data");
472 #if defined(ENABLE_JVMTI)
473 /* -Xdebug option depend on gnu classpath JDWP options. options:
474 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
475 puts(" -Xdebug enable remote debugging\n");
476 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
477 puts(" enable remote debugging\n");
480 /* exit with error code */
486 static void XXusage(void)
488 puts(" -v write state-information");
490 puts(" -verbose[:call|exception|jit|memory]");
491 puts(" enable specific verbose output");
492 puts(" -debug-color colored output for ANSI terms");
494 #ifdef TYPECHECK_VERBOSE
495 puts(" -verbosetc write debug messages while typechecking");
497 #if defined(__ALPHA__)
498 puts(" -noieee don't use ieee compliant arithmetic");
500 #if defined(ENABLE_VERIFIER)
501 puts(" -noverify don't verify classfiles");
503 puts(" -softnull use software nullpointer check");
504 #if defined(ENABLE_STATISTICS)
505 puts(" -time measure the runtime");
506 puts(" -stat detailed compiler statistics");
508 puts(" -log logfile specify a name for the logfile");
509 puts(" -c(heck)b(ounds) don't check array bounds");
510 puts(" s(ync) don't check for synchronization");
511 #if defined(ENABLE_LOOP)
512 puts(" -oloop optimize array accesses in loops");
514 puts(" -l don't start the class after loading");
515 puts(" -eager perform eager class loading and linking");
517 puts(" -all compile all methods, no execution");
518 puts(" -m compile only a specific method");
519 puts(" -sig specify signature for a specific method");
522 puts(" -s... show...");
523 puts(" (c)onstants the constant pool");
524 puts(" (m)ethods class fields and methods");
525 puts(" (u)tf the utf - hash");
526 puts(" (i)ntermediate intermediate representation");
527 #if defined(ENABLE_DISASSEMBLER)
528 puts(" (a)ssembler disassembled listing");
529 puts(" n(o)ps show NOPs in disassembler output");
530 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
531 puts(" (n)ative disassembled native stubs");
533 puts(" (d)atasegment data segment listing");
535 #if defined(ENABLE_INLINING)
536 puts(" -i activate inlining");
538 puts(" -il log inlining");
540 #if defined(ENABLE_INLINING_DEBUG)
541 puts(" -ia use inlining for all methods");
542 puts(" -ii <size> set minimum size for inlined result");
543 puts(" -im <size> set maximum size for inlined result");
544 puts(" -ie <number> stop inlining after the given number of roots");
545 puts(" -ir log on-stack replacement");
546 puts(" -iR log on-stack replacement, more verbose");
547 #endif /* defined(ENABLE_INLINING_DEBUG) */
548 #endif /* defined(ENABLE_INLINING) */
550 #if defined(ENABLE_IFCONV)
551 puts(" -ifconv use if-conversion");
553 #if defined(ENABLE_LSRA)
554 puts(" -lsra use linear scan register allocation");
556 #if defined(ENABLE_SSA)
557 puts(" -lsra use linear scan register allocation (with SSA)");
560 /* exit with error code */
566 /* version *********************************************************************
568 Only prints cacao version information.
570 *******************************************************************************/
572 static void version(bool opt_exit)
574 puts("java version \""JAVA_VERSION"\"");
575 puts("CACAO version "VERSION"");
577 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
578 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
579 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
580 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
582 puts("This program is free software; you can redistribute it and/or");
583 puts("modify it under the terms of the GNU General Public License as");
584 puts("published by the Free Software Foundation; either version 2, or (at");
585 puts("your option) any later version.\n");
587 puts("This program is distributed in the hope that it will be useful, but");
588 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
589 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
590 puts("General Public License for more details.\n");
592 puts("Configure/Build options:\n");
593 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
594 #if defined(__VERSION__)
595 puts(" CC : "VERSION_CC" ("__VERSION__")");
597 puts(" CC : "VERSION_CC"");
599 puts(" CFLAGS : "VERSION_CFLAGS"\n");
601 puts("Default variables:\n");
602 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
603 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
604 printf(" stack size : %d\n", STACK_SIZE);
605 #if defined(WITH_CLASSPATH_GNU)
606 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
608 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
610 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
612 puts("Runtime variables:\n");
613 printf(" maximum heap size : %d\n", opt_heapmaxsize);
614 printf(" initial heap size : %d\n", opt_heapstartsize);
615 printf(" stack size : %d\n", opt_stacksize);
616 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
617 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
618 printf(" java.class.path : %s\n", _Jv_classpath);
620 /* exit normally, if requested */
627 /* fullversion *****************************************************************
629 Prints a Sun compatible version information (required e.g. by
630 jpackage, www.jpackage.org).
632 *******************************************************************************/
634 static void fullversion(void)
636 puts("java full version \"cacao-"JAVA_VERSION"\"");
644 /* forward declarations *******************************************************/
646 static char *vm_get_mainclass_from_jar(char *mainstring);
648 static void vm_compile_all(void);
649 static void vm_compile_method(void);
653 /* vm_createjvm ****************************************************************
655 Implementation for JNI_CreateJavaVM.
657 *******************************************************************************/
659 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
661 JavaVMInitArgs *_vm_args;
665 /* get the arguments for the new JVM */
667 _vm_args = (JavaVMInitArgs *) vm_args;
669 /* get the VM and Env tables (must be set before vm_create) */
671 env = NEW(_Jv_JNIEnv);
673 #if defined(ENABLE_JNI)
674 env->env = &_Jv_JNINativeInterface;
677 /* XXX Set the global variable. Maybe we should do that differently. */
681 /* create and fill a JavaVM structure */
683 vm = NEW(_Jv_JavaVM);
685 #if defined(ENABLE_JNI)
686 vm->functions = &_Jv_JNIInvokeInterface;
689 /* XXX Set the global variable. Maybe we should do that differently. */
690 /* XXX JVMTI Agents needs a JavaVM */
694 /* actually create the JVM */
696 if (!vm_create(_vm_args))
699 #if defined(ENABLE_JNI)
700 /* setup the local ref table (must be created after vm_create) */
702 if (!jni_init_localref_table())
706 /* now return the values */
708 *p_vm = (JavaVM *) vm;
709 *p_env = (void *) env;
714 /* release allocated memory */
716 FREE(env, _Jv_JNIEnv);
717 FREE(vm, _Jv_JavaVM);
723 /* vm_create *******************************************************************
725 Creates a JVM. Called by vm_createjvm.
727 *******************************************************************************/
729 bool vm_create(JavaVMInitArgs *vm_args)
738 #if defined(ENABLE_JVMTI)
740 char *libname, *agentarg;
741 bool jdwp,agentbypath;
742 jdwp = agentbypath = false;
745 /* check the JNI version requested */
747 switch (vm_args->version) {
748 case JNI_VERSION_1_1:
750 case JNI_VERSION_1_2:
751 case JNI_VERSION_1_4:
757 /* we only support 1 JVM instance */
762 if (atexit(vm_exit_handler))
763 vm_abort("atexit failed: %s\n", strerror(errno));
766 log_text("CACAO started -------------------------------------------------------");
768 /* We need to check if the actual size of a java.lang.Class object
769 is smaller or equal than the assumption made in
770 src/vmcore/class.h. */
772 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
773 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
775 /* set the VM starttime */
777 _Jv_jvm->starttime = builtin_currenttimemillis();
779 /* get stuff from the environment *****************************************/
781 #if defined(WITH_JRE_LAYOUT)
782 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
784 cacao_prefix = MNEW(char, 4096);
786 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
787 vm_abort("readlink failed: %s\n", strerror(errno));
789 /* get the path of the current executable */
791 cacao_prefix = dirname(cacao_prefix);
793 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
794 vm_abort("libjvm name to long for buffer\n");
796 /* concatenate the library name */
798 strcat(cacao_prefix, "/..");
800 /* now set path to libjvm.so */
802 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
804 cacao_libjvm = MNEW(char, len);
805 strcpy(cacao_libjvm, cacao_prefix);
806 strcat(cacao_libjvm, "/lib/libjvm");
808 /* and finally set the path to GNU Classpath libraries */
810 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
812 classpath_libdir = MNEW(char, len);
813 strcpy(classpath_libdir, cacao_prefix);
814 strcat(classpath_libdir, "/lib/classpath");
816 cacao_prefix = CACAO_PREFIX;
817 cacao_libjvm = CACAO_LIBDIR"/libjvm";
818 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
821 /* set the bootclasspath */
823 cp = getenv("BOOTCLASSPATH");
826 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
827 strcpy(_Jv_bootclasspath, cp);
830 #if defined(WITH_JRE_LAYOUT)
832 # if defined(WITH_CLASSPATH_GNU)
833 strlen(cacao_prefix) +
834 strlen("/share/cacao/vm.zip") +
837 strlen(cacao_prefix) +
838 strlen("/share/classpath/glibj.zip") +
841 _Jv_bootclasspath = MNEW(char, len);
842 # if defined(WITH_CLASSPATH_GNU)
843 strcat(_Jv_bootclasspath, cacao_prefix);
844 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
845 strcat(_Jv_bootclasspath, ":");
847 strcat(_Jv_bootclasspath, cacao_prefix);
848 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
851 # if defined(WITH_CLASSPATH_GNU)
852 strlen(CACAO_VM_ZIP) +
855 strlen(CLASSPATH_CLASSES) +
858 _Jv_bootclasspath = MNEW(char, len);
859 # if defined(WITH_CLASSPATH_GNU)
860 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
861 strcat(_Jv_bootclasspath, ":");
863 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
867 /* set the classpath */
869 cp = getenv("CLASSPATH");
872 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
873 strcat(_Jv_classpath, cp);
876 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
877 strcpy(_Jv_classpath, ".");
880 /* get and set java.library.path */
882 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
884 if (_Jv_java_library_path == NULL)
885 _Jv_java_library_path = "";
887 /* interpret the options **************************************************/
895 opt_heapmaxsize = HEAP_MAXSIZE;
896 opt_heapstartsize = HEAP_STARTSIZE;
897 opt_stacksize = STACK_SIZE;
900 #if defined(ENABLE_JVMTI)
901 /* initialize JVMTI related **********************************************/
905 /* initialize and fill properties before command-line handling */
907 if (!properties_init())
908 vm_abort("properties_init failed");
910 /* iterate over all passed options */
912 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
926 #if SIZEOF_VOID_P == 8
927 puts("Running a 32-bit JVM is not supported on this platform.");
933 #if SIZEOF_VOID_P == 4
934 puts("Running a 64-bit JVM is not supported on this platform.");
940 /* forget old classpath and set the argument as new classpath */
941 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
943 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
944 strcpy(_Jv_classpath, opt_arg);
948 for (i = 0; i < strlen(opt_arg); i++) {
949 if (opt_arg[i] == '=') {
951 properties_add(opt_arg, opt_arg + i + 1);
956 /* if no '=' is given, just create an empty property */
958 properties_add(opt_arg, "");
963 case OPT_BOOTCLASSPATH:
964 /* Forget default bootclasspath and set the argument as
965 new boot classpath. */
967 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
969 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
970 strcpy(_Jv_bootclasspath, opt_arg);
973 case OPT_BOOTCLASSPATH_A:
974 /* append to end of bootclasspath */
976 len = strlen(_Jv_bootclasspath);
978 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
982 strlen(opt_arg) + strlen("0"));
984 strcat(_Jv_bootclasspath, ":");
985 strcat(_Jv_bootclasspath, opt_arg);
988 case OPT_BOOTCLASSPATH_P:
989 /* prepend in front of bootclasspath */
991 cp = _Jv_bootclasspath;
994 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
997 strcpy(_Jv_bootclasspath, opt_arg);
998 strcat(_Jv_bootclasspath, ":");
999 strcat(_Jv_bootclasspath, cp);
1001 MFREE(cp, char, len);
1004 case OPT_BOOTCLASSPATH_C:
1005 /* use as Java core library, but prepend VM interface classes */
1007 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1009 len = strlen(CACAO_VM_ZIP) +
1014 _Jv_bootclasspath = MNEW(char, len);
1016 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1017 strcat(_Jv_bootclasspath, ":");
1018 strcat(_Jv_bootclasspath, opt_arg);
1021 #if defined(ENABLE_JVMTI)
1023 /* this option exists only for compatibility reasons */
1027 /* I don't know yet what Xnoagent should do. This is only for
1028 compatiblity with eclipse - motse */
1037 strlen(CACAO_LIBDIR) +
1038 strlen("/libjdwp.so=") +
1042 agentarg = MNEW(char, len);
1044 strcpy(agentarg, CACAO_LIBDIR);
1045 strcat(agentarg, "/libjdwp.so=");
1046 strcat(agentarg, &opt_arg[1]);
1063 c = opt_arg[strlen(opt_arg) - 1];
1065 if ((c == 'k') || (c == 'K')) {
1066 j = atoi(opt_arg) * 1024;
1068 } else if ((c == 'm') || (c == 'M')) {
1069 j = atoi(opt_arg) * 1024 * 1024;
1075 opt_heapmaxsize = j;
1076 else if (opt == OPT_MS)
1077 opt_heapstartsize = j;
1088 if (strcmp("class", opt_arg) == 0) {
1089 opt_verboseclass = true;
1091 else if (strcmp("gc", opt_arg) == 0) {
1092 opt_verbosegc = true;
1094 else if (strcmp("jni", opt_arg) == 0) {
1095 opt_verbosejni = true;
1097 #if !defined(NDEBUG)
1098 else if (strcmp("call", opt_arg) == 0) {
1099 opt_verbosecall = true;
1101 else if (strcmp("exception", opt_arg) == 0) {
1102 opt_verboseexception = true;
1104 else if (strcmp("jit", opt_arg) == 0) {
1109 compileverbose = true;
1111 else if (strcmp("memory", opt_arg) == 0) {
1112 opt_verbosememory = true;
1114 # if defined(ENABLE_STATISTICS)
1115 /* we also need statistics */
1122 case OPT_DEBUGCOLOR:
1123 opt_debugcolor = true;
1126 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1128 opt_typecheckverbose = true;
1137 case OPT_FULLVERSION:
1141 case OPT_SHOWVERSION:
1149 #if defined(ENABLE_VERIFIER)
1159 #if defined(ENABLE_STATISTICS)
1161 opt_getcompilingtime = true;
1162 opt_getloadingtime = true;
1175 for (i = 0; i < strlen(opt_arg); i++) {
1176 switch (opt_arg[i]) {
1178 checkbounds = false;
1191 makeinitializations = false;
1198 #if !defined(NDEBUG)
1202 makeinitializations = false;
1207 opt_method = opt_arg;
1208 makeinitializations = false;
1212 opt_signature = opt_arg;
1216 case OPT_SHOW: /* Display options */
1217 for (i = 0; i < strlen(opt_arg); i++) {
1218 switch (opt_arg[i]) {
1220 showconstantpool = true;
1232 opt_showintermediate = true;
1233 compileverbose = true;
1236 #if defined(ENABLE_DISASSEMBLER)
1238 opt_showdisassemble = true;
1239 compileverbose = true;
1243 opt_shownops = true;
1247 opt_showexceptionstubs = true;
1251 opt_shownativestub = true;
1256 opt_showddatasegment = true;
1265 #if defined(ENABLE_LOOP)
1271 #if defined(ENABLE_INLINING)
1272 #if defined(ENABLE_INLINING_DEBUG)
1273 case OPT_INLINE_DEBUG_ALL:
1274 opt_inline_debug_all = true;
1276 case OPT_INLINE_DEBUG_END:
1277 opt_inline_debug_end_counter = atoi(opt_arg);
1279 case OPT_INLINE_DEBUG_MIN:
1280 opt_inline_debug_min_size = atoi(opt_arg);
1282 case OPT_INLINE_DEBUG_MAX:
1283 opt_inline_debug_max_size = atoi(opt_arg);
1285 case OPT_INLINE_REPLACE_VERBOSE:
1286 opt_replace_verbose = 1;
1288 case OPT_INLINE_REPLACE_VERBOSE2:
1289 opt_replace_verbose = 2;
1291 #endif /* defined(ENABLE_INLINING_DEBUG) */
1292 #if !defined(NDEBUG)
1293 case OPT_INLINE_LOG:
1294 opt_inline_debug_log = true;
1296 #endif /* !defined(NDEBUG) */
1299 opt_inlining = true;
1301 #endif /* defined(ENABLE_INLINING) */
1303 #if defined(ENABLE_IFCONV)
1309 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1328 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1332 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1335 #if defined(ENABLE_PROFILING)
1336 case OPT_PROF_OPTION:
1337 /* use <= to get the last \0 too */
1339 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1340 if (opt_arg[i] == ',')
1343 if (opt_arg[i] == '\0') {
1344 if (strcmp("bb", opt_arg + j) == 0)
1348 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1352 /* set k to next char */
1365 #if defined(ENABLE_JIT)
1368 printf("-Xjit option not enabled.\n");
1374 #if defined(ENABLE_INTRP)
1377 printf("-Xint option not enabled.\n");
1382 #if defined(ENABLE_INTRP)
1383 case OPT_STATIC_SUPERS:
1384 opt_static_supers = atoi(opt_arg);
1387 case OPT_NO_DYNAMIC:
1388 opt_no_dynamic = true;
1391 case OPT_NO_REPLICATION:
1392 opt_no_replication = true;
1395 case OPT_NO_QUICKSUPER:
1396 opt_no_quicksuper = true;
1405 printf("Unknown option: %s\n",
1406 vm_args->options[opt_index].optionString);
1411 /* get the main class *****************************************************/
1413 if (opt_index < vm_args->nOptions) {
1414 mainstring = vm_args->options[opt_index++].optionString;
1416 /* Put the jar file into the classpath (if any). */
1418 if (opt_jar == true) {
1419 /* free old classpath */
1421 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1423 /* put jarfile into classpath */
1425 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1427 strcpy(_Jv_classpath, mainstring);
1430 /* replace .'s with /'s in classname */
1432 for (i = strlen(mainstring) - 1; i >= 0; i--)
1433 if (mainstring[i] == '.')
1434 mainstring[i] = '/';
1438 #if defined(ENABLE_JVMTI)
1440 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1441 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1444 MFREE(agentarg, char, strlen(agentarg));
1446 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1450 /* initialize this JVM ****************************************************/
1452 vm_initializing = true;
1454 #if defined(ENABLE_THREADS)
1455 /* pre-initialize some core thread stuff, like the stopworldlock,
1456 thus this has to happen _before_ gc_init()!!! */
1461 /* initialize the garbage collector */
1463 gc_init(opt_heapmaxsize, opt_heapstartsize);
1465 #if defined(ENABLE_INTRP)
1466 /* Allocate main thread stack on the Java heap. */
1469 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1470 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1474 /* AFTER: threads_preinit */
1477 vm_abort("vm_create: string_init failed");
1479 /* AFTER: threads_preinit */
1482 vm_abort("vm_create: utf8_init failed");
1484 /* AFTER: thread_preinit */
1487 vm_abort("vm_create: suck_init failed");
1489 suck_add_from_property("java.endorsed.dirs");
1491 /* Now we have all options handled and we can print the version
1494 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1499 /* AFTER: utf8_init */
1501 suck_add(_Jv_bootclasspath);
1503 /* Now re-set some of the properties that may have changed. This
1504 must be done after _all_ environment variables have been
1505 processes (e.g. -jar handling).
1507 AFTER: suck_add_from_property, since it may change the
1508 _Jv_bootclasspath pointer. */
1510 if (!properties_postinit())
1511 vm_abort("vm_create: properties_postinit failed");
1513 /* initialize the classcache hashtable stuff: lock, hashtable
1514 (must be done _after_ threads_preinit) */
1516 if (!classcache_init())
1517 vm_abort("vm_create: classcache_init failed");
1519 /* initialize the memory subsystem (must be done _after_
1523 vm_abort("vm_create: memory_init failed");
1525 /* initialize the finalizer stuff (must be done _after_
1528 if (!finalizer_init())
1529 vm_abort("vm_create: finalizer_init failed");
1531 /* install architecture dependent signal handlers */
1535 /* initialize the codegen subsystems */
1539 /* initializes jit compiler */
1543 /* machine dependent initialization */
1545 #if defined(ENABLE_JIT)
1546 # if defined(ENABLE_INTRP)
1556 /* initialize the loader subsystems (must be done _after_
1560 vm_abort("vm_create: loader_init failed");
1563 vm_abort("vm_create: linker_init failed");
1566 vm_abort("vm_create: native_init failed");
1568 if (!exceptions_init())
1569 vm_abort("vm_create: exceptions_init failed");
1571 if (!builtin_init())
1572 vm_abort("vm_create: builtin_init 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_THREADS)
1584 if (!threads_init())
1585 vm_abort("vm_create: threads_init failed");
1588 #if defined(ENABLE_PROFILING)
1589 /* initialize profiling */
1591 if (!profile_init())
1592 vm_abort("vm_create: profile_init failed");
1595 #if defined(ENABLE_THREADS)
1596 /* initialize recompilation */
1598 if (!recompile_init())
1599 vm_abort("vm_create: recompile_init failed");
1601 /* start the signal handler thread */
1603 if (!signal_start_thread())
1604 vm_abort("vm_create: signal_start_thread failed");
1606 /* finally, start the finalizer thread */
1608 if (!finalizer_start_thread())
1609 vm_abort("vm_create: finalizer_start_thread failed");
1611 # if !defined(NDEBUG)
1612 /* start the memory profiling thread */
1614 if (opt_verbosememory)
1615 if (!memory_start_thread())
1616 vm_abort("vm_create: memory_start_thread failed");
1619 /* start the recompilation thread (must be done before the
1620 profiling thread) */
1622 if (!recompile_start_thread())
1623 vm_abort("vm_create: recompile_start_thread failed");
1625 # if defined(ENABLE_PROFILING)
1626 /* start the profile sampling thread */
1629 /* if (!profile_start_thread()) */
1630 /* exceptions_print_stacktrace(); */
1634 #if defined(ENABLE_JVMTI)
1636 /* add agent library to native library hashtable */
1637 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1641 /* increment the number of VMs */
1645 /* initialization is done */
1647 vm_initializing = false;
1649 /* everything's ok */
1655 /* vm_run **********************************************************************
1657 Runs the main-method of the passed class.
1659 *******************************************************************************/
1661 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1664 classinfo *mainclass;
1666 java_objectarray *oa;
1669 java_objectheader *s;
1673 #if !defined(NDEBUG)
1679 if (opt_method != NULL) {
1680 vm_compile_method();
1683 #endif /* !defined(NDEBUG) */
1685 /* should we run the main-method? */
1687 if (mainstring == NULL)
1690 /* set return value to OK */
1694 if (opt_jar == true) {
1695 /* open jar file with java.util.jar.JarFile */
1697 mainstring = vm_get_mainclass_from_jar(mainstring);
1699 if (mainstring == NULL)
1703 /* load the main class */
1705 mainutf = utf_new_char(mainstring);
1707 #if defined(ENABLE_JAVAME_CLDC1_1)
1708 mainclass = load_class_bootstrap(mainutf);
1710 mainclass = load_class_from_sysloader(mainutf);
1713 /* error loading class */
1715 if ((exceptions_get_exception() != NULL) || (mainclass == NULL)) {
1716 exceptions_print_stacktrace();
1720 if (!link_class(mainclass)) {
1721 exceptions_print_stacktrace();
1725 /* find the `main' method of the main class */
1727 m = class_resolveclassmethod(mainclass,
1728 utf_new_char("main"),
1729 utf_new_char("([Ljava/lang/String;)V"),
1730 class_java_lang_Object,
1733 if (exceptions_get_exception()) {
1734 exceptions_print_stacktrace();
1738 /* there is no main method or it isn't static */
1740 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1741 exceptions_clear_exception();
1742 exceptions_throw_nosuchmethoderror(mainclass,
1743 utf_new_char("main"),
1744 utf_new_char("([Ljava/lang/String;)V"));
1746 exceptions_print_stacktrace();
1750 /* build argument array */
1752 oalength = vm_args->nOptions - opt_index;
1754 oa = builtin_anewarray(oalength, class_java_lang_String);
1756 for (i = 0; i < oalength; i++) {
1757 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1758 s = javastring_new(u);
1763 #ifdef TYPEINFO_DEBUG_TEST
1764 /* test the typeinfo system */
1767 /*class_showmethods(currentThread->group->header.vftbl->class); */
1769 #if defined(ENABLE_JVMTI)
1770 jvmti_set_phase(JVMTI_PHASE_LIVE);
1773 /* set ThreadMXBean variables */
1775 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1776 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1778 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1779 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1780 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1781 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1783 /* start the main thread */
1785 (void) vm_call_method(m, NULL, oa);
1787 /* exception occurred? */
1789 if (exceptions_get_exception()) {
1790 exceptions_print_stacktrace();
1794 /* unload the JavaVM */
1796 (void) vm_destroy(vm);
1804 /* vm_destroy ******************************************************************
1806 Unloads a Java VM and reclaims its resources.
1808 *******************************************************************************/
1810 s4 vm_destroy(JavaVM *vm)
1812 #if defined(ENABLE_THREADS)
1813 threads_join_all_threads();
1816 /* everything's ok */
1822 /* vm_exit *********************************************************************
1824 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1826 *******************************************************************************/
1828 void vm_exit(s4 status)
1832 /* signal that we are exiting */
1836 assert(class_java_lang_System);
1837 assert(class_java_lang_System->state & CLASS_LOADED);
1839 #if defined(ENABLE_JVMTI)
1840 if (jvmti || (dbgcom!=NULL)) {
1841 jvmti_set_phase(JVMTI_PHASE_DEAD);
1842 if (jvmti) jvmti_agentunload();
1846 if (!link_class(class_java_lang_System)) {
1847 exceptions_print_stacktrace();
1851 /* call java.lang.System.exit(I)V */
1853 m = class_resolveclassmethod(class_java_lang_System,
1854 utf_new_char("exit"),
1856 class_java_lang_Object,
1860 exceptions_print_stacktrace();
1864 /* call the exit function with passed exit status */
1866 (void) vm_call_method(m, NULL, status);
1868 /* If we had an exception, just ignore the exception and exit with
1871 vm_shutdown(status);
1875 /* vm_shutdown *****************************************************************
1877 Terminates the system immediately without freeing memory explicitly
1878 (to be used only for abnormal termination).
1880 *******************************************************************************/
1882 void vm_shutdown(s4 status)
1885 #if defined(ENABLE_STATISTICS)
1886 || opt_getcompilingtime || opt_stat
1890 log_text("CACAO terminated by shutdown");
1891 dolog("Exit status: %d\n", (s4) status);
1895 #if defined(ENABLE_JVMTI)
1896 /* terminate cacaodbgserver */
1898 pthread_mutex_lock(&dbgcomlock);
1900 pthread_mutex_unlock(&dbgcomlock);
1901 jvmti_cacaodbgserver_quit();
1909 /* vm_exit_handler *************************************************************
1911 The exit_handler function is called upon program termination.
1913 ATTENTION: Don't free system resources here! Some threads may still
1914 be running as this is called from VMRuntime.exit(). The OS does the
1917 *******************************************************************************/
1919 void vm_exit_handler(void)
1921 #if !defined(NDEBUG)
1923 class_showmethods(mainclass);
1925 if (showconstantpool)
1926 class_showconstantpool(mainclass);
1931 # if defined(ENABLE_PROFILING)
1933 profile_printstats();
1935 #endif /* !defined(NDEBUG) */
1937 #if defined(ENABLE_RT_TIMING)
1938 rt_timing_print_time_stats(stderr);
1941 #if defined(ENABLE_CYCLES_STATS)
1942 builtin_print_cycles_stats(stderr);
1943 stacktrace_print_cycles_stats(stderr);
1947 #if defined(ENABLE_STATISTICS)
1948 || opt_getcompilingtime || opt_stat
1952 log_text("CACAO terminated");
1954 #if defined(ENABLE_STATISTICS)
1957 #ifdef TYPECHECK_STATISTICS
1958 typecheck_print_statistics(get_logfile());
1962 if (opt_getcompilingtime)
1964 #endif /* defined(ENABLE_STATISTICS) */
1966 /* vm_print_profile(stderr);*/
1970 /* vm_abort ********************************************************************
1972 Prints an error message and aborts the VM.
1974 *******************************************************************************/
1976 void vm_abort(const char *text, ...)
1980 /* print the log message */
1985 log_vprint(text, ap);
1990 /* now abort the VM */
1996 /* vm_get_mainclass_from_jar ***************************************************
1998 Gets the name of the main class from a JAR's manifest file.
2000 *******************************************************************************/
2002 static char *vm_get_mainclass_from_jar(char *mainstring)
2005 java_objectheader *o;
2007 java_objectheader *s;
2009 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2012 exceptions_print_stacktrace();
2016 /* create JarFile object */
2021 exceptions_print_stacktrace();
2025 m = class_resolveclassmethod(c,
2027 utf_java_lang_String__void,
2028 class_java_lang_Object,
2032 exceptions_print_stacktrace();
2036 s = javastring_new_from_ascii(mainstring);
2038 (void) vm_call_method(m, o, s);
2040 if (exceptions_get_exception()) {
2041 exceptions_print_stacktrace();
2045 /* get manifest object */
2047 m = class_resolveclassmethod(c,
2048 utf_new_char("getManifest"),
2049 utf_new_char("()Ljava/util/jar/Manifest;"),
2050 class_java_lang_Object,
2054 exceptions_print_stacktrace();
2058 o = vm_call_method(m, o);
2061 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2066 /* get Main Attributes */
2068 m = class_resolveclassmethod(o->vftbl->class,
2069 utf_new_char("getMainAttributes"),
2070 utf_new_char("()Ljava/util/jar/Attributes;"),
2071 class_java_lang_Object,
2075 exceptions_print_stacktrace();
2079 o = vm_call_method(m, o);
2082 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2087 /* get property Main-Class */
2089 m = class_resolveclassmethod(o->vftbl->class,
2090 utf_new_char("getValue"),
2091 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2092 class_java_lang_Object,
2096 exceptions_print_stacktrace();
2100 s = javastring_new_from_ascii("Main-Class");
2102 o = vm_call_method(m, o, s);
2105 exceptions_print_stacktrace();
2109 return javastring_tochar(o);
2113 /* vm_compile_all **************************************************************
2115 Compile all methods found in the bootclasspath.
2117 *******************************************************************************/
2119 #if !defined(NDEBUG)
2120 static void vm_compile_all(void)
2125 classcache_name_entry *nmen;
2126 classcache_class_entry *clsen;
2129 /* create all classes found in the bootclasspath */
2130 /* XXX currently only works with zip/jar's */
2132 loader_load_all_classes();
2134 /* link all classes */
2136 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2137 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2139 for (; nmen; nmen = nmen->hashlink) {
2140 /* iterate over all class entries */
2142 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2143 c = clsen->classobj;
2148 if (!(c->state & CLASS_LINKED)) {
2149 if (!link_class(c)) {
2150 fprintf(stderr, "Error linking: ");
2151 utf_fprint_printable_ascii_classname(stderr, c->name);
2152 fprintf(stderr, "\n");
2154 /* print out exception and cause */
2156 exceptions_print_current_exception();
2158 /* goto next class */
2164 /* compile all class methods */
2166 for (i = 0; i < c->methodscount; i++) {
2167 m = &(c->methods[i]);
2169 if (m->jcode != NULL) {
2170 if (!jit_compile(m)) {
2171 fprintf(stderr, "Error compiling: ");
2172 utf_fprint_printable_ascii_classname(stderr, c->name);
2173 fprintf(stderr, ".");
2174 utf_fprint_printable_ascii(stderr, m->name);
2175 utf_fprint_printable_ascii(stderr, m->descriptor);
2176 fprintf(stderr, "\n");
2178 /* print out exception and cause */
2180 exceptions_print_current_exception();
2188 #endif /* !defined(NDEBUG) */
2191 /* vm_compile_method ***********************************************************
2193 Compile a specific method.
2195 *******************************************************************************/
2197 #if !defined(NDEBUG)
2198 static void vm_compile_method(void)
2202 /* create, load and link the main class */
2204 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2206 if (mainclass == NULL)
2207 exceptions_print_stacktrace();
2209 if (!link_class(mainclass))
2210 exceptions_print_stacktrace();
2212 if (opt_signature != NULL) {
2213 m = class_resolveclassmethod(mainclass,
2214 utf_new_char(opt_method),
2215 utf_new_char(opt_signature),
2220 m = class_resolveclassmethod(mainclass,
2221 utf_new_char(opt_method),
2228 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2229 opt_method, opt_signature ? opt_signature : "");
2233 #endif /* !defined(NDEBUG) */
2236 /* vm_vmargs_from_valist *******************************************************
2240 *******************************************************************************/
2242 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2243 vm_arg *vmargs, va_list ap)
2245 typedesc *paramtypes;
2248 paramtypes = m->parseddesc->paramtypes;
2250 /* if method is non-static fill first block and skip `this' pointer */
2255 /* the `this' pointer */
2256 vmargs[0].type = TYPE_ADR;
2257 vmargs[0].data.l = (u8) (ptrint) o;
2263 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2264 switch (paramtypes->decltype) {
2265 /* primitive types */
2266 case PRIMITIVETYPE_BOOLEAN:
2267 case PRIMITIVETYPE_BYTE:
2268 case PRIMITIVETYPE_CHAR:
2269 case PRIMITIVETYPE_SHORT:
2270 case PRIMITIVETYPE_INT:
2271 vmargs[i].type = TYPE_INT;
2272 vmargs[i].data.l = (s8) va_arg(ap, s4);
2275 case PRIMITIVETYPE_LONG:
2276 vmargs[i].type = TYPE_LNG;
2277 vmargs[i].data.l = (s8) va_arg(ap, s8);
2280 case PRIMITIVETYPE_FLOAT:
2281 vmargs[i].type = TYPE_FLT;
2282 #if defined(__ALPHA__)
2283 /* this keeps the assembler function much simpler */
2285 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2287 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2291 case PRIMITIVETYPE_DOUBLE:
2292 vmargs[i].type = TYPE_DBL;
2293 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2297 vmargs[i].type = TYPE_ADR;
2298 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2305 /* vm_vmargs_from_jvalue *******************************************************
2309 *******************************************************************************/
2311 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2312 vm_arg *vmargs, jvalue *args)
2314 typedesc *paramtypes;
2318 paramtypes = m->parseddesc->paramtypes;
2320 /* if method is non-static fill first block and skip `this' pointer */
2325 /* the `this' pointer */
2326 vmargs[0].type = TYPE_ADR;
2327 vmargs[0].data.l = (u8) (ptrint) o;
2333 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2334 switch (paramtypes->decltype) {
2335 /* primitive types */
2336 case PRIMITIVETYPE_BOOLEAN:
2337 case PRIMITIVETYPE_BYTE:
2338 case PRIMITIVETYPE_CHAR:
2339 case PRIMITIVETYPE_SHORT:
2340 case PRIMITIVETYPE_INT:
2341 vmargs[i].type = TYPE_INT;
2342 vmargs[i].data.l = (s8) args[j].i;
2345 case PRIMITIVETYPE_LONG:
2346 vmargs[i].type = TYPE_LNG;
2347 vmargs[i].data.l = (s8) args[j].j;
2350 case PRIMITIVETYPE_FLOAT:
2351 vmargs[i].type = TYPE_FLT;
2352 #if defined(__ALPHA__)
2353 /* this keeps the assembler function much simpler */
2355 vmargs[i].data.d = (jdouble) args[j].f;
2357 vmargs[i].data.f = args[j].f;
2361 case PRIMITIVETYPE_DOUBLE:
2362 vmargs[i].type = TYPE_DBL;
2363 vmargs[i].data.d = args[j].d;
2367 vmargs[i].type = TYPE_ADR;
2368 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2375 /* vm_call_method **************************************************************
2377 Calls a Java method with a variable number of arguments and returns
2380 *******************************************************************************/
2382 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2385 java_objectheader *ro;
2388 ro = vm_call_method_valist(m, o, ap);
2395 /* vm_call_method_valist *******************************************************
2397 Calls a Java method with a variable number of arguments, passed via
2398 a va_list, and returns an address.
2400 *******************************************************************************/
2402 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2407 java_objectheader *ro;
2410 /* mark start of dump memory area */
2412 dumpsize = dump_size();
2414 /* get number of Java method arguments */
2416 vmargscount = m->parseddesc->paramcount;
2418 /* allocate vm_arg array */
2420 vmargs = DMNEW(vm_arg, vmargscount);
2422 /* fill the vm_arg array from a va_list */
2424 vm_vmargs_from_valist(m, o, vmargs, ap);
2426 /* call the Java method */
2428 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2430 /* release dump area */
2432 dump_release(dumpsize);
2438 /* vm_call_method_jvalue *******************************************************
2440 Calls a Java method with a variable number of arguments, passed via
2441 a jvalue array, and returns an address.
2443 *******************************************************************************/
2445 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2450 java_objectheader *ro;
2453 /* mark start of dump memory area */
2455 dumpsize = dump_size();
2457 /* get number of Java method arguments */
2459 vmargscount = m->parseddesc->paramcount;
2461 /* allocate vm_arg array */
2463 vmargs = DMNEW(vm_arg, vmargscount);
2465 /* fill the vm_arg array from a va_list */
2467 vm_vmargs_from_jvalue(m, o, vmargs, args);
2469 /* call the Java method */
2471 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2473 /* release dump area */
2475 dump_release(dumpsize);
2481 /* vm_call_method_vmarg ********************************************************
2483 Calls a Java method with a variable number of arguments, passed via
2484 a vm_arg array, and returns an address.
2486 *******************************************************************************/
2488 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2491 java_objectheader *o;
2493 #if defined(ENABLE_JIT)
2494 # if defined(ENABLE_INTRP)
2496 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2499 o = asm_vm_call_method(m, vmargscount, vmargs);
2501 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2508 /* vm_call_method_int **********************************************************
2510 Calls a Java method with a variable number of arguments and returns
2513 *******************************************************************************/
2515 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2521 i = vm_call_method_int_valist(m, o, ap);
2528 /* vm_call_method_int_valist ***************************************************
2530 Calls a Java method with a variable number of arguments, passed via
2531 a va_list, and returns an integer (s4).
2533 *******************************************************************************/
2535 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2542 /* mark start of dump memory area */
2544 dumpsize = dump_size();
2546 /* get number of Java method arguments */
2548 vmargscount = m->parseddesc->paramcount;
2550 /* allocate vm_arg array */
2552 vmargs = DMNEW(vm_arg, vmargscount);
2554 /* fill the vm_arg array from a va_list */
2556 vm_vmargs_from_valist(m, o, vmargs, ap);
2558 /* call the Java method */
2560 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2562 /* release dump area */
2564 dump_release(dumpsize);
2570 /* vm_call_method_int_jvalue ***************************************************
2572 Calls a Java method with a variable number of arguments, passed via
2573 a jvalue array, and returns an integer (s4).
2575 *******************************************************************************/
2577 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2584 /* mark start of dump memory area */
2586 dumpsize = dump_size();
2588 /* get number of Java method arguments */
2590 vmargscount = m->parseddesc->paramcount;
2592 /* allocate vm_arg array */
2594 vmargs = DMNEW(vm_arg, vmargscount);
2596 /* fill the vm_arg array from a va_list */
2598 vm_vmargs_from_jvalue(m, o, vmargs, args);
2600 /* call the Java method */
2602 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2604 /* release dump area */
2606 dump_release(dumpsize);
2612 /* vm_call_method_int_vmarg ****************************************************
2614 Calls a Java method with a variable number of arguments, passed via
2615 a vm_arg array, and returns an integer (s4).
2617 *******************************************************************************/
2619 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2623 #if defined(ENABLE_JIT)
2624 # if defined(ENABLE_INTRP)
2626 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2629 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2631 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2638 /* vm_call_method_long *********************************************************
2640 Calls a Java method with a variable number of arguments and returns
2643 *******************************************************************************/
2645 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2651 l = vm_call_method_long_valist(m, o, ap);
2658 /* vm_call_method_long_valist **************************************************
2660 Calls a Java method with a variable number of arguments, passed via
2661 a va_list, and returns a long (s8).
2663 *******************************************************************************/
2665 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2672 /* mark start of dump memory area */
2674 dumpsize = dump_size();
2676 /* get number of Java method arguments */
2678 vmargscount = m->parseddesc->paramcount;
2680 /* allocate vm_arg array */
2682 vmargs = DMNEW(vm_arg, vmargscount);
2684 /* fill the vm_arg array from a va_list */
2686 vm_vmargs_from_valist(m, o, vmargs, ap);
2688 /* call the Java method */
2690 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2692 /* release dump area */
2694 dump_release(dumpsize);
2700 /* vm_call_method_long_jvalue **************************************************
2702 Calls a Java method with a variable number of arguments, passed via
2703 a jvalue array, and returns a long (s8).
2705 *******************************************************************************/
2707 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2714 /* mark start of dump memory area */
2716 dumpsize = dump_size();
2718 /* get number of Java method arguments */
2720 vmargscount = m->parseddesc->paramcount;
2722 /* allocate vm_arg array */
2724 vmargs = DMNEW(vm_arg, vmargscount);
2726 /* fill the vm_arg array from a va_list */
2728 vm_vmargs_from_jvalue(m, o, vmargs, args);
2730 /* call the Java method */
2732 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2734 /* release dump area */
2736 dump_release(dumpsize);
2742 /* vm_call_method_long_vmarg ***************************************************
2744 Calls a Java method with a variable number of arguments, passed via
2745 a vm_arg array, and returns a long (s8).
2747 *******************************************************************************/
2749 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2753 #if defined(ENABLE_JIT)
2754 # if defined(ENABLE_INTRP)
2756 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2759 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2761 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2768 /* vm_call_method_float ********************************************************
2770 Calls a Java method with a variable number of arguments and returns
2773 *******************************************************************************/
2775 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2781 f = vm_call_method_float_valist(m, o, ap);
2788 /* vm_call_method_float_valist *************************************************
2790 Calls a Java method with a variable number of arguments, passed via
2791 a va_list, and returns a float.
2793 *******************************************************************************/
2795 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2803 /* mark start of dump memory area */
2805 dumpsize = dump_size();
2807 /* get number of Java method arguments */
2809 vmargscount = m->parseddesc->paramcount;
2811 /* allocate vm_arg array */
2813 vmargs = DMNEW(vm_arg, vmargscount);
2815 /* fill the vm_arg array from a va_list */
2817 vm_vmargs_from_valist(m, o, vmargs, ap);
2819 /* call the Java method */
2821 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2823 /* release dump area */
2825 dump_release(dumpsize);
2831 /* vm_call_method_float_jvalue *************************************************
2833 Calls a Java method with a variable number of arguments, passed via
2834 a jvalue array, and returns a float.
2836 *******************************************************************************/
2838 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2846 /* mark start of dump memory area */
2848 dumpsize = dump_size();
2850 /* get number of Java method arguments */
2852 vmargscount = m->parseddesc->paramcount;
2854 /* allocate vm_arg array */
2856 vmargs = DMNEW(vm_arg, vmargscount);
2858 /* fill the vm_arg array from a va_list */
2860 vm_vmargs_from_jvalue(m, o, vmargs, args);
2862 /* call the Java method */
2864 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2866 /* release dump area */
2868 dump_release(dumpsize);
2874 /* vm_call_method_float_vmarg **************************************************
2876 Calls a Java method with a variable number of arguments and returns
2879 *******************************************************************************/
2881 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2885 #if defined(ENABLE_JIT)
2886 # if defined(ENABLE_INTRP)
2888 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2891 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2893 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2900 /* vm_call_method_double *******************************************************
2902 Calls a Java method with a variable number of arguments and returns
2905 *******************************************************************************/
2907 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2913 d = vm_call_method_double_valist(m, o, ap);
2920 /* vm_call_method_double_valist ************************************************
2922 Calls a Java method with a variable number of arguments, passed via
2923 a va_list, and returns a double.
2925 *******************************************************************************/
2927 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2935 /* mark start of dump memory area */
2937 dumpsize = dump_size();
2939 /* get number of Java method arguments */
2941 vmargscount = m->parseddesc->paramcount;
2943 /* allocate vm_arg array */
2945 vmargs = DMNEW(vm_arg, vmargscount);
2947 /* fill the vm_arg array from a va_list */
2949 vm_vmargs_from_valist(m, o, vmargs, ap);
2951 /* call the Java method */
2953 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2955 /* release dump area */
2957 dump_release(dumpsize);
2963 /* vm_call_method_double_jvalue ************************************************
2965 Calls a Java method with a variable number of arguments, passed via
2966 a jvalue array, and returns a double.
2968 *******************************************************************************/
2970 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2978 /* mark start of dump memory area */
2980 dumpsize = dump_size();
2982 /* get number of Java method arguments */
2984 vmargscount = m->parseddesc->paramcount;
2986 /* allocate vm_arg array */
2988 vmargs = DMNEW(vm_arg, vmargscount);
2990 /* fill the vm_arg array from a va_list */
2992 vm_vmargs_from_jvalue(m, o, vmargs, args);
2994 /* call the Java method */
2996 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2998 /* release dump area */
3000 dump_release(dumpsize);
3006 /* vm_call_method_double_vmarg *************************************************
3008 Calls a Java method with a variable number of arguments and returns
3011 *******************************************************************************/
3013 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
3018 #if defined(ENABLE_JIT)
3019 # if defined(ENABLE_INTRP)
3021 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3024 d = asm_vm_call_method_double(m, vmargscount, vmargs);
3026 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3034 * These are local overrides for various environment variables in Emacs.
3035 * Please do not remove this and leave it at the end of the file, where
3036 * Emacs will automagically detect them.
3037 * ---------------------------------------------------------------------
3040 * indent-tabs-mode: t