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 #if defined(ENABLE_THREADS)
52 # include "threads/native/threads.h"
55 #include "toolbox/logging.h"
57 #include "vm/builtin.h"
58 #include "vm/exceptions.h"
59 #include "vm/finalizer.h"
60 #include "vm/global.h"
61 #include "vm/initialize.h"
62 #include "vm/properties.h"
63 #include "vm/signallocal.h"
64 #include "vm/stringlocal.h"
67 #include "vm/jit/jit.h"
68 #include "vm/jit/md.h"
69 #include "vm/jit/asmpart.h"
71 #if defined(ENABLE_PROFILING)
72 # include "vm/jit/optimizing/profile.h"
75 #include "vm/jit/optimizing/recompile.h"
77 #include "vmcore/classcache.h"
78 #include "vmcore/options.h"
79 #include "vmcore/suck.h"
81 #if defined(ENABLE_JVMTI)
82 # include "native/jvmti/cacaodbg.h"
85 #if defined(ENABLE_VMLOG)
86 #include <vmlog_cacao.h>
90 /* Invocation API variables ***************************************************/
92 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
93 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
96 /* global variables ***********************************************************/
98 s4 vms = 0; /* number of VMs created */
100 bool vm_initializing = false;
101 bool vm_exiting = false;
103 char *cacao_prefix = NULL;
104 char *cacao_libjvm = NULL;
105 char *classpath_libdir = NULL;
107 char *_Jv_bootclasspath; /* contains the boot classpath */
108 char *_Jv_classpath; /* contains the classpath */
109 char *_Jv_java_library_path;
111 char *mainstring = NULL;
112 classinfo *mainclass = NULL;
114 char *specificmethodname = NULL;
115 char *specificsignature = NULL;
119 #if defined(ENABLE_INTRP)
120 u1 *intrp_main_stack = NULL;
124 /* define heap sizes **********************************************************/
126 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
127 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
128 #define STACK_SIZE 64 * 1024 /* default 64kB */
131 /* define command line options ************************************************/
159 /* Java non-standard options */
170 #if defined(ENABLE_PROFILING)
183 #if defined(ENABLE_STATISTICS)
200 #if defined(ENABLE_VERIFIER)
202 #if defined(TYPECHECK_VERBOSE)
205 #endif /* defined(ENABLE_VERIFIER) */
208 /* optimization options */
210 #if defined(ENABLE_LOOP)
214 #if defined(ENABLE_IFCONV)
218 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
222 #if defined(ENABLE_INLINING)
227 #if defined(ENABLE_INLINING_DEBUG)
228 OPT_INLINE_DEBUG_ALL,
229 OPT_INLINE_DEBUG_END,
230 OPT_INLINE_DEBUG_MIN,
231 OPT_INLINE_DEBUG_MAX,
232 OPT_INLINE_REPLACE_VERBOSE,
233 OPT_INLINE_REPLACE_VERBOSE2,
234 #endif /* defined(ENABLE_INLINING_DEBUG) */
235 #endif /* defined(ENABLE_INLINING) */
237 #if defined(ENABLE_INTRP)
238 /* interpreter options */
261 opt_struct opts[] = {
262 { "foo", false, OPT_FOO },
266 { "jar", false, OPT_JAR },
268 { "d32", false, OPT_D32 },
269 { "d64", false, OPT_D64 },
270 { "client", false, OPT_IGNORE },
271 { "server", false, OPT_IGNORE },
272 { "jvm", false, OPT_IGNORE },
273 { "hotspot", false, OPT_IGNORE },
275 { "classpath", true, OPT_CLASSPATH },
276 { "cp", true, OPT_CLASSPATH },
277 { "D", true, OPT_D },
278 { "version", false, OPT_VERSION },
279 { "showversion", false, OPT_SHOWVERSION },
280 { "fullversion", false, OPT_FULLVERSION },
281 { "help", false, OPT_HELP },
282 { "?", false, OPT_HELP },
283 { "X", false, OPT_X },
284 { "XX", false, OPT_XX },
286 { "esa", false, OPT_ESA },
287 { "enablesystemassertions", false, OPT_ESA },
288 { "dsa", false, OPT_DSA },
289 { "disablesystemassertions", false, OPT_DSA },
291 { "noasyncgc", false, OPT_IGNORE },
292 #if defined(ENABLE_VERIFIER)
293 { "noverify", false, OPT_NOVERIFY },
295 { "v", false, OPT_VERBOSE1 },
296 { "verbose:", true, OPT_VERBOSE },
298 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
299 { "verbosetc", false, OPT_VERBOSETC },
301 #if defined(__ALPHA__)
302 { "noieee", false, OPT_NOIEEE },
304 #if defined(ENABLE_STATISTICS)
305 { "time", false, OPT_TIME },
306 { "stat", false, OPT_STAT },
308 { "log", true, OPT_LOG },
309 { "c", true, OPT_CHECK },
310 { "l", false, OPT_LOAD },
311 { "eager", false, OPT_EAGER },
314 { "all", false, OPT_ALL },
315 { "sig", true, OPT_SIGNATURE },
318 #if defined(ENABLE_LOOP)
319 { "oloop", false, OPT_OLOOP },
321 #if defined(ENABLE_IFCONV)
322 { "ifconv", false, OPT_IFCONV },
324 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
325 { "lsra", false, OPT_LSRA },
328 #if defined(ENABLE_INTRP)
329 /* interpreter options */
331 { "trace", false, OPT_TRACE },
332 { "static-supers", true, OPT_STATIC_SUPERS },
333 { "no-dynamic", false, OPT_NO_DYNAMIC },
334 { "no-replication", false, OPT_NO_REPLICATION },
335 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
338 /* JVMTI Agent Command Line Options */
340 { "agentlib:", true, OPT_AGENTLIB },
341 { "agentpath:", true, OPT_AGENTPATH },
344 /* Java non-standard options */
346 { "Xjit", false, OPT_JIT },
347 { "Xint", false, OPT_INTRP },
348 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
349 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
350 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
351 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
354 { "Xdebug", false, OPT_DEBUG },
355 { "Xnoagent", false, OPT_NOAGENT },
356 { "Xrunjdwp", true, OPT_XRUNJDWP },
359 { "Xms", true, OPT_MS },
360 { "ms", true, OPT_MS },
361 { "Xmx", true, OPT_MX },
362 { "mx", true, OPT_MX },
363 { "Xss", true, OPT_SS },
364 { "ss", true, OPT_SS },
366 #if defined(ENABLE_PROFILING)
367 { "Xprof:", true, OPT_PROF_OPTION },
368 { "Xprof", false, OPT_PROF },
371 /* inlining options */
373 #if defined(ENABLE_INLINING)
374 #if defined(ENABLE_INLINING_DEBUG)
375 { "ia", false, OPT_INLINE_DEBUG_ALL },
376 { "ii", true, OPT_INLINE_DEBUG_MIN },
377 { "im", true, OPT_INLINE_DEBUG_MAX },
378 { "ie", true, OPT_INLINE_DEBUG_END },
379 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
380 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
381 #endif /* defined(ENABLE_INLINING_DEBUG) */
383 { "il", false, OPT_INLINE_LOG },
385 { "i", false, OPT_INLINING },
386 #endif /* defined(ENABLE_INLINING) */
388 /* keep these at the end of the list */
391 { "m", true, OPT_METHOD },
394 { "s", true, OPT_SHOW },
395 { "debug-color", false, OPT_DEBUGCOLOR },
401 /* usage ***********************************************************************
403 Prints the correct usage syntax to stdout.
405 *******************************************************************************/
409 puts("Usage: cacao [-options] classname [arguments]");
410 puts(" (to run a class file)");
411 puts(" or cacao [-options] -jar jarfile [arguments]");
412 puts(" (to run a standalone jar file)\n");
414 puts("where options include:");
415 puts(" -d32 use 32-bit data model if available");
416 puts(" -d64 use 64-bit data model if available");
417 puts(" -client compatibility (currently ignored)");
418 puts(" -server compatibility (currently ignored)");
419 puts(" -jvm compatibility (currently ignored)");
420 puts(" -hotspot compatibility (currently ignored)\n");
422 puts(" -cp <path> specify a path to look for classes");
423 puts(" -classpath <path> specify a path to look for classes");
424 puts(" -D<name>=<value> add an entry to the property list");
425 puts(" -verbose[:class|gc|jni] enable specific verbose output");
426 puts(" -version print product version and exit");
427 puts(" -fullversion print jpackage-compatible product version and exit");
428 puts(" -showversion print product version and continue");
429 puts(" -help, -? print this help message");
430 puts(" -X print help on non-standard Java options");
431 puts(" -XX print help on CACAO options");
432 puts(" -esa | -enablesystemassertions");
433 puts(" enable system assertions");
434 puts(" -dsa | -disablesystemassertions");
435 puts(" disable system assertions");
438 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
439 puts (" for jdwp help use: -agentlib:jdwp=help");
440 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
443 /* exit with error code */
449 static void Xusage(void)
451 #if defined(ENABLE_JIT)
452 puts(" -Xjit JIT mode execution (default)");
454 #if defined(ENABLE_INTRP)
455 puts(" -Xint interpreter mode execution");
457 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
458 puts(" value is set as bootstrap class path");
459 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
460 puts(" value is appended to the bootstrap class path");
461 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
462 puts(" value is prepended to the bootstrap class path");
463 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
464 puts(" value is used as Java core library, but the");
465 puts(" hardcoded VM interface classes are prepended");
466 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
467 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
468 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
470 #if defined(ENABLE_PROFILING)
471 puts(" -Xprof[:bb] collect and print profiling data");
474 #if defined(ENABLE_JVMTI)
475 /* -Xdebug option depend on gnu classpath JDWP options. options:
476 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
477 puts(" -Xdebug enable remote debugging\n");
478 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
479 puts(" enable remote debugging\n");
482 /* exit with error code */
488 static void XXusage(void)
490 puts(" -v write state-information");
492 puts(" -verbose[:call|exception|jit|memory]");
493 puts(" enable specific verbose output");
494 puts(" -debug-color colored output for ANSI terms");
496 #ifdef TYPECHECK_VERBOSE
497 puts(" -verbosetc write debug messages while typechecking");
499 #if defined(__ALPHA__)
500 puts(" -noieee don't use ieee compliant arithmetic");
502 #if defined(ENABLE_VERIFIER)
503 puts(" -noverify don't verify classfiles");
505 #if defined(ENABLE_STATISTICS)
506 puts(" -time measure the runtime");
507 puts(" -stat detailed compiler statistics");
509 puts(" -log logfile specify a name for the logfile");
510 puts(" -c(heck)b(ounds) don't check array bounds");
511 puts(" s(ync) don't check for synchronization");
512 #if defined(ENABLE_LOOP)
513 puts(" -oloop optimize array accesses in loops");
515 puts(" -l don't start the class after loading");
516 puts(" -eager perform eager class loading and linking");
518 puts(" -all compile all methods, no execution");
519 puts(" -m compile only a specific method");
520 puts(" -sig specify signature for a specific method");
523 puts(" -s... show...");
524 puts(" (c)onstants the constant pool");
525 puts(" (m)ethods class fields and methods");
526 puts(" (u)tf the utf - hash");
527 puts(" (i)ntermediate intermediate representation");
528 #if defined(ENABLE_DISASSEMBLER)
529 puts(" (a)ssembler disassembled listing");
530 puts(" n(o)ps show NOPs in disassembler output");
531 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
532 puts(" (n)ative disassembled native stubs");
534 puts(" (d)atasegment data segment listing");
536 #if defined(ENABLE_INLINING)
537 puts(" -i activate inlining");
539 puts(" -il log inlining");
541 #if defined(ENABLE_INLINING_DEBUG)
542 puts(" -ia use inlining for all methods");
543 puts(" -ii <size> set minimum size for inlined result");
544 puts(" -im <size> set maximum size for inlined result");
545 puts(" -ie <number> stop inlining after the given number of roots");
546 puts(" -ir log on-stack replacement");
547 puts(" -iR log on-stack replacement, more verbose");
548 #endif /* defined(ENABLE_INLINING_DEBUG) */
549 #endif /* defined(ENABLE_INLINING) */
551 #if defined(ENABLE_IFCONV)
552 puts(" -ifconv use if-conversion");
554 #if defined(ENABLE_LSRA)
555 puts(" -lsra use linear scan register allocation");
557 #if defined(ENABLE_SSA)
558 puts(" -lsra use linear scan register allocation (with SSA)");
561 /* exit with error code */
567 /* version *********************************************************************
569 Only prints cacao version information.
571 *******************************************************************************/
573 static void version(bool opt_exit)
575 puts("java version \""JAVA_VERSION"\"");
576 puts("CACAO version "VERSION"");
578 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
579 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
580 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
581 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
583 puts("This program is free software; you can redistribute it and/or");
584 puts("modify it under the terms of the GNU General Public License as");
585 puts("published by the Free Software Foundation; either version 2, or (at");
586 puts("your option) any later version.\n");
588 puts("This program is distributed in the hope that it will be useful, but");
589 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
590 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
591 puts("General Public License for more details.\n");
593 puts("Configure/Build options:\n");
594 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
595 #if defined(__VERSION__)
596 puts(" CC : "VERSION_CC" ("__VERSION__")");
598 puts(" CC : "VERSION_CC"");
600 puts(" CFLAGS : "VERSION_CFLAGS"\n");
602 puts("Default variables:\n");
603 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
604 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
605 printf(" stack size : %d\n", STACK_SIZE);
606 #if defined(WITH_CLASSPATH_GNU)
607 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
609 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
611 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
613 puts("Runtime variables:\n");
614 printf(" maximum heap size : %d\n", opt_heapmaxsize);
615 printf(" initial heap size : %d\n", opt_heapstartsize);
616 printf(" stack size : %d\n", opt_stacksize);
617 printf(" libjvm.so : %s\n", cacao_libjvm);
618 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
619 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
620 printf(" java.class.path : %s\n", _Jv_classpath);
622 /* exit normally, if requested */
629 /* fullversion *****************************************************************
631 Prints a Sun compatible version information (required e.g. by
632 jpackage, www.jpackage.org).
634 *******************************************************************************/
636 static void fullversion(void)
638 puts("java full version \"cacao-"JAVA_VERSION"\"");
646 /* forward declarations *******************************************************/
648 static char *vm_get_mainclass_from_jar(char *mainstring);
650 static void vm_compile_all(void);
651 static void vm_compile_method(void);
655 /* vm_createjvm ****************************************************************
657 Implementation for JNI_CreateJavaVM.
659 *******************************************************************************/
661 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
663 JavaVMInitArgs *_vm_args;
667 /* get the arguments for the new JVM */
669 _vm_args = (JavaVMInitArgs *) vm_args;
671 /* get the VM and Env tables (must be set before vm_create) */
673 env = NEW(_Jv_JNIEnv);
675 #if defined(ENABLE_JNI)
676 env->env = &_Jv_JNINativeInterface;
679 /* XXX Set the global variable. Maybe we should do that differently. */
683 /* create and fill a JavaVM structure */
685 vm = NEW(_Jv_JavaVM);
687 #if defined(ENABLE_JNI)
688 vm->functions = &_Jv_JNIInvokeInterface;
691 /* XXX Set the global variable. Maybe we should do that differently. */
692 /* XXX JVMTI Agents needs a JavaVM */
696 /* actually create the JVM */
698 if (!vm_create(_vm_args))
701 #if defined(ENABLE_JNI)
702 /* setup the local ref table (must be created after vm_create) */
704 if (!jni_init_localref_table())
708 /* now return the values */
710 *p_vm = (JavaVM *) vm;
711 *p_env = (void *) env;
716 /* release allocated memory */
718 FREE(env, _Jv_JNIEnv);
719 FREE(vm, _Jv_JavaVM);
725 /* vm_create *******************************************************************
727 Creates a JVM. Called by vm_createjvm.
729 *******************************************************************************/
731 bool vm_create(JavaVMInitArgs *vm_args)
740 #if defined(ENABLE_JVMTI)
742 char *libname, *agentarg;
743 bool jdwp,agentbypath;
744 jdwp = agentbypath = false;
747 #if defined(ENABLE_VMLOG)
748 vmlog_cacao_init(vm_args);
751 /* check the JNI version requested */
753 switch (vm_args->version) {
754 case JNI_VERSION_1_1:
756 case JNI_VERSION_1_2:
757 case JNI_VERSION_1_4:
763 /* we only support 1 JVM instance */
768 if (atexit(vm_exit_handler))
769 vm_abort("atexit failed: %s\n", strerror(errno));
772 log_text("CACAO started -------------------------------------------------------");
774 /* We need to check if the actual size of a java.lang.Class object
775 is smaller or equal than the assumption made in
776 src/vmcore/class.h. */
778 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
779 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
781 /* set the VM starttime */
783 _Jv_jvm->starttime = builtin_currenttimemillis();
785 /* get stuff from the environment *****************************************/
787 #if defined(WITH_JRE_LAYOUT)
788 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
790 cacao_prefix = MNEW(char, 4096);
792 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
793 vm_abort("readlink failed: %s\n", strerror(errno));
795 /* get the path of the current executable */
797 cacao_prefix = dirname(cacao_prefix);
799 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
800 vm_abort("libjvm name to long for buffer\n");
802 /* concatenate the library name */
804 strcat(cacao_prefix, "/..");
806 /* now set path to libjvm.so */
808 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
810 cacao_libjvm = MNEW(char, len);
811 strcpy(cacao_libjvm, cacao_prefix);
812 strcat(cacao_libjvm, "/lib/libjvm");
814 /* and finally set the path to GNU Classpath libraries */
816 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
818 classpath_libdir = MNEW(char, len);
819 strcpy(classpath_libdir, cacao_prefix);
820 strcat(classpath_libdir, "/lib/classpath");
822 cacao_prefix = CACAO_PREFIX;
823 cacao_libjvm = CACAO_LIBDIR"/libjvm";
824 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
827 /* set the bootclasspath */
829 cp = getenv("BOOTCLASSPATH");
832 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
833 strcpy(_Jv_bootclasspath, cp);
836 #if defined(WITH_JRE_LAYOUT)
838 # if defined(WITH_CLASSPATH_GNU)
839 strlen(cacao_prefix) +
840 strlen("/share/cacao/vm.zip") +
843 strlen(cacao_prefix) +
844 strlen("/share/classpath/glibj.zip") +
847 _Jv_bootclasspath = MNEW(char, len);
848 # if defined(WITH_CLASSPATH_GNU)
849 strcat(_Jv_bootclasspath, cacao_prefix);
850 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
851 strcat(_Jv_bootclasspath, ":");
853 strcat(_Jv_bootclasspath, cacao_prefix);
854 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
857 # if defined(WITH_CLASSPATH_GNU)
858 strlen(CACAO_VM_ZIP) +
861 strlen(CLASSPATH_CLASSES) +
864 _Jv_bootclasspath = MNEW(char, len);
865 # if defined(WITH_CLASSPATH_GNU)
866 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
867 strcat(_Jv_bootclasspath, ":");
869 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
873 /* set the classpath */
875 cp = getenv("CLASSPATH");
878 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
879 strcat(_Jv_classpath, cp);
882 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
883 strcpy(_Jv_classpath, ".");
886 /* get and set java.library.path */
888 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
890 if (_Jv_java_library_path == NULL)
891 _Jv_java_library_path = "";
893 /* interpret the options **************************************************/
900 opt_heapmaxsize = HEAP_MAXSIZE;
901 opt_heapstartsize = HEAP_STARTSIZE;
902 opt_stacksize = STACK_SIZE;
905 #if defined(ENABLE_JVMTI)
906 /* initialize JVMTI related **********************************************/
910 /* initialize and fill properties before command-line handling */
912 if (!properties_init())
913 vm_abort("properties_init failed");
915 /* iterate over all passed options */
917 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
931 #if SIZEOF_VOID_P == 8
932 puts("Running a 32-bit JVM is not supported on this platform.");
938 #if SIZEOF_VOID_P == 4
939 puts("Running a 64-bit JVM is not supported on this platform.");
945 /* forget old classpath and set the argument as new classpath */
946 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
948 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
949 strcpy(_Jv_classpath, opt_arg);
953 for (i = 0; i < strlen(opt_arg); i++) {
954 if (opt_arg[i] == '=') {
956 properties_add(opt_arg, opt_arg + i + 1);
961 /* if no '=' is given, just create an empty property */
963 properties_add(opt_arg, "");
968 case OPT_BOOTCLASSPATH:
969 /* Forget default bootclasspath and set the argument as
970 new boot classpath. */
972 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
974 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
975 strcpy(_Jv_bootclasspath, opt_arg);
978 case OPT_BOOTCLASSPATH_A:
979 /* append to end of bootclasspath */
981 len = strlen(_Jv_bootclasspath);
983 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
987 strlen(opt_arg) + strlen("0"));
989 strcat(_Jv_bootclasspath, ":");
990 strcat(_Jv_bootclasspath, opt_arg);
993 case OPT_BOOTCLASSPATH_P:
994 /* prepend in front of bootclasspath */
996 cp = _Jv_bootclasspath;
999 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1002 strcpy(_Jv_bootclasspath, opt_arg);
1003 strcat(_Jv_bootclasspath, ":");
1004 strcat(_Jv_bootclasspath, cp);
1006 MFREE(cp, char, len);
1009 case OPT_BOOTCLASSPATH_C:
1010 /* use as Java core library, but prepend VM interface classes */
1012 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1014 len = strlen(CACAO_VM_ZIP) +
1019 _Jv_bootclasspath = MNEW(char, len);
1021 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1022 strcat(_Jv_bootclasspath, ":");
1023 strcat(_Jv_bootclasspath, opt_arg);
1026 #if defined(ENABLE_JVMTI)
1028 /* this option exists only for compatibility reasons */
1032 /* I don't know yet what Xnoagent should do. This is only for
1033 compatiblity with eclipse - motse */
1042 strlen(CACAO_LIBDIR) +
1043 strlen("/libjdwp.so=") +
1047 agentarg = MNEW(char, len);
1049 strcpy(agentarg, CACAO_LIBDIR);
1050 strcat(agentarg, "/libjdwp.so=");
1051 strcat(agentarg, &opt_arg[1]);
1068 c = opt_arg[strlen(opt_arg) - 1];
1070 if ((c == 'k') || (c == 'K')) {
1071 j = atoi(opt_arg) * 1024;
1073 } else if ((c == 'm') || (c == 'M')) {
1074 j = atoi(opt_arg) * 1024 * 1024;
1080 opt_heapmaxsize = j;
1081 else if (opt == OPT_MS)
1082 opt_heapstartsize = j;
1093 if (strcmp("class", opt_arg) == 0) {
1094 opt_verboseclass = true;
1096 else if (strcmp("gc", opt_arg) == 0) {
1097 opt_verbosegc = true;
1099 else if (strcmp("jni", opt_arg) == 0) {
1100 opt_verbosejni = true;
1102 #if !defined(NDEBUG)
1103 else if (strcmp("call", opt_arg) == 0) {
1104 opt_verbosecall = true;
1106 else if (strcmp("exception", opt_arg) == 0) {
1107 opt_verboseexception = true;
1109 else if (strcmp("jit", opt_arg) == 0) {
1114 compileverbose = true;
1116 else if (strcmp("memory", opt_arg) == 0) {
1117 opt_verbosememory = true;
1119 # if defined(ENABLE_STATISTICS)
1120 /* we also need statistics */
1126 printf("Unknown -verbose option: %s\n", opt_arg);
1131 case OPT_DEBUGCOLOR:
1132 opt_debugcolor = true;
1135 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1137 opt_typecheckverbose = true;
1146 case OPT_FULLVERSION:
1150 case OPT_SHOWVERSION:
1158 #if defined(ENABLE_VERIFIER)
1164 #if defined(ENABLE_STATISTICS)
1166 opt_getcompilingtime = true;
1167 opt_getloadingtime = true;
1180 for (i = 0; i < strlen(opt_arg); i++) {
1181 switch (opt_arg[i]) {
1183 checkbounds = false;
1196 makeinitializations = false;
1203 #if !defined(NDEBUG)
1207 makeinitializations = false;
1212 opt_method = opt_arg;
1213 makeinitializations = false;
1217 opt_signature = opt_arg;
1221 case OPT_SHOW: /* Display options */
1222 for (i = 0; i < strlen(opt_arg); i++) {
1223 switch (opt_arg[i]) {
1225 showconstantpool = true;
1237 opt_showintermediate = true;
1238 compileverbose = true;
1241 #if defined(ENABLE_DISASSEMBLER)
1243 opt_showdisassemble = true;
1244 compileverbose = true;
1248 opt_shownops = true;
1252 opt_showexceptionstubs = true;
1256 opt_shownativestub = true;
1261 opt_showddatasegment = true;
1270 #if defined(ENABLE_LOOP)
1276 #if defined(ENABLE_INLINING)
1277 #if defined(ENABLE_INLINING_DEBUG)
1278 case OPT_INLINE_DEBUG_ALL:
1279 opt_inline_debug_all = true;
1281 case OPT_INLINE_DEBUG_END:
1282 opt_inline_debug_end_counter = atoi(opt_arg);
1284 case OPT_INLINE_DEBUG_MIN:
1285 opt_inline_debug_min_size = atoi(opt_arg);
1287 case OPT_INLINE_DEBUG_MAX:
1288 opt_inline_debug_max_size = atoi(opt_arg);
1290 case OPT_INLINE_REPLACE_VERBOSE:
1291 opt_replace_verbose = 1;
1293 case OPT_INLINE_REPLACE_VERBOSE2:
1294 opt_replace_verbose = 2;
1296 #endif /* defined(ENABLE_INLINING_DEBUG) */
1297 #if !defined(NDEBUG)
1298 case OPT_INLINE_LOG:
1299 opt_inline_debug_log = true;
1301 #endif /* !defined(NDEBUG) */
1304 opt_inlining = true;
1306 #endif /* defined(ENABLE_INLINING) */
1308 #if defined(ENABLE_IFCONV)
1314 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1333 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1337 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1340 #if defined(ENABLE_PROFILING)
1341 case OPT_PROF_OPTION:
1342 /* use <= to get the last \0 too */
1344 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1345 if (opt_arg[i] == ',')
1348 if (opt_arg[i] == '\0') {
1349 if (strcmp("bb", opt_arg + j) == 0)
1353 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1357 /* set k to next char */
1370 #if defined(ENABLE_JIT)
1373 printf("-Xjit option not enabled.\n");
1379 #if defined(ENABLE_INTRP)
1382 printf("-Xint option not enabled.\n");
1387 #if defined(ENABLE_INTRP)
1388 case OPT_STATIC_SUPERS:
1389 opt_static_supers = atoi(opt_arg);
1392 case OPT_NO_DYNAMIC:
1393 opt_no_dynamic = true;
1396 case OPT_NO_REPLICATION:
1397 opt_no_replication = true;
1400 case OPT_NO_QUICKSUPER:
1401 opt_no_quicksuper = true;
1410 printf("Unknown option: %s\n",
1411 vm_args->options[opt_index].optionString);
1416 /* get the main class *****************************************************/
1418 if (opt_index < vm_args->nOptions) {
1419 mainstring = vm_args->options[opt_index++].optionString;
1421 /* Put the jar file into the classpath (if any). */
1423 if (opt_jar == true) {
1424 /* free old classpath */
1426 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1428 /* put jarfile into classpath */
1430 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1432 strcpy(_Jv_classpath, mainstring);
1435 /* replace .'s with /'s in classname */
1437 for (i = strlen(mainstring) - 1; i >= 0; i--)
1438 if (mainstring[i] == '.')
1439 mainstring[i] = '/';
1443 #if defined(ENABLE_JVMTI)
1445 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1446 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1449 MFREE(agentarg, char, strlen(agentarg));
1451 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1455 /* initialize this JVM ****************************************************/
1457 vm_initializing = true;
1459 #if defined(ENABLE_THREADS)
1460 /* pre-initialize some core thread stuff, like the stopworldlock,
1461 thus this has to happen _before_ gc_init()!!! */
1466 /* initialize the garbage collector */
1468 gc_init(opt_heapmaxsize, opt_heapstartsize);
1470 #if defined(ENABLE_INTRP)
1471 /* Allocate main thread stack on the Java heap. */
1474 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1475 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1479 /* AFTER: threads_preinit */
1482 vm_abort("vm_create: string_init failed");
1484 /* AFTER: threads_preinit */
1487 vm_abort("vm_create: utf8_init failed");
1489 /* AFTER: thread_preinit */
1492 vm_abort("vm_create: suck_init failed");
1494 suck_add_from_property("java.endorsed.dirs");
1496 /* Now we have all options handled and we can print the version
1499 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1504 /* AFTER: utf8_init */
1506 suck_add(_Jv_bootclasspath);
1508 /* Now re-set some of the properties that may have changed. This
1509 must be done after _all_ environment variables have been
1510 processes (e.g. -jar handling).
1512 AFTER: suck_add_from_property, since it may change the
1513 _Jv_bootclasspath pointer. */
1515 if (!properties_postinit())
1516 vm_abort("vm_create: properties_postinit failed");
1518 /* initialize the classcache hashtable stuff: lock, hashtable
1519 (must be done _after_ threads_preinit) */
1521 if (!classcache_init())
1522 vm_abort("vm_create: classcache_init failed");
1524 /* initialize the memory subsystem (must be done _after_
1528 vm_abort("vm_create: memory_init failed");
1530 /* initialize the finalizer stuff (must be done _after_
1533 if (!finalizer_init())
1534 vm_abort("vm_create: finalizer_init failed");
1536 /* install architecture dependent signal handlers */
1540 /* initialize the codegen subsystems */
1544 /* initializes jit compiler */
1548 /* machine dependent initialization */
1550 #if defined(ENABLE_JIT)
1551 # if defined(ENABLE_INTRP)
1561 /* initialize the loader subsystems (must be done _after_
1565 vm_abort("vm_create: loader_init failed");
1568 vm_abort("vm_create: linker_init failed");
1571 vm_abort("vm_create: native_init failed");
1573 if (!exceptions_init())
1574 vm_abort("vm_create: exceptions_init failed");
1576 if (!builtin_init())
1577 vm_abort("vm_create: builtin_init failed");
1579 #if defined(ENABLE_JNI)
1580 /* Initialize the JNI subsystem (must be done _before_
1581 threads_init, as threads_init can call JNI methods
1582 (e.g. NewGlobalRef). */
1585 vm_abort("vm_create: jni_init failed");
1588 #if defined(ENABLE_THREADS)
1589 if (!threads_init())
1590 vm_abort("vm_create: threads_init failed");
1593 #if defined(ENABLE_PROFILING)
1594 /* initialize profiling */
1596 if (!profile_init())
1597 vm_abort("vm_create: profile_init failed");
1600 #if defined(ENABLE_THREADS)
1601 /* initialize recompilation */
1603 if (!recompile_init())
1604 vm_abort("vm_create: recompile_init failed");
1606 /* start the signal handler thread */
1608 if (!signal_start_thread())
1609 vm_abort("vm_create: signal_start_thread failed");
1611 /* finally, start the finalizer thread */
1613 if (!finalizer_start_thread())
1614 vm_abort("vm_create: finalizer_start_thread failed");
1616 # if !defined(NDEBUG)
1617 /* start the memory profiling thread */
1619 if (opt_verbosememory)
1620 if (!memory_start_thread())
1621 vm_abort("vm_create: memory_start_thread failed");
1624 /* start the recompilation thread (must be done before the
1625 profiling thread) */
1627 if (!recompile_start_thread())
1628 vm_abort("vm_create: recompile_start_thread failed");
1630 # if defined(ENABLE_PROFILING)
1631 /* start the profile sampling thread */
1634 /* if (!profile_start_thread()) */
1635 /* exceptions_print_stacktrace(); */
1639 #if defined(ENABLE_JVMTI)
1640 # if defined(ENABLE_GC_CACAO)
1641 /* XXX this will not work with the new indirection cells for classloaders!!! */
1645 /* add agent library to native library hashtable */
1646 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1650 /* increment the number of VMs */
1654 /* initialization is done */
1656 vm_initializing = false;
1658 /* everything's ok */
1664 /* vm_run **********************************************************************
1666 Runs the main-method of the passed class.
1668 *******************************************************************************/
1670 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1673 classinfo *mainclass;
1675 java_objectarray *oa;
1678 java_objectheader *s;
1682 #if !defined(NDEBUG)
1688 if (opt_method != NULL) {
1689 vm_compile_method();
1692 #endif /* !defined(NDEBUG) */
1694 /* should we run the main-method? */
1696 if (mainstring == NULL)
1699 /* set return value to OK */
1703 if (opt_jar == true) {
1704 /* open jar file with java.util.jar.JarFile */
1706 mainstring = vm_get_mainclass_from_jar(mainstring);
1708 if (mainstring == NULL)
1712 /* load the main class */
1714 mainutf = utf_new_char(mainstring);
1716 #if defined(ENABLE_JAVAME_CLDC1_1)
1717 mainclass = load_class_bootstrap(mainutf);
1719 mainclass = load_class_from_sysloader(mainutf);
1722 /* error loading class */
1724 if ((exceptions_get_exception() != NULL) || (mainclass == NULL)) {
1725 exceptions_print_stacktrace();
1729 if (!link_class(mainclass)) {
1730 exceptions_print_stacktrace();
1734 /* find the `main' method of the main class */
1736 m = class_resolveclassmethod(mainclass,
1737 utf_new_char("main"),
1738 utf_new_char("([Ljava/lang/String;)V"),
1739 class_java_lang_Object,
1742 if (exceptions_get_exception()) {
1743 exceptions_print_stacktrace();
1747 /* there is no main method or it isn't static */
1749 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1750 exceptions_clear_exception();
1751 exceptions_throw_nosuchmethoderror(mainclass,
1752 utf_new_char("main"),
1753 utf_new_char("([Ljava/lang/String;)V"));
1755 exceptions_print_stacktrace();
1759 /* build argument array */
1761 oalength = vm_args->nOptions - opt_index;
1763 oa = builtin_anewarray(oalength, class_java_lang_String);
1765 for (i = 0; i < oalength; i++) {
1766 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1767 s = javastring_new(u);
1772 #ifdef TYPEINFO_DEBUG_TEST
1773 /* test the typeinfo system */
1776 /*class_showmethods(currentThread->group->header.vftbl->class); */
1778 #if defined(ENABLE_JVMTI)
1779 jvmti_set_phase(JVMTI_PHASE_LIVE);
1782 /* set ThreadMXBean variables */
1784 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1785 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1787 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1788 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1789 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1790 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1792 /* start the main thread */
1794 (void) vm_call_method(m, NULL, oa);
1796 /* exception occurred? */
1798 if (exceptions_get_exception()) {
1799 exceptions_print_stacktrace();
1803 /* unload the JavaVM */
1805 (void) vm_destroy(vm);
1813 /* vm_destroy ******************************************************************
1815 Unloads a Java VM and reclaims its resources.
1817 *******************************************************************************/
1819 s4 vm_destroy(JavaVM *vm)
1821 #if defined(ENABLE_THREADS)
1822 threads_join_all_threads();
1825 /* everything's ok */
1831 /* vm_exit *********************************************************************
1833 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1835 *******************************************************************************/
1837 void vm_exit(s4 status)
1841 /* signal that we are exiting */
1845 assert(class_java_lang_System);
1846 assert(class_java_lang_System->state & CLASS_LOADED);
1848 #if defined(ENABLE_JVMTI)
1849 if (jvmti || (dbgcom!=NULL)) {
1850 jvmti_set_phase(JVMTI_PHASE_DEAD);
1851 if (jvmti) jvmti_agentunload();
1855 if (!link_class(class_java_lang_System)) {
1856 exceptions_print_stacktrace();
1860 /* call java.lang.System.exit(I)V */
1862 m = class_resolveclassmethod(class_java_lang_System,
1863 utf_new_char("exit"),
1865 class_java_lang_Object,
1869 exceptions_print_stacktrace();
1873 /* call the exit function with passed exit status */
1875 (void) vm_call_method(m, NULL, status);
1877 /* If we had an exception, just ignore the exception and exit with
1880 vm_shutdown(status);
1884 /* vm_shutdown *****************************************************************
1886 Terminates the system immediately without freeing memory explicitly
1887 (to be used only for abnormal termination).
1889 *******************************************************************************/
1891 void vm_shutdown(s4 status)
1894 #if defined(ENABLE_STATISTICS)
1895 || opt_getcompilingtime || opt_stat
1899 log_text("CACAO terminated by shutdown");
1900 dolog("Exit status: %d\n", (s4) status);
1904 #if defined(ENABLE_JVMTI)
1905 /* terminate cacaodbgserver */
1907 pthread_mutex_lock(&dbgcomlock);
1909 pthread_mutex_unlock(&dbgcomlock);
1910 jvmti_cacaodbgserver_quit();
1918 /* vm_exit_handler *************************************************************
1920 The exit_handler function is called upon program termination.
1922 ATTENTION: Don't free system resources here! Some threads may still
1923 be running as this is called from VMRuntime.exit(). The OS does the
1926 *******************************************************************************/
1928 void vm_exit_handler(void)
1930 #if !defined(NDEBUG)
1932 class_showmethods(mainclass);
1934 if (showconstantpool)
1935 class_showconstantpool(mainclass);
1940 # if defined(ENABLE_PROFILING)
1942 profile_printstats();
1944 #endif /* !defined(NDEBUG) */
1946 #if defined(ENABLE_RT_TIMING)
1947 rt_timing_print_time_stats(stderr);
1950 #if defined(ENABLE_CYCLES_STATS)
1951 builtin_print_cycles_stats(stderr);
1952 stacktrace_print_cycles_stats(stderr);
1956 #if defined(ENABLE_STATISTICS)
1957 || opt_getcompilingtime || opt_stat
1961 log_text("CACAO terminated");
1963 #if defined(ENABLE_STATISTICS)
1966 #ifdef TYPECHECK_STATISTICS
1967 typecheck_print_statistics(get_logfile());
1971 if (opt_getcompilingtime)
1973 #endif /* defined(ENABLE_STATISTICS) */
1975 /* vm_print_profile(stderr);*/
1979 /* vm_abort ********************************************************************
1981 Prints an error message and aborts the VM.
1983 *******************************************************************************/
1985 void vm_abort(const char *text, ...)
1989 /* print the log message */
1994 log_vprint(text, ap);
1999 /* now abort the VM */
2005 /* vm_get_mainclass_from_jar ***************************************************
2007 Gets the name of the main class from a JAR's manifest file.
2009 *******************************************************************************/
2011 static char *vm_get_mainclass_from_jar(char *mainstring)
2014 java_objectheader *o;
2016 java_objectheader *s;
2018 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2021 exceptions_print_stacktrace();
2025 /* create JarFile object */
2030 exceptions_print_stacktrace();
2034 m = class_resolveclassmethod(c,
2036 utf_java_lang_String__void,
2037 class_java_lang_Object,
2041 exceptions_print_stacktrace();
2045 s = javastring_new_from_ascii(mainstring);
2047 (void) vm_call_method(m, o, s);
2049 if (exceptions_get_exception()) {
2050 exceptions_print_stacktrace();
2054 /* get manifest object */
2056 m = class_resolveclassmethod(c,
2057 utf_new_char("getManifest"),
2058 utf_new_char("()Ljava/util/jar/Manifest;"),
2059 class_java_lang_Object,
2063 exceptions_print_stacktrace();
2067 o = vm_call_method(m, o);
2070 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2075 /* get Main Attributes */
2077 m = class_resolveclassmethod(o->vftbl->class,
2078 utf_new_char("getMainAttributes"),
2079 utf_new_char("()Ljava/util/jar/Attributes;"),
2080 class_java_lang_Object,
2084 exceptions_print_stacktrace();
2088 o = vm_call_method(m, o);
2091 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2096 /* get property Main-Class */
2098 m = class_resolveclassmethod(o->vftbl->class,
2099 utf_new_char("getValue"),
2100 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2101 class_java_lang_Object,
2105 exceptions_print_stacktrace();
2109 s = javastring_new_from_ascii("Main-Class");
2111 o = vm_call_method(m, o, s);
2114 exceptions_print_stacktrace();
2118 return javastring_tochar(o);
2122 /* vm_compile_all **************************************************************
2124 Compile all methods found in the bootclasspath.
2126 *******************************************************************************/
2128 #if !defined(NDEBUG)
2129 static void vm_compile_all(void)
2134 classcache_name_entry *nmen;
2135 classcache_class_entry *clsen;
2138 /* create all classes found in the bootclasspath */
2139 /* XXX currently only works with zip/jar's */
2141 loader_load_all_classes();
2143 /* link all classes */
2145 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2146 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2148 for (; nmen; nmen = nmen->hashlink) {
2149 /* iterate over all class entries */
2151 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2152 c = clsen->classobj;
2157 if (!(c->state & CLASS_LINKED)) {
2158 if (!link_class(c)) {
2159 fprintf(stderr, "Error linking: ");
2160 utf_fprint_printable_ascii_classname(stderr, c->name);
2161 fprintf(stderr, "\n");
2163 /* print out exception and cause */
2165 exceptions_print_current_exception();
2167 /* goto next class */
2173 /* compile all class methods */
2175 for (i = 0; i < c->methodscount; i++) {
2176 m = &(c->methods[i]);
2178 if (m->jcode != NULL) {
2179 if (!jit_compile(m)) {
2180 fprintf(stderr, "Error compiling: ");
2181 utf_fprint_printable_ascii_classname(stderr, c->name);
2182 fprintf(stderr, ".");
2183 utf_fprint_printable_ascii(stderr, m->name);
2184 utf_fprint_printable_ascii(stderr, m->descriptor);
2185 fprintf(stderr, "\n");
2187 /* print out exception and cause */
2189 exceptions_print_current_exception();
2197 #endif /* !defined(NDEBUG) */
2200 /* vm_compile_method ***********************************************************
2202 Compile a specific method.
2204 *******************************************************************************/
2206 #if !defined(NDEBUG)
2207 static void vm_compile_method(void)
2211 /* create, load and link the main class */
2213 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2215 if (mainclass == NULL)
2216 exceptions_print_stacktrace();
2218 if (!link_class(mainclass))
2219 exceptions_print_stacktrace();
2221 if (opt_signature != NULL) {
2222 m = class_resolveclassmethod(mainclass,
2223 utf_new_char(opt_method),
2224 utf_new_char(opt_signature),
2229 m = class_resolveclassmethod(mainclass,
2230 utf_new_char(opt_method),
2237 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2238 opt_method, opt_signature ? opt_signature : "");
2242 #endif /* !defined(NDEBUG) */
2245 /* vm_vmargs_from_valist *******************************************************
2249 *******************************************************************************/
2251 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2252 vm_arg *vmargs, va_list ap)
2254 typedesc *paramtypes;
2257 paramtypes = m->parseddesc->paramtypes;
2259 /* if method is non-static fill first block and skip `this' pointer */
2264 /* the `this' pointer */
2265 vmargs[0].type = TYPE_ADR;
2266 vmargs[0].data.l = (u8) (ptrint) o;
2272 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2273 switch (paramtypes->decltype) {
2274 /* primitive types */
2275 case PRIMITIVETYPE_BOOLEAN:
2276 case PRIMITIVETYPE_BYTE:
2277 case PRIMITIVETYPE_CHAR:
2278 case PRIMITIVETYPE_SHORT:
2279 case PRIMITIVETYPE_INT:
2280 vmargs[i].type = TYPE_INT;
2281 vmargs[i].data.l = (s8) va_arg(ap, s4);
2284 case PRIMITIVETYPE_LONG:
2285 vmargs[i].type = TYPE_LNG;
2286 vmargs[i].data.l = (s8) va_arg(ap, s8);
2289 case PRIMITIVETYPE_FLOAT:
2290 vmargs[i].type = TYPE_FLT;
2291 #if defined(__ALPHA__)
2292 /* this keeps the assembler function much simpler */
2294 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2296 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2300 case PRIMITIVETYPE_DOUBLE:
2301 vmargs[i].type = TYPE_DBL;
2302 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2306 vmargs[i].type = TYPE_ADR;
2307 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2314 /* vm_vmargs_from_jvalue *******************************************************
2318 *******************************************************************************/
2320 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2321 vm_arg *vmargs, jvalue *args)
2323 typedesc *paramtypes;
2327 paramtypes = m->parseddesc->paramtypes;
2329 /* if method is non-static fill first block and skip `this' pointer */
2334 /* the `this' pointer */
2335 vmargs[0].type = TYPE_ADR;
2336 vmargs[0].data.l = (u8) (ptrint) o;
2342 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2343 switch (paramtypes->decltype) {
2344 /* primitive types */
2345 case PRIMITIVETYPE_BOOLEAN:
2346 case PRIMITIVETYPE_BYTE:
2347 case PRIMITIVETYPE_CHAR:
2348 case PRIMITIVETYPE_SHORT:
2349 case PRIMITIVETYPE_INT:
2350 vmargs[i].type = TYPE_INT;
2351 vmargs[i].data.l = (s8) args[j].i;
2354 case PRIMITIVETYPE_LONG:
2355 vmargs[i].type = TYPE_LNG;
2356 vmargs[i].data.l = (s8) args[j].j;
2359 case PRIMITIVETYPE_FLOAT:
2360 vmargs[i].type = TYPE_FLT;
2361 #if defined(__ALPHA__)
2362 /* this keeps the assembler function much simpler */
2364 vmargs[i].data.d = (jdouble) args[j].f;
2366 vmargs[i].data.f = args[j].f;
2370 case PRIMITIVETYPE_DOUBLE:
2371 vmargs[i].type = TYPE_DBL;
2372 vmargs[i].data.d = args[j].d;
2376 vmargs[i].type = TYPE_ADR;
2377 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2384 /* vm_call_method **************************************************************
2386 Calls a Java method with a variable number of arguments and returns
2389 *******************************************************************************/
2391 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2394 java_objectheader *ro;
2397 ro = vm_call_method_valist(m, o, ap);
2404 /* vm_call_method_valist *******************************************************
2406 Calls a Java method with a variable number of arguments, passed via
2407 a va_list, and returns an address.
2409 *******************************************************************************/
2411 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2416 java_objectheader *ro;
2419 /* mark start of dump memory area */
2421 dumpsize = dump_size();
2423 /* get number of Java method arguments */
2425 vmargscount = m->parseddesc->paramcount;
2427 /* allocate vm_arg array */
2429 vmargs = DMNEW(vm_arg, vmargscount);
2431 /* fill the vm_arg array from a va_list */
2433 vm_vmargs_from_valist(m, o, vmargs, ap);
2435 /* call the Java method */
2437 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2439 /* release dump area */
2441 dump_release(dumpsize);
2447 /* vm_call_method_jvalue *******************************************************
2449 Calls a Java method with a variable number of arguments, passed via
2450 a jvalue array, and returns an address.
2452 *******************************************************************************/
2454 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2459 java_objectheader *ro;
2462 /* mark start of dump memory area */
2464 dumpsize = dump_size();
2466 /* get number of Java method arguments */
2468 vmargscount = m->parseddesc->paramcount;
2470 /* allocate vm_arg array */
2472 vmargs = DMNEW(vm_arg, vmargscount);
2474 /* fill the vm_arg array from a va_list */
2476 vm_vmargs_from_jvalue(m, o, vmargs, args);
2478 /* call the Java method */
2480 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2482 /* release dump area */
2484 dump_release(dumpsize);
2490 /* vm_call_method_vmarg ********************************************************
2492 Calls a Java method with a variable number of arguments, passed via
2493 a vm_arg array, and returns an address.
2495 *******************************************************************************/
2497 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2500 java_objectheader *o;
2502 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2503 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
2506 #if defined(ENABLE_JIT)
2507 # if defined(ENABLE_INTRP)
2509 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2512 o = asm_vm_call_method(m, vmargscount, vmargs);
2514 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2517 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2518 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
2525 /* vm_call_method_int **********************************************************
2527 Calls a Java method with a variable number of arguments and returns
2530 *******************************************************************************/
2532 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2538 i = vm_call_method_int_valist(m, o, ap);
2545 /* vm_call_method_int_valist ***************************************************
2547 Calls a Java method with a variable number of arguments, passed via
2548 a va_list, and returns an integer (s4).
2550 *******************************************************************************/
2552 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2559 /* mark start of dump memory area */
2561 dumpsize = dump_size();
2563 /* get number of Java method arguments */
2565 vmargscount = m->parseddesc->paramcount;
2567 /* allocate vm_arg array */
2569 vmargs = DMNEW(vm_arg, vmargscount);
2571 /* fill the vm_arg array from a va_list */
2573 vm_vmargs_from_valist(m, o, vmargs, ap);
2575 /* call the Java method */
2577 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2579 /* release dump area */
2581 dump_release(dumpsize);
2587 /* vm_call_method_int_jvalue ***************************************************
2589 Calls a Java method with a variable number of arguments, passed via
2590 a jvalue array, and returns an integer (s4).
2592 *******************************************************************************/
2594 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2601 /* mark start of dump memory area */
2603 dumpsize = dump_size();
2605 /* get number of Java method arguments */
2607 vmargscount = m->parseddesc->paramcount;
2609 /* allocate vm_arg array */
2611 vmargs = DMNEW(vm_arg, vmargscount);
2613 /* fill the vm_arg array from a va_list */
2615 vm_vmargs_from_jvalue(m, o, vmargs, args);
2617 /* call the Java method */
2619 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2621 /* release dump area */
2623 dump_release(dumpsize);
2629 /* vm_call_method_int_vmarg ****************************************************
2631 Calls a Java method with a variable number of arguments, passed via
2632 a vm_arg array, and returns an integer (s4).
2634 *******************************************************************************/
2636 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2640 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2641 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
2644 #if defined(ENABLE_JIT)
2645 # if defined(ENABLE_INTRP)
2647 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2650 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2652 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2655 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2656 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
2663 /* vm_call_method_long *********************************************************
2665 Calls a Java method with a variable number of arguments and returns
2668 *******************************************************************************/
2670 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2676 l = vm_call_method_long_valist(m, o, ap);
2683 /* vm_call_method_long_valist **************************************************
2685 Calls a Java method with a variable number of arguments, passed via
2686 a va_list, and returns a long (s8).
2688 *******************************************************************************/
2690 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2697 /* mark start of dump memory area */
2699 dumpsize = dump_size();
2701 /* get number of Java method arguments */
2703 vmargscount = m->parseddesc->paramcount;
2705 /* allocate vm_arg array */
2707 vmargs = DMNEW(vm_arg, vmargscount);
2709 /* fill the vm_arg array from a va_list */
2711 vm_vmargs_from_valist(m, o, vmargs, ap);
2713 /* call the Java method */
2715 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2717 /* release dump area */
2719 dump_release(dumpsize);
2725 /* vm_call_method_long_jvalue **************************************************
2727 Calls a Java method with a variable number of arguments, passed via
2728 a jvalue array, and returns a long (s8).
2730 *******************************************************************************/
2732 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2739 /* mark start of dump memory area */
2741 dumpsize = dump_size();
2743 /* get number of Java method arguments */
2745 vmargscount = m->parseddesc->paramcount;
2747 /* allocate vm_arg array */
2749 vmargs = DMNEW(vm_arg, vmargscount);
2751 /* fill the vm_arg array from a va_list */
2753 vm_vmargs_from_jvalue(m, o, vmargs, args);
2755 /* call the Java method */
2757 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2759 /* release dump area */
2761 dump_release(dumpsize);
2767 /* vm_call_method_long_vmarg ***************************************************
2769 Calls a Java method with a variable number of arguments, passed via
2770 a vm_arg array, and returns a long (s8).
2772 *******************************************************************************/
2774 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2778 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2779 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
2782 #if defined(ENABLE_JIT)
2783 # if defined(ENABLE_INTRP)
2785 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2788 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2790 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2793 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2794 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
2801 /* vm_call_method_float ********************************************************
2803 Calls a Java method with a variable number of arguments and returns
2806 *******************************************************************************/
2808 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2814 f = vm_call_method_float_valist(m, o, ap);
2821 /* vm_call_method_float_valist *************************************************
2823 Calls a Java method with a variable number of arguments, passed via
2824 a va_list, and returns a float.
2826 *******************************************************************************/
2828 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2836 /* mark start of dump memory area */
2838 dumpsize = dump_size();
2840 /* get number of Java method arguments */
2842 vmargscount = m->parseddesc->paramcount;
2844 /* allocate vm_arg array */
2846 vmargs = DMNEW(vm_arg, vmargscount);
2848 /* fill the vm_arg array from a va_list */
2850 vm_vmargs_from_valist(m, o, vmargs, ap);
2852 /* call the Java method */
2854 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2856 /* release dump area */
2858 dump_release(dumpsize);
2864 /* vm_call_method_float_jvalue *************************************************
2866 Calls a Java method with a variable number of arguments, passed via
2867 a jvalue array, and returns a float.
2869 *******************************************************************************/
2871 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2879 /* mark start of dump memory area */
2881 dumpsize = dump_size();
2883 /* get number of Java method arguments */
2885 vmargscount = m->parseddesc->paramcount;
2887 /* allocate vm_arg array */
2889 vmargs = DMNEW(vm_arg, vmargscount);
2891 /* fill the vm_arg array from a va_list */
2893 vm_vmargs_from_jvalue(m, o, vmargs, args);
2895 /* call the Java method */
2897 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2899 /* release dump area */
2901 dump_release(dumpsize);
2907 /* vm_call_method_float_vmarg **************************************************
2909 Calls a Java method with a variable number of arguments and returns
2912 *******************************************************************************/
2914 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2918 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2919 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
2922 #if defined(ENABLE_JIT)
2923 # if defined(ENABLE_INTRP)
2925 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2928 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2930 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2933 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
2934 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
2941 /* vm_call_method_double *******************************************************
2943 Calls a Java method with a variable number of arguments and returns
2946 *******************************************************************************/
2948 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2954 d = vm_call_method_double_valist(m, o, ap);
2961 /* vm_call_method_double_valist ************************************************
2963 Calls a Java method with a variable number of arguments, passed via
2964 a va_list, and returns a double.
2966 *******************************************************************************/
2968 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2976 /* mark start of dump memory area */
2978 dumpsize = dump_size();
2980 /* get number of Java method arguments */
2982 vmargscount = m->parseddesc->paramcount;
2984 /* allocate vm_arg array */
2986 vmargs = DMNEW(vm_arg, vmargscount);
2988 /* fill the vm_arg array from a va_list */
2990 vm_vmargs_from_valist(m, o, vmargs, ap);
2992 /* call the Java method */
2994 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2996 /* release dump area */
2998 dump_release(dumpsize);
3004 /* vm_call_method_double_jvalue ************************************************
3006 Calls a Java method with a variable number of arguments, passed via
3007 a jvalue array, and returns a double.
3009 *******************************************************************************/
3011 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
3019 /* mark start of dump memory area */
3021 dumpsize = dump_size();
3023 /* get number of Java method arguments */
3025 vmargscount = m->parseddesc->paramcount;
3027 /* allocate vm_arg array */
3029 vmargs = DMNEW(vm_arg, vmargscount);
3031 /* fill the vm_arg array from a va_list */
3033 vm_vmargs_from_jvalue(m, o, vmargs, args);
3035 /* call the Java method */
3037 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
3039 /* release dump area */
3041 dump_release(dumpsize);
3047 /* vm_call_method_double_vmarg *************************************************
3049 Calls a Java method with a variable number of arguments and returns
3052 *******************************************************************************/
3054 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
3059 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3060 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
3063 #if defined(ENABLE_JIT)
3064 # if defined(ENABLE_INTRP)
3066 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3069 d = asm_vm_call_method_double(m, vmargscount, vmargs);
3071 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3074 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3075 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
3083 * These are local overrides for various environment variables in Emacs.
3084 * Please do not remove this and leave it at the end of the file, where
3085 * Emacs will automagically detect them.
3086 * ---------------------------------------------------------------------
3089 * indent-tabs-mode: t