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/package.h"
71 #include "vm/primitive.h"
72 #include "vm/properties.h"
73 #include "vm/signallocal.h"
74 #include "vm/stringlocal.h"
77 #include "vm/jit/jit.h"
78 #include "vm/jit/md.h"
79 #include "vm/jit/asmpart.h"
81 #if defined(ENABLE_PROFILING)
82 # include "vm/jit/optimizing/profile.h"
85 #include "vm/jit/optimizing/recompile.h"
87 #include "vmcore/classcache.h"
88 #include "vmcore/options.h"
89 #include "vmcore/statistics.h"
90 #include "vmcore/suck.h"
92 #if defined(ENABLE_JVMTI)
93 # include "native/jvmti/cacaodbg.h"
96 #if defined(ENABLE_VMLOG)
97 #include <vmlog_cacao.h>
101 /* Invocation API variables ***************************************************/
103 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
104 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
107 /* global variables ***********************************************************/
109 s4 vms = 0; /* number of VMs created */
111 bool vm_initializing = false;
112 bool vm_exiting = false;
114 char *mainstring = NULL;
115 classinfo *mainclass = NULL;
117 #if defined(ENABLE_INTRP)
118 u1 *intrp_main_stack = NULL;
122 /* define heap sizes **********************************************************/
124 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
125 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
126 #define STACK_SIZE 128 * 1024 /* default 64kB */
129 /* define command line options ************************************************/
160 /* Java non-standard options */
171 #if defined(ENABLE_PROFILING)
184 #if defined(ENABLE_STATISTICS)
201 #if defined(ENABLE_VERIFIER)
203 #if defined(TYPECHECK_VERBOSE)
206 #endif /* defined(ENABLE_VERIFIER) */
208 /* optimization options */
210 #if defined(ENABLE_LOOP)
214 #if defined(ENABLE_IFCONV)
218 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
222 #if defined(ENABLE_INLINING)
227 #if defined(ENABLE_INLINING_DEBUG)
228 OPT_INLINE_DEBUG_ALL,
229 OPT_INLINE_DEBUG_END,
230 OPT_INLINE_DEBUG_MIN,
231 OPT_INLINE_DEBUG_MAX,
232 #endif /* defined(ENABLE_INLINING_DEBUG) */
233 #endif /* defined(ENABLE_INLINING) */
235 #if defined(ENABLE_INTRP)
236 /* interpreter options */
255 #if defined(ENABLE_DEBUG_FILTER)
256 OPT_FILTER_VERBOSECALL_INCLUDE,
257 OPT_FILTER_VERBOSECALL_EXCLUDE,
258 OPT_FILTER_SHOW_METHOD,
265 opt_struct opts[] = {
266 { "foo", false, OPT_FOO },
270 { "jar", false, OPT_JAR },
272 { "d32", false, OPT_D32 },
273 { "d64", false, OPT_D64 },
274 { "client", false, OPT_IGNORE },
275 { "server", false, OPT_IGNORE },
276 { "jvm", false, OPT_IGNORE },
277 { "hotspot", false, OPT_IGNORE },
279 { "classpath", true, OPT_CLASSPATH },
280 { "cp", true, OPT_CLASSPATH },
281 { "D", true, OPT_D },
282 { "version", false, OPT_VERSION },
283 { "showversion", false, OPT_SHOWVERSION },
284 { "fullversion", false, OPT_FULLVERSION },
285 { "help", false, OPT_HELP },
286 { "?", false, OPT_HELP },
287 { "X", false, OPT_X },
288 { "XX:", true, 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");
551 puts(" (d)atasegment data segment listing");
553 #if defined(ENABLE_INLINING)
554 puts(" -i activate inlining");
556 puts(" -il log inlining");
558 #if defined(ENABLE_INLINING_DEBUG)
559 puts(" -ia use inlining for all methods");
560 puts(" -ii <size> set minimum size for inlined result");
561 puts(" -im <size> set maximum size for inlined result");
562 puts(" -ie <number> stop inlining after the given number of roots");
563 #endif /* defined(ENABLE_INLINING_DEBUG) */
564 #endif /* defined(ENABLE_INLINING) */
566 #if defined(ENABLE_IFCONV)
567 puts(" -ifconv use if-conversion");
569 #if defined(ENABLE_LSRA)
570 puts(" -lsra use linear scan register allocation");
572 #if defined(ENABLE_SSA)
573 puts(" -lsra use linear scan register allocation (with SSA)");
575 #if defined(ENABLE_DEBUG_FILTER)
576 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
577 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
578 puts(" -XXfm <regex> filter for show options");
580 /* exit with error code */
587 /* version *********************************************************************
589 Only prints cacao version information.
591 *******************************************************************************/
593 static void version(bool opt_exit)
595 puts("java version \""JAVA_VERSION"\"");
596 puts("CACAO version "VERSION"");
598 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
599 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
600 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
601 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
603 puts("This program is free software; you can redistribute it and/or");
604 puts("modify it under the terms of the GNU General Public License as");
605 puts("published by the Free Software Foundation; either version 2, or (at");
606 puts("your option) any later version.\n");
608 puts("This program is distributed in the hope that it will be useful, but");
609 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
610 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
611 puts("General Public License for more details.");
613 /* exit normally, if requested */
620 /* fullversion *****************************************************************
622 Prints a Sun compatible version information (required e.g. by
623 jpackage, www.jpackage.org).
625 *******************************************************************************/
627 static void fullversion(void)
629 puts("java full version \"cacao-"JAVA_VERSION"\"");
637 void vm_printconfig(void)
639 puts("Configure/Build options:\n");
640 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
641 #if defined(__VERSION__)
642 puts(" CC : "VERSION_CC" ("__VERSION__")");
644 puts(" CC : "VERSION_CC"");
646 puts(" CFLAGS : "VERSION_CFLAGS"\n");
648 puts("Default variables:\n");
649 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
650 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
651 printf(" stack size : %d\n", STACK_SIZE);
653 #if defined(WITH_JRE_LAYOUT)
654 /* When we're building with JRE-layout, the default paths are the
655 same as the runtime paths. */
657 # if defined(WITH_CLASSPATH_GNU)
658 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
659 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
660 # elif defined(WITH_CLASSPATH_SUN)
661 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
662 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
668 puts("Runtime variables:\n");
669 printf(" maximum heap size : %d\n", opt_heapmaxsize);
670 printf(" initial heap size : %d\n", opt_heapstartsize);
671 printf(" stack size : %d\n", opt_stacksize);
673 #if defined(WITH_CLASSPATH_GNU)
674 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
675 #elif defined(WITH_CLASSPATH_SUN)
676 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
679 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
680 printf(" java.class.path : %s\n", properties_get("java.class.path"));
684 /* forward declarations *******************************************************/
686 static char *vm_get_mainclass_from_jar(char *mainstring);
688 static void vm_compile_all(void);
689 static void vm_compile_method(void);
693 /* vm_createjvm ****************************************************************
695 Implementation for JNI_CreateJavaVM.
697 *******************************************************************************/
699 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
701 JavaVMInitArgs *_vm_args;
705 /* get the arguments for the new JVM */
707 _vm_args = (JavaVMInitArgs *) vm_args;
709 /* get the VM and Env tables (must be set before vm_create) */
711 env = NEW(_Jv_JNIEnv);
713 #if defined(ENABLE_JNI)
714 env->env = &_Jv_JNINativeInterface;
717 /* XXX Set the global variable. Maybe we should do that differently. */
721 /* create and fill a JavaVM structure */
723 vm = NEW(_Jv_JavaVM);
725 #if defined(ENABLE_JNI)
726 vm->functions = &_Jv_JNIInvokeInterface;
729 /* XXX Set the global variable. Maybe we should do that differently. */
730 /* XXX JVMTI Agents needs a JavaVM */
734 /* actually create the JVM */
736 if (!vm_create(_vm_args))
739 #if defined(ENABLE_JNI)
740 /* setup the local ref table (must be created after vm_create) */
742 /* XXX this one will never get freed for the main thread;
743 call localref_table_destroy() if you want to do it! */
745 if (!localref_table_init())
749 /* now return the values */
751 *p_vm = (JavaVM *) vm;
752 *p_env = (void *) env;
757 /* release allocated memory */
759 FREE(env, _Jv_JNIEnv);
760 FREE(vm, _Jv_JavaVM);
766 /* vm_create *******************************************************************
768 Creates a JVM. Called by vm_createjvm.
770 *******************************************************************************/
772 bool vm_create(JavaVMInitArgs *vm_args)
776 char *boot_class_path;
783 #if defined(ENABLE_JVMTI)
785 char *libname, *agentarg;
786 bool jdwp,agentbypath;
787 jdwp = agentbypath = false;
790 #if defined(ENABLE_VMLOG)
791 vmlog_cacao_init(vm_args);
794 #if defined(ENABLE_JNI)
795 /* Check the JNI version requested. */
797 if (!jni_version_check(vm_args->version))
801 /* We only support 1 JVM instance. */
806 /* Install the exit handler. */
808 if (atexit(vm_exit_handler))
809 vm_abort("atexit failed: %s\n", strerror(errno));
811 /* Set some options. */
818 opt_heapmaxsize = HEAP_MAXSIZE;
819 opt_heapstartsize = HEAP_STARTSIZE;
820 opt_stacksize = STACK_SIZE;
822 /* Initialize the properties list before command-line handling.
823 Otherwise -XX:+PrintConfig crashes. */
827 /* First of all, parse the -XX options. */
831 /* We need to check if the actual size of a java.lang.Class object
832 is smaller or equal than the assumption made in
833 src/vmcore/class.h. */
835 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
836 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
838 /* set the VM starttime */
840 _Jv_jvm->starttime = builtin_currenttimemillis();
842 #if defined(ENABLE_JVMTI)
843 /* initialize JVMTI related **********************************************/
847 /* Fill the 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;
1203 opt_showddatasegment = true;
1212 #if defined(ENABLE_LOOP)
1218 #if defined(ENABLE_INLINING)
1219 #if defined(ENABLE_INLINING_DEBUG)
1220 case OPT_INLINE_DEBUG_ALL:
1221 opt_inline_debug_all = true;
1223 case OPT_INLINE_DEBUG_END:
1224 opt_inline_debug_end_counter = atoi(opt_arg);
1226 case OPT_INLINE_DEBUG_MIN:
1227 opt_inline_debug_min_size = atoi(opt_arg);
1229 case OPT_INLINE_DEBUG_MAX:
1230 opt_inline_debug_max_size = atoi(opt_arg);
1232 #endif /* defined(ENABLE_INLINING_DEBUG) */
1233 #if !defined(NDEBUG)
1234 case OPT_INLINE_LOG:
1235 opt_inline_debug_log = true;
1237 #endif /* !defined(NDEBUG) */
1240 opt_inlining = true;
1242 #endif /* defined(ENABLE_INLINING) */
1244 #if defined(ENABLE_IFCONV)
1250 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1265 /* Already parsed. */
1269 /* currently ignored */
1273 /* currently ignored */
1277 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1281 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1284 #if defined(ENABLE_PROFILING)
1285 case OPT_PROF_OPTION:
1286 /* use <= to get the last \0 too */
1288 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1289 if (opt_arg[i] == ',')
1292 if (opt_arg[i] == '\0') {
1293 if (strcmp("bb", opt_arg + j) == 0)
1297 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1301 /* set k to next char */
1314 #if defined(ENABLE_JIT)
1317 printf("-Xjit option not enabled.\n");
1323 #if defined(ENABLE_INTRP)
1326 printf("-Xint option not enabled.\n");
1331 #if defined(ENABLE_INTRP)
1332 case OPT_STATIC_SUPERS:
1333 opt_static_supers = atoi(opt_arg);
1336 case OPT_NO_DYNAMIC:
1337 opt_no_dynamic = true;
1340 case OPT_NO_REPLICATION:
1341 opt_no_replication = true;
1344 case OPT_NO_QUICKSUPER:
1345 opt_no_quicksuper = true;
1353 #if defined(ENABLE_DEBUG_FILTER)
1354 case OPT_FILTER_VERBOSECALL_INCLUDE:
1355 opt_filter_verbosecall_include = opt_arg;
1358 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1359 opt_filter_verbosecall_exclude = opt_arg;
1362 case OPT_FILTER_SHOW_METHOD:
1363 opt_filter_show_method = opt_arg;
1368 printf("Unknown option: %s\n",
1369 vm_args->options[opt_index].optionString);
1374 /* get the main class *****************************************************/
1376 if (opt_index < vm_args->nOptions) {
1377 mainstring = vm_args->options[opt_index++].optionString;
1379 /* Put the jar file into the classpath (if any). */
1381 if (opt_jar == true) {
1382 /* free old classpath */
1384 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1386 /* put jarfile into classpath */
1388 p = MNEW(char, strlen(mainstring) + strlen("0"));
1390 strcpy(p, mainstring);
1392 #if defined(ENABLE_JAVASE)
1393 properties_add("java.class.path", p);
1397 /* replace .'s with /'s in classname */
1399 for (i = strlen(mainstring) - 1; i >= 0; i--)
1400 if (mainstring[i] == '.')
1401 mainstring[i] = '/';
1405 #if defined(ENABLE_JVMTI)
1407 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1408 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1411 MFREE(agentarg, char, strlen(agentarg));
1413 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1417 /* initialize this JVM ****************************************************/
1419 vm_initializing = true;
1421 /* initialize the garbage collector */
1423 gc_init(opt_heapmaxsize, opt_heapstartsize);
1425 #if defined(ENABLE_THREADS)
1426 /* AFTER: gc_init (directly after, as this initializes the
1427 stopworldlock lock */
1432 /* install architecture dependent signal handlers */
1435 vm_abort("vm_create: signal_init failed");
1437 #if defined(ENABLE_INTRP)
1438 /* Allocate main thread stack on the Java heap. */
1441 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1442 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1446 /* AFTER: threads_preinit */
1449 vm_abort("vm_create: string_init failed");
1451 /* AFTER: threads_preinit */
1454 vm_abort("vm_create: utf8_init failed");
1456 /* AFTER: thread_preinit */
1459 vm_abort("vm_create: suck_init failed");
1461 suck_add_from_property("java.endorsed.dirs");
1463 /* Now we have all options handled and we can print the version
1466 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1471 /* AFTER: utf8_init */
1473 boot_class_path = properties_get("sun.boot.class.path");
1474 suck_add(boot_class_path);
1476 /* initialize the classcache hashtable stuff: lock, hashtable
1477 (must be done _after_ threads_preinit) */
1479 if (!classcache_init())
1480 vm_abort("vm_create: classcache_init failed");
1482 /* initialize the memory subsystem (must be done _after_
1486 vm_abort("vm_create: memory_init failed");
1488 /* initialize the finalizer stuff (must be done _after_
1491 if (!finalizer_init())
1492 vm_abort("vm_create: finalizer_init failed");
1494 /* initialize the codegen subsystems */
1498 /* initializes jit compiler */
1502 /* machine dependent initialization */
1504 #if defined(ENABLE_JIT)
1505 # if defined(ENABLE_INTRP)
1515 /* BEFORE: loader_preinit */
1519 /* AFTER: utf8_init, classcache_init */
1524 /* AFTER: loader_preinit, linker_preinit */
1531 /* AFTER: loader_init, linker_init */
1533 primitive_postinit();
1535 if (!exceptions_init())
1536 vm_abort("vm_create: exceptions_init failed");
1538 if (!builtin_init())
1539 vm_abort("vm_create: builtin_init failed");
1541 /* Initialize the native subsystem. */
1542 /* BEFORE: threads_init */
1545 vm_abort("vm_create: native_init failed");
1547 /* Register the native methods implemented in the VM. */
1548 /* BEFORE: threads_init */
1550 if (!nativevm_preinit())
1551 vm_abort("vm_create: nativevm_preinit failed");
1553 #if defined(ENABLE_JNI)
1554 /* Initialize the JNI subsystem (must be done _before_
1555 threads_init, as threads_init can call JNI methods
1556 (e.g. NewGlobalRef). */
1559 vm_abort("vm_create: jni_init failed");
1562 #if defined(ENABLE_THREADS)
1563 if (!threads_init())
1564 vm_abort("vm_create: threads_init failed");
1567 /* Initialize the native VM subsystem. */
1568 /* AFTER: threads_init (at least for SUN's classes) */
1570 if (!nativevm_init())
1571 vm_abort("vm_create: nativevm_init failed");
1573 #if defined(ENABLE_PROFILING)
1574 /* initialize profiling */
1576 if (!profile_init())
1577 vm_abort("vm_create: profile_init failed");
1580 #if defined(ENABLE_THREADS)
1581 /* initialize recompilation */
1583 if (!recompile_init())
1584 vm_abort("vm_create: recompile_init failed");
1586 /* start the signal handler thread */
1588 #if defined(__LINUX__)
1589 /* XXX Remove for exact-GC. */
1590 if (threads_pthreads_implementation_nptl)
1592 if (!signal_start_thread())
1593 vm_abort("vm_create: signal_start_thread failed");
1595 /* finally, start the finalizer thread */
1597 if (!finalizer_start_thread())
1598 vm_abort("vm_create: finalizer_start_thread failed");
1600 # if !defined(NDEBUG)
1601 /* start the memory profiling thread */
1603 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1604 if (!memory_start_thread())
1605 vm_abort("vm_create: memory_start_thread failed");
1608 /* start the recompilation thread (must be done before the
1609 profiling thread) */
1611 if (!recompile_start_thread())
1612 vm_abort("vm_create: recompile_start_thread failed");
1614 # if defined(ENABLE_PROFILING)
1615 /* start the profile sampling thread */
1618 /* if (!profile_start_thread()) */
1619 /* vm_abort("vm_create: profile_start_thread failed"); */
1623 #if defined(ENABLE_JVMTI)
1624 # if defined(ENABLE_GC_CACAO)
1625 /* XXX this will not work with the new indirection cells for classloaders!!! */
1629 /* add agent library to native library hashtable */
1630 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1634 /* increment the number of VMs */
1638 /* initialization is done */
1640 vm_initializing = false;
1642 /* everything's ok */
1648 /* vm_run **********************************************************************
1650 Runs the main-method of the passed class.
1652 *******************************************************************************/
1654 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1657 classinfo *mainclass;
1660 java_handle_objectarray_t *oa;
1667 #if !defined(NDEBUG)
1673 if (opt_method != NULL) {
1674 vm_compile_method();
1677 #endif /* !defined(NDEBUG) */
1679 /* should we run the main-method? */
1681 if (mainstring == NULL)
1684 /* set return value to OK */
1688 if (opt_jar == true) {
1689 /* open jar file with java.util.jar.JarFile */
1691 mainstring = vm_get_mainclass_from_jar(mainstring);
1693 if (mainstring == NULL)
1697 /* load the main class */
1699 mainutf = utf_new_char(mainstring);
1701 #if defined(ENABLE_JAVAME_CLDC1_1)
1702 mainclass = load_class_bootstrap(mainutf);
1704 mainclass = load_class_from_sysloader(mainutf);
1707 /* error loading class */
1709 e = exceptions_get_and_clear_exception();
1711 if ((e != NULL) || (mainclass == NULL)) {
1712 exceptions_throw_noclassdeffounderror_cause(e);
1713 exceptions_print_stacktrace();
1717 if (!link_class(mainclass)) {
1718 exceptions_print_stacktrace();
1722 /* find the `main' method of the main class */
1724 m = class_resolveclassmethod(mainclass,
1725 utf_new_char("main"),
1726 utf_new_char("([Ljava/lang/String;)V"),
1727 class_java_lang_Object,
1730 if (exceptions_get_exception()) {
1731 exceptions_print_stacktrace();
1735 /* there is no main method or it isn't static */
1737 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1738 exceptions_clear_exception();
1739 exceptions_throw_nosuchmethoderror(mainclass,
1740 utf_new_char("main"),
1741 utf_new_char("([Ljava/lang/String;)V"));
1743 exceptions_print_stacktrace();
1747 /* build argument array */
1749 oalength = vm_args->nOptions - opt_index;
1751 oa = builtin_anewarray(oalength, class_java_lang_String);
1753 for (i = 0; i < oalength; i++) {
1754 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1755 s = javastring_new(u);
1757 LLNI_objectarray_element_set(oa, i, s);
1760 #ifdef TYPEINFO_DEBUG_TEST
1761 /* test the typeinfo system */
1764 /*class_showmethods(currentThread->group->header.vftbl->class); */
1766 #if defined(ENABLE_JVMTI)
1767 jvmti_set_phase(JVMTI_PHASE_LIVE);
1770 /* set ThreadMXBean variables */
1772 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1773 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1775 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1776 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1777 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1778 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1780 /* start the main thread */
1782 (void) vm_call_method(m, NULL, oa);
1784 /* exception occurred? */
1786 if (exceptions_get_exception()) {
1787 exceptions_print_stacktrace();
1791 /* unload the JavaVM */
1793 (void) vm_destroy(vm);
1801 /* vm_destroy ******************************************************************
1803 Unloads a Java VM and reclaims its resources.
1805 *******************************************************************************/
1807 s4 vm_destroy(JavaVM *vm)
1809 #if defined(ENABLE_THREADS)
1810 threads_join_all_threads();
1813 /* everything's ok */
1819 /* vm_exit *********************************************************************
1821 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1823 *******************************************************************************/
1825 void vm_exit(s4 status)
1829 /* signal that we are exiting */
1833 assert(class_java_lang_System);
1834 assert(class_java_lang_System->state & CLASS_LOADED);
1836 #if defined(ENABLE_JVMTI)
1837 if (jvmti || (dbgcom!=NULL)) {
1838 jvmti_set_phase(JVMTI_PHASE_DEAD);
1839 if (jvmti) jvmti_agentunload();
1843 if (!link_class(class_java_lang_System)) {
1844 exceptions_print_stacktrace();
1848 /* call java.lang.System.exit(I)V */
1850 m = class_resolveclassmethod(class_java_lang_System,
1851 utf_new_char("exit"),
1853 class_java_lang_Object,
1857 exceptions_print_stacktrace();
1861 /* call the exit function with passed exit status */
1863 (void) vm_call_method(m, NULL, status);
1865 /* If we had an exception, just ignore the exception and exit with
1868 vm_shutdown(status);
1872 /* vm_shutdown *****************************************************************
1874 Terminates the system immediately without freeing memory explicitly
1875 (to be used only for abnormal termination).
1877 *******************************************************************************/
1879 void vm_shutdown(s4 status)
1882 #if defined(ENABLE_STATISTICS)
1883 || opt_getcompilingtime || opt_stat
1887 log_text("CACAO terminated by shutdown");
1888 dolog("Exit status: %d\n", (s4) status);
1892 #if defined(ENABLE_JVMTI)
1893 /* terminate cacaodbgserver */
1895 pthread_mutex_lock(&dbgcomlock);
1897 pthread_mutex_unlock(&dbgcomlock);
1898 jvmti_cacaodbgserver_quit();
1906 /* vm_exit_handler *************************************************************
1908 The exit_handler function is called upon program termination.
1910 ATTENTION: Don't free system resources here! Some threads may still
1911 be running as this is called from VMRuntime.exit(). The OS does the
1914 *******************************************************************************/
1916 void vm_exit_handler(void)
1918 #if !defined(NDEBUG)
1920 class_showmethods(mainclass);
1922 if (showconstantpool)
1923 class_showconstantpool(mainclass);
1928 # if defined(ENABLE_PROFILING)
1930 profile_printstats();
1932 #endif /* !defined(NDEBUG) */
1934 #if defined(ENABLE_RT_TIMING)
1935 rt_timing_print_time_stats(stderr);
1938 #if defined(ENABLE_CYCLES_STATS)
1939 builtin_print_cycles_stats(stderr);
1940 stacktrace_print_cycles_stats(stderr);
1944 #if defined(ENABLE_STATISTICS)
1945 || opt_getcompilingtime || opt_stat
1949 log_text("CACAO terminated");
1951 #if defined(ENABLE_STATISTICS)
1954 #ifdef TYPECHECK_STATISTICS
1955 typecheck_print_statistics(get_logfile());
1959 if (opt_getcompilingtime)
1961 #endif /* defined(ENABLE_STATISTICS) */
1963 /* vm_print_profile(stderr);*/
1967 /* vm_abort ********************************************************************
1969 Prints an error message and aborts the VM.
1971 *******************************************************************************/
1973 void vm_abort(const char *text, ...)
1977 /* print the log message */
1982 log_vprint(text, ap);
1987 /* now abort the VM */
1993 /* vm_get_mainclass_from_jar ***************************************************
1995 Gets the name of the main class from a JAR's manifest file.
1997 *******************************************************************************/
1999 static char *vm_get_mainclass_from_jar(char *mainstring)
2006 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2009 exceptions_print_stacktrace();
2013 /* create JarFile object */
2018 exceptions_print_stacktrace();
2022 m = class_resolveclassmethod(c,
2024 utf_java_lang_String__void,
2025 class_java_lang_Object,
2029 exceptions_print_stacktrace();
2033 s = javastring_new_from_ascii(mainstring);
2035 (void) vm_call_method(m, o, s);
2037 if (exceptions_get_exception()) {
2038 exceptions_print_stacktrace();
2042 /* get manifest object */
2044 m = class_resolveclassmethod(c,
2045 utf_new_char("getManifest"),
2046 utf_new_char("()Ljava/util/jar/Manifest;"),
2047 class_java_lang_Object,
2051 exceptions_print_stacktrace();
2055 o = vm_call_method(m, o);
2058 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2063 /* get Main Attributes */
2065 LLNI_class_get(o, c);
2067 m = class_resolveclassmethod(c,
2068 utf_new_char("getMainAttributes"),
2069 utf_new_char("()Ljava/util/jar/Attributes;"),
2070 class_java_lang_Object,
2074 exceptions_print_stacktrace();
2078 o = vm_call_method(m, o);
2081 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2086 /* get property Main-Class */
2088 LLNI_class_get(o, c);
2090 m = class_resolveclassmethod(c,
2091 utf_new_char("getValue"),
2092 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2093 class_java_lang_Object,
2097 exceptions_print_stacktrace();
2101 s = javastring_new_from_ascii("Main-Class");
2103 o = vm_call_method(m, o, s);
2106 exceptions_print_stacktrace();
2110 return javastring_tochar(o);
2114 /* vm_compile_all **************************************************************
2116 Compile all methods found in the bootclasspath.
2118 *******************************************************************************/
2120 #if !defined(NDEBUG)
2121 static void vm_compile_all(void)
2126 classcache_name_entry *nmen;
2127 classcache_class_entry *clsen;
2130 /* create all classes found in the bootclasspath */
2131 /* XXX currently only works with zip/jar's */
2133 loader_load_all_classes();
2135 /* link all classes */
2137 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2138 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2140 for (; nmen; nmen = nmen->hashlink) {
2141 /* iterate over all class entries */
2143 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2144 c = clsen->classobj;
2149 if (!(c->state & CLASS_LINKED)) {
2150 if (!link_class(c)) {
2151 fprintf(stderr, "Error linking: ");
2152 utf_fprint_printable_ascii_classname(stderr, c->name);
2153 fprintf(stderr, "\n");
2155 /* print out exception and cause */
2157 exceptions_print_current_exception();
2159 /* goto next class */
2165 /* compile all class methods */
2167 for (i = 0; i < c->methodscount; i++) {
2168 m = &(c->methods[i]);
2170 if (m->jcode != NULL) {
2171 if (!jit_compile(m)) {
2172 fprintf(stderr, "Error compiling: ");
2173 utf_fprint_printable_ascii_classname(stderr, c->name);
2174 fprintf(stderr, ".");
2175 utf_fprint_printable_ascii(stderr, m->name);
2176 utf_fprint_printable_ascii(stderr, m->descriptor);
2177 fprintf(stderr, "\n");
2179 /* print out exception and cause */
2181 exceptions_print_current_exception();
2189 #endif /* !defined(NDEBUG) */
2192 /* vm_compile_method ***********************************************************
2194 Compile a specific method.
2196 *******************************************************************************/
2198 #if !defined(NDEBUG)
2199 static void vm_compile_method(void)
2203 /* create, load and link the main class */
2205 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2207 if (mainclass == NULL)
2208 exceptions_print_stacktrace();
2210 if (!link_class(mainclass))
2211 exceptions_print_stacktrace();
2213 if (opt_signature != NULL) {
2214 m = class_resolveclassmethod(mainclass,
2215 utf_new_char(opt_method),
2216 utf_new_char(opt_signature),
2221 m = class_resolveclassmethod(mainclass,
2222 utf_new_char(opt_method),
2229 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2230 opt_method, opt_signature ? opt_signature : "");
2234 #endif /* !defined(NDEBUG) */
2237 /* vm_array_store_int **********************************************************
2239 Helper function to store an integer into the argument array, taking
2240 care of architecture specific issues.
2242 *******************************************************************************/
2244 static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
2248 if (!pd->inmemory) {
2250 array[index] = (int64_t) value;
2253 index = ARG_CNT + pd->index;
2254 #if SIZEOF_VOID_P == 8
2255 array[index] = (int64_t) value;
2257 # if WORDS_BIGENDIAN == 1
2258 array[index] = ((int64_t) value) << 32;
2260 array[index] = (int64_t) value;
2267 /* vm_array_store_lng **********************************************************
2269 Helper function to store a long into the argument array, taking
2270 care of architecture specific issues.
2272 *******************************************************************************/
2274 static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
2278 #if SIZEOF_VOID_P == 8
2282 index = ARG_CNT + pd->index;
2284 array[index] = value;
2286 if (!pd->inmemory) {
2287 /* move low and high 32-bits into it's own argument slot */
2289 index = GET_LOW_REG(pd->index);
2290 array[index] = value & 0x00000000ffffffff;
2292 index = GET_HIGH_REG(pd->index);
2293 array[index] = value >> 32;
2296 index = ARG_CNT + pd->index;
2297 array[index] = value;
2303 /* vm_array_store_flt **********************************************************
2305 Helper function to store a float into the argument array, taking
2306 care of architecture specific issues.
2308 *******************************************************************************/
2310 static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
2314 if (!pd->inmemory) {
2315 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2318 index = INT_ARG_CNT + pd->index;
2320 #if WORDS_BIGENDIAN == 1 && !defined(__POWERPC__) && !defined(__POWERPC64__) && !defined(__S390__)
2321 array[index] = value >> 32;
2323 array[index] = value;
2327 index = ARG_CNT + pd->index;
2328 #if defined(__SPARC_64__)
2329 array[index] = value >> 32;
2331 array[index] = value;
2337 /* vm_array_store_dbl **********************************************************
2339 Helper function to store a double into the argument array, taking
2340 care of architecture specific issues.
2342 *******************************************************************************/
2344 static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
2348 if (!pd->inmemory) {
2349 #if SIZEOF_VOID_P != 8 && defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2350 index = GET_LOW_REG(pd->index);
2351 array[index] = value & 0x00000000ffffffff;
2353 index = GET_HIGH_REG(pd->index);
2354 array[index] = value >> 32;
2356 index = INT_ARG_CNT + pd->index;
2357 array[index] = value;
2361 index = ARG_CNT + pd->index;
2362 array[index] = value;
2367 /* vm_array_store_adr **********************************************************
2369 Helper function to store an address into the argument array, taking
2370 care of architecture specific issues.
2372 *******************************************************************************/
2374 static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
2378 if (!pd->inmemory) {
2379 #if defined(HAS_ADDRESS_REGISTER_FILE)
2380 /* When the architecture has address registers, place them
2381 after integer and float registers. */
2383 index = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
2387 array[index] = (uint64_t) (intptr_t) value;
2390 index = ARG_CNT + pd->index;
2391 #if SIZEOF_VOID_P == 8
2392 array[index] = (uint64_t) (intptr_t) value;
2394 # if WORDS_BIGENDIAN == 1
2395 array[index] = ((uint64_t) (intptr_t) value) << 32;
2397 array[index] = (uint64_t) (intptr_t) value;
2404 /* vm_array_from_valist ********************************************************
2408 *******************************************************************************/
2410 uint64_t *vm_array_from_valist(methodinfo *m, java_handle_t *o, va_list ap)
2419 /* get the descriptors */
2423 td = md->paramtypes;
2425 /* allocate argument array */
2427 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2429 /* if method is non-static fill first block and skip `this' pointer */
2434 /* the `this' pointer */
2435 vm_array_store_adr(array, pd, o);
2442 for (; i < md->paramcount; i++, pd++, td++) {
2445 value.i = va_arg(ap, int32_t);
2446 vm_array_store_int(array, pd, value.i);
2450 value.l = va_arg(ap, int64_t);
2451 vm_array_store_lng(array, pd, value.l);
2455 #if defined(__ALPHA__) || defined(__POWERPC__) || defined(__POWERPC64__)
2456 /* This is required to load the correct float value in
2459 value.d = (double) va_arg(ap, double);
2461 value.f = (float) va_arg(ap, double);
2463 vm_array_store_flt(array, pd, value.l);
2467 value.d = va_arg(ap, double);
2468 vm_array_store_dbl(array, pd, value.l);
2472 value.a = va_arg(ap, void*);
2473 vm_array_store_adr(array, pd, value.a);
2482 /* vm_array_from_jvalue ********************************************************
2486 *******************************************************************************/
2488 static uint64_t *vm_array_from_jvalue(methodinfo *m, java_handle_t *o,
2498 /* get the descriptors */
2502 td = md->paramtypes;
2504 /* allocate argument array */
2506 #if defined(HAS_ADDRESS_REGISTER_FILE)
2507 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
2509 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2512 /* if method is non-static fill first block and skip `this' pointer */
2517 /* the `this' pointer */
2518 vm_array_store_adr(array, pd, o);
2525 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2526 switch (td->decltype) {
2528 vm_array_store_int(array, pd, args[j].i);
2532 vm_array_store_lng(array, pd, args[j].j);
2536 vm_array_store_flt(array, pd, args[j].j);
2540 vm_array_store_dbl(array, pd, args[j].j);
2544 vm_array_store_adr(array, pd, args[j].l);
2553 /* vm_array_from_objectarray ***************************************************
2557 *******************************************************************************/
2559 uint64_t *vm_array_from_objectarray(methodinfo *m, java_handle_t *o,
2560 java_handle_objectarray_t *params)
2566 java_handle_t *param;
2573 /* get the descriptors */
2577 td = md->paramtypes;
2579 /* allocate argument array */
2581 array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
2583 /* if method is non-static fill first block and skip `this' pointer */
2589 vm_array_store_adr(array, pd, o);
2596 for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
2597 LLNI_objectarray_element_get(params, j, param);
2601 if (param == NULL) {
2602 exceptions_throw_illegalargumentexception();
2606 /* convert the value according to its declared type */
2608 LLNI_class_get(param, c);
2609 type = primitive_type_get_by_wrapperclass(c);
2611 switch (td->decltype) {
2612 case PRIMITIVETYPE_BOOLEAN:
2614 case PRIMITIVETYPE_BOOLEAN:
2615 /* This type is OK. */
2618 exceptions_throw_illegalargumentexception();
2623 case PRIMITIVETYPE_BYTE:
2625 case PRIMITIVETYPE_BYTE:
2626 /* This type is OK. */
2629 exceptions_throw_illegalargumentexception();
2634 case PRIMITIVETYPE_CHAR:
2636 case PRIMITIVETYPE_CHAR:
2637 /* This type is OK. */
2640 exceptions_throw_illegalargumentexception();
2645 case PRIMITIVETYPE_SHORT:
2647 case PRIMITIVETYPE_BYTE:
2648 case PRIMITIVETYPE_SHORT:
2649 /* These types are OK. */
2652 exceptions_throw_illegalargumentexception();
2657 case PRIMITIVETYPE_INT:
2659 case PRIMITIVETYPE_BYTE:
2660 case PRIMITIVETYPE_SHORT:
2661 case PRIMITIVETYPE_INT:
2662 /* These types are OK. */
2665 exceptions_throw_illegalargumentexception();
2671 vm_abort("vm_array_from_objectarray: invalid type %d",
2675 value = primitive_unbox(param);
2676 vm_array_store_int(array, pd, value.i);
2680 if (param == NULL) {
2681 exceptions_throw_illegalargumentexception();
2685 LLNI_class_get(param, c);
2686 type = primitive_type_get_by_wrapperclass(c);
2688 assert(td->decltype == PRIMITIVETYPE_LONG);
2691 case PRIMITIVETYPE_BYTE:
2692 case PRIMITIVETYPE_SHORT:
2693 case PRIMITIVETYPE_INT:
2694 case PRIMITIVETYPE_LONG:
2695 /* These types are OK. */
2698 exceptions_throw_illegalargumentexception();
2702 value = primitive_unbox(param);
2703 vm_array_store_lng(array, pd, value.l);
2707 if (param == NULL) {
2708 exceptions_throw_illegalargumentexception();
2712 LLNI_class_get(param, c);
2713 type = primitive_type_get_by_wrapperclass(c);
2715 assert(td->decltype == PRIMITIVETYPE_FLOAT);
2718 case PRIMITIVETYPE_FLOAT:
2719 /* This type is OK. */
2722 exceptions_throw_illegalargumentexception();
2726 value = primitive_unbox(param);
2727 vm_array_store_flt(array, pd, value.l);
2731 if (param == NULL) {
2732 exceptions_throw_illegalargumentexception();
2736 LLNI_class_get(param, c);
2737 type = primitive_type_get_by_wrapperclass(c);
2739 assert(td->decltype == PRIMITIVETYPE_DOUBLE);
2742 case PRIMITIVETYPE_FLOAT:
2743 case PRIMITIVETYPE_DOUBLE:
2744 /* These types are OK. */
2747 exceptions_throw_illegalargumentexception();
2751 value = primitive_unbox(param);
2752 vm_array_store_dbl(array, pd, value.l);
2756 if (!resolve_class_from_typedesc(td, true, true, &c))
2759 if (param != NULL) {
2760 if (td->arraydim > 0) {
2761 if (!builtin_arrayinstanceof(param, c)) {
2762 exceptions_throw_illegalargumentexception();
2767 if (!builtin_instanceof(param, c)) {
2768 exceptions_throw_illegalargumentexception();
2774 vm_array_store_adr(array, pd, param);
2778 vm_abort("vm_array_from_objectarray: invalid type %d", td->type);
2786 /* vm_call_method **************************************************************
2788 Calls a Java method with a variable number of arguments.
2790 *******************************************************************************/
2792 #define VM_CALL_METHOD(name, type) \
2793 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2799 value = vm_call_method##name##_valist(m, o, ap); \
2805 VM_CALL_METHOD(, java_handle_t *)
2806 VM_CALL_METHOD(_int, int32_t)
2807 VM_CALL_METHOD(_long, int64_t)
2808 VM_CALL_METHOD(_float, float)
2809 VM_CALL_METHOD(_double, double)
2812 /* vm_call_method_valist *******************************************************
2814 Calls a Java method with a variable number of arguments, passed via
2817 *******************************************************************************/
2819 #define VM_CALL_METHOD_VALIST(name, type) \
2820 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2827 dumpsize = dump_size(); \
2828 array = vm_array_from_valist(m, o, ap); \
2829 value = vm_call##name##_array(m, array); \
2830 dump_release(dumpsize); \
2835 VM_CALL_METHOD_VALIST(, java_handle_t *)
2836 VM_CALL_METHOD_VALIST(_int, int32_t)
2837 VM_CALL_METHOD_VALIST(_long, int64_t)
2838 VM_CALL_METHOD_VALIST(_float, float)
2839 VM_CALL_METHOD_VALIST(_double, double)
2842 /* vm_call_method_jvalue *******************************************************
2844 Calls a Java method with a variable number of arguments, passed via
2847 *******************************************************************************/
2849 #define VM_CALL_METHOD_JVALUE(name, type) \
2850 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2851 const jvalue *args) \
2857 dumpsize = dump_size(); \
2858 array = vm_array_from_jvalue(m, o, args); \
2859 value = vm_call##name##_array(m, array); \
2860 dump_release(dumpsize); \
2865 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2866 VM_CALL_METHOD_JVALUE(_int, int32_t)
2867 VM_CALL_METHOD_JVALUE(_long, int64_t)
2868 VM_CALL_METHOD_JVALUE(_float, float)
2869 VM_CALL_METHOD_JVALUE(_double, double)
2872 /* vm_call_array ***************************************************************
2874 Calls a Java method with a variable number of arguments, passed via
2877 *******************************************************************************/
2879 #define VM_CALL_ARRAY(name, type) \
2880 type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2886 md = m->parseddesc; \
2888 if (m->code == NULL) \
2889 if (!jit_compile(m)) \
2892 pv = m->code->entrypoint; \
2894 STATISTICS(count_calls_native_to_java++); \
2896 value = asm_vm_call_method##name(pv, array, md->memuse); \
2901 VM_CALL_ARRAY(, java_handle_t *)
2902 VM_CALL_ARRAY(_int, int32_t)
2903 VM_CALL_ARRAY(_long, int64_t)
2904 VM_CALL_ARRAY(_float, float)
2905 VM_CALL_ARRAY(_double, double)
2909 * These are local overrides for various environment variables in Emacs.
2910 * Please do not remove this and leave it at the end of the file, where
2911 * Emacs will automagically detect them.
2912 * ---------------------------------------------------------------------
2915 * indent-tabs-mode: t
2919 * vim:noexpandtab:sw=4:ts=4: