1 /* src/vm/vm.c - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006 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 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
30 $Id: vm.c 4357 2006-01-22 23:33:38Z twisti $
41 #if defined(WITH_JRE_LAYOUT)
48 #include "mm/gc-common.h"
49 #include "mm/memory.h"
50 #include "native/jni.h"
51 #include "native/native.h"
53 #if defined(ENABLE_THREADS)
54 # include "threads/native/threads.h"
57 #include "vm/classcache.h"
58 #include "vm/exceptions.h"
59 #include "vm/finalizer.h"
60 #include "vm/global.h"
61 #include "vm/initialize.h"
62 #include "vm/options.h"
63 #include "vm/properties.h"
64 #include "vm/rt-timing.h"
65 #include "vm/signallocal.h"
66 #include "vm/stringlocal.h"
69 #include "vm/jit/jit.h"
70 #include "vm/jit/asmpart.h"
72 #if defined(ENABLE_PROFILING)
73 # include "vm/jit/optimizing/profile.h"
76 #include "vm/jit/optimizing/recompile.h"
78 #if defined(ENABLE_JVMTI)
79 # include "native/jvmti/cacaodbg.h"
83 /* Invocation API variables ***************************************************/
85 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
86 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
89 /* global variables ***********************************************************/
91 s4 vms = 0; /* number of VMs created */
93 bool vm_initializing = false;
94 bool vm_exiting = false;
96 char *cacao_prefix = NULL;
97 char *cacao_libjvm = NULL;
98 char *classpath_libdir = NULL;
100 char *_Jv_bootclasspath; /* contains the boot classpath */
101 char *_Jv_classpath; /* contains the classpath */
102 char *_Jv_java_library_path;
104 char *mainstring = NULL;
105 classinfo *mainclass = NULL;
107 char *specificmethodname = NULL;
108 char *specificsignature = NULL;
112 #if defined(ENABLE_INTRP)
113 u1 *intrp_main_stack = NULL;
117 /* define heap sizes **********************************************************/
119 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
120 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
121 #define STACK_SIZE 64 * 1024 /* default 64kB */
124 /* define command line options ************************************************/
151 /* Java non-standard options */
162 #if defined(ENABLE_PROFILING)
176 #if defined(ENABLE_STATISTICS)
193 #if defined(ENABLE_VERIFIER)
195 #if defined(TYPECHECK_VERBOSE)
198 #endif /* defined(ENABLE_VERIFIER) */
201 /* optimization options */
203 #if defined(ENABLE_LOOP)
207 #if defined(ENABLE_IFCONV)
211 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
215 #if defined(ENABLE_INLINING)
219 #if defined(ENABLE_INTRP)
220 /* interpreter options */
243 opt_struct opts[] = {
244 { "foo", false, OPT_FOO },
248 { "jar", false, OPT_JAR },
250 { "d32", false, OPT_D32 },
251 { "d64", false, OPT_D64 },
252 { "client", false, OPT_IGNORE },
253 { "server", false, OPT_IGNORE },
254 { "jvm", false, OPT_IGNORE },
255 { "hotspot", false, OPT_IGNORE },
257 { "classpath", true, OPT_CLASSPATH },
258 { "cp", true, OPT_CLASSPATH },
259 { "D", true, OPT_D },
260 { "version", false, OPT_VERSION },
261 { "showversion", false, OPT_SHOWVERSION },
262 { "fullversion", false, OPT_FULLVERSION },
263 { "help", false, OPT_HELP },
264 { "?", false, OPT_HELP },
265 { "X", false, OPT_X },
267 { "esa", false, OPT_ESA },
268 { "enablesystemassertions", false, OPT_ESA },
269 { "dsa", false, OPT_DSA },
270 { "disablesystemassertions", false, OPT_DSA },
272 { "noasyncgc", false, OPT_IGNORE },
273 #if defined(ENABLE_VERIFIER)
274 { "noverify", false, OPT_NOVERIFY },
276 { "v", false, OPT_VERBOSE1 },
277 { "verbose:", true, OPT_VERBOSE },
279 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
280 { "verbosetc", false, OPT_VERBOSETC },
282 #if defined(__ALPHA__)
283 { "noieee", false, OPT_NOIEEE },
285 { "softnull", false, OPT_SOFTNULL },
286 #if defined(ENABLE_STATISTICS)
287 { "time", false, OPT_TIME },
288 { "stat", false, OPT_STAT },
290 { "log", true, OPT_LOG },
291 { "c", true, OPT_CHECK },
292 { "l", false, OPT_LOAD },
293 { "eager", false, OPT_EAGER },
296 { "all", false, OPT_ALL },
297 { "sig", true, OPT_SIGNATURE },
300 #if defined(ENABLE_LOOP)
301 { "oloop", false, OPT_OLOOP },
303 #if defined(ENABLE_IFCONV)
304 { "ifconv", false, OPT_IFCONV },
306 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
307 { "lsra", false, OPT_LSRA },
310 #if defined(ENABLE_INTRP)
311 /* interpreter options */
313 { "trace", false, OPT_TRACE },
314 { "static-supers", true, OPT_STATIC_SUPERS },
315 { "no-dynamic", false, OPT_NO_DYNAMIC },
316 { "no-replication", false, OPT_NO_REPLICATION },
317 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
320 /* JVMTI Agent Command Line Options */
322 { "agentlib:", true, OPT_AGENTLIB },
323 { "agentpath:", true, OPT_AGENTPATH },
326 /* Java non-standard options */
328 { "Xjit", false, OPT_JIT },
329 { "Xint", false, OPT_INTRP },
330 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
331 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
332 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
333 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
336 { "Xdebug", false, OPT_DEBUG },
337 { "Xnoagent", false, OPT_NOAGENT },
338 { "Xrunjdwp", true, OPT_XRUNJDWP },
341 { "Xms", true, OPT_MS },
342 { "ms", true, OPT_MS },
343 { "Xmx", true, OPT_MX },
344 { "mx", true, OPT_MX },
345 { "Xss", true, OPT_SS },
346 { "ss", true, OPT_SS },
348 #if defined(ENABLE_PROFILING)
349 { "Xprof:", true, OPT_PROF_OPTION },
350 { "Xprof", false, OPT_PROF },
353 /* keep these at the end of the list */
355 #if defined(ENABLE_INLINING)
356 { "i", true, OPT_INLINING },
360 { "m", true, OPT_METHOD },
363 { "s", true, OPT_SHOW },
364 { "debug-color", false, OPT_DEBUGCOLOR },
370 /* usage ***********************************************************************
372 Prints the correct usage syntax to stdout.
374 *******************************************************************************/
378 puts("Usage: cacao [-options] classname [arguments]");
379 puts(" (to run a class file)");
380 puts(" or cacao [-options] -jar jarfile [arguments]");
381 puts(" (to run a standalone jar file)\n");
383 puts("Java options:");
384 puts(" -d32 use 32-bit data model if available");
385 puts(" -d64 use 64-bit data model if available");
386 puts(" -client compatibility (currently ignored)");
387 puts(" -server compatibility (currently ignored)");
388 puts(" -jvm compatibility (currently ignored)");
389 puts(" -hotspot compatibility (currently ignored)\n");
391 puts(" -cp <path> specify a path to look for classes");
392 puts(" -classpath <path> specify a path to look for classes");
393 puts(" -D<name>=<value> add an entry to the property list");
394 puts(" -verbose[:class|gc|jni] enable specific verbose output");
395 puts(" -version print product version and exit");
396 puts(" -fullversion print jpackage-compatible product version and exit");
397 puts(" -showversion print product version and continue");
398 puts(" -help, -? print this help message");
399 puts(" -X print help on non-standard Java options");
400 puts(" -esa | -enablesystemassertions");
401 puts(" enable system assertions");
402 puts(" -dsa | -disablesystemassertions");
403 puts(" disable system assertions");
407 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
408 puts (" for jdwp help use: -agentlib:jdwp=help");
409 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
412 puts("CACAO options:");
413 puts(" -v write state-information");
414 puts(" -verbose[:call|exception|jit]");
415 puts(" enable specific verbose output");
416 puts(" -debug-color colored output for ANSI terms");
417 #ifdef TYPECHECK_VERBOSE
418 puts(" -verbosetc write debug messages while typechecking");
420 #if defined(__ALPHA__)
421 puts(" -noieee don't use ieee compliant arithmetic");
423 #if defined(ENABLE_VERIFIER)
424 puts(" -noverify don't verify classfiles");
426 puts(" -softnull use software nullpointer check");
427 #if defined(ENABLE_STATISTICS)
428 puts(" -time measure the runtime");
429 puts(" -stat detailed compiler statistics");
431 puts(" -log logfile specify a name for the logfile");
432 puts(" -c(heck)b(ounds) don't check array bounds");
433 puts(" s(ync) don't check for synchronization");
434 #if defined(ENABLE_LOOP)
435 puts(" -oloop optimize array accesses in loops");
437 puts(" -l don't start the class after loading");
438 puts(" -eager perform eager class loading and linking");
440 puts(" -all compile all methods, no execution");
441 puts(" -m compile only a specific method");
442 puts(" -sig specify signature for a specific method");
445 puts(" -s... show...");
446 puts(" (c)onstants the constant pool");
447 puts(" (m)ethods class fields and methods");
448 puts(" (u)tf the utf - hash");
449 puts(" (i)ntermediate intermediate representation");
450 #if defined(ENABLE_DISASSEMBLER)
451 puts(" (a)ssembler disassembled listing");
452 puts(" n(o)ps show NOPs in disassembler output");
453 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
454 puts(" (n)ative disassembled native stubs");
456 puts(" (d)atasegment data segment listing");
457 #if defined(ENABLE_INLINING)
458 puts(" -i n(line) activate inlining");
459 puts(" v(irtual) inline virtual methods (uses/turns rt option on)");
460 puts(" e(exception) inline methods with exceptions");
461 puts(" p(aramopt) optimize argument renaming");
462 puts(" o(utsiders) inline methods of foreign classes");
463 #endif /* defined(ENABLE_INLINING) */
464 #if defined(ENABLE_IFCONV)
465 puts(" -ifconv use if-conversion");
467 #if defined(ENABLE_LSRA)
468 puts(" -lsra use linear scan register allocation");
470 #if defined(ENABLE_SSA)
471 puts(" -lsra use linear scan register allocation (with SSA)");
474 /* exit with error code */
480 static void Xusage(void)
482 #if defined(ENABLE_JIT)
483 puts(" -Xjit JIT mode execution (default)");
485 #if defined(ENABLE_INTRP)
486 puts(" -Xint interpreter mode execution");
488 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
489 puts(" value is set as bootstrap class path");
490 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
491 puts(" value is appended to the bootstrap class path");
492 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
493 puts(" value is prepended to the bootstrap class path");
494 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
495 puts(" value is used as Java core library, but the");
496 puts(" hardcoded VM interface classes are prepended");
497 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
498 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
499 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
501 #if defined(ENABLE_PROFILING)
502 puts(" -Xprof[:bb] collect and print profiling data");
505 #if defined(ENABLE_JVMTI)
506 /* -Xdebug option depend on gnu classpath JDWP options. options:
507 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
508 puts(" -Xdebug enable remote debugging\n");
509 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
510 puts(" enable remote debugging\n");
513 /* exit with error code */
519 /* version *********************************************************************
521 Only prints cacao version information.
523 *******************************************************************************/
525 static void version(bool opt_exit)
527 puts("java version \""JAVA_VERSION"\"");
528 puts("CACAO version "VERSION"");
530 puts("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,");
531 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
532 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
533 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
535 puts("This program is free software; you can redistribute it and/or");
536 puts("modify it under the terms of the GNU General Public License as");
537 puts("published by the Free Software Foundation; either version 2, or (at");
538 puts("your option) any later version.\n");
540 puts("This program is distributed in the hope that it will be useful, but");
541 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
542 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
543 puts("General Public License for more details.\n");
545 puts("Configure/Build options:\n");
546 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
547 #if defined(__VERSION__)
548 puts(" CC : "VERSION_CC" ("__VERSION__")");
550 puts(" CC : "VERSION_CC"");
552 puts(" CFLAGS : "VERSION_CFLAGS"\n");
554 puts("Default variables:\n");
555 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
556 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
557 printf(" stack size : %d\n", STACK_SIZE);
558 #if defined(WITH_CLASSPATH_GNU)
559 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
561 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
563 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
565 puts("Runtime variables:\n");
566 printf(" maximum heap size : %d\n", opt_heapmaxsize);
567 printf(" initial heap size : %d\n", opt_heapstartsize);
568 printf(" stack size : %d\n", opt_stacksize);
569 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
570 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
571 printf(" java.class.path : %s\n", _Jv_classpath);
573 /* exit normally, if requested */
580 /* fullversion *****************************************************************
582 Prints a Sun compatible version information (required e.g. by
583 jpackage, www.jpackage.org).
585 *******************************************************************************/
587 static void fullversion(void)
589 puts("java full version \"cacao-"JAVA_VERSION"\"");
597 /* forward declarations *******************************************************/
599 static char *vm_get_mainclass_from_jar(char *mainstring);
601 static void vm_compile_all(void);
602 static void vm_compile_method(void);
606 /* vm_createjvm ****************************************************************
608 Implementation for JNI_CreateJavaVM.
610 *******************************************************************************/
612 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
614 JavaVMInitArgs *_vm_args;
618 /* get the arguments for the new JVM */
620 _vm_args = (JavaVMInitArgs *) vm_args;
622 /* get the VM and Env tables (must be set before vm_create) */
624 env = NEW(_Jv_JNIEnv);
626 #if defined(ENABLE_JAVASE)
627 env->env = &_Jv_JNINativeInterface;
630 /* XXX Set the global variable. Maybe we should do that differently. */
634 /* create and fill a JavaVM structure */
636 vm = NEW(_Jv_JavaVM);
638 #if defined(ENABLE_JAVASE)
639 vm->functions = &_Jv_JNIInvokeInterface;
642 /* XXX Set the global variable. Maybe we should do that differently. */
643 /* XXX JVMTI Agents needs a JavaVM */
647 /* actually create the JVM */
649 if (!vm_create(_vm_args))
652 #if defined(ENABLE_JAVASE)
653 /* setup the local ref table (must be created after vm_create) */
655 if (!jni_init_localref_table())
659 /* now return the values */
661 *p_vm = (JavaVM *) vm;
662 *p_env = (void *) env;
667 /* release allocated memory */
669 FREE(env, _Jv_JNIEnv);
670 FREE(vm, _Jv_JavaVM);
676 /* vm_create *******************************************************************
678 Creates a JVM. Called by vm_createjvm.
680 *******************************************************************************/
682 bool vm_create(JavaVMInitArgs *vm_args)
691 #if defined(ENABLE_JVMTI)
693 char *libname, *agentarg;
694 bool jdwp,agentbypath;
695 jdwp = agentbypath = false;
698 /* check the JNI version requested */
700 switch (vm_args->version) {
701 case JNI_VERSION_1_1:
703 case JNI_VERSION_1_2:
704 case JNI_VERSION_1_4:
710 /* we only support 1 JVM instance */
715 if (atexit(vm_exit_handler))
716 vm_abort("atexit failed: %s\n", strerror(errno));
719 log_text("CACAO started -------------------------------------------------------");
721 /* set the VM starttime */
723 _Jv_jvm->starttime = builtin_currenttimemillis();
725 /* get stuff from the environment *****************************************/
727 #if defined(WITH_JRE_LAYOUT)
728 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
730 cacao_prefix = MNEW(char, 4096);
732 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
733 vm_abort("readlink failed: %s\n", strerror(errno));
735 /* get the path of the current executable */
737 cacao_prefix = dirname(cacao_prefix);
739 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
740 vm_abort("libjvm name to long for buffer\n");
742 /* concatenate the library name */
744 strcat(cacao_prefix, "/..");
746 /* now set path to libjvm.so */
748 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
750 cacao_libjvm = MNEW(char, len);
751 strcpy(cacao_libjvm, cacao_prefix);
752 strcat(cacao_libjvm, "/lib/libjvm");
754 /* and finally set the path to GNU Classpath libraries */
756 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
758 classpath_libdir = MNEW(char, len);
759 strcpy(classpath_libdir, cacao_prefix);
760 strcat(classpath_libdir, "/lib/classpath");
762 cacao_prefix = CACAO_PREFIX;
763 cacao_libjvm = CACAO_LIBDIR"/libjvm";
764 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
767 /* set the bootclasspath */
769 cp = getenv("BOOTCLASSPATH");
772 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
773 strcpy(_Jv_bootclasspath, cp);
776 #if defined(WITH_JRE_LAYOUT)
778 # if defined(WITH_CLASSPATH_GNU)
779 strlen(cacao_prefix) +
780 strlen("/share/cacao/vm.zip") +
783 strlen(cacao_prefix) +
784 strlen("/share/classpath/glibj.zip") +
787 _Jv_bootclasspath = MNEW(char, len);
788 # if defined(WITH_CLASSPATH_GNU)
789 strcat(_Jv_bootclasspath, cacao_prefix);
790 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
791 strcat(_Jv_bootclasspath, ":");
793 strcat(_Jv_bootclasspath, cacao_prefix);
794 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
797 # if defined(WITH_CLASSPATH_GNU)
798 strlen(CACAO_VM_ZIP) +
801 strlen(CLASSPATH_CLASSES) +
804 _Jv_bootclasspath = MNEW(char, len);
805 # if defined(WITH_CLASSPATH_GNU)
806 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
807 strcat(_Jv_bootclasspath, ":");
809 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
813 /* set the classpath */
815 cp = getenv("CLASSPATH");
818 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
819 strcat(_Jv_classpath, cp);
822 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
823 strcpy(_Jv_classpath, ".");
826 /* get and set java.library.path */
828 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
830 if (_Jv_java_library_path == NULL)
831 _Jv_java_library_path = "";
833 /* interpret the options **************************************************/
841 opt_heapmaxsize = HEAP_MAXSIZE;
842 opt_heapstartsize = HEAP_STARTSIZE;
843 opt_stacksize = STACK_SIZE;
846 #if defined(ENABLE_JVMTI)
847 /* initialize JVMTI related **********************************************/
851 /* initialize and fill properties before command-line handling */
853 if (!properties_init())
854 vm_abort("properties_init failed");
856 /* iterate over all passed options */
858 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
872 #if SIZEOF_VOID_P == 8
873 puts("Running a 32-bit JVM is not supported on this platform.");
879 #if SIZEOF_VOID_P == 4
880 puts("Running a 64-bit JVM is not supported on this platform.");
886 /* forget old classpath and set the argument as new classpath */
887 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
889 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
890 strcpy(_Jv_classpath, opt_arg);
894 for (i = 0; i < strlen(opt_arg); i++) {
895 if (opt_arg[i] == '=') {
897 properties_add(opt_arg, opt_arg + i + 1);
902 /* if no '=' is given, just create an empty property */
904 properties_add(opt_arg, "");
909 case OPT_BOOTCLASSPATH:
910 /* Forget default bootclasspath and set the argument as
911 new boot classpath. */
913 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
915 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
916 strcpy(_Jv_bootclasspath, opt_arg);
919 case OPT_BOOTCLASSPATH_A:
920 /* append to end of bootclasspath */
922 len = strlen(_Jv_bootclasspath);
924 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
928 strlen(opt_arg) + strlen("0"));
930 strcat(_Jv_bootclasspath, ":");
931 strcat(_Jv_bootclasspath, opt_arg);
934 case OPT_BOOTCLASSPATH_P:
935 /* prepend in front of bootclasspath */
937 cp = _Jv_bootclasspath;
940 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
943 strcpy(_Jv_bootclasspath, opt_arg);
944 strcat(_Jv_bootclasspath, ":");
945 strcat(_Jv_bootclasspath, cp);
947 MFREE(cp, char, len);
950 case OPT_BOOTCLASSPATH_C:
951 /* use as Java core library, but prepend VM interface classes */
953 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
955 len = strlen(CACAO_VM_ZIP) +
960 _Jv_bootclasspath = MNEW(char, len);
962 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
963 strcat(_Jv_bootclasspath, ":");
964 strcat(_Jv_bootclasspath, opt_arg);
967 #if defined(ENABLE_JVMTI)
969 /* this option exists only for compatibility reasons */
973 /* I don't know yet what Xnoagent should do. This is only for
974 compatiblity with eclipse - motse */
983 strlen(CACAO_LIBDIR) +
984 strlen("/libjdwp.so=") +
988 agentarg = MNEW(char, len);
990 strcpy(agentarg, CACAO_LIBDIR);
991 strcat(agentarg, "/libjdwp.so=");
992 strcat(agentarg, &opt_arg[1]);
1009 c = opt_arg[strlen(opt_arg) - 1];
1011 if ((c == 'k') || (c == 'K')) {
1012 j = atoi(opt_arg) * 1024;
1014 } else if ((c == 'm') || (c == 'M')) {
1015 j = atoi(opt_arg) * 1024 * 1024;
1021 opt_heapmaxsize = j;
1022 else if (opt == OPT_MS)
1023 opt_heapstartsize = j;
1034 if (strcmp("class", opt_arg) == 0)
1035 opt_verboseclass = true;
1037 else if (strcmp("gc", opt_arg) == 0)
1038 opt_verbosegc = true;
1040 else if (strcmp("jni", opt_arg) == 0)
1041 opt_verbosejni = true;
1043 else if (strcmp("call", opt_arg) == 0)
1044 opt_verbosecall = true;
1046 else if (strcmp("jit", opt_arg) == 0) {
1051 compileverbose = true;
1053 else if (strcmp("exception", opt_arg) == 0)
1054 opt_verboseexception = true;
1056 case OPT_DEBUGCOLOR:
1057 opt_debugcolor = true;
1060 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1062 opt_typecheckverbose = true;
1071 case OPT_FULLVERSION:
1075 case OPT_SHOWVERSION:
1083 #if defined(ENABLE_VERIFIER)
1093 #if defined(ENABLE_STATISTICS)
1095 opt_getcompilingtime = true;
1096 opt_getloadingtime = true;
1109 for (i = 0; i < strlen(opt_arg); i++) {
1110 switch (opt_arg[i]) {
1112 checkbounds = false;
1125 makeinitializations = false;
1132 #if !defined(NDEBUG)
1136 makeinitializations = false;
1141 opt_method = opt_arg;
1142 makeinitializations = false;
1146 opt_signature = opt_arg;
1150 case OPT_SHOW: /* Display options */
1151 for (i = 0; i < strlen(opt_arg); i++) {
1152 switch (opt_arg[i]) {
1154 showconstantpool = true;
1166 opt_showintermediate = true;
1167 compileverbose = true;
1170 #if defined(ENABLE_DISASSEMBLER)
1172 opt_showdisassemble = true;
1173 compileverbose = true;
1177 opt_shownops = true;
1181 opt_showexceptionstubs = true;
1185 opt_shownativestub = true;
1190 opt_showddatasegment = true;
1199 #if defined(ENABLE_LOOP)
1205 #if defined(ENABLE_INLINING)
1207 for (i = 0; i < strlen(opt_arg); i++) {
1208 switch (opt_arg[i]) {
1210 /* define in options.h; Used in main.c, jit.c
1211 & inline.c inlining is currently
1215 inlinevirtuals = true;
1218 inlineexceptions = true;
1221 inlineparamopt = true;
1224 inlineoutsiders = true;
1231 #endif /* defined(ENABLE_INLINING) */
1233 #if defined(ENABLE_IFCONV)
1239 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1254 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1258 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1261 #if defined(ENABLE_PROFILING)
1262 case OPT_PROF_OPTION:
1263 /* use <= to get the last \0 too */
1265 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1266 if (opt_arg[i] == ',')
1269 if (opt_arg[i] == '\0') {
1270 if (strcmp("bb", opt_arg + j) == 0)
1274 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1278 /* set k to next char */
1291 #if defined(ENABLE_JIT)
1294 printf("-Xjit option not enabled.\n");
1300 #if defined(ENABLE_INTRP)
1303 printf("-Xint option not enabled.\n");
1308 #if defined(ENABLE_INTRP)
1309 case OPT_STATIC_SUPERS:
1310 opt_static_supers = atoi(opt_arg);
1313 case OPT_NO_DYNAMIC:
1314 opt_no_dynamic = true;
1317 case OPT_NO_REPLICATION:
1318 opt_no_replication = true;
1321 case OPT_NO_QUICKSUPER:
1322 opt_no_quicksuper = true;
1331 printf("Unknown option: %s\n",
1332 vm_args->options[opt_index].optionString);
1337 /* get the main class *****************************************************/
1339 if (opt_index < vm_args->nOptions) {
1340 mainstring = vm_args->options[opt_index++].optionString;
1342 /* Put the jar file into the classpath (if any). */
1344 if (opt_jar == true) {
1345 /* free old classpath */
1347 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1349 /* put jarfile into classpath */
1351 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1353 strcpy(_Jv_classpath, mainstring);
1356 /* replace .'s with /'s in classname */
1358 for (i = strlen(mainstring) - 1; i >= 0; i--)
1359 if (mainstring[i] == '.')
1360 mainstring[i] = '/';
1364 #if defined(ENABLE_JVMTI)
1366 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1367 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1370 MFREE(agentarg, char, strlen(agentarg));
1372 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1376 /* Now re-set some of the properties that may have changed. This
1377 must be done after _all_ environment variables have been
1378 processes (e.g. -jar handling). */
1380 if (!properties_postinit())
1381 vm_abort("properties_postinit failed");
1383 /* Now we have all options handled and we can print the version
1389 /* initialize this JVM ****************************************************/
1391 vm_initializing = true;
1393 #if defined(ENABLE_THREADS)
1394 /* pre-initialize some core thread stuff, like the stopworldlock,
1395 thus this has to happen _before_ gc_init()!!! */
1400 /* initialize the garbage collector */
1402 gc_init(opt_heapmaxsize, opt_heapstartsize);
1404 #if defined(ENABLE_INTRP)
1405 /* Allocate main thread stack on the Java heap. */
1408 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1409 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1413 /* initialize the string hashtable stuff: lock (must be done
1414 _after_ threads_preinit) */
1417 throw_main_exception_exit();
1419 /* initialize the utf8 hashtable stuff: lock, often used utf8
1420 strings (must be done _after_ threads_preinit) */
1423 throw_main_exception_exit();
1425 /* initialize the classcache hashtable stuff: lock, hashtable
1426 (must be done _after_ threads_preinit) */
1428 if (!classcache_init())
1429 throw_main_exception_exit();
1431 /* initialize the loader with bootclasspath (must be done _after_
1435 throw_main_exception_exit();
1437 suck_add_from_property("java.endorsed.dirs");
1438 suck_add(_Jv_bootclasspath);
1440 /* initialize the memory subsystem (must be done _after_
1444 throw_main_exception_exit();
1446 /* initialize the finalizer stuff (must be done _after_
1449 if (!finalizer_init())
1450 throw_main_exception_exit();
1452 /* install architecture dependent signal handler used for exceptions */
1456 /* initialize the codegen subsystems */
1460 /* initializes jit compiler */
1464 /* machine dependent initialization */
1466 #if defined(ENABLE_JIT)
1467 # if defined(ENABLE_INTRP)
1477 /* initialize the loader subsystems (must be done _after_
1481 throw_main_exception_exit();
1484 throw_main_exception_exit();
1487 throw_main_exception_exit();
1489 if (!exceptions_init())
1490 throw_main_exception_exit();
1492 if (!builtin_init())
1493 throw_main_exception_exit();
1495 #if defined(ENABLE_JAVASE)
1496 /* Initialize the JNI subsystem (must be done _before_
1497 threads_init, as threads_init can call JNI methods
1498 (e.g. NewGlobalRef). */
1501 throw_main_exception_exit();
1504 #if defined(ENABLE_THREADS)
1505 if (!threads_init())
1506 throw_main_exception_exit();
1509 #if defined(ENABLE_PROFILING)
1510 /* initialize profiling */
1512 if (!profile_init())
1513 throw_main_exception_exit();
1516 #if defined(ENABLE_THREADS)
1517 /* initialize recompilation */
1519 if (!recompile_init())
1520 throw_main_exception_exit();
1522 /* finally, start the finalizer thread */
1524 if (!finalizer_start_thread())
1525 throw_main_exception_exit();
1527 /* start the recompilation thread (must be done before the
1528 profiling thread) */
1530 if (!recompile_start_thread())
1531 throw_main_exception_exit();
1533 # if defined(ENABLE_PROFILING)
1534 /* start the profile sampling thread */
1537 /* if (!profile_start_thread()) */
1538 /* throw_main_exception_exit(); */
1542 #if defined(ENABLE_JVMTI)
1544 /* add agent library to native library hashtable */
1545 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1549 /* increment the number of VMs */
1553 /* initialization is done */
1555 vm_initializing = false;
1557 /* everything's ok */
1563 /* vm_run **********************************************************************
1565 Runs the main-method of the passed class.
1567 *******************************************************************************/
1569 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1572 classinfo *mainclass;
1574 java_objectarray *oa;
1577 java_lang_String *s;
1581 #if !defined(NDEBUG)
1587 if (opt_method != NULL) {
1588 vm_compile_method();
1591 #endif /* !defined(NDEBUG) */
1593 /* should we run the main-method? */
1595 if (mainstring == NULL)
1598 /* set return value to OK */
1602 if (opt_jar == true)
1603 /* open jar file with java.util.jar.JarFile */
1604 mainstring = vm_get_mainclass_from_jar(mainstring);
1606 /* load the main class */
1608 mainutf = utf_new_char(mainstring);
1610 #if defined(ENABLE_JAVAME_CLDC1_1)
1611 if (!(mainclass = load_class_bootstrap(mainutf)))
1612 throw_main_exception_exit();
1614 if (!(mainclass = load_class_from_sysloader(mainutf)))
1615 throw_main_exception_exit();
1618 /* error loading class */
1620 if ((*exceptionptr != NULL) || (mainclass == NULL))
1621 throw_main_exception_exit();
1623 if (!link_class(mainclass))
1624 throw_main_exception_exit();
1626 /* find the `main' method of the main class */
1628 m = class_resolveclassmethod(mainclass,
1629 utf_new_char("main"),
1630 utf_new_char("([Ljava/lang/String;)V"),
1631 class_java_lang_Object,
1634 if (*exceptionptr) {
1635 throw_main_exception_exit();
1638 /* there is no main method or it isn't static */
1640 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1641 *exceptionptr = NULL;
1644 new_exception_message(string_java_lang_NoSuchMethodError, "main");
1645 throw_main_exception_exit();
1648 /* build argument array */
1650 oalength = vm_args->nOptions - opt_index;
1652 oa = builtin_anewarray(oalength, class_java_lang_String);
1654 for (i = 0; i < oalength; i++) {
1655 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1656 s = javastring_new(u);
1658 oa->data[i] = (java_objectheader *) s;
1661 #ifdef TYPEINFO_DEBUG_TEST
1662 /* test the typeinfo system */
1665 /*class_showmethods(currentThread->group->header.vftbl->class); */
1667 #if defined(ENABLE_JVMTI)
1668 jvmti_set_phase(JVMTI_PHASE_LIVE);
1671 /* set ThreadMXBean variables */
1673 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1674 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1676 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1677 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1678 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1679 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1681 /* start the main thread */
1683 (void) vm_call_method(m, NULL, oa);
1685 /* exception occurred? */
1687 if (*exceptionptr) {
1688 throw_main_exception();
1692 /* unload the JavaVM */
1702 /* vm_destroy ******************************************************************
1704 Unloads a Java VM and reclaims its resources.
1706 *******************************************************************************/
1708 s4 vm_destroy(JavaVM *vm)
1710 #if defined(ENABLE_THREADS)
1711 threads_join_all_threads();
1714 /* everything's ok */
1720 /* vm_exit *********************************************************************
1722 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1724 *******************************************************************************/
1726 void vm_exit(s4 status)
1730 /* signal that we are exiting */
1734 assert(class_java_lang_System);
1735 assert(class_java_lang_System->state & CLASS_LOADED);
1737 #if defined(ENABLE_JVMTI)
1738 if (jvmti || (dbgcom!=NULL)) {
1739 jvmti_set_phase(JVMTI_PHASE_DEAD);
1740 if (jvmti) jvmti_agentunload();
1744 if (!link_class(class_java_lang_System))
1745 throw_main_exception_exit();
1747 /* call java.lang.System.exit(I)V */
1749 m = class_resolveclassmethod(class_java_lang_System,
1750 utf_new_char("exit"),
1752 class_java_lang_Object,
1756 throw_main_exception_exit();
1758 /* call the exit function with passed exit status */
1760 (void) vm_call_method(m, NULL, status);
1762 /* If we had an exception, just ignore the exception and exit with
1765 vm_shutdown(status);
1769 /* vm_shutdown *****************************************************************
1771 Terminates the system immediately without freeing memory explicitly
1772 (to be used only for abnormal termination).
1774 *******************************************************************************/
1776 void vm_shutdown(s4 status)
1779 #if defined(ENABLE_STATISTICS)
1780 || opt_getcompilingtime || opt_stat
1784 log_text("CACAO terminated by shutdown");
1785 dolog("Exit status: %d\n", (s4) status);
1789 #if defined(ENABLE_JVMTI)
1790 /* terminate cacaodbgserver */
1792 pthread_mutex_lock(&dbgcomlock);
1794 pthread_mutex_unlock(&dbgcomlock);
1795 jvmti_cacaodbgserver_quit();
1803 /* vm_exit_handler *************************************************************
1805 The exit_handler function is called upon program termination.
1807 ATTENTION: Don't free system resources here! Some threads may still
1808 be running as this is called from VMRuntime.exit(). The OS does the
1811 *******************************************************************************/
1813 void vm_exit_handler(void)
1815 #if !defined(NDEBUG)
1817 class_showmethods(mainclass);
1819 if (showconstantpool)
1820 class_showconstantpool(mainclass);
1825 # if defined(ENABLE_PROFILING)
1827 profile_printstats();
1829 #endif /* !defined(NDEBUG) */
1831 #if defined(ENABLE_RT_TIMING)
1832 rt_timing_print_time_stats(stderr);
1835 #if defined(ENABLE_CYCLES_STATS)
1836 builtin_print_cycles_stats(stderr);
1837 stacktrace_print_cycles_stats(stderr);
1841 #if defined(ENABLE_STATISTICS)
1842 || opt_getcompilingtime || opt_stat
1846 log_text("CACAO terminated");
1848 #if defined(ENABLE_STATISTICS)
1851 #ifdef TYPECHECK_STATISTICS
1852 typecheck_print_statistics(get_logfile());
1858 if (opt_getcompilingtime)
1860 #endif /* defined(ENABLE_STATISTICS) */
1862 /* vm_print_profile(stderr);*/
1866 /* vm_abort ********************************************************************
1868 Prints an error message and aborts the VM.
1870 *******************************************************************************/
1872 void vm_abort(const char *text, ...)
1876 /* print the log message */
1881 log_vprint(text, ap);
1886 /* now abort the VM */
1892 /* vm_get_mainclass_from_jar ***************************************************
1894 Gets the name of the main class from a JAR's manifest file.
1896 *******************************************************************************/
1898 static char *vm_get_mainclass_from_jar(char *mainstring)
1901 java_objectheader *o;
1903 java_lang_String *s;
1905 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
1908 throw_main_exception_exit();
1910 /* create JarFile object */
1915 throw_main_exception_exit();
1918 m = class_resolveclassmethod(c,
1920 utf_java_lang_String__void,
1921 class_java_lang_Object,
1925 throw_main_exception_exit();
1927 s = javastring_new_from_ascii(mainstring);
1929 (void) vm_call_method(m, o, s);
1932 throw_main_exception_exit();
1934 /* get manifest object */
1936 m = class_resolveclassmethod(c,
1937 utf_new_char("getManifest"),
1938 utf_new_char("()Ljava/util/jar/Manifest;"),
1939 class_java_lang_Object,
1943 throw_main_exception_exit();
1945 o = vm_call_method(m, o);
1948 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
1953 /* get Main Attributes */
1955 m = class_resolveclassmethod(o->vftbl->class,
1956 utf_new_char("getMainAttributes"),
1957 utf_new_char("()Ljava/util/jar/Attributes;"),
1958 class_java_lang_Object,
1962 throw_main_exception_exit();
1964 o = vm_call_method(m, o);
1967 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
1972 /* get property Main-Class */
1974 m = class_resolveclassmethod(o->vftbl->class,
1975 utf_new_char("getValue"),
1976 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
1977 class_java_lang_Object,
1981 throw_main_exception_exit();
1983 s = javastring_new_from_ascii("Main-Class");
1985 o = vm_call_method(m, o, s);
1988 throw_main_exception_exit();
1990 return javastring_tochar(o);
1994 /* vm_compile_all **************************************************************
1996 Compile all methods found in the bootclasspath.
1998 *******************************************************************************/
2000 #if !defined(NDEBUG)
2001 static void vm_compile_all(void)
2006 classcache_name_entry *nmen;
2007 classcache_class_entry *clsen;
2010 /* create all classes found in the bootclasspath */
2011 /* XXX currently only works with zip/jar's */
2013 loader_load_all_classes();
2015 /* link all classes */
2017 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2018 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2020 for (; nmen; nmen = nmen->hashlink) {
2021 /* iterate over all class entries */
2023 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2024 c = clsen->classobj;
2029 if (!(c->state & CLASS_LINKED)) {
2030 if (!link_class(c)) {
2031 fprintf(stderr, "Error linking: ");
2032 utf_fprint_printable_ascii_classname(stderr, c->name);
2033 fprintf(stderr, "\n");
2035 /* print out exception and cause */
2037 exceptions_print_exception(*exceptionptr);
2039 /* goto next class */
2045 /* compile all class methods */
2047 for (i = 0; i < c->methodscount; i++) {
2048 m = &(c->methods[i]);
2050 if (m->jcode != NULL) {
2051 if (!jit_compile(m)) {
2052 fprintf(stderr, "Error compiling: ");
2053 utf_fprint_printable_ascii_classname(stderr, c->name);
2054 fprintf(stderr, ".");
2055 utf_fprint_printable_ascii(stderr, m->name);
2056 utf_fprint_printable_ascii(stderr, m->descriptor);
2057 fprintf(stderr, "\n");
2059 /* print out exception and cause */
2061 exceptions_print_exception(*exceptionptr);
2069 #endif /* !defined(NDEBUG) */
2072 /* vm_compile_method ***********************************************************
2074 Compile a specific method.
2076 *******************************************************************************/
2078 #if !defined(NDEBUG)
2079 static void vm_compile_method(void)
2083 /* create, load and link the main class */
2085 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
2086 throw_main_exception_exit();
2088 if (!link_class(mainclass))
2089 throw_main_exception_exit();
2091 if (opt_signature != NULL) {
2092 m = class_resolveclassmethod(mainclass,
2093 utf_new_char(opt_method),
2094 utf_new_char(opt_signature),
2099 m = class_resolveclassmethod(mainclass,
2100 utf_new_char(opt_method),
2107 char message[MAXLOGTEXT];
2108 sprintf(message, "%s%s", opt_method,
2109 opt_signature ? opt_signature : "");
2112 new_exception_message(string_java_lang_NoSuchMethodException,
2115 throw_main_exception_exit();
2120 #endif /* !defined(NDEBUG) */
2123 /* vm_vmargs_from_valist *******************************************************
2127 *******************************************************************************/
2129 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2130 vm_arg *vmargs, va_list ap)
2132 typedesc *paramtypes;
2135 paramtypes = m->parseddesc->paramtypes;
2137 /* if method is non-static fill first block and skip `this' pointer */
2142 /* the `this' pointer */
2143 vmargs[0].type = TYPE_ADR;
2144 vmargs[0].data.l = (u8) (ptrint) o;
2150 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2151 switch (paramtypes->decltype) {
2152 /* primitive types */
2153 case PRIMITIVETYPE_BOOLEAN:
2154 case PRIMITIVETYPE_BYTE:
2155 case PRIMITIVETYPE_CHAR:
2156 case PRIMITIVETYPE_SHORT:
2157 case PRIMITIVETYPE_INT:
2158 vmargs[i].type = TYPE_INT;
2159 vmargs[i].data.l = (s8) va_arg(ap, s4);
2162 case PRIMITIVETYPE_LONG:
2163 vmargs[i].type = TYPE_LNG;
2164 vmargs[i].data.l = (s8) va_arg(ap, s8);
2167 case PRIMITIVETYPE_FLOAT:
2168 vmargs[i].type = TYPE_FLT;
2169 #if defined(__ALPHA__)
2170 /* this keeps the assembler function much simpler */
2172 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2174 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2178 case PRIMITIVETYPE_DOUBLE:
2179 vmargs[i].type = TYPE_DBL;
2180 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2184 vmargs[i].type = TYPE_ADR;
2185 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2192 /* vm_vmargs_from_jvalue *******************************************************
2196 *******************************************************************************/
2198 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2199 vm_arg *vmargs, jvalue *args)
2201 typedesc *paramtypes;
2205 paramtypes = m->parseddesc->paramtypes;
2207 /* if method is non-static fill first block and skip `this' pointer */
2212 /* the `this' pointer */
2213 vmargs[0].type = TYPE_ADR;
2214 vmargs[0].data.l = (u8) (ptrint) o;
2220 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2221 switch (paramtypes->decltype) {
2222 /* primitive types */
2223 case PRIMITIVETYPE_BOOLEAN:
2224 case PRIMITIVETYPE_BYTE:
2225 case PRIMITIVETYPE_CHAR:
2226 case PRIMITIVETYPE_SHORT:
2227 case PRIMITIVETYPE_INT:
2228 vmargs[i].type = TYPE_INT;
2229 vmargs[i].data.l = (s8) args[j].i;
2232 case PRIMITIVETYPE_LONG:
2233 vmargs[i].type = TYPE_LNG;
2234 vmargs[i].data.l = (s8) args[j].j;
2237 case PRIMITIVETYPE_FLOAT:
2238 vmargs[i].type = TYPE_FLT;
2239 #if defined(__ALPHA__)
2240 /* this keeps the assembler function much simpler */
2242 vmargs[i].data.d = (jdouble) args[j].f;
2244 vmargs[i].data.f = args[j].f;
2248 case PRIMITIVETYPE_DOUBLE:
2249 vmargs[i].type = TYPE_DBL;
2250 vmargs[i].data.d = args[j].d;
2254 vmargs[i].type = TYPE_ADR;
2255 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2262 /* vm_call_method **************************************************************
2264 Calls a Java method with a variable number of arguments and returns
2267 *******************************************************************************/
2269 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2272 java_objectheader *ro;
2275 ro = vm_call_method_valist(m, o, ap);
2282 /* vm_call_method_valist *******************************************************
2284 Calls a Java method with a variable number of arguments, passed via
2285 a va_list, and returns an address.
2287 *******************************************************************************/
2289 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2294 java_objectheader *ro;
2297 /* mark start of dump memory area */
2299 dumpsize = dump_size();
2301 /* get number of Java method arguments */
2303 vmargscount = m->parseddesc->paramcount;
2305 /* allocate vm_arg array */
2307 vmargs = DMNEW(vm_arg, vmargscount);
2309 /* fill the vm_arg array from a va_list */
2311 vm_vmargs_from_valist(m, o, vmargs, ap);
2313 /* call the Java method */
2315 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2317 /* release dump area */
2319 dump_release(dumpsize);
2325 /* vm_call_method_jvalue *******************************************************
2327 Calls a Java method with a variable number of arguments, passed via
2328 a jvalue array, and returns an address.
2330 *******************************************************************************/
2332 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2337 java_objectheader *ro;
2340 /* mark start of dump memory area */
2342 dumpsize = dump_size();
2344 /* get number of Java method arguments */
2346 vmargscount = m->parseddesc->paramcount;
2348 /* allocate vm_arg array */
2350 vmargs = DMNEW(vm_arg, vmargscount);
2352 /* fill the vm_arg array from a va_list */
2354 vm_vmargs_from_jvalue(m, o, vmargs, args);
2356 /* call the Java method */
2358 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2360 /* release dump area */
2362 dump_release(dumpsize);
2368 /* vm_call_method_vmarg ********************************************************
2370 Calls a Java method with a variable number of arguments, passed via
2371 a vm_arg array, and returns an address.
2373 *******************************************************************************/
2375 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2378 java_objectheader *o;
2380 #if defined(ENABLE_JIT)
2381 # if defined(ENABLE_INTRP)
2383 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2386 o = asm_vm_call_method(m, vmargscount, vmargs);
2388 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2395 /* vm_call_method_int **********************************************************
2397 Calls a Java method with a variable number of arguments and returns
2400 *******************************************************************************/
2402 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2408 i = vm_call_method_int_valist(m, o, ap);
2415 /* vm_call_method_int_valist ***************************************************
2417 Calls a Java method with a variable number of arguments, passed via
2418 a va_list, and returns an integer (s4).
2420 *******************************************************************************/
2422 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2429 /* mark start of dump memory area */
2431 dumpsize = dump_size();
2433 /* get number of Java method arguments */
2435 vmargscount = m->parseddesc->paramcount;
2437 /* allocate vm_arg array */
2439 vmargs = DMNEW(vm_arg, vmargscount);
2441 /* fill the vm_arg array from a va_list */
2443 vm_vmargs_from_valist(m, o, vmargs, ap);
2445 /* call the Java method */
2447 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2449 /* release dump area */
2451 dump_release(dumpsize);
2457 /* vm_call_method_int_jvalue ***************************************************
2459 Calls a Java method with a variable number of arguments, passed via
2460 a jvalue array, and returns an integer (s4).
2462 *******************************************************************************/
2464 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2471 /* mark start of dump memory area */
2473 dumpsize = dump_size();
2475 /* get number of Java method arguments */
2477 vmargscount = m->parseddesc->paramcount;
2479 /* allocate vm_arg array */
2481 vmargs = DMNEW(vm_arg, vmargscount);
2483 /* fill the vm_arg array from a va_list */
2485 vm_vmargs_from_jvalue(m, o, vmargs, args);
2487 /* call the Java method */
2489 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2491 /* release dump area */
2493 dump_release(dumpsize);
2499 /* vm_call_method_int_vmarg ****************************************************
2501 Calls a Java method with a variable number of arguments, passed via
2502 a vm_arg array, and returns an integer (s4).
2504 *******************************************************************************/
2506 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2510 #if defined(ENABLE_JIT)
2511 # if defined(ENABLE_INTRP)
2513 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2516 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2518 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2525 /* vm_call_method_long *********************************************************
2527 Calls a Java method with a variable number of arguments and returns
2530 *******************************************************************************/
2532 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2538 l = vm_call_method_long_valist(m, o, ap);
2545 /* vm_call_method_long_valist **************************************************
2547 Calls a Java method with a variable number of arguments, passed via
2548 a va_list, and returns a long (s8).
2550 *******************************************************************************/
2552 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2559 /* mark start of dump memory area */
2561 dumpsize = dump_size();
2563 /* get number of Java method arguments */
2565 vmargscount = m->parseddesc->paramcount;
2567 /* allocate vm_arg array */
2569 vmargs = DMNEW(vm_arg, vmargscount);
2571 /* fill the vm_arg array from a va_list */
2573 vm_vmargs_from_valist(m, o, vmargs, ap);
2575 /* call the Java method */
2577 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2579 /* release dump area */
2581 dump_release(dumpsize);
2587 /* vm_call_method_long_jvalue **************************************************
2589 Calls a Java method with a variable number of arguments, passed via
2590 a jvalue array, and returns a long (s8).
2592 *******************************************************************************/
2594 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2601 /* mark start of dump memory area */
2603 dumpsize = dump_size();
2605 /* get number of Java method arguments */
2607 vmargscount = m->parseddesc->paramcount;
2609 /* allocate vm_arg array */
2611 vmargs = DMNEW(vm_arg, vmargscount);
2613 /* fill the vm_arg array from a va_list */
2615 vm_vmargs_from_jvalue(m, o, vmargs, args);
2617 /* call the Java method */
2619 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2621 /* release dump area */
2623 dump_release(dumpsize);
2629 /* vm_call_method_long_vmarg ***************************************************
2631 Calls a Java method with a variable number of arguments, passed via
2632 a vm_arg array, and returns a long (s8).
2634 *******************************************************************************/
2636 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2640 #if defined(ENABLE_JIT)
2641 # if defined(ENABLE_INTRP)
2643 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2646 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2648 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2655 /* vm_call_method_float ********************************************************
2657 Calls a Java method with a variable number of arguments and returns
2660 *******************************************************************************/
2662 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2668 f = vm_call_method_float_valist(m, o, ap);
2675 /* vm_call_method_float_valist *************************************************
2677 Calls a Java method with a variable number of arguments, passed via
2678 a va_list, and returns a float.
2680 *******************************************************************************/
2682 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2690 /* mark start of dump memory area */
2692 dumpsize = dump_size();
2694 /* get number of Java method arguments */
2696 vmargscount = m->parseddesc->paramcount;
2698 /* allocate vm_arg array */
2700 vmargs = DMNEW(vm_arg, vmargscount);
2702 /* fill the vm_arg array from a va_list */
2704 vm_vmargs_from_valist(m, o, vmargs, ap);
2706 /* call the Java method */
2708 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2710 /* release dump area */
2712 dump_release(dumpsize);
2718 /* vm_call_method_float_jvalue *************************************************
2720 Calls a Java method with a variable number of arguments, passed via
2721 a jvalue array, and returns a float.
2723 *******************************************************************************/
2725 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2733 /* mark start of dump memory area */
2735 dumpsize = dump_size();
2737 /* get number of Java method arguments */
2739 vmargscount = m->parseddesc->paramcount;
2741 /* allocate vm_arg array */
2743 vmargs = DMNEW(vm_arg, vmargscount);
2745 /* fill the vm_arg array from a va_list */
2747 vm_vmargs_from_jvalue(m, o, vmargs, args);
2749 /* call the Java method */
2751 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2753 /* release dump area */
2755 dump_release(dumpsize);
2761 /* vm_call_method_float_vmarg **************************************************
2763 Calls a Java method with a variable number of arguments and returns
2766 *******************************************************************************/
2768 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2772 #if defined(ENABLE_JIT)
2773 # if defined(ENABLE_INTRP)
2775 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2778 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2780 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2787 /* vm_call_method_double *******************************************************
2789 Calls a Java method with a variable number of arguments and returns
2792 *******************************************************************************/
2794 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2800 d = vm_call_method_double_valist(m, o, ap);
2807 /* vm_call_method_double_valist ************************************************
2809 Calls a Java method with a variable number of arguments, passed via
2810 a va_list, and returns a double.
2812 *******************************************************************************/
2814 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2822 /* mark start of dump memory area */
2824 dumpsize = dump_size();
2826 /* get number of Java method arguments */
2828 vmargscount = m->parseddesc->paramcount;
2830 /* allocate vm_arg array */
2832 vmargs = DMNEW(vm_arg, vmargscount);
2834 /* fill the vm_arg array from a va_list */
2836 vm_vmargs_from_valist(m, o, vmargs, ap);
2838 /* call the Java method */
2840 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2842 /* release dump area */
2844 dump_release(dumpsize);
2850 /* vm_call_method_double_jvalue ************************************************
2852 Calls a Java method with a variable number of arguments, passed via
2853 a jvalue array, and returns a double.
2855 *******************************************************************************/
2857 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2865 /* mark start of dump memory area */
2867 dumpsize = dump_size();
2869 /* get number of Java method arguments */
2871 vmargscount = m->parseddesc->paramcount;
2873 /* allocate vm_arg array */
2875 vmargs = DMNEW(vm_arg, vmargscount);
2877 /* fill the vm_arg array from a va_list */
2879 vm_vmargs_from_jvalue(m, o, vmargs, args);
2881 /* call the Java method */
2883 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2885 /* release dump area */
2887 dump_release(dumpsize);
2893 /* vm_call_method_double_vmarg *************************************************
2895 Calls a Java method with a variable number of arguments and returns
2898 *******************************************************************************/
2900 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
2905 #if defined(ENABLE_JIT)
2906 # if defined(ENABLE_INTRP)
2908 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2911 d = asm_vm_call_method_double(m, vmargscount, vmargs);
2913 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2921 * These are local overrides for various environment variables in Emacs.
2922 * Please do not remove this and leave it at the end of the file, where
2923 * Emacs will automagically detect them.
2924 * ---------------------------------------------------------------------
2927 * indent-tabs-mode: t