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
40 #include "vm/jit/abi-asm.h"
42 #include "mm/gc-common.h"
43 #include "mm/memory.h"
45 #include "native/jni.h"
46 #include "native/llni.h"
47 #include "native/native.h"
49 #include "native/include/java_lang_Object.h" /* required by j.l.C */
50 #include "native/include/java_lang_String.h" /* required by j.l.C */
52 #if defined(WITH_CLASSPATH_SUN)
53 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
54 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
57 #include "native/include/java_lang_Class.h"
59 #include "native/vm/nativevm.h"
61 #include "threads/threads-common.h"
63 #include "toolbox/logging.h"
65 #include "vm/builtin.h"
66 #include "vm/exceptions.h"
67 #include "vm/finalizer.h"
68 #include "vm/global.h"
69 #include "vm/initialize.h"
70 #include "vm/primitive.h"
71 #include "vm/properties.h"
72 #include "vm/signallocal.h"
73 #include "vm/stringlocal.h"
76 #include "vm/jit/jit.h"
77 #include "vm/jit/md.h"
78 #include "vm/jit/asmpart.h"
80 #if defined(ENABLE_PROFILING)
81 # include "vm/jit/optimizing/profile.h"
84 #include "vm/jit/optimizing/recompile.h"
86 #include "vmcore/classcache.h"
87 #include "vmcore/options.h"
88 #include "vmcore/statistics.h"
89 #include "vmcore/suck.h"
91 #if defined(ENABLE_JVMTI)
92 # include "native/jvmti/cacaodbg.h"
95 #if defined(ENABLE_VMLOG)
96 #include <vmlog_cacao.h>
100 /* Invocation API variables ***************************************************/
102 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
103 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
106 /* global variables ***********************************************************/
108 s4 vms = 0; /* number of VMs created */
110 bool vm_initializing = false;
111 bool vm_exiting = false;
113 char *mainstring = NULL;
114 classinfo *mainclass = NULL;
116 #if defined(ENABLE_INTRP)
117 u1 *intrp_main_stack = NULL;
121 /* define heap sizes **********************************************************/
123 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
124 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
125 #define STACK_SIZE 64 * 1024 /* default 64kB */
128 /* define command line options ************************************************/
159 /* Java non-standard options */
170 #if defined(ENABLE_PROFILING)
183 #if defined(ENABLE_STATISTICS)
200 #if defined(ENABLE_VERIFIER)
202 #if defined(TYPECHECK_VERBOSE)
205 #endif /* defined(ENABLE_VERIFIER) */
207 /* optimization options */
209 #if defined(ENABLE_LOOP)
213 #if defined(ENABLE_IFCONV)
217 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
221 #if defined(ENABLE_INLINING)
226 #if defined(ENABLE_INLINING_DEBUG)
227 OPT_INLINE_DEBUG_ALL,
228 OPT_INLINE_DEBUG_END,
229 OPT_INLINE_DEBUG_MIN,
230 OPT_INLINE_DEBUG_MAX,
231 #endif /* defined(ENABLE_INLINING_DEBUG) */
232 #endif /* defined(ENABLE_INLINING) */
234 #if defined(ENABLE_INTRP)
235 /* interpreter options */
254 #if defined(ENABLE_DEBUG_FILTER)
255 OPT_FILTER_VERBOSECALL_INCLUDE,
256 OPT_FILTER_VERBOSECALL_EXCLUDE,
257 OPT_FILTER_SHOW_METHOD,
264 opt_struct opts[] = {
265 { "foo", false, OPT_FOO },
269 { "jar", false, OPT_JAR },
271 { "d32", false, OPT_D32 },
272 { "d64", false, OPT_D64 },
273 { "client", false, OPT_IGNORE },
274 { "server", false, OPT_IGNORE },
275 { "jvm", false, OPT_IGNORE },
276 { "hotspot", false, OPT_IGNORE },
278 { "classpath", true, OPT_CLASSPATH },
279 { "cp", true, OPT_CLASSPATH },
280 { "D", true, OPT_D },
281 { "version", false, OPT_VERSION },
282 { "showversion", false, OPT_SHOWVERSION },
283 { "fullversion", false, OPT_FULLVERSION },
284 { "help", false, OPT_HELP },
285 { "?", false, OPT_HELP },
286 { "X", false, OPT_X },
287 { "XX:", true, OPT_XX },
288 { "XX", false, OPT_XX },
290 { "ea:", true, OPT_EA },
291 { "da:", true, OPT_DA },
292 { "ea", false, OPT_EA },
293 { "da", false, OPT_DA },
295 { "esa", false, OPT_ESA },
296 { "enablesystemassertions", false, OPT_ESA },
297 { "dsa", false, OPT_DSA },
298 { "disablesystemassertions", false, OPT_DSA },
300 { "noasyncgc", false, OPT_IGNORE },
301 #if defined(ENABLE_VERIFIER)
302 { "noverify", false, OPT_NOVERIFY },
303 { "Xverify:none", false, OPT_NOVERIFY },
305 { "v", false, OPT_VERBOSE1 },
306 { "verbose:", true, OPT_VERBOSE },
308 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
309 { "verbosetc", false, OPT_VERBOSETC },
311 #if defined(__ALPHA__)
312 { "noieee", false, OPT_NOIEEE },
314 #if defined(ENABLE_STATISTICS)
315 { "time", false, OPT_TIME },
316 { "stat", false, OPT_STAT },
318 { "log", true, OPT_LOG },
319 { "c", true, OPT_CHECK },
320 { "l", false, OPT_LOAD },
323 { "all", false, OPT_ALL },
324 { "sig", true, OPT_SIGNATURE },
327 #if defined(ENABLE_LOOP)
328 { "oloop", false, OPT_OLOOP },
330 #if defined(ENABLE_IFCONV)
331 { "ifconv", false, OPT_IFCONV },
333 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
334 { "lsra", false, OPT_LSRA },
337 #if defined(ENABLE_INTRP)
338 /* interpreter options */
340 { "trace", false, OPT_TRACE },
341 { "static-supers", true, OPT_STATIC_SUPERS },
342 { "no-dynamic", false, OPT_NO_DYNAMIC },
343 { "no-replication", false, OPT_NO_REPLICATION },
344 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
347 /* JVMTI Agent Command Line Options */
349 { "agentlib:", true, OPT_AGENTLIB },
350 { "agentpath:", true, OPT_AGENTPATH },
353 /* Java non-standard options */
355 { "Xjit", false, OPT_JIT },
356 { "Xint", false, OPT_INTRP },
357 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
358 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
359 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
360 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
363 { "Xdebug", false, OPT_DEBUG },
364 { "Xnoagent", false, OPT_NOAGENT },
365 { "Xrunjdwp", true, OPT_XRUNJDWP },
368 { "Xms", true, OPT_MS },
369 { "ms", true, OPT_MS },
370 { "Xmx", true, OPT_MX },
371 { "mx", true, OPT_MX },
372 { "Xss", true, OPT_SS },
373 { "ss", true, OPT_SS },
375 #if defined(ENABLE_PROFILING)
376 { "Xprof:", true, OPT_PROF_OPTION },
377 { "Xprof", false, OPT_PROF },
380 /* inlining options */
382 #if defined(ENABLE_INLINING)
383 #if defined(ENABLE_INLINING_DEBUG)
384 { "ia", false, OPT_INLINE_DEBUG_ALL },
385 { "ii", true, OPT_INLINE_DEBUG_MIN },
386 { "im", true, OPT_INLINE_DEBUG_MAX },
387 { "ie", true, OPT_INLINE_DEBUG_END },
388 #endif /* defined(ENABLE_INLINING_DEBUG) */
390 { "il", false, OPT_INLINE_LOG },
392 { "i", false, OPT_INLINING },
393 #endif /* defined(ENABLE_INLINING) */
395 /* keep these at the end of the list */
398 { "m", true, OPT_METHOD },
401 { "s", true, OPT_SHOW },
402 { "debug-color", false, OPT_DEBUGCOLOR },
404 #if defined(ENABLE_DEBUG_FILTER)
405 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
406 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
407 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
414 /* usage ***********************************************************************
416 Prints the correct usage syntax to stdout.
418 *******************************************************************************/
422 puts("Usage: cacao [-options] classname [arguments]");
423 puts(" (to run a class file)");
424 puts(" or cacao [-options] -jar jarfile [arguments]");
425 puts(" (to run a standalone jar file)\n");
427 puts("where options include:");
428 puts(" -d32 use 32-bit data model if available");
429 puts(" -d64 use 64-bit data model if available");
430 puts(" -client compatibility (currently ignored)");
431 puts(" -server compatibility (currently ignored)");
432 puts(" -jvm compatibility (currently ignored)");
433 puts(" -hotspot compatibility (currently ignored)\n");
435 puts(" -cp <path> specify a path to look for classes");
436 puts(" -classpath <path> specify a path to look for classes");
437 puts(" -D<name>=<value> add an entry to the property list");
438 puts(" -verbose[:class|gc|jni] enable specific verbose output");
439 puts(" -version print product version and exit");
440 puts(" -fullversion print jpackage-compatible product version and exit");
441 puts(" -showversion print product version and continue");
442 puts(" -help, -? print this help message");
443 puts(" -X print help on non-standard Java options");
444 puts(" -XX print help on debugging options");
445 puts(" -ea[:<packagename>...|:<classname>]");
446 puts(" -enableassertions[:<packagename>...|:<classname>]");
447 puts(" enable assertions with specified granularity");
448 puts(" -da[:<packagename>...|:<classname>]");
449 puts(" -disableassertions[:<packagename>...|:<classname>]");
450 puts(" disable assertions with specified granularity");
451 puts(" -esa | -enablesystemassertions");
452 puts(" enable system assertions");
453 puts(" -dsa | -disablesystemassertions");
454 puts(" disable system assertions");
457 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
458 puts (" for jdwp help use: -agentlib:jdwp=help");
459 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
462 /* exit with error code */
468 static void Xusage(void)
470 #if defined(ENABLE_JIT)
471 puts(" -Xjit JIT mode execution (default)");
473 #if defined(ENABLE_INTRP)
474 puts(" -Xint interpreter mode execution");
476 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
477 puts(" value is set as bootstrap class path");
478 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
479 puts(" value is appended to the bootstrap class path");
480 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
481 puts(" value is prepended to the bootstrap class path");
482 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
483 puts(" value is used as Java core library, but the");
484 puts(" hardcoded VM interface classes are prepended");
485 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
486 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
487 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
489 #if defined(ENABLE_PROFILING)
490 puts(" -Xprof[:bb] collect and print profiling data");
493 #if defined(ENABLE_JVMTI)
494 /* -Xdebug option depend on gnu classpath JDWP options. options:
495 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
496 puts(" -Xdebug enable remote debugging\n");
497 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
498 puts(" enable remote debugging\n");
501 /* exit with error code */
508 static void XXusage(void)
510 puts(" -v write state-information");
512 puts(" -verbose[:jit|threads]");
513 puts(" enable specific verbose output");
514 puts(" -debug-color colored output for ANSI terms");
516 #ifdef TYPECHECK_VERBOSE
517 puts(" -verbosetc write debug messages while typechecking");
519 #if defined(__ALPHA__)
520 puts(" -noieee don't use ieee compliant arithmetic");
522 #if defined(ENABLE_VERIFIER)
523 puts(" -noverify don't verify classfiles");
525 #if defined(ENABLE_STATISTICS)
526 puts(" -time measure the runtime");
527 puts(" -stat detailed compiler statistics");
529 puts(" -log logfile specify a name for the logfile");
530 puts(" -c(heck)b(ounds) don't check array bounds");
531 puts(" s(ync) don't check for synchronization");
532 #if defined(ENABLE_LOOP)
533 puts(" -oloop optimize array accesses in loops");
535 puts(" -l don't start the class after loading");
537 puts(" -all compile all methods, no execution");
538 puts(" -m compile only a specific method");
539 puts(" -sig specify signature for a specific method");
542 puts(" -s... show...");
543 puts(" (c)onstants the constant pool");
544 puts(" (m)ethods class fields and methods");
545 puts(" (u)tf the utf - hash");
546 puts(" (i)ntermediate intermediate representation");
547 #if defined(ENABLE_DISASSEMBLER)
548 puts(" (a)ssembler disassembled listing");
549 puts(" n(o)ps show NOPs in disassembler output");
550 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
551 puts(" (n)ative disassembled native stubs");
553 puts(" (d)atasegment data segment listing");
555 #if defined(ENABLE_INLINING)
556 puts(" -i activate inlining");
558 puts(" -il log inlining");
560 #if defined(ENABLE_INLINING_DEBUG)
561 puts(" -ia use inlining for all methods");
562 puts(" -ii <size> set minimum size for inlined result");
563 puts(" -im <size> set maximum size for inlined result");
564 puts(" -ie <number> stop inlining after the given number of roots");
565 #endif /* defined(ENABLE_INLINING_DEBUG) */
566 #endif /* defined(ENABLE_INLINING) */
568 #if defined(ENABLE_IFCONV)
569 puts(" -ifconv use if-conversion");
571 #if defined(ENABLE_LSRA)
572 puts(" -lsra use linear scan register allocation");
574 #if defined(ENABLE_SSA)
575 puts(" -lsra use linear scan register allocation (with SSA)");
577 #if defined(ENABLE_DEBUG_FILTER)
578 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
579 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
580 puts(" -XXfm <regex> filter for show options");
582 /* exit with error code */
589 /* version *********************************************************************
591 Only prints cacao version information.
593 *******************************************************************************/
595 static void version(bool opt_exit)
597 puts("java version \""JAVA_VERSION"\"");
598 puts("CACAO version "VERSION"");
600 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
601 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
602 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
603 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
605 puts("This program is free software; you can redistribute it and/or");
606 puts("modify it under the terms of the GNU General Public License as");
607 puts("published by the Free Software Foundation; either version 2, or (at");
608 puts("your option) any later version.\n");
610 puts("This program is distributed in the hope that it will be useful, but");
611 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
612 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
613 puts("General Public License for more details.");
615 /* exit normally, if requested */
622 /* fullversion *****************************************************************
624 Prints a Sun compatible version information (required e.g. by
625 jpackage, www.jpackage.org).
627 *******************************************************************************/
629 static void fullversion(void)
631 puts("java full version \"cacao-"JAVA_VERSION"\"");
639 void vm_printconfig(void)
641 puts("Configure/Build options:\n");
642 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
643 #if defined(__VERSION__)
644 puts(" CC : "VERSION_CC" ("__VERSION__")");
646 puts(" CC : "VERSION_CC"");
648 puts(" CFLAGS : "VERSION_CFLAGS"\n");
650 puts("Default variables:\n");
651 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
652 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
653 printf(" stack size : %d\n", STACK_SIZE);
655 #if defined(WITH_JRE_LAYOUT)
656 /* When we're building with JRE-layout, the default paths are the
657 same as the runtime paths. */
659 # if defined(WITH_CLASSPATH_GNU)
660 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
661 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
662 # elif defined(WITH_CLASSPATH_SUN)
663 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
664 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
670 puts("Runtime variables:\n");
671 printf(" maximum heap size : %d\n", opt_heapmaxsize);
672 printf(" initial heap size : %d\n", opt_heapstartsize);
673 printf(" stack size : %d\n", opt_stacksize);
675 #if defined(WITH_CLASSPATH_GNU)
676 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
677 #elif defined(WITH_CLASSPATH_SUN)
678 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
681 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
682 printf(" java.class.path : %s\n", properties_get("java.class.path"));
686 /* forward declarations *******************************************************/
688 static char *vm_get_mainclass_from_jar(char *mainstring);
690 static void vm_compile_all(void);
691 static void vm_compile_method(void);
695 /* vm_createjvm ****************************************************************
697 Implementation for JNI_CreateJavaVM.
699 *******************************************************************************/
701 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
703 JavaVMInitArgs *_vm_args;
707 /* get the arguments for the new JVM */
709 _vm_args = (JavaVMInitArgs *) vm_args;
711 /* get the VM and Env tables (must be set before vm_create) */
713 env = NEW(_Jv_JNIEnv);
715 #if defined(ENABLE_JNI)
716 env->env = &_Jv_JNINativeInterface;
719 /* XXX Set the global variable. Maybe we should do that differently. */
723 /* create and fill a JavaVM structure */
725 vm = NEW(_Jv_JavaVM);
727 #if defined(ENABLE_JNI)
728 vm->functions = &_Jv_JNIInvokeInterface;
731 /* XXX Set the global variable. Maybe we should do that differently. */
732 /* XXX JVMTI Agents needs a JavaVM */
736 /* actually create the JVM */
738 if (!vm_create(_vm_args))
741 #if defined(ENABLE_JNI)
742 /* setup the local ref table (must be created after vm_create) */
744 /* XXX this one will never get freed for the main thread;
745 call localref_table_destroy() if you want to do it! */
747 if (!localref_table_init())
751 /* now return the values */
753 *p_vm = (JavaVM *) vm;
754 *p_env = (void *) env;
759 /* release allocated memory */
761 FREE(env, _Jv_JNIEnv);
762 FREE(vm, _Jv_JavaVM);
768 /* vm_create *******************************************************************
770 Creates a JVM. Called by vm_createjvm.
772 *******************************************************************************/
774 bool vm_create(JavaVMInitArgs *vm_args)
778 char *boot_class_path;
785 #if defined(ENABLE_JVMTI)
787 char *libname, *agentarg;
788 bool jdwp,agentbypath;
789 jdwp = agentbypath = false;
792 #if defined(ENABLE_VMLOG)
793 vmlog_cacao_init(vm_args);
796 /* check the JNI version requested */
798 switch (vm_args->version) {
799 case JNI_VERSION_1_1:
801 case JNI_VERSION_1_2:
802 case JNI_VERSION_1_4:
808 /* we only support 1 JVM instance */
813 if (atexit(vm_exit_handler))
814 vm_abort("atexit failed: %s\n", strerror(errno));
817 log_text("CACAO started -------------------------------------------------------");
819 /* We need to check if the actual size of a java.lang.Class object
820 is smaller or equal than the assumption made in
821 src/vmcore/class.h. */
823 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
824 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
826 /* set the VM starttime */
828 _Jv_jvm->starttime = builtin_currenttimemillis();
830 /* interpret the options **************************************************/
837 opt_heapmaxsize = HEAP_MAXSIZE;
838 opt_heapstartsize = HEAP_STARTSIZE;
839 opt_stacksize = STACK_SIZE;
842 #if defined(ENABLE_JVMTI)
843 /* initialize JVMTI related **********************************************/
847 /* Initialize and fill properties before command-line handling. */
852 /* iterate over all passed options */
854 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
868 #if SIZEOF_VOID_P == 8
869 puts("Running a 32-bit JVM is not supported on this platform.");
875 #if SIZEOF_VOID_P == 4
876 puts("Running a 64-bit JVM is not supported on this platform.");
882 /* Forget old classpath and set the argument as new
885 class_path = properties_get("java.class.path");
887 p = MNEW(char, strlen(opt_arg) + strlen("0"));
891 #if defined(ENABLE_JAVASE)
892 properties_add("java.class.path", p);
895 MFREE(class_path, char, strlen(class_path));
899 for (i = 0; i < strlen(opt_arg); i++) {
900 if (opt_arg[i] == '=') {
902 properties_add(opt_arg, opt_arg + i + 1);
907 /* if no '=' is given, just create an empty property */
909 properties_add(opt_arg, "");
914 case OPT_BOOTCLASSPATH:
915 /* Forget default bootclasspath and set the argument as
916 new boot classpath. */
918 boot_class_path = properties_get("sun.boot.class.path");
920 p = MNEW(char, strlen(opt_arg) + strlen("0"));
924 properties_add("sun.boot.class.path", p);
925 properties_add("java.boot.class.path", p);
927 MFREE(boot_class_path, char, strlen(boot_class_path));
930 case OPT_BOOTCLASSPATH_A:
931 /* Append to bootclasspath. */
933 boot_class_path = properties_get("sun.boot.class.path");
935 len = strlen(boot_class_path);
937 p = MREALLOC(boot_class_path,
941 strlen(opt_arg) + strlen("0"));
946 properties_add("sun.boot.class.path", p);
947 properties_add("java.boot.class.path", p);
950 case OPT_BOOTCLASSPATH_P:
951 /* Prepend to bootclasspath. */
953 boot_class_path = properties_get("sun.boot.class.path");
955 len = strlen(boot_class_path);
957 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
961 strcat(p, boot_class_path);
963 properties_add("sun.boot.class.path", p);
964 properties_add("java.boot.class.path", p);
966 MFREE(boot_class_path, char, len);
969 case OPT_BOOTCLASSPATH_C:
970 /* Use as Java core library, but prepend VM interface
973 boot_class_path = properties_get("sun.boot.class.path");
976 strlen(CACAO_VM_ZIP) +
983 strcpy(p, CACAO_VM_ZIP);
987 properties_add("sun.boot.class.path", p);
988 properties_add("java.boot.class.path", p);
990 MFREE(boot_class_path, char, strlen(boot_class_path));
993 #if defined(ENABLE_JVMTI)
995 /* this option exists only for compatibility reasons */
999 /* I don't know yet what Xnoagent should do. This is only for
1000 compatiblity with eclipse - motse */
1009 strlen(CACAO_LIBDIR) +
1010 strlen("/libjdwp.so=") +
1014 agentarg = MNEW(char, len);
1016 strcpy(agentarg, CACAO_LIBDIR);
1017 strcat(agentarg, "/libjdwp.so=");
1018 strcat(agentarg, &opt_arg[1]);
1035 c = opt_arg[strlen(opt_arg) - 1];
1037 if ((c == 'k') || (c == 'K')) {
1038 j = atoi(opt_arg) * 1024;
1040 } else if ((c == 'm') || (c == 'M')) {
1041 j = atoi(opt_arg) * 1024 * 1024;
1047 opt_heapmaxsize = j;
1048 else if (opt == OPT_MS)
1049 opt_heapstartsize = j;
1060 if (strcmp("class", opt_arg) == 0) {
1061 opt_verboseclass = true;
1063 else if (strcmp("gc", opt_arg) == 0) {
1064 opt_verbosegc = true;
1066 else if (strcmp("jni", opt_arg) == 0) {
1067 opt_verbosejni = true;
1069 #if !defined(NDEBUG)
1070 else if (strcmp("jit", opt_arg) == 0) {
1074 compileverbose = true;
1076 else if (strcmp("threads", opt_arg) == 0) {
1077 opt_verbosethreads = true;
1081 printf("Unknown -verbose option: %s\n", opt_arg);
1086 case OPT_DEBUGCOLOR:
1087 opt_debugcolor = true;
1090 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1092 opt_typecheckverbose = true;
1101 case OPT_FULLVERSION:
1105 case OPT_SHOWVERSION:
1113 #if defined(ENABLE_VERIFIER)
1119 #if defined(ENABLE_STATISTICS)
1121 opt_getcompilingtime = true;
1122 opt_getloadingtime = true;
1135 for (i = 0; i < strlen(opt_arg); i++) {
1136 switch (opt_arg[i]) {
1138 checkbounds = false;
1151 makeinitializations = false;
1154 #if !defined(NDEBUG)
1158 makeinitializations = false;
1163 opt_method = opt_arg;
1164 makeinitializations = false;
1168 opt_signature = opt_arg;
1172 case OPT_SHOW: /* Display options */
1173 for (i = 0; i < strlen(opt_arg); i++) {
1174 switch (opt_arg[i]) {
1176 showconstantpool = true;
1188 opt_showintermediate = true;
1189 compileverbose = true;
1192 #if defined(ENABLE_DISASSEMBLER)
1194 opt_showdisassemble = true;
1195 compileverbose = true;
1199 opt_shownops = true;
1203 opt_showexceptionstubs = true;
1207 opt_shownativestub = true;
1212 opt_showddatasegment = true;
1221 #if defined(ENABLE_LOOP)
1227 #if defined(ENABLE_INLINING)
1228 #if defined(ENABLE_INLINING_DEBUG)
1229 case OPT_INLINE_DEBUG_ALL:
1230 opt_inline_debug_all = true;
1232 case OPT_INLINE_DEBUG_END:
1233 opt_inline_debug_end_counter = atoi(opt_arg);
1235 case OPT_INLINE_DEBUG_MIN:
1236 opt_inline_debug_min_size = atoi(opt_arg);
1238 case OPT_INLINE_DEBUG_MAX:
1239 opt_inline_debug_max_size = atoi(opt_arg);
1241 #endif /* defined(ENABLE_INLINING_DEBUG) */
1242 #if !defined(NDEBUG)
1243 case OPT_INLINE_LOG:
1244 opt_inline_debug_log = true;
1246 #endif /* !defined(NDEBUG) */
1249 opt_inlining = true;
1251 #endif /* defined(ENABLE_INLINING) */
1253 #if defined(ENABLE_IFCONV)
1259 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1274 options_xx(opt_arg);
1278 /* currently ignored */
1282 /* currently ignored */
1286 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1290 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1293 #if defined(ENABLE_PROFILING)
1294 case OPT_PROF_OPTION:
1295 /* use <= to get the last \0 too */
1297 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1298 if (opt_arg[i] == ',')
1301 if (opt_arg[i] == '\0') {
1302 if (strcmp("bb", opt_arg + j) == 0)
1306 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1310 /* set k to next char */
1323 #if defined(ENABLE_JIT)
1326 printf("-Xjit option not enabled.\n");
1332 #if defined(ENABLE_INTRP)
1335 printf("-Xint option not enabled.\n");
1340 #if defined(ENABLE_INTRP)
1341 case OPT_STATIC_SUPERS:
1342 opt_static_supers = atoi(opt_arg);
1345 case OPT_NO_DYNAMIC:
1346 opt_no_dynamic = true;
1349 case OPT_NO_REPLICATION:
1350 opt_no_replication = true;
1353 case OPT_NO_QUICKSUPER:
1354 opt_no_quicksuper = true;
1362 #if defined(ENABLE_DEBUG_FILTER)
1363 case OPT_FILTER_VERBOSECALL_INCLUDE:
1364 opt_filter_verbosecall_include = opt_arg;
1367 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1368 opt_filter_verbosecall_exclude = opt_arg;
1371 case OPT_FILTER_SHOW_METHOD:
1372 opt_filter_show_method = opt_arg;
1377 printf("Unknown option: %s\n",
1378 vm_args->options[opt_index].optionString);
1383 /* get the main class *****************************************************/
1385 if (opt_index < vm_args->nOptions) {
1386 mainstring = vm_args->options[opt_index++].optionString;
1388 /* Put the jar file into the classpath (if any). */
1390 if (opt_jar == true) {
1391 /* free old classpath */
1393 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1395 /* put jarfile into classpath */
1397 p = MNEW(char, strlen(mainstring) + strlen("0"));
1399 strcpy(p, mainstring);
1401 #if defined(ENABLE_JAVASE)
1402 properties_add("java.class.path", p);
1406 /* replace .'s with /'s in classname */
1408 for (i = strlen(mainstring) - 1; i >= 0; i--)
1409 if (mainstring[i] == '.')
1410 mainstring[i] = '/';
1414 #if defined(ENABLE_JVMTI)
1416 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1417 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1420 MFREE(agentarg, char, strlen(agentarg));
1422 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1426 /* initialize this JVM ****************************************************/
1428 vm_initializing = true;
1430 /* initialize the garbage collector */
1432 gc_init(opt_heapmaxsize, opt_heapstartsize);
1434 #if defined(ENABLE_THREADS)
1435 /* AFTER: gc_init (directly after, as this initializes the
1436 stopworldlock lock */
1441 /* install architecture dependent signal handlers */
1444 vm_abort("vm_create: signal_init failed");
1446 #if defined(ENABLE_INTRP)
1447 /* Allocate main thread stack on the Java heap. */
1450 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1451 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1455 /* AFTER: threads_preinit */
1458 vm_abort("vm_create: string_init failed");
1460 /* AFTER: threads_preinit */
1463 vm_abort("vm_create: utf8_init failed");
1465 /* AFTER: thread_preinit */
1468 vm_abort("vm_create: suck_init failed");
1470 suck_add_from_property("java.endorsed.dirs");
1472 /* Now we have all options handled and we can print the version
1475 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1480 /* AFTER: utf8_init */
1482 boot_class_path = properties_get("sun.boot.class.path");
1483 suck_add(boot_class_path);
1485 /* initialize the classcache hashtable stuff: lock, hashtable
1486 (must be done _after_ threads_preinit) */
1488 if (!classcache_init())
1489 vm_abort("vm_create: classcache_init failed");
1491 /* initialize the memory subsystem (must be done _after_
1495 vm_abort("vm_create: memory_init failed");
1497 /* initialize the finalizer stuff (must be done _after_
1500 if (!finalizer_init())
1501 vm_abort("vm_create: finalizer_init failed");
1503 /* initialize the codegen subsystems */
1507 /* initializes jit compiler */
1511 /* machine dependent initialization */
1513 #if defined(ENABLE_JIT)
1514 # if defined(ENABLE_INTRP)
1524 /* AFTER: utf8_init, classcache_init */
1529 /* AFTER: loader_preinit, linker_preinit */
1536 /* AFTER: loader_init, linker_init */
1538 primitive_postinit();
1540 if (!exceptions_init())
1541 vm_abort("vm_create: exceptions_init failed");
1543 if (!builtin_init())
1544 vm_abort("vm_create: builtin_init failed");
1546 /* Initialize the native subsystem. */
1547 /* BEFORE: threads_init */
1550 vm_abort("vm_create: native_init failed");
1552 /* Register the native methods implemented in the VM. */
1553 /* BEFORE: threads_init */
1555 if (!nativevm_preinit())
1556 vm_abort("vm_create: nativevm_preinit failed");
1558 #if defined(ENABLE_JNI)
1559 /* Initialize the JNI subsystem (must be done _before_
1560 threads_init, as threads_init can call JNI methods
1561 (e.g. NewGlobalRef). */
1564 vm_abort("vm_create: jni_init failed");
1567 #if defined(ENABLE_THREADS)
1568 if (!threads_init())
1569 vm_abort("vm_create: threads_init failed");
1572 /* Initialize the native VM subsystem. */
1573 /* AFTER: threads_init (at least for SUN's classes) */
1575 if (!nativevm_init())
1576 vm_abort("vm_create: nativevm_init failed");
1578 #if defined(ENABLE_PROFILING)
1579 /* initialize profiling */
1581 if (!profile_init())
1582 vm_abort("vm_create: profile_init failed");
1585 #if defined(ENABLE_THREADS)
1586 /* initialize recompilation */
1588 if (!recompile_init())
1589 vm_abort("vm_create: recompile_init failed");
1591 /* start the signal handler thread */
1593 #if defined(__LINUX__)
1594 /* XXX Remove for exact-GC. */
1595 if (threads_pthreads_implementation_nptl)
1597 if (!signal_start_thread())
1598 vm_abort("vm_create: signal_start_thread failed");
1600 /* finally, start the finalizer thread */
1602 if (!finalizer_start_thread())
1603 vm_abort("vm_create: finalizer_start_thread failed");
1605 # if !defined(NDEBUG)
1606 /* start the memory profiling thread */
1608 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1609 if (!memory_start_thread())
1610 vm_abort("vm_create: memory_start_thread failed");
1613 /* start the recompilation thread (must be done before the
1614 profiling thread) */
1616 if (!recompile_start_thread())
1617 vm_abort("vm_create: recompile_start_thread failed");
1619 # if defined(ENABLE_PROFILING)
1620 /* start the profile sampling thread */
1623 /* if (!profile_start_thread()) */
1624 /* vm_abort("vm_create: profile_start_thread failed"); */
1628 #if defined(ENABLE_JVMTI)
1629 # if defined(ENABLE_GC_CACAO)
1630 /* XXX this will not work with the new indirection cells for classloaders!!! */
1634 /* add agent library to native library hashtable */
1635 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1639 /* increment the number of VMs */
1643 /* initialization is done */
1645 vm_initializing = false;
1647 /* everything's ok */
1653 /* vm_run **********************************************************************
1655 Runs the main-method of the passed class.
1657 *******************************************************************************/
1659 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1662 classinfo *mainclass;
1665 java_handle_objectarray_t *oa;
1672 #if !defined(NDEBUG)
1678 if (opt_method != NULL) {
1679 vm_compile_method();
1682 #endif /* !defined(NDEBUG) */
1684 /* should we run the main-method? */
1686 if (mainstring == NULL)
1689 /* set return value to OK */
1693 if (opt_jar == true) {
1694 /* open jar file with java.util.jar.JarFile */
1696 mainstring = vm_get_mainclass_from_jar(mainstring);
1698 if (mainstring == NULL)
1702 /* load the main class */
1704 mainutf = utf_new_char(mainstring);
1706 #if defined(ENABLE_JAVAME_CLDC1_1)
1707 mainclass = load_class_bootstrap(mainutf);
1709 mainclass = load_class_from_sysloader(mainutf);
1712 /* error loading class */
1714 e = exceptions_get_and_clear_exception();
1716 if ((e != NULL) || (mainclass == NULL)) {
1717 exceptions_throw_noclassdeffounderror_cause(e);
1718 exceptions_print_stacktrace();
1722 if (!link_class(mainclass)) {
1723 exceptions_print_stacktrace();
1727 /* find the `main' method of the main class */
1729 m = class_resolveclassmethod(mainclass,
1730 utf_new_char("main"),
1731 utf_new_char("([Ljava/lang/String;)V"),
1732 class_java_lang_Object,
1735 if (exceptions_get_exception()) {
1736 exceptions_print_stacktrace();
1740 /* there is no main method or it isn't static */
1742 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1743 exceptions_clear_exception();
1744 exceptions_throw_nosuchmethoderror(mainclass,
1745 utf_new_char("main"),
1746 utf_new_char("([Ljava/lang/String;)V"));
1748 exceptions_print_stacktrace();
1752 /* build argument array */
1754 oalength = vm_args->nOptions - opt_index;
1756 oa = builtin_anewarray(oalength, class_java_lang_String);
1758 for (i = 0; i < oalength; i++) {
1759 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1760 s = javastring_new(u);
1762 LLNI_objectarray_element_set(oa, i, s);
1765 #ifdef TYPEINFO_DEBUG_TEST
1766 /* test the typeinfo system */
1769 /*class_showmethods(currentThread->group->header.vftbl->class); */
1771 #if defined(ENABLE_JVMTI)
1772 jvmti_set_phase(JVMTI_PHASE_LIVE);
1775 /* set ThreadMXBean variables */
1777 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1778 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1780 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1781 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1782 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1783 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1785 /* start the main thread */
1787 (void) vm_call_method(m, NULL, oa);
1789 /* exception occurred? */
1791 if (exceptions_get_exception()) {
1792 exceptions_print_stacktrace();
1796 /* unload the JavaVM */
1798 (void) vm_destroy(vm);
1806 /* vm_destroy ******************************************************************
1808 Unloads a Java VM and reclaims its resources.
1810 *******************************************************************************/
1812 s4 vm_destroy(JavaVM *vm)
1814 #if defined(ENABLE_THREADS)
1815 threads_join_all_threads();
1818 /* everything's ok */
1824 /* vm_exit *********************************************************************
1826 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1828 *******************************************************************************/
1830 void vm_exit(s4 status)
1834 /* signal that we are exiting */
1838 assert(class_java_lang_System);
1839 assert(class_java_lang_System->state & CLASS_LOADED);
1841 #if defined(ENABLE_JVMTI)
1842 if (jvmti || (dbgcom!=NULL)) {
1843 jvmti_set_phase(JVMTI_PHASE_DEAD);
1844 if (jvmti) jvmti_agentunload();
1848 if (!link_class(class_java_lang_System)) {
1849 exceptions_print_stacktrace();
1853 /* call java.lang.System.exit(I)V */
1855 m = class_resolveclassmethod(class_java_lang_System,
1856 utf_new_char("exit"),
1858 class_java_lang_Object,
1862 exceptions_print_stacktrace();
1866 /* call the exit function with passed exit status */
1868 (void) vm_call_method(m, NULL, status);
1870 /* If we had an exception, just ignore the exception and exit with
1873 vm_shutdown(status);
1877 /* vm_shutdown *****************************************************************
1879 Terminates the system immediately without freeing memory explicitly
1880 (to be used only for abnormal termination).
1882 *******************************************************************************/
1884 void vm_shutdown(s4 status)
1887 #if defined(ENABLE_STATISTICS)
1888 || opt_getcompilingtime || opt_stat
1892 log_text("CACAO terminated by shutdown");
1893 dolog("Exit status: %d\n", (s4) status);
1897 #if defined(ENABLE_JVMTI)
1898 /* terminate cacaodbgserver */
1900 pthread_mutex_lock(&dbgcomlock);
1902 pthread_mutex_unlock(&dbgcomlock);
1903 jvmti_cacaodbgserver_quit();
1911 /* vm_exit_handler *************************************************************
1913 The exit_handler function is called upon program termination.
1915 ATTENTION: Don't free system resources here! Some threads may still
1916 be running as this is called from VMRuntime.exit(). The OS does the
1919 *******************************************************************************/
1921 void vm_exit_handler(void)
1923 #if !defined(NDEBUG)
1925 class_showmethods(mainclass);
1927 if (showconstantpool)
1928 class_showconstantpool(mainclass);
1933 # if defined(ENABLE_PROFILING)
1935 profile_printstats();
1937 #endif /* !defined(NDEBUG) */
1939 #if defined(ENABLE_RT_TIMING)
1940 rt_timing_print_time_stats(stderr);
1943 #if defined(ENABLE_CYCLES_STATS)
1944 builtin_print_cycles_stats(stderr);
1945 stacktrace_print_cycles_stats(stderr);
1949 #if defined(ENABLE_STATISTICS)
1950 || opt_getcompilingtime || opt_stat
1954 log_text("CACAO terminated");
1956 #if defined(ENABLE_STATISTICS)
1959 #ifdef TYPECHECK_STATISTICS
1960 typecheck_print_statistics(get_logfile());
1964 if (opt_getcompilingtime)
1966 #endif /* defined(ENABLE_STATISTICS) */
1968 /* vm_print_profile(stderr);*/
1972 /* vm_abort ********************************************************************
1974 Prints an error message and aborts the VM.
1976 *******************************************************************************/
1978 void vm_abort(const char *text, ...)
1982 /* print the log message */
1987 log_vprint(text, ap);
1992 /* now abort the VM */
1998 /* vm_get_mainclass_from_jar ***************************************************
2000 Gets the name of the main class from a JAR's manifest file.
2002 *******************************************************************************/
2004 static char *vm_get_mainclass_from_jar(char *mainstring)
2011 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2014 exceptions_print_stacktrace();
2018 /* create JarFile object */
2023 exceptions_print_stacktrace();
2027 m = class_resolveclassmethod(c,
2029 utf_java_lang_String__void,
2030 class_java_lang_Object,
2034 exceptions_print_stacktrace();
2038 s = javastring_new_from_ascii(mainstring);
2040 (void) vm_call_method(m, o, s);
2042 if (exceptions_get_exception()) {
2043 exceptions_print_stacktrace();
2047 /* get manifest object */
2049 m = class_resolveclassmethod(c,
2050 utf_new_char("getManifest"),
2051 utf_new_char("()Ljava/util/jar/Manifest;"),
2052 class_java_lang_Object,
2056 exceptions_print_stacktrace();
2060 o = vm_call_method(m, o);
2063 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2068 /* get Main Attributes */
2070 m = class_resolveclassmethod(o->vftbl->class,
2071 utf_new_char("getMainAttributes"),
2072 utf_new_char("()Ljava/util/jar/Attributes;"),
2073 class_java_lang_Object,
2077 exceptions_print_stacktrace();
2081 o = vm_call_method(m, o);
2084 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2089 /* get property Main-Class */
2091 m = class_resolveclassmethod(o->vftbl->class,
2092 utf_new_char("getValue"),
2093 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2094 class_java_lang_Object,
2098 exceptions_print_stacktrace();
2102 s = javastring_new_from_ascii("Main-Class");
2104 o = vm_call_method(m, o, s);
2107 exceptions_print_stacktrace();
2111 return javastring_tochar(o);
2115 /* vm_compile_all **************************************************************
2117 Compile all methods found in the bootclasspath.
2119 *******************************************************************************/
2121 #if !defined(NDEBUG)
2122 static void vm_compile_all(void)
2127 classcache_name_entry *nmen;
2128 classcache_class_entry *clsen;
2131 /* create all classes found in the bootclasspath */
2132 /* XXX currently only works with zip/jar's */
2134 loader_load_all_classes();
2136 /* link all classes */
2138 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2139 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2141 for (; nmen; nmen = nmen->hashlink) {
2142 /* iterate over all class entries */
2144 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2145 c = clsen->classobj;
2150 if (!(c->state & CLASS_LINKED)) {
2151 if (!link_class(c)) {
2152 fprintf(stderr, "Error linking: ");
2153 utf_fprint_printable_ascii_classname(stderr, c->name);
2154 fprintf(stderr, "\n");
2156 /* print out exception and cause */
2158 exceptions_print_current_exception();
2160 /* goto next class */
2166 /* compile all class methods */
2168 for (i = 0; i < c->methodscount; i++) {
2169 m = &(c->methods[i]);
2171 if (m->jcode != NULL) {
2172 if (!jit_compile(m)) {
2173 fprintf(stderr, "Error compiling: ");
2174 utf_fprint_printable_ascii_classname(stderr, c->name);
2175 fprintf(stderr, ".");
2176 utf_fprint_printable_ascii(stderr, m->name);
2177 utf_fprint_printable_ascii(stderr, m->descriptor);
2178 fprintf(stderr, "\n");
2180 /* print out exception and cause */
2182 exceptions_print_current_exception();
2190 #endif /* !defined(NDEBUG) */
2193 /* vm_compile_method ***********************************************************
2195 Compile a specific method.
2197 *******************************************************************************/
2199 #if !defined(NDEBUG)
2200 static void vm_compile_method(void)
2204 /* create, load and link the main class */
2206 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2208 if (mainclass == NULL)
2209 exceptions_print_stacktrace();
2211 if (!link_class(mainclass))
2212 exceptions_print_stacktrace();
2214 if (opt_signature != NULL) {
2215 m = class_resolveclassmethod(mainclass,
2216 utf_new_char(opt_method),
2217 utf_new_char(opt_signature),
2222 m = class_resolveclassmethod(mainclass,
2223 utf_new_char(opt_method),
2230 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2231 opt_method, opt_signature ? opt_signature : "");
2235 #endif /* !defined(NDEBUG) */
2238 /* vm_array_store_int **********************************************************
2240 Helper function to store an integer into the argument array, taking
2241 care of architecture specific issues.
2243 *******************************************************************************/
2245 static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
2249 if (!pd->inmemory) {
2251 array[index] = (int64_t) value;
2254 index = ARG_CNT + pd->index;
2255 #if SIZEOF_VOID_P == 8
2256 array[index] = (int64_t) value;
2258 # if WORDS_BIGENDIAN == 1
2259 array[index] = ((int64_t) value) << 32;
2261 array[index] = (int64_t) value;
2268 /* vm_array_store_lng **********************************************************
2270 Helper function to store a long into the argument array, taking
2271 care of architecture specific issues.
2273 *******************************************************************************/
2275 static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
2279 #if SIZEOF_VOID_P == 8
2283 index = ARG_CNT + pd->index;
2285 array[index] = value;
2287 if (!pd->inmemory) {
2288 /* move low and high 32-bits into it's own argument slot */
2290 index = GET_LOW_REG(pd->index);
2291 array[index] = value & 0x00000000ffffffff;
2293 index = GET_HIGH_REG(pd->index);
2294 array[index] = value >> 32;
2297 index = ARG_CNT + pd->index;
2298 array[index] = value;
2304 /* vm_array_store_flt **********************************************************
2306 Helper function to store a float into the argument array, taking
2307 care of architecture specific issues.
2309 *******************************************************************************/
2311 static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
2315 if (!pd->inmemory) {
2316 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2319 index = INT_ARG_CNT + pd->index;
2321 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC__) && !defined(__POWERPC64__) && !defined(__S390__)
2322 array[index] = value >> 32;
2324 array[index] = value;
2328 index = ARG_CNT + pd->index;
2329 #if defined(__SPARC_64__)
2330 array[index] = value >> 32;
2332 array[index] = value;
2338 /* vm_array_store_dbl **********************************************************
2340 Helper function to store a double into the argument array, taking
2341 care of architecture specific issues.
2343 *******************************************************************************/
2345 static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
2349 if (!pd->inmemory) {
2350 #if SIZEOF_VOID_P != 8 && defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2351 index = GET_LOW_REG(pd->index);
2352 array[index] = value & 0x00000000ffffffff;
2354 index = GET_HIGH_REG(pd->index);
2355 array[index] = value >> 32;
2357 index = INT_ARG_CNT + pd->index;
2358 array[index] = value;
2362 index = ARG_CNT + pd->index;
2363 array[index] = value;
2368 /* vm_array_store_adr **********************************************************
2370 Helper function to store an address into the argument array, taking
2371 care of architecture specific issues.
2373 *******************************************************************************/
2375 static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
2379 if (!pd->inmemory) {
2380 #if defined(HAS_ADDRESS_REGISTER_FILE)
2381 /* When the architecture has address registers, place them
2382 after integer and float registers. */
2384 index = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
2388 array[index] = (uint64_t) (intptr_t) value;
2391 index = ARG_CNT + pd->index;
2392 #if SIZEOF_VOID_P == 8
2393 array[index] = (uint64_t) (intptr_t) value;
2395 # if WORDS_BIGENDIAN == 1
2396 array[index] = ((uint64_t) (intptr_t) value) << 32;
2398 array[index] = (uint64_t) (intptr_t) value;
2405 /* vm_array_from_valist ********************************************************
2409 *******************************************************************************/
2411 uint64_t *vm_array_from_valist(methodinfo *m, java_object_t *o, va_list ap)
2420 /* get the descriptors */
2424 td = md->paramtypes;
2426 /* allocate argument array */
2428 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2430 /* if method is non-static fill first block and skip `this' pointer */
2435 /* the `this' pointer */
2436 vm_array_store_adr(array, pd, o);
2443 for (; i < md->paramcount; i++, pd++, td++) {
2446 value.i = va_arg(ap, int32_t);
2447 vm_array_store_int(array, pd, value.i);
2451 value.l = va_arg(ap, int64_t);
2452 vm_array_store_lng(array, pd, value.l);
2456 #if defined(__ALPHA__) || defined(__POWERPC__) || defined(__POWERPC64__)
2457 /* This is required to load the correct float value in
2460 value.d = (double) va_arg(ap, double);
2462 value.f = (float) va_arg(ap, double);
2464 vm_array_store_flt(array, pd, value.l);
2468 value.d = va_arg(ap, double);
2469 vm_array_store_dbl(array, pd, value.l);
2473 value.a = va_arg(ap, void*);
2474 vm_array_store_adr(array, pd, value.a);
2483 /* vm_array_from_jvalue ********************************************************
2487 *******************************************************************************/
2489 static uint64_t *vm_array_from_jvalue(methodinfo *m, java_object_t *o,
2499 /* get the descriptors */
2503 td = md->paramtypes;
2505 /* allocate argument array */
2507 #if defined(HAS_ADDRESS_REGISTER_FILE)
2508 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
2510 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2513 /* if method is non-static fill first block and skip `this' pointer */
2518 /* the `this' pointer */
2519 vm_array_store_adr(array, pd, o);
2526 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2527 switch (td->decltype) {
2529 vm_array_store_int(array, pd, args[j].i);
2533 vm_array_store_lng(array, pd, args[j].j);
2537 vm_array_store_flt(array, pd, args[j].j);
2541 vm_array_store_dbl(array, pd, args[j].j);
2545 vm_array_store_adr(array, pd, args[j].l);
2554 /* vm_array_from_objectarray ***************************************************
2558 *******************************************************************************/
2560 uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
2561 java_handle_objectarray_t *params)
2567 java_handle_t *param;
2574 /* get the descriptors */
2578 td = md->paramtypes;
2580 /* allocate argument array */
2582 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2584 /* if method is non-static fill first block and skip `this' pointer */
2590 vm_array_store_adr(array, pd, o);
2597 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2598 LLNI_objectarray_element_get(params, j, param);
2605 /* convert the value according to its declared type */
2607 c = param->vftbl->class;
2608 type = primitive_type_get_by_wrapperclass(c);
2610 switch (td->decltype) {
2611 case PRIMITIVETYPE_BOOLEAN:
2613 case PRIMITIVETYPE_BOOLEAN:
2614 /* This type is OK. */
2621 case PRIMITIVETYPE_BYTE:
2623 case PRIMITIVETYPE_BYTE:
2624 /* This type is OK. */
2631 case PRIMITIVETYPE_CHAR:
2633 case PRIMITIVETYPE_CHAR:
2634 /* This type is OK. */
2641 case PRIMITIVETYPE_SHORT:
2643 case PRIMITIVETYPE_BYTE:
2644 case PRIMITIVETYPE_SHORT:
2645 /* These types are OK. */
2652 case PRIMITIVETYPE_INT:
2654 case PRIMITIVETYPE_BYTE:
2655 case PRIMITIVETYPE_SHORT:
2656 case PRIMITIVETYPE_INT:
2657 /* These types are OK. */
2665 vm_abort("vm_array_from_objectarray: invalid type %d",
2669 value = primitive_unbox(param);
2670 vm_array_store_int(array, pd, value.i);
2677 c = param->vftbl->class;
2678 type = primitive_type_get_by_wrapperclass(c);
2680 assert(td->decltype == PRIMITIVETYPE_LONG);
2683 case PRIMITIVETYPE_BYTE:
2684 case PRIMITIVETYPE_SHORT:
2685 case PRIMITIVETYPE_INT:
2686 case PRIMITIVETYPE_LONG:
2687 /* These types are OK. */
2693 value = primitive_unbox(param);
2694 vm_array_store_lng(array, pd, value.l);
2701 c = param->vftbl->class;
2702 type = primitive_type_get_by_wrapperclass(c);
2704 assert(td->decltype == PRIMITIVETYPE_FLOAT);
2707 case PRIMITIVETYPE_FLOAT:
2708 /* This type is OK. */
2714 value = primitive_unbox(param);
2715 vm_array_store_flt(array, pd, value.l);
2722 c = param->vftbl->class;
2723 type = primitive_type_get_by_wrapperclass(c);
2725 assert(td->decltype == PRIMITIVETYPE_DOUBLE);
2728 case PRIMITIVETYPE_FLOAT:
2729 case PRIMITIVETYPE_DOUBLE:
2730 /* These types are OK. */
2736 value = primitive_unbox(param);
2737 vm_array_store_dbl(array, pd, value.l);
2741 if (!resolve_class_from_typedesc(td, true, true, &c))
2744 if (param != NULL) {
2745 if (td->arraydim > 0) {
2746 if (!builtin_arrayinstanceof(param, c))
2750 if (!builtin_instanceof(param, c))
2755 vm_array_store_adr(array, pd, param);
2759 vm_abort("vm_array_from_objectarray: invalid type %d", td->type);
2766 exceptions_throw_illegalargumentexception();
2771 /* vm_call_method **************************************************************
2773 Calls a Java method with a variable number of arguments.
2775 *******************************************************************************/
2777 #define VM_CALL_METHOD(name, type) \
2778 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2784 value = vm_call_method##name##_valist(m, o, ap); \
2790 VM_CALL_METHOD(, java_handle_t *)
2791 VM_CALL_METHOD(_int, int32_t)
2792 VM_CALL_METHOD(_long, int64_t)
2793 VM_CALL_METHOD(_float, float)
2794 VM_CALL_METHOD(_double, double)
2797 /* vm_call_method_valist *******************************************************
2799 Calls a Java method with a variable number of arguments, passed via
2802 *******************************************************************************/
2804 #define VM_CALL_METHOD_VALIST(name, type) \
2805 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2812 dumpsize = dump_size(); \
2813 array = vm_array_from_valist(m, o, ap); \
2814 value = vm_call##name##_array(m, array); \
2815 dump_release(dumpsize); \
2820 VM_CALL_METHOD_VALIST(, java_handle_t *)
2821 VM_CALL_METHOD_VALIST(_int, int32_t)
2822 VM_CALL_METHOD_VALIST(_long, int64_t)
2823 VM_CALL_METHOD_VALIST(_float, float)
2824 VM_CALL_METHOD_VALIST(_double, double)
2827 /* vm_call_method_jvalue *******************************************************
2829 Calls a Java method with a variable number of arguments, passed via
2832 *******************************************************************************/
2834 #define VM_CALL_METHOD_JVALUE(name, type) \
2835 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2836 const jvalue *args) \
2842 dumpsize = dump_size(); \
2843 array = vm_array_from_jvalue(m, o, args); \
2844 value = vm_call##name##_array(m, array); \
2845 dump_release(dumpsize); \
2850 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2851 VM_CALL_METHOD_JVALUE(_int, int32_t)
2852 VM_CALL_METHOD_JVALUE(_long, int64_t)
2853 VM_CALL_METHOD_JVALUE(_float, float)
2854 VM_CALL_METHOD_JVALUE(_double, double)
2857 /* vm_call_array ***************************************************************
2859 Calls a Java method with a variable number of arguments, passed via
2862 *******************************************************************************/
2864 #define VM_CALL_ARRAY(name, type) \
2865 type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2871 md = m->parseddesc; \
2873 if (m->code == NULL) \
2874 if (!jit_compile(m)) \
2877 pv = m->code->entrypoint; \
2879 STATISTICS(count_calls_native_to_java++); \
2881 value = asm_vm_call_method##name(pv, array, md->memuse); \
2886 VM_CALL_ARRAY(, java_handle_t *)
2887 VM_CALL_ARRAY(_int, int32_t)
2888 VM_CALL_ARRAY(_long, int64_t)
2889 VM_CALL_ARRAY(_float, float)
2890 VM_CALL_ARRAY(_double, double)
2894 * These are local overrides for various environment variables in Emacs.
2895 * Please do not remove this and leave it at the end of the file, where
2896 * Emacs will automagically detect them.
2897 * ---------------------------------------------------------------------
2900 * indent-tabs-mode: t