#include "native/include/java_lang_Object.h" /* required by j.l.C */
#include "native/include/java_lang_String.h" /* required by j.l.C */
-#if defined(WITH_CLASSPATH_SUN)
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
# include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
# include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
#endif
#include "native/vm/nativevm.h"
#include "threads/lock-common.h"
+#include "threads/mutex.h"
#include "threads/threadlist.h"
-#include "threads/threads-common.h"
+#include "threads/thread.h"
#include "toolbox/logging.h"
#include "vm/finalizer.h"
#include "vm/global.h"
#include "vm/initialize.h"
-#include "vm/package.h"
+#include "vm/package.hpp"
#include "vm/primitive.h"
#include "vm/properties.h"
#include "vm/signallocal.h"
#include "vm/jit/argument.h"
#include "vm/jit/asmpart.h"
+#include "vm/jit/code.h"
#if defined(ENABLE_DISASSEMBLER)
# include "vm/jit/disass.h"
#endif
#include "vm/jit/jit.h"
+#include "vm/jit/methodtree.h"
#if defined(ENABLE_PROFILING)
# include "vm/jit/optimizing/profile.h"
# include "vm/jit/python.h"
#endif
+#include "vm/jit/trap.h"
+
#include "vmcore/classcache.h"
#include "vmcore/options.h"
#include "vmcore/statistics.h"
bool vm_created = false;
bool vm_exiting = false;
-char *mainstring = NULL;
-classinfo *mainclass = NULL;
+static classinfo *mainclass = NULL;
#if defined(ENABLE_INTRP)
u1 *intrp_main_stack = NULL;
printf(" initial heap size : %d\n", HEAP_STARTSIZE);
printf(" stack size : %d\n", STACK_SIZE);
-#if defined(WITH_JRE_LAYOUT)
+#if defined(ENABLE_JRE_LAYOUT)
/* When we're building with JRE-layout, the default paths are the
same as the runtime paths. */
#else
-# if defined(WITH_CLASSPATH_GNU)
- puts(" gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
- puts(" java.boot.class.path : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
-# elif defined(WITH_CLASSPATH_SUN)
- puts(" sun.boot.library.path : "CLASSPATH_LIBDIR);
- puts(" java.boot.class.path : "CLASSPATH_CLASSES);
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+ puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
+ puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+ puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
+ puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
# endif
#endif
printf(" initial heap size : %d\n", opt_heapstartsize);
printf(" stack size : %d\n", opt_stacksize);
-#if defined(WITH_CLASSPATH_GNU)
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
-#elif defined(WITH_CLASSPATH_SUN)
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
#endif
static char *vm_get_mainclass_from_jar(char *mainstring);
#if !defined(NDEBUG)
static void vm_compile_all(void);
-static void vm_compile_method(void);
+static void vm_compile_method(char* mainname);
#endif
}
}
- /* get the main class *****************************************************/
-
- if (opt_index < vm_args->nOptions) {
- mainstring = vm_args->options[opt_index++].optionString;
-
- /* Put the jar file into the classpath (if any). */
-
- if (opt_jar == true) {
- /* free old classpath */
-
-/* MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
-
- /* put jarfile into classpath */
-
- p = MNEW(char, strlen(mainstring) + strlen("0"));
-
- strcpy(p, mainstring);
-
-#if defined(ENABLE_JAVASE)
- properties_add("java.class.path", p);
-#endif
- }
- else {
- /* replace .'s with /'s in classname */
-
- for (i = strlen(mainstring) - 1; i >= 0; i--)
- if (mainstring[i] == '.')
- mainstring[i] = '/';
- }
- }
-
#if defined(ENABLE_JVMTI)
if (jvmti) {
jvmti_set_phase(JVMTI_PHASE_ONLOAD);
if (!finalizer_init())
vm_abort("vm_create: finalizer_init failed");
- /* initializes jit compiler */
+ /* Initialize the JIT compiler. */
jit_init();
+ code_init();
+ methodtree_init();
#if defined(ENABLE_PYTHON)
pythonpass_init();
/* BEFORE: loader_preinit */
- package_init();
+ Package_initialize();
/* AFTER: utf8_init, classcache_init */
/* AFTER: loader_init, linker_init */
primitive_postinit();
+ method_init();
- exceptions_init();
+#if defined(ENABLE_JIT)
+ trap_init();
+#endif
if (!builtin_init())
vm_abort("vm_create: builtin_init failed");
/* Register the native methods implemented in the VM. */
/* BEFORE: threads_init */
- if (!nativevm_preinit())
- vm_abort("vm_create: nativevm_preinit failed");
+ nativevm_preinit();
#if defined(ENABLE_JNI)
/* Initialize the JNI subsystem (must be done _before_
vm_abort("vm_create: localref_table_init failed");
#endif
+ /* Iinitialize some important system classes. */
+ /* BEFORE: threads_init */
+
+ initialize_init();
+
#if defined(ENABLE_THREADS)
threads_init();
#endif
/* Initialize the native VM subsystem. */
/* AFTER: threads_init (at least for SUN's classes) */
- if (!nativevm_init())
- vm_abort("vm_create: nativevm_init failed");
+ nativevm_init();
#if defined(ENABLE_PROFILING)
/* initialize profiling */
void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
{
+ char* option;
+ char* mainname;
+ char* p;
utf *mainutf;
classinfo *mainclass;
java_handle_t *e;
s4 oalength;
utf *u;
java_handle_t *s;
- s4 status;
- s4 i;
+ int status;
+ int i;
+
+ // Prevent compiler warnings.
+ oa = NULL;
#if !defined(NDEBUG)
if (compileall) {
vm_compile_all();
return;
}
+#endif
- if (opt_method != NULL) {
- vm_compile_method();
- return;
+ /* Get the main class plus it's arguments. */
+
+ mainname = NULL;
+
+ if (opt_index < vm_args->nOptions) {
+ /* Get main-class argument. */
+
+ mainname = vm_args->options[opt_index].optionString;
+
+ /* If the main class argument is a jar file, put it into the
+ classpath. */
+
+ if (opt_jar == true) {
+ p = MNEW(char, strlen(mainname) + strlen("0"));
+
+ strcpy(p, mainname);
+
+#if defined(ENABLE_JAVASE)
+ properties_add("java.class.path", p);
+#endif
+ }
+ else {
+ /* Replace dots with slashes in the class name. */
+
+ for (i = 0; i < strlen(mainname); i++)
+ if (mainname[i] == '.')
+ mainname[i] = '/';
+ }
+
+ /* Build argument array. Move index to first argument. */
+
+ opt_index++;
+
+ oalength = vm_args->nOptions - opt_index;
+
+ oa = builtin_anewarray(oalength, class_java_lang_String);
+
+ for (i = 0; i < oalength; i++) {
+ option = vm_args->options[opt_index + i].optionString;
+
+ u = utf_new_char(option);
+ s = javastring_new(u);
+
+ array_objectarray_element_set(oa, i, s);
+ }
}
-#endif /* !defined(NDEBUG) */
- /* should we run the main-method? */
+ /* Do we have a main-class argument? */
- if (mainstring == NULL)
+ if (mainname == NULL)
usage();
+#if !defined(NDEBUG)
+ if (opt_method != NULL) {
+ vm_compile_method(mainname);
+ return;
+ }
+#endif
+
/* set return value to OK */
status = 0;
if (opt_jar == true) {
/* open jar file with java.util.jar.JarFile */
- mainstring = vm_get_mainclass_from_jar(mainstring);
+ mainname = vm_get_mainclass_from_jar(mainname);
- if (mainstring == NULL)
+ if (mainname == NULL)
vm_exit(1);
}
/* load the main class */
- mainutf = utf_new_char(mainstring);
+ mainutf = utf_new_char(mainname);
#if defined(ENABLE_JAVAME_CLDC1_1)
mainclass = load_class_bootstrap(mainutf);
vm_exit(1);
}
- /* build argument array */
-
- oalength = vm_args->nOptions - opt_index;
-
- oa = builtin_anewarray(oalength, class_java_lang_String);
-
- for (i = 0; i < oalength; i++) {
- u = utf_new_char(vm_args->options[opt_index + i].optionString);
- s = javastring_new(u);
-
- array_objectarray_element_set(oa, i, s);
- }
-
#ifdef TYPEINFO_DEBUG_TEST
/* test the typeinfo system */
typeinfo_test();
#endif
- /*class_showmethods(currentThread->group->header.vftbl->class); */
#if defined(ENABLE_JVMTI)
jvmti_set_phase(JVMTI_PHASE_LIVE);
status = 1;
}
- /* unload the JavaVM */
+#if defined(ENABLE_THREADS)
+ /* Detach the main thread so that it appears to have ended when
+ the application's main method exits. */
+
+ if (!thread_detach_current_thread())
+ vm_abort("vm_run: Could not detach main thread.");
+#endif
+
+ /* Destroy the JavaVM. */
(void) vm_destroy(vm);
- /* and exit */
+ /* And exit. */
vm_exit(status);
}
*******************************************************************************/
-s4 vm_destroy(JavaVM *vm)
+int vm_destroy(JavaVM *vm)
{
#if defined(ENABLE_THREADS)
+ /* Create a a trivial new Java waiter thread called
+ "DestroyJavaVM". */
+
+ JavaVMAttachArgs args;
+
+ args.name = "DestroyJavaVM";
+ args.group = NULL;
+
+ if (!thread_attach_current_thread(&args, false))
+ return 1;
+
+ /* Wait until we are the last non-daemon thread. */
+
threads_join_all_threads();
#endif
vm_created = false;
- /* everything's ok */
+ /* Everything is ok. */
return 0;
}
#if defined(ENABLE_JVMTI)
/* terminate cacaodbgserver */
if (dbgcom!=NULL) {
- pthread_mutex_lock(&dbgcomlock);
+ mutex_lock(&dbgcomlock);
dbgcom->running=1;
- pthread_mutex_unlock(&dbgcomlock);
+ mutex_unlock(&dbgcomlock);
jvmti_cacaodbgserver_quit();
}
#endif
*******************************************************************************/
-static char *vm_get_mainclass_from_jar(char *mainstring)
+static char *vm_get_mainclass_from_jar(char *mainname)
{
classinfo *c;
java_handle_t *o;
return NULL;
}
- s = javastring_new_from_ascii(mainstring);
+ s = javastring_new_from_ascii(mainname);
(void) vm_call_method(m, o, s);
o = vm_call_method(m, o);
if (o == NULL) {
- fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
+ fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainname);
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);
+ fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainname);
return NULL;
}
o = vm_call_method(m, o, s);
if (o == NULL) {
- exceptions_print_stacktrace();
+ fprintf(stderr, "Failed to load Main-Class manifest attribute from\n");
+ fprintf(stderr, "%s\n", mainname);
return NULL;
}
*******************************************************************************/
#if !defined(NDEBUG)
-static void vm_compile_method(void)
+static void vm_compile_method(char* mainname)
{
methodinfo *m;
/* create, load and link the main class */
- mainclass = load_class_bootstrap(utf_new_char(mainstring));
+ mainclass = load_class_bootstrap(utf_new_char(mainname));
if (mainclass == NULL)
exceptions_print_stacktrace();