1 /* src/vm/vm.c - VM startup and shutdown functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
40 #include "vm/jit/abi-asm.h"
42 #include "mm/gc-common.h"
43 #include "mm/memory.h"
45 #include "native/jni.h"
46 #include "native/llni.h"
47 #include "native/native.h"
49 #include "native/include/java_lang_Object.h" /* required by j.l.C */
50 #include "native/include/java_lang_String.h" /* required by j.l.C */
52 #if defined(WITH_CLASSPATH_SUN)
53 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
54 # include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
57 #include "native/include/java_lang_Class.h"
59 #include "native/vm/nativevm.h"
61 #include "threads/threads-common.h"
63 #include "toolbox/logging.h"
65 #include "vm/builtin.h"
66 #include "vm/exceptions.h"
67 #include "vm/finalizer.h"
68 #include "vm/global.h"
69 #include "vm/initialize.h"
70 #include "vm/package.h"
71 #include "vm/primitive.h"
72 #include "vm/properties.h"
73 #include "vm/signallocal.h"
74 #include "vm/stringlocal.h"
77 #include "vm/jit/argument.h"
78 #include "vm/jit/asmpart.h"
80 #if defined(ENABLE_DISASSEMBLER)
81 # include "vm/jit/disass.h"
84 #include "vm/jit/jit.h"
85 #include "vm/jit/md.h"
87 #if defined(ENABLE_PROFILING)
88 # include "vm/jit/optimizing/profile.h"
91 #include "vm/jit/optimizing/recompile.h"
93 #include "vmcore/classcache.h"
94 #include "vmcore/options.h"
95 #include "vmcore/statistics.h"
96 #include "vmcore/suck.h"
98 #if defined(ENABLE_JVMTI)
99 # include "native/jvmti/cacaodbg.h"
102 #if defined(ENABLE_VMLOG)
103 #include <vmlog_cacao.h>
107 /* Invocation API variables ***************************************************/
109 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
110 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
113 /* global variables ***********************************************************/
115 s4 vms = 0; /* number of VMs created */
117 bool vm_initializing = false;
118 bool vm_exiting = false;
120 char *mainstring = NULL;
121 classinfo *mainclass = NULL;
123 #if defined(ENABLE_INTRP)
124 u1 *intrp_main_stack = NULL;
128 /* define heap sizes **********************************************************/
130 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
131 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
132 #define STACK_SIZE 128 * 1024 /* default 64kB */
135 /* define command line options ************************************************/
166 /* Java non-standard options */
177 #if defined(ENABLE_PROFILING)
190 #if defined(ENABLE_STATISTICS)
207 #if defined(ENABLE_VERIFIER)
209 #if defined(TYPECHECK_VERBOSE)
212 #endif /* defined(ENABLE_VERIFIER) */
214 /* optimization options */
216 #if defined(ENABLE_LOOP)
220 #if defined(ENABLE_IFCONV)
224 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
228 #if defined(ENABLE_INLINING)
233 #if defined(ENABLE_INLINING_DEBUG)
234 OPT_INLINE_DEBUG_ALL,
235 OPT_INLINE_DEBUG_END,
236 OPT_INLINE_DEBUG_MIN,
237 OPT_INLINE_DEBUG_MAX,
238 #endif /* defined(ENABLE_INLINING_DEBUG) */
239 #endif /* defined(ENABLE_INLINING) */
241 #if defined(ENABLE_INTRP)
242 /* interpreter options */
261 #if defined(ENABLE_DEBUG_FILTER)
262 OPT_FILTER_VERBOSECALL_INCLUDE,
263 OPT_FILTER_VERBOSECALL_EXCLUDE,
264 OPT_FILTER_SHOW_METHOD,
271 opt_struct opts[] = {
272 { "foo", false, OPT_FOO },
276 { "jar", false, OPT_JAR },
278 { "d32", false, OPT_D32 },
279 { "d64", false, OPT_D64 },
280 { "client", false, OPT_IGNORE },
281 { "server", false, OPT_IGNORE },
282 { "jvm", false, OPT_IGNORE },
283 { "hotspot", false, OPT_IGNORE },
285 { "classpath", true, OPT_CLASSPATH },
286 { "cp", true, OPT_CLASSPATH },
287 { "D", true, OPT_D },
288 { "version", false, OPT_VERSION },
289 { "showversion", false, OPT_SHOWVERSION },
290 { "fullversion", false, OPT_FULLVERSION },
291 { "help", false, OPT_HELP },
292 { "?", false, OPT_HELP },
293 { "X", false, OPT_X },
294 { "XX:", true, OPT_XX },
296 { "ea:", true, OPT_EA },
297 { "da:", true, OPT_DA },
298 { "ea", false, OPT_EA },
299 { "da", false, OPT_DA },
301 { "esa", false, OPT_ESA },
302 { "enablesystemassertions", false, OPT_ESA },
303 { "dsa", false, OPT_DSA },
304 { "disablesystemassertions", false, OPT_DSA },
306 { "noasyncgc", false, OPT_IGNORE },
307 #if defined(ENABLE_VERIFIER)
308 { "noverify", false, OPT_NOVERIFY },
309 { "Xverify:none", false, OPT_NOVERIFY },
311 { "v", false, OPT_VERBOSE1 },
312 { "verbose:", true, OPT_VERBOSE },
314 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
315 { "verbosetc", false, OPT_VERBOSETC },
317 #if defined(__ALPHA__)
318 { "noieee", false, OPT_NOIEEE },
320 #if defined(ENABLE_STATISTICS)
321 { "time", false, OPT_TIME },
322 { "stat", false, OPT_STAT },
324 { "log", true, OPT_LOG },
325 { "c", true, OPT_CHECK },
326 { "l", false, OPT_LOAD },
329 { "all", false, OPT_ALL },
330 { "sig", true, OPT_SIGNATURE },
333 #if defined(ENABLE_LOOP)
334 { "oloop", false, OPT_OLOOP },
336 #if defined(ENABLE_IFCONV)
337 { "ifconv", false, OPT_IFCONV },
339 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
340 { "lsra", false, OPT_LSRA },
343 #if defined(ENABLE_INTRP)
344 /* interpreter options */
346 { "trace", false, OPT_TRACE },
347 { "static-supers", true, OPT_STATIC_SUPERS },
348 { "no-dynamic", false, OPT_NO_DYNAMIC },
349 { "no-replication", false, OPT_NO_REPLICATION },
350 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
353 /* JVMTI Agent Command Line Options */
355 { "agentlib:", true, OPT_AGENTLIB },
356 { "agentpath:", true, OPT_AGENTPATH },
359 /* Java non-standard options */
361 { "Xjit", false, OPT_JIT },
362 { "Xint", false, OPT_INTRP },
363 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
364 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
365 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
366 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
369 { "Xdebug", false, OPT_DEBUG },
370 { "Xnoagent", false, OPT_NOAGENT },
371 { "Xrunjdwp", true, OPT_XRUNJDWP },
374 { "Xms", true, OPT_MS },
375 { "ms", true, OPT_MS },
376 { "Xmx", true, OPT_MX },
377 { "mx", true, OPT_MX },
378 { "Xss", true, OPT_SS },
379 { "ss", true, OPT_SS },
381 #if defined(ENABLE_PROFILING)
382 { "Xprof:", true, OPT_PROF_OPTION },
383 { "Xprof", false, OPT_PROF },
386 /* inlining options */
388 #if defined(ENABLE_INLINING)
389 #if defined(ENABLE_INLINING_DEBUG)
390 { "ia", false, OPT_INLINE_DEBUG_ALL },
391 { "ii", true, OPT_INLINE_DEBUG_MIN },
392 { "im", true, OPT_INLINE_DEBUG_MAX },
393 { "ie", true, OPT_INLINE_DEBUG_END },
394 #endif /* defined(ENABLE_INLINING_DEBUG) */
396 { "il", false, OPT_INLINE_LOG },
398 { "i", false, OPT_INLINING },
399 #endif /* defined(ENABLE_INLINING) */
401 /* keep these at the end of the list */
404 { "m", true, OPT_METHOD },
407 { "s", true, OPT_SHOW },
408 { "debug-color", false, OPT_DEBUGCOLOR },
410 #if defined(ENABLE_DEBUG_FILTER)
411 { "XXfi", true, OPT_FILTER_VERBOSECALL_INCLUDE },
412 { "XXfx", true, OPT_FILTER_VERBOSECALL_EXCLUDE },
413 { "XXfm", true, OPT_FILTER_SHOW_METHOD },
420 /* usage ***********************************************************************
422 Prints the correct usage syntax to stdout.
424 *******************************************************************************/
428 puts("Usage: cacao [-options] classname [arguments]");
429 puts(" (to run a class file)");
430 puts(" or cacao [-options] -jar jarfile [arguments]");
431 puts(" (to run a standalone jar file)\n");
433 puts("where options include:");
434 puts(" -d32 use 32-bit data model if available");
435 puts(" -d64 use 64-bit data model if available");
436 puts(" -client compatibility (currently ignored)");
437 puts(" -server compatibility (currently ignored)");
438 puts(" -jvm compatibility (currently ignored)");
439 puts(" -hotspot compatibility (currently ignored)\n");
441 puts(" -cp <path> specify a path to look for classes");
442 puts(" -classpath <path> specify a path to look for classes");
443 puts(" -D<name>=<value> add an entry to the property list");
444 puts(" -verbose[:class|gc|jni] enable specific verbose output");
445 puts(" -version print product version and exit");
446 puts(" -fullversion print jpackage-compatible product version and exit");
447 puts(" -showversion print product version and continue");
448 puts(" -help, -? print this help message");
449 puts(" -X print help on non-standard Java options");
450 puts(" -XX print help on debugging options");
451 puts(" -ea[:<packagename>...|:<classname>]");
452 puts(" -enableassertions[:<packagename>...|:<classname>]");
453 puts(" enable assertions with specified granularity");
454 puts(" -da[:<packagename>...|:<classname>]");
455 puts(" -disableassertions[:<packagename>...|:<classname>]");
456 puts(" disable assertions with specified granularity");
457 puts(" -esa | -enablesystemassertions");
458 puts(" enable system assertions");
459 puts(" -dsa | -disablesystemassertions");
460 puts(" disable system assertions");
463 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
464 puts (" for jdwp help use: -agentlib:jdwp=help");
465 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
468 /* exit with error code */
474 static void Xusage(void)
476 #if defined(ENABLE_JIT)
477 puts(" -Xjit JIT mode execution (default)");
479 #if defined(ENABLE_INTRP)
480 puts(" -Xint interpreter mode execution");
482 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
483 puts(" value is set as bootstrap class path");
484 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
485 puts(" value is appended to the bootstrap class path");
486 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
487 puts(" value is prepended to the bootstrap class path");
488 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
489 puts(" value is used as Java core library, but the");
490 puts(" hardcoded VM interface classes are prepended");
491 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
492 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
493 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
495 #if defined(ENABLE_PROFILING)
496 puts(" -Xprof[:bb] collect and print profiling data");
499 #if defined(ENABLE_JVMTI)
500 /* -Xdebug option depend on gnu classpath JDWP options. options:
501 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
502 puts(" -Xdebug enable remote debugging\n");
503 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
504 puts(" enable remote debugging\n");
507 /* exit with error code */
514 static void XXusage(void)
516 puts(" -v write state-information");
518 puts(" -verbose:jit enable specific verbose output");
519 puts(" -debug-color colored output for ANSI terms");
521 #ifdef TYPECHECK_VERBOSE
522 puts(" -verbosetc write debug messages while typechecking");
524 #if defined(__ALPHA__)
525 puts(" -noieee don't use ieee compliant arithmetic");
527 #if defined(ENABLE_VERIFIER)
528 puts(" -noverify don't verify classfiles");
530 #if defined(ENABLE_STATISTICS)
531 puts(" -time measure the runtime");
532 puts(" -stat detailed compiler statistics");
534 puts(" -log logfile specify a name for the logfile");
535 puts(" -c(heck)b(ounds) don't check array bounds");
536 puts(" s(ync) don't check for synchronization");
537 #if defined(ENABLE_LOOP)
538 puts(" -oloop optimize array accesses in loops");
540 puts(" -l don't start the class after loading");
542 puts(" -all compile all methods, no execution");
543 puts(" -m compile only a specific method");
544 puts(" -sig specify signature for a specific method");
547 puts(" -s... show...");
548 puts(" (c)onstants the constant pool");
549 puts(" (m)ethods class fields and methods");
550 puts(" (u)tf the utf - hash");
551 puts(" (i)ntermediate intermediate representation");
552 #if defined(ENABLE_DISASSEMBLER)
553 puts(" (a)ssembler disassembled listing");
554 puts(" n(o)ps show NOPs in disassembler output");
556 puts(" (d)atasegment data segment listing");
558 #if defined(ENABLE_INLINING)
559 puts(" -i activate inlining");
561 puts(" -il log inlining");
563 #if defined(ENABLE_INLINING_DEBUG)
564 puts(" -ia use inlining for all methods");
565 puts(" -ii <size> set minimum size for inlined result");
566 puts(" -im <size> set maximum size for inlined result");
567 puts(" -ie <number> stop inlining after the given number of roots");
568 #endif /* defined(ENABLE_INLINING_DEBUG) */
569 #endif /* defined(ENABLE_INLINING) */
571 #if defined(ENABLE_IFCONV)
572 puts(" -ifconv use if-conversion");
574 #if defined(ENABLE_LSRA)
575 puts(" -lsra use linear scan register allocation");
577 #if defined(ENABLE_SSA)
578 puts(" -lsra use linear scan register allocation (with SSA)");
580 #if defined(ENABLE_DEBUG_FILTER)
581 puts(" -XXfi <regex> begin of dynamic scope for verbosecall filter");
582 puts(" -XXfx <regex> end of dynamic scope for verbosecall filter");
583 puts(" -XXfm <regex> filter for show options");
585 /* exit with error code */
592 /* version *********************************************************************
594 Only prints cacao version information.
596 *******************************************************************************/
598 static void version(bool opt_exit)
600 puts("java version \""JAVA_VERSION"\"");
601 puts("CACAO version "VERSION"");
603 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
604 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
605 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
606 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
608 puts("This program is free software; you can redistribute it and/or");
609 puts("modify it under the terms of the GNU General Public License as");
610 puts("published by the Free Software Foundation; either version 2, or (at");
611 puts("your option) any later version.\n");
613 puts("This program is distributed in the hope that it will be useful, but");
614 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
615 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
616 puts("General Public License for more details.");
618 /* exit normally, if requested */
625 /* fullversion *****************************************************************
627 Prints a Sun compatible version information (required e.g. by
628 jpackage, www.jpackage.org).
630 *******************************************************************************/
632 static void fullversion(void)
634 puts("java full version \"cacao-"JAVA_VERSION"\"");
642 static void vm_printconfig(void)
644 puts("Configure/Build options:\n");
645 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
646 #if defined(__VERSION__)
647 puts(" CC : "VERSION_CC" ("__VERSION__")");
649 puts(" CC : "VERSION_CC"");
651 puts(" CFLAGS : "VERSION_CFLAGS"\n");
653 puts("Default variables:\n");
654 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
655 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
656 printf(" stack size : %d\n", STACK_SIZE);
658 #if defined(WITH_JRE_LAYOUT)
659 /* When we're building with JRE-layout, the default paths are the
660 same as the runtime paths. */
662 # if defined(WITH_CLASSPATH_GNU)
663 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
664 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
665 # elif defined(WITH_CLASSPATH_SUN)
666 puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
667 puts(" java.boot.class.path : "CLASSPATH_CLASSES);
673 puts("Runtime variables:\n");
674 printf(" maximum heap size : %d\n", opt_heapmaxsize);
675 printf(" initial heap size : %d\n", opt_heapstartsize);
676 printf(" stack size : %d\n", opt_stacksize);
678 #if defined(WITH_CLASSPATH_GNU)
679 printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
680 #elif defined(WITH_CLASSPATH_SUN)
681 printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
684 printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
685 printf(" java.class.path : %s\n", properties_get("java.class.path"));
689 /* forward declarations *******************************************************/
691 static char *vm_get_mainclass_from_jar(char *mainstring);
693 static void vm_compile_all(void);
694 static void vm_compile_method(void);
698 /* vm_createjvm ****************************************************************
700 Implementation for JNI_CreateJavaVM.
702 *******************************************************************************/
704 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
706 JavaVMInitArgs *_vm_args;
710 /* get the arguments for the new JVM */
712 _vm_args = (JavaVMInitArgs *) vm_args;
714 /* get the VM and Env tables (must be set before vm_create) */
716 env = NEW(_Jv_JNIEnv);
718 #if defined(ENABLE_JNI)
719 env->env = &_Jv_JNINativeInterface;
722 /* XXX Set the global variable. Maybe we should do that differently. */
726 /* create and fill a JavaVM structure */
728 vm = NEW(_Jv_JavaVM);
730 #if defined(ENABLE_JNI)
731 vm->functions = &_Jv_JNIInvokeInterface;
734 /* XXX Set the global variable. Maybe we should do that differently. */
735 /* XXX JVMTI Agents needs a JavaVM */
739 /* actually create the JVM */
741 if (!vm_create(_vm_args))
744 #if defined(ENABLE_JNI)
745 /* setup the local ref table (must be created after vm_create) */
747 /* XXX this one will never get freed for the main thread;
748 call localref_table_destroy() if you want to do it! */
750 if (!localref_table_init())
754 /* now return the values */
756 *p_vm = (JavaVM *) vm;
757 *p_env = (void *) env;
762 /* release allocated memory */
764 FREE(env, _Jv_JNIEnv);
765 FREE(vm, _Jv_JavaVM);
771 /* vm_create *******************************************************************
773 Creates a JVM. Called by vm_createjvm.
775 *******************************************************************************/
777 bool vm_create(JavaVMInitArgs *vm_args)
781 char *boot_class_path;
788 #if defined(ENABLE_JVMTI)
790 char *libname, *agentarg;
791 bool jdwp,agentbypath;
792 jdwp = agentbypath = false;
795 #if defined(ENABLE_VMLOG)
796 vmlog_cacao_init(vm_args);
799 #if defined(ENABLE_JNI)
800 /* Check the JNI version requested. */
802 if (!jni_version_check(vm_args->version))
806 /* We only support 1 JVM instance. */
811 /* Install the exit handler. */
813 if (atexit(vm_exit_handler))
814 vm_abort("atexit failed: %s\n", strerror(errno));
816 /* Set some options. */
823 opt_heapmaxsize = HEAP_MAXSIZE;
824 opt_heapstartsize = HEAP_STARTSIZE;
825 opt_stacksize = STACK_SIZE;
827 /* Initialize the properties list before command-line handling.
828 Otherwise -XX:+PrintConfig crashes. */
832 /* First of all, parse the -XX options. */
836 /* We need to check if the actual size of a java.lang.Class object
837 is smaller or equal than the assumption made in
838 src/vmcore/class.h. */
840 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
841 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
843 /* set the VM starttime */
845 _Jv_jvm->starttime = builtin_currenttimemillis();
847 #if defined(ENABLE_JVMTI)
848 /* initialize JVMTI related **********************************************/
852 /* Fill the properties before command-line handling. */
856 /* iterate over all passed options */
858 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
872 #if SIZEOF_VOID_P == 8
873 puts("Running a 32-bit JVM is not supported on this platform.");
879 #if SIZEOF_VOID_P == 4
880 puts("Running a 64-bit JVM is not supported on this platform.");
886 /* Forget old classpath and set the argument as new
889 class_path = properties_get("java.class.path");
891 p = MNEW(char, strlen(opt_arg) + strlen("0"));
895 #if defined(ENABLE_JAVASE)
896 properties_add("java.class.path", p);
899 MFREE(class_path, char, strlen(class_path));
903 for (i = 0; i < strlen(opt_arg); i++) {
904 if (opt_arg[i] == '=') {
906 properties_add(opt_arg, opt_arg + i + 1);
911 /* if no '=' is given, just create an empty property */
913 properties_add(opt_arg, "");
918 case OPT_BOOTCLASSPATH:
919 /* Forget default bootclasspath and set the argument as
920 new boot classpath. */
922 boot_class_path = properties_get("sun.boot.class.path");
924 p = MNEW(char, strlen(opt_arg) + strlen("0"));
928 properties_add("sun.boot.class.path", p);
929 properties_add("java.boot.class.path", p);
931 MFREE(boot_class_path, char, strlen(boot_class_path));
934 case OPT_BOOTCLASSPATH_A:
935 /* Append to bootclasspath. */
937 boot_class_path = properties_get("sun.boot.class.path");
939 len = strlen(boot_class_path);
941 p = MREALLOC(boot_class_path,
945 strlen(opt_arg) + strlen("0"));
950 properties_add("sun.boot.class.path", p);
951 properties_add("java.boot.class.path", p);
954 case OPT_BOOTCLASSPATH_P:
955 /* Prepend to bootclasspath. */
957 boot_class_path = properties_get("sun.boot.class.path");
959 len = strlen(boot_class_path);
961 p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
965 strcat(p, boot_class_path);
967 properties_add("sun.boot.class.path", p);
968 properties_add("java.boot.class.path", p);
970 MFREE(boot_class_path, char, len);
973 case OPT_BOOTCLASSPATH_C:
974 /* Use as Java core library, but prepend VM interface
977 boot_class_path = properties_get("sun.boot.class.path");
980 strlen(CACAO_VM_ZIP) +
987 strcpy(p, CACAO_VM_ZIP);
991 properties_add("sun.boot.class.path", p);
992 properties_add("java.boot.class.path", p);
994 MFREE(boot_class_path, char, strlen(boot_class_path));
997 #if defined(ENABLE_JVMTI)
999 /* this option exists only for compatibility reasons */
1003 /* I don't know yet what Xnoagent should do. This is only for
1004 compatiblity with eclipse - motse */
1013 strlen(CACAO_LIBDIR) +
1014 strlen("/libjdwp.so=") +
1018 agentarg = MNEW(char, len);
1020 strcpy(agentarg, CACAO_LIBDIR);
1021 strcat(agentarg, "/libjdwp.so=");
1022 strcat(agentarg, &opt_arg[1]);
1039 c = opt_arg[strlen(opt_arg) - 1];
1041 if ((c == 'k') || (c == 'K')) {
1042 j = atoi(opt_arg) * 1024;
1044 } else if ((c == 'm') || (c == 'M')) {
1045 j = atoi(opt_arg) * 1024 * 1024;
1051 opt_heapmaxsize = j;
1052 else if (opt == OPT_MS)
1053 opt_heapstartsize = j;
1064 if (strcmp("class", opt_arg) == 0) {
1065 opt_verboseclass = true;
1067 else if (strcmp("gc", opt_arg) == 0) {
1068 opt_verbosegc = true;
1070 else if (strcmp("jni", opt_arg) == 0) {
1071 opt_verbosejni = true;
1073 #if !defined(NDEBUG)
1074 else if (strcmp("jit", opt_arg) == 0) {
1078 compileverbose = true;
1082 printf("Unknown -verbose option: %s\n", opt_arg);
1087 case OPT_DEBUGCOLOR:
1088 opt_debugcolor = true;
1091 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1093 opt_typecheckverbose = true;
1102 case OPT_FULLVERSION:
1106 case OPT_SHOWVERSION:
1114 #if defined(ENABLE_VERIFIER)
1120 #if defined(ENABLE_STATISTICS)
1122 opt_getcompilingtime = true;
1123 opt_getloadingtime = true;
1136 for (i = 0; i < strlen(opt_arg); i++) {
1137 switch (opt_arg[i]) {
1139 checkbounds = false;
1152 makeinitializations = false;
1155 #if !defined(NDEBUG)
1159 makeinitializations = false;
1164 opt_method = opt_arg;
1165 makeinitializations = false;
1169 opt_signature = opt_arg;
1173 case OPT_SHOW: /* Display options */
1174 for (i = 0; i < strlen(opt_arg); i++) {
1175 switch (opt_arg[i]) {
1177 showconstantpool = true;
1189 opt_showintermediate = true;
1190 compileverbose = true;
1193 #if defined(ENABLE_DISASSEMBLER)
1195 opt_showdisassemble = true;
1196 compileverbose = true;
1200 opt_shownops = true;
1205 opt_showddatasegment = true;
1214 #if defined(ENABLE_LOOP)
1220 #if defined(ENABLE_INLINING)
1221 #if defined(ENABLE_INLINING_DEBUG)
1222 case OPT_INLINE_DEBUG_ALL:
1223 opt_inline_debug_all = true;
1225 case OPT_INLINE_DEBUG_END:
1226 opt_inline_debug_end_counter = atoi(opt_arg);
1228 case OPT_INLINE_DEBUG_MIN:
1229 opt_inline_debug_min_size = atoi(opt_arg);
1231 case OPT_INLINE_DEBUG_MAX:
1232 opt_inline_debug_max_size = atoi(opt_arg);
1234 #endif /* defined(ENABLE_INLINING_DEBUG) */
1235 #if !defined(NDEBUG)
1236 case OPT_INLINE_LOG:
1237 opt_inline_debug_log = true;
1239 #endif /* !defined(NDEBUG) */
1242 opt_inlining = true;
1244 #endif /* defined(ENABLE_INLINING) */
1246 #if defined(ENABLE_IFCONV)
1252 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1267 /* Already parsed. */
1271 /* currently ignored */
1275 /* currently ignored */
1279 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1283 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1286 #if defined(ENABLE_PROFILING)
1287 case OPT_PROF_OPTION:
1288 /* use <= to get the last \0 too */
1290 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1291 if (opt_arg[i] == ',')
1294 if (opt_arg[i] == '\0') {
1295 if (strcmp("bb", opt_arg + j) == 0)
1299 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1303 /* set k to next char */
1316 #if defined(ENABLE_JIT)
1319 printf("-Xjit option not enabled.\n");
1325 #if defined(ENABLE_INTRP)
1328 printf("-Xint option not enabled.\n");
1333 #if defined(ENABLE_INTRP)
1334 case OPT_STATIC_SUPERS:
1335 opt_static_supers = atoi(opt_arg);
1338 case OPT_NO_DYNAMIC:
1339 opt_no_dynamic = true;
1342 case OPT_NO_REPLICATION:
1343 opt_no_replication = true;
1346 case OPT_NO_QUICKSUPER:
1347 opt_no_quicksuper = true;
1355 #if defined(ENABLE_DEBUG_FILTER)
1356 case OPT_FILTER_VERBOSECALL_INCLUDE:
1357 opt_filter_verbosecall_include = opt_arg;
1360 case OPT_FILTER_VERBOSECALL_EXCLUDE:
1361 opt_filter_verbosecall_exclude = opt_arg;
1364 case OPT_FILTER_SHOW_METHOD:
1365 opt_filter_show_method = opt_arg;
1370 printf("Unknown option: %s\n",
1371 vm_args->options[opt_index].optionString);
1376 /* get the main class *****************************************************/
1378 if (opt_index < vm_args->nOptions) {
1379 mainstring = vm_args->options[opt_index++].optionString;
1381 /* Put the jar file into the classpath (if any). */
1383 if (opt_jar == true) {
1384 /* free old classpath */
1386 /* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
1388 /* put jarfile into classpath */
1390 p = MNEW(char, strlen(mainstring) + strlen("0"));
1392 strcpy(p, mainstring);
1394 #if defined(ENABLE_JAVASE)
1395 properties_add("java.class.path", p);
1399 /* replace .'s with /'s in classname */
1401 for (i = strlen(mainstring) - 1; i >= 0; i--)
1402 if (mainstring[i] == '.')
1403 mainstring[i] = '/';
1407 #if defined(ENABLE_JVMTI)
1409 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1410 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1413 MFREE(agentarg, char, strlen(agentarg));
1415 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1419 /* initialize this JVM ****************************************************/
1421 vm_initializing = true;
1423 /* initialize the garbage collector */
1425 gc_init(opt_heapmaxsize, opt_heapstartsize);
1427 #if defined(ENABLE_THREADS)
1428 /* AFTER: gc_init (directly after, as this initializes the
1429 stopworldlock lock */
1434 /* install architecture dependent signal handlers */
1437 vm_abort("vm_create: signal_init failed");
1439 #if defined(ENABLE_INTRP)
1440 /* Allocate main thread stack on the Java heap. */
1443 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1444 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1448 /* AFTER: threads_preinit */
1451 vm_abort("vm_create: string_init failed");
1453 /* AFTER: threads_preinit */
1456 vm_abort("vm_create: utf8_init failed");
1458 /* AFTER: thread_preinit */
1461 vm_abort("vm_create: suck_init failed");
1463 suck_add_from_property("java.endorsed.dirs");
1465 /* Now we have all options handled and we can print the version
1468 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1473 /* AFTER: utf8_init */
1475 boot_class_path = properties_get("sun.boot.class.path");
1476 suck_add(boot_class_path);
1478 /* initialize the classcache hashtable stuff: lock, hashtable
1479 (must be done _after_ threads_preinit) */
1481 if (!classcache_init())
1482 vm_abort("vm_create: classcache_init failed");
1484 /* initialize the memory subsystem (must be done _after_
1488 vm_abort("vm_create: memory_init failed");
1490 /* initialize the finalizer stuff (must be done _after_
1493 if (!finalizer_init())
1494 vm_abort("vm_create: finalizer_init failed");
1496 /* initialize the codegen subsystems */
1500 /* initializes jit compiler */
1504 /* machine dependent initialization */
1506 #if defined(ENABLE_JIT)
1507 # if defined(ENABLE_INTRP)
1517 /* BEFORE: loader_preinit */
1521 /* AFTER: utf8_init, classcache_init */
1526 /* AFTER: loader_preinit, linker_preinit */
1533 /* AFTER: loader_init, linker_init */
1535 primitive_postinit();
1539 if (!builtin_init())
1540 vm_abort("vm_create: builtin_init failed");
1542 /* Initialize the native subsystem. */
1543 /* BEFORE: threads_init */
1546 vm_abort("vm_create: native_init failed");
1548 /* Register the native methods implemented in the VM. */
1549 /* BEFORE: threads_init */
1551 if (!nativevm_preinit())
1552 vm_abort("vm_create: nativevm_preinit failed");
1554 #if defined(ENABLE_JNI)
1555 /* Initialize the JNI subsystem (must be done _before_
1556 threads_init, as threads_init can call JNI methods
1557 (e.g. NewGlobalRef). */
1560 vm_abort("vm_create: jni_init failed");
1563 #if defined(ENABLE_THREADS)
1564 if (!threads_init())
1565 vm_abort("vm_create: threads_init failed");
1568 /* Initialize the native VM subsystem. */
1569 /* AFTER: threads_init (at least for SUN's classes) */
1571 if (!nativevm_init())
1572 vm_abort("vm_create: nativevm_init failed");
1574 #if defined(ENABLE_PROFILING)
1575 /* initialize profiling */
1577 if (!profile_init())
1578 vm_abort("vm_create: profile_init failed");
1581 #if defined(ENABLE_THREADS)
1582 /* initialize recompilation */
1584 if (!recompile_init())
1585 vm_abort("vm_create: recompile_init failed");
1587 /* start the signal handler thread */
1589 #if defined(__LINUX__)
1590 /* XXX Remove for exact-GC. */
1591 if (threads_pthreads_implementation_nptl)
1593 if (!signal_start_thread())
1594 vm_abort("vm_create: signal_start_thread failed");
1596 /* finally, start the finalizer thread */
1598 if (!finalizer_start_thread())
1599 vm_abort("vm_create: finalizer_start_thread failed");
1601 # if !defined(NDEBUG)
1602 /* start the memory profiling thread */
1604 if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
1605 if (!memory_start_thread())
1606 vm_abort("vm_create: memory_start_thread failed");
1609 /* start the recompilation thread (must be done before the
1610 profiling thread) */
1612 if (!recompile_start_thread())
1613 vm_abort("vm_create: recompile_start_thread failed");
1615 # if defined(ENABLE_PROFILING)
1616 /* start the profile sampling thread */
1619 /* if (!profile_start_thread()) */
1620 /* vm_abort("vm_create: profile_start_thread failed"); */
1624 #if defined(ENABLE_JVMTI)
1625 # if defined(ENABLE_GC_CACAO)
1626 /* XXX this will not work with the new indirection cells for classloaders!!! */
1630 /* add agent library to native library hashtable */
1631 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1635 /* increment the number of VMs */
1639 /* initialization is done */
1641 vm_initializing = false;
1643 #if !defined(NDEBUG)
1644 /* Print the VM configuration after all stuff is set and the VM is
1647 if (opt_PrintConfig)
1651 /* everything's ok */
1657 /* vm_run **********************************************************************
1659 Runs the main-method of the passed class.
1661 *******************************************************************************/
1663 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1666 classinfo *mainclass;
1669 java_handle_objectarray_t *oa;
1676 #if !defined(NDEBUG)
1682 if (opt_method != NULL) {
1683 vm_compile_method();
1686 #endif /* !defined(NDEBUG) */
1688 /* should we run the main-method? */
1690 if (mainstring == NULL)
1693 /* set return value to OK */
1697 if (opt_jar == true) {
1698 /* open jar file with java.util.jar.JarFile */
1700 mainstring = vm_get_mainclass_from_jar(mainstring);
1702 if (mainstring == NULL)
1706 /* load the main class */
1708 mainutf = utf_new_char(mainstring);
1710 #if defined(ENABLE_JAVAME_CLDC1_1)
1711 mainclass = load_class_bootstrap(mainutf);
1713 mainclass = load_class_from_sysloader(mainutf);
1716 /* error loading class */
1718 e = exceptions_get_and_clear_exception();
1720 if ((e != NULL) || (mainclass == NULL)) {
1721 exceptions_throw_noclassdeffounderror_cause(e);
1722 exceptions_print_stacktrace();
1726 if (!link_class(mainclass)) {
1727 exceptions_print_stacktrace();
1731 /* find the `main' method of the main class */
1733 m = class_resolveclassmethod(mainclass,
1734 utf_new_char("main"),
1735 utf_new_char("([Ljava/lang/String;)V"),
1736 class_java_lang_Object,
1739 if (exceptions_get_exception()) {
1740 exceptions_print_stacktrace();
1744 /* there is no main method or it isn't static */
1746 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1747 exceptions_clear_exception();
1748 exceptions_throw_nosuchmethoderror(mainclass,
1749 utf_new_char("main"),
1750 utf_new_char("([Ljava/lang/String;)V"));
1752 exceptions_print_stacktrace();
1756 /* build argument array */
1758 oalength = vm_args->nOptions - opt_index;
1760 oa = builtin_anewarray(oalength, class_java_lang_String);
1762 for (i = 0; i < oalength; i++) {
1763 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1764 s = javastring_new(u);
1766 LLNI_objectarray_element_set(oa, i, s);
1769 #ifdef TYPEINFO_DEBUG_TEST
1770 /* test the typeinfo system */
1773 /*class_showmethods(currentThread->group->header.vftbl->class); */
1775 #if defined(ENABLE_JVMTI)
1776 jvmti_set_phase(JVMTI_PHASE_LIVE);
1779 /* set ThreadMXBean variables */
1781 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1782 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1784 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1785 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1786 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1787 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1789 /* start the main thread */
1791 (void) vm_call_method(m, NULL, oa);
1793 /* exception occurred? */
1795 if (exceptions_get_exception()) {
1796 exceptions_print_stacktrace();
1800 /* unload the JavaVM */
1802 (void) vm_destroy(vm);
1810 /* vm_destroy ******************************************************************
1812 Unloads a Java VM and reclaims its resources.
1814 *******************************************************************************/
1816 s4 vm_destroy(JavaVM *vm)
1818 #if defined(ENABLE_THREADS)
1819 threads_join_all_threads();
1822 /* everything's ok */
1828 /* vm_exit *********************************************************************
1830 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1832 *******************************************************************************/
1834 void vm_exit(s4 status)
1838 /* signal that we are exiting */
1842 assert(class_java_lang_System);
1843 assert(class_java_lang_System->state & CLASS_LOADED);
1845 #if defined(ENABLE_JVMTI)
1846 if (jvmti || (dbgcom!=NULL)) {
1847 jvmti_set_phase(JVMTI_PHASE_DEAD);
1848 if (jvmti) jvmti_agentunload();
1852 if (!link_class(class_java_lang_System)) {
1853 exceptions_print_stacktrace();
1857 /* call java.lang.System.exit(I)V */
1859 m = class_resolveclassmethod(class_java_lang_System,
1860 utf_new_char("exit"),
1862 class_java_lang_Object,
1866 exceptions_print_stacktrace();
1870 /* call the exit function with passed exit status */
1872 (void) vm_call_method(m, NULL, status);
1874 /* If we had an exception, just ignore the exception and exit with
1877 vm_shutdown(status);
1881 /* vm_shutdown *****************************************************************
1883 Terminates the system immediately without freeing memory explicitly
1884 (to be used only for abnormal termination).
1886 *******************************************************************************/
1888 void vm_shutdown(s4 status)
1891 #if defined(ENABLE_STATISTICS)
1892 || opt_getcompilingtime || opt_stat
1896 log_text("CACAO terminated by shutdown");
1897 dolog("Exit status: %d\n", (s4) status);
1901 #if defined(ENABLE_JVMTI)
1902 /* terminate cacaodbgserver */
1904 pthread_mutex_lock(&dbgcomlock);
1906 pthread_mutex_unlock(&dbgcomlock);
1907 jvmti_cacaodbgserver_quit();
1915 /* vm_exit_handler *************************************************************
1917 The exit_handler function is called upon program termination.
1919 ATTENTION: Don't free system resources here! Some threads may still
1920 be running as this is called from VMRuntime.exit(). The OS does the
1923 *******************************************************************************/
1925 void vm_exit_handler(void)
1927 #if !defined(NDEBUG)
1929 class_showmethods(mainclass);
1931 if (showconstantpool)
1932 class_showconstantpool(mainclass);
1937 # if defined(ENABLE_PROFILING)
1939 profile_printstats();
1941 #endif /* !defined(NDEBUG) */
1943 #if defined(ENABLE_RT_TIMING)
1944 rt_timing_print_time_stats(stderr);
1947 #if defined(ENABLE_CYCLES_STATS)
1948 builtin_print_cycles_stats(stderr);
1949 stacktrace_print_cycles_stats(stderr);
1953 #if defined(ENABLE_STATISTICS)
1954 || opt_getcompilingtime || opt_stat
1958 log_text("CACAO terminated");
1960 #if defined(ENABLE_STATISTICS)
1963 #ifdef TYPECHECK_STATISTICS
1964 typecheck_print_statistics(get_logfile());
1968 if (opt_getcompilingtime)
1970 #endif /* defined(ENABLE_STATISTICS) */
1972 /* vm_print_profile(stderr);*/
1976 /* vm_abort ********************************************************************
1978 Prints an error message and aborts the VM.
1980 *******************************************************************************/
1982 void vm_abort(const char *text, ...)
1986 /* print the log message */
1991 log_vprint(text, ap);
1996 /* now abort the VM */
2002 /* vm_abort_disassemble ********************************************************
2004 Prints an error message, disassemble the given code range (if
2005 enabled) and aborts the VM.
2008 pc.......PC to disassemble
2009 count....number of instructions to disassemble
2011 *******************************************************************************/
2013 void vm_abort_disassemble(void *pc, int count, const char *text, ...)
2018 /* Print debug message. */
2023 log_vprint(text, ap);
2030 #if SIZEOF_VOID_P == 8
2031 log_println("PC=0x%016lx", pc);
2033 log_println("PC=0x%08x", pc);
2036 #if defined(ENABLE_DISASSEMBLER)
2037 log_println("machine instructions at PC:");
2039 /* Disassemble the given number of instructions. */
2041 for (i = 0; i < count; i++)
2042 pc = disassinstr(pc);
2045 vm_abort("Aborting...");
2049 /* vm_get_mainclass_from_jar ***************************************************
2051 Gets the name of the main class from a JAR's manifest file.
2053 *******************************************************************************/
2055 static char *vm_get_mainclass_from_jar(char *mainstring)
2062 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2065 exceptions_print_stacktrace();
2069 /* create JarFile object */
2074 exceptions_print_stacktrace();
2078 m = class_resolveclassmethod(c,
2080 utf_java_lang_String__void,
2081 class_java_lang_Object,
2085 exceptions_print_stacktrace();
2089 s = javastring_new_from_ascii(mainstring);
2091 (void) vm_call_method(m, o, s);
2093 if (exceptions_get_exception()) {
2094 exceptions_print_stacktrace();
2098 /* get manifest object */
2100 m = class_resolveclassmethod(c,
2101 utf_new_char("getManifest"),
2102 utf_new_char("()Ljava/util/jar/Manifest;"),
2103 class_java_lang_Object,
2107 exceptions_print_stacktrace();
2111 o = vm_call_method(m, o);
2114 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2119 /* get Main Attributes */
2121 LLNI_class_get(o, c);
2123 m = class_resolveclassmethod(c,
2124 utf_new_char("getMainAttributes"),
2125 utf_new_char("()Ljava/util/jar/Attributes;"),
2126 class_java_lang_Object,
2130 exceptions_print_stacktrace();
2134 o = vm_call_method(m, o);
2137 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2142 /* get property Main-Class */
2144 LLNI_class_get(o, c);
2146 m = class_resolveclassmethod(c,
2147 utf_new_char("getValue"),
2148 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2149 class_java_lang_Object,
2153 exceptions_print_stacktrace();
2157 s = javastring_new_from_ascii("Main-Class");
2159 o = vm_call_method(m, o, s);
2162 exceptions_print_stacktrace();
2166 return javastring_tochar(o);
2170 /* vm_compile_all **************************************************************
2172 Compile all methods found in the bootclasspath.
2174 *******************************************************************************/
2176 #if !defined(NDEBUG)
2177 static void vm_compile_all(void)
2182 classcache_name_entry *nmen;
2183 classcache_class_entry *clsen;
2186 /* create all classes found in the bootclasspath */
2187 /* XXX currently only works with zip/jar's */
2189 loader_load_all_classes();
2191 /* link all classes */
2193 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2194 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2196 for (; nmen; nmen = nmen->hashlink) {
2197 /* iterate over all class entries */
2199 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2200 c = clsen->classobj;
2205 if (!(c->state & CLASS_LINKED)) {
2206 if (!link_class(c)) {
2207 fprintf(stderr, "Error linking: ");
2208 utf_fprint_printable_ascii_classname(stderr, c->name);
2209 fprintf(stderr, "\n");
2211 /* print out exception and cause */
2213 exceptions_print_current_exception();
2215 /* goto next class */
2221 /* compile all class methods */
2223 for (i = 0; i < c->methodscount; i++) {
2224 m = &(c->methods[i]);
2226 if (m->jcode != NULL) {
2227 if (!jit_compile(m)) {
2228 fprintf(stderr, "Error compiling: ");
2229 utf_fprint_printable_ascii_classname(stderr, c->name);
2230 fprintf(stderr, ".");
2231 utf_fprint_printable_ascii(stderr, m->name);
2232 utf_fprint_printable_ascii(stderr, m->descriptor);
2233 fprintf(stderr, "\n");
2235 /* print out exception and cause */
2237 exceptions_print_current_exception();
2245 #endif /* !defined(NDEBUG) */
2248 /* vm_compile_method ***********************************************************
2250 Compile a specific method.
2252 *******************************************************************************/
2254 #if !defined(NDEBUG)
2255 static void vm_compile_method(void)
2259 /* create, load and link the main class */
2261 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2263 if (mainclass == NULL)
2264 exceptions_print_stacktrace();
2266 if (!link_class(mainclass))
2267 exceptions_print_stacktrace();
2269 if (opt_signature != NULL) {
2270 m = class_resolveclassmethod(mainclass,
2271 utf_new_char(opt_method),
2272 utf_new_char(opt_signature),
2277 m = class_resolveclassmethod(mainclass,
2278 utf_new_char(opt_method),
2285 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2286 opt_method, opt_signature ? opt_signature : "");
2290 #endif /* !defined(NDEBUG) */
2293 /* vm_call_array ***************************************************************
2295 Calls a Java method with a variable number of arguments, passed via
2298 ATTENTION: This function has to be used outside the nativeworld.
2300 *******************************************************************************/
2302 #define VM_CALL_ARRAY(name, type) \
2303 static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
2309 assert(m->code != NULL); \
2311 md = m->parseddesc; \
2312 pv = m->code->entrypoint; \
2314 STATISTICS(count_calls_native_to_java++); \
2316 value = asm_vm_call_method##name(pv, array, md->memuse); \
2321 static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
2327 assert(m->code != NULL);
2330 pv = m->code->entrypoint;
2332 STATISTICS(count_calls_native_to_java++);
2334 o = asm_vm_call_method(pv, array, md->memuse);
2336 if (md->returntype.type == TYPE_VOID)
2339 return LLNI_WRAP(o);
2342 VM_CALL_ARRAY(_int, int32_t)
2343 VM_CALL_ARRAY(_long, int64_t)
2344 VM_CALL_ARRAY(_float, float)
2345 VM_CALL_ARRAY(_double, double)
2348 /* vm_call_method **************************************************************
2350 Calls a Java method with a variable number of arguments.
2352 *******************************************************************************/
2354 #define VM_CALL_METHOD(name, type) \
2355 type vm_call_method##name(methodinfo *m, java_handle_t *o, ...) \
2361 value = vm_call_method##name##_valist(m, o, ap); \
2367 VM_CALL_METHOD(, java_handle_t *)
2368 VM_CALL_METHOD(_int, int32_t)
2369 VM_CALL_METHOD(_long, int64_t)
2370 VM_CALL_METHOD(_float, float)
2371 VM_CALL_METHOD(_double, double)
2374 /* vm_call_method_valist *******************************************************
2376 Calls a Java method with a variable number of arguments, passed via
2379 *******************************************************************************/
2381 #define VM_CALL_METHOD_VALIST(name, type) \
2382 type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o, \
2389 if (m->code == NULL) \
2390 if (!jit_compile(m)) \
2393 THREAD_NATIVEWORLD_EXIT; \
2395 dumpsize = dump_size(); \
2396 array = argument_vmarray_from_valist(m, o, ap); \
2397 value = vm_call##name##_array(m, array); \
2398 dump_release(dumpsize); \
2400 THREAD_NATIVEWORLD_ENTER; \
2405 VM_CALL_METHOD_VALIST(, java_handle_t *)
2406 VM_CALL_METHOD_VALIST(_int, int32_t)
2407 VM_CALL_METHOD_VALIST(_long, int64_t)
2408 VM_CALL_METHOD_VALIST(_float, float)
2409 VM_CALL_METHOD_VALIST(_double, double)
2412 /* vm_call_method_jvalue *******************************************************
2414 Calls a Java method with a variable number of arguments, passed via
2417 *******************************************************************************/
2419 #define VM_CALL_METHOD_JVALUE(name, type) \
2420 type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o, \
2421 const jvalue *args) \
2427 if (m->code == NULL) \
2428 if (!jit_compile(m)) \
2431 THREAD_NATIVEWORLD_EXIT; \
2433 dumpsize = dump_size(); \
2434 array = argument_vmarray_from_jvalue(m, o, args); \
2435 value = vm_call##name##_array(m, array); \
2436 dump_release(dumpsize); \
2438 THREAD_NATIVEWORLD_ENTER; \
2443 VM_CALL_METHOD_JVALUE(, java_handle_t *)
2444 VM_CALL_METHOD_JVALUE(_int, int32_t)
2445 VM_CALL_METHOD_JVALUE(_long, int64_t)
2446 VM_CALL_METHOD_JVALUE(_float, float)
2447 VM_CALL_METHOD_JVALUE(_double, double)
2450 /* vm_call_method_objectarray **************************************************
2452 Calls a Java method with a variable number if arguments, passed via
2453 an objectarray of boxed values. Returns a boxed value.
2455 *******************************************************************************/
2457 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
2458 java_handle_objectarray_t *params)
2462 java_handle_t *xptr;
2466 /* compile methods which are not yet compiled */
2468 if (m->code == NULL)
2469 if (!jit_compile(m))
2472 /* leave the nativeworld */
2474 THREAD_NATIVEWORLD_EXIT;
2476 /* mark start of dump memory area */
2478 dumpsize = dump_size();
2480 /* Fill the argument array from a object-array. */
2482 array = argument_vmarray_from_objectarray(m, o, params);
2484 if (array == NULL) {
2485 /* release dump area */
2487 dump_release(dumpsize);
2489 /* enter the nativeworld again */
2491 THREAD_NATIVEWORLD_ENTER;
2493 exceptions_throw_illegalargumentexception();
2498 switch (m->parseddesc->returntype.decltype) {
2500 (void) vm_call_array(m, array);
2504 case PRIMITIVETYPE_BOOLEAN:
2505 case PRIMITIVETYPE_BYTE:
2506 case PRIMITIVETYPE_CHAR:
2507 case PRIMITIVETYPE_SHORT:
2508 case PRIMITIVETYPE_INT:
2509 value.i = vm_call_int_array(m, array);
2510 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2513 case PRIMITIVETYPE_LONG:
2514 value.l = vm_call_long_array(m, array);
2515 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2518 case PRIMITIVETYPE_FLOAT:
2519 value.f = vm_call_float_array(m, array);
2520 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2523 case PRIMITIVETYPE_DOUBLE:
2524 value.d = vm_call_double_array(m, array);
2525 ro = primitive_box(m->parseddesc->returntype.decltype, value);
2529 ro = vm_call_array(m, array);
2533 vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
2536 /* release dump area */
2538 dump_release(dumpsize);
2540 /* enter the nativeworld again */
2542 THREAD_NATIVEWORLD_ENTER;
2544 /* check for an exception */
2546 xptr = exceptions_get_exception();
2549 /* clear exception pointer, we are calling JIT code again */
2551 exceptions_clear_exception();
2553 exceptions_throw_invocationtargetexception(xptr);
2561 * These are local overrides for various environment variables in Emacs.
2562 * Please do not remove this and leave it at the end of the file, where
2563 * Emacs will automagically detect them.
2564 * ---------------------------------------------------------------------
2567 * indent-tabs-mode: t
2571 * vim:noexpandtab:sw=4:ts=4: