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 8213 2007-07-18 20:08:26Z 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 #endif /* defined(ENABLE_INLINING_DEBUG) */
261 #endif /* defined(ENABLE_INLINING) */
263 #if defined(ENABLE_INTRP)
264 /* interpreter options */
283 #if defined(ENABLE_DEBUG_FILTER)
284 OPT_FILTER_VERBOSECALL_INCLUDE,
285 OPT_FILTER_VERBOSECALL_EXCLUDE,
286 OPT_FILTER_SHOW_METHOD,
293 opt_struct opts[] = {
294 { "foo", false, OPT_FOO },
298 { "jar", false, OPT_JAR },
300 { "d32", false, OPT_D32 },
301 { "d64", false, OPT_D64 },
302 { "client", false, OPT_IGNORE },
303 { "server", false, OPT_IGNORE },
304 { "jvm", false, OPT_IGNORE },
305 { "hotspot", false, OPT_IGNORE },
307 { "classpath", true, OPT_CLASSPATH },
308 { "cp", true, OPT_CLASSPATH },
309 { "D", true, OPT_D },
310 { "version", false, OPT_VERSION },
311 { "showversion", false, OPT_SHOWVERSION },
312 { "fullversion", false, OPT_FULLVERSION },
313 { "help", false, OPT_HELP },
314 { "?", false, OPT_HELP },
315 { "X", false, OPT_X },
316 { "XX:", true, OPT_XX },
317 { "XX", false, OPT_XX },
319 { "ea:", true, OPT_EA },
320 { "da:", true, OPT_DA },
321 { "ea", false, OPT_EA },
322 { "da", false, OPT_DA },
324 { "esa", false, OPT_ESA },
325 { "enablesystemassertions", false, OPT_ESA },
326 { "dsa", false, OPT_DSA },
327 { "disablesystemassertions", false, OPT_DSA },
329 { "noasyncgc", false, OPT_IGNORE },
330 #if defined(ENABLE_VERIFIER)
331 { "noverify", false, OPT_NOVERIFY },
333 { "v", false, OPT_VERBOSE1 },
334 { "verbose:", true, OPT_VERBOSE },
336 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
337 { "verbosetc", false, OPT_VERBOSETC },
339 #if defined(__ALPHA__)
340 { "noieee", false, OPT_NOIEEE },
342 #if defined(ENABLE_STATISTICS)
343 { "time", false, OPT_TIME },
344 { "stat", false, OPT_STAT },
346 { "log", true, OPT_LOG },
347 { "c", true, OPT_CHECK },
348 { "l", false, OPT_LOAD },
349 { "eager", false, OPT_EAGER },
352 { "all", false, OPT_ALL },
353 { "sig", true, OPT_SIGNATURE },
356 #if defined(ENABLE_LOOP)
357 { "oloop", false, OPT_OLOOP },
359 #if defined(ENABLE_IFCONV)
360 { "ifconv", false, OPT_IFCONV },
362 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
363 { "lsra", false, OPT_LSRA },
366 #if defined(ENABLE_INTRP)
367 /* interpreter options */
369 { "trace", false, OPT_TRACE },
370 { "static-supers", true, OPT_STATIC_SUPERS },
371 { "no-dynamic", false, OPT_NO_DYNAMIC },
372 { "no-replication", false, OPT_NO_REPLICATION },
373 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
376 /* JVMTI Agent Command Line Options */
378 { "agentlib:", true, OPT_AGENTLIB },
379 { "agentpath:", true, OPT_AGENTPATH },
382 /* Java non-standard options */
384 { "Xjit", false, OPT_JIT },
385 { "Xint", false, OPT_INTRP },
386 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
387 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
388 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
389 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
392 { "Xdebug", false, OPT_DEBUG },
393 { "Xnoagent", false, OPT_NOAGENT },
394 { "Xrunjdwp", true, OPT_XRUNJDWP },
397 { "Xms", true, OPT_MS },
398 { "ms", true, OPT_MS },
399 { "Xmx", true, OPT_MX },
400 { "mx", true, OPT_MX },
401 { "Xss", true, OPT_SS },
402 { "ss", true, OPT_SS },
404 #if defined(ENABLE_PROFILING)
405 { "Xprof:", true, OPT_PROF_OPTION },
406 { "Xprof", false, OPT_PROF },
409 /* inlining options */
411 #if defined(ENABLE_INLINING)
412 #if defined(ENABLE_INLINING_DEBUG)
413 { "ia", false, OPT_INLINE_DEBUG_ALL },
414 { "ii", true, OPT_INLINE_DEBUG_MIN },
415 { "im", true, OPT_INLINE_DEBUG_MAX },
416 { "ie", true, OPT_INLINE_DEBUG_END },
417 #endif /* defined(ENABLE_INLINING_DEBUG) */
419 { "il", false, OPT_INLINE_LOG },
421 { "i", false, OPT_INLINING },
422 #endif /* defined(ENABLE_INLINING) */
424 /* keep these at the end of the list */
427 { "m", true, OPT_METHOD },
430 { "s", true, OPT_SHOW },
431 { "debug-color", false, OPT_DEBUGCOLOR },
433 #if defined(ENABLE_DEBUG_FILTER)
434 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
435 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
436 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
443 /* usage ***********************************************************************
445 Prints the correct usage syntax to stdout.
447 *******************************************************************************/
451 puts("Usage: cacao [-options] classname [arguments]");
452 puts(" (to run a class file)");
453 puts(" or cacao [-options] -jar jarfile [arguments]");
454 puts(" (to run a standalone jar file)\n");
456 puts("where options include:");
457 puts(" -d32 use 32-bit data model if available");
458 puts(" -d64 use 64-bit data model if available");
459 puts(" -client compatibility (currently ignored)");
460 puts(" -server compatibility (currently ignored)");
461 puts(" -jvm compatibility (currently ignored)");
462 puts(" -hotspot compatibility (currently ignored)\n");
464 puts(" -cp <path> specify a path to look for classes");
465 puts(" -classpath <path> specify a path to look for classes");
466 puts(" -D<name>=<value> add an entry to the property list");
467 puts(" -verbose[:class|gc|jni] enable specific verbose output");
468 puts(" -version print product version and exit");
469 puts(" -fullversion print jpackage-compatible product version and exit");
470 puts(" -showversion print product version and continue");
471 puts(" -help, -? print this help message");
472 puts(" -X print help on non-standard Java options");
473 puts(" -XX print help on debugging options");
474 puts(" -ea[:<packagename>...|:<classname>]");
475 puts(" -enableassertions[:<packagename>...|:<classname>]");
476 puts(" enable assertions with specified granularity");
477 puts(" -da[:<packagename>...|:<classname>]");
478 puts(" -disableassertions[:<packagename>...|:<classname>]");
479 puts(" disable assertions with specified granularity");
480 puts(" -esa | -enablesystemassertions");
481 puts(" enable system assertions");
482 puts(" -dsa | -disablesystemassertions");
483 puts(" disable system assertions");
486 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
487 puts (" for jdwp help use: -agentlib:jdwp=help");
488 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
491 /* exit with error code */
497 static void Xusage(void)
499 #if defined(ENABLE_JIT)
500 puts(" -Xjit JIT mode execution (default)");
502 #if defined(ENABLE_INTRP)
503 puts(" -Xint interpreter mode execution");
505 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
506 puts(" value is set as bootstrap class path");
507 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
508 puts(" value is appended to the bootstrap class path");
509 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
510 puts(" value is prepended to the bootstrap class path");
511 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
512 puts(" value is used as Java core library, but the");
513 puts(" hardcoded VM interface classes are prepended");
514 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
515 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
516 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
518 #if defined(ENABLE_PROFILING)
519 puts(" -Xprof[:bb] collect and print profiling data");
522 #if defined(ENABLE_JVMTI)
523 /* -Xdebug option depend on gnu classpath JDWP options. options:
524 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
525 puts(" -Xdebug enable remote debugging\n");
526 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
527 puts(" enable remote debugging\n");
530 /* exit with error code */
536 static void XXusage(void)
538 puts(" -v write state-information");
540 puts(" -verbose[:jit|threads]");
541 puts(" enable specific verbose output");
542 puts(" -debug-color colored output for ANSI terms");
544 #ifdef TYPECHECK_VERBOSE
545 puts(" -verbosetc write debug messages while typechecking");
547 #if defined(__ALPHA__)
548 puts(" -noieee don't use ieee compliant arithmetic");
550 #if defined(ENABLE_VERIFIER)
551 puts(" -noverify don't verify classfiles");
553 #if defined(ENABLE_STATISTICS)
554 puts(" -time measure the runtime");
555 puts(" -stat detailed compiler statistics");
557 puts(" -log logfile specify a name for the logfile");
558 puts(" -c(heck)b(ounds) don't check array bounds");
559 puts(" s(ync) don't check for synchronization");
560 #if defined(ENABLE_LOOP)
561 puts(" -oloop optimize array accesses in loops");
563 puts(" -l don't start the class after loading");
564 puts(" -eager perform eager class loading and linking");
566 puts(" -all compile all methods, no execution");
567 puts(" -m compile only a specific method");
568 puts(" -sig specify signature for a specific method");
571 puts(" -s... show...");
572 puts(" (c)onstants the constant pool");
573 puts(" (m)ethods class fields and methods");
574 puts(" (u)tf the utf - hash");
575 puts(" (i)ntermediate intermediate representation");
576 #if defined(ENABLE_DISASSEMBLER)
577 puts(" (a)ssembler disassembled listing");
578 puts(" n(o)ps show NOPs in disassembler output");
579 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
580 puts(" (n)ative disassembled native stubs");
582 puts(" (d)atasegment data segment listing");
584 #if defined(ENABLE_INLINING)
585 puts(" -i activate inlining");
587 puts(" -il log inlining");
589 #if defined(ENABLE_INLINING_DEBUG)
590 puts(" -ia use inlining for all methods");
591 puts(" -ii <size> set minimum size for inlined result");
592 puts(" -im <size> set maximum size for inlined result");
593 puts(" -ie <number> stop inlining after the given number of roots");
594 #endif /* defined(ENABLE_INLINING_DEBUG) */
595 #endif /* defined(ENABLE_INLINING) */
597 #if defined(ENABLE_IFCONV)
598 puts(" -ifconv use if-conversion");
600 #if defined(ENABLE_LSRA)
601 puts(" -lsra use linear scan register allocation");
603 #if defined(ENABLE_SSA)
604 puts(" -lsra use linear scan register allocation (with SSA)");
606 #if defined(ENABLE_DEBUG_FILTER)
607 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
608 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
609 puts(" -XXfm <regex> filter for show options");
611 /* exit with error code */
617 /* version *********************************************************************
619 Only prints cacao version information.
621 *******************************************************************************/
623 static void version(bool opt_exit)
625 puts("java version \""JAVA_VERSION"\"");
626 puts("CACAO version "VERSION"");
628 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
629 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
630 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
631 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
633 puts("This program is free software; you can redistribute it and/or");
634 puts("modify it under the terms of the GNU General Public License as");
635 puts("published by the Free Software Foundation; either version 2, or (at");
636 puts("your option) any later version.\n");
638 puts("This program is distributed in the hope that it will be useful, but");
639 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
640 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
641 puts("General Public License for more details.\n");
643 puts("Configure/Build options:\n");
644 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
645 #if defined(__VERSION__)
646 puts(" CC : "VERSION_CC" ("__VERSION__")");
648 puts(" CC : "VERSION_CC"");
650 puts(" CFLAGS : "VERSION_CFLAGS"\n");
652 puts("Default variables:\n");
653 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
654 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
655 printf(" stack size : %d\n", STACK_SIZE);
656 #if defined(WITH_CLASSPATH_GNU)
657 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
659 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
661 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
663 puts("Runtime variables:\n");
664 printf(" maximum heap size : %d\n", opt_heapmaxsize);
665 printf(" initial heap size : %d\n", opt_heapstartsize);
666 printf(" stack size : %d\n", opt_stacksize);
667 printf(" libjvm.so : %s\n", cacao_libjvm);
668 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
669 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
670 printf(" java.class.path : %s\n", _Jv_classpath);
672 /* exit normally, if requested */
679 /* fullversion *****************************************************************
681 Prints a Sun compatible version information (required e.g. by
682 jpackage, www.jpackage.org).
684 *******************************************************************************/
686 static void fullversion(void)
688 puts("java full version \"cacao-"JAVA_VERSION"\"");
696 /* forward declarations *******************************************************/
698 static char *vm_get_mainclass_from_jar(char *mainstring);
700 static void vm_compile_all(void);
701 static void vm_compile_method(void);
705 /* vm_createjvm ****************************************************************
707 Implementation for JNI_CreateJavaVM.
709 *******************************************************************************/
711 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
713 JavaVMInitArgs *_vm_args;
717 /* get the arguments for the new JVM */
719 _vm_args = (JavaVMInitArgs *) vm_args;
721 /* get the VM and Env tables (must be set before vm_create) */
723 env = NEW(_Jv_JNIEnv);
725 #if defined(ENABLE_JNI)
726 env->env = &_Jv_JNINativeInterface;
729 /* XXX Set the global variable. Maybe we should do that differently. */
733 /* create and fill a JavaVM structure */
735 vm = NEW(_Jv_JavaVM);
737 #if defined(ENABLE_JNI)
738 vm->functions = &_Jv_JNIInvokeInterface;
741 /* XXX Set the global variable. Maybe we should do that differently. */
742 /* XXX JVMTI Agents needs a JavaVM */
746 /* actually create the JVM */
748 if (!vm_create(_vm_args))
751 #if defined(ENABLE_JNI)
752 /* setup the local ref table (must be created after vm_create) */
754 if (!jni_init_localref_table())
758 /* now return the values */
760 *p_vm = (JavaVM *) vm;
761 *p_env = (void *) env;
766 /* release allocated memory */
768 FREE(env, _Jv_JNIEnv);
769 FREE(vm, _Jv_JavaVM);
775 /* vm_create *******************************************************************
777 Creates a JVM. Called by vm_createjvm.
779 *******************************************************************************/
781 bool vm_create(JavaVMInitArgs *vm_args)
790 #if defined(ENABLE_JVMTI)
792 char *libname, *agentarg;
793 bool jdwp,agentbypath;
794 jdwp = agentbypath = false;
797 #if defined(ENABLE_VMLOG)
798 vmlog_cacao_init(vm_args);
801 /* check the JNI version requested */
803 switch (vm_args->version) {
804 case JNI_VERSION_1_1:
806 case JNI_VERSION_1_2:
807 case JNI_VERSION_1_4:
813 /* we only support 1 JVM instance */
818 if (atexit(vm_exit_handler))
819 vm_abort("atexit failed: %s\n", strerror(errno));
822 log_text("CACAO started -------------------------------------------------------");
824 /* We need to check if the actual size of a java.lang.Class object
825 is smaller or equal than the assumption made in
826 src/vmcore/class.h. */
828 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
829 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
831 /* set the VM starttime */
833 _Jv_jvm->starttime = builtin_currenttimemillis();
835 /* get stuff from the environment *****************************************/
837 #if defined(WITH_JRE_LAYOUT)
838 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
840 cacao_prefix = MNEW(char, 4096);
842 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
843 vm_abort("readlink failed: %s\n", strerror(errno));
845 /* get the path of the current executable */
847 cacao_prefix = dirname(cacao_prefix);
849 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
850 vm_abort("libjvm name to long for buffer\n");
852 /* concatenate the library name */
854 strcat(cacao_prefix, "/..");
856 /* now set path to libjvm.so */
858 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
860 cacao_libjvm = MNEW(char, len);
861 strcpy(cacao_libjvm, cacao_prefix);
862 strcat(cacao_libjvm, "/lib/libjvm");
864 /* and finally set the path to GNU Classpath libraries */
866 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
868 classpath_libdir = MNEW(char, len);
869 strcpy(classpath_libdir, cacao_prefix);
870 strcat(classpath_libdir, "/lib/classpath");
872 cacao_prefix = CACAO_PREFIX;
873 cacao_libjvm = CACAO_LIBDIR"/libjvm";
875 # if defined(WITH_CLASSPATH_GNU)
876 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
878 classpath_libdir = CLASSPATH_LIBDIR;
882 /* set the bootclasspath */
884 cp = getenv("BOOTCLASSPATH");
887 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
888 strcpy(_Jv_bootclasspath, cp);
891 #if defined(WITH_JRE_LAYOUT)
893 # if defined(WITH_CLASSPATH_GNU)
894 strlen(cacao_prefix) +
895 strlen("/share/cacao/vm.zip") +
898 strlen(cacao_prefix) +
899 strlen("/share/classpath/glibj.zip") +
902 _Jv_bootclasspath = MNEW(char, len);
903 # if defined(WITH_CLASSPATH_GNU)
904 strcat(_Jv_bootclasspath, cacao_prefix);
905 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
906 strcat(_Jv_bootclasspath, ":");
908 strcat(_Jv_bootclasspath, cacao_prefix);
909 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
912 # if defined(WITH_CLASSPATH_GNU)
913 strlen(CACAO_VM_ZIP) +
916 strlen(CLASSPATH_CLASSES) +
919 _Jv_bootclasspath = MNEW(char, len);
920 # if defined(WITH_CLASSPATH_GNU)
921 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
922 strcat(_Jv_bootclasspath, ":");
924 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
928 /* set the classpath */
930 cp = getenv("CLASSPATH");
933 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
934 strcat(_Jv_classpath, cp);
937 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
938 strcpy(_Jv_classpath, ".");
941 /* get and set java.library.path */
943 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
945 if (_Jv_java_library_path == NULL)
946 _Jv_java_library_path = "";
948 /* interpret the options **************************************************/
955 opt_heapmaxsize = HEAP_MAXSIZE;
956 opt_heapstartsize = HEAP_STARTSIZE;
957 opt_stacksize = STACK_SIZE;
960 #if defined(ENABLE_JVMTI)
961 /* initialize JVMTI related **********************************************/
965 /* initialize and fill properties before command-line handling */
967 if (!properties_init())
968 vm_abort("properties_init failed");
970 /* iterate over all passed options */
972 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
986 #if SIZEOF_VOID_P == 8
987 puts("Running a 32-bit JVM is not supported on this platform.");
993 #if SIZEOF_VOID_P == 4
994 puts("Running a 64-bit JVM is not supported on this platform.");
1000 /* forget old classpath and set the argument as new classpath */
1001 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1003 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
1004 strcpy(_Jv_classpath, opt_arg);
1008 for (i = 0; i < strlen(opt_arg); i++) {
1009 if (opt_arg[i] == '=') {
1011 properties_add(opt_arg, opt_arg + i + 1);
1016 /* if no '=' is given, just create an empty property */
1018 properties_add(opt_arg, "");
1023 case OPT_BOOTCLASSPATH:
1024 /* Forget default bootclasspath and set the argument as
1025 new boot classpath. */
1027 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1029 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
1030 strcpy(_Jv_bootclasspath, opt_arg);
1033 case OPT_BOOTCLASSPATH_A:
1034 /* append to end of bootclasspath */
1036 len = strlen(_Jv_bootclasspath);
1038 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
1042 strlen(opt_arg) + strlen("0"));
1044 strcat(_Jv_bootclasspath, ":");
1045 strcat(_Jv_bootclasspath, opt_arg);
1048 case OPT_BOOTCLASSPATH_P:
1049 /* prepend in front of bootclasspath */
1051 cp = _Jv_bootclasspath;
1054 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1057 strcpy(_Jv_bootclasspath, opt_arg);
1058 strcat(_Jv_bootclasspath, ":");
1059 strcat(_Jv_bootclasspath, cp);
1061 MFREE(cp, char, len);
1064 case OPT_BOOTCLASSPATH_C:
1065 /* use as Java core library, but prepend VM interface classes */
1067 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1069 len = strlen(CACAO_VM_ZIP) +
1074 _Jv_bootclasspath = MNEW(char, len);
1076 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1077 strcat(_Jv_bootclasspath, ":");
1078 strcat(_Jv_bootclasspath, opt_arg);
1081 #if defined(ENABLE_JVMTI)
1083 /* this option exists only for compatibility reasons */
1087 /* I don't know yet what Xnoagent should do. This is only for
1088 compatiblity with eclipse - motse */
1097 strlen(CACAO_LIBDIR) +
1098 strlen("/libjdwp.so=") +
1102 agentarg = MNEW(char, len);
1104 strcpy(agentarg, CACAO_LIBDIR);
1105 strcat(agentarg, "/libjdwp.so=");
1106 strcat(agentarg, &opt_arg[1]);
1123 c = opt_arg[strlen(opt_arg) - 1];
1125 if ((c == 'k') || (c == 'K')) {
1126 j = atoi(opt_arg) * 1024;
1128 } else if ((c == 'm') || (c == 'M')) {
1129 j = atoi(opt_arg) * 1024 * 1024;
1135 opt_heapmaxsize = j;
1136 else if (opt == OPT_MS)
1137 opt_heapstartsize = j;
1148 if (strcmp("class", opt_arg) == 0) {
1149 opt_verboseclass = true;
1151 else if (strcmp("gc", opt_arg) == 0) {
1152 opt_verbosegc = true;
1154 else if (strcmp("jni", opt_arg) == 0) {
1155 opt_verbosejni = true;
1157 #if !defined(NDEBUG)
1158 else if (strcmp("jit", opt_arg) == 0) {
1163 compileverbose = true;
1165 else if (strcmp("threads", opt_arg) == 0) {
1166 opt_verbosethreads = true;
1170 printf("Unknown -verbose option: %s\n", opt_arg);
1175 case OPT_DEBUGCOLOR:
1176 opt_debugcolor = true;
1179 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1181 opt_typecheckverbose = true;
1190 case OPT_FULLVERSION:
1194 case OPT_SHOWVERSION:
1202 #if defined(ENABLE_VERIFIER)
1208 #if defined(ENABLE_STATISTICS)
1210 opt_getcompilingtime = true;
1211 opt_getloadingtime = true;
1224 for (i = 0; i < strlen(opt_arg); i++) {
1225 switch (opt_arg[i]) {
1227 checkbounds = false;
1240 makeinitializations = false;
1247 #if !defined(NDEBUG)
1251 makeinitializations = false;
1256 opt_method = opt_arg;
1257 makeinitializations = false;
1261 opt_signature = opt_arg;
1265 case OPT_SHOW: /* Display options */
1266 for (i = 0; i < strlen(opt_arg); i++) {
1267 switch (opt_arg[i]) {
1269 showconstantpool = true;
1281 opt_showintermediate = true;
1282 compileverbose = true;
1285 #if defined(ENABLE_DISASSEMBLER)
1287 opt_showdisassemble = true;
1288 compileverbose = true;
1292 opt_shownops = true;
1296 opt_showexceptionstubs = true;
1300 opt_shownativestub = true;
1305 opt_showddatasegment = true;
1314 #if defined(ENABLE_LOOP)
1320 #if defined(ENABLE_INLINING)
1321 #if defined(ENABLE_INLINING_DEBUG)
1322 case OPT_INLINE_DEBUG_ALL:
1323 opt_inline_debug_all = true;
1325 case OPT_INLINE_DEBUG_END:
1326 opt_inline_debug_end_counter = atoi(opt_arg);
1328 case OPT_INLINE_DEBUG_MIN:
1329 opt_inline_debug_min_size = atoi(opt_arg);
1331 case OPT_INLINE_DEBUG_MAX:
1332 opt_inline_debug_max_size = atoi(opt_arg);
1334 #endif /* defined(ENABLE_INLINING_DEBUG) */
1335 #if !defined(NDEBUG)
1336 case OPT_INLINE_LOG:
1337 opt_inline_debug_log = true;
1339 #endif /* !defined(NDEBUG) */
1342 opt_inlining = true;
1344 #endif /* defined(ENABLE_INLINING) */
1346 #if defined(ENABLE_IFCONV)
1352 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1367 options_xx(opt_arg);
1371 /* currently ignored */
1375 /* currently ignored */
1379 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1383 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1386 #if defined(ENABLE_PROFILING)
1387 case OPT_PROF_OPTION:
1388 /* use <= to get the last \0 too */
1390 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1391 if (opt_arg[i] == ',')
1394 if (opt_arg[i] == '\0') {
1395 if (strcmp("bb", opt_arg + j) == 0)
1399 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1403 /* set k to next char */
1416 #if defined(ENABLE_JIT)
1419 printf("-Xjit option not enabled.\n");
1425 #if defined(ENABLE_INTRP)
1428 printf("-Xint option not enabled.\n");
1433 #if defined(ENABLE_INTRP)
1434 case OPT_STATIC_SUPERS:
1435 opt_static_supers = atoi(opt_arg);
1438 case OPT_NO_DYNAMIC:
1439 opt_no_dynamic = true;
1442 case OPT_NO_REPLICATION:
1443 opt_no_replication = true;
1446 case OPT_NO_QUICKSUPER:
1447 opt_no_quicksuper = true;
1455 #if defined(ENABLE_DEBUG_FILTER)
1456 case OPT_FILTER_VERBOSECALL_INCLUDE:
1457 opt_filter_verbosecall_include = opt_arg;
1460 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1461 opt_filter_verbosecall_exclude = opt_arg;
1464 case OPT_FILTER_SHOW_METHOD:
1465 opt_filter_show_method = opt_arg;
1470 printf("Unknown option: %s\n",
1471 vm_args->options[opt_index].optionString);
1476 /* get the main class *****************************************************/
1478 if (opt_index < vm_args->nOptions) {
1479 mainstring = vm_args->options[opt_index++].optionString;
1481 /* Put the jar file into the classpath (if any). */
1483 if (opt_jar == true) {
1484 /* free old classpath */
1486 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1488 /* put jarfile into classpath */
1490 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1492 strcpy(_Jv_classpath, mainstring);
1495 /* replace .'s with /'s in classname */
1497 for (i = strlen(mainstring) - 1; i >= 0; i--)
1498 if (mainstring[i] == '.')
1499 mainstring[i] = '/';
1503 #if defined(ENABLE_JVMTI)
1505 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1506 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1509 MFREE(agentarg, char, strlen(agentarg));
1511 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1515 /* initialize this JVM ****************************************************/
1517 vm_initializing = true;
1519 /* initialize the garbage collector */
1521 gc_init(opt_heapmaxsize, opt_heapstartsize);
1523 #if defined(ENABLE_THREADS)
1524 /* AFTER: gc_init (directly after, as this initializes the
1525 stopworldlock lock */
1530 /* install architecture dependent signal handlers */
1533 vm_abort("vm_create: signal_init failed");
1535 #if defined(ENABLE_INTRP)
1536 /* Allocate main thread stack on the Java heap. */
1539 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1540 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1544 /* AFTER: threads_preinit */
1547 vm_abort("vm_create: string_init failed");
1549 /* AFTER: threads_preinit */
1552 vm_abort("vm_create: utf8_init failed");
1554 /* AFTER: thread_preinit */
1557 vm_abort("vm_create: suck_init failed");
1559 suck_add_from_property("java.endorsed.dirs");
1561 /* Now we have all options handled and we can print the version
1564 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1569 /* AFTER: utf8_init */
1571 suck_add(_Jv_bootclasspath);
1573 /* Now re-set some of the properties that may have changed. This
1574 must be done after _all_ environment variables have been
1575 processes (e.g. -jar handling).
1577 AFTER: suck_add_from_property, since it may change the
1578 _Jv_bootclasspath pointer. */
1580 if (!properties_postinit())
1581 vm_abort("vm_create: properties_postinit failed");
1583 /* initialize the classcache hashtable stuff: lock, hashtable
1584 (must be done _after_ threads_preinit) */
1586 if (!classcache_init())
1587 vm_abort("vm_create: classcache_init failed");
1589 /* initialize the memory subsystem (must be done _after_
1593 vm_abort("vm_create: memory_init failed");
1595 /* initialize the finalizer stuff (must be done _after_
1598 if (!finalizer_init())
1599 vm_abort("vm_create: finalizer_init failed");
1601 /* initialize the codegen subsystems */
1605 /* initializes jit compiler */
1609 /* machine dependent initialization */
1611 #if defined(ENABLE_JIT)
1612 # if defined(ENABLE_INTRP)
1622 /* initialize the loader subsystems (must be done _after_
1626 vm_abort("vm_create: loader_init failed");
1628 /* Link some important VM classes. */
1629 /* AFTER: utf8_init */
1632 vm_abort("vm_create: linker_init failed");
1634 if (!primitive_init())
1635 vm_abort("vm_create: primitive_init failed");
1637 if (!exceptions_init())
1638 vm_abort("vm_create: exceptions_init failed");
1640 if (!builtin_init())
1641 vm_abort("vm_create: builtin_init failed");
1643 /* Initialize the native subsystem. */
1644 /* BEFORE: threads_init */
1647 vm_abort("vm_create: native_init failed");
1649 /* Register the native methods implemented in the VM. */
1650 /* BEFORE: threads_init */
1652 if (!nativevm_preinit())
1653 vm_abort("vm_create: nativevm_preinit failed");
1655 #if defined(ENABLE_JNI)
1656 /* Initialize the JNI subsystem (must be done _before_
1657 threads_init, as threads_init can call JNI methods
1658 (e.g. NewGlobalRef). */
1661 vm_abort("vm_create: jni_init failed");
1664 #if defined(ENABLE_THREADS)
1665 if (!threads_init())
1666 vm_abort("vm_create: threads_init failed");
1669 /* Initialize the native VM subsystem. */
1670 /* AFTER: threads_init (at least for SUN's classes) */
1672 if (!nativevm_init())
1673 vm_abort("vm_create: nativevm_init failed");
1675 #if defined(ENABLE_PROFILING)
1676 /* initialize profiling */
1678 if (!profile_init())
1679 vm_abort("vm_create: profile_init failed");
1682 #if defined(ENABLE_THREADS)
1683 /* initialize recompilation */
1685 if (!recompile_init())
1686 vm_abort("vm_create: recompile_init failed");
1688 /* start the signal handler thread */
1690 #if defined(__LINUX__)
1691 /* XXX Remove for exact-GC. */
1692 if (threads_pthreads_implementation_nptl)
1694 if (!signal_start_thread())
1695 vm_abort("vm_create: signal_start_thread failed");
1697 /* finally, start the finalizer thread */
1699 if (!finalizer_start_thread())
1700 vm_abort("vm_create: finalizer_start_thread failed");
1702 # if !defined(NDEBUG)
1703 /* start the memory profiling thread */
1705 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1706 if (!memory_start_thread())
1707 vm_abort("vm_create: memory_start_thread failed");
1710 /* start the recompilation thread (must be done before the
1711 profiling thread) */
1713 if (!recompile_start_thread())
1714 vm_abort("vm_create: recompile_start_thread failed");
1716 # if defined(ENABLE_PROFILING)
1717 /* start the profile sampling thread */
1720 /* if (!profile_start_thread()) */
1721 /* vm_abort("vm_create: profile_start_thread failed"); */
1725 #if defined(ENABLE_JVMTI)
1727 /* add agent library to native library hashtable */
1728 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1732 /* increment the number of VMs */
1736 /* initialization is done */
1738 vm_initializing = false;
1740 /* everything's ok */
1746 /* vm_run **********************************************************************
1748 Runs the main-method of the passed class.
1750 *******************************************************************************/
1752 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1755 classinfo *mainclass;
1756 java_objectheader *e;
1758 java_objectarray *oa;
1761 java_objectheader *s;
1765 #if !defined(NDEBUG)
1771 if (opt_method != NULL) {
1772 vm_compile_method();
1775 #endif /* !defined(NDEBUG) */
1777 /* should we run the main-method? */
1779 if (mainstring == NULL)
1782 /* set return value to OK */
1786 if (opt_jar == true) {
1787 /* open jar file with java.util.jar.JarFile */
1789 mainstring = vm_get_mainclass_from_jar(mainstring);
1791 if (mainstring == NULL)
1795 /* load the main class */
1797 mainutf = utf_new_char(mainstring);
1799 #if defined(ENABLE_JAVAME_CLDC1_1)
1800 mainclass = load_class_bootstrap(mainutf);
1802 mainclass = load_class_from_sysloader(mainutf);
1805 /* error loading class */
1807 e = exceptions_get_and_clear_exception();
1809 if ((e != NULL) || (mainclass == NULL)) {
1810 exceptions_throw_noclassdeffounderror_cause(e);
1811 exceptions_print_stacktrace();
1815 if (!link_class(mainclass)) {
1816 exceptions_print_stacktrace();
1820 /* find the `main' method of the main class */
1822 m = class_resolveclassmethod(mainclass,
1823 utf_new_char("main"),
1824 utf_new_char("([Ljava/lang/String;)V"),
1825 class_java_lang_Object,
1828 if (exceptions_get_exception()) {
1829 exceptions_print_stacktrace();
1833 /* there is no main method or it isn't static */
1835 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1836 exceptions_clear_exception();
1837 exceptions_throw_nosuchmethoderror(mainclass,
1838 utf_new_char("main"),
1839 utf_new_char("([Ljava/lang/String;)V"));
1841 exceptions_print_stacktrace();
1845 /* build argument array */
1847 oalength = vm_args->nOptions - opt_index;
1849 oa = builtin_anewarray(oalength, class_java_lang_String);
1851 for (i = 0; i < oalength; i++) {
1852 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1853 s = javastring_new(u);
1858 #ifdef TYPEINFO_DEBUG_TEST
1859 /* test the typeinfo system */
1862 /*class_showmethods(currentThread->group->header.vftbl->class); */
1864 #if defined(ENABLE_JVMTI)
1865 jvmti_set_phase(JVMTI_PHASE_LIVE);
1868 /* set ThreadMXBean variables */
1870 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1871 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1873 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1874 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1875 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1876 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1878 /* start the main thread */
1880 (void) vm_call_method(m, NULL, oa);
1882 /* exception occurred? */
1884 if (exceptions_get_exception()) {
1885 exceptions_print_stacktrace();
1889 /* unload the JavaVM */
1891 (void) vm_destroy(vm);
1899 /* vm_destroy ******************************************************************
1901 Unloads a Java VM and reclaims its resources.
1903 *******************************************************************************/
1905 s4 vm_destroy(JavaVM *vm)
1907 #if defined(ENABLE_THREADS)
1908 threads_join_all_threads();
1911 /* everything's ok */
1917 /* vm_exit *********************************************************************
1919 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1921 *******************************************************************************/
1923 void vm_exit(s4 status)
1927 /* signal that we are exiting */
1931 assert(class_java_lang_System);
1932 assert(class_java_lang_System->state & CLASS_LOADED);
1934 #if defined(ENABLE_JVMTI)
1935 if (jvmti || (dbgcom!=NULL)) {
1936 jvmti_set_phase(JVMTI_PHASE_DEAD);
1937 if (jvmti) jvmti_agentunload();
1941 if (!link_class(class_java_lang_System)) {
1942 exceptions_print_stacktrace();
1946 /* call java.lang.System.exit(I)V */
1948 m = class_resolveclassmethod(class_java_lang_System,
1949 utf_new_char("exit"),
1951 class_java_lang_Object,
1955 exceptions_print_stacktrace();
1959 /* call the exit function with passed exit status */
1961 (void) vm_call_method(m, NULL, status);
1963 /* If we had an exception, just ignore the exception and exit with
1966 vm_shutdown(status);
1970 /* vm_shutdown *****************************************************************
1972 Terminates the system immediately without freeing memory explicitly
1973 (to be used only for abnormal termination).
1975 *******************************************************************************/
1977 void vm_shutdown(s4 status)
1980 #if defined(ENABLE_STATISTICS)
1981 || opt_getcompilingtime || opt_stat
1985 log_text("CACAO terminated by shutdown");
1986 dolog("Exit status: %d\n", (s4) status);
1990 #if defined(ENABLE_JVMTI)
1991 /* terminate cacaodbgserver */
1993 pthread_mutex_lock(&dbgcomlock);
1995 pthread_mutex_unlock(&dbgcomlock);
1996 jvmti_cacaodbgserver_quit();
2004 /* vm_exit_handler *************************************************************
2006 The exit_handler function is called upon program termination.
2008 ATTENTION: Don't free system resources here! Some threads may still
2009 be running as this is called from VMRuntime.exit(). The OS does the
2012 *******************************************************************************/
2014 void vm_exit_handler(void)
2016 #if !defined(NDEBUG)
2018 class_showmethods(mainclass);
2020 if (showconstantpool)
2021 class_showconstantpool(mainclass);
2026 # if defined(ENABLE_PROFILING)
2028 profile_printstats();
2030 #endif /* !defined(NDEBUG) */
2032 #if defined(ENABLE_RT_TIMING)
2033 rt_timing_print_time_stats(stderr);
2036 #if defined(ENABLE_CYCLES_STATS)
2037 builtin_print_cycles_stats(stderr);
2038 stacktrace_print_cycles_stats(stderr);
2042 #if defined(ENABLE_STATISTICS)
2043 || opt_getcompilingtime || opt_stat
2047 log_text("CACAO terminated");
2049 #if defined(ENABLE_STATISTICS)
2052 #ifdef TYPECHECK_STATISTICS
2053 typecheck_print_statistics(get_logfile());
2057 if (opt_getcompilingtime)
2059 #endif /* defined(ENABLE_STATISTICS) */
2061 /* vm_print_profile(stderr);*/
2065 /* vm_abort ********************************************************************
2067 Prints an error message and aborts the VM.
2069 *******************************************************************************/
2071 void vm_abort(const char *text, ...)
2075 /* print the log message */
2080 log_vprint(text, ap);
2085 /* now abort the VM */
2091 /* vm_get_mainclass_from_jar ***************************************************
2093 Gets the name of the main class from a JAR's manifest file.
2095 *******************************************************************************/
2097 static char *vm_get_mainclass_from_jar(char *mainstring)
2100 java_objectheader *o;
2102 java_objectheader *s;
2104 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2107 exceptions_print_stacktrace();
2111 /* create JarFile object */
2116 exceptions_print_stacktrace();
2120 m = class_resolveclassmethod(c,
2122 utf_java_lang_String__void,
2123 class_java_lang_Object,
2127 exceptions_print_stacktrace();
2131 s = javastring_new_from_ascii(mainstring);
2133 (void) vm_call_method(m, o, s);
2135 if (exceptions_get_exception()) {
2136 exceptions_print_stacktrace();
2140 /* get manifest object */
2142 m = class_resolveclassmethod(c,
2143 utf_new_char("getManifest"),
2144 utf_new_char("()Ljava/util/jar/Manifest;"),
2145 class_java_lang_Object,
2149 exceptions_print_stacktrace();
2153 o = vm_call_method(m, o);
2156 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2161 /* get Main Attributes */
2163 m = class_resolveclassmethod(o->vftbl->class,
2164 utf_new_char("getMainAttributes"),
2165 utf_new_char("()Ljava/util/jar/Attributes;"),
2166 class_java_lang_Object,
2170 exceptions_print_stacktrace();
2174 o = vm_call_method(m, o);
2177 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2182 /* get property Main-Class */
2184 m = class_resolveclassmethod(o->vftbl->class,
2185 utf_new_char("getValue"),
2186 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2187 class_java_lang_Object,
2191 exceptions_print_stacktrace();
2195 s = javastring_new_from_ascii("Main-Class");
2197 o = vm_call_method(m, o, s);
2200 exceptions_print_stacktrace();
2204 return javastring_tochar(o);
2208 /* vm_compile_all **************************************************************
2210 Compile all methods found in the bootclasspath.
2212 *******************************************************************************/
2214 #if !defined(NDEBUG)
2215 static void vm_compile_all(void)
2220 classcache_name_entry *nmen;
2221 classcache_class_entry *clsen;
2224 /* create all classes found in the bootclasspath */
2225 /* XXX currently only works with zip/jar's */
2227 loader_load_all_classes();
2229 /* link all classes */
2231 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2232 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2234 for (; nmen; nmen = nmen->hashlink) {
2235 /* iterate over all class entries */
2237 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2238 c = clsen->classobj;
2243 if (!(c->state & CLASS_LINKED)) {
2244 if (!link_class(c)) {
2245 fprintf(stderr, "Error linking: ");
2246 utf_fprint_printable_ascii_classname(stderr, c->name);
2247 fprintf(stderr, "\n");
2249 /* print out exception and cause */
2251 exceptions_print_current_exception();
2253 /* goto next class */
2259 /* compile all class methods */
2261 for (i = 0; i < c->methodscount; i++) {
2262 m = &(c->methods[i]);
2264 if (m->jcode != NULL) {
2265 if (!jit_compile(m)) {
2266 fprintf(stderr, "Error compiling: ");
2267 utf_fprint_printable_ascii_classname(stderr, c->name);
2268 fprintf(stderr, ".");
2269 utf_fprint_printable_ascii(stderr, m->name);
2270 utf_fprint_printable_ascii(stderr, m->descriptor);
2271 fprintf(stderr, "\n");
2273 /* print out exception and cause */
2275 exceptions_print_current_exception();
2283 #endif /* !defined(NDEBUG) */
2286 /* vm_compile_method ***********************************************************
2288 Compile a specific method.
2290 *******************************************************************************/
2292 #if !defined(NDEBUG)
2293 static void vm_compile_method(void)
2297 /* create, load and link the main class */
2299 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2301 if (mainclass == NULL)
2302 exceptions_print_stacktrace();
2304 if (!link_class(mainclass))
2305 exceptions_print_stacktrace();
2307 if (opt_signature != NULL) {
2308 m = class_resolveclassmethod(mainclass,
2309 utf_new_char(opt_method),
2310 utf_new_char(opt_signature),
2315 m = class_resolveclassmethod(mainclass,
2316 utf_new_char(opt_method),
2323 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2324 opt_method, opt_signature ? opt_signature : "");
2328 #endif /* !defined(NDEBUG) */
2331 /* vm_array_store_int **********************************************************
2333 Helper function to store an integer into the argument array, taking
2334 care of architecture specific issues.
2336 *******************************************************************************/
2338 static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
2342 if (!pd->inmemory) {
2344 array[index] = (int64_t) value;
2347 index = ARG_CNT + pd->index;
2348 #if SIZEOF_VOID_P == 8
2349 array[index] = (int64_t) value;
2351 # if WORDS_BIGENDIAN == 1
2352 array[index] = ((int64_t) value) << 32;
2354 array[index] = (int64_t) value;
2361 /* vm_array_store_lng **********************************************************
2363 Helper function to store a long into the argument array, taking
2364 care of architecture specific issues.
2366 *******************************************************************************/
2368 static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
2372 #if SIZEOF_VOID_P == 8
2376 index = ARG_CNT + pd->index;
2378 array[index] = value;
2380 if (!pd->inmemory) {
2381 /* move low and high 32-bits into it's own argument slot */
2383 index = GET_LOW_REG(pd->index);
2384 array[index] = value & 0x00000000ffffffff;
2386 index = GET_HIGH_REG(pd->index);
2387 array[index] = value >> 32;
2390 index = ARG_CNT + pd->index;
2391 array[index] = value;
2397 /* vm_array_store_flt **********************************************************
2399 Helper function to store a float into the argument array, taking
2400 care of architecture specific issues.
2402 *******************************************************************************/
2404 static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
2408 if (!pd->inmemory) {
2409 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2412 index = INT_ARG_CNT + pd->index;
2414 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2415 array[index] = value >> 32;
2417 array[index] = value;
2421 index = ARG_CNT + pd->index;
2422 #if defined(__SPARC_64__)
2423 array[index] = value >> 32;
2425 array[index] = value;
2431 /* vm_array_store_dbl **********************************************************
2433 Helper function to store a double into the argument array, taking
2434 care of architecture specific issues.
2436 *******************************************************************************/
2438 static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
2442 if (!pd->inmemory) {
2443 #if SIZEOF_VOID_P != 8 && defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2444 index = GET_LOW_REG(pd->index);
2445 array[index] = value & 0x00000000ffffffff;
2447 index = GET_HIGH_REG(pd->index);
2448 array[index] = value >> 32;
2450 index = INT_ARG_CNT + pd->index;
2451 array[index] = value;
2455 index = ARG_CNT + pd->index;
2456 array[index] = value;
2461 /* vm_array_store_adr **********************************************************
2463 Helper function to store an address into the argument array, taking
2464 care of architecture specific issues.
2466 *******************************************************************************/
2468 static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
2472 if (!pd->inmemory) {
2473 #if defined(HAS_ADDRESS_REGISTER_FILE)
2474 /* When the architecture has address registers, place them
2475 after integer and float registers. */
2477 index = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
2481 array[index] = (uint64_t) (intptr_t) value;
2484 index = ARG_CNT + pd->index;
2485 #if SIZEOF_VOID_P == 8
2486 array[index] = (uint64_t) (intptr_t) value;
2488 # if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2489 array[index] = ((uint64_t) (intptr_t) value) << 32;
2491 array[index] = (uint64_t) (intptr_t) value;
2498 /* vm_vmargs_from_valist *******************************************************
2502 *******************************************************************************/
2504 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
2505 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2506 vm_arg *vmargs, va_list ap)
2508 typedesc *paramtypes;
2511 paramtypes = m->parseddesc->paramtypes;
2513 /* if method is non-static fill first block and skip `this' pointer */
2518 /* the `this' pointer */
2519 vmargs[0].type = TYPE_ADR;
2520 vmargs[0].data.l = (u8) (ptrint) o;
2526 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2527 switch (paramtypes->type) {
2529 vmargs[i].type = TYPE_INT;
2530 vmargs[i].data.l = (s8) va_arg(ap, s4);
2534 vmargs[i].type = TYPE_LNG;
2535 vmargs[i].data.l = (s8) va_arg(ap, s8);
2539 vmargs[i].type = TYPE_FLT;
2540 #if defined(__ALPHA__)
2541 /* this keeps the assembler function much simpler */
2543 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2545 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2550 vmargs[i].type = TYPE_DBL;
2551 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2555 vmargs[i].type = TYPE_ADR;
2556 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2562 uint64_t *vm_array_from_valist(methodinfo *m, java_objectheader *o, va_list ap)
2571 /* get the descriptors */
2575 td = md->paramtypes;
2577 /* allocate argument array */
2579 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2581 /* if method is non-static fill first block and skip `this' pointer */
2586 /* the `this' pointer */
2587 vm_array_store_adr(array, pd, o);
2594 for (; i < md->paramcount; i++, pd++, td++) {
2597 value.i = va_arg(ap, int32_t);
2598 vm_array_store_int(array, pd, value.i);
2602 value.l = va_arg(ap, int64_t);
2603 vm_array_store_lng(array, pd, value.l);
2607 #if defined(__ALPHA__) || defined(__POWERPC64__)
2608 /* this keeps the assembler function much simpler */
2610 value.d = (double) va_arg(ap, double);
2612 value.f = (float) va_arg(ap, double);
2614 vm_array_store_flt(array, pd, value.l);
2618 value.d = va_arg(ap, double);
2619 vm_array_store_dbl(array, pd, value.l);
2623 value.a = va_arg(ap, void*);
2624 vm_array_store_adr(array, pd, value.a);
2634 /* vm_vmargs_from_jvalue *******************************************************
2638 *******************************************************************************/
2640 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
2641 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2642 vm_arg *vmargs, const jvalue *args)
2644 typedesc *paramtypes;
2648 paramtypes = m->parseddesc->paramtypes;
2650 /* if method is non-static fill first block and skip `this' pointer */
2655 /* the `this' pointer */
2656 vmargs[0].type = TYPE_ADR;
2657 vmargs[0].data.l = (u8) (ptrint) o;
2663 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2664 switch (paramtypes->decltype) {
2666 vmargs[i].type = TYPE_INT;
2667 vmargs[i].data.l = (s8) args[j].i;
2671 vmargs[i].type = TYPE_LNG;
2672 vmargs[i].data.l = (s8) args[j].j;
2676 vmargs[i].type = TYPE_FLT;
2677 #if defined(__ALPHA__)
2678 /* this keeps the assembler function much simpler */
2680 vmargs[i].data.d = (jdouble) args[j].f;
2682 vmargs[i].data.f = args[j].f;
2687 vmargs[i].type = TYPE_DBL;
2688 vmargs[i].data.d = args[j].d;
2692 vmargs[i].type = TYPE_ADR;
2693 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2699 static uint64_t *vm_array_from_jvalue(methodinfo *m, java_objectheader *o,
2709 /* get the descriptors */
2713 td = md->paramtypes;
2715 /* allocate argument array */
2717 #if defined(HAS_ADDRESS_REGISTER_FILE)
2718 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
2720 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2723 /* if method is non-static fill first block and skip `this' pointer */
2728 /* the `this' pointer */
2729 vm_array_store_adr(array, pd, o);
2736 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2737 switch (td->decltype) {
2739 vm_array_store_int(array, pd, args[j].i);
2743 vm_array_store_lng(array, pd, args[j].j);
2747 vm_array_store_flt(array, pd, args[j].j);
2751 vm_array_store_dbl(array, pd, args[j].j);
2755 vm_array_store_adr(array, pd, args[j].l);
2764 /* vm_vmargs_from_objectarray **************************************************
2768 *******************************************************************************/
2770 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
2771 bool vm_vmargs_from_objectarray(methodinfo *m, java_objectheader *o,
2772 vm_arg *vmargs, java_objectarray *params)
2774 java_objectheader *param;
2775 typedesc *paramtypes;
2781 paramtypes = m->parseddesc->paramtypes;
2783 /* if method is non-static fill first block and skip `this' pointer */
2789 vmargs[0].type = TYPE_ADR;
2790 vmargs[0].data.l = (uint64_t) (intptr_t) o;
2796 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2797 switch (paramtypes->type) {
2798 /* primitive types */
2803 param = params->data[j];
2808 /* internally used data type */
2809 vmargs[i].type = paramtypes->type;
2811 /* convert the value according to its declared type */
2813 c = param->vftbl->class;
2815 switch (paramtypes->decltype) {
2816 case PRIMITIVETYPE_BOOLEAN:
2817 if (c == class_java_lang_Boolean)
2818 value = (int64_t) ((java_lang_Boolean *) param)->value;
2822 vmargs[i].data.l = value;
2825 case PRIMITIVETYPE_BYTE:
2826 if (c == class_java_lang_Byte)
2827 value = (int64_t) ((java_lang_Byte *) param)->value;
2831 vmargs[i].data.l = value;
2834 case PRIMITIVETYPE_CHAR:
2835 if (c == class_java_lang_Character)
2836 value = (int64_t) ((java_lang_Character *) param)->value;
2840 vmargs[i].data.l = value;
2843 case PRIMITIVETYPE_SHORT:
2844 if (c == class_java_lang_Short)
2845 value = (int64_t) ((java_lang_Short *) param)->value;
2846 else if (c == class_java_lang_Byte)
2847 value = (int64_t) ((java_lang_Byte *) param)->value;
2851 vmargs[i].data.l = value;
2854 case PRIMITIVETYPE_INT:
2855 if (c == class_java_lang_Integer)
2856 value = (int64_t) ((java_lang_Integer *) param)->value;
2857 else if (c == class_java_lang_Short)
2858 value = (int64_t) ((java_lang_Short *) param)->value;
2859 else if (c == class_java_lang_Byte)
2860 value = (int64_t) ((java_lang_Byte *) param)->value;
2864 vmargs[i].data.l = value;
2867 case PRIMITIVETYPE_LONG:
2868 if (c == class_java_lang_Long)
2869 value = (int64_t) ((java_lang_Long *) param)->value;
2870 else if (c == class_java_lang_Integer)
2871 value = (int64_t) ((java_lang_Integer *) param)->value;
2872 else if (c == class_java_lang_Short)
2873 value = (int64_t) ((java_lang_Short *) param)->value;
2874 else if (c == class_java_lang_Byte)
2875 value = (int64_t) ((java_lang_Byte *) param)->value;
2879 vmargs[i].data.l = value;
2882 case PRIMITIVETYPE_FLOAT:
2883 if (c == class_java_lang_Float)
2884 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
2889 case PRIMITIVETYPE_DOUBLE:
2890 if (c == class_java_lang_Double)
2891 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
2892 else if (c == class_java_lang_Float)
2893 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
2904 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
2907 if (params->data[j] != 0) {
2908 if (paramtypes->arraydim > 0) {
2909 if (!builtin_arrayinstanceof(params->data[j], c))
2913 if (!builtin_instanceof(params->data[j], c))
2918 vmargs[i].type = TYPE_ADR;
2919 vmargs[i].data.l = (u8) (ptrint) params->data[j];
2928 /* *rettype = descr->returntype.decltype; */
2933 exceptions_throw_illegalargumentexception();
2937 uint64_t *vm_array_from_objectarray(methodinfo *m, java_objectheader *o,
2938 java_objectarray *params)
2944 java_objectheader *param;
2950 /* get the descriptors */
2954 td = md->paramtypes;
2956 /* allocate argument array */
2958 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2960 /* if method is non-static fill first block and skip `this' pointer */
2966 vm_array_store_adr(array, pd, o);
2973 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2974 param = params->data[j];
2981 /* convert the value according to its declared type */
2983 c = param->vftbl->class;
2985 switch (td->decltype) {
2986 case PRIMITIVETYPE_BOOLEAN:
2987 if (c == class_java_lang_Boolean)
2988 value.i = ((java_lang_Boolean *) param)->value;
2993 case PRIMITIVETYPE_BYTE:
2994 if (c == class_java_lang_Byte)
2995 value.i = ((java_lang_Byte *) param)->value;
3000 case PRIMITIVETYPE_CHAR:
3001 if (c == class_java_lang_Character)
3002 value.i = ((java_lang_Character *) param)->value;
3007 case PRIMITIVETYPE_SHORT:
3008 if (c == class_java_lang_Short)
3009 value.i = ((java_lang_Short *) param)->value;
3010 else if (c == class_java_lang_Byte)
3011 value.i = ((java_lang_Byte *) param)->value;
3016 case PRIMITIVETYPE_INT:
3017 if (c == class_java_lang_Integer)
3018 value.i = ((java_lang_Integer *) param)->value;
3019 else if (c == class_java_lang_Short)
3020 value.i = ((java_lang_Short *) param)->value;
3021 else if (c == class_java_lang_Byte)
3022 value.i = ((java_lang_Byte *) param)->value;
3031 vm_array_store_int(array, pd, value.i);
3038 /* convert the value according to its declared type */
3040 c = param->vftbl->class;
3042 switch (td->decltype) {
3043 case PRIMITIVETYPE_LONG:
3044 if (c == class_java_lang_Long)
3045 value.l = ((java_lang_Long *) param)->value;
3046 else if (c == class_java_lang_Integer)
3047 value.l = (int64_t) ((java_lang_Integer *) param)->value;
3048 else if (c == class_java_lang_Short)
3049 value.l = (int64_t) ((java_lang_Short *) param)->value;
3050 else if (c == class_java_lang_Byte)
3051 value.l = (int64_t) ((java_lang_Byte *) param)->value;
3060 vm_array_store_lng(array, pd, value.l);
3067 /* convert the value according to its declared type */
3069 c = param->vftbl->class;
3071 switch (td->decltype) {
3072 case PRIMITIVETYPE_FLOAT:
3073 if (c == class_java_lang_Float)
3074 value.f = ((java_lang_Float *) param)->value;
3083 vm_array_store_flt(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_DOUBLE:
3096 if (c == class_java_lang_Double)
3097 value.d = ((java_lang_Double *) param)->value;
3098 else if (c == class_java_lang_Float)
3099 value.f = ((java_lang_Float *) param)->value;
3108 vm_array_store_dbl(array, pd, value.l);
3112 if (!resolve_class_from_typedesc(td, true, true, &c))
3115 if (param != NULL) {
3116 if (td->arraydim > 0) {
3117 if (!builtin_arrayinstanceof(param, c))
3121 if (!builtin_instanceof(param, c))
3126 vm_array_store_adr(array, pd, param);
3137 exceptions_throw_illegalargumentexception();
3143 /* vm_call_method **************************************************************
3145 Calls a Java method with a variable number of arguments and returns
3148 *******************************************************************************/
3150 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
3153 java_objectheader *ro;
3156 ro = vm_call_method_valist(m, o, ap);
3163 /* vm_call_method_valist *******************************************************
3165 Calls a Java method with a variable number of arguments, passed via
3166 a va_list, and returns an address.
3168 *******************************************************************************/
3170 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
3173 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3176 java_objectheader *ro;
3179 /* mark start of dump memory area */
3181 dumpsize = dump_size();
3183 /* get number of Java method arguments */
3185 vmargscount = m->parseddesc->paramcount;
3187 /* allocate vm_arg array */
3189 vmargs = DMNEW(vm_arg, vmargscount);
3191 /* fill the vm_arg array from a va_list */
3193 vm_vmargs_from_valist(m, o, vmargs, ap);
3195 /* call the Java method */
3197 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
3199 /* release dump area */
3201 dump_release(dumpsize);
3205 java_objectheader *ro;
3209 /* mark start of dump memory area */
3211 dumpsize = dump_size();
3213 /* fill the argument array from a va_list */
3215 array = vm_array_from_valist(m, o, ap);
3217 /* call the Java method */
3219 ro = vm_call_array(m, array);
3221 /* release dump area */
3223 dump_release(dumpsize);
3230 /* vm_call_method_jvalue *******************************************************
3232 Calls a Java method with a variable number of arguments, passed via
3233 a jvalue array, and returns an address.
3235 *******************************************************************************/
3237 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
3240 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3243 java_objectheader *ro;
3246 /* mark start of dump memory area */
3248 dumpsize = dump_size();
3250 /* get number of Java method arguments */
3252 vmargscount = m->parseddesc->paramcount;
3254 /* allocate vm_arg array */
3256 vmargs = DMNEW(vm_arg, vmargscount);
3258 /* fill the vm_arg array from a va_list */
3260 vm_vmargs_from_jvalue(m, o, vmargs, args);
3262 /* call the Java method */
3264 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
3266 /* release dump area */
3268 dump_release(dumpsize);
3272 java_objectheader *ro;
3276 /* mark start of dump memory area */
3278 dumpsize = dump_size();
3280 /* fill the argument array from a va_list */
3282 array = vm_array_from_jvalue(m, o, args);
3284 /* call the Java method */
3286 ro = vm_call_array(m, array);
3288 /* release dump area */
3290 dump_release(dumpsize);
3297 /* vm_call_array ***************************************************************
3299 Calls a Java method with a variable number of arguments, passed via
3300 an argument array, and returns an address.
3302 *******************************************************************************/
3304 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3305 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
3308 java_objectheader *o;
3310 STATISTICS(count_calls_native_to_java++);
3312 #if defined(ENABLE_JIT)
3313 # if defined(ENABLE_INTRP)
3315 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3318 o = asm_vm_call_method(m, vmargscount, vmargs);
3320 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3326 java_objectheader *vm_call_array(methodinfo *m, uint64_t *array)
3329 java_objectheader *o;
3333 /* compile the method if not already done */
3335 if (m->code == NULL)
3336 if (!jit_compile(m))
3339 STATISTICS(count_calls_native_to_java++);
3341 #if defined(ENABLE_JIT)
3342 # if defined(ENABLE_INTRP)
3344 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3347 o = asm_vm_call_method(m->code->entrypoint, array, md->memuse);
3349 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3357 /* vm_call_int_array ***********************************************************
3359 Calls a Java method with a variable number of arguments, passed via
3360 an argument array, and returns an integer (int32_t).
3362 *******************************************************************************/
3364 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3365 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3369 STATISTICS(count_calls_native_to_java++);
3371 #if defined(ENABLE_JIT)
3372 # if defined(ENABLE_INTRP)
3374 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3377 i = asm_vm_call_method_int(m, vmargscount, vmargs);
3379 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3385 int32_t vm_call_int_array(methodinfo *m, uint64_t *array)
3392 /* compile the method if not already done */
3394 if (m->code == NULL)
3395 if (!jit_compile(m))
3398 STATISTICS(count_calls_native_to_java++);
3400 #if defined(ENABLE_JIT)
3401 # if defined(ENABLE_INTRP)
3403 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3406 i = asm_vm_call_method_int(m->code->entrypoint, array, md->memuse);
3408 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3416 /* vm_call_method_int **********************************************************
3418 Calls a Java method with a variable number of arguments and returns
3421 *******************************************************************************/
3423 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
3429 i = vm_call_method_int_valist(m, o, ap);
3436 /* vm_call_method_int_valist ***************************************************
3438 Calls a Java method with a variable number of arguments, passed via
3439 a va_list, and returns an integer (int32_t).
3441 *******************************************************************************/
3443 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3444 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
3451 /* mark start of dump memory area */
3453 dumpsize = dump_size();
3455 /* get number of Java method arguments */
3457 vmargscount = m->parseddesc->paramcount;
3459 /* allocate vm_arg array */
3461 vmargs = DMNEW(vm_arg, vmargscount);
3463 /* fill the vm_arg array from a va_list */
3465 vm_vmargs_from_valist(m, o, vmargs, ap);
3467 /* call the Java method */
3469 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
3471 /* release dump area */
3473 dump_release(dumpsize);
3478 int32_t vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
3484 /* mark start of dump memory area */
3486 dumpsize = dump_size();
3488 /* fill the argument array from a va_list */
3490 array = vm_array_from_valist(m, o, ap);
3492 /* call the Java method */
3494 i = vm_call_int_array(m, array);
3496 /* release dump area */
3498 dump_release(dumpsize);
3505 /* vm_call_method_int_jvalue ***************************************************
3507 Calls a Java method with a variable number of arguments, passed via
3508 a jvalue array, and returns an integer (s4).
3510 *******************************************************************************/
3512 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3513 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o,
3521 /* mark start of dump memory area */
3523 dumpsize = dump_size();
3525 /* get number of Java method arguments */
3527 vmargscount = m->parseddesc->paramcount;
3529 /* allocate vm_arg array */
3531 vmargs = DMNEW(vm_arg, vmargscount);
3533 /* fill the vm_arg array from a va_list */
3535 vm_vmargs_from_jvalue(m, o, vmargs, args);
3537 /* call the Java method */
3539 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
3541 /* release dump area */
3543 dump_release(dumpsize);
3548 int32_t vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o,
3555 /* mark start of dump memory area */
3557 dumpsize = dump_size();
3559 /* fill the argument array from a va_list */
3561 array = vm_array_from_jvalue(m, o, args);
3563 /* call the Java method */
3565 i = vm_call_int_array(m, array);
3567 /* release dump area */
3569 dump_release(dumpsize);
3576 /* vm_call_long_array **********************************************************
3578 Calls a Java method with a variable number of arguments, passed via
3579 an argument array, and returns a long (int64_t).
3581 *******************************************************************************/
3583 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3584 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3588 STATISTICS(count_calls_native_to_java++);
3590 #if defined(ENABLE_JIT)
3591 # if defined(ENABLE_INTRP)
3593 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3596 l = asm_vm_call_method_long(m, vmargscount, vmargs);
3598 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3604 int64_t vm_call_long_array(methodinfo *m, uint64_t *array)
3611 /* compile the method if not already done */
3613 if (m->code == NULL)
3614 if (!jit_compile(m))
3617 STATISTICS(count_calls_native_to_java++);
3619 #if defined(ENABLE_JIT)
3620 # if defined(ENABLE_INTRP)
3622 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3625 l = asm_vm_call_method_long(m->code->entrypoint, array, md->memuse);
3627 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3635 /* vm_call_method_long *********************************************************
3637 Calls a Java method with a variable number of arguments and returns
3640 *******************************************************************************/
3642 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
3648 l = vm_call_method_long_valist(m, o, ap);
3655 /* vm_call_method_long_valist **************************************************
3657 Calls a Java method with a variable number of arguments, passed via
3658 a va_list, and returns a long (s8).
3660 *******************************************************************************/
3662 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3663 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
3670 /* mark start of dump memory area */
3672 dumpsize = dump_size();
3674 /* get number of Java method arguments */
3676 vmargscount = m->parseddesc->paramcount;
3678 /* allocate vm_arg array */
3680 vmargs = DMNEW(vm_arg, vmargscount);
3682 /* fill the vm_arg array from a va_list */
3684 vm_vmargs_from_valist(m, o, vmargs, ap);
3686 /* call the Java method */
3688 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
3690 /* release dump area */
3692 dump_release(dumpsize);
3697 int64_t vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
3703 /* mark start of dump memory area */
3705 dumpsize = dump_size();
3707 /* fill the argument array from a va_list */
3709 array = vm_array_from_valist(m, o, ap);
3711 /* call the Java method */
3713 l = vm_call_long_array(m, array);
3715 /* release dump area */
3717 dump_release(dumpsize);
3724 /* vm_call_method_long_jvalue **************************************************
3726 Calls a Java method with a variable number of arguments, passed via
3727 a jvalue array, and returns a long (s8).
3729 *******************************************************************************/
3731 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3732 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o,
3740 /* mark start of dump memory area */
3742 dumpsize = dump_size();
3744 /* get number of Java method arguments */
3746 vmargscount = m->parseddesc->paramcount;
3748 /* allocate vm_arg array */
3750 vmargs = DMNEW(vm_arg, vmargscount);
3752 /* fill the vm_arg array from a va_list */
3754 vm_vmargs_from_jvalue(m, o, vmargs, args);
3756 /* call the Java method */
3758 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
3760 /* release dump area */
3762 dump_release(dumpsize);
3767 int64_t vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o,
3774 /* mark start of dump memory area */
3776 dumpsize = dump_size();
3778 /* fill the argument array from a va_list */
3780 array = vm_array_from_jvalue(m, o, args);
3782 /* call the Java method */
3784 l = vm_call_long_array(m, array);
3786 /* release dump area */
3788 dump_release(dumpsize);
3795 /* vm_call_float_array *********************************************************
3797 Calls a Java method with a variable number of arguments and returns
3800 *******************************************************************************/
3802 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3803 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3807 vm_abort("IMPLEMENT ME!");
3809 STATISTICS(count_calls_native_to_java++);
3811 #if defined(ENABLE_JIT)
3812 # if defined(ENABLE_INTRP)
3814 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3817 f = asm_vm_call_method_float(m, vmargscount, vmargs);
3819 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3825 float vm_call_float_array(methodinfo *m, uint64_t *array)
3832 /* compile the method if not already done */
3834 if (m->code == NULL)
3835 if (!jit_compile(m))
3838 STATISTICS(count_calls_native_to_java++);
3840 #if defined(ENABLE_JIT)
3841 # if defined(ENABLE_INTRP)
3843 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3846 f = asm_vm_call_method_float(m->code->entrypoint, array, md->memuse);
3848 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3855 /* vm_call_method_float ********************************************************
3857 Calls a Java method with a variable number of arguments and returns
3860 *******************************************************************************/
3862 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
3868 f = vm_call_method_float_valist(m, o, ap);
3875 /* vm_call_method_float_valist *************************************************
3877 Calls a Java method with a variable number of arguments, passed via
3878 a va_list, and returns a float.
3880 *******************************************************************************/
3882 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3883 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
3891 /* mark start of dump memory area */
3893 dumpsize = dump_size();
3895 /* get number of Java method arguments */
3897 vmargscount = m->parseddesc->paramcount;
3899 /* allocate vm_arg array */
3901 vmargs = DMNEW(vm_arg, vmargscount);
3903 /* fill the vm_arg array from a va_list */
3905 vm_vmargs_from_valist(m, o, vmargs, ap);
3907 /* call the Java method */
3909 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
3911 /* release dump area */
3913 dump_release(dumpsize);
3918 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o, va_list ap)
3924 /* mark start of dump memory area */
3926 dumpsize = dump_size();
3928 /* fill the argument array from a va_list */
3930 array = vm_array_from_valist(m, o, ap);
3932 /* call the Java method */
3934 f = vm_call_float_array(m, array);
3936 /* release dump area */
3938 dump_release(dumpsize);
3944 /* vm_call_method_float_jvalue *************************************************
3946 Calls a Java method with a variable number of arguments, passed via
3947 a jvalue array, and returns a float.
3949 *******************************************************************************/
3951 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
3952 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
3960 /* mark start of dump memory area */
3962 dumpsize = dump_size();
3964 /* get number of Java method arguments */
3966 vmargscount = m->parseddesc->paramcount;
3968 /* allocate vm_arg array */
3970 vmargs = DMNEW(vm_arg, vmargscount);
3972 /* fill the vm_arg array from a va_list */
3974 vm_vmargs_from_jvalue(m, o, vmargs, args);
3976 /* call the Java method */
3978 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
3980 /* release dump area */
3982 dump_release(dumpsize);
3987 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o, const jvalue *args)
3993 /* mark start of dump memory area */
3995 dumpsize = dump_size();
3997 /* fill the argument array from a va_list */
3999 array = vm_array_from_jvalue(m, o, args);
4001 /* call the Java method */
4003 f = vm_call_float_array(m, array);
4005 /* release dump area */
4007 dump_release(dumpsize);
4014 /* vm_call_double_array ********************************************************
4016 Calls a Java method with a variable number of arguments and returns
4019 *******************************************************************************/
4021 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
4022 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
4027 vm_abort("IMPLEMENT ME!");
4029 STATISTICS(count_calls_native_to_java++);
4031 #if defined(ENABLE_JIT)
4032 # if defined(ENABLE_INTRP)
4034 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4037 d = asm_vm_call_method_double(m, vmargscount, vmargs);
4039 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4045 double vm_call_double_array(methodinfo *m, uint64_t *array)
4052 /* compile the method if not already done */
4054 if (m->code == NULL)
4055 if (!jit_compile(m))
4058 STATISTICS(count_calls_native_to_java++);
4060 #if defined(ENABLE_JIT)
4061 # if defined(ENABLE_INTRP)
4063 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4066 d = asm_vm_call_method_double(m->code->entrypoint, array, md->memuse);
4068 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4076 /* vm_call_method_double *******************************************************
4078 Calls a Java method with a variable number of arguments and returns
4081 *******************************************************************************/
4083 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
4089 d = vm_call_method_double_valist(m, o, ap);
4096 /* vm_call_method_double_valist ************************************************
4098 Calls a Java method with a variable number of arguments, passed via
4099 a va_list, and returns a double.
4101 *******************************************************************************/
4103 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
4104 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
4112 /* mark start of dump memory area */
4114 dumpsize = dump_size();
4116 /* get number of Java method arguments */
4118 vmargscount = m->parseddesc->paramcount;
4120 /* allocate vm_arg array */
4122 vmargs = DMNEW(vm_arg, vmargscount);
4124 /* fill the vm_arg array from a va_list */
4126 vm_vmargs_from_valist(m, o, vmargs, ap);
4128 /* call the Java method */
4130 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
4132 /* release dump area */
4134 dump_release(dumpsize);
4139 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o, va_list ap)
4145 /* mark start of dump memory area */
4147 dumpsize = dump_size();
4149 /* fill the argument array from a va_list */
4151 array = vm_array_from_valist(m, o, ap);
4153 /* call the Java method */
4155 d = vm_call_double_array(m, array);
4157 /* release dump area */
4159 dump_release(dumpsize);
4166 /* vm_call_method_double_jvalue ************************************************
4168 Calls a Java method with a variable number of arguments, passed via
4169 a jvalue array, and returns a double.
4171 *******************************************************************************/
4173 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
4174 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
4182 /* mark start of dump memory area */
4184 dumpsize = dump_size();
4186 /* get number of Java method arguments */
4188 vmargscount = m->parseddesc->paramcount;
4190 /* allocate vm_arg array */
4192 vmargs = DMNEW(vm_arg, vmargscount);
4194 /* fill the vm_arg array from a va_list */
4196 vm_vmargs_from_jvalue(m, o, vmargs, args);
4198 /* call the Java method */
4200 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
4202 /* release dump area */
4204 dump_release(dumpsize);
4209 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o, const jvalue *args)
4215 /* mark start of dump memory area */
4217 dumpsize = dump_size();
4219 /* fill the argument array from a va_list */
4221 array = vm_array_from_jvalue(m, o, args);
4223 /* call the Java method */
4225 d = vm_call_double_array(m, array);
4227 /* release dump area */
4229 dump_release(dumpsize);
4236 * These are local overrides for various environment variables in Emacs.
4237 * Please do not remove this and leave it at the end of the file, where
4238 * Emacs will automagically detect them.
4239 * ---------------------------------------------------------------------
4242 * indent-tabs-mode: t