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_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/suck.h"
79 #if defined(ENABLE_JVMTI)
80 # include "native/jvmti/cacaodbg.h"
83 #if defined(ENABLE_VMLOG)
84 #include <vmlog_cacao.h>
88 /* Invocation API variables ***************************************************/
90 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
91 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
94 /* global variables ***********************************************************/
96 s4 vms = 0; /* number of VMs created */
98 bool vm_initializing = false;
99 bool vm_exiting = false;
101 char *cacao_prefix = NULL;
102 char *cacao_libjvm = NULL;
103 char *classpath_libdir = NULL;
105 char *_Jv_bootclasspath; /* contains the boot classpath */
106 char *_Jv_classpath; /* contains the classpath */
107 char *_Jv_java_library_path;
109 char *mainstring = NULL;
110 classinfo *mainclass = NULL;
112 char *specificmethodname = NULL;
113 char *specificsignature = NULL;
117 #if defined(ENABLE_INTRP)
118 u1 *intrp_main_stack = NULL;
122 /* define heap sizes **********************************************************/
124 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
125 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
126 #define STACK_SIZE 64 * 1024 /* default 64kB */
129 /* define command line options ************************************************/
157 /* Java non-standard options */
168 #if defined(ENABLE_PROFILING)
181 #if defined(ENABLE_STATISTICS)
198 #if defined(ENABLE_VERIFIER)
200 #if defined(TYPECHECK_VERBOSE)
203 #endif /* defined(ENABLE_VERIFIER) */
206 /* optimization options */
208 #if defined(ENABLE_LOOP)
212 #if defined(ENABLE_IFCONV)
216 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
220 #if defined(ENABLE_INLINING)
225 #if defined(ENABLE_INLINING_DEBUG)
226 OPT_INLINE_DEBUG_ALL,
227 OPT_INLINE_DEBUG_END,
228 OPT_INLINE_DEBUG_MIN,
229 OPT_INLINE_DEBUG_MAX,
230 OPT_INLINE_REPLACE_VERBOSE,
231 OPT_INLINE_REPLACE_VERBOSE2,
232 #endif /* defined(ENABLE_INLINING_DEBUG) */
233 #endif /* defined(ENABLE_INLINING) */
235 #if defined(ENABLE_INTRP)
236 /* interpreter options */
255 #if defined(ENABLE_DEBUG_FILTER)
256 OPT_FILTER_VERBOSECALL_INCLUDE,
257 OPT_FILTER_VERBOSECALL_EXCLUDE,
258 OPT_FILTER_SHOW_METHOD,
265 opt_struct opts[] = {
266 { "foo", false, OPT_FOO },
270 { "jar", false, OPT_JAR },
272 { "d32", false, OPT_D32 },
273 { "d64", false, OPT_D64 },
274 { "client", false, OPT_IGNORE },
275 { "server", false, OPT_IGNORE },
276 { "jvm", false, OPT_IGNORE },
277 { "hotspot", false, OPT_IGNORE },
279 { "classpath", true, OPT_CLASSPATH },
280 { "cp", true, OPT_CLASSPATH },
281 { "D", true, OPT_D },
282 { "version", false, OPT_VERSION },
283 { "showversion", false, OPT_SHOWVERSION },
284 { "fullversion", false, OPT_FULLVERSION },
285 { "help", false, OPT_HELP },
286 { "?", false, OPT_HELP },
287 { "X", false, OPT_X },
288 { "XX", false, OPT_XX },
290 { "esa", false, OPT_ESA },
291 { "enablesystemassertions", false, OPT_ESA },
292 { "dsa", false, OPT_DSA },
293 { "disablesystemassertions", false, OPT_DSA },
295 { "noasyncgc", false, OPT_IGNORE },
296 #if defined(ENABLE_VERIFIER)
297 { "noverify", false, OPT_NOVERIFY },
299 { "v", false, OPT_VERBOSE1 },
300 { "verbose:", true, OPT_VERBOSE },
302 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
303 { "verbosetc", false, OPT_VERBOSETC },
305 #if defined(__ALPHA__)
306 { "noieee", false, OPT_NOIEEE },
308 #if defined(ENABLE_STATISTICS)
309 { "time", false, OPT_TIME },
310 { "stat", false, OPT_STAT },
312 { "log", true, OPT_LOG },
313 { "c", true, OPT_CHECK },
314 { "l", false, OPT_LOAD },
315 { "eager", false, OPT_EAGER },
318 { "all", false, OPT_ALL },
319 { "sig", true, OPT_SIGNATURE },
322 #if defined(ENABLE_LOOP)
323 { "oloop", false, OPT_OLOOP },
325 #if defined(ENABLE_IFCONV)
326 { "ifconv", false, OPT_IFCONV },
328 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
329 { "lsra", false, OPT_LSRA },
332 #if defined(ENABLE_INTRP)
333 /* interpreter options */
335 { "trace", false, OPT_TRACE },
336 { "static-supers", true, OPT_STATIC_SUPERS },
337 { "no-dynamic", false, OPT_NO_DYNAMIC },
338 { "no-replication", false, OPT_NO_REPLICATION },
339 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
342 /* JVMTI Agent Command Line Options */
344 { "agentlib:", true, OPT_AGENTLIB },
345 { "agentpath:", true, OPT_AGENTPATH },
348 /* Java non-standard options */
350 { "Xjit", false, OPT_JIT },
351 { "Xint", false, OPT_INTRP },
352 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
353 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
354 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
355 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
358 { "Xdebug", false, OPT_DEBUG },
359 { "Xnoagent", false, OPT_NOAGENT },
360 { "Xrunjdwp", true, OPT_XRUNJDWP },
363 { "Xms", true, OPT_MS },
364 { "ms", true, OPT_MS },
365 { "Xmx", true, OPT_MX },
366 { "mx", true, OPT_MX },
367 { "Xss", true, OPT_SS },
368 { "ss", true, OPT_SS },
370 #if defined(ENABLE_PROFILING)
371 { "Xprof:", true, OPT_PROF_OPTION },
372 { "Xprof", false, OPT_PROF },
375 /* inlining options */
377 #if defined(ENABLE_INLINING)
378 #if defined(ENABLE_INLINING_DEBUG)
379 { "ia", false, OPT_INLINE_DEBUG_ALL },
380 { "ii", true, OPT_INLINE_DEBUG_MIN },
381 { "im", true, OPT_INLINE_DEBUG_MAX },
382 { "ie", true, OPT_INLINE_DEBUG_END },
383 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
384 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
385 #endif /* defined(ENABLE_INLINING_DEBUG) */
387 { "il", false, OPT_INLINE_LOG },
389 { "i", false, OPT_INLINING },
390 #endif /* defined(ENABLE_INLINING) */
392 /* keep these at the end of the list */
395 { "m", true, OPT_METHOD },
398 { "s", true, OPT_SHOW },
399 { "debug-color", false, OPT_DEBUGCOLOR },
401 #if defined(ENABLE_DEBUG_FILTER)
402 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
403 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
404 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
411 /* usage ***********************************************************************
413 Prints the correct usage syntax to stdout.
415 *******************************************************************************/
419 puts("Usage: cacao [-options] classname [arguments]");
420 puts(" (to run a class file)");
421 puts(" or cacao [-options] -jar jarfile [arguments]");
422 puts(" (to run a standalone jar file)\n");
424 puts("where options include:");
425 puts(" -d32 use 32-bit data model if available");
426 puts(" -d64 use 64-bit data model if available");
427 puts(" -client compatibility (currently ignored)");
428 puts(" -server compatibility (currently ignored)");
429 puts(" -jvm compatibility (currently ignored)");
430 puts(" -hotspot compatibility (currently ignored)\n");
432 puts(" -cp <path> specify a path to look for classes");
433 puts(" -classpath <path> specify a path to look for classes");
434 puts(" -D<name>=<value> add an entry to the property list");
435 puts(" -verbose[:class|gc|jni] enable specific verbose output");
436 puts(" -version print product version and exit");
437 puts(" -fullversion print jpackage-compatible product version and exit");
438 puts(" -showversion print product version and continue");
439 puts(" -help, -? print this help message");
440 puts(" -X print help on non-standard Java options");
441 puts(" -XX print help on CACAO options");
442 puts(" -esa | -enablesystemassertions");
443 puts(" enable system assertions");
444 puts(" -dsa | -disablesystemassertions");
445 puts(" disable system assertions");
448 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
449 puts (" for jdwp help use: -agentlib:jdwp=help");
450 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
453 /* exit with error code */
459 static void Xusage(void)
461 #if defined(ENABLE_JIT)
462 puts(" -Xjit JIT mode execution (default)");
464 #if defined(ENABLE_INTRP)
465 puts(" -Xint interpreter mode execution");
467 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
468 puts(" value is set as bootstrap class path");
469 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
470 puts(" value is appended to the bootstrap class path");
471 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
472 puts(" value is prepended to the bootstrap class path");
473 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
474 puts(" value is used as Java core library, but the");
475 puts(" hardcoded VM interface classes are prepended");
476 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
477 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
478 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
480 #if defined(ENABLE_PROFILING)
481 puts(" -Xprof[:bb] collect and print profiling data");
484 #if defined(ENABLE_JVMTI)
485 /* -Xdebug option depend on gnu classpath JDWP options. options:
486 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
487 puts(" -Xdebug enable remote debugging\n");
488 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
489 puts(" enable remote debugging\n");
492 /* exit with error code */
498 static void XXusage(void)
500 puts(" -v write state-information");
502 puts(" -verbose[:call|exception|jit|memory|threads]");
503 puts(" enable specific verbose output");
504 puts(" -debug-color colored output for ANSI terms");
506 #ifdef TYPECHECK_VERBOSE
507 puts(" -verbosetc write debug messages while typechecking");
509 #if defined(__ALPHA__)
510 puts(" -noieee don't use ieee compliant arithmetic");
512 #if defined(ENABLE_VERIFIER)
513 puts(" -noverify don't verify classfiles");
515 #if defined(ENABLE_STATISTICS)
516 puts(" -time measure the runtime");
517 puts(" -stat detailed compiler statistics");
519 puts(" -log logfile specify a name for the logfile");
520 puts(" -c(heck)b(ounds) don't check array bounds");
521 puts(" s(ync) don't check for synchronization");
522 #if defined(ENABLE_LOOP)
523 puts(" -oloop optimize array accesses in loops");
525 puts(" -l don't start the class after loading");
526 puts(" -eager perform eager class loading and linking");
528 puts(" -all compile all methods, no execution");
529 puts(" -m compile only a specific method");
530 puts(" -sig specify signature for a specific method");
533 puts(" -s... show...");
534 puts(" (c)onstants the constant pool");
535 puts(" (m)ethods class fields and methods");
536 puts(" (u)tf the utf - hash");
537 puts(" (i)ntermediate intermediate representation");
538 #if defined(ENABLE_DISASSEMBLER)
539 puts(" (a)ssembler disassembled listing");
540 puts(" n(o)ps show NOPs in disassembler output");
541 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
542 puts(" (n)ative disassembled native stubs");
544 puts(" (d)atasegment data segment listing");
546 #if defined(ENABLE_INLINING)
547 puts(" -i activate inlining");
549 puts(" -il log inlining");
551 #if defined(ENABLE_INLINING_DEBUG)
552 puts(" -ia use inlining for all methods");
553 puts(" -ii <size> set minimum size for inlined result");
554 puts(" -im <size> set maximum size for inlined result");
555 puts(" -ie <number> stop inlining after the given number of roots");
556 puts(" -ir log on-stack replacement");
557 puts(" -iR log on-stack replacement, more verbose");
558 #endif /* defined(ENABLE_INLINING_DEBUG) */
559 #endif /* defined(ENABLE_INLINING) */
561 #if defined(ENABLE_IFCONV)
562 puts(" -ifconv use if-conversion");
564 #if defined(ENABLE_LSRA)
565 puts(" -lsra use linear scan register allocation");
567 #if defined(ENABLE_SSA)
568 puts(" -lsra use linear scan register allocation (with SSA)");
570 #if defined(ENABLE_DEBUG_FILTER)
571 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
572 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
573 puts(" -XXfm <regex> filter for show options");
575 /* exit with error code */
581 /* version *********************************************************************
583 Only prints cacao version information.
585 *******************************************************************************/
587 static void version(bool opt_exit)
589 puts("java version \""JAVA_VERSION"\"");
590 puts("CACAO version "VERSION"");
592 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
593 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
594 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
595 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
597 puts("This program is free software; you can redistribute it and/or");
598 puts("modify it under the terms of the GNU General Public License as");
599 puts("published by the Free Software Foundation; either version 2, or (at");
600 puts("your option) any later version.\n");
602 puts("This program is distributed in the hope that it will be useful, but");
603 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
604 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
605 puts("General Public License for more details.\n");
607 puts("Configure/Build options:\n");
608 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
609 #if defined(__VERSION__)
610 puts(" CC : "VERSION_CC" ("__VERSION__")");
612 puts(" CC : "VERSION_CC"");
614 puts(" CFLAGS : "VERSION_CFLAGS"\n");
616 puts("Default variables:\n");
617 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
618 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
619 printf(" stack size : %d\n", STACK_SIZE);
620 #if defined(WITH_CLASSPATH_GNU)
621 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
623 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
625 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
627 puts("Runtime variables:\n");
628 printf(" maximum heap size : %d\n", opt_heapmaxsize);
629 printf(" initial heap size : %d\n", opt_heapstartsize);
630 printf(" stack size : %d\n", opt_stacksize);
631 printf(" libjvm.so : %s\n", cacao_libjvm);
632 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
633 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
634 printf(" java.class.path : %s\n", _Jv_classpath);
636 /* exit normally, if requested */
643 /* fullversion *****************************************************************
645 Prints a Sun compatible version information (required e.g. by
646 jpackage, www.jpackage.org).
648 *******************************************************************************/
650 static void fullversion(void)
652 puts("java full version \"cacao-"JAVA_VERSION"\"");
660 /* forward declarations *******************************************************/
662 static char *vm_get_mainclass_from_jar(char *mainstring);
664 static void vm_compile_all(void);
665 static void vm_compile_method(void);
669 /* vm_createjvm ****************************************************************
671 Implementation for JNI_CreateJavaVM.
673 *******************************************************************************/
675 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
677 JavaVMInitArgs *_vm_args;
681 /* get the arguments for the new JVM */
683 _vm_args = (JavaVMInitArgs *) vm_args;
685 /* get the VM and Env tables (must be set before vm_create) */
687 env = NEW(_Jv_JNIEnv);
689 #if defined(ENABLE_JNI)
690 env->env = &_Jv_JNINativeInterface;
693 /* XXX Set the global variable. Maybe we should do that differently. */
697 /* create and fill a JavaVM structure */
699 vm = NEW(_Jv_JavaVM);
701 #if defined(ENABLE_JNI)
702 vm->functions = &_Jv_JNIInvokeInterface;
705 /* XXX Set the global variable. Maybe we should do that differently. */
706 /* XXX JVMTI Agents needs a JavaVM */
710 /* actually create the JVM */
712 if (!vm_create(_vm_args))
715 #if defined(ENABLE_JNI)
716 /* setup the local ref table (must be created after vm_create) */
718 if (!jni_init_localref_table())
722 /* now return the values */
724 *p_vm = (JavaVM *) vm;
725 *p_env = (void *) env;
730 /* release allocated memory */
732 FREE(env, _Jv_JNIEnv);
733 FREE(vm, _Jv_JavaVM);
739 /* vm_create *******************************************************************
741 Creates a JVM. Called by vm_createjvm.
743 *******************************************************************************/
745 bool vm_create(JavaVMInitArgs *vm_args)
754 #if defined(ENABLE_JVMTI)
756 char *libname, *agentarg;
757 bool jdwp,agentbypath;
758 jdwp = agentbypath = false;
761 #if defined(ENABLE_VMLOG)
762 vmlog_cacao_init(vm_args);
765 /* check the JNI version requested */
767 switch (vm_args->version) {
768 case JNI_VERSION_1_1:
770 case JNI_VERSION_1_2:
771 case JNI_VERSION_1_4:
777 /* we only support 1 JVM instance */
782 if (atexit(vm_exit_handler))
783 vm_abort("atexit failed: %s\n", strerror(errno));
786 log_text("CACAO started -------------------------------------------------------");
788 /* We need to check if the actual size of a java.lang.Class object
789 is smaller or equal than the assumption made in
790 src/vmcore/class.h. */
792 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
793 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
795 /* set the VM starttime */
797 _Jv_jvm->starttime = builtin_currenttimemillis();
799 /* get stuff from the environment *****************************************/
801 #if defined(WITH_JRE_LAYOUT)
802 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
804 cacao_prefix = MNEW(char, 4096);
806 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
807 vm_abort("readlink failed: %s\n", strerror(errno));
809 /* get the path of the current executable */
811 cacao_prefix = dirname(cacao_prefix);
813 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
814 vm_abort("libjvm name to long for buffer\n");
816 /* concatenate the library name */
818 strcat(cacao_prefix, "/..");
820 /* now set path to libjvm.so */
822 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
824 cacao_libjvm = MNEW(char, len);
825 strcpy(cacao_libjvm, cacao_prefix);
826 strcat(cacao_libjvm, "/lib/libjvm");
828 /* and finally set the path to GNU Classpath libraries */
830 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
832 classpath_libdir = MNEW(char, len);
833 strcpy(classpath_libdir, cacao_prefix);
834 strcat(classpath_libdir, "/lib/classpath");
836 cacao_prefix = CACAO_PREFIX;
837 cacao_libjvm = CACAO_LIBDIR"/libjvm";
838 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
841 /* set the bootclasspath */
843 cp = getenv("BOOTCLASSPATH");
846 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
847 strcpy(_Jv_bootclasspath, cp);
850 #if defined(WITH_JRE_LAYOUT)
852 # if defined(WITH_CLASSPATH_GNU)
853 strlen(cacao_prefix) +
854 strlen("/share/cacao/vm.zip") +
857 strlen(cacao_prefix) +
858 strlen("/share/classpath/glibj.zip") +
861 _Jv_bootclasspath = MNEW(char, len);
862 # if defined(WITH_CLASSPATH_GNU)
863 strcat(_Jv_bootclasspath, cacao_prefix);
864 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
865 strcat(_Jv_bootclasspath, ":");
867 strcat(_Jv_bootclasspath, cacao_prefix);
868 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
871 # if defined(WITH_CLASSPATH_GNU)
872 strlen(CACAO_VM_ZIP) +
875 strlen(CLASSPATH_CLASSES) +
878 _Jv_bootclasspath = MNEW(char, len);
879 # if defined(WITH_CLASSPATH_GNU)
880 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
881 strcat(_Jv_bootclasspath, ":");
883 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
887 /* set the classpath */
889 cp = getenv("CLASSPATH");
892 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
893 strcat(_Jv_classpath, cp);
896 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
897 strcpy(_Jv_classpath, ".");
900 /* get and set java.library.path */
902 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
904 if (_Jv_java_library_path == NULL)
905 _Jv_java_library_path = "";
907 /* interpret the options **************************************************/
914 opt_heapmaxsize = HEAP_MAXSIZE;
915 opt_heapstartsize = HEAP_STARTSIZE;
916 opt_stacksize = STACK_SIZE;
919 #if defined(ENABLE_JVMTI)
920 /* initialize JVMTI related **********************************************/
924 /* initialize and fill properties before command-line handling */
926 if (!properties_init())
927 vm_abort("properties_init failed");
929 /* iterate over all passed options */
931 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
945 #if SIZEOF_VOID_P == 8
946 puts("Running a 32-bit JVM is not supported on this platform.");
952 #if SIZEOF_VOID_P == 4
953 puts("Running a 64-bit JVM is not supported on this platform.");
959 /* forget old classpath and set the argument as new classpath */
960 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
962 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
963 strcpy(_Jv_classpath, opt_arg);
967 for (i = 0; i < strlen(opt_arg); i++) {
968 if (opt_arg[i] == '=') {
970 properties_add(opt_arg, opt_arg + i + 1);
975 /* if no '=' is given, just create an empty property */
977 properties_add(opt_arg, "");
982 case OPT_BOOTCLASSPATH:
983 /* Forget default bootclasspath and set the argument as
984 new boot classpath. */
986 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
988 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
989 strcpy(_Jv_bootclasspath, opt_arg);
992 case OPT_BOOTCLASSPATH_A:
993 /* append to end of bootclasspath */
995 len = strlen(_Jv_bootclasspath);
997 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
1001 strlen(opt_arg) + strlen("0"));
1003 strcat(_Jv_bootclasspath, ":");
1004 strcat(_Jv_bootclasspath, opt_arg);
1007 case OPT_BOOTCLASSPATH_P:
1008 /* prepend in front of bootclasspath */
1010 cp = _Jv_bootclasspath;
1013 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1016 strcpy(_Jv_bootclasspath, opt_arg);
1017 strcat(_Jv_bootclasspath, ":");
1018 strcat(_Jv_bootclasspath, cp);
1020 MFREE(cp, char, len);
1023 case OPT_BOOTCLASSPATH_C:
1024 /* use as Java core library, but prepend VM interface classes */
1026 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1028 len = strlen(CACAO_VM_ZIP) +
1033 _Jv_bootclasspath = MNEW(char, len);
1035 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1036 strcat(_Jv_bootclasspath, ":");
1037 strcat(_Jv_bootclasspath, opt_arg);
1040 #if defined(ENABLE_JVMTI)
1042 /* this option exists only for compatibility reasons */
1046 /* I don't know yet what Xnoagent should do. This is only for
1047 compatiblity with eclipse - motse */
1056 strlen(CACAO_LIBDIR) +
1057 strlen("/libjdwp.so=") +
1061 agentarg = MNEW(char, len);
1063 strcpy(agentarg, CACAO_LIBDIR);
1064 strcat(agentarg, "/libjdwp.so=");
1065 strcat(agentarg, &opt_arg[1]);
1082 c = opt_arg[strlen(opt_arg) - 1];
1084 if ((c == 'k') || (c == 'K')) {
1085 j = atoi(opt_arg) * 1024;
1087 } else if ((c == 'm') || (c == 'M')) {
1088 j = atoi(opt_arg) * 1024 * 1024;
1094 opt_heapmaxsize = j;
1095 else if (opt == OPT_MS)
1096 opt_heapstartsize = j;
1107 if (strcmp("class", opt_arg) == 0) {
1108 opt_verboseclass = true;
1110 else if (strcmp("gc", opt_arg) == 0) {
1111 opt_verbosegc = true;
1113 else if (strcmp("jni", opt_arg) == 0) {
1114 opt_verbosejni = true;
1116 #if !defined(NDEBUG)
1117 else if (strcmp("call", opt_arg) == 0) {
1118 opt_verbosecall = true;
1120 else if (strcmp("exception", opt_arg) == 0) {
1121 opt_verboseexception = true;
1123 else if (strcmp("jit", opt_arg) == 0) {
1128 compileverbose = true;
1130 else if (strcmp("memory", opt_arg) == 0) {
1131 opt_verbosememory = true;
1133 # if defined(ENABLE_STATISTICS)
1134 /* we also need statistics */
1139 else if (strcmp("threads", opt_arg) == 0) {
1140 opt_verbosethreads = true;
1144 printf("Unknown -verbose option: %s\n", opt_arg);
1149 case OPT_DEBUGCOLOR:
1150 opt_debugcolor = true;
1153 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1155 opt_typecheckverbose = true;
1164 case OPT_FULLVERSION:
1168 case OPT_SHOWVERSION:
1176 #if defined(ENABLE_VERIFIER)
1182 #if defined(ENABLE_STATISTICS)
1184 opt_getcompilingtime = true;
1185 opt_getloadingtime = true;
1198 for (i = 0; i < strlen(opt_arg); i++) {
1199 switch (opt_arg[i]) {
1201 checkbounds = false;
1214 makeinitializations = false;
1221 #if !defined(NDEBUG)
1225 makeinitializations = false;
1230 opt_method = opt_arg;
1231 makeinitializations = false;
1235 opt_signature = opt_arg;
1239 case OPT_SHOW: /* Display options */
1240 for (i = 0; i < strlen(opt_arg); i++) {
1241 switch (opt_arg[i]) {
1243 showconstantpool = true;
1255 opt_showintermediate = true;
1256 compileverbose = true;
1259 #if defined(ENABLE_DISASSEMBLER)
1261 opt_showdisassemble = true;
1262 compileverbose = true;
1266 opt_shownops = true;
1270 opt_showexceptionstubs = true;
1274 opt_shownativestub = true;
1279 opt_showddatasegment = true;
1288 #if defined(ENABLE_LOOP)
1294 #if defined(ENABLE_INLINING)
1295 #if defined(ENABLE_INLINING_DEBUG)
1296 case OPT_INLINE_DEBUG_ALL:
1297 opt_inline_debug_all = true;
1299 case OPT_INLINE_DEBUG_END:
1300 opt_inline_debug_end_counter = atoi(opt_arg);
1302 case OPT_INLINE_DEBUG_MIN:
1303 opt_inline_debug_min_size = atoi(opt_arg);
1305 case OPT_INLINE_DEBUG_MAX:
1306 opt_inline_debug_max_size = atoi(opt_arg);
1308 case OPT_INLINE_REPLACE_VERBOSE:
1309 opt_replace_verbose = 1;
1311 case OPT_INLINE_REPLACE_VERBOSE2:
1312 opt_replace_verbose = 2;
1314 #endif /* defined(ENABLE_INLINING_DEBUG) */
1315 #if !defined(NDEBUG)
1316 case OPT_INLINE_LOG:
1317 opt_inline_debug_log = true;
1319 #endif /* !defined(NDEBUG) */
1322 opt_inlining = true;
1324 #endif /* defined(ENABLE_INLINING) */
1326 #if defined(ENABLE_IFCONV)
1332 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1351 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1355 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1358 #if defined(ENABLE_PROFILING)
1359 case OPT_PROF_OPTION:
1360 /* use <= to get the last \0 too */
1362 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1363 if (opt_arg[i] == ',')
1366 if (opt_arg[i] == '\0') {
1367 if (strcmp("bb", opt_arg + j) == 0)
1371 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1375 /* set k to next char */
1388 #if defined(ENABLE_JIT)
1391 printf("-Xjit option not enabled.\n");
1397 #if defined(ENABLE_INTRP)
1400 printf("-Xint option not enabled.\n");
1405 #if defined(ENABLE_INTRP)
1406 case OPT_STATIC_SUPERS:
1407 opt_static_supers = atoi(opt_arg);
1410 case OPT_NO_DYNAMIC:
1411 opt_no_dynamic = true;
1414 case OPT_NO_REPLICATION:
1415 opt_no_replication = true;
1418 case OPT_NO_QUICKSUPER:
1419 opt_no_quicksuper = true;
1427 #if defined(ENABLE_DEBUG_FILTER)
1428 case OPT_FILTER_VERBOSECALL_INCLUDE:
1429 opt_filter_verbosecall_include = opt_arg;
1432 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1433 opt_filter_verbosecall_exclude = opt_arg;
1436 case OPT_FILTER_SHOW_METHOD:
1437 opt_filter_show_method = opt_arg;
1442 printf("Unknown option: %s\n",
1443 vm_args->options[opt_index].optionString);
1448 /* get the main class *****************************************************/
1450 if (opt_index < vm_args->nOptions) {
1451 mainstring = vm_args->options[opt_index++].optionString;
1453 /* Put the jar file into the classpath (if any). */
1455 if (opt_jar == true) {
1456 /* free old classpath */
1458 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1460 /* put jarfile into classpath */
1462 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1464 strcpy(_Jv_classpath, mainstring);
1467 /* replace .'s with /'s in classname */
1469 for (i = strlen(mainstring) - 1; i >= 0; i--)
1470 if (mainstring[i] == '.')
1471 mainstring[i] = '/';
1475 #if defined(ENABLE_JVMTI)
1477 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1478 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1481 MFREE(agentarg, char, strlen(agentarg));
1483 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1487 /* initialize this JVM ****************************************************/
1489 vm_initializing = true;
1491 #if defined(ENABLE_THREADS)
1492 /* pre-initialize some core thread stuff, like the stopworldlock,
1493 thus this has to happen _before_ gc_init()!!! */
1498 /* initialize the garbage collector */
1500 gc_init(opt_heapmaxsize, opt_heapstartsize);
1502 /* install architecture dependent signal handlers */
1505 vm_abort("vm_create: signal_init failed");
1507 #if defined(ENABLE_INTRP)
1508 /* Allocate main thread stack on the Java heap. */
1511 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1512 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1516 /* AFTER: threads_preinit */
1519 vm_abort("vm_create: string_init failed");
1521 /* AFTER: threads_preinit */
1524 vm_abort("vm_create: utf8_init failed");
1526 /* AFTER: thread_preinit */
1529 vm_abort("vm_create: suck_init failed");
1531 suck_add_from_property("java.endorsed.dirs");
1533 /* Now we have all options handled and we can print the version
1536 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1541 /* AFTER: utf8_init */
1543 suck_add(_Jv_bootclasspath);
1545 /* Now re-set some of the properties that may have changed. This
1546 must be done after _all_ environment variables have been
1547 processes (e.g. -jar handling).
1549 AFTER: suck_add_from_property, since it may change the
1550 _Jv_bootclasspath pointer. */
1552 if (!properties_postinit())
1553 vm_abort("vm_create: properties_postinit failed");
1555 /* initialize the classcache hashtable stuff: lock, hashtable
1556 (must be done _after_ threads_preinit) */
1558 if (!classcache_init())
1559 vm_abort("vm_create: classcache_init failed");
1561 /* initialize the memory subsystem (must be done _after_
1565 vm_abort("vm_create: memory_init failed");
1567 /* initialize the finalizer stuff (must be done _after_
1570 if (!finalizer_init())
1571 vm_abort("vm_create: finalizer_init failed");
1573 /* initialize the codegen subsystems */
1577 /* initializes jit compiler */
1581 /* machine dependent initialization */
1583 #if defined(ENABLE_JIT)
1584 # if defined(ENABLE_INTRP)
1594 /* initialize the loader subsystems (must be done _after_
1598 vm_abort("vm_create: loader_init failed");
1601 vm_abort("vm_create: linker_init failed");
1603 /* Initialize the native subsystem. */
1606 vm_abort("vm_create: native_init failed");
1608 if (!exceptions_init())
1609 vm_abort("vm_create: exceptions_init failed");
1611 if (!builtin_init())
1612 vm_abort("vm_create: builtin_init failed");
1614 #if defined(ENABLE_JNI)
1615 /* Initialize the JNI subsystem (must be done _before_
1616 threads_init, as threads_init can call JNI methods
1617 (e.g. NewGlobalRef). */
1620 vm_abort("vm_create: jni_init failed");
1623 #if defined(ENABLE_THREADS)
1624 if (!threads_init())
1625 vm_abort("vm_create: threads_init failed");
1628 #if defined(ENABLE_PROFILING)
1629 /* initialize profiling */
1631 if (!profile_init())
1632 vm_abort("vm_create: profile_init failed");
1635 #if defined(ENABLE_THREADS)
1636 /* initialize recompilation */
1638 if (!recompile_init())
1639 vm_abort("vm_create: recompile_init failed");
1641 #if !defined(PTHREADS_IS_LINUXTHREADS)
1642 /* XXX Remove this #ifdef with exact-GC. */
1644 /* start the signal handler thread */
1646 if (!signal_start_thread())
1647 vm_abort("vm_create: signal_start_thread failed");
1650 /* finally, start the finalizer thread */
1652 if (!finalizer_start_thread())
1653 vm_abort("vm_create: finalizer_start_thread failed");
1655 # if !defined(NDEBUG)
1656 /* start the memory profiling thread */
1658 if (opt_verbosememory)
1659 if (!memory_start_thread())
1660 vm_abort("vm_create: memory_start_thread failed");
1663 /* start the recompilation thread (must be done before the
1664 profiling thread) */
1666 if (!recompile_start_thread())
1667 vm_abort("vm_create: recompile_start_thread failed");
1669 # if defined(ENABLE_PROFILING)
1670 /* start the profile sampling thread */
1673 /* if (!profile_start_thread()) */
1674 /* vm_abort("vm_create: profile_start_thread failed"); */
1678 #if defined(ENABLE_JVMTI)
1680 /* add agent library to native library hashtable */
1681 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1685 /* increment the number of VMs */
1689 /* initialization is done */
1691 vm_initializing = false;
1693 /* everything's ok */
1699 /* vm_run **********************************************************************
1701 Runs the main-method of the passed class.
1703 *******************************************************************************/
1705 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1708 classinfo *mainclass;
1710 java_objectarray *oa;
1713 java_objectheader *s;
1717 #if !defined(NDEBUG)
1723 if (opt_method != NULL) {
1724 vm_compile_method();
1727 #endif /* !defined(NDEBUG) */
1729 /* should we run the main-method? */
1731 if (mainstring == NULL)
1734 /* set return value to OK */
1738 if (opt_jar == true) {
1739 /* open jar file with java.util.jar.JarFile */
1741 mainstring = vm_get_mainclass_from_jar(mainstring);
1743 if (mainstring == NULL)
1747 /* load the main class */
1749 mainutf = utf_new_char(mainstring);
1751 #if defined(ENABLE_JAVAME_CLDC1_1)
1752 mainclass = load_class_bootstrap(mainutf);
1754 mainclass = load_class_from_sysloader(mainutf);
1757 /* error loading class */
1759 if ((exceptions_get_exception() != NULL) || (mainclass == NULL)) {
1760 exceptions_print_stacktrace();
1764 if (!link_class(mainclass)) {
1765 exceptions_print_stacktrace();
1769 /* find the `main' method of the main class */
1771 m = class_resolveclassmethod(mainclass,
1772 utf_new_char("main"),
1773 utf_new_char("([Ljava/lang/String;)V"),
1774 class_java_lang_Object,
1777 if (exceptions_get_exception()) {
1778 exceptions_print_stacktrace();
1782 /* there is no main method or it isn't static */
1784 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1785 exceptions_clear_exception();
1786 exceptions_throw_nosuchmethoderror(mainclass,
1787 utf_new_char("main"),
1788 utf_new_char("([Ljava/lang/String;)V"));
1790 exceptions_print_stacktrace();
1794 /* build argument array */
1796 oalength = vm_args->nOptions - opt_index;
1798 oa = builtin_anewarray(oalength, class_java_lang_String);
1800 for (i = 0; i < oalength; i++) {
1801 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1802 s = javastring_new(u);
1807 #ifdef TYPEINFO_DEBUG_TEST
1808 /* test the typeinfo system */
1811 /*class_showmethods(currentThread->group->header.vftbl->class); */
1813 #if defined(ENABLE_JVMTI)
1814 jvmti_set_phase(JVMTI_PHASE_LIVE);
1817 /* set ThreadMXBean variables */
1819 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1820 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1822 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1823 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1824 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1825 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1827 /* start the main thread */
1829 (void) vm_call_method(m, NULL, oa);
1831 /* exception occurred? */
1833 if (exceptions_get_exception()) {
1834 exceptions_print_stacktrace();
1838 /* unload the JavaVM */
1840 (void) vm_destroy(vm);
1848 /* vm_destroy ******************************************************************
1850 Unloads a Java VM and reclaims its resources.
1852 *******************************************************************************/
1854 s4 vm_destroy(JavaVM *vm)
1856 #if defined(ENABLE_THREADS)
1857 threads_join_all_threads();
1860 /* everything's ok */
1866 /* vm_exit *********************************************************************
1868 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1870 *******************************************************************************/
1872 void vm_exit(s4 status)
1876 /* signal that we are exiting */
1880 assert(class_java_lang_System);
1881 assert(class_java_lang_System->state & CLASS_LOADED);
1883 #if defined(ENABLE_JVMTI)
1884 if (jvmti || (dbgcom!=NULL)) {
1885 jvmti_set_phase(JVMTI_PHASE_DEAD);
1886 if (jvmti) jvmti_agentunload();
1890 if (!link_class(class_java_lang_System)) {
1891 exceptions_print_stacktrace();
1895 /* call java.lang.System.exit(I)V */
1897 m = class_resolveclassmethod(class_java_lang_System,
1898 utf_new_char("exit"),
1900 class_java_lang_Object,
1904 exceptions_print_stacktrace();
1908 /* call the exit function with passed exit status */
1910 (void) vm_call_method(m, NULL, status);
1912 /* If we had an exception, just ignore the exception and exit with
1915 vm_shutdown(status);
1919 /* vm_shutdown *****************************************************************
1921 Terminates the system immediately without freeing memory explicitly
1922 (to be used only for abnormal termination).
1924 *******************************************************************************/
1926 void vm_shutdown(s4 status)
1929 #if defined(ENABLE_STATISTICS)
1930 || opt_getcompilingtime || opt_stat
1934 log_text("CACAO terminated by shutdown");
1935 dolog("Exit status: %d\n", (s4) status);
1939 #if defined(ENABLE_JVMTI)
1940 /* terminate cacaodbgserver */
1942 pthread_mutex_lock(&dbgcomlock);
1944 pthread_mutex_unlock(&dbgcomlock);
1945 jvmti_cacaodbgserver_quit();
1953 /* vm_exit_handler *************************************************************
1955 The exit_handler function is called upon program termination.
1957 ATTENTION: Don't free system resources here! Some threads may still
1958 be running as this is called from VMRuntime.exit(). The OS does the
1961 *******************************************************************************/
1963 void vm_exit_handler(void)
1965 #if !defined(NDEBUG)
1967 class_showmethods(mainclass);
1969 if (showconstantpool)
1970 class_showconstantpool(mainclass);
1975 # if defined(ENABLE_PROFILING)
1977 profile_printstats();
1979 #endif /* !defined(NDEBUG) */
1981 #if defined(ENABLE_RT_TIMING)
1982 rt_timing_print_time_stats(stderr);
1985 #if defined(ENABLE_CYCLES_STATS)
1986 builtin_print_cycles_stats(stderr);
1987 stacktrace_print_cycles_stats(stderr);
1991 #if defined(ENABLE_STATISTICS)
1992 || opt_getcompilingtime || opt_stat
1996 log_text("CACAO terminated");
1998 #if defined(ENABLE_STATISTICS)
2001 #ifdef TYPECHECK_STATISTICS
2002 typecheck_print_statistics(get_logfile());
2006 if (opt_getcompilingtime)
2008 #endif /* defined(ENABLE_STATISTICS) */
2010 /* vm_print_profile(stderr);*/
2014 /* vm_abort ********************************************************************
2016 Prints an error message and aborts the VM.
2018 *******************************************************************************/
2020 void vm_abort(const char *text, ...)
2024 /* print the log message */
2029 log_vprint(text, ap);
2034 /* now abort the VM */
2040 /* vm_get_mainclass_from_jar ***************************************************
2042 Gets the name of the main class from a JAR's manifest file.
2044 *******************************************************************************/
2046 static char *vm_get_mainclass_from_jar(char *mainstring)
2049 java_objectheader *o;
2051 java_objectheader *s;
2053 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2056 exceptions_print_stacktrace();
2060 /* create JarFile object */
2065 exceptions_print_stacktrace();
2069 m = class_resolveclassmethod(c,
2071 utf_java_lang_String__void,
2072 class_java_lang_Object,
2076 exceptions_print_stacktrace();
2080 s = javastring_new_from_ascii(mainstring);
2082 (void) vm_call_method(m, o, s);
2084 if (exceptions_get_exception()) {
2085 exceptions_print_stacktrace();
2089 /* get manifest object */
2091 m = class_resolveclassmethod(c,
2092 utf_new_char("getManifest"),
2093 utf_new_char("()Ljava/util/jar/Manifest;"),
2094 class_java_lang_Object,
2098 exceptions_print_stacktrace();
2102 o = vm_call_method(m, o);
2105 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2110 /* get Main Attributes */
2112 m = class_resolveclassmethod(o->vftbl->class,
2113 utf_new_char("getMainAttributes"),
2114 utf_new_char("()Ljava/util/jar/Attributes;"),
2115 class_java_lang_Object,
2119 exceptions_print_stacktrace();
2123 o = vm_call_method(m, o);
2126 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2131 /* get property Main-Class */
2133 m = class_resolveclassmethod(o->vftbl->class,
2134 utf_new_char("getValue"),
2135 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2136 class_java_lang_Object,
2140 exceptions_print_stacktrace();
2144 s = javastring_new_from_ascii("Main-Class");
2146 o = vm_call_method(m, o, s);
2149 exceptions_print_stacktrace();
2153 return javastring_tochar(o);
2157 /* vm_compile_all **************************************************************
2159 Compile all methods found in the bootclasspath.
2161 *******************************************************************************/
2163 #if !defined(NDEBUG)
2164 static void vm_compile_all(void)
2169 classcache_name_entry *nmen;
2170 classcache_class_entry *clsen;
2173 /* create all classes found in the bootclasspath */
2174 /* XXX currently only works with zip/jar's */
2176 loader_load_all_classes();
2178 /* link all classes */
2180 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2181 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2183 for (; nmen; nmen = nmen->hashlink) {
2184 /* iterate over all class entries */
2186 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2187 c = clsen->classobj;
2192 if (!(c->state & CLASS_LINKED)) {
2193 if (!link_class(c)) {
2194 fprintf(stderr, "Error linking: ");
2195 utf_fprint_printable_ascii_classname(stderr, c->name);
2196 fprintf(stderr, "\n");
2198 /* print out exception and cause */
2200 exceptions_print_current_exception();
2202 /* goto next class */
2208 /* compile all class methods */
2210 for (i = 0; i < c->methodscount; i++) {
2211 m = &(c->methods[i]);
2213 if (m->jcode != NULL) {
2214 if (!jit_compile(m)) {
2215 fprintf(stderr, "Error compiling: ");
2216 utf_fprint_printable_ascii_classname(stderr, c->name);
2217 fprintf(stderr, ".");
2218 utf_fprint_printable_ascii(stderr, m->name);
2219 utf_fprint_printable_ascii(stderr, m->descriptor);
2220 fprintf(stderr, "\n");
2222 /* print out exception and cause */
2224 exceptions_print_current_exception();
2232 #endif /* !defined(NDEBUG) */
2235 /* vm_compile_method ***********************************************************
2237 Compile a specific method.
2239 *******************************************************************************/
2241 #if !defined(NDEBUG)
2242 static void vm_compile_method(void)
2246 /* create, load and link the main class */
2248 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2250 if (mainclass == NULL)
2251 exceptions_print_stacktrace();
2253 if (!link_class(mainclass))
2254 exceptions_print_stacktrace();
2256 if (opt_signature != NULL) {
2257 m = class_resolveclassmethod(mainclass,
2258 utf_new_char(opt_method),
2259 utf_new_char(opt_signature),
2264 m = class_resolveclassmethod(mainclass,
2265 utf_new_char(opt_method),
2272 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2273 opt_method, opt_signature ? opt_signature : "");
2277 #endif /* !defined(NDEBUG) */
2280 /* vm_vmargs_from_valist *******************************************************
2284 *******************************************************************************/
2286 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2287 vm_arg *vmargs, va_list ap)
2289 typedesc *paramtypes;
2292 paramtypes = m->parseddesc->paramtypes;
2294 /* if method is non-static fill first block and skip `this' pointer */
2299 /* the `this' pointer */
2300 vmargs[0].type = TYPE_ADR;
2301 vmargs[0].data.l = (u8) (ptrint) o;
2307 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2308 switch (paramtypes->decltype) {
2309 /* primitive types */
2310 case PRIMITIVETYPE_BOOLEAN:
2311 case PRIMITIVETYPE_BYTE:
2312 case PRIMITIVETYPE_CHAR:
2313 case PRIMITIVETYPE_SHORT:
2314 case PRIMITIVETYPE_INT:
2315 vmargs[i].type = TYPE_INT;
2316 vmargs[i].data.l = (s8) va_arg(ap, s4);
2319 case PRIMITIVETYPE_LONG:
2320 vmargs[i].type = TYPE_LNG;
2321 vmargs[i].data.l = (s8) va_arg(ap, s8);
2324 case PRIMITIVETYPE_FLOAT:
2325 vmargs[i].type = TYPE_FLT;
2326 #if defined(__ALPHA__)
2327 /* this keeps the assembler function much simpler */
2329 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2331 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2335 case PRIMITIVETYPE_DOUBLE:
2336 vmargs[i].type = TYPE_DBL;
2337 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2341 vmargs[i].type = TYPE_ADR;
2342 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2349 /* vm_vmargs_from_jvalue *******************************************************
2353 *******************************************************************************/
2355 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2356 vm_arg *vmargs, jvalue *args)
2358 typedesc *paramtypes;
2362 paramtypes = m->parseddesc->paramtypes;
2364 /* if method is non-static fill first block and skip `this' pointer */
2369 /* the `this' pointer */
2370 vmargs[0].type = TYPE_ADR;
2371 vmargs[0].data.l = (u8) (ptrint) o;
2377 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2378 switch (paramtypes->decltype) {
2379 /* primitive types */
2380 case PRIMITIVETYPE_BOOLEAN:
2381 case PRIMITIVETYPE_BYTE:
2382 case PRIMITIVETYPE_CHAR:
2383 case PRIMITIVETYPE_SHORT:
2384 case PRIMITIVETYPE_INT:
2385 vmargs[i].type = TYPE_INT;
2386 vmargs[i].data.l = (s8) args[j].i;
2389 case PRIMITIVETYPE_LONG:
2390 vmargs[i].type = TYPE_LNG;
2391 vmargs[i].data.l = (s8) args[j].j;
2394 case PRIMITIVETYPE_FLOAT:
2395 vmargs[i].type = TYPE_FLT;
2396 #if defined(__ALPHA__)
2397 /* this keeps the assembler function much simpler */
2399 vmargs[i].data.d = (jdouble) args[j].f;
2401 vmargs[i].data.f = args[j].f;
2405 case PRIMITIVETYPE_DOUBLE:
2406 vmargs[i].type = TYPE_DBL;
2407 vmargs[i].data.d = args[j].d;
2411 vmargs[i].type = TYPE_ADR;
2412 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2419 /* vm_call_method **************************************************************
2421 Calls a Java method with a variable number of arguments and returns
2424 *******************************************************************************/
2426 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2429 java_objectheader *ro;
2432 ro = vm_call_method_valist(m, o, ap);
2439 /* vm_call_method_valist *******************************************************
2441 Calls a Java method with a variable number of arguments, passed via
2442 a va_list, and returns an address.
2444 *******************************************************************************/
2446 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2451 java_objectheader *ro;
2454 /* mark start of dump memory area */
2456 dumpsize = dump_size();
2458 /* get number of Java method arguments */
2460 vmargscount = m->parseddesc->paramcount;
2462 /* allocate vm_arg array */
2464 vmargs = DMNEW(vm_arg, vmargscount);
2466 /* fill the vm_arg array from a va_list */
2468 vm_vmargs_from_valist(m, o, vmargs, ap);
2470 /* call the Java method */
2472 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2474 /* release dump area */
2476 dump_release(dumpsize);
2482 /* vm_call_method_jvalue *******************************************************
2484 Calls a Java method with a variable number of arguments, passed via
2485 a jvalue array, and returns an address.
2487 *******************************************************************************/
2489 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2494 java_objectheader *ro;
2497 /* mark start of dump memory area */
2499 dumpsize = dump_size();
2501 /* get number of Java method arguments */
2503 vmargscount = m->parseddesc->paramcount;
2505 /* allocate vm_arg array */
2507 vmargs = DMNEW(vm_arg, vmargscount);
2509 /* fill the vm_arg array from a va_list */
2511 vm_vmargs_from_jvalue(m, o, vmargs, args);
2513 /* call the Java method */
2515 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2517 /* release dump area */
2519 dump_release(dumpsize);
2525 /* vm_call_method_vmarg ********************************************************
2527 Calls a Java method with a variable number of arguments, passed via
2528 a vm_arg array, and returns an address.
2530 *******************************************************************************/
2532 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2535 java_objectheader *o;
2537 #if defined(ENABLE_JIT)
2538 # if defined(ENABLE_INTRP)
2540 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2543 o = asm_vm_call_method(m, vmargscount, vmargs);
2545 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2552 /* vm_call_method_int **********************************************************
2554 Calls a Java method with a variable number of arguments and returns
2557 *******************************************************************************/
2559 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2565 i = vm_call_method_int_valist(m, o, ap);
2572 /* vm_call_method_int_valist ***************************************************
2574 Calls a Java method with a variable number of arguments, passed via
2575 a va_list, and returns an integer (s4).
2577 *******************************************************************************/
2579 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2586 /* mark start of dump memory area */
2588 dumpsize = dump_size();
2590 /* get number of Java method arguments */
2592 vmargscount = m->parseddesc->paramcount;
2594 /* allocate vm_arg array */
2596 vmargs = DMNEW(vm_arg, vmargscount);
2598 /* fill the vm_arg array from a va_list */
2600 vm_vmargs_from_valist(m, o, vmargs, ap);
2602 /* call the Java method */
2604 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2606 /* release dump area */
2608 dump_release(dumpsize);
2614 /* vm_call_method_int_jvalue ***************************************************
2616 Calls a Java method with a variable number of arguments, passed via
2617 a jvalue array, and returns an integer (s4).
2619 *******************************************************************************/
2621 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2628 /* mark start of dump memory area */
2630 dumpsize = dump_size();
2632 /* get number of Java method arguments */
2634 vmargscount = m->parseddesc->paramcount;
2636 /* allocate vm_arg array */
2638 vmargs = DMNEW(vm_arg, vmargscount);
2640 /* fill the vm_arg array from a va_list */
2642 vm_vmargs_from_jvalue(m, o, vmargs, args);
2644 /* call the Java method */
2646 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2648 /* release dump area */
2650 dump_release(dumpsize);
2656 /* vm_call_method_int_vmarg ****************************************************
2658 Calls a Java method with a variable number of arguments, passed via
2659 a vm_arg array, and returns an integer (s4).
2661 *******************************************************************************/
2663 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2667 #if defined(ENABLE_JIT)
2668 # if defined(ENABLE_INTRP)
2670 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2673 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2675 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2682 /* vm_call_method_long *********************************************************
2684 Calls a Java method with a variable number of arguments and returns
2687 *******************************************************************************/
2689 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2695 l = vm_call_method_long_valist(m, o, ap);
2702 /* vm_call_method_long_valist **************************************************
2704 Calls a Java method with a variable number of arguments, passed via
2705 a va_list, and returns a long (s8).
2707 *******************************************************************************/
2709 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2716 /* mark start of dump memory area */
2718 dumpsize = dump_size();
2720 /* get number of Java method arguments */
2722 vmargscount = m->parseddesc->paramcount;
2724 /* allocate vm_arg array */
2726 vmargs = DMNEW(vm_arg, vmargscount);
2728 /* fill the vm_arg array from a va_list */
2730 vm_vmargs_from_valist(m, o, vmargs, ap);
2732 /* call the Java method */
2734 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2736 /* release dump area */
2738 dump_release(dumpsize);
2744 /* vm_call_method_long_jvalue **************************************************
2746 Calls a Java method with a variable number of arguments, passed via
2747 a jvalue array, and returns a long (s8).
2749 *******************************************************************************/
2751 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2758 /* mark start of dump memory area */
2760 dumpsize = dump_size();
2762 /* get number of Java method arguments */
2764 vmargscount = m->parseddesc->paramcount;
2766 /* allocate vm_arg array */
2768 vmargs = DMNEW(vm_arg, vmargscount);
2770 /* fill the vm_arg array from a va_list */
2772 vm_vmargs_from_jvalue(m, o, vmargs, args);
2774 /* call the Java method */
2776 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2778 /* release dump area */
2780 dump_release(dumpsize);
2786 /* vm_call_method_long_vmarg ***************************************************
2788 Calls a Java method with a variable number of arguments, passed via
2789 a vm_arg array, and returns a long (s8).
2791 *******************************************************************************/
2793 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2797 #if defined(ENABLE_JIT)
2798 # if defined(ENABLE_INTRP)
2800 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2803 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2805 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2812 /* vm_call_method_float ********************************************************
2814 Calls a Java method with a variable number of arguments and returns
2817 *******************************************************************************/
2819 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2825 f = vm_call_method_float_valist(m, o, ap);
2832 /* vm_call_method_float_valist *************************************************
2834 Calls a Java method with a variable number of arguments, passed via
2835 a va_list, and returns a float.
2837 *******************************************************************************/
2839 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2847 /* mark start of dump memory area */
2849 dumpsize = dump_size();
2851 /* get number of Java method arguments */
2853 vmargscount = m->parseddesc->paramcount;
2855 /* allocate vm_arg array */
2857 vmargs = DMNEW(vm_arg, vmargscount);
2859 /* fill the vm_arg array from a va_list */
2861 vm_vmargs_from_valist(m, o, vmargs, ap);
2863 /* call the Java method */
2865 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2867 /* release dump area */
2869 dump_release(dumpsize);
2875 /* vm_call_method_float_jvalue *************************************************
2877 Calls a Java method with a variable number of arguments, passed via
2878 a jvalue array, and returns a float.
2880 *******************************************************************************/
2882 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2890 /* mark start of dump memory area */
2892 dumpsize = dump_size();
2894 /* get number of Java method arguments */
2896 vmargscount = m->parseddesc->paramcount;
2898 /* allocate vm_arg array */
2900 vmargs = DMNEW(vm_arg, vmargscount);
2902 /* fill the vm_arg array from a va_list */
2904 vm_vmargs_from_jvalue(m, o, vmargs, args);
2906 /* call the Java method */
2908 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2910 /* release dump area */
2912 dump_release(dumpsize);
2918 /* vm_call_method_float_vmarg **************************************************
2920 Calls a Java method with a variable number of arguments and returns
2923 *******************************************************************************/
2925 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2929 #if defined(ENABLE_JIT)
2930 # if defined(ENABLE_INTRP)
2932 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2935 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2937 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2944 /* vm_call_method_double *******************************************************
2946 Calls a Java method with a variable number of arguments and returns
2949 *******************************************************************************/
2951 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2957 d = vm_call_method_double_valist(m, o, ap);
2964 /* vm_call_method_double_valist ************************************************
2966 Calls a Java method with a variable number of arguments, passed via
2967 a va_list, and returns a double.
2969 *******************************************************************************/
2971 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2979 /* mark start of dump memory area */
2981 dumpsize = dump_size();
2983 /* get number of Java method arguments */
2985 vmargscount = m->parseddesc->paramcount;
2987 /* allocate vm_arg array */
2989 vmargs = DMNEW(vm_arg, vmargscount);
2991 /* fill the vm_arg array from a va_list */
2993 vm_vmargs_from_valist(m, o, vmargs, ap);
2995 /* call the Java method */
2997 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2999 /* release dump area */
3001 dump_release(dumpsize);
3007 /* vm_call_method_double_jvalue ************************************************
3009 Calls a Java method with a variable number of arguments, passed via
3010 a jvalue array, and returns a double.
3012 *******************************************************************************/
3014 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
3022 /* mark start of dump memory area */
3024 dumpsize = dump_size();
3026 /* get number of Java method arguments */
3028 vmargscount = m->parseddesc->paramcount;
3030 /* allocate vm_arg array */
3032 vmargs = DMNEW(vm_arg, vmargscount);
3034 /* fill the vm_arg array from a va_list */
3036 vm_vmargs_from_jvalue(m, o, vmargs, args);
3038 /* call the Java method */
3040 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
3042 /* release dump area */
3044 dump_release(dumpsize);
3050 /* vm_call_method_double_vmarg *************************************************
3052 Calls a Java method with a variable number of arguments and returns
3055 *******************************************************************************/
3057 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
3062 #if defined(ENABLE_JIT)
3063 # if defined(ENABLE_INTRP)
3065 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3068 d = asm_vm_call_method_double(m, vmargscount, vmargs);
3070 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3078 * These are local overrides for various environment variables in Emacs.
3079 * Please do not remove this and leave it at the end of the file, where
3080 * Emacs will automagically detect them.
3081 * ---------------------------------------------------------------------
3084 * indent-tabs-mode: t