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 8404 2007-08-22 21:34:24Z 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);
657 #if defined(WITH_JRE_LAYOUT)
658 /* When we're building with JRE-layout, the default paths are the
659 same as the runtime paths. */
661 # if defined(WITH_CLASSPATH_GNU)
662 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
663 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
664 # elif defined(WITH_CLASSPATH_SUN)
665 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
666 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
672 puts("Runtime variables:\n");
673 printf(" maximum heap size : %d\n", opt_heapmaxsize);
674 printf(" initial heap size : %d\n", opt_heapstartsize);
675 printf(" stack size : %d\n", opt_stacksize);
677 #if defined(WITH_CLASSPATH_GNU)
678 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
679 #elif defined(WITH_CLASSPATH_SUN)
680 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
683 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
684 printf(" java.class.path : %s\n", properties_get("java.class.path"));
688 /* forward declarations *******************************************************/
690 static char *vm_get_mainclass_from_jar(char *mainstring);
692 static void vm_compile_all(void);
693 static void vm_compile_method(void);
697 /* vm_createjvm ****************************************************************
699 Implementation for JNI_CreateJavaVM.
701 *******************************************************************************/
703 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
705 JavaVMInitArgs *_vm_args;
709 /* get the arguments for the new JVM */
711 _vm_args = (JavaVMInitArgs *) vm_args;
713 /* get the VM and Env tables (must be set before vm_create) */
715 env = NEW(_Jv_JNIEnv);
717 #if defined(ENABLE_JNI)
718 env->env = &_Jv_JNINativeInterface;
721 /* XXX Set the global variable. Maybe we should do that differently. */
725 /* create and fill a JavaVM structure */
727 vm = NEW(_Jv_JavaVM);
729 #if defined(ENABLE_JNI)
730 vm->functions = &_Jv_JNIInvokeInterface;
733 /* XXX Set the global variable. Maybe we should do that differently. */
734 /* XXX JVMTI Agents needs a JavaVM */
738 /* actually create the JVM */
740 if (!vm_create(_vm_args))
743 #if defined(ENABLE_JNI)
744 /* setup the local ref table (must be created after vm_create) */
746 if (!localref_table_init())
750 /* now return the values */
752 *p_vm = (JavaVM *) vm;
753 *p_env = (void *) env;
758 /* release allocated memory */
760 FREE(env, _Jv_JNIEnv);
761 FREE(vm, _Jv_JavaVM);
767 /* vm_create *******************************************************************
769 Creates a JVM. Called by vm_createjvm.
771 *******************************************************************************/
773 bool vm_create(JavaVMInitArgs *vm_args)
777 char *boot_class_path;
784 #if defined(ENABLE_JVMTI)
786 char *libname, *agentarg;
787 bool jdwp,agentbypath;
788 jdwp = agentbypath = false;
791 #if defined(ENABLE_VMLOG)
792 vmlog_cacao_init(vm_args);
795 /* check the JNI version requested */
797 switch (vm_args->version) {
798 case JNI_VERSION_1_1:
800 case JNI_VERSION_1_2:
801 case JNI_VERSION_1_4:
807 /* we only support 1 JVM instance */
812 if (atexit(vm_exit_handler))
813 vm_abort("atexit failed: %s\n", strerror(errno));
816 log_text("CACAO started -------------------------------------------------------");
818 /* We need to check if the actual size of a java.lang.Class object
819 is smaller or equal than the assumption made in
820 src/vmcore/class.h. */
822 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
823 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
825 /* set the VM starttime */
827 _Jv_jvm->starttime = builtin_currenttimemillis();
829 /* interpret the options **************************************************/
836 opt_heapmaxsize = HEAP_MAXSIZE;
837 opt_heapstartsize = HEAP_STARTSIZE;
838 opt_stacksize = STACK_SIZE;
841 #if defined(ENABLE_JVMTI)
842 /* initialize JVMTI related **********************************************/
846 /* Initialize and fill properties before command-line handling. */
851 /* iterate over all passed options */
853 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
867 #if SIZEOF_VOID_P == 8
868 puts("Running a 32-bit JVM is not supported on this platform.");
874 #if SIZEOF_VOID_P == 4
875 puts("Running a 64-bit JVM is not supported on this platform.");
881 /* Forget old classpath and set the argument as new
884 class_path = properties_get("java.class.path");
886 p = MNEW(char, strlen(opt_arg) + strlen("0"));
890 #if defined(ENABLE_JAVASE)
891 properties_add("java.class.path", p);
894 MFREE(class_path, char, strlen(class_path));
898 for (i = 0; i < strlen(opt_arg); i++) {
899 if (opt_arg[i] == '=') {
901 properties_add(opt_arg, opt_arg + i + 1);
906 /* if no '=' is given, just create an empty property */
908 properties_add(opt_arg, "");
913 case OPT_BOOTCLASSPATH:
914 /* Forget default bootclasspath and set the argument as
915 new boot classpath. */
917 boot_class_path = properties_get("sun.boot.class.path");
919 p = MNEW(char, strlen(opt_arg) + strlen("0"));
923 properties_add("sun.boot.class.path", p);
924 properties_add("java.boot.class.path", p);
926 MFREE(boot_class_path, char, strlen(boot_class_path));
929 case OPT_BOOTCLASSPATH_A:
930 /* Append to bootclasspath. */
932 boot_class_path = properties_get("sun.boot.class.path");
934 len = strlen(boot_class_path);
936 p = MREALLOC(boot_class_path,
940 strlen(opt_arg) + strlen("0"));
945 properties_add("sun.boot.class.path", p);
946 properties_add("java.boot.class.path", p);
949 case OPT_BOOTCLASSPATH_P:
950 /* Prepend to bootclasspath. */
952 boot_class_path = properties_get("sun.boot.class.path");
954 len = strlen(boot_class_path);
956 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
960 strcat(p, boot_class_path);
962 properties_add("sun.boot.class.path", p);
963 properties_add("java.boot.class.path", p);
965 MFREE(boot_class_path, char, len);
968 case OPT_BOOTCLASSPATH_C:
969 /* Use as Java core library, but prepend VM interface
972 boot_class_path = properties_get("sun.boot.class.path");
975 strlen(CACAO_VM_ZIP) +
982 strcpy(p, CACAO_VM_ZIP);
986 properties_add("sun.boot.class.path", p);
987 properties_add("java.boot.class.path", p);
989 MFREE(boot_class_path, char, strlen(boot_class_path));
992 #if defined(ENABLE_JVMTI)
994 /* this option exists only for compatibility reasons */
998 /* I don't know yet what Xnoagent should do. This is only for
999 compatiblity with eclipse - motse */
1008 strlen(CACAO_LIBDIR) +
1009 strlen("/libjdwp.so=") +
1013 agentarg = MNEW(char, len);
1015 strcpy(agentarg, CACAO_LIBDIR);
1016 strcat(agentarg, "/libjdwp.so=");
1017 strcat(agentarg, &opt_arg[1]);
1034 c = opt_arg[strlen(opt_arg) - 1];
1036 if ((c == 'k') || (c == 'K')) {
1037 j = atoi(opt_arg) * 1024;
1039 } else if ((c == 'm') || (c == 'M')) {
1040 j = atoi(opt_arg) * 1024 * 1024;
1046 opt_heapmaxsize = j;
1047 else if (opt == OPT_MS)
1048 opt_heapstartsize = j;
1059 if (strcmp("class", opt_arg) == 0) {
1060 opt_verboseclass = true;
1062 else if (strcmp("gc", opt_arg) == 0) {
1063 opt_verbosegc = true;
1065 else if (strcmp("jni", opt_arg) == 0) {
1066 opt_verbosejni = true;
1068 #if !defined(NDEBUG)
1069 else if (strcmp("jit", opt_arg) == 0) {
1073 compileverbose = true;
1075 else if (strcmp("threads", opt_arg) == 0) {
1076 opt_verbosethreads = true;
1080 printf("Unknown -verbose option: %s\n", opt_arg);
1085 case OPT_DEBUGCOLOR:
1086 opt_debugcolor = true;
1089 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1091 opt_typecheckverbose = true;
1100 case OPT_FULLVERSION:
1104 case OPT_SHOWVERSION:
1112 #if defined(ENABLE_VERIFIER)
1118 #if defined(ENABLE_STATISTICS)
1120 opt_getcompilingtime = true;
1121 opt_getloadingtime = true;
1134 for (i = 0; i < strlen(opt_arg); i++) {
1135 switch (opt_arg[i]) {
1137 checkbounds = false;
1150 makeinitializations = false;
1153 #if !defined(NDEBUG)
1157 makeinitializations = false;
1162 opt_method = opt_arg;
1163 makeinitializations = false;
1167 opt_signature = opt_arg;
1171 case OPT_SHOW: /* Display options */
1172 for (i = 0; i < strlen(opt_arg); i++) {
1173 switch (opt_arg[i]) {
1175 showconstantpool = true;
1187 opt_showintermediate = true;
1188 compileverbose = true;
1191 #if defined(ENABLE_DISASSEMBLER)
1193 opt_showdisassemble = true;
1194 compileverbose = true;
1198 opt_shownops = true;
1202 opt_showexceptionstubs = true;
1206 opt_shownativestub = true;
1211 opt_showddatasegment = true;
1220 #if defined(ENABLE_LOOP)
1226 #if defined(ENABLE_INLINING)
1227 #if defined(ENABLE_INLINING_DEBUG)
1228 case OPT_INLINE_DEBUG_ALL:
1229 opt_inline_debug_all = true;
1231 case OPT_INLINE_DEBUG_END:
1232 opt_inline_debug_end_counter = atoi(opt_arg);
1234 case OPT_INLINE_DEBUG_MIN:
1235 opt_inline_debug_min_size = atoi(opt_arg);
1237 case OPT_INLINE_DEBUG_MAX:
1238 opt_inline_debug_max_size = atoi(opt_arg);
1240 #endif /* defined(ENABLE_INLINING_DEBUG) */
1241 #if !defined(NDEBUG)
1242 case OPT_INLINE_LOG:
1243 opt_inline_debug_log = true;
1245 #endif /* !defined(NDEBUG) */
1248 opt_inlining = true;
1250 #endif /* defined(ENABLE_INLINING) */
1252 #if defined(ENABLE_IFCONV)
1258 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1273 options_xx(opt_arg);
1277 /* currently ignored */
1281 /* currently ignored */
1285 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1289 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1292 #if defined(ENABLE_PROFILING)
1293 case OPT_PROF_OPTION:
1294 /* use <= to get the last \0 too */
1296 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1297 if (opt_arg[i] == ',')
1300 if (opt_arg[i] == '\0') {
1301 if (strcmp("bb", opt_arg + j) == 0)
1305 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1309 /* set k to next char */
1322 #if defined(ENABLE_JIT)
1325 printf("-Xjit option not enabled.\n");
1331 #if defined(ENABLE_INTRP)
1334 printf("-Xint option not enabled.\n");
1339 #if defined(ENABLE_INTRP)
1340 case OPT_STATIC_SUPERS:
1341 opt_static_supers = atoi(opt_arg);
1344 case OPT_NO_DYNAMIC:
1345 opt_no_dynamic = true;
1348 case OPT_NO_REPLICATION:
1349 opt_no_replication = true;
1352 case OPT_NO_QUICKSUPER:
1353 opt_no_quicksuper = true;
1361 #if defined(ENABLE_DEBUG_FILTER)
1362 case OPT_FILTER_VERBOSECALL_INCLUDE:
1363 opt_filter_verbosecall_include = opt_arg;
1366 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1367 opt_filter_verbosecall_exclude = opt_arg;
1370 case OPT_FILTER_SHOW_METHOD:
1371 opt_filter_show_method = opt_arg;
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 p = MNEW(char, strlen(mainstring) + strlen("0"));
1398 strcpy(p, mainstring);
1400 #if defined(ENABLE_JAVASE)
1401 properties_add("java.class.path", p);
1405 /* replace .'s with /'s in classname */
1407 for (i = strlen(mainstring) - 1; i >= 0; i--)
1408 if (mainstring[i] == '.')
1409 mainstring[i] = '/';
1413 #if defined(ENABLE_JVMTI)
1415 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1416 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1419 MFREE(agentarg, char, strlen(agentarg));
1421 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1425 /* initialize this JVM ****************************************************/
1427 vm_initializing = true;
1429 /* initialize the garbage collector */
1431 gc_init(opt_heapmaxsize, opt_heapstartsize);
1433 #if defined(ENABLE_THREADS)
1434 /* AFTER: gc_init (directly after, as this initializes the
1435 stopworldlock lock */
1440 /* install architecture dependent signal handlers */
1443 vm_abort("vm_create: signal_init failed");
1445 #if defined(ENABLE_INTRP)
1446 /* Allocate main thread stack on the Java heap. */
1449 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1450 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1454 /* AFTER: threads_preinit */
1457 vm_abort("vm_create: string_init failed");
1459 /* AFTER: threads_preinit */
1462 vm_abort("vm_create: utf8_init failed");
1464 /* AFTER: thread_preinit */
1467 vm_abort("vm_create: suck_init failed");
1469 suck_add_from_property("java.endorsed.dirs");
1471 /* Now we have all options handled and we can print the version
1474 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1479 /* AFTER: utf8_init */
1481 boot_class_path = properties_get("sun.boot.class.path");
1482 suck_add(boot_class_path);
1484 /* initialize the classcache hashtable stuff: lock, hashtable
1485 (must be done _after_ threads_preinit) */
1487 if (!classcache_init())
1488 vm_abort("vm_create: classcache_init failed");
1490 /* initialize the memory subsystem (must be done _after_
1494 vm_abort("vm_create: memory_init failed");
1496 /* initialize the finalizer stuff (must be done _after_
1499 if (!finalizer_init())
1500 vm_abort("vm_create: finalizer_init failed");
1502 /* initialize the codegen subsystems */
1506 /* initializes jit compiler */
1510 /* machine dependent initialization */
1512 #if defined(ENABLE_JIT)
1513 # if defined(ENABLE_INTRP)
1523 /* initialize the loader subsystems (must be done _after_
1527 vm_abort("vm_create: loader_init failed");
1529 /* Link some important VM classes. */
1530 /* AFTER: utf8_init */
1533 vm_abort("vm_create: linker_init failed");
1535 if (!primitive_init())
1536 vm_abort("vm_create: primitive_init failed");
1538 if (!exceptions_init())
1539 vm_abort("vm_create: exceptions_init failed");
1541 if (!builtin_init())
1542 vm_abort("vm_create: builtin_init failed");
1544 /* Initialize the native subsystem. */
1545 /* BEFORE: threads_init */
1548 vm_abort("vm_create: native_init failed");
1550 /* Register the native methods implemented in the VM. */
1551 /* BEFORE: threads_init */
1553 if (!nativevm_preinit())
1554 vm_abort("vm_create: nativevm_preinit failed");
1556 #if defined(ENABLE_JNI)
1557 /* Initialize the JNI subsystem (must be done _before_
1558 threads_init, as threads_init can call JNI methods
1559 (e.g. NewGlobalRef). */
1562 vm_abort("vm_create: jni_init failed");
1565 #if defined(ENABLE_THREADS)
1566 if (!threads_init())
1567 vm_abort("vm_create: threads_init failed");
1570 /* Initialize the native VM subsystem. */
1571 /* AFTER: threads_init (at least for SUN's classes) */
1573 if (!nativevm_init())
1574 vm_abort("vm_create: nativevm_init failed");
1576 #if defined(ENABLE_PROFILING)
1577 /* initialize profiling */
1579 if (!profile_init())
1580 vm_abort("vm_create: profile_init failed");
1583 #if defined(ENABLE_THREADS)
1584 /* initialize recompilation */
1586 if (!recompile_init())
1587 vm_abort("vm_create: recompile_init failed");
1589 /* start the signal handler thread */
1591 #if defined(__LINUX__)
1592 /* XXX Remove for exact-GC. */
1593 if (threads_pthreads_implementation_nptl)
1595 if (!signal_start_thread())
1596 vm_abort("vm_create: signal_start_thread failed");
1598 /* finally, start the finalizer thread */
1600 if (!finalizer_start_thread())
1601 vm_abort("vm_create: finalizer_start_thread failed");
1603 # if !defined(NDEBUG)
1604 /* start the memory profiling thread */
1606 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1607 if (!memory_start_thread())
1608 vm_abort("vm_create: memory_start_thread failed");
1611 /* start the recompilation thread (must be done before the
1612 profiling thread) */
1614 if (!recompile_start_thread())
1615 vm_abort("vm_create: recompile_start_thread failed");
1617 # if defined(ENABLE_PROFILING)
1618 /* start the profile sampling thread */
1621 /* if (!profile_start_thread()) */
1622 /* vm_abort("vm_create: profile_start_thread failed"); */
1626 #if defined(ENABLE_JVMTI)
1628 /* add agent library to native library hashtable */
1629 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1633 /* increment the number of VMs */
1637 /* initialization is done */
1639 vm_initializing = false;
1641 /* everything's ok */
1647 /* vm_run **********************************************************************
1649 Runs the main-method of the passed class.
1651 *******************************************************************************/
1653 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1656 classinfo *mainclass;
1659 java_handle_objectarray_t *oa;
1666 #if !defined(NDEBUG)
1672 if (opt_method != NULL) {
1673 vm_compile_method();
1676 #endif /* !defined(NDEBUG) */
1678 /* should we run the main-method? */
1680 if (mainstring == NULL)
1683 /* set return value to OK */
1687 if (opt_jar == true) {
1688 /* open jar file with java.util.jar.JarFile */
1690 mainstring = vm_get_mainclass_from_jar(mainstring);
1692 if (mainstring == NULL)
1696 /* load the main class */
1698 mainutf = utf_new_char(mainstring);
1700 #if defined(ENABLE_JAVAME_CLDC1_1)
1701 mainclass = load_class_bootstrap(mainutf);
1703 mainclass = load_class_from_sysloader(mainutf);
1706 /* error loading class */
1708 e = exceptions_get_and_clear_exception();
1710 if ((e != NULL) || (mainclass == NULL)) {
1711 exceptions_throw_noclassdeffounderror_cause(e);
1712 exceptions_print_stacktrace();
1716 if (!link_class(mainclass)) {
1717 exceptions_print_stacktrace();
1721 /* find the `main' method of the main class */
1723 m = class_resolveclassmethod(mainclass,
1724 utf_new_char("main"),
1725 utf_new_char("([Ljava/lang/String;)V"),
1726 class_java_lang_Object,
1729 if (exceptions_get_exception()) {
1730 exceptions_print_stacktrace();
1734 /* there is no main method or it isn't static */
1736 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1737 exceptions_clear_exception();
1738 exceptions_throw_nosuchmethoderror(mainclass,
1739 utf_new_char("main"),
1740 utf_new_char("([Ljava/lang/String;)V"));
1742 exceptions_print_stacktrace();
1746 /* build argument array */
1748 oalength = vm_args->nOptions - opt_index;
1750 oa = builtin_anewarray(oalength, class_java_lang_String);
1752 for (i = 0; i < oalength; i++) {
1753 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1754 s = javastring_new(u);
1756 LLNI_objectarray_element_set(oa, i, s);
1759 #ifdef TYPEINFO_DEBUG_TEST
1760 /* test the typeinfo system */
1763 /*class_showmethods(currentThread->group->header.vftbl->class); */
1765 #if defined(ENABLE_JVMTI)
1766 jvmti_set_phase(JVMTI_PHASE_LIVE);
1769 /* set ThreadMXBean variables */
1771 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1772 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1774 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1775 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1776 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1777 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1779 /* start the main thread */
1781 (void) vm_call_method(m, NULL, oa);
1783 /* exception occurred? */
1785 if (exceptions_get_exception()) {
1786 exceptions_print_stacktrace();
1790 /* unload the JavaVM */
1792 (void) vm_destroy(vm);
1800 /* vm_destroy ******************************************************************
1802 Unloads a Java VM and reclaims its resources.
1804 *******************************************************************************/
1806 s4 vm_destroy(JavaVM *vm)
1808 #if defined(ENABLE_THREADS)
1809 threads_join_all_threads();
1812 /* everything's ok */
1818 /* vm_exit *********************************************************************
1820 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1822 *******************************************************************************/
1824 void vm_exit(s4 status)
1828 /* signal that we are exiting */
1832 assert(class_java_lang_System);
1833 assert(class_java_lang_System->state & CLASS_LOADED);
1835 #if defined(ENABLE_JVMTI)
1836 if (jvmti || (dbgcom!=NULL)) {
1837 jvmti_set_phase(JVMTI_PHASE_DEAD);
1838 if (jvmti) jvmti_agentunload();
1842 if (!link_class(class_java_lang_System)) {
1843 exceptions_print_stacktrace();
1847 /* call java.lang.System.exit(I)V */
1849 m = class_resolveclassmethod(class_java_lang_System,
1850 utf_new_char("exit"),
1852 class_java_lang_Object,
1856 exceptions_print_stacktrace();
1860 /* call the exit function with passed exit status */
1862 (void) vm_call_method(m, NULL, status);
1864 /* If we had an exception, just ignore the exception and exit with
1867 vm_shutdown(status);
1871 /* vm_shutdown *****************************************************************
1873 Terminates the system immediately without freeing memory explicitly
1874 (to be used only for abnormal termination).
1876 *******************************************************************************/
1878 void vm_shutdown(s4 status)
1881 #if defined(ENABLE_STATISTICS)
1882 || opt_getcompilingtime || opt_stat
1886 log_text("CACAO terminated by shutdown");
1887 dolog("Exit status: %d\n", (s4) status);
1891 #if defined(ENABLE_JVMTI)
1892 /* terminate cacaodbgserver */
1894 pthread_mutex_lock(&dbgcomlock);
1896 pthread_mutex_unlock(&dbgcomlock);
1897 jvmti_cacaodbgserver_quit();
1905 /* vm_exit_handler *************************************************************
1907 The exit_handler function is called upon program termination.
1909 ATTENTION: Don't free system resources here! Some threads may still
1910 be running as this is called from VMRuntime.exit(). The OS does the
1913 *******************************************************************************/
1915 void vm_exit_handler(void)
1917 #if !defined(NDEBUG)
1919 class_showmethods(mainclass);
1921 if (showconstantpool)
1922 class_showconstantpool(mainclass);
1927 # if defined(ENABLE_PROFILING)
1929 profile_printstats();
1931 #endif /* !defined(NDEBUG) */
1933 #if defined(ENABLE_RT_TIMING)
1934 rt_timing_print_time_stats(stderr);
1937 #if defined(ENABLE_CYCLES_STATS)
1938 builtin_print_cycles_stats(stderr);
1939 stacktrace_print_cycles_stats(stderr);
1943 #if defined(ENABLE_STATISTICS)
1944 || opt_getcompilingtime || opt_stat
1948 log_text("CACAO terminated");
1950 #if defined(ENABLE_STATISTICS)
1953 #ifdef TYPECHECK_STATISTICS
1954 typecheck_print_statistics(get_logfile());
1958 if (opt_getcompilingtime)
1960 #endif /* defined(ENABLE_STATISTICS) */
1962 /* vm_print_profile(stderr);*/
1966 /* vm_abort ********************************************************************
1968 Prints an error message and aborts the VM.
1970 *******************************************************************************/
1972 void vm_abort(const char *text, ...)
1976 /* print the log message */
1981 log_vprint(text, ap);
1986 /* now abort the VM */
1992 /* vm_get_mainclass_from_jar ***************************************************
1994 Gets the name of the main class from a JAR's manifest file.
1996 *******************************************************************************/
1998 static char *vm_get_mainclass_from_jar(char *mainstring)
2005 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2008 exceptions_print_stacktrace();
2012 /* create JarFile object */
2017 exceptions_print_stacktrace();
2021 m = class_resolveclassmethod(c,
2023 utf_java_lang_String__void,
2024 class_java_lang_Object,
2028 exceptions_print_stacktrace();
2032 s = javastring_new_from_ascii(mainstring);
2034 (void) vm_call_method(m, o, s);
2036 if (exceptions_get_exception()) {
2037 exceptions_print_stacktrace();
2041 /* get manifest object */
2043 m = class_resolveclassmethod(c,
2044 utf_new_char("getManifest"),
2045 utf_new_char("()Ljava/util/jar/Manifest;"),
2046 class_java_lang_Object,
2050 exceptions_print_stacktrace();
2054 o = vm_call_method(m, o);
2057 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2062 /* get Main Attributes */
2064 m = class_resolveclassmethod(o->vftbl->class,
2065 utf_new_char("getMainAttributes"),
2066 utf_new_char("()Ljava/util/jar/Attributes;"),
2067 class_java_lang_Object,
2071 exceptions_print_stacktrace();
2075 o = vm_call_method(m, o);
2078 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2083 /* get property Main-Class */
2085 m = class_resolveclassmethod(o->vftbl->class,
2086 utf_new_char("getValue"),
2087 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2088 class_java_lang_Object,
2092 exceptions_print_stacktrace();
2096 s = javastring_new_from_ascii("Main-Class");
2098 o = vm_call_method(m, o, s);
2101 exceptions_print_stacktrace();
2105 return javastring_tochar(o);
2109 /* vm_compile_all **************************************************************
2111 Compile all methods found in the bootclasspath.
2113 *******************************************************************************/
2115 #if !defined(NDEBUG)
2116 static void vm_compile_all(void)
2121 classcache_name_entry *nmen;
2122 classcache_class_entry *clsen;
2125 /* create all classes found in the bootclasspath */
2126 /* XXX currently only works with zip/jar's */
2128 loader_load_all_classes();
2130 /* link all classes */
2132 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2133 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2135 for (; nmen; nmen = nmen->hashlink) {
2136 /* iterate over all class entries */
2138 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2139 c = clsen->classobj;
2144 if (!(c->state & CLASS_LINKED)) {
2145 if (!link_class(c)) {
2146 fprintf(stderr, "Error linking: ");
2147 utf_fprint_printable_ascii_classname(stderr, c->name);
2148 fprintf(stderr, "\n");
2150 /* print out exception and cause */
2152 exceptions_print_current_exception();
2154 /* goto next class */
2160 /* compile all class methods */
2162 for (i = 0; i < c->methodscount; i++) {
2163 m = &(c->methods[i]);
2165 if (m->jcode != NULL) {
2166 if (!jit_compile(m)) {
2167 fprintf(stderr, "Error compiling: ");
2168 utf_fprint_printable_ascii_classname(stderr, c->name);
2169 fprintf(stderr, ".");
2170 utf_fprint_printable_ascii(stderr, m->name);
2171 utf_fprint_printable_ascii(stderr, m->descriptor);
2172 fprintf(stderr, "\n");
2174 /* print out exception and cause */
2176 exceptions_print_current_exception();
2184 #endif /* !defined(NDEBUG) */
2187 /* vm_compile_method ***********************************************************
2189 Compile a specific method.
2191 *******************************************************************************/
2193 #if !defined(NDEBUG)
2194 static void vm_compile_method(void)
2198 /* create, load and link the main class */
2200 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2202 if (mainclass == NULL)
2203 exceptions_print_stacktrace();
2205 if (!link_class(mainclass))
2206 exceptions_print_stacktrace();
2208 if (opt_signature != NULL) {
2209 m = class_resolveclassmethod(mainclass,
2210 utf_new_char(opt_method),
2211 utf_new_char(opt_signature),
2216 m = class_resolveclassmethod(mainclass,
2217 utf_new_char(opt_method),
2224 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2225 opt_method, opt_signature ? opt_signature : "");
2229 #endif /* !defined(NDEBUG) */
2232 /* vm_array_store_int **********************************************************
2234 Helper function to store an integer into the argument array, taking
2235 care of architecture specific issues.
2237 *******************************************************************************/
2239 static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
2243 if (!pd->inmemory) {
2245 array[index] = (int64_t) value;
2248 index = ARG_CNT + pd->index;
2249 #if SIZEOF_VOID_P == 8
2250 array[index] = (int64_t) value;
2252 # if WORDS_BIGENDIAN == 1
2253 array[index] = ((int64_t) value) << 32;
2255 array[index] = (int64_t) value;
2262 /* vm_array_store_lng **********************************************************
2264 Helper function to store a long into the argument array, taking
2265 care of architecture specific issues.
2267 *******************************************************************************/
2269 static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
2273 #if SIZEOF_VOID_P == 8
2277 index = ARG_CNT + pd->index;
2279 array[index] = value;
2281 if (!pd->inmemory) {
2282 /* move low and high 32-bits into it's own argument slot */
2284 index = GET_LOW_REG(pd->index);
2285 array[index] = value & 0x00000000ffffffff;
2287 index = GET_HIGH_REG(pd->index);
2288 array[index] = value >> 32;
2291 index = ARG_CNT + pd->index;
2292 array[index] = value;
2298 /* vm_array_store_flt **********************************************************
2300 Helper function to store a float into the argument array, taking
2301 care of architecture specific issues.
2303 *******************************************************************************/
2305 static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
2309 if (!pd->inmemory) {
2310 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2313 index = INT_ARG_CNT + pd->index;
2315 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC__) && !defined(__POWERPC64__) && !defined(__S390__)
2316 array[index] = value >> 32;
2318 array[index] = value;
2322 index = ARG_CNT + pd->index;
2323 #if defined(__SPARC_64__)
2324 array[index] = value >> 32;
2326 array[index] = value;
2332 /* vm_array_store_dbl **********************************************************
2334 Helper function to store a double into the argument array, taking
2335 care of architecture specific issues.
2337 *******************************************************************************/
2339 static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
2343 if (!pd->inmemory) {
2344 #if SIZEOF_VOID_P != 8 && defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2345 index = GET_LOW_REG(pd->index);
2346 array[index] = value & 0x00000000ffffffff;
2348 index = GET_HIGH_REG(pd->index);
2349 array[index] = value >> 32;
2351 index = INT_ARG_CNT + pd->index;
2352 array[index] = value;
2356 index = ARG_CNT + pd->index;
2357 array[index] = value;
2362 /* vm_array_store_adr **********************************************************
2364 Helper function to store an address into the argument array, taking
2365 care of architecture specific issues.
2367 *******************************************************************************/
2369 static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
2373 if (!pd->inmemory) {
2374 #if defined(HAS_ADDRESS_REGISTER_FILE)
2375 /* When the architecture has address registers, place them
2376 after integer and float registers. */
2378 index = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
2382 array[index] = (uint64_t) (intptr_t) value;
2385 index = ARG_CNT + pd->index;
2386 #if SIZEOF_VOID_P == 8
2387 array[index] = (uint64_t) (intptr_t) value;
2389 # if WORDS_BIGENDIAN == 1
2390 array[index] = ((uint64_t) (intptr_t) value) << 32;
2392 array[index] = (uint64_t) (intptr_t) value;
2399 /* vm_array_from_valist ********************************************************
2403 *******************************************************************************/
2405 uint64_t *vm_array_from_valist(methodinfo *m, java_object_t *o, va_list ap)
2414 /* get the descriptors */
2418 td = md->paramtypes;
2420 /* allocate argument array */
2422 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2424 /* if method is non-static fill first block and skip `this' pointer */
2429 /* the `this' pointer */
2430 vm_array_store_adr(array, pd, o);
2437 for (; i < md->paramcount; i++, pd++, td++) {
2440 value.i = va_arg(ap, int32_t);
2441 vm_array_store_int(array, pd, value.i);
2445 value.l = va_arg(ap, int64_t);
2446 vm_array_store_lng(array, pd, value.l);
2450 #if defined(__ALPHA__) || defined(__POWERPC__) || defined(__POWERPC64__)
2451 /* This is required to load the correct float value in
2454 value.d = (double) va_arg(ap, double);
2456 value.f = (float) va_arg(ap, double);
2458 vm_array_store_flt(array, pd, value.l);
2462 value.d = va_arg(ap, double);
2463 vm_array_store_dbl(array, pd, value.l);
2467 value.a = va_arg(ap, void*);
2468 vm_array_store_adr(array, pd, value.a);
2477 /* vm_array_from_jvalue ********************************************************
2481 *******************************************************************************/
2483 static uint64_t *vm_array_from_jvalue(methodinfo *m, java_object_t *o,
2493 /* get the descriptors */
2497 td = md->paramtypes;
2499 /* allocate argument array */
2501 #if defined(HAS_ADDRESS_REGISTER_FILE)
2502 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
2504 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2507 /* if method is non-static fill first block and skip `this' pointer */
2512 /* the `this' pointer */
2513 vm_array_store_adr(array, pd, o);
2520 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2521 switch (td->decltype) {
2523 vm_array_store_int(array, pd, args[j].i);
2527 vm_array_store_lng(array, pd, args[j].j);
2531 vm_array_store_flt(array, pd, args[j].j);
2535 vm_array_store_dbl(array, pd, args[j].j);
2539 vm_array_store_adr(array, pd, args[j].l);
2548 /* vm_array_from_objectarray ***************************************************
2552 *******************************************************************************/
2554 uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
2555 java_handle_objectarray_t *params)
2561 java_handle_t *param;
2568 /* get the descriptors */
2572 td = md->paramtypes;
2574 /* allocate argument array */
2576 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2578 /* if method is non-static fill first block and skip `this' pointer */
2584 vm_array_store_adr(array, pd, o);
2591 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2592 LLNI_objectarray_element_get(params, j, param);
2599 /* convert the value according to its declared type */
2601 c = param->vftbl->class;
2602 type = primitive_type_get_by_wrapperclass(c);
2604 switch (td->decltype) {
2605 case PRIMITIVETYPE_BOOLEAN:
2607 case PRIMITIVETYPE_BOOLEAN:
2608 /* This type is OK. */
2615 case PRIMITIVETYPE_BYTE:
2617 case PRIMITIVETYPE_BYTE:
2618 /* This type is OK. */
2625 case PRIMITIVETYPE_CHAR:
2627 case PRIMITIVETYPE_CHAR:
2628 /* This type is OK. */
2635 case PRIMITIVETYPE_SHORT:
2637 case PRIMITIVETYPE_BYTE:
2638 case PRIMITIVETYPE_SHORT:
2639 /* These types are OK. */
2646 case PRIMITIVETYPE_INT:
2648 case PRIMITIVETYPE_BYTE:
2649 case PRIMITIVETYPE_SHORT:
2650 case PRIMITIVETYPE_INT:
2651 /* These types are OK. */
2659 vm_abort("vm_array_from_objectarray: invalid type %d",
2663 value = primitive_unbox(param);
2664 vm_array_store_int(array, pd, value.i);
2671 c = param->vftbl->class;
2672 type = primitive_type_get_by_wrapperclass(c);
2674 assert(td->decltype == PRIMITIVETYPE_LONG);
2677 case PRIMITIVETYPE_BYTE:
2678 case PRIMITIVETYPE_SHORT:
2679 case PRIMITIVETYPE_INT:
2680 case PRIMITIVETYPE_LONG:
2681 /* These types are OK. */
2687 value = primitive_unbox(param);
2688 vm_array_store_lng(array, pd, value.l);
2695 c = param->vftbl->class;
2696 type = primitive_type_get_by_wrapperclass(c);
2698 assert(td->decltype == PRIMITIVETYPE_FLOAT);
2701 case PRIMITIVETYPE_FLOAT:
2702 /* This type is OK. */
2708 value = primitive_unbox(param);
2709 vm_array_store_flt(array, pd, value.l);
2716 c = param->vftbl->class;
2717 type = primitive_type_get_by_wrapperclass(c);
2719 assert(td->decltype == PRIMITIVETYPE_DOUBLE);
2722 case PRIMITIVETYPE_FLOAT:
2723 case PRIMITIVETYPE_DOUBLE:
2724 /* These types are OK. */
2730 value = primitive_unbox(param);
2731 vm_array_store_dbl(array, pd, value.l);
2735 if (!resolve_class_from_typedesc(td, true, true, &c))
2738 if (param != NULL) {
2739 if (td->arraydim > 0) {
2740 if (!builtin_arrayinstanceof(param, c))
2744 if (!builtin_instanceof(param, c))
2749 vm_array_store_adr(array, pd, param);
2753 vm_abort("vm_array_from_objectarray: invalid type %d", td->type);
2760 exceptions_throw_illegalargumentexception();
2765 /* vm_call_method **************************************************************
2767 Calls a Java method with a variable number of arguments.
2769 *******************************************************************************/
2771 #define VM_CALL_METHOD(name, type) \
2772 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2778 value = vm_call_method##name##_valist(m, o, ap); \
2784 VM_CALL_METHOD(, java_handle_t *)
2785 VM_CALL_METHOD(_int, int32_t)
2786 VM_CALL_METHOD(_long, int64_t)
2787 VM_CALL_METHOD(_float, float)
2788 VM_CALL_METHOD(_double, double)
2791 /* vm_call_method_valist *******************************************************
2793 Calls a Java method with a variable number of arguments, passed via
2796 *******************************************************************************/
2798 #define VM_CALL_METHOD_VALIST(name, type) \
2799 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2806 dumpsize = dump_size(); \
2807 array = vm_array_from_valist(m, o, ap); \
2808 value = vm_call##name##_array(m, array); \
2809 dump_release(dumpsize); \
2814 VM_CALL_METHOD_VALIST(, java_handle_t *)
2815 VM_CALL_METHOD_VALIST(_int, int32_t)
2816 VM_CALL_METHOD_VALIST(_long, int64_t)
2817 VM_CALL_METHOD_VALIST(_float, float)
2818 VM_CALL_METHOD_VALIST(_double, double)
2821 /* vm_call_method_jvalue *******************************************************
2823 Calls a Java method with a variable number of arguments, passed via
2826 *******************************************************************************/
2828 #define VM_CALL_METHOD_JVALUE(name, type) \
2829 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2830 const jvalue *args) \
2836 dumpsize = dump_size(); \
2837 array = vm_array_from_jvalue(m, o, args); \
2838 value = vm_call##name##_array(m, array); \
2839 dump_release(dumpsize); \
2844 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2845 VM_CALL_METHOD_JVALUE(_int, int32_t)
2846 VM_CALL_METHOD_JVALUE(_long, int64_t)
2847 VM_CALL_METHOD_JVALUE(_float, float)
2848 VM_CALL_METHOD_JVALUE(_double, double)
2851 /* vm_call_array ***************************************************************
2853 Calls a Java method with a variable number of arguments, passed via
2856 *******************************************************************************/
2858 #define VM_CALL_ARRAY(name, type) \
2859 type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2865 md = m->parseddesc; \
2867 if (m->code == NULL) \
2868 if (!jit_compile(m)) \
2871 pv = m->code->entrypoint; \
2873 STATISTICS(count_calls_native_to_java++); \
2875 value = asm_vm_call_method##name(pv, array, md->memuse); \
2880 VM_CALL_ARRAY(, java_handle_t *)
2881 VM_CALL_ARRAY(_int, int32_t)
2882 VM_CALL_ARRAY(_long, int64_t)
2883 VM_CALL_ARRAY(_float, float)
2884 VM_CALL_ARRAY(_double, double)
2888 * These are local overrides for various environment variables in Emacs.
2889 * Please do not remove this and leave it at the end of the file, where
2890 * Emacs will automagically detect them.
2891 * ---------------------------------------------------------------------
2894 * indent-tabs-mode: t