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 /* vm_abort("vm_create: profile_start_thread failed"); */
1641 #if defined(ENABLE_JVMTI)
1643 /* add agent library to native library hashtable */
1644 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1648 /* increment the number of VMs */
1652 /* initialization is done */
1654 vm_initializing = false;
1656 /* everything's ok */
1662 /* vm_run **********************************************************************
1664 Runs the main-method of the passed class.
1666 *******************************************************************************/
1668 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1671 classinfo *mainclass;
1673 java_objectarray *oa;
1676 java_objectheader *s;
1680 #if !defined(NDEBUG)
1686 if (opt_method != NULL) {
1687 vm_compile_method();
1690 #endif /* !defined(NDEBUG) */
1692 /* should we run the main-method? */
1694 if (mainstring == NULL)
1697 /* set return value to OK */
1701 if (opt_jar == true) {
1702 /* open jar file with java.util.jar.JarFile */
1704 mainstring = vm_get_mainclass_from_jar(mainstring);
1706 if (mainstring == NULL)
1710 /* load the main class */
1712 mainutf = utf_new_char(mainstring);
1714 #if defined(ENABLE_JAVAME_CLDC1_1)
1715 mainclass = load_class_bootstrap(mainutf);
1717 mainclass = load_class_from_sysloader(mainutf);
1720 /* error loading class */
1722 if ((exceptions_get_exception() != NULL) || (mainclass == NULL)) {
1723 exceptions_print_stacktrace();
1727 if (!link_class(mainclass)) {
1728 exceptions_print_stacktrace();
1732 /* find the `main' method of the main class */
1734 m = class_resolveclassmethod(mainclass,
1735 utf_new_char("main"),
1736 utf_new_char("([Ljava/lang/String;)V"),
1737 class_java_lang_Object,
1740 if (exceptions_get_exception()) {
1741 exceptions_print_stacktrace();
1745 /* there is no main method or it isn't static */
1747 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1748 exceptions_clear_exception();
1749 exceptions_throw_nosuchmethoderror(mainclass,
1750 utf_new_char("main"),
1751 utf_new_char("([Ljava/lang/String;)V"));
1753 exceptions_print_stacktrace();
1757 /* build argument array */
1759 oalength = vm_args->nOptions - opt_index;
1761 oa = builtin_anewarray(oalength, class_java_lang_String);
1763 for (i = 0; i < oalength; i++) {
1764 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1765 s = javastring_new(u);
1770 #ifdef TYPEINFO_DEBUG_TEST
1771 /* test the typeinfo system */
1774 /*class_showmethods(currentThread->group->header.vftbl->class); */
1776 #if defined(ENABLE_JVMTI)
1777 jvmti_set_phase(JVMTI_PHASE_LIVE);
1780 /* set ThreadMXBean variables */
1782 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1783 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1785 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1786 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1787 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1788 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1790 /* start the main thread */
1792 (void) vm_call_method(m, NULL, oa);
1794 /* exception occurred? */
1796 if (exceptions_get_exception()) {
1797 exceptions_print_stacktrace();
1801 /* unload the JavaVM */
1803 (void) vm_destroy(vm);
1811 /* vm_destroy ******************************************************************
1813 Unloads a Java VM and reclaims its resources.
1815 *******************************************************************************/
1817 s4 vm_destroy(JavaVM *vm)
1819 #if defined(ENABLE_THREADS)
1820 threads_join_all_threads();
1823 /* everything's ok */
1829 /* vm_exit *********************************************************************
1831 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1833 *******************************************************************************/
1835 void vm_exit(s4 status)
1839 /* signal that we are exiting */
1843 assert(class_java_lang_System);
1844 assert(class_java_lang_System->state & CLASS_LOADED);
1846 #if defined(ENABLE_JVMTI)
1847 if (jvmti || (dbgcom!=NULL)) {
1848 jvmti_set_phase(JVMTI_PHASE_DEAD);
1849 if (jvmti) jvmti_agentunload();
1853 if (!link_class(class_java_lang_System)) {
1854 exceptions_print_stacktrace();
1858 /* call java.lang.System.exit(I)V */
1860 m = class_resolveclassmethod(class_java_lang_System,
1861 utf_new_char("exit"),
1863 class_java_lang_Object,
1867 exceptions_print_stacktrace();
1871 /* call the exit function with passed exit status */
1873 (void) vm_call_method(m, NULL, status);
1875 /* If we had an exception, just ignore the exception and exit with
1878 vm_shutdown(status);
1882 /* vm_shutdown *****************************************************************
1884 Terminates the system immediately without freeing memory explicitly
1885 (to be used only for abnormal termination).
1887 *******************************************************************************/
1889 void vm_shutdown(s4 status)
1892 #if defined(ENABLE_STATISTICS)
1893 || opt_getcompilingtime || opt_stat
1897 log_text("CACAO terminated by shutdown");
1898 dolog("Exit status: %d\n", (s4) status);
1902 #if defined(ENABLE_JVMTI)
1903 /* terminate cacaodbgserver */
1905 pthread_mutex_lock(&dbgcomlock);
1907 pthread_mutex_unlock(&dbgcomlock);
1908 jvmti_cacaodbgserver_quit();
1916 /* vm_exit_handler *************************************************************
1918 The exit_handler function is called upon program termination.
1920 ATTENTION: Don't free system resources here! Some threads may still
1921 be running as this is called from VMRuntime.exit(). The OS does the
1924 *******************************************************************************/
1926 void vm_exit_handler(void)
1928 #if !defined(NDEBUG)
1930 class_showmethods(mainclass);
1932 if (showconstantpool)
1933 class_showconstantpool(mainclass);
1938 # if defined(ENABLE_PROFILING)
1940 profile_printstats();
1942 #endif /* !defined(NDEBUG) */
1944 #if defined(ENABLE_RT_TIMING)
1945 rt_timing_print_time_stats(stderr);
1948 #if defined(ENABLE_CYCLES_STATS)
1949 builtin_print_cycles_stats(stderr);
1950 stacktrace_print_cycles_stats(stderr);
1954 #if defined(ENABLE_STATISTICS)
1955 || opt_getcompilingtime || opt_stat
1959 log_text("CACAO terminated");
1961 #if defined(ENABLE_STATISTICS)
1964 #ifdef TYPECHECK_STATISTICS
1965 typecheck_print_statistics(get_logfile());
1969 if (opt_getcompilingtime)
1971 #endif /* defined(ENABLE_STATISTICS) */
1973 /* vm_print_profile(stderr);*/
1977 /* vm_abort ********************************************************************
1979 Prints an error message and aborts the VM.
1981 *******************************************************************************/
1983 void vm_abort(const char *text, ...)
1987 /* print the log message */
1992 log_vprint(text, ap);
1997 /* now abort the VM */
2003 /* vm_get_mainclass_from_jar ***************************************************
2005 Gets the name of the main class from a JAR's manifest file.
2007 *******************************************************************************/
2009 static char *vm_get_mainclass_from_jar(char *mainstring)
2012 java_objectheader *o;
2014 java_objectheader *s;
2016 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2019 exceptions_print_stacktrace();
2023 /* create JarFile object */
2028 exceptions_print_stacktrace();
2032 m = class_resolveclassmethod(c,
2034 utf_java_lang_String__void,
2035 class_java_lang_Object,
2039 exceptions_print_stacktrace();
2043 s = javastring_new_from_ascii(mainstring);
2045 (void) vm_call_method(m, o, s);
2047 if (exceptions_get_exception()) {
2048 exceptions_print_stacktrace();
2052 /* get manifest object */
2054 m = class_resolveclassmethod(c,
2055 utf_new_char("getManifest"),
2056 utf_new_char("()Ljava/util/jar/Manifest;"),
2057 class_java_lang_Object,
2061 exceptions_print_stacktrace();
2065 o = vm_call_method(m, o);
2068 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2073 /* get Main Attributes */
2075 m = class_resolveclassmethod(o->vftbl->class,
2076 utf_new_char("getMainAttributes"),
2077 utf_new_char("()Ljava/util/jar/Attributes;"),
2078 class_java_lang_Object,
2082 exceptions_print_stacktrace();
2086 o = vm_call_method(m, o);
2089 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2094 /* get property Main-Class */
2096 m = class_resolveclassmethod(o->vftbl->class,
2097 utf_new_char("getValue"),
2098 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2099 class_java_lang_Object,
2103 exceptions_print_stacktrace();
2107 s = javastring_new_from_ascii("Main-Class");
2109 o = vm_call_method(m, o, s);
2112 exceptions_print_stacktrace();
2116 return javastring_tochar(o);
2120 /* vm_compile_all **************************************************************
2122 Compile all methods found in the bootclasspath.
2124 *******************************************************************************/
2126 #if !defined(NDEBUG)
2127 static void vm_compile_all(void)
2132 classcache_name_entry *nmen;
2133 classcache_class_entry *clsen;
2136 /* create all classes found in the bootclasspath */
2137 /* XXX currently only works with zip/jar's */
2139 loader_load_all_classes();
2141 /* link all classes */
2143 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2144 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2146 for (; nmen; nmen = nmen->hashlink) {
2147 /* iterate over all class entries */
2149 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2150 c = clsen->classobj;
2155 if (!(c->state & CLASS_LINKED)) {
2156 if (!link_class(c)) {
2157 fprintf(stderr, "Error linking: ");
2158 utf_fprint_printable_ascii_classname(stderr, c->name);
2159 fprintf(stderr, "\n");
2161 /* print out exception and cause */
2163 exceptions_print_current_exception();
2165 /* goto next class */
2171 /* compile all class methods */
2173 for (i = 0; i < c->methodscount; i++) {
2174 m = &(c->methods[i]);
2176 if (m->jcode != NULL) {
2177 if (!jit_compile(m)) {
2178 fprintf(stderr, "Error compiling: ");
2179 utf_fprint_printable_ascii_classname(stderr, c->name);
2180 fprintf(stderr, ".");
2181 utf_fprint_printable_ascii(stderr, m->name);
2182 utf_fprint_printable_ascii(stderr, m->descriptor);
2183 fprintf(stderr, "\n");
2185 /* print out exception and cause */
2187 exceptions_print_current_exception();
2195 #endif /* !defined(NDEBUG) */
2198 /* vm_compile_method ***********************************************************
2200 Compile a specific method.
2202 *******************************************************************************/
2204 #if !defined(NDEBUG)
2205 static void vm_compile_method(void)
2209 /* create, load and link the main class */
2211 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2213 if (mainclass == NULL)
2214 exceptions_print_stacktrace();
2216 if (!link_class(mainclass))
2217 exceptions_print_stacktrace();
2219 if (opt_signature != NULL) {
2220 m = class_resolveclassmethod(mainclass,
2221 utf_new_char(opt_method),
2222 utf_new_char(opt_signature),
2227 m = class_resolveclassmethod(mainclass,
2228 utf_new_char(opt_method),
2235 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2236 opt_method, opt_signature ? opt_signature : "");
2240 #endif /* !defined(NDEBUG) */
2243 /* vm_vmargs_from_valist *******************************************************
2247 *******************************************************************************/
2249 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2250 vm_arg *vmargs, va_list ap)
2252 typedesc *paramtypes;
2255 paramtypes = m->parseddesc->paramtypes;
2257 /* if method is non-static fill first block and skip `this' pointer */
2262 /* the `this' pointer */
2263 vmargs[0].type = TYPE_ADR;
2264 vmargs[0].data.l = (u8) (ptrint) o;
2270 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2271 switch (paramtypes->decltype) {
2272 /* primitive types */
2273 case PRIMITIVETYPE_BOOLEAN:
2274 case PRIMITIVETYPE_BYTE:
2275 case PRIMITIVETYPE_CHAR:
2276 case PRIMITIVETYPE_SHORT:
2277 case PRIMITIVETYPE_INT:
2278 vmargs[i].type = TYPE_INT;
2279 vmargs[i].data.l = (s8) va_arg(ap, s4);
2282 case PRIMITIVETYPE_LONG:
2283 vmargs[i].type = TYPE_LNG;
2284 vmargs[i].data.l = (s8) va_arg(ap, s8);
2287 case PRIMITIVETYPE_FLOAT:
2288 vmargs[i].type = TYPE_FLT;
2289 #if defined(__ALPHA__)
2290 /* this keeps the assembler function much simpler */
2292 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2294 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2298 case PRIMITIVETYPE_DOUBLE:
2299 vmargs[i].type = TYPE_DBL;
2300 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2304 vmargs[i].type = TYPE_ADR;
2305 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2312 /* vm_vmargs_from_jvalue *******************************************************
2316 *******************************************************************************/
2318 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2319 vm_arg *vmargs, jvalue *args)
2321 typedesc *paramtypes;
2325 paramtypes = m->parseddesc->paramtypes;
2327 /* if method is non-static fill first block and skip `this' pointer */
2332 /* the `this' pointer */
2333 vmargs[0].type = TYPE_ADR;
2334 vmargs[0].data.l = (u8) (ptrint) o;
2340 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2341 switch (paramtypes->decltype) {
2342 /* primitive types */
2343 case PRIMITIVETYPE_BOOLEAN:
2344 case PRIMITIVETYPE_BYTE:
2345 case PRIMITIVETYPE_CHAR:
2346 case PRIMITIVETYPE_SHORT:
2347 case PRIMITIVETYPE_INT:
2348 vmargs[i].type = TYPE_INT;
2349 vmargs[i].data.l = (s8) args[j].i;
2352 case PRIMITIVETYPE_LONG:
2353 vmargs[i].type = TYPE_LNG;
2354 vmargs[i].data.l = (s8) args[j].j;
2357 case PRIMITIVETYPE_FLOAT:
2358 vmargs[i].type = TYPE_FLT;
2359 #if defined(__ALPHA__)
2360 /* this keeps the assembler function much simpler */
2362 vmargs[i].data.d = (jdouble) args[j].f;
2364 vmargs[i].data.f = args[j].f;
2368 case PRIMITIVETYPE_DOUBLE:
2369 vmargs[i].type = TYPE_DBL;
2370 vmargs[i].data.d = args[j].d;
2374 vmargs[i].type = TYPE_ADR;
2375 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2382 /* vm_call_method **************************************************************
2384 Calls a Java method with a variable number of arguments and returns
2387 *******************************************************************************/
2389 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2392 java_objectheader *ro;
2395 ro = vm_call_method_valist(m, o, ap);
2402 /* vm_call_method_valist *******************************************************
2404 Calls a Java method with a variable number of arguments, passed via
2405 a va_list, and returns an address.
2407 *******************************************************************************/
2409 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2414 java_objectheader *ro;
2417 /* mark start of dump memory area */
2419 dumpsize = dump_size();
2421 /* get number of Java method arguments */
2423 vmargscount = m->parseddesc->paramcount;
2425 /* allocate vm_arg array */
2427 vmargs = DMNEW(vm_arg, vmargscount);
2429 /* fill the vm_arg array from a va_list */
2431 vm_vmargs_from_valist(m, o, vmargs, ap);
2433 /* call the Java method */
2435 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2437 /* release dump area */
2439 dump_release(dumpsize);
2445 /* vm_call_method_jvalue *******************************************************
2447 Calls a Java method with a variable number of arguments, passed via
2448 a jvalue array, and returns an address.
2450 *******************************************************************************/
2452 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2457 java_objectheader *ro;
2460 /* mark start of dump memory area */
2462 dumpsize = dump_size();
2464 /* get number of Java method arguments */
2466 vmargscount = m->parseddesc->paramcount;
2468 /* allocate vm_arg array */
2470 vmargs = DMNEW(vm_arg, vmargscount);
2472 /* fill the vm_arg array from a va_list */
2474 vm_vmargs_from_jvalue(m, o, vmargs, args);
2476 /* call the Java method */
2478 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2480 /* release dump area */
2482 dump_release(dumpsize);
2488 /* vm_call_method_vmarg ********************************************************
2490 Calls a Java method with a variable number of arguments, passed via
2491 a vm_arg array, and returns an address.
2493 *******************************************************************************/
2495 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2498 java_objectheader *o;
2500 #if defined(ENABLE_JIT)
2501 # if defined(ENABLE_INTRP)
2503 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2506 o = asm_vm_call_method(m, vmargscount, vmargs);
2508 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2515 /* vm_call_method_int **********************************************************
2517 Calls a Java method with a variable number of arguments and returns
2520 *******************************************************************************/
2522 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2528 i = vm_call_method_int_valist(m, o, ap);
2535 /* vm_call_method_int_valist ***************************************************
2537 Calls a Java method with a variable number of arguments, passed via
2538 a va_list, and returns an integer (s4).
2540 *******************************************************************************/
2542 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2549 /* mark start of dump memory area */
2551 dumpsize = dump_size();
2553 /* get number of Java method arguments */
2555 vmargscount = m->parseddesc->paramcount;
2557 /* allocate vm_arg array */
2559 vmargs = DMNEW(vm_arg, vmargscount);
2561 /* fill the vm_arg array from a va_list */
2563 vm_vmargs_from_valist(m, o, vmargs, ap);
2565 /* call the Java method */
2567 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2569 /* release dump area */
2571 dump_release(dumpsize);
2577 /* vm_call_method_int_jvalue ***************************************************
2579 Calls a Java method with a variable number of arguments, passed via
2580 a jvalue array, and returns an integer (s4).
2582 *******************************************************************************/
2584 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2591 /* mark start of dump memory area */
2593 dumpsize = dump_size();
2595 /* get number of Java method arguments */
2597 vmargscount = m->parseddesc->paramcount;
2599 /* allocate vm_arg array */
2601 vmargs = DMNEW(vm_arg, vmargscount);
2603 /* fill the vm_arg array from a va_list */
2605 vm_vmargs_from_jvalue(m, o, vmargs, args);
2607 /* call the Java method */
2609 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2611 /* release dump area */
2613 dump_release(dumpsize);
2619 /* vm_call_method_int_vmarg ****************************************************
2621 Calls a Java method with a variable number of arguments, passed via
2622 a vm_arg array, and returns an integer (s4).
2624 *******************************************************************************/
2626 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2630 #if defined(ENABLE_JIT)
2631 # if defined(ENABLE_INTRP)
2633 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2636 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2638 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2645 /* vm_call_method_long *********************************************************
2647 Calls a Java method with a variable number of arguments and returns
2650 *******************************************************************************/
2652 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2658 l = vm_call_method_long_valist(m, o, ap);
2665 /* vm_call_method_long_valist **************************************************
2667 Calls a Java method with a variable number of arguments, passed via
2668 a va_list, and returns a long (s8).
2670 *******************************************************************************/
2672 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2679 /* mark start of dump memory area */
2681 dumpsize = dump_size();
2683 /* get number of Java method arguments */
2685 vmargscount = m->parseddesc->paramcount;
2687 /* allocate vm_arg array */
2689 vmargs = DMNEW(vm_arg, vmargscount);
2691 /* fill the vm_arg array from a va_list */
2693 vm_vmargs_from_valist(m, o, vmargs, ap);
2695 /* call the Java method */
2697 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2699 /* release dump area */
2701 dump_release(dumpsize);
2707 /* vm_call_method_long_jvalue **************************************************
2709 Calls a Java method with a variable number of arguments, passed via
2710 a jvalue array, and returns a long (s8).
2712 *******************************************************************************/
2714 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2721 /* mark start of dump memory area */
2723 dumpsize = dump_size();
2725 /* get number of Java method arguments */
2727 vmargscount = m->parseddesc->paramcount;
2729 /* allocate vm_arg array */
2731 vmargs = DMNEW(vm_arg, vmargscount);
2733 /* fill the vm_arg array from a va_list */
2735 vm_vmargs_from_jvalue(m, o, vmargs, args);
2737 /* call the Java method */
2739 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2741 /* release dump area */
2743 dump_release(dumpsize);
2749 /* vm_call_method_long_vmarg ***************************************************
2751 Calls a Java method with a variable number of arguments, passed via
2752 a vm_arg array, and returns a long (s8).
2754 *******************************************************************************/
2756 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2760 #if defined(ENABLE_JIT)
2761 # if defined(ENABLE_INTRP)
2763 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2766 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2768 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2775 /* vm_call_method_float ********************************************************
2777 Calls a Java method with a variable number of arguments and returns
2780 *******************************************************************************/
2782 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2788 f = vm_call_method_float_valist(m, o, ap);
2795 /* vm_call_method_float_valist *************************************************
2797 Calls a Java method with a variable number of arguments, passed via
2798 a va_list, and returns a float.
2800 *******************************************************************************/
2802 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2810 /* mark start of dump memory area */
2812 dumpsize = dump_size();
2814 /* get number of Java method arguments */
2816 vmargscount = m->parseddesc->paramcount;
2818 /* allocate vm_arg array */
2820 vmargs = DMNEW(vm_arg, vmargscount);
2822 /* fill the vm_arg array from a va_list */
2824 vm_vmargs_from_valist(m, o, vmargs, ap);
2826 /* call the Java method */
2828 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2830 /* release dump area */
2832 dump_release(dumpsize);
2838 /* vm_call_method_float_jvalue *************************************************
2840 Calls a Java method with a variable number of arguments, passed via
2841 a jvalue array, and returns a float.
2843 *******************************************************************************/
2845 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2853 /* mark start of dump memory area */
2855 dumpsize = dump_size();
2857 /* get number of Java method arguments */
2859 vmargscount = m->parseddesc->paramcount;
2861 /* allocate vm_arg array */
2863 vmargs = DMNEW(vm_arg, vmargscount);
2865 /* fill the vm_arg array from a va_list */
2867 vm_vmargs_from_jvalue(m, o, vmargs, args);
2869 /* call the Java method */
2871 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2873 /* release dump area */
2875 dump_release(dumpsize);
2881 /* vm_call_method_float_vmarg **************************************************
2883 Calls a Java method with a variable number of arguments and returns
2886 *******************************************************************************/
2888 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2892 #if defined(ENABLE_JIT)
2893 # if defined(ENABLE_INTRP)
2895 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2898 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2900 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2907 /* vm_call_method_double *******************************************************
2909 Calls a Java method with a variable number of arguments and returns
2912 *******************************************************************************/
2914 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2920 d = vm_call_method_double_valist(m, o, ap);
2927 /* vm_call_method_double_valist ************************************************
2929 Calls a Java method with a variable number of arguments, passed via
2930 a va_list, and returns a double.
2932 *******************************************************************************/
2934 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2942 /* mark start of dump memory area */
2944 dumpsize = dump_size();
2946 /* get number of Java method arguments */
2948 vmargscount = m->parseddesc->paramcount;
2950 /* allocate vm_arg array */
2952 vmargs = DMNEW(vm_arg, vmargscount);
2954 /* fill the vm_arg array from a va_list */
2956 vm_vmargs_from_valist(m, o, vmargs, ap);
2958 /* call the Java method */
2960 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2962 /* release dump area */
2964 dump_release(dumpsize);
2970 /* vm_call_method_double_jvalue ************************************************
2972 Calls a Java method with a variable number of arguments, passed via
2973 a jvalue array, and returns a double.
2975 *******************************************************************************/
2977 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2985 /* mark start of dump memory area */
2987 dumpsize = dump_size();
2989 /* get number of Java method arguments */
2991 vmargscount = m->parseddesc->paramcount;
2993 /* allocate vm_arg array */
2995 vmargs = DMNEW(vm_arg, vmargscount);
2997 /* fill the vm_arg array from a va_list */
2999 vm_vmargs_from_jvalue(m, o, vmargs, args);
3001 /* call the Java method */
3003 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
3005 /* release dump area */
3007 dump_release(dumpsize);
3013 /* vm_call_method_double_vmarg *************************************************
3015 Calls a Java method with a variable number of arguments and returns
3018 *******************************************************************************/
3020 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
3025 #if defined(ENABLE_JIT)
3026 # if defined(ENABLE_INTRP)
3028 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3031 d = asm_vm_call_method_double(m, vmargscount, vmargs);
3033 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3041 * These are local overrides for various environment variables in Emacs.
3042 * Please do not remove this and leave it at the end of the file, where
3043 * Emacs will automagically detect them.
3044 * ---------------------------------------------------------------------
3047 * indent-tabs-mode: t