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 8106 2007-06-19 22:50: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"
54 #include "native/include/java_lang_String.h" /* required by java_lang_Class.h */
55 #include "native/include/java_lang_Class.h"
57 #include "native/include/java_lang_Byte.h"
58 #include "native/include/java_lang_Character.h"
59 #include "native/include/java_lang_Short.h"
60 #include "native/include/java_lang_Integer.h"
61 #include "native/include/java_lang_Boolean.h"
62 #include "native/include/java_lang_Long.h"
63 #include "native/include/java_lang_Float.h"
64 #include "native/include/java_lang_Double.h"
66 #include "threads/threads-common.h"
68 #include "toolbox/logging.h"
70 #include "vm/builtin.h"
71 #include "vm/exceptions.h"
72 #include "vm/finalizer.h"
73 #include "vm/global.h"
74 #include "vm/initialize.h"
75 #include "vm/properties.h"
76 #include "vm/signallocal.h"
77 #include "vm/stringlocal.h"
80 #include "vm/jit/jit.h"
81 #include "vm/jit/md.h"
82 #include "vm/jit/asmpart.h"
84 #if defined(ENABLE_PROFILING)
85 # include "vm/jit/optimizing/profile.h"
88 #include "vm/jit/optimizing/recompile.h"
90 #include "vmcore/classcache.h"
91 #include "vmcore/options.h"
92 #include "vmcore/primitive.h"
93 #include "vmcore/statistics.h"
94 #include "vmcore/suck.h"
96 #if defined(ENABLE_JVMTI)
97 # include "native/jvmti/cacaodbg.h"
100 #if defined(ENABLE_VMLOG)
101 #include <vmlog_cacao.h>
105 /* Invocation API variables ***************************************************/
107 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
108 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
111 /* global variables ***********************************************************/
113 s4 vms = 0; /* number of VMs created */
115 bool vm_initializing = false;
116 bool vm_exiting = false;
118 char *cacao_prefix = NULL;
119 char *cacao_libjvm = NULL;
120 char *classpath_libdir = NULL;
122 char *_Jv_bootclasspath; /* contains the boot classpath */
123 char *_Jv_classpath; /* contains the classpath */
124 char *_Jv_java_library_path;
126 char *mainstring = NULL;
127 classinfo *mainclass = NULL;
129 char *specificmethodname = NULL;
130 char *specificsignature = NULL;
134 #if defined(ENABLE_INTRP)
135 u1 *intrp_main_stack = NULL;
139 /* define heap sizes **********************************************************/
141 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
142 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
143 #define STACK_SIZE 64 * 1024 /* default 64kB */
146 /* define command line options ************************************************/
177 /* Java non-standard options */
188 #if defined(ENABLE_PROFILING)
201 #if defined(ENABLE_STATISTICS)
218 #if defined(ENABLE_VERIFIER)
220 #if defined(TYPECHECK_VERBOSE)
223 #endif /* defined(ENABLE_VERIFIER) */
226 /* optimization options */
228 #if defined(ENABLE_LOOP)
232 #if defined(ENABLE_IFCONV)
236 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
240 #if defined(ENABLE_INLINING)
245 #if defined(ENABLE_INLINING_DEBUG)
246 OPT_INLINE_DEBUG_ALL,
247 OPT_INLINE_DEBUG_END,
248 OPT_INLINE_DEBUG_MIN,
249 OPT_INLINE_DEBUG_MAX,
250 OPT_INLINE_REPLACE_VERBOSE,
251 OPT_INLINE_REPLACE_VERBOSE2,
252 #endif /* defined(ENABLE_INLINING_DEBUG) */
253 #endif /* defined(ENABLE_INLINING) */
255 #if defined(ENABLE_INTRP)
256 /* interpreter options */
275 #if defined(ENABLE_DEBUG_FILTER)
276 OPT_FILTER_VERBOSECALL_INCLUDE,
277 OPT_FILTER_VERBOSECALL_EXCLUDE,
278 OPT_FILTER_SHOW_METHOD,
285 opt_struct opts[] = {
286 { "foo", false, OPT_FOO },
290 { "jar", false, OPT_JAR },
292 { "d32", false, OPT_D32 },
293 { "d64", false, OPT_D64 },
294 { "client", false, OPT_IGNORE },
295 { "server", false, OPT_IGNORE },
296 { "jvm", false, OPT_IGNORE },
297 { "hotspot", false, OPT_IGNORE },
299 { "classpath", true, OPT_CLASSPATH },
300 { "cp", true, OPT_CLASSPATH },
301 { "D", true, OPT_D },
302 { "version", false, OPT_VERSION },
303 { "showversion", false, OPT_SHOWVERSION },
304 { "fullversion", false, OPT_FULLVERSION },
305 { "help", false, OPT_HELP },
306 { "?", false, OPT_HELP },
307 { "X", false, OPT_X },
308 { "XX:", true, OPT_XX },
310 { "ea:", true, OPT_EA },
311 { "da:", true, OPT_DA },
312 { "ea", false, OPT_EA },
313 { "da", false, OPT_DA },
315 { "esa", false, OPT_ESA },
316 { "enablesystemassertions", false, OPT_ESA },
317 { "dsa", false, OPT_DSA },
318 { "disablesystemassertions", false, OPT_DSA },
320 { "noasyncgc", false, OPT_IGNORE },
321 #if defined(ENABLE_VERIFIER)
322 { "noverify", false, OPT_NOVERIFY },
324 { "v", false, OPT_VERBOSE1 },
325 { "verbose:", true, OPT_VERBOSE },
327 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
328 { "verbosetc", false, OPT_VERBOSETC },
330 #if defined(__ALPHA__)
331 { "noieee", false, OPT_NOIEEE },
333 #if defined(ENABLE_STATISTICS)
334 { "time", false, OPT_TIME },
335 { "stat", false, OPT_STAT },
337 { "log", true, OPT_LOG },
338 { "c", true, OPT_CHECK },
339 { "l", false, OPT_LOAD },
340 { "eager", false, OPT_EAGER },
343 { "all", false, OPT_ALL },
344 { "sig", true, OPT_SIGNATURE },
347 #if defined(ENABLE_LOOP)
348 { "oloop", false, OPT_OLOOP },
350 #if defined(ENABLE_IFCONV)
351 { "ifconv", false, OPT_IFCONV },
353 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
354 { "lsra", false, OPT_LSRA },
357 #if defined(ENABLE_INTRP)
358 /* interpreter options */
360 { "trace", false, OPT_TRACE },
361 { "static-supers", true, OPT_STATIC_SUPERS },
362 { "no-dynamic", false, OPT_NO_DYNAMIC },
363 { "no-replication", false, OPT_NO_REPLICATION },
364 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
367 /* JVMTI Agent Command Line Options */
369 { "agentlib:", true, OPT_AGENTLIB },
370 { "agentpath:", true, OPT_AGENTPATH },
373 /* Java non-standard options */
375 { "Xjit", false, OPT_JIT },
376 { "Xint", false, OPT_INTRP },
377 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
378 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
379 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
380 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
383 { "Xdebug", false, OPT_DEBUG },
384 { "Xnoagent", false, OPT_NOAGENT },
385 { "Xrunjdwp", true, OPT_XRUNJDWP },
388 { "Xms", true, OPT_MS },
389 { "ms", true, OPT_MS },
390 { "Xmx", true, OPT_MX },
391 { "mx", true, OPT_MX },
392 { "Xss", true, OPT_SS },
393 { "ss", true, OPT_SS },
395 #if defined(ENABLE_PROFILING)
396 { "Xprof:", true, OPT_PROF_OPTION },
397 { "Xprof", false, OPT_PROF },
400 /* inlining options */
402 #if defined(ENABLE_INLINING)
403 #if defined(ENABLE_INLINING_DEBUG)
404 { "ia", false, OPT_INLINE_DEBUG_ALL },
405 { "ii", true, OPT_INLINE_DEBUG_MIN },
406 { "im", true, OPT_INLINE_DEBUG_MAX },
407 { "ie", true, OPT_INLINE_DEBUG_END },
408 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
409 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
410 #endif /* defined(ENABLE_INLINING_DEBUG) */
412 { "il", false, OPT_INLINE_LOG },
414 { "i", false, OPT_INLINING },
415 #endif /* defined(ENABLE_INLINING) */
417 /* keep these at the end of the list */
420 { "m", true, OPT_METHOD },
423 { "s", true, OPT_SHOW },
424 { "debug-color", false, OPT_DEBUGCOLOR },
426 #if defined(ENABLE_DEBUG_FILTER)
427 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
428 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
429 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
436 /* usage ***********************************************************************
438 Prints the correct usage syntax to stdout.
440 *******************************************************************************/
444 puts("Usage: cacao [-options] classname [arguments]");
445 puts(" (to run a class file)");
446 puts(" or cacao [-options] -jar jarfile [arguments]");
447 puts(" (to run a standalone jar file)\n");
449 puts("where options include:");
450 puts(" -d32 use 32-bit data model if available");
451 puts(" -d64 use 64-bit data model if available");
452 puts(" -client compatibility (currently ignored)");
453 puts(" -server compatibility (currently ignored)");
454 puts(" -jvm compatibility (currently ignored)");
455 puts(" -hotspot compatibility (currently ignored)\n");
457 puts(" -cp <path> specify a path to look for classes");
458 puts(" -classpath <path> specify a path to look for classes");
459 puts(" -D<name>=<value> add an entry to the property list");
460 puts(" -verbose[:class|gc|jni] enable specific verbose output");
461 puts(" -version print product version and exit");
462 puts(" -fullversion print jpackage-compatible product version and exit");
463 puts(" -showversion print product version and continue");
464 puts(" -help, -? print this help message");
465 puts(" -X print help on non-standard Java options");
466 puts(" -XX print help on CACAO options");
467 puts(" -ea[:<packagename>...|:<classname>]");
468 puts(" -enableassertions[:<packagename>...|:<classname>]");
469 puts(" enable assertions with specified granularity");
470 puts(" -da[:<packagename>...|:<classname>]");
471 puts(" -disableassertions[:<packagename>...|:<classname>]");
472 puts(" disable assertions with specified granularity");
473 puts(" -esa | -enablesystemassertions");
474 puts(" enable system assertions");
475 puts(" -dsa | -disablesystemassertions");
476 puts(" disable system assertions");
479 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
480 puts (" for jdwp help use: -agentlib:jdwp=help");
481 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
484 /* exit with error code */
490 static void Xusage(void)
492 #if defined(ENABLE_JIT)
493 puts(" -Xjit JIT mode execution (default)");
495 #if defined(ENABLE_INTRP)
496 puts(" -Xint interpreter mode execution");
498 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
499 puts(" value is set as bootstrap class path");
500 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
501 puts(" value is appended to the bootstrap class path");
502 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
503 puts(" value is prepended to the bootstrap class path");
504 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
505 puts(" value is used as Java core library, but the");
506 puts(" hardcoded VM interface classes are prepended");
507 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
508 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
509 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
511 #if defined(ENABLE_PROFILING)
512 puts(" -Xprof[:bb] collect and print profiling data");
515 #if defined(ENABLE_JVMTI)
516 /* -Xdebug option depend on gnu classpath JDWP options. options:
517 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
518 puts(" -Xdebug enable remote debugging\n");
519 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
520 puts(" enable remote debugging\n");
523 /* exit with error code */
529 static void XXusage(void)
531 puts(" -v write state-information");
533 puts(" -verbose[:call|exception|jit|memory|threads]");
534 puts(" enable specific verbose output");
535 puts(" -debug-color colored output for ANSI terms");
537 #ifdef TYPECHECK_VERBOSE
538 puts(" -verbosetc write debug messages while typechecking");
540 #if defined(__ALPHA__)
541 puts(" -noieee don't use ieee compliant arithmetic");
543 #if defined(ENABLE_VERIFIER)
544 puts(" -noverify don't verify classfiles");
546 #if defined(ENABLE_STATISTICS)
547 puts(" -time measure the runtime");
548 puts(" -stat detailed compiler statistics");
550 puts(" -log logfile specify a name for the logfile");
551 puts(" -c(heck)b(ounds) don't check array bounds");
552 puts(" s(ync) don't check for synchronization");
553 #if defined(ENABLE_LOOP)
554 puts(" -oloop optimize array accesses in loops");
556 puts(" -l don't start the class after loading");
557 puts(" -eager perform eager class loading and linking");
559 puts(" -all compile all methods, no execution");
560 puts(" -m compile only a specific method");
561 puts(" -sig specify signature for a specific method");
564 puts(" -s... show...");
565 puts(" (c)onstants the constant pool");
566 puts(" (m)ethods class fields and methods");
567 puts(" (u)tf the utf - hash");
568 puts(" (i)ntermediate intermediate representation");
569 #if defined(ENABLE_DISASSEMBLER)
570 puts(" (a)ssembler disassembled listing");
571 puts(" n(o)ps show NOPs in disassembler output");
572 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
573 puts(" (n)ative disassembled native stubs");
575 puts(" (d)atasegment data segment listing");
577 #if defined(ENABLE_INLINING)
578 puts(" -i activate inlining");
580 puts(" -il log inlining");
582 #if defined(ENABLE_INLINING_DEBUG)
583 puts(" -ia use inlining for all methods");
584 puts(" -ii <size> set minimum size for inlined result");
585 puts(" -im <size> set maximum size for inlined result");
586 puts(" -ie <number> stop inlining after the given number of roots");
587 puts(" -ir log on-stack replacement");
588 puts(" -iR log on-stack replacement, more verbose");
589 #endif /* defined(ENABLE_INLINING_DEBUG) */
590 #endif /* defined(ENABLE_INLINING) */
592 #if defined(ENABLE_IFCONV)
593 puts(" -ifconv use if-conversion");
595 #if defined(ENABLE_LSRA)
596 puts(" -lsra use linear scan register allocation");
598 #if defined(ENABLE_SSA)
599 puts(" -lsra use linear scan register allocation (with SSA)");
601 #if defined(ENABLE_DEBUG_FILTER)
602 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
603 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
604 puts(" -XXfm <regex> filter for show options");
606 /* exit with error code */
612 /* version *********************************************************************
614 Only prints cacao version information.
616 *******************************************************************************/
618 static void version(bool opt_exit)
620 puts("java version \""JAVA_VERSION"\"");
621 puts("CACAO version "VERSION"");
623 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
624 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
625 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
626 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
628 puts("This program is free software; you can redistribute it and/or");
629 puts("modify it under the terms of the GNU General Public License as");
630 puts("published by the Free Software Foundation; either version 2, or (at");
631 puts("your option) any later version.\n");
633 puts("This program is distributed in the hope that it will be useful, but");
634 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
635 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
636 puts("General Public License for more details.\n");
638 puts("Configure/Build options:\n");
639 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
640 #if defined(__VERSION__)
641 puts(" CC : "VERSION_CC" ("__VERSION__")");
643 puts(" CC : "VERSION_CC"");
645 puts(" CFLAGS : "VERSION_CFLAGS"\n");
647 puts("Default variables:\n");
648 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
649 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
650 printf(" stack size : %d\n", STACK_SIZE);
651 #if defined(WITH_CLASSPATH_GNU)
652 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
654 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
656 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
658 puts("Runtime variables:\n");
659 printf(" maximum heap size : %d\n", opt_heapmaxsize);
660 printf(" initial heap size : %d\n", opt_heapstartsize);
661 printf(" stack size : %d\n", opt_stacksize);
662 printf(" libjvm.so : %s\n", cacao_libjvm);
663 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
664 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
665 printf(" java.class.path : %s\n", _Jv_classpath);
667 /* exit normally, if requested */
674 /* fullversion *****************************************************************
676 Prints a Sun compatible version information (required e.g. by
677 jpackage, www.jpackage.org).
679 *******************************************************************************/
681 static void fullversion(void)
683 puts("java full version \"cacao-"JAVA_VERSION"\"");
691 /* forward declarations *******************************************************/
693 static char *vm_get_mainclass_from_jar(char *mainstring);
695 static void vm_compile_all(void);
696 static void vm_compile_method(void);
700 /* vm_createjvm ****************************************************************
702 Implementation for JNI_CreateJavaVM.
704 *******************************************************************************/
706 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
708 JavaVMInitArgs *_vm_args;
712 /* get the arguments for the new JVM */
714 _vm_args = (JavaVMInitArgs *) vm_args;
716 /* get the VM and Env tables (must be set before vm_create) */
718 env = NEW(_Jv_JNIEnv);
720 #if defined(ENABLE_JNI)
721 env->env = &_Jv_JNINativeInterface;
724 /* XXX Set the global variable. Maybe we should do that differently. */
728 /* create and fill a JavaVM structure */
730 vm = NEW(_Jv_JavaVM);
732 #if defined(ENABLE_JNI)
733 vm->functions = &_Jv_JNIInvokeInterface;
736 /* XXX Set the global variable. Maybe we should do that differently. */
737 /* XXX JVMTI Agents needs a JavaVM */
741 /* actually create the JVM */
743 if (!vm_create(_vm_args))
746 #if defined(ENABLE_JNI)
747 /* setup the local ref table (must be created after vm_create) */
749 if (!jni_init_localref_table())
753 /* now return the values */
755 *p_vm = (JavaVM *) vm;
756 *p_env = (void *) env;
761 /* release allocated memory */
763 FREE(env, _Jv_JNIEnv);
764 FREE(vm, _Jv_JavaVM);
770 /* vm_create *******************************************************************
772 Creates a JVM. Called by vm_createjvm.
774 *******************************************************************************/
776 bool vm_create(JavaVMInitArgs *vm_args)
785 #if defined(ENABLE_JVMTI)
787 char *libname, *agentarg;
788 bool jdwp,agentbypath;
789 jdwp = agentbypath = false;
792 #if defined(ENABLE_VMLOG)
793 vmlog_cacao_init(vm_args);
796 /* check the JNI version requested */
798 switch (vm_args->version) {
799 case JNI_VERSION_1_1:
801 case JNI_VERSION_1_2:
802 case JNI_VERSION_1_4:
808 /* we only support 1 JVM instance */
813 if (atexit(vm_exit_handler))
814 vm_abort("atexit failed: %s\n", strerror(errno));
817 log_text("CACAO started -------------------------------------------------------");
819 /* We need to check if the actual size of a java.lang.Class object
820 is smaller or equal than the assumption made in
821 src/vmcore/class.h. */
823 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
824 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
826 /* set the VM starttime */
828 _Jv_jvm->starttime = builtin_currenttimemillis();
830 /* get stuff from the environment *****************************************/
832 #if defined(WITH_JRE_LAYOUT)
833 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
835 cacao_prefix = MNEW(char, 4096);
837 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
838 vm_abort("readlink failed: %s\n", strerror(errno));
840 /* get the path of the current executable */
842 cacao_prefix = dirname(cacao_prefix);
844 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
845 vm_abort("libjvm name to long for buffer\n");
847 /* concatenate the library name */
849 strcat(cacao_prefix, "/..");
851 /* now set path to libjvm.so */
853 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
855 cacao_libjvm = MNEW(char, len);
856 strcpy(cacao_libjvm, cacao_prefix);
857 strcat(cacao_libjvm, "/lib/libjvm");
859 /* and finally set the path to GNU Classpath libraries */
861 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
863 classpath_libdir = MNEW(char, len);
864 strcpy(classpath_libdir, cacao_prefix);
865 strcat(classpath_libdir, "/lib/classpath");
867 cacao_prefix = CACAO_PREFIX;
868 cacao_libjvm = CACAO_LIBDIR"/libjvm";
869 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
872 /* set the bootclasspath */
874 cp = getenv("BOOTCLASSPATH");
877 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
878 strcpy(_Jv_bootclasspath, cp);
881 #if defined(WITH_JRE_LAYOUT)
883 # if defined(WITH_CLASSPATH_GNU)
884 strlen(cacao_prefix) +
885 strlen("/share/cacao/vm.zip") +
888 strlen(cacao_prefix) +
889 strlen("/share/classpath/glibj.zip") +
892 _Jv_bootclasspath = MNEW(char, len);
893 # if defined(WITH_CLASSPATH_GNU)
894 strcat(_Jv_bootclasspath, cacao_prefix);
895 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
896 strcat(_Jv_bootclasspath, ":");
898 strcat(_Jv_bootclasspath, cacao_prefix);
899 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
902 # if defined(WITH_CLASSPATH_GNU)
903 strlen(CACAO_VM_ZIP) +
906 strlen(CLASSPATH_CLASSES) +
909 _Jv_bootclasspath = MNEW(char, len);
910 # if defined(WITH_CLASSPATH_GNU)
911 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
912 strcat(_Jv_bootclasspath, ":");
914 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
918 /* set the classpath */
920 cp = getenv("CLASSPATH");
923 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
924 strcat(_Jv_classpath, cp);
927 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
928 strcpy(_Jv_classpath, ".");
931 /* get and set java.library.path */
933 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
935 if (_Jv_java_library_path == NULL)
936 _Jv_java_library_path = "";
938 /* interpret the options **************************************************/
945 opt_heapmaxsize = HEAP_MAXSIZE;
946 opt_heapstartsize = HEAP_STARTSIZE;
947 opt_stacksize = STACK_SIZE;
950 #if defined(ENABLE_JVMTI)
951 /* initialize JVMTI related **********************************************/
955 /* initialize and fill properties before command-line handling */
957 if (!properties_init())
958 vm_abort("properties_init failed");
960 /* iterate over all passed options */
962 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
976 #if SIZEOF_VOID_P == 8
977 puts("Running a 32-bit JVM is not supported on this platform.");
983 #if SIZEOF_VOID_P == 4
984 puts("Running a 64-bit JVM is not supported on this platform.");
990 /* forget old classpath and set the argument as new classpath */
991 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
993 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
994 strcpy(_Jv_classpath, opt_arg);
998 for (i = 0; i < strlen(opt_arg); i++) {
999 if (opt_arg[i] == '=') {
1001 properties_add(opt_arg, opt_arg + i + 1);
1006 /* if no '=' is given, just create an empty property */
1008 properties_add(opt_arg, "");
1013 case OPT_BOOTCLASSPATH:
1014 /* Forget default bootclasspath and set the argument as
1015 new boot classpath. */
1017 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1019 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
1020 strcpy(_Jv_bootclasspath, opt_arg);
1023 case OPT_BOOTCLASSPATH_A:
1024 /* append to end of bootclasspath */
1026 len = strlen(_Jv_bootclasspath);
1028 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
1032 strlen(opt_arg) + strlen("0"));
1034 strcat(_Jv_bootclasspath, ":");
1035 strcat(_Jv_bootclasspath, opt_arg);
1038 case OPT_BOOTCLASSPATH_P:
1039 /* prepend in front of bootclasspath */
1041 cp = _Jv_bootclasspath;
1044 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1047 strcpy(_Jv_bootclasspath, opt_arg);
1048 strcat(_Jv_bootclasspath, ":");
1049 strcat(_Jv_bootclasspath, cp);
1051 MFREE(cp, char, len);
1054 case OPT_BOOTCLASSPATH_C:
1055 /* use as Java core library, but prepend VM interface classes */
1057 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1059 len = strlen(CACAO_VM_ZIP) +
1064 _Jv_bootclasspath = MNEW(char, len);
1066 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1067 strcat(_Jv_bootclasspath, ":");
1068 strcat(_Jv_bootclasspath, opt_arg);
1071 #if defined(ENABLE_JVMTI)
1073 /* this option exists only for compatibility reasons */
1077 /* I don't know yet what Xnoagent should do. This is only for
1078 compatiblity with eclipse - motse */
1087 strlen(CACAO_LIBDIR) +
1088 strlen("/libjdwp.so=") +
1092 agentarg = MNEW(char, len);
1094 strcpy(agentarg, CACAO_LIBDIR);
1095 strcat(agentarg, "/libjdwp.so=");
1096 strcat(agentarg, &opt_arg[1]);
1113 c = opt_arg[strlen(opt_arg) - 1];
1115 if ((c == 'k') || (c == 'K')) {
1116 j = atoi(opt_arg) * 1024;
1118 } else if ((c == 'm') || (c == 'M')) {
1119 j = atoi(opt_arg) * 1024 * 1024;
1125 opt_heapmaxsize = j;
1126 else if (opt == OPT_MS)
1127 opt_heapstartsize = j;
1138 if (strcmp("class", opt_arg) == 0) {
1139 opt_verboseclass = true;
1141 else if (strcmp("gc", opt_arg) == 0) {
1142 opt_verbosegc = true;
1144 else if (strcmp("jni", opt_arg) == 0) {
1145 opt_verbosejni = true;
1147 #if !defined(NDEBUG)
1148 else if (strcmp("call", opt_arg) == 0) {
1149 opt_verbosecall = true;
1151 else if (strcmp("exception", opt_arg) == 0) {
1152 opt_verboseexception = true;
1154 else if (strcmp("jit", opt_arg) == 0) {
1159 compileverbose = true;
1161 else if (strcmp("memory", opt_arg) == 0) {
1162 opt_verbosememory = true;
1164 # if defined(ENABLE_STATISTICS)
1165 /* we also need statistics */
1170 else if (strcmp("threads", opt_arg) == 0) {
1171 opt_verbosethreads = true;
1175 printf("Unknown -verbose option: %s\n", opt_arg);
1180 case OPT_DEBUGCOLOR:
1181 opt_debugcolor = true;
1184 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1186 opt_typecheckverbose = true;
1195 case OPT_FULLVERSION:
1199 case OPT_SHOWVERSION:
1207 #if defined(ENABLE_VERIFIER)
1213 #if defined(ENABLE_STATISTICS)
1215 opt_getcompilingtime = true;
1216 opt_getloadingtime = true;
1229 for (i = 0; i < strlen(opt_arg); i++) {
1230 switch (opt_arg[i]) {
1232 checkbounds = false;
1245 makeinitializations = false;
1252 #if !defined(NDEBUG)
1256 makeinitializations = false;
1261 opt_method = opt_arg;
1262 makeinitializations = false;
1266 opt_signature = opt_arg;
1270 case OPT_SHOW: /* Display options */
1271 for (i = 0; i < strlen(opt_arg); i++) {
1272 switch (opt_arg[i]) {
1274 showconstantpool = true;
1286 opt_showintermediate = true;
1287 compileverbose = true;
1290 #if defined(ENABLE_DISASSEMBLER)
1292 opt_showdisassemble = true;
1293 compileverbose = true;
1297 opt_shownops = true;
1301 opt_showexceptionstubs = true;
1305 opt_shownativestub = true;
1310 opt_showddatasegment = true;
1319 #if defined(ENABLE_LOOP)
1325 #if defined(ENABLE_INLINING)
1326 #if defined(ENABLE_INLINING_DEBUG)
1327 case OPT_INLINE_DEBUG_ALL:
1328 opt_inline_debug_all = true;
1330 case OPT_INLINE_DEBUG_END:
1331 opt_inline_debug_end_counter = atoi(opt_arg);
1333 case OPT_INLINE_DEBUG_MIN:
1334 opt_inline_debug_min_size = atoi(opt_arg);
1336 case OPT_INLINE_DEBUG_MAX:
1337 opt_inline_debug_max_size = atoi(opt_arg);
1339 case OPT_INLINE_REPLACE_VERBOSE:
1340 opt_replace_verbose = 1;
1342 case OPT_INLINE_REPLACE_VERBOSE2:
1343 opt_replace_verbose = 2;
1345 #endif /* defined(ENABLE_INLINING_DEBUG) */
1346 #if !defined(NDEBUG)
1347 case OPT_INLINE_LOG:
1348 opt_inline_debug_log = true;
1350 #endif /* !defined(NDEBUG) */
1353 opt_inlining = true;
1355 #endif /* defined(ENABLE_INLINING) */
1357 #if defined(ENABLE_IFCONV)
1363 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1378 options_xx(opt_arg);
1382 /* currently ignored */
1386 /* currently ignored */
1390 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1394 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1397 #if defined(ENABLE_PROFILING)
1398 case OPT_PROF_OPTION:
1399 /* use <= to get the last \0 too */
1401 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1402 if (opt_arg[i] == ',')
1405 if (opt_arg[i] == '\0') {
1406 if (strcmp("bb", opt_arg + j) == 0)
1410 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1414 /* set k to next char */
1427 #if defined(ENABLE_JIT)
1430 printf("-Xjit option not enabled.\n");
1436 #if defined(ENABLE_INTRP)
1439 printf("-Xint option not enabled.\n");
1444 #if defined(ENABLE_INTRP)
1445 case OPT_STATIC_SUPERS:
1446 opt_static_supers = atoi(opt_arg);
1449 case OPT_NO_DYNAMIC:
1450 opt_no_dynamic = true;
1453 case OPT_NO_REPLICATION:
1454 opt_no_replication = true;
1457 case OPT_NO_QUICKSUPER:
1458 opt_no_quicksuper = true;
1466 #if defined(ENABLE_DEBUG_FILTER)
1467 case OPT_FILTER_VERBOSECALL_INCLUDE:
1468 opt_filter_verbosecall_include = opt_arg;
1471 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1472 opt_filter_verbosecall_exclude = opt_arg;
1475 case OPT_FILTER_SHOW_METHOD:
1476 opt_filter_show_method = opt_arg;
1481 printf("Unknown option: %s\n",
1482 vm_args->options[opt_index].optionString);
1487 /* get the main class *****************************************************/
1489 if (opt_index < vm_args->nOptions) {
1490 mainstring = vm_args->options[opt_index++].optionString;
1492 /* Put the jar file into the classpath (if any). */
1494 if (opt_jar == true) {
1495 /* free old classpath */
1497 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1499 /* put jarfile into classpath */
1501 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1503 strcpy(_Jv_classpath, mainstring);
1506 /* replace .'s with /'s in classname */
1508 for (i = strlen(mainstring) - 1; i >= 0; i--)
1509 if (mainstring[i] == '.')
1510 mainstring[i] = '/';
1514 #if defined(ENABLE_JVMTI)
1516 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1517 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1520 MFREE(agentarg, char, strlen(agentarg));
1522 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1526 /* initialize this JVM ****************************************************/
1528 vm_initializing = true;
1530 #if defined(ENABLE_THREADS)
1531 /* pre-initialize some core thread stuff, like the stopworldlock,
1532 thus this has to happen _before_ gc_init()!!! */
1537 /* initialize the garbage collector */
1539 gc_init(opt_heapmaxsize, opt_heapstartsize);
1541 /* install architecture dependent signal handlers */
1544 vm_abort("vm_create: signal_init failed");
1546 #if defined(ENABLE_INTRP)
1547 /* Allocate main thread stack on the Java heap. */
1550 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1551 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1555 /* AFTER: threads_preinit */
1558 vm_abort("vm_create: string_init failed");
1560 /* AFTER: threads_preinit */
1563 vm_abort("vm_create: utf8_init failed");
1565 /* AFTER: thread_preinit */
1568 vm_abort("vm_create: suck_init failed");
1570 suck_add_from_property("java.endorsed.dirs");
1572 /* Now we have all options handled and we can print the version
1575 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1580 /* AFTER: utf8_init */
1582 suck_add(_Jv_bootclasspath);
1584 /* Now re-set some of the properties that may have changed. This
1585 must be done after _all_ environment variables have been
1586 processes (e.g. -jar handling).
1588 AFTER: suck_add_from_property, since it may change the
1589 _Jv_bootclasspath pointer. */
1591 if (!properties_postinit())
1592 vm_abort("vm_create: properties_postinit failed");
1594 /* initialize the classcache hashtable stuff: lock, hashtable
1595 (must be done _after_ threads_preinit) */
1597 if (!classcache_init())
1598 vm_abort("vm_create: classcache_init failed");
1600 /* initialize the memory subsystem (must be done _after_
1604 vm_abort("vm_create: memory_init failed");
1606 /* initialize the finalizer stuff (must be done _after_
1609 if (!finalizer_init())
1610 vm_abort("vm_create: finalizer_init failed");
1612 /* initialize the codegen subsystems */
1616 /* initializes jit compiler */
1620 /* machine dependent initialization */
1622 #if defined(ENABLE_JIT)
1623 # if defined(ENABLE_INTRP)
1633 /* initialize the loader subsystems (must be done _after_
1637 vm_abort("vm_create: loader_init failed");
1639 /* Link some important VM classes. */
1640 /* AFTER: utf8_init */
1643 vm_abort("vm_create: linker_init failed");
1645 if (!primitive_init())
1646 vm_abort("vm_create: primitive_init failed");
1648 /* Initialize the native subsystem. */
1651 vm_abort("vm_create: native_init failed");
1653 if (!exceptions_init())
1654 vm_abort("vm_create: exceptions_init failed");
1656 if (!builtin_init())
1657 vm_abort("vm_create: builtin_init failed");
1659 #if defined(ENABLE_JNI)
1660 /* Initialize the JNI subsystem (must be done _before_
1661 threads_init, as threads_init can call JNI methods
1662 (e.g. NewGlobalRef). */
1665 vm_abort("vm_create: jni_init failed");
1668 #if defined(ENABLE_THREADS)
1669 if (!threads_init())
1670 vm_abort("vm_create: threads_init failed");
1673 #if defined(ENABLE_PROFILING)
1674 /* initialize profiling */
1676 if (!profile_init())
1677 vm_abort("vm_create: profile_init failed");
1680 #if defined(ENABLE_THREADS)
1681 /* initialize recompilation */
1683 if (!recompile_init())
1684 vm_abort("vm_create: recompile_init failed");
1686 /* start the signal handler thread */
1688 #if defined(__LINUX__)
1689 /* XXX Remove for exact-GC. */
1690 if (threads_pthreads_implementation_nptl)
1692 if (!signal_start_thread())
1693 vm_abort("vm_create: signal_start_thread failed");
1695 /* finally, start the finalizer thread */
1697 if (!finalizer_start_thread())
1698 vm_abort("vm_create: finalizer_start_thread failed");
1700 # if !defined(NDEBUG)
1701 /* start the memory profiling thread */
1703 if (opt_verbosememory)
1704 if (!memory_start_thread())
1705 vm_abort("vm_create: memory_start_thread failed");
1708 /* start the recompilation thread (must be done before the
1709 profiling thread) */
1711 if (!recompile_start_thread())
1712 vm_abort("vm_create: recompile_start_thread failed");
1714 # if defined(ENABLE_PROFILING)
1715 /* start the profile sampling thread */
1718 /* if (!profile_start_thread()) */
1719 /* vm_abort("vm_create: profile_start_thread failed"); */
1723 #if defined(ENABLE_JVMTI)
1725 /* add agent library to native library hashtable */
1726 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1730 /* increment the number of VMs */
1734 /* initialization is done */
1736 vm_initializing = false;
1738 /* everything's ok */
1744 /* vm_run **********************************************************************
1746 Runs the main-method of the passed class.
1748 *******************************************************************************/
1750 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1753 classinfo *mainclass;
1754 java_objectheader *e;
1756 java_objectarray *oa;
1759 java_objectheader *s;
1763 #if !defined(NDEBUG)
1769 if (opt_method != NULL) {
1770 vm_compile_method();
1773 #endif /* !defined(NDEBUG) */
1775 /* should we run the main-method? */
1777 if (mainstring == NULL)
1780 /* set return value to OK */
1784 if (opt_jar == true) {
1785 /* open jar file with java.util.jar.JarFile */
1787 mainstring = vm_get_mainclass_from_jar(mainstring);
1789 if (mainstring == NULL)
1793 /* load the main class */
1795 mainutf = utf_new_char(mainstring);
1797 #if defined(ENABLE_JAVAME_CLDC1_1)
1798 mainclass = load_class_bootstrap(mainutf);
1800 mainclass = load_class_from_sysloader(mainutf);
1803 /* error loading class */
1805 e = exceptions_get_and_clear_exception();
1807 if ((e != NULL) || (mainclass == NULL)) {
1808 exceptions_throw_noclassdeffounderror_cause(e);
1809 exceptions_print_stacktrace();
1813 if (!link_class(mainclass)) {
1814 exceptions_print_stacktrace();
1818 /* find the `main' method of the main class */
1820 m = class_resolveclassmethod(mainclass,
1821 utf_new_char("main"),
1822 utf_new_char("([Ljava/lang/String;)V"),
1823 class_java_lang_Object,
1826 if (exceptions_get_exception()) {
1827 exceptions_print_stacktrace();
1831 /* there is no main method or it isn't static */
1833 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1834 exceptions_clear_exception();
1835 exceptions_throw_nosuchmethoderror(mainclass,
1836 utf_new_char("main"),
1837 utf_new_char("([Ljava/lang/String;)V"));
1839 exceptions_print_stacktrace();
1843 /* build argument array */
1845 oalength = vm_args->nOptions - opt_index;
1847 oa = builtin_anewarray(oalength, class_java_lang_String);
1849 for (i = 0; i < oalength; i++) {
1850 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1851 s = javastring_new(u);
1856 #ifdef TYPEINFO_DEBUG_TEST
1857 /* test the typeinfo system */
1860 /*class_showmethods(currentThread->group->header.vftbl->class); */
1862 #if defined(ENABLE_JVMTI)
1863 jvmti_set_phase(JVMTI_PHASE_LIVE);
1866 /* set ThreadMXBean variables */
1868 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1869 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1871 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1872 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1873 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1874 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1876 /* start the main thread */
1878 (void) vm_call_method(m, NULL, oa);
1880 /* exception occurred? */
1882 if (exceptions_get_exception()) {
1883 exceptions_print_stacktrace();
1887 /* unload the JavaVM */
1889 (void) vm_destroy(vm);
1897 /* vm_destroy ******************************************************************
1899 Unloads a Java VM and reclaims its resources.
1901 *******************************************************************************/
1903 s4 vm_destroy(JavaVM *vm)
1905 #if defined(ENABLE_THREADS)
1906 threads_join_all_threads();
1909 /* everything's ok */
1915 /* vm_exit *********************************************************************
1917 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1919 *******************************************************************************/
1921 void vm_exit(s4 status)
1925 /* signal that we are exiting */
1929 assert(class_java_lang_System);
1930 assert(class_java_lang_System->state & CLASS_LOADED);
1932 #if defined(ENABLE_JVMTI)
1933 if (jvmti || (dbgcom!=NULL)) {
1934 jvmti_set_phase(JVMTI_PHASE_DEAD);
1935 if (jvmti) jvmti_agentunload();
1939 if (!link_class(class_java_lang_System)) {
1940 exceptions_print_stacktrace();
1944 /* call java.lang.System.exit(I)V */
1946 m = class_resolveclassmethod(class_java_lang_System,
1947 utf_new_char("exit"),
1949 class_java_lang_Object,
1953 exceptions_print_stacktrace();
1957 /* call the exit function with passed exit status */
1959 (void) vm_call_method(m, NULL, status);
1961 /* If we had an exception, just ignore the exception and exit with
1964 vm_shutdown(status);
1968 /* vm_shutdown *****************************************************************
1970 Terminates the system immediately without freeing memory explicitly
1971 (to be used only for abnormal termination).
1973 *******************************************************************************/
1975 void vm_shutdown(s4 status)
1978 #if defined(ENABLE_STATISTICS)
1979 || opt_getcompilingtime || opt_stat
1983 log_text("CACAO terminated by shutdown");
1984 dolog("Exit status: %d\n", (s4) status);
1988 #if defined(ENABLE_JVMTI)
1989 /* terminate cacaodbgserver */
1991 pthread_mutex_lock(&dbgcomlock);
1993 pthread_mutex_unlock(&dbgcomlock);
1994 jvmti_cacaodbgserver_quit();
2002 /* vm_exit_handler *************************************************************
2004 The exit_handler function is called upon program termination.
2006 ATTENTION: Don't free system resources here! Some threads may still
2007 be running as this is called from VMRuntime.exit(). The OS does the
2010 *******************************************************************************/
2012 void vm_exit_handler(void)
2014 #if !defined(NDEBUG)
2016 class_showmethods(mainclass);
2018 if (showconstantpool)
2019 class_showconstantpool(mainclass);
2024 # if defined(ENABLE_PROFILING)
2026 profile_printstats();
2028 #endif /* !defined(NDEBUG) */
2030 #if defined(ENABLE_RT_TIMING)
2031 rt_timing_print_time_stats(stderr);
2034 #if defined(ENABLE_CYCLES_STATS)
2035 builtin_print_cycles_stats(stderr);
2036 stacktrace_print_cycles_stats(stderr);
2040 #if defined(ENABLE_STATISTICS)
2041 || opt_getcompilingtime || opt_stat
2045 log_text("CACAO terminated");
2047 #if defined(ENABLE_STATISTICS)
2050 #ifdef TYPECHECK_STATISTICS
2051 typecheck_print_statistics(get_logfile());
2055 if (opt_getcompilingtime)
2057 #endif /* defined(ENABLE_STATISTICS) */
2059 /* vm_print_profile(stderr);*/
2063 /* vm_abort ********************************************************************
2065 Prints an error message and aborts the VM.
2067 *******************************************************************************/
2069 void vm_abort(const char *text, ...)
2073 /* print the log message */
2078 log_vprint(text, ap);
2083 /* now abort the VM */
2089 /* vm_get_mainclass_from_jar ***************************************************
2091 Gets the name of the main class from a JAR's manifest file.
2093 *******************************************************************************/
2095 static char *vm_get_mainclass_from_jar(char *mainstring)
2098 java_objectheader *o;
2100 java_objectheader *s;
2102 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2105 exceptions_print_stacktrace();
2109 /* create JarFile object */
2114 exceptions_print_stacktrace();
2118 m = class_resolveclassmethod(c,
2120 utf_java_lang_String__void,
2121 class_java_lang_Object,
2125 exceptions_print_stacktrace();
2129 s = javastring_new_from_ascii(mainstring);
2131 (void) vm_call_method(m, o, s);
2133 if (exceptions_get_exception()) {
2134 exceptions_print_stacktrace();
2138 /* get manifest object */
2140 m = class_resolveclassmethod(c,
2141 utf_new_char("getManifest"),
2142 utf_new_char("()Ljava/util/jar/Manifest;"),
2143 class_java_lang_Object,
2147 exceptions_print_stacktrace();
2151 o = vm_call_method(m, o);
2154 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2159 /* get Main Attributes */
2161 m = class_resolveclassmethod(o->vftbl->class,
2162 utf_new_char("getMainAttributes"),
2163 utf_new_char("()Ljava/util/jar/Attributes;"),
2164 class_java_lang_Object,
2168 exceptions_print_stacktrace();
2172 o = vm_call_method(m, o);
2175 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2180 /* get property Main-Class */
2182 m = class_resolveclassmethod(o->vftbl->class,
2183 utf_new_char("getValue"),
2184 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2185 class_java_lang_Object,
2189 exceptions_print_stacktrace();
2193 s = javastring_new_from_ascii("Main-Class");
2195 o = vm_call_method(m, o, s);
2198 exceptions_print_stacktrace();
2202 return javastring_tochar(o);
2206 /* vm_compile_all **************************************************************
2208 Compile all methods found in the bootclasspath.
2210 *******************************************************************************/
2212 #if !defined(NDEBUG)
2213 static void vm_compile_all(void)
2218 classcache_name_entry *nmen;
2219 classcache_class_entry *clsen;
2222 /* create all classes found in the bootclasspath */
2223 /* XXX currently only works with zip/jar's */
2225 loader_load_all_classes();
2227 /* link all classes */
2229 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2230 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2232 for (; nmen; nmen = nmen->hashlink) {
2233 /* iterate over all class entries */
2235 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2236 c = clsen->classobj;
2241 if (!(c->state & CLASS_LINKED)) {
2242 if (!link_class(c)) {
2243 fprintf(stderr, "Error linking: ");
2244 utf_fprint_printable_ascii_classname(stderr, c->name);
2245 fprintf(stderr, "\n");
2247 /* print out exception and cause */
2249 exceptions_print_current_exception();
2251 /* goto next class */
2257 /* compile all class methods */
2259 for (i = 0; i < c->methodscount; i++) {
2260 m = &(c->methods[i]);
2262 if (m->jcode != NULL) {
2263 if (!jit_compile(m)) {
2264 fprintf(stderr, "Error compiling: ");
2265 utf_fprint_printable_ascii_classname(stderr, c->name);
2266 fprintf(stderr, ".");
2267 utf_fprint_printable_ascii(stderr, m->name);
2268 utf_fprint_printable_ascii(stderr, m->descriptor);
2269 fprintf(stderr, "\n");
2271 /* print out exception and cause */
2273 exceptions_print_current_exception();
2281 #endif /* !defined(NDEBUG) */
2284 /* vm_compile_method ***********************************************************
2286 Compile a specific method.
2288 *******************************************************************************/
2290 #if !defined(NDEBUG)
2291 static void vm_compile_method(void)
2295 /* create, load and link the main class */
2297 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2299 if (mainclass == NULL)
2300 exceptions_print_stacktrace();
2302 if (!link_class(mainclass))
2303 exceptions_print_stacktrace();
2305 if (opt_signature != NULL) {
2306 m = class_resolveclassmethod(mainclass,
2307 utf_new_char(opt_method),
2308 utf_new_char(opt_signature),
2313 m = class_resolveclassmethod(mainclass,
2314 utf_new_char(opt_method),
2321 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2322 opt_method, opt_signature ? opt_signature : "");
2326 #endif /* !defined(NDEBUG) */
2329 /* vm_array_store_int **********************************************************
2331 Helper function to store an integer into the argument array, taking
2332 care of architecture specific issues.
2334 *******************************************************************************/
2336 static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
2340 if (!pd->inmemory) {
2342 array[index] = (int64_t) value;
2345 index = ARG_CNT + pd->regoff;
2346 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2347 array[index] = ((int64_t) value) << 32;
2349 array[index] = (int64_t) value;
2355 /* vm_array_store_lng **********************************************************
2357 Helper function to store a long into the argument array, taking
2358 care of architecture specific issues.
2360 *******************************************************************************/
2362 static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
2366 #if SIZEOF_VOID_P == 8
2370 index = ARG_CNT + pd->regoff;
2372 array[index] = value;
2374 if (!pd->inmemory) {
2375 /* move low and high 32-bits into it's own argument slot */
2377 index = GET_LOW_REG(pd->index);
2378 array[index] = value & 0x00000000ffffffff;
2380 index = GET_HIGH_REG(pd->index);
2381 array[index] = value >> 32;
2384 index = ARG_CNT + pd->regoff;
2385 array[index] = value;
2391 /* vm_array_store_flt **********************************************************
2393 Helper function to store a float into the argument array, taking
2394 care of architecture specific issues.
2396 *******************************************************************************/
2398 static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
2402 if (!pd->inmemory) {
2403 index = INT_ARG_CNT + pd->index;
2404 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2405 array[index] = value >> 32;
2407 array[index] = value;
2411 index = ARG_CNT + pd->regoff;
2412 array[index] = value;
2417 /* vm_array_store_dbl **********************************************************
2419 Helper function to store a double into the argument array, taking
2420 care of architecture specific issues.
2422 *******************************************************************************/
2424 static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
2429 index = INT_ARG_CNT + pd->index;
2431 index = ARG_CNT + pd->regoff;
2433 array[index] = value;
2437 /* vm_array_store_adr **********************************************************
2439 Helper function to store an address into the argument array, taking
2440 care of architecture specific issues.
2442 *******************************************************************************/
2444 static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
2448 if (!pd->inmemory) {
2449 #if defined(HAS_ADDRESS_REGISTER_FILE)
2450 /* When the architecture has address registers, place them
2451 after integer and float registers. */
2453 index = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
2457 array[index] = (uint64_t) (intptr_t) value;
2460 index = ARG_CNT + pd->regoff;
2461 #if SIZEOF_VOID_P == 8
2462 array[index] = (uint64_t) (intptr_t) value;
2464 # if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
2465 array[index] = ((uint64_t) (intptr_t) value) << 32;
2467 array[index] = (uint64_t) (intptr_t) value;
2474 /* vm_vmargs_from_valist *******************************************************
2478 *******************************************************************************/
2480 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
2481 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2482 vm_arg *vmargs, va_list ap)
2484 typedesc *paramtypes;
2487 paramtypes = m->parseddesc->paramtypes;
2489 /* if method is non-static fill first block and skip `this' pointer */
2494 /* the `this' pointer */
2495 vmargs[0].type = TYPE_ADR;
2496 vmargs[0].data.l = (u8) (ptrint) o;
2502 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2503 switch (paramtypes->type) {
2505 vmargs[i].type = TYPE_INT;
2506 vmargs[i].data.l = (s8) va_arg(ap, s4);
2510 vmargs[i].type = TYPE_LNG;
2511 vmargs[i].data.l = (s8) va_arg(ap, s8);
2515 vmargs[i].type = TYPE_FLT;
2516 #if defined(__ALPHA__)
2517 /* this keeps the assembler function much simpler */
2519 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2521 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2526 vmargs[i].type = TYPE_DBL;
2527 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2531 vmargs[i].type = TYPE_ADR;
2532 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2538 uint64_t *vm_array_from_valist(methodinfo *m, java_objectheader *o, va_list ap)
2547 /* get the descriptors */
2551 td = md->paramtypes;
2553 /* allocate argument array */
2555 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2557 /* if method is non-static fill first block and skip `this' pointer */
2562 /* the `this' pointer */
2563 vm_array_store_adr(array, pd, o);
2570 for (; i < md->paramcount; i++, pd++, td++) {
2573 value.i = va_arg(ap, int32_t);
2574 vm_array_store_int(array, pd, value.i);
2578 value.l = va_arg(ap, int64_t);
2579 vm_array_store_lng(array, pd, value.l);
2583 #if defined(__ALPHA__) || defined(__POWERPC64__)
2584 /* this keeps the assembler function much simpler */
2586 value.d = (double) va_arg(ap, double);
2588 value.f = (float) va_arg(ap, double);
2590 vm_array_store_flt(array, pd, value.l);
2594 value.d = va_arg(ap, double);
2595 vm_array_store_dbl(array, pd, value.l);
2599 value.a = va_arg(ap, void*);
2600 vm_array_store_adr(array, pd, value.a);
2610 /* vm_vmargs_from_jvalue *******************************************************
2614 *******************************************************************************/
2616 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
2617 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2618 vm_arg *vmargs, jvalue *args)
2620 typedesc *paramtypes;
2624 paramtypes = m->parseddesc->paramtypes;
2626 /* if method is non-static fill first block and skip `this' pointer */
2631 /* the `this' pointer */
2632 vmargs[0].type = TYPE_ADR;
2633 vmargs[0].data.l = (u8) (ptrint) o;
2639 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2640 switch (paramtypes->decltype) {
2642 vmargs[i].type = TYPE_INT;
2643 vmargs[i].data.l = (s8) args[j].i;
2647 vmargs[i].type = TYPE_LNG;
2648 vmargs[i].data.l = (s8) args[j].j;
2652 vmargs[i].type = TYPE_FLT;
2653 #if defined(__ALPHA__)
2654 /* this keeps the assembler function much simpler */
2656 vmargs[i].data.d = (jdouble) args[j].f;
2658 vmargs[i].data.f = args[j].f;
2663 vmargs[i].type = TYPE_DBL;
2664 vmargs[i].data.d = args[j].d;
2668 vmargs[i].type = TYPE_ADR;
2669 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2675 static uint64_t *vm_array_from_jvalue(methodinfo *m, java_objectheader *o,
2685 /* get the descriptors */
2689 td = md->paramtypes;
2691 /* allocate argument array */
2693 #if defined(HAS_ADDRESS_REGISTER_FILE)
2694 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
2696 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2699 /* if method is non-static fill first block and skip `this' pointer */
2704 /* the `this' pointer */
2705 vm_array_store_adr(array, pd, o);
2712 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2713 switch (td->decltype) {
2715 vm_array_store_int(array, pd, args[j].i);
2719 vm_array_store_lng(array, pd, args[j].j);
2723 vm_array_store_flt(array, pd, args[j].j);
2727 vm_array_store_dbl(array, pd, args[j].j);
2731 vm_array_store_adr(array, pd, args[j].l);
2740 /* vm_vmargs_from_objectarray **************************************************
2744 *******************************************************************************/
2746 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
2747 bool vm_vmargs_from_objectarray(methodinfo *m, java_objectheader *o,
2748 vm_arg *vmargs, java_objectarray *params)
2750 java_objectheader *param;
2751 typedesc *paramtypes;
2757 paramtypes = m->parseddesc->paramtypes;
2759 /* if method is non-static fill first block and skip `this' pointer */
2765 vmargs[0].type = TYPE_ADR;
2766 vmargs[0].data.l = (uint64_t) (intptr_t) o;
2772 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2773 switch (paramtypes->type) {
2774 /* primitive types */
2779 param = params->data[j];
2784 /* internally used data type */
2785 vmargs[i].type = paramtypes->type;
2787 /* convert the value according to its declared type */
2789 c = param->vftbl->class;
2791 switch (paramtypes->decltype) {
2792 case PRIMITIVETYPE_BOOLEAN:
2793 if (c == class_java_lang_Boolean)
2794 value = (int64_t) ((java_lang_Boolean *) param)->value;
2798 vmargs[i].data.l = value;
2801 case PRIMITIVETYPE_BYTE:
2802 if (c == class_java_lang_Byte)
2803 value = (int64_t) ((java_lang_Byte *) param)->value;
2807 vmargs[i].data.l = value;
2810 case PRIMITIVETYPE_CHAR:
2811 if (c == class_java_lang_Character)
2812 value = (int64_t) ((java_lang_Character *) param)->value;
2816 vmargs[i].data.l = value;
2819 case PRIMITIVETYPE_SHORT:
2820 if (c == class_java_lang_Short)
2821 value = (int64_t) ((java_lang_Short *) param)->value;
2822 else if (c == class_java_lang_Byte)
2823 value = (int64_t) ((java_lang_Byte *) param)->value;
2827 vmargs[i].data.l = value;
2830 case PRIMITIVETYPE_INT:
2831 if (c == class_java_lang_Integer)
2832 value = (int64_t) ((java_lang_Integer *) param)->value;
2833 else if (c == class_java_lang_Short)
2834 value = (int64_t) ((java_lang_Short *) param)->value;
2835 else if (c == class_java_lang_Byte)
2836 value = (int64_t) ((java_lang_Byte *) param)->value;
2840 vmargs[i].data.l = value;
2843 case PRIMITIVETYPE_LONG:
2844 if (c == class_java_lang_Long)
2845 value = (int64_t) ((java_lang_Long *) param)->value;
2846 else if (c == class_java_lang_Integer)
2847 value = (int64_t) ((java_lang_Integer *) param)->value;
2848 else if (c == class_java_lang_Short)
2849 value = (int64_t) ((java_lang_Short *) param)->value;
2850 else if (c == class_java_lang_Byte)
2851 value = (int64_t) ((java_lang_Byte *) param)->value;
2855 vmargs[i].data.l = value;
2858 case PRIMITIVETYPE_FLOAT:
2859 if (c == class_java_lang_Float)
2860 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
2865 case PRIMITIVETYPE_DOUBLE:
2866 if (c == class_java_lang_Double)
2867 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
2868 else if (c == class_java_lang_Float)
2869 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
2880 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
2883 if (params->data[j] != 0) {
2884 if (paramtypes->arraydim > 0) {
2885 if (!builtin_arrayinstanceof(params->data[j], c))
2889 if (!builtin_instanceof(params->data[j], c))
2894 vmargs[i].type = TYPE_ADR;
2895 vmargs[i].data.l = (u8) (ptrint) params->data[j];
2904 /* *rettype = descr->returntype.decltype; */
2909 exceptions_throw_illegalargumentexception();
2913 uint64_t *vm_array_from_objectarray(methodinfo *m, java_objectheader *o,
2914 java_objectarray *params)
2920 java_objectheader *param;
2926 /* get the descriptors */
2930 td = md->paramtypes;
2932 /* allocate argument array */
2934 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2936 /* if method is non-static fill first block and skip `this' pointer */
2942 vm_array_store_adr(array, pd, o);
2949 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2950 param = params->data[j];
2957 /* convert the value according to its declared type */
2959 c = param->vftbl->class;
2961 switch (td->decltype) {
2962 case PRIMITIVETYPE_BOOLEAN:
2963 if (c == class_java_lang_Boolean)
2964 value.i = ((java_lang_Boolean *) param)->value;
2969 case PRIMITIVETYPE_BYTE:
2970 if (c == class_java_lang_Byte)
2971 value.i = ((java_lang_Byte *) param)->value;
2976 case PRIMITIVETYPE_CHAR:
2977 if (c == class_java_lang_Character)
2978 value.i = ((java_lang_Character *) param)->value;
2983 case PRIMITIVETYPE_SHORT:
2984 if (c == class_java_lang_Short)
2985 value.i = ((java_lang_Short *) param)->value;
2986 else if (c == class_java_lang_Byte)
2987 value.i = ((java_lang_Byte *) param)->value;
2992 case PRIMITIVETYPE_INT:
2993 if (c == class_java_lang_Integer)
2994 value.i = ((java_lang_Integer *) param)->value;
2995 else if (c == class_java_lang_Short)
2996 value.i = ((java_lang_Short *) param)->value;
2997 else if (c == class_java_lang_Byte)
2998 value.i = ((java_lang_Byte *) param)->value;
3007 vm_array_store_int(array, pd, value.i);
3014 /* convert the value according to its declared type */
3016 c = param->vftbl->class;
3018 switch (td->decltype) {
3019 case PRIMITIVETYPE_LONG:
3020 if (c == class_java_lang_Long)
3021 value.l = ((java_lang_Long *) param)->value;
3022 else if (c == class_java_lang_Integer)
3023 value.l = (int64_t) ((java_lang_Integer *) param)->value;
3024 else if (c == class_java_lang_Short)
3025 value.l = (int64_t) ((java_lang_Short *) param)->value;
3026 else if (c == class_java_lang_Byte)
3027 value.l = (int64_t) ((java_lang_Byte *) param)->value;
3036 vm_array_store_lng(array, pd, value.l);
3043 /* convert the value according to its declared type */
3045 c = param->vftbl->class;
3047 switch (td->decltype) {
3048 case PRIMITIVETYPE_FLOAT:
3049 if (c == class_java_lang_Float)
3050 value.f = ((java_lang_Float *) param)->value;
3059 vm_array_store_flt(array, pd, value.l);
3066 /* convert the value according to its declared type */
3068 c = param->vftbl->class;
3070 switch (td->decltype) {
3071 case PRIMITIVETYPE_DOUBLE:
3072 if (c == class_java_lang_Double)
3073 value.d = ((java_lang_Double *) param)->value;
3074 else if (c == class_java_lang_Float)
3075 value.f = ((java_lang_Float *) param)->value;
3084 vm_array_store_dbl(array, pd, value.l);
3088 if (!resolve_class_from_typedesc(td, true, true, &c))
3091 if (param != NULL) {
3092 if (td->arraydim > 0) {
3093 if (!builtin_arrayinstanceof(param, c))
3097 if (!builtin_instanceof(param, c))
3102 vm_array_store_adr(array, pd, param);
3113 exceptions_throw_illegalargumentexception();
3119 /* vm_call_method **************************************************************
3121 Calls a Java method with a variable number of arguments and returns
3124 *******************************************************************************/
3126 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
3129 java_objectheader *ro;
3132 ro = vm_call_method_valist(m, o, ap);
3139 /* vm_call_method_valist *******************************************************
3141 Calls a Java method with a variable number of arguments, passed via
3142 a va_list, and returns an address.
3144 *******************************************************************************/
3146 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
3149 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3152 java_objectheader *ro;
3155 /* mark start of dump memory area */
3157 dumpsize = dump_size();
3159 /* get number of Java method arguments */
3161 vmargscount = m->parseddesc->paramcount;
3163 /* allocate vm_arg array */
3165 vmargs = DMNEW(vm_arg, vmargscount);
3167 /* fill the vm_arg array from a va_list */
3169 vm_vmargs_from_valist(m, o, vmargs, ap);
3171 /* call the Java method */
3173 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
3175 /* release dump area */
3177 dump_release(dumpsize);
3181 java_objectheader *ro;
3185 /* mark start of dump memory area */
3187 dumpsize = dump_size();
3189 /* fill the argument array from a va_list */
3191 array = vm_array_from_valist(m, o, ap);
3193 /* call the Java method */
3195 ro = vm_call_array(m, array);
3197 /* release dump area */
3199 dump_release(dumpsize);
3206 /* vm_call_method_jvalue *******************************************************
3208 Calls a Java method with a variable number of arguments, passed via
3209 a jvalue array, and returns an address.
3211 *******************************************************************************/
3213 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
3216 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3219 java_objectheader *ro;
3222 /* mark start of dump memory area */
3224 dumpsize = dump_size();
3226 /* get number of Java method arguments */
3228 vmargscount = m->parseddesc->paramcount;
3230 /* allocate vm_arg array */
3232 vmargs = DMNEW(vm_arg, vmargscount);
3234 /* fill the vm_arg array from a va_list */
3236 vm_vmargs_from_jvalue(m, o, vmargs, args);
3238 /* call the Java method */
3240 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
3242 /* release dump area */
3244 dump_release(dumpsize);
3248 java_objectheader *ro;
3252 /* mark start of dump memory area */
3254 dumpsize = dump_size();
3256 /* fill the argument array from a va_list */
3258 array = vm_array_from_jvalue(m, o, args);
3260 /* call the Java method */
3262 ro = vm_call_array(m, array);
3264 /* release dump area */
3266 dump_release(dumpsize);
3273 /* vm_call_array ***************************************************************
3275 Calls a Java method with a variable number of arguments, passed via
3276 an argument array, and returns an address.
3278 *******************************************************************************/
3280 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3281 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
3284 java_objectheader *o;
3286 STATISTICS(count_calls_native_to_java++);
3288 #if defined(ENABLE_JIT)
3289 # if defined(ENABLE_INTRP)
3291 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3294 o = asm_vm_call_method(m, vmargscount, vmargs);
3296 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3302 java_objectheader *vm_call_array(methodinfo *m, uint64_t *array)
3305 java_objectheader *o;
3309 /* compile the method if not already done */
3311 if (m->code == NULL)
3312 if (!jit_compile(m))
3315 STATISTICS(count_calls_native_to_java++);
3317 #if defined(ENABLE_JIT)
3318 # if defined(ENABLE_INTRP)
3320 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3323 o = asm_vm_call_method(m->code->entrypoint, array, md->memuse);
3325 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
3333 /* vm_call_int_array ***********************************************************
3335 Calls a Java method with a variable number of arguments, passed via
3336 an argument array, and returns an integer (int32_t).
3338 *******************************************************************************/
3340 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3341 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3345 STATISTICS(count_calls_native_to_java++);
3347 #if defined(ENABLE_JIT)
3348 # if defined(ENABLE_INTRP)
3350 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3353 i = asm_vm_call_method_int(m, vmargscount, vmargs);
3355 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3361 int32_t vm_call_int_array(methodinfo *m, uint64_t *array)
3368 /* compile the method if not already done */
3370 if (m->code == NULL)
3371 if (!jit_compile(m))
3374 STATISTICS(count_calls_native_to_java++);
3376 #if defined(ENABLE_JIT)
3377 # if defined(ENABLE_INTRP)
3379 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3382 i = asm_vm_call_method_int(m->code->entrypoint, array, md->memuse);
3384 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
3392 /* vm_call_method_int **********************************************************
3394 Calls a Java method with a variable number of arguments and returns
3397 *******************************************************************************/
3399 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
3405 i = vm_call_method_int_valist(m, o, ap);
3412 /* vm_call_method_int_valist ***************************************************
3414 Calls a Java method with a variable number of arguments, passed via
3415 a va_list, and returns an integer (int32_t).
3417 *******************************************************************************/
3419 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3420 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
3427 /* mark start of dump memory area */
3429 dumpsize = dump_size();
3431 /* get number of Java method arguments */
3433 vmargscount = m->parseddesc->paramcount;
3435 /* allocate vm_arg array */
3437 vmargs = DMNEW(vm_arg, vmargscount);
3439 /* fill the vm_arg array from a va_list */
3441 vm_vmargs_from_valist(m, o, vmargs, ap);
3443 /* call the Java method */
3445 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
3447 /* release dump area */
3449 dump_release(dumpsize);
3454 int32_t vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
3460 /* mark start of dump memory area */
3462 dumpsize = dump_size();
3464 /* fill the argument array from a va_list */
3466 array = vm_array_from_valist(m, o, ap);
3468 /* call the Java method */
3470 i = vm_call_int_array(m, array);
3472 /* release dump area */
3474 dump_release(dumpsize);
3481 /* vm_call_method_int_jvalue ***************************************************
3483 Calls a Java method with a variable number of arguments, passed via
3484 a jvalue array, and returns an integer (s4).
3486 *******************************************************************************/
3488 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3489 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
3496 /* mark start of dump memory area */
3498 dumpsize = dump_size();
3500 /* get number of Java method arguments */
3502 vmargscount = m->parseddesc->paramcount;
3504 /* allocate vm_arg array */
3506 vmargs = DMNEW(vm_arg, vmargscount);
3508 /* fill the vm_arg array from a va_list */
3510 vm_vmargs_from_jvalue(m, o, vmargs, args);
3512 /* call the Java method */
3514 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
3516 /* release dump area */
3518 dump_release(dumpsize);
3523 int32_t vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
3529 /* mark start of dump memory area */
3531 dumpsize = dump_size();
3533 /* fill the argument array from a va_list */
3535 array = vm_array_from_jvalue(m, o, args);
3537 /* call the Java method */
3539 i = vm_call_int_array(m, array);
3541 /* release dump area */
3543 dump_release(dumpsize);
3550 /* vm_call_long_array **********************************************************
3552 Calls a Java method with a variable number of arguments, passed via
3553 an argument array, and returns a long (int64_t).
3555 *******************************************************************************/
3557 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3558 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3562 STATISTICS(count_calls_native_to_java++);
3564 #if defined(ENABLE_JIT)
3565 # if defined(ENABLE_INTRP)
3567 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3570 l = asm_vm_call_method_long(m, vmargscount, vmargs);
3572 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3578 int64_t vm_call_long_array(methodinfo *m, uint64_t *array)
3585 /* compile the method if not already done */
3587 if (m->code == NULL)
3588 if (!jit_compile(m))
3591 STATISTICS(count_calls_native_to_java++);
3593 #if defined(ENABLE_JIT)
3594 # if defined(ENABLE_INTRP)
3596 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3599 l = asm_vm_call_method_long(m->code->entrypoint, array, md->memuse);
3601 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
3609 /* vm_call_method_long *********************************************************
3611 Calls a Java method with a variable number of arguments and returns
3614 *******************************************************************************/
3616 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
3622 l = vm_call_method_long_valist(m, o, ap);
3629 /* vm_call_method_long_valist **************************************************
3631 Calls a Java method with a variable number of arguments, passed via
3632 a va_list, and returns a long (s8).
3634 *******************************************************************************/
3636 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3637 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
3644 /* mark start of dump memory area */
3646 dumpsize = dump_size();
3648 /* get number of Java method arguments */
3650 vmargscount = m->parseddesc->paramcount;
3652 /* allocate vm_arg array */
3654 vmargs = DMNEW(vm_arg, vmargscount);
3656 /* fill the vm_arg array from a va_list */
3658 vm_vmargs_from_valist(m, o, vmargs, ap);
3660 /* call the Java method */
3662 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
3664 /* release dump area */
3666 dump_release(dumpsize);
3671 int64_t vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
3677 /* mark start of dump memory area */
3679 dumpsize = dump_size();
3681 /* fill the argument array from a va_list */
3683 array = vm_array_from_valist(m, o, ap);
3685 /* call the Java method */
3687 l = vm_call_long_array(m, array);
3689 /* release dump area */
3691 dump_release(dumpsize);
3698 /* vm_call_method_long_jvalue **************************************************
3700 Calls a Java method with a variable number of arguments, passed via
3701 a jvalue array, and returns a long (s8).
3703 *******************************************************************************/
3705 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3706 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
3713 /* mark start of dump memory area */
3715 dumpsize = dump_size();
3717 /* get number of Java method arguments */
3719 vmargscount = m->parseddesc->paramcount;
3721 /* allocate vm_arg array */
3723 vmargs = DMNEW(vm_arg, vmargscount);
3725 /* fill the vm_arg array from a va_list */
3727 vm_vmargs_from_jvalue(m, o, vmargs, args);
3729 /* call the Java method */
3731 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
3733 /* release dump area */
3735 dump_release(dumpsize);
3740 int64_t vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
3746 /* mark start of dump memory area */
3748 dumpsize = dump_size();
3750 /* fill the argument array from a va_list */
3752 array = vm_array_from_jvalue(m, o, args);
3754 /* call the Java method */
3756 l = vm_call_long_array(m, array);
3758 /* release dump area */
3760 dump_release(dumpsize);
3767 /* vm_call_float_array *********************************************************
3769 Calls a Java method with a variable number of arguments and returns
3772 *******************************************************************************/
3774 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3775 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
3779 vm_abort("IMPLEMENT ME!");
3781 STATISTICS(count_calls_native_to_java++);
3783 #if defined(ENABLE_JIT)
3784 # if defined(ENABLE_INTRP)
3786 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3789 f = asm_vm_call_method_float(m, vmargscount, vmargs);
3791 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3797 float vm_call_float_array(methodinfo *m, uint64_t *array)
3804 /* compile the method if not already done */
3806 if (m->code == NULL)
3807 if (!jit_compile(m))
3810 STATISTICS(count_calls_native_to_java++);
3812 #if defined(ENABLE_JIT)
3813 # if defined(ENABLE_INTRP)
3815 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3818 f = asm_vm_call_method_float(m->code->entrypoint, array, md->memuse);
3820 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
3828 /* vm_call_method_float ********************************************************
3830 Calls a Java method with a variable number of arguments and returns
3833 *******************************************************************************/
3835 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
3841 f = vm_call_method_float_valist(m, o, ap);
3848 /* vm_call_method_float_valist *************************************************
3850 Calls a Java method with a variable number of arguments, passed via
3851 a va_list, and returns a float.
3853 *******************************************************************************/
3855 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3856 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
3864 /* mark start of dump memory area */
3866 dumpsize = dump_size();
3868 /* get number of Java method arguments */
3870 vmargscount = m->parseddesc->paramcount;
3872 /* allocate vm_arg array */
3874 vmargs = DMNEW(vm_arg, vmargscount);
3876 /* fill the vm_arg array from a va_list */
3878 vm_vmargs_from_valist(m, o, vmargs, ap);
3880 /* call the Java method */
3882 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
3884 /* release dump area */
3886 dump_release(dumpsize);
3891 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o, va_list ap)
3897 /* mark start of dump memory area */
3899 dumpsize = dump_size();
3901 /* fill the argument array from a va_list */
3903 array = vm_array_from_valist(m, o, ap);
3905 /* call the Java method */
3907 f = vm_call_float_array(m, array);
3909 /* release dump area */
3911 dump_release(dumpsize);
3918 /* vm_call_method_float_jvalue *************************************************
3920 Calls a Java method with a variable number of arguments, passed via
3921 a jvalue array, and returns a float.
3923 *******************************************************************************/
3925 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3926 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
3934 /* mark start of dump memory area */
3936 dumpsize = dump_size();
3938 /* get number of Java method arguments */
3940 vmargscount = m->parseddesc->paramcount;
3942 /* allocate vm_arg array */
3944 vmargs = DMNEW(vm_arg, vmargscount);
3946 /* fill the vm_arg array from a va_list */
3948 vm_vmargs_from_jvalue(m, o, vmargs, args);
3950 /* call the Java method */
3952 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
3954 /* release dump area */
3956 dump_release(dumpsize);
3961 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
3967 /* mark start of dump memory area */
3969 dumpsize = dump_size();
3971 /* fill the argument array from a va_list */
3973 array = vm_array_from_jvalue(m, o, args);
3975 /* call the Java method */
3977 f = vm_call_float_array(m, array);
3979 /* release dump area */
3981 dump_release(dumpsize);
3988 /* vm_call_double_array ********************************************************
3990 Calls a Java method with a variable number of arguments and returns
3993 *******************************************************************************/
3995 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
3996 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
4001 vm_abort("IMPLEMENT ME!");
4003 STATISTICS(count_calls_native_to_java++);
4005 #if defined(ENABLE_JIT)
4006 # if defined(ENABLE_INTRP)
4008 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4011 d = asm_vm_call_method_double(m, vmargscount, vmargs);
4013 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4019 double vm_call_double_array(methodinfo *m, uint64_t *array)
4026 /* compile the method if not already done */
4028 if (m->code == NULL)
4029 if (!jit_compile(m))
4032 STATISTICS(count_calls_native_to_java++);
4034 #if defined(ENABLE_JIT)
4035 # if defined(ENABLE_INTRP)
4037 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4040 d = asm_vm_call_method_double(m->code->entrypoint, array, md->memuse);
4042 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
4050 /* vm_call_method_double *******************************************************
4052 Calls a Java method with a variable number of arguments and returns
4055 *******************************************************************************/
4057 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
4063 d = vm_call_method_double_valist(m, o, ap);
4070 /* vm_call_method_double_valist ************************************************
4072 Calls a Java method with a variable number of arguments, passed via
4073 a va_list, and returns a double.
4075 *******************************************************************************/
4077 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
4078 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
4086 /* mark start of dump memory area */
4088 dumpsize = dump_size();
4090 /* get number of Java method arguments */
4092 vmargscount = m->parseddesc->paramcount;
4094 /* allocate vm_arg array */
4096 vmargs = DMNEW(vm_arg, vmargscount);
4098 /* fill the vm_arg array from a va_list */
4100 vm_vmargs_from_valist(m, o, vmargs, ap);
4102 /* call the Java method */
4104 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
4106 /* release dump area */
4108 dump_release(dumpsize);
4113 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o, va_list ap)
4119 /* mark start of dump memory area */
4121 dumpsize = dump_size();
4123 /* fill the argument array from a va_list */
4125 array = vm_array_from_valist(m, o, ap);
4127 /* call the Java method */
4129 d = vm_call_double_array(m, array);
4131 /* release dump area */
4133 dump_release(dumpsize);
4140 /* vm_call_method_double_jvalue ************************************************
4142 Calls a Java method with a variable number of arguments, passed via
4143 a jvalue array, and returns a double.
4145 *******************************************************************************/
4147 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
4148 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
4156 /* mark start of dump memory area */
4158 dumpsize = dump_size();
4160 /* get number of Java method arguments */
4162 vmargscount = m->parseddesc->paramcount;
4164 /* allocate vm_arg array */
4166 vmargs = DMNEW(vm_arg, vmargscount);
4168 /* fill the vm_arg array from a va_list */
4170 vm_vmargs_from_jvalue(m, o, vmargs, args);
4172 /* call the Java method */
4174 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
4176 /* release dump area */
4178 dump_release(dumpsize);
4183 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
4189 /* mark start of dump memory area */
4191 dumpsize = dump_size();
4193 /* fill the argument array from a va_list */
4195 array = vm_array_from_jvalue(m, o, args);
4197 /* call the Java method */
4199 d = vm_call_double_array(m, array);
4201 /* release dump area */
4203 dump_release(dumpsize);
4211 * These are local overrides for various environment variables in Emacs.
4212 * Please do not remove this and leave it at the end of the file, where
4213 * Emacs will automagically detect them.
4214 * ---------------------------------------------------------------------
4217 * indent-tabs-mode: t