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
25 $Id: vm.c 4357 2006-01-22 23:33:38Z twisti $
36 #if defined(WITH_JRE_LAYOUT)
43 #include "mm/gc-common.h"
44 #include "mm/memory.h"
46 #include "native/jni.h"
47 #include "native/native.h"
48 #include "native/include/java_lang_String.h" /* required by java_lang_Class.h */
49 #include "native/include/java_lang_Class.h"
51 #include "threads/threads-common.h"
53 #include "toolbox/logging.h"
55 #include "vm/builtin.h"
56 #include "vm/exceptions.h"
57 #include "vm/finalizer.h"
58 #include "vm/global.h"
59 #include "vm/initialize.h"
60 #include "vm/properties.h"
61 #include "vm/signallocal.h"
62 #include "vm/stringlocal.h"
65 #include "vm/jit/jit.h"
66 #include "vm/jit/md.h"
67 #include "vm/jit/asmpart.h"
69 #if defined(ENABLE_PROFILING)
70 # include "vm/jit/optimizing/profile.h"
73 #include "vm/jit/optimizing/recompile.h"
75 #include "vmcore/classcache.h"
76 #include "vmcore/options.h"
77 #include "vmcore/suck.h"
79 #if defined(ENABLE_JVMTI)
80 # include "native/jvmti/cacaodbg.h"
83 #if defined(ENABLE_VMLOG)
84 #include <vmlog_cacao.h>
88 /* Invocation API variables ***************************************************/
90 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
91 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
94 /* global variables ***********************************************************/
96 s4 vms = 0; /* number of VMs created */
98 bool vm_initializing = false;
99 bool vm_exiting = false;
101 char *cacao_prefix = NULL;
102 char *cacao_libjvm = NULL;
103 char *classpath_libdir = NULL;
105 char *_Jv_bootclasspath; /* contains the boot classpath */
106 char *_Jv_classpath; /* contains the classpath */
107 char *_Jv_java_library_path;
109 char *mainstring = NULL;
110 classinfo *mainclass = NULL;
112 char *specificmethodname = NULL;
113 char *specificsignature = NULL;
117 #if defined(ENABLE_INTRP)
118 u1 *intrp_main_stack = NULL;
122 /* define heap sizes **********************************************************/
124 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
125 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
126 #define STACK_SIZE 64 * 1024 /* default 64kB */
129 /* define command line options ************************************************/
157 /* Java non-standard options */
168 #if defined(ENABLE_PROFILING)
181 #if defined(ENABLE_STATISTICS)
198 #if defined(ENABLE_VERIFIER)
200 #if defined(TYPECHECK_VERBOSE)
203 #endif /* defined(ENABLE_VERIFIER) */
206 /* optimization options */
208 #if defined(ENABLE_LOOP)
212 #if defined(ENABLE_IFCONV)
216 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
220 #if defined(ENABLE_INLINING)
225 #if defined(ENABLE_INLINING_DEBUG)
226 OPT_INLINE_DEBUG_ALL,
227 OPT_INLINE_DEBUG_END,
228 OPT_INLINE_DEBUG_MIN,
229 OPT_INLINE_DEBUG_MAX,
230 OPT_INLINE_REPLACE_VERBOSE,
231 OPT_INLINE_REPLACE_VERBOSE2,
232 #endif /* defined(ENABLE_INLINING_DEBUG) */
233 #endif /* defined(ENABLE_INLINING) */
235 #if defined(ENABLE_INTRP)
236 /* interpreter options */
259 opt_struct opts[] = {
260 { "foo", false, OPT_FOO },
264 { "jar", false, OPT_JAR },
266 { "d32", false, OPT_D32 },
267 { "d64", false, OPT_D64 },
268 { "client", false, OPT_IGNORE },
269 { "server", false, OPT_IGNORE },
270 { "jvm", false, OPT_IGNORE },
271 { "hotspot", false, OPT_IGNORE },
273 { "classpath", true, OPT_CLASSPATH },
274 { "cp", true, OPT_CLASSPATH },
275 { "D", true, OPT_D },
276 { "version", false, OPT_VERSION },
277 { "showversion", false, OPT_SHOWVERSION },
278 { "fullversion", false, OPT_FULLVERSION },
279 { "help", false, OPT_HELP },
280 { "?", false, OPT_HELP },
281 { "X", false, OPT_X },
282 { "XX", false, OPT_XX },
284 { "esa", false, OPT_ESA },
285 { "enablesystemassertions", false, OPT_ESA },
286 { "dsa", false, OPT_DSA },
287 { "disablesystemassertions", false, OPT_DSA },
289 { "noasyncgc", false, OPT_IGNORE },
290 #if defined(ENABLE_VERIFIER)
291 { "noverify", false, OPT_NOVERIFY },
293 { "v", false, OPT_VERBOSE1 },
294 { "verbose:", true, OPT_VERBOSE },
296 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
297 { "verbosetc", false, OPT_VERBOSETC },
299 #if defined(__ALPHA__)
300 { "noieee", false, OPT_NOIEEE },
302 #if defined(ENABLE_STATISTICS)
303 { "time", false, OPT_TIME },
304 { "stat", false, OPT_STAT },
306 { "log", true, OPT_LOG },
307 { "c", true, OPT_CHECK },
308 { "l", false, OPT_LOAD },
309 { "eager", false, OPT_EAGER },
312 { "all", false, OPT_ALL },
313 { "sig", true, OPT_SIGNATURE },
316 #if defined(ENABLE_LOOP)
317 { "oloop", false, OPT_OLOOP },
319 #if defined(ENABLE_IFCONV)
320 { "ifconv", false, OPT_IFCONV },
322 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
323 { "lsra", false, 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 */
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 },
352 { "Xdebug", false, OPT_DEBUG },
353 { "Xnoagent", false, OPT_NOAGENT },
354 { "Xrunjdwp", true, OPT_XRUNJDWP },
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 #if defined(ENABLE_PROFILING)
365 { "Xprof:", true, OPT_PROF_OPTION },
366 { "Xprof", false, OPT_PROF },
369 /* inlining options */
371 #if defined(ENABLE_INLINING)
372 #if defined(ENABLE_INLINING_DEBUG)
373 { "ia", false, OPT_INLINE_DEBUG_ALL },
374 { "ii", true, OPT_INLINE_DEBUG_MIN },
375 { "im", true, OPT_INLINE_DEBUG_MAX },
376 { "ie", true, OPT_INLINE_DEBUG_END },
377 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
378 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
379 #endif /* defined(ENABLE_INLINING_DEBUG) */
381 { "il", false, OPT_INLINE_LOG },
383 { "i", false, OPT_INLINING },
384 #endif /* defined(ENABLE_INLINING) */
386 /* keep these at the end of the list */
389 { "m", true, OPT_METHOD },
392 { "s", true, OPT_SHOW },
393 { "debug-color", false, OPT_DEBUGCOLOR },
399 /* usage ***********************************************************************
401 Prints the correct usage syntax to stdout.
403 *******************************************************************************/
407 puts("Usage: cacao [-options] classname [arguments]");
408 puts(" (to run a class file)");
409 puts(" or cacao [-options] -jar jarfile [arguments]");
410 puts(" (to run a standalone jar file)\n");
412 puts("where options include:");
413 puts(" -d32 use 32-bit data model if available");
414 puts(" -d64 use 64-bit data model if available");
415 puts(" -client compatibility (currently ignored)");
416 puts(" -server compatibility (currently ignored)");
417 puts(" -jvm compatibility (currently ignored)");
418 puts(" -hotspot compatibility (currently ignored)\n");
420 puts(" -cp <path> specify a path to look for classes");
421 puts(" -classpath <path> specify a path to look for classes");
422 puts(" -D<name>=<value> add an entry to the property list");
423 puts(" -verbose[:class|gc|jni] enable specific verbose output");
424 puts(" -version print product version and exit");
425 puts(" -fullversion print jpackage-compatible product version and exit");
426 puts(" -showversion print product version and continue");
427 puts(" -help, -? print this help message");
428 puts(" -X print help on non-standard Java options");
429 puts(" -XX print help on CACAO options");
430 puts(" -esa | -enablesystemassertions");
431 puts(" enable system assertions");
432 puts(" -dsa | -disablesystemassertions");
433 puts(" disable system assertions");
436 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
437 puts (" for jdwp help use: -agentlib:jdwp=help");
438 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
441 /* exit with error code */
447 static void Xusage(void)
449 #if defined(ENABLE_JIT)
450 puts(" -Xjit JIT mode execution (default)");
452 #if defined(ENABLE_INTRP)
453 puts(" -Xint interpreter mode execution");
455 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
456 puts(" value is set as bootstrap class path");
457 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
458 puts(" value is appended to the bootstrap class path");
459 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
460 puts(" value is prepended to the bootstrap class path");
461 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
462 puts(" value is used as Java core library, but the");
463 puts(" hardcoded VM interface classes are prepended");
464 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
465 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
466 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
468 #if defined(ENABLE_PROFILING)
469 puts(" -Xprof[:bb] collect and print profiling data");
472 #if defined(ENABLE_JVMTI)
473 /* -Xdebug option depend on gnu classpath JDWP options. options:
474 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
475 puts(" -Xdebug enable remote debugging\n");
476 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
477 puts(" enable remote debugging\n");
480 /* exit with error code */
486 static void XXusage(void)
488 puts(" -v write state-information");
490 puts(" -verbose[:call|exception|jit|memory]");
491 puts(" enable specific verbose output");
492 puts(" -debug-color colored output for ANSI terms");
494 #ifdef TYPECHECK_VERBOSE
495 puts(" -verbosetc write debug messages while typechecking");
497 #if defined(__ALPHA__)
498 puts(" -noieee don't use ieee compliant arithmetic");
500 #if defined(ENABLE_VERIFIER)
501 puts(" -noverify don't verify classfiles");
503 #if defined(ENABLE_STATISTICS)
504 puts(" -time measure the runtime");
505 puts(" -stat detailed compiler statistics");
507 puts(" -log logfile specify a name for the logfile");
508 puts(" -c(heck)b(ounds) don't check array bounds");
509 puts(" s(ync) don't check for synchronization");
510 #if defined(ENABLE_LOOP)
511 puts(" -oloop optimize array accesses in loops");
513 puts(" -l don't start the class after loading");
514 puts(" -eager perform eager class loading and linking");
516 puts(" -all compile all methods, no execution");
517 puts(" -m compile only a specific method");
518 puts(" -sig specify signature for a specific method");
521 puts(" -s... show...");
522 puts(" (c)onstants the constant pool");
523 puts(" (m)ethods class fields and methods");
524 puts(" (u)tf the utf - hash");
525 puts(" (i)ntermediate intermediate representation");
526 #if defined(ENABLE_DISASSEMBLER)
527 puts(" (a)ssembler disassembled listing");
528 puts(" n(o)ps show NOPs in disassembler output");
529 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
530 puts(" (n)ative disassembled native stubs");
532 puts(" (d)atasegment data segment listing");
534 #if defined(ENABLE_INLINING)
535 puts(" -i activate inlining");
537 puts(" -il log inlining");
539 #if defined(ENABLE_INLINING_DEBUG)
540 puts(" -ia use inlining for all methods");
541 puts(" -ii <size> set minimum size for inlined result");
542 puts(" -im <size> set maximum size for inlined result");
543 puts(" -ie <number> stop inlining after the given number of roots");
544 puts(" -ir log on-stack replacement");
545 puts(" -iR log on-stack replacement, more verbose");
546 #endif /* defined(ENABLE_INLINING_DEBUG) */
547 #endif /* defined(ENABLE_INLINING) */
549 #if defined(ENABLE_IFCONV)
550 puts(" -ifconv use if-conversion");
552 #if defined(ENABLE_LSRA)
553 puts(" -lsra use linear scan register allocation");
555 #if defined(ENABLE_SSA)
556 puts(" -lsra use linear scan register allocation (with SSA)");
559 /* exit with error code */
565 /* version *********************************************************************
567 Only prints cacao version information.
569 *******************************************************************************/
571 static void version(bool opt_exit)
573 puts("java version \""JAVA_VERSION"\"");
574 puts("CACAO version "VERSION"");
576 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
577 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
578 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
579 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
581 puts("This program is free software; you can redistribute it and/or");
582 puts("modify it under the terms of the GNU General Public License as");
583 puts("published by the Free Software Foundation; either version 2, or (at");
584 puts("your option) any later version.\n");
586 puts("This program is distributed in the hope that it will be useful, but");
587 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
588 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
589 puts("General Public License for more details.\n");
591 puts("Configure/Build options:\n");
592 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
593 #if defined(__VERSION__)
594 puts(" CC : "VERSION_CC" ("__VERSION__")");
596 puts(" CC : "VERSION_CC"");
598 puts(" CFLAGS : "VERSION_CFLAGS"\n");
600 puts("Default variables:\n");
601 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
602 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
603 printf(" stack size : %d\n", STACK_SIZE);
604 #if defined(WITH_CLASSPATH_GNU)
605 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
607 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
609 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
611 puts("Runtime variables:\n");
612 printf(" maximum heap size : %d\n", opt_heapmaxsize);
613 printf(" initial heap size : %d\n", opt_heapstartsize);
614 printf(" stack size : %d\n", opt_stacksize);
615 printf(" libjvm.so : %s\n", cacao_libjvm);
616 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
617 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
618 printf(" java.class.path : %s\n", _Jv_classpath);
620 /* exit normally, if requested */
627 /* fullversion *****************************************************************
629 Prints a Sun compatible version information (required e.g. by
630 jpackage, www.jpackage.org).
632 *******************************************************************************/
634 static void fullversion(void)
636 puts("java full version \"cacao-"JAVA_VERSION"\"");
644 /* forward declarations *******************************************************/
646 static char *vm_get_mainclass_from_jar(char *mainstring);
648 static void vm_compile_all(void);
649 static void vm_compile_method(void);
653 /* vm_createjvm ****************************************************************
655 Implementation for JNI_CreateJavaVM.
657 *******************************************************************************/
659 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
661 JavaVMInitArgs *_vm_args;
665 /* get the arguments for the new JVM */
667 _vm_args = (JavaVMInitArgs *) vm_args;
669 /* get the VM and Env tables (must be set before vm_create) */
671 env = NEW(_Jv_JNIEnv);
673 #if defined(ENABLE_JNI)
674 env->env = &_Jv_JNINativeInterface;
677 /* XXX Set the global variable. Maybe we should do that differently. */
681 /* create and fill a JavaVM structure */
683 vm = NEW(_Jv_JavaVM);
685 #if defined(ENABLE_JNI)
686 vm->functions = &_Jv_JNIInvokeInterface;
689 /* XXX Set the global variable. Maybe we should do that differently. */
690 /* XXX JVMTI Agents needs a JavaVM */
694 /* actually create the JVM */
696 if (!vm_create(_vm_args))
699 #if defined(ENABLE_JNI)
700 /* setup the local ref table (must be created after vm_create) */
702 if (!jni_init_localref_table())
706 /* now return the values */
708 *p_vm = (JavaVM *) vm;
709 *p_env = (void *) env;
714 /* release allocated memory */
716 FREE(env, _Jv_JNIEnv);
717 FREE(vm, _Jv_JavaVM);
723 /* vm_create *******************************************************************
725 Creates a JVM. Called by vm_createjvm.
727 *******************************************************************************/
729 bool vm_create(JavaVMInitArgs *vm_args)
738 #if defined(ENABLE_JVMTI)
740 char *libname, *agentarg;
741 bool jdwp,agentbypath;
742 jdwp = agentbypath = false;
745 #if defined(ENABLE_VMLOG)
746 vmlog_cacao_init(vm_args);
749 /* check the JNI version requested */
751 switch (vm_args->version) {
752 case JNI_VERSION_1_1:
754 case JNI_VERSION_1_2:
755 case JNI_VERSION_1_4:
761 /* we only support 1 JVM instance */
766 if (atexit(vm_exit_handler))
767 vm_abort("atexit failed: %s\n", strerror(errno));
770 log_text("CACAO started -------------------------------------------------------");
772 /* We need to check if the actual size of a java.lang.Class object
773 is smaller or equal than the assumption made in
774 src/vmcore/class.h. */
776 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
777 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
779 /* set the VM starttime */
781 _Jv_jvm->starttime = builtin_currenttimemillis();
783 /* get stuff from the environment *****************************************/
785 #if defined(WITH_JRE_LAYOUT)
786 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
788 cacao_prefix = MNEW(char, 4096);
790 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
791 vm_abort("readlink failed: %s\n", strerror(errno));
793 /* get the path of the current executable */
795 cacao_prefix = dirname(cacao_prefix);
797 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
798 vm_abort("libjvm name to long for buffer\n");
800 /* concatenate the library name */
802 strcat(cacao_prefix, "/..");
804 /* now set path to libjvm.so */
806 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
808 cacao_libjvm = MNEW(char, len);
809 strcpy(cacao_libjvm, cacao_prefix);
810 strcat(cacao_libjvm, "/lib/libjvm");
812 /* and finally set the path to GNU Classpath libraries */
814 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
816 classpath_libdir = MNEW(char, len);
817 strcpy(classpath_libdir, cacao_prefix);
818 strcat(classpath_libdir, "/lib/classpath");
820 cacao_prefix = CACAO_PREFIX;
821 cacao_libjvm = CACAO_LIBDIR"/libjvm";
822 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
825 /* set the bootclasspath */
827 cp = getenv("BOOTCLASSPATH");
830 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
831 strcpy(_Jv_bootclasspath, cp);
834 #if defined(WITH_JRE_LAYOUT)
836 # if defined(WITH_CLASSPATH_GNU)
837 strlen(cacao_prefix) +
838 strlen("/share/cacao/vm.zip") +
841 strlen(cacao_prefix) +
842 strlen("/share/classpath/glibj.zip") +
845 _Jv_bootclasspath = MNEW(char, len);
846 # if defined(WITH_CLASSPATH_GNU)
847 strcat(_Jv_bootclasspath, cacao_prefix);
848 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
849 strcat(_Jv_bootclasspath, ":");
851 strcat(_Jv_bootclasspath, cacao_prefix);
852 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
855 # if defined(WITH_CLASSPATH_GNU)
856 strlen(CACAO_VM_ZIP) +
859 strlen(CLASSPATH_CLASSES) +
862 _Jv_bootclasspath = MNEW(char, len);
863 # if defined(WITH_CLASSPATH_GNU)
864 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
865 strcat(_Jv_bootclasspath, ":");
867 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
871 /* set the classpath */
873 cp = getenv("CLASSPATH");
876 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
877 strcat(_Jv_classpath, cp);
880 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
881 strcpy(_Jv_classpath, ".");
884 /* get and set java.library.path */
886 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
888 if (_Jv_java_library_path == NULL)
889 _Jv_java_library_path = "";
891 /* interpret the options **************************************************/
898 opt_heapmaxsize = HEAP_MAXSIZE;
899 opt_heapstartsize = HEAP_STARTSIZE;
900 opt_stacksize = STACK_SIZE;
903 #if defined(ENABLE_JVMTI)
904 /* initialize JVMTI related **********************************************/
908 /* initialize and fill properties before command-line handling */
910 if (!properties_init())
911 vm_abort("properties_init failed");
913 /* iterate over all passed options */
915 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
929 #if SIZEOF_VOID_P == 8
930 puts("Running a 32-bit JVM is not supported on this platform.");
936 #if SIZEOF_VOID_P == 4
937 puts("Running a 64-bit JVM is not supported on this platform.");
943 /* forget old classpath and set the argument as new classpath */
944 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
946 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
947 strcpy(_Jv_classpath, opt_arg);
951 for (i = 0; i < strlen(opt_arg); i++) {
952 if (opt_arg[i] == '=') {
954 properties_add(opt_arg, opt_arg + i + 1);
959 /* if no '=' is given, just create an empty property */
961 properties_add(opt_arg, "");
966 case OPT_BOOTCLASSPATH:
967 /* Forget default bootclasspath and set the argument as
968 new boot classpath. */
970 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
972 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
973 strcpy(_Jv_bootclasspath, opt_arg);
976 case OPT_BOOTCLASSPATH_A:
977 /* append to end of bootclasspath */
979 len = strlen(_Jv_bootclasspath);
981 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
985 strlen(opt_arg) + strlen("0"));
987 strcat(_Jv_bootclasspath, ":");
988 strcat(_Jv_bootclasspath, opt_arg);
991 case OPT_BOOTCLASSPATH_P:
992 /* prepend in front of bootclasspath */
994 cp = _Jv_bootclasspath;
997 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
1000 strcpy(_Jv_bootclasspath, opt_arg);
1001 strcat(_Jv_bootclasspath, ":");
1002 strcat(_Jv_bootclasspath, cp);
1004 MFREE(cp, char, len);
1007 case OPT_BOOTCLASSPATH_C:
1008 /* use as Java core library, but prepend VM interface classes */
1010 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1012 len = strlen(CACAO_VM_ZIP) +
1017 _Jv_bootclasspath = MNEW(char, len);
1019 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1020 strcat(_Jv_bootclasspath, ":");
1021 strcat(_Jv_bootclasspath, opt_arg);
1024 #if defined(ENABLE_JVMTI)
1026 /* this option exists only for compatibility reasons */
1030 /* I don't know yet what Xnoagent should do. This is only for
1031 compatiblity with eclipse - motse */
1040 strlen(CACAO_LIBDIR) +
1041 strlen("/libjdwp.so=") +
1045 agentarg = MNEW(char, len);
1047 strcpy(agentarg, CACAO_LIBDIR);
1048 strcat(agentarg, "/libjdwp.so=");
1049 strcat(agentarg, &opt_arg[1]);
1066 c = opt_arg[strlen(opt_arg) - 1];
1068 if ((c == 'k') || (c == 'K')) {
1069 j = atoi(opt_arg) * 1024;
1071 } else if ((c == 'm') || (c == 'M')) {
1072 j = atoi(opt_arg) * 1024 * 1024;
1078 opt_heapmaxsize = j;
1079 else if (opt == OPT_MS)
1080 opt_heapstartsize = j;
1091 if (strcmp("class", opt_arg) == 0) {
1092 opt_verboseclass = true;
1094 else if (strcmp("gc", opt_arg) == 0) {
1095 opt_verbosegc = true;
1097 else if (strcmp("jni", opt_arg) == 0) {
1098 opt_verbosejni = true;
1100 #if !defined(NDEBUG)
1101 else if (strcmp("call", opt_arg) == 0) {
1102 opt_verbosecall = true;
1104 else if (strcmp("exception", opt_arg) == 0) {
1105 opt_verboseexception = true;
1107 else if (strcmp("jit", opt_arg) == 0) {
1112 compileverbose = true;
1114 else if (strcmp("memory", opt_arg) == 0) {
1115 opt_verbosememory = true;
1117 # if defined(ENABLE_STATISTICS)
1118 /* we also need statistics */
1124 printf("Unknown -verbose option: %s\n", opt_arg);
1129 case OPT_DEBUGCOLOR:
1130 opt_debugcolor = true;
1133 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1135 opt_typecheckverbose = true;
1144 case OPT_FULLVERSION:
1148 case OPT_SHOWVERSION:
1156 #if defined(ENABLE_VERIFIER)
1162 #if defined(ENABLE_STATISTICS)
1164 opt_getcompilingtime = true;
1165 opt_getloadingtime = true;
1178 for (i = 0; i < strlen(opt_arg); i++) {
1179 switch (opt_arg[i]) {
1181 checkbounds = false;
1194 makeinitializations = false;
1201 #if !defined(NDEBUG)
1205 makeinitializations = false;
1210 opt_method = opt_arg;
1211 makeinitializations = false;
1215 opt_signature = opt_arg;
1219 case OPT_SHOW: /* Display options */
1220 for (i = 0; i < strlen(opt_arg); i++) {
1221 switch (opt_arg[i]) {
1223 showconstantpool = true;
1235 opt_showintermediate = true;
1236 compileverbose = true;
1239 #if defined(ENABLE_DISASSEMBLER)
1241 opt_showdisassemble = true;
1242 compileverbose = true;
1246 opt_shownops = true;
1250 opt_showexceptionstubs = true;
1254 opt_shownativestub = true;
1259 opt_showddatasegment = true;
1268 #if defined(ENABLE_LOOP)
1274 #if defined(ENABLE_INLINING)
1275 #if defined(ENABLE_INLINING_DEBUG)
1276 case OPT_INLINE_DEBUG_ALL:
1277 opt_inline_debug_all = true;
1279 case OPT_INLINE_DEBUG_END:
1280 opt_inline_debug_end_counter = atoi(opt_arg);
1282 case OPT_INLINE_DEBUG_MIN:
1283 opt_inline_debug_min_size = atoi(opt_arg);
1285 case OPT_INLINE_DEBUG_MAX:
1286 opt_inline_debug_max_size = atoi(opt_arg);
1288 case OPT_INLINE_REPLACE_VERBOSE:
1289 opt_replace_verbose = 1;
1291 case OPT_INLINE_REPLACE_VERBOSE2:
1292 opt_replace_verbose = 2;
1294 #endif /* defined(ENABLE_INLINING_DEBUG) */
1295 #if !defined(NDEBUG)
1296 case OPT_INLINE_LOG:
1297 opt_inline_debug_log = true;
1299 #endif /* !defined(NDEBUG) */
1302 opt_inlining = true;
1304 #endif /* defined(ENABLE_INLINING) */
1306 #if defined(ENABLE_IFCONV)
1312 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1331 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1335 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1338 #if defined(ENABLE_PROFILING)
1339 case OPT_PROF_OPTION:
1340 /* use <= to get the last \0 too */
1342 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1343 if (opt_arg[i] == ',')
1346 if (opt_arg[i] == '\0') {
1347 if (strcmp("bb", opt_arg + j) == 0)
1351 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1355 /* set k to next char */
1368 #if defined(ENABLE_JIT)
1371 printf("-Xjit option not enabled.\n");
1377 #if defined(ENABLE_INTRP)
1380 printf("-Xint option not enabled.\n");
1385 #if defined(ENABLE_INTRP)
1386 case OPT_STATIC_SUPERS:
1387 opt_static_supers = atoi(opt_arg);
1390 case OPT_NO_DYNAMIC:
1391 opt_no_dynamic = true;
1394 case OPT_NO_REPLICATION:
1395 opt_no_replication = true;
1398 case OPT_NO_QUICKSUPER:
1399 opt_no_quicksuper = true;
1408 printf("Unknown option: %s\n",
1409 vm_args->options[opt_index].optionString);
1414 /* get the main class *****************************************************/
1416 if (opt_index < vm_args->nOptions) {
1417 mainstring = vm_args->options[opt_index++].optionString;
1419 /* Put the jar file into the classpath (if any). */
1421 if (opt_jar == true) {
1422 /* free old classpath */
1424 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1426 /* put jarfile into classpath */
1428 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1430 strcpy(_Jv_classpath, mainstring);
1433 /* replace .'s with /'s in classname */
1435 for (i = strlen(mainstring) - 1; i >= 0; i--)
1436 if (mainstring[i] == '.')
1437 mainstring[i] = '/';
1441 #if defined(ENABLE_JVMTI)
1443 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1444 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1447 MFREE(agentarg, char, strlen(agentarg));
1449 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1453 /* initialize this JVM ****************************************************/
1455 vm_initializing = true;
1457 #if defined(ENABLE_THREADS)
1458 /* pre-initialize some core thread stuff, like the stopworldlock,
1459 thus this has to happen _before_ gc_init()!!! */
1464 /* initialize the garbage collector */
1466 gc_init(opt_heapmaxsize, opt_heapstartsize);
1468 #if defined(ENABLE_INTRP)
1469 /* Allocate main thread stack on the Java heap. */
1472 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1473 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1477 /* AFTER: threads_preinit */
1480 vm_abort("vm_create: string_init failed");
1482 /* AFTER: threads_preinit */
1485 vm_abort("vm_create: utf8_init failed");
1487 /* AFTER: thread_preinit */
1490 vm_abort("vm_create: suck_init failed");
1492 suck_add_from_property("java.endorsed.dirs");
1494 /* Now we have all options handled and we can print the version
1497 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1502 /* AFTER: utf8_init */
1504 suck_add(_Jv_bootclasspath);
1506 /* Now re-set some of the properties that may have changed. This
1507 must be done after _all_ environment variables have been
1508 processes (e.g. -jar handling).
1510 AFTER: suck_add_from_property, since it may change the
1511 _Jv_bootclasspath pointer. */
1513 if (!properties_postinit())
1514 vm_abort("vm_create: properties_postinit failed");
1516 /* initialize the classcache hashtable stuff: lock, hashtable
1517 (must be done _after_ threads_preinit) */
1519 if (!classcache_init())
1520 vm_abort("vm_create: classcache_init failed");
1522 /* initialize the memory subsystem (must be done _after_
1526 vm_abort("vm_create: memory_init failed");
1528 /* initialize the finalizer stuff (must be done _after_
1531 if (!finalizer_init())
1532 vm_abort("vm_create: finalizer_init failed");
1534 /* install architecture dependent signal handlers */
1538 /* initialize the codegen subsystems */
1542 /* initializes jit compiler */
1546 /* machine dependent initialization */
1548 #if defined(ENABLE_JIT)
1549 # if defined(ENABLE_INTRP)
1559 /* initialize the loader subsystems (must be done _after_
1563 vm_abort("vm_create: loader_init failed");
1566 vm_abort("vm_create: linker_init failed");
1569 vm_abort("vm_create: native_init failed");
1571 if (!exceptions_init())
1572 vm_abort("vm_create: exceptions_init failed");
1574 if (!builtin_init())
1575 vm_abort("vm_create: builtin_init failed");
1577 #if defined(ENABLE_JNI)
1578 /* Initialize the JNI subsystem (must be done _before_
1579 threads_init, as threads_init can call JNI methods
1580 (e.g. NewGlobalRef). */
1583 vm_abort("vm_create: jni_init failed");
1586 #if defined(ENABLE_THREADS)
1587 if (!threads_init())
1588 vm_abort("vm_create: threads_init failed");
1591 #if defined(ENABLE_PROFILING)
1592 /* initialize profiling */
1594 if (!profile_init())
1595 vm_abort("vm_create: profile_init failed");
1598 #if defined(ENABLE_THREADS)
1599 /* initialize recompilation */
1601 if (!recompile_init())
1602 vm_abort("vm_create: recompile_init failed");
1604 /* start the signal handler thread */
1606 if (!signal_start_thread())
1607 vm_abort("vm_create: signal_start_thread failed");
1609 /* finally, start the finalizer thread */
1611 if (!finalizer_start_thread())
1612 vm_abort("vm_create: finalizer_start_thread failed");
1614 # if !defined(NDEBUG)
1615 /* start the memory profiling thread */
1617 if (opt_verbosememory)
1618 if (!memory_start_thread())
1619 vm_abort("vm_create: memory_start_thread failed");
1622 /* start the recompilation thread (must be done before the
1623 profiling thread) */
1625 if (!recompile_start_thread())
1626 vm_abort("vm_create: recompile_start_thread failed");
1628 # if defined(ENABLE_PROFILING)
1629 /* start the profile sampling thread */
1632 /* if (!profile_start_thread()) */
1633 /* exceptions_print_stacktrace(); */
1637 #if defined(ENABLE_JVMTI)
1639 /* add agent library to native library hashtable */
1640 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1644 /* increment the number of VMs */
1648 /* initialization is done */
1650 vm_initializing = false;
1652 /* everything's ok */
1658 /* vm_run **********************************************************************
1660 Runs the main-method of the passed class.
1662 *******************************************************************************/
1664 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1667 classinfo *mainclass;
1669 java_objectarray *oa;
1672 java_objectheader *s;
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 if ((exceptions_get_exception() != NULL) || (mainclass == NULL)) {
1719 exceptions_print_stacktrace();
1723 if (!link_class(mainclass)) {
1724 exceptions_print_stacktrace();
1728 /* find the `main' method of the main class */
1730 m = class_resolveclassmethod(mainclass,
1731 utf_new_char("main"),
1732 utf_new_char("([Ljava/lang/String;)V"),
1733 class_java_lang_Object,
1736 if (exceptions_get_exception()) {
1737 exceptions_print_stacktrace();
1741 /* there is no main method or it isn't static */
1743 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1744 exceptions_clear_exception();
1745 exceptions_throw_nosuchmethoderror(mainclass,
1746 utf_new_char("main"),
1747 utf_new_char("([Ljava/lang/String;)V"));
1749 exceptions_print_stacktrace();
1753 /* build argument array */
1755 oalength = vm_args->nOptions - opt_index;
1757 oa = builtin_anewarray(oalength, class_java_lang_String);
1759 for (i = 0; i < oalength; i++) {
1760 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1761 s = javastring_new(u);
1766 #ifdef TYPEINFO_DEBUG_TEST
1767 /* test the typeinfo system */
1770 /*class_showmethods(currentThread->group->header.vftbl->class); */
1772 #if defined(ENABLE_JVMTI)
1773 jvmti_set_phase(JVMTI_PHASE_LIVE);
1776 /* set ThreadMXBean variables */
1778 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1779 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1781 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1782 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1783 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1784 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1786 /* start the main thread */
1788 (void) vm_call_method(m, NULL, oa);
1790 /* exception occurred? */
1792 if (exceptions_get_exception()) {
1793 exceptions_print_stacktrace();
1797 /* unload the JavaVM */
1799 (void) vm_destroy(vm);
1807 /* vm_destroy ******************************************************************
1809 Unloads a Java VM and reclaims its resources.
1811 *******************************************************************************/
1813 s4 vm_destroy(JavaVM *vm)
1815 #if defined(ENABLE_THREADS)
1816 threads_join_all_threads();
1819 /* everything's ok */
1825 /* vm_exit *********************************************************************
1827 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1829 *******************************************************************************/
1831 void vm_exit(s4 status)
1835 /* signal that we are exiting */
1839 assert(class_java_lang_System);
1840 assert(class_java_lang_System->state & CLASS_LOADED);
1842 #if defined(ENABLE_JVMTI)
1843 if (jvmti || (dbgcom!=NULL)) {
1844 jvmti_set_phase(JVMTI_PHASE_DEAD);
1845 if (jvmti) jvmti_agentunload();
1849 if (!link_class(class_java_lang_System)) {
1850 exceptions_print_stacktrace();
1854 /* call java.lang.System.exit(I)V */
1856 m = class_resolveclassmethod(class_java_lang_System,
1857 utf_new_char("exit"),
1859 class_java_lang_Object,
1863 exceptions_print_stacktrace();
1867 /* call the exit function with passed exit status */
1869 (void) vm_call_method(m, NULL, status);
1871 /* If we had an exception, just ignore the exception and exit with
1874 vm_shutdown(status);
1878 /* vm_shutdown *****************************************************************
1880 Terminates the system immediately without freeing memory explicitly
1881 (to be used only for abnormal termination).
1883 *******************************************************************************/
1885 void vm_shutdown(s4 status)
1888 #if defined(ENABLE_STATISTICS)
1889 || opt_getcompilingtime || opt_stat
1893 log_text("CACAO terminated by shutdown");
1894 dolog("Exit status: %d\n", (s4) status);
1898 #if defined(ENABLE_JVMTI)
1899 /* terminate cacaodbgserver */
1901 pthread_mutex_lock(&dbgcomlock);
1903 pthread_mutex_unlock(&dbgcomlock);
1904 jvmti_cacaodbgserver_quit();
1912 /* vm_exit_handler *************************************************************
1914 The exit_handler function is called upon program termination.
1916 ATTENTION: Don't free system resources here! Some threads may still
1917 be running as this is called from VMRuntime.exit(). The OS does the
1920 *******************************************************************************/
1922 void vm_exit_handler(void)
1924 #if !defined(NDEBUG)
1926 class_showmethods(mainclass);
1928 if (showconstantpool)
1929 class_showconstantpool(mainclass);
1934 # if defined(ENABLE_PROFILING)
1936 profile_printstats();
1938 #endif /* !defined(NDEBUG) */
1940 #if defined(ENABLE_RT_TIMING)
1941 rt_timing_print_time_stats(stderr);
1944 #if defined(ENABLE_CYCLES_STATS)
1945 builtin_print_cycles_stats(stderr);
1946 stacktrace_print_cycles_stats(stderr);
1950 #if defined(ENABLE_STATISTICS)
1951 || opt_getcompilingtime || opt_stat
1955 log_text("CACAO terminated");
1957 #if defined(ENABLE_STATISTICS)
1960 #ifdef TYPECHECK_STATISTICS
1961 typecheck_print_statistics(get_logfile());
1965 if (opt_getcompilingtime)
1967 #endif /* defined(ENABLE_STATISTICS) */
1969 /* vm_print_profile(stderr);*/
1973 /* vm_abort ********************************************************************
1975 Prints an error message and aborts the VM.
1977 *******************************************************************************/
1979 void vm_abort(const char *text, ...)
1983 /* print the log message */
1988 log_vprint(text, ap);
1993 /* now abort the VM */
1999 /* vm_get_mainclass_from_jar ***************************************************
2001 Gets the name of the main class from a JAR's manifest file.
2003 *******************************************************************************/
2005 static char *vm_get_mainclass_from_jar(char *mainstring)
2008 java_objectheader *o;
2010 java_objectheader *s;
2012 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(mainstring);
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", mainstring);
2069 /* get Main Attributes */
2071 m = class_resolveclassmethod(o->vftbl->class,
2072 utf_new_char("getMainAttributes"),
2073 utf_new_char("()Ljava/util/jar/Attributes;"),
2074 class_java_lang_Object,
2078 exceptions_print_stacktrace();
2082 o = vm_call_method(m, o);
2085 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2090 /* get property Main-Class */
2092 m = class_resolveclassmethod(o->vftbl->class,
2093 utf_new_char("getValue"),
2094 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2095 class_java_lang_Object,
2099 exceptions_print_stacktrace();
2103 s = javastring_new_from_ascii("Main-Class");
2105 o = vm_call_method(m, o, s);
2108 exceptions_print_stacktrace();
2112 return javastring_tochar(o);
2116 /* vm_compile_all **************************************************************
2118 Compile all methods found in the bootclasspath.
2120 *******************************************************************************/
2122 #if !defined(NDEBUG)
2123 static void vm_compile_all(void)
2128 classcache_name_entry *nmen;
2129 classcache_class_entry *clsen;
2132 /* create all classes found in the bootclasspath */
2133 /* XXX currently only works with zip/jar's */
2135 loader_load_all_classes();
2137 /* link all classes */
2139 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2140 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2142 for (; nmen; nmen = nmen->hashlink) {
2143 /* iterate over all class entries */
2145 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2146 c = clsen->classobj;
2151 if (!(c->state & CLASS_LINKED)) {
2152 if (!link_class(c)) {
2153 fprintf(stderr, "Error linking: ");
2154 utf_fprint_printable_ascii_classname(stderr, c->name);
2155 fprintf(stderr, "\n");
2157 /* print out exception and cause */
2159 exceptions_print_current_exception();
2161 /* goto next class */
2167 /* compile all class methods */
2169 for (i = 0; i < c->methodscount; i++) {
2170 m = &(c->methods[i]);
2172 if (m->jcode != NULL) {
2173 if (!jit_compile(m)) {
2174 fprintf(stderr, "Error compiling: ");
2175 utf_fprint_printable_ascii_classname(stderr, c->name);
2176 fprintf(stderr, ".");
2177 utf_fprint_printable_ascii(stderr, m->name);
2178 utf_fprint_printable_ascii(stderr, m->descriptor);
2179 fprintf(stderr, "\n");
2181 /* print out exception and cause */
2183 exceptions_print_current_exception();
2191 #endif /* !defined(NDEBUG) */
2194 /* vm_compile_method ***********************************************************
2196 Compile a specific method.
2198 *******************************************************************************/
2200 #if !defined(NDEBUG)
2201 static void vm_compile_method(void)
2205 /* create, load and link the main class */
2207 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2209 if (mainclass == NULL)
2210 exceptions_print_stacktrace();
2212 if (!link_class(mainclass))
2213 exceptions_print_stacktrace();
2215 if (opt_signature != NULL) {
2216 m = class_resolveclassmethod(mainclass,
2217 utf_new_char(opt_method),
2218 utf_new_char(opt_signature),
2223 m = class_resolveclassmethod(mainclass,
2224 utf_new_char(opt_method),
2231 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2232 opt_method, opt_signature ? opt_signature : "");
2236 #endif /* !defined(NDEBUG) */
2239 /* vm_vmargs_from_valist *******************************************************
2243 *******************************************************************************/
2245 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2246 vm_arg *vmargs, va_list ap)
2248 typedesc *paramtypes;
2251 paramtypes = m->parseddesc->paramtypes;
2253 /* if method is non-static fill first block and skip `this' pointer */
2258 /* the `this' pointer */
2259 vmargs[0].type = TYPE_ADR;
2260 vmargs[0].data.l = (u8) (ptrint) o;
2266 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2267 switch (paramtypes->decltype) {
2268 /* primitive types */
2269 case PRIMITIVETYPE_BOOLEAN:
2270 case PRIMITIVETYPE_BYTE:
2271 case PRIMITIVETYPE_CHAR:
2272 case PRIMITIVETYPE_SHORT:
2273 case PRIMITIVETYPE_INT:
2274 vmargs[i].type = TYPE_INT;
2275 vmargs[i].data.l = (s8) va_arg(ap, s4);
2278 case PRIMITIVETYPE_LONG:
2279 vmargs[i].type = TYPE_LNG;
2280 vmargs[i].data.l = (s8) va_arg(ap, s8);
2283 case PRIMITIVETYPE_FLOAT:
2284 vmargs[i].type = TYPE_FLT;
2285 #if defined(__ALPHA__)
2286 /* this keeps the assembler function much simpler */
2288 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2290 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2294 case PRIMITIVETYPE_DOUBLE:
2295 vmargs[i].type = TYPE_DBL;
2296 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2300 vmargs[i].type = TYPE_ADR;
2301 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2308 /* vm_vmargs_from_jvalue *******************************************************
2312 *******************************************************************************/
2314 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2315 vm_arg *vmargs, jvalue *args)
2317 typedesc *paramtypes;
2321 paramtypes = m->parseddesc->paramtypes;
2323 /* if method is non-static fill first block and skip `this' pointer */
2328 /* the `this' pointer */
2329 vmargs[0].type = TYPE_ADR;
2330 vmargs[0].data.l = (u8) (ptrint) o;
2336 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2337 switch (paramtypes->decltype) {
2338 /* primitive types */
2339 case PRIMITIVETYPE_BOOLEAN:
2340 case PRIMITIVETYPE_BYTE:
2341 case PRIMITIVETYPE_CHAR:
2342 case PRIMITIVETYPE_SHORT:
2343 case PRIMITIVETYPE_INT:
2344 vmargs[i].type = TYPE_INT;
2345 vmargs[i].data.l = (s8) args[j].i;
2348 case PRIMITIVETYPE_LONG:
2349 vmargs[i].type = TYPE_LNG;
2350 vmargs[i].data.l = (s8) args[j].j;
2353 case PRIMITIVETYPE_FLOAT:
2354 vmargs[i].type = TYPE_FLT;
2355 #if defined(__ALPHA__)
2356 /* this keeps the assembler function much simpler */
2358 vmargs[i].data.d = (jdouble) args[j].f;
2360 vmargs[i].data.f = args[j].f;
2364 case PRIMITIVETYPE_DOUBLE:
2365 vmargs[i].type = TYPE_DBL;
2366 vmargs[i].data.d = args[j].d;
2370 vmargs[i].type = TYPE_ADR;
2371 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2378 /* vm_call_method **************************************************************
2380 Calls a Java method with a variable number of arguments and returns
2383 *******************************************************************************/
2385 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2388 java_objectheader *ro;
2391 ro = vm_call_method_valist(m, o, ap);
2398 /* vm_call_method_valist *******************************************************
2400 Calls a Java method with a variable number of arguments, passed via
2401 a va_list, and returns an address.
2403 *******************************************************************************/
2405 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2410 java_objectheader *ro;
2413 /* mark start of dump memory area */
2415 dumpsize = dump_size();
2417 /* get number of Java method arguments */
2419 vmargscount = m->parseddesc->paramcount;
2421 /* allocate vm_arg array */
2423 vmargs = DMNEW(vm_arg, vmargscount);
2425 /* fill the vm_arg array from a va_list */
2427 vm_vmargs_from_valist(m, o, vmargs, ap);
2429 /* call the Java method */
2431 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2433 /* release dump area */
2435 dump_release(dumpsize);
2441 /* vm_call_method_jvalue *******************************************************
2443 Calls a Java method with a variable number of arguments, passed via
2444 a jvalue array, and returns an address.
2446 *******************************************************************************/
2448 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2453 java_objectheader *ro;
2456 /* mark start of dump memory area */
2458 dumpsize = dump_size();
2460 /* get number of Java method arguments */
2462 vmargscount = m->parseddesc->paramcount;
2464 /* allocate vm_arg array */
2466 vmargs = DMNEW(vm_arg, vmargscount);
2468 /* fill the vm_arg array from a va_list */
2470 vm_vmargs_from_jvalue(m, o, vmargs, args);
2472 /* call the Java method */
2474 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2476 /* release dump area */
2478 dump_release(dumpsize);
2484 /* vm_call_method_vmarg ********************************************************
2486 Calls a Java method with a variable number of arguments, passed via
2487 a vm_arg array, and returns an address.
2489 *******************************************************************************/
2491 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2494 java_objectheader *o;
2496 #if defined(ENABLE_JIT)
2497 # if defined(ENABLE_INTRP)
2499 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2502 o = asm_vm_call_method(m, vmargscount, vmargs);
2504 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2511 /* vm_call_method_int **********************************************************
2513 Calls a Java method with a variable number of arguments and returns
2516 *******************************************************************************/
2518 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2524 i = vm_call_method_int_valist(m, o, ap);
2531 /* vm_call_method_int_valist ***************************************************
2533 Calls a Java method with a variable number of arguments, passed via
2534 a va_list, and returns an integer (s4).
2536 *******************************************************************************/
2538 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2545 /* mark start of dump memory area */
2547 dumpsize = dump_size();
2549 /* get number of Java method arguments */
2551 vmargscount = m->parseddesc->paramcount;
2553 /* allocate vm_arg array */
2555 vmargs = DMNEW(vm_arg, vmargscount);
2557 /* fill the vm_arg array from a va_list */
2559 vm_vmargs_from_valist(m, o, vmargs, ap);
2561 /* call the Java method */
2563 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2565 /* release dump area */
2567 dump_release(dumpsize);
2573 /* vm_call_method_int_jvalue ***************************************************
2575 Calls a Java method with a variable number of arguments, passed via
2576 a jvalue array, and returns an integer (s4).
2578 *******************************************************************************/
2580 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2587 /* mark start of dump memory area */
2589 dumpsize = dump_size();
2591 /* get number of Java method arguments */
2593 vmargscount = m->parseddesc->paramcount;
2595 /* allocate vm_arg array */
2597 vmargs = DMNEW(vm_arg, vmargscount);
2599 /* fill the vm_arg array from a va_list */
2601 vm_vmargs_from_jvalue(m, o, vmargs, args);
2603 /* call the Java method */
2605 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2607 /* release dump area */
2609 dump_release(dumpsize);
2615 /* vm_call_method_int_vmarg ****************************************************
2617 Calls a Java method with a variable number of arguments, passed via
2618 a vm_arg array, and returns an integer (s4).
2620 *******************************************************************************/
2622 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2626 #if defined(ENABLE_JIT)
2627 # if defined(ENABLE_INTRP)
2629 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2632 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2634 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2641 /* vm_call_method_long *********************************************************
2643 Calls a Java method with a variable number of arguments and returns
2646 *******************************************************************************/
2648 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2654 l = vm_call_method_long_valist(m, o, ap);
2661 /* vm_call_method_long_valist **************************************************
2663 Calls a Java method with a variable number of arguments, passed via
2664 a va_list, and returns a long (s8).
2666 *******************************************************************************/
2668 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2675 /* mark start of dump memory area */
2677 dumpsize = dump_size();
2679 /* get number of Java method arguments */
2681 vmargscount = m->parseddesc->paramcount;
2683 /* allocate vm_arg array */
2685 vmargs = DMNEW(vm_arg, vmargscount);
2687 /* fill the vm_arg array from a va_list */
2689 vm_vmargs_from_valist(m, o, vmargs, ap);
2691 /* call the Java method */
2693 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2695 /* release dump area */
2697 dump_release(dumpsize);
2703 /* vm_call_method_long_jvalue **************************************************
2705 Calls a Java method with a variable number of arguments, passed via
2706 a jvalue array, and returns a long (s8).
2708 *******************************************************************************/
2710 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2717 /* mark start of dump memory area */
2719 dumpsize = dump_size();
2721 /* get number of Java method arguments */
2723 vmargscount = m->parseddesc->paramcount;
2725 /* allocate vm_arg array */
2727 vmargs = DMNEW(vm_arg, vmargscount);
2729 /* fill the vm_arg array from a va_list */
2731 vm_vmargs_from_jvalue(m, o, vmargs, args);
2733 /* call the Java method */
2735 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2737 /* release dump area */
2739 dump_release(dumpsize);
2745 /* vm_call_method_long_vmarg ***************************************************
2747 Calls a Java method with a variable number of arguments, passed via
2748 a vm_arg array, and returns a long (s8).
2750 *******************************************************************************/
2752 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2756 #if defined(ENABLE_JIT)
2757 # if defined(ENABLE_INTRP)
2759 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2762 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2764 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2771 /* vm_call_method_float ********************************************************
2773 Calls a Java method with a variable number of arguments and returns
2776 *******************************************************************************/
2778 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2784 f = vm_call_method_float_valist(m, o, ap);
2791 /* vm_call_method_float_valist *************************************************
2793 Calls a Java method with a variable number of arguments, passed via
2794 a va_list, and returns a float.
2796 *******************************************************************************/
2798 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2806 /* mark start of dump memory area */
2808 dumpsize = dump_size();
2810 /* get number of Java method arguments */
2812 vmargscount = m->parseddesc->paramcount;
2814 /* allocate vm_arg array */
2816 vmargs = DMNEW(vm_arg, vmargscount);
2818 /* fill the vm_arg array from a va_list */
2820 vm_vmargs_from_valist(m, o, vmargs, ap);
2822 /* call the Java method */
2824 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2826 /* release dump area */
2828 dump_release(dumpsize);
2834 /* vm_call_method_float_jvalue *************************************************
2836 Calls a Java method with a variable number of arguments, passed via
2837 a jvalue array, and returns a float.
2839 *******************************************************************************/
2841 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2849 /* mark start of dump memory area */
2851 dumpsize = dump_size();
2853 /* get number of Java method arguments */
2855 vmargscount = m->parseddesc->paramcount;
2857 /* allocate vm_arg array */
2859 vmargs = DMNEW(vm_arg, vmargscount);
2861 /* fill the vm_arg array from a va_list */
2863 vm_vmargs_from_jvalue(m, o, vmargs, args);
2865 /* call the Java method */
2867 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2869 /* release dump area */
2871 dump_release(dumpsize);
2877 /* vm_call_method_float_vmarg **************************************************
2879 Calls a Java method with a variable number of arguments and returns
2882 *******************************************************************************/
2884 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2888 #if defined(ENABLE_JIT)
2889 # if defined(ENABLE_INTRP)
2891 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2894 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2896 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2903 /* vm_call_method_double *******************************************************
2905 Calls a Java method with a variable number of arguments and returns
2908 *******************************************************************************/
2910 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2916 d = vm_call_method_double_valist(m, o, ap);
2923 /* vm_call_method_double_valist ************************************************
2925 Calls a Java method with a variable number of arguments, passed via
2926 a va_list, and returns a double.
2928 *******************************************************************************/
2930 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2938 /* mark start of dump memory area */
2940 dumpsize = dump_size();
2942 /* get number of Java method arguments */
2944 vmargscount = m->parseddesc->paramcount;
2946 /* allocate vm_arg array */
2948 vmargs = DMNEW(vm_arg, vmargscount);
2950 /* fill the vm_arg array from a va_list */
2952 vm_vmargs_from_valist(m, o, vmargs, ap);
2954 /* call the Java method */
2956 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2958 /* release dump area */
2960 dump_release(dumpsize);
2966 /* vm_call_method_double_jvalue ************************************************
2968 Calls a Java method with a variable number of arguments, passed via
2969 a jvalue array, and returns a double.
2971 *******************************************************************************/
2973 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2981 /* mark start of dump memory area */
2983 dumpsize = dump_size();
2985 /* get number of Java method arguments */
2987 vmargscount = m->parseddesc->paramcount;
2989 /* allocate vm_arg array */
2991 vmargs = DMNEW(vm_arg, vmargscount);
2993 /* fill the vm_arg array from a va_list */
2995 vm_vmargs_from_jvalue(m, o, vmargs, args);
2997 /* call the Java method */
2999 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
3001 /* release dump area */
3003 dump_release(dumpsize);
3009 /* vm_call_method_double_vmarg *************************************************
3011 Calls a Java method with a variable number of arguments and returns
3014 *******************************************************************************/
3016 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
3021 #if defined(ENABLE_JIT)
3022 # if defined(ENABLE_INTRP)
3024 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3027 d = asm_vm_call_method_double(m, vmargscount, vmargs);
3029 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3037 * These are local overrides for various environment variables in Emacs.
3038 * Please do not remove this and leave it at the end of the file, where
3039 * Emacs will automagically detect them.
3040 * ---------------------------------------------------------------------
3043 * indent-tabs-mode: t