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 */
259 opt_struct opts[] = {
260 { "foo", false, OPT_FOO },
264 { "jar", false, OPT_JAR },
266 { "d32", false, OPT_D32 },
267 { "d64", false, OPT_D64 },
268 { "client", false, OPT_IGNORE },
269 { "server", false, OPT_IGNORE },
270 { "jvm", false, OPT_IGNORE },
271 { "hotspot", false, OPT_IGNORE },
273 { "classpath", true, OPT_CLASSPATH },
274 { "cp", true, OPT_CLASSPATH },
275 { "D", true, OPT_D },
276 { "version", false, OPT_VERSION },
277 { "showversion", false, OPT_SHOWVERSION },
278 { "fullversion", false, OPT_FULLVERSION },
279 { "help", false, OPT_HELP },
280 { "?", false, OPT_HELP },
281 { "X", false, OPT_X },
282 { "XX", false, OPT_XX },
284 { "esa", false, OPT_ESA },
285 { "enablesystemassertions", false, OPT_ESA },
286 { "dsa", false, OPT_DSA },
287 { "disablesystemassertions", false, OPT_DSA },
289 { "noasyncgc", false, OPT_IGNORE },
290 #if defined(ENABLE_VERIFIER)
291 { "noverify", false, OPT_NOVERIFY },
293 { "v", false, OPT_VERBOSE1 },
294 { "verbose:", true, OPT_VERBOSE },
296 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
297 { "verbosetc", false, OPT_VERBOSETC },
299 #if defined(__ALPHA__)
300 { "noieee", false, OPT_NOIEEE },
302 #if defined(ENABLE_STATISTICS)
303 { "time", false, OPT_TIME },
304 { "stat", false, OPT_STAT },
306 { "log", true, OPT_LOG },
307 { "c", true, OPT_CHECK },
308 { "l", false, OPT_LOAD },
309 { "eager", false, OPT_EAGER },
312 { "all", false, OPT_ALL },
313 { "sig", true, OPT_SIGNATURE },
316 #if defined(ENABLE_LOOP)
317 { "oloop", false, OPT_OLOOP },
319 #if defined(ENABLE_IFCONV)
320 { "ifconv", false, OPT_IFCONV },
322 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
323 { "lsra", false, OPT_LSRA },
326 #if defined(ENABLE_INTRP)
327 /* interpreter options */
329 { "trace", false, OPT_TRACE },
330 { "static-supers", true, OPT_STATIC_SUPERS },
331 { "no-dynamic", false, OPT_NO_DYNAMIC },
332 { "no-replication", false, OPT_NO_REPLICATION },
333 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
336 /* JVMTI Agent Command Line Options */
338 { "agentlib:", true, OPT_AGENTLIB },
339 { "agentpath:", true, OPT_AGENTPATH },
342 /* Java non-standard options */
344 { "Xjit", false, OPT_JIT },
345 { "Xint", false, OPT_INTRP },
346 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
347 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
348 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
349 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
352 { "Xdebug", false, OPT_DEBUG },
353 { "Xnoagent", false, OPT_NOAGENT },
354 { "Xrunjdwp", true, OPT_XRUNJDWP },
357 { "Xms", true, OPT_MS },
358 { "ms", true, OPT_MS },
359 { "Xmx", true, OPT_MX },
360 { "mx", true, OPT_MX },
361 { "Xss", true, OPT_SS },
362 { "ss", true, OPT_SS },
364 #if defined(ENABLE_PROFILING)
365 { "Xprof:", true, OPT_PROF_OPTION },
366 { "Xprof", false, OPT_PROF },
369 /* inlining options */
371 #if defined(ENABLE_INLINING)
372 #if defined(ENABLE_INLINING_DEBUG)
373 { "ia", false, OPT_INLINE_DEBUG_ALL },
374 { "ii", true, OPT_INLINE_DEBUG_MIN },
375 { "im", true, OPT_INLINE_DEBUG_MAX },
376 { "ie", true, OPT_INLINE_DEBUG_END },
377 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
378 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
379 #endif /* defined(ENABLE_INLINING_DEBUG) */
381 { "il", false, OPT_INLINE_LOG },
383 { "i", false, OPT_INLINING },
384 #endif /* defined(ENABLE_INLINING) */
386 /* keep these at the end of the list */
389 { "m", true, OPT_METHOD },
392 { "s", true, OPT_SHOW },
393 { "debug-color", false, OPT_DEBUGCOLOR },
399 /* usage ***********************************************************************
401 Prints the correct usage syntax to stdout.
403 *******************************************************************************/
407 puts("Usage: cacao [-options] classname [arguments]");
408 puts(" (to run a class file)");
409 puts(" or cacao [-options] -jar jarfile [arguments]");
410 puts(" (to run a standalone jar file)\n");
412 puts("where options include:");
413 puts(" -d32 use 32-bit data model if available");
414 puts(" -d64 use 64-bit data model if available");
415 puts(" -client compatibility (currently ignored)");
416 puts(" -server compatibility (currently ignored)");
417 puts(" -jvm compatibility (currently ignored)");
418 puts(" -hotspot compatibility (currently ignored)\n");
420 puts(" -cp <path> specify a path to look for classes");
421 puts(" -classpath <path> specify a path to look for classes");
422 puts(" -D<name>=<value> add an entry to the property list");
423 puts(" -verbose[:class|gc|jni] enable specific verbose output");
424 puts(" -version print product version and exit");
425 puts(" -fullversion print jpackage-compatible product version and exit");
426 puts(" -showversion print product version and continue");
427 puts(" -help, -? print this help message");
428 puts(" -X print help on non-standard Java options");
429 puts(" -XX print help on CACAO options");
430 puts(" -esa | -enablesystemassertions");
431 puts(" enable system assertions");
432 puts(" -dsa | -disablesystemassertions");
433 puts(" disable system assertions");
436 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
437 puts (" for jdwp help use: -agentlib:jdwp=help");
438 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
441 /* exit with error code */
447 static void Xusage(void)
449 #if defined(ENABLE_JIT)
450 puts(" -Xjit JIT mode execution (default)");
452 #if defined(ENABLE_INTRP)
453 puts(" -Xint interpreter mode execution");
455 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
456 puts(" value is set as bootstrap class path");
457 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
458 puts(" value is appended to the bootstrap class path");
459 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
460 puts(" value is prepended to the bootstrap class path");
461 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
462 puts(" value is used as Java core library, but the");
463 puts(" hardcoded VM interface classes are prepended");
464 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
465 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
466 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
468 #if defined(ENABLE_PROFILING)
469 puts(" -Xprof[:bb] collect and print profiling data");
472 #if defined(ENABLE_JVMTI)
473 /* -Xdebug option depend on gnu classpath JDWP options. options:
474 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
475 puts(" -Xdebug enable remote debugging\n");
476 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
477 puts(" enable remote debugging\n");
480 /* exit with error code */
486 static void XXusage(void)
488 puts(" -v write state-information");
490 puts(" -verbose[:call|exception|jit|memory|threads]");
491 puts(" enable specific verbose output");
492 puts(" -debug-color colored output for ANSI terms");
494 #ifdef TYPECHECK_VERBOSE
495 puts(" -verbosetc write debug messages while typechecking");
497 #if defined(__ALPHA__)
498 puts(" -noieee don't use ieee compliant arithmetic");
500 #if defined(ENABLE_VERIFIER)
501 puts(" -noverify don't verify classfiles");
503 #if defined(ENABLE_STATISTICS)
504 puts(" -time measure the runtime");
505 puts(" -stat detailed compiler statistics");
507 puts(" -log logfile specify a name for the logfile");
508 puts(" -c(heck)b(ounds) don't check array bounds");
509 puts(" s(ync) don't check for synchronization");
510 #if defined(ENABLE_LOOP)
511 puts(" -oloop optimize array accesses in loops");
513 puts(" -l don't start the class after loading");
514 puts(" -eager perform eager class loading and linking");
516 puts(" -all compile all methods, no execution");
517 puts(" -m compile only a specific method");
518 puts(" -sig specify signature for a specific method");
521 puts(" -s... show...");
522 puts(" (c)onstants the constant pool");
523 puts(" (m)ethods class fields and methods");
524 puts(" (u)tf the utf - hash");
525 puts(" (i)ntermediate intermediate representation");
526 #if defined(ENABLE_DISASSEMBLER)
527 puts(" (a)ssembler disassembled listing");
528 puts(" n(o)ps show NOPs in disassembler output");
529 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
530 puts(" (n)ative disassembled native stubs");
532 puts(" (d)atasegment data segment listing");
534 #if defined(ENABLE_INLINING)
535 puts(" -i activate inlining");
537 puts(" -il log inlining");
539 #if defined(ENABLE_INLINING_DEBUG)
540 puts(" -ia use inlining for all methods");
541 puts(" -ii <size> set minimum size for inlined result");
542 puts(" -im <size> set maximum size for inlined result");
543 puts(" -ie <number> stop inlining after the given number of roots");
544 puts(" -ir log on-stack replacement");
545 puts(" -iR log on-stack replacement, more verbose");
546 #endif /* defined(ENABLE_INLINING_DEBUG) */
547 #endif /* defined(ENABLE_INLINING) */
549 #if defined(ENABLE_IFCONV)
550 puts(" -ifconv use if-conversion");
552 #if defined(ENABLE_LSRA)
553 puts(" -lsra use linear scan register allocation");
555 #if defined(ENABLE_SSA)
556 puts(" -lsra use linear scan register allocation (with SSA)");
559 /* exit with error code */
565 /* version *********************************************************************
567 Only prints cacao version information.
569 *******************************************************************************/
571 static void version(bool opt_exit)
573 puts("java version \""JAVA_VERSION"\"");
574 puts("CACAO version "VERSION"");
576 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
577 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
578 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
579 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
581 puts("This program is free software; you can redistribute it and/or");
582 puts("modify it under the terms of the GNU General Public License as");
583 puts("published by the Free Software Foundation; either version 2, or (at");
584 puts("your option) any later version.\n");
586 puts("This program is distributed in the hope that it will be useful, but");
587 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
588 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
589 puts("General Public License for more details.\n");
591 puts("Configure/Build options:\n");
592 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
593 #if defined(__VERSION__)
594 puts(" CC : "VERSION_CC" ("__VERSION__")");
596 puts(" CC : "VERSION_CC"");
598 puts(" CFLAGS : "VERSION_CFLAGS"\n");
600 puts("Default variables:\n");
601 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
602 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
603 printf(" stack size : %d\n", STACK_SIZE);
604 #if defined(WITH_CLASSPATH_GNU)
605 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
607 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
609 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
611 puts("Runtime variables:\n");
612 printf(" maximum heap size : %d\n", opt_heapmaxsize);
613 printf(" initial heap size : %d\n", opt_heapstartsize);
614 printf(" stack size : %d\n", opt_stacksize);
615 printf(" libjvm.so : %s\n", cacao_libjvm);
616 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
617 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
618 printf(" java.class.path : %s\n", _Jv_classpath);
620 /* exit normally, if requested */
627 /* fullversion *****************************************************************
629 Prints a Sun compatible version information (required e.g. by
630 jpackage, www.jpackage.org).
632 *******************************************************************************/
634 static void fullversion(void)
636 puts("java full version \"cacao-"JAVA_VERSION"\"");
644 /* forward declarations *******************************************************/
646 static char *vm_get_mainclass_from_jar(char *mainstring);
648 static void vm_compile_all(void);
649 static void vm_compile_method(void);
653 /* vm_createjvm ****************************************************************
655 Implementation for JNI_CreateJavaVM.
657 *******************************************************************************/
659 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
661 JavaVMInitArgs *_vm_args;
665 /* get the arguments for the new JVM */
667 _vm_args = (JavaVMInitArgs *) vm_args;
669 /* get the VM and Env tables (must be set before vm_create) */
671 env = NEW(_Jv_JNIEnv);
673 #if defined(ENABLE_JNI)
674 env->env = &_Jv_JNINativeInterface;
677 /* XXX Set the global variable. Maybe we should do that differently. */
681 /* create and fill a JavaVM structure */
683 vm = NEW(_Jv_JavaVM);
685 #if defined(ENABLE_JNI)
686 vm->functions = &_Jv_JNIInvokeInterface;
689 /* XXX Set the global variable. Maybe we should do that differently. */
690 /* XXX JVMTI Agents needs a JavaVM */
694 /* actually create the JVM */
696 if (!vm_create(_vm_args))
699 #if defined(ENABLE_JNI)
700 /* setup the local ref table (must be created after vm_create) */
702 if (!jni_init_localref_table())
706 /* now return the values */
708 *p_vm = (JavaVM *) vm;
709 *p_env = (void *) env;
714 /* release allocated memory */
716 FREE(env, _Jv_JNIEnv);
717 FREE(vm, _Jv_JavaVM);
723 /* vm_create *******************************************************************
725 Creates a JVM. Called by vm_createjvm.
727 *******************************************************************************/
729 bool vm_create(JavaVMInitArgs *vm_args)
738 #if defined(ENABLE_JVMTI)
740 char *libname, *agentarg;
741 bool jdwp,agentbypath;
742 jdwp = agentbypath = false;
745 #if defined(ENABLE_VMLOG)
746 vmlog_cacao_init(vm_args);
749 /* check the JNI version requested */
751 switch (vm_args->version) {
752 case JNI_VERSION_1_1:
754 case JNI_VERSION_1_2:
755 case JNI_VERSION_1_4:
761 /* we only support 1 JVM instance */
766 if (atexit(vm_exit_handler))
767 vm_abort("atexit failed: %s\n", strerror(errno));
770 log_text("CACAO started -------------------------------------------------------");
772 /* We need to check if the actual size of a java.lang.Class object
773 is smaller or equal than the assumption made in
774 src/vmcore/class.h. */
776 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
777 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
779 /* set the VM starttime */
781 _Jv_jvm->starttime = builtin_currenttimemillis();
783 /* get stuff from the environment *****************************************/
785 #if defined(WITH_JRE_LAYOUT)
786 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
788 cacao_prefix = MNEW(char, 4096);
790 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
791 vm_abort("readlink failed: %s\n", strerror(errno));
793 /* get the path of the current executable */
795 cacao_prefix = dirname(cacao_prefix);
797 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
798 vm_abort("libjvm name to long for buffer\n");
800 /* concatenate the library name */
802 strcat(cacao_prefix, "/..");
804 /* now set path to libjvm.so */
806 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
808 cacao_libjvm = MNEW(char, len);
809 strcpy(cacao_libjvm, cacao_prefix);
810 strcat(cacao_libjvm, "/lib/libjvm");
812 /* and finally set the path to GNU Classpath libraries */
814 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
816 classpath_libdir = MNEW(char, len);
817 strcpy(classpath_libdir, cacao_prefix);
818 strcat(classpath_libdir, "/lib/classpath");
820 cacao_prefix = CACAO_PREFIX;
821 cacao_libjvm = CACAO_LIBDIR"/libjvm";
822 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
825 /* set the bootclasspath */
827 cp = getenv("BOOTCLASSPATH");
830 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
831 strcpy(_Jv_bootclasspath, cp);
834 #if defined(WITH_JRE_LAYOUT)
836 # if defined(WITH_CLASSPATH_GNU)
837 strlen(cacao_prefix) +
838 strlen("/share/cacao/vm.zip") +
841 strlen(cacao_prefix) +
842 strlen("/share/classpath/glibj.zip") +
845 _Jv_bootclasspath = MNEW(char, len);
846 # if defined(WITH_CLASSPATH_GNU)
847 strcat(_Jv_bootclasspath, cacao_prefix);
848 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
849 strcat(_Jv_bootclasspath, ":");
851 strcat(_Jv_bootclasspath, cacao_prefix);
852 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
855 # if defined(WITH_CLASSPATH_GNU)
856 strlen(CACAO_VM_ZIP) +
859 strlen(CLASSPATH_CLASSES) +
862 _Jv_bootclasspath = MNEW(char, len);
863 # if defined(WITH_CLASSPATH_GNU)
864 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
865 strcat(_Jv_bootclasspath, ":");
867 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
871 /* set the classpath */
873 cp = getenv("CLASSPATH");
876 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
877 strcat(_Jv_classpath, cp);
880 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
881 strcpy(_Jv_classpath, ".");
884 /* get and set java.library.path */
886 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
888 if (_Jv_java_library_path == NULL)
889 _Jv_java_library_path = "";
891 /* interpret the options **************************************************/
898 opt_heapmaxsize = HEAP_MAXSIZE;
899 opt_heapstartsize = HEAP_STARTSIZE;
900 opt_stacksize = STACK_SIZE;
903 #if defined(ENABLE_JVMTI)
904 /* initialize JVMTI related **********************************************/
908 /* initialize and fill properties before command-line handling */
910 if (!properties_init())
911 vm_abort("properties_init failed");
913 /* iterate over all passed options */
915 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
929 #if SIZEOF_VOID_P == 8
930 puts("Running a 32-bit JVM is not supported on this platform.");
936 #if SIZEOF_VOID_P == 4
937 puts("Running a 64-bit JVM is not supported on this platform.");
943 /* forget old classpath and set the argument as new classpath */
944 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
946 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
947 strcpy(_Jv_classpath, opt_arg);
951 for (i = 0; i < strlen(opt_arg); i++) {
952 if (opt_arg[i] == '=') {
954 properties_add(opt_arg, opt_arg + i + 1);
959 /* if no '=' is given, just create an empty property */
961 properties_add(opt_arg, "");
966 case OPT_BOOTCLASSPATH:
967 /* Forget default bootclasspath and set the argument as
968 new boot classpath. */
970 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
972 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
973 strcpy(_Jv_bootclasspath, opt_arg);
976 case OPT_BOOTCLASSPATH_A:
977 /* append to end of bootclasspath */
979 len = strlen(_Jv_bootclasspath);
981 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
985 strlen(opt_arg) + strlen("0"));
987 strcat(_Jv_bootclasspath, ":");
988 strcat(_Jv_bootclasspath, opt_arg);
991 case OPT_BOOTCLASSPATH_P:
992 /* prepend in front of bootclasspath */
994 cp = _Jv_bootclasspath;
997 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1000 strcpy(_Jv_bootclasspath, opt_arg);
1001 strcat(_Jv_bootclasspath, ":");
1002 strcat(_Jv_bootclasspath, cp);
1004 MFREE(cp, char, len);
1007 case OPT_BOOTCLASSPATH_C:
1008 /* use as Java core library, but prepend VM interface classes */
1010 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1012 len = strlen(CACAO_VM_ZIP) +
1017 _Jv_bootclasspath = MNEW(char, len);
1019 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1020 strcat(_Jv_bootclasspath, ":");
1021 strcat(_Jv_bootclasspath, opt_arg);
1024 #if defined(ENABLE_JVMTI)
1026 /* this option exists only for compatibility reasons */
1030 /* I don't know yet what Xnoagent should do. This is only for
1031 compatiblity with eclipse - motse */
1040 strlen(CACAO_LIBDIR) +
1041 strlen("/libjdwp.so=") +
1045 agentarg = MNEW(char, len);
1047 strcpy(agentarg, CACAO_LIBDIR);
1048 strcat(agentarg, "/libjdwp.so=");
1049 strcat(agentarg, &opt_arg[1]);
1066 c = opt_arg[strlen(opt_arg) - 1];
1068 if ((c == 'k') || (c == 'K')) {
1069 j = atoi(opt_arg) * 1024;
1071 } else if ((c == 'm') || (c == 'M')) {
1072 j = atoi(opt_arg) * 1024 * 1024;
1078 opt_heapmaxsize = j;
1079 else if (opt == OPT_MS)
1080 opt_heapstartsize = j;
1091 if (strcmp("class", opt_arg) == 0) {
1092 opt_verboseclass = true;
1094 else if (strcmp("gc", opt_arg) == 0) {
1095 opt_verbosegc = true;
1097 else if (strcmp("jni", opt_arg) == 0) {
1098 opt_verbosejni = true;
1100 #if !defined(NDEBUG)
1101 else if (strcmp("call", opt_arg) == 0) {
1102 opt_verbosecall = true;
1104 else if (strcmp("exception", opt_arg) == 0) {
1105 opt_verboseexception = true;
1107 else if (strcmp("jit", opt_arg) == 0) {
1112 compileverbose = true;
1114 else if (strcmp("memory", opt_arg) == 0) {
1115 opt_verbosememory = true;
1117 # if defined(ENABLE_STATISTICS)
1118 /* we also need statistics */
1123 else if (strcmp("threads", opt_arg) == 0) {
1124 opt_verbosethreads = true;
1128 printf("Unknown -verbose option: %s\n", opt_arg);
1133 case OPT_DEBUGCOLOR:
1134 opt_debugcolor = true;
1137 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1139 opt_typecheckverbose = true;
1148 case OPT_FULLVERSION:
1152 case OPT_SHOWVERSION:
1160 #if defined(ENABLE_VERIFIER)
1166 #if defined(ENABLE_STATISTICS)
1168 opt_getcompilingtime = true;
1169 opt_getloadingtime = true;
1182 for (i = 0; i < strlen(opt_arg); i++) {
1183 switch (opt_arg[i]) {
1185 checkbounds = false;
1198 makeinitializations = false;
1205 #if !defined(NDEBUG)
1209 makeinitializations = false;
1214 opt_method = opt_arg;
1215 makeinitializations = false;
1219 opt_signature = opt_arg;
1223 case OPT_SHOW: /* Display options */
1224 for (i = 0; i < strlen(opt_arg); i++) {
1225 switch (opt_arg[i]) {
1227 showconstantpool = true;
1239 opt_showintermediate = true;
1240 compileverbose = true;
1243 #if defined(ENABLE_DISASSEMBLER)
1245 opt_showdisassemble = true;
1246 compileverbose = true;
1250 opt_shownops = true;
1254 opt_showexceptionstubs = true;
1258 opt_shownativestub = true;
1263 opt_showddatasegment = true;
1272 #if defined(ENABLE_LOOP)
1278 #if defined(ENABLE_INLINING)
1279 #if defined(ENABLE_INLINING_DEBUG)
1280 case OPT_INLINE_DEBUG_ALL:
1281 opt_inline_debug_all = true;
1283 case OPT_INLINE_DEBUG_END:
1284 opt_inline_debug_end_counter = atoi(opt_arg);
1286 case OPT_INLINE_DEBUG_MIN:
1287 opt_inline_debug_min_size = atoi(opt_arg);
1289 case OPT_INLINE_DEBUG_MAX:
1290 opt_inline_debug_max_size = atoi(opt_arg);
1292 case OPT_INLINE_REPLACE_VERBOSE:
1293 opt_replace_verbose = 1;
1295 case OPT_INLINE_REPLACE_VERBOSE2:
1296 opt_replace_verbose = 2;
1298 #endif /* defined(ENABLE_INLINING_DEBUG) */
1299 #if !defined(NDEBUG)
1300 case OPT_INLINE_LOG:
1301 opt_inline_debug_log = true;
1303 #endif /* !defined(NDEBUG) */
1306 opt_inlining = true;
1308 #endif /* defined(ENABLE_INLINING) */
1310 #if defined(ENABLE_IFCONV)
1316 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1335 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1339 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1342 #if defined(ENABLE_PROFILING)
1343 case OPT_PROF_OPTION:
1344 /* use <= to get the last \0 too */
1346 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1347 if (opt_arg[i] == ',')
1350 if (opt_arg[i] == '\0') {
1351 if (strcmp("bb", opt_arg + j) == 0)
1355 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1359 /* set k to next char */
1372 #if defined(ENABLE_JIT)
1375 printf("-Xjit option not enabled.\n");
1381 #if defined(ENABLE_INTRP)
1384 printf("-Xint option not enabled.\n");
1389 #if defined(ENABLE_INTRP)
1390 case OPT_STATIC_SUPERS:
1391 opt_static_supers = atoi(opt_arg);
1394 case OPT_NO_DYNAMIC:
1395 opt_no_dynamic = true;
1398 case OPT_NO_REPLICATION:
1399 opt_no_replication = true;
1402 case OPT_NO_QUICKSUPER:
1403 opt_no_quicksuper = true;
1412 printf("Unknown option: %s\n",
1413 vm_args->options[opt_index].optionString);
1418 /* get the main class *****************************************************/
1420 if (opt_index < vm_args->nOptions) {
1421 mainstring = vm_args->options[opt_index++].optionString;
1423 /* Put the jar file into the classpath (if any). */
1425 if (opt_jar == true) {
1426 /* free old classpath */
1428 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1430 /* put jarfile into classpath */
1432 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1434 strcpy(_Jv_classpath, mainstring);
1437 /* replace .'s with /'s in classname */
1439 for (i = strlen(mainstring) - 1; i >= 0; i--)
1440 if (mainstring[i] == '.')
1441 mainstring[i] = '/';
1445 #if defined(ENABLE_JVMTI)
1447 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1448 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1451 MFREE(agentarg, char, strlen(agentarg));
1453 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1457 /* initialize this JVM ****************************************************/
1459 vm_initializing = true;
1461 #if defined(ENABLE_THREADS)
1462 /* pre-initialize some core thread stuff, like the stopworldlock,
1463 thus this has to happen _before_ gc_init()!!! */
1468 /* initialize the garbage collector */
1470 gc_init(opt_heapmaxsize, opt_heapstartsize);
1472 #if defined(ENABLE_INTRP)
1473 /* Allocate main thread stack on the Java heap. */
1476 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1477 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1481 /* AFTER: threads_preinit */
1484 vm_abort("vm_create: string_init failed");
1486 /* AFTER: threads_preinit */
1489 vm_abort("vm_create: utf8_init failed");
1491 /* AFTER: thread_preinit */
1494 vm_abort("vm_create: suck_init failed");
1496 suck_add_from_property("java.endorsed.dirs");
1498 /* Now we have all options handled and we can print the version
1501 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1506 /* AFTER: utf8_init */
1508 suck_add(_Jv_bootclasspath);
1510 /* Now re-set some of the properties that may have changed. This
1511 must be done after _all_ environment variables have been
1512 processes (e.g. -jar handling).
1514 AFTER: suck_add_from_property, since it may change the
1515 _Jv_bootclasspath pointer. */
1517 if (!properties_postinit())
1518 vm_abort("vm_create: properties_postinit failed");
1520 /* initialize the classcache hashtable stuff: lock, hashtable
1521 (must be done _after_ threads_preinit) */
1523 if (!classcache_init())
1524 vm_abort("vm_create: classcache_init failed");
1526 /* initialize the memory subsystem (must be done _after_
1530 vm_abort("vm_create: memory_init failed");
1532 /* initialize the finalizer stuff (must be done _after_
1535 if (!finalizer_init())
1536 vm_abort("vm_create: finalizer_init failed");
1538 /* install architecture dependent signal handlers */
1542 /* initialize the codegen subsystems */
1546 /* initializes jit compiler */
1550 /* machine dependent initialization */
1552 #if defined(ENABLE_JIT)
1553 # if defined(ENABLE_INTRP)
1563 /* initialize the loader subsystems (must be done _after_
1567 vm_abort("vm_create: loader_init failed");
1570 vm_abort("vm_create: linker_init failed");
1573 vm_abort("vm_create: native_init failed");
1575 if (!exceptions_init())
1576 vm_abort("vm_create: exceptions_init failed");
1578 if (!builtin_init())
1579 vm_abort("vm_create: builtin_init failed");
1581 #if defined(ENABLE_JNI)
1582 /* Initialize the JNI subsystem (must be done _before_
1583 threads_init, as threads_init can call JNI methods
1584 (e.g. NewGlobalRef). */
1587 vm_abort("vm_create: jni_init failed");
1590 #if defined(ENABLE_THREADS)
1591 if (!threads_init())
1592 vm_abort("vm_create: threads_init failed");
1595 #if defined(ENABLE_PROFILING)
1596 /* initialize profiling */
1598 if (!profile_init())
1599 vm_abort("vm_create: profile_init failed");
1602 #if defined(ENABLE_THREADS)
1603 /* initialize recompilation */
1605 if (!recompile_init())
1606 vm_abort("vm_create: recompile_init failed");
1608 /* start the signal handler thread */
1610 if (!signal_start_thread())
1611 vm_abort("vm_create: signal_start_thread failed");
1613 /* finally, start the finalizer thread */
1615 if (!finalizer_start_thread())
1616 vm_abort("vm_create: finalizer_start_thread failed");
1618 # if !defined(NDEBUG)
1619 /* start the memory profiling thread */
1621 if (opt_verbosememory)
1622 if (!memory_start_thread())
1623 vm_abort("vm_create: memory_start_thread failed");
1626 /* start the recompilation thread (must be done before the
1627 profiling thread) */
1629 if (!recompile_start_thread())
1630 vm_abort("vm_create: recompile_start_thread failed");
1632 # if defined(ENABLE_PROFILING)
1633 /* start the profile sampling thread */
1636 /* if (!profile_start_thread()) */
1637 /* exceptions_print_stacktrace(); */
1641 #if defined(ENABLE_JVMTI)
1642 # if defined(ENABLE_GC_CACAO)
1643 /* XXX this will not work with the new indirection cells for classloaders!!! */
1647 /* add agent library to native library hashtable */
1648 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1652 /* increment the number of VMs */
1656 /* initialization is done */
1658 vm_initializing = false;
1660 /* everything's ok */
1666 /* vm_run **********************************************************************
1668 Runs the main-method of the passed class.
1670 *******************************************************************************/
1672 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1675 classinfo *mainclass;
1677 java_objectarray *oa;
1680 java_objectheader *s;
1684 #if !defined(NDEBUG)
1690 if (opt_method != NULL) {
1691 vm_compile_method();
1694 #endif /* !defined(NDEBUG) */
1696 /* should we run the main-method? */
1698 if (mainstring == NULL)
1701 /* set return value to OK */
1705 if (opt_jar == true) {
1706 /* open jar file with java.util.jar.JarFile */
1708 mainstring = vm_get_mainclass_from_jar(mainstring);
1710 if (mainstring == NULL)
1714 /* load the main class */
1716 mainutf = utf_new_char(mainstring);
1718 #if defined(ENABLE_JAVAME_CLDC1_1)
1719 mainclass = load_class_bootstrap(mainutf);
1721 mainclass = load_class_from_sysloader(mainutf);
1724 /* error loading class */
1726 if ((exceptions_get_exception() != NULL) || (mainclass == NULL)) {
1727 exceptions_print_stacktrace();
1731 if (!link_class(mainclass)) {
1732 exceptions_print_stacktrace();
1736 /* find the `main' method of the main class */
1738 m = class_resolveclassmethod(mainclass,
1739 utf_new_char("main"),
1740 utf_new_char("([Ljava/lang/String;)V"),
1741 class_java_lang_Object,
1744 if (exceptions_get_exception()) {
1745 exceptions_print_stacktrace();
1749 /* there is no main method or it isn't static */
1751 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1752 exceptions_clear_exception();
1753 exceptions_throw_nosuchmethoderror(mainclass,
1754 utf_new_char("main"),
1755 utf_new_char("([Ljava/lang/String;)V"));
1757 exceptions_print_stacktrace();
1761 /* build argument array */
1763 oalength = vm_args->nOptions - opt_index;
1765 oa = builtin_anewarray(oalength, class_java_lang_String);
1767 for (i = 0; i < oalength; i++) {
1768 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1769 s = javastring_new(u);
1774 #ifdef TYPEINFO_DEBUG_TEST
1775 /* test the typeinfo system */
1778 /*class_showmethods(currentThread->group->header.vftbl->class); */
1780 #if defined(ENABLE_JVMTI)
1781 jvmti_set_phase(JVMTI_PHASE_LIVE);
1784 /* set ThreadMXBean variables */
1786 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1787 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1789 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1790 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1791 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1792 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1794 /* start the main thread */
1796 (void) vm_call_method(m, NULL, oa);
1798 /* exception occurred? */
1800 if (exceptions_get_exception()) {
1801 exceptions_print_stacktrace();
1805 /* unload the JavaVM */
1807 (void) vm_destroy(vm);
1815 /* vm_destroy ******************************************************************
1817 Unloads a Java VM and reclaims its resources.
1819 *******************************************************************************/
1821 s4 vm_destroy(JavaVM *vm)
1823 #if defined(ENABLE_THREADS)
1824 threads_join_all_threads();
1827 /* everything's ok */
1833 /* vm_exit *********************************************************************
1835 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1837 *******************************************************************************/
1839 void vm_exit(s4 status)
1843 /* signal that we are exiting */
1847 assert(class_java_lang_System);
1848 assert(class_java_lang_System->state & CLASS_LOADED);
1850 #if defined(ENABLE_JVMTI)
1851 if (jvmti || (dbgcom!=NULL)) {
1852 jvmti_set_phase(JVMTI_PHASE_DEAD);
1853 if (jvmti) jvmti_agentunload();
1857 if (!link_class(class_java_lang_System)) {
1858 exceptions_print_stacktrace();
1862 /* call java.lang.System.exit(I)V */
1864 m = class_resolveclassmethod(class_java_lang_System,
1865 utf_new_char("exit"),
1867 class_java_lang_Object,
1871 exceptions_print_stacktrace();
1875 /* call the exit function with passed exit status */
1877 (void) vm_call_method(m, NULL, status);
1879 /* If we had an exception, just ignore the exception and exit with
1882 vm_shutdown(status);
1886 /* vm_shutdown *****************************************************************
1888 Terminates the system immediately without freeing memory explicitly
1889 (to be used only for abnormal termination).
1891 *******************************************************************************/
1893 void vm_shutdown(s4 status)
1896 #if defined(ENABLE_STATISTICS)
1897 || opt_getcompilingtime || opt_stat
1901 log_text("CACAO terminated by shutdown");
1902 dolog("Exit status: %d\n", (s4) status);
1906 #if defined(ENABLE_JVMTI)
1907 /* terminate cacaodbgserver */
1909 pthread_mutex_lock(&dbgcomlock);
1911 pthread_mutex_unlock(&dbgcomlock);
1912 jvmti_cacaodbgserver_quit();
1920 /* vm_exit_handler *************************************************************
1922 The exit_handler function is called upon program termination.
1924 ATTENTION: Don't free system resources here! Some threads may still
1925 be running as this is called from VMRuntime.exit(). The OS does the
1928 *******************************************************************************/
1930 void vm_exit_handler(void)
1932 #if !defined(NDEBUG)
1934 class_showmethods(mainclass);
1936 if (showconstantpool)
1937 class_showconstantpool(mainclass);
1942 # if defined(ENABLE_PROFILING)
1944 profile_printstats();
1946 #endif /* !defined(NDEBUG) */
1948 #if defined(ENABLE_RT_TIMING)
1949 rt_timing_print_time_stats(stderr);
1952 #if defined(ENABLE_CYCLES_STATS)
1953 builtin_print_cycles_stats(stderr);
1954 stacktrace_print_cycles_stats(stderr);
1958 #if defined(ENABLE_STATISTICS)
1959 || opt_getcompilingtime || opt_stat
1963 log_text("CACAO terminated");
1965 #if defined(ENABLE_STATISTICS)
1968 #ifdef TYPECHECK_STATISTICS
1969 typecheck_print_statistics(get_logfile());
1973 if (opt_getcompilingtime)
1975 #endif /* defined(ENABLE_STATISTICS) */
1977 /* vm_print_profile(stderr);*/
1981 /* vm_abort ********************************************************************
1983 Prints an error message and aborts the VM.
1985 *******************************************************************************/
1987 void vm_abort(const char *text, ...)
1991 /* print the log message */
1996 log_vprint(text, ap);
2001 /* now abort the VM */
2007 /* vm_get_mainclass_from_jar ***************************************************
2009 Gets the name of the main class from a JAR's manifest file.
2011 *******************************************************************************/
2013 static char *vm_get_mainclass_from_jar(char *mainstring)
2016 java_objectheader *o;
2018 java_objectheader *s;
2020 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2023 exceptions_print_stacktrace();
2027 /* create JarFile object */
2032 exceptions_print_stacktrace();
2036 m = class_resolveclassmethod(c,
2038 utf_java_lang_String__void,
2039 class_java_lang_Object,
2043 exceptions_print_stacktrace();
2047 s = javastring_new_from_ascii(mainstring);
2049 (void) vm_call_method(m, o, s);
2051 if (exceptions_get_exception()) {
2052 exceptions_print_stacktrace();
2056 /* get manifest object */
2058 m = class_resolveclassmethod(c,
2059 utf_new_char("getManifest"),
2060 utf_new_char("()Ljava/util/jar/Manifest;"),
2061 class_java_lang_Object,
2065 exceptions_print_stacktrace();
2069 o = vm_call_method(m, o);
2072 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2077 /* get Main Attributes */
2079 m = class_resolveclassmethod(o->vftbl->class,
2080 utf_new_char("getMainAttributes"),
2081 utf_new_char("()Ljava/util/jar/Attributes;"),
2082 class_java_lang_Object,
2086 exceptions_print_stacktrace();
2090 o = vm_call_method(m, o);
2093 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2098 /* get property Main-Class */
2100 m = class_resolveclassmethod(o->vftbl->class,
2101 utf_new_char("getValue"),
2102 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2103 class_java_lang_Object,
2107 exceptions_print_stacktrace();
2111 s = javastring_new_from_ascii("Main-Class");
2113 o = vm_call_method(m, o, s);
2116 exceptions_print_stacktrace();
2120 return javastring_tochar(o);
2124 /* vm_compile_all **************************************************************
2126 Compile all methods found in the bootclasspath.
2128 *******************************************************************************/
2130 #if !defined(NDEBUG)
2131 static void vm_compile_all(void)
2136 classcache_name_entry *nmen;
2137 classcache_class_entry *clsen;
2140 /* create all classes found in the bootclasspath */
2141 /* XXX currently only works with zip/jar's */
2143 loader_load_all_classes();
2145 /* link all classes */
2147 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2148 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2150 for (; nmen; nmen = nmen->hashlink) {
2151 /* iterate over all class entries */
2153 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2154 c = clsen->classobj;
2159 if (!(c->state & CLASS_LINKED)) {
2160 if (!link_class(c)) {
2161 fprintf(stderr, "Error linking: ");
2162 utf_fprint_printable_ascii_classname(stderr, c->name);
2163 fprintf(stderr, "\n");
2165 /* print out exception and cause */
2167 exceptions_print_current_exception();
2169 /* goto next class */
2175 /* compile all class methods */
2177 for (i = 0; i < c->methodscount; i++) {
2178 m = &(c->methods[i]);
2180 if (m->jcode != NULL) {
2181 if (!jit_compile(m)) {
2182 fprintf(stderr, "Error compiling: ");
2183 utf_fprint_printable_ascii_classname(stderr, c->name);
2184 fprintf(stderr, ".");
2185 utf_fprint_printable_ascii(stderr, m->name);
2186 utf_fprint_printable_ascii(stderr, m->descriptor);
2187 fprintf(stderr, "\n");
2189 /* print out exception and cause */
2191 exceptions_print_current_exception();
2199 #endif /* !defined(NDEBUG) */
2202 /* vm_compile_method ***********************************************************
2204 Compile a specific method.
2206 *******************************************************************************/
2208 #if !defined(NDEBUG)
2209 static void vm_compile_method(void)
2213 /* create, load and link the main class */
2215 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2217 if (mainclass == NULL)
2218 exceptions_print_stacktrace();
2220 if (!link_class(mainclass))
2221 exceptions_print_stacktrace();
2223 if (opt_signature != NULL) {
2224 m = class_resolveclassmethod(mainclass,
2225 utf_new_char(opt_method),
2226 utf_new_char(opt_signature),
2231 m = class_resolveclassmethod(mainclass,
2232 utf_new_char(opt_method),
2239 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2240 opt_method, opt_signature ? opt_signature : "");
2244 #endif /* !defined(NDEBUG) */
2247 /* vm_vmargs_from_valist *******************************************************
2251 *******************************************************************************/
2253 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2254 vm_arg *vmargs, va_list ap)
2256 typedesc *paramtypes;
2259 paramtypes = m->parseddesc->paramtypes;
2261 /* if method is non-static fill first block and skip `this' pointer */
2266 /* the `this' pointer */
2267 vmargs[0].type = TYPE_ADR;
2268 vmargs[0].data.l = (u8) (ptrint) o;
2274 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2275 switch (paramtypes->decltype) {
2276 /* primitive types */
2277 case PRIMITIVETYPE_BOOLEAN:
2278 case PRIMITIVETYPE_BYTE:
2279 case PRIMITIVETYPE_CHAR:
2280 case PRIMITIVETYPE_SHORT:
2281 case PRIMITIVETYPE_INT:
2282 vmargs[i].type = TYPE_INT;
2283 vmargs[i].data.l = (s8) va_arg(ap, s4);
2286 case PRIMITIVETYPE_LONG:
2287 vmargs[i].type = TYPE_LNG;
2288 vmargs[i].data.l = (s8) va_arg(ap, s8);
2291 case PRIMITIVETYPE_FLOAT:
2292 vmargs[i].type = TYPE_FLT;
2293 #if defined(__ALPHA__)
2294 /* this keeps the assembler function much simpler */
2296 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2298 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2302 case PRIMITIVETYPE_DOUBLE:
2303 vmargs[i].type = TYPE_DBL;
2304 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2308 vmargs[i].type = TYPE_ADR;
2309 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2316 /* vm_vmargs_from_jvalue *******************************************************
2320 *******************************************************************************/
2322 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2323 vm_arg *vmargs, jvalue *args)
2325 typedesc *paramtypes;
2329 paramtypes = m->parseddesc->paramtypes;
2331 /* if method is non-static fill first block and skip `this' pointer */
2336 /* the `this' pointer */
2337 vmargs[0].type = TYPE_ADR;
2338 vmargs[0].data.l = (u8) (ptrint) o;
2344 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2345 switch (paramtypes->decltype) {
2346 /* primitive types */
2347 case PRIMITIVETYPE_BOOLEAN:
2348 case PRIMITIVETYPE_BYTE:
2349 case PRIMITIVETYPE_CHAR:
2350 case PRIMITIVETYPE_SHORT:
2351 case PRIMITIVETYPE_INT:
2352 vmargs[i].type = TYPE_INT;
2353 vmargs[i].data.l = (s8) args[j].i;
2356 case PRIMITIVETYPE_LONG:
2357 vmargs[i].type = TYPE_LNG;
2358 vmargs[i].data.l = (s8) args[j].j;
2361 case PRIMITIVETYPE_FLOAT:
2362 vmargs[i].type = TYPE_FLT;
2363 #if defined(__ALPHA__)
2364 /* this keeps the assembler function much simpler */
2366 vmargs[i].data.d = (jdouble) args[j].f;
2368 vmargs[i].data.f = args[j].f;
2372 case PRIMITIVETYPE_DOUBLE:
2373 vmargs[i].type = TYPE_DBL;
2374 vmargs[i].data.d = args[j].d;
2378 vmargs[i].type = TYPE_ADR;
2379 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2386 /* vm_call_method **************************************************************
2388 Calls a Java method with a variable number of arguments and returns
2391 *******************************************************************************/
2393 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2396 java_objectheader *ro;
2399 ro = vm_call_method_valist(m, o, ap);
2406 /* vm_call_method_valist *******************************************************
2408 Calls a Java method with a variable number of arguments, passed via
2409 a va_list, and returns an address.
2411 *******************************************************************************/
2413 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2418 java_objectheader *ro;
2421 /* mark start of dump memory area */
2423 dumpsize = dump_size();
2425 /* get number of Java method arguments */
2427 vmargscount = m->parseddesc->paramcount;
2429 /* allocate vm_arg array */
2431 vmargs = DMNEW(vm_arg, vmargscount);
2433 /* fill the vm_arg array from a va_list */
2435 vm_vmargs_from_valist(m, o, vmargs, ap);
2437 /* call the Java method */
2439 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2441 /* release dump area */
2443 dump_release(dumpsize);
2449 /* vm_call_method_jvalue *******************************************************
2451 Calls a Java method with a variable number of arguments, passed via
2452 a jvalue array, and returns an address.
2454 *******************************************************************************/
2456 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2461 java_objectheader *ro;
2464 /* mark start of dump memory area */
2466 dumpsize = dump_size();
2468 /* get number of Java method arguments */
2470 vmargscount = m->parseddesc->paramcount;
2472 /* allocate vm_arg array */
2474 vmargs = DMNEW(vm_arg, vmargscount);
2476 /* fill the vm_arg array from a va_list */
2478 vm_vmargs_from_jvalue(m, o, vmargs, args);
2480 /* call the Java method */
2482 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2484 /* release dump area */
2486 dump_release(dumpsize);
2492 /* vm_call_method_vmarg ********************************************************
2494 Calls a Java method with a variable number of arguments, passed via
2495 a vm_arg array, and returns an address.
2497 *******************************************************************************/
2499 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2502 java_objectheader *o;
2504 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2505 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
2508 #if defined(ENABLE_JIT)
2509 # if defined(ENABLE_INTRP)
2511 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2514 o = asm_vm_call_method(m, vmargscount, vmargs);
2516 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2519 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2520 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
2527 /* vm_call_method_int **********************************************************
2529 Calls a Java method with a variable number of arguments and returns
2532 *******************************************************************************/
2534 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2540 i = vm_call_method_int_valist(m, o, ap);
2547 /* vm_call_method_int_valist ***************************************************
2549 Calls a Java method with a variable number of arguments, passed via
2550 a va_list, and returns an integer (s4).
2552 *******************************************************************************/
2554 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2561 /* mark start of dump memory area */
2563 dumpsize = dump_size();
2565 /* get number of Java method arguments */
2567 vmargscount = m->parseddesc->paramcount;
2569 /* allocate vm_arg array */
2571 vmargs = DMNEW(vm_arg, vmargscount);
2573 /* fill the vm_arg array from a va_list */
2575 vm_vmargs_from_valist(m, o, vmargs, ap);
2577 /* call the Java method */
2579 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2581 /* release dump area */
2583 dump_release(dumpsize);
2589 /* vm_call_method_int_jvalue ***************************************************
2591 Calls a Java method with a variable number of arguments, passed via
2592 a jvalue array, and returns an integer (s4).
2594 *******************************************************************************/
2596 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2603 /* mark start of dump memory area */
2605 dumpsize = dump_size();
2607 /* get number of Java method arguments */
2609 vmargscount = m->parseddesc->paramcount;
2611 /* allocate vm_arg array */
2613 vmargs = DMNEW(vm_arg, vmargscount);
2615 /* fill the vm_arg array from a va_list */
2617 vm_vmargs_from_jvalue(m, o, vmargs, args);
2619 /* call the Java method */
2621 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2623 /* release dump area */
2625 dump_release(dumpsize);
2631 /* vm_call_method_int_vmarg ****************************************************
2633 Calls a Java method with a variable number of arguments, passed via
2634 a vm_arg array, and returns an integer (s4).
2636 *******************************************************************************/
2638 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2642 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2643 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
2646 #if defined(ENABLE_JIT)
2647 # if defined(ENABLE_INTRP)
2649 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2652 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2654 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2657 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2658 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
2665 /* vm_call_method_long *********************************************************
2667 Calls a Java method with a variable number of arguments and returns
2670 *******************************************************************************/
2672 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2678 l = vm_call_method_long_valist(m, o, ap);
2685 /* vm_call_method_long_valist **************************************************
2687 Calls a Java method with a variable number of arguments, passed via
2688 a va_list, and returns a long (s8).
2690 *******************************************************************************/
2692 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2699 /* mark start of dump memory area */
2701 dumpsize = dump_size();
2703 /* get number of Java method arguments */
2705 vmargscount = m->parseddesc->paramcount;
2707 /* allocate vm_arg array */
2709 vmargs = DMNEW(vm_arg, vmargscount);
2711 /* fill the vm_arg array from a va_list */
2713 vm_vmargs_from_valist(m, o, vmargs, ap);
2715 /* call the Java method */
2717 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2719 /* release dump area */
2721 dump_release(dumpsize);
2727 /* vm_call_method_long_jvalue **************************************************
2729 Calls a Java method with a variable number of arguments, passed via
2730 a jvalue array, and returns a long (s8).
2732 *******************************************************************************/
2734 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2741 /* mark start of dump memory area */
2743 dumpsize = dump_size();
2745 /* get number of Java method arguments */
2747 vmargscount = m->parseddesc->paramcount;
2749 /* allocate vm_arg array */
2751 vmargs = DMNEW(vm_arg, vmargscount);
2753 /* fill the vm_arg array from a va_list */
2755 vm_vmargs_from_jvalue(m, o, vmargs, args);
2757 /* call the Java method */
2759 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2761 /* release dump area */
2763 dump_release(dumpsize);
2769 /* vm_call_method_long_vmarg ***************************************************
2771 Calls a Java method with a variable number of arguments, passed via
2772 a vm_arg array, and returns a long (s8).
2774 *******************************************************************************/
2776 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2780 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2781 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
2784 #if defined(ENABLE_JIT)
2785 # if defined(ENABLE_INTRP)
2787 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2790 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2792 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2795 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2796 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
2803 /* vm_call_method_float ********************************************************
2805 Calls a Java method with a variable number of arguments and returns
2808 *******************************************************************************/
2810 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2816 f = vm_call_method_float_valist(m, o, ap);
2823 /* vm_call_method_float_valist *************************************************
2825 Calls a Java method with a variable number of arguments, passed via
2826 a va_list, and returns a float.
2828 *******************************************************************************/
2830 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2838 /* mark start of dump memory area */
2840 dumpsize = dump_size();
2842 /* get number of Java method arguments */
2844 vmargscount = m->parseddesc->paramcount;
2846 /* allocate vm_arg array */
2848 vmargs = DMNEW(vm_arg, vmargscount);
2850 /* fill the vm_arg array from a va_list */
2852 vm_vmargs_from_valist(m, o, vmargs, ap);
2854 /* call the Java method */
2856 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2858 /* release dump area */
2860 dump_release(dumpsize);
2866 /* vm_call_method_float_jvalue *************************************************
2868 Calls a Java method with a variable number of arguments, passed via
2869 a jvalue array, and returns a float.
2871 *******************************************************************************/
2873 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2881 /* mark start of dump memory area */
2883 dumpsize = dump_size();
2885 /* get number of Java method arguments */
2887 vmargscount = m->parseddesc->paramcount;
2889 /* allocate vm_arg array */
2891 vmargs = DMNEW(vm_arg, vmargscount);
2893 /* fill the vm_arg array from a va_list */
2895 vm_vmargs_from_jvalue(m, o, vmargs, args);
2897 /* call the Java method */
2899 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2901 /* release dump area */
2903 dump_release(dumpsize);
2909 /* vm_call_method_float_vmarg **************************************************
2911 Calls a Java method with a variable number of arguments and returns
2914 *******************************************************************************/
2916 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2920 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2921 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
2924 #if defined(ENABLE_JIT)
2925 # if defined(ENABLE_INTRP)
2927 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2930 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2932 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2935 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2936 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
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 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3062 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
3065 #if defined(ENABLE_JIT)
3066 # if defined(ENABLE_INTRP)
3068 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3071 d = asm_vm_call_method_double(m, vmargscount, vmargs);
3073 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3076 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3077 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
3085 * These are local overrides for various environment variables in Emacs.
3086 * Please do not remove this and leave it at the end of the file, where
3087 * Emacs will automagically detect them.
3088 * ---------------------------------------------------------------------
3091 * indent-tabs-mode: t