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_Class.h"
49 #include "native/include/java_lang_String.h"
51 #if defined(ENABLE_THREADS)
52 # include "threads/native/threads.h"
55 #include "toolbox/logging.h"
57 #include "vm/builtin.h"
58 #include "vm/exceptions.h"
59 #include "vm/finalizer.h"
60 #include "vm/global.h"
61 #include "vm/initialize.h"
62 #include "vm/properties.h"
63 #include "vm/signallocal.h"
64 #include "vm/stringlocal.h"
67 #include "vm/jit/jit.h"
68 #include "vm/jit/md.h"
69 #include "vm/jit/asmpart.h"
71 #if defined(ENABLE_PROFILING)
72 # include "vm/jit/optimizing/profile.h"
75 #include "vm/jit/optimizing/recompile.h"
77 #include "vmcore/classcache.h"
78 #include "vmcore/options.h"
79 #include "vmcore/suck.h"
81 #if defined(ENABLE_JVMTI)
82 # include "native/jvmti/cacaodbg.h"
86 /* Invocation API variables ***************************************************/
88 _Jv_JavaVM *_Jv_jvm; /* denotes a Java VM */
89 _Jv_JNIEnv *_Jv_env; /* pointer to native method interface */
92 /* global variables ***********************************************************/
94 s4 vms = 0; /* number of VMs created */
96 bool vm_initializing = false;
97 bool vm_exiting = false;
99 char *cacao_prefix = NULL;
100 char *cacao_libjvm = NULL;
101 char *classpath_libdir = NULL;
103 char *_Jv_bootclasspath; /* contains the boot classpath */
104 char *_Jv_classpath; /* contains the classpath */
105 char *_Jv_java_library_path;
107 char *mainstring = NULL;
108 classinfo *mainclass = NULL;
110 char *specificmethodname = NULL;
111 char *specificsignature = NULL;
115 #if defined(ENABLE_INTRP)
116 u1 *intrp_main_stack = NULL;
120 /* define heap sizes **********************************************************/
122 #define HEAP_MAXSIZE 128 * 1024 * 1024 /* default 128MB */
123 #define HEAP_STARTSIZE 2 * 1024 * 1024 /* default 2MB */
124 #define STACK_SIZE 64 * 1024 /* default 64kB */
127 /* define command line options ************************************************/
155 /* Java non-standard options */
166 #if defined(ENABLE_PROFILING)
179 #if defined(ENABLE_STATISTICS)
196 #if defined(ENABLE_VERIFIER)
198 #if defined(TYPECHECK_VERBOSE)
201 #endif /* defined(ENABLE_VERIFIER) */
204 /* optimization options */
206 #if defined(ENABLE_LOOP)
210 #if defined(ENABLE_IFCONV)
214 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
218 #if defined(ENABLE_INLINING)
223 #if defined(ENABLE_INLINING_DEBUG)
224 OPT_INLINE_DEBUG_ALL,
225 OPT_INLINE_DEBUG_END,
226 OPT_INLINE_DEBUG_MIN,
227 OPT_INLINE_DEBUG_MAX,
228 OPT_INLINE_REPLACE_VERBOSE,
229 OPT_INLINE_REPLACE_VERBOSE2,
230 #endif /* defined(ENABLE_INLINING_DEBUG) */
231 #endif /* defined(ENABLE_INLINING) */
233 #if defined(ENABLE_INTRP)
234 /* interpreter options */
257 opt_struct opts[] = {
258 { "foo", false, OPT_FOO },
262 { "jar", false, OPT_JAR },
264 { "d32", false, OPT_D32 },
265 { "d64", false, OPT_D64 },
266 { "client", false, OPT_IGNORE },
267 { "server", false, OPT_IGNORE },
268 { "jvm", false, OPT_IGNORE },
269 { "hotspot", false, OPT_IGNORE },
271 { "classpath", true, OPT_CLASSPATH },
272 { "cp", true, OPT_CLASSPATH },
273 { "D", true, OPT_D },
274 { "version", false, OPT_VERSION },
275 { "showversion", false, OPT_SHOWVERSION },
276 { "fullversion", false, OPT_FULLVERSION },
277 { "help", false, OPT_HELP },
278 { "?", false, OPT_HELP },
279 { "X", false, OPT_X },
280 { "XX", false, OPT_XX },
282 { "esa", false, OPT_ESA },
283 { "enablesystemassertions", false, OPT_ESA },
284 { "dsa", false, OPT_DSA },
285 { "disablesystemassertions", false, OPT_DSA },
287 { "noasyncgc", false, OPT_IGNORE },
288 #if defined(ENABLE_VERIFIER)
289 { "noverify", false, OPT_NOVERIFY },
291 { "v", false, OPT_VERBOSE1 },
292 { "verbose:", true, OPT_VERBOSE },
294 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
295 { "verbosetc", false, OPT_VERBOSETC },
297 #if defined(__ALPHA__)
298 { "noieee", false, OPT_NOIEEE },
300 #if defined(ENABLE_STATISTICS)
301 { "time", false, OPT_TIME },
302 { "stat", false, OPT_STAT },
304 { "log", true, OPT_LOG },
305 { "c", true, OPT_CHECK },
306 { "l", false, OPT_LOAD },
307 { "eager", false, OPT_EAGER },
310 { "all", false, OPT_ALL },
311 { "sig", true, OPT_SIGNATURE },
314 #if defined(ENABLE_LOOP)
315 { "oloop", false, OPT_OLOOP },
317 #if defined(ENABLE_IFCONV)
318 { "ifconv", false, OPT_IFCONV },
320 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
321 { "lsra", false, OPT_LSRA },
324 #if defined(ENABLE_INTRP)
325 /* interpreter options */
327 { "trace", false, OPT_TRACE },
328 { "static-supers", true, OPT_STATIC_SUPERS },
329 { "no-dynamic", false, OPT_NO_DYNAMIC },
330 { "no-replication", false, OPT_NO_REPLICATION },
331 { "no-quicksuper", false, OPT_NO_QUICKSUPER },
334 /* JVMTI Agent Command Line Options */
336 { "agentlib:", true, OPT_AGENTLIB },
337 { "agentpath:", true, OPT_AGENTPATH },
340 /* Java non-standard options */
342 { "Xjit", false, OPT_JIT },
343 { "Xint", false, OPT_INTRP },
344 { "Xbootclasspath:", true, OPT_BOOTCLASSPATH },
345 { "Xbootclasspath/a:", true, OPT_BOOTCLASSPATH_A },
346 { "Xbootclasspath/p:", true, OPT_BOOTCLASSPATH_P },
347 { "Xbootclasspath/c:", true, OPT_BOOTCLASSPATH_C },
350 { "Xdebug", false, OPT_DEBUG },
351 { "Xnoagent", false, OPT_NOAGENT },
352 { "Xrunjdwp", true, OPT_XRUNJDWP },
355 { "Xms", true, OPT_MS },
356 { "ms", true, OPT_MS },
357 { "Xmx", true, OPT_MX },
358 { "mx", true, OPT_MX },
359 { "Xss", true, OPT_SS },
360 { "ss", true, OPT_SS },
362 #if defined(ENABLE_PROFILING)
363 { "Xprof:", true, OPT_PROF_OPTION },
364 { "Xprof", false, OPT_PROF },
367 /* inlining options */
369 #if defined(ENABLE_INLINING)
370 #if defined(ENABLE_INLINING_DEBUG)
371 { "ia", false, OPT_INLINE_DEBUG_ALL },
372 { "ii", true, OPT_INLINE_DEBUG_MIN },
373 { "im", true, OPT_INLINE_DEBUG_MAX },
374 { "ie", true, OPT_INLINE_DEBUG_END },
375 { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
376 { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
377 #endif /* defined(ENABLE_INLINING_DEBUG) */
379 { "il", false, OPT_INLINE_LOG },
381 { "i", false, OPT_INLINING },
382 #endif /* defined(ENABLE_INLINING) */
384 /* keep these at the end of the list */
387 { "m", true, OPT_METHOD },
390 { "s", true, OPT_SHOW },
391 { "debug-color", false, OPT_DEBUGCOLOR },
397 /* usage ***********************************************************************
399 Prints the correct usage syntax to stdout.
401 *******************************************************************************/
405 puts("Usage: cacao [-options] classname [arguments]");
406 puts(" (to run a class file)");
407 puts(" or cacao [-options] -jar jarfile [arguments]");
408 puts(" (to run a standalone jar file)\n");
410 puts("where options include:");
411 puts(" -d32 use 32-bit data model if available");
412 puts(" -d64 use 64-bit data model if available");
413 puts(" -client compatibility (currently ignored)");
414 puts(" -server compatibility (currently ignored)");
415 puts(" -jvm compatibility (currently ignored)");
416 puts(" -hotspot compatibility (currently ignored)\n");
418 puts(" -cp <path> specify a path to look for classes");
419 puts(" -classpath <path> specify a path to look for classes");
420 puts(" -D<name>=<value> add an entry to the property list");
421 puts(" -verbose[:class|gc|jni] enable specific verbose output");
422 puts(" -version print product version and exit");
423 puts(" -fullversion print jpackage-compatible product version and exit");
424 puts(" -showversion print product version and continue");
425 puts(" -help, -? print this help message");
426 puts(" -X print help on non-standard Java options");
427 puts(" -XX print help on CACAO options");
428 puts(" -esa | -enablesystemassertions");
429 puts(" enable system assertions");
430 puts(" -dsa | -disablesystemassertions");
431 puts(" disable system assertions");
434 puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
435 puts (" for jdwp help use: -agentlib:jdwp=help");
436 puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
439 /* exit with error code */
445 static void Xusage(void)
447 #if defined(ENABLE_JIT)
448 puts(" -Xjit JIT mode execution (default)");
450 #if defined(ENABLE_INTRP)
451 puts(" -Xint interpreter mode execution");
453 puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
454 puts(" value is set as bootstrap class path");
455 puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
456 puts(" value is appended to the bootstrap class path");
457 puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
458 puts(" value is prepended to the bootstrap class path");
459 puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
460 puts(" value is used as Java core library, but the");
461 puts(" hardcoded VM interface classes are prepended");
462 printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
463 printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
464 printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
466 #if defined(ENABLE_PROFILING)
467 puts(" -Xprof[:bb] collect and print profiling data");
470 #if defined(ENABLE_JVMTI)
471 /* -Xdebug option depend on gnu classpath JDWP options. options:
472 transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
473 puts(" -Xdebug enable remote debugging\n");
474 puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
475 puts(" enable remote debugging\n");
478 /* exit with error code */
484 static void XXusage(void)
486 puts(" -v write state-information");
488 puts(" -verbose[:call|exception|jit|memory]");
489 puts(" enable specific verbose output");
490 puts(" -debug-color colored output for ANSI terms");
492 #ifdef TYPECHECK_VERBOSE
493 puts(" -verbosetc write debug messages while typechecking");
495 #if defined(__ALPHA__)
496 puts(" -noieee don't use ieee compliant arithmetic");
498 #if defined(ENABLE_VERIFIER)
499 puts(" -noverify don't verify classfiles");
501 #if defined(ENABLE_STATISTICS)
502 puts(" -time measure the runtime");
503 puts(" -stat detailed compiler statistics");
505 puts(" -log logfile specify a name for the logfile");
506 puts(" -c(heck)b(ounds) don't check array bounds");
507 puts(" s(ync) don't check for synchronization");
508 #if defined(ENABLE_LOOP)
509 puts(" -oloop optimize array accesses in loops");
511 puts(" -l don't start the class after loading");
512 puts(" -eager perform eager class loading and linking");
514 puts(" -all compile all methods, no execution");
515 puts(" -m compile only a specific method");
516 puts(" -sig specify signature for a specific method");
519 puts(" -s... show...");
520 puts(" (c)onstants the constant pool");
521 puts(" (m)ethods class fields and methods");
522 puts(" (u)tf the utf - hash");
523 puts(" (i)ntermediate intermediate representation");
524 #if defined(ENABLE_DISASSEMBLER)
525 puts(" (a)ssembler disassembled listing");
526 puts(" n(o)ps show NOPs in disassembler output");
527 puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
528 puts(" (n)ative disassembled native stubs");
530 puts(" (d)atasegment data segment listing");
532 #if defined(ENABLE_INLINING)
533 puts(" -i activate inlining");
535 puts(" -il log inlining");
537 #if defined(ENABLE_INLINING_DEBUG)
538 puts(" -ia use inlining for all methods");
539 puts(" -ii <size> set minimum size for inlined result");
540 puts(" -im <size> set maximum size for inlined result");
541 puts(" -ie <number> stop inlining after the given number of roots");
542 puts(" -ir log on-stack replacement");
543 puts(" -iR log on-stack replacement, more verbose");
544 #endif /* defined(ENABLE_INLINING_DEBUG) */
545 #endif /* defined(ENABLE_INLINING) */
547 #if defined(ENABLE_IFCONV)
548 puts(" -ifconv use if-conversion");
550 #if defined(ENABLE_LSRA)
551 puts(" -lsra use linear scan register allocation");
553 #if defined(ENABLE_SSA)
554 puts(" -lsra use linear scan register allocation (with SSA)");
557 /* exit with error code */
563 /* version *********************************************************************
565 Only prints cacao version information.
567 *******************************************************************************/
569 static void version(bool opt_exit)
571 puts("java version \""JAVA_VERSION"\"");
572 puts("CACAO version "VERSION"");
574 puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
575 puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
576 puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
577 puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
579 puts("This program is free software; you can redistribute it and/or");
580 puts("modify it under the terms of the GNU General Public License as");
581 puts("published by the Free Software Foundation; either version 2, or (at");
582 puts("your option) any later version.\n");
584 puts("This program is distributed in the hope that it will be useful, but");
585 puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
586 puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
587 puts("General Public License for more details.\n");
589 puts("Configure/Build options:\n");
590 puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
591 #if defined(__VERSION__)
592 puts(" CC : "VERSION_CC" ("__VERSION__")");
594 puts(" CC : "VERSION_CC"");
596 puts(" CFLAGS : "VERSION_CFLAGS"\n");
598 puts("Default variables:\n");
599 printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
600 printf(" initial heap size : %d\n", HEAP_STARTSIZE);
601 printf(" stack size : %d\n", STACK_SIZE);
602 #if defined(WITH_CLASSPATH_GNU)
603 puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
605 puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
607 puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
609 puts("Runtime variables:\n");
610 printf(" maximum heap size : %d\n", opt_heapmaxsize);
611 printf(" initial heap size : %d\n", opt_heapstartsize);
612 printf(" stack size : %d\n", opt_stacksize);
613 printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
614 printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
615 printf(" java.class.path : %s\n", _Jv_classpath);
617 /* exit normally, if requested */
624 /* fullversion *****************************************************************
626 Prints a Sun compatible version information (required e.g. by
627 jpackage, www.jpackage.org).
629 *******************************************************************************/
631 static void fullversion(void)
633 puts("java full version \"cacao-"JAVA_VERSION"\"");
641 /* forward declarations *******************************************************/
643 static char *vm_get_mainclass_from_jar(char *mainstring);
645 static void vm_compile_all(void);
646 static void vm_compile_method(void);
650 /* vm_createjvm ****************************************************************
652 Implementation for JNI_CreateJavaVM.
654 *******************************************************************************/
656 bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
658 JavaVMInitArgs *_vm_args;
662 /* get the arguments for the new JVM */
664 _vm_args = (JavaVMInitArgs *) vm_args;
666 /* get the VM and Env tables (must be set before vm_create) */
668 env = NEW(_Jv_JNIEnv);
670 #if defined(ENABLE_JNI)
671 env->env = &_Jv_JNINativeInterface;
674 /* XXX Set the global variable. Maybe we should do that differently. */
678 /* create and fill a JavaVM structure */
680 vm = NEW(_Jv_JavaVM);
682 #if defined(ENABLE_JNI)
683 vm->functions = &_Jv_JNIInvokeInterface;
686 /* XXX Set the global variable. Maybe we should do that differently. */
687 /* XXX JVMTI Agents needs a JavaVM */
691 /* actually create the JVM */
693 if (!vm_create(_vm_args))
696 #if defined(ENABLE_JNI)
697 /* setup the local ref table (must be created after vm_create) */
699 if (!jni_init_localref_table())
703 /* now return the values */
705 *p_vm = (JavaVM *) vm;
706 *p_env = (void *) env;
711 /* release allocated memory */
713 FREE(env, _Jv_JNIEnv);
714 FREE(vm, _Jv_JavaVM);
720 /* vm_create *******************************************************************
722 Creates a JVM. Called by vm_createjvm.
724 *******************************************************************************/
726 bool vm_create(JavaVMInitArgs *vm_args)
735 #if defined(ENABLE_JVMTI)
737 char *libname, *agentarg;
738 bool jdwp,agentbypath;
739 jdwp = agentbypath = false;
742 /* check the JNI version requested */
744 switch (vm_args->version) {
745 case JNI_VERSION_1_1:
747 case JNI_VERSION_1_2:
748 case JNI_VERSION_1_4:
754 /* we only support 1 JVM instance */
759 if (atexit(vm_exit_handler))
760 vm_abort("atexit failed: %s\n", strerror(errno));
763 log_text("CACAO started -------------------------------------------------------");
765 /* We need to check if the actual size of a java.lang.Class object
766 is smaller or equal than the assumption made in
767 src/vmcore/class.h. */
769 if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
770 vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
772 /* set the VM starttime */
774 _Jv_jvm->starttime = builtin_currenttimemillis();
776 /* get stuff from the environment *****************************************/
778 #if defined(WITH_JRE_LAYOUT)
779 /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
781 cacao_prefix = MNEW(char, 4096);
783 if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
784 vm_abort("readlink failed: %s\n", strerror(errno));
786 /* get the path of the current executable */
788 cacao_prefix = dirname(cacao_prefix);
790 if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
791 vm_abort("libjvm name to long for buffer\n");
793 /* concatenate the library name */
795 strcat(cacao_prefix, "/..");
797 /* now set path to libjvm.so */
799 len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
801 cacao_libjvm = MNEW(char, len);
802 strcpy(cacao_libjvm, cacao_prefix);
803 strcat(cacao_libjvm, "/lib/libjvm");
805 /* and finally set the path to GNU Classpath libraries */
807 len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
809 classpath_libdir = MNEW(char, len);
810 strcpy(classpath_libdir, cacao_prefix);
811 strcat(classpath_libdir, "/lib/classpath");
813 cacao_prefix = CACAO_PREFIX;
814 cacao_libjvm = CACAO_LIBDIR"/libjvm";
815 classpath_libdir = CLASSPATH_LIBDIR"/classpath";
818 /* set the bootclasspath */
820 cp = getenv("BOOTCLASSPATH");
823 _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
824 strcpy(_Jv_bootclasspath, cp);
827 #if defined(WITH_JRE_LAYOUT)
829 # if defined(WITH_CLASSPATH_GNU)
830 strlen(cacao_prefix) +
831 strlen("/share/cacao/vm.zip") +
834 strlen(cacao_prefix) +
835 strlen("/share/classpath/glibj.zip") +
838 _Jv_bootclasspath = MNEW(char, len);
839 # if defined(WITH_CLASSPATH_GNU)
840 strcat(_Jv_bootclasspath, cacao_prefix);
841 strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
842 strcat(_Jv_bootclasspath, ":");
844 strcat(_Jv_bootclasspath, cacao_prefix);
845 strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
848 # if defined(WITH_CLASSPATH_GNU)
849 strlen(CACAO_VM_ZIP) +
852 strlen(CLASSPATH_CLASSES) +
855 _Jv_bootclasspath = MNEW(char, len);
856 # if defined(WITH_CLASSPATH_GNU)
857 strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
858 strcat(_Jv_bootclasspath, ":");
860 strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
864 /* set the classpath */
866 cp = getenv("CLASSPATH");
869 _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
870 strcat(_Jv_classpath, cp);
873 _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
874 strcpy(_Jv_classpath, ".");
877 /* get and set java.library.path */
879 _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
881 if (_Jv_java_library_path == NULL)
882 _Jv_java_library_path = "";
884 /* interpret the options **************************************************/
891 opt_heapmaxsize = HEAP_MAXSIZE;
892 opt_heapstartsize = HEAP_STARTSIZE;
893 opt_stacksize = STACK_SIZE;
896 #if defined(ENABLE_JVMTI)
897 /* initialize JVMTI related **********************************************/
901 /* initialize and fill properties before command-line handling */
903 if (!properties_init())
904 vm_abort("properties_init failed");
906 /* iterate over all passed options */
908 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
922 #if SIZEOF_VOID_P == 8
923 puts("Running a 32-bit JVM is not supported on this platform.");
929 #if SIZEOF_VOID_P == 4
930 puts("Running a 64-bit JVM is not supported on this platform.");
936 /* forget old classpath and set the argument as new classpath */
937 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
939 _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
940 strcpy(_Jv_classpath, opt_arg);
944 for (i = 0; i < strlen(opt_arg); i++) {
945 if (opt_arg[i] == '=') {
947 properties_add(opt_arg, opt_arg + i + 1);
952 /* if no '=' is given, just create an empty property */
954 properties_add(opt_arg, "");
959 case OPT_BOOTCLASSPATH:
960 /* Forget default bootclasspath and set the argument as
961 new boot classpath. */
963 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
965 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
966 strcpy(_Jv_bootclasspath, opt_arg);
969 case OPT_BOOTCLASSPATH_A:
970 /* append to end of bootclasspath */
972 len = strlen(_Jv_bootclasspath);
974 _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
978 strlen(opt_arg) + strlen("0"));
980 strcat(_Jv_bootclasspath, ":");
981 strcat(_Jv_bootclasspath, opt_arg);
984 case OPT_BOOTCLASSPATH_P:
985 /* prepend in front of bootclasspath */
987 cp = _Jv_bootclasspath;
990 _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
993 strcpy(_Jv_bootclasspath, opt_arg);
994 strcat(_Jv_bootclasspath, ":");
995 strcat(_Jv_bootclasspath, cp);
997 MFREE(cp, char, len);
1000 case OPT_BOOTCLASSPATH_C:
1001 /* use as Java core library, but prepend VM interface classes */
1003 MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
1005 len = strlen(CACAO_VM_ZIP) +
1010 _Jv_bootclasspath = MNEW(char, len);
1012 strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
1013 strcat(_Jv_bootclasspath, ":");
1014 strcat(_Jv_bootclasspath, opt_arg);
1017 #if defined(ENABLE_JVMTI)
1019 /* this option exists only for compatibility reasons */
1023 /* I don't know yet what Xnoagent should do. This is only for
1024 compatiblity with eclipse - motse */
1033 strlen(CACAO_LIBDIR) +
1034 strlen("/libjdwp.so=") +
1038 agentarg = MNEW(char, len);
1040 strcpy(agentarg, CACAO_LIBDIR);
1041 strcat(agentarg, "/libjdwp.so=");
1042 strcat(agentarg, &opt_arg[1]);
1059 c = opt_arg[strlen(opt_arg) - 1];
1061 if ((c == 'k') || (c == 'K')) {
1062 j = atoi(opt_arg) * 1024;
1064 } else if ((c == 'm') || (c == 'M')) {
1065 j = atoi(opt_arg) * 1024 * 1024;
1071 opt_heapmaxsize = j;
1072 else if (opt == OPT_MS)
1073 opt_heapstartsize = j;
1084 if (strcmp("class", opt_arg) == 0) {
1085 opt_verboseclass = true;
1087 else if (strcmp("gc", opt_arg) == 0) {
1088 opt_verbosegc = true;
1090 else if (strcmp("jni", opt_arg) == 0) {
1091 opt_verbosejni = true;
1093 #if !defined(NDEBUG)
1094 else if (strcmp("call", opt_arg) == 0) {
1095 opt_verbosecall = true;
1097 else if (strcmp("exception", opt_arg) == 0) {
1098 opt_verboseexception = true;
1100 else if (strcmp("jit", opt_arg) == 0) {
1105 compileverbose = true;
1107 else if (strcmp("memory", opt_arg) == 0) {
1108 opt_verbosememory = true;
1110 # if defined(ENABLE_STATISTICS)
1111 /* we also need statistics */
1118 case OPT_DEBUGCOLOR:
1119 opt_debugcolor = true;
1122 #if defined(ENABLE_VERIFIER) && defined(TYPECHECK_VERBOSE)
1124 opt_typecheckverbose = true;
1133 case OPT_FULLVERSION:
1137 case OPT_SHOWVERSION:
1145 #if defined(ENABLE_VERIFIER)
1151 #if defined(ENABLE_STATISTICS)
1153 opt_getcompilingtime = true;
1154 opt_getloadingtime = true;
1167 for (i = 0; i < strlen(opt_arg); i++) {
1168 switch (opt_arg[i]) {
1170 checkbounds = false;
1183 makeinitializations = false;
1190 #if !defined(NDEBUG)
1194 makeinitializations = false;
1199 opt_method = opt_arg;
1200 makeinitializations = false;
1204 opt_signature = opt_arg;
1208 case OPT_SHOW: /* Display options */
1209 for (i = 0; i < strlen(opt_arg); i++) {
1210 switch (opt_arg[i]) {
1212 showconstantpool = true;
1224 opt_showintermediate = true;
1225 compileverbose = true;
1228 #if defined(ENABLE_DISASSEMBLER)
1230 opt_showdisassemble = true;
1231 compileverbose = true;
1235 opt_shownops = true;
1239 opt_showexceptionstubs = true;
1243 opt_shownativestub = true;
1248 opt_showddatasegment = true;
1257 #if defined(ENABLE_LOOP)
1263 #if defined(ENABLE_INLINING)
1264 #if defined(ENABLE_INLINING_DEBUG)
1265 case OPT_INLINE_DEBUG_ALL:
1266 opt_inline_debug_all = true;
1268 case OPT_INLINE_DEBUG_END:
1269 opt_inline_debug_end_counter = atoi(opt_arg);
1271 case OPT_INLINE_DEBUG_MIN:
1272 opt_inline_debug_min_size = atoi(opt_arg);
1274 case OPT_INLINE_DEBUG_MAX:
1275 opt_inline_debug_max_size = atoi(opt_arg);
1277 case OPT_INLINE_REPLACE_VERBOSE:
1278 opt_replace_verbose = 1;
1280 case OPT_INLINE_REPLACE_VERBOSE2:
1281 opt_replace_verbose = 2;
1283 #endif /* defined(ENABLE_INLINING_DEBUG) */
1284 #if !defined(NDEBUG)
1285 case OPT_INLINE_LOG:
1286 opt_inline_debug_log = true;
1288 #endif /* !defined(NDEBUG) */
1291 opt_inlining = true;
1293 #endif /* defined(ENABLE_INLINING) */
1295 #if defined(ENABLE_IFCONV)
1301 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1320 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
1324 _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
1327 #if defined(ENABLE_PROFILING)
1328 case OPT_PROF_OPTION:
1329 /* use <= to get the last \0 too */
1331 for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
1332 if (opt_arg[i] == ',')
1335 if (opt_arg[i] == '\0') {
1336 if (strcmp("bb", opt_arg + j) == 0)
1340 printf("Unknown option: -Xprof:%s\n", opt_arg + j);
1344 /* set k to next char */
1357 #if defined(ENABLE_JIT)
1360 printf("-Xjit option not enabled.\n");
1366 #if defined(ENABLE_INTRP)
1369 printf("-Xint option not enabled.\n");
1374 #if defined(ENABLE_INTRP)
1375 case OPT_STATIC_SUPERS:
1376 opt_static_supers = atoi(opt_arg);
1379 case OPT_NO_DYNAMIC:
1380 opt_no_dynamic = true;
1383 case OPT_NO_REPLICATION:
1384 opt_no_replication = true;
1387 case OPT_NO_QUICKSUPER:
1388 opt_no_quicksuper = true;
1397 printf("Unknown option: %s\n",
1398 vm_args->options[opt_index].optionString);
1403 /* get the main class *****************************************************/
1405 if (opt_index < vm_args->nOptions) {
1406 mainstring = vm_args->options[opt_index++].optionString;
1408 /* Put the jar file into the classpath (if any). */
1410 if (opt_jar == true) {
1411 /* free old classpath */
1413 MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
1415 /* put jarfile into classpath */
1417 _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
1419 strcpy(_Jv_classpath, mainstring);
1422 /* replace .'s with /'s in classname */
1424 for (i = strlen(mainstring) - 1; i >= 0; i--)
1425 if (mainstring[i] == '.')
1426 mainstring[i] = '/';
1430 #if defined(ENABLE_JVMTI)
1432 jvmti_set_phase(JVMTI_PHASE_ONLOAD);
1433 jvmti_agentload(agentarg, agentbypath, &handle, &libname);
1436 MFREE(agentarg, char, strlen(agentarg));
1438 jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
1442 /* initialize this JVM ****************************************************/
1444 vm_initializing = true;
1446 #if defined(ENABLE_THREADS)
1447 /* pre-initialize some core thread stuff, like the stopworldlock,
1448 thus this has to happen _before_ gc_init()!!! */
1453 /* initialize the garbage collector */
1455 gc_init(opt_heapmaxsize, opt_heapstartsize);
1457 #if defined(ENABLE_INTRP)
1458 /* Allocate main thread stack on the Java heap. */
1461 intrp_main_stack = GCMNEW(u1, opt_stacksize);
1462 MSET(intrp_main_stack, 0, u1, opt_stacksize);
1466 /* AFTER: threads_preinit */
1469 vm_abort("vm_create: string_init failed");
1471 /* AFTER: threads_preinit */
1474 vm_abort("vm_create: utf8_init failed");
1476 /* AFTER: thread_preinit */
1479 vm_abort("vm_create: suck_init failed");
1481 suck_add_from_property("java.endorsed.dirs");
1483 /* Now we have all options handled and we can print the version
1486 AFTER: suck_add_from_property("java.endorsed.dirs"); */
1491 /* AFTER: utf8_init */
1493 suck_add(_Jv_bootclasspath);
1495 /* Now re-set some of the properties that may have changed. This
1496 must be done after _all_ environment variables have been
1497 processes (e.g. -jar handling).
1499 AFTER: suck_add_from_property, since it may change the
1500 _Jv_bootclasspath pointer. */
1502 if (!properties_postinit())
1503 vm_abort("vm_create: properties_postinit failed");
1505 /* initialize the classcache hashtable stuff: lock, hashtable
1506 (must be done _after_ threads_preinit) */
1508 if (!classcache_init())
1509 vm_abort("vm_create: classcache_init failed");
1511 /* initialize the memory subsystem (must be done _after_
1515 vm_abort("vm_create: memory_init failed");
1517 /* initialize the finalizer stuff (must be done _after_
1520 if (!finalizer_init())
1521 vm_abort("vm_create: finalizer_init failed");
1523 /* install architecture dependent signal handlers */
1527 /* initialize the codegen subsystems */
1531 /* initializes jit compiler */
1535 /* machine dependent initialization */
1537 #if defined(ENABLE_JIT)
1538 # if defined(ENABLE_INTRP)
1548 /* initialize the loader subsystems (must be done _after_
1552 vm_abort("vm_create: loader_init failed");
1555 vm_abort("vm_create: linker_init failed");
1558 vm_abort("vm_create: native_init failed");
1560 if (!exceptions_init())
1561 vm_abort("vm_create: exceptions_init failed");
1563 if (!builtin_init())
1564 vm_abort("vm_create: builtin_init failed");
1566 #if defined(ENABLE_JNI)
1567 /* Initialize the JNI subsystem (must be done _before_
1568 threads_init, as threads_init can call JNI methods
1569 (e.g. NewGlobalRef). */
1572 vm_abort("vm_create: jni_init failed");
1575 #if defined(ENABLE_THREADS)
1576 if (!threads_init())
1577 vm_abort("vm_create: threads_init failed");
1580 #if defined(ENABLE_PROFILING)
1581 /* initialize profiling */
1583 if (!profile_init())
1584 vm_abort("vm_create: profile_init failed");
1587 #if defined(ENABLE_THREADS)
1588 /* initialize recompilation */
1590 if (!recompile_init())
1591 vm_abort("vm_create: recompile_init failed");
1593 /* start the signal handler thread */
1595 if (!signal_start_thread())
1596 vm_abort("vm_create: signal_start_thread failed");
1598 /* finally, start the finalizer thread */
1600 if (!finalizer_start_thread())
1601 vm_abort("vm_create: finalizer_start_thread failed");
1603 # if !defined(NDEBUG)
1604 /* start the memory profiling thread */
1606 if (opt_verbosememory)
1607 if (!memory_start_thread())
1608 vm_abort("vm_create: memory_start_thread failed");
1611 /* start the recompilation thread (must be done before the
1612 profiling thread) */
1614 if (!recompile_start_thread())
1615 vm_abort("vm_create: recompile_start_thread failed");
1617 # if defined(ENABLE_PROFILING)
1618 /* start the profile sampling thread */
1621 /* if (!profile_start_thread()) */
1622 /* exceptions_print_stacktrace(); */
1626 #if defined(ENABLE_JVMTI)
1628 /* add agent library to native library hashtable */
1629 native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
1633 /* increment the number of VMs */
1637 /* initialization is done */
1639 vm_initializing = false;
1641 /* everything's ok */
1647 /* vm_run **********************************************************************
1649 Runs the main-method of the passed class.
1651 *******************************************************************************/
1653 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
1656 classinfo *mainclass;
1658 java_objectarray *oa;
1661 java_objectheader *s;
1665 #if !defined(NDEBUG)
1671 if (opt_method != NULL) {
1672 vm_compile_method();
1675 #endif /* !defined(NDEBUG) */
1677 /* should we run the main-method? */
1679 if (mainstring == NULL)
1682 /* set return value to OK */
1686 if (opt_jar == true) {
1687 /* open jar file with java.util.jar.JarFile */
1689 mainstring = vm_get_mainclass_from_jar(mainstring);
1691 if (mainstring == NULL)
1695 /* load the main class */
1697 mainutf = utf_new_char(mainstring);
1699 #if defined(ENABLE_JAVAME_CLDC1_1)
1700 mainclass = load_class_bootstrap(mainutf);
1702 mainclass = load_class_from_sysloader(mainutf);
1705 /* error loading class */
1707 if ((exceptions_get_exception() != NULL) || (mainclass == NULL)) {
1708 exceptions_print_stacktrace();
1712 if (!link_class(mainclass)) {
1713 exceptions_print_stacktrace();
1717 /* find the `main' method of the main class */
1719 m = class_resolveclassmethod(mainclass,
1720 utf_new_char("main"),
1721 utf_new_char("([Ljava/lang/String;)V"),
1722 class_java_lang_Object,
1725 if (exceptions_get_exception()) {
1726 exceptions_print_stacktrace();
1730 /* there is no main method or it isn't static */
1732 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
1733 exceptions_clear_exception();
1734 exceptions_throw_nosuchmethoderror(mainclass,
1735 utf_new_char("main"),
1736 utf_new_char("([Ljava/lang/String;)V"));
1738 exceptions_print_stacktrace();
1742 /* build argument array */
1744 oalength = vm_args->nOptions - opt_index;
1746 oa = builtin_anewarray(oalength, class_java_lang_String);
1748 for (i = 0; i < oalength; i++) {
1749 u = utf_new_char(vm_args->options[opt_index + i].optionString);
1750 s = javastring_new(u);
1755 #ifdef TYPEINFO_DEBUG_TEST
1756 /* test the typeinfo system */
1759 /*class_showmethods(currentThread->group->header.vftbl->class); */
1761 #if defined(ENABLE_JVMTI)
1762 jvmti_set_phase(JVMTI_PHASE_LIVE);
1765 /* set ThreadMXBean variables */
1767 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
1768 _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
1770 if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
1771 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
1772 _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
1773 _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
1775 /* start the main thread */
1777 (void) vm_call_method(m, NULL, oa);
1779 /* exception occurred? */
1781 if (exceptions_get_exception()) {
1782 exceptions_print_stacktrace();
1786 /* unload the JavaVM */
1788 (void) vm_destroy(vm);
1796 /* vm_destroy ******************************************************************
1798 Unloads a Java VM and reclaims its resources.
1800 *******************************************************************************/
1802 s4 vm_destroy(JavaVM *vm)
1804 #if defined(ENABLE_THREADS)
1805 threads_join_all_threads();
1808 /* everything's ok */
1814 /* vm_exit *********************************************************************
1816 Calls java.lang.System.exit(I)V to exit the JavaVM correctly.
1818 *******************************************************************************/
1820 void vm_exit(s4 status)
1824 /* signal that we are exiting */
1828 assert(class_java_lang_System);
1829 assert(class_java_lang_System->state & CLASS_LOADED);
1831 #if defined(ENABLE_JVMTI)
1832 if (jvmti || (dbgcom!=NULL)) {
1833 jvmti_set_phase(JVMTI_PHASE_DEAD);
1834 if (jvmti) jvmti_agentunload();
1838 if (!link_class(class_java_lang_System)) {
1839 exceptions_print_stacktrace();
1843 /* call java.lang.System.exit(I)V */
1845 m = class_resolveclassmethod(class_java_lang_System,
1846 utf_new_char("exit"),
1848 class_java_lang_Object,
1852 exceptions_print_stacktrace();
1856 /* call the exit function with passed exit status */
1858 (void) vm_call_method(m, NULL, status);
1860 /* If we had an exception, just ignore the exception and exit with
1863 vm_shutdown(status);
1867 /* vm_shutdown *****************************************************************
1869 Terminates the system immediately without freeing memory explicitly
1870 (to be used only for abnormal termination).
1872 *******************************************************************************/
1874 void vm_shutdown(s4 status)
1877 #if defined(ENABLE_STATISTICS)
1878 || opt_getcompilingtime || opt_stat
1882 log_text("CACAO terminated by shutdown");
1883 dolog("Exit status: %d\n", (s4) status);
1887 #if defined(ENABLE_JVMTI)
1888 /* terminate cacaodbgserver */
1890 pthread_mutex_lock(&dbgcomlock);
1892 pthread_mutex_unlock(&dbgcomlock);
1893 jvmti_cacaodbgserver_quit();
1901 /* vm_exit_handler *************************************************************
1903 The exit_handler function is called upon program termination.
1905 ATTENTION: Don't free system resources here! Some threads may still
1906 be running as this is called from VMRuntime.exit(). The OS does the
1909 *******************************************************************************/
1911 void vm_exit_handler(void)
1913 #if !defined(NDEBUG)
1915 class_showmethods(mainclass);
1917 if (showconstantpool)
1918 class_showconstantpool(mainclass);
1923 # if defined(ENABLE_PROFILING)
1925 profile_printstats();
1927 #endif /* !defined(NDEBUG) */
1929 #if defined(ENABLE_RT_TIMING)
1930 rt_timing_print_time_stats(stderr);
1933 #if defined(ENABLE_CYCLES_STATS)
1934 builtin_print_cycles_stats(stderr);
1935 stacktrace_print_cycles_stats(stderr);
1939 #if defined(ENABLE_STATISTICS)
1940 || opt_getcompilingtime || opt_stat
1944 log_text("CACAO terminated");
1946 #if defined(ENABLE_STATISTICS)
1949 #ifdef TYPECHECK_STATISTICS
1950 typecheck_print_statistics(get_logfile());
1954 if (opt_getcompilingtime)
1956 #endif /* defined(ENABLE_STATISTICS) */
1958 /* vm_print_profile(stderr);*/
1962 /* vm_abort ********************************************************************
1964 Prints an error message and aborts the VM.
1966 *******************************************************************************/
1968 void vm_abort(const char *text, ...)
1972 /* print the log message */
1977 log_vprint(text, ap);
1982 /* now abort the VM */
1988 /* vm_get_mainclass_from_jar ***************************************************
1990 Gets the name of the main class from a JAR's manifest file.
1992 *******************************************************************************/
1994 static char *vm_get_mainclass_from_jar(char *mainstring)
1997 java_objectheader *o;
1999 java_objectheader *s;
2001 c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
2004 exceptions_print_stacktrace();
2008 /* create JarFile object */
2013 exceptions_print_stacktrace();
2017 m = class_resolveclassmethod(c,
2019 utf_java_lang_String__void,
2020 class_java_lang_Object,
2024 exceptions_print_stacktrace();
2028 s = javastring_new_from_ascii(mainstring);
2030 (void) vm_call_method(m, o, s);
2032 if (exceptions_get_exception()) {
2033 exceptions_print_stacktrace();
2037 /* get manifest object */
2039 m = class_resolveclassmethod(c,
2040 utf_new_char("getManifest"),
2041 utf_new_char("()Ljava/util/jar/Manifest;"),
2042 class_java_lang_Object,
2046 exceptions_print_stacktrace();
2050 o = vm_call_method(m, o);
2053 fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
2058 /* get Main Attributes */
2060 m = class_resolveclassmethod(o->vftbl->class,
2061 utf_new_char("getMainAttributes"),
2062 utf_new_char("()Ljava/util/jar/Attributes;"),
2063 class_java_lang_Object,
2067 exceptions_print_stacktrace();
2071 o = vm_call_method(m, o);
2074 fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
2079 /* get property Main-Class */
2081 m = class_resolveclassmethod(o->vftbl->class,
2082 utf_new_char("getValue"),
2083 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
2084 class_java_lang_Object,
2088 exceptions_print_stacktrace();
2092 s = javastring_new_from_ascii("Main-Class");
2094 o = vm_call_method(m, o, s);
2097 exceptions_print_stacktrace();
2101 return javastring_tochar(o);
2105 /* vm_compile_all **************************************************************
2107 Compile all methods found in the bootclasspath.
2109 *******************************************************************************/
2111 #if !defined(NDEBUG)
2112 static void vm_compile_all(void)
2117 classcache_name_entry *nmen;
2118 classcache_class_entry *clsen;
2121 /* create all classes found in the bootclasspath */
2122 /* XXX currently only works with zip/jar's */
2124 loader_load_all_classes();
2126 /* link all classes */
2128 for (slot = 0; slot < hashtable_classcache.size; slot++) {
2129 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
2131 for (; nmen; nmen = nmen->hashlink) {
2132 /* iterate over all class entries */
2134 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
2135 c = clsen->classobj;
2140 if (!(c->state & CLASS_LINKED)) {
2141 if (!link_class(c)) {
2142 fprintf(stderr, "Error linking: ");
2143 utf_fprint_printable_ascii_classname(stderr, c->name);
2144 fprintf(stderr, "\n");
2146 /* print out exception and cause */
2148 exceptions_print_current_exception();
2150 /* goto next class */
2156 /* compile all class methods */
2158 for (i = 0; i < c->methodscount; i++) {
2159 m = &(c->methods[i]);
2161 if (m->jcode != NULL) {
2162 if (!jit_compile(m)) {
2163 fprintf(stderr, "Error compiling: ");
2164 utf_fprint_printable_ascii_classname(stderr, c->name);
2165 fprintf(stderr, ".");
2166 utf_fprint_printable_ascii(stderr, m->name);
2167 utf_fprint_printable_ascii(stderr, m->descriptor);
2168 fprintf(stderr, "\n");
2170 /* print out exception and cause */
2172 exceptions_print_current_exception();
2180 #endif /* !defined(NDEBUG) */
2183 /* vm_compile_method ***********************************************************
2185 Compile a specific method.
2187 *******************************************************************************/
2189 #if !defined(NDEBUG)
2190 static void vm_compile_method(void)
2194 /* create, load and link the main class */
2196 mainclass = load_class_bootstrap(utf_new_char(mainstring));
2198 if (mainclass == NULL)
2199 exceptions_print_stacktrace();
2201 if (!link_class(mainclass))
2202 exceptions_print_stacktrace();
2204 if (opt_signature != NULL) {
2205 m = class_resolveclassmethod(mainclass,
2206 utf_new_char(opt_method),
2207 utf_new_char(opt_signature),
2212 m = class_resolveclassmethod(mainclass,
2213 utf_new_char(opt_method),
2220 vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
2221 opt_method, opt_signature ? opt_signature : "");
2225 #endif /* !defined(NDEBUG) */
2228 /* vm_vmargs_from_valist *******************************************************
2232 *******************************************************************************/
2234 static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
2235 vm_arg *vmargs, va_list ap)
2237 typedesc *paramtypes;
2240 paramtypes = m->parseddesc->paramtypes;
2242 /* if method is non-static fill first block and skip `this' pointer */
2247 /* the `this' pointer */
2248 vmargs[0].type = TYPE_ADR;
2249 vmargs[0].data.l = (u8) (ptrint) o;
2255 for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
2256 switch (paramtypes->decltype) {
2257 /* primitive types */
2258 case PRIMITIVETYPE_BOOLEAN:
2259 case PRIMITIVETYPE_BYTE:
2260 case PRIMITIVETYPE_CHAR:
2261 case PRIMITIVETYPE_SHORT:
2262 case PRIMITIVETYPE_INT:
2263 vmargs[i].type = TYPE_INT;
2264 vmargs[i].data.l = (s8) va_arg(ap, s4);
2267 case PRIMITIVETYPE_LONG:
2268 vmargs[i].type = TYPE_LNG;
2269 vmargs[i].data.l = (s8) va_arg(ap, s8);
2272 case PRIMITIVETYPE_FLOAT:
2273 vmargs[i].type = TYPE_FLT;
2274 #if defined(__ALPHA__)
2275 /* this keeps the assembler function much simpler */
2277 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2279 vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
2283 case PRIMITIVETYPE_DOUBLE:
2284 vmargs[i].type = TYPE_DBL;
2285 vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
2289 vmargs[i].type = TYPE_ADR;
2290 vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
2297 /* vm_vmargs_from_jvalue *******************************************************
2301 *******************************************************************************/
2303 static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
2304 vm_arg *vmargs, jvalue *args)
2306 typedesc *paramtypes;
2310 paramtypes = m->parseddesc->paramtypes;
2312 /* if method is non-static fill first block and skip `this' pointer */
2317 /* the `this' pointer */
2318 vmargs[0].type = TYPE_ADR;
2319 vmargs[0].data.l = (u8) (ptrint) o;
2325 for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
2326 switch (paramtypes->decltype) {
2327 /* primitive types */
2328 case PRIMITIVETYPE_BOOLEAN:
2329 case PRIMITIVETYPE_BYTE:
2330 case PRIMITIVETYPE_CHAR:
2331 case PRIMITIVETYPE_SHORT:
2332 case PRIMITIVETYPE_INT:
2333 vmargs[i].type = TYPE_INT;
2334 vmargs[i].data.l = (s8) args[j].i;
2337 case PRIMITIVETYPE_LONG:
2338 vmargs[i].type = TYPE_LNG;
2339 vmargs[i].data.l = (s8) args[j].j;
2342 case PRIMITIVETYPE_FLOAT:
2343 vmargs[i].type = TYPE_FLT;
2344 #if defined(__ALPHA__)
2345 /* this keeps the assembler function much simpler */
2347 vmargs[i].data.d = (jdouble) args[j].f;
2349 vmargs[i].data.f = args[j].f;
2353 case PRIMITIVETYPE_DOUBLE:
2354 vmargs[i].type = TYPE_DBL;
2355 vmargs[i].data.d = args[j].d;
2359 vmargs[i].type = TYPE_ADR;
2360 vmargs[i].data.l = (u8) (ptrint) args[j].l;
2367 /* vm_call_method **************************************************************
2369 Calls a Java method with a variable number of arguments and returns
2372 *******************************************************************************/
2374 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
2377 java_objectheader *ro;
2380 ro = vm_call_method_valist(m, o, ap);
2387 /* vm_call_method_valist *******************************************************
2389 Calls a Java method with a variable number of arguments, passed via
2390 a va_list, and returns an address.
2392 *******************************************************************************/
2394 java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
2399 java_objectheader *ro;
2402 /* mark start of dump memory area */
2404 dumpsize = dump_size();
2406 /* get number of Java method arguments */
2408 vmargscount = m->parseddesc->paramcount;
2410 /* allocate vm_arg array */
2412 vmargs = DMNEW(vm_arg, vmargscount);
2414 /* fill the vm_arg array from a va_list */
2416 vm_vmargs_from_valist(m, o, vmargs, ap);
2418 /* call the Java method */
2420 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2422 /* release dump area */
2424 dump_release(dumpsize);
2430 /* vm_call_method_jvalue *******************************************************
2432 Calls a Java method with a variable number of arguments, passed via
2433 a jvalue array, and returns an address.
2435 *******************************************************************************/
2437 java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
2442 java_objectheader *ro;
2445 /* mark start of dump memory area */
2447 dumpsize = dump_size();
2449 /* get number of Java method arguments */
2451 vmargscount = m->parseddesc->paramcount;
2453 /* allocate vm_arg array */
2455 vmargs = DMNEW(vm_arg, vmargscount);
2457 /* fill the vm_arg array from a va_list */
2459 vm_vmargs_from_jvalue(m, o, vmargs, args);
2461 /* call the Java method */
2463 ro = vm_call_method_vmarg(m, vmargscount, vmargs);
2465 /* release dump area */
2467 dump_release(dumpsize);
2473 /* vm_call_method_vmarg ********************************************************
2475 Calls a Java method with a variable number of arguments, passed via
2476 a vm_arg array, and returns an address.
2478 *******************************************************************************/
2480 java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
2483 java_objectheader *o;
2485 #if defined(ENABLE_JIT)
2486 # if defined(ENABLE_INTRP)
2488 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2491 o = asm_vm_call_method(m, vmargscount, vmargs);
2493 o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
2500 /* vm_call_method_int **********************************************************
2502 Calls a Java method with a variable number of arguments and returns
2505 *******************************************************************************/
2507 s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
2513 i = vm_call_method_int_valist(m, o, ap);
2520 /* vm_call_method_int_valist ***************************************************
2522 Calls a Java method with a variable number of arguments, passed via
2523 a va_list, and returns an integer (s4).
2525 *******************************************************************************/
2527 s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
2534 /* mark start of dump memory area */
2536 dumpsize = dump_size();
2538 /* get number of Java method arguments */
2540 vmargscount = m->parseddesc->paramcount;
2542 /* allocate vm_arg array */
2544 vmargs = DMNEW(vm_arg, vmargscount);
2546 /* fill the vm_arg array from a va_list */
2548 vm_vmargs_from_valist(m, o, vmargs, ap);
2550 /* call the Java method */
2552 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2554 /* release dump area */
2556 dump_release(dumpsize);
2562 /* vm_call_method_int_jvalue ***************************************************
2564 Calls a Java method with a variable number of arguments, passed via
2565 a jvalue array, and returns an integer (s4).
2567 *******************************************************************************/
2569 s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2576 /* mark start of dump memory area */
2578 dumpsize = dump_size();
2580 /* get number of Java method arguments */
2582 vmargscount = m->parseddesc->paramcount;
2584 /* allocate vm_arg array */
2586 vmargs = DMNEW(vm_arg, vmargscount);
2588 /* fill the vm_arg array from a va_list */
2590 vm_vmargs_from_jvalue(m, o, vmargs, args);
2592 /* call the Java method */
2594 i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
2596 /* release dump area */
2598 dump_release(dumpsize);
2604 /* vm_call_method_int_vmarg ****************************************************
2606 Calls a Java method with a variable number of arguments, passed via
2607 a vm_arg array, and returns an integer (s4).
2609 *******************************************************************************/
2611 s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2615 #if defined(ENABLE_JIT)
2616 # if defined(ENABLE_INTRP)
2618 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2621 i = asm_vm_call_method_int(m, vmargscount, vmargs);
2623 i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
2630 /* vm_call_method_long *********************************************************
2632 Calls a Java method with a variable number of arguments and returns
2635 *******************************************************************************/
2637 s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
2643 l = vm_call_method_long_valist(m, o, ap);
2650 /* vm_call_method_long_valist **************************************************
2652 Calls a Java method with a variable number of arguments, passed via
2653 a va_list, and returns a long (s8).
2655 *******************************************************************************/
2657 s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
2664 /* mark start of dump memory area */
2666 dumpsize = dump_size();
2668 /* get number of Java method arguments */
2670 vmargscount = m->parseddesc->paramcount;
2672 /* allocate vm_arg array */
2674 vmargs = DMNEW(vm_arg, vmargscount);
2676 /* fill the vm_arg array from a va_list */
2678 vm_vmargs_from_valist(m, o, vmargs, ap);
2680 /* call the Java method */
2682 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2684 /* release dump area */
2686 dump_release(dumpsize);
2692 /* vm_call_method_long_jvalue **************************************************
2694 Calls a Java method with a variable number of arguments, passed via
2695 a jvalue array, and returns a long (s8).
2697 *******************************************************************************/
2699 s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o, jvalue *args)
2706 /* mark start of dump memory area */
2708 dumpsize = dump_size();
2710 /* get number of Java method arguments */
2712 vmargscount = m->parseddesc->paramcount;
2714 /* allocate vm_arg array */
2716 vmargs = DMNEW(vm_arg, vmargscount);
2718 /* fill the vm_arg array from a va_list */
2720 vm_vmargs_from_jvalue(m, o, vmargs, args);
2722 /* call the Java method */
2724 l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
2726 /* release dump area */
2728 dump_release(dumpsize);
2734 /* vm_call_method_long_vmarg ***************************************************
2736 Calls a Java method with a variable number of arguments, passed via
2737 a vm_arg array, and returns a long (s8).
2739 *******************************************************************************/
2741 s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2745 #if defined(ENABLE_JIT)
2746 # if defined(ENABLE_INTRP)
2748 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2751 l = asm_vm_call_method_long(m, vmargscount, vmargs);
2753 l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
2760 /* vm_call_method_float ********************************************************
2762 Calls a Java method with a variable number of arguments and returns
2765 *******************************************************************************/
2767 float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
2773 f = vm_call_method_float_valist(m, o, ap);
2780 /* vm_call_method_float_valist *************************************************
2782 Calls a Java method with a variable number of arguments, passed via
2783 a va_list, and returns a float.
2785 *******************************************************************************/
2787 float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
2795 /* mark start of dump memory area */
2797 dumpsize = dump_size();
2799 /* get number of Java method arguments */
2801 vmargscount = m->parseddesc->paramcount;
2803 /* allocate vm_arg array */
2805 vmargs = DMNEW(vm_arg, vmargscount);
2807 /* fill the vm_arg array from a va_list */
2809 vm_vmargs_from_valist(m, o, vmargs, ap);
2811 /* call the Java method */
2813 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2815 /* release dump area */
2817 dump_release(dumpsize);
2823 /* vm_call_method_float_jvalue *************************************************
2825 Calls a Java method with a variable number of arguments, passed via
2826 a jvalue array, and returns a float.
2828 *******************************************************************************/
2830 float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
2838 /* mark start of dump memory area */
2840 dumpsize = dump_size();
2842 /* get number of Java method arguments */
2844 vmargscount = m->parseddesc->paramcount;
2846 /* allocate vm_arg array */
2848 vmargs = DMNEW(vm_arg, vmargscount);
2850 /* fill the vm_arg array from a va_list */
2852 vm_vmargs_from_jvalue(m, o, vmargs, args);
2854 /* call the Java method */
2856 f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
2858 /* release dump area */
2860 dump_release(dumpsize);
2866 /* vm_call_method_float_vmarg **************************************************
2868 Calls a Java method with a variable number of arguments and returns
2871 *******************************************************************************/
2873 float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
2877 #if defined(ENABLE_JIT)
2878 # if defined(ENABLE_INTRP)
2880 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2883 f = asm_vm_call_method_float(m, vmargscount, vmargs);
2885 f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
2892 /* vm_call_method_double *******************************************************
2894 Calls a Java method with a variable number of arguments and returns
2897 *******************************************************************************/
2899 double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
2905 d = vm_call_method_double_valist(m, o, ap);
2912 /* vm_call_method_double_valist ************************************************
2914 Calls a Java method with a variable number of arguments, passed via
2915 a va_list, and returns a double.
2917 *******************************************************************************/
2919 double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
2927 /* mark start of dump memory area */
2929 dumpsize = dump_size();
2931 /* get number of Java method arguments */
2933 vmargscount = m->parseddesc->paramcount;
2935 /* allocate vm_arg array */
2937 vmargs = DMNEW(vm_arg, vmargscount);
2939 /* fill the vm_arg array from a va_list */
2941 vm_vmargs_from_valist(m, o, vmargs, ap);
2943 /* call the Java method */
2945 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2947 /* release dump area */
2949 dump_release(dumpsize);
2955 /* vm_call_method_double_jvalue ************************************************
2957 Calls a Java method with a variable number of arguments, passed via
2958 a jvalue array, and returns a double.
2960 *******************************************************************************/
2962 double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
2970 /* mark start of dump memory area */
2972 dumpsize = dump_size();
2974 /* get number of Java method arguments */
2976 vmargscount = m->parseddesc->paramcount;
2978 /* allocate vm_arg array */
2980 vmargs = DMNEW(vm_arg, vmargscount);
2982 /* fill the vm_arg array from a va_list */
2984 vm_vmargs_from_jvalue(m, o, vmargs, args);
2986 /* call the Java method */
2988 d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
2990 /* release dump area */
2992 dump_release(dumpsize);
2998 /* vm_call_method_double_vmarg *************************************************
3000 Calls a Java method with a variable number of arguments and returns
3003 *******************************************************************************/
3005 double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
3010 #if defined(ENABLE_JIT)
3011 # if defined(ENABLE_INTRP)
3013 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3016 d = asm_vm_call_method_double(m, vmargscount, vmargs);
3018 d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
3026 * These are local overrides for various environment variables in Emacs.
3027 * Please do not remove this and leave it at the end of the file, where
3028 * Emacs will automagically detect them.
3029 * ---------------------------------------------------------------------
3032 * indent-tabs-mode: t