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"
44 #include "mm/dumpmemory.hpp"
46 #include "mm/memory.hpp"
48 #include "native/jni.hpp"
49 #include "native/llni.h"
50 #include "native/localref.hpp"
51 #include "native/native.hpp"
53 #include "native/vm/nativevm.hpp"
55 #include "threads/lock.hpp"
56 #include "threads/thread.hpp"
58 #include "toolbox/logging.hpp"
60 #include "vm/array.hpp"
62 #if defined(ENABLE_ASSERTION)
63 #include "vm/assertion.hpp"
66 #include "vm/jit/builtin.hpp"
67 #include "vm/classcache.hpp"
68 #include "vm/exceptions.hpp"
69 #include "vm/finalizer.hpp"
70 #include "vm/global.h"
71 #include "vm/globals.hpp"
72 #include "vm/initialize.hpp"
73 #include "vm/options.h"
75 #include "vm/primitive.hpp"
76 #include "vm/properties.hpp"
77 #include "vm/signallocal.hpp"
78 #include "vm/statistics.h"
79 #include "vm/string.hpp"
80 #include "vm/suck.hpp"
83 #include "vm/jit/argument.hpp"
84 #include "vm/jit/asmpart.h"
85 #include "vm/jit/code.hpp"
87 #if defined(ENABLE_DISASSEMBLER)
88 # include "vm/jit/disass.h"
91 #include "vm/jit/jit.hpp"
92 #include "vm/jit/methodtree.h"
94 #include "vm/jit/optimizing/profile.hpp"
95 #include "vm/jit/optimizing/recompiler.hpp"
97 #if defined(ENABLE_PYTHON)
98 # include "vm/jit/python.h"
101 #include "vm/jit/trap.hpp"
103 #if defined(ENABLE_VMLOG)
104 #include <vmlog_cacao.h>
109 * This is _the_ VM instance.
114 /* global variables ***********************************************************/
116 s4 vms = 0; /* number of VMs created */
118 static classinfo *mainclass = NULL;
120 #if defined(ENABLE_INTRP)
121 u1 *intrp_main_stack = NULL;
125 /* define heap sizes **********************************************************/
127 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
128 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
129 #define STACK_SIZE 128 * 1024 /* default 64kB */
132 /* define command line options ************************************************/
166 /* Java non-standard options */
177 #if defined(ENABLE_PROFILING)
191 #if defined(ENABLE_STATISTICS)
202 #if defined(ENABLE_VERIFIER)
206 #if defined(TYPECHECK_VERBOSE)
209 #endif /* defined(ENABLE_VERIFIER) */
211 /* optimization options */
213 #if defined(ENABLE_LOOP)
217 #if defined(ENABLE_IFCONV)
221 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
225 #if defined(ENABLE_INTRP)
226 /* interpreter options */
237 #if defined(ENABLE_JVMTI)
243 #if defined(ENABLE_DEBUG_FILTER)
244 OPT_FILTER_VERBOSECALL_INCLUDE,
245 OPT_FILTER_VERBOSECALL_EXCLUDE,
246 OPT_FILTER_SHOW_METHOD,
253 opt_struct opts[] = {
254 { "foo", false, OPT_FOO },
258 { "jar", false, OPT_JAR },
260 { "d32", false, OPT_D32 },
261 { "d64", false, OPT_D64 },
262 { "client", false, OPT_IGNORE },
263 { "server", false, OPT_IGNORE },
264 { "jvm", false, OPT_IGNORE },
265 { "hotspot", false, OPT_IGNORE },
267 { "classpath", true, OPT_CLASSPATH },
268 { "cp", true, OPT_CLASSPATH },
269 { "D", true, OPT_D },
270 { "version", false, OPT_VERSION },
271 { "showversion", false, OPT_SHOWVERSION },
272 { "fullversion", false, OPT_FULLVERSION },
273 { "help", false, OPT_HELP },
274 { "?", false, OPT_HELP },
275 { "X", false, OPT_X },
276 { "XX:", true, OPT_XX },
278 { "ea:", true, OPT_EA },
279 { "da:", true, OPT_DA },
280 { "ea", false, OPT_EA_NOARG },
281 { "da", false, OPT_DA_NOARG },
283 { "enableassertions:", true, OPT_EA },
284 { "disableassertions:", true, OPT_DA },
285 { "enableassertions", false, OPT_EA_NOARG },
286 { "disableassertions", false, OPT_DA_NOARG },
288 { "esa", false, OPT_ESA },
289 { "enablesystemassertions", false, OPT_ESA },
290 { "dsa", false, OPT_DSA },
291 { "disablesystemassertions", false, OPT_DSA },
293 { "noasyncgc", false, OPT_IGNORE },
294 #if defined(ENABLE_VERIFIER)
295 { "noverify", false, OPT_NOVERIFY },
296 { "Xverify:all", false, OPT_XVERIFY_ALL },
297 { "Xverify:none", false, OPT_XVERIFY_NONE },
299 { "v", false, OPT_VERBOSE1 },
300 { "verbose:", true, OPT_VERBOSE },
302 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
303 { "verbosetc", false, OPT_VERBOSETC },
305 #if defined(ENABLE_STATISTICS)
306 { "time", false, OPT_TIME },
307 { "stat", false, OPT_STAT },
309 { "log", true, OPT_LOG },
310 { "c", true, OPT_CHECK },
311 { "l", false, OPT_LOAD },
313 #if defined(ENABLE_LOOP)
314 { "oloop", false, OPT_OLOOP },
316 #if defined(ENABLE_IFCONV)
317 { "ifconv", false, OPT_IFCONV },
319 #if defined(ENABLE_LSRA)
320 { "lsra", false, OPT_LSRA },
322 #if defined(ENABLE_SSA)
323 { "lsra", true, OPT_LSRA },
326 #if defined(ENABLE_INTRP)
327 /* interpreter options */
329 { "trace", false, OPT_TRACE },
330 { "static-supers", true, OPT_STATIC_SUPERS },
331 { "no-dynamic", false, OPT_NO_DYNAMIC },
332 { "no-replication", false, OPT_NO_REPLICATION },
333 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
336 /* JVMTI Agent Command Line Options */
337 #if defined(ENABLE_JVMTI)
338 { "agentlib:", true, OPT_AGENTLIB },
339 { "agentpath:", true, OPT_AGENTPATH },
342 /* Java non-standard options */
344 { "Xjit", false, OPT_JIT },
345 { "Xint", false, OPT_INTRP },
346 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
347 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
348 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
349 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
351 #if defined(ENABLE_JVMTI)
352 { "Xdebug", false, OPT_IGNORE },
353 { "Xnoagent", false, OPT_IGNORE },
354 { "Xrun", true, OPT_RUN },
357 { "Xms", true, OPT_MS },
358 { "ms", true, OPT_MS },
359 { "Xmx", true, OPT_MX },
360 { "mx", true, OPT_MX },
361 { "Xss", true, OPT_SS },
362 { "ss", true, OPT_SS },
364 { "Xcheck:jni", false, OPT_XCHECK_JNI },
366 #if defined(ENABLE_PROFILING)
367 { "Xprof:", true, OPT_PROF_OPTION },
368 { "Xprof", false, OPT_PROF },
371 /* keep these at the end of the list */
373 { "s", true, OPT_SHOW },
374 { "debug-color", false, OPT_DEBUGCOLOR },
376 #if defined(ENABLE_DEBUG_FILTER)
377 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
378 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
379 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
386 /* usage ***********************************************************************
388 Prints the correct usage syntax to stdout.
390 *******************************************************************************/
394 puts("Usage: cacao [-options] classname [arguments]");
395 puts(" (to run a class file)");
396 puts(" or cacao [-options] -jar jarfile [arguments]");
397 puts(" (to run a standalone jar file)\n");
399 puts("where options include:");
400 puts(" -d32 use 32-bit data model if available");
401 puts(" -d64 use 64-bit data model if available");
402 puts(" -client compatibility (currently ignored)");
403 puts(" -server compatibility (currently ignored)");
404 puts(" -jvm compatibility (currently ignored)");
405 puts(" -hotspot compatibility (currently ignored)\n");
407 puts(" -cp <path> specify a path to look for classes");
408 puts(" -classpath <path> specify a path to look for classes");
409 puts(" -D<name>=<value> add an entry to the property list");
410 puts(" -verbose[:class|gc|jni] enable specific verbose output");
411 puts(" -version print product version and exit");
412 puts(" -fullversion print jpackage-compatible product version and exit");
413 puts(" -showversion print product version and continue");
414 puts(" -help, -? print this help message");
415 puts(" -X print help on non-standard Java options");
416 puts(" -XX print help on debugging options");
417 puts(" -ea[:<packagename>...|:<classname>]");
418 puts(" -enableassertions[:<packagename>...|:<classname>]");
419 puts(" enable assertions with specified granularity");
420 puts(" -da[:<packagename>...|:<classname>]");
421 puts(" -disableassertions[:<packagename>...|:<classname>]");
422 puts(" disable assertions with specified granularity");
423 puts(" -esa | -enablesystemassertions");
424 puts(" enable system assertions");
425 puts(" -dsa | -disablesystemassertions");
426 puts(" disable system assertions");
428 #if defined(ENABLE_JVMTI)
429 puts(" -agentlib:<agent-lib-name>=<options>");
430 puts(" load native agent library by library name");
431 puts(" for additional help use: -agentlib:jdwp=help");
432 puts(" -agentpath:<path-to-agent>=<options>");
433 puts(" load native agent library by full pathname");
436 /* exit with error code */
442 static void Xusage(void)
444 #if defined(ENABLE_JIT)
445 puts(" -Xjit JIT mode execution (default)");
447 #if defined(ENABLE_INTRP)
448 puts(" -Xint interpreter mode execution");
450 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
451 puts(" value is set as bootstrap class path");
452 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
453 puts(" value is appended to the bootstrap class path");
454 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
455 puts(" value is prepended to the bootstrap class path");
456 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
457 puts(" value is used as Java core library, but the");
458 puts(" hardcoded VM interface classes are prepended");
459 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
460 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
461 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
463 #if defined(ENABLE_PROFILING)
464 puts(" -Xprof[:bb] collect and print profiling data");
467 /* exit with error code */
474 static void XXusage(void)
476 puts(" -v write state-information");
478 puts(" -verbose:jit enable specific verbose output");
479 puts(" -debug-color colored output for ANSI terms");
481 #ifdef TYPECHECK_VERBOSE
482 puts(" -verbosetc write debug messages while typechecking");
484 #if defined(ENABLE_VERIFIER)
485 puts(" -noverify don't verify classfiles");
487 #if defined(ENABLE_STATISTICS)
488 puts(" -time measure the runtime");
489 puts(" -stat detailed compiler statistics");
491 puts(" -log logfile specify a name for the logfile");
492 puts(" -c(heck)b(ounds) don't check array bounds");
493 puts(" s(ync) don't check for synchronization");
494 #if defined(ENABLE_LOOP)
495 puts(" -oloop optimize array accesses in loops");
497 puts(" -l don't start the class after loading");
499 puts(" -s... show...");
500 puts(" (c)onstants the constant pool");
501 puts(" (m)ethods class fields and methods");
502 puts(" (u)tf the utf - hash");
503 puts(" (i)ntermediate intermediate representation");
504 #if defined(ENABLE_DISASSEMBLER)
505 puts(" (a)ssembler disassembled listing");
506 puts(" n(o)ps show NOPs in disassembler output");
508 puts(" (d)atasegment data segment listing");
510 #if defined(ENABLE_IFCONV)
511 puts(" -ifconv use if-conversion");
513 #if defined(ENABLE_LSRA)
514 puts(" -lsra use linear scan register allocation");
516 #if defined(ENABLE_SSA)
517 puts(" -lsra:... use linear scan register allocation (with SSA)");
518 puts(" (d)ead code elimination");
519 puts(" (c)opy propagation");
521 #if defined(ENABLE_DEBUG_FILTER)
522 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
523 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
524 puts(" -XXfm <regex> filter for show options");
526 /* exit with error code */
533 /* version *********************************************************************
535 Only prints cacao version information.
537 *******************************************************************************/
539 static void version(bool opt_exit)
541 puts("java version \""JAVA_VERSION"\"");
542 puts("CACAO version "VERSION"\n");
544 puts("Copyright (C) 1996-2005, 2006, 2007, 2008");
545 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
546 puts("This is free software; see the source for copying conditions. There is NO");
547 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
549 /* exit normally, if requested */
556 /* fullversion *****************************************************************
558 Prints a Sun compatible version information (required e.g. by
559 jpackage, www.jpackage.org).
561 *******************************************************************************/
563 static void fullversion(void)
565 puts("java full version \"cacao-"JAVA_VERSION"\"");
573 /* forward declarations *******************************************************/
575 static char *vm_get_mainclass_from_jar(char *mainstring);
577 static void vm_compile_all(void);
578 static void vm_compile_method(char* mainname);
583 * Implementation for JNI_CreateJavaVM. This function creates a VM
590 * @return true on success, false otherwise.
592 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
594 JavaVMInitArgs* _vm_args;
596 // Get the arguments for the new JVM.
597 _vm_args = (JavaVMInitArgs *) vm_args;
599 // Instantiate a new VM.
601 _vm = new VM(_vm_args);
603 catch (std::exception e) {
604 // FIXME How can we delete the resources allocated?
605 // /* release allocated memory */
606 // FREE(env, _Jv_JNIEnv);
607 // FREE(vm, _Jv_JavaVM);
614 // Return the values.
616 *p_vm = _vm->get_javavm();
617 *p_env = _vm->get_jnienv();
624 * C wrapper for VM::create.
627 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
629 return VM::create(p_vm, p_env, vm_args);
637 VM::VM(JavaVMInitArgs* vm_args)
639 // Very first thing to do: we are initializing.
640 _initializing = true;
642 // Make ourself globally visible.
643 // XXX Is this a good idea?
646 /* create and fill a JavaVM structure */
648 _javavm = new JavaVM();
650 #if defined(ENABLE_JNI)
651 _javavm->functions = &_Jv_JNIInvokeInterface;
654 /* get the VM and Env tables (must be set before vm_create) */
655 /* XXX JVMTI Agents needs a JavaVM */
657 _jnienv = new JNIEnv();
659 #if defined(ENABLE_JNI)
660 _jnienv->functions = &_Jv_JNINativeInterface;
663 /* actually create the JVM */
667 char *boot_class_path;
673 #if defined(ENABLE_JNI)
674 /* Check the JNI version requested. */
676 if (!jni_version_check(vm_args->version))
677 throw std::exception();
680 /* We only support 1 JVM instance. */
683 throw std::exception();
685 /* Install the exit handler. */
687 if (atexit(vm_exit_handler))
688 os::abort("atexit failed: %s\n", strerror(errno));
690 /* Set some options. */
695 opt_heapmaxsize = HEAP_MAXSIZE;
696 opt_heapstartsize = HEAP_STARTSIZE;
697 opt_stacksize = STACK_SIZE;
699 // First of all, parse the -XX options.
701 #if defined(ENABLE_VMLOG)
702 vmlog_cacao_init_options();
707 // After -XX options are parsed, print the build-time
708 // configuration, if requested.
710 print_build_time_config();
712 #if defined(ENABLE_VMLOG)
716 /* We need to check if the actual size of a java.lang.Class object
717 is smaller or equal than the assumption made in
720 #warning FIXME We need to check the size of java.lang.Class!!!
721 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
722 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
724 /* set the VM starttime */
726 _starttime = builtin_currenttimemillis();
728 /* iterate over all passed options */
730 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
744 #if SIZEOF_VOID_P == 8
745 puts("Running a 32-bit JVM is not supported on this platform.");
751 #if SIZEOF_VOID_P == 4
752 puts("Running a 64-bit JVM is not supported on this platform.");
758 /* Forget old classpath and set the argument as new
761 // FIXME Make class_path const char*.
762 class_path = (char*) _properties.get("java.class.path");
764 p = MNEW(char, strlen(opt_arg) + strlen("0"));
768 #if defined(ENABLE_JAVASE)
769 _properties.put("java.class.path", p);
772 MFREE(class_path, char, strlen(class_path));
776 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
777 if (opt_arg[i] == '=') {
779 _properties.put(opt_arg, opt_arg + i + 1);
784 /* if no '=' is given, just create an empty property */
786 _properties.put(opt_arg, "");
791 case OPT_BOOTCLASSPATH:
792 /* Forget default bootclasspath and set the argument as
793 new boot classpath. */
795 // FIXME Make boot_class_path const char*.
796 boot_class_path = (char*) _properties.get("sun.boot.class.path");
798 p = MNEW(char, strlen(opt_arg) + strlen("0"));
802 _properties.put("sun.boot.class.path", p);
803 _properties.put("java.boot.class.path", p);
805 MFREE(boot_class_path, char, strlen(boot_class_path));
808 case OPT_BOOTCLASSPATH_A:
809 /* Append to bootclasspath. */
811 // FIXME Make boot_class_path const char*.
812 boot_class_path = (char*) _properties.get("sun.boot.class.path");
814 len = strlen(boot_class_path);
816 // XXX (char*) quick hack
817 p = (char*) MREALLOC(boot_class_path,
821 strlen(opt_arg) + strlen("0"));
826 _properties.put("sun.boot.class.path", p);
827 _properties.put("java.boot.class.path", p);
830 case OPT_BOOTCLASSPATH_P:
831 /* Prepend to bootclasspath. */
833 // FIXME Make boot_class_path const char*.
834 boot_class_path = (char*) _properties.get("sun.boot.class.path");
836 len = strlen(boot_class_path);
838 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
842 strcat(p, boot_class_path);
844 _properties.put("sun.boot.class.path", p);
845 _properties.put("java.boot.class.path", p);
847 MFREE(boot_class_path, char, len);
850 case OPT_BOOTCLASSPATH_C:
851 /* Use as Java core library, but prepend VM interface
854 // FIXME Make boot_class_path const char*.
855 boot_class_path = (char*) _properties.get("sun.boot.class.path");
858 strlen(CACAO_VM_ZIP) +
865 strcpy(p, CACAO_VM_ZIP);
869 _properties.put("sun.boot.class.path", p);
870 _properties.put("java.boot.class.path", p);
872 MFREE(boot_class_path, char, strlen(boot_class_path));
875 #if defined(ENABLE_JVMTI)
877 // Parse option argument.
878 p = strchr(opt_arg, '=');
882 _nativeagents.register_agent_library(opt_arg, p);
886 // Parse option argument.
887 p = strchr(opt_arg, '=');
891 _nativeagents.register_agent_path(opt_arg, p);
895 // Parse option argument.
896 p = strchr(opt_arg, ':');
900 _nativeagents.register_agent_library(opt_arg, p);
911 c = opt_arg[strlen(opt_arg) - 1];
913 if ((c == 'k') || (c == 'K')) {
914 j = atoi(opt_arg) * 1024;
916 } else if ((c == 'm') || (c == 'M')) {
917 j = atoi(opt_arg) * 1024 * 1024;
924 else if (opt == OPT_MS)
925 opt_heapstartsize = j;
932 // HotSpot compatibility option.
940 if (strcmp("class", opt_arg) == 0) {
941 opt_verboseclass = true;
943 else if (strcmp("gc", opt_arg) == 0) {
944 opt_verbosegc = true;
946 else if (strcmp("jni", opt_arg) == 0) {
947 opt_verbosejni = true;
950 else if (strcmp("jit", opt_arg) == 0) {
954 compileverbose = true;
958 printf("Unknown -verbose option: %s\n", opt_arg);
964 opt_debugcolor = true;
967 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
969 opt_typecheckverbose = true;
978 case OPT_FULLVERSION:
982 case OPT_SHOWVERSION:
986 #if defined(ENABLE_VERIFIER)
987 case OPT_XVERIFY_ALL:
992 case OPT_XVERIFY_NONE:
997 #if defined(ENABLE_STATISTICS)
999 opt_getcompilingtime = true;
1000 opt_getloadingtime = true;
1013 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1014 switch (opt_arg[i]) {
1016 checkbounds = false;
1029 makeinitializations = false;
1032 case OPT_SHOW: /* Display options */
1033 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1034 switch (opt_arg[i]) {
1036 showconstantpool = true;
1048 opt_showintermediate = true;
1049 compileverbose = true;
1052 #if defined(ENABLE_DISASSEMBLER)
1054 opt_showdisassemble = true;
1055 compileverbose = true;
1060 opt_showddatasegment = true;
1069 #if defined(ENABLE_LOOP)
1075 #if defined(ENABLE_IFCONV)
1081 #if defined(ENABLE_LSRA)
1086 #if defined(ENABLE_SSA)
1089 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1090 switch (opt_arg[i]) {
1118 /* Already parsed. */
1122 #if defined(ENABLE_ASSERTION)
1123 assertion_ea_da(opt_arg, true);
1128 #if defined(ENABLE_ASSERTION)
1129 assertion_ea_da(opt_arg, false);
1134 #if defined(ENABLE_ASSERTION)
1135 assertion_user_enabled = true;
1140 #if defined(ENABLE_ASSERTION)
1141 assertion_user_enabled = false;
1146 #if defined(ENABLE_ASSERTION)
1147 assertion_system_enabled = true;
1152 #if defined(ENABLE_ASSERTION)
1153 assertion_system_enabled = false;
1157 #if defined(ENABLE_PROFILING)
1158 case OPT_PROF_OPTION:
1159 /* use <= to get the last \0 too */
1161 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1162 if (opt_arg[i] == ',')
1165 if (opt_arg[i] == '\0') {
1166 if (strcmp("bb", opt_arg + j) == 0)
1170 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1174 /* set k to next char */
1187 #if defined(ENABLE_JIT)
1190 printf("-Xjit option not enabled.\n");
1196 #if defined(ENABLE_INTRP)
1199 printf("-Xint option not enabled.\n");
1204 #if defined(ENABLE_INTRP)
1205 case OPT_STATIC_SUPERS:
1206 opt_static_supers = atoi(opt_arg);
1209 case OPT_NO_DYNAMIC:
1210 opt_no_dynamic = true;
1213 case OPT_NO_REPLICATION:
1214 opt_no_replication = true;
1217 case OPT_NO_QUICKSUPER:
1218 opt_no_quicksuper = true;
1226 #if defined(ENABLE_DEBUG_FILTER)
1227 case OPT_FILTER_VERBOSECALL_INCLUDE:
1228 opt_filter_verbosecall_include = opt_arg;
1231 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1232 opt_filter_verbosecall_exclude = opt_arg;
1235 case OPT_FILTER_SHOW_METHOD:
1236 opt_filter_show_method = opt_arg;
1241 printf("Unknown option: %s\n",
1242 vm_args->options[opt_index].optionString);
1247 // Print the preliminary run-time VM configuration after options
1249 if (opt_PrintConfig)
1250 print_run_time_config();
1252 /* initialize the garbage collector */
1254 gc_init(opt_heapmaxsize, opt_heapstartsize);
1256 #if defined(ENABLE_THREADS)
1257 /* AFTER: gc_init */
1263 /* install architecture dependent signal handlers */
1266 os::abort("vm_create: signal_init failed");
1268 #if defined(ENABLE_INTRP)
1269 /* Allocate main thread stack on the Java heap. */
1272 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1273 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1277 /* AFTER: threads_preinit */
1280 os::abort("vm_create: string_init failed");
1282 /* AFTER: threads_preinit */
1286 #if defined(ENABLE_JVMTI)
1288 if (!_nativeagents.load_agents())
1289 os::abort("vm_create: load_agents failed");
1292 /* AFTER: thread_preinit */
1294 _suckclasspath.add_from_property("java.endorsed.dirs");
1296 /* Now we have all options handled and we can print the version
1299 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1304 /* AFTER: utf8_init */
1306 // FIXME Make boot_class_path const char*.
1307 boot_class_path = (char*) _properties.get("sun.boot.class.path");
1308 _suckclasspath.add(boot_class_path);
1310 /* initialize the classcache hashtable stuff: lock, hashtable
1311 (must be done _after_ threads_preinit) */
1313 if (!classcache_init())
1314 os::abort("vm_create: classcache_init failed");
1316 /* Initialize the code memory management. */
1317 /* AFTER: threads_preinit */
1321 /* initialize the finalizer stuff (must be done _after_
1324 if (!finalizer_init())
1325 os::abort("vm_create: finalizer_init failed");
1327 /* Initialize the JIT compiler. */
1333 #if defined(ENABLE_PYTHON)
1337 /* AFTER: utf8_init, classcache_init */
1342 // AFTER: loader_preinit, linker_preinit
1343 Primitive::initialize_table();
1348 // AFTER: loader_init, linker_init
1349 Primitive::post_initialize_table();
1352 #if defined(ENABLE_JIT)
1356 if (!builtin_init())
1357 os::abort("vm_create: builtin_init failed");
1359 /* Register the native methods implemented in the VM. */
1360 /* BEFORE: threads_init */
1364 #if defined(ENABLE_JNI)
1365 /* Initialize the JNI subsystem (must be done _before_
1366 threads_init, as threads_init can call JNI methods
1367 (e.g. NewGlobalRef). */
1370 os::abort("vm_create: jni_init failed");
1373 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1374 /* Initialize the local reference table for the main thread. */
1375 /* BEFORE: threads_init */
1377 if (!localref_table_init())
1378 os::abort("vm_create: localref_table_init failed");
1381 /* Iinitialize some important system classes. */
1382 /* BEFORE: threads_init */
1386 #if defined(ENABLE_THREADS)
1390 /* Initialize the native VM subsystem. */
1391 /* AFTER: threads_init (at least for SUN's classes) */
1393 if (!nativevm_init())
1394 os::abort("vm_create: nativevm_init failed");
1396 #if defined(ENABLE_PROFILING)
1397 /* initialize profiling */
1399 if (!profile_init())
1400 os::abort("vm_create: profile_init failed");
1403 #if defined(ENABLE_THREADS)
1404 /* start the signal handler thread */
1406 #if defined(__LINUX__)
1407 /* XXX Remove for exact-GC. */
1408 if (threads_pthreads_implementation_nptl)
1410 if (!signal_start_thread())
1411 os::abort("vm_create: signal_start_thread failed");
1413 /* finally, start the finalizer thread */
1415 if (!finalizer_start_thread())
1416 os::abort("vm_create: finalizer_start_thread failed");
1418 # if !defined(NDEBUG)
1419 /* start the memory profiling thread */
1421 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1422 if (!memory_start_thread())
1423 os::abort("vm_create: memory_start_thread failed");
1426 // Start the recompilation thread (must be done before the
1427 // profiling thread).
1428 // FIXME Only works for one recompiler.
1429 _recompiler.start();
1431 # if defined(ENABLE_PROFILING)
1432 /* start the profile sampling thread */
1435 /* if (!profile_start_thread()) */
1436 /* os::abort("vm_create: profile_start_thread failed"); */
1440 /* Increment the number of VMs. */
1444 // Initialization is done, VM is created.
1446 _initializing = false;
1448 // Print the run-time VM configuration after all stuff is set and
1449 // the VM is initialized.
1450 if (opt_PrintConfig)
1451 print_run_time_config();
1453 // Start runtime agents after the VM is created.
1454 if (!start_runtime_agents())
1455 os::abort("vm_create: start_runtime_agents failed");
1460 * Print build-time (default) VM configuration.
1462 void VM::print_build_time_config(void)
1464 puts("CACAO "VERSION" configure/build options:");
1466 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1467 #if defined(__VERSION__)
1468 puts(" CC : "VERSION_CC" ("__VERSION__")");
1469 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1471 puts(" CC : "VERSION_CC"");
1472 puts(" CXX : "VERSION_CXX"");
1474 puts(" CFLAGS : "VERSION_CFLAGS"");
1475 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1479 puts("Build-time (default) variables:\n");
1480 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1481 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1482 printf(" stack size : %d\n", STACK_SIZE);
1484 #if defined(ENABLE_JRE_LAYOUT)
1485 // When we're building with JRE-layout, the default paths are the
1486 // same as the runtime paths.
1488 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1489 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1490 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1491 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1492 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1493 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1502 * Print run-time VM configuration.
1504 void VM::print_run_time_config()
1506 puts("Run-time variables:\n");
1507 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1508 printf(" initial heap size : %d\n", opt_heapstartsize);
1509 printf(" stack size : %d\n", opt_stacksize);
1511 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1512 printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1513 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1514 printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1517 printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1518 printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1525 * Start runtime agents which are provided by the JRE but need to be
1526 * started explicitly by the VM.
1528 bool VM::start_runtime_agents()
1530 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1534 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1536 // Check whether the management agent should be loaded.
1537 if ((_properties.get("com.sun.management.jmxremote") != NULL) ||
1538 (_properties.get("com.sun.management.snmp") != NULL))
1541 // Load the management agent class.
1542 classinfo* class_sun_management_Agent;
1543 if (!(class_sun_management_Agent = load_class_from_sysloader(utf_new_char("sun/management/Agent"))))
1546 // Link the management agent class.
1547 if (!link_class(class_sun_management_Agent))
1550 // Actually start the management agent.
1551 methodinfo* m = class_resolveclassmethod(class_sun_management_Agent,
1552 utf_new_char("startAgent"),
1554 class_java_lang_Object,
1560 (void) vm_call_method(m, NULL);
1562 if (exceptions_get_exception() != NULL)
1566 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
1571 # error unknown classpath configuration
1578 /* vm_run **********************************************************************
1580 Runs the main-method of the passed class.
1582 *******************************************************************************/
1584 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1589 #if !defined(NDEBUG)
1590 if (opt_CompileAll) {
1596 /* Get the main class or jar file argument. */
1598 char* mainname = NULL;
1600 if (opt_index < vm_args->nOptions) {
1601 /* Get main-class argument. */
1603 mainname = vm_args->options[opt_index].optionString;
1605 /* If the main class argument is a jar file, put it into the
1608 if (opt_jar == true) {
1609 char* p = MNEW(char, strlen(mainname) + strlen("0"));
1611 strcpy(p, mainname);
1613 #if defined(ENABLE_JAVASE)
1614 VM::get_current()->get_properties().put("java.class.path", p);
1618 /* Replace dots with slashes in the class name. */
1620 for (unsigned int i = 0; i < strlen(mainname); i++)
1621 if (mainname[i] == '.')
1625 /* Move index to first argument. */
1630 /* Do we have a main-class argument? */
1632 if (mainname == NULL)
1635 #if !defined(NDEBUG)
1636 if (opt_CompileMethod != NULL) {
1637 vm_compile_method(mainname);
1642 /* Build argument array. */
1644 int32_t oalength = vm_args->nOptions - opt_index;
1646 ObjectArray oa(oalength, class_java_lang_String);
1651 for (int i = 0; i < oalength; i++) {
1652 char* option = vm_args->options[opt_index + i].optionString;
1654 utf* u = utf_new_char(option);
1655 java_handle_t* s = javastring_new(u);
1657 oa.set_element(i, s);
1660 /* set return value to OK */
1664 if (opt_jar == true) {
1665 /* open jar file with java.util.jar.JarFile */
1667 mainname = vm_get_mainclass_from_jar(mainname);
1669 if (mainname == NULL)
1673 /* load the main class */
1675 utf* mainutf = utf_new_char(mainname);
1677 #if defined(ENABLE_JAVAME_CLDC1_1)
1678 classinfo* mainclass = load_class_bootstrap(mainutf);
1680 classinfo* mainclass = load_class_from_sysloader(mainutf);
1683 /* error loading class */
1685 java_handle_t* e = exceptions_get_and_clear_exception();
1687 if ((e != NULL) || (mainclass == NULL)) {
1688 exceptions_throw_noclassdeffounderror_cause(e);
1689 exceptions_print_stacktrace();
1693 if (!link_class(mainclass)) {
1694 exceptions_print_stacktrace();
1698 /* find the `main' method of the main class */
1700 m = class_resolveclassmethod(mainclass,
1701 utf_new_char("main"),
1702 utf_new_char("([Ljava/lang/String;)V"),
1703 class_java_lang_Object,
1706 if (exceptions_get_exception()) {
1707 exceptions_print_stacktrace();
1711 /* there is no main method or it isn't static */
1713 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1714 exceptions_clear_exception();
1715 exceptions_throw_nosuchmethoderror(mainclass,
1716 utf_new_char("main"),
1717 utf_new_char("([Ljava/lang/String;)V"));
1719 exceptions_print_stacktrace();
1723 #ifdef TYPEINFO_DEBUG_TEST
1724 /* test the typeinfo system */
1728 /* set ThreadMXBean variables */
1730 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1731 // _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1733 // if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1734 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1735 // _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1736 // _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1737 #warning Move to C++
1739 /* start the main thread */
1741 (void) vm_call_method(m, NULL, oa.get_handle());
1743 /* exception occurred? */
1745 if (exceptions_get_exception()) {
1746 exceptions_print_stacktrace();
1750 #if defined(ENABLE_THREADS)
1751 /* Detach the main thread so that it appears to have ended when
1752 the application's main method exits. */
1754 if (!thread_detach_current_thread())
1755 os::abort("vm_run: Could not detach main thread.");
1758 /* Destroy the JavaVM. */
1760 (void) vm_destroy(vm);
1768 /* vm_destroy ******************************************************************
1770 Unloads a Java VM and reclaims its resources.
1772 *******************************************************************************/
1774 int vm_destroy(JavaVM *vm)
1776 #if defined(ENABLE_THREADS)
1777 /* Create a a trivial new Java waiter thread called
1780 JavaVMAttachArgs args;
1782 args.name = (char*) "DestroyJavaVM";
1785 if (!thread_attach_current_thread(&args, false))
1788 /* Wait until we are the last non-daemon thread. */
1790 threads_join_all_threads();
1795 // _created = false;
1796 #warning Move to C++
1798 /* Everything is ok. */
1804 /* vm_exit *********************************************************************
1806 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1808 *******************************************************************************/
1810 void vm_exit(s4 status)
1814 /* signal that we are exiting */
1817 #warning Move to C++
1819 assert(class_java_lang_System);
1820 assert(class_java_lang_System->state & CLASS_LOADED);
1822 #if defined(ENABLE_JVMTI)
1823 if (jvmti || (dbgcom!=NULL)) {
1824 jvmti_set_phase(JVMTI_PHASE_DEAD);
1825 if (jvmti) jvmti_agentunload();
1829 if (!link_class(class_java_lang_System)) {
1830 exceptions_print_stacktrace();
1834 /* call java.lang.System.exit(I)V */
1836 m = class_resolveclassmethod(class_java_lang_System,
1837 utf_new_char("exit"),
1839 class_java_lang_Object,
1843 exceptions_print_stacktrace();
1847 /* call the exit function with passed exit status */
1849 (void) vm_call_method(m, NULL, status);
1851 /* If we had an exception, just ignore the exception and exit with
1854 vm_shutdown(status);
1858 /* vm_shutdown *****************************************************************
1860 Terminates the system immediately without freeing memory explicitly
1861 (to be used only for abnormal termination).
1863 *******************************************************************************/
1865 void vm_shutdown(s4 status)
1868 #if defined(ENABLE_STATISTICS)
1869 || opt_getcompilingtime || opt_stat
1873 log_text("CACAO terminated by shutdown");
1874 dolog("Exit status: %d\n", (s4) status);
1878 #if defined(ENABLE_JVMTI)
1879 /* terminate cacaodbgserver */
1881 mutex_lock(&dbgcomlock);
1883 mutex_unlock(&dbgcomlock);
1884 jvmti_cacaodbgserver_quit();
1892 /* vm_exit_handler *************************************************************
1894 The exit_handler function is called upon program termination.
1896 ATTENTION: Don't free system resources here! Some threads may still
1897 be running as this is called from VMRuntime.exit(). The OS does the
1900 *******************************************************************************/
1902 void vm_exit_handler(void)
1904 #if !defined(NDEBUG)
1906 class_showmethods(mainclass);
1908 if (showconstantpool)
1909 class_showconstantpool(mainclass);
1914 # if defined(ENABLE_PROFILING)
1916 profile_printstats();
1918 #endif /* !defined(NDEBUG) */
1920 #if defined(ENABLE_RT_TIMING)
1921 rt_timing_print_time_stats(stderr);
1924 #if defined(ENABLE_CYCLES_STATS)
1925 builtin_print_cycles_stats(stderr);
1926 stacktrace_print_cycles_stats(stderr);
1930 #if defined(ENABLE_STATISTICS)
1931 || opt_getcompilingtime || opt_stat
1935 log_text("CACAO terminated");
1937 #if defined(ENABLE_STATISTICS)
1940 #ifdef TYPECHECK_STATISTICS
1941 typecheck_print_statistics(get_logfile());
1945 if (opt_getcompilingtime)
1947 #endif /* defined(ENABLE_STATISTICS) */
1949 /* vm_print_profile(stderr);*/
1953 /* vm_abort_disassemble ********************************************************
1955 Prints an error message, disassemble the given code range (if
1956 enabled) and aborts the VM.
1959 pc.......PC to disassemble
1960 count....number of instructions to disassemble
1962 *******************************************************************************/
1964 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
1967 #if defined(ENABLE_DISASSEMBLER)
1971 /* Print debug message. */
1976 log_vprint(text, ap);
1983 #if SIZEOF_VOID_P == 8
1984 log_println("PC=0x%016lx", pc);
1986 log_println("PC=0x%08x", pc);
1989 #if defined(ENABLE_DISASSEMBLER)
1990 log_println("machine instructions at PC:");
1992 /* Disassemble the given number of instructions. */
1994 for (i = 0; i < count; i++)
1995 // FIXME disassinstr should use void*.
1996 pc = disassinstr((u1*) pc);
1999 os::abort("Aborting...");
2003 /* vm_get_mainclass_from_jar ***************************************************
2005 Gets the name of the main class from a JAR's manifest file.
2007 *******************************************************************************/
2009 static char *vm_get_mainclass_from_jar(char *mainname)
2016 #if defined(ENABLE_JAVAME_CLDC1_1)
2017 c = load_class_bootstrap(utf_new_char("java/util/jar/JarFile"));
2019 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2023 exceptions_print_stacktrace();
2027 /* create JarFile object */
2032 exceptions_print_stacktrace();
2036 m = class_resolveclassmethod(c,
2038 utf_java_lang_String__void,
2039 class_java_lang_Object,
2043 exceptions_print_stacktrace();
2047 s = javastring_new_from_ascii(mainname);
2049 (void) vm_call_method(m, o, s);
2051 if (exceptions_get_exception()) {
2052 exceptions_print_stacktrace();
2056 /* get manifest object */
2058 m = class_resolveclassmethod(c,
2059 utf_new_char("getManifest"),
2060 utf_new_char("()Ljava/util/jar/Manifest;"),
2061 class_java_lang_Object,
2065 exceptions_print_stacktrace();
2069 o = vm_call_method(m, o);
2072 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2077 /* get Main Attributes */
2079 LLNI_class_get(o, c);
2081 m = class_resolveclassmethod(c,
2082 utf_new_char("getMainAttributes"),
2083 utf_new_char("()Ljava/util/jar/Attributes;"),
2084 class_java_lang_Object,
2088 exceptions_print_stacktrace();
2092 o = vm_call_method(m, o);
2095 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2100 /* get property Main-Class */
2102 LLNI_class_get(o, c);
2104 m = class_resolveclassmethod(c,
2105 utf_new_char("getValue"),
2106 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2107 class_java_lang_Object,
2111 exceptions_print_stacktrace();
2115 s = javastring_new_from_ascii("Main-Class");
2117 o = vm_call_method(m, o, s);
2120 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2121 fprintf(stderr, "%s\n", mainname);
2125 return javastring_tochar(o);
2129 /* vm_compile_all **************************************************************
2131 Compile all methods found in the bootclasspath.
2133 *******************************************************************************/
2135 #if !defined(NDEBUG)
2136 static void vm_compile_all(void)
2141 classcache_name_entry *nmen;
2142 classcache_class_entry *clsen;
2145 /* create all classes found in the bootclasspath */
2146 /* XXX currently only works with zip/jar's */
2148 loader_load_all_classes();
2150 /* link all classes */
2152 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2153 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2155 for (; nmen; nmen = nmen->hashlink) {
2156 /* iterate over all class entries */
2158 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2159 c = clsen->classobj;
2164 if (!(c->state & CLASS_LINKED)) {
2165 if (!link_class(c)) {
2166 fprintf(stderr, "Error linking: ");
2167 utf_fprint_printable_ascii_classname(stderr, c->name);
2168 fprintf(stderr, "\n");
2170 /* print out exception and cause */
2172 exceptions_print_current_exception();
2174 /* goto next class */
2180 /* compile all class methods */
2182 for (i = 0; i < c->methodscount; i++) {
2183 m = &(c->methods[i]);
2185 if (m->jcode != NULL) {
2186 if (!jit_compile(m)) {
2187 fprintf(stderr, "Error compiling: ");
2188 utf_fprint_printable_ascii_classname(stderr, c->name);
2189 fprintf(stderr, ".");
2190 utf_fprint_printable_ascii(stderr, m->name);
2191 utf_fprint_printable_ascii(stderr, m->descriptor);
2192 fprintf(stderr, "\n");
2194 /* print out exception and cause */
2196 exceptions_print_current_exception();
2204 #endif /* !defined(NDEBUG) */
2207 /* vm_compile_method ***********************************************************
2209 Compile a specific method.
2211 *******************************************************************************/
2213 #if !defined(NDEBUG)
2214 static void vm_compile_method(char* mainname)
2218 /* create, load and link the main class */
2220 mainclass = load_class_bootstrap(utf_new_char(mainname));
2222 if (mainclass == NULL)
2223 exceptions_print_stacktrace();
2225 if (!link_class(mainclass))
2226 exceptions_print_stacktrace();
2228 if (opt_CompileSignature != NULL) {
2229 m = class_resolveclassmethod(mainclass,
2230 utf_new_char(opt_CompileMethod),
2231 utf_new_char(opt_CompileSignature),
2236 m = class_resolveclassmethod(mainclass,
2237 utf_new_char(opt_CompileMethod),
2244 os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2245 opt_CompileMethod, opt_CompileSignature ? opt_CompileSignature : "");
2249 #endif /* !defined(NDEBUG) */
2252 /* vm_call_array ***************************************************************
2254 Calls a Java method with a variable number of arguments, passed via
2257 ATTENTION: This function has to be used outside the nativeworld.
2259 *******************************************************************************/
2261 #define VM_CALL_ARRAY(name, type) \
2262 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2268 assert(m->code != NULL); \
2270 md = m->parseddesc; \
2271 pv = m->code->entrypoint; \
2273 STATISTICS(count_calls_native_to_java++); \
2275 value = asm_vm_call_method##name(pv, array, md->memuse); \
2280 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2286 assert(m->code != NULL);
2289 pv = m->code->entrypoint;
2291 STATISTICS(count_calls_native_to_java++);
2293 o = asm_vm_call_method(pv, array, md->memuse);
2295 if (md->returntype.type == TYPE_VOID)
2298 return LLNI_WRAP(o);
2301 VM_CALL_ARRAY(_int, int32_t)
2302 VM_CALL_ARRAY(_long, int64_t)
2303 VM_CALL_ARRAY(_float, float)
2304 VM_CALL_ARRAY(_double, double)
2307 /* vm_call_method **************************************************************
2309 Calls a Java method with a variable number of arguments.
2311 *******************************************************************************/
2313 #define VM_CALL_METHOD(name, type) \
2314 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2320 value = vm_call_method##name##_valist(m, o, ap); \
2326 VM_CALL_METHOD(, java_handle_t *)
2327 VM_CALL_METHOD(_int, int32_t)
2328 VM_CALL_METHOD(_long, int64_t)
2329 VM_CALL_METHOD(_float, float)
2330 VM_CALL_METHOD(_double, double)
2333 /* vm_call_method_valist *******************************************************
2335 Calls a Java method with a variable number of arguments, passed via
2338 *******************************************************************************/
2340 #define VM_CALL_METHOD_VALIST(name, type) \
2341 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2347 if (m->code == NULL) \
2348 if (!jit_compile(m)) \
2351 THREAD_NATIVEWORLD_EXIT; \
2353 DumpMemoryArea dma; \
2355 array = argument_vmarray_from_valist(m, o, ap); \
2356 value = vm_call##name##_array(m, array); \
2358 THREAD_NATIVEWORLD_ENTER; \
2363 VM_CALL_METHOD_VALIST(, java_handle_t *)
2364 VM_CALL_METHOD_VALIST(_int, int32_t)
2365 VM_CALL_METHOD_VALIST(_long, int64_t)
2366 VM_CALL_METHOD_VALIST(_float, float)
2367 VM_CALL_METHOD_VALIST(_double, double)
2370 /* vm_call_method_jvalue *******************************************************
2372 Calls a Java method with a variable number of arguments, passed via
2375 *******************************************************************************/
2377 #define VM_CALL_METHOD_JVALUE(name, type) \
2378 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2379 const jvalue *args) \
2384 if (m->code == NULL) \
2385 if (!jit_compile(m)) \
2388 THREAD_NATIVEWORLD_EXIT; \
2390 DumpMemoryArea dma; \
2392 array = argument_vmarray_from_jvalue(m, o, args); \
2393 value = vm_call##name##_array(m, array); \
2395 THREAD_NATIVEWORLD_ENTER; \
2400 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2401 VM_CALL_METHOD_JVALUE(_int, int32_t)
2402 VM_CALL_METHOD_JVALUE(_long, int64_t)
2403 VM_CALL_METHOD_JVALUE(_float, float)
2404 VM_CALL_METHOD_JVALUE(_double, double)
2407 /* vm_call_method_objectarray **************************************************
2409 Calls a Java method with a variable number if arguments, passed via
2410 an objectarray of boxed values. Returns a boxed value.
2412 *******************************************************************************/
2414 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2415 java_handle_objectarray_t *params)
2418 java_handle_t *xptr;
2422 /* Prevent compiler warnings. */
2426 /* compile methods which are not yet compiled */
2428 if (m->code == NULL)
2429 if (!jit_compile(m))
2432 /* leave the nativeworld */
2434 THREAD_NATIVEWORLD_EXIT;
2436 // Create new dump memory area.
2439 /* Fill the argument array from a object-array. */
2441 array = argument_vmarray_from_objectarray(m, o, params);
2443 if (array == NULL) {
2444 /* enter the nativeworld again */
2446 THREAD_NATIVEWORLD_ENTER;
2448 exceptions_throw_illegalargumentexception();
2453 switch (m->parseddesc->returntype.primitivetype) {
2454 case PRIMITIVETYPE_VOID:
2455 value.a = vm_call_array(m, array);
2458 case PRIMITIVETYPE_BOOLEAN:
2459 case PRIMITIVETYPE_BYTE:
2460 case PRIMITIVETYPE_CHAR:
2461 case PRIMITIVETYPE_SHORT:
2462 case PRIMITIVETYPE_INT:
2463 value.i = vm_call_int_array(m, array);
2466 case PRIMITIVETYPE_LONG:
2467 value.l = vm_call_long_array(m, array);
2470 case PRIMITIVETYPE_FLOAT:
2471 value.f = vm_call_float_array(m, array);
2474 case PRIMITIVETYPE_DOUBLE:
2475 value.d = vm_call_double_array(m, array);
2479 ro = vm_call_array(m, array);
2483 os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2486 /* enter the nativeworld again */
2488 THREAD_NATIVEWORLD_ENTER;
2490 /* box the return value if necesarry */
2492 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2493 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2495 /* check for an exception */
2497 xptr = exceptions_get_exception();
2500 /* clear exception pointer, we are calling JIT code again */
2502 exceptions_clear_exception();
2504 exceptions_throw_invocationtargetexception(xptr);
2511 /* Legacy C interface *********************************************************/
2515 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2516 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2517 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2518 bool VM_is_created() { return VM::get_current()->is_created(); }
2519 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2521 void vm_abort(const char* text, ...)
2525 log_println("vm_abort: WARNING, port me to C++ and use os::abort() instead.");
2527 // Print the log message.
2531 log_vprint(text, ap);
2536 // Print a backtrace.
2537 os::print_backtrace();
2539 // Now abort the VM.
2547 * These are local overrides for various environment variables in Emacs.
2548 * Please do not remove this and leave it at the end of the file, where
2549 * Emacs will automagically detect them.
2550 * ---------------------------------------------------------------------
2553 * indent-tabs-mode: t
2557 * vim:noexpandtab:sw=4:ts=4: