src/vm/vm.c (vm_create): rename jvmti function calls
[cacao.git] / src / cacao / cacao.c
index 58b4a9c9130f9d279dff83110c8f2faa29fcd185..57a51f63545de682b8dba8c2b35bf7bd025549b4 100644 (file)
@@ -31,7 +31,7 @@
             Philipp Tomsich
             Christian Thalinger
 
-   $Id: cacao.c 4552 2006-03-04 17:15:44Z twisti $
+   $Id: cacao.c 4944 2006-05-23 15:31:19Z motse $
 
 */
 
 
 #include "vm/types.h"
 
-#include "mm/boehm.h"
-#include "mm/memory.h"
 #include "native/jni.h"
 #include "native/include/java_lang_String.h"
 
 #if defined(ENABLE_JVMTI)
 #include "native/jvmti/jvmti.h"
-#include "native/jvmti/dbg.h"
-#include <sys/types.h>
-#include <signal.h>
-#include <sys/wait.h>
+#include "native/jvmti/cacaodbg.h"
+
+#if defined(ENABLE_THREADS)
+#include <pthread.h>
+#endif
 #endif
 
 #include "toolbox/logging.h"
 #include "vm/jit/verify/typeinfo.h"
 #endif
 
-
 #ifdef TYPECHECK_STATISTICS
 void typecheck_print_statistics(FILE *file);
 #endif
 
-/* setup_debugger_process *****************************************************
-
-   Helper function to start JDWP threads
-
-*******************************************************************************/
-#if defined(ENABLE_JVMTI)
-
-static void setup_debugger_process(char* transport) {
-       java_objectheader *o;
-       methodinfo *m;
-       java_lang_String  *s;
-
-       /* new gnu.classpath.jdwp.Jdwp() */
-       mainclass = 
-               load_class_from_sysloader(utf_new_char("gnu.classpath.jdwp.Jdwp"));
-       if (!mainclass)
-               throw_main_exception_exit();
-
-       o = builtin_new(mainclass);
-
-       if (!o)
-               throw_main_exception_exit();
-       
-       m = class_resolveclassmethod(mainclass,
-                                                                utf_init, 
-                                                                utf_java_lang_String__void,
-                                                                class_java_lang_Object,
-                                                                true);
-       if (!m)
-               throw_main_exception_exit();
-
-       (void) vm_call_method_intern(m, o, NULL, NULL, NULL);
-
-       /* configure(transport,NULL) */
-       m = class_resolveclassmethod(
-               mainclass, utf_new_char("configure"), 
-               utf_new_char("(Ljava/lang/String;Ljava/lang/Thread;)V"),
-               class_java_lang_Object,
-               false);
-
-
-       s = javastring_new_char(transport);
-
-       (void) vm_call_method_intern(m, o, s, NULL, NULL);
-
-       if (!m)
-               throw_main_exception_exit();
-
-       /* _doInitialization */
-       m = class_resolveclassmethod(mainclass,
-                                                                utf_new_char("_doInitialization"), 
-                                                                utf_new_char("()V"),
-                                                                mainclass,
-                                                                false);
-       
-       if (!m)
-               throw_main_exception_exit();
-
-       (void) vm_call_method_intern(m, o, NULL, NULL, NULL);
-}
-#endif
-
-
 /* getmainclassfromjar *********************************************************
 
    Gets the name of the main class form a JAR's manifest file.
@@ -177,9 +112,9 @@ static char *getmainclassnamefromjar(char *mainstring)
        if (!m)
                throw_main_exception_exit();
 
-       s = javastring_new_char(mainstring);
+       s = javastring_new_from_ascii(mainstring);
 
-       (void) vm_call_method_intern(m, o, s, NULL, NULL);
+       (void) vm_call_method(m, o, s);
 
        if (*exceptionptr)
                throw_main_exception_exit();
@@ -195,7 +130,7 @@ static char *getmainclassnamefromjar(char *mainstring)
        if (!m)
                throw_main_exception_exit();
 
-       o = vm_call_method_intern(m, o, NULL, NULL, NULL);
+       o = vm_call_method(m, o);
 
        if (o == NULL) {
                fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
@@ -214,7 +149,7 @@ static char *getmainclassnamefromjar(char *mainstring)
        if (!m)
                throw_main_exception_exit();
 
-       o = vm_call_method_intern(m, o, NULL, NULL, 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);
@@ -233,9 +168,9 @@ static char *getmainclassnamefromjar(char *mainstring)
        if (!m)
                throw_main_exception_exit();
 
-       s = javastring_new_char("Main-Class");
+       s = javastring_new_from_ascii("Main-Class");
 
-       o = vm_call_method_intern(m, o, s, NULL, NULL);
+       o = vm_call_method(m, o, s);
 
        if (!o)
                throw_main_exception_exit();
@@ -243,10 +178,10 @@ static char *getmainclassnamefromjar(char *mainstring)
        return javastring_tochar(o);
 }
 
-
 void exit_handler(void);
 
 
+
 /* main ************************************************************************
 
    The main program.
@@ -255,7 +190,6 @@ void exit_handler(void);
 
 int main(int argc, char **argv)
 {
-       void *dummy;
        s4 i;
        
        /* local variables ********************************************************/
@@ -263,16 +197,6 @@ int main(int argc, char **argv)
        JavaVMInitArgs *vm_args;
        JavaVM         *jvm;                /* denotes a Java VM                  */
 
-#if defined(ENABLE_JVMTI)
-       bool dbg = false;
-       char *transport;
-       int waitval;
-#endif
-
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
-       stackbottom = &dummy;
-#endif
-       
        if (atexit(vm_exit_handler))
                throw_cacao_exception_exit(string_java_lang_InternalError,
                                                                   "Unable to register exit_handler");
@@ -289,10 +213,11 @@ int main(int argc, char **argv)
        
        /* load and initialize a Java VM, return a JNI interface pointer in env */
 
-       JNI_CreateJavaVM(&jvm, (void **) &_Jv_env, vm_args);
+       JNI_CreateJavaVM(&jvm, (void *) &_Jv_env, vm_args);
 
 #if defined(ENABLE_JVMTI)
-       set_jvmti_phase(JVMTI_PHASE_START);
+       pthread_mutex_init(&dbgcomlock,NULL);
+       jvmti_set_phase(JVMTI_PHASE_START);
 #endif
 
        /* do we have a main class? */
@@ -382,57 +307,24 @@ int main(int argc, char **argv)
 #endif
                /*class_showmethods(currentThread->group->header.vftbl->class); */
 
-#if defined(ENABLE_JVMTI) && defined(NATIVE_THREADS)
-               if(dbg) {
-                       debuggee = fork();
-                       if (debuggee == (-1)) {
-                               log_text("fork error");
-                               exit(1);
+#if defined(ENABLE_JVMTI)
+               /* start the jdwp listening thread*/
+               if (jdwp) {
+                       log_text("cacao vm - init VMjdwp");
+                       if (!jvmti_VMjdwpInit()) exit(1);
+                       setup_jdwp_thread(transport);
+                       if (!suspend) {
+                               fprintf(stderr,"suspend false -> continue debuggee\n");
                        } else {
-                               if (debuggee == 0) {
-                                       /* child: allow helper process to trace us  */
-                                       if (TRACEME != 0)  exit(0);
-                                       
-                                       /* give parent/helper debugger process control */
-                                       kill(0, SIGTRAP);  /* do we need this at this stage ? */
-
-                                       /* continue with normal startup */      
-
-                               } else {
-
-                                       /* parent/helper debugger process */
-                                       wait(&waitval);
-
-                                       remotedbgjvmtienv = new_jvmtienv();
-                                       /* set eventcallbacks */
-                                       if (JVMTI_ERROR_NONE == 
-                                               remotedbgjvmtienv->
-                                               SetEventCallbacks(remotedbgjvmtienv,
-                                                                                 &jvmti_jdwp_EventCallbacks,
-                                                                                 sizeof(jvmti_jdwp_EventCallbacks))){
-                                               log_text("unable to setup event callbacks");
-                                               vm_exit(1);
-                                       }
-
-                                       /* setup listening process (JDWP) */
-                                       setup_debugger_process(transport);
-
-                                       /* start to be debugged program */
-                                       CONT(debuggee);
-
-                    /* exit debugger process - todo: cleanup */
-                                       joinAllThreads();
-                                       cacao_exit(0);
-                               }
+                               fprintf(stderr,"suspend true -> do no continue debuggee(todo)\n");
+                               /* XXX todo*/
                        }
                }
-               else 
-                       debuggee= -1;
-               
+
+               jvmti_set_phase(JVMTI_PHASE_LIVE);
 #endif
-               /* here we go... */
 
-               (void) vm_call_method_intern(m, oa, NULL, NULL, NULL);
+               (void) vm_call_method(m, NULL, oa);
 
                /* exception occurred? */
 
@@ -450,8 +342,10 @@ int main(int argc, char **argv)
                vm_exit(status);
        }
 
-       /************* If requested, compile all methods ********************/
 
+       /* If requested, compile all methods. *************************************/
+
+#if !defined(NDEBUG)
        if (compileall) {
                classinfo *c;
                methodinfo *m;
@@ -482,7 +376,7 @@ int main(int argc, char **argv)
                                        if (!(c->state & CLASS_LINKED)) {
                                                if (!link_class(c)) {
                                                        fprintf(stderr, "Error linking: ");
-                                                       utf_fprint_classname(stderr, c->name);
+                                                       utf_fprint_printable_ascii_classname(stderr, c->name);
                                                        fprintf(stderr, "\n");
 
                                                        /* print out exception and cause */
@@ -503,10 +397,10 @@ int main(int argc, char **argv)
                                                if (m->jcode) {
                                                        if (!jit_compile(m)) {
                                                                fprintf(stderr, "Error compiling: ");
-                                                               utf_fprint_classname(stderr, c->name);
+                                                               utf_fprint_printable_ascii_classname(stderr, c->name);
                                                                fprintf(stderr, ".");
-                                                               utf_fprint(stderr, m->name);
-                                                               utf_fprint(stderr, m->descriptor);
+                                                               utf_fprint_printable_ascii(stderr, m->name);
+                                                               utf_fprint_printable_ascii(stderr, m->descriptor);
                                                                fprintf(stderr, "\n");
 
                                                                /* print out exception and cause */
@@ -519,10 +413,12 @@ int main(int argc, char **argv)
                        }
                }
        }
+#endif /* !defined(NDEBUG) */
 
 
-       /******** If requested, compile a specific method ***************/
+       /* If requested, compile a specific method. *******************************/
 
+#if !defined(NDEBUG)
        if (opt_method != NULL) {
                methodinfo *m;
 
@@ -564,6 +460,7 @@ int main(int argc, char **argv)
        }
 
        vm_shutdown(0);
+#endif /* !defined(NDEBUG) */
 
        /* keep compiler happy */