* src/native/vm/openjdk/jvm.cpp (JVM_CurrentClassLoader): Implemented.
[cacao.git] / src / vm / vm.cpp
index 5719f86ff01f6f4c903c577ccfe927b7d968d7e0..1239da685cfc3c129b10ff7f81576d1a2ee68b83 100644 (file)
@@ -74,7 +74,7 @@
 #include "vm/os.hpp"
 #include "vm/primitive.hpp"
 #include "vm/properties.hpp"
-#include "vm/signallocal.h"
+#include "vm/signallocal.hpp"
 #include "vm/statistics.h"
 #include "vm/string.hpp"
 #include "vm/suck.hpp"
 # include "vm/jit/python.h"
 #endif
 
-#include "vm/jit/trap.h"
+#include "vm/jit/trap.hpp"
 
 #if defined(ENABLE_JVMTI)
 # include "native/jvmti/cacaodbg.h"
@@ -206,12 +206,6 @@ enum {
        OPT_SHOW,
        OPT_DEBUGCOLOR,
 
-#if !defined(NDEBUG)
-       OPT_ALL,
-       OPT_METHOD,
-       OPT_SIGNATURE,
-#endif
-
 #if defined(ENABLE_VERIFIER)
        OPT_NOVERIFY,
        OPT_XVERIFY_ALL,
@@ -325,11 +319,6 @@ opt_struct opts[] = {
        { "c",                 true,  OPT_CHECK },
        { "l",                 false, OPT_LOAD },
 
-#if !defined(NDEBUG)
-       { "all",               false, OPT_ALL },
-       { "sig",               true,  OPT_SIGNATURE },
-#endif
-
 #if defined(ENABLE_LOOP)
        { "oloop",             false, OPT_OLOOP },
 #endif
@@ -390,10 +379,6 @@ opt_struct opts[] = {
 
        /* keep these at the end of the list */
 
-#if !defined(NDEBUG)
-       { "m",                 true,  OPT_METHOD },
-#endif
-
        { "s",                 true,  OPT_SHOW },
        { "debug-color",      false,  OPT_DEBUGCOLOR },
 
@@ -525,11 +510,6 @@ static void XXusage(void)
        puts("    -oloop                   optimize array accesses in loops");
 #endif
        puts("    -l                       don't start the class after loading");
-#if !defined(NDEBUG)
-       puts("    -all                     compile all methods, no execution");
-       puts("    -m                       compile only a specific method");
-       puts("    -sig                     specify signature for a specific method");
-#endif
 
        puts("    -s...                    show...");
        puts("      (c)onstants            the constant pool");
@@ -1084,24 +1064,6 @@ VM::VM(JavaVMInitArgs* vm_args)
                        makeinitializations = false;
                        break;
 
-#if !defined(NDEBUG)
-               case OPT_ALL:
-                       compileall = true;
-                       opt_run = false;
-                       makeinitializations = false;
-                       break;
-
-               case OPT_METHOD:
-                       opt_run = false;
-                       opt_method = opt_arg;
-                       makeinitializations = false;
-                       break;
-
-               case OPT_SIGNATURE:
-                       opt_signature = opt_arg;
-                       break;
-#endif
-
                case OPT_SHOW:       /* Display options */
                        for (unsigned int i = 0; i < strlen(opt_arg); i++) {            
                                switch (opt_arg[i]) {
@@ -1370,10 +1332,7 @@ VM::VM(JavaVMInitArgs* vm_args)
 
        /* AFTER: thread_preinit */
 
-       if (!suck_init())
-               os::abort("vm_create: suck_init failed");
-
-       suck_add_from_property("java.endorsed.dirs");
+       _suckclasspath.add_from_property("java.endorsed.dirs");
 
        /* Now we have all options handled and we can print the version
           information.
@@ -1387,7 +1346,7 @@ VM::VM(JavaVMInitArgs* vm_args)
 
        // FIXME Make boot_class_path const char*.
        boot_class_path = (char*) _properties.get("sun.boot.class.path");
-       suck_add(boot_class_path);
+       _suckclasspath.add(boot_class_path);
 
        /* initialize the classcache hashtable stuff: lock, hashtable
           (must be done _after_ threads_preinit) */
@@ -1472,7 +1431,8 @@ VM::VM(JavaVMInitArgs* vm_args)
        /* Initialize the native VM subsystem. */
        /* AFTER: threads_init (at least for SUN's classes) */
 
-       nativevm_init();
+       if (!nativevm_init())
+               os::abort("vm_create: nativevm_init failed");
 
 #if defined(ENABLE_PROFILING)
        /* initialize profiling */
@@ -1617,32 +1577,19 @@ void VM::print_run_time_config()
 
 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
 {
-       char*                      option;
-       char*                      mainname;
-       char*                      p;
-       utf                       *mainutf;
-       classinfo                 *mainclass;
-       java_handle_t             *e;
-       methodinfo                *m;
-       java_handle_objectarray_t *oa; 
-       s4                         oalength;
-       utf                       *u;
-       java_handle_t             *s;
-       int                        status;
-
-       // Prevent compiler warnings.
-       oa = NULL;
+       methodinfo* m;
+       int         status;
 
 #if !defined(NDEBUG)
-       if (compileall) {
+       if (opt_CompileAll) {
                vm_compile_all();
                return;
        }
 #endif
 
-       /* Get the main class plus it's arguments. */
+       /* Get the main class or jar file argument. */
 
-       mainname = NULL;
+       char* mainname = NULL;
 
        if (opt_index < vm_args->nOptions) {
                /* Get main-class argument. */
@@ -1653,7 +1600,7 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
                   classpath. */
 
                if (opt_jar == true) {
-                       p = MNEW(char, strlen(mainname) + strlen("0"));
+                       char* p = MNEW(char, strlen(mainname) + strlen("0"));
 
                        strcpy(p, mainname);
 
@@ -1669,22 +1616,9 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
                                        mainname[i] = '/';
                }
 
-               /* Build argument array.  Move index to first argument. */
+               /* Move index to first argument. */
 
                opt_index++;
-
-               oalength = vm_args->nOptions - opt_index;
-
-               oa = builtin_anewarray(oalength, class_java_lang_String);
-
-               for (int 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);
-               }
        }
 
        /* Do we have a main-class argument? */
@@ -1693,12 +1627,30 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
                usage();
 
 #if !defined(NDEBUG)
-       if (opt_method != NULL) {
+       if (opt_CompileMethod != NULL) {
                vm_compile_method(mainname);
                return;
        }
 #endif
 
+       /* Build argument array. */
+
+       int32_t oalength = vm_args->nOptions - opt_index;
+
+       ObjectArray oa(oalength, class_java_lang_String);
+
+       if (oa.is_null())
+               vm_exit(1);
+
+       for (int i = 0; i < oalength; i++) {
+               char* option = vm_args->options[opt_index + i].optionString;
+
+               utf*           u = utf_new_char(option);
+               java_handle_t* s = javastring_new(u);
+
+               oa.set_element(i, s);
+       }
+
        /* set return value to OK */
 
        status = 0;
@@ -1714,17 +1666,17 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
 
        /* load the main class */
 
-       mainutf = utf_new_char(mainname);
+       utf* mainutf = utf_new_char(mainname);
 
 #if defined(ENABLE_JAVAME_CLDC1_1)
-       mainclass = load_class_bootstrap(mainutf);
+       classinfo* mainclass = load_class_bootstrap(mainutf);
 #else
-       mainclass = load_class_from_sysloader(mainutf);
+       classinfo* mainclass = load_class_from_sysloader(mainutf);
 #endif
 
        /* error loading class */
 
-       e = exceptions_get_and_clear_exception();
+       java_handle_t* e = exceptions_get_and_clear_exception();
 
        if ((e != NULL) || (mainclass == NULL)) {
                exceptions_throw_noclassdeffounderror_cause(e);
@@ -1784,7 +1736,7 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
 
        /* start the main thread */
 
-       (void) vm_call_method(m, NULL, oa);
+       (void) vm_call_method(m, NULL, oa.get_handle());
 
        /* exception occurred? */
 
@@ -2059,7 +2011,11 @@ static char *vm_get_mainclass_from_jar(char *mainname)
        methodinfo    *m;
        java_handle_t *s;
 
+#if defined(ENABLE_JAVAME_CLDC1_1)
+       c = load_class_bootstrap(utf_new_char("java/util/jar/JarFile"));
+#else
        c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
+#endif
 
        if (c == NULL) {
                exceptions_print_stacktrace();
@@ -2267,16 +2223,16 @@ static void vm_compile_method(char* mainname)
        if (!link_class(mainclass))
                exceptions_print_stacktrace();
 
-       if (opt_signature != NULL) {
+       if (opt_CompileSignature != NULL) {
                m = class_resolveclassmethod(mainclass,
-                                                                        utf_new_char(opt_method),
-                                                                        utf_new_char(opt_signature),
+                                                                        utf_new_char(opt_CompileMethod),
+                                                                        utf_new_char(opt_CompileSignature),
                                                                         mainclass,
                                                                         false);
        }
        else {
                m = class_resolveclassmethod(mainclass,
-                                                                        utf_new_char(opt_method),
+                                                                        utf_new_char(opt_CompileMethod),
                                                                         NULL,
                                                                         mainclass,
                                                                         false);
@@ -2284,7 +2240,7 @@ static void vm_compile_method(char* mainname)
 
        if (m == NULL)
                os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
-                                opt_method, opt_signature ? opt_signature : "");
+                                opt_CompileMethod, opt_CompileSignature ? opt_CompileSignature : "");
                
        jit_compile(m);
 }
@@ -2564,27 +2520,22 @@ void vm_abort(const char* text, ...)
 {
        va_list ap;
 
-       va_start(ap, text);
-       os::abort(text, ap);
-       va_end(ap);
-}
+       log_println("vm_abort: WARNING, port me to C++ and use os::abort() instead.");
 
-void vm_abort_errnum(int errnum, const char* text, ...)
-{
-       va_list ap;
+       // Print the log message.
+       log_start();
 
        va_start(ap, text);
-       os::abort_errnum(errnum, text, ap);
+       log_vprint(text, ap);
        va_end(ap);
-}
 
-void vm_abort_errno(const char* text, ...)
-{
-       va_list ap;
+       log_finish();
 
-       va_start(ap, text);
-       os::abort_errno(text, ap);
-       va_end(ap);
+       // Print a backtrace.
+       os::print_backtrace();
+
+       // Now abort the VM.
+       os::abort();
 }
 
 }