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 4357 2006-01-22 23:33:38Z twisti $
36 #if defined(WITH_JRE_LAYOUT)
43 #include "mm/gc-common.h"
44 #include "mm/memory.h"
46 #include "native/jni.h"
47 #include "native/native.h"
48 #include "native/include/java_lang_String.h"
50 #if defined(ENABLE_THREADS)
51 # include "threads/native/threads.h"
54 #include "toolbox/logging.h"
56 #include "vm/builtin.h"
57 #include "vm/exceptions.h"
58 #include "vm/finalizer.h"
59 #include "vm/global.h"
60 #include "vm/initialize.h"
61 #include "vm/properties.h"
62 #include "vm/signallocal.h"
63 #include "vm/stringlocal.h"
66 #include "vm/jit/jit.h"
67 #include "vm/jit/md.h"
68 #include "vm/jit/asmpart.h"
70 #if defined(ENABLE_PROFILING)
71 # include "vm/jit/optimizing/profile.h"
74 #include "vm/jit/optimizing/recompile.h"
76 #include "vmcore/classcache.h"
77 #include "vmcore/options.h"
78 #include "vmcore/suck.h"
80 #if defined(ENABLE_JVMTI)
81 # include "native/jvmti/cacaodbg.h"
85 /* Invocation API variables ***************************************************/
87 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
88 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
91 /* global variables ***********************************************************/
93 s4 vms = 0; /* number of VMs created */
95 bool vm_initializing = false;
96 bool vm_exiting = false;
98 char *cacao_prefix = NULL;
99 char *cacao_libjvm = NULL;
100 char *classpath_libdir = NULL;
102 char *_Jv_bootclasspath; /* contains the boot classpath */
103 char *_Jv_classpath; /* contains the classpath */
104 char *_Jv_java_library_path;
106 char *mainstring = NULL;
107 classinfo *mainclass = NULL;
109 char *specificmethodname = NULL;
110 char *specificsignature = NULL;
114 #if defined(ENABLE_INTRP)
115 u1 *intrp_main_stack = NULL;
119 /* define heap sizes **********************************************************/
121 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
122 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
123 #define STACK_SIZE 64 * 1024 /* default 64kB */
126 /* define command line options ************************************************/
154 /* Java non-standard options */
165 #if defined(ENABLE_PROFILING)
179 #if defined(ENABLE_STATISTICS)
196 #if defined(ENABLE_VERIFIER)
198 #if defined(TYPECHECK_VERBOSE)
201 #endif /* defined(ENABLE_VERIFIER) */
204 /* optimization options */
206 #if defined(ENABLE_LOOP)
210 #if defined(ENABLE_IFCONV)
214 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
218 #if defined(ENABLE_INLINING)
223 #if defined(ENABLE_INLINING_DEBUG)
224 OPT_INLINE_DEBUG_ALL,
225 OPT_INLINE_DEBUG_END,
226 OPT_INLINE_DEBUG_MIN,
227 OPT_INLINE_DEBUG_MAX,
228 OPT_INLINE_REPLACE_VERBOSE,
229 OPT_INLINE_REPLACE_VERBOSE2,
230 #endif /* defined(ENABLE_INLINING_DEBUG) */
231 #endif /* defined(ENABLE_INLINING) */
233 #if defined(ENABLE_INTRP)
234 /* interpreter options */
257 opt_struct opts[] = {
258 { "foo", false, OPT_FOO },
262 { "jar", false, OPT_JAR },
264 { "d32", false, OPT_D32 },
265 { "d64", false, OPT_D64 },
266 { "client", false, OPT_IGNORE },
267 { "server", false, OPT_IGNORE },
268 { "jvm", false, OPT_IGNORE },
269 { "hotspot", false, OPT_IGNORE },
271 { "classpath", true, OPT_CLASSPATH },
272 { "cp", true, OPT_CLASSPATH },
273 { "D", true, OPT_D },
274 { "version", false, OPT_VERSION },
275 { "showversion", false, OPT_SHOWVERSION },
276 { "fullversion", false, OPT_FULLVERSION },
277 { "help", false, OPT_HELP },
278 { "?", false, OPT_HELP },
279 { "X", false, OPT_X },
280 { "XX", false, OPT_XX },
282 { "esa", false, OPT_ESA },
283 { "enablesystemassertions", false, OPT_ESA },
284 { "dsa", false, OPT_DSA },
285 { "disablesystemassertions", false, OPT_DSA },
287 { "noasyncgc", false, OPT_IGNORE },
288 #if defined(ENABLE_VERIFIER)
289 { "noverify", false, OPT_NOVERIFY },
291 { "v", false, OPT_VERBOSE1 },
292 { "verbose:", true, OPT_VERBOSE },
294 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
295 { "verbosetc", false, OPT_VERBOSETC },
297 #if defined(__ALPHA__)
298 { "noieee", false, OPT_NOIEEE },
300 { "softnull", false, OPT_SOFTNULL },
301 #if defined(ENABLE_STATISTICS)
302 { "time", false, OPT_TIME },
303 { "stat", false, OPT_STAT },
305 { "log", true, OPT_LOG },
306 { "c", true, OPT_CHECK },
307 { "l", false, OPT_LOAD },
308 { "eager", false, OPT_EAGER },
311 { "all", false, OPT_ALL },
312 { "sig", true, OPT_SIGNATURE },
315 #if defined(ENABLE_LOOP)
316 { "oloop", false, OPT_OLOOP },
318 #if defined(ENABLE_IFCONV)
319 { "ifconv", false, OPT_IFCONV },
321 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
322 { "lsra", false, OPT_LSRA },
325 #if defined(ENABLE_INTRP)
326 /* interpreter options */
328 { "trace", false, OPT_TRACE },
329 { "static-supers", true, OPT_STATIC_SUPERS },
330 { "no-dynamic", false, OPT_NO_DYNAMIC },
331 { "no-replication", false, OPT_NO_REPLICATION },
332 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
335 /* JVMTI Agent Command Line Options */
337 { "agentlib:", true, OPT_AGENTLIB },
338 { "agentpath:", true, OPT_AGENTPATH },
341 /* Java non-standard options */
343 { "Xjit", false, OPT_JIT },
344 { "Xint", false, OPT_INTRP },
345 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
346 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
347 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
348 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
351 { "Xdebug", false, OPT_DEBUG },
352 { "Xnoagent", false, OPT_NOAGENT },
353 { "Xrunjdwp", true, OPT_XRUNJDWP },
356 { "Xms", true, OPT_MS },
357 { "ms", true, OPT_MS },
358 { "Xmx", true, OPT_MX },
359 { "mx", true, OPT_MX },
360 { "Xss", true, OPT_SS },
361 { "ss", true, OPT_SS },
363 #if defined(ENABLE_PROFILING)
364 { "Xprof:", true, OPT_PROF_OPTION },
365 { "Xprof", false, OPT_PROF },
368 /* inlining options */
370 #if defined(ENABLE_INLINING)
371 #if defined(ENABLE_INLINING_DEBUG)
372 { "ia", false, OPT_INLINE_DEBUG_ALL },
373 { "ii", true, OPT_INLINE_DEBUG_MIN },
374 { "im", true, OPT_INLINE_DEBUG_MAX },
375 { "ie", true, OPT_INLINE_DEBUG_END },
376 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
377 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
378 #endif /* defined(ENABLE_INLINING_DEBUG) */
380 { "il", false, OPT_INLINE_LOG },
382 { "i", false, OPT_INLINING },
383 #endif /* defined(ENABLE_INLINING) */
385 /* keep these at the end of the list */
388 { "m", true, OPT_METHOD },
391 { "s", true, OPT_SHOW },
392 { "debug-color", false, OPT_DEBUGCOLOR },
398 /* usage ***********************************************************************
400 Prints the correct usage syntax to stdout.
402 *******************************************************************************/
406 puts("Usage: cacao [-options] classname [arguments]");
407 puts(" (to run a class file)");
408 puts(" or cacao [-options] -jar jarfile [arguments]");
409 puts(" (to run a standalone jar file)\n");
411 puts("where options include:");
412 puts(" -d32 use 32-bit data model if available");
413 puts(" -d64 use 64-bit data model if available");
414 puts(" -client compatibility (currently ignored)");
415 puts(" -server compatibility (currently ignored)");
416 puts(" -jvm compatibility (currently ignored)");
417 puts(" -hotspot compatibility (currently ignored)\n");
419 puts(" -cp <path> specify a path to look for classes");
420 puts(" -classpath <path> specify a path to look for classes");
421 puts(" -D<name>=<value> add an entry to the property list");
422 puts(" -verbose[:class|gc|jni] enable specific verbose output");
423 puts(" -version print product version and exit");
424 puts(" -fullversion print jpackage-compatible product version and exit");
425 puts(" -showversion print product version and continue");
426 puts(" -help, -? print this help message");
427 puts(" -X print help on non-standard Java options");
428 puts(" -XX print help on CACAO options");
429 puts(" -esa | -enablesystemassertions");
430 puts(" enable system assertions");
431 puts(" -dsa | -disablesystemassertions");
432 puts(" disable system assertions");
435 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
436 puts (" for jdwp help use: -agentlib:jdwp=help");
437 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
440 /* exit with error code */
446 static void Xusage(void)
448 #if defined(ENABLE_JIT)
449 puts(" -Xjit JIT mode execution (default)");
451 #if defined(ENABLE_INTRP)
452 puts(" -Xint interpreter mode execution");
454 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
455 puts(" value is set as bootstrap class path");
456 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
457 puts(" value is appended to the bootstrap class path");
458 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
459 puts(" value is prepended to the bootstrap class path");
460 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
461 puts(" value is used as Java core library, but the");
462 puts(" hardcoded VM interface classes are prepended");
463 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
464 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
465 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
467 #if defined(ENABLE_PROFILING)
468 puts(" -Xprof[:bb] collect and print profiling data");
471 #if defined(ENABLE_JVMTI)
472 /* -Xdebug option depend on gnu classpath JDWP options. options:
473 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
474 puts(" -Xdebug enable remote debugging\n");
475 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
476 puts(" enable remote debugging\n");
479 /* exit with error code */
485 static void XXusage(void)
487 puts(" -v write state-information");
488 puts(" -verbose[:call|exception|jit]");
489 puts(" enable specific verbose output");
490 puts(" -debug-color colored output for ANSI terms");
491 #ifdef TYPECHECK_VERBOSE
492 puts(" -verbosetc write debug messages while typechecking");
494 #if defined(__ALPHA__)
495 puts(" -noieee don't use ieee compliant arithmetic");
497 #if defined(ENABLE_VERIFIER)
498 puts(" -noverify don't verify classfiles");
500 puts(" -softnull use software nullpointer check");
501 #if defined(ENABLE_STATISTICS)
502 puts(" -time measure the runtime");
503 puts(" -stat detailed compiler statistics");
505 puts(" -log logfile specify a name for the logfile");
506 puts(" -c(heck)b(ounds) don't check array bounds");
507 puts(" s(ync) don't check for synchronization");
508 #if defined(ENABLE_LOOP)
509 puts(" -oloop optimize array accesses in loops");
511 puts(" -l don't start the class after loading");
512 puts(" -eager perform eager class loading and linking");
514 puts(" -all compile all methods, no execution");
515 puts(" -m compile only a specific method");
516 puts(" -sig specify signature for a specific method");
519 puts(" -s... show...");
520 puts(" (c)onstants the constant pool");
521 puts(" (m)ethods class fields and methods");
522 puts(" (u)tf the utf - hash");
523 puts(" (i)ntermediate intermediate representation");
524 #if defined(ENABLE_DISASSEMBLER)
525 puts(" (a)ssembler disassembled listing");
526 puts(" n(o)ps show NOPs in disassembler output");
527 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
528 puts(" (n)ative disassembled native stubs");
530 puts(" (d)atasegment data segment listing");
532 #if defined(ENABLE_INLINING)
533 puts(" -i activate inlining");
535 puts(" -il log inlining");
537 #if defined(ENABLE_INLINING_DEBUG)
538 puts(" -ia use inlining for all methods");
539 puts(" -ii <size> set minimum size for inlined result");
540 puts(" -im <size> set maximum size for inlined result");
541 puts(" -ie <number> stop inlining after the given number of roots");
542 puts(" -ir log on-stack replacement");
543 puts(" -iR log on-stack replacement, more verbose");
544 #endif /* defined(ENABLE_INLINING_DEBUG) */
545 #endif /* defined(ENABLE_INLINING) */
547 #if defined(ENABLE_IFCONV)
548 puts(" -ifconv use if-conversion");
550 #if defined(ENABLE_LSRA)
551 puts(" -lsra use linear scan register allocation");
553 #if defined(ENABLE_SSA)
554 puts(" -lsra use linear scan register allocation (with SSA)");
557 /* exit with error code */
563 /* version *********************************************************************
565 Only prints cacao version information.
567 *******************************************************************************/
569 static void version(bool opt_exit)
571 puts("java version \""JAVA_VERSION"\"");
572 puts("CACAO version "VERSION"");
574 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
575 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
576 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
577 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
579 puts("This program is free software; you can redistribute it and/or");
580 puts("modify it under the terms of the GNU General Public License as");
581 puts("published by the Free Software Foundation; either version 2, or (at");
582 puts("your option) any later version.\n");
584 puts("This program is distributed in the hope that it will be useful, but");
585 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
586 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
587 puts("General Public License for more details.\n");
589 puts("Configure/Build options:\n");
590 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
591 #if defined(__VERSION__)
592 puts(" CC : "VERSION_CC" ("__VERSION__")");
594 puts(" CC : "VERSION_CC"");
596 puts(" CFLAGS : "VERSION_CFLAGS"\n");
598 puts("Default variables:\n");
599 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
600 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
601 printf(" stack size : %d\n", STACK_SIZE);
602 #if defined(WITH_CLASSPATH_GNU)
603 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
605 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
607 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
609 puts("Runtime variables:\n");
610 printf(" maximum heap size : %d\n", opt_heapmaxsize);
611 printf(" initial heap size : %d\n", opt_heapstartsize);
612 printf(" stack size : %d\n", opt_stacksize);
613 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
614 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
615 printf(" java.class.path : %s\n", _Jv_classpath);
617 /* exit normally, if requested */
624 /* fullversion *****************************************************************
626 Prints a Sun compatible version information (required e.g. by
627 jpackage, www.jpackage.org).
629 *******************************************************************************/
631 static void fullversion(void)
633 puts("java full version \"cacao-"JAVA_VERSION"\"");
641 /* forward declarations *******************************************************/
643 static char *vm_get_mainclass_from_jar(char *mainstring);
645 static void vm_compile_all(void);
646 static void vm_compile_method(void);
650 /* vm_createjvm ****************************************************************
652 Implementation for JNI_CreateJavaVM.
654 *******************************************************************************/
656 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
658 JavaVMInitArgs *_vm_args;
662 /* get the arguments for the new JVM */
664 _vm_args = (JavaVMInitArgs *) vm_args;
666 /* get the VM and Env tables (must be set before vm_create) */
668 env = NEW(_Jv_JNIEnv);
670 #if defined(ENABLE_JAVASE)
671 env->env = &_Jv_JNINativeInterface;
674 /* XXX Set the global variable. Maybe we should do that differently. */
678 /* create and fill a JavaVM structure */
680 vm = NEW(_Jv_JavaVM);
682 #if defined(ENABLE_JAVASE)
683 vm->functions = &_Jv_JNIInvokeInterface;
686 /* XXX Set the global variable. Maybe we should do that differently. */
687 /* XXX JVMTI Agents needs a JavaVM */
691 /* actually create the JVM */
693 if (!vm_create(_vm_args))
696 #if defined(ENABLE_JAVASE)
697 /* setup the local ref table (must be created after vm_create) */
699 if (!jni_init_localref_table())
703 /* now return the values */
705 *p_vm = (JavaVM *) vm;
706 *p_env = (void *) env;
711 /* release allocated memory */
713 FREE(env, _Jv_JNIEnv);
714 FREE(vm, _Jv_JavaVM);
720 /* vm_create *******************************************************************
722 Creates a JVM. Called by vm_createjvm.
724 *******************************************************************************/
726 bool vm_create(JavaVMInitArgs *vm_args)
735 #if defined(ENABLE_JVMTI)
737 char *libname, *agentarg;
738 bool jdwp,agentbypath;
739 jdwp = agentbypath = false;
742 /* check the JNI version requested */
744 switch (vm_args->version) {
745 case JNI_VERSION_1_1:
747 case JNI_VERSION_1_2:
748 case JNI_VERSION_1_4:
754 /* we only support 1 JVM instance */
759 if (atexit(vm_exit_handler))
760 vm_abort("atexit failed: %s\n", strerror(errno));
763 log_text("CACAO started -------------------------------------------------------");
765 /* set the VM starttime */
767 _Jv_jvm->starttime = builtin_currenttimemillis();
769 /* get stuff from the environment *****************************************/
771 #if defined(WITH_JRE_LAYOUT)
772 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
774 cacao_prefix = MNEW(char, 4096);
776 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
777 vm_abort("readlink failed: %s\n", strerror(errno));
779 /* get the path of the current executable */
781 cacao_prefix = dirname(cacao_prefix);
783 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
784 vm_abort("libjvm name to long for buffer\n");
786 /* concatenate the library name */
788 strcat(cacao_prefix, "/..");
790 /* now set path to libjvm.so */
792 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
794 cacao_libjvm = MNEW(char, len);
795 strcpy(cacao_libjvm, cacao_prefix);
796 strcat(cacao_libjvm, "/lib/libjvm");
798 /* and finally set the path to GNU Classpath libraries */
800 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
802 classpath_libdir = MNEW(char, len);
803 strcpy(classpath_libdir, cacao_prefix);
804 strcat(classpath_libdir, "/lib/classpath");
806 cacao_prefix = CACAO_PREFIX;
807 cacao_libjvm = CACAO_LIBDIR"/libjvm";
808 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
811 /* set the bootclasspath */
813 cp = getenv("BOOTCLASSPATH");
816 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
817 strcpy(_Jv_bootclasspath, cp);
820 #if defined(WITH_JRE_LAYOUT)
822 # if defined(WITH_CLASSPATH_GNU)
823 strlen(cacao_prefix) +
824 strlen("/share/cacao/vm.zip") +
827 strlen(cacao_prefix) +
828 strlen("/share/classpath/glibj.zip") +
831 _Jv_bootclasspath = MNEW(char, len);
832 # if defined(WITH_CLASSPATH_GNU)
833 strcat(_Jv_bootclasspath, cacao_prefix);
834 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
835 strcat(_Jv_bootclasspath, ":");
837 strcat(_Jv_bootclasspath, cacao_prefix);
838 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
841 # if defined(WITH_CLASSPATH_GNU)
842 strlen(CACAO_VM_ZIP) +
845 strlen(CLASSPATH_CLASSES) +
848 _Jv_bootclasspath = MNEW(char, len);
849 # if defined(WITH_CLASSPATH_GNU)
850 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
851 strcat(_Jv_bootclasspath, ":");
853 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
857 /* set the classpath */
859 cp = getenv("CLASSPATH");
862 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
863 strcat(_Jv_classpath, cp);
866 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
867 strcpy(_Jv_classpath, ".");
870 /* get and set java.library.path */
872 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
874 if (_Jv_java_library_path == NULL)
875 _Jv_java_library_path = "";
877 /* interpret the options **************************************************/
885 opt_heapmaxsize = HEAP_MAXSIZE;
886 opt_heapstartsize = HEAP_STARTSIZE;
887 opt_stacksize = STACK_SIZE;
890 #if defined(ENABLE_JVMTI)
891 /* initialize JVMTI related **********************************************/
895 /* initialize and fill properties before command-line handling */
897 if (!properties_init())
898 vm_abort("properties_init failed");
900 /* iterate over all passed options */
902 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
916 #if SIZEOF_VOID_P == 8
917 puts("Running a 32-bit JVM is not supported on this platform.");
923 #if SIZEOF_VOID_P == 4
924 puts("Running a 64-bit JVM is not supported on this platform.");
930 /* forget old classpath and set the argument as new classpath */
931 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
933 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
934 strcpy(_Jv_classpath, opt_arg);
938 for (i = 0; i < strlen(opt_arg); i++) {
939 if (opt_arg[i] == '=') {
941 properties_add(opt_arg, opt_arg + i + 1);
946 /* if no '=' is given, just create an empty property */
948 properties_add(opt_arg, "");
953 case OPT_BOOTCLASSPATH:
954 /* Forget default bootclasspath and set the argument as
955 new boot classpath. */
957 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
959 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
960 strcpy(_Jv_bootclasspath, opt_arg);
963 case OPT_BOOTCLASSPATH_A:
964 /* append to end of bootclasspath */
966 len = strlen(_Jv_bootclasspath);
968 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
972 strlen(opt_arg) + strlen("0"));
974 strcat(_Jv_bootclasspath, ":");
975 strcat(_Jv_bootclasspath, opt_arg);
978 case OPT_BOOTCLASSPATH_P:
979 /* prepend in front of bootclasspath */
981 cp = _Jv_bootclasspath;
984 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
987 strcpy(_Jv_bootclasspath, opt_arg);
988 strcat(_Jv_bootclasspath, ":");
989 strcat(_Jv_bootclasspath, cp);
991 MFREE(cp, char, len);
994 case OPT_BOOTCLASSPATH_C:
995 /* use as Java core library, but prepend VM interface classes */
997 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
999 len = strlen(CACAO_VM_ZIP) +
1004 _Jv_bootclasspath = MNEW(char, len);
1006 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1007 strcat(_Jv_bootclasspath, ":");
1008 strcat(_Jv_bootclasspath, opt_arg);
1011 #if defined(ENABLE_JVMTI)
1013 /* this option exists only for compatibility reasons */
1017 /* I don't know yet what Xnoagent should do. This is only for
1018 compatiblity with eclipse - motse */
1027 strlen(CACAO_LIBDIR) +
1028 strlen("/libjdwp.so=") +
1032 agentarg = MNEW(char, len);
1034 strcpy(agentarg, CACAO_LIBDIR);
1035 strcat(agentarg, "/libjdwp.so=");
1036 strcat(agentarg, &opt_arg[1]);
1053 c = opt_arg[strlen(opt_arg) - 1];
1055 if ((c == 'k') || (c == 'K')) {
1056 j = atoi(opt_arg) * 1024;
1058 } else if ((c == 'm') || (c == 'M')) {
1059 j = atoi(opt_arg) * 1024 * 1024;
1065 opt_heapmaxsize = j;
1066 else if (opt == OPT_MS)
1067 opt_heapstartsize = j;
1078 if (strcmp("class", opt_arg) == 0)
1079 opt_verboseclass = true;
1081 else if (strcmp("gc", opt_arg) == 0)
1082 opt_verbosegc = true;
1084 else if (strcmp("jni", opt_arg) == 0)
1085 opt_verbosejni = true;
1087 else if (strcmp("call", opt_arg) == 0)
1088 opt_verbosecall = true;
1090 else if (strcmp("jit", opt_arg) == 0) {
1095 compileverbose = true;
1097 else if (strcmp("exception", opt_arg) == 0)
1098 opt_verboseexception = true;
1100 case OPT_DEBUGCOLOR:
1101 opt_debugcolor = true;
1104 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1106 opt_typecheckverbose = true;
1115 case OPT_FULLVERSION:
1119 case OPT_SHOWVERSION:
1127 #if defined(ENABLE_VERIFIER)
1137 #if defined(ENABLE_STATISTICS)
1139 opt_getcompilingtime = true;
1140 opt_getloadingtime = true;
1153 for (i = 0; i < strlen(opt_arg); i++) {
1154 switch (opt_arg[i]) {
1156 checkbounds = false;
1169 makeinitializations = false;
1176 #if !defined(NDEBUG)
1180 makeinitializations = false;
1185 opt_method = opt_arg;
1186 makeinitializations = false;
1190 opt_signature = opt_arg;
1194 case OPT_SHOW: /* Display options */
1195 for (i = 0; i < strlen(opt_arg); i++) {
1196 switch (opt_arg[i]) {
1198 showconstantpool = true;
1210 opt_showintermediate = true;
1211 compileverbose = true;
1214 #if defined(ENABLE_DISASSEMBLER)
1216 opt_showdisassemble = true;
1217 compileverbose = true;
1221 opt_shownops = true;
1225 opt_showexceptionstubs = true;
1229 opt_shownativestub = true;
1234 opt_showddatasegment = true;
1243 #if defined(ENABLE_LOOP)
1249 #if defined(ENABLE_INLINING)
1250 #if defined(ENABLE_INLINING_DEBUG)
1251 case OPT_INLINE_DEBUG_ALL:
1252 opt_inline_debug_all = true;
1254 case OPT_INLINE_DEBUG_END:
1255 opt_inline_debug_end_counter = atoi(opt_arg);
1257 case OPT_INLINE_DEBUG_MIN:
1258 opt_inline_debug_min_size = atoi(opt_arg);
1260 case OPT_INLINE_DEBUG_MAX:
1261 opt_inline_debug_max_size = atoi(opt_arg);
1263 case OPT_INLINE_REPLACE_VERBOSE:
1264 opt_replace_verbose = 1;
1266 case OPT_INLINE_REPLACE_VERBOSE2:
1267 opt_replace_verbose = 2;
1269 #endif /* defined(ENABLE_INLINING_DEBUG) */
1270 #if !defined(NDEBUG)
1271 case OPT_INLINE_LOG:
1272 opt_inline_debug_log = true;
1274 #endif /* !defined(NDEBUG) */
1277 opt_inlining = true;
1279 #endif /* defined(ENABLE_INLINING) */
1281 #if defined(ENABLE_IFCONV)
1287 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1306 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1310 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1313 #if defined(ENABLE_PROFILING)
1314 case OPT_PROF_OPTION:
1315 /* use <= to get the last \0 too */
1317 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1318 if (opt_arg[i] == ',')
1321 if (opt_arg[i] == '\0') {
1322 if (strcmp("bb", opt_arg + j) == 0)
1326 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1330 /* set k to next char */
1343 #if defined(ENABLE_JIT)
1346 printf("-Xjit option not enabled.\n");
1352 #if defined(ENABLE_INTRP)
1355 printf("-Xint option not enabled.\n");
1360 #if defined(ENABLE_INTRP)
1361 case OPT_STATIC_SUPERS:
1362 opt_static_supers = atoi(opt_arg);
1365 case OPT_NO_DYNAMIC:
1366 opt_no_dynamic = true;
1369 case OPT_NO_REPLICATION:
1370 opt_no_replication = true;
1373 case OPT_NO_QUICKSUPER:
1374 opt_no_quicksuper = true;
1383 printf("Unknown option: %s\n",
1384 vm_args->options[opt_index].optionString);
1389 /* get the main class *****************************************************/
1391 if (opt_index < vm_args->nOptions) {
1392 mainstring = vm_args->options[opt_index++].optionString;
1394 /* Put the jar file into the classpath (if any). */
1396 if (opt_jar == true) {
1397 /* free old classpath */
1399 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1401 /* put jarfile into classpath */
1403 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1405 strcpy(_Jv_classpath, mainstring);
1408 /* replace .'s with /'s in classname */
1410 for (i = strlen(mainstring) - 1; i >= 0; i--)
1411 if (mainstring[i] == '.')
1412 mainstring[i] = '/';
1416 #if defined(ENABLE_JVMTI)
1418 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1419 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1422 MFREE(agentarg, char, strlen(agentarg));
1424 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1428 /* Now re-set some of the properties that may have changed. This
1429 must be done after _all_ environment variables have been
1430 processes (e.g. -jar handling). */
1432 if (!properties_postinit())
1433 vm_abort("properties_postinit failed");
1435 /* Now we have all options handled and we can print the version
1441 /* initialize this JVM ****************************************************/
1443 vm_initializing = true;
1445 #if defined(ENABLE_THREADS)
1446 /* pre-initialize some core thread stuff, like the stopworldlock,
1447 thus this has to happen _before_ gc_init()!!! */
1452 /* initialize the garbage collector */
1454 gc_init(opt_heapmaxsize, opt_heapstartsize);
1456 #if defined(ENABLE_INTRP)
1457 /* Allocate main thread stack on the Java heap. */
1460 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1461 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1465 /* initialize the string hashtable stuff: lock (must be done
1466 _after_ threads_preinit) */
1469 throw_main_exception_exit();
1471 /* initialize the utf8 hashtable stuff: lock, often used utf8
1472 strings (must be done _after_ threads_preinit) */
1475 throw_main_exception_exit();
1477 /* initialize the classcache hashtable stuff: lock, hashtable
1478 (must be done _after_ threads_preinit) */
1480 if (!classcache_init())
1481 throw_main_exception_exit();
1483 /* initialize the loader with bootclasspath (must be done _after_
1487 throw_main_exception_exit();
1489 suck_add_from_property("java.endorsed.dirs");
1490 suck_add(_Jv_bootclasspath);
1492 /* initialize the memory subsystem (must be done _after_
1496 throw_main_exception_exit();
1498 /* initialize the finalizer stuff (must be done _after_
1501 if (!finalizer_init())
1502 throw_main_exception_exit();
1504 /* install architecture dependent signal handlers */
1508 /* initialize the codegen subsystems */
1512 /* initializes jit compiler */
1516 /* machine dependent initialization */
1518 #if defined(ENABLE_JIT)
1519 # if defined(ENABLE_INTRP)
1529 /* initialize the loader subsystems (must be done _after_
1533 vm_abort("loader_init failed");
1536 vm_abort("linker_init failed");
1539 throw_main_exception_exit();
1541 if (!exceptions_init())
1542 throw_main_exception_exit();
1544 if (!builtin_init())
1545 throw_main_exception_exit();
1547 #if defined(ENABLE_JAVASE)
1548 /* Initialize the JNI subsystem (must be done _before_
1549 threads_init, as threads_init can call JNI methods
1550 (e.g. NewGlobalRef). */
1553 throw_main_exception_exit();
1556 #if defined(ENABLE_THREADS)
1557 if (!threads_init())
1558 throw_main_exception_exit();
1561 #if defined(ENABLE_PROFILING)
1562 /* initialize profiling */
1564 if (!profile_init())
1565 throw_main_exception_exit();
1568 #if defined(ENABLE_THREADS)
1569 /* initialize recompilation */
1571 if (!recompile_init())
1572 throw_main_exception_exit();
1574 /* start the signal handler thread */
1576 /* if (!signal_start_thread()) */
1577 /* throw_main_exception_exit(); */
1579 /* finally, start the finalizer thread */
1581 if (!finalizer_start_thread())
1582 throw_main_exception_exit();
1584 /* start the recompilation thread (must be done before the
1585 profiling thread) */
1587 if (!recompile_start_thread())
1588 throw_main_exception_exit();
1590 # if defined(ENABLE_PROFILING)
1591 /* start the profile sampling thread */
1594 /* if (!profile_start_thread()) */
1595 /* throw_main_exception_exit(); */
1599 #if defined(ENABLE_JVMTI)
1601 /* add agent library to native library hashtable */
1602 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1606 /* increment the number of VMs */
1610 /* initialization is done */
1612 vm_initializing = false;
1614 /* everything's ok */
1620 /* vm_run **********************************************************************
1622 Runs the main-method of the passed class.
1624 *******************************************************************************/
1626 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1629 classinfo *mainclass;
1631 java_objectarray *oa;
1634 java_objectheader *s;
1638 #if !defined(NDEBUG)
1644 if (opt_method != NULL) {
1645 vm_compile_method();
1648 #endif /* !defined(NDEBUG) */
1650 /* should we run the main-method? */
1652 if (mainstring == NULL)
1655 /* set return value to OK */
1659 if (opt_jar == true)
1660 /* open jar file with java.util.jar.JarFile */
1661 mainstring = vm_get_mainclass_from_jar(mainstring);
1663 /* load the main class */
1665 mainutf = utf_new_char(mainstring);
1667 #if defined(ENABLE_JAVAME_CLDC1_1)
1668 mainclass = load_class_bootstrap(mainutf);
1670 mainclass = load_class_from_sysloader(mainutf);
1673 /* error loading class */
1675 if ((exceptions_get_exception() != NULL) || (mainclass == NULL))
1676 throw_main_exception_exit();
1678 if (!link_class(mainclass))
1679 throw_main_exception_exit();
1681 /* find the `main' method of the main class */
1683 m = class_resolveclassmethod(mainclass,
1684 utf_new_char("main"),
1685 utf_new_char("([Ljava/lang/String;)V"),
1686 class_java_lang_Object,
1689 if (*exceptionptr) {
1690 throw_main_exception_exit();
1693 /* there is no main method or it isn't static */
1695 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1696 exceptions_clear_exception();
1697 exceptions_throw_nosuchmethoderror(mainclass,
1698 utf_new_char("main"),
1699 utf_new_char("([Ljava/lang/String;)V"));
1701 throw_main_exception_exit();
1704 /* build argument array */
1706 oalength = vm_args->nOptions - opt_index;
1708 oa = builtin_anewarray(oalength, class_java_lang_String);
1710 for (i = 0; i < oalength; i++) {
1711 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1712 s = javastring_new(u);
1717 #ifdef TYPEINFO_DEBUG_TEST
1718 /* test the typeinfo system */
1721 /*class_showmethods(currentThread->group->header.vftbl->class); */
1723 #if defined(ENABLE_JVMTI)
1724 jvmti_set_phase(JVMTI_PHASE_LIVE);
1727 /* set ThreadMXBean variables */
1729 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1730 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1732 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1733 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1734 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1735 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1737 /* start the main thread */
1739 (void) vm_call_method(m, NULL, oa);
1741 /* exception occurred? */
1743 if (*exceptionptr) {
1744 throw_main_exception();
1748 /* unload the JavaVM */
1758 /* vm_destroy ******************************************************************
1760 Unloads a Java VM and reclaims its resources.
1762 *******************************************************************************/
1764 s4 vm_destroy(JavaVM *vm)
1766 #if defined(ENABLE_THREADS)
1767 threads_join_all_threads();
1770 /* everything's ok */
1776 /* vm_exit *********************************************************************
1778 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1780 *******************************************************************************/
1782 void vm_exit(s4 status)
1786 /* signal that we are exiting */
1790 assert(class_java_lang_System);
1791 assert(class_java_lang_System->state & CLASS_LOADED);
1793 #if defined(ENABLE_JVMTI)
1794 if (jvmti || (dbgcom!=NULL)) {
1795 jvmti_set_phase(JVMTI_PHASE_DEAD);
1796 if (jvmti) jvmti_agentunload();
1800 if (!link_class(class_java_lang_System))
1801 throw_main_exception_exit();
1803 /* call java.lang.System.exit(I)V */
1805 m = class_resolveclassmethod(class_java_lang_System,
1806 utf_new_char("exit"),
1808 class_java_lang_Object,
1812 throw_main_exception_exit();
1814 /* call the exit function with passed exit status */
1816 (void) vm_call_method(m, NULL, status);
1818 /* If we had an exception, just ignore the exception and exit with
1821 vm_shutdown(status);
1825 /* vm_shutdown *****************************************************************
1827 Terminates the system immediately without freeing memory explicitly
1828 (to be used only for abnormal termination).
1830 *******************************************************************************/
1832 void vm_shutdown(s4 status)
1835 #if defined(ENABLE_STATISTICS)
1836 || opt_getcompilingtime || opt_stat
1840 log_text("CACAO terminated by shutdown");
1841 dolog("Exit status: %d\n", (s4) status);
1845 #if defined(ENABLE_JVMTI)
1846 /* terminate cacaodbgserver */
1848 pthread_mutex_lock(&dbgcomlock);
1850 pthread_mutex_unlock(&dbgcomlock);
1851 jvmti_cacaodbgserver_quit();
1859 /* vm_exit_handler *************************************************************
1861 The exit_handler function is called upon program termination.
1863 ATTENTION: Don't free system resources here! Some threads may still
1864 be running as this is called from VMRuntime.exit(). The OS does the
1867 *******************************************************************************/
1869 void vm_exit_handler(void)
1871 #if !defined(NDEBUG)
1873 class_showmethods(mainclass);
1875 if (showconstantpool)
1876 class_showconstantpool(mainclass);
1881 # if defined(ENABLE_PROFILING)
1883 profile_printstats();
1885 #endif /* !defined(NDEBUG) */
1887 #if defined(ENABLE_RT_TIMING)
1888 rt_timing_print_time_stats(stderr);
1891 #if defined(ENABLE_CYCLES_STATS)
1892 builtin_print_cycles_stats(stderr);
1893 stacktrace_print_cycles_stats(stderr);
1897 #if defined(ENABLE_STATISTICS)
1898 || opt_getcompilingtime || opt_stat
1902 log_text("CACAO terminated");
1904 #if defined(ENABLE_STATISTICS)
1907 #ifdef TYPECHECK_STATISTICS
1908 typecheck_print_statistics(get_logfile());
1912 if (opt_getcompilingtime)
1914 #endif /* defined(ENABLE_STATISTICS) */
1916 /* vm_print_profile(stderr);*/
1920 /* vm_abort ********************************************************************
1922 Prints an error message and aborts the VM.
1924 *******************************************************************************/
1926 void vm_abort(const char *text, ...)
1930 /* print the log message */
1935 log_vprint(text, ap);
1940 /* now abort the VM */
1946 /* vm_get_mainclass_from_jar ***************************************************
1948 Gets the name of the main class from a JAR's manifest file.
1950 *******************************************************************************/
1952 static char *vm_get_mainclass_from_jar(char *mainstring)
1955 java_objectheader *o;
1957 java_lang_String *s;
1959 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
1962 throw_main_exception_exit();
1964 /* create JarFile object */
1969 throw_main_exception_exit();
1972 m = class_resolveclassmethod(c,
1974 utf_java_lang_String__void,
1975 class_java_lang_Object,
1979 throw_main_exception_exit();
1981 s = javastring_new_from_ascii(mainstring);
1983 (void) vm_call_method(m, o, s);
1986 throw_main_exception_exit();
1988 /* get manifest object */
1990 m = class_resolveclassmethod(c,
1991 utf_new_char("getManifest"),
1992 utf_new_char("()Ljava/util/jar/Manifest;"),
1993 class_java_lang_Object,
1997 throw_main_exception_exit();
1999 o = vm_call_method(m, o);
2002 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2007 /* get Main Attributes */
2009 m = class_resolveclassmethod(o->vftbl->class,
2010 utf_new_char("getMainAttributes"),
2011 utf_new_char("()Ljava/util/jar/Attributes;"),
2012 class_java_lang_Object,
2016 throw_main_exception_exit();
2018 o = vm_call_method(m, o);
2021 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2026 /* get property Main-Class */
2028 m = class_resolveclassmethod(o->vftbl->class,
2029 utf_new_char("getValue"),
2030 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2031 class_java_lang_Object,
2035 throw_main_exception_exit();
2037 s = javastring_new_from_ascii("Main-Class");
2039 o = vm_call_method(m, o, s);
2042 throw_main_exception_exit();
2044 return javastring_tochar(o);
2048 /* vm_compile_all **************************************************************
2050 Compile all methods found in the bootclasspath.
2052 *******************************************************************************/
2054 #if !defined(NDEBUG)
2055 static void vm_compile_all(void)
2060 classcache_name_entry *nmen;
2061 classcache_class_entry *clsen;
2064 /* create all classes found in the bootclasspath */
2065 /* XXX currently only works with zip/jar's */
2067 loader_load_all_classes();
2069 /* link all classes */
2071 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2072 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2074 for (; nmen; nmen = nmen->hashlink) {
2075 /* iterate over all class entries */
2077 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2078 c = clsen->classobj;
2083 if (!(c->state & CLASS_LINKED)) {
2084 if (!link_class(c)) {
2085 fprintf(stderr, "Error linking: ");
2086 utf_fprint_printable_ascii_classname(stderr, c->name);
2087 fprintf(stderr, "\n");
2089 /* print out exception and cause */
2091 exceptions_print_current_exception();
2093 /* goto next class */
2099 /* compile all class methods */
2101 for (i = 0; i < c->methodscount; i++) {
2102 m = &(c->methods[i]);
2104 if (m->jcode != NULL) {
2105 if (!jit_compile(m)) {
2106 fprintf(stderr, "Error compiling: ");
2107 utf_fprint_printable_ascii_classname(stderr, c->name);
2108 fprintf(stderr, ".");
2109 utf_fprint_printable_ascii(stderr, m->name);
2110 utf_fprint_printable_ascii(stderr, m->descriptor);
2111 fprintf(stderr, "\n");
2113 /* print out exception and cause */
2115 exceptions_print_current_exception();
2123 #endif /* !defined(NDEBUG) */
2126 /* vm_compile_method ***********************************************************
2128 Compile a specific method.
2130 *******************************************************************************/
2132 #if !defined(NDEBUG)
2133 static void vm_compile_method(void)
2137 /* create, load and link the main class */
2139 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
2140 throw_main_exception_exit();
2142 if (!link_class(mainclass))
2143 throw_main_exception_exit();
2145 if (opt_signature != NULL) {
2146 m = class_resolveclassmethod(mainclass,
2147 utf_new_char(opt_method),
2148 utf_new_char(opt_signature),
2153 m = class_resolveclassmethod(mainclass,
2154 utf_new_char(opt_method),
2161 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2162 opt_method, opt_signature ? opt_signature : "");
2166 #endif /* !defined(NDEBUG) */
2169 /* vm_vmargs_from_valist *******************************************************
2173 *******************************************************************************/
2175 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2176 vm_arg *vmargs, va_list ap)
2178 typedesc *paramtypes;
2181 paramtypes = m->parseddesc->paramtypes;
2183 /* if method is non-static fill first block and skip `this' pointer */
2188 /* the `this' pointer */
2189 vmargs[0].type = TYPE_ADR;
2190 vmargs[0].data.l = (u8) (ptrint) o;
2196 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2197 switch (paramtypes->decltype) {
2198 /* primitive types */
2199 case PRIMITIVETYPE_BOOLEAN:
2200 case PRIMITIVETYPE_BYTE:
2201 case PRIMITIVETYPE_CHAR:
2202 case PRIMITIVETYPE_SHORT:
2203 case PRIMITIVETYPE_INT:
2204 vmargs[i].type = TYPE_INT;
2205 vmargs[i].data.l = (s8) va_arg(ap, s4);
2208 case PRIMITIVETYPE_LONG:
2209 vmargs[i].type = TYPE_LNG;
2210 vmargs[i].data.l = (s8) va_arg(ap, s8);
2213 case PRIMITIVETYPE_FLOAT:
2214 vmargs[i].type = TYPE_FLT;
2215 #if defined(__ALPHA__)
2216 /* this keeps the assembler function much simpler */
2218 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2220 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2224 case PRIMITIVETYPE_DOUBLE:
2225 vmargs[i].type = TYPE_DBL;
2226 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2230 vmargs[i].type = TYPE_ADR;
2231 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2238 /* vm_vmargs_from_jvalue *******************************************************
2242 *******************************************************************************/
2244 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2245 vm_arg *vmargs, jvalue *args)
2247 typedesc *paramtypes;
2251 paramtypes = m->parseddesc->paramtypes;
2253 /* if method is non-static fill first block and skip `this' pointer */
2258 /* the `this' pointer */
2259 vmargs[0].type = TYPE_ADR;
2260 vmargs[0].data.l = (u8) (ptrint) o;
2266 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2267 switch (paramtypes->decltype) {
2268 /* primitive types */
2269 case PRIMITIVETYPE_BOOLEAN:
2270 case PRIMITIVETYPE_BYTE:
2271 case PRIMITIVETYPE_CHAR:
2272 case PRIMITIVETYPE_SHORT:
2273 case PRIMITIVETYPE_INT:
2274 vmargs[i].type = TYPE_INT;
2275 vmargs[i].data.l = (s8) args[j].i;
2278 case PRIMITIVETYPE_LONG:
2279 vmargs[i].type = TYPE_LNG;
2280 vmargs[i].data.l = (s8) args[j].j;
2283 case PRIMITIVETYPE_FLOAT:
2284 vmargs[i].type = TYPE_FLT;
2285 #if defined(__ALPHA__)
2286 /* this keeps the assembler function much simpler */
2288 vmargs[i].data.d = (jdouble) args[j].f;
2290 vmargs[i].data.f = args[j].f;
2294 case PRIMITIVETYPE_DOUBLE:
2295 vmargs[i].type = TYPE_DBL;
2296 vmargs[i].data.d = args[j].d;
2300 vmargs[i].type = TYPE_ADR;
2301 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2308 /* vm_call_method **************************************************************
2310 Calls a Java method with a variable number of arguments and returns
2313 *******************************************************************************/
2315 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2318 java_objectheader *ro;
2321 ro = vm_call_method_valist(m, o, ap);
2328 /* vm_call_method_valist *******************************************************
2330 Calls a Java method with a variable number of arguments, passed via
2331 a va_list, and returns an address.
2333 *******************************************************************************/
2335 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2340 java_objectheader *ro;
2343 /* mark start of dump memory area */
2345 dumpsize = dump_size();
2347 /* get number of Java method arguments */
2349 vmargscount = m->parseddesc->paramcount;
2351 /* allocate vm_arg array */
2353 vmargs = DMNEW(vm_arg, vmargscount);
2355 /* fill the vm_arg array from a va_list */
2357 vm_vmargs_from_valist(m, o, vmargs, ap);
2359 /* call the Java method */
2361 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2363 /* release dump area */
2365 dump_release(dumpsize);
2371 /* vm_call_method_jvalue *******************************************************
2373 Calls a Java method with a variable number of arguments, passed via
2374 a jvalue array, and returns an address.
2376 *******************************************************************************/
2378 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2383 java_objectheader *ro;
2386 /* mark start of dump memory area */
2388 dumpsize = dump_size();
2390 /* get number of Java method arguments */
2392 vmargscount = m->parseddesc->paramcount;
2394 /* allocate vm_arg array */
2396 vmargs = DMNEW(vm_arg, vmargscount);
2398 /* fill the vm_arg array from a va_list */
2400 vm_vmargs_from_jvalue(m, o, vmargs, args);
2402 /* call the Java method */
2404 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2406 /* release dump area */
2408 dump_release(dumpsize);
2414 /* vm_call_method_vmarg ********************************************************
2416 Calls a Java method with a variable number of arguments, passed via
2417 a vm_arg array, and returns an address.
2419 *******************************************************************************/
2421 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2424 java_objectheader *o;
2426 #if defined(ENABLE_JIT)
2427 # if defined(ENABLE_INTRP)
2429 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2432 o = asm_vm_call_method(m, vmargscount, vmargs);
2434 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2441 /* vm_call_method_int **********************************************************
2443 Calls a Java method with a variable number of arguments and returns
2446 *******************************************************************************/
2448 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2454 i = vm_call_method_int_valist(m, o, ap);
2461 /* vm_call_method_int_valist ***************************************************
2463 Calls a Java method with a variable number of arguments, passed via
2464 a va_list, and returns an integer (s4).
2466 *******************************************************************************/
2468 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2475 /* mark start of dump memory area */
2477 dumpsize = dump_size();
2479 /* get number of Java method arguments */
2481 vmargscount = m->parseddesc->paramcount;
2483 /* allocate vm_arg array */
2485 vmargs = DMNEW(vm_arg, vmargscount);
2487 /* fill the vm_arg array from a va_list */
2489 vm_vmargs_from_valist(m, o, vmargs, ap);
2491 /* call the Java method */
2493 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2495 /* release dump area */
2497 dump_release(dumpsize);
2503 /* vm_call_method_int_jvalue ***************************************************
2505 Calls a Java method with a variable number of arguments, passed via
2506 a jvalue array, and returns an integer (s4).
2508 *******************************************************************************/
2510 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2517 /* mark start of dump memory area */
2519 dumpsize = dump_size();
2521 /* get number of Java method arguments */
2523 vmargscount = m->parseddesc->paramcount;
2525 /* allocate vm_arg array */
2527 vmargs = DMNEW(vm_arg, vmargscount);
2529 /* fill the vm_arg array from a va_list */
2531 vm_vmargs_from_jvalue(m, o, vmargs, args);
2533 /* call the Java method */
2535 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2537 /* release dump area */
2539 dump_release(dumpsize);
2545 /* vm_call_method_int_vmarg ****************************************************
2547 Calls a Java method with a variable number of arguments, passed via
2548 a vm_arg array, and returns an integer (s4).
2550 *******************************************************************************/
2552 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2556 #if defined(ENABLE_JIT)
2557 # if defined(ENABLE_INTRP)
2559 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2562 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2564 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2571 /* vm_call_method_long *********************************************************
2573 Calls a Java method with a variable number of arguments and returns
2576 *******************************************************************************/
2578 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2584 l = vm_call_method_long_valist(m, o, ap);
2591 /* vm_call_method_long_valist **************************************************
2593 Calls a Java method with a variable number of arguments, passed via
2594 a va_list, and returns a long (s8).
2596 *******************************************************************************/
2598 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2605 /* mark start of dump memory area */
2607 dumpsize = dump_size();
2609 /* get number of Java method arguments */
2611 vmargscount = m->parseddesc->paramcount;
2613 /* allocate vm_arg array */
2615 vmargs = DMNEW(vm_arg, vmargscount);
2617 /* fill the vm_arg array from a va_list */
2619 vm_vmargs_from_valist(m, o, vmargs, ap);
2621 /* call the Java method */
2623 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2625 /* release dump area */
2627 dump_release(dumpsize);
2633 /* vm_call_method_long_jvalue **************************************************
2635 Calls a Java method with a variable number of arguments, passed via
2636 a jvalue array, and returns a long (s8).
2638 *******************************************************************************/
2640 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2647 /* mark start of dump memory area */
2649 dumpsize = dump_size();
2651 /* get number of Java method arguments */
2653 vmargscount = m->parseddesc->paramcount;
2655 /* allocate vm_arg array */
2657 vmargs = DMNEW(vm_arg, vmargscount);
2659 /* fill the vm_arg array from a va_list */
2661 vm_vmargs_from_jvalue(m, o, vmargs, args);
2663 /* call the Java method */
2665 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2667 /* release dump area */
2669 dump_release(dumpsize);
2675 /* vm_call_method_long_vmarg ***************************************************
2677 Calls a Java method with a variable number of arguments, passed via
2678 a vm_arg array, and returns a long (s8).
2680 *******************************************************************************/
2682 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2686 #if defined(ENABLE_JIT)
2687 # if defined(ENABLE_INTRP)
2689 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2692 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2694 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2701 /* vm_call_method_float ********************************************************
2703 Calls a Java method with a variable number of arguments and returns
2706 *******************************************************************************/
2708 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2714 f = vm_call_method_float_valist(m, o, ap);
2721 /* vm_call_method_float_valist *************************************************
2723 Calls a Java method with a variable number of arguments, passed via
2724 a va_list, and returns a float.
2726 *******************************************************************************/
2728 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2736 /* mark start of dump memory area */
2738 dumpsize = dump_size();
2740 /* get number of Java method arguments */
2742 vmargscount = m->parseddesc->paramcount;
2744 /* allocate vm_arg array */
2746 vmargs = DMNEW(vm_arg, vmargscount);
2748 /* fill the vm_arg array from a va_list */
2750 vm_vmargs_from_valist(m, o, vmargs, ap);
2752 /* call the Java method */
2754 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2756 /* release dump area */
2758 dump_release(dumpsize);
2764 /* vm_call_method_float_jvalue *************************************************
2766 Calls a Java method with a variable number of arguments, passed via
2767 a jvalue array, and returns a float.
2769 *******************************************************************************/
2771 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2779 /* mark start of dump memory area */
2781 dumpsize = dump_size();
2783 /* get number of Java method arguments */
2785 vmargscount = m->parseddesc->paramcount;
2787 /* allocate vm_arg array */
2789 vmargs = DMNEW(vm_arg, vmargscount);
2791 /* fill the vm_arg array from a va_list */
2793 vm_vmargs_from_jvalue(m, o, vmargs, args);
2795 /* call the Java method */
2797 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2799 /* release dump area */
2801 dump_release(dumpsize);
2807 /* vm_call_method_float_vmarg **************************************************
2809 Calls a Java method with a variable number of arguments and returns
2812 *******************************************************************************/
2814 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2818 #if defined(ENABLE_JIT)
2819 # if defined(ENABLE_INTRP)
2821 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2824 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2826 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2833 /* vm_call_method_double *******************************************************
2835 Calls a Java method with a variable number of arguments and returns
2838 *******************************************************************************/
2840 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2846 d = vm_call_method_double_valist(m, o, ap);
2853 /* vm_call_method_double_valist ************************************************
2855 Calls a Java method with a variable number of arguments, passed via
2856 a va_list, and returns a double.
2858 *******************************************************************************/
2860 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2868 /* mark start of dump memory area */
2870 dumpsize = dump_size();
2872 /* get number of Java method arguments */
2874 vmargscount = m->parseddesc->paramcount;
2876 /* allocate vm_arg array */
2878 vmargs = DMNEW(vm_arg, vmargscount);
2880 /* fill the vm_arg array from a va_list */
2882 vm_vmargs_from_valist(m, o, vmargs, ap);
2884 /* call the Java method */
2886 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2888 /* release dump area */
2890 dump_release(dumpsize);
2896 /* vm_call_method_double_jvalue ************************************************
2898 Calls a Java method with a variable number of arguments, passed via
2899 a jvalue array, and returns a double.
2901 *******************************************************************************/
2903 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2911 /* mark start of dump memory area */
2913 dumpsize = dump_size();
2915 /* get number of Java method arguments */
2917 vmargscount = m->parseddesc->paramcount;
2919 /* allocate vm_arg array */
2921 vmargs = DMNEW(vm_arg, vmargscount);
2923 /* fill the vm_arg array from a va_list */
2925 vm_vmargs_from_jvalue(m, o, vmargs, args);
2927 /* call the Java method */
2929 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2931 /* release dump area */
2933 dump_release(dumpsize);
2939 /* vm_call_method_double_vmarg *************************************************
2941 Calls a Java method with a variable number of arguments and returns
2944 *******************************************************************************/
2946 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
2951 #if defined(ENABLE_JIT)
2952 # if defined(ENABLE_INTRP)
2954 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2957 d = asm_vm_call_method_double(m, vmargscount, vmargs);
2959 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2967 * These are local overrides for various environment variables in Emacs.
2968 * Please do not remove this and leave it at the end of the file, where
2969 * Emacs will automagically detect them.
2970 * ---------------------------------------------------------------------
2973 * indent-tabs-mode: t