1 /* src/vm/vm.cpp - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008, 2009, 2010
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/hook.hpp"
73 #include "vm/initialize.hpp"
74 #include "vm/javaobjects.hpp"
75 #include "vm/options.h"
77 #include "vm/primitive.hpp"
78 #include "vm/properties.hpp"
79 #include "vm/signallocal.hpp"
80 #include "vm/statistics.h"
81 #include "vm/string.hpp"
82 #include "vm/suck.hpp"
85 #include "vm/jit/argument.hpp"
86 #include "vm/jit/asmpart.h"
87 #include "vm/jit/code.hpp"
89 #if defined(ENABLE_DISASSEMBLER)
90 # include "vm/jit/disass.h"
93 #include "vm/jit/jit.hpp"
94 #include "vm/jit/methodtree.h"
96 #include "vm/jit/optimizing/profile.hpp"
97 #include "vm/jit/optimizing/recompiler.hpp"
99 #if defined(ENABLE_PYTHON)
100 # include "vm/jit/python.h"
103 #include "vm/jit/trap.hpp"
105 #if defined(ENABLE_VMLOG)
106 #include <vmlog_cacao.h>
111 * This is _the_ VM instance.
116 /* global variables ***********************************************************/
118 s4 vms = 0; /* number of VMs created */
120 static classinfo *mainclass = NULL;
122 #if defined(ENABLE_INTRP)
123 u1 *intrp_main_stack = NULL;
127 /* define heap sizes **********************************************************/
129 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
130 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
131 #define STACK_SIZE 128 * 1024 /* default 64kB */
134 /* define command line options ************************************************/
168 /* Java non-standard options */
179 #if defined(ENABLE_PROFILING)
193 #if defined(ENABLE_STATISTICS)
204 #if defined(ENABLE_VERIFIER)
208 #if defined(TYPECHECK_VERBOSE)
211 #endif /* defined(ENABLE_VERIFIER) */
213 /* optimization options */
215 #if defined(ENABLE_LOOP)
219 #if defined(ENABLE_IFCONV)
223 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
227 #if defined(ENABLE_INTRP)
228 /* interpreter options */
239 #if defined(ENABLE_JVMTI)
245 #if defined(ENABLE_DEBUG_FILTER)
246 OPT_FILTER_VERBOSECALL_INCLUDE,
247 OPT_FILTER_VERBOSECALL_EXCLUDE,
248 OPT_FILTER_SHOW_METHOD,
255 opt_struct opts[] = {
256 { "foo", false, OPT_FOO },
260 { "jar", false, OPT_JAR },
262 { "d32", false, OPT_D32 },
263 { "d64", false, OPT_D64 },
264 { "client", false, OPT_IGNORE },
265 { "server", false, OPT_IGNORE },
266 { "jvm", false, OPT_IGNORE },
267 { "hotspot", false, OPT_IGNORE },
269 { "classpath", true, OPT_CLASSPATH },
270 { "cp", true, OPT_CLASSPATH },
271 { "D", true, OPT_D },
272 { "version", false, OPT_VERSION },
273 { "showversion", false, OPT_SHOWVERSION },
274 { "fullversion", false, OPT_FULLVERSION },
275 { "help", false, OPT_HELP },
276 { "?", false, OPT_HELP },
277 { "X", false, OPT_X },
278 { "XX:", true, OPT_XX },
280 { "ea:", true, OPT_EA },
281 { "da:", true, OPT_DA },
282 { "ea", false, OPT_EA_NOARG },
283 { "da", false, OPT_DA_NOARG },
285 { "enableassertions:", true, OPT_EA },
286 { "disableassertions:", true, OPT_DA },
287 { "enableassertions", false, OPT_EA_NOARG },
288 { "disableassertions", false, OPT_DA_NOARG },
290 { "esa", false, OPT_ESA },
291 { "enablesystemassertions", false, OPT_ESA },
292 { "dsa", false, OPT_DSA },
293 { "disablesystemassertions", false, OPT_DSA },
295 { "noasyncgc", false, OPT_IGNORE },
296 #if defined(ENABLE_VERIFIER)
297 { "noverify", false, OPT_NOVERIFY },
298 { "Xverify:all", false, OPT_XVERIFY_ALL },
299 { "Xverify:none", false, OPT_XVERIFY_NONE },
301 { "v", false, OPT_VERBOSE1 },
302 { "verbose:", true, OPT_VERBOSE },
304 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
305 { "verbosetc", false, OPT_VERBOSETC },
307 #if defined(ENABLE_STATISTICS)
308 { "time", false, OPT_TIME },
309 { "stat", false, OPT_STAT },
311 { "log", true, OPT_LOG },
312 { "c", true, OPT_CHECK },
313 { "l", false, OPT_LOAD },
315 #if defined(ENABLE_LOOP)
316 { "oloop", false, OPT_OLOOP },
318 #if defined(ENABLE_IFCONV)
319 { "ifconv", false, OPT_IFCONV },
321 #if defined(ENABLE_LSRA)
322 { "lsra", false, OPT_LSRA },
324 #if defined(ENABLE_SSA)
325 { "lsra", true, OPT_LSRA },
328 #if defined(ENABLE_INTRP)
329 /* interpreter options */
331 { "trace", false, OPT_TRACE },
332 { "static-supers", true, OPT_STATIC_SUPERS },
333 { "no-dynamic", false, OPT_NO_DYNAMIC },
334 { "no-replication", false, OPT_NO_REPLICATION },
335 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
338 /* JVMTI Agent Command Line Options */
339 #if defined(ENABLE_JVMTI)
340 { "agentlib:", true, OPT_AGENTLIB },
341 { "agentpath:", true, OPT_AGENTPATH },
344 /* Java non-standard options */
346 { "Xjit", false, OPT_JIT },
347 { "Xint", false, OPT_INTRP },
348 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
349 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
350 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
351 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
353 #if defined(ENABLE_JVMTI)
354 { "Xdebug", false, OPT_IGNORE },
355 { "Xnoagent", false, OPT_IGNORE },
356 { "Xrun", true, OPT_RUN },
359 { "Xms", true, OPT_MS },
360 { "ms", true, OPT_MS },
361 { "Xmx", true, OPT_MX },
362 { "mx", true, OPT_MX },
363 { "Xss", true, OPT_SS },
364 { "ss", true, OPT_SS },
366 { "Xcheck:jni", false, OPT_XCHECK_JNI },
368 #if defined(ENABLE_PROFILING)
369 { "Xprof:", true, OPT_PROF_OPTION },
370 { "Xprof", false, OPT_PROF },
373 /* keep these at the end of the list */
375 { "s", true, OPT_SHOW },
376 { "debug-color", false, OPT_DEBUGCOLOR },
378 #if defined(ENABLE_DEBUG_FILTER)
379 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
380 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
381 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
388 /* usage ***********************************************************************
390 Prints the correct usage syntax to stdout.
392 *******************************************************************************/
394 static void usage(void)
396 puts("Usage: cacao [-options] classname [arguments]");
397 puts(" (to run a class file)");
398 puts(" or cacao [-options] -jar jarfile [arguments]");
399 puts(" (to run a standalone jar file)\n");
401 puts("where options include:");
402 puts(" -d32 use 32-bit data model if available");
403 puts(" -d64 use 64-bit data model if available");
404 puts(" -client compatibility (currently ignored)");
405 puts(" -server compatibility (currently ignored)");
406 puts(" -jvm compatibility (currently ignored)");
407 puts(" -hotspot compatibility (currently ignored)\n");
409 puts(" -cp <path> specify a path to look for classes");
410 puts(" -classpath <path> specify a path to look for classes");
411 puts(" -D<name>=<value> add an entry to the property list");
412 puts(" -verbose[:class|gc|jni] enable specific verbose output");
413 puts(" -version print product version and exit");
414 puts(" -fullversion print jpackage-compatible product version and exit");
415 puts(" -showversion print product version and continue");
416 puts(" -help, -? print this help message");
417 puts(" -X print help on non-standard Java options");
418 puts(" -XX print help on debugging options");
419 puts(" -ea[:<packagename>...|:<classname>]");
420 puts(" -enableassertions[:<packagename>...|:<classname>]");
421 puts(" enable assertions with specified granularity");
422 puts(" -da[:<packagename>...|:<classname>]");
423 puts(" -disableassertions[:<packagename>...|:<classname>]");
424 puts(" disable assertions with specified granularity");
425 puts(" -esa | -enablesystemassertions");
426 puts(" enable system assertions");
427 puts(" -dsa | -disablesystemassertions");
428 puts(" disable system assertions");
430 #if defined(ENABLE_JVMTI)
431 puts(" -agentlib:<agent-lib-name>=<options>");
432 puts(" load native agent library by library name");
433 puts(" for additional help use: -agentlib:jdwp=help");
434 puts(" -agentpath:<path-to-agent>=<options>");
435 puts(" load native agent library by full pathname");
438 /* exit with error code */
444 static void Xusage(void)
446 #if defined(ENABLE_JIT)
447 puts(" -Xjit JIT mode execution (default)");
449 #if defined(ENABLE_INTRP)
450 puts(" -Xint interpreter mode execution");
452 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
453 puts(" value is set as bootstrap class path");
454 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
455 puts(" value is appended to the bootstrap class path");
456 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
457 puts(" value is prepended to the bootstrap class path");
458 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
459 puts(" value is used as Java core library, but the");
460 puts(" hardcoded VM interface classes are prepended");
461 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
462 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
463 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
465 #if defined(ENABLE_PROFILING)
466 puts(" -Xprof[:bb] collect and print profiling data");
469 /* exit with error code */
476 static void XXusage(void)
478 puts(" -v write state-information");
480 puts(" -verbose:jit enable specific verbose output");
481 puts(" -debug-color colored output for ANSI terms");
483 #ifdef TYPECHECK_VERBOSE
484 puts(" -verbosetc write debug messages while typechecking");
486 #if defined(ENABLE_VERIFIER)
487 puts(" -noverify don't verify classfiles");
489 #if defined(ENABLE_STATISTICS)
490 puts(" -time measure the runtime");
491 puts(" -stat detailed compiler statistics");
493 puts(" -log logfile specify a name for the logfile");
494 puts(" -c(heck)b(ounds) don't check array bounds");
495 puts(" s(ync) don't check for synchronization");
496 #if defined(ENABLE_LOOP)
497 puts(" -oloop optimize array accesses in loops");
499 puts(" -l don't start the class after loading");
501 puts(" -s... show...");
502 puts(" (c)onstants the constant pool");
503 puts(" (m)ethods class fields and methods");
504 puts(" (u)tf the utf - hash");
505 puts(" (i)ntermediate intermediate representation");
506 #if defined(ENABLE_DISASSEMBLER)
507 puts(" (a)ssembler disassembled listing");
508 puts(" n(o)ps show NOPs in disassembler output");
510 puts(" (d)atasegment data segment listing");
512 #if defined(ENABLE_IFCONV)
513 puts(" -ifconv use if-conversion");
515 #if defined(ENABLE_LSRA)
516 puts(" -lsra use linear scan register allocation");
518 #if defined(ENABLE_SSA)
519 puts(" -lsra:... use linear scan register allocation (with SSA)");
520 puts(" (d)ead code elimination");
521 puts(" (c)opy propagation");
523 #if defined(ENABLE_DEBUG_FILTER)
524 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
525 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
526 puts(" -XXfm <regex> filter for show options");
528 /* exit with error code */
535 /* version *********************************************************************
537 Only prints cacao version information.
539 *******************************************************************************/
541 static void version(bool opt_exit)
543 puts("java version \""JAVA_VERSION"\"");
544 puts("CACAO version "VERSION_FULL"\n");
546 puts("Copyright (C) 1996-2005, 2006, 2007, 2008, 2009, 2010, 2011");
547 puts("CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO");
548 puts("This is free software; see the source for copying conditions. There is NO");
549 puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
551 /* exit normally, if requested */
558 /* fullversion *****************************************************************
560 Prints a Sun compatible version information (required e.g. by
561 jpackage, www.jpackage.org).
563 *******************************************************************************/
565 static void fullversion(void)
567 puts("java full version \"cacao-"JAVA_VERSION"\"");
575 /* forward declarations *******************************************************/
577 static char *vm_get_mainclass_from_jar(char *mainstring);
579 static void vm_compile_all(void);
580 static void vm_compile_method(char* mainname);
585 * Implementation for JNI_CreateJavaVM. This function creates a VM
592 * @return true on success, false otherwise.
594 bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
596 JavaVMInitArgs* _vm_args;
598 // Get the arguments for the new JVM.
599 _vm_args = (JavaVMInitArgs *) vm_args;
601 // Instantiate a new VM.
603 _vm = new VM(_vm_args);
605 catch (std::exception e) {
606 // FIXME How can we delete the resources allocated?
607 // /* release allocated memory */
608 // FREE(env, _Jv_JNIEnv);
609 // FREE(vm, _Jv_JavaVM);
616 // Return the values.
618 *p_vm = _vm->get_javavm();
619 *p_env = _vm->get_jnienv();
626 * C wrapper for VM::create.
629 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args)
631 return VM::create(p_vm, p_env, vm_args);
639 VM::VM(JavaVMInitArgs* vm_args)
641 // Very first thing to do: we are initializing.
642 _initializing = true;
644 // Make ourself globally visible.
645 // XXX Is this a good idea?
648 /* create and fill a JavaVM structure */
650 _javavm = new JavaVM();
652 #if defined(ENABLE_JNI)
653 _javavm->functions = &_Jv_JNIInvokeInterface;
656 /* get the VM and Env tables (must be set before vm_create) */
657 /* XXX JVMTI Agents needs a JavaVM */
659 _jnienv = new JNIEnv();
661 #if defined(ENABLE_JNI)
662 _jnienv->functions = &_Jv_JNINativeInterface;
665 /* actually create the JVM */
669 char *boot_class_path;
675 #if defined(ENABLE_JNI)
676 /* Check the JNI version requested. */
678 if (!jni_version_check(vm_args->version))
679 throw std::exception();
682 /* We only support 1 JVM instance. */
685 throw std::exception();
687 /* Install the exit handler. */
689 if (atexit(vm_exit_handler))
690 os::abort("atexit failed: %s\n", strerror(errno));
692 /* Set some options. */
697 opt_heapmaxsize = HEAP_MAXSIZE;
698 opt_heapstartsize = HEAP_STARTSIZE;
699 opt_stacksize = STACK_SIZE;
701 // First of all, parse the -XX options.
703 #if defined(ENABLE_VMLOG)
704 vmlog_cacao_init_options();
709 // After -XX options are parsed, print the build-time
710 // configuration, if requested.
712 print_build_time_config();
714 #if defined(ENABLE_VMLOG)
718 /* We need to check if the actual size of a java.lang.Class object
719 is smaller or equal than the assumption made in
722 // FIXME We need to check the size of java.lang.Class!!!
723 // if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
724 // vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
726 /* set the VM starttime */
728 _starttime = builtin_currenttimemillis();
730 /* iterate over all passed options */
732 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
746 #if SIZEOF_VOID_P == 8
747 puts("Running a 32-bit JVM is not supported on this platform.");
753 #if SIZEOF_VOID_P == 4
754 puts("Running a 64-bit JVM is not supported on this platform.");
760 /* Forget old classpath and set the argument as new
763 // FIXME Make class_path const char*.
764 class_path = (char*) _properties.get("java.class.path");
766 p = MNEW(char, strlen(opt_arg) + strlen("0"));
770 #if defined(ENABLE_JAVASE)
771 _properties.put("java.class.path", p);
774 MFREE(class_path, char, strlen(class_path));
778 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
779 if (opt_arg[i] == '=') {
781 _properties.put(opt_arg, opt_arg + i + 1);
786 /* if no '=' is given, just create an empty property */
788 _properties.put(opt_arg, "");
793 case OPT_BOOTCLASSPATH:
794 /* Forget default bootclasspath and set the argument as
795 new boot classpath. */
797 // FIXME Make boot_class_path const char*.
798 boot_class_path = (char*) _properties.get("sun.boot.class.path");
800 p = MNEW(char, strlen(opt_arg) + strlen("0"));
804 _properties.put("sun.boot.class.path", p);
805 _properties.put("java.boot.class.path", p);
807 MFREE(boot_class_path, char, strlen(boot_class_path));
810 case OPT_BOOTCLASSPATH_A:
811 /* Append to bootclasspath. */
813 // FIXME Make boot_class_path const char*.
814 boot_class_path = (char*) _properties.get("sun.boot.class.path");
816 len = strlen(boot_class_path);
818 // XXX (char*) quick hack
819 p = (char*) MREALLOC(boot_class_path,
823 strlen(opt_arg) + strlen("0"));
828 _properties.put("sun.boot.class.path", p);
829 _properties.put("java.boot.class.path", p);
832 case OPT_BOOTCLASSPATH_P:
833 /* Prepend to bootclasspath. */
835 // FIXME Make boot_class_path const char*.
836 boot_class_path = (char*) _properties.get("sun.boot.class.path");
838 len = strlen(boot_class_path);
840 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
844 strcat(p, boot_class_path);
846 _properties.put("sun.boot.class.path", p);
847 _properties.put("java.boot.class.path", p);
849 MFREE(boot_class_path, char, len);
852 case OPT_BOOTCLASSPATH_C:
853 /* Use as Java core library, but prepend VM interface
856 // FIXME Make boot_class_path const char*.
857 boot_class_path = (char*) _properties.get("sun.boot.class.path");
860 strlen(CACAO_VM_ZIP) +
867 strcpy(p, CACAO_VM_ZIP);
871 _properties.put("sun.boot.class.path", p);
872 _properties.put("java.boot.class.path", p);
874 MFREE(boot_class_path, char, strlen(boot_class_path));
877 #if defined(ENABLE_JVMTI)
879 // Parse option argument.
880 p = strchr(opt_arg, '=');
884 _nativeagents.register_agent_library(opt_arg, p);
888 // Parse option argument.
889 p = strchr(opt_arg, '=');
893 _nativeagents.register_agent_path(opt_arg, p);
897 // Parse option argument.
898 p = strchr(opt_arg, ':');
902 _nativeagents.register_agent_library(opt_arg, p);
913 c = opt_arg[strlen(opt_arg) - 1];
915 if ((c == 'k') || (c == 'K')) {
916 j = atoi(opt_arg) * 1024;
918 } else if ((c == 'm') || (c == 'M')) {
919 j = atoi(opt_arg) * 1024 * 1024;
926 else if (opt == OPT_MS)
927 opt_heapstartsize = j;
934 // HotSpot compatibility option.
942 if (strcmp("class", opt_arg) == 0) {
943 opt_verboseclass = true;
945 else if (strcmp("gc", opt_arg) == 0) {
946 opt_verbosegc = true;
948 else if (strcmp("jni", opt_arg) == 0) {
949 opt_verbosejni = true;
952 else if (strcmp("jit", opt_arg) == 0) {
956 compileverbose = true;
960 printf("Unknown -verbose option: %s\n", opt_arg);
966 opt_debugcolor = true;
969 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
971 opt_typecheckverbose = true;
980 case OPT_FULLVERSION:
984 case OPT_SHOWVERSION:
988 #if defined(ENABLE_VERIFIER)
989 case OPT_XVERIFY_ALL:
994 case OPT_XVERIFY_NONE:
999 #if defined(ENABLE_STATISTICS)
1001 opt_getcompilingtime = true;
1002 opt_getloadingtime = true;
1015 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1016 switch (opt_arg[i]) {
1018 checkbounds = false;
1031 makeinitializations = false;
1034 case OPT_SHOW: /* Display options */
1035 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1036 switch (opt_arg[i]) {
1038 showconstantpool = true;
1050 opt_showintermediate = true;
1051 compileverbose = true;
1054 #if defined(ENABLE_DISASSEMBLER)
1056 opt_showdisassemble = true;
1057 compileverbose = true;
1062 opt_showddatasegment = true;
1071 #if defined(ENABLE_LOOP)
1077 #if defined(ENABLE_IFCONV)
1083 #if defined(ENABLE_LSRA)
1088 #if defined(ENABLE_SSA)
1091 for (unsigned int i = 0; i < strlen(opt_arg); i++) {
1092 switch (opt_arg[i]) {
1120 /* Already parsed. */
1124 #if defined(ENABLE_ASSERTION)
1125 assertion_ea_da(opt_arg, true);
1130 #if defined(ENABLE_ASSERTION)
1131 assertion_ea_da(opt_arg, false);
1136 #if defined(ENABLE_ASSERTION)
1137 assertion_user_enabled = true;
1142 #if defined(ENABLE_ASSERTION)
1143 assertion_user_enabled = false;
1148 #if defined(ENABLE_ASSERTION)
1149 assertion_system_enabled = true;
1154 #if defined(ENABLE_ASSERTION)
1155 assertion_system_enabled = false;
1159 #if defined(ENABLE_PROFILING)
1160 case OPT_PROF_OPTION:
1161 /* use <= to get the last \0 too */
1163 for (unsigned int i = 0, j = 0; i <= strlen(opt_arg); i++) {
1164 if (opt_arg[i] == ',')
1167 if (opt_arg[i] == '\0') {
1168 if (strcmp("bb", opt_arg + j) == 0)
1172 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1176 /* set k to next char */
1189 #if defined(ENABLE_JIT)
1192 printf("-Xjit option not enabled.\n");
1198 #if defined(ENABLE_INTRP)
1201 printf("-Xint option not enabled.\n");
1206 #if defined(ENABLE_INTRP)
1207 case OPT_STATIC_SUPERS:
1208 opt_static_supers = atoi(opt_arg);
1211 case OPT_NO_DYNAMIC:
1212 opt_no_dynamic = true;
1215 case OPT_NO_REPLICATION:
1216 opt_no_replication = true;
1219 case OPT_NO_QUICKSUPER:
1220 opt_no_quicksuper = true;
1228 #if defined(ENABLE_DEBUG_FILTER)
1229 case OPT_FILTER_VERBOSECALL_INCLUDE:
1230 opt_filter_verbosecall_include = opt_arg;
1233 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1234 opt_filter_verbosecall_exclude = opt_arg;
1237 case OPT_FILTER_SHOW_METHOD:
1238 opt_filter_show_method = opt_arg;
1243 printf("Unknown option: %s\n",
1244 vm_args->options[opt_index].optionString);
1249 // Print the preliminary run-time VM configuration after options
1251 if (opt_PrintConfig)
1252 print_run_time_config();
1254 /* initialize the garbage collector */
1256 gc_init(opt_heapmaxsize, opt_heapstartsize);
1258 #if defined(ENABLE_THREADS)
1259 /* AFTER: gc_init */
1265 /* install architecture dependent signal handlers */
1268 os::abort("vm_create: signal_init failed");
1270 #if defined(ENABLE_INTRP)
1271 /* Allocate main thread stack on the Java heap. */
1274 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1275 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1279 /* AFTER: threads_preinit */
1282 os::abort("vm_create: string_init failed");
1284 /* AFTER: threads_preinit */
1288 // Hook point before the VM is initialized.
1291 #if defined(ENABLE_JVMTI)
1293 if (!_nativeagents.load_agents())
1294 os::abort("vm_create: load_agents failed");
1297 /* AFTER: thread_preinit */
1299 _suckclasspath.add_from_property("java.endorsed.dirs");
1301 /* Now we have all options handled and we can print the version
1304 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1309 /* AFTER: utf8_init */
1311 // FIXME Make boot_class_path const char*.
1312 boot_class_path = (char*) _properties.get("sun.boot.class.path");
1313 _suckclasspath.add(boot_class_path);
1315 /* initialize the classcache hashtable stuff: lock, hashtable
1316 (must be done _after_ threads_preinit) */
1318 if (!classcache_init())
1319 os::abort("vm_create: classcache_init failed");
1321 /* Initialize the code memory management. */
1322 /* AFTER: threads_preinit */
1326 /* initialize the finalizer stuff (must be done _after_
1329 if (!finalizer_init())
1330 os::abort("vm_create: finalizer_init failed");
1332 /* Initialize the JIT compiler. */
1338 #if defined(ENABLE_PYTHON)
1342 /* AFTER: utf8_init, classcache_init */
1347 // AFTER: loader_preinit, linker_preinit
1348 Primitive::initialize_table();
1351 jobjects_register_dyn_offsets();
1354 // AFTER: loader_init, linker_init
1355 Primitive::post_initialize_table();
1358 #if defined(ENABLE_JIT)
1362 if (!builtin_init())
1363 os::abort("vm_create: builtin_init failed");
1365 /* Register the native methods implemented in the VM. */
1366 /* BEFORE: threads_init */
1370 #if defined(ENABLE_JNI)
1371 /* Initialize the JNI subsystem (must be done _before_
1372 threads_init, as threads_init can call JNI methods
1373 (e.g. NewGlobalRef). */
1376 os::abort("vm_create: jni_init failed");
1379 #if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
1380 /* Initialize the local reference table for the main thread. */
1381 /* BEFORE: threads_init */
1383 if (!localref_table_init())
1384 os::abort("vm_create: localref_table_init failed");
1387 /* Iinitialize some important system classes. */
1388 /* BEFORE: threads_init */
1392 #if defined(ENABLE_THREADS)
1396 /* Initialize the native VM subsystem. */
1397 /* AFTER: threads_init (at least for SUN's classes) */
1399 if (!nativevm_init())
1400 os::abort("vm_create: nativevm_init failed");
1402 #if defined(ENABLE_PROFILING)
1403 /* initialize profiling */
1405 if (!profile_init())
1406 os::abort("vm_create: profile_init failed");
1409 #if defined(ENABLE_THREADS)
1410 /* start the signal handler thread */
1412 #if defined(__LINUX__)
1413 /* XXX Remove for exact-GC. */
1414 if (threads_pthreads_implementation_nptl)
1416 if (!signal_start_thread())
1417 os::abort("vm_create: signal_start_thread failed");
1419 /* finally, start the finalizer thread */
1421 if (!finalizer_start_thread())
1422 os::abort("vm_create: finalizer_start_thread failed");
1424 # if !defined(NDEBUG)
1425 /* start the memory profiling thread */
1427 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1428 if (!memory_start_thread())
1429 os::abort("vm_create: memory_start_thread failed");
1432 // Start the recompilation thread (must be done before the
1433 // profiling thread).
1434 // FIXME Only works for one recompiler.
1435 _recompiler.start();
1437 # if defined(ENABLE_PROFILING)
1438 /* start the profile sampling thread */
1441 /* if (!profile_start_thread()) */
1442 /* os::abort("vm_create: profile_start_thread failed"); */
1446 /* Increment the number of VMs. */
1450 // Initialization is done, VM is created.
1452 _initializing = false;
1454 // Set the VM inittime.
1455 _inittime = builtin_currenttimemillis();
1457 // Hook point after the VM is initialized.
1460 // Print the run-time VM configuration after all stuff is set and
1461 // the VM is initialized.
1462 if (opt_PrintConfig)
1463 print_run_time_config();
1465 // Start runtime agents after the VM is created.
1466 if (!start_runtime_agents())
1467 os::abort("vm_create: start_runtime_agents failed");
1472 * Print build-time (default) VM configuration.
1474 void VM::print_build_time_config(void)
1476 puts("CACAO "VERSION_FULL" configure/build options:");
1478 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1479 #if defined(__VERSION__)
1480 puts(" CC : "VERSION_CC" ("__VERSION__")");
1481 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1483 puts(" CC : "VERSION_CC"");
1484 puts(" CXX : "VERSION_CXX"");
1486 puts(" CFLAGS : "VERSION_CFLAGS"");
1487 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1491 puts("Build-time (default) variables:\n");
1492 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1493 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1494 printf(" stack size : %d\n", STACK_SIZE);
1496 #if defined(ENABLE_JRE_LAYOUT)
1497 // When we're building with JRE-layout, the default paths are the
1498 // same as the runtime paths.
1500 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1501 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1502 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1503 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1504 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1505 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1514 * Print run-time VM configuration.
1516 void VM::print_run_time_config()
1518 puts("Run-time variables:\n");
1519 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1520 printf(" initial heap size : %d\n", opt_heapstartsize);
1521 printf(" stack size : %d\n", opt_stacksize);
1523 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1524 printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1525 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1526 printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1529 printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1530 printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1537 * Start runtime agents which are provided by the JRE but need to be
1538 * started explicitly by the VM.
1540 bool VM::start_runtime_agents()
1542 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1546 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1548 // Check whether the management agent should be loaded.
1549 if ((_properties.get("com.sun.management.jmxremote") != NULL) ||
1550 (_properties.get("com.sun.management.snmp") != NULL))
1553 // Load the management agent class.
1554 classinfo* class_sun_management_Agent;
1555 if (!(class_sun_management_Agent = load_class_from_sysloader(utf_new_char("sun/management/Agent"))))
1558 // Link the management agent class.
1559 if (!link_class(class_sun_management_Agent))
1562 // Actually start the management agent.
1563 methodinfo* m = class_resolveclassmethod(class_sun_management_Agent,
1564 utf_new_char("startAgent"),
1566 class_java_lang_Object,
1572 (void) vm_call_method(m, NULL);
1574 if (exceptions_get_exception() != NULL)
1578 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
1583 # error unknown classpath configuration
1590 /* vm_run **********************************************************************
1592 Runs the main-method of the passed class.
1594 *******************************************************************************/
1596 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1601 #if !defined(NDEBUG)
1602 if (opt_CompileAll) {
1608 /* Get the main class or jar file argument. */
1610 char* mainname = NULL;
1612 if (opt_index < vm_args->nOptions) {
1613 /* Get main-class argument. */
1615 mainname = vm_args->options[opt_index].optionString;
1617 /* If the main class argument is a jar file, put it into the
1620 if (opt_jar == true) {
1621 char* p = MNEW(char, strlen(mainname) + strlen("0"));
1623 strcpy(p, mainname);
1625 #if defined(ENABLE_JAVASE)
1626 VM::get_current()->get_properties().put("java.class.path", p);
1630 /* Replace dots with slashes in the class name. */
1632 for (unsigned int i = 0; i < strlen(mainname); i++)
1633 if (mainname[i] == '.')
1637 /* Move index to first argument. */
1642 /* Do we have a main-class argument? */
1644 if (mainname == NULL)
1647 #if !defined(NDEBUG)
1648 if (opt_CompileMethod != NULL) {
1649 vm_compile_method(mainname);
1654 /* Build argument array. */
1656 int32_t oalength = vm_args->nOptions - opt_index;
1658 ObjectArray oa(oalength, class_java_lang_String);
1663 for (int i = 0; i < oalength; i++) {
1664 char* option = vm_args->options[opt_index + i].optionString;
1666 utf* u = utf_new_char(option);
1667 java_handle_t* s = javastring_new(u);
1669 oa.set_element(i, s);
1672 /* set return value to OK */
1676 if (opt_jar == true) {
1677 /* open jar file with java.util.jar.JarFile */
1679 mainname = vm_get_mainclass_from_jar(mainname);
1681 if (mainname == NULL)
1685 /* load the main class */
1687 utf* mainutf = utf_new_char(mainname);
1689 #if defined(ENABLE_JAVAME_CLDC1_1)
1690 classinfo* mainclass = load_class_bootstrap(mainutf);
1692 classinfo* mainclass = load_class_from_sysloader(mainutf);
1695 /* error loading class */
1697 java_handle_t* e = exceptions_get_and_clear_exception();
1699 if ((e != NULL) || (mainclass == NULL)) {
1700 exceptions_throw_noclassdeffounderror_cause(e);
1701 exceptions_print_stacktrace();
1705 if (!link_class(mainclass)) {
1706 exceptions_print_stacktrace();
1710 /* find the `main' method of the main class */
1712 m = class_resolveclassmethod(mainclass,
1713 utf_new_char("main"),
1714 utf_new_char("([Ljava/lang/String;)V"),
1715 class_java_lang_Object,
1718 if (exceptions_get_exception()) {
1719 exceptions_print_stacktrace();
1723 /* there is no main method or it isn't static */
1725 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1726 exceptions_clear_exception();
1727 exceptions_throw_nosuchmethoderror(mainclass,
1728 utf_new_char("main"),
1729 utf_new_char("([Ljava/lang/String;)V"));
1731 exceptions_print_stacktrace();
1735 #ifdef TYPEINFO_DEBUG_TEST
1736 /* test the typeinfo system */
1740 /* start the main thread */
1742 (void) vm_call_method(m, NULL, oa.get_handle());
1744 /* exception occurred? */
1746 if (exceptions_get_exception()) {
1747 exceptions_print_stacktrace();
1751 #if defined(ENABLE_THREADS)
1752 /* Detach the main thread so that it appears to have ended when
1753 the application's main method exits. */
1755 if (!thread_detach_current_thread())
1756 os::abort("vm_run: Could not detach main thread.");
1759 /* Destroy the JavaVM. */
1761 (void) vm_destroy(vm);
1769 /* vm_destroy ******************************************************************
1771 Unloads a Java VM and reclaims its resources.
1773 *******************************************************************************/
1775 int vm_destroy(JavaVM *vm)
1777 #if defined(ENABLE_THREADS)
1778 /* Create a a trivial new Java waiter thread called
1781 JavaVMAttachArgs args;
1783 args.name = (char*) "DestroyJavaVM";
1786 if (!thread_attach_current_thread(&args, false))
1789 /* Wait until we are the last non-daemon thread. */
1791 threads_join_all_threads();
1794 // Hook point before the VM is actually destroyed.
1795 Hook::vm_shutdown();
1799 // _created = false;
1801 /* Everything is ok. */
1807 /* vm_exit *********************************************************************
1809 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1811 *******************************************************************************/
1813 void vm_exit(s4 status)
1817 /* signal that we are exiting */
1821 assert(class_java_lang_System);
1822 assert(class_java_lang_System->state & CLASS_LOADED);
1824 #if defined(ENABLE_JVMTI)
1825 if (jvmti || (dbgcom!=NULL)) {
1826 jvmti_set_phase(JVMTI_PHASE_DEAD);
1827 if (jvmti) jvmti_agentunload();
1831 if (!link_class(class_java_lang_System)) {
1832 exceptions_print_stacktrace();
1836 /* call java.lang.System.exit(I)V */
1838 m = class_resolveclassmethod(class_java_lang_System,
1839 utf_new_char("exit"),
1841 class_java_lang_Object,
1845 exceptions_print_stacktrace();
1849 /* call the exit function with passed exit status */
1851 (void) vm_call_method(m, NULL, status);
1853 /* If we had an exception, just ignore the exception and exit with
1856 vm_shutdown(status);
1860 /* vm_shutdown *****************************************************************
1862 Terminates the system immediately without freeing memory explicitly
1863 (to be used only for abnormal termination).
1865 *******************************************************************************/
1867 void vm_shutdown(s4 status)
1870 #if defined(ENABLE_STATISTICS)
1871 || opt_getcompilingtime || opt_stat
1875 log_text("CACAO terminated by shutdown");
1876 dolog("Exit status: %d\n", (s4) status);
1880 #if defined(ENABLE_JVMTI)
1881 /* terminate cacaodbgserver */
1883 mutex_lock(&dbgcomlock);
1885 mutex_unlock(&dbgcomlock);
1886 jvmti_cacaodbgserver_quit();
1894 /* vm_exit_handler *************************************************************
1896 The exit_handler function is called upon program termination.
1898 ATTENTION: Don't free system resources here! Some threads may still
1899 be running as this is called from VMRuntime.exit(). The OS does the
1902 *******************************************************************************/
1904 void vm_exit_handler(void)
1906 #if !defined(NDEBUG)
1908 class_showmethods(mainclass);
1910 if (showconstantpool)
1911 class_showconstantpool(mainclass);
1916 # if defined(ENABLE_PROFILING)
1918 profile_printstats();
1920 #endif /* !defined(NDEBUG) */
1922 #if defined(ENABLE_RT_TIMING)
1923 rt_timing_print_time_stats(stderr);
1926 #if defined(ENABLE_CYCLES_STATS)
1927 builtin_print_cycles_stats(stderr);
1928 stacktrace_print_cycles_stats(stderr);
1932 #if defined(ENABLE_STATISTICS)
1933 || opt_getcompilingtime || opt_stat
1937 log_text("CACAO terminated");
1939 #if defined(ENABLE_STATISTICS)
1942 #ifdef TYPECHECK_STATISTICS
1943 typecheck_print_statistics(get_logfile());
1947 if (opt_getcompilingtime)
1949 #endif /* defined(ENABLE_STATISTICS) */
1951 /* vm_print_profile(stderr);*/
1955 /* vm_abort_disassemble ********************************************************
1957 Prints an error message, disassemble the given code range (if
1958 enabled) and aborts the VM.
1961 pc.......PC to disassemble
1962 count....number of instructions to disassemble
1964 *******************************************************************************/
1966 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
1969 #if defined(ENABLE_DISASSEMBLER)
1973 /* Print debug message. */
1978 log_vprint(text, ap);
1985 #if SIZEOF_VOID_P == 8
1986 log_println("PC=0x%016lx", pc);
1988 log_println("PC=0x%08x", pc);
1991 #if defined(ENABLE_DISASSEMBLER)
1992 log_println("machine instructions at PC:");
1994 /* Disassemble the given number of instructions. */
1996 for (i = 0; i < count; i++)
1997 // FIXME disassinstr should use void*.
1998 pc = disassinstr((u1*) pc);
2001 os::abort("Aborting...");
2005 /* vm_get_mainclass_from_jar ***************************************************
2007 Gets the name of the main class from a JAR's manifest file.
2009 *******************************************************************************/
2011 static char *vm_get_mainclass_from_jar(char *mainname)
2018 #if defined(ENABLE_JAVAME_CLDC1_1)
2019 c = load_class_bootstrap(utf_new_char("java/util/jar/JarFile"));
2021 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2025 exceptions_print_stacktrace();
2029 /* create JarFile object */
2034 exceptions_print_stacktrace();
2038 m = class_resolveclassmethod(c,
2040 utf_java_lang_String__void,
2041 class_java_lang_Object,
2045 exceptions_print_stacktrace();
2049 s = javastring_new_from_ascii(mainname);
2051 (void) vm_call_method(m, o, s);
2053 if (exceptions_get_exception()) {
2054 exceptions_print_stacktrace();
2058 /* get manifest object */
2060 m = class_resolveclassmethod(c,
2061 utf_new_char("getManifest"),
2062 utf_new_char("()Ljava/util/jar/Manifest;"),
2063 class_java_lang_Object,
2067 exceptions_print_stacktrace();
2071 o = vm_call_method(m, o);
2074 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2079 /* get Main Attributes */
2081 LLNI_class_get(o, c);
2083 m = class_resolveclassmethod(c,
2084 utf_new_char("getMainAttributes"),
2085 utf_new_char("()Ljava/util/jar/Attributes;"),
2086 class_java_lang_Object,
2090 exceptions_print_stacktrace();
2094 o = vm_call_method(m, o);
2097 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2102 /* get property Main-Class */
2104 LLNI_class_get(o, c);
2106 m = class_resolveclassmethod(c,
2107 utf_new_char("getValue"),
2108 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2109 class_java_lang_Object,
2113 exceptions_print_stacktrace();
2117 s = javastring_new_from_ascii("Main-Class");
2119 o = vm_call_method(m, o, s);
2122 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2123 fprintf(stderr, "%s\n", mainname);
2127 return javastring_tochar(o);
2131 /* vm_compile_all **************************************************************
2133 Compile all methods found in the bootclasspath.
2135 *******************************************************************************/
2137 #if !defined(NDEBUG)
2138 static void vm_compile_all(void)
2143 classcache_name_entry *nmen;
2144 classcache_class_entry *clsen;
2147 /* create all classes found in the bootclasspath */
2148 /* XXX currently only works with zip/jar's */
2150 loader_load_all_classes();
2152 /* link all classes */
2154 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2155 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2157 for (; nmen; nmen = nmen->hashlink) {
2158 /* iterate over all class entries */
2160 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2161 c = clsen->classobj;
2166 if (!(c->state & CLASS_LINKED)) {
2167 if (!link_class(c)) {
2168 fprintf(stderr, "Error linking: ");
2169 utf_fprint_printable_ascii_classname(stderr, c->name);
2170 fprintf(stderr, "\n");
2172 /* print out exception and cause */
2174 exceptions_print_current_exception();
2176 /* goto next class */
2182 /* compile all class methods */
2184 for (i = 0; i < c->methodscount; i++) {
2185 m = &(c->methods[i]);
2187 if (m->jcode != NULL) {
2188 if (!jit_compile(m)) {
2189 fprintf(stderr, "Error compiling: ");
2190 utf_fprint_printable_ascii_classname(stderr, c->name);
2191 fprintf(stderr, ".");
2192 utf_fprint_printable_ascii(stderr, m->name);
2193 utf_fprint_printable_ascii(stderr, m->descriptor);
2194 fprintf(stderr, "\n");
2196 /* print out exception and cause */
2198 exceptions_print_current_exception();
2206 #endif /* !defined(NDEBUG) */
2209 /* vm_compile_method ***********************************************************
2211 Compile a specific method.
2213 *******************************************************************************/
2215 #if !defined(NDEBUG)
2216 static void vm_compile_method(char* mainname)
2220 /* create, load and link the main class */
2222 mainclass = load_class_bootstrap(utf_new_char(mainname));
2224 if (mainclass == NULL)
2225 exceptions_print_stacktrace();
2227 if (!link_class(mainclass))
2228 exceptions_print_stacktrace();
2230 if (opt_CompileSignature != NULL) {
2231 m = class_resolveclassmethod(mainclass,
2232 utf_new_char(opt_CompileMethod),
2233 utf_new_char(opt_CompileSignature),
2238 m = class_resolveclassmethod(mainclass,
2239 utf_new_char(opt_CompileMethod),
2246 os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2247 opt_CompileMethod, opt_CompileSignature ? opt_CompileSignature : "");
2251 #endif /* !defined(NDEBUG) */
2254 /* vm_call_array ***************************************************************
2256 Calls a Java method with a variable number of arguments, passed via
2259 ATTENTION: This function has to be used outside the nativeworld.
2261 *******************************************************************************/
2263 #define VM_CALL_ARRAY(name, type) \
2264 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2270 assert(m->code != NULL); \
2272 md = m->parseddesc; \
2273 pv = m->code->entrypoint; \
2275 STATISTICS(count_calls_native_to_java++); \
2277 value = asm_vm_call_method##name(pv, array, md->memuse); \
2282 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2288 assert(m->code != NULL);
2291 pv = m->code->entrypoint;
2293 STATISTICS(count_calls_native_to_java++);
2295 o = asm_vm_call_method(pv, array, md->memuse);
2297 if (md->returntype.type == TYPE_VOID)
2300 return LLNI_WRAP(o);
2303 VM_CALL_ARRAY(_int, int32_t)
2304 VM_CALL_ARRAY(_long, int64_t)
2305 VM_CALL_ARRAY(_float, float)
2306 VM_CALL_ARRAY(_double, double)
2309 /* vm_call_method **************************************************************
2311 Calls a Java method with a variable number of arguments.
2313 *******************************************************************************/
2315 #define VM_CALL_METHOD(name, type) \
2316 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2322 value = vm_call_method##name##_valist(m, o, ap); \
2328 VM_CALL_METHOD(, java_handle_t *)
2329 VM_CALL_METHOD(_int, int32_t)
2330 VM_CALL_METHOD(_long, int64_t)
2331 VM_CALL_METHOD(_float, float)
2332 VM_CALL_METHOD(_double, double)
2335 /* vm_call_method_valist *******************************************************
2337 Calls a Java method with a variable number of arguments, passed via
2340 *******************************************************************************/
2342 #define VM_CALL_METHOD_VALIST(name, type) \
2343 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2349 if (m->code == NULL) \
2350 if (!jit_compile(m)) \
2353 THREAD_NATIVEWORLD_EXIT; \
2355 DumpMemoryArea dma; \
2357 array = argument_vmarray_from_valist(m, o, ap); \
2358 value = vm_call##name##_array(m, array); \
2360 THREAD_NATIVEWORLD_ENTER; \
2365 VM_CALL_METHOD_VALIST(, java_handle_t *)
2366 VM_CALL_METHOD_VALIST(_int, int32_t)
2367 VM_CALL_METHOD_VALIST(_long, int64_t)
2368 VM_CALL_METHOD_VALIST(_float, float)
2369 VM_CALL_METHOD_VALIST(_double, double)
2372 /* vm_call_method_jvalue *******************************************************
2374 Calls a Java method with a variable number of arguments, passed via
2377 *******************************************************************************/
2379 #define VM_CALL_METHOD_JVALUE(name, type) \
2380 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2381 const jvalue *args) \
2386 if (m->code == NULL) \
2387 if (!jit_compile(m)) \
2390 THREAD_NATIVEWORLD_EXIT; \
2392 DumpMemoryArea dma; \
2394 array = argument_vmarray_from_jvalue(m, o, args); \
2395 value = vm_call##name##_array(m, array); \
2397 THREAD_NATIVEWORLD_ENTER; \
2402 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2403 VM_CALL_METHOD_JVALUE(_int, int32_t)
2404 VM_CALL_METHOD_JVALUE(_long, int64_t)
2405 VM_CALL_METHOD_JVALUE(_float, float)
2406 VM_CALL_METHOD_JVALUE(_double, double)
2409 /* vm_call_method_objectarray **************************************************
2411 Calls a Java method with a variable number if arguments, passed via
2412 an objectarray of boxed values. Returns a boxed value.
2414 *******************************************************************************/
2416 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2417 java_handle_objectarray_t *params)
2420 java_handle_t *xptr;
2424 /* Prevent compiler warnings. */
2428 /* compile methods which are not yet compiled */
2430 if (m->code == NULL)
2431 if (!jit_compile(m))
2434 /* leave the nativeworld */
2436 THREAD_NATIVEWORLD_EXIT;
2438 // Create new dump memory area.
2441 /* Fill the argument array from a object-array. */
2443 array = argument_vmarray_from_objectarray(m, o, params);
2445 if (array == NULL) {
2446 /* enter the nativeworld again */
2448 THREAD_NATIVEWORLD_ENTER;
2450 exceptions_throw_illegalargumentexception();
2455 switch (m->parseddesc->returntype.primitivetype) {
2456 case PRIMITIVETYPE_VOID:
2457 value.a = vm_call_array(m, array);
2460 case PRIMITIVETYPE_BOOLEAN:
2461 case PRIMITIVETYPE_BYTE:
2462 case PRIMITIVETYPE_CHAR:
2463 case PRIMITIVETYPE_SHORT:
2464 case PRIMITIVETYPE_INT:
2465 value.i = vm_call_int_array(m, array);
2468 case PRIMITIVETYPE_LONG:
2469 value.l = vm_call_long_array(m, array);
2472 case PRIMITIVETYPE_FLOAT:
2473 value.f = vm_call_float_array(m, array);
2476 case PRIMITIVETYPE_DOUBLE:
2477 value.d = vm_call_double_array(m, array);
2481 ro = vm_call_array(m, array);
2485 os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2488 /* enter the nativeworld again */
2490 THREAD_NATIVEWORLD_ENTER;
2492 /* box the return value if necesarry */
2494 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2495 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2497 /* check for an exception */
2499 xptr = exceptions_get_exception();
2502 /* clear exception pointer, we are calling JIT code again */
2504 exceptions_clear_exception();
2506 exceptions_throw_invocationtargetexception(xptr);
2513 /* Legacy C interface *********************************************************/
2517 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2519 void vm_abort(const char* text, ...)
2523 log_println("vm_abort: WARNING, port me to C++ and use os::abort() instead.");
2525 // Print the log message.
2529 log_vprint(text, ap);
2534 // Print a backtrace.
2535 os::print_backtrace();
2537 // Now abort the VM.
2545 * These are local overrides for various environment variables in Emacs.
2546 * Please do not remove this and leave it at the end of the file, where
2547 * Emacs will automagically detect them.
2548 * ---------------------------------------------------------------------
2551 * indent-tabs-mode: t
2555 * vim:noexpandtab:sw=4:ts=4: