X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fvm%2Fvm.c;h=6c192e277174db21e42d97b5a8c5e5b63385e88a;hb=e6d0cee8fc14f4d50201631761f6a10da3611271;hp=3a44d2daec65ab4e5df0f31bcdf3547413e1c943;hpb=a18f7606d521cf6c36bfb9c4702e1740dd62da2e;p=cacao.git diff --git a/src/vm/vm.c b/src/vm/vm.c index 3a44d2dae..6c192e277 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -49,7 +49,7 @@ #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 @@ -59,7 +59,6 @@ #include "native/vm/nativevm.h" #include "threads/lock-common.h" -#include "threads/mutex.h" #include "threads/threadlist.h" #include "threads/thread.h" @@ -76,7 +75,7 @@ #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" @@ -135,8 +134,7 @@ bool vm_initializing = false; 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; @@ -635,16 +633,16 @@ static void vm_printconfig(void) 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 @@ -655,9 +653,9 @@ static void vm_printconfig(void) 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 @@ -671,7 +669,7 @@ static void vm_printconfig(void) 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 @@ -1363,37 +1361,6 @@ bool vm_create(JavaVMInitArgs *vm_args) } } - /* 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); @@ -1424,7 +1391,6 @@ bool vm_create(JavaVMInitArgs *vm_args) threads_preinit(); lock_init(); - critical_init(); #endif /* install architecture dependent signal handlers */ @@ -1499,7 +1465,7 @@ bool vm_create(JavaVMInitArgs *vm_args) /* BEFORE: loader_preinit */ - package_init(); + Package_initialize(); /* AFTER: utf8_init, classcache_init */ @@ -1657,6 +1623,9 @@ bool vm_create(JavaVMInitArgs *vm_args) void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args) { + char* option; + char* mainname; + char* p; utf *mainutf; classinfo *mainclass; java_handle_t *e; @@ -1668,27 +1637,75 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args) int status; int i; -#if defined(ENABLE_THREADS) - threadobject *t; -#endif + // 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; @@ -1696,15 +1713,15 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args) 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); @@ -1752,24 +1769,10 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args) 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); @@ -1800,9 +1803,7 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args) /* Detach the main thread so that it appears to have ended when the application's main method exits. */ - t = thread_get_current(); - - if (!threads_detach_thread(t)) + if (!thread_detach_current_thread()) vm_abort("vm_run: Could not detach main thread."); #endif @@ -1833,7 +1834,7 @@ int vm_destroy(JavaVM *vm) args.name = "DestroyJavaVM"; args.group = NULL; - if (!threads_attach_current_thread(&args, false)) + if (!thread_attach_current_thread(&args, false)) return 1; /* Wait until we are the last non-daemon thread. */ @@ -1925,11 +1926,12 @@ void vm_shutdown(s4 status) } #if defined(ENABLE_JVMTI) +# error This should be a JVMTI function. /* terminate cacaodbgserver */ if (dbgcom!=NULL) { - mutex_lock(&dbgcomlock); + Mutex_lock(&dbgcomlock); dbgcom->running=1; - mutex_unlock(&dbgcomlock); + Mutex_unlock(&dbgcomlock); jvmti_cacaodbgserver_quit(); } #endif @@ -2137,7 +2139,7 @@ void vm_abort_disassemble(void *pc, int count, const char *text, ...) *******************************************************************************/ -static char *vm_get_mainclass_from_jar(char *mainstring) +static char *vm_get_mainclass_from_jar(char *mainname) { classinfo *c; java_handle_t *o; @@ -2171,7 +2173,7 @@ static char *vm_get_mainclass_from_jar(char *mainstring) return NULL; } - s = javastring_new_from_ascii(mainstring); + s = javastring_new_from_ascii(mainname); (void) vm_call_method(m, o, s); @@ -2196,7 +2198,7 @@ static char *vm_get_mainclass_from_jar(char *mainstring) 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; } @@ -2219,7 +2221,7 @@ static char *vm_get_mainclass_from_jar(char *mainstring) 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; } @@ -2244,7 +2246,8 @@ static char *vm_get_mainclass_from_jar(char *mainstring) 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; } @@ -2337,13 +2340,13 @@ static void vm_compile_all(void) *******************************************************************************/ #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();