1 /* src/vm/vm.cpp - 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
41 #include "vm/jit/abi-asm.h"
43 #include "mm/codememory.h"
45 #include "mm/memory.h"
47 #include "native/jni.h"
48 #include "native/llni.h"
49 #include "native/localref.h"
50 #include "native/native.h"
52 #include "native/include/java_lang_Object.h" /* required by j.l.C */
53 #include "native/include/java_lang_String.h" /* required by j.l.C */
55 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
56 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
57 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
60 #include "native/include/java_lang_Class.h"
62 #include "native/vm/nativevm.h"
64 #include "threads/lock-common.h"
65 #include "threads/threadlist.h"
66 #include "threads/thread.hpp"
68 #include "toolbox/logging.h"
72 #if defined(ENABLE_ASSERTION)
73 #include "vm/assertion.h"
76 #include "vm/builtin.h"
77 #include "vm/exceptions.hpp"
78 #include "vm/finalizer.h"
79 #include "vm/global.h"
80 #include "vm/initialize.h"
81 #include "vm/package.hpp"
82 #include "vm/primitive.hpp"
83 #include "vm/properties.h"
84 #include "vm/signallocal.h"
85 #include "vm/string.hpp"
88 #include "vm/jit/argument.h"
89 #include "vm/jit/asmpart.h"
90 #include "vm/jit/code.h"
92 #if defined(ENABLE_DISASSEMBLER)
93 # include "vm/jit/disass.h"
96 #include "vm/jit/jit.h"
97 #include "vm/jit/methodtree.h"
99 #if defined(ENABLE_PROFILING)
100 # include "vm/jit/optimizing/profile.h"
103 #include "vm/jit/optimizing/recompile.h"
105 #if defined(ENABLE_PYTHON)
106 # include "vm/jit/python.h"
109 #include "vm/jit/trap.h"
111 #include "vmcore/classcache.h"
112 #include "vmcore/globals.hpp"
113 #include "vmcore/options.h"
114 #include "vmcore/statistics.h"
115 #include "vmcore/suck.h"
116 #include "vmcore/os.hpp"
118 #if defined(ENABLE_JVMTI)
119 # include "native/jvmti/cacaodbg.h"
122 #if defined(ENABLE_VMLOG)
123 #include <vmlog_cacao.h>
128 * This is _the_ instance of the VM.
133 /* global variables ***********************************************************/
135 s4 vms = 0; /* number of VMs created */
137 static classinfo *mainclass = NULL;
139 #if defined(ENABLE_INTRP)
140 u1 *intrp_main_stack = NULL;
144 /* define heap sizes **********************************************************/
146 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
147 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
148 #define STACK_SIZE 128 * 1024 /* default 64kB */
151 /* define command line options ************************************************/
185 /* Java non-standard options */
196 #if defined(ENABLE_PROFILING)
209 #if defined(ENABLE_STATISTICS)
226 #if defined(ENABLE_VERIFIER)
228 #if defined(TYPECHECK_VERBOSE)
231 #endif /* defined(ENABLE_VERIFIER) */
233 /* optimization options */
235 #if defined(ENABLE_LOOP)
239 #if defined(ENABLE_IFCONV)
243 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
247 #if defined(ENABLE_INTRP)
248 /* interpreter options */
267 #if defined(ENABLE_DEBUG_FILTER)
268 OPT_FILTER_VERBOSECALL_INCLUDE,
269 OPT_FILTER_VERBOSECALL_EXCLUDE,
270 OPT_FILTER_SHOW_METHOD,
277 opt_struct opts[] = {
278 { "foo", false, OPT_FOO },
282 { "jar", false, OPT_JAR },
284 { "d32", false, OPT_D32 },
285 { "d64", false, OPT_D64 },
286 { "client", false, OPT_IGNORE },
287 { "server", false, OPT_IGNORE },
288 { "jvm", false, OPT_IGNORE },
289 { "hotspot", false, OPT_IGNORE },
291 { "classpath", true, OPT_CLASSPATH },
292 { "cp", true, OPT_CLASSPATH },
293 { "D", true, OPT_D },
294 { "version", false, OPT_VERSION },
295 { "showversion", false, OPT_SHOWVERSION },
296 { "fullversion", false, OPT_FULLVERSION },
297 { "help", false, OPT_HELP },
298 { "?", false, OPT_HELP },
299 { "X", false, OPT_X },
300 { "XX:", true, OPT_XX },
302 { "ea:", true, OPT_EA },
303 { "da:", true, OPT_DA },
304 { "ea", false, OPT_EA_NOARG },
305 { "da", false, OPT_DA_NOARG },
307 { "enableassertions:", true, OPT_EA },
308 { "disableassertions:", true, OPT_DA },
309 { "enableassertions", false, OPT_EA_NOARG },
310 { "disableassertions", false, OPT_DA_NOARG },
312 { "esa", false, OPT_ESA },
313 { "enablesystemassertions", false, OPT_ESA },
314 { "dsa", false, OPT_DSA },
315 { "disablesystemassertions", false, OPT_DSA },
317 { "noasyncgc", false, OPT_IGNORE },
318 #if defined(ENABLE_VERIFIER)
319 { "noverify", false, OPT_NOVERIFY },
320 { "Xverify:none", false, OPT_NOVERIFY },
322 { "v", false, OPT_VERBOSE1 },
323 { "verbose:", true, OPT_VERBOSE },
325 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
326 { "verbosetc", false, OPT_VERBOSETC },
328 #if defined(__ALPHA__)
329 { "noieee", false, OPT_NOIEEE },
331 #if defined(ENABLE_STATISTICS)
332 { "time", false, OPT_TIME },
333 { "stat", false, OPT_STAT },
335 { "log", true, OPT_LOG },
336 { "c", true, OPT_CHECK },
337 { "l", false, OPT_LOAD },
340 { "all", false, OPT_ALL },
341 { "sig", true, OPT_SIGNATURE },
344 #if defined(ENABLE_LOOP)
345 { "oloop", false, OPT_OLOOP },
347 #if defined(ENABLE_IFCONV)
348 { "ifconv", false, OPT_IFCONV },
350 #if defined(ENABLE_LSRA)
351 { "lsra", false, OPT_LSRA },
353 #if defined(ENABLE_SSA)
354 { "lsra", true, OPT_LSRA },
357 #if defined(ENABLE_INTRP)
358 /* interpreter options */
360 { "trace", false, OPT_TRACE },
361 { "static-supers", true, OPT_STATIC_SUPERS },
362 { "no-dynamic", false, OPT_NO_DYNAMIC },
363 { "no-replication", false, OPT_NO_REPLICATION },
364 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
367 /* JVMTI Agent Command Line Options */
369 { "agentlib:", true, OPT_AGENTLIB },
370 { "agentpath:", true, OPT_AGENTPATH },
373 /* Java non-standard options */
375 { "Xjit", false, OPT_JIT },
376 { "Xint", false, OPT_INTRP },
377 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
378 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
379 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
380 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
383 { "Xdebug", false, OPT_DEBUG },
384 { "Xnoagent", false, OPT_NOAGENT },
385 { "Xrunjdwp", true, OPT_XRUNJDWP },
388 { "Xms", true, OPT_MS },
389 { "ms", true, OPT_MS },
390 { "Xmx", true, OPT_MX },
391 { "mx", true, OPT_MX },
392 { "Xss", true, OPT_SS },
393 { "ss", true, OPT_SS },
395 #if defined(ENABLE_PROFILING)
396 { "Xprof:", true, OPT_PROF_OPTION },
397 { "Xprof", false, OPT_PROF },
400 /* keep these at the end of the list */
403 { "m", true, OPT_METHOD },
406 { "s", true, OPT_SHOW },
407 { "debug-color", false, OPT_DEBUGCOLOR },
409 #if defined(ENABLE_DEBUG_FILTER)
410 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
411 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
412 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
419 /* usage ***********************************************************************
421 Prints the correct usage syntax to stdout.
423 *******************************************************************************/
427 puts("Usage: cacao [-options] classname [arguments]");
428 puts(" (to run a class file)");
429 puts(" or cacao [-options] -jar jarfile [arguments]");
430 puts(" (to run a standalone jar file)\n");
432 puts("where options include:");
433 puts(" -d32 use 32-bit data model if available");
434 puts(" -d64 use 64-bit data model if available");
435 puts(" -client compatibility (currently ignored)");
436 puts(" -server compatibility (currently ignored)");
437 puts(" -jvm compatibility (currently ignored)");
438 puts(" -hotspot compatibility (currently ignored)\n");
440 puts(" -cp <path> specify a path to look for classes");
441 puts(" -classpath <path> specify a path to look for classes");
442 puts(" -D<name>=<value> add an entry to the property list");
443 puts(" -verbose[:class|gc|jni] enable specific verbose output");
444 puts(" -version print product version and exit");
445 puts(" -fullversion print jpackage-compatible product version and exit");
446 puts(" -showversion print product version and continue");
447 puts(" -help, -? print this help message");
448 puts(" -X print help on non-standard Java options");
449 puts(" -XX print help on debugging options");
450 puts(" -ea[:<packagename>...|:<classname>]");
451 puts(" -enableassertions[:<packagename>...|:<classname>]");
452 puts(" enable assertions with specified granularity");
453 puts(" -da[:<packagename>...|:<classname>]");
454 puts(" -disableassertions[:<packagename>...|:<classname>]");
455 puts(" disable assertions with specified granularity");
456 puts(" -esa | -enablesystemassertions");
457 puts(" enable system assertions");
458 puts(" -dsa | -disablesystemassertions");
459 puts(" disable system assertions");
462 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
463 puts (" for jdwp help use: -agentlib:jdwp=help");
464 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
467 /* exit with error code */
473 static void Xusage(void)
475 #if defined(ENABLE_JIT)
476 puts(" -Xjit JIT mode execution (default)");
478 #if defined(ENABLE_INTRP)
479 puts(" -Xint interpreter mode execution");
481 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
482 puts(" value is set as bootstrap class path");
483 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
484 puts(" value is appended to the bootstrap class path");
485 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
486 puts(" value is prepended to the bootstrap class path");
487 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
488 puts(" value is used as Java core library, but the");
489 puts(" hardcoded VM interface classes are prepended");
490 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
491 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
492 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
494 #if defined(ENABLE_PROFILING)
495 puts(" -Xprof[:bb] collect and print profiling data");
498 #if defined(ENABLE_JVMTI)
499 /* -Xdebug option depend on gnu classpath JDWP options. options:
500 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
501 puts(" -Xdebug enable remote debugging\n");
502 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
503 puts(" enable remote debugging\n");
506 /* exit with error code */
513 static void XXusage(void)
515 puts(" -v write state-information");
517 puts(" -verbose:jit enable specific verbose output");
518 puts(" -debug-color colored output for ANSI terms");
520 #ifdef TYPECHECK_VERBOSE
521 puts(" -verbosetc write debug messages while typechecking");
523 #if defined(__ALPHA__)
524 puts(" -noieee don't use ieee compliant arithmetic");
526 #if defined(ENABLE_VERIFIER)
527 puts(" -noverify don't verify classfiles");
529 #if defined(ENABLE_STATISTICS)
530 puts(" -time measure the runtime");
531 puts(" -stat detailed compiler statistics");
533 puts(" -log logfile specify a name for the logfile");
534 puts(" -c(heck)b(ounds) don't check array bounds");
535 puts(" s(ync) don't check for synchronization");
536 #if defined(ENABLE_LOOP)
537 puts(" -oloop optimize array accesses in loops");
539 puts(" -l don't start the class after loading");
541 puts(" -all compile all methods, no execution");
542 puts(" -m compile only a specific method");
543 puts(" -sig specify signature for a specific method");
546 puts(" -s... show...");
547 puts(" (c)onstants the constant pool");
548 puts(" (m)ethods class fields and methods");
549 puts(" (u)tf the utf - hash");
550 puts(" (i)ntermediate intermediate representation");
551 #if defined(ENABLE_DISASSEMBLER)
552 puts(" (a)ssembler disassembled listing");
553 puts(" n(o)ps show NOPs in disassembler output");
555 puts(" (d)atasegment data segment listing");
557 #if defined(ENABLE_IFCONV)
558 puts(" -ifconv use if-conversion");
560 #if defined(ENABLE_LSRA)
561 puts(" -lsra use linear scan register allocation");
563 #if defined(ENABLE_SSA)
564 puts(" -lsra:... use linear scan register allocation (with SSA)");
565 puts(" (d)ead code elimination");
566 puts(" (c)opy propagation");
568 #if defined(ENABLE_DEBUG_FILTER)
569 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
570 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
571 puts(" -XXfm <regex> filter for show options");
573 /* exit with error code */
580 /* version *********************************************************************
582 Only prints cacao version information.
584 *******************************************************************************/
586 static void version(bool opt_exit)
588 puts("java version \""JAVA_VERSION"\"");
589 puts("CACAO version "VERSION"\n");
591 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
592 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
593 puts("This is free software; see the source for copying conditions. There is NO");
594 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
596 /* exit normally, if requested */
603 /* fullversion *****************************************************************
605 Prints a Sun compatible version information (required e.g. by
606 jpackage, www.jpackage.org).
608 *******************************************************************************/
610 static void fullversion(void)
612 puts("java full version \"cacao-"JAVA_VERSION"\"");
620 static void vm_printconfig(void)
622 puts("Configure/Build options:\n");
623 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
624 #if defined(__VERSION__)
625 puts(" CC : "VERSION_CC" ("__VERSION__")");
627 puts(" CC : "VERSION_CC"");
629 puts(" CFLAGS : "VERSION_CFLAGS"\n");
631 puts("Default variables:\n");
632 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
633 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
634 printf(" stack size : %d\n", STACK_SIZE);
636 #if defined(ENABLE_JRE_LAYOUT)
637 /* When we're building with JRE-layout, the default paths are the
638 same as the runtime paths. */
640 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
641 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
642 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
643 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
644 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
645 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
651 puts("Runtime variables:\n");
652 printf(" maximum heap size : %d\n", opt_heapmaxsize);
653 printf(" initial heap size : %d\n", opt_heapstartsize);
654 printf(" stack size : %d\n", opt_stacksize);
656 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
657 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
658 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
659 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
662 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
663 printf(" java.class.path : %s\n", properties_get("java.class.path"));
667 /* forward declarations *******************************************************/
669 static char *vm_get_mainclass_from_jar(char *mainstring);
671 static void vm_compile_all(void);
672 static void vm_compile_method(char* mainname);
677 * Implementation for JNI_CreateJavaVM. This function creates a VM
684 * @return true on success, false otherwise.
686 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
688 JavaVMInitArgs* _vm_args;
690 // Get the arguments for the new JVM.
691 _vm_args = (JavaVMInitArgs *) vm_args;
693 // Instantiate a new VM.
695 vm = new VM(_vm_args);
697 catch (std::exception e) {
698 // FIXME How can we delete the resources allocated?
699 // /* release allocated memory */
700 // FREE(env, _Jv_JNIEnv);
701 // FREE(vm, _Jv_JavaVM);
708 // Return the values.
710 *p_vm = vm->get_javavm();
711 *p_env = vm->get_jnienv();
718 * C wrapper for VM::create.
721 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
723 return VM::create(p_vm, p_env, vm_args);
731 VM::VM(JavaVMInitArgs* vm_args)
733 // Very first thing to do: we are initializing.
734 _initializing = true;
736 // Make ourself globally visible.
737 // XXX Is this a good idea?
740 /* create and fill a JavaVM structure */
742 _javavm = new JavaVM();
744 #if defined(ENABLE_JNI)
745 _javavm->functions = &_Jv_JNIInvokeInterface;
748 /* get the VM and Env tables (must be set before vm_create) */
749 /* XXX JVMTI Agents needs a JavaVM */
751 _jnienv = new JNIEnv();
753 #if defined(ENABLE_JNI)
754 _jnienv->functions = &_Jv_JNINativeInterface;
757 /* actually create the JVM */
761 char *boot_class_path;
767 #if defined(ENABLE_JVMTI)
769 char *libname, *agentarg;
770 bool jdwp,agentbypath;
771 jdwp = agentbypath = false;
774 #if defined(ENABLE_JNI)
775 /* Check the JNI version requested. */
777 if (!jni_version_check(vm_args->version))
778 throw std::exception();
781 /* We only support 1 JVM instance. */
784 throw std::exception();
786 /* Install the exit handler. */
788 if (atexit(vm_exit_handler))
789 vm_abort("atexit failed: %s\n", strerror(errno));
791 /* Set some options. */
798 opt_heapmaxsize = HEAP_MAXSIZE;
799 opt_heapstartsize = HEAP_STARTSIZE;
800 opt_stacksize = STACK_SIZE;
802 /* Initialize the properties list before command-line handling.
803 Otherwise -XX:+PrintConfig crashes. */
807 /* First of all, parse the -XX options. */
809 #if defined(ENABLE_VMLOG)
810 vmlog_cacao_init_options();
815 #if defined(ENABLE_VMLOG)
819 /* We need to check if the actual size of a java.lang.Class object
820 is smaller or equal than the assumption made in
821 src/vmcore/class.h. */
823 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
824 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
826 /* set the VM starttime */
828 _starttime = builtin_currenttimemillis();
830 #if defined(ENABLE_JVMTI)
831 /* initialize JVMTI related **********************************************/
835 /* Fill the properties before command-line handling. */
839 /* iterate over all passed options */
841 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
855 #if SIZEOF_VOID_P == 8
856 puts("Running a 32-bit JVM is not supported on this platform.");
862 #if SIZEOF_VOID_P == 4
863 puts("Running a 64-bit JVM is not supported on this platform.");
869 /* Forget old classpath and set the argument as new
872 // FIXME Make class_path const char*.
873 class_path = (char*) properties_get("java.class.path");
875 p = MNEW(char, strlen(opt_arg) + strlen("0"));
879 #if defined(ENABLE_JAVASE)
880 properties_add("java.class.path", p);
883 MFREE(class_path, char, strlen(class_path));
887 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
888 if (opt_arg[i] == '=') {
890 properties_add(opt_arg, opt_arg + i + 1);
895 /* if no '=' is given, just create an empty property */
897 properties_add(opt_arg, "");
902 case OPT_BOOTCLASSPATH:
903 /* Forget default bootclasspath and set the argument as
904 new boot classpath. */
906 // FIXME Make boot_class_path const char*.
907 boot_class_path = (char*) properties_get("sun.boot.class.path");
909 p = MNEW(char, strlen(opt_arg) + strlen("0"));
913 properties_add("sun.boot.class.path", p);
914 properties_add("java.boot.class.path", p);
916 MFREE(boot_class_path, char, strlen(boot_class_path));
919 case OPT_BOOTCLASSPATH_A:
920 /* Append to bootclasspath. */
922 // FIXME Make boot_class_path const char*.
923 boot_class_path = (char*) properties_get("sun.boot.class.path");
925 len = strlen(boot_class_path);
927 // XXX (char*) quick hack
928 p = (char*) MREALLOC(boot_class_path,
932 strlen(opt_arg) + strlen("0"));
937 properties_add("sun.boot.class.path", p);
938 properties_add("java.boot.class.path", p);
941 case OPT_BOOTCLASSPATH_P:
942 /* Prepend to bootclasspath. */
944 // FIXME Make boot_class_path const char*.
945 boot_class_path = (char*) properties_get("sun.boot.class.path");
947 len = strlen(boot_class_path);
949 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
953 strcat(p, boot_class_path);
955 properties_add("sun.boot.class.path", p);
956 properties_add("java.boot.class.path", p);
958 MFREE(boot_class_path, char, len);
961 case OPT_BOOTCLASSPATH_C:
962 /* Use as Java core library, but prepend VM interface
965 // FIXME Make boot_class_path const char*.
966 boot_class_path = (char*) properties_get("sun.boot.class.path");
969 strlen(CACAO_VM_ZIP) +
976 strcpy(p, CACAO_VM_ZIP);
980 properties_add("sun.boot.class.path", p);
981 properties_add("java.boot.class.path", p);
983 MFREE(boot_class_path, char, strlen(boot_class_path));
986 #if defined(ENABLE_JVMTI)
988 /* this option exists only for compatibility reasons */
992 /* I don't know yet what Xnoagent should do. This is only for
993 compatiblity with eclipse - motse */
1002 strlen(CACAO_LIBDIR) +
1003 strlen("/libjdwp.so=") +
1007 agentarg = MNEW(char, len);
1009 strcpy(agentarg, CACAO_LIBDIR);
1010 strcat(agentarg, "/libjdwp.so=");
1011 strcat(agentarg, &opt_arg[1]);
1030 c = opt_arg[strlen(opt_arg) - 1];
1032 if ((c == 'k') || (c == 'K')) {
1033 j = atoi(opt_arg) * 1024;
1035 } else if ((c == 'm') || (c == 'M')) {
1036 j = atoi(opt_arg) * 1024 * 1024;
1042 opt_heapmaxsize = j;
1043 else if (opt == OPT_MS)
1044 opt_heapstartsize = j;
1055 if (strcmp("class", opt_arg) == 0) {
1056 opt_verboseclass = true;
1058 else if (strcmp("gc", opt_arg) == 0) {
1059 opt_verbosegc = true;
1061 else if (strcmp("jni", opt_arg) == 0) {
1062 opt_verbosejni = true;
1064 #if !defined(NDEBUG)
1065 else if (strcmp("jit", opt_arg) == 0) {
1069 compileverbose = true;
1073 printf("Unknown -verbose option: %s\n", opt_arg);
1078 case OPT_DEBUGCOLOR:
1079 opt_debugcolor = true;
1082 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1084 opt_typecheckverbose = true;
1093 case OPT_FULLVERSION:
1097 case OPT_SHOWVERSION:
1105 #if defined(ENABLE_VERIFIER)
1111 #if defined(ENABLE_STATISTICS)
1113 opt_getcompilingtime = true;
1114 opt_getloadingtime = true;
1127 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1128 switch (opt_arg[i]) {
1130 checkbounds = false;
1143 makeinitializations = false;
1146 #if !defined(NDEBUG)
1150 makeinitializations = false;
1155 opt_method = opt_arg;
1156 makeinitializations = false;
1160 opt_signature = opt_arg;
1164 case OPT_SHOW: /* Display options */
1165 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1166 switch (opt_arg[i]) {
1168 showconstantpool = true;
1180 opt_showintermediate = true;
1181 compileverbose = true;
1184 #if defined(ENABLE_DISASSEMBLER)
1186 opt_showdisassemble = true;
1187 compileverbose = true;
1191 opt_shownops = true;
1196 opt_showddatasegment = true;
1205 #if defined(ENABLE_LOOP)
1211 #if defined(ENABLE_IFCONV)
1217 #if defined(ENABLE_LSRA)
1222 #if defined(ENABLE_SSA)
1225 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1226 switch (opt_arg[i]) {
1254 /* Already parsed. */
1258 #if defined(ENABLE_ASSERTION)
1259 assertion_ea_da(opt_arg, true);
1264 #if defined(ENABLE_ASSERTION)
1265 assertion_ea_da(opt_arg, false);
1270 #if defined(ENABLE_ASSERTION)
1271 assertion_user_enabled = true;
1276 #if defined(ENABLE_ASSERTION)
1277 assertion_user_enabled = false;
1282 #if defined(ENABLE_ASSERTION)
1283 assertion_system_enabled = true;
1288 #if defined(ENABLE_ASSERTION)
1289 assertion_system_enabled = false;
1293 #if defined(ENABLE_PROFILING)
1294 case OPT_PROF_OPTION:
1295 /* use <= to get the last \0 too */
1297 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1298 if (opt_arg[i] == ',')
1301 if (opt_arg[i] == '\0') {
1302 if (strcmp("bb", opt_arg + j) == 0)
1306 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1310 /* set k to next char */
1323 #if defined(ENABLE_JIT)
1326 printf("-Xjit option not enabled.\n");
1332 #if defined(ENABLE_INTRP)
1335 printf("-Xint option not enabled.\n");
1340 #if defined(ENABLE_INTRP)
1341 case OPT_STATIC_SUPERS:
1342 opt_static_supers = atoi(opt_arg);
1345 case OPT_NO_DYNAMIC:
1346 opt_no_dynamic = true;
1349 case OPT_NO_REPLICATION:
1350 opt_no_replication = true;
1353 case OPT_NO_QUICKSUPER:
1354 opt_no_quicksuper = true;
1362 #if defined(ENABLE_DEBUG_FILTER)
1363 case OPT_FILTER_VERBOSECALL_INCLUDE:
1364 opt_filter_verbosecall_include = opt_arg;
1367 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1368 opt_filter_verbosecall_exclude = opt_arg;
1371 case OPT_FILTER_SHOW_METHOD:
1372 opt_filter_show_method = opt_arg;
1377 printf("Unknown option: %s\n",
1378 vm_args->options[opt_index].optionString);
1383 #if defined(ENABLE_JVMTI)
1385 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1386 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1389 MFREE(agentarg, char, strlen(agentarg));
1391 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1395 /* initialize the garbage collector */
1397 gc_init(opt_heapmaxsize, opt_heapstartsize);
1399 #if defined(ENABLE_THREADS)
1400 /* BEFORE: threads_preinit */
1404 /* AFTER: gc_init */
1410 /* install architecture dependent signal handlers */
1413 vm_abort("vm_create: signal_init failed");
1415 #if defined(ENABLE_INTRP)
1416 /* Allocate main thread stack on the Java heap. */
1419 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1420 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1424 /* AFTER: threads_preinit */
1427 vm_abort("vm_create: string_init failed");
1429 /* AFTER: threads_preinit */
1433 /* AFTER: thread_preinit */
1436 vm_abort("vm_create: suck_init failed");
1438 suck_add_from_property("java.endorsed.dirs");
1440 /* Now we have all options handled and we can print the version
1443 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1448 /* AFTER: utf8_init */
1450 // FIXME Make boot_class_path const char*.
1451 boot_class_path = (char*) properties_get("sun.boot.class.path");
1452 suck_add(boot_class_path);
1454 /* initialize the classcache hashtable stuff: lock, hashtable
1455 (must be done _after_ threads_preinit) */
1457 if (!classcache_init())
1458 vm_abort("vm_create: classcache_init failed");
1460 /* Initialize the code memory management. */
1461 /* AFTER: threads_preinit */
1465 /* initialize the finalizer stuff (must be done _after_
1468 if (!finalizer_init())
1469 vm_abort("vm_create: finalizer_init failed");
1471 /* Initialize the JIT compiler. */
1477 #if defined(ENABLE_PYTHON)
1481 /* BEFORE: loader_preinit */
1483 Package::initialize();
1485 /* AFTER: utf8_init, classcache_init */
1490 /* AFTER: loader_preinit, linker_preinit */
1497 /* AFTER: loader_init, linker_init */
1499 primitive_postinit();
1502 #if defined(ENABLE_JIT)
1506 if (!builtin_init())
1507 vm_abort("vm_create: builtin_init failed");
1509 /* Initialize the native subsystem. */
1510 /* BEFORE: threads_init */
1513 vm_abort("vm_create: native_init failed");
1515 /* Register the native methods implemented in the VM. */
1516 /* BEFORE: threads_init */
1520 #if defined(ENABLE_JNI)
1521 /* Initialize the JNI subsystem (must be done _before_
1522 threads_init, as threads_init can call JNI methods
1523 (e.g. NewGlobalRef). */
1526 vm_abort("vm_create: jni_init failed");
1529 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1530 /* Initialize the local reference table for the main thread. */
1531 /* BEFORE: threads_init */
1533 if (!localref_table_init())
1534 vm_abort("vm_create: localref_table_init failed");
1537 /* Iinitialize some important system classes. */
1538 /* BEFORE: threads_init */
1542 #if defined(ENABLE_THREADS)
1546 /* Initialize the native VM subsystem. */
1547 /* AFTER: threads_init (at least for SUN's classes) */
1551 #if defined(ENABLE_PROFILING)
1552 /* initialize profiling */
1554 if (!profile_init())
1555 vm_abort("vm_create: profile_init failed");
1558 #if defined(ENABLE_THREADS)
1559 /* initialize recompilation */
1561 if (!recompile_init())
1562 vm_abort("vm_create: recompile_init failed");
1564 /* start the signal handler thread */
1566 #if defined(__LINUX__)
1567 /* XXX Remove for exact-GC. */
1568 if (threads_pthreads_implementation_nptl)
1570 if (!signal_start_thread())
1571 vm_abort("vm_create: signal_start_thread failed");
1573 /* finally, start the finalizer thread */
1575 if (!finalizer_start_thread())
1576 vm_abort("vm_create: finalizer_start_thread failed");
1578 # if !defined(NDEBUG)
1579 /* start the memory profiling thread */
1581 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1582 if (!memory_start_thread())
1583 vm_abort("vm_create: memory_start_thread failed");
1586 /* start the recompilation thread (must be done before the
1587 profiling thread) */
1589 if (!recompile_start_thread())
1590 vm_abort("vm_create: recompile_start_thread failed");
1592 # if defined(ENABLE_PROFILING)
1593 /* start the profile sampling thread */
1596 /* if (!profile_start_thread()) */
1597 /* vm_abort("vm_create: profile_start_thread failed"); */
1601 #if defined(ENABLE_JVMTI)
1602 # if defined(ENABLE_GC_CACAO)
1603 /* XXX this will not work with the new indirection cells for classloaders!!! */
1607 /* add agent library to native library hashtable */
1608 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1612 /* Increment the number of VMs. */
1616 // Initialization is done, VM is created.
1618 _initializing = false;
1620 /* Print the VM configuration after all stuff is set and the VM is
1623 if (opt_PrintConfig)
1628 /* vm_run **********************************************************************
1630 Runs the main-method of the passed class.
1632 *******************************************************************************/
1634 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1640 classinfo *mainclass;
1643 java_handle_objectarray_t *oa;
1649 // Prevent compiler warnings.
1652 #if !defined(NDEBUG)
1659 /* Get the main class plus it's arguments. */
1663 if (opt_index < vm_args->nOptions) {
1664 /* Get main-class argument. */
1666 mainname = vm_args->options[opt_index].optionString;
1668 /* If the main class argument is a jar file, put it into the
1671 if (opt_jar == true) {
1672 p = MNEW(char, strlen(mainname) + strlen("0"));
1674 strcpy(p, mainname);
1676 #if defined(ENABLE_JAVASE)
1677 properties_add("java.class.path", p);
1681 /* Replace dots with slashes in the class name. */
1683 for (unsigned int i = 0; i < strlen(mainname); i++)
1684 if (mainname[i] == '.')
1688 /* Build argument array. Move index to first argument. */
1692 oalength = vm_args->nOptions - opt_index;
1694 oa = builtin_anewarray(oalength, class_java_lang_String);
1696 for (int i = 0; i < oalength; i++) {
1697 option = vm_args->options[opt_index + i].optionString;
1699 u = utf_new_char(option);
1700 s = javastring_new(u);
1702 array_objectarray_element_set(oa, i, s);
1706 /* Do we have a main-class argument? */
1708 if (mainname == NULL)
1711 #if !defined(NDEBUG)
1712 if (opt_method != NULL) {
1713 vm_compile_method(mainname);
1718 /* set return value to OK */
1722 if (opt_jar == true) {
1723 /* open jar file with java.util.jar.JarFile */
1725 mainname = vm_get_mainclass_from_jar(mainname);
1727 if (mainname == NULL)
1731 /* load the main class */
1733 mainutf = utf_new_char(mainname);
1735 #if defined(ENABLE_JAVAME_CLDC1_1)
1736 mainclass = load_class_bootstrap(mainutf);
1738 mainclass = load_class_from_sysloader(mainutf);
1741 /* error loading class */
1743 e = exceptions_get_and_clear_exception();
1745 if ((e != NULL) || (mainclass == NULL)) {
1746 exceptions_throw_noclassdeffounderror_cause(e);
1747 exceptions_print_stacktrace();
1751 if (!link_class(mainclass)) {
1752 exceptions_print_stacktrace();
1756 /* find the `main' method of the main class */
1758 m = class_resolveclassmethod(mainclass,
1759 utf_new_char("main"),
1760 utf_new_char("([Ljava/lang/String;)V"),
1761 class_java_lang_Object,
1764 if (exceptions_get_exception()) {
1765 exceptions_print_stacktrace();
1769 /* there is no main method or it isn't static */
1771 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1772 exceptions_clear_exception();
1773 exceptions_throw_nosuchmethoderror(mainclass,
1774 utf_new_char("main"),
1775 utf_new_char("([Ljava/lang/String;)V"));
1777 exceptions_print_stacktrace();
1781 #ifdef TYPEINFO_DEBUG_TEST
1782 /* test the typeinfo system */
1786 #if defined(ENABLE_JVMTI)
1787 jvmti_set_phase(JVMTI_PHASE_LIVE);
1790 /* set ThreadMXBean variables */
1792 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1793 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1795 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1796 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1797 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1798 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1799 #warning Move to C++
1801 /* start the main thread */
1803 (void) vm_call_method(m, NULL, oa);
1805 /* exception occurred? */
1807 if (exceptions_get_exception()) {
1808 exceptions_print_stacktrace();
1812 #if defined(ENABLE_THREADS)
1813 /* Detach the main thread so that it appears to have ended when
1814 the application's main method exits. */
1816 if (!thread_detach_current_thread())
1817 vm_abort("vm_run: Could not detach main thread.");
1820 /* Destroy the JavaVM. */
1822 (void) vm_destroy(vm);
1830 /* vm_destroy ******************************************************************
1832 Unloads a Java VM and reclaims its resources.
1834 *******************************************************************************/
1836 int vm_destroy(JavaVM *vm)
1838 #if defined(ENABLE_THREADS)
1839 /* Create a a trivial new Java waiter thread called
1842 JavaVMAttachArgs args;
1844 args.name = (char*) "DestroyJavaVM";
1847 if (!thread_attach_current_thread(&args, false))
1850 /* Wait until we are the last non-daemon thread. */
1852 threads_join_all_threads();
1857 // _created = false;
1858 #warning Move to C++
1860 /* Everything is ok. */
1866 /* vm_exit *********************************************************************
1868 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1870 *******************************************************************************/
1872 void vm_exit(s4 status)
1876 /* signal that we are exiting */
1879 #warning Move to C++
1881 assert(class_java_lang_System);
1882 assert(class_java_lang_System->state & CLASS_LOADED);
1884 #if defined(ENABLE_JVMTI)
1885 if (jvmti || (dbgcom!=NULL)) {
1886 jvmti_set_phase(JVMTI_PHASE_DEAD);
1887 if (jvmti) jvmti_agentunload();
1891 if (!link_class(class_java_lang_System)) {
1892 exceptions_print_stacktrace();
1896 /* call java.lang.System.exit(I)V */
1898 m = class_resolveclassmethod(class_java_lang_System,
1899 utf_new_char("exit"),
1901 class_java_lang_Object,
1905 exceptions_print_stacktrace();
1909 /* call the exit function with passed exit status */
1911 (void) vm_call_method(m, NULL, status);
1913 /* If we had an exception, just ignore the exception and exit with
1916 vm_shutdown(status);
1920 /* vm_shutdown *****************************************************************
1922 Terminates the system immediately without freeing memory explicitly
1923 (to be used only for abnormal termination).
1925 *******************************************************************************/
1927 void vm_shutdown(s4 status)
1930 #if defined(ENABLE_STATISTICS)
1931 || opt_getcompilingtime || opt_stat
1935 log_text("CACAO terminated by shutdown");
1936 dolog("Exit status: %d\n", (s4) status);
1940 #if defined(ENABLE_JVMTI)
1941 /* terminate cacaodbgserver */
1943 mutex_lock(&dbgcomlock);
1945 mutex_unlock(&dbgcomlock);
1946 jvmti_cacaodbgserver_quit();
1954 /* vm_exit_handler *************************************************************
1956 The exit_handler function is called upon program termination.
1958 ATTENTION: Don't free system resources here! Some threads may still
1959 be running as this is called from VMRuntime.exit(). The OS does the
1962 *******************************************************************************/
1964 void vm_exit_handler(void)
1966 #if !defined(NDEBUG)
1968 class_showmethods(mainclass);
1970 if (showconstantpool)
1971 class_showconstantpool(mainclass);
1976 # if defined(ENABLE_PROFILING)
1978 profile_printstats();
1980 #endif /* !defined(NDEBUG) */
1982 #if defined(ENABLE_RT_TIMING)
1983 rt_timing_print_time_stats(stderr);
1986 #if defined(ENABLE_CYCLES_STATS)
1987 builtin_print_cycles_stats(stderr);
1988 stacktrace_print_cycles_stats(stderr);
1992 #if defined(ENABLE_STATISTICS)
1993 || opt_getcompilingtime || opt_stat
1997 log_text("CACAO terminated");
1999 #if defined(ENABLE_STATISTICS)
2002 #ifdef TYPECHECK_STATISTICS
2003 typecheck_print_statistics(get_logfile());
2007 if (opt_getcompilingtime)
2009 #endif /* defined(ENABLE_STATISTICS) */
2011 /* vm_print_profile(stderr);*/
2015 /* vm_abort ********************************************************************
2017 Prints an error message and aborts the VM.
2020 text ... error message to print
2022 *******************************************************************************/
2024 void vm_abort(const char *text, ...)
2028 /* Print the log message. */
2033 log_vprint(text, ap);
2038 /* Now abort the VM. */
2044 /* vm_abort_errnum *************************************************************
2046 Prints an error message, appends ":" plus the strerror-message of
2047 errnum and aborts the VM.
2050 errnum ... error number
2051 text ..... error message to print
2053 *******************************************************************************/
2055 void vm_abort_errnum(int errnum, const char *text, ...)
2059 /* Print the log message. */
2064 log_vprint(text, ap);
2067 /* Print the strerror-message of errnum. */
2069 log_print(": %s", os::strerror(errnum));
2073 /* Now abort the VM. */
2079 /* vm_abort_errno **************************************************************
2081 Equal to vm_abort_errnum, but uses errno to get the error number.
2084 text ... error message to print
2086 *******************************************************************************/
2088 void vm_abort_errno(const char *text, ...)
2093 vm_abort_errnum(errno, text, ap);
2098 /* vm_abort_disassemble ********************************************************
2100 Prints an error message, disassemble the given code range (if
2101 enabled) and aborts the VM.
2104 pc.......PC to disassemble
2105 count....number of instructions to disassemble
2107 *******************************************************************************/
2109 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2112 #if defined(ENABLE_DISASSEMBLER)
2116 /* Print debug message. */
2121 log_vprint(text, ap);
2128 #if SIZEOF_VOID_P == 8
2129 log_println("PC=0x%016lx", pc);
2131 log_println("PC=0x%08x", pc);
2134 #if defined(ENABLE_DISASSEMBLER)
2135 log_println("machine instructions at PC:");
2137 /* Disassemble the given number of instructions. */
2139 for (i = 0; i < count; i++)
2140 // FIXME disassinstr should use void*.
2141 pc = disassinstr((u1*) pc);
2144 vm_abort("Aborting...");
2148 /* vm_get_mainclass_from_jar ***************************************************
2150 Gets the name of the main class from a JAR's manifest file.
2152 *******************************************************************************/
2154 static char *vm_get_mainclass_from_jar(char *mainname)
2161 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2164 exceptions_print_stacktrace();
2168 /* create JarFile object */
2173 exceptions_print_stacktrace();
2177 m = class_resolveclassmethod(c,
2179 utf_java_lang_String__void,
2180 class_java_lang_Object,
2184 exceptions_print_stacktrace();
2188 s = javastring_new_from_ascii(mainname);
2190 (void) vm_call_method(m, o, s);
2192 if (exceptions_get_exception()) {
2193 exceptions_print_stacktrace();
2197 /* get manifest object */
2199 m = class_resolveclassmethod(c,
2200 utf_new_char("getManifest"),
2201 utf_new_char("()Ljava/util/jar/Manifest;"),
2202 class_java_lang_Object,
2206 exceptions_print_stacktrace();
2210 o = vm_call_method(m, o);
2213 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2218 /* get Main Attributes */
2220 LLNI_class_get(o, c);
2222 m = class_resolveclassmethod(c,
2223 utf_new_char("getMainAttributes"),
2224 utf_new_char("()Ljava/util/jar/Attributes;"),
2225 class_java_lang_Object,
2229 exceptions_print_stacktrace();
2233 o = vm_call_method(m, o);
2236 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2241 /* get property Main-Class */
2243 LLNI_class_get(o, c);
2245 m = class_resolveclassmethod(c,
2246 utf_new_char("getValue"),
2247 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2248 class_java_lang_Object,
2252 exceptions_print_stacktrace();
2256 s = javastring_new_from_ascii("Main-Class");
2258 o = vm_call_method(m, o, s);
2261 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2262 fprintf(stderr, "%s\n", mainname);
2266 return javastring_tochar(o);
2270 /* vm_compile_all **************************************************************
2272 Compile all methods found in the bootclasspath.
2274 *******************************************************************************/
2276 #if !defined(NDEBUG)
2277 static void vm_compile_all(void)
2282 classcache_name_entry *nmen;
2283 classcache_class_entry *clsen;
2286 /* create all classes found in the bootclasspath */
2287 /* XXX currently only works with zip/jar's */
2289 loader_load_all_classes();
2291 /* link all classes */
2293 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2294 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2296 for (; nmen; nmen = nmen->hashlink) {
2297 /* iterate over all class entries */
2299 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2300 c = clsen->classobj;
2305 if (!(c->state & CLASS_LINKED)) {
2306 if (!link_class(c)) {
2307 fprintf(stderr, "Error linking: ");
2308 utf_fprint_printable_ascii_classname(stderr, c->name);
2309 fprintf(stderr, "\n");
2311 /* print out exception and cause */
2313 exceptions_print_current_exception();
2315 /* goto next class */
2321 /* compile all class methods */
2323 for (i = 0; i < c->methodscount; i++) {
2324 m = &(c->methods[i]);
2326 if (m->jcode != NULL) {
2327 if (!jit_compile(m)) {
2328 fprintf(stderr, "Error compiling: ");
2329 utf_fprint_printable_ascii_classname(stderr, c->name);
2330 fprintf(stderr, ".");
2331 utf_fprint_printable_ascii(stderr, m->name);
2332 utf_fprint_printable_ascii(stderr, m->descriptor);
2333 fprintf(stderr, "\n");
2335 /* print out exception and cause */
2337 exceptions_print_current_exception();
2345 #endif /* !defined(NDEBUG) */
2348 /* vm_compile_method ***********************************************************
2350 Compile a specific method.
2352 *******************************************************************************/
2354 #if !defined(NDEBUG)
2355 static void vm_compile_method(char* mainname)
2359 /* create, load and link the main class */
2361 mainclass = load_class_bootstrap(utf_new_char(mainname));
2363 if (mainclass == NULL)
2364 exceptions_print_stacktrace();
2366 if (!link_class(mainclass))
2367 exceptions_print_stacktrace();
2369 if (opt_signature != NULL) {
2370 m = class_resolveclassmethod(mainclass,
2371 utf_new_char(opt_method),
2372 utf_new_char(opt_signature),
2377 m = class_resolveclassmethod(mainclass,
2378 utf_new_char(opt_method),
2385 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2386 opt_method, opt_signature ? opt_signature : "");
2390 #endif /* !defined(NDEBUG) */
2393 /* vm_call_array ***************************************************************
2395 Calls a Java method with a variable number of arguments, passed via
2398 ATTENTION: This function has to be used outside the nativeworld.
2400 *******************************************************************************/
2402 #define VM_CALL_ARRAY(name, type) \
2403 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2409 assert(m->code != NULL); \
2411 md = m->parseddesc; \
2412 pv = m->code->entrypoint; \
2414 STATISTICS(count_calls_native_to_java++); \
2416 value = asm_vm_call_method##name(pv, array, md->memuse); \
2421 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2427 assert(m->code != NULL);
2430 pv = m->code->entrypoint;
2432 STATISTICS(count_calls_native_to_java++);
2434 o = asm_vm_call_method(pv, array, md->memuse);
2436 if (md->returntype.type == TYPE_VOID)
2439 return LLNI_WRAP(o);
2442 VM_CALL_ARRAY(_int, int32_t)
2443 VM_CALL_ARRAY(_long, int64_t)
2444 VM_CALL_ARRAY(_float, float)
2445 VM_CALL_ARRAY(_double, double)
2448 /* vm_call_method **************************************************************
2450 Calls a Java method with a variable number of arguments.
2452 *******************************************************************************/
2454 #define VM_CALL_METHOD(name, type) \
2455 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2461 value = vm_call_method##name##_valist(m, o, ap); \
2467 VM_CALL_METHOD(, java_handle_t *)
2468 VM_CALL_METHOD(_int, int32_t)
2469 VM_CALL_METHOD(_long, int64_t)
2470 VM_CALL_METHOD(_float, float)
2471 VM_CALL_METHOD(_double, double)
2474 /* vm_call_method_valist *******************************************************
2476 Calls a Java method with a variable number of arguments, passed via
2479 *******************************************************************************/
2481 #define VM_CALL_METHOD_VALIST(name, type) \
2482 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2487 int32_t dumpmarker; \
2489 if (m->code == NULL) \
2490 if (!jit_compile(m)) \
2493 THREAD_NATIVEWORLD_EXIT; \
2496 array = argument_vmarray_from_valist(m, o, ap); \
2497 value = vm_call##name##_array(m, array); \
2500 THREAD_NATIVEWORLD_ENTER; \
2505 VM_CALL_METHOD_VALIST(, java_handle_t *)
2506 VM_CALL_METHOD_VALIST(_int, int32_t)
2507 VM_CALL_METHOD_VALIST(_long, int64_t)
2508 VM_CALL_METHOD_VALIST(_float, float)
2509 VM_CALL_METHOD_VALIST(_double, double)
2512 /* vm_call_method_jvalue *******************************************************
2514 Calls a Java method with a variable number of arguments, passed via
2517 *******************************************************************************/
2519 #define VM_CALL_METHOD_JVALUE(name, type) \
2520 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2521 const jvalue *args) \
2525 int32_t dumpmarker; \
2527 if (m->code == NULL) \
2528 if (!jit_compile(m)) \
2531 THREAD_NATIVEWORLD_EXIT; \
2534 array = argument_vmarray_from_jvalue(m, o, args); \
2535 value = vm_call##name##_array(m, array); \
2538 THREAD_NATIVEWORLD_ENTER; \
2543 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2544 VM_CALL_METHOD_JVALUE(_int, int32_t)
2545 VM_CALL_METHOD_JVALUE(_long, int64_t)
2546 VM_CALL_METHOD_JVALUE(_float, float)
2547 VM_CALL_METHOD_JVALUE(_double, double)
2550 /* vm_call_method_objectarray **************************************************
2552 Calls a Java method with a variable number if arguments, passed via
2553 an objectarray of boxed values. Returns a boxed value.
2555 *******************************************************************************/
2557 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2558 java_handle_objectarray_t *params)
2561 java_handle_t *xptr;
2566 /* Prevent compiler warnings. */
2570 /* compile methods which are not yet compiled */
2572 if (m->code == NULL)
2573 if (!jit_compile(m))
2576 /* leave the nativeworld */
2578 THREAD_NATIVEWORLD_EXIT;
2580 /* mark start of dump memory area */
2584 /* Fill the argument array from a object-array. */
2586 array = argument_vmarray_from_objectarray(m, o, params);
2588 if (array == NULL) {
2589 /* release dump area */
2593 /* enter the nativeworld again */
2595 THREAD_NATIVEWORLD_ENTER;
2597 exceptions_throw_illegalargumentexception();
2602 switch (m->parseddesc->returntype.decltype) {
2603 case PRIMITIVETYPE_VOID:
2604 value.a = vm_call_array(m, array);
2607 case PRIMITIVETYPE_BOOLEAN:
2608 case PRIMITIVETYPE_BYTE:
2609 case PRIMITIVETYPE_CHAR:
2610 case PRIMITIVETYPE_SHORT:
2611 case PRIMITIVETYPE_INT:
2612 value.i = vm_call_int_array(m, array);
2615 case PRIMITIVETYPE_LONG:
2616 value.l = vm_call_long_array(m, array);
2619 case PRIMITIVETYPE_FLOAT:
2620 value.f = vm_call_float_array(m, array);
2623 case PRIMITIVETYPE_DOUBLE:
2624 value.d = vm_call_double_array(m, array);
2628 ro = vm_call_array(m, array);
2632 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2635 /* release dump area */
2639 /* enter the nativeworld again */
2641 THREAD_NATIVEWORLD_ENTER;
2643 /* box the return value if necesarry */
2645 if (m->parseddesc->returntype.decltype != TYPE_ADR)
2646 ro = Primitive::box(m->parseddesc->returntype.decltype, value);
2648 /* check for an exception */
2650 xptr = exceptions_get_exception();
2653 /* clear exception pointer, we are calling JIT code again */
2655 exceptions_clear_exception();
2657 exceptions_throw_invocationtargetexception(xptr);
2664 /* Legacy C interface *********************************************************/
2668 JavaVM* VM_get_javavm() { return vm->get_javavm(); }
2669 JNIEnv* VM_get_jnienv() { return vm->get_jnienv(); }
2670 bool VM_is_initializing() { return vm->is_initializing(); }
2671 bool VM_is_created() { return vm->is_created(); }
2672 int64_t VM_get_starttime() { return vm->get_starttime(); }
2678 * These are local overrides for various environment variables in Emacs.
2679 * Please do not remove this and leave it at the end of the file, where
2680 * Emacs will automagically detect them.
2681 * ---------------------------------------------------------------------
2684 * indent-tabs-mode: t
2688 * vim:noexpandtab:sw=4:ts=4: