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 8059 2007-06-10 19:31:28Z 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_String.h" /* required by java_lang_Class.h */
49 #include "native/include/java_lang_Class.h"
51 #include "threads/threads-common.h"
53 #include "toolbox/logging.h"
55 #include "vm/builtin.h"
56 #include "vm/exceptions.h"
57 #include "vm/finalizer.h"
58 #include "vm/global.h"
59 #include "vm/initialize.h"
60 #include "vm/properties.h"
61 #include "vm/signallocal.h"
62 #include "vm/stringlocal.h"
65 #include "vm/jit/jit.h"
66 #include "vm/jit/md.h"
67 #include "vm/jit/asmpart.h"
69 #if defined(ENABLE_PROFILING)
70 # include "vm/jit/optimizing/profile.h"
73 #include "vm/jit/optimizing/recompile.h"
75 #include "vmcore/classcache.h"
76 #include "vmcore/options.h"
77 #include "vmcore/statistics.h"
78 #include "vmcore/suck.h"
80 #if defined(ENABLE_JVMTI)
81 # include "native/jvmti/cacaodbg.h"
84 #if defined(ENABLE_VMLOG)
85 #include <vmlog_cacao.h>
89 /* Invocation API variables ***************************************************/
91 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
92 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
95 /* global variables ***********************************************************/
97 s4 vms = 0; /* number of VMs created */
99 bool vm_initializing = false;
100 bool vm_exiting = false;
102 char *cacao_prefix = NULL;
103 char *cacao_libjvm = NULL;
104 char *classpath_libdir = NULL;
106 char *_Jv_bootclasspath; /* contains the boot classpath */
107 char *_Jv_classpath; /* contains the classpath */
108 char *_Jv_java_library_path;
110 char *mainstring = NULL;
111 classinfo *mainclass = NULL;
113 char *specificmethodname = NULL;
114 char *specificsignature = NULL;
118 #if defined(ENABLE_INTRP)
119 u1 *intrp_main_stack = NULL;
123 /* define heap sizes **********************************************************/
125 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
126 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
127 #define STACK_SIZE 64 * 1024 /* default 64kB */
130 /* define command line options ************************************************/
158 /* Java non-standard options */
169 #if defined(ENABLE_PROFILING)
182 #if defined(ENABLE_STATISTICS)
199 #if defined(ENABLE_VERIFIER)
201 #if defined(TYPECHECK_VERBOSE)
204 #endif /* defined(ENABLE_VERIFIER) */
207 /* optimization options */
209 #if defined(ENABLE_LOOP)
213 #if defined(ENABLE_IFCONV)
217 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
221 #if defined(ENABLE_INLINING)
226 #if defined(ENABLE_INLINING_DEBUG)
227 OPT_INLINE_DEBUG_ALL,
228 OPT_INLINE_DEBUG_END,
229 OPT_INLINE_DEBUG_MIN,
230 OPT_INLINE_DEBUG_MAX,
231 OPT_INLINE_REPLACE_VERBOSE,
232 OPT_INLINE_REPLACE_VERBOSE2,
233 #endif /* defined(ENABLE_INLINING_DEBUG) */
234 #endif /* defined(ENABLE_INLINING) */
236 #if defined(ENABLE_INTRP)
237 /* interpreter options */
256 #if defined(ENABLE_DEBUG_FILTER)
257 OPT_FILTER_VERBOSECALL_INCLUDE,
258 OPT_FILTER_VERBOSECALL_EXCLUDE,
259 OPT_FILTER_SHOW_METHOD,
266 opt_struct opts[] = {
267 { "foo", false, OPT_FOO },
271 { "jar", false, OPT_JAR },
273 { "d32", false, OPT_D32 },
274 { "d64", false, OPT_D64 },
275 { "client", false, OPT_IGNORE },
276 { "server", false, OPT_IGNORE },
277 { "jvm", false, OPT_IGNORE },
278 { "hotspot", false, OPT_IGNORE },
280 { "classpath", true, OPT_CLASSPATH },
281 { "cp", true, OPT_CLASSPATH },
282 { "D", true, OPT_D },
283 { "version", false, OPT_VERSION },
284 { "showversion", false, OPT_SHOWVERSION },
285 { "fullversion", false, OPT_FULLVERSION },
286 { "help", false, OPT_HELP },
287 { "?", false, OPT_HELP },
288 { "X", false, OPT_X },
289 { "XX", false, OPT_XX },
291 { "esa", false, OPT_ESA },
292 { "enablesystemassertions", false, OPT_ESA },
293 { "dsa", false, OPT_DSA },
294 { "disablesystemassertions", false, OPT_DSA },
296 { "noasyncgc", false, OPT_IGNORE },
297 #if defined(ENABLE_VERIFIER)
298 { "noverify", false, OPT_NOVERIFY },
300 { "v", false, OPT_VERBOSE1 },
301 { "verbose:", true, OPT_VERBOSE },
303 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
304 { "verbosetc", false, OPT_VERBOSETC },
306 #if defined(__ALPHA__)
307 { "noieee", false, OPT_NOIEEE },
309 #if defined(ENABLE_STATISTICS)
310 { "time", false, OPT_TIME },
311 { "stat", false, OPT_STAT },
313 { "log", true, OPT_LOG },
314 { "c", true, OPT_CHECK },
315 { "l", false, OPT_LOAD },
316 { "eager", false, OPT_EAGER },
319 { "all", false, OPT_ALL },
320 { "sig", true, OPT_SIGNATURE },
323 #if defined(ENABLE_LOOP)
324 { "oloop", false, OPT_OLOOP },
326 #if defined(ENABLE_IFCONV)
327 { "ifconv", false, OPT_IFCONV },
329 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
330 { "lsra", false, OPT_LSRA },
333 #if defined(ENABLE_INTRP)
334 /* interpreter options */
336 { "trace", false, OPT_TRACE },
337 { "static-supers", true, OPT_STATIC_SUPERS },
338 { "no-dynamic", false, OPT_NO_DYNAMIC },
339 { "no-replication", false, OPT_NO_REPLICATION },
340 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
343 /* JVMTI Agent Command Line Options */
345 { "agentlib:", true, OPT_AGENTLIB },
346 { "agentpath:", true, OPT_AGENTPATH },
349 /* Java non-standard options */
351 { "Xjit", false, OPT_JIT },
352 { "Xint", false, OPT_INTRP },
353 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
354 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
355 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
356 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
359 { "Xdebug", false, OPT_DEBUG },
360 { "Xnoagent", false, OPT_NOAGENT },
361 { "Xrunjdwp", true, OPT_XRUNJDWP },
364 { "Xms", true, OPT_MS },
365 { "ms", true, OPT_MS },
366 { "Xmx", true, OPT_MX },
367 { "mx", true, OPT_MX },
368 { "Xss", true, OPT_SS },
369 { "ss", true, OPT_SS },
371 #if defined(ENABLE_PROFILING)
372 { "Xprof:", true, OPT_PROF_OPTION },
373 { "Xprof", false, OPT_PROF },
376 /* inlining options */
378 #if defined(ENABLE_INLINING)
379 #if defined(ENABLE_INLINING_DEBUG)
380 { "ia", false, OPT_INLINE_DEBUG_ALL },
381 { "ii", true, OPT_INLINE_DEBUG_MIN },
382 { "im", true, OPT_INLINE_DEBUG_MAX },
383 { "ie", true, OPT_INLINE_DEBUG_END },
384 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
385 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
386 #endif /* defined(ENABLE_INLINING_DEBUG) */
388 { "il", false, OPT_INLINE_LOG },
390 { "i", false, OPT_INLINING },
391 #endif /* defined(ENABLE_INLINING) */
393 /* keep these at the end of the list */
396 { "m", true, OPT_METHOD },
399 { "s", true, OPT_SHOW },
400 { "debug-color", false, OPT_DEBUGCOLOR },
402 #if defined(ENABLE_DEBUG_FILTER)
403 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
404 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
405 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
412 /* usage ***********************************************************************
414 Prints the correct usage syntax to stdout.
416 *******************************************************************************/
420 puts("Usage: cacao [-options] classname [arguments]");
421 puts(" (to run a class file)");
422 puts(" or cacao [-options] -jar jarfile [arguments]");
423 puts(" (to run a standalone jar file)\n");
425 puts("where options include:");
426 puts(" -d32 use 32-bit data model if available");
427 puts(" -d64 use 64-bit data model if available");
428 puts(" -client compatibility (currently ignored)");
429 puts(" -server compatibility (currently ignored)");
430 puts(" -jvm compatibility (currently ignored)");
431 puts(" -hotspot compatibility (currently ignored)\n");
433 puts(" -cp <path> specify a path to look for classes");
434 puts(" -classpath <path> specify a path to look for classes");
435 puts(" -D<name>=<value> add an entry to the property list");
436 puts(" -verbose[:class|gc|jni] enable specific verbose output");
437 puts(" -version print product version and exit");
438 puts(" -fullversion print jpackage-compatible product version and exit");
439 puts(" -showversion print product version and continue");
440 puts(" -help, -? print this help message");
441 puts(" -X print help on non-standard Java options");
442 puts(" -XX print help on CACAO options");
443 puts(" -esa | -enablesystemassertions");
444 puts(" enable system assertions");
445 puts(" -dsa | -disablesystemassertions");
446 puts(" disable system assertions");
449 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
450 puts (" for jdwp help use: -agentlib:jdwp=help");
451 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
454 /* exit with error code */
460 static void Xusage(void)
462 #if defined(ENABLE_JIT)
463 puts(" -Xjit JIT mode execution (default)");
465 #if defined(ENABLE_INTRP)
466 puts(" -Xint interpreter mode execution");
468 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
469 puts(" value is set as bootstrap class path");
470 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
471 puts(" value is appended to the bootstrap class path");
472 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
473 puts(" value is prepended to the bootstrap class path");
474 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
475 puts(" value is used as Java core library, but the");
476 puts(" hardcoded VM interface classes are prepended");
477 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
478 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
479 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
481 #if defined(ENABLE_PROFILING)
482 puts(" -Xprof[:bb] collect and print profiling data");
485 #if defined(ENABLE_JVMTI)
486 /* -Xdebug option depend on gnu classpath JDWP options. options:
487 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
488 puts(" -Xdebug enable remote debugging\n");
489 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
490 puts(" enable remote debugging\n");
493 /* exit with error code */
499 static void XXusage(void)
501 puts(" -v write state-information");
503 puts(" -verbose[:call|exception|jit|memory|threads]");
504 puts(" enable specific verbose output");
505 puts(" -debug-color colored output for ANSI terms");
507 #ifdef TYPECHECK_VERBOSE
508 puts(" -verbosetc write debug messages while typechecking");
510 #if defined(__ALPHA__)
511 puts(" -noieee don't use ieee compliant arithmetic");
513 #if defined(ENABLE_VERIFIER)
514 puts(" -noverify don't verify classfiles");
516 #if defined(ENABLE_STATISTICS)
517 puts(" -time measure the runtime");
518 puts(" -stat detailed compiler statistics");
520 puts(" -log logfile specify a name for the logfile");
521 puts(" -c(heck)b(ounds) don't check array bounds");
522 puts(" s(ync) don't check for synchronization");
523 #if defined(ENABLE_LOOP)
524 puts(" -oloop optimize array accesses in loops");
526 puts(" -l don't start the class after loading");
527 puts(" -eager perform eager class loading and linking");
529 puts(" -all compile all methods, no execution");
530 puts(" -m compile only a specific method");
531 puts(" -sig specify signature for a specific method");
534 puts(" -s... show...");
535 puts(" (c)onstants the constant pool");
536 puts(" (m)ethods class fields and methods");
537 puts(" (u)tf the utf - hash");
538 puts(" (i)ntermediate intermediate representation");
539 #if defined(ENABLE_DISASSEMBLER)
540 puts(" (a)ssembler disassembled listing");
541 puts(" n(o)ps show NOPs in disassembler output");
542 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
543 puts(" (n)ative disassembled native stubs");
545 puts(" (d)atasegment data segment listing");
547 #if defined(ENABLE_INLINING)
548 puts(" -i activate inlining");
550 puts(" -il log inlining");
552 #if defined(ENABLE_INLINING_DEBUG)
553 puts(" -ia use inlining for all methods");
554 puts(" -ii <size> set minimum size for inlined result");
555 puts(" -im <size> set maximum size for inlined result");
556 puts(" -ie <number> stop inlining after the given number of roots");
557 puts(" -ir log on-stack replacement");
558 puts(" -iR log on-stack replacement, more verbose");
559 #endif /* defined(ENABLE_INLINING_DEBUG) */
560 #endif /* defined(ENABLE_INLINING) */
562 #if defined(ENABLE_IFCONV)
563 puts(" -ifconv use if-conversion");
565 #if defined(ENABLE_LSRA)
566 puts(" -lsra use linear scan register allocation");
568 #if defined(ENABLE_SSA)
569 puts(" -lsra use linear scan register allocation (with SSA)");
571 #if defined(ENABLE_DEBUG_FILTER)
572 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
573 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
574 puts(" -XXfm <regex> filter for show options");
576 /* exit with error code */
582 /* version *********************************************************************
584 Only prints cacao version information.
586 *******************************************************************************/
588 static void version(bool opt_exit)
590 puts("java version \""JAVA_VERSION"\"");
591 puts("CACAO version "VERSION"");
593 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
594 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
595 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
596 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
598 puts("This program is free software; you can redistribute it and/or");
599 puts("modify it under the terms of the GNU General Public License as");
600 puts("published by the Free Software Foundation; either version 2, or (at");
601 puts("your option) any later version.\n");
603 puts("This program is distributed in the hope that it will be useful, but");
604 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
605 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
606 puts("General Public License for more details.\n");
608 puts("Configure/Build options:\n");
609 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
610 #if defined(__VERSION__)
611 puts(" CC : "VERSION_CC" ("__VERSION__")");
613 puts(" CC : "VERSION_CC"");
615 puts(" CFLAGS : "VERSION_CFLAGS"\n");
617 puts("Default variables:\n");
618 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
619 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
620 printf(" stack size : %d\n", STACK_SIZE);
621 #if defined(WITH_CLASSPATH_GNU)
622 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
624 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
626 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
628 puts("Runtime variables:\n");
629 printf(" maximum heap size : %d\n", opt_heapmaxsize);
630 printf(" initial heap size : %d\n", opt_heapstartsize);
631 printf(" stack size : %d\n", opt_stacksize);
632 printf(" libjvm.so : %s\n", cacao_libjvm);
633 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
634 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
635 printf(" java.class.path : %s\n", _Jv_classpath);
637 /* exit normally, if requested */
644 /* fullversion *****************************************************************
646 Prints a Sun compatible version information (required e.g. by
647 jpackage, www.jpackage.org).
649 *******************************************************************************/
651 static void fullversion(void)
653 puts("java full version \"cacao-"JAVA_VERSION"\"");
661 /* forward declarations *******************************************************/
663 static char *vm_get_mainclass_from_jar(char *mainstring);
665 static void vm_compile_all(void);
666 static void vm_compile_method(void);
670 /* vm_createjvm ****************************************************************
672 Implementation for JNI_CreateJavaVM.
674 *******************************************************************************/
676 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
678 JavaVMInitArgs *_vm_args;
682 /* get the arguments for the new JVM */
684 _vm_args = (JavaVMInitArgs *) vm_args;
686 /* get the VM and Env tables (must be set before vm_create) */
688 env = NEW(_Jv_JNIEnv);
690 #if defined(ENABLE_JNI)
691 env->env = &_Jv_JNINativeInterface;
694 /* XXX Set the global variable. Maybe we should do that differently. */
698 /* create and fill a JavaVM structure */
700 vm = NEW(_Jv_JavaVM);
702 #if defined(ENABLE_JNI)
703 vm->functions = &_Jv_JNIInvokeInterface;
706 /* XXX Set the global variable. Maybe we should do that differently. */
707 /* XXX JVMTI Agents needs a JavaVM */
711 /* actually create the JVM */
713 if (!vm_create(_vm_args))
716 #if defined(ENABLE_JNI)
717 /* setup the local ref table (must be created after vm_create) */
719 if (!jni_init_localref_table())
723 /* now return the values */
725 *p_vm = (JavaVM *) vm;
726 *p_env = (void *) env;
731 /* release allocated memory */
733 FREE(env, _Jv_JNIEnv);
734 FREE(vm, _Jv_JavaVM);
740 /* vm_create *******************************************************************
742 Creates a JVM. Called by vm_createjvm.
744 *******************************************************************************/
746 bool vm_create(JavaVMInitArgs *vm_args)
755 #if defined(ENABLE_JVMTI)
757 char *libname, *agentarg;
758 bool jdwp,agentbypath;
759 jdwp = agentbypath = false;
762 #if defined(ENABLE_VMLOG)
763 vmlog_cacao_init(vm_args);
766 /* check the JNI version requested */
768 switch (vm_args->version) {
769 case JNI_VERSION_1_1:
771 case JNI_VERSION_1_2:
772 case JNI_VERSION_1_4:
778 /* we only support 1 JVM instance */
783 if (atexit(vm_exit_handler))
784 vm_abort("atexit failed: %s\n", strerror(errno));
787 log_text("CACAO started -------------------------------------------------------");
789 /* We need to check if the actual size of a java.lang.Class object
790 is smaller or equal than the assumption made in
791 src/vmcore/class.h. */
793 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
794 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
796 /* set the VM starttime */
798 _Jv_jvm->starttime = builtin_currenttimemillis();
800 /* get stuff from the environment *****************************************/
802 #if defined(WITH_JRE_LAYOUT)
803 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
805 cacao_prefix = MNEW(char, 4096);
807 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
808 vm_abort("readlink failed: %s\n", strerror(errno));
810 /* get the path of the current executable */
812 cacao_prefix = dirname(cacao_prefix);
814 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
815 vm_abort("libjvm name to long for buffer\n");
817 /* concatenate the library name */
819 strcat(cacao_prefix, "/..");
821 /* now set path to libjvm.so */
823 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
825 cacao_libjvm = MNEW(char, len);
826 strcpy(cacao_libjvm, cacao_prefix);
827 strcat(cacao_libjvm, "/lib/libjvm");
829 /* and finally set the path to GNU Classpath libraries */
831 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
833 classpath_libdir = MNEW(char, len);
834 strcpy(classpath_libdir, cacao_prefix);
835 strcat(classpath_libdir, "/lib/classpath");
837 cacao_prefix = CACAO_PREFIX;
838 cacao_libjvm = CACAO_LIBDIR"/libjvm";
839 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
842 /* set the bootclasspath */
844 cp = getenv("BOOTCLASSPATH");
847 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
848 strcpy(_Jv_bootclasspath, cp);
851 #if defined(WITH_JRE_LAYOUT)
853 # if defined(WITH_CLASSPATH_GNU)
854 strlen(cacao_prefix) +
855 strlen("/share/cacao/vm.zip") +
858 strlen(cacao_prefix) +
859 strlen("/share/classpath/glibj.zip") +
862 _Jv_bootclasspath = MNEW(char, len);
863 # if defined(WITH_CLASSPATH_GNU)
864 strcat(_Jv_bootclasspath, cacao_prefix);
865 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
866 strcat(_Jv_bootclasspath, ":");
868 strcat(_Jv_bootclasspath, cacao_prefix);
869 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
872 # if defined(WITH_CLASSPATH_GNU)
873 strlen(CACAO_VM_ZIP) +
876 strlen(CLASSPATH_CLASSES) +
879 _Jv_bootclasspath = MNEW(char, len);
880 # if defined(WITH_CLASSPATH_GNU)
881 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
882 strcat(_Jv_bootclasspath, ":");
884 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
888 /* set the classpath */
890 cp = getenv("CLASSPATH");
893 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
894 strcat(_Jv_classpath, cp);
897 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
898 strcpy(_Jv_classpath, ".");
901 /* get and set java.library.path */
903 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
905 if (_Jv_java_library_path == NULL)
906 _Jv_java_library_path = "";
908 /* interpret the options **************************************************/
915 opt_heapmaxsize = HEAP_MAXSIZE;
916 opt_heapstartsize = HEAP_STARTSIZE;
917 opt_stacksize = STACK_SIZE;
920 #if defined(ENABLE_JVMTI)
921 /* initialize JVMTI related **********************************************/
925 /* initialize and fill properties before command-line handling */
927 if (!properties_init())
928 vm_abort("properties_init failed");
930 /* iterate over all passed options */
932 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
946 #if SIZEOF_VOID_P == 8
947 puts("Running a 32-bit JVM is not supported on this platform.");
953 #if SIZEOF_VOID_P == 4
954 puts("Running a 64-bit JVM is not supported on this platform.");
960 /* forget old classpath and set the argument as new classpath */
961 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
963 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
964 strcpy(_Jv_classpath, opt_arg);
968 for (i = 0; i < strlen(opt_arg); i++) {
969 if (opt_arg[i] == '=') {
971 properties_add(opt_arg, opt_arg + i + 1);
976 /* if no '=' is given, just create an empty property */
978 properties_add(opt_arg, "");
983 case OPT_BOOTCLASSPATH:
984 /* Forget default bootclasspath and set the argument as
985 new boot classpath. */
987 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
989 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
990 strcpy(_Jv_bootclasspath, opt_arg);
993 case OPT_BOOTCLASSPATH_A:
994 /* append to end of bootclasspath */
996 len = strlen(_Jv_bootclasspath);
998 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
1002 strlen(opt_arg) + strlen("0"));
1004 strcat(_Jv_bootclasspath, ":");
1005 strcat(_Jv_bootclasspath, opt_arg);
1008 case OPT_BOOTCLASSPATH_P:
1009 /* prepend in front of bootclasspath */
1011 cp = _Jv_bootclasspath;
1014 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1017 strcpy(_Jv_bootclasspath, opt_arg);
1018 strcat(_Jv_bootclasspath, ":");
1019 strcat(_Jv_bootclasspath, cp);
1021 MFREE(cp, char, len);
1024 case OPT_BOOTCLASSPATH_C:
1025 /* use as Java core library, but prepend VM interface classes */
1027 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1029 len = strlen(CACAO_VM_ZIP) +
1034 _Jv_bootclasspath = MNEW(char, len);
1036 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1037 strcat(_Jv_bootclasspath, ":");
1038 strcat(_Jv_bootclasspath, opt_arg);
1041 #if defined(ENABLE_JVMTI)
1043 /* this option exists only for compatibility reasons */
1047 /* I don't know yet what Xnoagent should do. This is only for
1048 compatiblity with eclipse - motse */
1057 strlen(CACAO_LIBDIR) +
1058 strlen("/libjdwp.so=") +
1062 agentarg = MNEW(char, len);
1064 strcpy(agentarg, CACAO_LIBDIR);
1065 strcat(agentarg, "/libjdwp.so=");
1066 strcat(agentarg, &opt_arg[1]);
1083 c = opt_arg[strlen(opt_arg) - 1];
1085 if ((c == 'k') || (c == 'K')) {
1086 j = atoi(opt_arg) * 1024;
1088 } else if ((c == 'm') || (c == 'M')) {
1089 j = atoi(opt_arg) * 1024 * 1024;
1095 opt_heapmaxsize = j;
1096 else if (opt == OPT_MS)
1097 opt_heapstartsize = j;
1108 if (strcmp("class", opt_arg) == 0) {
1109 opt_verboseclass = true;
1111 else if (strcmp("gc", opt_arg) == 0) {
1112 opt_verbosegc = true;
1114 else if (strcmp("jni", opt_arg) == 0) {
1115 opt_verbosejni = true;
1117 #if !defined(NDEBUG)
1118 else if (strcmp("call", opt_arg) == 0) {
1119 opt_verbosecall = true;
1121 else if (strcmp("exception", opt_arg) == 0) {
1122 opt_verboseexception = true;
1124 else if (strcmp("jit", opt_arg) == 0) {
1129 compileverbose = true;
1131 else if (strcmp("memory", opt_arg) == 0) {
1132 opt_verbosememory = true;
1134 # if defined(ENABLE_STATISTICS)
1135 /* we also need statistics */
1140 else if (strcmp("threads", opt_arg) == 0) {
1141 opt_verbosethreads = true;
1145 printf("Unknown -verbose option: %s\n", opt_arg);
1150 case OPT_DEBUGCOLOR:
1151 opt_debugcolor = true;
1154 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1156 opt_typecheckverbose = true;
1165 case OPT_FULLVERSION:
1169 case OPT_SHOWVERSION:
1177 #if defined(ENABLE_VERIFIER)
1183 #if defined(ENABLE_STATISTICS)
1185 opt_getcompilingtime = true;
1186 opt_getloadingtime = true;
1199 for (i = 0; i < strlen(opt_arg); i++) {
1200 switch (opt_arg[i]) {
1202 checkbounds = false;
1215 makeinitializations = false;
1222 #if !defined(NDEBUG)
1226 makeinitializations = false;
1231 opt_method = opt_arg;
1232 makeinitializations = false;
1236 opt_signature = opt_arg;
1240 case OPT_SHOW: /* Display options */
1241 for (i = 0; i < strlen(opt_arg); i++) {
1242 switch (opt_arg[i]) {
1244 showconstantpool = true;
1256 opt_showintermediate = true;
1257 compileverbose = true;
1260 #if defined(ENABLE_DISASSEMBLER)
1262 opt_showdisassemble = true;
1263 compileverbose = true;
1267 opt_shownops = true;
1271 opt_showexceptionstubs = true;
1275 opt_shownativestub = true;
1280 opt_showddatasegment = true;
1289 #if defined(ENABLE_LOOP)
1295 #if defined(ENABLE_INLINING)
1296 #if defined(ENABLE_INLINING_DEBUG)
1297 case OPT_INLINE_DEBUG_ALL:
1298 opt_inline_debug_all = true;
1300 case OPT_INLINE_DEBUG_END:
1301 opt_inline_debug_end_counter = atoi(opt_arg);
1303 case OPT_INLINE_DEBUG_MIN:
1304 opt_inline_debug_min_size = atoi(opt_arg);
1306 case OPT_INLINE_DEBUG_MAX:
1307 opt_inline_debug_max_size = atoi(opt_arg);
1309 case OPT_INLINE_REPLACE_VERBOSE:
1310 opt_replace_verbose = 1;
1312 case OPT_INLINE_REPLACE_VERBOSE2:
1313 opt_replace_verbose = 2;
1315 #endif /* defined(ENABLE_INLINING_DEBUG) */
1316 #if !defined(NDEBUG)
1317 case OPT_INLINE_LOG:
1318 opt_inline_debug_log = true;
1320 #endif /* !defined(NDEBUG) */
1323 opt_inlining = true;
1325 #endif /* defined(ENABLE_INLINING) */
1327 #if defined(ENABLE_IFCONV)
1333 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1352 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1356 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1359 #if defined(ENABLE_PROFILING)
1360 case OPT_PROF_OPTION:
1361 /* use <= to get the last \0 too */
1363 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1364 if (opt_arg[i] == ',')
1367 if (opt_arg[i] == '\0') {
1368 if (strcmp("bb", opt_arg + j) == 0)
1372 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1376 /* set k to next char */
1389 #if defined(ENABLE_JIT)
1392 printf("-Xjit option not enabled.\n");
1398 #if defined(ENABLE_INTRP)
1401 printf("-Xint option not enabled.\n");
1406 #if defined(ENABLE_INTRP)
1407 case OPT_STATIC_SUPERS:
1408 opt_static_supers = atoi(opt_arg);
1411 case OPT_NO_DYNAMIC:
1412 opt_no_dynamic = true;
1415 case OPT_NO_REPLICATION:
1416 opt_no_replication = true;
1419 case OPT_NO_QUICKSUPER:
1420 opt_no_quicksuper = true;
1428 #if defined(ENABLE_DEBUG_FILTER)
1429 case OPT_FILTER_VERBOSECALL_INCLUDE:
1430 opt_filter_verbosecall_include = opt_arg;
1433 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1434 opt_filter_verbosecall_exclude = opt_arg;
1437 case OPT_FILTER_SHOW_METHOD:
1438 opt_filter_show_method = opt_arg;
1443 printf("Unknown option: %s\n",
1444 vm_args->options[opt_index].optionString);
1449 /* get the main class *****************************************************/
1451 if (opt_index < vm_args->nOptions) {
1452 mainstring = vm_args->options[opt_index++].optionString;
1454 /* Put the jar file into the classpath (if any). */
1456 if (opt_jar == true) {
1457 /* free old classpath */
1459 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1461 /* put jarfile into classpath */
1463 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1465 strcpy(_Jv_classpath, mainstring);
1468 /* replace .'s with /'s in classname */
1470 for (i = strlen(mainstring) - 1; i >= 0; i--)
1471 if (mainstring[i] == '.')
1472 mainstring[i] = '/';
1476 #if defined(ENABLE_JVMTI)
1478 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1479 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1482 MFREE(agentarg, char, strlen(agentarg));
1484 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1488 /* initialize this JVM ****************************************************/
1490 vm_initializing = true;
1492 #if defined(ENABLE_THREADS)
1493 /* pre-initialize some core thread stuff, like the stopworldlock,
1494 thus this has to happen _before_ gc_init()!!! */
1499 /* initialize the garbage collector */
1501 gc_init(opt_heapmaxsize, opt_heapstartsize);
1503 /* install architecture dependent signal handlers */
1506 vm_abort("vm_create: signal_init failed");
1508 #if defined(ENABLE_INTRP)
1509 /* Allocate main thread stack on the Java heap. */
1512 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1513 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1517 /* AFTER: threads_preinit */
1520 vm_abort("vm_create: string_init failed");
1522 /* AFTER: threads_preinit */
1525 vm_abort("vm_create: utf8_init failed");
1527 /* AFTER: thread_preinit */
1530 vm_abort("vm_create: suck_init failed");
1532 suck_add_from_property("java.endorsed.dirs");
1534 /* Now we have all options handled and we can print the version
1537 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1542 /* AFTER: utf8_init */
1544 suck_add(_Jv_bootclasspath);
1546 /* Now re-set some of the properties that may have changed. This
1547 must be done after _all_ environment variables have been
1548 processes (e.g. -jar handling).
1550 AFTER: suck_add_from_property, since it may change the
1551 _Jv_bootclasspath pointer. */
1553 if (!properties_postinit())
1554 vm_abort("vm_create: properties_postinit failed");
1556 /* initialize the classcache hashtable stuff: lock, hashtable
1557 (must be done _after_ threads_preinit) */
1559 if (!classcache_init())
1560 vm_abort("vm_create: classcache_init failed");
1562 /* initialize the memory subsystem (must be done _after_
1566 vm_abort("vm_create: memory_init failed");
1568 /* initialize the finalizer stuff (must be done _after_
1571 if (!finalizer_init())
1572 vm_abort("vm_create: finalizer_init failed");
1574 /* initialize the codegen subsystems */
1578 /* initializes jit compiler */
1582 /* machine dependent initialization */
1584 #if defined(ENABLE_JIT)
1585 # if defined(ENABLE_INTRP)
1595 /* initialize the loader subsystems (must be done _after_
1599 vm_abort("vm_create: loader_init failed");
1602 vm_abort("vm_create: linker_init failed");
1604 /* Initialize the native subsystem. */
1607 vm_abort("vm_create: native_init failed");
1609 if (!exceptions_init())
1610 vm_abort("vm_create: exceptions_init failed");
1612 if (!builtin_init())
1613 vm_abort("vm_create: builtin_init failed");
1615 #if defined(ENABLE_JNI)
1616 /* Initialize the JNI subsystem (must be done _before_
1617 threads_init, as threads_init can call JNI methods
1618 (e.g. NewGlobalRef). */
1621 vm_abort("vm_create: jni_init failed");
1624 #if defined(ENABLE_THREADS)
1625 if (!threads_init())
1626 vm_abort("vm_create: threads_init failed");
1629 #if defined(ENABLE_PROFILING)
1630 /* initialize profiling */
1632 if (!profile_init())
1633 vm_abort("vm_create: profile_init failed");
1636 #if defined(ENABLE_THREADS)
1637 /* initialize recompilation */
1639 if (!recompile_init())
1640 vm_abort("vm_create: recompile_init failed");
1642 /* start the signal handler thread */
1644 #if defined(__LINUX__)
1645 /* XXX Remove for exact-GC. */
1646 if (threads_pthreads_implementation_nptl)
1648 if (!signal_start_thread())
1649 vm_abort("vm_create: signal_start_thread failed");
1651 /* finally, start the finalizer thread */
1653 if (!finalizer_start_thread())
1654 vm_abort("vm_create: finalizer_start_thread failed");
1656 # if !defined(NDEBUG)
1657 /* start the memory profiling thread */
1659 if (opt_verbosememory)
1660 if (!memory_start_thread())
1661 vm_abort("vm_create: memory_start_thread failed");
1664 /* start the recompilation thread (must be done before the
1665 profiling thread) */
1667 if (!recompile_start_thread())
1668 vm_abort("vm_create: recompile_start_thread failed");
1670 # if defined(ENABLE_PROFILING)
1671 /* start the profile sampling thread */
1674 /* if (!profile_start_thread()) */
1675 /* vm_abort("vm_create: profile_start_thread failed"); */
1679 #if defined(ENABLE_JVMTI)
1681 /* add agent library to native library hashtable */
1682 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1686 /* increment the number of VMs */
1690 /* initialization is done */
1692 vm_initializing = false;
1694 /* everything's ok */
1700 /* vm_run **********************************************************************
1702 Runs the main-method of the passed class.
1704 *******************************************************************************/
1706 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1709 classinfo *mainclass;
1711 java_objectarray *oa;
1714 java_objectheader *s;
1718 #if !defined(NDEBUG)
1724 if (opt_method != NULL) {
1725 vm_compile_method();
1728 #endif /* !defined(NDEBUG) */
1730 /* should we run the main-method? */
1732 if (mainstring == NULL)
1735 /* set return value to OK */
1739 if (opt_jar == true) {
1740 /* open jar file with java.util.jar.JarFile */
1742 mainstring = vm_get_mainclass_from_jar(mainstring);
1744 if (mainstring == NULL)
1748 /* load the main class */
1750 mainutf = utf_new_char(mainstring);
1752 #if defined(ENABLE_JAVAME_CLDC1_1)
1753 mainclass = load_class_bootstrap(mainutf);
1755 mainclass = load_class_from_sysloader(mainutf);
1758 /* error loading class */
1760 if ((exceptions_get_exception() != NULL) || (mainclass == NULL)) {
1761 exceptions_print_stacktrace();
1765 if (!link_class(mainclass)) {
1766 exceptions_print_stacktrace();
1770 /* find the `main' method of the main class */
1772 m = class_resolveclassmethod(mainclass,
1773 utf_new_char("main"),
1774 utf_new_char("([Ljava/lang/String;)V"),
1775 class_java_lang_Object,
1778 if (exceptions_get_exception()) {
1779 exceptions_print_stacktrace();
1783 /* there is no main method or it isn't static */
1785 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1786 exceptions_clear_exception();
1787 exceptions_throw_nosuchmethoderror(mainclass,
1788 utf_new_char("main"),
1789 utf_new_char("([Ljava/lang/String;)V"));
1791 exceptions_print_stacktrace();
1795 /* build argument array */
1797 oalength = vm_args->nOptions - opt_index;
1799 oa = builtin_anewarray(oalength, class_java_lang_String);
1801 for (i = 0; i < oalength; i++) {
1802 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1803 s = javastring_new(u);
1808 #ifdef TYPEINFO_DEBUG_TEST
1809 /* test the typeinfo system */
1812 /*class_showmethods(currentThread->group->header.vftbl->class); */
1814 #if defined(ENABLE_JVMTI)
1815 jvmti_set_phase(JVMTI_PHASE_LIVE);
1818 /* set ThreadMXBean variables */
1820 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1821 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1823 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1824 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1825 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1826 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1828 /* start the main thread */
1830 (void) vm_call_method(m, NULL, oa);
1832 /* exception occurred? */
1834 if (exceptions_get_exception()) {
1835 exceptions_print_stacktrace();
1839 /* unload the JavaVM */
1841 (void) vm_destroy(vm);
1849 /* vm_destroy ******************************************************************
1851 Unloads a Java VM and reclaims its resources.
1853 *******************************************************************************/
1855 s4 vm_destroy(JavaVM *vm)
1857 #if defined(ENABLE_THREADS)
1858 threads_join_all_threads();
1861 /* everything's ok */
1867 /* vm_exit *********************************************************************
1869 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1871 *******************************************************************************/
1873 void vm_exit(s4 status)
1877 /* signal that we are exiting */
1881 assert(class_java_lang_System);
1882 assert(class_java_lang_System->state & CLASS_LOADED);
1884 #if defined(ENABLE_JVMTI)
1885 if (jvmti || (dbgcom!=NULL)) {
1886 jvmti_set_phase(JVMTI_PHASE_DEAD);
1887 if (jvmti) jvmti_agentunload();
1891 if (!link_class(class_java_lang_System)) {
1892 exceptions_print_stacktrace();
1896 /* call java.lang.System.exit(I)V */
1898 m = class_resolveclassmethod(class_java_lang_System,
1899 utf_new_char("exit"),
1901 class_java_lang_Object,
1905 exceptions_print_stacktrace();
1909 /* call the exit function with passed exit status */
1911 (void) vm_call_method(m, NULL, status);
1913 /* If we had an exception, just ignore the exception and exit with
1916 vm_shutdown(status);
1920 /* vm_shutdown *****************************************************************
1922 Terminates the system immediately without freeing memory explicitly
1923 (to be used only for abnormal termination).
1925 *******************************************************************************/
1927 void vm_shutdown(s4 status)
1930 #if defined(ENABLE_STATISTICS)
1931 || opt_getcompilingtime || opt_stat
1935 log_text("CACAO terminated by shutdown");
1936 dolog("Exit status: %d\n", (s4) status);
1940 #if defined(ENABLE_JVMTI)
1941 /* terminate cacaodbgserver */
1943 pthread_mutex_lock(&dbgcomlock);
1945 pthread_mutex_unlock(&dbgcomlock);
1946 jvmti_cacaodbgserver_quit();
1954 /* vm_exit_handler *************************************************************
1956 The exit_handler function is called upon program termination.
1958 ATTENTION: Don't free system resources here! Some threads may still
1959 be running as this is called from VMRuntime.exit(). The OS does the
1962 *******************************************************************************/
1964 void vm_exit_handler(void)
1966 #if !defined(NDEBUG)
1968 class_showmethods(mainclass);
1970 if (showconstantpool)
1971 class_showconstantpool(mainclass);
1976 # if defined(ENABLE_PROFILING)
1978 profile_printstats();
1980 #endif /* !defined(NDEBUG) */
1982 #if defined(ENABLE_RT_TIMING)
1983 rt_timing_print_time_stats(stderr);
1986 #if defined(ENABLE_CYCLES_STATS)
1987 builtin_print_cycles_stats(stderr);
1988 stacktrace_print_cycles_stats(stderr);
1992 #if defined(ENABLE_STATISTICS)
1993 || opt_getcompilingtime || opt_stat
1997 log_text("CACAO terminated");
1999 #if defined(ENABLE_STATISTICS)
2002 #ifdef TYPECHECK_STATISTICS
2003 typecheck_print_statistics(get_logfile());
2007 if (opt_getcompilingtime)
2009 #endif /* defined(ENABLE_STATISTICS) */
2011 /* vm_print_profile(stderr);*/
2015 /* vm_abort ********************************************************************
2017 Prints an error message and aborts the VM.
2019 *******************************************************************************/
2021 void vm_abort(const char *text, ...)
2025 /* print the log message */
2030 log_vprint(text, ap);
2035 /* now abort the VM */
2041 /* vm_get_mainclass_from_jar ***************************************************
2043 Gets the name of the main class from a JAR's manifest file.
2045 *******************************************************************************/
2047 static char *vm_get_mainclass_from_jar(char *mainstring)
2050 java_objectheader *o;
2052 java_objectheader *s;
2054 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2057 exceptions_print_stacktrace();
2061 /* create JarFile object */
2066 exceptions_print_stacktrace();
2070 m = class_resolveclassmethod(c,
2072 utf_java_lang_String__void,
2073 class_java_lang_Object,
2077 exceptions_print_stacktrace();
2081 s = javastring_new_from_ascii(mainstring);
2083 (void) vm_call_method(m, o, s);
2085 if (exceptions_get_exception()) {
2086 exceptions_print_stacktrace();
2090 /* get manifest object */
2092 m = class_resolveclassmethod(c,
2093 utf_new_char("getManifest"),
2094 utf_new_char("()Ljava/util/jar/Manifest;"),
2095 class_java_lang_Object,
2099 exceptions_print_stacktrace();
2103 o = vm_call_method(m, o);
2106 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2111 /* get Main Attributes */
2113 m = class_resolveclassmethod(o->vftbl->class,
2114 utf_new_char("getMainAttributes"),
2115 utf_new_char("()Ljava/util/jar/Attributes;"),
2116 class_java_lang_Object,
2120 exceptions_print_stacktrace();
2124 o = vm_call_method(m, o);
2127 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2132 /* get property Main-Class */
2134 m = class_resolveclassmethod(o->vftbl->class,
2135 utf_new_char("getValue"),
2136 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2137 class_java_lang_Object,
2141 exceptions_print_stacktrace();
2145 s = javastring_new_from_ascii("Main-Class");
2147 o = vm_call_method(m, o, s);
2150 exceptions_print_stacktrace();
2154 return javastring_tochar(o);
2158 /* vm_compile_all **************************************************************
2160 Compile all methods found in the bootclasspath.
2162 *******************************************************************************/
2164 #if !defined(NDEBUG)
2165 static void vm_compile_all(void)
2170 classcache_name_entry *nmen;
2171 classcache_class_entry *clsen;
2174 /* create all classes found in the bootclasspath */
2175 /* XXX currently only works with zip/jar's */
2177 loader_load_all_classes();
2179 /* link all classes */
2181 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2182 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2184 for (; nmen; nmen = nmen->hashlink) {
2185 /* iterate over all class entries */
2187 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2188 c = clsen->classobj;
2193 if (!(c->state & CLASS_LINKED)) {
2194 if (!link_class(c)) {
2195 fprintf(stderr, "Error linking: ");
2196 utf_fprint_printable_ascii_classname(stderr, c->name);
2197 fprintf(stderr, "\n");
2199 /* print out exception and cause */
2201 exceptions_print_current_exception();
2203 /* goto next class */
2209 /* compile all class methods */
2211 for (i = 0; i < c->methodscount; i++) {
2212 m = &(c->methods[i]);
2214 if (m->jcode != NULL) {
2215 if (!jit_compile(m)) {
2216 fprintf(stderr, "Error compiling: ");
2217 utf_fprint_printable_ascii_classname(stderr, c->name);
2218 fprintf(stderr, ".");
2219 utf_fprint_printable_ascii(stderr, m->name);
2220 utf_fprint_printable_ascii(stderr, m->descriptor);
2221 fprintf(stderr, "\n");
2223 /* print out exception and cause */
2225 exceptions_print_current_exception();
2233 #endif /* !defined(NDEBUG) */
2236 /* vm_compile_method ***********************************************************
2238 Compile a specific method.
2240 *******************************************************************************/
2242 #if !defined(NDEBUG)
2243 static void vm_compile_method(void)
2247 /* create, load and link the main class */
2249 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2251 if (mainclass == NULL)
2252 exceptions_print_stacktrace();
2254 if (!link_class(mainclass))
2255 exceptions_print_stacktrace();
2257 if (opt_signature != NULL) {
2258 m = class_resolveclassmethod(mainclass,
2259 utf_new_char(opt_method),
2260 utf_new_char(opt_signature),
2265 m = class_resolveclassmethod(mainclass,
2266 utf_new_char(opt_method),
2273 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2274 opt_method, opt_signature ? opt_signature : "");
2278 #endif /* !defined(NDEBUG) */
2281 /* vm_vmargs_from_valist *******************************************************
2285 *******************************************************************************/
2287 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2288 vm_arg *vmargs, va_list ap)
2290 typedesc *paramtypes;
2293 paramtypes = m->parseddesc->paramtypes;
2295 /* if method is non-static fill first block and skip `this' pointer */
2300 /* the `this' pointer */
2301 vmargs[0].type = TYPE_ADR;
2302 vmargs[0].data.l = (u8) (ptrint) o;
2308 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2309 switch (paramtypes->type) {
2311 vmargs[i].type = TYPE_INT;
2312 vmargs[i].data.l = (s8) va_arg(ap, s4);
2316 vmargs[i].type = TYPE_LNG;
2317 vmargs[i].data.l = (s8) va_arg(ap, s8);
2321 vmargs[i].type = TYPE_FLT;
2322 #if defined(__ALPHA__)
2323 /* this keeps the assembler function much simpler */
2325 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2327 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2332 vmargs[i].type = TYPE_DBL;
2333 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2337 vmargs[i].type = TYPE_ADR;
2338 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2345 /* vm_vmargs_from_jvalue *******************************************************
2349 *******************************************************************************/
2351 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2352 vm_arg *vmargs, jvalue *args)
2354 typedesc *paramtypes;
2358 paramtypes = m->parseddesc->paramtypes;
2360 /* if method is non-static fill first block and skip `this' pointer */
2365 /* the `this' pointer */
2366 vmargs[0].type = TYPE_ADR;
2367 vmargs[0].data.l = (u8) (ptrint) o;
2373 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2374 switch (paramtypes->decltype) {
2376 vmargs[i].type = TYPE_INT;
2377 vmargs[i].data.l = (s8) args[j].i;
2381 vmargs[i].type = TYPE_LNG;
2382 vmargs[i].data.l = (s8) args[j].j;
2386 vmargs[i].type = TYPE_FLT;
2387 #if defined(__ALPHA__)
2388 /* this keeps the assembler function much simpler */
2390 vmargs[i].data.d = (jdouble) args[j].f;
2392 vmargs[i].data.f = args[j].f;
2397 vmargs[i].type = TYPE_DBL;
2398 vmargs[i].data.d = args[j].d;
2402 vmargs[i].type = TYPE_ADR;
2403 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2410 /* vm_call_method **************************************************************
2412 Calls a Java method with a variable number of arguments and returns
2415 *******************************************************************************/
2417 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2420 java_objectheader *ro;
2423 ro = vm_call_method_valist(m, o, ap);
2430 /* vm_call_method_valist *******************************************************
2432 Calls a Java method with a variable number of arguments, passed via
2433 a va_list, and returns an address.
2435 *******************************************************************************/
2437 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2442 java_objectheader *ro;
2445 /* mark start of dump memory area */
2447 dumpsize = dump_size();
2449 /* get number of Java method arguments */
2451 vmargscount = m->parseddesc->paramcount;
2453 /* allocate vm_arg array */
2455 vmargs = DMNEW(vm_arg, vmargscount);
2457 /* fill the vm_arg array from a va_list */
2459 vm_vmargs_from_valist(m, o, vmargs, ap);
2461 /* call the Java method */
2463 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2465 /* release dump area */
2467 dump_release(dumpsize);
2473 /* vm_call_method_jvalue *******************************************************
2475 Calls a Java method with a variable number of arguments, passed via
2476 a jvalue array, and returns an address.
2478 *******************************************************************************/
2480 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2485 java_objectheader *ro;
2488 /* mark start of dump memory area */
2490 dumpsize = dump_size();
2492 /* get number of Java method arguments */
2494 vmargscount = m->parseddesc->paramcount;
2496 /* allocate vm_arg array */
2498 vmargs = DMNEW(vm_arg, vmargscount);
2500 /* fill the vm_arg array from a va_list */
2502 vm_vmargs_from_jvalue(m, o, vmargs, args);
2504 /* call the Java method */
2506 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2508 /* release dump area */
2510 dump_release(dumpsize);
2516 /* vm_call_method_vmarg ********************************************************
2518 Calls a Java method with a variable number of arguments, passed via
2519 a vm_arg array, and returns an address.
2521 *******************************************************************************/
2523 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2526 java_objectheader *o;
2528 STATISTICS(count_calls_native_to_java++);
2530 #if defined(ENABLE_JIT)
2531 # if defined(ENABLE_INTRP)
2533 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2536 o = asm_vm_call_method(m, vmargscount, vmargs);
2538 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2545 /* vm_call_method_int **********************************************************
2547 Calls a Java method with a variable number of arguments and returns
2550 *******************************************************************************/
2552 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2558 i = vm_call_method_int_valist(m, o, ap);
2565 /* vm_call_method_int_valist ***************************************************
2567 Calls a Java method with a variable number of arguments, passed via
2568 a va_list, and returns an integer (s4).
2570 *******************************************************************************/
2572 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2579 /* mark start of dump memory area */
2581 dumpsize = dump_size();
2583 /* get number of Java method arguments */
2585 vmargscount = m->parseddesc->paramcount;
2587 /* allocate vm_arg array */
2589 vmargs = DMNEW(vm_arg, vmargscount);
2591 /* fill the vm_arg array from a va_list */
2593 vm_vmargs_from_valist(m, o, vmargs, ap);
2595 /* call the Java method */
2597 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2599 /* release dump area */
2601 dump_release(dumpsize);
2607 /* vm_call_method_int_jvalue ***************************************************
2609 Calls a Java method with a variable number of arguments, passed via
2610 a jvalue array, and returns an integer (s4).
2612 *******************************************************************************/
2614 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2621 /* mark start of dump memory area */
2623 dumpsize = dump_size();
2625 /* get number of Java method arguments */
2627 vmargscount = m->parseddesc->paramcount;
2629 /* allocate vm_arg array */
2631 vmargs = DMNEW(vm_arg, vmargscount);
2633 /* fill the vm_arg array from a va_list */
2635 vm_vmargs_from_jvalue(m, o, vmargs, args);
2637 /* call the Java method */
2639 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2641 /* release dump area */
2643 dump_release(dumpsize);
2649 /* vm_call_method_int_vmarg ****************************************************
2651 Calls a Java method with a variable number of arguments, passed via
2652 a vm_arg array, and returns an integer (s4).
2654 *******************************************************************************/
2656 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2660 STATISTICS(count_calls_native_to_java++);
2662 #if defined(ENABLE_JIT)
2663 # if defined(ENABLE_INTRP)
2665 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2668 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2670 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2677 /* vm_call_method_long *********************************************************
2679 Calls a Java method with a variable number of arguments and returns
2682 *******************************************************************************/
2684 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2690 l = vm_call_method_long_valist(m, o, ap);
2697 /* vm_call_method_long_valist **************************************************
2699 Calls a Java method with a variable number of arguments, passed via
2700 a va_list, and returns a long (s8).
2702 *******************************************************************************/
2704 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2711 /* mark start of dump memory area */
2713 dumpsize = dump_size();
2715 /* get number of Java method arguments */
2717 vmargscount = m->parseddesc->paramcount;
2719 /* allocate vm_arg array */
2721 vmargs = DMNEW(vm_arg, vmargscount);
2723 /* fill the vm_arg array from a va_list */
2725 vm_vmargs_from_valist(m, o, vmargs, ap);
2727 /* call the Java method */
2729 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2731 /* release dump area */
2733 dump_release(dumpsize);
2739 /* vm_call_method_long_jvalue **************************************************
2741 Calls a Java method with a variable number of arguments, passed via
2742 a jvalue array, and returns a long (s8).
2744 *******************************************************************************/
2746 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2753 /* mark start of dump memory area */
2755 dumpsize = dump_size();
2757 /* get number of Java method arguments */
2759 vmargscount = m->parseddesc->paramcount;
2761 /* allocate vm_arg array */
2763 vmargs = DMNEW(vm_arg, vmargscount);
2765 /* fill the vm_arg array from a va_list */
2767 vm_vmargs_from_jvalue(m, o, vmargs, args);
2769 /* call the Java method */
2771 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2773 /* release dump area */
2775 dump_release(dumpsize);
2781 /* vm_call_method_long_vmarg ***************************************************
2783 Calls a Java method with a variable number of arguments, passed via
2784 a vm_arg array, and returns a long (s8).
2786 *******************************************************************************/
2788 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2792 STATISTICS(count_calls_native_to_java++);
2794 #if defined(ENABLE_JIT)
2795 # if defined(ENABLE_INTRP)
2797 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2800 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2802 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2809 /* vm_call_method_float ********************************************************
2811 Calls a Java method with a variable number of arguments and returns
2814 *******************************************************************************/
2816 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2822 f = vm_call_method_float_valist(m, o, ap);
2829 /* vm_call_method_float_valist *************************************************
2831 Calls a Java method with a variable number of arguments, passed via
2832 a va_list, and returns a float.
2834 *******************************************************************************/
2836 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2844 /* mark start of dump memory area */
2846 dumpsize = dump_size();
2848 /* get number of Java method arguments */
2850 vmargscount = m->parseddesc->paramcount;
2852 /* allocate vm_arg array */
2854 vmargs = DMNEW(vm_arg, vmargscount);
2856 /* fill the vm_arg array from a va_list */
2858 vm_vmargs_from_valist(m, o, vmargs, ap);
2860 /* call the Java method */
2862 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2864 /* release dump area */
2866 dump_release(dumpsize);
2872 /* vm_call_method_float_jvalue *************************************************
2874 Calls a Java method with a variable number of arguments, passed via
2875 a jvalue array, and returns a float.
2877 *******************************************************************************/
2879 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2887 /* mark start of dump memory area */
2889 dumpsize = dump_size();
2891 /* get number of Java method arguments */
2893 vmargscount = m->parseddesc->paramcount;
2895 /* allocate vm_arg array */
2897 vmargs = DMNEW(vm_arg, vmargscount);
2899 /* fill the vm_arg array from a va_list */
2901 vm_vmargs_from_jvalue(m, o, vmargs, args);
2903 /* call the Java method */
2905 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2907 /* release dump area */
2909 dump_release(dumpsize);
2915 /* vm_call_method_float_vmarg **************************************************
2917 Calls a Java method with a variable number of arguments and returns
2920 *******************************************************************************/
2922 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2926 STATISTICS(count_calls_native_to_java++);
2928 #if defined(ENABLE_JIT)
2929 # if defined(ENABLE_INTRP)
2931 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2934 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2936 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2943 /* vm_call_method_double *******************************************************
2945 Calls a Java method with a variable number of arguments and returns
2948 *******************************************************************************/
2950 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2956 d = vm_call_method_double_valist(m, o, ap);
2963 /* vm_call_method_double_valist ************************************************
2965 Calls a Java method with a variable number of arguments, passed via
2966 a va_list, and returns a double.
2968 *******************************************************************************/
2970 double vm_call_method_double_valist(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_valist(m, o, vmargs, ap);
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_jvalue ************************************************
3008 Calls a Java method with a variable number of arguments, passed via
3009 a jvalue array, and returns a double.
3011 *******************************************************************************/
3013 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
3021 /* mark start of dump memory area */
3023 dumpsize = dump_size();
3025 /* get number of Java method arguments */
3027 vmargscount = m->parseddesc->paramcount;
3029 /* allocate vm_arg array */
3031 vmargs = DMNEW(vm_arg, vmargscount);
3033 /* fill the vm_arg array from a va_list */
3035 vm_vmargs_from_jvalue(m, o, vmargs, args);
3037 /* call the Java method */
3039 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
3041 /* release dump area */
3043 dump_release(dumpsize);
3049 /* vm_call_method_double_vmarg *************************************************
3051 Calls a Java method with a variable number of arguments and returns
3054 *******************************************************************************/
3056 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
3061 STATISTICS(count_calls_native_to_java++);
3063 #if defined(ENABLE_JIT)
3064 # if defined(ENABLE_INTRP)
3066 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3069 d = asm_vm_call_method_double(m, vmargscount, vmargs);
3071 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3079 * These are local overrides for various environment variables in Emacs.
3080 * Please do not remove this and leave it at the end of the file, where
3081 * Emacs will automagically detect them.
3082 * ---------------------------------------------------------------------
3085 * indent-tabs-mode: t