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 8236 2007-07-27 10:18:17Z twisti $
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) */
235 /* optimization options */
237 #if defined(ENABLE_LOOP)
241 #if defined(ENABLE_IFCONV)
245 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
249 #if defined(ENABLE_INLINING)
254 #if defined(ENABLE_INLINING_DEBUG)
255 OPT_INLINE_DEBUG_ALL,
256 OPT_INLINE_DEBUG_END,
257 OPT_INLINE_DEBUG_MIN,
258 OPT_INLINE_DEBUG_MAX,
259 #endif /* defined(ENABLE_INLINING_DEBUG) */
260 #endif /* defined(ENABLE_INLINING) */
262 #if defined(ENABLE_INTRP)
263 /* interpreter options */
282 #if defined(ENABLE_DEBUG_FILTER)
283 OPT_FILTER_VERBOSECALL_INCLUDE,
284 OPT_FILTER_VERBOSECALL_EXCLUDE,
285 OPT_FILTER_SHOW_METHOD,
292 opt_struct opts[] = {
293 { "foo", false, OPT_FOO },
297 { "jar", false, OPT_JAR },
299 { "d32", false, OPT_D32 },
300 { "d64", false, OPT_D64 },
301 { "client", false, OPT_IGNORE },
302 { "server", false, OPT_IGNORE },
303 { "jvm", false, OPT_IGNORE },
304 { "hotspot", false, OPT_IGNORE },
306 { "classpath", true, OPT_CLASSPATH },
307 { "cp", true, OPT_CLASSPATH },
308 { "D", true, OPT_D },
309 { "version", false, OPT_VERSION },
310 { "showversion", false, OPT_SHOWVERSION },
311 { "fullversion", false, OPT_FULLVERSION },
312 { "help", false, OPT_HELP },
313 { "?", false, OPT_HELP },
314 { "X", false, OPT_X },
315 { "XX:", true, OPT_XX },
316 { "XX", false, OPT_XX },
318 { "ea:", true, OPT_EA },
319 { "da:", true, OPT_DA },
320 { "ea", false, OPT_EA },
321 { "da", false, OPT_DA },
323 { "esa", false, OPT_ESA },
324 { "enablesystemassertions", false, OPT_ESA },
325 { "dsa", false, OPT_DSA },
326 { "disablesystemassertions", false, OPT_DSA },
328 { "noasyncgc", false, OPT_IGNORE },
329 #if defined(ENABLE_VERIFIER)
330 { "noverify", false, OPT_NOVERIFY },
332 { "v", false, OPT_VERBOSE1 },
333 { "verbose:", true, OPT_VERBOSE },
335 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
336 { "verbosetc", false, OPT_VERBOSETC },
338 #if defined(__ALPHA__)
339 { "noieee", false, OPT_NOIEEE },
341 #if defined(ENABLE_STATISTICS)
342 { "time", false, OPT_TIME },
343 { "stat", false, OPT_STAT },
345 { "log", true, OPT_LOG },
346 { "c", true, OPT_CHECK },
347 { "l", false, OPT_LOAD },
350 { "all", false, OPT_ALL },
351 { "sig", true, OPT_SIGNATURE },
354 #if defined(ENABLE_LOOP)
355 { "oloop", false, OPT_OLOOP },
357 #if defined(ENABLE_IFCONV)
358 { "ifconv", false, OPT_IFCONV },
360 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
361 { "lsra", false, OPT_LSRA },
364 #if defined(ENABLE_INTRP)
365 /* interpreter options */
367 { "trace", false, OPT_TRACE },
368 { "static-supers", true, OPT_STATIC_SUPERS },
369 { "no-dynamic", false, OPT_NO_DYNAMIC },
370 { "no-replication", false, OPT_NO_REPLICATION },
371 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
374 /* JVMTI Agent Command Line Options */
376 { "agentlib:", true, OPT_AGENTLIB },
377 { "agentpath:", true, OPT_AGENTPATH },
380 /* Java non-standard options */
382 { "Xjit", false, OPT_JIT },
383 { "Xint", false, OPT_INTRP },
384 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
385 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
386 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
387 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
390 { "Xdebug", false, OPT_DEBUG },
391 { "Xnoagent", false, OPT_NOAGENT },
392 { "Xrunjdwp", true, OPT_XRUNJDWP },
395 { "Xms", true, OPT_MS },
396 { "ms", true, OPT_MS },
397 { "Xmx", true, OPT_MX },
398 { "mx", true, OPT_MX },
399 { "Xss", true, OPT_SS },
400 { "ss", true, OPT_SS },
402 #if defined(ENABLE_PROFILING)
403 { "Xprof:", true, OPT_PROF_OPTION },
404 { "Xprof", false, OPT_PROF },
407 /* inlining options */
409 #if defined(ENABLE_INLINING)
410 #if defined(ENABLE_INLINING_DEBUG)
411 { "ia", false, OPT_INLINE_DEBUG_ALL },
412 { "ii", true, OPT_INLINE_DEBUG_MIN },
413 { "im", true, OPT_INLINE_DEBUG_MAX },
414 { "ie", true, OPT_INLINE_DEBUG_END },
415 #endif /* defined(ENABLE_INLINING_DEBUG) */
417 { "il", false, OPT_INLINE_LOG },
419 { "i", false, OPT_INLINING },
420 #endif /* defined(ENABLE_INLINING) */
422 /* keep these at the end of the list */
425 { "m", true, OPT_METHOD },
428 { "s", true, OPT_SHOW },
429 { "debug-color", false, OPT_DEBUGCOLOR },
431 #if defined(ENABLE_DEBUG_FILTER)
432 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
433 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
434 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
441 /* usage ***********************************************************************
443 Prints the correct usage syntax to stdout.
445 *******************************************************************************/
449 puts("Usage: cacao [-options] classname [arguments]");
450 puts(" (to run a class file)");
451 puts(" or cacao [-options] -jar jarfile [arguments]");
452 puts(" (to run a standalone jar file)\n");
454 puts("where options include:");
455 puts(" -d32 use 32-bit data model if available");
456 puts(" -d64 use 64-bit data model if available");
457 puts(" -client compatibility (currently ignored)");
458 puts(" -server compatibility (currently ignored)");
459 puts(" -jvm compatibility (currently ignored)");
460 puts(" -hotspot compatibility (currently ignored)\n");
462 puts(" -cp <path> specify a path to look for classes");
463 puts(" -classpath <path> specify a path to look for classes");
464 puts(" -D<name>=<value> add an entry to the property list");
465 puts(" -verbose[:class|gc|jni] enable specific verbose output");
466 puts(" -version print product version and exit");
467 puts(" -fullversion print jpackage-compatible product version and exit");
468 puts(" -showversion print product version and continue");
469 puts(" -help, -? print this help message");
470 puts(" -X print help on non-standard Java options");
471 puts(" -XX print help on debugging options");
472 puts(" -ea[:<packagename>...|:<classname>]");
473 puts(" -enableassertions[:<packagename>...|:<classname>]");
474 puts(" enable assertions with specified granularity");
475 puts(" -da[:<packagename>...|:<classname>]");
476 puts(" -disableassertions[:<packagename>...|:<classname>]");
477 puts(" disable assertions with specified granularity");
478 puts(" -esa | -enablesystemassertions");
479 puts(" enable system assertions");
480 puts(" -dsa | -disablesystemassertions");
481 puts(" disable system assertions");
484 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
485 puts (" for jdwp help use: -agentlib:jdwp=help");
486 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
489 /* exit with error code */
495 static void Xusage(void)
497 #if defined(ENABLE_JIT)
498 puts(" -Xjit JIT mode execution (default)");
500 #if defined(ENABLE_INTRP)
501 puts(" -Xint interpreter mode execution");
503 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
504 puts(" value is set as bootstrap class path");
505 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
506 puts(" value is appended to the bootstrap class path");
507 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
508 puts(" value is prepended to the bootstrap class path");
509 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
510 puts(" value is used as Java core library, but the");
511 puts(" hardcoded VM interface classes are prepended");
512 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
513 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
514 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
516 #if defined(ENABLE_PROFILING)
517 puts(" -Xprof[:bb] collect and print profiling data");
520 #if defined(ENABLE_JVMTI)
521 /* -Xdebug option depend on gnu classpath JDWP options. options:
522 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
523 puts(" -Xdebug enable remote debugging\n");
524 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
525 puts(" enable remote debugging\n");
528 /* exit with error code */
534 static void XXusage(void)
536 puts(" -v write state-information");
538 puts(" -verbose[:jit|threads]");
539 puts(" enable specific verbose output");
540 puts(" -debug-color colored output for ANSI terms");
542 #ifdef TYPECHECK_VERBOSE
543 puts(" -verbosetc write debug messages while typechecking");
545 #if defined(__ALPHA__)
546 puts(" -noieee don't use ieee compliant arithmetic");
548 #if defined(ENABLE_VERIFIER)
549 puts(" -noverify don't verify classfiles");
551 #if defined(ENABLE_STATISTICS)
552 puts(" -time measure the runtime");
553 puts(" -stat detailed compiler statistics");
555 puts(" -log logfile specify a name for the logfile");
556 puts(" -c(heck)b(ounds) don't check array bounds");
557 puts(" s(ync) don't check for synchronization");
558 #if defined(ENABLE_LOOP)
559 puts(" -oloop optimize array accesses in loops");
561 puts(" -l don't start the class after loading");
563 puts(" -all compile all methods, no execution");
564 puts(" -m compile only a specific method");
565 puts(" -sig specify signature for a specific method");
568 puts(" -s... show...");
569 puts(" (c)onstants the constant pool");
570 puts(" (m)ethods class fields and methods");
571 puts(" (u)tf the utf - hash");
572 puts(" (i)ntermediate intermediate representation");
573 #if defined(ENABLE_DISASSEMBLER)
574 puts(" (a)ssembler disassembled listing");
575 puts(" n(o)ps show NOPs in disassembler output");
576 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
577 puts(" (n)ative disassembled native stubs");
579 puts(" (d)atasegment data segment listing");
581 #if defined(ENABLE_INLINING)
582 puts(" -i activate inlining");
584 puts(" -il log inlining");
586 #if defined(ENABLE_INLINING_DEBUG)
587 puts(" -ia use inlining for all methods");
588 puts(" -ii <size> set minimum size for inlined result");
589 puts(" -im <size> set maximum size for inlined result");
590 puts(" -ie <number> stop inlining after the given number of roots");
591 #endif /* defined(ENABLE_INLINING_DEBUG) */
592 #endif /* defined(ENABLE_INLINING) */
594 #if defined(ENABLE_IFCONV)
595 puts(" -ifconv use if-conversion");
597 #if defined(ENABLE_LSRA)
598 puts(" -lsra use linear scan register allocation");
600 #if defined(ENABLE_SSA)
601 puts(" -lsra use linear scan register allocation (with SSA)");
603 #if defined(ENABLE_DEBUG_FILTER)
604 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
605 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
606 puts(" -XXfm <regex> filter for show options");
608 /* exit with error code */
614 /* version *********************************************************************
616 Only prints cacao version information.
618 *******************************************************************************/
620 static void version(bool opt_exit)
622 puts("java version \""JAVA_VERSION"\"");
623 puts("CACAO version "VERSION"");
625 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
626 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
627 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
628 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
630 puts("This program is free software; you can redistribute it and/or");
631 puts("modify it under the terms of the GNU General Public License as");
632 puts("published by the Free Software Foundation; either version 2, or (at");
633 puts("your option) any later version.\n");
635 puts("This program is distributed in the hope that it will be useful, but");
636 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
637 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
638 puts("General Public License for more details.");
640 /* exit normally, if requested */
647 /* fullversion *****************************************************************
649 Prints a Sun compatible version information (required e.g. by
650 jpackage, www.jpackage.org).
652 *******************************************************************************/
654 static void fullversion(void)
656 puts("java full version \"cacao-"JAVA_VERSION"\"");
664 void vm_printconfig(void)
666 puts("Configure/Build options:\n");
667 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
668 #if defined(__VERSION__)
669 puts(" CC : "VERSION_CC" ("__VERSION__")");
671 puts(" CC : "VERSION_CC"");
673 puts(" CFLAGS : "VERSION_CFLAGS"\n");
675 puts("Default variables:\n");
676 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
677 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
678 printf(" stack size : %d\n", STACK_SIZE);
679 #if defined(WITH_CLASSPATH_GNU)
680 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
682 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
684 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
686 puts("Runtime variables:\n");
687 printf(" maximum heap size : %d\n", opt_heapmaxsize);
688 printf(" initial heap size : %d\n", opt_heapstartsize);
689 printf(" stack size : %d\n", opt_stacksize);
690 printf(" libjvm.so : %s\n", cacao_libjvm);
691 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
692 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
693 printf(" java.class.path : %s\n", _Jv_classpath);
697 /* forward declarations *******************************************************/
699 static char *vm_get_mainclass_from_jar(char *mainstring);
701 static void vm_compile_all(void);
702 static void vm_compile_method(void);
706 /* vm_createjvm ****************************************************************
708 Implementation for JNI_CreateJavaVM.
710 *******************************************************************************/
712 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
714 JavaVMInitArgs *_vm_args;
718 /* get the arguments for the new JVM */
720 _vm_args = (JavaVMInitArgs *) vm_args;
722 /* get the VM and Env tables (must be set before vm_create) */
724 env = NEW(_Jv_JNIEnv);
726 #if defined(ENABLE_JNI)
727 env->env = &_Jv_JNINativeInterface;
730 /* XXX Set the global variable. Maybe we should do that differently. */
734 /* create and fill a JavaVM structure */
736 vm = NEW(_Jv_JavaVM);
738 #if defined(ENABLE_JNI)
739 vm->functions = &_Jv_JNIInvokeInterface;
742 /* XXX Set the global variable. Maybe we should do that differently. */
743 /* XXX JVMTI Agents needs a JavaVM */
747 /* actually create the JVM */
749 if (!vm_create(_vm_args))
752 #if defined(ENABLE_JNI)
753 /* setup the local ref table (must be created after vm_create) */
755 if (!jni_init_localref_table())
759 /* now return the values */
761 *p_vm = (JavaVM *) vm;
762 *p_env = (void *) env;
767 /* release allocated memory */
769 FREE(env, _Jv_JNIEnv);
770 FREE(vm, _Jv_JavaVM);
776 /* vm_create *******************************************************************
778 Creates a JVM. Called by vm_createjvm.
780 *******************************************************************************/
782 bool vm_create(JavaVMInitArgs *vm_args)
791 #if defined(ENABLE_JVMTI)
793 char *libname, *agentarg;
794 bool jdwp,agentbypath;
795 jdwp = agentbypath = false;
798 #if defined(ENABLE_VMLOG)
799 vmlog_cacao_init(vm_args);
802 /* check the JNI version requested */
804 switch (vm_args->version) {
805 case JNI_VERSION_1_1:
807 case JNI_VERSION_1_2:
808 case JNI_VERSION_1_4:
814 /* we only support 1 JVM instance */
819 if (atexit(vm_exit_handler))
820 vm_abort("atexit failed: %s\n", strerror(errno));
823 log_text("CACAO started -------------------------------------------------------");
825 /* We need to check if the actual size of a java.lang.Class object
826 is smaller or equal than the assumption made in
827 src/vmcore/class.h. */
829 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
830 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
832 /* set the VM starttime */
834 _Jv_jvm->starttime = builtin_currenttimemillis();
836 /* get stuff from the environment *****************************************/
838 #if defined(WITH_JRE_LAYOUT)
839 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
841 cacao_prefix = MNEW(char, 4096);
843 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
844 vm_abort("readlink failed: %s\n", strerror(errno));
846 /* get the path of the current executable */
848 cacao_prefix = dirname(cacao_prefix);
850 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
851 vm_abort("libjvm name to long for buffer\n");
853 /* concatenate the library name */
855 strcat(cacao_prefix, "/..");
857 /* now set path to libjvm.so */
859 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
861 cacao_libjvm = MNEW(char, len);
862 strcpy(cacao_libjvm, cacao_prefix);
863 strcat(cacao_libjvm, "/lib/libjvm");
865 /* and finally set the path to GNU Classpath libraries */
867 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
869 classpath_libdir = MNEW(char, len);
870 strcpy(classpath_libdir, cacao_prefix);
871 strcat(classpath_libdir, "/lib/classpath");
873 cacao_prefix = CACAO_PREFIX;
874 cacao_libjvm = CACAO_LIBDIR"/libjvm";
876 # if defined(WITH_CLASSPATH_GNU)
877 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
879 classpath_libdir = CLASSPATH_LIBDIR;
883 /* set the bootclasspath */
885 cp = getenv("BOOTCLASSPATH");
888 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
889 strcpy(_Jv_bootclasspath, cp);
892 #if defined(WITH_JRE_LAYOUT)
894 # if defined(WITH_CLASSPATH_GNU)
895 strlen(cacao_prefix) +
896 strlen("/share/cacao/vm.zip") +
899 strlen(cacao_prefix) +
900 strlen("/share/classpath/glibj.zip") +
903 _Jv_bootclasspath = MNEW(char, len);
904 # if defined(WITH_CLASSPATH_GNU)
905 strcat(_Jv_bootclasspath, cacao_prefix);
906 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
907 strcat(_Jv_bootclasspath, ":");
909 strcat(_Jv_bootclasspath, cacao_prefix);
910 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
913 # if defined(WITH_CLASSPATH_GNU)
914 strlen(CACAO_VM_ZIP) +
917 strlen(CLASSPATH_CLASSES) +
920 _Jv_bootclasspath = MNEW(char, len);
921 # if defined(WITH_CLASSPATH_GNU)
922 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
923 strcat(_Jv_bootclasspath, ":");
925 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
929 /* set the classpath */
931 cp = getenv("CLASSPATH");
934 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
935 strcat(_Jv_classpath, cp);
938 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
939 strcpy(_Jv_classpath, ".");
942 /* Get and set java.library.path. */
944 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
946 if (_Jv_java_library_path == NULL)
947 _Jv_java_library_path = "";
949 /* interpret the options **************************************************/
956 opt_heapmaxsize = HEAP_MAXSIZE;
957 opt_heapstartsize = HEAP_STARTSIZE;
958 opt_stacksize = STACK_SIZE;
961 #if defined(ENABLE_JVMTI)
962 /* initialize JVMTI related **********************************************/
966 /* Initialize and fill properties before command-line handling. */
968 if (!properties_init())
969 vm_abort("vm_create: properties_init failed");
971 /* Set the classpath properties. */
973 #if defined(ENABLE_JAVASE)
974 properties_add("java.boot.class.path", _Jv_bootclasspath);
975 properties_add("sun.boot.class.path", _Jv_bootclasspath);
976 properties_add("java.class.path", _Jv_classpath);
979 /* iterate over all passed options */
981 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
995 #if SIZEOF_VOID_P == 8
996 puts("Running a 32-bit JVM is not supported on this platform.");
1002 #if SIZEOF_VOID_P == 4
1003 puts("Running a 64-bit JVM is not supported on this platform.");
1009 /* forget old classpath and set the argument as new classpath */
1010 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1012 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
1013 strcpy(_Jv_classpath, opt_arg);
1015 #if defined(ENABLE_JAVASE)
1016 properties_add("java.class.path", _Jv_classpath);
1021 for (i = 0; i < strlen(opt_arg); i++) {
1022 if (opt_arg[i] == '=') {
1024 properties_add(opt_arg, opt_arg + i + 1);
1029 /* if no '=' is given, just create an empty property */
1031 properties_add(opt_arg, "");
1036 case OPT_BOOTCLASSPATH:
1037 /* Forget default bootclasspath and set the argument as
1038 new boot classpath. */
1040 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1042 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
1043 strcpy(_Jv_bootclasspath, opt_arg);
1045 #if defined(ENABLE_JAVASE)
1046 properties_add("java.boot.class.path", _Jv_bootclasspath);
1047 properties_add("sun.boot.class.path", _Jv_bootclasspath);
1051 case OPT_BOOTCLASSPATH_A:
1052 /* append to end of bootclasspath */
1054 len = strlen(_Jv_bootclasspath);
1056 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
1060 strlen(opt_arg) + strlen("0"));
1062 strcat(_Jv_bootclasspath, ":");
1063 strcat(_Jv_bootclasspath, opt_arg);
1065 #if defined(ENABLE_JAVASE)
1066 properties_add("java.boot.class.path", _Jv_bootclasspath);
1067 properties_add("sun.boot.class.path", _Jv_bootclasspath);
1071 case OPT_BOOTCLASSPATH_P:
1072 /* prepend in front of bootclasspath */
1074 cp = _Jv_bootclasspath;
1077 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1080 strcpy(_Jv_bootclasspath, opt_arg);
1081 strcat(_Jv_bootclasspath, ":");
1082 strcat(_Jv_bootclasspath, cp);
1084 MFREE(cp, char, len);
1086 #if defined(ENABLE_JAVASE)
1087 properties_add("java.boot.class.path", _Jv_bootclasspath);
1088 properties_add("sun.boot.class.path", _Jv_bootclasspath);
1092 case OPT_BOOTCLASSPATH_C:
1093 /* use as Java core library, but prepend VM interface classes */
1095 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1097 len = strlen(CACAO_VM_ZIP) +
1102 _Jv_bootclasspath = MNEW(char, len);
1104 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1105 strcat(_Jv_bootclasspath, ":");
1106 strcat(_Jv_bootclasspath, opt_arg);
1108 #if defined(ENABLE_JAVASE)
1109 properties_add("java.boot.class.path", _Jv_bootclasspath);
1110 properties_add("sun.boot.class.path", _Jv_bootclasspath);
1114 #if defined(ENABLE_JVMTI)
1116 /* this option exists only for compatibility reasons */
1120 /* I don't know yet what Xnoagent should do. This is only for
1121 compatiblity with eclipse - motse */
1130 strlen(CACAO_LIBDIR) +
1131 strlen("/libjdwp.so=") +
1135 agentarg = MNEW(char, len);
1137 strcpy(agentarg, CACAO_LIBDIR);
1138 strcat(agentarg, "/libjdwp.so=");
1139 strcat(agentarg, &opt_arg[1]);
1156 c = opt_arg[strlen(opt_arg) - 1];
1158 if ((c == 'k') || (c == 'K')) {
1159 j = atoi(opt_arg) * 1024;
1161 } else if ((c == 'm') || (c == 'M')) {
1162 j = atoi(opt_arg) * 1024 * 1024;
1168 opt_heapmaxsize = j;
1169 else if (opt == OPT_MS)
1170 opt_heapstartsize = j;
1181 if (strcmp("class", opt_arg) == 0) {
1182 opt_verboseclass = true;
1184 else if (strcmp("gc", opt_arg) == 0) {
1185 opt_verbosegc = true;
1187 else if (strcmp("jni", opt_arg) == 0) {
1188 opt_verbosejni = true;
1190 #if !defined(NDEBUG)
1191 else if (strcmp("jit", opt_arg) == 0) {
1196 compileverbose = true;
1198 else if (strcmp("threads", opt_arg) == 0) {
1199 opt_verbosethreads = true;
1203 printf("Unknown -verbose option: %s\n", opt_arg);
1208 case OPT_DEBUGCOLOR:
1209 opt_debugcolor = true;
1212 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1214 opt_typecheckverbose = true;
1223 case OPT_FULLVERSION:
1227 case OPT_SHOWVERSION:
1235 #if defined(ENABLE_VERIFIER)
1241 #if defined(ENABLE_STATISTICS)
1243 opt_getcompilingtime = true;
1244 opt_getloadingtime = true;
1257 for (i = 0; i < strlen(opt_arg); i++) {
1258 switch (opt_arg[i]) {
1260 checkbounds = false;
1273 makeinitializations = false;
1276 #if !defined(NDEBUG)
1280 makeinitializations = false;
1285 opt_method = opt_arg;
1286 makeinitializations = false;
1290 opt_signature = opt_arg;
1294 case OPT_SHOW: /* Display options */
1295 for (i = 0; i < strlen(opt_arg); i++) {
1296 switch (opt_arg[i]) {
1298 showconstantpool = true;
1310 opt_showintermediate = true;
1311 compileverbose = true;
1314 #if defined(ENABLE_DISASSEMBLER)
1316 opt_showdisassemble = true;
1317 compileverbose = true;
1321 opt_shownops = true;
1325 opt_showexceptionstubs = true;
1329 opt_shownativestub = true;
1334 opt_showddatasegment = true;
1343 #if defined(ENABLE_LOOP)
1349 #if defined(ENABLE_INLINING)
1350 #if defined(ENABLE_INLINING_DEBUG)
1351 case OPT_INLINE_DEBUG_ALL:
1352 opt_inline_debug_all = true;
1354 case OPT_INLINE_DEBUG_END:
1355 opt_inline_debug_end_counter = atoi(opt_arg);
1357 case OPT_INLINE_DEBUG_MIN:
1358 opt_inline_debug_min_size = atoi(opt_arg);
1360 case OPT_INLINE_DEBUG_MAX:
1361 opt_inline_debug_max_size = atoi(opt_arg);
1363 #endif /* defined(ENABLE_INLINING_DEBUG) */
1364 #if !defined(NDEBUG)
1365 case OPT_INLINE_LOG:
1366 opt_inline_debug_log = true;
1368 #endif /* !defined(NDEBUG) */
1371 opt_inlining = true;
1373 #endif /* defined(ENABLE_INLINING) */
1375 #if defined(ENABLE_IFCONV)
1381 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1396 options_xx(opt_arg);
1400 /* currently ignored */
1404 /* currently ignored */
1408 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1412 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1415 #if defined(ENABLE_PROFILING)
1416 case OPT_PROF_OPTION:
1417 /* use <= to get the last \0 too */
1419 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1420 if (opt_arg[i] == ',')
1423 if (opt_arg[i] == '\0') {
1424 if (strcmp("bb", opt_arg + j) == 0)
1428 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1432 /* set k to next char */
1445 #if defined(ENABLE_JIT)
1448 printf("-Xjit option not enabled.\n");
1454 #if defined(ENABLE_INTRP)
1457 printf("-Xint option not enabled.\n");
1462 #if defined(ENABLE_INTRP)
1463 case OPT_STATIC_SUPERS:
1464 opt_static_supers = atoi(opt_arg);
1467 case OPT_NO_DYNAMIC:
1468 opt_no_dynamic = true;
1471 case OPT_NO_REPLICATION:
1472 opt_no_replication = true;
1475 case OPT_NO_QUICKSUPER:
1476 opt_no_quicksuper = true;
1484 #if defined(ENABLE_DEBUG_FILTER)
1485 case OPT_FILTER_VERBOSECALL_INCLUDE:
1486 opt_filter_verbosecall_include = opt_arg;
1489 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1490 opt_filter_verbosecall_exclude = opt_arg;
1493 case OPT_FILTER_SHOW_METHOD:
1494 opt_filter_show_method = opt_arg;
1499 printf("Unknown option: %s\n",
1500 vm_args->options[opt_index].optionString);
1505 /* get the main class *****************************************************/
1507 if (opt_index < vm_args->nOptions) {
1508 mainstring = vm_args->options[opt_index++].optionString;
1510 /* Put the jar file into the classpath (if any). */
1512 if (opt_jar == true) {
1513 /* free old classpath */
1515 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1517 /* put jarfile into classpath */
1519 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1521 strcpy(_Jv_classpath, mainstring);
1523 #if defined(ENABLE_JAVASE)
1524 properties_add("java.class.path", _Jv_classpath);
1528 /* replace .'s with /'s in classname */
1530 for (i = strlen(mainstring) - 1; i >= 0; i--)
1531 if (mainstring[i] == '.')
1532 mainstring[i] = '/';
1536 #if defined(ENABLE_JVMTI)
1538 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1539 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1542 MFREE(agentarg, char, strlen(agentarg));
1544 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1548 /* initialize this JVM ****************************************************/
1550 vm_initializing = true;
1552 /* initialize the garbage collector */
1554 gc_init(opt_heapmaxsize, opt_heapstartsize);
1556 #if defined(ENABLE_THREADS)
1557 /* AFTER: gc_init (directly after, as this initializes the
1558 stopworldlock lock */
1563 /* install architecture dependent signal handlers */
1566 vm_abort("vm_create: signal_init failed");
1568 #if defined(ENABLE_INTRP)
1569 /* Allocate main thread stack on the Java heap. */
1572 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1573 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1577 /* AFTER: threads_preinit */
1580 vm_abort("vm_create: string_init failed");
1582 /* AFTER: threads_preinit */
1585 vm_abort("vm_create: utf8_init failed");
1587 /* AFTER: thread_preinit */
1590 vm_abort("vm_create: suck_init failed");
1592 suck_add_from_property("java.endorsed.dirs");
1594 /* Now we have all options handled and we can print the version
1597 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1602 /* AFTER: utf8_init */
1604 suck_add(_Jv_bootclasspath);
1606 /* initialize the classcache hashtable stuff: lock, hashtable
1607 (must be done _after_ threads_preinit) */
1609 if (!classcache_init())
1610 vm_abort("vm_create: classcache_init failed");
1612 /* initialize the memory subsystem (must be done _after_
1616 vm_abort("vm_create: memory_init failed");
1618 /* initialize the finalizer stuff (must be done _after_
1621 if (!finalizer_init())
1622 vm_abort("vm_create: finalizer_init failed");
1624 /* initialize the codegen subsystems */
1628 /* initializes jit compiler */
1632 /* machine dependent initialization */
1634 #if defined(ENABLE_JIT)
1635 # if defined(ENABLE_INTRP)
1645 /* initialize the loader subsystems (must be done _after_
1649 vm_abort("vm_create: loader_init failed");
1651 /* Link some important VM classes. */
1652 /* AFTER: utf8_init */
1655 vm_abort("vm_create: linker_init failed");
1657 if (!primitive_init())
1658 vm_abort("vm_create: primitive_init failed");
1660 if (!exceptions_init())
1661 vm_abort("vm_create: exceptions_init failed");
1663 if (!builtin_init())
1664 vm_abort("vm_create: builtin_init failed");
1666 /* Initialize the native subsystem. */
1667 /* BEFORE: threads_init */
1670 vm_abort("vm_create: native_init failed");
1672 /* Register the native methods implemented in the VM. */
1673 /* BEFORE: threads_init */
1675 if (!nativevm_preinit())
1676 vm_abort("vm_create: nativevm_preinit failed");
1678 #if defined(ENABLE_JNI)
1679 /* Initialize the JNI subsystem (must be done _before_
1680 threads_init, as threads_init can call JNI methods
1681 (e.g. NewGlobalRef). */
1684 vm_abort("vm_create: jni_init failed");
1687 #if defined(ENABLE_THREADS)
1688 if (!threads_init())
1689 vm_abort("vm_create: threads_init failed");
1692 /* Initialize the native VM subsystem. */
1693 /* AFTER: threads_init (at least for SUN's classes) */
1695 if (!nativevm_init())
1696 vm_abort("vm_create: nativevm_init failed");
1698 #if defined(ENABLE_PROFILING)
1699 /* initialize profiling */
1701 if (!profile_init())
1702 vm_abort("vm_create: profile_init failed");
1705 #if defined(ENABLE_THREADS)
1706 /* initialize recompilation */
1708 if (!recompile_init())
1709 vm_abort("vm_create: recompile_init failed");
1711 /* start the signal handler thread */
1713 #if defined(__LINUX__)
1714 /* XXX Remove for exact-GC. */
1715 if (threads_pthreads_implementation_nptl)
1717 if (!signal_start_thread())
1718 vm_abort("vm_create: signal_start_thread failed");
1720 /* finally, start the finalizer thread */
1722 if (!finalizer_start_thread())
1723 vm_abort("vm_create: finalizer_start_thread failed");
1725 # if !defined(NDEBUG)
1726 /* start the memory profiling thread */
1728 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1729 if (!memory_start_thread())
1730 vm_abort("vm_create: memory_start_thread failed");
1733 /* start the recompilation thread (must be done before the
1734 profiling thread) */
1736 if (!recompile_start_thread())
1737 vm_abort("vm_create: recompile_start_thread failed");
1739 # if defined(ENABLE_PROFILING)
1740 /* start the profile sampling thread */
1743 /* if (!profile_start_thread()) */
1744 /* vm_abort("vm_create: profile_start_thread failed"); */
1748 #if defined(ENABLE_JVMTI)
1750 /* add agent library to native library hashtable */
1751 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1755 /* increment the number of VMs */
1759 /* initialization is done */
1761 vm_initializing = false;
1763 /* everything's ok */
1769 /* vm_run **********************************************************************
1771 Runs the main-method of the passed class.
1773 *******************************************************************************/
1775 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1778 classinfo *mainclass;
1779 java_objectheader *e;
1781 java_objectarray *oa;
1784 java_objectheader *s;
1788 #if !defined(NDEBUG)
1794 if (opt_method != NULL) {
1795 vm_compile_method();
1798 #endif /* !defined(NDEBUG) */
1800 /* should we run the main-method? */
1802 if (mainstring == NULL)
1805 /* set return value to OK */
1809 if (opt_jar == true) {
1810 /* open jar file with java.util.jar.JarFile */
1812 mainstring = vm_get_mainclass_from_jar(mainstring);
1814 if (mainstring == NULL)
1818 /* load the main class */
1820 mainutf = utf_new_char(mainstring);
1822 #if defined(ENABLE_JAVAME_CLDC1_1)
1823 mainclass = load_class_bootstrap(mainutf);
1825 mainclass = load_class_from_sysloader(mainutf);
1828 /* error loading class */
1830 e = exceptions_get_and_clear_exception();
1832 if ((e != NULL) || (mainclass == NULL)) {
1833 exceptions_throw_noclassdeffounderror_cause(e);
1834 exceptions_print_stacktrace();
1838 if (!link_class(mainclass)) {
1839 exceptions_print_stacktrace();
1843 /* find the `main' method of the main class */
1845 m = class_resolveclassmethod(mainclass,
1846 utf_new_char("main"),
1847 utf_new_char("([Ljava/lang/String;)V"),
1848 class_java_lang_Object,
1851 if (exceptions_get_exception()) {
1852 exceptions_print_stacktrace();
1856 /* there is no main method or it isn't static */
1858 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1859 exceptions_clear_exception();
1860 exceptions_throw_nosuchmethoderror(mainclass,
1861 utf_new_char("main"),
1862 utf_new_char("([Ljava/lang/String;)V"));
1864 exceptions_print_stacktrace();
1868 /* build argument array */
1870 oalength = vm_args->nOptions - opt_index;
1872 oa = builtin_anewarray(oalength, class_java_lang_String);
1874 for (i = 0; i < oalength; i++) {
1875 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1876 s = javastring_new(u);
1881 #ifdef TYPEINFO_DEBUG_TEST
1882 /* test the typeinfo system */
1885 /*class_showmethods(currentThread->group->header.vftbl->class); */
1887 #if defined(ENABLE_JVMTI)
1888 jvmti_set_phase(JVMTI_PHASE_LIVE);
1891 /* set ThreadMXBean variables */
1893 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1894 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1896 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1897 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1898 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1899 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1901 /* start the main thread */
1903 (void) vm_call_method(m, NULL, oa);
1905 /* exception occurred? */
1907 if (exceptions_get_exception()) {
1908 exceptions_print_stacktrace();
1912 /* unload the JavaVM */
1914 (void) vm_destroy(vm);
1922 /* vm_destroy ******************************************************************
1924 Unloads a Java VM and reclaims its resources.
1926 *******************************************************************************/
1928 s4 vm_destroy(JavaVM *vm)
1930 #if defined(ENABLE_THREADS)
1931 threads_join_all_threads();
1934 /* everything's ok */
1940 /* vm_exit *********************************************************************
1942 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1944 *******************************************************************************/
1946 void vm_exit(s4 status)
1950 /* signal that we are exiting */
1954 assert(class_java_lang_System);
1955 assert(class_java_lang_System->state & CLASS_LOADED);
1957 #if defined(ENABLE_JVMTI)
1958 if (jvmti || (dbgcom!=NULL)) {
1959 jvmti_set_phase(JVMTI_PHASE_DEAD);
1960 if (jvmti) jvmti_agentunload();
1964 if (!link_class(class_java_lang_System)) {
1965 exceptions_print_stacktrace();
1969 /* call java.lang.System.exit(I)V */
1971 m = class_resolveclassmethod(class_java_lang_System,
1972 utf_new_char("exit"),
1974 class_java_lang_Object,
1978 exceptions_print_stacktrace();
1982 /* call the exit function with passed exit status */
1984 (void) vm_call_method(m, NULL, status);
1986 /* If we had an exception, just ignore the exception and exit with
1989 vm_shutdown(status);
1993 /* vm_shutdown *****************************************************************
1995 Terminates the system immediately without freeing memory explicitly
1996 (to be used only for abnormal termination).
1998 *******************************************************************************/
2000 void vm_shutdown(s4 status)
2003 #if defined(ENABLE_STATISTICS)
2004 || opt_getcompilingtime || opt_stat
2008 log_text("CACAO terminated by shutdown");
2009 dolog("Exit status: %d\n", (s4) status);
2013 #if defined(ENABLE_JVMTI)
2014 /* terminate cacaodbgserver */
2016 pthread_mutex_lock(&dbgcomlock);
2018 pthread_mutex_unlock(&dbgcomlock);
2019 jvmti_cacaodbgserver_quit();
2027 /* vm_exit_handler *************************************************************
2029 The exit_handler function is called upon program termination.
2031 ATTENTION: Don't free system resources here! Some threads may still
2032 be running as this is called from VMRuntime.exit(). The OS does the
2035 *******************************************************************************/
2037 void vm_exit_handler(void)
2039 #if !defined(NDEBUG)
2041 class_showmethods(mainclass);
2043 if (showconstantpool)
2044 class_showconstantpool(mainclass);
2049 # if defined(ENABLE_PROFILING)
2051 profile_printstats();
2053 #endif /* !defined(NDEBUG) */
2055 #if defined(ENABLE_RT_TIMING)
2056 rt_timing_print_time_stats(stderr);
2059 #if defined(ENABLE_CYCLES_STATS)
2060 builtin_print_cycles_stats(stderr);
2061 stacktrace_print_cycles_stats(stderr);
2065 #if defined(ENABLE_STATISTICS)
2066 || opt_getcompilingtime || opt_stat
2070 log_text("CACAO terminated");
2072 #if defined(ENABLE_STATISTICS)
2075 #ifdef TYPECHECK_STATISTICS
2076 typecheck_print_statistics(get_logfile());
2080 if (opt_getcompilingtime)
2082 #endif /* defined(ENABLE_STATISTICS) */
2084 /* vm_print_profile(stderr);*/
2088 /* vm_abort ********************************************************************
2090 Prints an error message and aborts the VM.
2092 *******************************************************************************/
2094 void vm_abort(const char *text, ...)
2098 /* print the log message */
2103 log_vprint(text, ap);
2108 /* now abort the VM */
2114 /* vm_get_mainclass_from_jar ***************************************************
2116 Gets the name of the main class from a JAR's manifest file.
2118 *******************************************************************************/
2120 static char *vm_get_mainclass_from_jar(char *mainstring)
2123 java_objectheader *o;
2125 java_objectheader *s;
2127 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2130 exceptions_print_stacktrace();
2134 /* create JarFile object */
2139 exceptions_print_stacktrace();
2143 m = class_resolveclassmethod(c,
2145 utf_java_lang_String__void,
2146 class_java_lang_Object,
2150 exceptions_print_stacktrace();
2154 s = javastring_new_from_ascii(mainstring);
2156 (void) vm_call_method(m, o, s);
2158 if (exceptions_get_exception()) {
2159 exceptions_print_stacktrace();
2163 /* get manifest object */
2165 m = class_resolveclassmethod(c,
2166 utf_new_char("getManifest"),
2167 utf_new_char("()Ljava/util/jar/Manifest;"),
2168 class_java_lang_Object,
2172 exceptions_print_stacktrace();
2176 o = vm_call_method(m, o);
2179 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2184 /* get Main Attributes */
2186 m = class_resolveclassmethod(o->vftbl->class,
2187 utf_new_char("getMainAttributes"),
2188 utf_new_char("()Ljava/util/jar/Attributes;"),
2189 class_java_lang_Object,
2193 exceptions_print_stacktrace();
2197 o = vm_call_method(m, o);
2200 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2205 /* get property Main-Class */
2207 m = class_resolveclassmethod(o->vftbl->class,
2208 utf_new_char("getValue"),
2209 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2210 class_java_lang_Object,
2214 exceptions_print_stacktrace();
2218 s = javastring_new_from_ascii("Main-Class");
2220 o = vm_call_method(m, o, s);
2223 exceptions_print_stacktrace();
2227 return javastring_tochar(o);
2231 /* vm_compile_all **************************************************************
2233 Compile all methods found in the bootclasspath.
2235 *******************************************************************************/
2237 #if !defined(NDEBUG)
2238 static void vm_compile_all(void)
2243 classcache_name_entry *nmen;
2244 classcache_class_entry *clsen;
2247 /* create all classes found in the bootclasspath */
2248 /* XXX currently only works with zip/jar's */
2250 loader_load_all_classes();
2252 /* link all classes */
2254 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2255 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2257 for (; nmen; nmen = nmen->hashlink) {
2258 /* iterate over all class entries */
2260 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2261 c = clsen->classobj;
2266 if (!(c->state & CLASS_LINKED)) {
2267 if (!link_class(c)) {
2268 fprintf(stderr, "Error linking: ");
2269 utf_fprint_printable_ascii_classname(stderr, c->name);
2270 fprintf(stderr, "\n");
2272 /* print out exception and cause */
2274 exceptions_print_current_exception();
2276 /* goto next class */
2282 /* compile all class methods */
2284 for (i = 0; i < c->methodscount; i++) {
2285 m = &(c->methods[i]);
2287 if (m->jcode != NULL) {
2288 if (!jit_compile(m)) {
2289 fprintf(stderr, "Error compiling: ");
2290 utf_fprint_printable_ascii_classname(stderr, c->name);
2291 fprintf(stderr, ".");
2292 utf_fprint_printable_ascii(stderr, m->name);
2293 utf_fprint_printable_ascii(stderr, m->descriptor);
2294 fprintf(stderr, "\n");
2296 /* print out exception and cause */
2298 exceptions_print_current_exception();
2306 #endif /* !defined(NDEBUG) */
2309 /* vm_compile_method ***********************************************************
2311 Compile a specific method.
2313 *******************************************************************************/
2315 #if !defined(NDEBUG)
2316 static void vm_compile_method(void)
2320 /* create, load and link the main class */
2322 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2324 if (mainclass == NULL)
2325 exceptions_print_stacktrace();
2327 if (!link_class(mainclass))
2328 exceptions_print_stacktrace();
2330 if (opt_signature != NULL) {
2331 m = class_resolveclassmethod(mainclass,
2332 utf_new_char(opt_method),
2333 utf_new_char(opt_signature),
2338 m = class_resolveclassmethod(mainclass,
2339 utf_new_char(opt_method),
2346 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2347 opt_method, opt_signature ? opt_signature : "");
2351 #endif /* !defined(NDEBUG) */
2354 /* vm_array_store_int **********************************************************
2356 Helper function to store an integer into the argument array, taking
2357 care of architecture specific issues.
2359 *******************************************************************************/
2361 static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
2365 if (!pd->inmemory) {
2367 array[index] = (int64_t) value;
2370 index = ARG_CNT + pd->index;
2371 #if SIZEOF_VOID_P == 8
2372 array[index] = (int64_t) value;
2374 # if WORDS_BIGENDIAN == 1
2375 array[index] = ((int64_t) value) << 32;
2377 array[index] = (int64_t) value;
2384 /* vm_array_store_lng **********************************************************
2386 Helper function to store a long into the argument array, taking
2387 care of architecture specific issues.
2389 *******************************************************************************/
2391 static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
2395 #if SIZEOF_VOID_P == 8
2399 index = ARG_CNT + pd->index;
2401 array[index] = value;
2403 if (!pd->inmemory) {
2404 /* move low and high 32-bits into it's own argument slot */
2406 index = GET_LOW_REG(pd->index);
2407 array[index] = value & 0x00000000ffffffff;
2409 index = GET_HIGH_REG(pd->index);
2410 array[index] = value >> 32;
2413 index = ARG_CNT + pd->index;
2414 array[index] = value;
2420 /* vm_array_store_flt **********************************************************
2422 Helper function to store a float into the argument array, taking
2423 care of architecture specific issues.
2425 *******************************************************************************/
2427 static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
2431 if (!pd->inmemory) {
2432 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2435 index = INT_ARG_CNT + pd->index;
2437 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2438 array[index] = value >> 32;
2440 array[index] = value;
2444 index = ARG_CNT + pd->index;
2445 #if defined(__SPARC_64__)
2446 array[index] = value >> 32;
2448 array[index] = value;
2454 /* vm_array_store_dbl **********************************************************
2456 Helper function to store a double into the argument array, taking
2457 care of architecture specific issues.
2459 *******************************************************************************/
2461 static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
2465 if (!pd->inmemory) {
2466 #if SIZEOF_VOID_P != 8 && defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2467 index = GET_LOW_REG(pd->index);
2468 array[index] = value & 0x00000000ffffffff;
2470 index = GET_HIGH_REG(pd->index);
2471 array[index] = value >> 32;
2473 index = INT_ARG_CNT + pd->index;
2474 array[index] = value;
2478 index = ARG_CNT + pd->index;
2479 array[index] = value;
2484 /* vm_array_store_adr **********************************************************
2486 Helper function to store an address into the argument array, taking
2487 care of architecture specific issues.
2489 *******************************************************************************/
2491 static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
2495 if (!pd->inmemory) {
2496 #if defined(HAS_ADDRESS_REGISTER_FILE)
2497 /* When the architecture has address registers, place them
2498 after integer and float registers. */
2500 index = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
2504 array[index] = (uint64_t) (intptr_t) value;
2507 index = ARG_CNT + pd->index;
2508 #if SIZEOF_VOID_P == 8
2509 array[index] = (uint64_t) (intptr_t) value;
2511 # if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2512 array[index] = ((uint64_t) (intptr_t) value) << 32;
2514 array[index] = (uint64_t) (intptr_t) value;
2521 /* vm_vmargs_from_valist *******************************************************
2525 *******************************************************************************/
2527 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
2528 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2529 vm_arg *vmargs, va_list ap)
2531 typedesc *paramtypes;
2534 paramtypes = m->parseddesc->paramtypes;
2536 /* if method is non-static fill first block and skip `this' pointer */
2541 /* the `this' pointer */
2542 vmargs[0].type = TYPE_ADR;
2543 vmargs[0].data.l = (u8) (ptrint) o;
2549 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2550 switch (paramtypes->type) {
2552 vmargs[i].type = TYPE_INT;
2553 vmargs[i].data.l = (s8) va_arg(ap, s4);
2557 vmargs[i].type = TYPE_LNG;
2558 vmargs[i].data.l = (s8) va_arg(ap, s8);
2562 vmargs[i].type = TYPE_FLT;
2563 #if defined(__ALPHA__)
2564 /* this keeps the assembler function much simpler */
2566 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2568 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2573 vmargs[i].type = TYPE_DBL;
2574 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2578 vmargs[i].type = TYPE_ADR;
2579 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2585 uint64_t *vm_array_from_valist(methodinfo *m, java_objectheader *o, va_list ap)
2594 /* get the descriptors */
2598 td = md->paramtypes;
2600 /* allocate argument array */
2602 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2604 /* if method is non-static fill first block and skip `this' pointer */
2609 /* the `this' pointer */
2610 vm_array_store_adr(array, pd, o);
2617 for (; i < md->paramcount; i++, pd++, td++) {
2620 value.i = va_arg(ap, int32_t);
2621 vm_array_store_int(array, pd, value.i);
2625 value.l = va_arg(ap, int64_t);
2626 vm_array_store_lng(array, pd, value.l);
2630 #if defined(__ALPHA__) || defined(__POWERPC64__)
2631 /* this keeps the assembler function much simpler */
2633 value.d = (double) va_arg(ap, double);
2635 value.f = (float) va_arg(ap, double);
2637 vm_array_store_flt(array, pd, value.l);
2641 value.d = va_arg(ap, double);
2642 vm_array_store_dbl(array, pd, value.l);
2646 value.a = va_arg(ap, void*);
2647 vm_array_store_adr(array, pd, value.a);
2657 /* vm_vmargs_from_jvalue *******************************************************
2661 *******************************************************************************/
2663 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
2664 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2665 vm_arg *vmargs, const jvalue *args)
2667 typedesc *paramtypes;
2671 paramtypes = m->parseddesc->paramtypes;
2673 /* if method is non-static fill first block and skip `this' pointer */
2678 /* the `this' pointer */
2679 vmargs[0].type = TYPE_ADR;
2680 vmargs[0].data.l = (u8) (ptrint) o;
2686 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2687 switch (paramtypes->decltype) {
2689 vmargs[i].type = TYPE_INT;
2690 vmargs[i].data.l = (s8) args[j].i;
2694 vmargs[i].type = TYPE_LNG;
2695 vmargs[i].data.l = (s8) args[j].j;
2699 vmargs[i].type = TYPE_FLT;
2700 #if defined(__ALPHA__)
2701 /* this keeps the assembler function much simpler */
2703 vmargs[i].data.d = (jdouble) args[j].f;
2705 vmargs[i].data.f = args[j].f;
2710 vmargs[i].type = TYPE_DBL;
2711 vmargs[i].data.d = args[j].d;
2715 vmargs[i].type = TYPE_ADR;
2716 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2722 static uint64_t *vm_array_from_jvalue(methodinfo *m, java_objectheader *o,
2732 /* get the descriptors */
2736 td = md->paramtypes;
2738 /* allocate argument array */
2740 #if defined(HAS_ADDRESS_REGISTER_FILE)
2741 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
2743 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2746 /* if method is non-static fill first block and skip `this' pointer */
2751 /* the `this' pointer */
2752 vm_array_store_adr(array, pd, o);
2759 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2760 switch (td->decltype) {
2762 vm_array_store_int(array, pd, args[j].i);
2766 vm_array_store_lng(array, pd, args[j].j);
2770 vm_array_store_flt(array, pd, args[j].j);
2774 vm_array_store_dbl(array, pd, args[j].j);
2778 vm_array_store_adr(array, pd, args[j].l);
2787 /* vm_vmargs_from_objectarray **************************************************
2791 *******************************************************************************/
2793 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
2794 bool vm_vmargs_from_objectarray(methodinfo *m, java_objectheader *o,
2795 vm_arg *vmargs, java_objectarray *params)
2797 java_objectheader *param;
2798 typedesc *paramtypes;
2804 paramtypes = m->parseddesc->paramtypes;
2806 /* if method is non-static fill first block and skip `this' pointer */
2812 vmargs[0].type = TYPE_ADR;
2813 vmargs[0].data.l = (uint64_t) (intptr_t) o;
2819 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2820 switch (paramtypes->type) {
2821 /* primitive types */
2826 param = params->data[j];
2831 /* internally used data type */
2832 vmargs[i].type = paramtypes->type;
2834 /* convert the value according to its declared type */
2836 c = param->vftbl->class;
2838 switch (paramtypes->decltype) {
2839 case PRIMITIVETYPE_BOOLEAN:
2840 if (c == class_java_lang_Boolean)
2841 value = (int64_t) ((java_lang_Boolean *) param)->value;
2845 vmargs[i].data.l = value;
2848 case PRIMITIVETYPE_BYTE:
2849 if (c == class_java_lang_Byte)
2850 value = (int64_t) ((java_lang_Byte *) param)->value;
2854 vmargs[i].data.l = value;
2857 case PRIMITIVETYPE_CHAR:
2858 if (c == class_java_lang_Character)
2859 value = (int64_t) ((java_lang_Character *) param)->value;
2863 vmargs[i].data.l = value;
2866 case PRIMITIVETYPE_SHORT:
2867 if (c == class_java_lang_Short)
2868 value = (int64_t) ((java_lang_Short *) param)->value;
2869 else if (c == class_java_lang_Byte)
2870 value = (int64_t) ((java_lang_Byte *) param)->value;
2874 vmargs[i].data.l = value;
2877 case PRIMITIVETYPE_INT:
2878 if (c == class_java_lang_Integer)
2879 value = (int64_t) ((java_lang_Integer *) param)->value;
2880 else if (c == class_java_lang_Short)
2881 value = (int64_t) ((java_lang_Short *) param)->value;
2882 else if (c == class_java_lang_Byte)
2883 value = (int64_t) ((java_lang_Byte *) param)->value;
2887 vmargs[i].data.l = value;
2890 case PRIMITIVETYPE_LONG:
2891 if (c == class_java_lang_Long)
2892 value = (int64_t) ((java_lang_Long *) param)->value;
2893 else if (c == class_java_lang_Integer)
2894 value = (int64_t) ((java_lang_Integer *) param)->value;
2895 else if (c == class_java_lang_Short)
2896 value = (int64_t) ((java_lang_Short *) param)->value;
2897 else if (c == class_java_lang_Byte)
2898 value = (int64_t) ((java_lang_Byte *) param)->value;
2902 vmargs[i].data.l = value;
2905 case PRIMITIVETYPE_FLOAT:
2906 if (c == class_java_lang_Float)
2907 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
2912 case PRIMITIVETYPE_DOUBLE:
2913 if (c == class_java_lang_Double)
2914 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
2915 else if (c == class_java_lang_Float)
2916 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
2927 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
2930 if (params->data[j] != 0) {
2931 if (paramtypes->arraydim > 0) {
2932 if (!builtin_arrayinstanceof(params->data[j], c))
2936 if (!builtin_instanceof(params->data[j], c))
2941 vmargs[i].type = TYPE_ADR;
2942 vmargs[i].data.l = (u8) (ptrint) params->data[j];
2951 /* *rettype = descr->returntype.decltype; */
2956 exceptions_throw_illegalargumentexception();
2960 uint64_t *vm_array_from_objectarray(methodinfo *m, java_objectheader *o,
2961 java_objectarray *params)
2967 java_objectheader *param;
2973 /* get the descriptors */
2977 td = md->paramtypes;
2979 /* allocate argument array */
2981 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2983 /* if method is non-static fill first block and skip `this' pointer */
2989 vm_array_store_adr(array, pd, o);
2996 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2997 param = params->data[j];
3004 /* convert the value according to its declared type */
3006 c = param->vftbl->class;
3008 switch (td->decltype) {
3009 case PRIMITIVETYPE_BOOLEAN:
3010 if (c == class_java_lang_Boolean)
3011 value.i = ((java_lang_Boolean *) param)->value;
3016 case PRIMITIVETYPE_BYTE:
3017 if (c == class_java_lang_Byte)
3018 value.i = ((java_lang_Byte *) param)->value;
3023 case PRIMITIVETYPE_CHAR:
3024 if (c == class_java_lang_Character)
3025 value.i = ((java_lang_Character *) param)->value;
3030 case PRIMITIVETYPE_SHORT:
3031 if (c == class_java_lang_Short)
3032 value.i = ((java_lang_Short *) param)->value;
3033 else if (c == class_java_lang_Byte)
3034 value.i = ((java_lang_Byte *) param)->value;
3039 case PRIMITIVETYPE_INT:
3040 if (c == class_java_lang_Integer)
3041 value.i = ((java_lang_Integer *) param)->value;
3042 else if (c == class_java_lang_Short)
3043 value.i = ((java_lang_Short *) param)->value;
3044 else if (c == class_java_lang_Byte)
3045 value.i = ((java_lang_Byte *) param)->value;
3054 vm_array_store_int(array, pd, value.i);
3061 /* convert the value according to its declared type */
3063 c = param->vftbl->class;
3065 switch (td->decltype) {
3066 case PRIMITIVETYPE_LONG:
3067 if (c == class_java_lang_Long)
3068 value.l = ((java_lang_Long *) param)->value;
3069 else if (c == class_java_lang_Integer)
3070 value.l = (int64_t) ((java_lang_Integer *) param)->value;
3071 else if (c == class_java_lang_Short)
3072 value.l = (int64_t) ((java_lang_Short *) param)->value;
3073 else if (c == class_java_lang_Byte)
3074 value.l = (int64_t) ((java_lang_Byte *) param)->value;
3083 vm_array_store_lng(array, pd, value.l);
3090 /* convert the value according to its declared type */
3092 c = param->vftbl->class;
3094 switch (td->decltype) {
3095 case PRIMITIVETYPE_FLOAT:
3096 if (c == class_java_lang_Float)
3097 value.f = ((java_lang_Float *) param)->value;
3106 vm_array_store_flt(array, pd, value.l);
3113 /* convert the value according to its declared type */
3115 c = param->vftbl->class;
3117 switch (td->decltype) {
3118 case PRIMITIVETYPE_DOUBLE:
3119 if (c == class_java_lang_Double)
3120 value.d = ((java_lang_Double *) param)->value;
3121 else if (c == class_java_lang_Float)
3122 value.f = ((java_lang_Float *) param)->value;
3131 vm_array_store_dbl(array, pd, value.l);
3135 if (!resolve_class_from_typedesc(td, true, true, &c))
3138 if (param != NULL) {
3139 if (td->arraydim > 0) {
3140 if (!builtin_arrayinstanceof(param, c))
3144 if (!builtin_instanceof(param, c))
3149 vm_array_store_adr(array, pd, param);
3160 exceptions_throw_illegalargumentexception();
3166 /* vm_call_method **************************************************************
3168 Calls a Java method with a variable number of arguments and returns
3171 *******************************************************************************/
3173 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
3176 java_objectheader *ro;
3179 ro = vm_call_method_valist(m, o, ap);
3186 /* vm_call_method_valist *******************************************************
3188 Calls a Java method with a variable number of arguments, passed via
3189 a va_list, and returns an address.
3191 *******************************************************************************/
3193 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
3196 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3199 java_objectheader *ro;
3202 /* mark start of dump memory area */
3204 dumpsize = dump_size();
3206 /* get number of Java method arguments */
3208 vmargscount = m->parseddesc->paramcount;
3210 /* allocate vm_arg array */
3212 vmargs = DMNEW(vm_arg, vmargscount);
3214 /* fill the vm_arg array from a va_list */
3216 vm_vmargs_from_valist(m, o, vmargs, ap);
3218 /* call the Java method */
3220 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
3222 /* release dump area */
3224 dump_release(dumpsize);
3228 java_objectheader *ro;
3232 /* mark start of dump memory area */
3234 dumpsize = dump_size();
3236 /* fill the argument array from a va_list */
3238 array = vm_array_from_valist(m, o, ap);
3240 /* call the Java method */
3242 ro = vm_call_array(m, array);
3244 /* release dump area */
3246 dump_release(dumpsize);
3253 /* vm_call_method_jvalue *******************************************************
3255 Calls a Java method with a variable number of arguments, passed via
3256 a jvalue array, and returns an address.
3258 *******************************************************************************/
3260 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
3263 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3266 java_objectheader *ro;
3269 /* mark start of dump memory area */
3271 dumpsize = dump_size();
3273 /* get number of Java method arguments */
3275 vmargscount = m->parseddesc->paramcount;
3277 /* allocate vm_arg array */
3279 vmargs = DMNEW(vm_arg, vmargscount);
3281 /* fill the vm_arg array from a va_list */
3283 vm_vmargs_from_jvalue(m, o, vmargs, args);
3285 /* call the Java method */
3287 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
3289 /* release dump area */
3291 dump_release(dumpsize);
3295 java_objectheader *ro;
3299 /* mark start of dump memory area */
3301 dumpsize = dump_size();
3303 /* fill the argument array from a va_list */
3305 array = vm_array_from_jvalue(m, o, args);
3307 /* call the Java method */
3309 ro = vm_call_array(m, array);
3311 /* release dump area */
3313 dump_release(dumpsize);
3320 /* vm_call_array ***************************************************************
3322 Calls a Java method with a variable number of arguments, passed via
3323 an argument array, and returns an address.
3325 *******************************************************************************/
3327 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3328 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
3331 java_objectheader *o;
3333 STATISTICS(count_calls_native_to_java++);
3335 #if defined(ENABLE_JIT)
3336 # if defined(ENABLE_INTRP)
3338 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3341 o = asm_vm_call_method(m, vmargscount, vmargs);
3343 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3349 java_objectheader *vm_call_array(methodinfo *m, uint64_t *array)
3352 java_objectheader *o;
3356 /* compile the method if not already done */
3358 if (m->code == NULL)
3359 if (!jit_compile(m))
3362 STATISTICS(count_calls_native_to_java++);
3364 #if defined(ENABLE_JIT)
3365 # if defined(ENABLE_INTRP)
3367 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3370 o = asm_vm_call_method(m->code->entrypoint, array, md->memuse);
3372 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3380 /* vm_call_int_array ***********************************************************
3382 Calls a Java method with a variable number of arguments, passed via
3383 an argument array, and returns an integer (int32_t).
3385 *******************************************************************************/
3387 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3388 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3392 STATISTICS(count_calls_native_to_java++);
3394 #if defined(ENABLE_JIT)
3395 # if defined(ENABLE_INTRP)
3397 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3400 i = asm_vm_call_method_int(m, vmargscount, vmargs);
3402 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3408 int32_t vm_call_int_array(methodinfo *m, uint64_t *array)
3415 /* compile the method if not already done */
3417 if (m->code == NULL)
3418 if (!jit_compile(m))
3421 STATISTICS(count_calls_native_to_java++);
3423 #if defined(ENABLE_JIT)
3424 # if defined(ENABLE_INTRP)
3426 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3429 i = asm_vm_call_method_int(m->code->entrypoint, array, md->memuse);
3431 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3439 /* vm_call_method_int **********************************************************
3441 Calls a Java method with a variable number of arguments and returns
3444 *******************************************************************************/
3446 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
3452 i = vm_call_method_int_valist(m, o, ap);
3459 /* vm_call_method_int_valist ***************************************************
3461 Calls a Java method with a variable number of arguments, passed via
3462 a va_list, and returns an integer (int32_t).
3464 *******************************************************************************/
3466 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3467 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
3474 /* mark start of dump memory area */
3476 dumpsize = dump_size();
3478 /* get number of Java method arguments */
3480 vmargscount = m->parseddesc->paramcount;
3482 /* allocate vm_arg array */
3484 vmargs = DMNEW(vm_arg, vmargscount);
3486 /* fill the vm_arg array from a va_list */
3488 vm_vmargs_from_valist(m, o, vmargs, ap);
3490 /* call the Java method */
3492 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
3494 /* release dump area */
3496 dump_release(dumpsize);
3501 int32_t vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
3507 /* mark start of dump memory area */
3509 dumpsize = dump_size();
3511 /* fill the argument array from a va_list */
3513 array = vm_array_from_valist(m, o, ap);
3515 /* call the Java method */
3517 i = vm_call_int_array(m, array);
3519 /* release dump area */
3521 dump_release(dumpsize);
3528 /* vm_call_method_int_jvalue ***************************************************
3530 Calls a Java method with a variable number of arguments, passed via
3531 a jvalue array, and returns an integer (s4).
3533 *******************************************************************************/
3535 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3536 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o,
3544 /* mark start of dump memory area */
3546 dumpsize = dump_size();
3548 /* get number of Java method arguments */
3550 vmargscount = m->parseddesc->paramcount;
3552 /* allocate vm_arg array */
3554 vmargs = DMNEW(vm_arg, vmargscount);
3556 /* fill the vm_arg array from a va_list */
3558 vm_vmargs_from_jvalue(m, o, vmargs, args);
3560 /* call the Java method */
3562 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
3564 /* release dump area */
3566 dump_release(dumpsize);
3571 int32_t vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o,
3578 /* mark start of dump memory area */
3580 dumpsize = dump_size();
3582 /* fill the argument array from a va_list */
3584 array = vm_array_from_jvalue(m, o, args);
3586 /* call the Java method */
3588 i = vm_call_int_array(m, array);
3590 /* release dump area */
3592 dump_release(dumpsize);
3599 /* vm_call_long_array **********************************************************
3601 Calls a Java method with a variable number of arguments, passed via
3602 an argument array, and returns a long (int64_t).
3604 *******************************************************************************/
3606 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3607 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3611 STATISTICS(count_calls_native_to_java++);
3613 #if defined(ENABLE_JIT)
3614 # if defined(ENABLE_INTRP)
3616 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3619 l = asm_vm_call_method_long(m, vmargscount, vmargs);
3621 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3627 int64_t vm_call_long_array(methodinfo *m, uint64_t *array)
3634 /* compile the method if not already done */
3636 if (m->code == NULL)
3637 if (!jit_compile(m))
3640 STATISTICS(count_calls_native_to_java++);
3642 #if defined(ENABLE_JIT)
3643 # if defined(ENABLE_INTRP)
3645 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3648 l = asm_vm_call_method_long(m->code->entrypoint, array, md->memuse);
3650 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3658 /* vm_call_method_long *********************************************************
3660 Calls a Java method with a variable number of arguments and returns
3663 *******************************************************************************/
3665 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
3671 l = vm_call_method_long_valist(m, o, ap);
3678 /* vm_call_method_long_valist **************************************************
3680 Calls a Java method with a variable number of arguments, passed via
3681 a va_list, and returns a long (s8).
3683 *******************************************************************************/
3685 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3686 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
3693 /* mark start of dump memory area */
3695 dumpsize = dump_size();
3697 /* get number of Java method arguments */
3699 vmargscount = m->parseddesc->paramcount;
3701 /* allocate vm_arg array */
3703 vmargs = DMNEW(vm_arg, vmargscount);
3705 /* fill the vm_arg array from a va_list */
3707 vm_vmargs_from_valist(m, o, vmargs, ap);
3709 /* call the Java method */
3711 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
3713 /* release dump area */
3715 dump_release(dumpsize);
3720 int64_t vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
3726 /* mark start of dump memory area */
3728 dumpsize = dump_size();
3730 /* fill the argument array from a va_list */
3732 array = vm_array_from_valist(m, o, ap);
3734 /* call the Java method */
3736 l = vm_call_long_array(m, array);
3738 /* release dump area */
3740 dump_release(dumpsize);
3747 /* vm_call_method_long_jvalue **************************************************
3749 Calls a Java method with a variable number of arguments, passed via
3750 a jvalue array, and returns a long (s8).
3752 *******************************************************************************/
3754 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3755 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o,
3763 /* mark start of dump memory area */
3765 dumpsize = dump_size();
3767 /* get number of Java method arguments */
3769 vmargscount = m->parseddesc->paramcount;
3771 /* allocate vm_arg array */
3773 vmargs = DMNEW(vm_arg, vmargscount);
3775 /* fill the vm_arg array from a va_list */
3777 vm_vmargs_from_jvalue(m, o, vmargs, args);
3779 /* call the Java method */
3781 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
3783 /* release dump area */
3785 dump_release(dumpsize);
3790 int64_t vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o,
3797 /* mark start of dump memory area */
3799 dumpsize = dump_size();
3801 /* fill the argument array from a va_list */
3803 array = vm_array_from_jvalue(m, o, args);
3805 /* call the Java method */
3807 l = vm_call_long_array(m, array);
3809 /* release dump area */
3811 dump_release(dumpsize);
3818 /* vm_call_float_array *********************************************************
3820 Calls a Java method with a variable number of arguments and returns
3823 *******************************************************************************/
3825 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3826 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3830 vm_abort("IMPLEMENT ME!");
3832 STATISTICS(count_calls_native_to_java++);
3834 #if defined(ENABLE_JIT)
3835 # if defined(ENABLE_INTRP)
3837 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3840 f = asm_vm_call_method_float(m, vmargscount, vmargs);
3842 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3848 float vm_call_float_array(methodinfo *m, uint64_t *array)
3855 /* compile the method if not already done */
3857 if (m->code == NULL)
3858 if (!jit_compile(m))
3861 STATISTICS(count_calls_native_to_java++);
3863 #if defined(ENABLE_JIT)
3864 # if defined(ENABLE_INTRP)
3866 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3869 f = asm_vm_call_method_float(m->code->entrypoint, array, md->memuse);
3871 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3878 /* vm_call_method_float ********************************************************
3880 Calls a Java method with a variable number of arguments and returns
3883 *******************************************************************************/
3885 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
3891 f = vm_call_method_float_valist(m, o, ap);
3898 /* vm_call_method_float_valist *************************************************
3900 Calls a Java method with a variable number of arguments, passed via
3901 a va_list, and returns a float.
3903 *******************************************************************************/
3905 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3906 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
3914 /* mark start of dump memory area */
3916 dumpsize = dump_size();
3918 /* get number of Java method arguments */
3920 vmargscount = m->parseddesc->paramcount;
3922 /* allocate vm_arg array */
3924 vmargs = DMNEW(vm_arg, vmargscount);
3926 /* fill the vm_arg array from a va_list */
3928 vm_vmargs_from_valist(m, o, vmargs, ap);
3930 /* call the Java method */
3932 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
3934 /* release dump area */
3936 dump_release(dumpsize);
3941 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o, va_list ap)
3947 /* mark start of dump memory area */
3949 dumpsize = dump_size();
3951 /* fill the argument array from a va_list */
3953 array = vm_array_from_valist(m, o, ap);
3955 /* call the Java method */
3957 f = vm_call_float_array(m, array);
3959 /* release dump area */
3961 dump_release(dumpsize);
3967 /* vm_call_method_float_jvalue *************************************************
3969 Calls a Java method with a variable number of arguments, passed via
3970 a jvalue array, and returns a float.
3972 *******************************************************************************/
3974 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3975 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
3983 /* mark start of dump memory area */
3985 dumpsize = dump_size();
3987 /* get number of Java method arguments */
3989 vmargscount = m->parseddesc->paramcount;
3991 /* allocate vm_arg array */
3993 vmargs = DMNEW(vm_arg, vmargscount);
3995 /* fill the vm_arg array from a va_list */
3997 vm_vmargs_from_jvalue(m, o, vmargs, args);
3999 /* call the Java method */
4001 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
4003 /* release dump area */
4005 dump_release(dumpsize);
4010 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o, const jvalue *args)
4016 /* mark start of dump memory area */
4018 dumpsize = dump_size();
4020 /* fill the argument array from a va_list */
4022 array = vm_array_from_jvalue(m, o, args);
4024 /* call the Java method */
4026 f = vm_call_float_array(m, array);
4028 /* release dump area */
4030 dump_release(dumpsize);
4037 /* vm_call_double_array ********************************************************
4039 Calls a Java method with a variable number of arguments and returns
4042 *******************************************************************************/
4044 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
4045 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
4050 vm_abort("IMPLEMENT ME!");
4052 STATISTICS(count_calls_native_to_java++);
4054 #if defined(ENABLE_JIT)
4055 # if defined(ENABLE_INTRP)
4057 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4060 d = asm_vm_call_method_double(m, vmargscount, vmargs);
4062 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4068 double vm_call_double_array(methodinfo *m, uint64_t *array)
4075 /* compile the method if not already done */
4077 if (m->code == NULL)
4078 if (!jit_compile(m))
4081 STATISTICS(count_calls_native_to_java++);
4083 #if defined(ENABLE_JIT)
4084 # if defined(ENABLE_INTRP)
4086 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4089 d = asm_vm_call_method_double(m->code->entrypoint, array, md->memuse);
4091 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4099 /* vm_call_method_double *******************************************************
4101 Calls a Java method with a variable number of arguments and returns
4104 *******************************************************************************/
4106 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
4112 d = vm_call_method_double_valist(m, o, ap);
4119 /* vm_call_method_double_valist ************************************************
4121 Calls a Java method with a variable number of arguments, passed via
4122 a va_list, and returns a double.
4124 *******************************************************************************/
4126 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
4127 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
4135 /* mark start of dump memory area */
4137 dumpsize = dump_size();
4139 /* get number of Java method arguments */
4141 vmargscount = m->parseddesc->paramcount;
4143 /* allocate vm_arg array */
4145 vmargs = DMNEW(vm_arg, vmargscount);
4147 /* fill the vm_arg array from a va_list */
4149 vm_vmargs_from_valist(m, o, vmargs, ap);
4151 /* call the Java method */
4153 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
4155 /* release dump area */
4157 dump_release(dumpsize);
4162 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o, va_list ap)
4168 /* mark start of dump memory area */
4170 dumpsize = dump_size();
4172 /* fill the argument array from a va_list */
4174 array = vm_array_from_valist(m, o, ap);
4176 /* call the Java method */
4178 d = vm_call_double_array(m, array);
4180 /* release dump area */
4182 dump_release(dumpsize);
4189 /* vm_call_method_double_jvalue ************************************************
4191 Calls a Java method with a variable number of arguments, passed via
4192 a jvalue array, and returns a double.
4194 *******************************************************************************/
4196 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
4197 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
4205 /* mark start of dump memory area */
4207 dumpsize = dump_size();
4209 /* get number of Java method arguments */
4211 vmargscount = m->parseddesc->paramcount;
4213 /* allocate vm_arg array */
4215 vmargs = DMNEW(vm_arg, vmargscount);
4217 /* fill the vm_arg array from a va_list */
4219 vm_vmargs_from_jvalue(m, o, vmargs, args);
4221 /* call the Java method */
4223 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
4225 /* release dump area */
4227 dump_release(dumpsize);
4232 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o, const jvalue *args)
4238 /* mark start of dump memory area */
4240 dumpsize = dump_size();
4242 /* fill the argument array from a va_list */
4244 array = vm_array_from_jvalue(m, o, args);
4246 /* call the Java method */
4248 d = vm_call_double_array(m, array);
4250 /* release dump area */
4252 dump_release(dumpsize);
4259 * These are local overrides for various environment variables in Emacs.
4260 * Please do not remove this and leave it at the end of the file, where
4261 * Emacs will automagically detect them.
4262 * ---------------------------------------------------------------------
4265 * indent-tabs-mode: t