1 /* src/vm/vm.c - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
38 #include "vm/jit/abi-asm.h"
40 #include "mm/codememory.h"
41 #include "mm/gc-common.h"
42 #include "mm/memory.h"
44 #include "native/jni.h"
45 #include "native/llni.h"
46 #include "native/localref.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/lock-common.h"
62 #include "threads/mutex.h"
63 #include "threads/threadlist.h"
64 #include "threads/thread.h"
66 #include "toolbox/logging.h"
70 #if defined(ENABLE_ASSERTION)
71 #include "vm/assertion.h"
74 #include "vm/builtin.h"
75 #include "vm/exceptions.h"
76 #include "vm/finalizer.h"
77 #include "vm/global.h"
78 #include "vm/initialize.h"
79 #include "vm/package.h"
80 #include "vm/primitive.h"
81 #include "vm/properties.h"
82 #include "vm/signallocal.h"
83 #include "vm/stringlocal.h"
86 #include "vm/jit/argument.h"
87 #include "vm/jit/asmpart.h"
88 #include "vm/jit/code.h"
90 #if defined(ENABLE_DISASSEMBLER)
91 # include "vm/jit/disass.h"
94 #include "vm/jit/jit.h"
95 #include "vm/jit/methodtree.h"
97 #if defined(ENABLE_PROFILING)
98 # include "vm/jit/optimizing/profile.h"
101 #include "vm/jit/optimizing/recompile.h"
103 #if defined(ENABLE_PYTHON)
104 # include "vm/jit/python.h"
107 #include "vm/jit/trap.h"
109 #include "vmcore/classcache.h"
110 #include "vmcore/options.h"
111 #include "vmcore/statistics.h"
112 #include "vmcore/suck.h"
113 #include "vmcore/system.h"
115 #if defined(ENABLE_JVMTI)
116 # include "native/jvmti/cacaodbg.h"
119 #if defined(ENABLE_VMLOG)
120 #include <vmlog_cacao.h>
124 /* Invocation API variables ***************************************************/
126 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
127 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
130 /* global variables ***********************************************************/
132 s4 vms = 0; /* number of VMs created */
134 bool vm_initializing = false;
135 bool vm_created = false;
136 bool vm_exiting = false;
138 static classinfo *mainclass = NULL;
140 #if defined(ENABLE_INTRP)
141 u1 *intrp_main_stack = NULL;
145 /* define heap sizes **********************************************************/
147 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
148 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
149 #define STACK_SIZE 128 * 1024 /* default 64kB */
152 /* define command line options ************************************************/
186 /* Java non-standard options */
197 #if defined(ENABLE_PROFILING)
210 #if defined(ENABLE_STATISTICS)
227 #if defined(ENABLE_VERIFIER)
229 #if defined(TYPECHECK_VERBOSE)
232 #endif /* defined(ENABLE_VERIFIER) */
234 /* optimization options */
236 #if defined(ENABLE_LOOP)
240 #if defined(ENABLE_IFCONV)
244 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
248 #if defined(ENABLE_INTRP)
249 /* interpreter options */
268 #if defined(ENABLE_DEBUG_FILTER)
269 OPT_FILTER_VERBOSECALL_INCLUDE,
270 OPT_FILTER_VERBOSECALL_EXCLUDE,
271 OPT_FILTER_SHOW_METHOD,
278 opt_struct opts[] = {
279 { "foo", false, OPT_FOO },
283 { "jar", false, OPT_JAR },
285 { "d32", false, OPT_D32 },
286 { "d64", false, OPT_D64 },
287 { "client", false, OPT_IGNORE },
288 { "server", false, OPT_IGNORE },
289 { "jvm", false, OPT_IGNORE },
290 { "hotspot", false, OPT_IGNORE },
292 { "classpath", true, OPT_CLASSPATH },
293 { "cp", true, OPT_CLASSPATH },
294 { "D", true, OPT_D },
295 { "version", false, OPT_VERSION },
296 { "showversion", false, OPT_SHOWVERSION },
297 { "fullversion", false, OPT_FULLVERSION },
298 { "help", false, OPT_HELP },
299 { "?", false, OPT_HELP },
300 { "X", false, OPT_X },
301 { "XX:", true, OPT_XX },
303 { "ea:", true, OPT_EA },
304 { "da:", true, OPT_DA },
305 { "ea", false, OPT_EA_NOARG },
306 { "da", false, OPT_DA_NOARG },
308 { "enableassertions:", true, OPT_EA },
309 { "disableassertions:", true, OPT_DA },
310 { "enableassertions", false, OPT_EA_NOARG },
311 { "disableassertions", false, OPT_DA_NOARG },
313 { "esa", false, OPT_ESA },
314 { "enablesystemassertions", false, OPT_ESA },
315 { "dsa", false, OPT_DSA },
316 { "disablesystemassertions", false, OPT_DSA },
318 { "noasyncgc", false, OPT_IGNORE },
319 #if defined(ENABLE_VERIFIER)
320 { "noverify", false, OPT_NOVERIFY },
321 { "Xverify:none", false, OPT_NOVERIFY },
323 { "v", false, OPT_VERBOSE1 },
324 { "verbose:", true, OPT_VERBOSE },
326 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
327 { "verbosetc", false, OPT_VERBOSETC },
329 #if defined(__ALPHA__)
330 { "noieee", false, OPT_NOIEEE },
332 #if defined(ENABLE_STATISTICS)
333 { "time", false, OPT_TIME },
334 { "stat", false, OPT_STAT },
336 { "log", true, OPT_LOG },
337 { "c", true, OPT_CHECK },
338 { "l", false, OPT_LOAD },
341 { "all", false, OPT_ALL },
342 { "sig", true, OPT_SIGNATURE },
345 #if defined(ENABLE_LOOP)
346 { "oloop", false, OPT_OLOOP },
348 #if defined(ENABLE_IFCONV)
349 { "ifconv", false, OPT_IFCONV },
351 #if defined(ENABLE_LSRA)
352 { "lsra", false, OPT_LSRA },
354 #if defined(ENABLE_SSA)
355 { "lsra", true, OPT_LSRA },
358 #if defined(ENABLE_INTRP)
359 /* interpreter options */
361 { "trace", false, OPT_TRACE },
362 { "static-supers", true, OPT_STATIC_SUPERS },
363 { "no-dynamic", false, OPT_NO_DYNAMIC },
364 { "no-replication", false, OPT_NO_REPLICATION },
365 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
368 /* JVMTI Agent Command Line Options */
370 { "agentlib:", true, OPT_AGENTLIB },
371 { "agentpath:", true, OPT_AGENTPATH },
374 /* Java non-standard options */
376 { "Xjit", false, OPT_JIT },
377 { "Xint", false, OPT_INTRP },
378 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
379 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
380 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
381 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
384 { "Xdebug", false, OPT_DEBUG },
385 { "Xnoagent", false, OPT_NOAGENT },
386 { "Xrunjdwp", true, OPT_XRUNJDWP },
389 { "Xms", true, OPT_MS },
390 { "ms", true, OPT_MS },
391 { "Xmx", true, OPT_MX },
392 { "mx", true, OPT_MX },
393 { "Xss", true, OPT_SS },
394 { "ss", true, OPT_SS },
396 #if defined(ENABLE_PROFILING)
397 { "Xprof:", true, OPT_PROF_OPTION },
398 { "Xprof", false, OPT_PROF },
401 /* keep these at the end of the list */
404 { "m", true, OPT_METHOD },
407 { "s", true, OPT_SHOW },
408 { "debug-color", false, OPT_DEBUGCOLOR },
410 #if defined(ENABLE_DEBUG_FILTER)
411 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
412 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
413 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
420 /* usage ***********************************************************************
422 Prints the correct usage syntax to stdout.
424 *******************************************************************************/
428 puts("Usage: cacao [-options] classname [arguments]");
429 puts(" (to run a class file)");
430 puts(" or cacao [-options] -jar jarfile [arguments]");
431 puts(" (to run a standalone jar file)\n");
433 puts("where options include:");
434 puts(" -d32 use 32-bit data model if available");
435 puts(" -d64 use 64-bit data model if available");
436 puts(" -client compatibility (currently ignored)");
437 puts(" -server compatibility (currently ignored)");
438 puts(" -jvm compatibility (currently ignored)");
439 puts(" -hotspot compatibility (currently ignored)\n");
441 puts(" -cp <path> specify a path to look for classes");
442 puts(" -classpath <path> specify a path to look for classes");
443 puts(" -D<name>=<value> add an entry to the property list");
444 puts(" -verbose[:class|gc|jni] enable specific verbose output");
445 puts(" -version print product version and exit");
446 puts(" -fullversion print jpackage-compatible product version and exit");
447 puts(" -showversion print product version and continue");
448 puts(" -help, -? print this help message");
449 puts(" -X print help on non-standard Java options");
450 puts(" -XX print help on debugging options");
451 puts(" -ea[:<packagename>...|:<classname>]");
452 puts(" -enableassertions[:<packagename>...|:<classname>]");
453 puts(" enable assertions with specified granularity");
454 puts(" -da[:<packagename>...|:<classname>]");
455 puts(" -disableassertions[:<packagename>...|:<classname>]");
456 puts(" disable assertions with specified granularity");
457 puts(" -esa | -enablesystemassertions");
458 puts(" enable system assertions");
459 puts(" -dsa | -disablesystemassertions");
460 puts(" disable system assertions");
463 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
464 puts (" for jdwp help use: -agentlib:jdwp=help");
465 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
468 /* exit with error code */
474 static void Xusage(void)
476 #if defined(ENABLE_JIT)
477 puts(" -Xjit JIT mode execution (default)");
479 #if defined(ENABLE_INTRP)
480 puts(" -Xint interpreter mode execution");
482 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
483 puts(" value is set as bootstrap class path");
484 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
485 puts(" value is appended to the bootstrap class path");
486 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
487 puts(" value is prepended to the bootstrap class path");
488 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
489 puts(" value is used as Java core library, but the");
490 puts(" hardcoded VM interface classes are prepended");
491 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
492 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
493 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
495 #if defined(ENABLE_PROFILING)
496 puts(" -Xprof[:bb] collect and print profiling data");
499 #if defined(ENABLE_JVMTI)
500 /* -Xdebug option depend on gnu classpath JDWP options. options:
501 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
502 puts(" -Xdebug enable remote debugging\n");
503 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
504 puts(" enable remote debugging\n");
507 /* exit with error code */
514 static void XXusage(void)
516 puts(" -v write state-information");
518 puts(" -verbose:jit enable specific verbose output");
519 puts(" -debug-color colored output for ANSI terms");
521 #ifdef TYPECHECK_VERBOSE
522 puts(" -verbosetc write debug messages while typechecking");
524 #if defined(__ALPHA__)
525 puts(" -noieee don't use ieee compliant arithmetic");
527 #if defined(ENABLE_VERIFIER)
528 puts(" -noverify don't verify classfiles");
530 #if defined(ENABLE_STATISTICS)
531 puts(" -time measure the runtime");
532 puts(" -stat detailed compiler statistics");
534 puts(" -log logfile specify a name for the logfile");
535 puts(" -c(heck)b(ounds) don't check array bounds");
536 puts(" s(ync) don't check for synchronization");
537 #if defined(ENABLE_LOOP)
538 puts(" -oloop optimize array accesses in loops");
540 puts(" -l don't start the class after loading");
542 puts(" -all compile all methods, no execution");
543 puts(" -m compile only a specific method");
544 puts(" -sig specify signature for a specific method");
547 puts(" -s... show...");
548 puts(" (c)onstants the constant pool");
549 puts(" (m)ethods class fields and methods");
550 puts(" (u)tf the utf - hash");
551 puts(" (i)ntermediate intermediate representation");
552 #if defined(ENABLE_DISASSEMBLER)
553 puts(" (a)ssembler disassembled listing");
554 puts(" n(o)ps show NOPs in disassembler output");
556 puts(" (d)atasegment data segment listing");
558 #if defined(ENABLE_IFCONV)
559 puts(" -ifconv use if-conversion");
561 #if defined(ENABLE_LSRA)
562 puts(" -lsra use linear scan register allocation");
564 #if defined(ENABLE_SSA)
565 puts(" -lsra:... use linear scan register allocation (with SSA)");
566 puts(" (d)ead code elimination");
567 puts(" (c)opy propagation");
569 #if defined(ENABLE_DEBUG_FILTER)
570 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
571 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
572 puts(" -XXfm <regex> filter for show options");
574 /* exit with error code */
581 /* version *********************************************************************
583 Only prints cacao version information.
585 *******************************************************************************/
587 static void version(bool opt_exit)
589 puts("java version \""JAVA_VERSION"\"");
590 puts("CACAO version "VERSION"\n");
592 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
593 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
594 puts("This is free software; see the source for copying conditions. There is NO");
595 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
597 /* exit normally, if requested */
604 /* fullversion *****************************************************************
606 Prints a Sun compatible version information (required e.g. by
607 jpackage, www.jpackage.org).
609 *******************************************************************************/
611 static void fullversion(void)
613 puts("java full version \"cacao-"JAVA_VERSION"\"");
621 static void vm_printconfig(void)
623 puts("Configure/Build options:\n");
624 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
625 #if defined(__VERSION__)
626 puts(" CC : "VERSION_CC" ("__VERSION__")");
628 puts(" CC : "VERSION_CC"");
630 puts(" CFLAGS : "VERSION_CFLAGS"\n");
632 puts("Default variables:\n");
633 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
634 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
635 printf(" stack size : %d\n", STACK_SIZE);
637 #if defined(ENABLE_JRE_LAYOUT)
638 /* When we're building with JRE-layout, the default paths are the
639 same as the runtime paths. */
641 # if defined(WITH_CLASSPATH_GNU)
642 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
643 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
644 # elif defined(WITH_CLASSPATH_SUN)
645 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
646 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
652 puts("Runtime variables:\n");
653 printf(" maximum heap size : %d\n", opt_heapmaxsize);
654 printf(" initial heap size : %d\n", opt_heapstartsize);
655 printf(" stack size : %d\n", opt_stacksize);
657 #if defined(WITH_CLASSPATH_GNU)
658 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
659 #elif defined(WITH_CLASSPATH_SUN)
660 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
663 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
664 printf(" java.class.path : %s\n", properties_get("java.class.path"));
668 /* forward declarations *******************************************************/
670 static char *vm_get_mainclass_from_jar(char *mainstring);
672 static void vm_compile_all(void);
673 static void vm_compile_method(char* mainname);
677 /* vm_createjvm ****************************************************************
679 Implementation for JNI_CreateJavaVM.
681 *******************************************************************************/
683 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
685 JavaVMInitArgs *_vm_args;
689 /* get the arguments for the new JVM */
691 _vm_args = (JavaVMInitArgs *) vm_args;
693 /* get the VM and Env tables (must be set before vm_create) */
695 env = NEW(_Jv_JNIEnv);
697 #if defined(ENABLE_JNI)
698 env->env = &_Jv_JNINativeInterface;
701 /* XXX Set the global variable. Maybe we should do that differently. */
705 /* create and fill a JavaVM structure */
707 vm = NEW(_Jv_JavaVM);
709 #if defined(ENABLE_JNI)
710 vm->functions = &_Jv_JNIInvokeInterface;
713 /* XXX Set the global variable. Maybe we should do that differently. */
714 /* XXX JVMTI Agents needs a JavaVM */
718 /* actually create the JVM */
720 if (!vm_create(_vm_args))
723 /* now return the values */
725 *p_vm = (JavaVM *) vm;
726 *p_env = (void *) env;
731 /* release allocated memory */
733 FREE(env, _Jv_JNIEnv);
734 FREE(vm, _Jv_JavaVM);
740 /* vm_create *******************************************************************
742 Creates a JVM. Called by vm_createjvm.
744 *******************************************************************************/
746 bool vm_create(JavaVMInitArgs *vm_args)
750 char *boot_class_path;
757 #if defined(ENABLE_JVMTI)
759 char *libname, *agentarg;
760 bool jdwp,agentbypath;
761 jdwp = agentbypath = false;
764 #if defined(ENABLE_JNI)
765 /* Check the JNI version requested. */
767 if (!jni_version_check(vm_args->version))
771 /* We only support 1 JVM instance. */
776 /* Install the exit handler. */
778 if (atexit(vm_exit_handler))
779 vm_abort("atexit failed: %s\n", strerror(errno));
781 /* Set some options. */
788 opt_heapmaxsize = HEAP_MAXSIZE;
789 opt_heapstartsize = HEAP_STARTSIZE;
790 opt_stacksize = STACK_SIZE;
792 /* Initialize the properties list before command-line handling.
793 Otherwise -XX:+PrintConfig crashes. */
797 /* First of all, parse the -XX options. */
799 #if defined(ENABLE_VMLOG)
800 vmlog_cacao_init_options();
805 #if defined(ENABLE_VMLOG)
809 /* We need to check if the actual size of a java.lang.Class object
810 is smaller or equal than the assumption made in
811 src/vmcore/class.h. */
813 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
814 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
816 /* set the VM starttime */
818 _Jv_jvm->starttime = builtin_currenttimemillis();
820 #if defined(ENABLE_JVMTI)
821 /* initialize JVMTI related **********************************************/
825 /* Fill the properties before command-line handling. */
829 /* iterate over all passed options */
831 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
845 #if SIZEOF_VOID_P == 8
846 puts("Running a 32-bit JVM is not supported on this platform.");
852 #if SIZEOF_VOID_P == 4
853 puts("Running a 64-bit JVM is not supported on this platform.");
859 /* Forget old classpath and set the argument as new
862 class_path = properties_get("java.class.path");
864 p = MNEW(char, strlen(opt_arg) + strlen("0"));
868 #if defined(ENABLE_JAVASE)
869 properties_add("java.class.path", p);
872 MFREE(class_path, char, strlen(class_path));
876 for (i = 0; i < strlen(opt_arg); i++) {
877 if (opt_arg[i] == '=') {
879 properties_add(opt_arg, opt_arg + i + 1);
884 /* if no '=' is given, just create an empty property */
886 properties_add(opt_arg, "");
891 case OPT_BOOTCLASSPATH:
892 /* Forget default bootclasspath and set the argument as
893 new boot classpath. */
895 boot_class_path = properties_get("sun.boot.class.path");
897 p = MNEW(char, strlen(opt_arg) + strlen("0"));
901 properties_add("sun.boot.class.path", p);
902 properties_add("java.boot.class.path", p);
904 MFREE(boot_class_path, char, strlen(boot_class_path));
907 case OPT_BOOTCLASSPATH_A:
908 /* Append to bootclasspath. */
910 boot_class_path = properties_get("sun.boot.class.path");
912 len = strlen(boot_class_path);
914 p = MREALLOC(boot_class_path,
918 strlen(opt_arg) + strlen("0"));
923 properties_add("sun.boot.class.path", p);
924 properties_add("java.boot.class.path", p);
927 case OPT_BOOTCLASSPATH_P:
928 /* Prepend to bootclasspath. */
930 boot_class_path = properties_get("sun.boot.class.path");
932 len = strlen(boot_class_path);
934 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
938 strcat(p, boot_class_path);
940 properties_add("sun.boot.class.path", p);
941 properties_add("java.boot.class.path", p);
943 MFREE(boot_class_path, char, len);
946 case OPT_BOOTCLASSPATH_C:
947 /* Use as Java core library, but prepend VM interface
950 boot_class_path = properties_get("sun.boot.class.path");
953 strlen(CACAO_VM_ZIP) +
960 strcpy(p, CACAO_VM_ZIP);
964 properties_add("sun.boot.class.path", p);
965 properties_add("java.boot.class.path", p);
967 MFREE(boot_class_path, char, strlen(boot_class_path));
970 #if defined(ENABLE_JVMTI)
972 /* this option exists only for compatibility reasons */
976 /* I don't know yet what Xnoagent should do. This is only for
977 compatiblity with eclipse - motse */
986 strlen(CACAO_LIBDIR) +
987 strlen("/libjdwp.so=") +
991 agentarg = MNEW(char, len);
993 strcpy(agentarg, CACAO_LIBDIR);
994 strcat(agentarg, "/libjdwp.so=");
995 strcat(agentarg, &opt_arg[1]);
1012 c = opt_arg[strlen(opt_arg) - 1];
1014 if ((c == 'k') || (c == 'K')) {
1015 j = atoi(opt_arg) * 1024;
1017 } else if ((c == 'm') || (c == 'M')) {
1018 j = atoi(opt_arg) * 1024 * 1024;
1024 opt_heapmaxsize = j;
1025 else if (opt == OPT_MS)
1026 opt_heapstartsize = j;
1037 if (strcmp("class", opt_arg) == 0) {
1038 opt_verboseclass = true;
1040 else if (strcmp("gc", opt_arg) == 0) {
1041 opt_verbosegc = true;
1043 else if (strcmp("jni", opt_arg) == 0) {
1044 opt_verbosejni = true;
1046 #if !defined(NDEBUG)
1047 else if (strcmp("jit", opt_arg) == 0) {
1051 compileverbose = true;
1055 printf("Unknown -verbose option: %s\n", opt_arg);
1060 case OPT_DEBUGCOLOR:
1061 opt_debugcolor = true;
1064 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1066 opt_typecheckverbose = true;
1075 case OPT_FULLVERSION:
1079 case OPT_SHOWVERSION:
1087 #if defined(ENABLE_VERIFIER)
1093 #if defined(ENABLE_STATISTICS)
1095 opt_getcompilingtime = true;
1096 opt_getloadingtime = true;
1109 for (i = 0; i < strlen(opt_arg); i++) {
1110 switch (opt_arg[i]) {
1112 checkbounds = false;
1125 makeinitializations = false;
1128 #if !defined(NDEBUG)
1132 makeinitializations = false;
1137 opt_method = opt_arg;
1138 makeinitializations = false;
1142 opt_signature = opt_arg;
1146 case OPT_SHOW: /* Display options */
1147 for (i = 0; i < strlen(opt_arg); i++) {
1148 switch (opt_arg[i]) {
1150 showconstantpool = true;
1162 opt_showintermediate = true;
1163 compileverbose = true;
1166 #if defined(ENABLE_DISASSEMBLER)
1168 opt_showdisassemble = true;
1169 compileverbose = true;
1173 opt_shownops = true;
1178 opt_showddatasegment = true;
1187 #if defined(ENABLE_LOOP)
1193 #if defined(ENABLE_IFCONV)
1199 #if defined(ENABLE_LSRA)
1204 #if defined(ENABLE_SSA)
1207 for (i = 0; i < strlen(opt_arg); i++) {
1208 switch (opt_arg[i]) {
1236 /* Already parsed. */
1240 #if defined(ENABLE_ASSERTION)
1241 assertion_ea_da(opt_arg, true);
1246 #if defined(ENABLE_ASSERTION)
1247 assertion_ea_da(opt_arg, false);
1252 #if defined(ENABLE_ASSERTION)
1253 assertion_user_enabled = true;
1258 #if defined(ENABLE_ASSERTION)
1259 assertion_user_enabled = false;
1264 #if defined(ENABLE_ASSERTION)
1265 assertion_system_enabled = true;
1270 #if defined(ENABLE_ASSERTION)
1271 assertion_system_enabled = false;
1275 #if defined(ENABLE_PROFILING)
1276 case OPT_PROF_OPTION:
1277 /* use <= to get the last \0 too */
1279 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1280 if (opt_arg[i] == ',')
1283 if (opt_arg[i] == '\0') {
1284 if (strcmp("bb", opt_arg + j) == 0)
1288 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1292 /* set k to next char */
1305 #if defined(ENABLE_JIT)
1308 printf("-Xjit option not enabled.\n");
1314 #if defined(ENABLE_INTRP)
1317 printf("-Xint option not enabled.\n");
1322 #if defined(ENABLE_INTRP)
1323 case OPT_STATIC_SUPERS:
1324 opt_static_supers = atoi(opt_arg);
1327 case OPT_NO_DYNAMIC:
1328 opt_no_dynamic = true;
1331 case OPT_NO_REPLICATION:
1332 opt_no_replication = true;
1335 case OPT_NO_QUICKSUPER:
1336 opt_no_quicksuper = true;
1344 #if defined(ENABLE_DEBUG_FILTER)
1345 case OPT_FILTER_VERBOSECALL_INCLUDE:
1346 opt_filter_verbosecall_include = opt_arg;
1349 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1350 opt_filter_verbosecall_exclude = opt_arg;
1353 case OPT_FILTER_SHOW_METHOD:
1354 opt_filter_show_method = opt_arg;
1359 printf("Unknown option: %s\n",
1360 vm_args->options[opt_index].optionString);
1365 #if defined(ENABLE_JVMTI)
1367 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1368 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1371 MFREE(agentarg, char, strlen(agentarg));
1373 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1377 /* initialize this JVM ****************************************************/
1379 vm_initializing = true;
1381 /* initialize the garbage collector */
1383 gc_init(opt_heapmaxsize, opt_heapstartsize);
1385 #if defined(ENABLE_THREADS)
1386 /* BEFORE: threads_preinit */
1390 /* AFTER: gc_init (directly after, as this initializes the
1391 stopworldlock lock */
1398 /* install architecture dependent signal handlers */
1401 vm_abort("vm_create: signal_init failed");
1403 #if defined(ENABLE_INTRP)
1404 /* Allocate main thread stack on the Java heap. */
1407 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1408 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1412 /* AFTER: threads_preinit */
1415 vm_abort("vm_create: string_init failed");
1417 /* AFTER: threads_preinit */
1421 /* AFTER: thread_preinit */
1424 vm_abort("vm_create: suck_init failed");
1426 suck_add_from_property("java.endorsed.dirs");
1428 /* Now we have all options handled and we can print the version
1431 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1436 /* AFTER: utf8_init */
1438 boot_class_path = properties_get("sun.boot.class.path");
1439 suck_add(boot_class_path);
1441 /* initialize the classcache hashtable stuff: lock, hashtable
1442 (must be done _after_ threads_preinit) */
1444 if (!classcache_init())
1445 vm_abort("vm_create: classcache_init failed");
1447 /* Initialize the code memory management. */
1448 /* AFTER: threads_preinit */
1452 /* initialize the finalizer stuff (must be done _after_
1455 if (!finalizer_init())
1456 vm_abort("vm_create: finalizer_init failed");
1458 /* Initialize the JIT compiler. */
1464 #if defined(ENABLE_PYTHON)
1468 /* BEFORE: loader_preinit */
1472 /* AFTER: utf8_init, classcache_init */
1477 /* AFTER: loader_preinit, linker_preinit */
1484 /* AFTER: loader_init, linker_init */
1486 primitive_postinit();
1489 #if defined(ENABLE_JIT)
1493 if (!builtin_init())
1494 vm_abort("vm_create: builtin_init failed");
1496 /* Initialize the native subsystem. */
1497 /* BEFORE: threads_init */
1500 vm_abort("vm_create: native_init failed");
1502 /* Register the native methods implemented in the VM. */
1503 /* BEFORE: threads_init */
1507 #if defined(ENABLE_JNI)
1508 /* Initialize the JNI subsystem (must be done _before_
1509 threads_init, as threads_init can call JNI methods
1510 (e.g. NewGlobalRef). */
1513 vm_abort("vm_create: jni_init failed");
1516 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1517 /* Initialize the local reference table for the main thread. */
1518 /* BEFORE: threads_init */
1520 if (!localref_table_init())
1521 vm_abort("vm_create: localref_table_init failed");
1524 /* Iinitialize some important system classes. */
1525 /* BEFORE: threads_init */
1529 #if defined(ENABLE_THREADS)
1533 /* Initialize the native VM subsystem. */
1534 /* AFTER: threads_init (at least for SUN's classes) */
1538 #if defined(ENABLE_PROFILING)
1539 /* initialize profiling */
1541 if (!profile_init())
1542 vm_abort("vm_create: profile_init failed");
1545 #if defined(ENABLE_THREADS)
1546 /* initialize recompilation */
1548 if (!recompile_init())
1549 vm_abort("vm_create: recompile_init failed");
1551 /* start the signal handler thread */
1553 #if defined(__LINUX__)
1554 /* XXX Remove for exact-GC. */
1555 if (threads_pthreads_implementation_nptl)
1557 if (!signal_start_thread())
1558 vm_abort("vm_create: signal_start_thread failed");
1560 /* finally, start the finalizer thread */
1562 if (!finalizer_start_thread())
1563 vm_abort("vm_create: finalizer_start_thread failed");
1565 # if !defined(NDEBUG)
1566 /* start the memory profiling thread */
1568 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1569 if (!memory_start_thread())
1570 vm_abort("vm_create: memory_start_thread failed");
1573 /* start the recompilation thread (must be done before the
1574 profiling thread) */
1576 if (!recompile_start_thread())
1577 vm_abort("vm_create: recompile_start_thread failed");
1579 # if defined(ENABLE_PROFILING)
1580 /* start the profile sampling thread */
1583 /* if (!profile_start_thread()) */
1584 /* vm_abort("vm_create: profile_start_thread failed"); */
1588 #if defined(ENABLE_JVMTI)
1589 # if defined(ENABLE_GC_CACAO)
1590 /* XXX this will not work with the new indirection cells for classloaders!!! */
1594 /* add agent library to native library hashtable */
1595 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1599 /* Increment the number of VMs. */
1603 /* Initialization is done, VM is created.. */
1606 vm_initializing = false;
1608 /* Print the VM configuration after all stuff is set and the VM is
1611 if (opt_PrintConfig)
1614 /* everything's ok */
1620 /* vm_run **********************************************************************
1622 Runs the main-method of the passed class.
1624 *******************************************************************************/
1626 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1632 classinfo *mainclass;
1635 java_handle_objectarray_t *oa;
1642 #if defined(ENABLE_THREADS)
1646 #if !defined(NDEBUG)
1653 /* Get the main class plus it's arguments. */
1657 if (opt_index < vm_args->nOptions) {
1658 /* Get main-class argument. */
1660 mainname = vm_args->options[opt_index].optionString;
1662 /* If the main class argument is a jar file, put it into the
1665 if (opt_jar == true) {
1666 p = MNEW(char, strlen(mainname) + strlen("0"));
1668 strcpy(p, mainname);
1670 #if defined(ENABLE_JAVASE)
1671 properties_add("java.class.path", p);
1675 /* Replace dots with slashes in the class name. */
1677 for (i = 0; i < strlen(mainname); i++)
1678 if (mainname[i] == '.')
1682 /* Build argument array. Move index to first argument. */
1686 oalength = vm_args->nOptions - opt_index;
1688 oa = builtin_anewarray(oalength, class_java_lang_String);
1690 for (i = 0; i < oalength; i++) {
1691 option = vm_args->options[opt_index + i].optionString;
1693 u = utf_new_char(option);
1694 s = javastring_new(u);
1696 array_objectarray_element_set(oa, i, s);
1700 /* Do we have a main-class argument? */
1702 if (mainname == NULL)
1705 #if !defined(NDEBUG)
1706 if (opt_method != NULL) {
1707 vm_compile_method(mainname);
1712 /* set return value to OK */
1716 if (opt_jar == true) {
1717 /* open jar file with java.util.jar.JarFile */
1719 mainname = vm_get_mainclass_from_jar(mainname);
1721 if (mainname == NULL)
1725 /* load the main class */
1727 mainutf = utf_new_char(mainname);
1729 #if defined(ENABLE_JAVAME_CLDC1_1)
1730 mainclass = load_class_bootstrap(mainutf);
1732 mainclass = load_class_from_sysloader(mainutf);
1735 /* error loading class */
1737 e = exceptions_get_and_clear_exception();
1739 if ((e != NULL) || (mainclass == NULL)) {
1740 exceptions_throw_noclassdeffounderror_cause(e);
1741 exceptions_print_stacktrace();
1745 if (!link_class(mainclass)) {
1746 exceptions_print_stacktrace();
1750 /* find the `main' method of the main class */
1752 m = class_resolveclassmethod(mainclass,
1753 utf_new_char("main"),
1754 utf_new_char("([Ljava/lang/String;)V"),
1755 class_java_lang_Object,
1758 if (exceptions_get_exception()) {
1759 exceptions_print_stacktrace();
1763 /* there is no main method or it isn't static */
1765 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1766 exceptions_clear_exception();
1767 exceptions_throw_nosuchmethoderror(mainclass,
1768 utf_new_char("main"),
1769 utf_new_char("([Ljava/lang/String;)V"));
1771 exceptions_print_stacktrace();
1775 #ifdef TYPEINFO_DEBUG_TEST
1776 /* test the typeinfo system */
1780 #if defined(ENABLE_JVMTI)
1781 jvmti_set_phase(JVMTI_PHASE_LIVE);
1784 /* set ThreadMXBean variables */
1786 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1787 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1789 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1790 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1791 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1792 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1794 /* start the main thread */
1796 (void) vm_call_method(m, NULL, oa);
1798 /* exception occurred? */
1800 if (exceptions_get_exception()) {
1801 exceptions_print_stacktrace();
1805 #if defined(ENABLE_THREADS)
1806 /* Detach the main thread so that it appears to have ended when
1807 the application's main method exits. */
1809 t = thread_get_current();
1811 if (!threads_detach_thread(t))
1812 vm_abort("vm_run: Could not detach main thread.");
1815 /* Destroy the JavaVM. */
1817 (void) vm_destroy(vm);
1825 /* vm_destroy ******************************************************************
1827 Unloads a Java VM and reclaims its resources.
1829 *******************************************************************************/
1831 int vm_destroy(JavaVM *vm)
1833 #if defined(ENABLE_THREADS)
1834 /* Create a a trivial new Java waiter thread called
1837 JavaVMAttachArgs args;
1839 args.name = "DestroyJavaVM";
1842 if (!threads_attach_current_thread(&args, false))
1845 /* Wait until we are the last non-daemon thread. */
1847 threads_join_all_threads();
1854 /* Everything is ok. */
1860 /* vm_exit *********************************************************************
1862 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1864 *******************************************************************************/
1866 void vm_exit(s4 status)
1870 /* signal that we are exiting */
1874 assert(class_java_lang_System);
1875 assert(class_java_lang_System->state & CLASS_LOADED);
1877 #if defined(ENABLE_JVMTI)
1878 if (jvmti || (dbgcom!=NULL)) {
1879 jvmti_set_phase(JVMTI_PHASE_DEAD);
1880 if (jvmti) jvmti_agentunload();
1884 if (!link_class(class_java_lang_System)) {
1885 exceptions_print_stacktrace();
1889 /* call java.lang.System.exit(I)V */
1891 m = class_resolveclassmethod(class_java_lang_System,
1892 utf_new_char("exit"),
1894 class_java_lang_Object,
1898 exceptions_print_stacktrace();
1902 /* call the exit function with passed exit status */
1904 (void) vm_call_method(m, NULL, status);
1906 /* If we had an exception, just ignore the exception and exit with
1909 vm_shutdown(status);
1913 /* vm_shutdown *****************************************************************
1915 Terminates the system immediately without freeing memory explicitly
1916 (to be used only for abnormal termination).
1918 *******************************************************************************/
1920 void vm_shutdown(s4 status)
1923 #if defined(ENABLE_STATISTICS)
1924 || opt_getcompilingtime || opt_stat
1928 log_text("CACAO terminated by shutdown");
1929 dolog("Exit status: %d\n", (s4) status);
1933 #if defined(ENABLE_JVMTI)
1934 /* terminate cacaodbgserver */
1936 mutex_lock(&dbgcomlock);
1938 mutex_unlock(&dbgcomlock);
1939 jvmti_cacaodbgserver_quit();
1947 /* vm_exit_handler *************************************************************
1949 The exit_handler function is called upon program termination.
1951 ATTENTION: Don't free system resources here! Some threads may still
1952 be running as this is called from VMRuntime.exit(). The OS does the
1955 *******************************************************************************/
1957 void vm_exit_handler(void)
1959 #if !defined(NDEBUG)
1961 class_showmethods(mainclass);
1963 if (showconstantpool)
1964 class_showconstantpool(mainclass);
1969 # if defined(ENABLE_PROFILING)
1971 profile_printstats();
1973 #endif /* !defined(NDEBUG) */
1975 #if defined(ENABLE_RT_TIMING)
1976 rt_timing_print_time_stats(stderr);
1979 #if defined(ENABLE_CYCLES_STATS)
1980 builtin_print_cycles_stats(stderr);
1981 stacktrace_print_cycles_stats(stderr);
1985 #if defined(ENABLE_STATISTICS)
1986 || opt_getcompilingtime || opt_stat
1990 log_text("CACAO terminated");
1992 #if defined(ENABLE_STATISTICS)
1995 #ifdef TYPECHECK_STATISTICS
1996 typecheck_print_statistics(get_logfile());
2000 if (opt_getcompilingtime)
2002 #endif /* defined(ENABLE_STATISTICS) */
2004 /* vm_print_profile(stderr);*/
2008 /* vm_abort ********************************************************************
2010 Prints an error message and aborts the VM.
2013 text ... error message to print
2015 *******************************************************************************/
2017 void vm_abort(const char *text, ...)
2021 /* Print the log message. */
2026 log_vprint(text, ap);
2031 /* Now abort the VM. */
2037 /* vm_abort_errnum *************************************************************
2039 Prints an error message, appends ":" plus the strerror-message of
2040 errnum and aborts the VM.
2043 errnum ... error number
2044 text ..... error message to print
2046 *******************************************************************************/
2048 void vm_abort_errnum(int errnum, const char *text, ...)
2052 /* Print the log message. */
2057 log_vprint(text, ap);
2060 /* Print the strerror-message of errnum. */
2062 log_print(": %s", system_strerror(errnum));
2066 /* Now abort the VM. */
2072 /* vm_abort_errno **************************************************************
2074 Equal to vm_abort_errnum, but uses errno to get the error number.
2077 text ... error message to print
2079 *******************************************************************************/
2081 void vm_abort_errno(const char *text, ...)
2086 vm_abort_errnum(errno, text, ap);
2091 /* vm_abort_disassemble ********************************************************
2093 Prints an error message, disassemble the given code range (if
2094 enabled) and aborts the VM.
2097 pc.......PC to disassemble
2098 count....number of instructions to disassemble
2100 *******************************************************************************/
2102 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2105 #if defined(ENABLE_DISASSEMBLER)
2109 /* Print debug message. */
2114 log_vprint(text, ap);
2121 #if SIZEOF_VOID_P == 8
2122 log_println("PC=0x%016lx", pc);
2124 log_println("PC=0x%08x", pc);
2127 #if defined(ENABLE_DISASSEMBLER)
2128 log_println("machine instructions at PC:");
2130 /* Disassemble the given number of instructions. */
2132 for (i = 0; i < count; i++)
2133 pc = disassinstr(pc);
2136 vm_abort("Aborting...");
2140 /* vm_get_mainclass_from_jar ***************************************************
2142 Gets the name of the main class from a JAR's manifest file.
2144 *******************************************************************************/
2146 static char *vm_get_mainclass_from_jar(char *mainname)
2153 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2156 exceptions_print_stacktrace();
2160 /* create JarFile object */
2165 exceptions_print_stacktrace();
2169 m = class_resolveclassmethod(c,
2171 utf_java_lang_String__void,
2172 class_java_lang_Object,
2176 exceptions_print_stacktrace();
2180 s = javastring_new_from_ascii(mainname);
2182 (void) vm_call_method(m, o, s);
2184 if (exceptions_get_exception()) {
2185 exceptions_print_stacktrace();
2189 /* get manifest object */
2191 m = class_resolveclassmethod(c,
2192 utf_new_char("getManifest"),
2193 utf_new_char("()Ljava/util/jar/Manifest;"),
2194 class_java_lang_Object,
2198 exceptions_print_stacktrace();
2202 o = vm_call_method(m, o);
2205 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2210 /* get Main Attributes */
2212 LLNI_class_get(o, c);
2214 m = class_resolveclassmethod(c,
2215 utf_new_char("getMainAttributes"),
2216 utf_new_char("()Ljava/util/jar/Attributes;"),
2217 class_java_lang_Object,
2221 exceptions_print_stacktrace();
2225 o = vm_call_method(m, o);
2228 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2233 /* get property Main-Class */
2235 LLNI_class_get(o, c);
2237 m = class_resolveclassmethod(c,
2238 utf_new_char("getValue"),
2239 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2240 class_java_lang_Object,
2244 exceptions_print_stacktrace();
2248 s = javastring_new_from_ascii("Main-Class");
2250 o = vm_call_method(m, o, s);
2253 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2254 fprintf(stderr, "%s\n", mainname);
2258 return javastring_tochar(o);
2262 /* vm_compile_all **************************************************************
2264 Compile all methods found in the bootclasspath.
2266 *******************************************************************************/
2268 #if !defined(NDEBUG)
2269 static void vm_compile_all(void)
2274 classcache_name_entry *nmen;
2275 classcache_class_entry *clsen;
2278 /* create all classes found in the bootclasspath */
2279 /* XXX currently only works with zip/jar's */
2281 loader_load_all_classes();
2283 /* link all classes */
2285 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2286 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2288 for (; nmen; nmen = nmen->hashlink) {
2289 /* iterate over all class entries */
2291 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2292 c = clsen->classobj;
2297 if (!(c->state & CLASS_LINKED)) {
2298 if (!link_class(c)) {
2299 fprintf(stderr, "Error linking: ");
2300 utf_fprint_printable_ascii_classname(stderr, c->name);
2301 fprintf(stderr, "\n");
2303 /* print out exception and cause */
2305 exceptions_print_current_exception();
2307 /* goto next class */
2313 /* compile all class methods */
2315 for (i = 0; i < c->methodscount; i++) {
2316 m = &(c->methods[i]);
2318 if (m->jcode != NULL) {
2319 if (!jit_compile(m)) {
2320 fprintf(stderr, "Error compiling: ");
2321 utf_fprint_printable_ascii_classname(stderr, c->name);
2322 fprintf(stderr, ".");
2323 utf_fprint_printable_ascii(stderr, m->name);
2324 utf_fprint_printable_ascii(stderr, m->descriptor);
2325 fprintf(stderr, "\n");
2327 /* print out exception and cause */
2329 exceptions_print_current_exception();
2337 #endif /* !defined(NDEBUG) */
2340 /* vm_compile_method ***********************************************************
2342 Compile a specific method.
2344 *******************************************************************************/
2346 #if !defined(NDEBUG)
2347 static void vm_compile_method(char* mainname)
2351 /* create, load and link the main class */
2353 mainclass = load_class_bootstrap(utf_new_char(mainname));
2355 if (mainclass == NULL)
2356 exceptions_print_stacktrace();
2358 if (!link_class(mainclass))
2359 exceptions_print_stacktrace();
2361 if (opt_signature != NULL) {
2362 m = class_resolveclassmethod(mainclass,
2363 utf_new_char(opt_method),
2364 utf_new_char(opt_signature),
2369 m = class_resolveclassmethod(mainclass,
2370 utf_new_char(opt_method),
2377 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2378 opt_method, opt_signature ? opt_signature : "");
2382 #endif /* !defined(NDEBUG) */
2385 /* vm_call_array ***************************************************************
2387 Calls a Java method with a variable number of arguments, passed via
2390 ATTENTION: This function has to be used outside the nativeworld.
2392 *******************************************************************************/
2394 #define VM_CALL_ARRAY(name, type) \
2395 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2401 assert(m->code != NULL); \
2403 md = m->parseddesc; \
2404 pv = m->code->entrypoint; \
2406 STATISTICS(count_calls_native_to_java++); \
2408 value = asm_vm_call_method##name(pv, array, md->memuse); \
2413 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2419 assert(m->code != NULL);
2422 pv = m->code->entrypoint;
2424 STATISTICS(count_calls_native_to_java++);
2426 o = asm_vm_call_method(pv, array, md->memuse);
2428 if (md->returntype.type == TYPE_VOID)
2431 return LLNI_WRAP(o);
2434 VM_CALL_ARRAY(_int, int32_t)
2435 VM_CALL_ARRAY(_long, int64_t)
2436 VM_CALL_ARRAY(_float, float)
2437 VM_CALL_ARRAY(_double, double)
2440 /* vm_call_method **************************************************************
2442 Calls a Java method with a variable number of arguments.
2444 *******************************************************************************/
2446 #define VM_CALL_METHOD(name, type) \
2447 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2453 value = vm_call_method##name##_valist(m, o, ap); \
2459 VM_CALL_METHOD(, java_handle_t *)
2460 VM_CALL_METHOD(_int, int32_t)
2461 VM_CALL_METHOD(_long, int64_t)
2462 VM_CALL_METHOD(_float, float)
2463 VM_CALL_METHOD(_double, double)
2466 /* vm_call_method_valist *******************************************************
2468 Calls a Java method with a variable number of arguments, passed via
2471 *******************************************************************************/
2473 #define VM_CALL_METHOD_VALIST(name, type) \
2474 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2479 int32_t dumpmarker; \
2481 if (m->code == NULL) \
2482 if (!jit_compile(m)) \
2485 THREAD_NATIVEWORLD_EXIT; \
2488 array = argument_vmarray_from_valist(m, o, ap); \
2489 value = vm_call##name##_array(m, array); \
2492 THREAD_NATIVEWORLD_ENTER; \
2497 VM_CALL_METHOD_VALIST(, java_handle_t *)
2498 VM_CALL_METHOD_VALIST(_int, int32_t)
2499 VM_CALL_METHOD_VALIST(_long, int64_t)
2500 VM_CALL_METHOD_VALIST(_float, float)
2501 VM_CALL_METHOD_VALIST(_double, double)
2504 /* vm_call_method_jvalue *******************************************************
2506 Calls a Java method with a variable number of arguments, passed via
2509 *******************************************************************************/
2511 #define VM_CALL_METHOD_JVALUE(name, type) \
2512 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2513 const jvalue *args) \
2517 int32_t dumpmarker; \
2519 if (m->code == NULL) \
2520 if (!jit_compile(m)) \
2523 THREAD_NATIVEWORLD_EXIT; \
2526 array = argument_vmarray_from_jvalue(m, o, args); \
2527 value = vm_call##name##_array(m, array); \
2530 THREAD_NATIVEWORLD_ENTER; \
2535 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2536 VM_CALL_METHOD_JVALUE(_int, int32_t)
2537 VM_CALL_METHOD_JVALUE(_long, int64_t)
2538 VM_CALL_METHOD_JVALUE(_float, float)
2539 VM_CALL_METHOD_JVALUE(_double, double)
2542 /* vm_call_method_objectarray **************************************************
2544 Calls a Java method with a variable number if arguments, passed via
2545 an objectarray of boxed values. Returns a boxed value.
2547 *******************************************************************************/
2549 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2550 java_handle_objectarray_t *params)
2553 java_handle_t *xptr;
2558 /* Prevent compiler warnings. */
2562 /* compile methods which are not yet compiled */
2564 if (m->code == NULL)
2565 if (!jit_compile(m))
2568 /* leave the nativeworld */
2570 THREAD_NATIVEWORLD_EXIT;
2572 /* mark start of dump memory area */
2576 /* Fill the argument array from a object-array. */
2578 array = argument_vmarray_from_objectarray(m, o, params);
2580 if (array == NULL) {
2581 /* release dump area */
2585 /* enter the nativeworld again */
2587 THREAD_NATIVEWORLD_ENTER;
2589 exceptions_throw_illegalargumentexception();
2594 switch (m->parseddesc->returntype.decltype) {
2595 case PRIMITIVETYPE_VOID:
2596 value.a = vm_call_array(m, array);
2599 case PRIMITIVETYPE_BOOLEAN:
2600 case PRIMITIVETYPE_BYTE:
2601 case PRIMITIVETYPE_CHAR:
2602 case PRIMITIVETYPE_SHORT:
2603 case PRIMITIVETYPE_INT:
2604 value.i = vm_call_int_array(m, array);
2607 case PRIMITIVETYPE_LONG:
2608 value.l = vm_call_long_array(m, array);
2611 case PRIMITIVETYPE_FLOAT:
2612 value.f = vm_call_float_array(m, array);
2615 case PRIMITIVETYPE_DOUBLE:
2616 value.d = vm_call_double_array(m, array);
2620 ro = vm_call_array(m, array);
2624 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2627 /* release dump area */
2631 /* enter the nativeworld again */
2633 THREAD_NATIVEWORLD_ENTER;
2635 /* box the return value if necesarry */
2637 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2638 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2640 /* check for an exception */
2642 xptr = exceptions_get_exception();
2645 /* clear exception pointer, we are calling JIT code again */
2647 exceptions_clear_exception();
2649 exceptions_throw_invocationtargetexception(xptr);
2657 * These are local overrides for various environment variables in Emacs.
2658 * Please do not remove this and leave it at the end of the file, where
2659 * Emacs will automagically detect them.
2660 * ---------------------------------------------------------------------
2663 * indent-tabs-mode: t
2667 * vim:noexpandtab:sw=4:ts=4: