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 8179 2007-07-05 11:21:08Z michi $
37 #if defined(WITH_JRE_LAYOUT)
47 #include "vm/jit/abi-asm.h"
49 #include "mm/gc-common.h"
50 #include "mm/memory.h"
52 #include "native/jni.h"
53 #include "native/native.h"
55 #include "native/include/java_lang_Object.h" /* required by j.l.C */
56 #include "native/include/java_lang_String.h" /* required by j.l.C */
58 #if defined(WITH_CLASSPATH_SUN)
59 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
60 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
63 #include "native/include/java_lang_Class.h"
65 #include "native/include/java_lang_Byte.h"
66 #include "native/include/java_lang_Character.h"
67 #include "native/include/java_lang_Short.h"
68 #include "native/include/java_lang_Integer.h"
69 #include "native/include/java_lang_Boolean.h"
70 #include "native/include/java_lang_Long.h"
71 #include "native/include/java_lang_Float.h"
72 #include "native/include/java_lang_Double.h"
74 #include "native/vm/nativevm.h"
76 #include "threads/threads-common.h"
78 #include "toolbox/logging.h"
80 #include "vm/builtin.h"
81 #include "vm/exceptions.h"
82 #include "vm/finalizer.h"
83 #include "vm/global.h"
84 #include "vm/initialize.h"
85 #include "vm/properties.h"
86 #include "vm/signallocal.h"
87 #include "vm/stringlocal.h"
90 #include "vm/jit/jit.h"
91 #include "vm/jit/md.h"
92 #include "vm/jit/asmpart.h"
94 #if defined(ENABLE_PROFILING)
95 # include "vm/jit/optimizing/profile.h"
98 #include "vm/jit/optimizing/recompile.h"
100 #include "vmcore/classcache.h"
101 #include "vmcore/options.h"
102 #include "vmcore/primitive.h"
103 #include "vmcore/statistics.h"
104 #include "vmcore/suck.h"
106 #if defined(ENABLE_JVMTI)
107 # include "native/jvmti/cacaodbg.h"
110 #if defined(ENABLE_VMLOG)
111 #include <vmlog_cacao.h>
115 /* Invocation API variables ***************************************************/
117 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
118 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
121 /* global variables ***********************************************************/
123 s4 vms = 0; /* number of VMs created */
125 bool vm_initializing = false;
126 bool vm_exiting = false;
128 char *cacao_prefix = NULL;
129 char *cacao_libjvm = NULL;
130 char *classpath_libdir = NULL;
132 char *_Jv_bootclasspath; /* contains the boot classpath */
133 char *_Jv_classpath; /* contains the classpath */
134 char *_Jv_java_library_path;
136 char *mainstring = NULL;
137 classinfo *mainclass = NULL;
139 char *specificmethodname = NULL;
140 char *specificsignature = NULL;
144 #if defined(ENABLE_INTRP)
145 u1 *intrp_main_stack = NULL;
149 /* define heap sizes **********************************************************/
151 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
152 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
153 #define STACK_SIZE 64 * 1024 /* default 64kB */
156 /* define command line options ************************************************/
187 /* Java non-standard options */
198 #if defined(ENABLE_PROFILING)
211 #if defined(ENABLE_STATISTICS)
228 #if defined(ENABLE_VERIFIER)
230 #if defined(TYPECHECK_VERBOSE)
233 #endif /* defined(ENABLE_VERIFIER) */
236 /* optimization options */
238 #if defined(ENABLE_LOOP)
242 #if defined(ENABLE_IFCONV)
246 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
250 #if defined(ENABLE_INLINING)
255 #if defined(ENABLE_INLINING_DEBUG)
256 OPT_INLINE_DEBUG_ALL,
257 OPT_INLINE_DEBUG_END,
258 OPT_INLINE_DEBUG_MIN,
259 OPT_INLINE_DEBUG_MAX,
260 OPT_INLINE_REPLACE_VERBOSE,
261 OPT_INLINE_REPLACE_VERBOSE2,
262 #endif /* defined(ENABLE_INLINING_DEBUG) */
263 #endif /* defined(ENABLE_INLINING) */
265 #if defined(ENABLE_INTRP)
266 /* interpreter options */
285 #if defined(ENABLE_DEBUG_FILTER)
286 OPT_FILTER_VERBOSECALL_INCLUDE,
287 OPT_FILTER_VERBOSECALL_EXCLUDE,
288 OPT_FILTER_SHOW_METHOD,
295 opt_struct opts[] = {
296 { "foo", false, OPT_FOO },
300 { "jar", false, OPT_JAR },
302 { "d32", false, OPT_D32 },
303 { "d64", false, OPT_D64 },
304 { "client", false, OPT_IGNORE },
305 { "server", false, OPT_IGNORE },
306 { "jvm", false, OPT_IGNORE },
307 { "hotspot", false, OPT_IGNORE },
309 { "classpath", true, OPT_CLASSPATH },
310 { "cp", true, OPT_CLASSPATH },
311 { "D", true, OPT_D },
312 { "version", false, OPT_VERSION },
313 { "showversion", false, OPT_SHOWVERSION },
314 { "fullversion", false, OPT_FULLVERSION },
315 { "help", false, OPT_HELP },
316 { "?", false, OPT_HELP },
317 { "X", false, OPT_X },
318 { "XX:", true, OPT_XX },
320 { "ea:", true, OPT_EA },
321 { "da:", true, OPT_DA },
322 { "ea", false, OPT_EA },
323 { "da", false, OPT_DA },
325 { "esa", false, OPT_ESA },
326 { "enablesystemassertions", false, OPT_ESA },
327 { "dsa", false, OPT_DSA },
328 { "disablesystemassertions", false, OPT_DSA },
330 { "noasyncgc", false, OPT_IGNORE },
331 #if defined(ENABLE_VERIFIER)
332 { "noverify", false, OPT_NOVERIFY },
334 { "v", false, OPT_VERBOSE1 },
335 { "verbose:", true, OPT_VERBOSE },
337 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
338 { "verbosetc", false, OPT_VERBOSETC },
340 #if defined(__ALPHA__)
341 { "noieee", false, OPT_NOIEEE },
343 #if defined(ENABLE_STATISTICS)
344 { "time", false, OPT_TIME },
345 { "stat", false, OPT_STAT },
347 { "log", true, OPT_LOG },
348 { "c", true, OPT_CHECK },
349 { "l", false, OPT_LOAD },
350 { "eager", false, OPT_EAGER },
353 { "all", false, OPT_ALL },
354 { "sig", true, OPT_SIGNATURE },
357 #if defined(ENABLE_LOOP)
358 { "oloop", false, OPT_OLOOP },
360 #if defined(ENABLE_IFCONV)
361 { "ifconv", false, OPT_IFCONV },
363 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
364 { "lsra", false, OPT_LSRA },
367 #if defined(ENABLE_INTRP)
368 /* interpreter options */
370 { "trace", false, OPT_TRACE },
371 { "static-supers", true, OPT_STATIC_SUPERS },
372 { "no-dynamic", false, OPT_NO_DYNAMIC },
373 { "no-replication", false, OPT_NO_REPLICATION },
374 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
377 /* JVMTI Agent Command Line Options */
379 { "agentlib:", true, OPT_AGENTLIB },
380 { "agentpath:", true, OPT_AGENTPATH },
383 /* Java non-standard options */
385 { "Xjit", false, OPT_JIT },
386 { "Xint", false, OPT_INTRP },
387 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
388 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
389 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
390 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
393 { "Xdebug", false, OPT_DEBUG },
394 { "Xnoagent", false, OPT_NOAGENT },
395 { "Xrunjdwp", true, OPT_XRUNJDWP },
398 { "Xms", true, OPT_MS },
399 { "ms", true, OPT_MS },
400 { "Xmx", true, OPT_MX },
401 { "mx", true, OPT_MX },
402 { "Xss", true, OPT_SS },
403 { "ss", true, OPT_SS },
405 #if defined(ENABLE_PROFILING)
406 { "Xprof:", true, OPT_PROF_OPTION },
407 { "Xprof", false, OPT_PROF },
410 /* inlining options */
412 #if defined(ENABLE_INLINING)
413 #if defined(ENABLE_INLINING_DEBUG)
414 { "ia", false, OPT_INLINE_DEBUG_ALL },
415 { "ii", true, OPT_INLINE_DEBUG_MIN },
416 { "im", true, OPT_INLINE_DEBUG_MAX },
417 { "ie", true, OPT_INLINE_DEBUG_END },
418 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
419 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
420 #endif /* defined(ENABLE_INLINING_DEBUG) */
422 { "il", false, OPT_INLINE_LOG },
424 { "i", false, OPT_INLINING },
425 #endif /* defined(ENABLE_INLINING) */
427 /* keep these at the end of the list */
430 { "m", true, OPT_METHOD },
433 { "s", true, OPT_SHOW },
434 { "debug-color", false, OPT_DEBUGCOLOR },
436 #if defined(ENABLE_DEBUG_FILTER)
437 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
438 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
439 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
446 /* usage ***********************************************************************
448 Prints the correct usage syntax to stdout.
450 *******************************************************************************/
454 puts("Usage: cacao [-options] classname [arguments]");
455 puts(" (to run a class file)");
456 puts(" or cacao [-options] -jar jarfile [arguments]");
457 puts(" (to run a standalone jar file)\n");
459 puts("where options include:");
460 puts(" -d32 use 32-bit data model if available");
461 puts(" -d64 use 64-bit data model if available");
462 puts(" -client compatibility (currently ignored)");
463 puts(" -server compatibility (currently ignored)");
464 puts(" -jvm compatibility (currently ignored)");
465 puts(" -hotspot compatibility (currently ignored)\n");
467 puts(" -cp <path> specify a path to look for classes");
468 puts(" -classpath <path> specify a path to look for classes");
469 puts(" -D<name>=<value> add an entry to the property list");
470 puts(" -verbose[:class|gc|jni] enable specific verbose output");
471 puts(" -version print product version and exit");
472 puts(" -fullversion print jpackage-compatible product version and exit");
473 puts(" -showversion print product version and continue");
474 puts(" -help, -? print this help message");
475 puts(" -X print help on non-standard Java options");
476 puts(" -XX print help on CACAO options");
477 puts(" -ea[:<packagename>...|:<classname>]");
478 puts(" -enableassertions[:<packagename>...|:<classname>]");
479 puts(" enable assertions with specified granularity");
480 puts(" -da[:<packagename>...|:<classname>]");
481 puts(" -disableassertions[:<packagename>...|:<classname>]");
482 puts(" disable assertions with specified granularity");
483 puts(" -esa | -enablesystemassertions");
484 puts(" enable system assertions");
485 puts(" -dsa | -disablesystemassertions");
486 puts(" disable system assertions");
489 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
490 puts (" for jdwp help use: -agentlib:jdwp=help");
491 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
494 /* exit with error code */
500 static void Xusage(void)
502 #if defined(ENABLE_JIT)
503 puts(" -Xjit JIT mode execution (default)");
505 #if defined(ENABLE_INTRP)
506 puts(" -Xint interpreter mode execution");
508 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
509 puts(" value is set as bootstrap class path");
510 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
511 puts(" value is appended to the bootstrap class path");
512 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
513 puts(" value is prepended to the bootstrap class path");
514 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
515 puts(" value is used as Java core library, but the");
516 puts(" hardcoded VM interface classes are prepended");
517 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
518 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
519 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
521 #if defined(ENABLE_PROFILING)
522 puts(" -Xprof[:bb] collect and print profiling data");
525 #if defined(ENABLE_JVMTI)
526 /* -Xdebug option depend on gnu classpath JDWP options. options:
527 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
528 puts(" -Xdebug enable remote debugging\n");
529 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
530 puts(" enable remote debugging\n");
533 /* exit with error code */
539 static void XXusage(void)
541 puts(" -v write state-information");
543 puts(" -verbose[:call|jit|threads]");
544 puts(" enable specific verbose output");
545 puts(" -debug-color colored output for ANSI terms");
547 #ifdef TYPECHECK_VERBOSE
548 puts(" -verbosetc write debug messages while typechecking");
550 #if defined(__ALPHA__)
551 puts(" -noieee don't use ieee compliant arithmetic");
553 #if defined(ENABLE_VERIFIER)
554 puts(" -noverify don't verify classfiles");
556 #if defined(ENABLE_STATISTICS)
557 puts(" -time measure the runtime");
558 puts(" -stat detailed compiler statistics");
560 puts(" -log logfile specify a name for the logfile");
561 puts(" -c(heck)b(ounds) don't check array bounds");
562 puts(" s(ync) don't check for synchronization");
563 #if defined(ENABLE_LOOP)
564 puts(" -oloop optimize array accesses in loops");
566 puts(" -l don't start the class after loading");
567 puts(" -eager perform eager class loading and linking");
569 puts(" -all compile all methods, no execution");
570 puts(" -m compile only a specific method");
571 puts(" -sig specify signature for a specific method");
574 puts(" -s... show...");
575 puts(" (c)onstants the constant pool");
576 puts(" (m)ethods class fields and methods");
577 puts(" (u)tf the utf - hash");
578 puts(" (i)ntermediate intermediate representation");
579 #if defined(ENABLE_DISASSEMBLER)
580 puts(" (a)ssembler disassembled listing");
581 puts(" n(o)ps show NOPs in disassembler output");
582 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
583 puts(" (n)ative disassembled native stubs");
585 puts(" (d)atasegment data segment listing");
587 #if defined(ENABLE_INLINING)
588 puts(" -i activate inlining");
590 puts(" -il log inlining");
592 #if defined(ENABLE_INLINING_DEBUG)
593 puts(" -ia use inlining for all methods");
594 puts(" -ii <size> set minimum size for inlined result");
595 puts(" -im <size> set maximum size for inlined result");
596 puts(" -ie <number> stop inlining after the given number of roots");
597 puts(" -ir log on-stack replacement");
598 puts(" -iR log on-stack replacement, more verbose");
599 #endif /* defined(ENABLE_INLINING_DEBUG) */
600 #endif /* defined(ENABLE_INLINING) */
602 #if defined(ENABLE_IFCONV)
603 puts(" -ifconv use if-conversion");
605 #if defined(ENABLE_LSRA)
606 puts(" -lsra use linear scan register allocation");
608 #if defined(ENABLE_SSA)
609 puts(" -lsra use linear scan register allocation (with SSA)");
611 #if defined(ENABLE_DEBUG_FILTER)
612 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
613 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
614 puts(" -XXfm <regex> filter for show options");
616 /* exit with error code */
622 /* version *********************************************************************
624 Only prints cacao version information.
626 *******************************************************************************/
628 static void version(bool opt_exit)
630 puts("java version \""JAVA_VERSION"\"");
631 puts("CACAO version "VERSION"");
633 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
634 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
635 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
636 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
638 puts("This program is free software; you can redistribute it and/or");
639 puts("modify it under the terms of the GNU General Public License as");
640 puts("published by the Free Software Foundation; either version 2, or (at");
641 puts("your option) any later version.\n");
643 puts("This program is distributed in the hope that it will be useful, but");
644 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
645 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
646 puts("General Public License for more details.\n");
648 puts("Configure/Build options:\n");
649 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
650 #if defined(__VERSION__)
651 puts(" CC : "VERSION_CC" ("__VERSION__")");
653 puts(" CC : "VERSION_CC"");
655 puts(" CFLAGS : "VERSION_CFLAGS"\n");
657 puts("Default variables:\n");
658 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
659 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
660 printf(" stack size : %d\n", STACK_SIZE);
661 #if defined(WITH_CLASSPATH_GNU)
662 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
664 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
666 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
668 puts("Runtime variables:\n");
669 printf(" maximum heap size : %d\n", opt_heapmaxsize);
670 printf(" initial heap size : %d\n", opt_heapstartsize);
671 printf(" stack size : %d\n", opt_stacksize);
672 printf(" libjvm.so : %s\n", cacao_libjvm);
673 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
674 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
675 printf(" java.class.path : %s\n", _Jv_classpath);
677 /* exit normally, if requested */
684 /* fullversion *****************************************************************
686 Prints a Sun compatible version information (required e.g. by
687 jpackage, www.jpackage.org).
689 *******************************************************************************/
691 static void fullversion(void)
693 puts("java full version \"cacao-"JAVA_VERSION"\"");
701 /* forward declarations *******************************************************/
703 static char *vm_get_mainclass_from_jar(char *mainstring);
705 static void vm_compile_all(void);
706 static void vm_compile_method(void);
710 /* vm_createjvm ****************************************************************
712 Implementation for JNI_CreateJavaVM.
714 *******************************************************************************/
716 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
718 JavaVMInitArgs *_vm_args;
722 /* get the arguments for the new JVM */
724 _vm_args = (JavaVMInitArgs *) vm_args;
726 /* get the VM and Env tables (must be set before vm_create) */
728 env = NEW(_Jv_JNIEnv);
730 #if defined(ENABLE_JNI)
731 env->env = &_Jv_JNINativeInterface;
734 /* XXX Set the global variable. Maybe we should do that differently. */
738 /* create and fill a JavaVM structure */
740 vm = NEW(_Jv_JavaVM);
742 #if defined(ENABLE_JNI)
743 vm->functions = &_Jv_JNIInvokeInterface;
746 /* XXX Set the global variable. Maybe we should do that differently. */
747 /* XXX JVMTI Agents needs a JavaVM */
751 /* actually create the JVM */
753 if (!vm_create(_vm_args))
756 #if defined(ENABLE_JNI)
757 /* setup the local ref table (must be created after vm_create) */
759 if (!jni_init_localref_table())
763 /* now return the values */
765 *p_vm = (JavaVM *) vm;
766 *p_env = (void *) env;
771 /* release allocated memory */
773 FREE(env, _Jv_JNIEnv);
774 FREE(vm, _Jv_JavaVM);
780 /* vm_create *******************************************************************
782 Creates a JVM. Called by vm_createjvm.
784 *******************************************************************************/
786 bool vm_create(JavaVMInitArgs *vm_args)
795 #if defined(ENABLE_JVMTI)
797 char *libname, *agentarg;
798 bool jdwp,agentbypath;
799 jdwp = agentbypath = false;
802 #if defined(ENABLE_VMLOG)
803 vmlog_cacao_init(vm_args);
806 /* check the JNI version requested */
808 switch (vm_args->version) {
809 case JNI_VERSION_1_1:
811 case JNI_VERSION_1_2:
812 case JNI_VERSION_1_4:
818 /* we only support 1 JVM instance */
823 if (atexit(vm_exit_handler))
824 vm_abort("atexit failed: %s\n", strerror(errno));
827 log_text("CACAO started -------------------------------------------------------");
829 /* We need to check if the actual size of a java.lang.Class object
830 is smaller or equal than the assumption made in
831 src/vmcore/class.h. */
833 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
834 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
836 /* set the VM starttime */
838 _Jv_jvm->starttime = builtin_currenttimemillis();
840 /* get stuff from the environment *****************************************/
842 #if defined(WITH_JRE_LAYOUT)
843 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
845 cacao_prefix = MNEW(char, 4096);
847 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
848 vm_abort("readlink failed: %s\n", strerror(errno));
850 /* get the path of the current executable */
852 cacao_prefix = dirname(cacao_prefix);
854 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
855 vm_abort("libjvm name to long for buffer\n");
857 /* concatenate the library name */
859 strcat(cacao_prefix, "/..");
861 /* now set path to libjvm.so */
863 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
865 cacao_libjvm = MNEW(char, len);
866 strcpy(cacao_libjvm, cacao_prefix);
867 strcat(cacao_libjvm, "/lib/libjvm");
869 /* and finally set the path to GNU Classpath libraries */
871 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
873 classpath_libdir = MNEW(char, len);
874 strcpy(classpath_libdir, cacao_prefix);
875 strcat(classpath_libdir, "/lib/classpath");
877 cacao_prefix = CACAO_PREFIX;
878 cacao_libjvm = CACAO_LIBDIR"/libjvm";
880 # if defined(WITH_CLASSPATH_GNU)
881 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
883 classpath_libdir = CLASSPATH_LIBDIR;
887 /* set the bootclasspath */
889 cp = getenv("BOOTCLASSPATH");
892 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
893 strcpy(_Jv_bootclasspath, cp);
896 #if defined(WITH_JRE_LAYOUT)
898 # if defined(WITH_CLASSPATH_GNU)
899 strlen(cacao_prefix) +
900 strlen("/share/cacao/vm.zip") +
903 strlen(cacao_prefix) +
904 strlen("/share/classpath/glibj.zip") +
907 _Jv_bootclasspath = MNEW(char, len);
908 # if defined(WITH_CLASSPATH_GNU)
909 strcat(_Jv_bootclasspath, cacao_prefix);
910 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
911 strcat(_Jv_bootclasspath, ":");
913 strcat(_Jv_bootclasspath, cacao_prefix);
914 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
917 # if defined(WITH_CLASSPATH_GNU)
918 strlen(CACAO_VM_ZIP) +
921 strlen(CLASSPATH_CLASSES) +
924 _Jv_bootclasspath = MNEW(char, len);
925 # if defined(WITH_CLASSPATH_GNU)
926 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
927 strcat(_Jv_bootclasspath, ":");
929 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
933 /* set the classpath */
935 cp = getenv("CLASSPATH");
938 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
939 strcat(_Jv_classpath, cp);
942 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
943 strcpy(_Jv_classpath, ".");
946 /* get and set java.library.path */
948 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
950 if (_Jv_java_library_path == NULL)
951 _Jv_java_library_path = "";
953 /* interpret the options **************************************************/
960 opt_heapmaxsize = HEAP_MAXSIZE;
961 opt_heapstartsize = HEAP_STARTSIZE;
962 opt_stacksize = STACK_SIZE;
965 #if defined(ENABLE_JVMTI)
966 /* initialize JVMTI related **********************************************/
970 /* initialize and fill properties before command-line handling */
972 if (!properties_init())
973 vm_abort("properties_init failed");
975 /* iterate over all passed options */
977 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
991 #if SIZEOF_VOID_P == 8
992 puts("Running a 32-bit JVM is not supported on this platform.");
998 #if SIZEOF_VOID_P == 4
999 puts("Running a 64-bit JVM is not supported on this platform.");
1005 /* forget old classpath and set the argument as new classpath */
1006 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1008 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
1009 strcpy(_Jv_classpath, opt_arg);
1013 for (i = 0; i < strlen(opt_arg); i++) {
1014 if (opt_arg[i] == '=') {
1016 properties_add(opt_arg, opt_arg + i + 1);
1021 /* if no '=' is given, just create an empty property */
1023 properties_add(opt_arg, "");
1028 case OPT_BOOTCLASSPATH:
1029 /* Forget default bootclasspath and set the argument as
1030 new boot classpath. */
1032 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1034 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
1035 strcpy(_Jv_bootclasspath, opt_arg);
1038 case OPT_BOOTCLASSPATH_A:
1039 /* append to end of bootclasspath */
1041 len = strlen(_Jv_bootclasspath);
1043 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
1047 strlen(opt_arg) + strlen("0"));
1049 strcat(_Jv_bootclasspath, ":");
1050 strcat(_Jv_bootclasspath, opt_arg);
1053 case OPT_BOOTCLASSPATH_P:
1054 /* prepend in front of bootclasspath */
1056 cp = _Jv_bootclasspath;
1059 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1062 strcpy(_Jv_bootclasspath, opt_arg);
1063 strcat(_Jv_bootclasspath, ":");
1064 strcat(_Jv_bootclasspath, cp);
1066 MFREE(cp, char, len);
1069 case OPT_BOOTCLASSPATH_C:
1070 /* use as Java core library, but prepend VM interface classes */
1072 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1074 len = strlen(CACAO_VM_ZIP) +
1079 _Jv_bootclasspath = MNEW(char, len);
1081 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1082 strcat(_Jv_bootclasspath, ":");
1083 strcat(_Jv_bootclasspath, opt_arg);
1086 #if defined(ENABLE_JVMTI)
1088 /* this option exists only for compatibility reasons */
1092 /* I don't know yet what Xnoagent should do. This is only for
1093 compatiblity with eclipse - motse */
1102 strlen(CACAO_LIBDIR) +
1103 strlen("/libjdwp.so=") +
1107 agentarg = MNEW(char, len);
1109 strcpy(agentarg, CACAO_LIBDIR);
1110 strcat(agentarg, "/libjdwp.so=");
1111 strcat(agentarg, &opt_arg[1]);
1128 c = opt_arg[strlen(opt_arg) - 1];
1130 if ((c == 'k') || (c == 'K')) {
1131 j = atoi(opt_arg) * 1024;
1133 } else if ((c == 'm') || (c == 'M')) {
1134 j = atoi(opt_arg) * 1024 * 1024;
1140 opt_heapmaxsize = j;
1141 else if (opt == OPT_MS)
1142 opt_heapstartsize = j;
1153 if (strcmp("class", opt_arg) == 0) {
1154 opt_verboseclass = true;
1156 else if (strcmp("gc", opt_arg) == 0) {
1157 opt_verbosegc = true;
1159 else if (strcmp("jni", opt_arg) == 0) {
1160 opt_verbosejni = true;
1162 #if !defined(NDEBUG)
1163 else if (strcmp("call", opt_arg) == 0) {
1164 opt_verbosecall = true;
1166 else if (strcmp("jit", opt_arg) == 0) {
1171 compileverbose = true;
1173 else if (strcmp("threads", opt_arg) == 0) {
1174 opt_verbosethreads = true;
1178 printf("Unknown -verbose option: %s\n", opt_arg);
1183 case OPT_DEBUGCOLOR:
1184 opt_debugcolor = true;
1187 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1189 opt_typecheckverbose = true;
1198 case OPT_FULLVERSION:
1202 case OPT_SHOWVERSION:
1210 #if defined(ENABLE_VERIFIER)
1216 #if defined(ENABLE_STATISTICS)
1218 opt_getcompilingtime = true;
1219 opt_getloadingtime = true;
1232 for (i = 0; i < strlen(opt_arg); i++) {
1233 switch (opt_arg[i]) {
1235 checkbounds = false;
1248 makeinitializations = false;
1255 #if !defined(NDEBUG)
1259 makeinitializations = false;
1264 opt_method = opt_arg;
1265 makeinitializations = false;
1269 opt_signature = opt_arg;
1273 case OPT_SHOW: /* Display options */
1274 for (i = 0; i < strlen(opt_arg); i++) {
1275 switch (opt_arg[i]) {
1277 showconstantpool = true;
1289 opt_showintermediate = true;
1290 compileverbose = true;
1293 #if defined(ENABLE_DISASSEMBLER)
1295 opt_showdisassemble = true;
1296 compileverbose = true;
1300 opt_shownops = true;
1304 opt_showexceptionstubs = true;
1308 opt_shownativestub = true;
1313 opt_showddatasegment = true;
1322 #if defined(ENABLE_LOOP)
1328 #if defined(ENABLE_INLINING)
1329 #if defined(ENABLE_INLINING_DEBUG)
1330 case OPT_INLINE_DEBUG_ALL:
1331 opt_inline_debug_all = true;
1333 case OPT_INLINE_DEBUG_END:
1334 opt_inline_debug_end_counter = atoi(opt_arg);
1336 case OPT_INLINE_DEBUG_MIN:
1337 opt_inline_debug_min_size = atoi(opt_arg);
1339 case OPT_INLINE_DEBUG_MAX:
1340 opt_inline_debug_max_size = atoi(opt_arg);
1342 case OPT_INLINE_REPLACE_VERBOSE:
1343 opt_replace_verbose = 1;
1345 case OPT_INLINE_REPLACE_VERBOSE2:
1346 opt_replace_verbose = 2;
1348 #endif /* defined(ENABLE_INLINING_DEBUG) */
1349 #if !defined(NDEBUG)
1350 case OPT_INLINE_LOG:
1351 opt_inline_debug_log = true;
1353 #endif /* !defined(NDEBUG) */
1356 opt_inlining = true;
1358 #endif /* defined(ENABLE_INLINING) */
1360 #if defined(ENABLE_IFCONV)
1366 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1381 options_xx(opt_arg);
1385 /* currently ignored */
1389 /* currently ignored */
1393 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1397 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1400 #if defined(ENABLE_PROFILING)
1401 case OPT_PROF_OPTION:
1402 /* use <= to get the last \0 too */
1404 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1405 if (opt_arg[i] == ',')
1408 if (opt_arg[i] == '\0') {
1409 if (strcmp("bb", opt_arg + j) == 0)
1413 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1417 /* set k to next char */
1430 #if defined(ENABLE_JIT)
1433 printf("-Xjit option not enabled.\n");
1439 #if defined(ENABLE_INTRP)
1442 printf("-Xint option not enabled.\n");
1447 #if defined(ENABLE_INTRP)
1448 case OPT_STATIC_SUPERS:
1449 opt_static_supers = atoi(opt_arg);
1452 case OPT_NO_DYNAMIC:
1453 opt_no_dynamic = true;
1456 case OPT_NO_REPLICATION:
1457 opt_no_replication = true;
1460 case OPT_NO_QUICKSUPER:
1461 opt_no_quicksuper = true;
1469 #if defined(ENABLE_DEBUG_FILTER)
1470 case OPT_FILTER_VERBOSECALL_INCLUDE:
1471 opt_filter_verbosecall_include = opt_arg;
1474 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1475 opt_filter_verbosecall_exclude = opt_arg;
1478 case OPT_FILTER_SHOW_METHOD:
1479 opt_filter_show_method = opt_arg;
1484 printf("Unknown option: %s\n",
1485 vm_args->options[opt_index].optionString);
1490 /* get the main class *****************************************************/
1492 if (opt_index < vm_args->nOptions) {
1493 mainstring = vm_args->options[opt_index++].optionString;
1495 /* Put the jar file into the classpath (if any). */
1497 if (opt_jar == true) {
1498 /* free old classpath */
1500 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1502 /* put jarfile into classpath */
1504 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1506 strcpy(_Jv_classpath, mainstring);
1509 /* replace .'s with /'s in classname */
1511 for (i = strlen(mainstring) - 1; i >= 0; i--)
1512 if (mainstring[i] == '.')
1513 mainstring[i] = '/';
1517 #if defined(ENABLE_JVMTI)
1519 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1520 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1523 MFREE(agentarg, char, strlen(agentarg));
1525 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1529 /* initialize this JVM ****************************************************/
1531 vm_initializing = true;
1533 /* initialize the garbage collector */
1535 gc_init(opt_heapmaxsize, opt_heapstartsize);
1537 #if defined(ENABLE_THREADS)
1538 /* AFTER: gc_init (directly after, as this initializes the
1539 stopworldlock lock */
1544 /* install architecture dependent signal handlers */
1547 vm_abort("vm_create: signal_init failed");
1549 #if defined(ENABLE_INTRP)
1550 /* Allocate main thread stack on the Java heap. */
1553 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1554 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1558 /* AFTER: threads_preinit */
1561 vm_abort("vm_create: string_init failed");
1563 /* AFTER: threads_preinit */
1566 vm_abort("vm_create: utf8_init failed");
1568 /* AFTER: thread_preinit */
1571 vm_abort("vm_create: suck_init failed");
1573 suck_add_from_property("java.endorsed.dirs");
1575 /* Now we have all options handled and we can print the version
1578 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1583 /* AFTER: utf8_init */
1585 suck_add(_Jv_bootclasspath);
1587 /* Now re-set some of the properties that may have changed. This
1588 must be done after _all_ environment variables have been
1589 processes (e.g. -jar handling).
1591 AFTER: suck_add_from_property, since it may change the
1592 _Jv_bootclasspath pointer. */
1594 if (!properties_postinit())
1595 vm_abort("vm_create: properties_postinit failed");
1597 /* initialize the classcache hashtable stuff: lock, hashtable
1598 (must be done _after_ threads_preinit) */
1600 if (!classcache_init())
1601 vm_abort("vm_create: classcache_init failed");
1603 /* initialize the memory subsystem (must be done _after_
1607 vm_abort("vm_create: memory_init failed");
1609 /* initialize the finalizer stuff (must be done _after_
1612 if (!finalizer_init())
1613 vm_abort("vm_create: finalizer_init failed");
1615 /* initialize the codegen subsystems */
1619 /* initializes jit compiler */
1623 /* machine dependent initialization */
1625 #if defined(ENABLE_JIT)
1626 # if defined(ENABLE_INTRP)
1636 /* initialize the loader subsystems (must be done _after_
1640 vm_abort("vm_create: loader_init failed");
1642 /* Link some important VM classes. */
1643 /* AFTER: utf8_init */
1646 vm_abort("vm_create: linker_init failed");
1648 if (!primitive_init())
1649 vm_abort("vm_create: primitive_init failed");
1651 if (!exceptions_init())
1652 vm_abort("vm_create: exceptions_init failed");
1654 if (!builtin_init())
1655 vm_abort("vm_create: builtin_init failed");
1657 /* Initialize the native subsystem. */
1658 /* BEFORE: threads_init */
1661 vm_abort("vm_create: native_init failed");
1663 /* Register the native methods implemented in the VM. */
1664 /* BEFORE: threads_init */
1666 if (!nativevm_preinit())
1667 vm_abort("vm_create: nativevm_preinit failed");
1669 #if defined(ENABLE_JNI)
1670 /* Initialize the JNI subsystem (must be done _before_
1671 threads_init, as threads_init can call JNI methods
1672 (e.g. NewGlobalRef). */
1675 vm_abort("vm_create: jni_init failed");
1678 #if defined(ENABLE_THREADS)
1679 if (!threads_init())
1680 vm_abort("vm_create: threads_init failed");
1683 /* Initialize the native VM subsystem. */
1684 /* AFTER: threads_init (at least for SUN's classes) */
1686 if (!nativevm_init())
1687 vm_abort("vm_create: nativevm_init failed");
1689 #if defined(ENABLE_PROFILING)
1690 /* initialize profiling */
1692 if (!profile_init())
1693 vm_abort("vm_create: profile_init failed");
1696 #if defined(ENABLE_THREADS)
1697 /* initialize recompilation */
1699 if (!recompile_init())
1700 vm_abort("vm_create: recompile_init failed");
1702 /* start the signal handler thread */
1704 #if defined(__LINUX__)
1705 /* XXX Remove for exact-GC. */
1706 if (threads_pthreads_implementation_nptl)
1708 if (!signal_start_thread())
1709 vm_abort("vm_create: signal_start_thread failed");
1711 /* finally, start the finalizer thread */
1713 if (!finalizer_start_thread())
1714 vm_abort("vm_create: finalizer_start_thread failed");
1716 # if !defined(NDEBUG)
1717 /* start the memory profiling thread */
1719 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1720 if (!memory_start_thread())
1721 vm_abort("vm_create: memory_start_thread failed");
1724 /* start the recompilation thread (must be done before the
1725 profiling thread) */
1727 if (!recompile_start_thread())
1728 vm_abort("vm_create: recompile_start_thread failed");
1730 # if defined(ENABLE_PROFILING)
1731 /* start the profile sampling thread */
1734 /* if (!profile_start_thread()) */
1735 /* vm_abort("vm_create: profile_start_thread failed"); */
1739 #if defined(ENABLE_JVMTI)
1740 # if defined(ENABLE_GC_CACAO)
1741 /* XXX this will not work with the new indirection cells for classloaders!!! */
1745 /* add agent library to native library hashtable */
1746 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1750 /* increment the number of VMs */
1754 /* initialization is done */
1756 vm_initializing = false;
1758 /* everything's ok */
1764 /* vm_run **********************************************************************
1766 Runs the main-method of the passed class.
1768 *******************************************************************************/
1770 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1773 classinfo *mainclass;
1774 java_objectheader *e;
1776 java_objectarray *oa;
1779 java_objectheader *s;
1783 #if !defined(NDEBUG)
1789 if (opt_method != NULL) {
1790 vm_compile_method();
1793 #endif /* !defined(NDEBUG) */
1795 /* should we run the main-method? */
1797 if (mainstring == NULL)
1800 /* set return value to OK */
1804 if (opt_jar == true) {
1805 /* open jar file with java.util.jar.JarFile */
1807 mainstring = vm_get_mainclass_from_jar(mainstring);
1809 if (mainstring == NULL)
1813 /* load the main class */
1815 mainutf = utf_new_char(mainstring);
1817 #if defined(ENABLE_JAVAME_CLDC1_1)
1818 mainclass = load_class_bootstrap(mainutf);
1820 mainclass = load_class_from_sysloader(mainutf);
1823 /* error loading class */
1825 e = exceptions_get_and_clear_exception();
1827 if ((e != NULL) || (mainclass == NULL)) {
1828 exceptions_throw_noclassdeffounderror_cause(e);
1829 exceptions_print_stacktrace();
1833 if (!link_class(mainclass)) {
1834 exceptions_print_stacktrace();
1838 /* find the `main' method of the main class */
1840 m = class_resolveclassmethod(mainclass,
1841 utf_new_char("main"),
1842 utf_new_char("([Ljava/lang/String;)V"),
1843 class_java_lang_Object,
1846 if (exceptions_get_exception()) {
1847 exceptions_print_stacktrace();
1851 /* there is no main method or it isn't static */
1853 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1854 exceptions_clear_exception();
1855 exceptions_throw_nosuchmethoderror(mainclass,
1856 utf_new_char("main"),
1857 utf_new_char("([Ljava/lang/String;)V"));
1859 exceptions_print_stacktrace();
1863 /* build argument array */
1865 oalength = vm_args->nOptions - opt_index;
1867 oa = builtin_anewarray(oalength, class_java_lang_String);
1869 for (i = 0; i < oalength; i++) {
1870 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1871 s = javastring_new(u);
1876 #ifdef TYPEINFO_DEBUG_TEST
1877 /* test the typeinfo system */
1880 /*class_showmethods(currentThread->group->header.vftbl->class); */
1882 #if defined(ENABLE_JVMTI)
1883 jvmti_set_phase(JVMTI_PHASE_LIVE);
1886 /* set ThreadMXBean variables */
1888 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1889 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1891 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1892 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1893 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1894 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1896 /* start the main thread */
1898 (void) vm_call_method(m, NULL, oa);
1900 /* exception occurred? */
1902 if (exceptions_get_exception()) {
1903 exceptions_print_stacktrace();
1907 /* unload the JavaVM */
1909 (void) vm_destroy(vm);
1917 /* vm_destroy ******************************************************************
1919 Unloads a Java VM and reclaims its resources.
1921 *******************************************************************************/
1923 s4 vm_destroy(JavaVM *vm)
1925 #if defined(ENABLE_THREADS)
1926 threads_join_all_threads();
1929 /* everything's ok */
1935 /* vm_exit *********************************************************************
1937 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1939 *******************************************************************************/
1941 void vm_exit(s4 status)
1945 /* signal that we are exiting */
1949 assert(class_java_lang_System);
1950 assert(class_java_lang_System->state & CLASS_LOADED);
1952 #if defined(ENABLE_JVMTI)
1953 if (jvmti || (dbgcom!=NULL)) {
1954 jvmti_set_phase(JVMTI_PHASE_DEAD);
1955 if (jvmti) jvmti_agentunload();
1959 if (!link_class(class_java_lang_System)) {
1960 exceptions_print_stacktrace();
1964 /* call java.lang.System.exit(I)V */
1966 m = class_resolveclassmethod(class_java_lang_System,
1967 utf_new_char("exit"),
1969 class_java_lang_Object,
1973 exceptions_print_stacktrace();
1977 /* call the exit function with passed exit status */
1979 (void) vm_call_method(m, NULL, status);
1981 /* If we had an exception, just ignore the exception and exit with
1984 vm_shutdown(status);
1988 /* vm_shutdown *****************************************************************
1990 Terminates the system immediately without freeing memory explicitly
1991 (to be used only for abnormal termination).
1993 *******************************************************************************/
1995 void vm_shutdown(s4 status)
1998 #if defined(ENABLE_STATISTICS)
1999 || opt_getcompilingtime || opt_stat
2003 log_text("CACAO terminated by shutdown");
2004 dolog("Exit status: %d\n", (s4) status);
2008 #if defined(ENABLE_JVMTI)
2009 /* terminate cacaodbgserver */
2011 pthread_mutex_lock(&dbgcomlock);
2013 pthread_mutex_unlock(&dbgcomlock);
2014 jvmti_cacaodbgserver_quit();
2022 /* vm_exit_handler *************************************************************
2024 The exit_handler function is called upon program termination.
2026 ATTENTION: Don't free system resources here! Some threads may still
2027 be running as this is called from VMRuntime.exit(). The OS does the
2030 *******************************************************************************/
2032 void vm_exit_handler(void)
2034 #if !defined(NDEBUG)
2036 class_showmethods(mainclass);
2038 if (showconstantpool)
2039 class_showconstantpool(mainclass);
2044 # if defined(ENABLE_PROFILING)
2046 profile_printstats();
2048 #endif /* !defined(NDEBUG) */
2050 #if defined(ENABLE_RT_TIMING)
2051 rt_timing_print_time_stats(stderr);
2054 #if defined(ENABLE_CYCLES_STATS)
2055 builtin_print_cycles_stats(stderr);
2056 stacktrace_print_cycles_stats(stderr);
2060 #if defined(ENABLE_STATISTICS)
2061 || opt_getcompilingtime || opt_stat
2065 log_text("CACAO terminated");
2067 #if defined(ENABLE_STATISTICS)
2070 #ifdef TYPECHECK_STATISTICS
2071 typecheck_print_statistics(get_logfile());
2075 if (opt_getcompilingtime)
2077 #endif /* defined(ENABLE_STATISTICS) */
2079 /* vm_print_profile(stderr);*/
2083 /* vm_abort ********************************************************************
2085 Prints an error message and aborts the VM.
2087 *******************************************************************************/
2089 void vm_abort(const char *text, ...)
2093 /* print the log message */
2098 log_vprint(text, ap);
2103 /* now abort the VM */
2109 /* vm_get_mainclass_from_jar ***************************************************
2111 Gets the name of the main class from a JAR's manifest file.
2113 *******************************************************************************/
2115 static char *vm_get_mainclass_from_jar(char *mainstring)
2118 java_objectheader *o;
2120 java_objectheader *s;
2122 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2125 exceptions_print_stacktrace();
2129 /* create JarFile object */
2134 exceptions_print_stacktrace();
2138 m = class_resolveclassmethod(c,
2140 utf_java_lang_String__void,
2141 class_java_lang_Object,
2145 exceptions_print_stacktrace();
2149 s = javastring_new_from_ascii(mainstring);
2151 (void) vm_call_method(m, o, s);
2153 if (exceptions_get_exception()) {
2154 exceptions_print_stacktrace();
2158 /* get manifest object */
2160 m = class_resolveclassmethod(c,
2161 utf_new_char("getManifest"),
2162 utf_new_char("()Ljava/util/jar/Manifest;"),
2163 class_java_lang_Object,
2167 exceptions_print_stacktrace();
2171 o = vm_call_method(m, o);
2174 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2179 /* get Main Attributes */
2181 m = class_resolveclassmethod(o->vftbl->class,
2182 utf_new_char("getMainAttributes"),
2183 utf_new_char("()Ljava/util/jar/Attributes;"),
2184 class_java_lang_Object,
2188 exceptions_print_stacktrace();
2192 o = vm_call_method(m, o);
2195 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2200 /* get property Main-Class */
2202 m = class_resolveclassmethod(o->vftbl->class,
2203 utf_new_char("getValue"),
2204 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2205 class_java_lang_Object,
2209 exceptions_print_stacktrace();
2213 s = javastring_new_from_ascii("Main-Class");
2215 o = vm_call_method(m, o, s);
2218 exceptions_print_stacktrace();
2222 return javastring_tochar(o);
2226 /* vm_compile_all **************************************************************
2228 Compile all methods found in the bootclasspath.
2230 *******************************************************************************/
2232 #if !defined(NDEBUG)
2233 static void vm_compile_all(void)
2238 classcache_name_entry *nmen;
2239 classcache_class_entry *clsen;
2242 /* create all classes found in the bootclasspath */
2243 /* XXX currently only works with zip/jar's */
2245 loader_load_all_classes();
2247 /* link all classes */
2249 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2250 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2252 for (; nmen; nmen = nmen->hashlink) {
2253 /* iterate over all class entries */
2255 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2256 c = clsen->classobj;
2261 if (!(c->state & CLASS_LINKED)) {
2262 if (!link_class(c)) {
2263 fprintf(stderr, "Error linking: ");
2264 utf_fprint_printable_ascii_classname(stderr, c->name);
2265 fprintf(stderr, "\n");
2267 /* print out exception and cause */
2269 exceptions_print_current_exception();
2271 /* goto next class */
2277 /* compile all class methods */
2279 for (i = 0; i < c->methodscount; i++) {
2280 m = &(c->methods[i]);
2282 if (m->jcode != NULL) {
2283 if (!jit_compile(m)) {
2284 fprintf(stderr, "Error compiling: ");
2285 utf_fprint_printable_ascii_classname(stderr, c->name);
2286 fprintf(stderr, ".");
2287 utf_fprint_printable_ascii(stderr, m->name);
2288 utf_fprint_printable_ascii(stderr, m->descriptor);
2289 fprintf(stderr, "\n");
2291 /* print out exception and cause */
2293 exceptions_print_current_exception();
2301 #endif /* !defined(NDEBUG) */
2304 /* vm_compile_method ***********************************************************
2306 Compile a specific method.
2308 *******************************************************************************/
2310 #if !defined(NDEBUG)
2311 static void vm_compile_method(void)
2315 /* create, load and link the main class */
2317 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2319 if (mainclass == NULL)
2320 exceptions_print_stacktrace();
2322 if (!link_class(mainclass))
2323 exceptions_print_stacktrace();
2325 if (opt_signature != NULL) {
2326 m = class_resolveclassmethod(mainclass,
2327 utf_new_char(opt_method),
2328 utf_new_char(opt_signature),
2333 m = class_resolveclassmethod(mainclass,
2334 utf_new_char(opt_method),
2341 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2342 opt_method, opt_signature ? opt_signature : "");
2346 #endif /* !defined(NDEBUG) */
2349 /* vm_array_store_int **********************************************************
2351 Helper function to store an integer into the argument array, taking
2352 care of architecture specific issues.
2354 *******************************************************************************/
2356 static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
2360 if (!pd->inmemory) {
2362 array[index] = (int64_t) value;
2365 index = ARG_CNT + pd->index;
2366 #if SIZEOF_VOID_P == 8
2367 array[index] = (int64_t) value;
2369 # if WORDS_BIGENDIAN == 1
2370 array[index] = ((int64_t) value) << 32;
2372 array[index] = (int64_t) value;
2379 /* vm_array_store_lng **********************************************************
2381 Helper function to store a long into the argument array, taking
2382 care of architecture specific issues.
2384 *******************************************************************************/
2386 static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
2390 #if SIZEOF_VOID_P == 8
2394 index = ARG_CNT + pd->index;
2396 array[index] = value;
2398 if (!pd->inmemory) {
2399 /* move low and high 32-bits into it's own argument slot */
2401 index = GET_LOW_REG(pd->index);
2402 array[index] = value & 0x00000000ffffffff;
2404 index = GET_HIGH_REG(pd->index);
2405 array[index] = value >> 32;
2408 index = ARG_CNT + pd->index;
2409 array[index] = value;
2415 /* vm_array_store_flt **********************************************************
2417 Helper function to store a float into the argument array, taking
2418 care of architecture specific issues.
2420 *******************************************************************************/
2422 static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
2426 if (!pd->inmemory) {
2427 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2430 index = INT_ARG_CNT + pd->index;
2432 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2433 array[index] = value >> 32;
2435 array[index] = value;
2439 index = ARG_CNT + pd->index;
2440 #if defined(__SPARC_64__)
2441 array[index] = value >> 32;
2443 array[index] = value;
2449 /* vm_array_store_dbl **********************************************************
2451 Helper function to store a double into the argument array, taking
2452 care of architecture specific issues.
2454 *******************************************************************************/
2456 static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
2460 if (!pd->inmemory) {
2461 #if SIZEOF_VOID_P != 8 && defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2462 index = GET_LOW_REG(pd->index);
2463 array[index] = value & 0x00000000ffffffff;
2465 index = GET_HIGH_REG(pd->index);
2466 array[index] = value >> 32;
2468 index = INT_ARG_CNT + pd->index;
2469 array[index] = value;
2473 index = ARG_CNT + pd->index;
2474 array[index] = value;
2479 /* vm_array_store_adr **********************************************************
2481 Helper function to store an address into the argument array, taking
2482 care of architecture specific issues.
2484 *******************************************************************************/
2486 static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
2490 if (!pd->inmemory) {
2491 #if defined(HAS_ADDRESS_REGISTER_FILE)
2492 /* When the architecture has address registers, place them
2493 after integer and float registers. */
2495 index = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
2499 array[index] = (uint64_t) (intptr_t) value;
2502 index = ARG_CNT + pd->index;
2503 #if SIZEOF_VOID_P == 8
2504 array[index] = (uint64_t) (intptr_t) value;
2506 # if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2507 array[index] = ((uint64_t) (intptr_t) value) << 32;
2509 array[index] = (uint64_t) (intptr_t) value;
2516 /* vm_vmargs_from_valist *******************************************************
2520 *******************************************************************************/
2522 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
2523 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2524 vm_arg *vmargs, va_list ap)
2526 typedesc *paramtypes;
2529 paramtypes = m->parseddesc->paramtypes;
2531 /* if method is non-static fill first block and skip `this' pointer */
2536 /* the `this' pointer */
2537 vmargs[0].type = TYPE_ADR;
2538 vmargs[0].data.l = (u8) (ptrint) o;
2544 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2545 switch (paramtypes->type) {
2547 vmargs[i].type = TYPE_INT;
2548 vmargs[i].data.l = (s8) va_arg(ap, s4);
2552 vmargs[i].type = TYPE_LNG;
2553 vmargs[i].data.l = (s8) va_arg(ap, s8);
2557 vmargs[i].type = TYPE_FLT;
2558 #if defined(__ALPHA__)
2559 /* this keeps the assembler function much simpler */
2561 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2563 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2568 vmargs[i].type = TYPE_DBL;
2569 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2573 vmargs[i].type = TYPE_ADR;
2574 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2580 uint64_t *vm_array_from_valist(methodinfo *m, java_objectheader *o, va_list ap)
2589 /* get the descriptors */
2593 td = md->paramtypes;
2595 /* allocate argument array */
2597 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2599 /* if method is non-static fill first block and skip `this' pointer */
2604 /* the `this' pointer */
2605 vm_array_store_adr(array, pd, o);
2612 for (; i < md->paramcount; i++, pd++, td++) {
2615 value.i = va_arg(ap, int32_t);
2616 vm_array_store_int(array, pd, value.i);
2620 value.l = va_arg(ap, int64_t);
2621 vm_array_store_lng(array, pd, value.l);
2625 #if defined(__ALPHA__) || defined(__POWERPC64__)
2626 /* this keeps the assembler function much simpler */
2628 value.d = (double) va_arg(ap, double);
2630 value.f = (float) va_arg(ap, double);
2632 vm_array_store_flt(array, pd, value.l);
2636 value.d = va_arg(ap, double);
2637 vm_array_store_dbl(array, pd, value.l);
2641 value.a = va_arg(ap, void*);
2642 vm_array_store_adr(array, pd, value.a);
2652 /* vm_vmargs_from_jvalue *******************************************************
2656 *******************************************************************************/
2658 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
2659 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2660 vm_arg *vmargs, const jvalue *args)
2662 typedesc *paramtypes;
2666 paramtypes = m->parseddesc->paramtypes;
2668 /* if method is non-static fill first block and skip `this' pointer */
2673 /* the `this' pointer */
2674 vmargs[0].type = TYPE_ADR;
2675 vmargs[0].data.l = (u8) (ptrint) o;
2681 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2682 switch (paramtypes->decltype) {
2684 vmargs[i].type = TYPE_INT;
2685 vmargs[i].data.l = (s8) args[j].i;
2689 vmargs[i].type = TYPE_LNG;
2690 vmargs[i].data.l = (s8) args[j].j;
2694 vmargs[i].type = TYPE_FLT;
2695 #if defined(__ALPHA__)
2696 /* this keeps the assembler function much simpler */
2698 vmargs[i].data.d = (jdouble) args[j].f;
2700 vmargs[i].data.f = args[j].f;
2705 vmargs[i].type = TYPE_DBL;
2706 vmargs[i].data.d = args[j].d;
2710 vmargs[i].type = TYPE_ADR;
2711 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2717 static uint64_t *vm_array_from_jvalue(methodinfo *m, java_objectheader *o,
2727 /* get the descriptors */
2731 td = md->paramtypes;
2733 /* allocate argument array */
2735 #if defined(HAS_ADDRESS_REGISTER_FILE)
2736 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
2738 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2741 /* if method is non-static fill first block and skip `this' pointer */
2746 /* the `this' pointer */
2747 vm_array_store_adr(array, pd, o);
2754 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2755 switch (td->decltype) {
2757 vm_array_store_int(array, pd, args[j].i);
2761 vm_array_store_lng(array, pd, args[j].j);
2765 vm_array_store_flt(array, pd, args[j].j);
2769 vm_array_store_dbl(array, pd, args[j].j);
2773 vm_array_store_adr(array, pd, args[j].l);
2782 /* vm_vmargs_from_objectarray **************************************************
2786 *******************************************************************************/
2788 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
2789 bool vm_vmargs_from_objectarray(methodinfo *m, java_objectheader *o,
2790 vm_arg *vmargs, java_objectarray *params)
2792 java_objectheader *param;
2793 typedesc *paramtypes;
2799 paramtypes = m->parseddesc->paramtypes;
2801 /* if method is non-static fill first block and skip `this' pointer */
2807 vmargs[0].type = TYPE_ADR;
2808 vmargs[0].data.l = (uint64_t) (intptr_t) o;
2814 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2815 switch (paramtypes->type) {
2816 /* primitive types */
2821 param = params->data[j];
2826 /* internally used data type */
2827 vmargs[i].type = paramtypes->type;
2829 /* convert the value according to its declared type */
2831 c = param->vftbl->class;
2833 switch (paramtypes->decltype) {
2834 case PRIMITIVETYPE_BOOLEAN:
2835 if (c == class_java_lang_Boolean)
2836 value = (int64_t) ((java_lang_Boolean *) param)->value;
2840 vmargs[i].data.l = value;
2843 case PRIMITIVETYPE_BYTE:
2844 if (c == class_java_lang_Byte)
2845 value = (int64_t) ((java_lang_Byte *) param)->value;
2849 vmargs[i].data.l = value;
2852 case PRIMITIVETYPE_CHAR:
2853 if (c == class_java_lang_Character)
2854 value = (int64_t) ((java_lang_Character *) param)->value;
2858 vmargs[i].data.l = value;
2861 case PRIMITIVETYPE_SHORT:
2862 if (c == class_java_lang_Short)
2863 value = (int64_t) ((java_lang_Short *) param)->value;
2864 else if (c == class_java_lang_Byte)
2865 value = (int64_t) ((java_lang_Byte *) param)->value;
2869 vmargs[i].data.l = value;
2872 case PRIMITIVETYPE_INT:
2873 if (c == class_java_lang_Integer)
2874 value = (int64_t) ((java_lang_Integer *) param)->value;
2875 else if (c == class_java_lang_Short)
2876 value = (int64_t) ((java_lang_Short *) param)->value;
2877 else if (c == class_java_lang_Byte)
2878 value = (int64_t) ((java_lang_Byte *) param)->value;
2882 vmargs[i].data.l = value;
2885 case PRIMITIVETYPE_LONG:
2886 if (c == class_java_lang_Long)
2887 value = (int64_t) ((java_lang_Long *) param)->value;
2888 else if (c == class_java_lang_Integer)
2889 value = (int64_t) ((java_lang_Integer *) param)->value;
2890 else if (c == class_java_lang_Short)
2891 value = (int64_t) ((java_lang_Short *) param)->value;
2892 else if (c == class_java_lang_Byte)
2893 value = (int64_t) ((java_lang_Byte *) param)->value;
2897 vmargs[i].data.l = value;
2900 case PRIMITIVETYPE_FLOAT:
2901 if (c == class_java_lang_Float)
2902 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
2907 case PRIMITIVETYPE_DOUBLE:
2908 if (c == class_java_lang_Double)
2909 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
2910 else if (c == class_java_lang_Float)
2911 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
2922 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
2925 if (params->data[j] != 0) {
2926 if (paramtypes->arraydim > 0) {
2927 if (!builtin_arrayinstanceof(params->data[j], c))
2931 if (!builtin_instanceof(params->data[j], c))
2936 vmargs[i].type = TYPE_ADR;
2937 vmargs[i].data.l = (u8) (ptrint) params->data[j];
2946 /* *rettype = descr->returntype.decltype; */
2951 exceptions_throw_illegalargumentexception();
2955 uint64_t *vm_array_from_objectarray(methodinfo *m, java_objectheader *o,
2956 java_objectarray *params)
2962 java_objectheader *param;
2968 /* get the descriptors */
2972 td = md->paramtypes;
2974 /* allocate argument array */
2976 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2978 /* if method is non-static fill first block and skip `this' pointer */
2984 vm_array_store_adr(array, pd, o);
2991 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2992 param = params->data[j];
2999 /* convert the value according to its declared type */
3001 c = param->vftbl->class;
3003 switch (td->decltype) {
3004 case PRIMITIVETYPE_BOOLEAN:
3005 if (c == class_java_lang_Boolean)
3006 value.i = ((java_lang_Boolean *) param)->value;
3011 case PRIMITIVETYPE_BYTE:
3012 if (c == class_java_lang_Byte)
3013 value.i = ((java_lang_Byte *) param)->value;
3018 case PRIMITIVETYPE_CHAR:
3019 if (c == class_java_lang_Character)
3020 value.i = ((java_lang_Character *) param)->value;
3025 case PRIMITIVETYPE_SHORT:
3026 if (c == class_java_lang_Short)
3027 value.i = ((java_lang_Short *) param)->value;
3028 else if (c == class_java_lang_Byte)
3029 value.i = ((java_lang_Byte *) param)->value;
3034 case PRIMITIVETYPE_INT:
3035 if (c == class_java_lang_Integer)
3036 value.i = ((java_lang_Integer *) param)->value;
3037 else if (c == class_java_lang_Short)
3038 value.i = ((java_lang_Short *) param)->value;
3039 else if (c == class_java_lang_Byte)
3040 value.i = ((java_lang_Byte *) param)->value;
3049 vm_array_store_int(array, pd, value.i);
3056 /* convert the value according to its declared type */
3058 c = param->vftbl->class;
3060 switch (td->decltype) {
3061 case PRIMITIVETYPE_LONG:
3062 if (c == class_java_lang_Long)
3063 value.l = ((java_lang_Long *) param)->value;
3064 else if (c == class_java_lang_Integer)
3065 value.l = (int64_t) ((java_lang_Integer *) param)->value;
3066 else if (c == class_java_lang_Short)
3067 value.l = (int64_t) ((java_lang_Short *) param)->value;
3068 else if (c == class_java_lang_Byte)
3069 value.l = (int64_t) ((java_lang_Byte *) param)->value;
3078 vm_array_store_lng(array, pd, value.l);
3085 /* convert the value according to its declared type */
3087 c = param->vftbl->class;
3089 switch (td->decltype) {
3090 case PRIMITIVETYPE_FLOAT:
3091 if (c == class_java_lang_Float)
3092 value.f = ((java_lang_Float *) param)->value;
3101 vm_array_store_flt(array, pd, value.l);
3108 /* convert the value according to its declared type */
3110 c = param->vftbl->class;
3112 switch (td->decltype) {
3113 case PRIMITIVETYPE_DOUBLE:
3114 if (c == class_java_lang_Double)
3115 value.d = ((java_lang_Double *) param)->value;
3116 else if (c == class_java_lang_Float)
3117 value.f = ((java_lang_Float *) param)->value;
3126 vm_array_store_dbl(array, pd, value.l);
3130 if (!resolve_class_from_typedesc(td, true, true, &c))
3133 if (param != NULL) {
3134 if (td->arraydim > 0) {
3135 if (!builtin_arrayinstanceof(param, c))
3139 if (!builtin_instanceof(param, c))
3144 vm_array_store_adr(array, pd, param);
3155 exceptions_throw_illegalargumentexception();
3161 /* vm_call_method **************************************************************
3163 Calls a Java method with a variable number of arguments and returns
3166 *******************************************************************************/
3168 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
3171 java_objectheader *ro;
3174 ro = vm_call_method_valist(m, o, ap);
3181 /* vm_call_method_valist *******************************************************
3183 Calls a Java method with a variable number of arguments, passed via
3184 a va_list, and returns an address.
3186 *******************************************************************************/
3188 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
3191 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3194 java_objectheader *ro;
3197 /* mark start of dump memory area */
3199 dumpsize = dump_size();
3201 /* get number of Java method arguments */
3203 vmargscount = m->parseddesc->paramcount;
3205 /* allocate vm_arg array */
3207 vmargs = DMNEW(vm_arg, vmargscount);
3209 /* fill the vm_arg array from a va_list */
3211 vm_vmargs_from_valist(m, o, vmargs, ap);
3213 /* call the Java method */
3215 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
3217 /* release dump area */
3219 dump_release(dumpsize);
3223 java_objectheader *ro;
3227 /* mark start of dump memory area */
3229 dumpsize = dump_size();
3231 /* fill the argument array from a va_list */
3233 array = vm_array_from_valist(m, o, ap);
3235 /* call the Java method */
3237 ro = vm_call_array(m, array);
3239 /* release dump area */
3241 dump_release(dumpsize);
3248 /* vm_call_method_jvalue *******************************************************
3250 Calls a Java method with a variable number of arguments, passed via
3251 a jvalue array, and returns an address.
3253 *******************************************************************************/
3255 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
3258 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3261 java_objectheader *ro;
3264 /* mark start of dump memory area */
3266 dumpsize = dump_size();
3268 /* get number of Java method arguments */
3270 vmargscount = m->parseddesc->paramcount;
3272 /* allocate vm_arg array */
3274 vmargs = DMNEW(vm_arg, vmargscount);
3276 /* fill the vm_arg array from a va_list */
3278 vm_vmargs_from_jvalue(m, o, vmargs, args);
3280 /* call the Java method */
3282 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
3284 /* release dump area */
3286 dump_release(dumpsize);
3290 java_objectheader *ro;
3294 /* mark start of dump memory area */
3296 dumpsize = dump_size();
3298 /* fill the argument array from a va_list */
3300 array = vm_array_from_jvalue(m, o, args);
3302 /* call the Java method */
3304 ro = vm_call_array(m, array);
3306 /* release dump area */
3308 dump_release(dumpsize);
3315 /* vm_call_array ***************************************************************
3317 Calls a Java method with a variable number of arguments, passed via
3318 an argument array, and returns an address.
3320 *******************************************************************************/
3322 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3323 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
3326 java_objectheader *o;
3328 STATISTICS(count_calls_native_to_java++);
3330 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3331 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
3334 #if defined(ENABLE_JIT)
3335 # if defined(ENABLE_INTRP)
3337 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3340 o = asm_vm_call_method(m, vmargscount, vmargs);
3342 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3345 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3346 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
3352 java_objectheader *vm_call_array(methodinfo *m, uint64_t *array)
3355 java_objectheader *o;
3359 /* compile the method if not already done */
3361 if (m->code == NULL)
3362 if (!jit_compile(m))
3365 STATISTICS(count_calls_native_to_java++);
3367 #if defined(ENABLE_JIT)
3368 # if defined(ENABLE_INTRP)
3370 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3373 o = asm_vm_call_method(m->code->entrypoint, array, md->memuse);
3375 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3383 /* vm_call_int_array ***********************************************************
3385 Calls a Java method with a variable number of arguments, passed via
3386 an argument array, and returns an integer (int32_t).
3388 *******************************************************************************/
3390 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3391 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3395 STATISTICS(count_calls_native_to_java++);
3397 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3398 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
3401 #if defined(ENABLE_JIT)
3402 # if defined(ENABLE_INTRP)
3404 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3407 i = asm_vm_call_method_int(m, vmargscount, vmargs);
3409 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3412 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3413 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
3419 int32_t vm_call_int_array(methodinfo *m, uint64_t *array)
3426 /* compile the method if not already done */
3428 if (m->code == NULL)
3429 if (!jit_compile(m))
3432 STATISTICS(count_calls_native_to_java++);
3434 #if defined(ENABLE_JIT)
3435 # if defined(ENABLE_INTRP)
3437 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3440 i = asm_vm_call_method_int(m->code->entrypoint, array, md->memuse);
3442 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3450 /* vm_call_method_int **********************************************************
3452 Calls a Java method with a variable number of arguments and returns
3455 *******************************************************************************/
3457 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
3463 i = vm_call_method_int_valist(m, o, ap);
3470 /* vm_call_method_int_valist ***************************************************
3472 Calls a Java method with a variable number of arguments, passed via
3473 a va_list, and returns an integer (int32_t).
3475 *******************************************************************************/
3477 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3478 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
3485 /* mark start of dump memory area */
3487 dumpsize = dump_size();
3489 /* get number of Java method arguments */
3491 vmargscount = m->parseddesc->paramcount;
3493 /* allocate vm_arg array */
3495 vmargs = DMNEW(vm_arg, vmargscount);
3497 /* fill the vm_arg array from a va_list */
3499 vm_vmargs_from_valist(m, o, vmargs, ap);
3501 /* call the Java method */
3503 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
3505 /* release dump area */
3507 dump_release(dumpsize);
3512 int32_t vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
3518 /* mark start of dump memory area */
3520 dumpsize = dump_size();
3522 /* fill the argument array from a va_list */
3524 array = vm_array_from_valist(m, o, ap);
3526 /* call the Java method */
3528 i = vm_call_int_array(m, array);
3530 /* release dump area */
3532 dump_release(dumpsize);
3539 /* vm_call_method_int_jvalue ***************************************************
3541 Calls a Java method with a variable number of arguments, passed via
3542 a jvalue array, and returns an integer (s4).
3544 *******************************************************************************/
3546 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3547 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o,
3555 /* mark start of dump memory area */
3557 dumpsize = dump_size();
3559 /* get number of Java method arguments */
3561 vmargscount = m->parseddesc->paramcount;
3563 /* allocate vm_arg array */
3565 vmargs = DMNEW(vm_arg, vmargscount);
3567 /* fill the vm_arg array from a va_list */
3569 vm_vmargs_from_jvalue(m, o, vmargs, args);
3571 /* call the Java method */
3573 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
3575 /* release dump area */
3577 dump_release(dumpsize);
3582 int32_t vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o,
3589 /* mark start of dump memory area */
3591 dumpsize = dump_size();
3593 /* fill the argument array from a va_list */
3595 array = vm_array_from_jvalue(m, o, args);
3597 /* call the Java method */
3599 i = vm_call_int_array(m, array);
3601 /* release dump area */
3603 dump_release(dumpsize);
3610 /* vm_call_long_array **********************************************************
3612 Calls a Java method with a variable number of arguments, passed via
3613 an argument array, and returns a long (int64_t).
3615 *******************************************************************************/
3617 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3618 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3622 STATISTICS(count_calls_native_to_java++);
3624 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3625 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
3628 #if defined(ENABLE_JIT)
3629 # if defined(ENABLE_INTRP)
3631 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3634 l = asm_vm_call_method_long(m, vmargscount, vmargs);
3636 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3639 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3640 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
3646 int64_t vm_call_long_array(methodinfo *m, uint64_t *array)
3653 /* compile the method if not already done */
3655 if (m->code == NULL)
3656 if (!jit_compile(m))
3659 STATISTICS(count_calls_native_to_java++);
3661 #if defined(ENABLE_JIT)
3662 # if defined(ENABLE_INTRP)
3664 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3667 l = asm_vm_call_method_long(m->code->entrypoint, array, md->memuse);
3669 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3677 /* vm_call_method_long *********************************************************
3679 Calls a Java method with a variable number of arguments and returns
3682 *******************************************************************************/
3684 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
3690 l = vm_call_method_long_valist(m, o, ap);
3697 /* vm_call_method_long_valist **************************************************
3699 Calls a Java method with a variable number of arguments, passed via
3700 a va_list, and returns a long (s8).
3702 *******************************************************************************/
3704 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3705 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
3712 /* mark start of dump memory area */
3714 dumpsize = dump_size();
3716 /* get number of Java method arguments */
3718 vmargscount = m->parseddesc->paramcount;
3720 /* allocate vm_arg array */
3722 vmargs = DMNEW(vm_arg, vmargscount);
3724 /* fill the vm_arg array from a va_list */
3726 vm_vmargs_from_valist(m, o, vmargs, ap);
3728 /* call the Java method */
3730 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
3732 /* release dump area */
3734 dump_release(dumpsize);
3739 int64_t vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
3745 /* mark start of dump memory area */
3747 dumpsize = dump_size();
3749 /* fill the argument array from a va_list */
3751 array = vm_array_from_valist(m, o, ap);
3753 /* call the Java method */
3755 l = vm_call_long_array(m, array);
3757 /* release dump area */
3759 dump_release(dumpsize);
3766 /* vm_call_method_long_jvalue **************************************************
3768 Calls a Java method with a variable number of arguments, passed via
3769 a jvalue array, and returns a long (s8).
3771 *******************************************************************************/
3773 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3774 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o,
3782 /* mark start of dump memory area */
3784 dumpsize = dump_size();
3786 /* get number of Java method arguments */
3788 vmargscount = m->parseddesc->paramcount;
3790 /* allocate vm_arg array */
3792 vmargs = DMNEW(vm_arg, vmargscount);
3794 /* fill the vm_arg array from a va_list */
3796 vm_vmargs_from_jvalue(m, o, vmargs, args);
3798 /* call the Java method */
3800 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
3802 /* release dump area */
3804 dump_release(dumpsize);
3809 int64_t vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o,
3816 /* mark start of dump memory area */
3818 dumpsize = dump_size();
3820 /* fill the argument array from a va_list */
3822 array = vm_array_from_jvalue(m, o, args);
3824 /* call the Java method */
3826 l = vm_call_long_array(m, array);
3828 /* release dump area */
3830 dump_release(dumpsize);
3837 /* vm_call_float_array *********************************************************
3839 Calls a Java method with a variable number of arguments and returns
3842 *******************************************************************************/
3844 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3845 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3849 vm_abort("IMPLEMENT ME!");
3851 STATISTICS(count_calls_native_to_java++);
3853 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3854 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
3857 #if defined(ENABLE_JIT)
3858 # if defined(ENABLE_INTRP)
3860 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3863 f = asm_vm_call_method_float(m, vmargscount, vmargs);
3865 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3868 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
3869 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
3875 float vm_call_float_array(methodinfo *m, uint64_t *array)
3882 /* compile the method if not already done */
3884 if (m->code == NULL)
3885 if (!jit_compile(m))
3888 STATISTICS(count_calls_native_to_java++);
3890 #if defined(ENABLE_JIT)
3891 # if defined(ENABLE_INTRP)
3893 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3896 f = asm_vm_call_method_float(m->code->entrypoint, array, md->memuse);
3898 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3905 /* vm_call_method_float ********************************************************
3907 Calls a Java method with a variable number of arguments and returns
3910 *******************************************************************************/
3912 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
3918 f = vm_call_method_float_valist(m, o, ap);
3925 /* vm_call_method_float_valist *************************************************
3927 Calls a Java method with a variable number of arguments, passed via
3928 a va_list, and returns a float.
3930 *******************************************************************************/
3932 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
3933 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
3941 /* mark start of dump memory area */
3943 dumpsize = dump_size();
3945 /* get number of Java method arguments */
3947 vmargscount = m->parseddesc->paramcount;
3949 /* allocate vm_arg array */
3951 vmargs = DMNEW(vm_arg, vmargscount);
3953 /* fill the vm_arg array from a va_list */
3955 vm_vmargs_from_valist(m, o, vmargs, ap);
3957 /* call the Java method */
3959 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
3961 /* release dump area */
3963 dump_release(dumpsize);
3968 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o, va_list ap)
3974 /* mark start of dump memory area */
3976 dumpsize = dump_size();
3978 /* fill the argument array from a va_list */
3980 array = vm_array_from_valist(m, o, ap);
3982 /* call the Java method */
3984 f = vm_call_float_array(m, array);
3986 /* release dump area */
3988 dump_release(dumpsize);
3994 /* vm_call_method_float_jvalue *************************************************
3996 Calls a Java method with a variable number of arguments, passed via
3997 a jvalue array, and returns a float.
3999 *******************************************************************************/
4001 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
4002 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
4010 /* mark start of dump memory area */
4012 dumpsize = dump_size();
4014 /* get number of Java method arguments */
4016 vmargscount = m->parseddesc->paramcount;
4018 /* allocate vm_arg array */
4020 vmargs = DMNEW(vm_arg, vmargscount);
4022 /* fill the vm_arg array from a va_list */
4024 vm_vmargs_from_jvalue(m, o, vmargs, args);
4026 /* call the Java method */
4028 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
4030 /* release dump area */
4032 dump_release(dumpsize);
4037 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o, const jvalue *args)
4043 /* mark start of dump memory area */
4045 dumpsize = dump_size();
4047 /* fill the argument array from a va_list */
4049 array = vm_array_from_jvalue(m, o, args);
4051 /* call the Java method */
4053 f = vm_call_float_array(m, array);
4055 /* release dump area */
4057 dump_release(dumpsize);
4064 /* vm_call_double_array ********************************************************
4066 Calls a Java method with a variable number of arguments and returns
4069 *******************************************************************************/
4071 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
4072 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
4077 vm_abort("IMPLEMENT ME!");
4079 STATISTICS(count_calls_native_to_java++);
4081 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
4082 THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
4085 #if defined(ENABLE_JIT)
4086 # if defined(ENABLE_INTRP)
4088 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4091 d = asm_vm_call_method_double(m, vmargscount, vmargs);
4093 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4096 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
4097 THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
4103 double vm_call_double_array(methodinfo *m, uint64_t *array)
4110 /* compile the method if not already done */
4112 if (m->code == NULL)
4113 if (!jit_compile(m))
4116 STATISTICS(count_calls_native_to_java++);
4118 #if defined(ENABLE_JIT)
4119 # if defined(ENABLE_INTRP)
4121 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4124 d = asm_vm_call_method_double(m->code->entrypoint, array, md->memuse);
4126 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4134 /* vm_call_method_double *******************************************************
4136 Calls a Java method with a variable number of arguments and returns
4139 *******************************************************************************/
4141 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
4147 d = vm_call_method_double_valist(m, o, ap);
4154 /* vm_call_method_double_valist ************************************************
4156 Calls a Java method with a variable number of arguments, passed via
4157 a va_list, and returns a double.
4159 *******************************************************************************/
4161 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
4162 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
4170 /* mark start of dump memory area */
4172 dumpsize = dump_size();
4174 /* get number of Java method arguments */
4176 vmargscount = m->parseddesc->paramcount;
4178 /* allocate vm_arg array */
4180 vmargs = DMNEW(vm_arg, vmargscount);
4182 /* fill the vm_arg array from a va_list */
4184 vm_vmargs_from_valist(m, o, vmargs, ap);
4186 /* call the Java method */
4188 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
4190 /* release dump area */
4192 dump_release(dumpsize);
4197 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o, va_list ap)
4203 /* mark start of dump memory area */
4205 dumpsize = dump_size();
4207 /* fill the argument array from a va_list */
4209 array = vm_array_from_valist(m, o, ap);
4211 /* call the Java method */
4213 d = vm_call_double_array(m, array);
4215 /* release dump area */
4217 dump_release(dumpsize);
4224 /* vm_call_method_double_jvalue ************************************************
4226 Calls a Java method with a variable number of arguments, passed via
4227 a jvalue array, and returns a double.
4229 *******************************************************************************/
4231 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__)
4232 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
4240 /* mark start of dump memory area */
4242 dumpsize = dump_size();
4244 /* get number of Java method arguments */
4246 vmargscount = m->parseddesc->paramcount;
4248 /* allocate vm_arg array */
4250 vmargs = DMNEW(vm_arg, vmargscount);
4252 /* fill the vm_arg array from a va_list */
4254 vm_vmargs_from_jvalue(m, o, vmargs, args);
4256 /* call the Java method */
4258 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
4260 /* release dump area */
4262 dump_release(dumpsize);
4267 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o, const jvalue *args)
4273 /* mark start of dump memory area */
4275 dumpsize = dump_size();
4277 /* fill the argument array from a va_list */
4279 array = vm_array_from_jvalue(m, o, args);
4281 /* call the Java method */
4283 d = vm_call_double_array(m, array);
4285 /* release dump area */
4287 dump_release(dumpsize);
4294 * These are local overrides for various environment variables in Emacs.
4295 * Please do not remove this and leave it at the end of the file, where
4296 * Emacs will automagically detect them.
4297 * ---------------------------------------------------------------------
4300 * indent-tabs-mode: t