/* src/vm/vm.c - VM startup and shutdown functions
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
J. Wenninger, Institut f. Computersprachen - TU Wien
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Contact: cacao@cacaojvm.org
-
- Authors: Christian Thalinger
- Martin Platter
-
$Id: vm.c 4357 2006-01-22 23:33:38Z twisti $
*/
#include "mm/gc-common.h"
#include "mm/memory.h"
+
#include "native/jni.h"
#include "native/native.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_String.h"
#if defined(ENABLE_THREADS)
# include "threads/native/threads.h"
#endif
-#include "vm/classcache.h"
+#include "toolbox/logging.h"
+
+#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/finalizer.h"
#include "vm/global.h"
#include "vm/initialize.h"
-#include "vm/options.h"
#include "vm/properties.h"
-#include "vm/rt-timing.h"
#include "vm/signallocal.h"
#include "vm/stringlocal.h"
-#include "vm/suck.h"
#include "vm/vm.h"
+
#include "vm/jit/jit.h"
+#include "vm/jit/md.h"
#include "vm/jit/asmpart.h"
#if defined(ENABLE_PROFILING)
#include "vm/jit/optimizing/recompile.h"
+#include "vmcore/classcache.h"
+#include "vmcore/options.h"
+#include "vmcore/suck.h"
+
#if defined(ENABLE_JVMTI)
# include "native/jvmti/cacaodbg.h"
#endif
OPT_HELP,
OPT_X,
+ OPT_XX,
OPT_ESA,
OPT_DSA,
OPT_VERBOSE1,
OPT_NOIEEE,
- OPT_SOFTNULL,
#if defined(ENABLE_STATISTICS)
OPT_TIME,
#if defined(ENABLE_INLINING)
OPT_INLINING,
-#endif
+#if !defined(NDEBUG)
+ OPT_INLINE_LOG,
+#endif
+#if defined(ENABLE_INLINING_DEBUG)
+ OPT_INLINE_DEBUG_ALL,
+ OPT_INLINE_DEBUG_END,
+ OPT_INLINE_DEBUG_MIN,
+ OPT_INLINE_DEBUG_MAX,
+ OPT_INLINE_REPLACE_VERBOSE,
+ OPT_INLINE_REPLACE_VERBOSE2,
+#endif /* defined(ENABLE_INLINING_DEBUG) */
+#endif /* defined(ENABLE_INLINING) */
#if defined(ENABLE_INTRP)
/* interpreter options */
{ "help", false, OPT_HELP },
{ "?", false, OPT_HELP },
{ "X", false, OPT_X },
+ { "XX", false, OPT_XX },
{ "esa", false, OPT_ESA },
{ "enablesystemassertions", false, OPT_ESA },
#if defined(__ALPHA__)
{ "noieee", false, OPT_NOIEEE },
#endif
- { "softnull", false, OPT_SOFTNULL },
#if defined(ENABLE_STATISTICS)
{ "time", false, OPT_TIME },
{ "stat", false, OPT_STAT },
{ "Xprof", false, OPT_PROF },
#endif
- /* keep these at the end of the list */
+ /* inlining options */
#if defined(ENABLE_INLINING)
- { "i", true, OPT_INLINING },
+#if defined(ENABLE_INLINING_DEBUG)
+ { "ia", false, OPT_INLINE_DEBUG_ALL },
+ { "ii", true, OPT_INLINE_DEBUG_MIN },
+ { "im", true, OPT_INLINE_DEBUG_MAX },
+ { "ie", true, OPT_INLINE_DEBUG_END },
+ { "ir", false, OPT_INLINE_REPLACE_VERBOSE },
+ { "iR", false, OPT_INLINE_REPLACE_VERBOSE2 },
+#endif /* defined(ENABLE_INLINING_DEBUG) */
+#if !defined(NDEBUG)
+ { "il", false, OPT_INLINE_LOG },
#endif
+ { "i", false, OPT_INLINING },
+#endif /* defined(ENABLE_INLINING) */
+
+ /* keep these at the end of the list */
#if !defined(NDEBUG)
{ "m", true, OPT_METHOD },
puts(" or cacao [-options] -jar jarfile [arguments]");
puts(" (to run a standalone jar file)\n");
- puts("Java options:");
+ puts("where options include:");
puts(" -d32 use 32-bit data model if available");
puts(" -d64 use 64-bit data model if available");
puts(" -client compatibility (currently ignored)");
puts(" -showversion print product version and continue");
puts(" -help, -? print this help message");
puts(" -X print help on non-standard Java options");
+ puts(" -XX print help on CACAO options");
puts(" -esa | -enablesystemassertions");
puts(" enable system assertions");
puts(" -dsa | -disablesystemassertions");
puts(" disable system assertions");
- puts("");
#ifdef ENABLE_JVMTI
puts(" -agentlib:<agent-lib-name>=<options> library to load containg JVMTI agent");
puts(" -agentpath:<path-to-agent>=<options> path to library containg JVMTI agent");
#endif
- puts("CACAO options:");
+ /* exit with error code */
+
+ exit(1);
+}
+
+
+static void Xusage(void)
+{
+#if defined(ENABLE_JIT)
+ puts(" -Xjit JIT mode execution (default)");
+#endif
+#if defined(ENABLE_INTRP)
+ puts(" -Xint interpreter mode execution");
+#endif
+ puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
+ puts(" value is set as bootstrap class path");
+ puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
+ puts(" value is appended to the bootstrap class path");
+ puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
+ puts(" value is prepended to the bootstrap class path");
+ puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
+ puts(" value is used as Java core library, but the");
+ puts(" hardcoded VM interface classes are prepended");
+ printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
+ printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
+ printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
+
+#if defined(ENABLE_PROFILING)
+ puts(" -Xprof[:bb] collect and print profiling data");
+#endif
+
+#if defined(ENABLE_JVMTI)
+ /* -Xdebug option depend on gnu classpath JDWP options. options:
+ transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
+ puts(" -Xdebug enable remote debugging\n");
+ puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
+ puts(" enable remote debugging\n");
+#endif
+
+ /* exit with error code */
+
+ exit(1);
+}
+
+
+static void XXusage(void)
+{
puts(" -v write state-information");
- puts(" -verbose[:call|exception|jit]");
+#if !defined(NDEBUG)
+ puts(" -verbose[:call|exception|jit|memory]");
puts(" enable specific verbose output");
puts(" -debug-color colored output for ANSI terms");
+#endif
#ifdef TYPECHECK_VERBOSE
puts(" -verbosetc write debug messages while typechecking");
#endif
#if defined(ENABLE_VERIFIER)
puts(" -noverify don't verify classfiles");
#endif
- puts(" -softnull use software nullpointer check");
#if defined(ENABLE_STATISTICS)
puts(" -time measure the runtime");
puts(" -stat detailed compiler statistics");
puts(" (e)xceptionstubs disassembled exception stubs (only with -sa)");
puts(" (n)ative disassembled native stubs");
#endif
- puts(" (d)atasegment data segment listing");
+ puts(" (d)atasegment data segment listing");
+
#if defined(ENABLE_INLINING)
- puts(" -i n(line) activate inlining");
- puts(" v(irtual) inline virtual methods (uses/turns rt option on)");
- puts(" e(exception) inline methods with exceptions");
- puts(" p(aramopt) optimize argument renaming");
- puts(" o(utsiders) inline methods of foreign classes");
+ puts(" -i activate inlining");
+#if !defined(NDEBUG)
+ puts(" -il log inlining");
+#endif
+#if defined(ENABLE_INLINING_DEBUG)
+ puts(" -ia use inlining for all methods");
+ puts(" -ii <size> set minimum size for inlined result");
+ puts(" -im <size> set maximum size for inlined result");
+ puts(" -ie <number> stop inlining after the given number of roots");
+ puts(" -ir log on-stack replacement");
+ puts(" -iR log on-stack replacement, more verbose");
+#endif /* defined(ENABLE_INLINING_DEBUG) */
#endif /* defined(ENABLE_INLINING) */
+
#if defined(ENABLE_IFCONV)
puts(" -ifconv use if-conversion");
#endif
/* exit with error code */
exit(1);
-}
-
-
-static void Xusage(void)
-{
-#if defined(ENABLE_JIT)
- puts(" -Xjit JIT mode execution (default)");
-#endif
-#if defined(ENABLE_INTRP)
- puts(" -Xint interpreter mode execution");
-#endif
- puts(" -Xbootclasspath:<zip/jar files and directories separated by :>");
- puts(" value is set as bootstrap class path");
- puts(" -Xbootclasspath/a:<zip/jar files and directories separated by :>");
- puts(" value is appended to the bootstrap class path");
- puts(" -Xbootclasspath/p:<zip/jar files and directories separated by :>");
- puts(" value is prepended to the bootstrap class path");
- puts(" -Xbootclasspath/c:<zip/jar files and directories separated by :>");
- puts(" value is used as Java core library, but the");
- puts(" hardcoded VM interface classes are prepended");
- printf(" -Xms<size> set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
- printf(" -Xmx<size> set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
- printf(" -Xss<size> set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
-
-#if defined(ENABLE_PROFILING)
- puts(" -Xprof[:bb] collect and print profiling data");
-#endif
-
-#if defined(ENABLE_JVMTI)
- /* -Xdebug option depend on gnu classpath JDWP options. options:
- transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
- puts(" -Xdebug enable remote debugging\n");
- puts(" -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
- puts(" enable remote debugging\n");
-#endif
-
- /* exit with error code */
-
- exit(1);
-}
+}
/* version *********************************************************************
puts("java version \""JAVA_VERSION"\"");
puts("CACAO version "VERSION"");
- puts("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,");
+ puts("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,");
puts("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,");
puts("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,");
puts("J. Wenninger, Institut f. Computersprachen - TU Wien\n");
printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
printf(" initial heap size : %d\n", HEAP_STARTSIZE);
printf(" stack size : %d\n", STACK_SIZE);
- puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_GLIBJ_ZIP"");
+#if defined(WITH_CLASSPATH_GNU)
+ puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
+#else
+ puts(" java.boot.class.path : "CLASSPATH_CLASSES"");
+#endif
puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
puts("Runtime variables:\n");
printf(" stack size : %d\n", opt_stacksize);
printf(" java.boot.class.path : %s\n", _Jv_bootclasspath);
printf(" gnu.classpath.boot.library.path: %s\n", classpath_libdir);
+ printf(" java.class.path : %s\n", _Jv_classpath);
/* exit normally, if requested */
/* get the VM and Env tables (must be set before vm_create) */
env = NEW(_Jv_JNIEnv);
+
+#if defined(ENABLE_JNI)
env->env = &_Jv_JNINativeInterface;
+#endif
/* XXX Set the global variable. Maybe we should do that differently. */
/* create and fill a JavaVM structure */
vm = NEW(_Jv_JavaVM);
+
+#if defined(ENABLE_JNI)
vm->functions = &_Jv_JNIInvokeInterface;
+#endif
/* XXX Set the global variable. Maybe we should do that differently. */
/* XXX JVMTI Agents needs a JavaVM */
if (!vm_create(_vm_args))
goto error;
-#if defined(ENABLE_JAVASE)
+#if defined(ENABLE_JNI)
/* setup the local ref table (must be created after vm_create) */
if (!jni_init_localref_table())
if (opt_verbose)
log_text("CACAO started -------------------------------------------------------");
+ /* We need to check if the actual size of a java.lang.Class object
+ is smaller or equal than the assumption made in
+ src/vmcore/class.h. */
+
+ if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
+ vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
+
/* set the VM starttime */
_Jv_jvm->starttime = builtin_currenttimemillis();
else {
#if defined(WITH_JRE_LAYOUT)
len =
+# if defined(WITH_CLASSPATH_GNU)
strlen(cacao_prefix) +
strlen("/share/cacao/vm.zip") +
strlen(":") +
+# endif
strlen(cacao_prefix) +
strlen("/share/classpath/glibj.zip") +
strlen("0");
_Jv_bootclasspath = MNEW(char, len);
+# if defined(WITH_CLASSPATH_GNU)
strcat(_Jv_bootclasspath, cacao_prefix);
strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
strcat(_Jv_bootclasspath, ":");
+# endif
strcat(_Jv_bootclasspath, cacao_prefix);
strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
#else
len =
+# if defined(WITH_CLASSPATH_GNU)
strlen(CACAO_VM_ZIP) +
strlen(":") +
- strlen(CLASSPATH_GLIBJ_ZIP) +
+# endif
+ strlen(CLASSPATH_CLASSES) +
strlen("0");
_Jv_bootclasspath = MNEW(char, len);
+# if defined(WITH_CLASSPATH_GNU)
strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
strcat(_Jv_bootclasspath, ":");
- strcat(_Jv_bootclasspath, CLASSPATH_GLIBJ_ZIP);
+# endif
+ strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
#endif
}
opt_version = false;
opt_exit = false;
- checknull = false;
opt_noieee = false;
opt_heapmaxsize = HEAP_MAXSIZE;
_Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
char,
- len,
+ len + strlen("0"),
len + strlen(":") +
strlen(opt_arg) + strlen("0"));
break;
case OPT_VERBOSE:
- if (strcmp("class", opt_arg) == 0)
+ if (strcmp("class", opt_arg) == 0) {
opt_verboseclass = true;
-
- else if (strcmp("gc", opt_arg) == 0)
+ }
+ else if (strcmp("gc", opt_arg) == 0) {
opt_verbosegc = true;
-
- else if (strcmp("jni", opt_arg) == 0)
+ }
+ else if (strcmp("jni", opt_arg) == 0) {
opt_verbosejni = true;
-
- else if (strcmp("call", opt_arg) == 0)
+ }
+#if !defined(NDEBUG)
+ else if (strcmp("call", opt_arg) == 0) {
opt_verbosecall = true;
-
+ }
+ else if (strcmp("exception", opt_arg) == 0) {
+ opt_verboseexception = true;
+ }
else if (strcmp("jit", opt_arg) == 0) {
opt_verbose = true;
loadverbose = true;
initverbose = true;
compileverbose = true;
}
- else if (strcmp("exception", opt_arg) == 0)
- opt_verboseexception = true;
+ else if (strcmp("memory", opt_arg) == 0) {
+ opt_verbosememory = true;
+
+# if defined(ENABLE_STATISTICS)
+ /* we also need statistics */
+
+ opt_stat = true;
+# endif
+ }
+#endif
break;
case OPT_DEBUGCOLOR:
opt_debugcolor = true;
break;
#endif
- case OPT_SOFTNULL:
- checknull = true;
- break;
-
#if defined(ENABLE_STATISTICS)
case OPT_TIME:
opt_getcompilingtime = true;
#endif
#if defined(ENABLE_INLINING)
+#if defined(ENABLE_INLINING_DEBUG)
+ case OPT_INLINE_DEBUG_ALL:
+ opt_inline_debug_all = true;
+ break;
+ case OPT_INLINE_DEBUG_END:
+ opt_inline_debug_end_counter = atoi(opt_arg);
+ break;
+ case OPT_INLINE_DEBUG_MIN:
+ opt_inline_debug_min_size = atoi(opt_arg);
+ break;
+ case OPT_INLINE_DEBUG_MAX:
+ opt_inline_debug_max_size = atoi(opt_arg);
+ break;
+ case OPT_INLINE_REPLACE_VERBOSE:
+ opt_replace_verbose = 1;
+ break;
+ case OPT_INLINE_REPLACE_VERBOSE2:
+ opt_replace_verbose = 2;
+ break;
+#endif /* defined(ENABLE_INLINING_DEBUG) */
+#if !defined(NDEBUG)
+ case OPT_INLINE_LOG:
+ opt_inline_debug_log = true;
+ break;
+#endif /* !defined(NDEBUG) */
+
case OPT_INLINING:
- for (i = 0; i < strlen(opt_arg); i++) {
- switch (opt_arg[i]) {
- case 'n':
- /* define in options.h; Used in main.c, jit.c
- & inline.c inlining is currently
- deactivated */
- break;
- case 'v':
- inlinevirtuals = true;
- break;
- case 'e':
- inlineexceptions = true;
- break;
- case 'p':
- inlineparamopt = true;
- break;
- case 'o':
- inlineoutsiders = true;
- break;
- default:
- usage();
- }
- }
+ opt_inlining = true;
break;
#endif /* defined(ENABLE_INLINING) */
Xusage();
break;
+ case OPT_XX:
+ XXusage();
+ break;
+
case OPT_ESA:
_Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
break;
}
}
- /* now re-set some of the properties that may have changed */
-
- if (!properties_postinit())
- vm_abort("properties_postinit failed");
-
- /* Now we have all options handled and we can print the version
- information. */
-
- if (opt_version)
- version(opt_exit);
-
-
/* get the main class *****************************************************/
if (opt_index < vm_args->nOptions) {
jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
}
-
#endif
-
/* initialize this JVM ****************************************************/
vm_initializing = true;
}
#endif
- /* initialize the string hashtable stuff: lock (must be done
- _after_ threads_preinit) */
+ /* AFTER: threads_preinit */
if (!string_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: string_init failed");
- /* initialize the utf8 hashtable stuff: lock, often used utf8
- strings (must be done _after_ threads_preinit) */
+ /* AFTER: threads_preinit */
if (!utf8_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: utf8_init failed");
- /* initialize the classcache hashtable stuff: lock, hashtable
- (must be done _after_ threads_preinit) */
-
- if (!classcache_init())
- throw_main_exception_exit();
-
- /* initialize the loader with bootclasspath (must be done _after_
- thread_preinit) */
+ /* AFTER: thread_preinit */
if (!suck_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: suck_init failed");
suck_add_from_property("java.endorsed.dirs");
+
+ /* Now we have all options handled and we can print the version
+ information.
+
+ AFTER: suck_add_from_property("java.endorsed.dirs"); */
+
+ if (opt_version)
+ version(opt_exit);
+
+ /* AFTER: utf8_init */
+
suck_add(_Jv_bootclasspath);
+ /* Now re-set some of the properties that may have changed. This
+ must be done after _all_ environment variables have been
+ processes (e.g. -jar handling).
+
+ AFTER: suck_add_from_property, since it may change the
+ _Jv_bootclasspath pointer. */
+
+ if (!properties_postinit())
+ vm_abort("vm_create: properties_postinit failed");
+
+ /* initialize the classcache hashtable stuff: lock, hashtable
+ (must be done _after_ threads_preinit) */
+
+ if (!classcache_init())
+ vm_abort("vm_create: classcache_init failed");
+
/* initialize the memory subsystem (must be done _after_
threads_preinit) */
if (!memory_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: memory_init failed");
/* initialize the finalizer stuff (must be done _after_
threads_preinit) */
if (!finalizer_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: finalizer_init failed");
- /* install architecture dependent signal handler used for exceptions */
+ /* install architecture dependent signal handlers */
signal_init();
classcache_init) */
if (!loader_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: loader_init failed");
if (!linker_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: linker_init failed");
if (!native_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: native_init failed");
if (!exceptions_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: exceptions_init failed");
if (!builtin_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: builtin_init failed");
+#if defined(ENABLE_JNI)
/* Initialize the JNI subsystem (must be done _before_
threads_init, as threads_init can call JNI methods
(e.g. NewGlobalRef). */
if (!jni_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: jni_init failed");
+#endif
#if defined(ENABLE_THREADS)
if (!threads_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: threads_init failed");
#endif
#if defined(ENABLE_PROFILING)
/* initialize profiling */
if (!profile_init())
- throw_main_exception_exit();
+ vm_abort("vm_create: profile_init failed");
#endif
#if defined(ENABLE_THREADS)
/* initialize recompilation */
if (!recompile_init())
- throw_main_exception_exit();
-
+ vm_abort("vm_create: recompile_init failed");
+
+ /* start the signal handler thread */
+
+ if (!signal_start_thread())
+ vm_abort("vm_create: signal_start_thread failed");
+
/* finally, start the finalizer thread */
if (!finalizer_start_thread())
- throw_main_exception_exit();
+ vm_abort("vm_create: finalizer_start_thread failed");
+
+# if !defined(NDEBUG)
+ /* start the memory profiling thread */
+
+ if (opt_verbosememory)
+ if (!memory_start_thread())
+ vm_abort("vm_create: memory_start_thread failed");
+# endif
/* start the recompilation thread (must be done before the
profiling thread) */
if (!recompile_start_thread())
- throw_main_exception_exit();
+ vm_abort("vm_create: recompile_start_thread failed");
# if defined(ENABLE_PROFILING)
/* start the profile sampling thread */
/* if (opt_prof) */
/* if (!profile_start_thread()) */
-/* throw_main_exception_exit(); */
+/* exceptions_print_stacktrace(); */
# endif
#endif
#if defined(ENABLE_JVMTI)
+# if defined(ENABLE_GC_CACAO)
+ /* XXX this will not work with the new indirection cells for classloaders!!! */
+ assert(0);
+# endif
if (jvmti) {
/* add agent library to native library hashtable */
native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
{
- utf *mainutf;
- classinfo *mainclass;
- methodinfo *m;
- java_objectarray *oa;
- s4 oalength;
- utf *u;
- java_lang_String *s;
- s4 status;
- s4 i;
+ utf *mainutf;
+ classinfo *mainclass;
+ methodinfo *m;
+ java_objectarray *oa;
+ s4 oalength;
+ utf *u;
+ java_objectheader *s;
+ s4 status;
+ s4 i;
#if !defined(NDEBUG)
if (compileall) {
status = 0;
- if (opt_jar == true)
+ if (opt_jar == true) {
/* open jar file with java.util.jar.JarFile */
+
mainstring = vm_get_mainclass_from_jar(mainstring);
+ if (mainstring == NULL)
+ vm_exit(1);
+ }
+
/* load the main class */
mainutf = utf_new_char(mainstring);
#if defined(ENABLE_JAVAME_CLDC1_1)
- if (!(mainclass = load_class_bootstrap(mainutf)))
- throw_main_exception_exit();
+ mainclass = load_class_bootstrap(mainutf);
#else
- if (!(mainclass = load_class_from_sysloader(mainutf)))
- throw_main_exception_exit();
+ mainclass = load_class_from_sysloader(mainutf);
#endif
/* error loading class */
- if ((*exceptionptr != NULL) || (mainclass == NULL))
- throw_main_exception_exit();
+ if ((exceptions_get_exception() != NULL) || (mainclass == NULL)) {
+ exceptions_print_stacktrace();
+ vm_exit(1);
+ }
- if (!link_class(mainclass))
- throw_main_exception_exit();
+ if (!link_class(mainclass)) {
+ exceptions_print_stacktrace();
+ vm_exit(1);
+ }
/* find the `main' method of the main class */
class_java_lang_Object,
false);
- if (*exceptionptr) {
- throw_main_exception_exit();
+ if (exceptions_get_exception()) {
+ exceptions_print_stacktrace();
+ vm_exit(1);
}
/* there is no main method or it isn't static */
if ((m == NULL) || !(m->flags & ACC_STATIC)) {
- *exceptionptr = NULL;
+ exceptions_clear_exception();
+ exceptions_throw_nosuchmethoderror(mainclass,
+ utf_new_char("main"),
+ utf_new_char("([Ljava/lang/String;)V"));
- *exceptionptr =
- new_exception_message(string_java_lang_NoSuchMethodError, "main");
- throw_main_exception_exit();
+ exceptions_print_stacktrace();
+ vm_exit(1);
}
/* build argument array */
u = utf_new_char(vm_args->options[opt_index + i].optionString);
s = javastring_new(u);
- oa->data[i] = (java_objectheader *) s;
+ oa->data[i] = s;
}
#ifdef TYPEINFO_DEBUG_TEST
jvmti_set_phase(JVMTI_PHASE_LIVE);
#endif
- /* increase total started thread count */
+ /* set ThreadMXBean variables */
+
+ _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
+ _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
- _Jv_jvm->total_started_thread_count++;
+ if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
+ _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
+ _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
+ _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
/* start the main thread */
/* exception occurred? */
- if (*exceptionptr) {
- throw_main_exception();
+ if (exceptions_get_exception()) {
+ exceptions_print_stacktrace();
status = 1;
}
/* unload the JavaVM */
- vm_destroy(vm);
+ (void) vm_destroy(vm);
/* and exit */
}
#endif
- if (!link_class(class_java_lang_System))
- throw_main_exception_exit();
+ if (!link_class(class_java_lang_System)) {
+ exceptions_print_stacktrace();
+ exit(1);
+ }
/* call java.lang.System.exit(I)V */
class_java_lang_Object,
true);
- if (m == NULL)
- throw_main_exception_exit();
+ if (m == NULL) {
+ exceptions_print_stacktrace();
+ exit(1);
+ }
/* call the exit function with passed exit status */
#endif
}
- mem_usagelog(1);
-
if (opt_getcompilingtime)
print_times();
#endif /* defined(ENABLE_STATISTICS) */
classinfo *c;
java_objectheader *o;
methodinfo *m;
- java_lang_String *s;
+ java_objectheader *s;
c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
- if (c == NULL)
- throw_main_exception_exit();
-
+ if (c == NULL) {
+ exceptions_print_stacktrace();
+ return NULL;
+ }
+
/* create JarFile object */
o = builtin_new(c);
- if (o == NULL)
- throw_main_exception_exit();
-
+ if (o == NULL) {
+ exceptions_print_stacktrace();
+ return NULL;
+ }
m = class_resolveclassmethod(c,
utf_init,
class_java_lang_Object,
true);
- if (m == NULL)
- throw_main_exception_exit();
+ if (m == NULL) {
+ exceptions_print_stacktrace();
+ return NULL;
+ }
s = javastring_new_from_ascii(mainstring);
(void) vm_call_method(m, o, s);
- if (*exceptionptr)
- throw_main_exception_exit();
+ if (exceptions_get_exception()) {
+ exceptions_print_stacktrace();
+ return NULL;
+ }
/* get manifest object */
class_java_lang_Object,
true);
- if (m == NULL)
- throw_main_exception_exit();
+ if (m == NULL) {
+ exceptions_print_stacktrace();
+ return NULL;
+ }
o = vm_call_method(m, o);
if (o == NULL) {
fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
- vm_exit(1);
+ return NULL;
}
class_java_lang_Object,
true);
- if (m == NULL)
- throw_main_exception_exit();
+ if (m == NULL) {
+ exceptions_print_stacktrace();
+ return NULL;
+ }
o = vm_call_method(m, o);
if (o == NULL) {
fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
- vm_exit(1);
+ return NULL;
}
class_java_lang_Object,
true);
- if (m == NULL)
- throw_main_exception_exit();
+ if (m == NULL) {
+ exceptions_print_stacktrace();
+ return NULL;
+ }
s = javastring_new_from_ascii("Main-Class");
o = vm_call_method(m, o, s);
- if (o == NULL)
- throw_main_exception_exit();
+ if (o == NULL) {
+ exceptions_print_stacktrace();
+ return NULL;
+ }
return javastring_tochar(o);
}
/* print out exception and cause */
- exceptions_print_exception(*exceptionptr);
+ exceptions_print_current_exception();
/* goto next class */
/* print out exception and cause */
- exceptions_print_exception(*exceptionptr);
+ exceptions_print_current_exception();
}
}
}
/* create, load and link the main class */
- if (!(mainclass = load_class_bootstrap(utf_new_char(mainstring))))
- throw_main_exception_exit();
+ mainclass = load_class_bootstrap(utf_new_char(mainstring));
+
+ if (mainclass == NULL)
+ exceptions_print_stacktrace();
if (!link_class(mainclass))
- throw_main_exception_exit();
+ exceptions_print_stacktrace();
if (opt_signature != NULL) {
m = class_resolveclassmethod(mainclass,
false);
}
- if (m == NULL) {
- char message[MAXLOGTEXT];
- sprintf(message, "%s%s", opt_method,
- opt_signature ? opt_signature : "");
-
- *exceptionptr =
- new_exception_message(string_java_lang_NoSuchMethodException,
- message);
-
- throw_main_exception_exit();
- }
+ if (m == NULL)
+ vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
+ opt_method, opt_signature ? opt_signature : "");
jit_compile(m);
}
{
java_objectheader *o;
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+ THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
+#endif
+
#if defined(ENABLE_JIT)
# if defined(ENABLE_INTRP)
if (opt_intrp)
o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
#endif
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+ THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
+#endif
+
return o;
}
{
s4 i;
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+ THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
+#endif
+
#if defined(ENABLE_JIT)
# if defined(ENABLE_INTRP)
if (opt_intrp)
i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
#endif
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+ THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
+#endif
+
return i;
}
{
s8 l;
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+ THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
+#endif
+
#if defined(ENABLE_JIT)
# if defined(ENABLE_INTRP)
if (opt_intrp)
l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
#endif
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+ THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
+#endif
+
return l;
}
{
float f;
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+ THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
+#endif
+
#if defined(ENABLE_JIT)
# if defined(ENABLE_INTRP)
if (opt_intrp)
f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
#endif
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+ THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
+#endif
+
return f;
}
{
double d;
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+ THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE;
+#endif
+
#if defined(ENABLE_JIT)
# if defined(ENABLE_INTRP)
if (opt_intrp)
d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
#endif
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+ THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE;
+#endif
+
return d;
}