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 8401 2007-08-22 18:45:31Z twisti $
42 #include "vm/jit/abi-asm.h"
44 #include "mm/gc-common.h"
45 #include "mm/memory.h"
47 #include "native/jni.h"
48 #include "native/llni.h"
49 #include "native/native.h"
51 #include "native/include/java_lang_Object.h" /* required by j.l.C */
52 #include "native/include/java_lang_String.h" /* required by j.l.C */
54 #if defined(WITH_CLASSPATH_SUN)
55 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
56 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
59 #include "native/include/java_lang_Class.h"
61 #include "native/vm/nativevm.h"
63 #include "threads/threads-common.h"
65 #include "toolbox/logging.h"
67 #include "vm/builtin.h"
68 #include "vm/exceptions.h"
69 #include "vm/finalizer.h"
70 #include "vm/global.h"
71 #include "vm/initialize.h"
72 #include "vm/primitive.h"
73 #include "vm/properties.h"
74 #include "vm/signallocal.h"
75 #include "vm/stringlocal.h"
78 #include "vm/jit/jit.h"
79 #include "vm/jit/md.h"
80 #include "vm/jit/asmpart.h"
82 #if defined(ENABLE_PROFILING)
83 # include "vm/jit/optimizing/profile.h"
86 #include "vm/jit/optimizing/recompile.h"
88 #include "vmcore/classcache.h"
89 #include "vmcore/options.h"
90 #include "vmcore/statistics.h"
91 #include "vmcore/suck.h"
93 #if defined(ENABLE_JVMTI)
94 # include "native/jvmti/cacaodbg.h"
97 #if defined(ENABLE_VMLOG)
98 #include <vmlog_cacao.h>
102 /* Invocation API variables ***************************************************/
104 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
105 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
108 /* global variables ***********************************************************/
110 s4 vms = 0; /* number of VMs created */
112 bool vm_initializing = false;
113 bool vm_exiting = false;
115 char *mainstring = NULL;
116 classinfo *mainclass = NULL;
118 #if defined(ENABLE_INTRP)
119 u1 *intrp_main_stack = NULL;
123 /* define heap sizes **********************************************************/
125 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
126 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
127 #define STACK_SIZE 64 * 1024 /* default 64kB */
130 /* define command line options ************************************************/
161 /* Java non-standard options */
172 #if defined(ENABLE_PROFILING)
185 #if defined(ENABLE_STATISTICS)
202 #if defined(ENABLE_VERIFIER)
204 #if defined(TYPECHECK_VERBOSE)
207 #endif /* defined(ENABLE_VERIFIER) */
209 /* optimization options */
211 #if defined(ENABLE_LOOP)
215 #if defined(ENABLE_IFCONV)
219 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
223 #if defined(ENABLE_INLINING)
228 #if defined(ENABLE_INLINING_DEBUG)
229 OPT_INLINE_DEBUG_ALL,
230 OPT_INLINE_DEBUG_END,
231 OPT_INLINE_DEBUG_MIN,
232 OPT_INLINE_DEBUG_MAX,
233 #endif /* defined(ENABLE_INLINING_DEBUG) */
234 #endif /* defined(ENABLE_INLINING) */
236 #if defined(ENABLE_INTRP)
237 /* interpreter options */
256 #if defined(ENABLE_DEBUG_FILTER)
257 OPT_FILTER_VERBOSECALL_INCLUDE,
258 OPT_FILTER_VERBOSECALL_EXCLUDE,
259 OPT_FILTER_SHOW_METHOD,
266 opt_struct opts[] = {
267 { "foo", false, OPT_FOO },
271 { "jar", false, OPT_JAR },
273 { "d32", false, OPT_D32 },
274 { "d64", false, OPT_D64 },
275 { "client", false, OPT_IGNORE },
276 { "server", false, OPT_IGNORE },
277 { "jvm", false, OPT_IGNORE },
278 { "hotspot", false, OPT_IGNORE },
280 { "classpath", true, OPT_CLASSPATH },
281 { "cp", true, OPT_CLASSPATH },
282 { "D", true, OPT_D },
283 { "version", false, OPT_VERSION },
284 { "showversion", false, OPT_SHOWVERSION },
285 { "fullversion", false, OPT_FULLVERSION },
286 { "help", false, OPT_HELP },
287 { "?", false, OPT_HELP },
288 { "X", false, OPT_X },
289 { "XX:", true, OPT_XX },
290 { "XX", false, OPT_XX },
292 { "ea:", true, OPT_EA },
293 { "da:", true, OPT_DA },
294 { "ea", false, OPT_EA },
295 { "da", false, OPT_DA },
297 { "esa", false, OPT_ESA },
298 { "enablesystemassertions", false, OPT_ESA },
299 { "dsa", false, OPT_DSA },
300 { "disablesystemassertions", false, OPT_DSA },
302 { "noasyncgc", false, OPT_IGNORE },
303 #if defined(ENABLE_VERIFIER)
304 { "noverify", false, OPT_NOVERIFY },
305 { "Xverify:none", false, OPT_NOVERIFY },
307 { "v", false, OPT_VERBOSE1 },
308 { "verbose:", true, OPT_VERBOSE },
310 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
311 { "verbosetc", false, OPT_VERBOSETC },
313 #if defined(__ALPHA__)
314 { "noieee", false, OPT_NOIEEE },
316 #if defined(ENABLE_STATISTICS)
317 { "time", false, OPT_TIME },
318 { "stat", false, OPT_STAT },
320 { "log", true, OPT_LOG },
321 { "c", true, OPT_CHECK },
322 { "l", false, OPT_LOAD },
325 { "all", false, OPT_ALL },
326 { "sig", true, OPT_SIGNATURE },
329 #if defined(ENABLE_LOOP)
330 { "oloop", false, OPT_OLOOP },
332 #if defined(ENABLE_IFCONV)
333 { "ifconv", false, OPT_IFCONV },
335 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
336 { "lsra", false, OPT_LSRA },
339 #if defined(ENABLE_INTRP)
340 /* interpreter options */
342 { "trace", false, OPT_TRACE },
343 { "static-supers", true, OPT_STATIC_SUPERS },
344 { "no-dynamic", false, OPT_NO_DYNAMIC },
345 { "no-replication", false, OPT_NO_REPLICATION },
346 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
349 /* JVMTI Agent Command Line Options */
351 { "agentlib:", true, OPT_AGENTLIB },
352 { "agentpath:", true, OPT_AGENTPATH },
355 /* Java non-standard options */
357 { "Xjit", false, OPT_JIT },
358 { "Xint", false, OPT_INTRP },
359 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
360 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
361 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
362 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
365 { "Xdebug", false, OPT_DEBUG },
366 { "Xnoagent", false, OPT_NOAGENT },
367 { "Xrunjdwp", true, OPT_XRUNJDWP },
370 { "Xms", true, OPT_MS },
371 { "ms", true, OPT_MS },
372 { "Xmx", true, OPT_MX },
373 { "mx", true, OPT_MX },
374 { "Xss", true, OPT_SS },
375 { "ss", true, OPT_SS },
377 #if defined(ENABLE_PROFILING)
378 { "Xprof:", true, OPT_PROF_OPTION },
379 { "Xprof", false, OPT_PROF },
382 /* inlining options */
384 #if defined(ENABLE_INLINING)
385 #if defined(ENABLE_INLINING_DEBUG)
386 { "ia", false, OPT_INLINE_DEBUG_ALL },
387 { "ii", true, OPT_INLINE_DEBUG_MIN },
388 { "im", true, OPT_INLINE_DEBUG_MAX },
389 { "ie", true, OPT_INLINE_DEBUG_END },
390 #endif /* defined(ENABLE_INLINING_DEBUG) */
392 { "il", false, OPT_INLINE_LOG },
394 { "i", false, OPT_INLINING },
395 #endif /* defined(ENABLE_INLINING) */
397 /* keep these at the end of the list */
400 { "m", true, OPT_METHOD },
403 { "s", true, OPT_SHOW },
404 { "debug-color", false, OPT_DEBUGCOLOR },
406 #if defined(ENABLE_DEBUG_FILTER)
407 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
408 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
409 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
416 /* usage ***********************************************************************
418 Prints the correct usage syntax to stdout.
420 *******************************************************************************/
424 puts("Usage: cacao [-options] classname [arguments]");
425 puts(" (to run a class file)");
426 puts(" or cacao [-options] -jar jarfile [arguments]");
427 puts(" (to run a standalone jar file)\n");
429 puts("where options include:");
430 puts(" -d32 use 32-bit data model if available");
431 puts(" -d64 use 64-bit data model if available");
432 puts(" -client compatibility (currently ignored)");
433 puts(" -server compatibility (currently ignored)");
434 puts(" -jvm compatibility (currently ignored)");
435 puts(" -hotspot compatibility (currently ignored)\n");
437 puts(" -cp <path> specify a path to look for classes");
438 puts(" -classpath <path> specify a path to look for classes");
439 puts(" -D<name>=<value> add an entry to the property list");
440 puts(" -verbose[:class|gc|jni] enable specific verbose output");
441 puts(" -version print product version and exit");
442 puts(" -fullversion print jpackage-compatible product version and exit");
443 puts(" -showversion print product version and continue");
444 puts(" -help, -? print this help message");
445 puts(" -X print help on non-standard Java options");
446 puts(" -XX print help on debugging options");
447 puts(" -ea[:<packagename>...|:<classname>]");
448 puts(" -enableassertions[:<packagename>...|:<classname>]");
449 puts(" enable assertions with specified granularity");
450 puts(" -da[:<packagename>...|:<classname>]");
451 puts(" -disableassertions[:<packagename>...|:<classname>]");
452 puts(" disable assertions with specified granularity");
453 puts(" -esa | -enablesystemassertions");
454 puts(" enable system assertions");
455 puts(" -dsa | -disablesystemassertions");
456 puts(" disable system assertions");
459 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
460 puts (" for jdwp help use: -agentlib:jdwp=help");
461 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
464 /* exit with error code */
470 static void Xusage(void)
472 #if defined(ENABLE_JIT)
473 puts(" -Xjit JIT mode execution (default)");
475 #if defined(ENABLE_INTRP)
476 puts(" -Xint interpreter mode execution");
478 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
479 puts(" value is set as bootstrap class path");
480 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
481 puts(" value is appended to the bootstrap class path");
482 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
483 puts(" value is prepended to the bootstrap class path");
484 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
485 puts(" value is used as Java core library, but the");
486 puts(" hardcoded VM interface classes are prepended");
487 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
488 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
489 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
491 #if defined(ENABLE_PROFILING)
492 puts(" -Xprof[:bb] collect and print profiling data");
495 #if defined(ENABLE_JVMTI)
496 /* -Xdebug option depend on gnu classpath JDWP options. options:
497 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
498 puts(" -Xdebug enable remote debugging\n");
499 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
500 puts(" enable remote debugging\n");
503 /* exit with error code */
510 static void XXusage(void)
512 puts(" -v write state-information");
514 puts(" -verbose[:jit|threads]");
515 puts(" enable specific verbose output");
516 puts(" -debug-color colored output for ANSI terms");
518 #ifdef TYPECHECK_VERBOSE
519 puts(" -verbosetc write debug messages while typechecking");
521 #if defined(__ALPHA__)
522 puts(" -noieee don't use ieee compliant arithmetic");
524 #if defined(ENABLE_VERIFIER)
525 puts(" -noverify don't verify classfiles");
527 #if defined(ENABLE_STATISTICS)
528 puts(" -time measure the runtime");
529 puts(" -stat detailed compiler statistics");
531 puts(" -log logfile specify a name for the logfile");
532 puts(" -c(heck)b(ounds) don't check array bounds");
533 puts(" s(ync) don't check for synchronization");
534 #if defined(ENABLE_LOOP)
535 puts(" -oloop optimize array accesses in loops");
537 puts(" -l don't start the class after loading");
539 puts(" -all compile all methods, no execution");
540 puts(" -m compile only a specific method");
541 puts(" -sig specify signature for a specific method");
544 puts(" -s... show...");
545 puts(" (c)onstants the constant pool");
546 puts(" (m)ethods class fields and methods");
547 puts(" (u)tf the utf - hash");
548 puts(" (i)ntermediate intermediate representation");
549 #if defined(ENABLE_DISASSEMBLER)
550 puts(" (a)ssembler disassembled listing");
551 puts(" n(o)ps show NOPs in disassembler output");
552 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
553 puts(" (n)ative disassembled native stubs");
555 puts(" (d)atasegment data segment listing");
557 #if defined(ENABLE_INLINING)
558 puts(" -i activate inlining");
560 puts(" -il log inlining");
562 #if defined(ENABLE_INLINING_DEBUG)
563 puts(" -ia use inlining for all methods");
564 puts(" -ii <size> set minimum size for inlined result");
565 puts(" -im <size> set maximum size for inlined result");
566 puts(" -ie <number> stop inlining after the given number of roots");
567 #endif /* defined(ENABLE_INLINING_DEBUG) */
568 #endif /* defined(ENABLE_INLINING) */
570 #if defined(ENABLE_IFCONV)
571 puts(" -ifconv use if-conversion");
573 #if defined(ENABLE_LSRA)
574 puts(" -lsra use linear scan register allocation");
576 #if defined(ENABLE_SSA)
577 puts(" -lsra use linear scan register allocation (with SSA)");
579 #if defined(ENABLE_DEBUG_FILTER)
580 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
581 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
582 puts(" -XXfm <regex> filter for show options");
584 /* exit with error code */
591 /* version *********************************************************************
593 Only prints cacao version information.
595 *******************************************************************************/
597 static void version(bool opt_exit)
599 puts("java version \""JAVA_VERSION"\"");
600 puts("CACAO version "VERSION"");
602 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
603 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
604 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
605 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
607 puts("This program is free software; you can redistribute it and/or");
608 puts("modify it under the terms of the GNU General Public License as");
609 puts("published by the Free Software Foundation; either version 2, or (at");
610 puts("your option) any later version.\n");
612 puts("This program is distributed in the hope that it will be useful, but");
613 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
614 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
615 puts("General Public License for more details.");
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 void vm_printconfig(void)
643 puts("Configure/Build options:\n");
644 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
645 #if defined(__VERSION__)
646 puts(" CC : "VERSION_CC" ("__VERSION__")");
648 puts(" CC : "VERSION_CC"");
650 puts(" CFLAGS : "VERSION_CFLAGS"\n");
652 puts("Default variables:\n");
653 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
654 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
655 printf(" stack size : %d\n", STACK_SIZE);
656 #if defined(WITH_CLASSPATH_GNU)
657 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
659 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
661 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
663 puts("Runtime variables:\n");
664 printf(" maximum heap size : %d\n", opt_heapmaxsize);
665 printf(" initial heap size : %d\n", opt_heapstartsize);
666 printf(" stack size : %d\n", opt_stacksize);
667 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
668 printf(" java.class.path : %s\n", properties_get("java.class.path"));
670 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
674 /* forward declarations *******************************************************/
676 static char *vm_get_mainclass_from_jar(char *mainstring);
678 static void vm_compile_all(void);
679 static void vm_compile_method(void);
683 /* vm_createjvm ****************************************************************
685 Implementation for JNI_CreateJavaVM.
687 *******************************************************************************/
689 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
691 JavaVMInitArgs *_vm_args;
695 /* get the arguments for the new JVM */
697 _vm_args = (JavaVMInitArgs *) vm_args;
699 /* get the VM and Env tables (must be set before vm_create) */
701 env = NEW(_Jv_JNIEnv);
703 #if defined(ENABLE_JNI)
704 env->env = &_Jv_JNINativeInterface;
707 /* XXX Set the global variable. Maybe we should do that differently. */
711 /* create and fill a JavaVM structure */
713 vm = NEW(_Jv_JavaVM);
715 #if defined(ENABLE_JNI)
716 vm->functions = &_Jv_JNIInvokeInterface;
719 /* XXX Set the global variable. Maybe we should do that differently. */
720 /* XXX JVMTI Agents needs a JavaVM */
724 /* actually create the JVM */
726 if (!vm_create(_vm_args))
729 #if defined(ENABLE_JNI)
730 /* setup the local ref table (must be created after vm_create) */
732 if (!localref_table_init())
736 /* now return the values */
738 *p_vm = (JavaVM *) vm;
739 *p_env = (void *) env;
744 /* release allocated memory */
746 FREE(env, _Jv_JNIEnv);
747 FREE(vm, _Jv_JavaVM);
753 /* vm_create *******************************************************************
755 Creates a JVM. Called by vm_createjvm.
757 *******************************************************************************/
759 bool vm_create(JavaVMInitArgs *vm_args)
763 char *boot_class_path;
770 #if defined(ENABLE_JVMTI)
772 char *libname, *agentarg;
773 bool jdwp,agentbypath;
774 jdwp = agentbypath = false;
777 #if defined(ENABLE_VMLOG)
778 vmlog_cacao_init(vm_args);
781 /* check the JNI version requested */
783 switch (vm_args->version) {
784 case JNI_VERSION_1_1:
786 case JNI_VERSION_1_2:
787 case JNI_VERSION_1_4:
793 /* we only support 1 JVM instance */
798 if (atexit(vm_exit_handler))
799 vm_abort("atexit failed: %s\n", strerror(errno));
802 log_text("CACAO started -------------------------------------------------------");
804 /* We need to check if the actual size of a java.lang.Class object
805 is smaller or equal than the assumption made in
806 src/vmcore/class.h. */
808 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
809 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
811 /* set the VM starttime */
813 _Jv_jvm->starttime = builtin_currenttimemillis();
815 /* interpret the options **************************************************/
822 opt_heapmaxsize = HEAP_MAXSIZE;
823 opt_heapstartsize = HEAP_STARTSIZE;
824 opt_stacksize = STACK_SIZE;
827 #if defined(ENABLE_JVMTI)
828 /* initialize JVMTI related **********************************************/
832 /* Initialize and fill properties before command-line handling. */
837 /* iterate over all passed options */
839 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
853 #if SIZEOF_VOID_P == 8
854 puts("Running a 32-bit JVM is not supported on this platform.");
860 #if SIZEOF_VOID_P == 4
861 puts("Running a 64-bit JVM is not supported on this platform.");
867 /* Forget old classpath and set the argument as new
870 class_path = properties_get("java.class.path");
872 MFREE(class_path, char, len);
874 p = MNEW(char, strlen(opt_arg) + strlen("0"));
878 #if defined(ENABLE_JAVASE)
879 properties_add("java.class.path", p);
884 for (i = 0; i < strlen(opt_arg); i++) {
885 if (opt_arg[i] == '=') {
887 properties_add(opt_arg, opt_arg + i + 1);
892 /* if no '=' is given, just create an empty property */
894 properties_add(opt_arg, "");
899 case OPT_BOOTCLASSPATH:
900 /* Forget default bootclasspath and set the argument as
901 new boot classpath. */
903 boot_class_path = properties_get("sun.boot.class.path");
905 MFREE(boot_class_path, char, len);
907 p = MNEW(char, strlen(opt_arg) + strlen("0"));
911 #if defined(ENABLE_JAVASE)
912 properties_add("sun.boot.class.path", p);
913 properties_add("java.boot.class.path", p);
917 case OPT_BOOTCLASSPATH_A:
918 /* Append to bootclasspath. */
920 boot_class_path = properties_get("sun.boot.class.path");
922 len = strlen(boot_class_path);
924 p = MREALLOC(boot_class_path,
928 strlen(opt_arg) + strlen("0"));
933 #if defined(ENABLE_JAVASE)
934 properties_add("sun.boot.class.path", p);
935 properties_add("java.boot.class.path", p);
939 case OPT_BOOTCLASSPATH_P:
940 /* Prepend to bootclasspath. */
942 boot_class_path = properties_get("sun.boot.class.path");
944 len = strlen(boot_class_path);
946 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
950 strcat(p, boot_class_path);
952 MFREE(boot_class_path, char, len);
954 #if defined(ENABLE_JAVASE)
955 properties_add("sun.boot.class.path", p);
956 properties_add("java.boot.class.path", p);
960 case OPT_BOOTCLASSPATH_C:
961 /* Use as Java core library, but prepend VM interface
964 boot_class_path = properties_get("sun.boot.class.path");
966 MFREE(boot_class_path, char, strlen(boot_class_path));
969 strlen(CACAO_VM_ZIP) +
976 strcpy(p, CACAO_VM_ZIP);
980 #if defined(ENABLE_JAVASE)
981 properties_add("sun.boot.class.path", p);
982 properties_add("java.boot.class.path", p);
986 #if defined(ENABLE_JVMTI)
988 /* this option exists only for compatibility reasons */
992 /* I don't know yet what Xnoagent should do. This is only for
993 compatiblity with eclipse - motse */
1002 strlen(CACAO_LIBDIR) +
1003 strlen("/libjdwp.so=") +
1007 agentarg = MNEW(char, len);
1009 strcpy(agentarg, CACAO_LIBDIR);
1010 strcat(agentarg, "/libjdwp.so=");
1011 strcat(agentarg, &opt_arg[1]);
1028 c = opt_arg[strlen(opt_arg) - 1];
1030 if ((c == 'k') || (c == 'K')) {
1031 j = atoi(opt_arg) * 1024;
1033 } else if ((c == 'm') || (c == 'M')) {
1034 j = atoi(opt_arg) * 1024 * 1024;
1040 opt_heapmaxsize = j;
1041 else if (opt == OPT_MS)
1042 opt_heapstartsize = j;
1053 if (strcmp("class", opt_arg) == 0) {
1054 opt_verboseclass = true;
1056 else if (strcmp("gc", opt_arg) == 0) {
1057 opt_verbosegc = true;
1059 else if (strcmp("jni", opt_arg) == 0) {
1060 opt_verbosejni = true;
1062 #if !defined(NDEBUG)
1063 else if (strcmp("jit", opt_arg) == 0) {
1067 compileverbose = true;
1069 else if (strcmp("threads", opt_arg) == 0) {
1070 opt_verbosethreads = true;
1074 printf("Unknown -verbose option: %s\n", opt_arg);
1079 case OPT_DEBUGCOLOR:
1080 opt_debugcolor = true;
1083 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1085 opt_typecheckverbose = true;
1094 case OPT_FULLVERSION:
1098 case OPT_SHOWVERSION:
1106 #if defined(ENABLE_VERIFIER)
1112 #if defined(ENABLE_STATISTICS)
1114 opt_getcompilingtime = true;
1115 opt_getloadingtime = true;
1128 for (i = 0; i < strlen(opt_arg); i++) {
1129 switch (opt_arg[i]) {
1131 checkbounds = false;
1144 makeinitializations = false;
1147 #if !defined(NDEBUG)
1151 makeinitializations = false;
1156 opt_method = opt_arg;
1157 makeinitializations = false;
1161 opt_signature = opt_arg;
1165 case OPT_SHOW: /* Display options */
1166 for (i = 0; i < strlen(opt_arg); i++) {
1167 switch (opt_arg[i]) {
1169 showconstantpool = true;
1181 opt_showintermediate = true;
1182 compileverbose = true;
1185 #if defined(ENABLE_DISASSEMBLER)
1187 opt_showdisassemble = true;
1188 compileverbose = true;
1192 opt_shownops = true;
1196 opt_showexceptionstubs = true;
1200 opt_shownativestub = true;
1205 opt_showddatasegment = true;
1214 #if defined(ENABLE_LOOP)
1220 #if defined(ENABLE_INLINING)
1221 #if defined(ENABLE_INLINING_DEBUG)
1222 case OPT_INLINE_DEBUG_ALL:
1223 opt_inline_debug_all = true;
1225 case OPT_INLINE_DEBUG_END:
1226 opt_inline_debug_end_counter = atoi(opt_arg);
1228 case OPT_INLINE_DEBUG_MIN:
1229 opt_inline_debug_min_size = atoi(opt_arg);
1231 case OPT_INLINE_DEBUG_MAX:
1232 opt_inline_debug_max_size = atoi(opt_arg);
1234 #endif /* defined(ENABLE_INLINING_DEBUG) */
1235 #if !defined(NDEBUG)
1236 case OPT_INLINE_LOG:
1237 opt_inline_debug_log = true;
1239 #endif /* !defined(NDEBUG) */
1242 opt_inlining = true;
1244 #endif /* defined(ENABLE_INLINING) */
1246 #if defined(ENABLE_IFCONV)
1252 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1267 options_xx(opt_arg);
1271 /* currently ignored */
1275 /* currently ignored */
1279 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1283 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1286 #if defined(ENABLE_PROFILING)
1287 case OPT_PROF_OPTION:
1288 /* use <= to get the last \0 too */
1290 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1291 if (opt_arg[i] == ',')
1294 if (opt_arg[i] == '\0') {
1295 if (strcmp("bb", opt_arg + j) == 0)
1299 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1303 /* set k to next char */
1316 #if defined(ENABLE_JIT)
1319 printf("-Xjit option not enabled.\n");
1325 #if defined(ENABLE_INTRP)
1328 printf("-Xint option not enabled.\n");
1333 #if defined(ENABLE_INTRP)
1334 case OPT_STATIC_SUPERS:
1335 opt_static_supers = atoi(opt_arg);
1338 case OPT_NO_DYNAMIC:
1339 opt_no_dynamic = true;
1342 case OPT_NO_REPLICATION:
1343 opt_no_replication = true;
1346 case OPT_NO_QUICKSUPER:
1347 opt_no_quicksuper = true;
1355 #if defined(ENABLE_DEBUG_FILTER)
1356 case OPT_FILTER_VERBOSECALL_INCLUDE:
1357 opt_filter_verbosecall_include = opt_arg;
1360 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1361 opt_filter_verbosecall_exclude = opt_arg;
1364 case OPT_FILTER_SHOW_METHOD:
1365 opt_filter_show_method = opt_arg;
1370 printf("Unknown option: %s\n",
1371 vm_args->options[opt_index].optionString);
1376 /* get the main class *****************************************************/
1378 if (opt_index < vm_args->nOptions) {
1379 mainstring = vm_args->options[opt_index++].optionString;
1381 /* Put the jar file into the classpath (if any). */
1383 if (opt_jar == true) {
1384 /* free old classpath */
1386 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1388 /* put jarfile into classpath */
1390 p = MNEW(char, strlen(mainstring) + strlen("0"));
1392 strcpy(p, mainstring);
1394 #if defined(ENABLE_JAVASE)
1395 properties_add("java.class.path", p);
1399 /* replace .'s with /'s in classname */
1401 for (i = strlen(mainstring) - 1; i >= 0; i--)
1402 if (mainstring[i] == '.')
1403 mainstring[i] = '/';
1407 #if defined(ENABLE_JVMTI)
1409 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1410 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1413 MFREE(agentarg, char, strlen(agentarg));
1415 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1419 /* initialize this JVM ****************************************************/
1421 vm_initializing = true;
1423 /* initialize the garbage collector */
1425 gc_init(opt_heapmaxsize, opt_heapstartsize);
1427 #if defined(ENABLE_THREADS)
1428 /* AFTER: gc_init (directly after, as this initializes the
1429 stopworldlock lock */
1434 /* install architecture dependent signal handlers */
1437 vm_abort("vm_create: signal_init failed");
1439 #if defined(ENABLE_INTRP)
1440 /* Allocate main thread stack on the Java heap. */
1443 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1444 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1448 /* AFTER: threads_preinit */
1451 vm_abort("vm_create: string_init failed");
1453 /* AFTER: threads_preinit */
1456 vm_abort("vm_create: utf8_init failed");
1458 /* AFTER: thread_preinit */
1461 vm_abort("vm_create: suck_init failed");
1463 suck_add_from_property("java.endorsed.dirs");
1465 /* Now we have all options handled and we can print the version
1468 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1473 /* AFTER: utf8_init */
1475 boot_class_path = properties_get("sun.boot.class.path");
1476 suck_add(boot_class_path);
1478 /* initialize the classcache hashtable stuff: lock, hashtable
1479 (must be done _after_ threads_preinit) */
1481 if (!classcache_init())
1482 vm_abort("vm_create: classcache_init failed");
1484 /* initialize the memory subsystem (must be done _after_
1488 vm_abort("vm_create: memory_init failed");
1490 /* initialize the finalizer stuff (must be done _after_
1493 if (!finalizer_init())
1494 vm_abort("vm_create: finalizer_init failed");
1496 /* initialize the codegen subsystems */
1500 /* initializes jit compiler */
1504 /* machine dependent initialization */
1506 #if defined(ENABLE_JIT)
1507 # if defined(ENABLE_INTRP)
1517 /* initialize the loader subsystems (must be done _after_
1521 vm_abort("vm_create: loader_init failed");
1523 /* Link some important VM classes. */
1524 /* AFTER: utf8_init */
1527 vm_abort("vm_create: linker_init failed");
1529 if (!primitive_init())
1530 vm_abort("vm_create: primitive_init failed");
1532 if (!exceptions_init())
1533 vm_abort("vm_create: exceptions_init failed");
1535 if (!builtin_init())
1536 vm_abort("vm_create: builtin_init failed");
1538 /* Initialize the native subsystem. */
1539 /* BEFORE: threads_init */
1542 vm_abort("vm_create: native_init failed");
1544 /* Register the native methods implemented in the VM. */
1545 /* BEFORE: threads_init */
1547 if (!nativevm_preinit())
1548 vm_abort("vm_create: nativevm_preinit failed");
1550 #if defined(ENABLE_JNI)
1551 /* Initialize the JNI subsystem (must be done _before_
1552 threads_init, as threads_init can call JNI methods
1553 (e.g. NewGlobalRef). */
1556 vm_abort("vm_create: jni_init failed");
1559 #if defined(ENABLE_THREADS)
1560 if (!threads_init())
1561 vm_abort("vm_create: threads_init failed");
1564 /* Initialize the native VM subsystem. */
1565 /* AFTER: threads_init (at least for SUN's classes) */
1567 if (!nativevm_init())
1568 vm_abort("vm_create: nativevm_init failed");
1570 #if defined(ENABLE_PROFILING)
1571 /* initialize profiling */
1573 if (!profile_init())
1574 vm_abort("vm_create: profile_init failed");
1577 #if defined(ENABLE_THREADS)
1578 /* initialize recompilation */
1580 if (!recompile_init())
1581 vm_abort("vm_create: recompile_init failed");
1583 /* start the signal handler thread */
1585 #if defined(__LINUX__)
1586 /* XXX Remove for exact-GC. */
1587 if (threads_pthreads_implementation_nptl)
1589 if (!signal_start_thread())
1590 vm_abort("vm_create: signal_start_thread failed");
1592 /* finally, start the finalizer thread */
1594 if (!finalizer_start_thread())
1595 vm_abort("vm_create: finalizer_start_thread failed");
1597 # if !defined(NDEBUG)
1598 /* start the memory profiling thread */
1600 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1601 if (!memory_start_thread())
1602 vm_abort("vm_create: memory_start_thread failed");
1605 /* start the recompilation thread (must be done before the
1606 profiling thread) */
1608 if (!recompile_start_thread())
1609 vm_abort("vm_create: recompile_start_thread failed");
1611 # if defined(ENABLE_PROFILING)
1612 /* start the profile sampling thread */
1615 /* if (!profile_start_thread()) */
1616 /* vm_abort("vm_create: profile_start_thread failed"); */
1620 #if defined(ENABLE_JVMTI)
1622 /* add agent library to native library hashtable */
1623 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1627 /* increment the number of VMs */
1631 /* initialization is done */
1633 vm_initializing = false;
1635 /* everything's ok */
1641 /* vm_run **********************************************************************
1643 Runs the main-method of the passed class.
1645 *******************************************************************************/
1647 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1650 classinfo *mainclass;
1653 java_handle_objectarray_t *oa;
1660 #if !defined(NDEBUG)
1666 if (opt_method != NULL) {
1667 vm_compile_method();
1670 #endif /* !defined(NDEBUG) */
1672 /* should we run the main-method? */
1674 if (mainstring == NULL)
1677 /* set return value to OK */
1681 if (opt_jar == true) {
1682 /* open jar file with java.util.jar.JarFile */
1684 mainstring = vm_get_mainclass_from_jar(mainstring);
1686 if (mainstring == NULL)
1690 /* load the main class */
1692 mainutf = utf_new_char(mainstring);
1694 #if defined(ENABLE_JAVAME_CLDC1_1)
1695 mainclass = load_class_bootstrap(mainutf);
1697 mainclass = load_class_from_sysloader(mainutf);
1700 /* error loading class */
1702 e = exceptions_get_and_clear_exception();
1704 if ((e != NULL) || (mainclass == NULL)) {
1705 exceptions_throw_noclassdeffounderror_cause(e);
1706 exceptions_print_stacktrace();
1710 if (!link_class(mainclass)) {
1711 exceptions_print_stacktrace();
1715 /* find the `main' method of the main class */
1717 m = class_resolveclassmethod(mainclass,
1718 utf_new_char("main"),
1719 utf_new_char("([Ljava/lang/String;)V"),
1720 class_java_lang_Object,
1723 if (exceptions_get_exception()) {
1724 exceptions_print_stacktrace();
1728 /* there is no main method or it isn't static */
1730 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1731 exceptions_clear_exception();
1732 exceptions_throw_nosuchmethoderror(mainclass,
1733 utf_new_char("main"),
1734 utf_new_char("([Ljava/lang/String;)V"));
1736 exceptions_print_stacktrace();
1740 /* build argument array */
1742 oalength = vm_args->nOptions - opt_index;
1744 oa = builtin_anewarray(oalength, class_java_lang_String);
1746 for (i = 0; i < oalength; i++) {
1747 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1748 s = javastring_new(u);
1750 LLNI_objectarray_element_set(oa, i, s);
1753 #ifdef TYPEINFO_DEBUG_TEST
1754 /* test the typeinfo system */
1757 /*class_showmethods(currentThread->group->header.vftbl->class); */
1759 #if defined(ENABLE_JVMTI)
1760 jvmti_set_phase(JVMTI_PHASE_LIVE);
1763 /* set ThreadMXBean variables */
1765 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1766 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1768 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1769 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1770 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1771 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1773 /* start the main thread */
1775 (void) vm_call_method(m, NULL, oa);
1777 /* exception occurred? */
1779 if (exceptions_get_exception()) {
1780 exceptions_print_stacktrace();
1784 /* unload the JavaVM */
1786 (void) vm_destroy(vm);
1794 /* vm_destroy ******************************************************************
1796 Unloads a Java VM and reclaims its resources.
1798 *******************************************************************************/
1800 s4 vm_destroy(JavaVM *vm)
1802 #if defined(ENABLE_THREADS)
1803 threads_join_all_threads();
1806 /* everything's ok */
1812 /* vm_exit *********************************************************************
1814 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1816 *******************************************************************************/
1818 void vm_exit(s4 status)
1822 /* signal that we are exiting */
1826 assert(class_java_lang_System);
1827 assert(class_java_lang_System->state & CLASS_LOADED);
1829 #if defined(ENABLE_JVMTI)
1830 if (jvmti || (dbgcom!=NULL)) {
1831 jvmti_set_phase(JVMTI_PHASE_DEAD);
1832 if (jvmti) jvmti_agentunload();
1836 if (!link_class(class_java_lang_System)) {
1837 exceptions_print_stacktrace();
1841 /* call java.lang.System.exit(I)V */
1843 m = class_resolveclassmethod(class_java_lang_System,
1844 utf_new_char("exit"),
1846 class_java_lang_Object,
1850 exceptions_print_stacktrace();
1854 /* call the exit function with passed exit status */
1856 (void) vm_call_method(m, NULL, status);
1858 /* If we had an exception, just ignore the exception and exit with
1861 vm_shutdown(status);
1865 /* vm_shutdown *****************************************************************
1867 Terminates the system immediately without freeing memory explicitly
1868 (to be used only for abnormal termination).
1870 *******************************************************************************/
1872 void vm_shutdown(s4 status)
1875 #if defined(ENABLE_STATISTICS)
1876 || opt_getcompilingtime || opt_stat
1880 log_text("CACAO terminated by shutdown");
1881 dolog("Exit status: %d\n", (s4) status);
1885 #if defined(ENABLE_JVMTI)
1886 /* terminate cacaodbgserver */
1888 pthread_mutex_lock(&dbgcomlock);
1890 pthread_mutex_unlock(&dbgcomlock);
1891 jvmti_cacaodbgserver_quit();
1899 /* vm_exit_handler *************************************************************
1901 The exit_handler function is called upon program termination.
1903 ATTENTION: Don't free system resources here! Some threads may still
1904 be running as this is called from VMRuntime.exit(). The OS does the
1907 *******************************************************************************/
1909 void vm_exit_handler(void)
1911 #if !defined(NDEBUG)
1913 class_showmethods(mainclass);
1915 if (showconstantpool)
1916 class_showconstantpool(mainclass);
1921 # if defined(ENABLE_PROFILING)
1923 profile_printstats();
1925 #endif /* !defined(NDEBUG) */
1927 #if defined(ENABLE_RT_TIMING)
1928 rt_timing_print_time_stats(stderr);
1931 #if defined(ENABLE_CYCLES_STATS)
1932 builtin_print_cycles_stats(stderr);
1933 stacktrace_print_cycles_stats(stderr);
1937 #if defined(ENABLE_STATISTICS)
1938 || opt_getcompilingtime || opt_stat
1942 log_text("CACAO terminated");
1944 #if defined(ENABLE_STATISTICS)
1947 #ifdef TYPECHECK_STATISTICS
1948 typecheck_print_statistics(get_logfile());
1952 if (opt_getcompilingtime)
1954 #endif /* defined(ENABLE_STATISTICS) */
1956 /* vm_print_profile(stderr);*/
1960 /* vm_abort ********************************************************************
1962 Prints an error message and aborts the VM.
1964 *******************************************************************************/
1966 void vm_abort(const char *text, ...)
1970 /* print the log message */
1975 log_vprint(text, ap);
1980 /* now abort the VM */
1986 /* vm_get_mainclass_from_jar ***************************************************
1988 Gets the name of the main class from a JAR's manifest file.
1990 *******************************************************************************/
1992 static char *vm_get_mainclass_from_jar(char *mainstring)
1999 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2002 exceptions_print_stacktrace();
2006 /* create JarFile object */
2011 exceptions_print_stacktrace();
2015 m = class_resolveclassmethod(c,
2017 utf_java_lang_String__void,
2018 class_java_lang_Object,
2022 exceptions_print_stacktrace();
2026 s = javastring_new_from_ascii(mainstring);
2028 (void) vm_call_method(m, o, s);
2030 if (exceptions_get_exception()) {
2031 exceptions_print_stacktrace();
2035 /* get manifest object */
2037 m = class_resolveclassmethod(c,
2038 utf_new_char("getManifest"),
2039 utf_new_char("()Ljava/util/jar/Manifest;"),
2040 class_java_lang_Object,
2044 exceptions_print_stacktrace();
2048 o = vm_call_method(m, o);
2051 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2056 /* get Main Attributes */
2058 m = class_resolveclassmethod(o->vftbl->class,
2059 utf_new_char("getMainAttributes"),
2060 utf_new_char("()Ljava/util/jar/Attributes;"),
2061 class_java_lang_Object,
2065 exceptions_print_stacktrace();
2069 o = vm_call_method(m, o);
2072 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2077 /* get property Main-Class */
2079 m = class_resolveclassmethod(o->vftbl->class,
2080 utf_new_char("getValue"),
2081 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2082 class_java_lang_Object,
2086 exceptions_print_stacktrace();
2090 s = javastring_new_from_ascii("Main-Class");
2092 o = vm_call_method(m, o, s);
2095 exceptions_print_stacktrace();
2099 return javastring_tochar(o);
2103 /* vm_compile_all **************************************************************
2105 Compile all methods found in the bootclasspath.
2107 *******************************************************************************/
2109 #if !defined(NDEBUG)
2110 static void vm_compile_all(void)
2115 classcache_name_entry *nmen;
2116 classcache_class_entry *clsen;
2119 /* create all classes found in the bootclasspath */
2120 /* XXX currently only works with zip/jar's */
2122 loader_load_all_classes();
2124 /* link all classes */
2126 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2127 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2129 for (; nmen; nmen = nmen->hashlink) {
2130 /* iterate over all class entries */
2132 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2133 c = clsen->classobj;
2138 if (!(c->state & CLASS_LINKED)) {
2139 if (!link_class(c)) {
2140 fprintf(stderr, "Error linking: ");
2141 utf_fprint_printable_ascii_classname(stderr, c->name);
2142 fprintf(stderr, "\n");
2144 /* print out exception and cause */
2146 exceptions_print_current_exception();
2148 /* goto next class */
2154 /* compile all class methods */
2156 for (i = 0; i < c->methodscount; i++) {
2157 m = &(c->methods[i]);
2159 if (m->jcode != NULL) {
2160 if (!jit_compile(m)) {
2161 fprintf(stderr, "Error compiling: ");
2162 utf_fprint_printable_ascii_classname(stderr, c->name);
2163 fprintf(stderr, ".");
2164 utf_fprint_printable_ascii(stderr, m->name);
2165 utf_fprint_printable_ascii(stderr, m->descriptor);
2166 fprintf(stderr, "\n");
2168 /* print out exception and cause */
2170 exceptions_print_current_exception();
2178 #endif /* !defined(NDEBUG) */
2181 /* vm_compile_method ***********************************************************
2183 Compile a specific method.
2185 *******************************************************************************/
2187 #if !defined(NDEBUG)
2188 static void vm_compile_method(void)
2192 /* create, load and link the main class */
2194 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2196 if (mainclass == NULL)
2197 exceptions_print_stacktrace();
2199 if (!link_class(mainclass))
2200 exceptions_print_stacktrace();
2202 if (opt_signature != NULL) {
2203 m = class_resolveclassmethod(mainclass,
2204 utf_new_char(opt_method),
2205 utf_new_char(opt_signature),
2210 m = class_resolveclassmethod(mainclass,
2211 utf_new_char(opt_method),
2218 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2219 opt_method, opt_signature ? opt_signature : "");
2223 #endif /* !defined(NDEBUG) */
2226 /* vm_array_store_int **********************************************************
2228 Helper function to store an integer into the argument array, taking
2229 care of architecture specific issues.
2231 *******************************************************************************/
2233 static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
2237 if (!pd->inmemory) {
2239 array[index] = (int64_t) value;
2242 index = ARG_CNT + pd->index;
2243 #if SIZEOF_VOID_P == 8
2244 array[index] = (int64_t) value;
2246 # if WORDS_BIGENDIAN == 1
2247 array[index] = ((int64_t) value) << 32;
2249 array[index] = (int64_t) value;
2256 /* vm_array_store_lng **********************************************************
2258 Helper function to store a long into the argument array, taking
2259 care of architecture specific issues.
2261 *******************************************************************************/
2263 static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
2267 #if SIZEOF_VOID_P == 8
2271 index = ARG_CNT + pd->index;
2273 array[index] = value;
2275 if (!pd->inmemory) {
2276 /* move low and high 32-bits into it's own argument slot */
2278 index = GET_LOW_REG(pd->index);
2279 array[index] = value & 0x00000000ffffffff;
2281 index = GET_HIGH_REG(pd->index);
2282 array[index] = value >> 32;
2285 index = ARG_CNT + pd->index;
2286 array[index] = value;
2292 /* vm_array_store_flt **********************************************************
2294 Helper function to store a float into the argument array, taking
2295 care of architecture specific issues.
2297 *******************************************************************************/
2299 static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
2303 if (!pd->inmemory) {
2304 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2307 index = INT_ARG_CNT + pd->index;
2309 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC__) && !defined(__POWERPC64__) && !defined(__S390__)
2310 array[index] = value >> 32;
2312 array[index] = value;
2316 index = ARG_CNT + pd->index;
2317 #if defined(__SPARC_64__)
2318 array[index] = value >> 32;
2320 array[index] = value;
2326 /* vm_array_store_dbl **********************************************************
2328 Helper function to store a double into the argument array, taking
2329 care of architecture specific issues.
2331 *******************************************************************************/
2333 static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
2337 if (!pd->inmemory) {
2338 #if SIZEOF_VOID_P != 8 && defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2339 index = GET_LOW_REG(pd->index);
2340 array[index] = value & 0x00000000ffffffff;
2342 index = GET_HIGH_REG(pd->index);
2343 array[index] = value >> 32;
2345 index = INT_ARG_CNT + pd->index;
2346 array[index] = value;
2350 index = ARG_CNT + pd->index;
2351 array[index] = value;
2356 /* vm_array_store_adr **********************************************************
2358 Helper function to store an address into the argument array, taking
2359 care of architecture specific issues.
2361 *******************************************************************************/
2363 static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
2367 if (!pd->inmemory) {
2368 #if defined(HAS_ADDRESS_REGISTER_FILE)
2369 /* When the architecture has address registers, place them
2370 after integer and float registers. */
2372 index = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
2376 array[index] = (uint64_t) (intptr_t) value;
2379 index = ARG_CNT + pd->index;
2380 #if SIZEOF_VOID_P == 8
2381 array[index] = (uint64_t) (intptr_t) value;
2383 # if WORDS_BIGENDIAN == 1
2384 array[index] = ((uint64_t) (intptr_t) value) << 32;
2386 array[index] = (uint64_t) (intptr_t) value;
2393 /* vm_array_from_valist ********************************************************
2397 *******************************************************************************/
2399 uint64_t *vm_array_from_valist(methodinfo *m, java_object_t *o, va_list ap)
2408 /* get the descriptors */
2412 td = md->paramtypes;
2414 /* allocate argument array */
2416 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2418 /* if method is non-static fill first block and skip `this' pointer */
2423 /* the `this' pointer */
2424 vm_array_store_adr(array, pd, o);
2431 for (; i < md->paramcount; i++, pd++, td++) {
2434 value.i = va_arg(ap, int32_t);
2435 vm_array_store_int(array, pd, value.i);
2439 value.l = va_arg(ap, int64_t);
2440 vm_array_store_lng(array, pd, value.l);
2444 #if defined(__ALPHA__) || defined(__POWERPC__) || defined(__POWERPC64__)
2445 /* This is required to load the correct float value in
2448 value.d = (double) va_arg(ap, double);
2450 value.f = (float) va_arg(ap, double);
2452 vm_array_store_flt(array, pd, value.l);
2456 value.d = va_arg(ap, double);
2457 vm_array_store_dbl(array, pd, value.l);
2461 value.a = va_arg(ap, void*);
2462 vm_array_store_adr(array, pd, value.a);
2471 /* vm_array_from_jvalue ********************************************************
2475 *******************************************************************************/
2477 static uint64_t *vm_array_from_jvalue(methodinfo *m, java_object_t *o,
2487 /* get the descriptors */
2491 td = md->paramtypes;
2493 /* allocate argument array */
2495 #if defined(HAS_ADDRESS_REGISTER_FILE)
2496 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
2498 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2501 /* if method is non-static fill first block and skip `this' pointer */
2506 /* the `this' pointer */
2507 vm_array_store_adr(array, pd, o);
2514 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2515 switch (td->decltype) {
2517 vm_array_store_int(array, pd, args[j].i);
2521 vm_array_store_lng(array, pd, args[j].j);
2525 vm_array_store_flt(array, pd, args[j].j);
2529 vm_array_store_dbl(array, pd, args[j].j);
2533 vm_array_store_adr(array, pd, args[j].l);
2542 /* vm_array_from_objectarray ***************************************************
2546 *******************************************************************************/
2548 uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
2549 java_handle_objectarray_t *params)
2555 java_handle_t *param;
2562 /* get the descriptors */
2566 td = md->paramtypes;
2568 /* allocate argument array */
2570 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2572 /* if method is non-static fill first block and skip `this' pointer */
2578 vm_array_store_adr(array, pd, o);
2585 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2586 LLNI_objectarray_element_get(params, j, param);
2593 /* convert the value according to its declared type */
2595 c = param->vftbl->class;
2596 type = primitive_type_get_by_wrapperclass(c);
2598 switch (td->decltype) {
2599 case PRIMITIVETYPE_BOOLEAN:
2601 case PRIMITIVETYPE_BOOLEAN:
2602 /* This type is OK. */
2609 case PRIMITIVETYPE_BYTE:
2611 case PRIMITIVETYPE_BYTE:
2612 /* This type is OK. */
2619 case PRIMITIVETYPE_CHAR:
2621 case PRIMITIVETYPE_CHAR:
2622 /* This type is OK. */
2629 case PRIMITIVETYPE_SHORT:
2631 case PRIMITIVETYPE_BYTE:
2632 case PRIMITIVETYPE_SHORT:
2633 /* These types are OK. */
2640 case PRIMITIVETYPE_INT:
2642 case PRIMITIVETYPE_BYTE:
2643 case PRIMITIVETYPE_SHORT:
2644 case PRIMITIVETYPE_INT:
2645 /* These types are OK. */
2653 vm_abort("vm_array_from_objectarray: invalid type %d",
2657 value = primitive_unbox(param);
2658 vm_array_store_int(array, pd, value.i);
2665 c = param->vftbl->class;
2666 type = primitive_type_get_by_wrapperclass(c);
2668 assert(td->decltype == PRIMITIVETYPE_LONG);
2671 case PRIMITIVETYPE_BYTE:
2672 case PRIMITIVETYPE_SHORT:
2673 case PRIMITIVETYPE_INT:
2674 case PRIMITIVETYPE_LONG:
2675 /* These types are OK. */
2681 value = primitive_unbox(param);
2682 vm_array_store_lng(array, pd, value.l);
2689 c = param->vftbl->class;
2690 type = primitive_type_get_by_wrapperclass(c);
2692 assert(td->decltype == PRIMITIVETYPE_FLOAT);
2695 case PRIMITIVETYPE_FLOAT:
2696 /* This type is OK. */
2702 value = primitive_unbox(param);
2703 vm_array_store_flt(array, pd, value.l);
2710 c = param->vftbl->class;
2711 type = primitive_type_get_by_wrapperclass(c);
2713 assert(td->decltype == PRIMITIVETYPE_DOUBLE);
2716 case PRIMITIVETYPE_FLOAT:
2717 case PRIMITIVETYPE_DOUBLE:
2718 /* These types are OK. */
2724 value = primitive_unbox(param);
2725 vm_array_store_dbl(array, pd, value.l);
2729 if (!resolve_class_from_typedesc(td, true, true, &c))
2732 if (param != NULL) {
2733 if (td->arraydim > 0) {
2734 if (!builtin_arrayinstanceof(param, c))
2738 if (!builtin_instanceof(param, c))
2743 vm_array_store_adr(array, pd, param);
2747 vm_abort("vm_array_from_objectarray: invalid type %d", td->type);
2754 exceptions_throw_illegalargumentexception();
2759 /* vm_call_method **************************************************************
2761 Calls a Java method with a variable number of arguments.
2763 *******************************************************************************/
2765 #define VM_CALL_METHOD(name, type) \
2766 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2772 value = vm_call_method##name##_valist(m, o, ap); \
2778 VM_CALL_METHOD(, java_handle_t *)
2779 VM_CALL_METHOD(_int, int32_t)
2780 VM_CALL_METHOD(_long, int64_t)
2781 VM_CALL_METHOD(_float, float)
2782 VM_CALL_METHOD(_double, double)
2785 /* vm_call_method_valist *******************************************************
2787 Calls a Java method with a variable number of arguments, passed via
2790 *******************************************************************************/
2792 #define VM_CALL_METHOD_VALIST(name, type) \
2793 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2800 dumpsize = dump_size(); \
2801 array = vm_array_from_valist(m, o, ap); \
2802 value = vm_call##name##_array(m, array); \
2803 dump_release(dumpsize); \
2808 VM_CALL_METHOD_VALIST(, java_handle_t *)
2809 VM_CALL_METHOD_VALIST(_int, int32_t)
2810 VM_CALL_METHOD_VALIST(_long, int64_t)
2811 VM_CALL_METHOD_VALIST(_float, float)
2812 VM_CALL_METHOD_VALIST(_double, double)
2815 /* vm_call_method_jvalue *******************************************************
2817 Calls a Java method with a variable number of arguments, passed via
2820 *******************************************************************************/
2822 #define VM_CALL_METHOD_JVALUE(name, type) \
2823 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2824 const jvalue *args) \
2830 dumpsize = dump_size(); \
2831 array = vm_array_from_jvalue(m, o, args); \
2832 value = vm_call##name##_array(m, array); \
2833 dump_release(dumpsize); \
2838 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2839 VM_CALL_METHOD_JVALUE(_int, int32_t)
2840 VM_CALL_METHOD_JVALUE(_long, int64_t)
2841 VM_CALL_METHOD_JVALUE(_float, float)
2842 VM_CALL_METHOD_JVALUE(_double, double)
2845 /* vm_call_array ***************************************************************
2847 Calls a Java method with a variable number of arguments, passed via
2850 *******************************************************************************/
2852 #define VM_CALL_ARRAY(name, type) \
2853 type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2859 md = m->parseddesc; \
2861 if (m->code == NULL) \
2862 if (!jit_compile(m)) \
2865 pv = m->code->entrypoint; \
2867 STATISTICS(count_calls_native_to_java++); \
2869 value = asm_vm_call_method##name(pv, array, md->memuse); \
2874 VM_CALL_ARRAY(, java_handle_t *)
2875 VM_CALL_ARRAY(_int, int32_t)
2876 VM_CALL_ARRAY(_long, int64_t)
2877 VM_CALL_ARRAY(_float, float)
2878 VM_CALL_ARRAY(_double, double)
2882 * These are local overrides for various environment variables in Emacs.
2883 * Please do not remove this and leave it at the end of the file, where
2884 * Emacs will automagically detect them.
2885 * ---------------------------------------------------------------------
2888 * indent-tabs-mode: t