1 /* src/vm/vm.cpp - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008, 2009
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, 2009");
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 // Set the VM inittime.
1449 _inittime = builtin_currenttimemillis();
1451 // Print the run-time VM configuration after all stuff is set and
1452 // the VM is initialized.
1453 if (opt_PrintConfig)
1454 print_run_time_config();
1456 // Start runtime agents after the VM is created.
1457 if (!start_runtime_agents())
1458 os::abort("vm_create: start_runtime_agents failed");
1463 * Print build-time (default) VM configuration.
1465 void VM::print_build_time_config(void)
1467 puts("CACAO "VERSION" configure/build options:");
1469 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
1470 #if defined(__VERSION__)
1471 puts(" CC : "VERSION_CC" ("__VERSION__")");
1472 puts(" CXX : "VERSION_CXX" ("__VERSION__")");
1474 puts(" CC : "VERSION_CC"");
1475 puts(" CXX : "VERSION_CXX"");
1477 puts(" CFLAGS : "VERSION_CFLAGS"");
1478 puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
1482 puts("Build-time (default) variables:\n");
1483 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
1484 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
1485 printf(" stack size : %d\n", STACK_SIZE);
1487 #if defined(ENABLE_JRE_LAYOUT)
1488 // When we're building with JRE-layout, the default paths are the
1489 // same as the runtime paths.
1491 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1492 puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
1493 puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
1494 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1495 puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
1496 puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
1505 * Print run-time VM configuration.
1507 void VM::print_run_time_config()
1509 puts("Run-time variables:\n");
1510 printf(" maximum heap size : %d\n", opt_heapmaxsize);
1511 printf(" initial heap size : %d\n", opt_heapstartsize);
1512 printf(" stack size : %d\n", opt_stacksize);
1514 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1515 printf(" gnu.classpath.boot.library.path: %s\n", _properties.get("gnu.classpath.boot.library.path"));
1516 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1517 printf(" sun.boot.library.path : %s\n", _properties.get("sun.boot.library.path"));
1520 printf(" java.boot.class.path : %s\n", _properties.get("java.boot.class.path"));
1521 printf(" java.class.path : %s\n", _properties.get("java.class.path"));
1528 * Start runtime agents which are provided by the JRE but need to be
1529 * started explicitly by the VM.
1531 bool VM::start_runtime_agents()
1533 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1537 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1539 // Check whether the management agent should be loaded.
1540 if ((_properties.get("com.sun.management.jmxremote") != NULL) ||
1541 (_properties.get("com.sun.management.snmp") != NULL))
1544 // Load the management agent class.
1545 classinfo* class_sun_management_Agent;
1546 if (!(class_sun_management_Agent = load_class_from_sysloader(utf_new_char("sun/management/Agent"))))
1549 // Link the management agent class.
1550 if (!link_class(class_sun_management_Agent))
1553 // Actually start the management agent.
1554 methodinfo* m = class_resolveclassmethod(class_sun_management_Agent,
1555 utf_new_char("startAgent"),
1557 class_java_lang_Object,
1563 (void) vm_call_method(m, NULL);
1565 if (exceptions_get_exception() != NULL)
1569 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
1574 # error unknown classpath configuration
1581 /* vm_run **********************************************************************
1583 Runs the main-method of the passed class.
1585 *******************************************************************************/
1587 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1592 #if !defined(NDEBUG)
1593 if (opt_CompileAll) {
1599 /* Get the main class or jar file argument. */
1601 char* mainname = NULL;
1603 if (opt_index < vm_args->nOptions) {
1604 /* Get main-class argument. */
1606 mainname = vm_args->options[opt_index].optionString;
1608 /* If the main class argument is a jar file, put it into the
1611 if (opt_jar == true) {
1612 char* p = MNEW(char, strlen(mainname) + strlen("0"));
1614 strcpy(p, mainname);
1616 #if defined(ENABLE_JAVASE)
1617 VM::get_current()->get_properties().put("java.class.path", p);
1621 /* Replace dots with slashes in the class name. */
1623 for (unsigned int i = 0; i < strlen(mainname); i++)
1624 if (mainname[i] == '.')
1628 /* Move index to first argument. */
1633 /* Do we have a main-class argument? */
1635 if (mainname == NULL)
1638 #if !defined(NDEBUG)
1639 if (opt_CompileMethod != NULL) {
1640 vm_compile_method(mainname);
1645 /* Build argument array. */
1647 int32_t oalength = vm_args->nOptions - opt_index;
1649 ObjectArray oa(oalength, class_java_lang_String);
1654 for (int i = 0; i < oalength; i++) {
1655 char* option = vm_args->options[opt_index + i].optionString;
1657 utf* u = utf_new_char(option);
1658 java_handle_t* s = javastring_new(u);
1660 oa.set_element(i, s);
1663 /* set return value to OK */
1667 if (opt_jar == true) {
1668 /* open jar file with java.util.jar.JarFile */
1670 mainname = vm_get_mainclass_from_jar(mainname);
1672 if (mainname == NULL)
1676 /* load the main class */
1678 utf* mainutf = utf_new_char(mainname);
1680 #if defined(ENABLE_JAVAME_CLDC1_1)
1681 classinfo* mainclass = load_class_bootstrap(mainutf);
1683 classinfo* mainclass = load_class_from_sysloader(mainutf);
1686 /* error loading class */
1688 java_handle_t* e = exceptions_get_and_clear_exception();
1690 if ((e != NULL) || (mainclass == NULL)) {
1691 exceptions_throw_noclassdeffounderror_cause(e);
1692 exceptions_print_stacktrace();
1696 if (!link_class(mainclass)) {
1697 exceptions_print_stacktrace();
1701 /* find the `main' method of the main class */
1703 m = class_resolveclassmethod(mainclass,
1704 utf_new_char("main"),
1705 utf_new_char("([Ljava/lang/String;)V"),
1706 class_java_lang_Object,
1709 if (exceptions_get_exception()) {
1710 exceptions_print_stacktrace();
1714 /* there is no main method or it isn't static */
1716 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1717 exceptions_clear_exception();
1718 exceptions_throw_nosuchmethoderror(mainclass,
1719 utf_new_char("main"),
1720 utf_new_char("([Ljava/lang/String;)V"));
1722 exceptions_print_stacktrace();
1726 #ifdef TYPEINFO_DEBUG_TEST
1727 /* test the typeinfo system */
1731 /* start the main thread */
1733 (void) vm_call_method(m, NULL, oa.get_handle());
1735 /* exception occurred? */
1737 if (exceptions_get_exception()) {
1738 exceptions_print_stacktrace();
1742 #if defined(ENABLE_THREADS)
1743 /* Detach the main thread so that it appears to have ended when
1744 the application's main method exits. */
1746 if (!thread_detach_current_thread())
1747 os::abort("vm_run: Could not detach main thread.");
1750 /* Destroy the JavaVM. */
1752 (void) vm_destroy(vm);
1760 /* vm_destroy ******************************************************************
1762 Unloads a Java VM and reclaims its resources.
1764 *******************************************************************************/
1766 int vm_destroy(JavaVM *vm)
1768 #if defined(ENABLE_THREADS)
1769 /* Create a a trivial new Java waiter thread called
1772 JavaVMAttachArgs args;
1774 args.name = (char*) "DestroyJavaVM";
1777 if (!thread_attach_current_thread(&args, false))
1780 /* Wait until we are the last non-daemon thread. */
1782 threads_join_all_threads();
1787 // _created = false;
1788 #warning Move to C++
1790 /* Everything is ok. */
1796 /* vm_exit *********************************************************************
1798 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1800 *******************************************************************************/
1802 void vm_exit(s4 status)
1806 /* signal that we are exiting */
1809 #warning Move to C++
1811 assert(class_java_lang_System);
1812 assert(class_java_lang_System->state & CLASS_LOADED);
1814 #if defined(ENABLE_JVMTI)
1815 if (jvmti || (dbgcom!=NULL)) {
1816 jvmti_set_phase(JVMTI_PHASE_DEAD);
1817 if (jvmti) jvmti_agentunload();
1821 if (!link_class(class_java_lang_System)) {
1822 exceptions_print_stacktrace();
1826 /* call java.lang.System.exit(I)V */
1828 m = class_resolveclassmethod(class_java_lang_System,
1829 utf_new_char("exit"),
1831 class_java_lang_Object,
1835 exceptions_print_stacktrace();
1839 /* call the exit function with passed exit status */
1841 (void) vm_call_method(m, NULL, status);
1843 /* If we had an exception, just ignore the exception and exit with
1846 vm_shutdown(status);
1850 /* vm_shutdown *****************************************************************
1852 Terminates the system immediately without freeing memory explicitly
1853 (to be used only for abnormal termination).
1855 *******************************************************************************/
1857 void vm_shutdown(s4 status)
1860 #if defined(ENABLE_STATISTICS)
1861 || opt_getcompilingtime || opt_stat
1865 log_text("CACAO terminated by shutdown");
1866 dolog("Exit status: %d\n", (s4) status);
1870 #if defined(ENABLE_JVMTI)
1871 /* terminate cacaodbgserver */
1873 mutex_lock(&dbgcomlock);
1875 mutex_unlock(&dbgcomlock);
1876 jvmti_cacaodbgserver_quit();
1884 /* vm_exit_handler *************************************************************
1886 The exit_handler function is called upon program termination.
1888 ATTENTION: Don't free system resources here! Some threads may still
1889 be running as this is called from VMRuntime.exit(). The OS does the
1892 *******************************************************************************/
1894 void vm_exit_handler(void)
1896 #if !defined(NDEBUG)
1898 class_showmethods(mainclass);
1900 if (showconstantpool)
1901 class_showconstantpool(mainclass);
1906 # if defined(ENABLE_PROFILING)
1908 profile_printstats();
1910 #endif /* !defined(NDEBUG) */
1912 #if defined(ENABLE_RT_TIMING)
1913 rt_timing_print_time_stats(stderr);
1916 #if defined(ENABLE_CYCLES_STATS)
1917 builtin_print_cycles_stats(stderr);
1918 stacktrace_print_cycles_stats(stderr);
1922 #if defined(ENABLE_STATISTICS)
1923 || opt_getcompilingtime || opt_stat
1927 log_text("CACAO terminated");
1929 #if defined(ENABLE_STATISTICS)
1932 #ifdef TYPECHECK_STATISTICS
1933 typecheck_print_statistics(get_logfile());
1937 if (opt_getcompilingtime)
1939 #endif /* defined(ENABLE_STATISTICS) */
1941 /* vm_print_profile(stderr);*/
1945 /* vm_abort_disassemble ********************************************************
1947 Prints an error message, disassemble the given code range (if
1948 enabled) and aborts the VM.
1951 pc.......PC to disassemble
1952 count....number of instructions to disassemble
1954 *******************************************************************************/
1956 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
1959 #if defined(ENABLE_DISASSEMBLER)
1963 /* Print debug message. */
1968 log_vprint(text, ap);
1975 #if SIZEOF_VOID_P == 8
1976 log_println("PC=0x%016lx", pc);
1978 log_println("PC=0x%08x", pc);
1981 #if defined(ENABLE_DISASSEMBLER)
1982 log_println("machine instructions at PC:");
1984 /* Disassemble the given number of instructions. */
1986 for (i = 0; i < count; i++)
1987 // FIXME disassinstr should use void*.
1988 pc = disassinstr((u1*) pc);
1991 os::abort("Aborting...");
1995 /* vm_get_mainclass_from_jar ***************************************************
1997 Gets the name of the main class from a JAR's manifest file.
1999 *******************************************************************************/
2001 static char *vm_get_mainclass_from_jar(char *mainname)
2008 #if defined(ENABLE_JAVAME_CLDC1_1)
2009 c = load_class_bootstrap(utf_new_char("java/util/jar/JarFile"));
2011 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2015 exceptions_print_stacktrace();
2019 /* create JarFile object */
2024 exceptions_print_stacktrace();
2028 m = class_resolveclassmethod(c,
2030 utf_java_lang_String__void,
2031 class_java_lang_Object,
2035 exceptions_print_stacktrace();
2039 s = javastring_new_from_ascii(mainname);
2041 (void) vm_call_method(m, o, s);
2043 if (exceptions_get_exception()) {
2044 exceptions_print_stacktrace();
2048 /* get manifest object */
2050 m = class_resolveclassmethod(c,
2051 utf_new_char("getManifest"),
2052 utf_new_char("()Ljava/util/jar/Manifest;"),
2053 class_java_lang_Object,
2057 exceptions_print_stacktrace();
2061 o = vm_call_method(m, o);
2064 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
2069 /* get Main Attributes */
2071 LLNI_class_get(o, c);
2073 m = class_resolveclassmethod(c,
2074 utf_new_char("getMainAttributes"),
2075 utf_new_char("()Ljava/util/jar/Attributes;"),
2076 class_java_lang_Object,
2080 exceptions_print_stacktrace();
2084 o = vm_call_method(m, o);
2087 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
2092 /* get property Main-Class */
2094 LLNI_class_get(o, c);
2096 m = class_resolveclassmethod(c,
2097 utf_new_char("getValue"),
2098 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2099 class_java_lang_Object,
2103 exceptions_print_stacktrace();
2107 s = javastring_new_from_ascii("Main-Class");
2109 o = vm_call_method(m, o, s);
2112 fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
2113 fprintf(stderr, "%s\n", mainname);
2117 return javastring_tochar(o);
2121 /* vm_compile_all **************************************************************
2123 Compile all methods found in the bootclasspath.
2125 *******************************************************************************/
2127 #if !defined(NDEBUG)
2128 static void vm_compile_all(void)
2133 classcache_name_entry *nmen;
2134 classcache_class_entry *clsen;
2137 /* create all classes found in the bootclasspath */
2138 /* XXX currently only works with zip/jar's */
2140 loader_load_all_classes();
2142 /* link all classes */
2144 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2145 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2147 for (; nmen; nmen = nmen->hashlink) {
2148 /* iterate over all class entries */
2150 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2151 c = clsen->classobj;
2156 if (!(c->state & CLASS_LINKED)) {
2157 if (!link_class(c)) {
2158 fprintf(stderr, "Error linking: ");
2159 utf_fprint_printable_ascii_classname(stderr, c->name);
2160 fprintf(stderr, "\n");
2162 /* print out exception and cause */
2164 exceptions_print_current_exception();
2166 /* goto next class */
2172 /* compile all class methods */
2174 for (i = 0; i < c->methodscount; i++) {
2175 m = &(c->methods[i]);
2177 if (m->jcode != NULL) {
2178 if (!jit_compile(m)) {
2179 fprintf(stderr, "Error compiling: ");
2180 utf_fprint_printable_ascii_classname(stderr, c->name);
2181 fprintf(stderr, ".");
2182 utf_fprint_printable_ascii(stderr, m->name);
2183 utf_fprint_printable_ascii(stderr, m->descriptor);
2184 fprintf(stderr, "\n");
2186 /* print out exception and cause */
2188 exceptions_print_current_exception();
2196 #endif /* !defined(NDEBUG) */
2199 /* vm_compile_method ***********************************************************
2201 Compile a specific method.
2203 *******************************************************************************/
2205 #if !defined(NDEBUG)
2206 static void vm_compile_method(char* mainname)
2210 /* create, load and link the main class */
2212 mainclass = load_class_bootstrap(utf_new_char(mainname));
2214 if (mainclass == NULL)
2215 exceptions_print_stacktrace();
2217 if (!link_class(mainclass))
2218 exceptions_print_stacktrace();
2220 if (opt_CompileSignature != NULL) {
2221 m = class_resolveclassmethod(mainclass,
2222 utf_new_char(opt_CompileMethod),
2223 utf_new_char(opt_CompileSignature),
2228 m = class_resolveclassmethod(mainclass,
2229 utf_new_char(opt_CompileMethod),
2236 os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2237 opt_CompileMethod, opt_CompileSignature ? opt_CompileSignature : "");
2241 #endif /* !defined(NDEBUG) */
2244 /* vm_call_array ***************************************************************
2246 Calls a Java method with a variable number of arguments, passed via
2249 ATTENTION: This function has to be used outside the nativeworld.
2251 *******************************************************************************/
2253 #define VM_CALL_ARRAY(name, type) \
2254 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2260 assert(m->code != NULL); \
2262 md = m->parseddesc; \
2263 pv = m->code->entrypoint; \
2265 STATISTICS(count_calls_native_to_java++); \
2267 value = asm_vm_call_method##name(pv, array, md->memuse); \
2272 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2278 assert(m->code != NULL);
2281 pv = m->code->entrypoint;
2283 STATISTICS(count_calls_native_to_java++);
2285 o = asm_vm_call_method(pv, array, md->memuse);
2287 if (md->returntype.type == TYPE_VOID)
2290 return LLNI_WRAP(o);
2293 VM_CALL_ARRAY(_int, int32_t)
2294 VM_CALL_ARRAY(_long, int64_t)
2295 VM_CALL_ARRAY(_float, float)
2296 VM_CALL_ARRAY(_double, double)
2299 /* vm_call_method **************************************************************
2301 Calls a Java method with a variable number of arguments.
2303 *******************************************************************************/
2305 #define VM_CALL_METHOD(name, type) \
2306 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2312 value = vm_call_method##name##_valist(m, o, ap); \
2318 VM_CALL_METHOD(, java_handle_t *)
2319 VM_CALL_METHOD(_int, int32_t)
2320 VM_CALL_METHOD(_long, int64_t)
2321 VM_CALL_METHOD(_float, float)
2322 VM_CALL_METHOD(_double, double)
2325 /* vm_call_method_valist *******************************************************
2327 Calls a Java method with a variable number of arguments, passed via
2330 *******************************************************************************/
2332 #define VM_CALL_METHOD_VALIST(name, type) \
2333 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2339 if (m->code == NULL) \
2340 if (!jit_compile(m)) \
2343 THREAD_NATIVEWORLD_EXIT; \
2345 DumpMemoryArea dma; \
2347 array = argument_vmarray_from_valist(m, o, ap); \
2348 value = vm_call##name##_array(m, array); \
2350 THREAD_NATIVEWORLD_ENTER; \
2355 VM_CALL_METHOD_VALIST(, java_handle_t *)
2356 VM_CALL_METHOD_VALIST(_int, int32_t)
2357 VM_CALL_METHOD_VALIST(_long, int64_t)
2358 VM_CALL_METHOD_VALIST(_float, float)
2359 VM_CALL_METHOD_VALIST(_double, double)
2362 /* vm_call_method_jvalue *******************************************************
2364 Calls a Java method with a variable number of arguments, passed via
2367 *******************************************************************************/
2369 #define VM_CALL_METHOD_JVALUE(name, type) \
2370 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2371 const jvalue *args) \
2376 if (m->code == NULL) \
2377 if (!jit_compile(m)) \
2380 THREAD_NATIVEWORLD_EXIT; \
2382 DumpMemoryArea dma; \
2384 array = argument_vmarray_from_jvalue(m, o, args); \
2385 value = vm_call##name##_array(m, array); \
2387 THREAD_NATIVEWORLD_ENTER; \
2392 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2393 VM_CALL_METHOD_JVALUE(_int, int32_t)
2394 VM_CALL_METHOD_JVALUE(_long, int64_t)
2395 VM_CALL_METHOD_JVALUE(_float, float)
2396 VM_CALL_METHOD_JVALUE(_double, double)
2399 /* vm_call_method_objectarray **************************************************
2401 Calls a Java method with a variable number if arguments, passed via
2402 an objectarray of boxed values. Returns a boxed value.
2404 *******************************************************************************/
2406 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2407 java_handle_objectarray_t *params)
2410 java_handle_t *xptr;
2414 /* Prevent compiler warnings. */
2418 /* compile methods which are not yet compiled */
2420 if (m->code == NULL)
2421 if (!jit_compile(m))
2424 /* leave the nativeworld */
2426 THREAD_NATIVEWORLD_EXIT;
2428 // Create new dump memory area.
2431 /* Fill the argument array from a object-array. */
2433 array = argument_vmarray_from_objectarray(m, o, params);
2435 if (array == NULL) {
2436 /* enter the nativeworld again */
2438 THREAD_NATIVEWORLD_ENTER;
2440 exceptions_throw_illegalargumentexception();
2445 switch (m->parseddesc->returntype.primitivetype) {
2446 case PRIMITIVETYPE_VOID:
2447 value.a = vm_call_array(m, array);
2450 case PRIMITIVETYPE_BOOLEAN:
2451 case PRIMITIVETYPE_BYTE:
2452 case PRIMITIVETYPE_CHAR:
2453 case PRIMITIVETYPE_SHORT:
2454 case PRIMITIVETYPE_INT:
2455 value.i = vm_call_int_array(m, array);
2458 case PRIMITIVETYPE_LONG:
2459 value.l = vm_call_long_array(m, array);
2462 case PRIMITIVETYPE_FLOAT:
2463 value.f = vm_call_float_array(m, array);
2466 case PRIMITIVETYPE_DOUBLE:
2467 value.d = vm_call_double_array(m, array);
2471 ro = vm_call_array(m, array);
2475 os::abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
2478 /* enter the nativeworld again */
2480 THREAD_NATIVEWORLD_ENTER;
2482 /* box the return value if necesarry */
2484 if (m->parseddesc->returntype.primitivetype != TYPE_ADR)
2485 ro = Primitive::box(m->parseddesc->returntype.primitivetype, value);
2487 /* check for an exception */
2489 xptr = exceptions_get_exception();
2492 /* clear exception pointer, we are calling JIT code again */
2494 exceptions_clear_exception();
2496 exceptions_throw_invocationtargetexception(xptr);
2503 /* Legacy C interface *********************************************************/
2507 JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
2508 JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
2509 bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
2510 bool VM_is_created() { return VM::get_current()->is_created(); }
2511 int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
2513 void vm_abort(const char* text, ...)
2517 log_println("vm_abort: WARNING, port me to C++ and use os::abort() instead.");
2519 // Print the log message.
2523 log_vprint(text, ap);
2528 // Print a backtrace.
2529 os::print_backtrace();
2531 // Now abort the VM.
2539 * These are local overrides for various environment variables in Emacs.
2540 * Please do not remove this and leave it at the end of the file, where
2541 * Emacs will automagically detect them.
2542 * ---------------------------------------------------------------------
2545 * indent-tabs-mode: t
2549 * vim:noexpandtab:sw=4:ts=4: