src/native/jni.c: removed jvmti.h included cacaodbg.h for GetEnv - jvmti
authormotse <none@none>
Mon, 29 May 2006 09:41:02 +0000 (09:41 +0000)
committermotse <none@none>
Mon, 29 May 2006 09:41:02 +0000 (09:41 +0000)
src/native/vm/VMVirtualMachine.c: formatting changes/removed debug statements
src/native/vm/VMMethod.c: (getName/getSignature/getModifiers/getLineTable): (Samuel Vinson) new implementation. (partially changed by motse)
src/native/jvmti/cacaodbg.h: removed unused function declarations
src/native/jvmti/jvmti.c (getcacaostacktrace): new implementation - does not yet handle traces of not current threads correctly.
(GetMethodName): fix: return JVMTI_ERROR_NULL_POINTER only on method == NULL
(GetFrameCount/GetStackTrace): fixed check for valid thread argument.

src/native/jni.c
src/native/jvmti/cacaodbg.h
src/native/jvmti/jvmti.c
src/native/vm/VMMethod.c
src/native/vm/VMVirtualMachine.c

index db8dc70421da154e451a75330e76868caecef710..3a476c7b04a36019e17c4a5c5121f928e97a7aff 100644 (file)
@@ -32,7 +32,7 @@
             Christian Thalinger
                        Edwin Steiner
 
-   $Id: jni.c 4958 2006-05-26 11:57:20Z twisti $
+   $Id: jni.c 4969 2006-05-29 09:41:02Z motse $
 
 */
 
@@ -78,7 +78,7 @@
 #include "native/include/java_nio_DirectByteBufferImpl.h"
 
 #if defined(ENABLE_JVMTI)
-# include "native/jvmti/jvmti.h"
+# include "native/jvmti/cacaodbg.h"
 #endif
 
 #if defined(ENABLE_THREADS)
index 10332fdd146cead3111f86658791f7730fb39b3f..445d569e38a921ca628fab93d0d9859eb69660e6 100644 (file)
@@ -125,9 +125,6 @@ bool jvmti;                 /* jvmti agent                                     *
 
 extern pthread_mutex_t dbgcomlock;
 
-void setup_jdwp_thread(char* transport);
-void jvmti_cacao_breakpointhandler();
-bool jvmti_VMjdwpInit();
 jvmtiEnv* jvmti_new_environment();
 void jvmti_set_phase(jvmtiPhase p);
 void jvmti_fireEvent(genericEventData* data);
index 0aac6f9b2000354cf362e00d09b0be8646e5f452..a2b211c0ab8ac908b812c79b85a212b921739f60 100644 (file)
@@ -31,7 +31,7 @@
             Samuel Vinson
 
    
-   $Id: jvmti.c 4963 2006-05-26 12:31:23Z motse $
+   $Id: jvmti.c 4969 2006-05-29 09:41:02Z motse $
 
 */
 
@@ -41,6 +41,7 @@
 #include "native/native.h"
 #include "native/jvmti/cacaodbg.h"
 #include "native/jvmti/jvmti.h"
+#include "vm/jit/stacktrace.h"
 #include "vm/global.h"
 #include "vm/loader.h"
 #include "vm/builtin.h"
@@ -125,10 +126,11 @@ static lt_ptr unload;
 #define CHECK_PHASE_START  if (!(false 
 #define CHECK_PHASE(chkphase) || (phase == chkphase)
 #define CHECK_PHASE_END  )) return JVMTI_ERROR_WRONG_PHASE
-#define CHECK_CAPABILITY(env,CAP) if(((environment*)env)->capabilities.CAP == 0) \
+#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)== \
-                                  JVMTI_ERROR_THREAD_NOT_ALIVE) \
+#define CHECK_THREAD_IS_ALIVE(t) if(check_thread_is_alive(t)==                  \
+                                  JVMTI_ERROR_THREAD_NOT_ALIVE)                 \
                                        return JVMTI_ERROR_THREAD_NOT_ALIVE;
 
 
@@ -1040,13 +1042,18 @@ GetThreadGroupChildren (jvmtiEnv * env, jthreadGroup group,
 *******************************************************************************/
 static jvmtiError getcacaostacktrace(stacktracebuffer** trace, jthread thread) {
        threadobject *t;
+       
+       if (thread == NULL)
+               t = jvmti_get_current_thread();
+       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 */
+                       return JVMTI_ERROR_INTERNAL;
+       }
 
-       log_text("getcacaostacktrace");
-
-       t = (threadobject*)((java_lang_Thread*)thread)->vmThread;
-
-/*      XXX todo
- *trace = stacktrace_create(t); */
+       *trace = stacktrace_create(t);
 
     return JVMTI_ERROR_NONE;
 }
@@ -1069,18 +1076,24 @@ GetFrameCount (jvmtiEnv * env, jthread thread, jint * count_ptr)
     CHECK_PHASE(JVMTI_PHASE_LIVE)
     CHECK_PHASE_END;
     
-       if(!builtin_instanceof(thread,class_java_lang_Thread))
-               return JVMTI_ERROR_INVALID_THREAD;
+       if (thread != NULL){
+               if(!builtin_instanceof(thread,class_java_lang_Thread))
+                       return JVMTI_ERROR_INVALID_THREAD;
 
-       CHECK_THREAD_IS_ALIVE(thread);
+               CHECK_THREAD_IS_ALIVE(thread);
+       }
        
        if(count_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
 
        er = getcacaostacktrace(&trace, thread);
-       if (er==JVMTI_ERROR_NONE) return er;
+       if (er==JVMTI_ERROR_NONE) {
+               heap_free(trace);
+               return er;
+       }
 
        *count_ptr = trace->used;
 
+       heap_free(trace);
     return JVMTI_ERROR_NONE;
 }
 
@@ -2216,19 +2229,25 @@ GetMethodName (jvmtiEnv * env, jmethodID method, char **name_ptr,
     CHECK_PHASE(JVMTI_PHASE_LIVE)
     CHECK_PHASE_END;
 
-    if ((method == NULL) || (name_ptr == NULL) || (signature_ptr == NULL)
-        || (generic_ptr == NULL)) return JVMTI_ERROR_NULL_POINTER;
 
-    *name_ptr = (char*)
-               heap_allocate(sizeof(char) * (m->name->blength),true,NULL);
-       utf_sprint_convert_to_latin1(*name_ptr, m->name);
+       if (method == NULL) return JVMTI_ERROR_INVALID_METHODID;
 
-    *signature_ptr = (char*)
-               heap_allocate(sizeof(char) * (m->descriptor->blength),true,NULL);
-       utf_sprint_convert_to_latin1(*signature_ptr, m->descriptor);
+       if (name_ptr == NULL) {
+               *name_ptr = (char*)
+                       heap_allocate(sizeof(char) * (m->name->blength),true,NULL);
+               utf_sprint_convert_to_latin1(*name_ptr, m->name);
+       }
+       
+       if (signature_ptr == NULL) {
+               *signature_ptr = (char*)
+                       heap_allocate(sizeof(char) * (m->descriptor->blength),true,NULL);
+               utf_sprint_convert_to_latin1(*signature_ptr, m->descriptor);
+       }
 
+       if (generic_ptr == NULL) {
     /* there is no generic signature attribute */
-    *generic_ptr = NULL;
+               *generic_ptr = NULL;
+       }
 
     return JVMTI_ERROR_NONE;
 }
@@ -2407,8 +2426,10 @@ GetMethodLocation (jvmtiEnv * env, jmethodID method,
        /* XXX Don't know if that's the right way to deal with not-yet-
         * compiled methods. -Edwin */
 
+    fprintf(stderr,"GetMethodLocation *** XXX todo \n");
+
        if (!m->code)
-               return JVMTI_ERROR_NULL_POINTER;
+               return JVMTI_ERROR_INTERNAL;
        
     *start_location_ptr = (jlocation)m->code->mcode;
     *end_location_ptr = (jlocation)(m->code->mcode)+m->code->mcodelength;
@@ -2805,10 +2826,12 @@ GetStackTrace (jvmtiEnv * env, jthread thread, jint start_depth,
     CHECK_PHASE(JVMTI_PHASE_LIVE)
     CHECK_PHASE_END;
     
-       if(!builtin_instanceof(thread,class_java_lang_Thread))
-               return JVMTI_ERROR_INVALID_THREAD;
+       if (thread != NULL){
+               if(!builtin_instanceof(thread,class_java_lang_Thread))
+                       return JVMTI_ERROR_INVALID_THREAD;
 
-       CHECK_THREAD_IS_ALIVE(thread);
+               CHECK_THREAD_IS_ALIVE(thread);
+       }
 
        if((count_ptr == NULL)||(frame_buffer == NULL)) 
                return JVMTI_ERROR_NULL_POINTER;
@@ -2816,7 +2839,10 @@ 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) return er;
+       if (er==JVMTI_ERROR_NONE) {
+               heap_free(trace);
+               return er;
+       }
 
        if ((trace->used >= start_depth) || ((trace->used * -1) > start_depth)) 
                return JVMTI_ERROR_ILLEGAL_ARGUMENT; 
@@ -2826,6 +2852,8 @@ GetStackTrace (jvmtiEnv * env, jthread thread, jint start_depth,
         /* todo: location BCI/MachinePC not avilable - Linenumber not expected */
                frame_buffer[j].location = 0;
                }
+
+       heap_free(trace);
        
     return JVMTI_ERROR_NONE;
 }
index 76eae22b91ff940e01fef0d1131ced35dd604518..377150afe52edcf24e730d9112f4d7a8e8a8fa5d 100644 (file)
@@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 Contact: cacao@cacaojvm.org
 
 Authors: Samuel Vinson
-         Martin Platter
+Martin Platter
          
 
 Changes: 
@@ -35,26 +35,39 @@ $Id: $
 
 */
 
-#include "toolbox/logging.h"
 #include "native/jni.h"
 #include "native/include/gnu_classpath_jdwp_VMMethod.h"
-#include "vm/stringlocal.h"
-#include "toolbox/logging.h"
+#include "native/jvmti/jvmti.h"
+#include "native/jvmti/VMjdwp.h"
 
 /*
  * Class:     gnu/classpath/jdwp/VMMethod
  * Method:    getName
  * Signature: ()Ljava/lang/String;
  */
-JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getName(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
+JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getName(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) 
 {
-       classinfo  *c;
-       methodinfo *m;
-
-       c = (classinfo *)this->_class;
-       m = &(c->methods[this->_methodId]);
-       log_message_utf("Method_getName %s", m->name);
-       return javastring_new(m->name);
+    jvmtiError err;
+    char* errdesc;
+    char *name, *signature, *generic;
+    jstring stringname;
+    
+    if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+                             GetMethodName(jvmtienv, (jmethodID)this->_methodId,
+                                           &name, &signature, &generic))) {
+        (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
+        fprintf(stderr,"jvmti error: %s\n",errdesc);
+        fflush(stderr);
+        (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
+        return NULL;
+    }
+    
+    stringname = (*env)->NewStringUTF(env,name);
+    (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)name);
+    (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)signature);
+    (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)generic);
+
+    return stringname;
 }
 
 
@@ -63,10 +76,29 @@ JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getN
  * Method:    getSignature
  * Signature: ()Ljava/lang/String;
  */
-JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getSignature(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
+JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getSignature(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) 
 {
-       log_text ("JVMTI-Call: IMPLEMENT ME!!!");
-       return 0;
+    jvmtiError err;
+    char* errdesc;
+    char *name, *signature, *generic;
+    struct java_lang_String* stringsignature;
+    
+    if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+                             GetMethodName(jvmtienv, (jmethodID)this->_methodId,
+                                           &name, &signature, &generic))) {
+        (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
+        fprintf(stderr,"jvmti error: %s\n",errdesc);
+        fflush(stderr);
+        (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
+        return NULL;
+    }
+    
+    stringsignature = (*env)->NewStringUTF(env,signature);
+    (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)name);
+    (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)signature);
+    (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)generic);
+    
+    return stringsignature;
 }
 
 
@@ -75,15 +107,24 @@ JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getS
  * Method:    getModifiers
  * Signature: ()I
  */
-JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMMethod_getModifiers(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
+JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMMethod_getModifiers(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) 
 {
-       classinfo  *c;
-       methodinfo *m;
-
-       c = (classinfo *) this->_class;
-       m = &(c->methods[this->_methodId]);
-
-       return m->flags;
+    jvmtiError err;
+    char* errdesc;
+    jint modifiers;
+       
+    if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+                             GetMethodModifiers(jvmtienv, 
+                                                (jmethodID) this->_methodId,
+                                                &modifiers))) {
+        (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
+        fprintf(stderr,"jvmti error: %s\n",errdesc);
+        fflush(stderr);
+        (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
+        return 0;
+    }
+    
+    return modifiers;
 }
 
 
@@ -92,10 +133,69 @@ JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMMethod_getModifiers(JNIEnv *env,
  * Method:    getLineTable
  * Signature: ()Lgnu/classpath/jdwp/util/LineTable;
  */
-JNIEXPORT struct gnu_classpath_jdwp_util_LineTable* JNICALL Java_gnu_classpath_jdwp_VMMethod_getLineTable(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
+JNIEXPORT struct gnu_classpath_jdwp_util_LineTable* JNICALL Java_gnu_classpath_jdwp_VMMethod_getLineTable(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) 
 {
-       log_text ("JVMTI-Call: IMPLEMENT ME!!!");
-       return 0;
+    jclass cl;
+    jmethodID m;
+    jobject ol;
+    jlongArray jlineCI;
+    jintArray jlineNum;
+    jint count = 0, i;
+    int *lineNum;
+    long *lineCI;
+    jvmtiLineNumberEntry *lne;
+    jlocation start,end;
+    
+    jvmtiError err;
+    char* errdesc;
+
+    if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+                             GetLineNumberTable(jvmtienv, 
+                                                (jmethodID)this->_methodId, 
+                                                &count, &lne))) {
+        (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
+        fprintf(stderr,"jvmti error: %s\n",errdesc);
+        fflush(stderr);
+        (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
+        return NULL;
+    }
+
+    cl = (*env)->FindClass(env,"gnu.classpath.jdwp.util.LineTable");
+    if (!cl) return NULL;
+
+    m = (*env)->GetMethodID(env, cl, "<init>", "(JJ[I[J)V");
+    if (!m) return NULL;
+       
+    jlineNum = (*env)->NewIntArray(env, count);
+    if (!jlineNum) return NULL;
+    jlineCI = (*env)->NewLongArray(env, count);
+    if (!jlineCI) return NULL;
+    lineNum = (*env)->GetIntArrayElements(env, jlineNum, NULL);
+    lineCI = (*env)->GetLongArrayElements(env, jlineCI, NULL);
+    for (i = 0; i < count; ++i) {
+        lineNum[i] = lne[i].line_number;
+        lineCI[i] = lne[i].start_location;
+    }
+    (*env)->ReleaseLongArrayElements(env, jlineCI, lineCI, 0);
+    (*env)->ReleaseIntArrayElements(env, jlineNum, lineNum, 0);
+    (*jvmtienv)->Deallocate(jvmtienv,lne);
+
+    if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
+                             GetMethodLocation(jvmtienv, 
+                                               (jmethodID)this->_methodId, 
+                                                &start, &end))) {
+        (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
+        fprintf(stderr,"jvmti error: %s\n",errdesc);
+        fflush(stderr);
+        (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
+        return NULL;
+    }
+
+    ol = (*env)->NewObject(env, cl, m, start, 
+                           end, jlineNum, jlineCI);
+
+    return (struct gnu_classpath_jdwp_util_LineTable*)ol;
 }
 
 
@@ -106,6 +206,19 @@ JNIEXPORT struct gnu_classpath_jdwp_util_LineTable* JNICALL Java_gnu_classpath_j
  */
 JNIEXPORT struct gnu_classpath_jdwp_util_VariableTable* JNICALL Java_gnu_classpath_jdwp_VMMethod_getVariableTable(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
 {
-       log_text ("JVMTI-Call: IMPLEMENT ME!!!");
-       return 0;
+    fprintf(stderr,"VMMethod_getVariableTable: IMPLEMENT ME!!!");
+    return 0;
 }
+
+/*
+ * 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
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
index 8844f2b394ac8728eb565ca35faf1a6ee48e914b..3428d9d5ad363834c4ad2848d68c73dff70acf90 100644 (file)
@@ -29,7 +29,7 @@ Authors: Martin Platter
 Changes: Samuel Vinson
 
 
-$Id: VMVirtualMachine.c 4944 2006-05-23 15:31:19Z motse $
+$Id: VMVirtualMachine.c 4969 2006-05-29 09:41:02Z motse $
 
 */
 
@@ -182,19 +182,20 @@ JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_get
        jobject *ol;
        jobjectArray joa;
        int i;
-       fprintf(stderr, "VMVirtualMachine_getAllClassMethods start\n");
+
     if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
-                                                        GetClassMethods(jvmtienv, (jclass) par1, &count, &methodID))) {
+                                                        GetClassMethods(jvmtienv, (jclass) par1, 
+                                                                                        &count, &methodID))) {
                (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
                fprintf(stderr,"jvmti error: %s\n",errdesc);
                (*jvmtienv)->Deallocate(jvmtienv, (unsigned char *)errdesc);
                fflush(stderr);
-/*             env->ThrowNew(env,ec,"jvmti error occoured");*/
                return NULL;
        }
        
-       fprintf(stderr, "VMVirtualMachine_getAllClassMethods count %d\n", count);
-       m = (*env)->GetStaticMethodID(env, clazz, "getClassMethod", "(Ljava/lang/Class;J)Lgnu/classpath/jdwp/VMMethod;");
+       m = (*env)->
+               GetStaticMethodID(env, clazz, "getClassMethod", 
+                                                 "(Ljava/lang/Class;J)Lgnu/classpath/jdwp/VMMethod;");
        if (!m) return NULL;
    
     cl = (*env)->FindClass(env,"gnu.classpath.jdwp.VMMethod");
@@ -204,11 +205,11 @@ JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_get
        if (!joa) return NULL;
        fprintf(stderr, "VMVirtualMachine_getAllClassMethods 3\n");
     for (i = 0; i < count; i++) {
-       ol = (*env)->CallStaticObjectMethod(env,clazz,m,(jobject)par1, methodID[i]);
+       ol = (*env)->
+                       CallStaticObjectMethod(env,clazz,m,(jobject)par1, methodID[i]);
                if (!ol) return NULL;
        (*env)->SetObjectArrayElement(env,joa,(jsize)i, ol);
     }
-       fprintf(stderr, "VMVirtualMachine_getAllClassMethods end\n");
        return joa;
 }