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 $
*/
#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)
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);
Samuel Vinson
- $Id: jvmti.c 4963 2006-05-26 12:31:23Z motse $
+ $Id: jvmti.c 4969 2006-05-29 09:41:02Z motse $
*/
#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"
#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;
*******************************************************************************/
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;
}
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;
}
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;
}
/* 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;
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;
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;
/* todo: location BCI/MachinePC not avilable - Linenumber not expected */
frame_buffer[j].location = 0;
}
+
+ heap_free(trace);
return JVMTI_ERROR_NONE;
}
Contact: cacao@cacaojvm.org
Authors: Samuel Vinson
- Martin Platter
+Martin Platter
Changes:
*/
-#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;
}
* 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;
}
* 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;
}
* 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;
+
}
*/
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:
+ */
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 $
*/
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");
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;
}