src/native/vm/VMVirtualMachine.c (unregisterEvent): print error message
authormotse <none@none>
Tue, 6 Jun 2006 21:13:41 +0000 (21:13 +0000)
committermotse <none@none>
Tue, 6 Jun 2006 21:13:41 +0000 (21:13 +0000)
src/native/jvmti/cacaodbg.c (jvmti_cacao_debug_init): set  variable jvmti

src/native/jvmti/VMjdwp.c: add jmethodID and jclass cache variables. Add new callback functions to jvmti_jdwp_EventCallbacks
(ThreadStart/ThreadEnd/ClassPrepare/Breakpoint): add ThreadStart/ThreadEnd event callbackes implementation who notify jdwp.
(Exception/MethodEntry): dummy implementation. There are no jdwp exeception/MethodEntry events in gnu classpath yet.
(setup_jdwp_thread): use cache variables.
FINDCLASSWITHEXCEPTION/GETMIDWITHEXCEPTION: helper macros to ease jni findclass and getmethodid.
(fillidcache): new function that fills valid jmethodIDs and jclasses in the cache variables.
(VMInit): add call to fillidcache.
(Agent_OnLoad): do not enable all jvmti callbacks anymore. Only enable needed VMInit callback. The other callbacks will be enable with VMVirtualMachine.registerEvent by need.

src/native/jvmti.c (dofireEvent): check if a valid event callback is available before executing it.
(SetEventNotificationMode): ThreadStart/End event are no more implemented as breakpoints but have direct function calls to dofireEvent.
(SuspendThread/ResumeThread/getcacaostacktrace): sketch for further implementation of this function. Final threads_suspend* functions are not yet available.
(GetArgumentsSize):  new implementation using parsed descriptors.
(GetMethodLocation): add checks for JVMTI_ERROR_NATIVE_METHOD (Samuel Vinson). And return -1 as return values for this dummy implementation.
(GetJLocationFormat): JLocationFormat probably will be JVMTI_JLOCATION_OTHER

src/native/jvmti/VMjdwp.h: add jdwpthread which stores the thread object for the jdwp listening thread.

src/threads/native/threads.h: remove jvmti_get_threads_breakpoints beacause ThreadStart/End events are implemented as direct function calls by now.

src/threads/native/threads.c (threads_startup_thread): replace ThreadStart/End event implementation.
(jvmti_get_threads_breakpoints): removed.

src/cacaoh/headers.c (jvmti_fireEvent): added dummy implementation to enable linking of cacaoh.

12 files changed:
src/cacaoh/headers.c
src/native/jvmti/VMjdwp.c
src/native/jvmti/VMjdwp.h
src/native/jvmti/cacaodbg.c
src/native/jvmti/cacaodbg.h
src/native/jvmti/cacaodbgserver.c
src/native/jvmti/jvmti.c
src/native/jvmti/jvmti.h
src/native/vm/VMMethod.c
src/native/vm/VMVirtualMachine.c
src/threads/native/threads.c
src/threads/native/threads.h

index 817eddccb66665e0cf62b376e78e93202fb29ed0..f01b1a9099224ed01a144edf29dfc3be72eefc12 100644 (file)
@@ -31,7 +31,7 @@
             Christian Thalinger
                        Edwin Steiner
 
-   $Id: headers.c 4938 2006-05-22 09:06:44Z twisti $
+   $Id: headers.c 5019 2006-06-06 21:13:41Z motse $
 
 */
 
@@ -887,6 +887,13 @@ void print_classname(classinfo *clazz)
        }
 } 
 
+/* jvmti releated functions ************************************************/
+
+#if defined(ENABLE_JVMTI)
+void jvmti_fireEvent(void* d) {;}
+#endif
+
+
 
 /*
  * These are local overrides for various environment variables in Emacs.
index 82281eb8a45f666fa1d4d3c8ce48e511e92a21d6..647596ca89ef4eaad5aea85f1131c7adc80de53f 100644 (file)
@@ -29,7 +29,7 @@
    Changes:             
 
 
-   $Id: VMjdwp.c 4996 2006-05-31 13:53:16Z motse $
+   $Id: VMjdwp.c 5019 2006-06-06 21:13:41Z motse $
 
 */
 
@@ -50,55 +50,149 @@ void printjvmtierror(char *desc, jvmtiError err) {
 }
 
 
-
-static jmethodID notifymid = NULL;
-static jclass Jdwpclass = NULL;
+/* class and method IDs */
+static jclass Jdwpclass, threadstartclass,threadendclass, classprepareclass,   vmmethodclass, locationclass, breakpointclass;
+static jmethodID notifymid, threadstartmid,threadendmid, classpreparemid, 
+       vmmethodmid, locationmid, breakpointmid;
 
 static void notify (JNIEnv* jni_env, jobject event){
-       fprintf(stderr,"VMjdwp notfiy called");
-
-    if (notifymid == NULL) {
-               notifymid = (*jni_env)->
-                       GetStaticMethodID(jni_env,Jdwpclass,
-                                                         "notify","(Lgnu/classpath/jdwp/event/Event;)V");
-                       if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
-                               fprintf(stderr,"could not get notify method\n");
-                               (*jni_env)->ExceptionDescribe(jni_env);
-                               exit(1); 
-                       }
-    }
-    
+       fprintf(stderr,"VMjdwp notfiy called\n");
+
        (*jni_env)->CallStaticVoidMethod(jni_env,Jdwpclass,notifymid,event);
     if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
         fprintf(stderr,"Exception occourred in notify mehtod\n");
                (*jni_env)->ExceptionDescribe(jni_env);
-               exit(1); 
        }
 
 }
 
-/*static void ThreadStart (jvmtiEnv *jvmti_env,
-                         JNIEnv* jni_env,
+static void ThreadStart (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
                          jthread thread){
-       jclass cl;
-       jmethodID cc;
        jobject obj;
 
-       GETJNIMETHOD(jni_env,cl,"gnu/classpath/jdwp/event/ThreadStartEvent",cc,"<init>","(Ljava/lang/Thread;)V"); 
-
-       obj = builtin_new(cl);
-       if (!obj) throw_main_exception_exit();
+       obj = (*jni_env)->
+               NewObject(jni_env, threadstartclass, threadstartmid, thread);
+       if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+        fprintf(stderr,"error calling ThreadStartEvent constructor\n");
+               (*jni_env)->ExceptionDescribe(jni_env);
+               return;
+       }
 
        fprintf(stderr,"VMjdwp:ThreadStart: thread %p\n",thread);
        fflush(stderr);
 
-       vm_call_method((methodinfo*)cc, obj, thread);
+       notify (jni_env,obj);
+}
+
+
+static void ThreadEnd (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+                         jthread thread){
+       jobject obj;
+
+
+       obj = (*jni_env)->NewObject(jni_env, threadendclass, threadendmid, thread);
+       if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+        fprintf(stderr,"error calling ThreadEndEvent constructor\n");
+               (*jni_env)->ExceptionDescribe(jni_env);
+               return;
+       }
+
+       fprintf(stderr,"VMjdwp:ThreadEnd: thread %p\n",thread);
+       fflush(stderr);
+
+       notify (jni_env,obj);
+}
+
+
+static void ClassPrepare (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+                                                 jthread thread, jclass klass) {
+       jobject obj;
+       int classstatus;
+       jvmtiError e;
+
+       if (JVMTI_ERROR_NONE != 
+               (e = (*jvmtienv)->GetClassStatus(jvmtienv, klass, &classstatus))) {
+               printjvmtierror("unable to get class status", e);
+               return;
+       }
 
-       if (*exceptionptr)
-               throw_main_exception_exit();
+       obj = (*jni_env)->NewObject(jni_env, classprepareclass, classpreparemid, thread, klass, classstatus);
+       if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+        fprintf(stderr,"error calling ClassPrepareEvent constructor\n");
+               (*jni_env)->ExceptionDescribe(jni_env);
+               return;
+       }
+
+       fprintf(stderr,"VMjdwp:ClassPrepareEvent: thread %p\n",thread);
+       fflush(stderr);
 
        notify (jni_env,obj);
-       } */
+}
+
+static void Exception (jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
+                                          jmethodID method, jlocation location, jobject exception,
+                                          jmethodID catch_method, jlocation catch_location) {
+       /* gnu classpath jdwp has no ExceptionEvent yet */
+       fprintf(stderr,"VMjdwp:Exception: thread %p\n",thread);
+       fflush(stderr);
+       
+}
+
+static void Breakpoint (jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
+                                               jmethodID method, jlocation location) {
+       jobject vmmethod, loc, ev;
+       jclass mcl;
+       jvmtiError e;
+
+       if (JVMTI_ERROR_NONE != 
+               (e = (*jvmtienv)->GetMethodDeclaringClass(jvmtienv,
+                                                                          method,
+                                                                          &mcl))){
+               printjvmtierror("unable to get declaring class", e);
+               return;
+       }
+
+       vmmethod = (*jni_env)->NewObject(jni_env, vmmethodclass, vmmethodmid, 
+                                                                        mcl, method);
+       if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+        fprintf(stderr,"error calling VMMethod constructor\n");
+               (*jni_env)->ExceptionDescribe(jni_env);
+               return;
+       }
+
+       loc = (*jni_env)->NewObject(jni_env, locationclass, locationmid, 
+                                                                        vmmethod, location);
+       if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+        fprintf(stderr,"error calling location constructor\n");
+               (*jni_env)->ExceptionDescribe(jni_env);
+               return;
+       }
+       
+       ev = (*jni_env)->NewObject(jni_env, breakpointclass, breakpointmid, 
+                                                                        thread, loc);
+       if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+        fprintf(stderr,"error calling breakpoint constructor\n");
+               (*jni_env)->ExceptionDescribe(jni_env);
+               return;
+       }
+
+       fprintf(stderr,"VMjdwp:Breakpoint: thread %p\n",thread);
+       fflush(stderr);
+
+       notify (jni_env,ev);    
+}
+
+
+static void MethodEntry (jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+                                                jthread thread, jmethodID method) {
+       /* do not report gnu/classpath/jdwp method entries */
+}
+
+
+static void VMDeath (jvmtiEnv *jvmti_env,
+                     JNIEnv* jni_env) {
+  fprintf(stderr,"JVMTI-Event: IMPLEMENT ME!!!");
+}
 
 
 /* setup_jdwp_thread **********************************************************
@@ -113,14 +207,6 @@ static void setup_jdwp_thread(JNIEnv* jni_env) {
        jstring  s;
 
        /* new gnu.classpath.jdwp.Jdwp() */
-    Jdwpclass = (*jni_env)->FindClass(jni_env, "gnu/classpath/jdwp/Jdwp"); 
-    if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
-        fprintf(stderr,"could not find gnu/classpath/jdwp/Jdwp\n");
-               (*jni_env)->ExceptionDescribe(jni_env);
-               exit(1); 
-       }
-
-       
        m = (*jni_env)->GetMethodID(jni_env,Jdwpclass,"<init>","()V");
     if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
         fprintf(stderr,"could not get Jdwp constructor\n");
@@ -134,6 +220,8 @@ static void setup_jdwp_thread(JNIEnv* jni_env) {
                (*jni_env)->ExceptionDescribe(jni_env);
                exit(1); 
        }
+
+       jdwpthread = (jthread)o;
        
        
        /* configure(jdwpoptions) */
@@ -177,6 +265,66 @@ static void setup_jdwp_thread(JNIEnv* jni_env) {
        }
 }
 
+#define FINDCLASSWITHEXCEPTION(CLASS,SIGNATURE) \
+       CLASS = (*jni_env)->FindClass(jni_env, SIGNATURE);     \
+       if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {  \
+               fprintf(stderr,"could not find %s\n", SIGNATURE);  \
+               (*jni_env)->ExceptionDescribe(jni_env);            \
+               exit(1);                                           \
+       }
+#define GETMIDWITHEXCEPTION(CLASS, CLASSNAME, MID, METHODNAME, METHODSIG) \
+       FINDCLASSWITHEXCEPTION(CLASS, CLASSNAME);                             \
+       MID = (*jni_env)->GetMethodID(jni_env, CLASS, METHODNAME, METHODSIG); \
+    if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {                 \
+        fprintf(stderr,"could not get %s %s\n",CLASSNAME, METHODNAME);    \
+               (*jni_env)->ExceptionDescribe(jni_env);                           \
+               exit(1);                                                          \
+       }
+
+
+static void fillidcache(JNIEnv* jni_env) {
+       FINDCLASSWITHEXCEPTION(Jdwpclass, "gnu/classpath/jdwp/Jdwp");
+       
+       notifymid = (*jni_env)->
+        GetStaticMethodID(jni_env,Jdwpclass,
+                                          "notify","(Lgnu/classpath/jdwp/event/Event;)V");
+       if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
+               fprintf(stderr,"could not get notify method\n");
+               (*jni_env)->ExceptionDescribe(jni_env);
+               exit(1); 
+       }
+
+       GETMIDWITHEXCEPTION(threadstartclass, 
+                                               "gnu/classpath/jdwp/event/ThreadStartEvent", 
+                                               threadstartmid, "<init>", "(Ljava/lang/Thread;)V");
+
+
+       GETMIDWITHEXCEPTION(threadendclass, 
+                                               "gnu/classpath/jdwp/event/ThreadEndEvent", 
+                                               threadendmid, "<init>", "(Ljava/lang/Thread;)V");
+
+
+       GETMIDWITHEXCEPTION(classprepareclass, 
+                                               "gnu/classpath/jdwp/event/ClassPrepareEvent", 
+                                               classpreparemid, "<init>", 
+                                               "(Ljava/lang/Thread;Ljava/lang/Class;I)V");
+
+
+       GETMIDWITHEXCEPTION(vmmethodclass, "gnu/classpath/jdwp/VMMethod",
+                                               vmmethodmid, "<init>", "(Ljava/lang/Class;J)V");
+
+       GETMIDWITHEXCEPTION(locationclass, "gnu/classpath/jdwp/util/Location",
+                                               locationmid, "<init>", 
+                                               "(Lgnu/classpath/jdwp/VMMethod;J)V");
+
+
+       GETMIDWITHEXCEPTION(
+               breakpointclass, 
+               "gnu/classpath/jdwp/event/BreakpointEvent", 
+               breakpointmid, "<init>", 
+               "(Ljava/lang/Thread;Lgnu/classpath/jdwp/util/Location;)V");
+
+}
 
 static void VMInit (jvmtiEnv *jvmti_env, 
                     JNIEnv* jni_env,
@@ -184,15 +332,19 @@ static void VMInit (jvmtiEnv *jvmti_env,
        jclass cl;
        jmethodID m;
        jobject eventobj;
-       jvmtiError err; 
+       jvmtiError err;
 
        fprintf(stderr,"JDWP VMInit\n");
 
+       /* get needed jmethodIDs and jclasses for callbacks */
+       fillidcache(jni_env);
+
        /* startup gnu classpath jdwp thread */
        setup_jdwp_thread(jni_env);
 
        fprintf(stderr,"JDWP listening thread started\n");
 
+       /* send VmInitEvent */
     cl = (*jni_env)->FindClass(jni_env, 
                                                                          "gnu/classpath/jdwp/event/VmInitEvent");
     if ((*jni_env)->ExceptionOccurred(jni_env) != NULL) {
@@ -226,11 +378,6 @@ static void VMInit (jvmtiEnv *jvmti_env,
        }
 }
 
-static void VMDeath (jvmtiEnv *jvmti_env,
-                     JNIEnv* jni_env) {
-  fprintf(stderr,"JVMTI-Event: IMPLEMENT ME!!!");
-}
-
 static void usage() {  
        puts("usage jdwp:[help]|(<option>=<value>),*");
        puts("   transport=[dt_socket|...]");
@@ -287,7 +434,6 @@ static bool processoptions(char *options) {
 
 JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) { 
        jint rc;
-       int end, i=0;
        jvmtiCapabilities cap;
        jvmtiError e;
 
@@ -319,21 +465,14 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
                return -1;
        }
        
-
-       end = sizeof(jvmtiEventCallbacks) / sizeof(void*);
-       for (i = 0; i < end; i++) {
-               /* enable VM callbacks  */
-               if (((void**)&jvmti_jdwp_EventCallbacks)[i] != NULL) {
-                       e = (*jvmtienv)->SetEventNotificationMode(jvmtienv,
-                                                                                                         JVMTI_ENABLE,
-                                                                                                         JVMTI_EVENT_START_ENUM+i,
-                                                                                                         NULL);
-                       
-                       if (JVMTI_ERROR_NONE != e) {
-                               printjvmtierror("jdwp: unable to setup event notification mode",e);
-                               return -1;
-                       }
-               }
+       /* only enable needed events. VMVirtualMachine.registerEvent will  
+          be used to enable other events by need */
+       if (JVMTI_ERROR_NONE != (e = (*jvmtienv)->
+                                                        SetEventNotificationMode(jvmtienv, JVMTI_ENABLE,
+                                                                                                         JVMTI_EVENT_VM_INIT, 
+                                                                                                         NULL))) {
+               printjvmtierror("jdwp unable to enable vm init callback",e);
+               return -1;
        }
 
        return 0;
@@ -343,20 +482,20 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
 jvmtiEventCallbacks jvmti_jdwp_EventCallbacks = {
     &VMInit,
     &VMDeath,
-    NULL, /*    &ThreadStart,*/
-    NULL, /*    &ThreadEnd, */
+    &ThreadStart,
+    &ThreadEnd,
     NULL, /* &ClassFileLoadHook, */
     NULL, /* &ClassLoad, */
-    NULL, /* &ClassPrepare,*/
+    &ClassPrepare,
     NULL, /* &VMStart */
-    NULL, /* &Exception, */
+    &Exception,
     NULL, /* &ExceptionCatch, */
     NULL, /* &SingleStep, */
     NULL, /* &FramePop, */
-    NULL, /* &Breakpoint, */
+    &Breakpoint,
     NULL, /* &FieldAccess, */
     NULL, /* &FieldModification, */
-    NULL, /* &MethodEntry, */
+    &MethodEntry,
     NULL, /* &MethodExit, */
     NULL, /* &NativeMethodBind, */
     NULL, /* &CompiledMethodLoad, */
index 2c2f3d7d3b71a190e3f18f622e183d48f750b677..5cb12e93ee6d6d4006fc7c86fce935c084e20745 100644 (file)
@@ -42,6 +42,7 @@ jvmtiEnv* jvmtienv;
 extern jvmtiEventCallbacks jvmti_jdwp_EventCallbacks;
 char* jdwpoptions;
 bool suspend;               /* should the virtual machine suspend on startup?  */
+jthread jdwpthread;
 
 void printjvmtierror(char *desc, jvmtiError err);
 #endif
index a685b44f0bc15c9991a624cdd2916680ed9fb238..05e7131e359239f3312e529f742330d79ef703e6 100644 (file)
@@ -281,13 +281,13 @@ static void jvmti_cacao_generic_breakpointhandler(int kindofbrk){
 
 void jvmti_cacao_debug_init() {
        pid_t dbgserver;        
-       void* addr[2];
 
        /* start new cacaodbgserver if needed*/
        pthread_mutex_lock(&dbgcomlock);
        if (dbgcom == NULL) {
                dbgcom = heap_allocate(sizeof(cacaodbgcommunication),true,NULL);                
                dbgcom->running = 1;
+               jvmti = true;
 
                breakpointtable_creator();
                /* set addresses of hard coded TRAPs */
@@ -296,10 +296,6 @@ void jvmti_cacao_debug_init() {
                __asm__ ("movl $cacaodbgserver_quit,%0;" 
                         :"=m"(dbgcom->jvmtibrkpt.brk[CACAODBGSERVERQUIT].addr));
 
-               jvmti_get_threads_breakpoints(addr);
-               dbgcom->jvmtibrkpt.brk[THREADSTARTBRK].addr = addr[0];
-               dbgcom->jvmtibrkpt.brk[THREADENDBRK].addr = addr[1];
-
                dbgserver = fork();
                if (dbgserver  == (-1)) {
                        log_text("cacaodbgserver fork error");
index 445d569e38a921ca628fab93d0d9859eb69660e6..7b73904570b498bf5a6356ddedee4e38b28ca8e2 100644 (file)
@@ -121,7 +121,7 @@ typedef struct {
 
 cacaodbgcommunication *dbgcom;
 
-bool jvmti;                 /* jvmti agent                                     */
+bool jvmti;                 /* jvmti agent  */
 
 extern pthread_mutex_t dbgcomlock;
 
index 02ce300b5b73c7315f9cfde852b08176ba948f68..ec95b83f3868b4e2bd12fcdb7bb876a6bd7b6242 100644 (file)
@@ -142,11 +142,11 @@ static unsigned long dataevaluate(char *expr) {
        fflush(gdbout); 
 
        getgdboutput(inbuf,160);
-       if ((match=strstr(inbuf,DATAEVALUATE))==NULL) {
+       if ((match=strstr(inbuf,DATAEVALUATE)) == NULL) {
                fprintf(stderr,"dataevaluate: no matching value\n");
                return -1;
        }
-       return strtoll(&match[strlen(DATAEVALUATE)],NULL,16);
+       return strtoll(&match[strlen(DATAEVALUATE)], NULL, 16);
 }
 
 
@@ -257,7 +257,7 @@ static void controlloop() {
                        getgdboutput(inbuf,INBUFLEN);
                        fprintf(stderr,"gdbin: %s\n",inbuf);
                        SENDCMD("-gdb-exit\n");
-                       return false;
+                       return;
                }
        }
 
index fa88ca11607f52e1d28e1ed9ffae30cbac63a5af..77bd2caa6dbc75e5013a924e0001551269ce84fa 100644 (file)
@@ -31,7 +31,7 @@
             Samuel Vinson
 
    
-   $Id: jvmti.c 4996 2006-05-31 13:53:16Z motse $
+   $Id: jvmti.c 5019 2006-06-06 21:13:41Z motse $
 
 */
 
@@ -129,7 +129,7 @@ static lt_ptr unload;
 #define CHECK_CAPABILITY(env,CAP) if(((environment*)                            \
                                                                                 env)->capabilities.CAP == 0)           \
                                      return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
-#define CHECK_THREAD_IS_ALIVE(t) if(check_thread_is_alive(t)==                  \
+#define CHECK_THREAD_IS_ALIVE(t) if(check_thread_is_alive(t) ==                 \
                                   JVMTI_ERROR_THREAD_NOT_ALIVE)                 \
                                        return JVMTI_ERROR_THREAD_NOT_ALIVE;
 
@@ -142,8 +142,8 @@ static lt_ptr unload;
 
 *******************************************************************************/
 static jvmtiError check_thread_is_alive(jthread t) {
-       if(t==NULL) return JVMTI_ERROR_THREAD_NOT_ALIVE;
-       if(((java_lang_Thread*) t)->vmThread==NULL) 
+       if(t == NULL) return JVMTI_ERROR_THREAD_NOT_ALIVE;
+       if(((java_lang_Thread*) t)->vmThread == NULL) 
                return JVMTI_ERROR_THREAD_NOT_ALIVE;
        return JVMTI_ERROR_NONE;
 }
@@ -372,22 +372,25 @@ static void dofireEvent(jvmtiEvent e, genericEventData* data) {
        functionptr ec;
 
        env = envs;
-       while (env!=NULL) {
+       while (env != NULL) {
                if (env->events[e-JVMTI_EVENT_START_ENUM].mode == JVMTI_DISABLE) {
                        evm = env->events[e-JVMTI_EVENT_START_ENUM].next;
             /* test if the event is enable for some threads */
-                       while (evm!=NULL) { 
+                       while (evm != NULL) { 
                                if (evm->mode == JVMTI_ENABLE) {
-                                       data->jvmti_env=&env->env;
-                                       ec = ((functionptr*)(&env->callbacks))[e-JVMTI_EVENT_START_ENUM];
-                                       execute_callback(e, ec, data);
+                                       ec = ((functionptr*)
+                                                 (&env->callbacks))[e-JVMTI_EVENT_START_ENUM];
+                                       if (ec != NULL) {
+                                               data->jvmti_env=&env->env;
+                                               execute_callback(e, ec, data);
+                                       }
                                }
                                evm=evm->next;
                        }
                } else { /* event enabled globally */
                        data->jvmti_env=&env->env;
                        ec = ((functionptr*)(&env->callbacks))[e-JVMTI_EVENT_START_ENUM];
-                       execute_callback(e, ec, data);
+                       if (ec != NULL) execute_callback(e, ec, data);
                }
                
                env=env->next;
@@ -405,10 +408,11 @@ void jvmti_fireEvent(genericEventData* d) {
        jthread thread;
     /* XXX todo : respect event order JVMTI-Spec:Multiple Co-located Events */
 
-       if (d->ev != JVMTI_EVENT_VM_START)
-               thread = jvmti_get_current_thread();
-       else
+       if (d->ev == JVMTI_EVENT_VM_START)
                thread = NULL;
+       else
+               thread = jvmti_get_current_thread();
+
 
        d->thread = thread;
        dofireEvent(d->ev,d);
@@ -439,7 +443,6 @@ SetEventNotificationMode (jvmtiEnv * env, jvmtiEventMode mode,
                CHECK_THREAD_IS_ALIVE(event_thread);
        }
        
-
        cacao_env = (environment*) env;    
        if ((mode != JVMTI_ENABLE) && (mode != JVMTI_DISABLE))
                return JVMTI_ERROR_ILLEGAL_ARGUMENT;
@@ -493,13 +496,6 @@ SetEventNotificationMode (jvmtiEnv * env, jvmtiEventMode mode,
     case JVMTI_EVENT_VM_OBJECT_ALLOC:
                CHECK_CAPABILITY(env,can_generate_vm_object_alloc_events)
                break;
-    case JVMTI_EVENT_THREAD_START:
-               jvmti_set_system_breakpoint(THREADSTARTBRK, mode);
-               break;
-    case JVMTI_EVENT_THREAD_END:
-               jvmti_set_system_breakpoint(THREADENDBRK, mode);
-               break;
-
        default:
                /* all other events are required */
                if ((event_type < JVMTI_EVENT_START_ENUM) ||
@@ -508,6 +504,7 @@ SetEventNotificationMode (jvmtiEnv * env, jvmtiEventMode mode,
                break;
        }
 
+
        if (event_thread != NULL) {
                /* thread level control */
                if ((JVMTI_EVENT_VM_INIT == mode) ||
@@ -591,11 +588,9 @@ SuspendThread (jvmtiEnv * env, jthread thread)
                return JVMTI_ERROR_INVALID_THREAD;
        CHECK_THREAD_IS_ALIVE(thread);
 
-
-       /* quick try - this should be changed in the future */
-       pthread_kill(((threadobject*)((java_lang_Thread*) thread)->vmThread)->tid,
-                                GC_signum1());
-       
+    /* threads_suspend_thread will implement suspend
+          threads_suspend_thread (
+          (threadobject*)((java_lang_Thread*) thread)->vmThread))*/
        
     return JVMTI_ERROR_NONE;
 }
@@ -619,10 +614,9 @@ ResumeThread (jvmtiEnv * env, jthread thread)
                return JVMTI_ERROR_INVALID_THREAD;
        CHECK_THREAD_IS_ALIVE(thread);
 
-
-       /* quick try - this should be changed in the future */
-       pthread_kill(((threadobject*)((java_lang_Thread*) thread)->vmThread)->tid,
-                                GC_signum2());
+    /* threads_resume_thread will implement resume
+          threads_resume_thread (
+          (threadobject*)((java_lang_Thread*) thread)->vmThread))*/
 
     return JVMTI_ERROR_NONE;
 }
@@ -730,7 +724,7 @@ GetOwnedMonitorInfo (jvmtiEnv * env, jthread thread,
     CHECK_PHASE_END;
     CHECK_CAPABILITY(env,can_get_owned_monitor_info);
 
-       if ((owned_monitors_ptr==NULL)||(owned_monitor_count_ptr==NULL)) 
+       if ((owned_monitors_ptr == NULL)||(owned_monitor_count_ptr == NULL)) 
                return JVMTI_ERROR_NULL_POINTER;
 
        if (thread == NULL) {
@@ -797,7 +791,7 @@ GetCurrentContendedMonitor (jvmtiEnv * env, jthread thread,
     CHECK_PHASE_END;
        CHECK_CAPABILITY(env, can_get_current_contended_monitor)
         
-       if (monitor_ptr==NULL) return JVMTI_ERROR_NULL_POINTER;
+       if (monitor_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
        *monitor_ptr=NULL;
 
        if(!builtin_instanceof(thread,class_java_lang_Thread))
@@ -812,7 +806,7 @@ GetCurrentContendedMonitor (jvmtiEnv * env, jthread thread,
 
        lrp=lock_global_pool;
 
-       while ((lrp != NULL)&&(monitor==NULL)) {
+       while ((lrp != NULL)&&(monitor == NULL)) {
                for (j=0; j<lrp->header.size; j++) {
 /*                     if((lrp->lr[j].owner==(threadobject*)thread)&&(lrp->lr[j].waiting)) {
                                monitor=lrp->lr[j].o;
@@ -919,8 +913,6 @@ GetTopThreadGroups (jvmtiEnv * env, jint * group_count_ptr,
     CHECK_PHASE(JVMTI_PHASE_LIVE)
     CHECK_PHASE_END;
 
-       log_text("GetTopThreadGroups called");
-
     if ((groups_ptr == NULL) || (group_count_ptr == NULL)) 
         return JVMTI_ERROR_NULL_POINTER;
 
@@ -1054,24 +1046,27 @@ GetThreadGroupChildren (jvmtiEnv * env, jthreadGroup group,
 /* getcacaostacktrace *********************************************************
 
    Helper function that retrives stack trace for specified thread. 
-   Has to take care of suspend/resume issuses
-
+   
 *******************************************************************************/
+
 static jvmtiError getcacaostacktrace(stacktracebuffer** trace, jthread thread) {
        threadobject *t;
+       bool resume;
        
-       if (thread == NULL)
+       if (thread == NULL) {
                t = jvmti_get_current_thread();
-       else {
+               *trace = stacktrace_create(t);
+       } else {
                t = (threadobject*)((java_lang_Thread*)thread)->vmThread;
-               if (t != jvmti_get_current_thread())
-                       /* XXX: todo: take care that the requested thread is in a 
-                          safe state - this needs a working thread suspend */
-                       return JVMTI_ERROR_INTERNAL;
+/*             if (t != jvmti_get_current_thread())
+                       resume = threads_suspend_thread_if_running(thread);
+    
+               *trace = stacktrace_create(thread );
+               
+               if (resume)
+               threads_resume_thread ( thread );*/
        }
 
-       *trace = stacktrace_create(t);
-
     return JVMTI_ERROR_NONE;
 }
 
@@ -1079,7 +1074,8 @@ static jvmtiError getcacaostacktrace(stacktracebuffer** trace, jthread thread) {
 /* GetFrameCount **************************************************************
 
 
-   Get the number of frames in the specified thread's stack.
+   Get the number of frames in the specified thread's stack. Calling function
+   has to take care of suspending/resuming thread.
 
 *******************************************************************************/
 
@@ -1103,7 +1099,7 @@ GetFrameCount (jvmtiEnv * env, jthread thread, jint * count_ptr)
        if(count_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
 
        er = getcacaostacktrace(&trace, thread);
-       if (er==JVMTI_ERROR_NONE) {
+       if (er == JVMTI_ERROR_NONE) {
                heap_free(trace);
                return er;
        }
@@ -1138,7 +1134,7 @@ GetThreadState (jvmtiEnv * env, jthread thread, jint * thread_state_ptr)
 
        *thread_state_ptr = 0;
 #if defined(ENABLE_THREADS)
-       if((th->vmThread==NULL)&&(th->group==NULL)) { /* alive ? */
+       if((th->vmThread == NULL)&&(th->group == NULL)) { /* alive ? */
                /* not alive */
                if (((threadobject*)th->vmThread)->tid == 0)
                        *thread_state_ptr = JVMTI_THREAD_STATE_TERMINATED;
@@ -2372,7 +2368,7 @@ GetMaxLocals (jvmtiEnv * env, jmethodID method, jint * max_ptr)
     
     if (((methodinfo*)method)->flags & ACC_NATIVE)  
         return JVMTI_ERROR_NATIVE_METHOD;
-   
     *max_ptr = (jint) ((methodinfo*)method)->maxlocals;
 
     return JVMTI_ERROR_NONE;
@@ -2400,13 +2396,13 @@ GetArgumentsSize (jvmtiEnv * env, jmethodID method, jint * size_ptr)
     if (((methodinfo*)method)->flags & ACC_NATIVE)  
         return JVMTI_ERROR_NATIVE_METHOD;
 
-/* todo    *size_ptr = (jint)((methodinfo*)method)->paramcount;*/
+    *size_ptr = (jint)((methodinfo*)method)->parseddesc->paramslots;
     return JVMTI_ERROR_NONE;
 }
 
 
 
-/* GetLineNumberTable ***********************************************************
+/* GetLineNumberTable **********************************************************
 
    Return table of source line number entries for a given method
 
@@ -2426,8 +2422,10 @@ GetLineNumberTable (jvmtiEnv * env, jmethodID method,
    
     if ((method == NULL) || (entry_count_ptr == NULL) || (table_ptr == NULL)) 
         return JVMTI_ERROR_NULL_POINTER;    
+
     if (((methodinfo*)method)->flags & ACC_NATIVE)  
         return JVMTI_ERROR_NATIVE_METHOD;
+
     if (((methodinfo*)method)->linenumbers == NULL) 
         return JVMTI_ERROR_ABSENT_INFORMATION;
 
@@ -2467,8 +2465,13 @@ GetMethodLocation (jvmtiEnv * env, jmethodID method,
     CHECK_PHASE(JVMTI_PHASE_LIVE)
     CHECK_PHASE_END;
 
-    if ((method == NULL) || (start_location_ptr == NULL) || 
-        (end_location_ptr == NULL)) return JVMTI_ERROR_NULL_POINTER;
+       if (method == NULL)     return JVMTI_ERROR_INVALID_METHODID;
+
+       if (((methodinfo*)method)->flags & ACC_NATIVE) 
+               return JVMTI_ERROR_NATIVE_METHOD;
+
+    if ((start_location_ptr == NULL) || (end_location_ptr == NULL)) 
+       return JVMTI_ERROR_NULL_POINTER;
     
        /* XXX we return the location of the most recent code. Don't know
         * if there is a way to teach jvmti that a method can have more
@@ -2479,11 +2482,14 @@ GetMethodLocation (jvmtiEnv * env, jmethodID method,
 
     fprintf(stderr,"GetMethodLocation *** XXX todo \n");
 
-       if (!m->code)
-               return JVMTI_ERROR_INTERNAL;
-       
+
+       /* -1 states location information is not available */
+    *start_location_ptr = (jlocation)-1;
+    *end_location_ptr = (jlocation)-1;
+
+/*     
     *start_location_ptr = (jlocation)m->code->mcode;
-    *end_location_ptr = (jlocation)(m->code->mcode)+m->code->mcodelength;
+    *end_location_ptr = (jlocation)(m->code->mcode)+m->code->mcodelength;*/
     return JVMTI_ERROR_NONE;
 }
 
@@ -2619,7 +2625,7 @@ GetLoadedClasses (jvmtiEnv * env, jint * class_count_ptr, jclass ** classes_ptr)
                while (nameentry != NULL) { /* iterate over hashlink */
 
                        /* filter pseudo classes $NEW$,$NULL$,$ARRAYSTUB$ out */
-                       if (nameentry->name->text[0]=='$')
+                       if (nameentry->name->text[0] == '$')
                        {
                                *class_count_ptr -= 1;
                                break;
@@ -2812,7 +2818,7 @@ SuspendThreadList (jvmtiEnv * env, jint request_count,
     CHECK_CAPABILITY(env,can_suspend);
     
        if (request_count<0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
-       if ((request_list==NULL) || (results == NULL)) 
+       if ((request_list == NULL) || (results == NULL)) 
                return JVMTI_ERROR_NULL_POINTER;
 
        me = jvmti_get_current_thread();
@@ -2849,7 +2855,7 @@ ResumeThreadList (jvmtiEnv * env, jint request_count,
     CHECK_CAPABILITY(env,can_suspend);
     
        if (request_count<0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
-       if ((request_list==NULL) || (results == NULL)) 
+       if ((request_list == NULL) || (results == NULL)) 
                return JVMTI_ERROR_NULL_POINTER;
 
        for (i=0;i<request_count;i++) 
@@ -2891,7 +2897,7 @@ GetStackTrace (jvmtiEnv * env, jthread thread, jint start_depth,
        if (max_frame_count <0) return JVMTI_ERROR_ILLEGAL_ARGUMENT;
 
        er = getcacaostacktrace(&trace, thread);
-       if (er==JVMTI_ERROR_NONE) {
+       if (er == JVMTI_ERROR_NONE) {
                heap_free(trace);
                return er;
        }
@@ -3356,7 +3362,7 @@ GetExtensionFunctions (jvmtiEnv * env, jint * extension_count_ptr,
     CHECK_PHASE(JVMTI_PHASE_LIVE)
     CHECK_PHASE_END;
         
-    if ((extension_count_ptr== NULL)||(extensions == NULL)) 
+    if ((extension_count_ptr == NULL)||(extensions == NULL)) 
         return JVMTI_ERROR_NULL_POINTER;
 
     /* cacao has no extended functions yet */
@@ -3381,7 +3387,7 @@ GetExtensionEvents (jvmtiEnv * env, jint * extension_count_ptr,
     CHECK_PHASE(JVMTI_PHASE_LIVE)
     CHECK_PHASE_END;
         
-    if ((extension_count_ptr== NULL)||(extensions == NULL)) 
+    if ((extension_count_ptr == NULL)||(extensions == NULL)) 
         return JVMTI_ERROR_NULL_POINTER;
 
     /* cacao has no extended events yet */
@@ -3582,7 +3588,7 @@ GetErrorName (jvmtiEnv * env, jvmtiError error, char **name_ptr)
 static jvmtiError
 GetJLocationFormat (jvmtiEnv * env, jvmtiJlocationFormat * format_ptr)
 {
-    *format_ptr = JVMTI_JLOCATION_MACHINEPC;
+    *format_ptr = JVMTI_JLOCATION_OTHER;
     return JVMTI_ERROR_NONE;
 }
 
@@ -4222,14 +4228,14 @@ static jvmtiCapabilities JVMTI_Capabilities = {
   0,                           /* can_access_local_variables */
   0,                           /* can_maintain_original_method_order */
   0,                           /* can_generate_single_step_events */
-  0,                           /* can_generate_exception_events */
+  1,                           /* can_generate_exception_events */
   0,                           /* can_generate_frame_pop_events */
   0,                           /* can_generate_breakpoint_events */
   1,                           /* can_suspend */
   0,                           /* can_redefine_any_class */
   0,                           /* can_get_current_thread_cpu_time */
   0,                           /* can_get_thread_cpu_time */
-  0,                           /* can_generate_method_entry_events */
+  1,                           /* can_generate_method_entry_events */
   0,                           /* can_generate_method_exit_events */
   0,                           /* can_generate_all_class_hook_events */
   0,                           /* can_generate_compiled_method_load_events */
@@ -4472,7 +4478,7 @@ void jvmti_agentload(char* opt_arg, bool agentbypath, lt_dlhandle  *handle, char
        len = strlen(opt_arg);
        
        /* separate argumtents */
-       while ((opt_arg[i]!='=')&&(i<len)) i++;
+       while ((opt_arg[i] != '=') && (i<len)) i++;
        if (i<len)
                arg = &opt_arg[i+1];
        else
index 69fc3df1ae4297714d199fd63d49443ae2a97703..ea24ac0346400afb933f345f70bdd177b5df81b6 100644 (file)
    Changes:             
 
    
-   $Id: jvmti.h 4944 2006-05-23 15:31:19Z motse $
+   $Id: jvmti.h 5019 2006-06-06 21:13:41Z motse $
 
 */
 #ifndef _JVMTI_H
 #define _JVMTI_H
 
 #include "native/jni.h"
-#include <sys/types.h>
 
 
 #define JVMTI_VERSION_INTERFACE_JNI   0x00000000
index 9792ec6c9f4df1f20d77938577e93c1ccbbf939f..8dbbfac7afe8a8525e3b282e4303bda4a8839c5c 100644 (file)
@@ -88,7 +88,7 @@ JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getS
 {
     jvmtiError err;
     char *signature;
-    struct java_lang_String* stringsignature;
+    jstring stringsignature;
     
     if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
                              GetMethodName(jvmtienv, 
index cbf9c24af42d17fe2c1ff53f7b34bc7c975c1411..abb11edcf23a00b696ffbd6887c1330837c2b174 100644 (file)
@@ -29,7 +29,7 @@ Authors: Martin Platter
 Changes: Samuel Vinson
 
 
-$Id: VMVirtualMachine.c 4996 2006-05-31 13:53:16Z motse $
+$Id: VMVirtualMachine.c 5019 2006-06-06 21:13:41Z motse $
 
 */
 
@@ -392,7 +392,6 @@ JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_registerEvent(JN
                                                                 EventKind2jvmtiEvent(kind), NULL)))
                printjvmtierror("VMVirtualMachine_registerEvent SetEventNotificationMode",err);
 
-       /* todo: error handling, suspend policy */
 }
 
 
@@ -405,17 +404,18 @@ JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_unregisterEvent(
        jbyte kind;
        jfieldID kindid;
        jclass erc;
+       jvmtiError err;
 
        erc = (*env)->FindClass(env,"gnu.classpath.jdwp.event.EventRequest");
        
        kindid = (*env)->GetFieldID(env, erc, "_kind", "B");
        kind = (*env)->GetByteField(env, (jobject)par1, kindid);
 
-       (*jvmtienv)->
+       if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
                SetEventNotificationMode(jvmtienv, JVMTI_DISABLE, 
-                                                                EventKind2jvmtiEvent(kind), NULL);
+                                                                EventKind2jvmtiEvent(kind), NULL)))
+               printjvmtierror("VMVirtualMachine_registerEvent SetEventNotificationMode",err);
 
-       /* todo: error handling, suspend policy */
 }
 
 
@@ -425,8 +425,7 @@ JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_unregisterEvent(
  * Signature: (B)V
  */
 JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_clearEvents(JNIEnv *env, jclass clazz, s4 par1) {
-       /* jvmti events are not saved */
-    log_text ("VMVirtualMachine_clearEvents IMPLEMENT ME!!!");
+       /* jvmti events are not saved - there is nothing to clear */
 }
 
 
index a9cffad36a3d7d9241367c2bea69b658b84e5ed7..03b9bbcb0f2527335c4cd8490873ad0b4a79d44d 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Christian Thalinger
                        Edwin Steiner
 
-   $Id: threads.c 4958 2006-05-26 11:57:20Z twisti $
+   $Id: threads.c 5019 2006-06-06 21:13:41Z motse $
 
 */
 
@@ -90,6 +90,9 @@
 # include "boehm-gc/include/gc.h"
 #endif
 
+#if defined(ENABLE_JVMTI)
+#include "native/jvmti/cacaodbg.h"
+#endif
 
 #if defined(__DARWIN__)
 /* Darwin has no working semaphore implementation.  This one is taken
@@ -1011,6 +1014,10 @@ static void *threads_startup_thread(void *t)
        methodinfo   *method;
        functionptr   function;
 
+#if defined(ENABLE_JVMTI)
+       genericEventData d;
+#endif
+
 #if defined(ENABLE_INTRP)
        u1 *intrp_thread_stack;
 
@@ -1083,7 +1090,10 @@ static void *threads_startup_thread(void *t)
 
 #if defined(ENABLE_JVMTI)
        /* breakpoint for thread start event */
-       __asm__("threadstart:");
+       if (jvmti) {
+               d.ev = JVMTI_EVENT_THREAD_START;
+               jvmti_fireEvent(&d);
+       }
 #endif
 
 
@@ -1110,7 +1120,10 @@ static void *threads_startup_thread(void *t)
 
 #if defined(ENABLE_JVMTI)
        /* breakpoint for thread end event */
-       __asm__("threadend:");
+       if (jvmti) {
+               d.ev = JVMTI_EVENT_THREAD_END;
+               jvmti_fireEvent(&d);
+       }       
 #endif
 
 
@@ -1673,20 +1686,6 @@ static void threads_table_dump(FILE *file)
 }
 #endif
 
-
-#if defined(ENABLE_JVMTI)
-/* jvmti_get_threads_breakpoints ***********************************************
-
-   gets all breakpoints from this file
-
-*******************************************************************************/
-
-void jvmti_get_threads_breakpoints(void **brks) {
-       __asm__ ("movl $threadstart,%0;" :"=m"(brks[0]));
-       __asm__ ("movl $threadend,%0;" :"=m"(brks[1]));
-}
-#endif
-
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where
index 4fa18b7b209e6590824f086ccb0b20f48a156c6d..27969cff889da8d261cba1e30a275e0d205b4d3e 100644 (file)
@@ -29,7 +29,7 @@
 
    Changes: Christian Thalinger
 
-   $Id: threads.h 4953 2006-05-25 12:28:51Z twisti $
+   $Id: threads.h 5019 2006-06-06 21:13:41Z motse $
 
 */
 
@@ -212,9 +212,6 @@ void threads_cast_startworld(void);
 
 void threads_dump(void);
 
-#if defined(ENABLE_JVMTI)
-void jvmti_get_threads_breakpoints(void **brks);
-#endif
 /******************************************************************************/
 /* Recursive Mutex Implementation for Darwin                                  */
 /******************************************************************************/