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"
45 #include "native/jni.h"
46 #include "native/native.h"
48 #if defined(ENABLE_THREADS)
49 # include "threads/native/threads.h"
52 #include "vm/classcache.h"
53 #include "vm/exceptions.h"
54 #include "vm/finalizer.h"
55 #include "vm/global.h"
56 #include "vm/initialize.h"
57 #include "vm/options.h"
58 #include "vm/properties.h"
59 #include "vm/rt-timing.h"
60 #include "vm/signallocal.h"
61 #include "vm/stringlocal.h"
64 #include "vm/jit/jit.h"
65 #include "vm/jit/asmpart.h"
67 #if defined(ENABLE_PROFILING)
68 # include "vm/jit/optimizing/profile.h"
71 #include "vm/jit/optimizing/recompile.h"
73 #if defined(ENABLE_JVMTI)
74 # include "native/jvmti/cacaodbg.h"
78 /* Invocation API variables ***************************************************/
80 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
81 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
84 /* global variables ***********************************************************/
86 s4 vms = 0; /* number of VMs created */
88 bool vm_initializing = false;
89 bool vm_exiting = false;
91 char *cacao_prefix = NULL;
92 char *cacao_libjvm = NULL;
93 char *classpath_libdir = NULL;
95 char *_Jv_bootclasspath; /* contains the boot classpath */
96 char *_Jv_classpath; /* contains the classpath */
97 char *_Jv_java_library_path;
99 char *mainstring = NULL;
100 classinfo *mainclass = NULL;
102 char *specificmethodname = NULL;
103 char *specificsignature = NULL;
107 #if defined(ENABLE_INTRP)
108 u1 *intrp_main_stack = NULL;
112 /* define heap sizes **********************************************************/
114 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
115 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
116 #define STACK_SIZE 64 * 1024 /* default 64kB */
119 /* define command line options ************************************************/
147 /* Java non-standard options */
158 #if defined(ENABLE_PROFILING)
172 #if defined(ENABLE_STATISTICS)
189 #if defined(ENABLE_VERIFIER)
191 #if defined(TYPECHECK_VERBOSE)
194 #endif /* defined(ENABLE_VERIFIER) */
197 /* optimization options */
199 #if defined(ENABLE_LOOP)
203 #if defined(ENABLE_IFCONV)
207 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
211 #if defined(ENABLE_INLINING)
216 #if defined(ENABLE_INLINING_DEBUG)
217 OPT_INLINE_DEBUG_ALL,
218 OPT_INLINE_DEBUG_END,
219 OPT_INLINE_DEBUG_MIN,
220 OPT_INLINE_DEBUG_MAX,
221 OPT_INLINE_REPLACE_VERBOSE,
222 OPT_INLINE_REPLACE_VERBOSE2,
223 #endif /* defined(ENABLE_INLINING_DEBUG) */
224 #endif /* defined(ENABLE_INLINING) */
226 #if defined(ENABLE_INTRP)
227 /* interpreter options */
250 opt_struct opts[] = {
251 { "foo", false, OPT_FOO },
255 { "jar", false, OPT_JAR },
257 { "d32", false, OPT_D32 },
258 { "d64", false, OPT_D64 },
259 { "client", false, OPT_IGNORE },
260 { "server", false, OPT_IGNORE },
261 { "jvm", false, OPT_IGNORE },
262 { "hotspot", false, OPT_IGNORE },
264 { "classpath", true, OPT_CLASSPATH },
265 { "cp", true, OPT_CLASSPATH },
266 { "D", true, OPT_D },
267 { "version", false, OPT_VERSION },
268 { "showversion", false, OPT_SHOWVERSION },
269 { "fullversion", false, OPT_FULLVERSION },
270 { "help", false, OPT_HELP },
271 { "?", false, OPT_HELP },
272 { "X", false, OPT_X },
273 { "XX", false, OPT_XX },
275 { "esa", false, OPT_ESA },
276 { "enablesystemassertions", false, OPT_ESA },
277 { "dsa", false, OPT_DSA },
278 { "disablesystemassertions", false, OPT_DSA },
280 { "noasyncgc", false, OPT_IGNORE },
281 #if defined(ENABLE_VERIFIER)
282 { "noverify", false, OPT_NOVERIFY },
284 { "v", false, OPT_VERBOSE1 },
285 { "verbose:", true, OPT_VERBOSE },
287 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
288 { "verbosetc", false, OPT_VERBOSETC },
290 #if defined(__ALPHA__)
291 { "noieee", false, OPT_NOIEEE },
293 { "softnull", false, OPT_SOFTNULL },
294 #if defined(ENABLE_STATISTICS)
295 { "time", false, OPT_TIME },
296 { "stat", false, OPT_STAT },
298 { "log", true, OPT_LOG },
299 { "c", true, OPT_CHECK },
300 { "l", false, OPT_LOAD },
301 { "eager", false, OPT_EAGER },
304 { "all", false, OPT_ALL },
305 { "sig", true, OPT_SIGNATURE },
308 #if defined(ENABLE_LOOP)
309 { "oloop", false, OPT_OLOOP },
311 #if defined(ENABLE_IFCONV)
312 { "ifconv", false, OPT_IFCONV },
314 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
315 { "lsra", false, OPT_LSRA },
318 #if defined(ENABLE_INTRP)
319 /* interpreter options */
321 { "trace", false, OPT_TRACE },
322 { "static-supers", true, OPT_STATIC_SUPERS },
323 { "no-dynamic", false, OPT_NO_DYNAMIC },
324 { "no-replication", false, OPT_NO_REPLICATION },
325 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
328 /* JVMTI Agent Command Line Options */
330 { "agentlib:", true, OPT_AGENTLIB },
331 { "agentpath:", true, OPT_AGENTPATH },
334 /* Java non-standard options */
336 { "Xjit", false, OPT_JIT },
337 { "Xint", false, OPT_INTRP },
338 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
339 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
340 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
341 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
344 { "Xdebug", false, OPT_DEBUG },
345 { "Xnoagent", false, OPT_NOAGENT },
346 { "Xrunjdwp", true, OPT_XRUNJDWP },
349 { "Xms", true, OPT_MS },
350 { "ms", true, OPT_MS },
351 { "Xmx", true, OPT_MX },
352 { "mx", true, OPT_MX },
353 { "Xss", true, OPT_SS },
354 { "ss", true, OPT_SS },
356 #if defined(ENABLE_PROFILING)
357 { "Xprof:", true, OPT_PROF_OPTION },
358 { "Xprof", false, OPT_PROF },
361 /* inlining options */
363 #if defined(ENABLE_INLINING)
364 #if defined(ENABLE_INLINING_DEBUG)
365 { "ia", false, OPT_INLINE_DEBUG_ALL },
366 { "ii", true, OPT_INLINE_DEBUG_MIN },
367 { "im", true, OPT_INLINE_DEBUG_MAX },
368 { "ie", true, OPT_INLINE_DEBUG_END },
369 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
370 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
371 #endif /* defined(ENABLE_INLINING_DEBUG) */
373 { "il", false, OPT_INLINE_LOG },
375 { "i", false, OPT_INLINING },
376 #endif /* defined(ENABLE_INLINING) */
378 /* keep these at the end of the list */
381 { "m", true, OPT_METHOD },
384 { "s", true, OPT_SHOW },
385 { "debug-color", false, OPT_DEBUGCOLOR },
391 /* usage ***********************************************************************
393 Prints the correct usage syntax to stdout.
395 *******************************************************************************/
399 puts("Usage: cacao [-options] classname [arguments]");
400 puts(" (to run a class file)");
401 puts(" or cacao [-options] -jar jarfile [arguments]");
402 puts(" (to run a standalone jar file)\n");
404 puts("where options include:");
405 puts(" -d32 use 32-bit data model if available");
406 puts(" -d64 use 64-bit data model if available");
407 puts(" -client compatibility (currently ignored)");
408 puts(" -server compatibility (currently ignored)");
409 puts(" -jvm compatibility (currently ignored)");
410 puts(" -hotspot compatibility (currently ignored)\n");
412 puts(" -cp <path> specify a path to look for classes");
413 puts(" -classpath <path> specify a path to look for classes");
414 puts(" -D<name>=<value> add an entry to the property list");
415 puts(" -verbose[:class|gc|jni] enable specific verbose output");
416 puts(" -version print product version and exit");
417 puts(" -fullversion print jpackage-compatible product version and exit");
418 puts(" -showversion print product version and continue");
419 puts(" -help, -? print this help message");
420 puts(" -X print help on non-standard Java options");
421 puts(" -XX print help on CACAO options");
422 puts(" -esa | -enablesystemassertions");
423 puts(" enable system assertions");
424 puts(" -dsa | -disablesystemassertions");
425 puts(" disable system assertions");
428 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
429 puts (" for jdwp help use: -agentlib:jdwp=help");
430 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
433 /* exit with error code */
439 static void Xusage(void)
441 #if defined(ENABLE_JIT)
442 puts(" -Xjit JIT mode execution (default)");
444 #if defined(ENABLE_INTRP)
445 puts(" -Xint interpreter mode execution");
447 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
448 puts(" value is set as bootstrap class path");
449 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
450 puts(" value is appended to the bootstrap class path");
451 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
452 puts(" value is prepended to the bootstrap class path");
453 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
454 puts(" value is used as Java core library, but the");
455 puts(" hardcoded VM interface classes are prepended");
456 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
457 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
458 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
460 #if defined(ENABLE_PROFILING)
461 puts(" -Xprof[:bb] collect and print profiling data");
464 #if defined(ENABLE_JVMTI)
465 /* -Xdebug option depend on gnu classpath JDWP options. options:
466 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
467 puts(" -Xdebug enable remote debugging\n");
468 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
469 puts(" enable remote debugging\n");
472 /* exit with error code */
478 static void XXusage(void)
480 puts(" -v write state-information");
481 puts(" -verbose[:call|exception|jit]");
482 puts(" enable specific verbose output");
483 puts(" -debug-color colored output for ANSI terms");
484 #ifdef TYPECHECK_VERBOSE
485 puts(" -verbosetc write debug messages while typechecking");
487 #if defined(__ALPHA__)
488 puts(" -noieee don't use ieee compliant arithmetic");
490 #if defined(ENABLE_VERIFIER)
491 puts(" -noverify don't verify classfiles");
493 puts(" -softnull use software nullpointer check");
494 #if defined(ENABLE_STATISTICS)
495 puts(" -time measure the runtime");
496 puts(" -stat detailed compiler statistics");
498 puts(" -log logfile specify a name for the logfile");
499 puts(" -c(heck)b(ounds) don't check array bounds");
500 puts(" s(ync) don't check for synchronization");
501 #if defined(ENABLE_LOOP)
502 puts(" -oloop optimize array accesses in loops");
504 puts(" -l don't start the class after loading");
505 puts(" -eager perform eager class loading and linking");
507 puts(" -all compile all methods, no execution");
508 puts(" -m compile only a specific method");
509 puts(" -sig specify signature for a specific method");
512 puts(" -s... show...");
513 puts(" (c)onstants the constant pool");
514 puts(" (m)ethods class fields and methods");
515 puts(" (u)tf the utf - hash");
516 puts(" (i)ntermediate intermediate representation");
517 #if defined(ENABLE_DISASSEMBLER)
518 puts(" (a)ssembler disassembled listing");
519 puts(" n(o)ps show NOPs in disassembler output");
520 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
521 puts(" (n)ative disassembled native stubs");
523 puts(" (d)atasegment data segment listing");
525 #if defined(ENABLE_INLINING)
526 puts(" -i activate inlining");
528 puts(" -il log inlining");
530 #if defined(ENABLE_INLINING_DEBUG)
531 puts(" -ia use inlining for all methods");
532 puts(" -ii <size> set minimum size for inlined result");
533 puts(" -im <size> set maximum size for inlined result");
534 puts(" -ie <number> stop inlining after the given number of roots");
535 puts(" -ir log on-stack replacement");
536 puts(" -iR log on-stack replacement, more verbose");
537 #endif /* defined(ENABLE_INLINING_DEBUG) */
538 #endif /* defined(ENABLE_INLINING) */
540 #if defined(ENABLE_IFCONV)
541 puts(" -ifconv use if-conversion");
543 #if defined(ENABLE_LSRA)
544 puts(" -lsra use linear scan register allocation");
546 #if defined(ENABLE_SSA)
547 puts(" -lsra use linear scan register allocation (with SSA)");
550 /* exit with error code */
556 /* version *********************************************************************
558 Only prints cacao version information.
560 *******************************************************************************/
562 static void version(bool opt_exit)
564 puts("java version \""JAVA_VERSION"\"");
565 puts("CACAO version "VERSION"");
567 puts("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,");
568 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
569 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
570 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
572 puts("This program is free software; you can redistribute it and/or");
573 puts("modify it under the terms of the GNU General Public License as");
574 puts("published by the Free Software Foundation; either version 2, or (at");
575 puts("your option) any later version.\n");
577 puts("This program is distributed in the hope that it will be useful, but");
578 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
579 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
580 puts("General Public License for more details.\n");
582 puts("Configure/Build options:\n");
583 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
584 #if defined(__VERSION__)
585 puts(" CC : "VERSION_CC" ("__VERSION__")");
587 puts(" CC : "VERSION_CC"");
589 puts(" CFLAGS : "VERSION_CFLAGS"\n");
591 puts("Default variables:\n");
592 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
593 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
594 printf(" stack size : %d\n", STACK_SIZE);
595 #if defined(WITH_CLASSPATH_GNU)
596 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
598 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
600 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
602 puts("Runtime variables:\n");
603 printf(" maximum heap size : %d\n", opt_heapmaxsize);
604 printf(" initial heap size : %d\n", opt_heapstartsize);
605 printf(" stack size : %d\n", opt_stacksize);
606 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
607 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
608 printf(" java.class.path : %s\n", _Jv_classpath);
610 /* exit normally, if requested */
617 /* fullversion *****************************************************************
619 Prints a Sun compatible version information (required e.g. by
620 jpackage, www.jpackage.org).
622 *******************************************************************************/
624 static void fullversion(void)
626 puts("java full version \"cacao-"JAVA_VERSION"\"");
634 /* forward declarations *******************************************************/
636 static char *vm_get_mainclass_from_jar(char *mainstring);
638 static void vm_compile_all(void);
639 static void vm_compile_method(void);
643 /* vm_createjvm ****************************************************************
645 Implementation for JNI_CreateJavaVM.
647 *******************************************************************************/
649 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
651 JavaVMInitArgs *_vm_args;
655 /* get the arguments for the new JVM */
657 _vm_args = (JavaVMInitArgs *) vm_args;
659 /* get the VM and Env tables (must be set before vm_create) */
661 env = NEW(_Jv_JNIEnv);
663 #if defined(ENABLE_JAVASE)
664 env->env = &_Jv_JNINativeInterface;
667 /* XXX Set the global variable. Maybe we should do that differently. */
671 /* create and fill a JavaVM structure */
673 vm = NEW(_Jv_JavaVM);
675 #if defined(ENABLE_JAVASE)
676 vm->functions = &_Jv_JNIInvokeInterface;
679 /* XXX Set the global variable. Maybe we should do that differently. */
680 /* XXX JVMTI Agents needs a JavaVM */
684 /* actually create the JVM */
686 if (!vm_create(_vm_args))
689 #if defined(ENABLE_JAVASE)
690 /* setup the local ref table (must be created after vm_create) */
692 if (!jni_init_localref_table())
696 /* now return the values */
698 *p_vm = (JavaVM *) vm;
699 *p_env = (void *) env;
704 /* release allocated memory */
706 FREE(env, _Jv_JNIEnv);
707 FREE(vm, _Jv_JavaVM);
713 /* vm_create *******************************************************************
715 Creates a JVM. Called by vm_createjvm.
717 *******************************************************************************/
719 bool vm_create(JavaVMInitArgs *vm_args)
728 #if defined(ENABLE_JVMTI)
730 char *libname, *agentarg;
731 bool jdwp,agentbypath;
732 jdwp = agentbypath = false;
735 /* check the JNI version requested */
737 switch (vm_args->version) {
738 case JNI_VERSION_1_1:
740 case JNI_VERSION_1_2:
741 case JNI_VERSION_1_4:
747 /* we only support 1 JVM instance */
752 if (atexit(vm_exit_handler))
753 vm_abort("atexit failed: %s\n", strerror(errno));
756 log_text("CACAO started -------------------------------------------------------");
758 /* set the VM starttime */
760 _Jv_jvm->starttime = builtin_currenttimemillis();
762 /* get stuff from the environment *****************************************/
764 #if defined(WITH_JRE_LAYOUT)
765 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
767 cacao_prefix = MNEW(char, 4096);
769 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
770 vm_abort("readlink failed: %s\n", strerror(errno));
772 /* get the path of the current executable */
774 cacao_prefix = dirname(cacao_prefix);
776 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
777 vm_abort("libjvm name to long for buffer\n");
779 /* concatenate the library name */
781 strcat(cacao_prefix, "/..");
783 /* now set path to libjvm.so */
785 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
787 cacao_libjvm = MNEW(char, len);
788 strcpy(cacao_libjvm, cacao_prefix);
789 strcat(cacao_libjvm, "/lib/libjvm");
791 /* and finally set the path to GNU Classpath libraries */
793 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
795 classpath_libdir = MNEW(char, len);
796 strcpy(classpath_libdir, cacao_prefix);
797 strcat(classpath_libdir, "/lib/classpath");
799 cacao_prefix = CACAO_PREFIX;
800 cacao_libjvm = CACAO_LIBDIR"/libjvm";
801 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
804 /* set the bootclasspath */
806 cp = getenv("BOOTCLASSPATH");
809 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
810 strcpy(_Jv_bootclasspath, cp);
813 #if defined(WITH_JRE_LAYOUT)
815 # if defined(WITH_CLASSPATH_GNU)
816 strlen(cacao_prefix) +
817 strlen("/share/cacao/vm.zip") +
820 strlen(cacao_prefix) +
821 strlen("/share/classpath/glibj.zip") +
824 _Jv_bootclasspath = MNEW(char, len);
825 # if defined(WITH_CLASSPATH_GNU)
826 strcat(_Jv_bootclasspath, cacao_prefix);
827 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
828 strcat(_Jv_bootclasspath, ":");
830 strcat(_Jv_bootclasspath, cacao_prefix);
831 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
834 # if defined(WITH_CLASSPATH_GNU)
835 strlen(CACAO_VM_ZIP) +
838 strlen(CLASSPATH_CLASSES) +
841 _Jv_bootclasspath = MNEW(char, len);
842 # if defined(WITH_CLASSPATH_GNU)
843 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
844 strcat(_Jv_bootclasspath, ":");
846 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
850 /* set the classpath */
852 cp = getenv("CLASSPATH");
855 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
856 strcat(_Jv_classpath, cp);
859 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
860 strcpy(_Jv_classpath, ".");
863 /* get and set java.library.path */
865 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
867 if (_Jv_java_library_path == NULL)
868 _Jv_java_library_path = "";
870 /* interpret the options **************************************************/
878 opt_heapmaxsize = HEAP_MAXSIZE;
879 opt_heapstartsize = HEAP_STARTSIZE;
880 opt_stacksize = STACK_SIZE;
883 #if defined(ENABLE_JVMTI)
884 /* initialize JVMTI related **********************************************/
888 /* initialize and fill properties before command-line handling */
890 if (!properties_init())
891 vm_abort("properties_init failed");
893 /* iterate over all passed options */
895 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
909 #if SIZEOF_VOID_P == 8
910 puts("Running a 32-bit JVM is not supported on this platform.");
916 #if SIZEOF_VOID_P == 4
917 puts("Running a 64-bit JVM is not supported on this platform.");
923 /* forget old classpath and set the argument as new classpath */
924 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
926 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
927 strcpy(_Jv_classpath, opt_arg);
931 for (i = 0; i < strlen(opt_arg); i++) {
932 if (opt_arg[i] == '=') {
934 properties_add(opt_arg, opt_arg + i + 1);
939 /* if no '=' is given, just create an empty property */
941 properties_add(opt_arg, "");
946 case OPT_BOOTCLASSPATH:
947 /* Forget default bootclasspath and set the argument as
948 new boot classpath. */
950 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
952 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
953 strcpy(_Jv_bootclasspath, opt_arg);
956 case OPT_BOOTCLASSPATH_A:
957 /* append to end of bootclasspath */
959 len = strlen(_Jv_bootclasspath);
961 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
965 strlen(opt_arg) + strlen("0"));
967 strcat(_Jv_bootclasspath, ":");
968 strcat(_Jv_bootclasspath, opt_arg);
971 case OPT_BOOTCLASSPATH_P:
972 /* prepend in front of bootclasspath */
974 cp = _Jv_bootclasspath;
977 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
980 strcpy(_Jv_bootclasspath, opt_arg);
981 strcat(_Jv_bootclasspath, ":");
982 strcat(_Jv_bootclasspath, cp);
984 MFREE(cp, char, len);
987 case OPT_BOOTCLASSPATH_C:
988 /* use as Java core library, but prepend VM interface classes */
990 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
992 len = strlen(CACAO_VM_ZIP) +
997 _Jv_bootclasspath = MNEW(char, len);
999 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1000 strcat(_Jv_bootclasspath, ":");
1001 strcat(_Jv_bootclasspath, opt_arg);
1004 #if defined(ENABLE_JVMTI)
1006 /* this option exists only for compatibility reasons */
1010 /* I don't know yet what Xnoagent should do. This is only for
1011 compatiblity with eclipse - motse */
1020 strlen(CACAO_LIBDIR) +
1021 strlen("/libjdwp.so=") +
1025 agentarg = MNEW(char, len);
1027 strcpy(agentarg, CACAO_LIBDIR);
1028 strcat(agentarg, "/libjdwp.so=");
1029 strcat(agentarg, &opt_arg[1]);
1046 c = opt_arg[strlen(opt_arg) - 1];
1048 if ((c == 'k') || (c == 'K')) {
1049 j = atoi(opt_arg) * 1024;
1051 } else if ((c == 'm') || (c == 'M')) {
1052 j = atoi(opt_arg) * 1024 * 1024;
1058 opt_heapmaxsize = j;
1059 else if (opt == OPT_MS)
1060 opt_heapstartsize = j;
1071 if (strcmp("class", opt_arg) == 0)
1072 opt_verboseclass = true;
1074 else if (strcmp("gc", opt_arg) == 0)
1075 opt_verbosegc = true;
1077 else if (strcmp("jni", opt_arg) == 0)
1078 opt_verbosejni = true;
1080 else if (strcmp("call", opt_arg) == 0)
1081 opt_verbosecall = true;
1083 else if (strcmp("jit", opt_arg) == 0) {
1088 compileverbose = true;
1090 else if (strcmp("exception", opt_arg) == 0)
1091 opt_verboseexception = true;
1093 case OPT_DEBUGCOLOR:
1094 opt_debugcolor = true;
1097 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1099 opt_typecheckverbose = true;
1108 case OPT_FULLVERSION:
1112 case OPT_SHOWVERSION:
1120 #if defined(ENABLE_VERIFIER)
1130 #if defined(ENABLE_STATISTICS)
1132 opt_getcompilingtime = true;
1133 opt_getloadingtime = true;
1146 for (i = 0; i < strlen(opt_arg); i++) {
1147 switch (opt_arg[i]) {
1149 checkbounds = false;
1162 makeinitializations = false;
1169 #if !defined(NDEBUG)
1173 makeinitializations = false;
1178 opt_method = opt_arg;
1179 makeinitializations = false;
1183 opt_signature = opt_arg;
1187 case OPT_SHOW: /* Display options */
1188 for (i = 0; i < strlen(opt_arg); i++) {
1189 switch (opt_arg[i]) {
1191 showconstantpool = true;
1203 opt_showintermediate = true;
1204 compileverbose = true;
1207 #if defined(ENABLE_DISASSEMBLER)
1209 opt_showdisassemble = true;
1210 compileverbose = true;
1214 opt_shownops = true;
1218 opt_showexceptionstubs = true;
1222 opt_shownativestub = true;
1227 opt_showddatasegment = true;
1236 #if defined(ENABLE_LOOP)
1242 #if defined(ENABLE_INLINING)
1243 #if defined(ENABLE_INLINING_DEBUG)
1244 case OPT_INLINE_DEBUG_ALL:
1245 opt_inline_debug_all = true;
1247 case OPT_INLINE_DEBUG_END:
1248 opt_inline_debug_end_counter = atoi(opt_arg);
1250 case OPT_INLINE_DEBUG_MIN:
1251 opt_inline_debug_min_size = atoi(opt_arg);
1253 case OPT_INLINE_DEBUG_MAX:
1254 opt_inline_debug_max_size = atoi(opt_arg);
1256 case OPT_INLINE_REPLACE_VERBOSE:
1257 opt_replace_verbose = 1;
1259 case OPT_INLINE_REPLACE_VERBOSE2:
1260 opt_replace_verbose = 2;
1262 #endif /* defined(ENABLE_INLINING_DEBUG) */
1263 #if !defined(NDEBUG)
1264 case OPT_INLINE_LOG:
1265 opt_inline_debug_log = true;
1267 #endif /* !defined(NDEBUG) */
1270 opt_inlining = true;
1272 #endif /* defined(ENABLE_INLINING) */
1274 #if defined(ENABLE_IFCONV)
1280 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1299 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1303 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1306 #if defined(ENABLE_PROFILING)
1307 case OPT_PROF_OPTION:
1308 /* use <= to get the last \0 too */
1310 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1311 if (opt_arg[i] == ',')
1314 if (opt_arg[i] == '\0') {
1315 if (strcmp("bb", opt_arg + j) == 0)
1319 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1323 /* set k to next char */
1336 #if defined(ENABLE_JIT)
1339 printf("-Xjit option not enabled.\n");
1345 #if defined(ENABLE_INTRP)
1348 printf("-Xint option not enabled.\n");
1353 #if defined(ENABLE_INTRP)
1354 case OPT_STATIC_SUPERS:
1355 opt_static_supers = atoi(opt_arg);
1358 case OPT_NO_DYNAMIC:
1359 opt_no_dynamic = true;
1362 case OPT_NO_REPLICATION:
1363 opt_no_replication = true;
1366 case OPT_NO_QUICKSUPER:
1367 opt_no_quicksuper = true;
1376 printf("Unknown option: %s\n",
1377 vm_args->options[opt_index].optionString);
1382 /* get the main class *****************************************************/
1384 if (opt_index < vm_args->nOptions) {
1385 mainstring = vm_args->options[opt_index++].optionString;
1387 /* Put the jar file into the classpath (if any). */
1389 if (opt_jar == true) {
1390 /* free old classpath */
1392 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1394 /* put jarfile into classpath */
1396 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1398 strcpy(_Jv_classpath, mainstring);
1401 /* replace .'s with /'s in classname */
1403 for (i = strlen(mainstring) - 1; i >= 0; i--)
1404 if (mainstring[i] == '.')
1405 mainstring[i] = '/';
1409 #if defined(ENABLE_JVMTI)
1411 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1412 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1415 MFREE(agentarg, char, strlen(agentarg));
1417 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1421 /* Now re-set some of the properties that may have changed. This
1422 must be done after _all_ environment variables have been
1423 processes (e.g. -jar handling). */
1425 if (!properties_postinit())
1426 vm_abort("properties_postinit failed");
1428 /* Now we have all options handled and we can print the version
1434 /* initialize this JVM ****************************************************/
1436 vm_initializing = true;
1438 #if defined(ENABLE_THREADS)
1439 /* pre-initialize some core thread stuff, like the stopworldlock,
1440 thus this has to happen _before_ gc_init()!!! */
1445 /* initialize the garbage collector */
1447 gc_init(opt_heapmaxsize, opt_heapstartsize);
1449 #if defined(ENABLE_INTRP)
1450 /* Allocate main thread stack on the Java heap. */
1453 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1454 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1458 /* initialize the string hashtable stuff: lock (must be done
1459 _after_ threads_preinit) */
1462 throw_main_exception_exit();
1464 /* initialize the utf8 hashtable stuff: lock, often used utf8
1465 strings (must be done _after_ threads_preinit) */
1468 throw_main_exception_exit();
1470 /* initialize the classcache hashtable stuff: lock, hashtable
1471 (must be done _after_ threads_preinit) */
1473 if (!classcache_init())
1474 throw_main_exception_exit();
1476 /* initialize the loader with bootclasspath (must be done _after_
1480 throw_main_exception_exit();
1482 suck_add_from_property("java.endorsed.dirs");
1483 suck_add(_Jv_bootclasspath);
1485 /* initialize the memory subsystem (must be done _after_
1489 throw_main_exception_exit();
1491 /* initialize the finalizer stuff (must be done _after_
1494 if (!finalizer_init())
1495 throw_main_exception_exit();
1497 /* install architecture dependent signal handler used for exceptions */
1501 /* initialize the codegen subsystems */
1505 /* initializes jit compiler */
1509 /* machine dependent initialization */
1511 #if defined(ENABLE_JIT)
1512 # if defined(ENABLE_INTRP)
1522 /* initialize the loader subsystems (must be done _after_
1526 vm_abort("loader_init failed");
1529 vm_abort("linker_init failed");
1532 throw_main_exception_exit();
1534 if (!exceptions_init())
1535 throw_main_exception_exit();
1537 if (!builtin_init())
1538 throw_main_exception_exit();
1540 #if defined(ENABLE_JAVASE)
1541 /* Initialize the JNI subsystem (must be done _before_
1542 threads_init, as threads_init can call JNI methods
1543 (e.g. NewGlobalRef). */
1546 throw_main_exception_exit();
1549 #if defined(ENABLE_THREADS)
1550 if (!threads_init())
1551 throw_main_exception_exit();
1554 #if defined(ENABLE_PROFILING)
1555 /* initialize profiling */
1557 if (!profile_init())
1558 throw_main_exception_exit();
1561 #if defined(ENABLE_THREADS)
1562 /* initialize recompilation */
1564 if (!recompile_init())
1565 throw_main_exception_exit();
1567 /* finally, start the finalizer thread */
1569 if (!finalizer_start_thread())
1570 throw_main_exception_exit();
1572 /* start the recompilation thread (must be done before the
1573 profiling thread) */
1575 if (!recompile_start_thread())
1576 throw_main_exception_exit();
1578 # if defined(ENABLE_PROFILING)
1579 /* start the profile sampling thread */
1582 /* if (!profile_start_thread()) */
1583 /* throw_main_exception_exit(); */
1587 #if defined(ENABLE_JVMTI)
1589 /* add agent library to native library hashtable */
1590 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1594 /* increment the number of VMs */
1598 /* initialization is done */
1600 vm_initializing = false;
1602 /* everything's ok */
1608 /* vm_run **********************************************************************
1610 Runs the main-method of the passed class.
1612 *******************************************************************************/
1614 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1617 classinfo *mainclass;
1619 java_objectarray *oa;
1622 java_lang_String *s;
1626 #if !defined(NDEBUG)
1632 if (opt_method != NULL) {
1633 vm_compile_method();
1636 #endif /* !defined(NDEBUG) */
1638 /* should we run the main-method? */
1640 if (mainstring == NULL)
1643 /* set return value to OK */
1647 if (opt_jar == true)
1648 /* open jar file with java.util.jar.JarFile */
1649 mainstring = vm_get_mainclass_from_jar(mainstring);
1651 /* load the main class */
1653 mainutf = utf_new_char(mainstring);
1655 #if defined(ENABLE_JAVAME_CLDC1_1)
1656 if (!(mainclass = load_class_bootstrap(mainutf)))
1657 throw_main_exception_exit();
1659 if (!(mainclass = load_class_from_sysloader(mainutf)))
1660 throw_main_exception_exit();
1663 /* error loading class */
1665 if ((*exceptionptr != NULL) || (mainclass == NULL))
1666 throw_main_exception_exit();
1668 if (!link_class(mainclass))
1669 throw_main_exception_exit();
1671 /* find the `main' method of the main class */
1673 m = class_resolveclassmethod(mainclass,
1674 utf_new_char("main"),
1675 utf_new_char("([Ljava/lang/String;)V"),
1676 class_java_lang_Object,
1679 if (*exceptionptr) {
1680 throw_main_exception_exit();
1683 /* there is no main method or it isn't static */
1685 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1686 *exceptionptr = NULL;
1689 new_exception_message(string_java_lang_NoSuchMethodError, "main");
1690 throw_main_exception_exit();
1693 /* build argument array */
1695 oalength = vm_args->nOptions - opt_index;
1697 oa = builtin_anewarray(oalength, class_java_lang_String);
1699 for (i = 0; i < oalength; i++) {
1700 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1701 s = javastring_new(u);
1703 oa->data[i] = (java_objectheader *) s;
1706 #ifdef TYPEINFO_DEBUG_TEST
1707 /* test the typeinfo system */
1710 /*class_showmethods(currentThread->group->header.vftbl->class); */
1712 #if defined(ENABLE_JVMTI)
1713 jvmti_set_phase(JVMTI_PHASE_LIVE);
1716 /* set ThreadMXBean variables */
1718 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1719 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1721 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1722 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1723 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1724 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1726 /* start the main thread */
1728 (void) vm_call_method(m, NULL, oa);
1730 /* exception occurred? */
1732 if (*exceptionptr) {
1733 throw_main_exception();
1737 /* unload the JavaVM */
1747 /* vm_destroy ******************************************************************
1749 Unloads a Java VM and reclaims its resources.
1751 *******************************************************************************/
1753 s4 vm_destroy(JavaVM *vm)
1755 #if defined(ENABLE_THREADS)
1756 threads_join_all_threads();
1759 /* everything's ok */
1765 /* vm_exit *********************************************************************
1767 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1769 *******************************************************************************/
1771 void vm_exit(s4 status)
1775 /* signal that we are exiting */
1779 assert(class_java_lang_System);
1780 assert(class_java_lang_System->state & CLASS_LOADED);
1782 #if defined(ENABLE_JVMTI)
1783 if (jvmti || (dbgcom!=NULL)) {
1784 jvmti_set_phase(JVMTI_PHASE_DEAD);
1785 if (jvmti) jvmti_agentunload();
1789 if (!link_class(class_java_lang_System))
1790 throw_main_exception_exit();
1792 /* call java.lang.System.exit(I)V */
1794 m = class_resolveclassmethod(class_java_lang_System,
1795 utf_new_char("exit"),
1797 class_java_lang_Object,
1801 throw_main_exception_exit();
1803 /* call the exit function with passed exit status */
1805 (void) vm_call_method(m, NULL, status);
1807 /* If we had an exception, just ignore the exception and exit with
1810 vm_shutdown(status);
1814 /* vm_shutdown *****************************************************************
1816 Terminates the system immediately without freeing memory explicitly
1817 (to be used only for abnormal termination).
1819 *******************************************************************************/
1821 void vm_shutdown(s4 status)
1824 #if defined(ENABLE_STATISTICS)
1825 || opt_getcompilingtime || opt_stat
1829 log_text("CACAO terminated by shutdown");
1830 dolog("Exit status: %d\n", (s4) status);
1834 #if defined(ENABLE_JVMTI)
1835 /* terminate cacaodbgserver */
1837 pthread_mutex_lock(&dbgcomlock);
1839 pthread_mutex_unlock(&dbgcomlock);
1840 jvmti_cacaodbgserver_quit();
1848 /* vm_exit_handler *************************************************************
1850 The exit_handler function is called upon program termination.
1852 ATTENTION: Don't free system resources here! Some threads may still
1853 be running as this is called from VMRuntime.exit(). The OS does the
1856 *******************************************************************************/
1858 void vm_exit_handler(void)
1860 #if !defined(NDEBUG)
1862 class_showmethods(mainclass);
1864 if (showconstantpool)
1865 class_showconstantpool(mainclass);
1870 # if defined(ENABLE_PROFILING)
1872 profile_printstats();
1874 #endif /* !defined(NDEBUG) */
1876 #if defined(ENABLE_RT_TIMING)
1877 rt_timing_print_time_stats(stderr);
1880 #if defined(ENABLE_CYCLES_STATS)
1881 builtin_print_cycles_stats(stderr);
1882 stacktrace_print_cycles_stats(stderr);
1886 #if defined(ENABLE_STATISTICS)
1887 || opt_getcompilingtime || opt_stat
1891 log_text("CACAO terminated");
1893 #if defined(ENABLE_STATISTICS)
1896 #ifdef TYPECHECK_STATISTICS
1897 typecheck_print_statistics(get_logfile());
1903 if (opt_getcompilingtime)
1905 #endif /* defined(ENABLE_STATISTICS) */
1907 /* vm_print_profile(stderr);*/
1911 /* vm_abort ********************************************************************
1913 Prints an error message and aborts the VM.
1915 *******************************************************************************/
1917 void vm_abort(const char *text, ...)
1921 /* print the log message */
1926 log_vprint(text, ap);
1931 /* now abort the VM */
1937 /* vm_get_mainclass_from_jar ***************************************************
1939 Gets the name of the main class from a JAR's manifest file.
1941 *******************************************************************************/
1943 static char *vm_get_mainclass_from_jar(char *mainstring)
1946 java_objectheader *o;
1948 java_lang_String *s;
1950 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
1953 throw_main_exception_exit();
1955 /* create JarFile object */
1960 throw_main_exception_exit();
1963 m = class_resolveclassmethod(c,
1965 utf_java_lang_String__void,
1966 class_java_lang_Object,
1970 throw_main_exception_exit();
1972 s = javastring_new_from_ascii(mainstring);
1974 (void) vm_call_method(m, o, s);
1977 throw_main_exception_exit();
1979 /* get manifest object */
1981 m = class_resolveclassmethod(c,
1982 utf_new_char("getManifest"),
1983 utf_new_char("()Ljava/util/jar/Manifest;"),
1984 class_java_lang_Object,
1988 throw_main_exception_exit();
1990 o = vm_call_method(m, o);
1993 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
1998 /* get Main Attributes */
2000 m = class_resolveclassmethod(o->vftbl->class,
2001 utf_new_char("getMainAttributes"),
2002 utf_new_char("()Ljava/util/jar/Attributes;"),
2003 class_java_lang_Object,
2007 throw_main_exception_exit();
2009 o = vm_call_method(m, o);
2012 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2017 /* get property Main-Class */
2019 m = class_resolveclassmethod(o->vftbl->class,
2020 utf_new_char("getValue"),
2021 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2022 class_java_lang_Object,
2026 throw_main_exception_exit();
2028 s = javastring_new_from_ascii("Main-Class");
2030 o = vm_call_method(m, o, s);
2033 throw_main_exception_exit();
2035 return javastring_tochar(o);
2039 /* vm_compile_all **************************************************************
2041 Compile all methods found in the bootclasspath.
2043 *******************************************************************************/
2045 #if !defined(NDEBUG)
2046 static void vm_compile_all(void)
2051 classcache_name_entry *nmen;
2052 classcache_class_entry *clsen;
2055 /* create all classes found in the bootclasspath */
2056 /* XXX currently only works with zip/jar's */
2058 loader_load_all_classes();
2060 /* link all classes */
2062 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2063 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2065 for (; nmen; nmen = nmen->hashlink) {
2066 /* iterate over all class entries */
2068 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2069 c = clsen->classobj;
2074 if (!(c->state & CLASS_LINKED)) {
2075 if (!link_class(c)) {
2076 fprintf(stderr, "Error linking: ");
2077 utf_fprint_printable_ascii_classname(stderr, c->name);
2078 fprintf(stderr, "\n");
2080 /* print out exception and cause */
2082 exceptions_print_exception(*exceptionptr);
2084 /* goto next class */
2090 /* compile all class methods */
2092 for (i = 0; i < c->methodscount; i++) {
2093 m = &(c->methods[i]);
2095 if (m->jcode != NULL) {
2096 if (!jit_compile(m)) {
2097 fprintf(stderr, "Error compiling: ");
2098 utf_fprint_printable_ascii_classname(stderr, c->name);
2099 fprintf(stderr, ".");
2100 utf_fprint_printable_ascii(stderr, m->name);
2101 utf_fprint_printable_ascii(stderr, m->descriptor);
2102 fprintf(stderr, "\n");
2104 /* print out exception and cause */
2106 exceptions_print_exception(*exceptionptr);
2114 #endif /* !defined(NDEBUG) */
2117 /* vm_compile_method ***********************************************************
2119 Compile a specific method.
2121 *******************************************************************************/
2123 #if !defined(NDEBUG)
2124 static void vm_compile_method(void)
2128 /* create, load and link the main class */
2130 if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
2131 throw_main_exception_exit();
2133 if (!link_class(mainclass))
2134 throw_main_exception_exit();
2136 if (opt_signature != NULL) {
2137 m = class_resolveclassmethod(mainclass,
2138 utf_new_char(opt_method),
2139 utf_new_char(opt_signature),
2144 m = class_resolveclassmethod(mainclass,
2145 utf_new_char(opt_method),
2152 char message[MAXLOGTEXT];
2153 sprintf(message, "%s%s", opt_method,
2154 opt_signature ? opt_signature : "");
2157 new_exception_message(string_java_lang_NoSuchMethodException,
2160 throw_main_exception_exit();
2165 #endif /* !defined(NDEBUG) */
2168 /* vm_vmargs_from_valist *******************************************************
2172 *******************************************************************************/
2174 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2175 vm_arg *vmargs, va_list ap)
2177 typedesc *paramtypes;
2180 paramtypes = m->parseddesc->paramtypes;
2182 /* if method is non-static fill first block and skip `this' pointer */
2187 /* the `this' pointer */
2188 vmargs[0].type = TYPE_ADR;
2189 vmargs[0].data.l = (u8) (ptrint) o;
2195 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2196 switch (paramtypes->decltype) {
2197 /* primitive types */
2198 case PRIMITIVETYPE_BOOLEAN:
2199 case PRIMITIVETYPE_BYTE:
2200 case PRIMITIVETYPE_CHAR:
2201 case PRIMITIVETYPE_SHORT:
2202 case PRIMITIVETYPE_INT:
2203 vmargs[i].type = TYPE_INT;
2204 vmargs[i].data.l = (s8) va_arg(ap, s4);
2207 case PRIMITIVETYPE_LONG:
2208 vmargs[i].type = TYPE_LNG;
2209 vmargs[i].data.l = (s8) va_arg(ap, s8);
2212 case PRIMITIVETYPE_FLOAT:
2213 vmargs[i].type = TYPE_FLT;
2214 #if defined(__ALPHA__)
2215 /* this keeps the assembler function much simpler */
2217 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2219 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2223 case PRIMITIVETYPE_DOUBLE:
2224 vmargs[i].type = TYPE_DBL;
2225 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2229 vmargs[i].type = TYPE_ADR;
2230 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2237 /* vm_vmargs_from_jvalue *******************************************************
2241 *******************************************************************************/
2243 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2244 vm_arg *vmargs, jvalue *args)
2246 typedesc *paramtypes;
2250 paramtypes = m->parseddesc->paramtypes;
2252 /* if method is non-static fill first block and skip `this' pointer */
2257 /* the `this' pointer */
2258 vmargs[0].type = TYPE_ADR;
2259 vmargs[0].data.l = (u8) (ptrint) o;
2265 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2266 switch (paramtypes->decltype) {
2267 /* primitive types */
2268 case PRIMITIVETYPE_BOOLEAN:
2269 case PRIMITIVETYPE_BYTE:
2270 case PRIMITIVETYPE_CHAR:
2271 case PRIMITIVETYPE_SHORT:
2272 case PRIMITIVETYPE_INT:
2273 vmargs[i].type = TYPE_INT;
2274 vmargs[i].data.l = (s8) args[j].i;
2277 case PRIMITIVETYPE_LONG:
2278 vmargs[i].type = TYPE_LNG;
2279 vmargs[i].data.l = (s8) args[j].j;
2282 case PRIMITIVETYPE_FLOAT:
2283 vmargs[i].type = TYPE_FLT;
2284 #if defined(__ALPHA__)
2285 /* this keeps the assembler function much simpler */
2287 vmargs[i].data.d = (jdouble) args[j].f;
2289 vmargs[i].data.f = args[j].f;
2293 case PRIMITIVETYPE_DOUBLE:
2294 vmargs[i].type = TYPE_DBL;
2295 vmargs[i].data.d = args[j].d;
2299 vmargs[i].type = TYPE_ADR;
2300 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2307 /* vm_call_method **************************************************************
2309 Calls a Java method with a variable number of arguments and returns
2312 *******************************************************************************/
2314 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2317 java_objectheader *ro;
2320 ro = vm_call_method_valist(m, o, ap);
2327 /* vm_call_method_valist *******************************************************
2329 Calls a Java method with a variable number of arguments, passed via
2330 a va_list, and returns an address.
2332 *******************************************************************************/
2334 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2339 java_objectheader *ro;
2342 /* mark start of dump memory area */
2344 dumpsize = dump_size();
2346 /* get number of Java method arguments */
2348 vmargscount = m->parseddesc->paramcount;
2350 /* allocate vm_arg array */
2352 vmargs = DMNEW(vm_arg, vmargscount);
2354 /* fill the vm_arg array from a va_list */
2356 vm_vmargs_from_valist(m, o, vmargs, ap);
2358 /* call the Java method */
2360 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2362 /* release dump area */
2364 dump_release(dumpsize);
2370 /* vm_call_method_jvalue *******************************************************
2372 Calls a Java method with a variable number of arguments, passed via
2373 a jvalue array, and returns an address.
2375 *******************************************************************************/
2377 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2382 java_objectheader *ro;
2385 /* mark start of dump memory area */
2387 dumpsize = dump_size();
2389 /* get number of Java method arguments */
2391 vmargscount = m->parseddesc->paramcount;
2393 /* allocate vm_arg array */
2395 vmargs = DMNEW(vm_arg, vmargscount);
2397 /* fill the vm_arg array from a va_list */
2399 vm_vmargs_from_jvalue(m, o, vmargs, args);
2401 /* call the Java method */
2403 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2405 /* release dump area */
2407 dump_release(dumpsize);
2413 /* vm_call_method_vmarg ********************************************************
2415 Calls a Java method with a variable number of arguments, passed via
2416 a vm_arg array, and returns an address.
2418 *******************************************************************************/
2420 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2423 java_objectheader *o;
2425 #if defined(ENABLE_JIT)
2426 # if defined(ENABLE_INTRP)
2428 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2431 o = asm_vm_call_method(m, vmargscount, vmargs);
2433 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2440 /* vm_call_method_int **********************************************************
2442 Calls a Java method with a variable number of arguments and returns
2445 *******************************************************************************/
2447 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2453 i = vm_call_method_int_valist(m, o, ap);
2460 /* vm_call_method_int_valist ***************************************************
2462 Calls a Java method with a variable number of arguments, passed via
2463 a va_list, and returns an integer (s4).
2465 *******************************************************************************/
2467 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2474 /* mark start of dump memory area */
2476 dumpsize = dump_size();
2478 /* get number of Java method arguments */
2480 vmargscount = m->parseddesc->paramcount;
2482 /* allocate vm_arg array */
2484 vmargs = DMNEW(vm_arg, vmargscount);
2486 /* fill the vm_arg array from a va_list */
2488 vm_vmargs_from_valist(m, o, vmargs, ap);
2490 /* call the Java method */
2492 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2494 /* release dump area */
2496 dump_release(dumpsize);
2502 /* vm_call_method_int_jvalue ***************************************************
2504 Calls a Java method with a variable number of arguments, passed via
2505 a jvalue array, and returns an integer (s4).
2507 *******************************************************************************/
2509 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2516 /* mark start of dump memory area */
2518 dumpsize = dump_size();
2520 /* get number of Java method arguments */
2522 vmargscount = m->parseddesc->paramcount;
2524 /* allocate vm_arg array */
2526 vmargs = DMNEW(vm_arg, vmargscount);
2528 /* fill the vm_arg array from a va_list */
2530 vm_vmargs_from_jvalue(m, o, vmargs, args);
2532 /* call the Java method */
2534 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2536 /* release dump area */
2538 dump_release(dumpsize);
2544 /* vm_call_method_int_vmarg ****************************************************
2546 Calls a Java method with a variable number of arguments, passed via
2547 a vm_arg array, and returns an integer (s4).
2549 *******************************************************************************/
2551 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2555 #if defined(ENABLE_JIT)
2556 # if defined(ENABLE_INTRP)
2558 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2561 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2563 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2570 /* vm_call_method_long *********************************************************
2572 Calls a Java method with a variable number of arguments and returns
2575 *******************************************************************************/
2577 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2583 l = vm_call_method_long_valist(m, o, ap);
2590 /* vm_call_method_long_valist **************************************************
2592 Calls a Java method with a variable number of arguments, passed via
2593 a va_list, and returns a long (s8).
2595 *******************************************************************************/
2597 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2604 /* mark start of dump memory area */
2606 dumpsize = dump_size();
2608 /* get number of Java method arguments */
2610 vmargscount = m->parseddesc->paramcount;
2612 /* allocate vm_arg array */
2614 vmargs = DMNEW(vm_arg, vmargscount);
2616 /* fill the vm_arg array from a va_list */
2618 vm_vmargs_from_valist(m, o, vmargs, ap);
2620 /* call the Java method */
2622 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2624 /* release dump area */
2626 dump_release(dumpsize);
2632 /* vm_call_method_long_jvalue **************************************************
2634 Calls a Java method with a variable number of arguments, passed via
2635 a jvalue array, and returns a long (s8).
2637 *******************************************************************************/
2639 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2646 /* mark start of dump memory area */
2648 dumpsize = dump_size();
2650 /* get number of Java method arguments */
2652 vmargscount = m->parseddesc->paramcount;
2654 /* allocate vm_arg array */
2656 vmargs = DMNEW(vm_arg, vmargscount);
2658 /* fill the vm_arg array from a va_list */
2660 vm_vmargs_from_jvalue(m, o, vmargs, args);
2662 /* call the Java method */
2664 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2666 /* release dump area */
2668 dump_release(dumpsize);
2674 /* vm_call_method_long_vmarg ***************************************************
2676 Calls a Java method with a variable number of arguments, passed via
2677 a vm_arg array, and returns a long (s8).
2679 *******************************************************************************/
2681 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2685 #if defined(ENABLE_JIT)
2686 # if defined(ENABLE_INTRP)
2688 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2691 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2693 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2700 /* vm_call_method_float ********************************************************
2702 Calls a Java method with a variable number of arguments and returns
2705 *******************************************************************************/
2707 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2713 f = vm_call_method_float_valist(m, o, ap);
2720 /* vm_call_method_float_valist *************************************************
2722 Calls a Java method with a variable number of arguments, passed via
2723 a va_list, and returns a float.
2725 *******************************************************************************/
2727 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2735 /* mark start of dump memory area */
2737 dumpsize = dump_size();
2739 /* get number of Java method arguments */
2741 vmargscount = m->parseddesc->paramcount;
2743 /* allocate vm_arg array */
2745 vmargs = DMNEW(vm_arg, vmargscount);
2747 /* fill the vm_arg array from a va_list */
2749 vm_vmargs_from_valist(m, o, vmargs, ap);
2751 /* call the Java method */
2753 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2755 /* release dump area */
2757 dump_release(dumpsize);
2763 /* vm_call_method_float_jvalue *************************************************
2765 Calls a Java method with a variable number of arguments, passed via
2766 a jvalue array, and returns a float.
2768 *******************************************************************************/
2770 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2778 /* mark start of dump memory area */
2780 dumpsize = dump_size();
2782 /* get number of Java method arguments */
2784 vmargscount = m->parseddesc->paramcount;
2786 /* allocate vm_arg array */
2788 vmargs = DMNEW(vm_arg, vmargscount);
2790 /* fill the vm_arg array from a va_list */
2792 vm_vmargs_from_jvalue(m, o, vmargs, args);
2794 /* call the Java method */
2796 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2798 /* release dump area */
2800 dump_release(dumpsize);
2806 /* vm_call_method_float_vmarg **************************************************
2808 Calls a Java method with a variable number of arguments and returns
2811 *******************************************************************************/
2813 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2817 #if defined(ENABLE_JIT)
2818 # if defined(ENABLE_INTRP)
2820 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2823 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2825 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2832 /* vm_call_method_double *******************************************************
2834 Calls a Java method with a variable number of arguments and returns
2837 *******************************************************************************/
2839 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2845 d = vm_call_method_double_valist(m, o, ap);
2852 /* vm_call_method_double_valist ************************************************
2854 Calls a Java method with a variable number of arguments, passed via
2855 a va_list, and returns a double.
2857 *******************************************************************************/
2859 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2867 /* mark start of dump memory area */
2869 dumpsize = dump_size();
2871 /* get number of Java method arguments */
2873 vmargscount = m->parseddesc->paramcount;
2875 /* allocate vm_arg array */
2877 vmargs = DMNEW(vm_arg, vmargscount);
2879 /* fill the vm_arg array from a va_list */
2881 vm_vmargs_from_valist(m, o, vmargs, ap);
2883 /* call the Java method */
2885 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2887 /* release dump area */
2889 dump_release(dumpsize);
2895 /* vm_call_method_double_jvalue ************************************************
2897 Calls a Java method with a variable number of arguments, passed via
2898 a jvalue array, and returns a double.
2900 *******************************************************************************/
2902 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2910 /* mark start of dump memory area */
2912 dumpsize = dump_size();
2914 /* get number of Java method arguments */
2916 vmargscount = m->parseddesc->paramcount;
2918 /* allocate vm_arg array */
2920 vmargs = DMNEW(vm_arg, vmargscount);
2922 /* fill the vm_arg array from a va_list */
2924 vm_vmargs_from_jvalue(m, o, vmargs, args);
2926 /* call the Java method */
2928 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2930 /* release dump area */
2932 dump_release(dumpsize);
2938 /* vm_call_method_double_vmarg *************************************************
2940 Calls a Java method with a variable number of arguments and returns
2943 *******************************************************************************/
2945 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
2950 #if defined(ENABLE_JIT)
2951 # if defined(ENABLE_INTRP)
2953 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2956 d = asm_vm_call_method_double(m, vmargscount, vmargs);
2958 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
2966 * These are local overrides for various environment variables in Emacs.
2967 * Please do not remove this and leave it at the end of the file, where
2968 * Emacs will automagically detect them.
2969 * ---------------------------------------------------------------------
2972 * indent-tabs-mode: t