From: motse Date: Wed, 31 May 2006 13:53:16 +0000 (+0000) Subject: src/native/vm/VMVirtualMachine.c (suspendThread): print error message with printjvmti... X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=94fa59c2bdbe7b066d7bcabaacc4f19914b434ba;p=cacao.git src/native/vm/VMVirtualMachine.c (suspendThread): print error message with printjvmtierror (resumeThread): idem (getAllLoadedClassCount): idem (getAllLoadedClasses): idem (getClassStatus): idem (getAllClassMethods): idem (getFrameCount): idem (getThreadStatus): idem (getSourceFile): idem (registerEvent): idem src/native/vm/VMMethod.c (printjvmtierror): new helper function for getting and print error messages (getName): print error message with printjvmtierror, remove signature, generic signature (getSignature): print error message with printjvmtierror, remove name, generic signature (getModifiers): print error message with printjvmtierror (getlinetable): idem (fillVariableTable): new function for converting jvmtiLocalVariableEntry to arguments for gnu.classpath.jdwp.util.VariableTable constructor (getVariableTable): new implementation. tries to get local variable table and return gnu.classpath.jdwp.util.VariableTable. src/native/include/Makefile.am: add VariableTable src/native/jvmti/VMjdwp.c (printjvmtierror) new function (duplicate) - this is a work around (VMInit): print error message with printjvmtierror src/native/jvmti/jvmti.c (InterruptThread): new implentation (GetThreadInfo): switch form using javastring_tochar (uses malloc) to javastring_toutf/utf_sprint_convert_to_latin1 (GetOwnedMonitorInfo): fix error handling (GetFrameLocation): idem (DestroyRawMonitor): use heap_free (GetClassSignature): fix error handling (GetSourceFileName): use utf_bytes (GetFieldName): fix error handling (GetFieldDeclaringClass): add error handling (GetFieldModifiers): idem (GetMethodName): fix error handling (GetClassLoaderClasses): idem (GenerateEvents): add CHECK_CAPABILITY can_generate_compiled_method_load_events src/native/jvmti/VMjdwp.h add printjvmtierror --- diff --git a/src/native/include/Makefile.am b/src/native/include/Makefile.am index 209fbd56b..7376c13d0 100644 --- a/src/native/include/Makefile.am +++ b/src/native/include/Makefile.am @@ -28,7 +28,7 @@ ## ## Changes: ## -## $Id: Makefile.am 4892 2006-05-06 18:29:55Z motse $ +## $Id: Makefile.am 4996 2006-05-31 13:53:16Z motse $ ## Process this file with automake to produce Makefile.in @@ -77,7 +77,8 @@ GEN_JVMTI_HEADER_FILES = \ gnu_classpath_jdwp_VMFrame.h \ gnu_classpath_jdwp_VMMethod.h \ gnu_classpath_jdwp_VMVirtualMachine.h \ - gnu_classpath_jdwp_event_EventRequest.h + gnu_classpath_jdwp_event_EventRequest.h \ + gnu_classpath_jdwp_util_VariableTable.h ADDITIONAL_IMPLEMENTED_VM_CLASSES_HEADER_FILES = \ gnu_classpath_VMStackWalker.h \ diff --git a/src/native/jvmti/Makefile.am b/src/native/jvmti/Makefile.am index 04fd2eacb..120ec55a3 100644 --- a/src/native/jvmti/Makefile.am +++ b/src/native/jvmti/Makefile.am @@ -28,7 +28,7 @@ ## ## Changes: ## -## $Id: Makefile.am 4954 2006-05-25 21:59:49Z motse $ +## $Id: Makefile.am 4996 2006-05-31 13:53:16Z motse $ ## Process this file with automake to produce Makefile.in @@ -58,8 +58,7 @@ lib_LTLIBRARIES = \ libjdwp_la_SOURCES = \ VMjdwp.c \ - VMjdwp.h - + VMjdwp.h \ ## Local variables: ## mode: Makefile diff --git a/src/native/jvmti/VMjdwp.c b/src/native/jvmti/VMjdwp.c index 9bcde095b..82281eb8a 100644 --- a/src/native/jvmti/VMjdwp.c +++ b/src/native/jvmti/VMjdwp.c @@ -29,7 +29,7 @@ Changes: - $Id: VMjdwp.c 4954 2006-05-25 21:59:49Z motse $ + $Id: VMjdwp.c 4996 2006-05-31 13:53:16Z motse $ */ @@ -39,6 +39,16 @@ #include #include +void printjvmtierror(char *desc, jvmtiError err) { + char* errdesc; + + if (err == JVMTI_ERROR_NONE) return; + (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc); + fprintf(stderr,"%s: jvmti error %s\n",desc, errdesc); + fflush(stderr); + (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc); +} + static jmethodID notifymid = NULL; @@ -174,6 +184,7 @@ static void VMInit (jvmtiEnv *jvmti_env, jclass cl; jmethodID m; jobject eventobj; + jvmtiError err; fprintf(stderr,"JDWP VMInit\n"); @@ -209,9 +220,9 @@ static void VMInit (jvmtiEnv *jvmti_env, notify (jni_env,eventobj); if (suspend) { - fprintf(stderr,"suspend true -> do not continue debuggee\n"); - if (JVMTI_ERROR_NONE!=(*jvmti_env)->SuspendThread(jvmti_env,thread)) - fprintf(stderr,"error suspending initial thread\n"); + fprintf(stderr,"suspend initial thread\n"); + err = (*jvmti_env)->SuspendThread(jvmti_env,thread); + printjvmtierror("error suspending initial thread",err); } } @@ -292,19 +303,19 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) { /* set eventcallbacks */ if (JVMTI_ERROR_NONE != - (*jvmtienv)->SetEventCallbacks(jvmtienv, + (e = (*jvmtienv)->SetEventCallbacks(jvmtienv, &jvmti_jdwp_EventCallbacks, - sizeof(jvmtiEventCallbacks))){ - fprintf(stderr,"jdwp: unable to setup event callbacks"); + sizeof(jvmtiEventCallbacks)))){ + printjvmtierror("jdwp: unable to setup event callbacks", e); return -1; } e = (*jvmtienv)->GetPotentialCapabilities(jvmtienv, &cap); - if (e == JVMTI_ERROR_NONE) { + printjvmtierror("jdwp: unable to get potential capabilities", e); + if (e == JVMTI_ERROR_NONE) e = (*jvmtienv)->AddCapabilities(jvmtienv, &cap); - } if (e != JVMTI_ERROR_NONE) { - fprintf(stderr,"jdwp: error adding jvmti capabilities"); + printjvmtierror("jdwp: error adding jvmti capabilities", e); return -1; } @@ -319,7 +330,7 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) { NULL); if (JVMTI_ERROR_NONE != e) { - fprintf(stderr,"jdwp: unable to setup event notification mode"); + printjvmtierror("jdwp: unable to setup event notification mode",e); return -1; } } diff --git a/src/native/jvmti/VMjdwp.h b/src/native/jvmti/VMjdwp.h index 235ddf993..2c2f3d7d3 100644 --- a/src/native/jvmti/VMjdwp.h +++ b/src/native/jvmti/VMjdwp.h @@ -43,4 +43,5 @@ extern jvmtiEventCallbacks jvmti_jdwp_EventCallbacks; char* jdwpoptions; bool suspend; /* should the virtual machine suspend on startup? */ +void printjvmtierror(char *desc, jvmtiError err); #endif diff --git a/src/native/jvmti/jvmti.c b/src/native/jvmti/jvmti.c index a2b211c0a..fa88ca116 100644 --- a/src/native/jvmti/jvmti.c +++ b/src/native/jvmti/jvmti.c @@ -31,7 +31,7 @@ Samuel Vinson - $Id: jvmti.c 4969 2006-05-29 09:41:02Z motse $ + $Id: jvmti.c 4996 2006-05-31 13:53:16Z motse $ */ @@ -65,7 +65,7 @@ #include "native/include/java_lang_VMSystem.h" #include "native/include/java_lang_VMClass.h" #include "vm/suck.h" -#include "boehm-gc/include/gc.h" +#include "boehm-gc/include/gc.h" #include #include @@ -662,16 +662,19 @@ InterruptThread (jvmtiEnv * env, jthread thread) CHECK_PHASE_END; CHECK_CAPABILITY(env,can_signal_thread) - log_text ("JVMTI-Call: TBD OPTIONAL IMPLEMENT ME!!!"); - - return JVMTI_ERROR_NOT_AVAILABLE; - +#if defined(ENABLE_THREADS) if(!builtin_instanceof(thread,class_java_lang_Thread)) return JVMTI_ERROR_INVALID_THREAD; - CHECK_THREAD_IS_ALIVE(thread); + CHECK_THREAD_IS_ALIVE(thread); + + threads_interrupt_thread(((java_lang_Thread*)thread)->vmThread); + return JVMTI_ERROR_NONE; +#else + return JVMTI_ERROR_NOT_AVAILABLE; +#endif } /* GetThreadInfo *************************************************************** @@ -684,16 +687,22 @@ InterruptThread (jvmtiEnv * env, jthread thread) static jvmtiError GetThreadInfo (jvmtiEnv * env, jthread t, jvmtiThreadInfo * info_ptr) { + utf *name; java_lang_Thread* th = (java_lang_Thread*)t; + CHECK_PHASE_START CHECK_PHASE(JVMTI_PHASE_LIVE) CHECK_PHASE_END; + info_ptr->priority=(jint)th->priority; info_ptr->is_daemon=(jboolean)th->daemon; info_ptr->thread_group=(jthreadGroup)th->group; info_ptr->context_class_loader=(jobject)th->contextClassLoader; - info_ptr->name= javastring_tochar((java_objectheader *)th->name); + + name = javastring_toutf(th->name,false); + info_ptr->name=(char*)heap_allocate(sizeof(char)*(utf_bytes(name)+1),true,NULL); + utf_sprint_convert_to_latin1(info_ptr->name, name); return JVMTI_ERROR_NONE; } @@ -712,6 +721,7 @@ GetOwnedMonitorInfo (jvmtiEnv * env, jthread thread, int i,j,size=20; java_objectheader **om; lock_record_pool_t* lrp; + threadobject* t; log_text("GetOwnedMonitorInfo called"); @@ -723,10 +733,15 @@ GetOwnedMonitorInfo (jvmtiEnv * env, jthread thread, if ((owned_monitors_ptr==NULL)||(owned_monitor_count_ptr==NULL)) return JVMTI_ERROR_NULL_POINTER; - if(!builtin_instanceof(thread,class_java_lang_Thread)) - return JVMTI_ERROR_INVALID_THREAD; - - CHECK_THREAD_IS_ALIVE(thread); + if (thread == NULL) { + t = jvmti_get_current_thread(); + } else { + if(!builtin_instanceof(thread,class_java_lang_Thread)) + return JVMTI_ERROR_INVALID_THREAD; + + CHECK_THREAD_IS_ALIVE(thread); + t = (threadobject*) thread; + } #if defined(ENABLE_THREADS) @@ -737,7 +752,7 @@ GetOwnedMonitorInfo (jvmtiEnv * env, jthread thread, while (lrp != NULL) { for (j=0; jheader.size; j++) { -/* if((lrp->lr[j].owner==(threadobject*)thread)&& +/* if((lrp->lr[j].owner==t)&& (!lrp->lr[j].waiting)) { if (i>=size) { MREALLOC(om,java_objectheader*,size,size*2); @@ -857,7 +872,7 @@ RunAgentThread (jvmtiEnv * env, jthread thread, jvmtiStartFunction proc, (priority > JVMTI_THREAD_MAX_PRIORITY)) return JVMTI_ERROR_INVALID_PRIORITY; - /* XXX: Threads started with with this function should not be visible to + /* XXX: Threads started with this function should not be visible to Java programming language queries but are included in JVM TI queries */ rap.sf = proc; @@ -1018,14 +1033,16 @@ GetThreadGroupChildren (jvmtiEnv * env, jthreadGroup group, *thread_count_ptr = (jint)tgp->threads->elementCount; - *threads_ptr = heap_allocate(sizeof(jthread*)*(*thread_count_ptr),true,NULL); + *threads_ptr = + heap_allocate(sizeof(jthread)*(*thread_count_ptr),true,NULL); memcpy(*threads_ptr, &tgp->threads->elementData, - (*thread_count_ptr)*sizeof(jthread*)); + (*thread_count_ptr)*sizeof(java_objectarray*)); *group_count_ptr = (jint) tgp->groups->elementCount; - *groups_ptr = heap_allocate(sizeof(jthreadGroup*)*(*group_count_ptr),true,NULL); + *groups_ptr = + heap_allocate(sizeof(jthreadGroup)*(*group_count_ptr),true,NULL); memcpy(*groups_ptr, &tgp->threads->elementData, (*group_count_ptr)*sizeof(jthreadGroup*)); @@ -1049,7 +1066,7 @@ static jvmtiError getcacaostacktrace(stacktracebuffer** trace, jthread thread) { 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 */ + safe state - this needs a working thread suspend */ return JVMTI_ERROR_INTERNAL; } @@ -1129,7 +1146,7 @@ GetThreadState (jvmtiEnv * env, jthread thread, jint * thread_state_ptr) /* alive */ *thread_state_ptr = JVMTI_THREAD_STATE_ALIVE; if (t->interrupted) *thread_state_ptr |= JVMTI_THREAD_STATE_INTERRUPTED; - /* todo */ + /* XXX todo - info not available */ if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_SUSPENDED; if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_IN_NATIVE; if (false) *thread_state_ptr |= JVMTI_THREAD_STATE_RUNNABLE; @@ -1161,22 +1178,28 @@ GetFrameLocation (jvmtiEnv * env, jthread thread, jint depth, { stackframeinfo *sfi; int i; + threadobject* th; CHECK_PHASE_START CHECK_PHASE(JVMTI_PHASE_LIVE) CHECK_PHASE_END; - if(!builtin_instanceof(thread,class_java_lang_Thread)) - return JVMTI_ERROR_INVALID_THREAD; - - CHECK_THREAD_IS_ALIVE(thread); + if (thread == NULL) { + th = jvmti_get_current_thread(); + } else { + if(!builtin_instanceof(thread,class_java_lang_Thread)) + return JVMTI_ERROR_INVALID_THREAD; + + CHECK_THREAD_IS_ALIVE(thread); + th = (threadobject*) ((java_lang_Thread*)thread)->vmThread; + } if (depth < 0) return JVMTI_ERROR_ILLEGAL_ARGUMENT; if ((method_ptr == NULL)&&(location_ptr == NULL)) return JVMTI_ERROR_NULL_POINTER; - sfi = ((threadobject*)thread)->_stackframeinfo; + sfi = th->_stackframeinfo; i = 0; while ((sfi != NULL) && (iname); - /* GC will clean monitor up */ + heap_free(monitor); #else log_text ("DestroyRawMonitor not supported"); #endif @@ -1767,16 +1790,21 @@ GetClassSignature (jvmtiEnv * env, jclass klass, char **signature_ptr, CHECK_PHASE(JVMTI_PHASE_START) CHECK_PHASE(JVMTI_PHASE_LIVE) CHECK_PHASE_END; - - if ((generic_ptr== NULL)||(signature_ptr == NULL)) - return JVMTI_ERROR_NULL_POINTER; + + if (klass == NULL) return JVMTI_ERROR_INVALID_CLASS; + if (!builtin_instanceof(klass,class_java_lang_Class)) + return JVMTI_ERROR_INVALID_CLASS; - *signature_ptr = (char*) - heap_allocate(sizeof(char) * - ((classinfo*)klass)->name->blength,true,NULL); + if (signature_ptr != NULL) { + *signature_ptr = (char*) + heap_allocate(sizeof(char) * + utf_bytes(((classinfo*)klass)->name)+1,true,NULL); + + utf_sprint_convert_to_latin1(*signature_ptr,((classinfo*)klass)->name); + } - utf_sprint_convert_to_latin1(*signature_ptr, ((classinfo*)klass)->name); - *generic_ptr = NULL; + if (generic_ptr!= NULL) + *generic_ptr = NULL; return JVMTI_ERROR_NONE; } @@ -1845,7 +1873,7 @@ GetSourceFileName (jvmtiEnv * env, jclass klass, char **source_name_ptr) if ((klass == NULL)||(source_name_ptr == NULL)) return JVMTI_ERROR_NULL_POINTER; - size = (((classinfo*)klass)->sourcefile->blength)+1; + size = utf_bytes(((classinfo*)klass)->sourcefile)+1; *source_name_ptr = (char*) heap_allocate(sizeof(char)* size,true,NULL); @@ -2121,19 +2149,29 @@ GetFieldName (jvmtiEnv * env, jclass klass, jfieldID field, CHECK_PHASE(JVMTI_PHASE_START) CHECK_PHASE(JVMTI_PHASE_LIVE) CHECK_PHASE_END; - - if ((field == NULL)||(name_ptr == NULL)||(signature_ptr == NULL)) - return JVMTI_ERROR_NULL_POINTER; + + if (klass == NULL) + return JVMTI_ERROR_INVALID_CLASS; + else + if (!builtin_instanceof(klass,class_java_lang_Class)) + return JVMTI_ERROR_INVALID_CLASS; + if (field == NULL) return JVMTI_ERROR_INVALID_FIELDID; - size = (((fieldinfo*)field)->name->blength); - *name_ptr = (char*) heap_allocate(sizeof(char)* size,true,NULL); - memcpy(*name_ptr,((fieldinfo*)field)->name->text, size); + if (name_ptr != NULL) { + size = utf_bytes(((fieldinfo*)field)->name)+1; + *name_ptr = (char*) heap_allocate(sizeof(char)* size,true,NULL); + utf_sprint_convert_to_latin1(*name_ptr, ((fieldinfo*)field)->name); + } - size = (((fieldinfo*)field)->descriptor->blength); - *signature_ptr = (char*) heap_allocate(sizeof(char)* size,true,NULL); - memcpy(*signature_ptr,((fieldinfo*)field)->descriptor->text, size); + if (signature_ptr != NULL) { + size = utf_bytes(((fieldinfo*)field)->descriptor)+1; + *signature_ptr = (char*) heap_allocate(sizeof(char)* size,true,NULL); + utf_sprint_convert_to_latin1(*signature_ptr, + ((fieldinfo*)field)->descriptor); + } - *generic_ptr = NULL; + if (generic_ptr != NULL) + *generic_ptr = NULL; return JVMTI_ERROR_NONE; } @@ -2155,7 +2193,17 @@ GetFieldDeclaringClass (jvmtiEnv * env, jclass klass, jfieldID field, CHECK_PHASE(JVMTI_PHASE_START) CHECK_PHASE(JVMTI_PHASE_LIVE) CHECK_PHASE_END; - + + if (klass == NULL) + return JVMTI_ERROR_INVALID_CLASS; + else + if (!builtin_instanceof(klass,class_java_lang_Class)) + return JVMTI_ERROR_INVALID_CLASS; + + if (field == NULL) return JVMTI_ERROR_INVALID_FIELDID; + + if (declaring_class_ptr == NULL) return JVMTI_ERROR_NULL_POINTER; + *declaring_class_ptr = (jclass) ((fieldinfo*)field)->class; return JVMTI_ERROR_NONE; @@ -2176,14 +2224,17 @@ GetFieldModifiers (jvmtiEnv * env, jclass klass, jfieldID field, CHECK_PHASE(JVMTI_PHASE_START) CHECK_PHASE(JVMTI_PHASE_LIVE) CHECK_PHASE_END; - - if (!builtin_instanceof((java_objectheader*)klass, class_java_lang_Class)) - return JVMTI_ERROR_INVALID_OBJECT; + + if (klass == NULL) + return JVMTI_ERROR_INVALID_CLASS; + else + if (!builtin_instanceof(klass,class_java_lang_Class)) + return JVMTI_ERROR_INVALID_CLASS; + + if (field == NULL) return JVMTI_ERROR_INVALID_FIELDID; if (modifiers_ptr == NULL) return JVMTI_ERROR_NULL_POINTER; - /* todo: JVMTI_ERROR_INVALID_FIELDID; */ - *modifiers_ptr = ((fieldinfo*)field)->flags; return JVMTI_ERROR_NONE; @@ -2232,20 +2283,20 @@ GetMethodName (jvmtiEnv * env, jmethodID method, char **name_ptr, if (method == NULL) return JVMTI_ERROR_INVALID_METHODID; - if (name_ptr == NULL) { + if (name_ptr != NULL) { *name_ptr = (char*) - heap_allocate(sizeof(char) * (m->name->blength),true,NULL); + heap_allocate(sizeof(char) * (utf_bytes(m->name)+1),true,NULL); utf_sprint_convert_to_latin1(*name_ptr, m->name); } - if (signature_ptr == NULL) { + if (signature_ptr != NULL) { *signature_ptr = (char*) - heap_allocate(sizeof(char) * (m->descriptor->blength),true,NULL); + heap_allocate(sizeof(char)*(utf_bytes(m->descriptor)+1),true,NULL); utf_sprint_convert_to_latin1(*signature_ptr, m->descriptor); } - if (generic_ptr == NULL) { - /* there is no generic signature attribute */ + if (generic_ptr != NULL) { + /* there is no generic signature attribute */ *generic_ptr = NULL; } @@ -2612,8 +2663,8 @@ GetClassLoaderClasses (jvmtiEnv * env, jobject initiating_loader, CHECK_PHASE(JVMTI_PHASE_LIVE) CHECK_PHASE_END; -/* if (class_count_ptr == NULL) return JVMTI_ERROR_NULL_POINTER; - if (classes_ptr == NULL) return JVMTI_ERROR_NULL_POINTER;*/ + if ((class_count_ptr == NULL) || (classes_ptr == NULL)) + return JVMTI_ERROR_NULL_POINTER; /* behave like jdk 1.1 and make no distinction between initiating and defining class loaders */ @@ -2657,6 +2708,7 @@ RedefineClasses (jvmtiEnv * env, jint class_count, CHECK_PHASE_END; CHECK_CAPABILITY(env,can_redefine_classes) CHECK_CAPABILITY(env,can_redefine_any_class) + log_text ("JVMTI-Call: OPTIONAL IMPLEMENT ME!!!"); return JVMTI_ERROR_NONE; } @@ -2849,7 +2901,7 @@ GetStackTrace (jvmtiEnv * env, jthread thread, jint start_depth, for (i=start_depth, j=0;iused;i++,j++) { frame_buffer[j].method = (jmethodID)trace->entries[i].method; - /* todo: location BCI/MachinePC not avilable - Linenumber not expected */ + /* XXX todo: location BCI/MachinePC not avilable - Linenumber not expected */ frame_buffer[j].location = 0; } @@ -2923,15 +2975,12 @@ GetAllStackTraces (jvmtiEnv * env, jint max_frame_count, if (thread_count_ptr == NULL) return JVMTI_ERROR_NULL_POINTER; - /* todo: all threads have to be suspended */ - if (JVMTI_ERROR_NONE!=GetAllThreads(env,thread_count_ptr,&threads_ptr)) return JVMTI_ERROR_INTERNAL; GetThreadListStackTraces(env, *thread_count_ptr, threads_ptr, max_frame_count, stack_info_ptr); - /* todo: resume all threads have to be suspended */ if (er != JVMTI_ERROR_NONE) return er; return JVMTI_ERROR_NONE; @@ -3286,8 +3335,8 @@ GenerateEvents (jvmtiEnv * env, jvmtiEvent event_type) CHECK_PHASE_START CHECK_PHASE(JVMTI_PHASE_LIVE) CHECK_PHASE_END; - - log_text ("JVMTI-Call: IMPLEMENT ME!!!"); + CHECK_CAPABILITY(env,can_generate_compiled_method_load_events); + return JVMTI_ERROR_NONE; } @@ -4003,9 +4052,9 @@ RelinquishCapabilities (jvmtiEnv * env, return JVMTI_ERROR_NONE; } -/* ***************************************************************************** +/* GetAvailableProcessors ***************************************************** - + Get number of processors available to the virtual machine. *******************************************************************************/ diff --git a/src/native/vm/VMFrame.c b/src/native/vm/VMFrame.c index f2d9efaea..cddaf18cf 100644 --- a/src/native/vm/VMFrame.c +++ b/src/native/vm/VMFrame.c @@ -29,7 +29,7 @@ Authors: Martin Platter Changes: -$Id: VMFrame.c 4357 2006-01-22 23:33:38Z twisti $ +$Id: VMFrame.c 4996 2006-05-31 13:53:16Z motse $ */ @@ -45,7 +45,7 @@ $Id: VMFrame.c 4357 2006-01-22 23:33:38Z twisti $ */ JNIEXPORT struct java_lang_Object* JNICALL Java_gnu_classpath_jdwp_VMFrame_getValue(JNIEnv *env, struct gnu_classpath_jdwp_VMFrame* this, s4 par1) { log_text ("JVMTI-Call: IMPLEMENT ME!!!"); - return 0; + return 0; } diff --git a/src/native/vm/VMMethod.c b/src/native/vm/VMMethod.c index 377150afe..9792ec6c9 100644 --- a/src/native/vm/VMMethod.c +++ b/src/native/vm/VMMethod.c @@ -25,13 +25,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA Contact: cacao@cacaojvm.org Authors: Samuel Vinson -Martin Platter + Martin Platter Changes: -$Id: $ +$Id: VMMethod.c $ */ @@ -40,6 +40,19 @@ $Id: $ #include "native/jvmti/jvmti.h" #include "native/jvmti/VMjdwp.h" + +void printjvmtierror(char *desc, jvmtiError err) { + char* errdesc; + + if (err == JVMTI_ERROR_NONE) return; + (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc); + fprintf(stderr,"%s: jvmti error %s\n",desc, errdesc); + fflush(stderr); + (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc); +} + + + /* * Class: gnu/classpath/jdwp/VMMethod * Method: getName @@ -48,24 +61,19 @@ $Id: $ JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getName(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) { jvmtiError err; - char* errdesc; - char *name, *signature, *generic; + char *name; 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); + GetMethodName(jvmtienv, + (jmethodID)(long)this->_methodId, + &name,NULL, NULL))) { + printjvmtierror("VMMethod.getName GetMethodName",err); 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; } @@ -79,24 +87,19 @@ JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getN JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getSignature(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) { jvmtiError err; - char* errdesc; - char *name, *signature, *generic; + char *signature; 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); + GetMethodName(jvmtienv, + (jmethodID)(long)this->_methodId, + NULL, &signature, NULL))) { + printjvmtierror("VMMethod.getSignature GetMethodName",err); 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; } @@ -110,17 +113,13 @@ JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getS JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMMethod_getModifiers(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) { 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); + if (JVMTI_ERROR_NONE!=(err= (*jvmtienv)-> + GetMethodModifiers(jvmtienv, + (jmethodID)(long)this->_methodId, + &modifiers))) { + printjvmtierror("VMMethod.getModifiers GetMethodModifiers",err); return 0; } @@ -147,16 +146,12 @@ JNIEXPORT struct gnu_classpath_jdwp_util_LineTable* JNICALL Java_gnu_classpath_j 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); + if (JVMTI_ERROR_NONE!=(err= (*jvmtienv)-> + GetLineNumberTable(jvmtienv, + (jmethodID)(long)this->_methodId, + &count, &lne))) { + printjvmtierror("VMMethod.getlinetable GetLineNumberTable",err); return NULL; } @@ -178,16 +173,13 @@ JNIEXPORT struct gnu_classpath_jdwp_util_LineTable* JNICALL Java_gnu_classpath_j } (*env)->ReleaseLongArrayElements(env, jlineCI, lineCI, 0); (*env)->ReleaseIntArrayElements(env, jlineNum, lineNum, 0); - (*jvmtienv)->Deallocate(jvmtienv,lne); + (*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); + if (JVMTI_ERROR_NONE!=(err= (*jvmtienv)-> + GetMethodLocation(jvmtienv, + (jmethodID)(long)this->_methodId, + &start, &end))) { + printjvmtierror("VMMethod.getlinetable GetMethodLocation",err); return NULL; } @@ -198,6 +190,52 @@ JNIEXPORT struct gnu_classpath_jdwp_util_LineTable* JNICALL Java_gnu_classpath_j } +static bool fillVariableTable(JNIEnv *env, jvmtiLocalVariableEntry* entries, + int count, jlongArray *jlineCI, + jobjectArray *names, jobjectArray *sigs, + jintArray *jlengths, jintArray *jslot) { + jint *lengths, *slot,i; + jclass cl; + jlong *lineCI; + + *jlineCI = (*env)->NewLongArray(env, count); + if (!*jlineCI) return false; + + cl=(*env)->FindClass(env,"java/lang/String"); + if (!cl) return false; + + *names = (*env)->NewObjectArray(env, count, cl, NULL); + if (names) return false; + sigs = (*env)->NewObjectArray(env, count, cl, NULL); + if (sigs) return false; + + jlengths = (*env)->NewIntArray(env, count); + if (!lengths) return false; + + jslot = (*env)->NewIntArray(env, count); + if (!slot) return false; + + lineCI = (*env)->GetLongArrayElements(env, *jlineCI, NULL); + lengths = (*env)->GetIntArrayElements(env, *jlengths, NULL); + slot = (*env)->GetIntArrayElements(env, jslot, NULL); + + for (i=0; i + SetObjectArrayElement(env, *names, i, + (*env)->NewStringUTF(env,entries[i].name)); + (*env)-> + SetObjectArrayElement(env, *sigs, i, (*env)->NewStringUTF( + env,entries[i].signature)); + lineCI[i]=entries[i].start_location; + lengths[i]=entries[i].length; + slot[i]=entries[i].slot; + } + (*env)->ReleaseLongArrayElements(env, jlineCI, lineCI, 0); + (*env)->ReleaseIntArrayElements(env, jlengths, lengths, 0); + (*env)->ReleaseIntArrayElements(env, jslot, slot, 0); + return true; +} + /* * Class: gnu/classpath/jdwp/VMMethod @@ -206,8 +244,76 @@ 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) { - fprintf(stderr,"VMMethod_getVariableTable: IMPLEMENT ME!!!"); - return 0; + jvmtiLocalVariableEntry* localvarentries; + jint entry_count, argCnt, slots; + jclass cl; + jmethodID m, vmmethodid; + jobject o; + jobjectArray names, sigs; + jvmtiError err; + jlongArray jlineCI; + jintArray jlengths, jslot; + + vmmethodid = (jmethodID)(long)this->_methodId; + + err= (*jvmtienv)->GetLocalVariableTable(jvmtienv, + vmmethodid, + &entry_count, + &localvarentries); + if (JVMTI_ERROR_NONE != err) { + if (err == JVMTI_ERROR_ABSENT_INFORMATION) { + /* no local variable table available for this method. + return an empty local variable table */ + argCnt = slots = 0; + names = sigs = jlineCI = jlengths = jslot = NULL; + } else { + printjvmtierror("VMMethod.getVariableTable GetLocalVariableTable",err); + return NULL; + } + } else { + if (JVMTI_ERROR_NONE != (err= + (*jvmtienv)->GetArgumentsSize(jvmtienv, + vmmethodid, + &argCnt))) { + printjvmtierror("VMMethod.getVariableTable GetArgumentsSize",err); + return NULL; + } + + if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->GetMaxLocals(jvmtienv, + vmmethodid, + &slots))) { + printjvmtierror("VMMethod.getVariableTable GetMaxLocals",err); + return NULL; + } + + slots = slots - argCnt; + if (!fillVariableTable(env, localvarentries, entry_count, &jlineCI, + &names, &sigs, &jlengths, &jslot)) + return NULL; + (*jvmtienv)-> + Deallocate(jvmtienv, (unsigned char*)localvarentries->signature); + (*jvmtienv)-> + Deallocate(jvmtienv, (unsigned char*)localvarentries->name); + if (localvarentries->generic_signature != NULL) + (*jvmtienv)-> Deallocate(jvmtienv, (unsigned char*) + localvarentries->generic_signature); + + + (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)localvarentries); + } + + cl = (*env)->FindClass(env,"gnu.classpath.jdwp.util.VariableTable"); + if (!cl) return NULL; + + m = (*env)-> + GetMethodID(env, cl,"", + "(II[J[Ljava/lang/String;[Ljava/lang/String;[I[I)V"); + if (!m) return NULL; + + o = (*env)->NewObject(env, cl, m, argCnt, slots, jlineCI, + names, sigs, jlengths, jslot); + + return (struct gnu_classpath_jdwp_util_VariableTable*) o; } /* diff --git a/src/native/vm/VMVirtualMachine.c b/src/native/vm/VMVirtualMachine.c index 3428d9d5a..cbf9c24af 100644 --- a/src/native/vm/VMVirtualMachine.c +++ b/src/native/vm/VMVirtualMachine.c @@ -29,7 +29,7 @@ Authors: Martin Platter Changes: Samuel Vinson -$Id: VMVirtualMachine.c 4969 2006-05-29 09:41:02Z motse $ +$Id: VMVirtualMachine.c 4996 2006-05-31 13:53:16Z motse $ */ @@ -54,7 +54,10 @@ $Id: VMVirtualMachine.c 4969 2006-05-29 09:41:02Z motse $ */ JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_suspendThread(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) { - (*jvmtienv)->SuspendThread(jvmtienv, (jthread) par1); + jvmtiError err; + + err = (*jvmtienv)->SuspendThread(jvmtienv, (jthread) par1); + printjvmtierror("VMVirtualMachine.suspendThread SuspendThread", err); } /* @@ -64,7 +67,10 @@ JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_suspendThread(JN */ JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_resumeThread(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) { - (*jvmtienv)->ResumeThread(jvmtienv, (jthread) par1); + jvmtiError err; + + err = (*jvmtienv)->ResumeThread(jvmtienv, (jthread) par1); + printjvmtierror("VMVirtualMachine.resumethread ResumeThread", err); } @@ -87,14 +93,10 @@ JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClasse jint count; jclass* classes; jvmtiError err; - char* errdesc; if (JVMTI_ERROR_NONE != (err= (*jvmtienv)-> GetLoadedClasses(jvmtienv, &count, &classes))) { - (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc); - fprintf(stderr,"jvmti error: %s\n",errdesc); - (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc); - fflush(stderr); + printjvmtierror("VMVirtualMachine_getAllLoadedClassCount GetLoadedClasses",err); return 0; } (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)classes); @@ -115,13 +117,10 @@ JNIEXPORT struct java_util_Iterator* JNICALL Java_gnu_classpath_jdwp_VMVirtualMa jobject *ol,*oi; int i; jvmtiError err; - char* errdesc; if (JVMTI_ERROR_NONE != (err= (*jvmtienv)-> GetLoadedClasses(jvmtienv, &classcount, &classes))) { - (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc); - fprintf(stderr,"jvmti error: %s\n",errdesc); - fflush(stderr); + printjvmtierror("VMVirtualMachine_getAllLoadedClasses GetLoadedClasses",err); /* we should throw JDWP Exception INTERNAL = 113;*/ /* env->ThrowNew(env,ec,"jvmti error occoured"); */ @@ -163,7 +162,11 @@ JNIEXPORT struct java_util_Iterator* JNICALL Java_gnu_classpath_jdwp_VMVirtualMa */ JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getClassStatus(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) { jint status; - (*jvmtienv)->GetClassStatus(jvmtienv, (jclass) par1, &status); + jvmtiError err; + + err = (*jvmtienv)->GetClassStatus(jvmtienv, (jclass) par1, &status); + printjvmtierror("VMVirtualMachine_getClassStatus GetClassStatus", err); + return status; } @@ -176,7 +179,6 @@ JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_get jint count; jmethodID* methodID, m; jvmtiError err; - char* errdesc; jclass *cl; jobject *ol; @@ -186,10 +188,7 @@ JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_get if (JVMTI_ERROR_NONE != (err= (*jvmtienv)-> 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); + printjvmtierror("VMVirtualMachine_getAllClassMethods GetClassMethods", err); return NULL; } @@ -203,7 +202,7 @@ JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_get joa = (*env)->NewObjectArray(env, (jsize)count, cl , NULL); 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]); @@ -268,7 +267,9 @@ JNIEXPORT struct gnu_classpath_jdwp_VMFrame* JNICALL Java_gnu_classpath_jdwp_VMV */ JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrameCount(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) { jint count; - (*jvmtienv)->GetFrameCount(jvmtienv, (jthread)par1, &count); + jvmtiError err; + err = (*jvmtienv)->GetFrameCount(jvmtienv, (jthread)par1, &count); + printjvmtierror("VMVirtualMachine_getFrameCount GetFrameCount", err); return count; } @@ -280,8 +281,11 @@ JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrameCount(JNIE */ JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getThreadStatus(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) { jint status; - if (JVMTI_ERROR_NONE != (*jvmtienv)->GetThreadState(jvmtienv, (jthread)par1, &status)) + jvmtiError err; + if (JVMTI_ERROR_NONE != (err = (*jvmtienv)->GetThreadState(jvmtienv, (jthread)par1, &status))) { + printjvmtierror("VMVirtualMachine_getThreadStatus GetThreadState", err); return 0; + } if (status && JVMTI_THREAD_STATE_ALIVE) { if (status && JVMTI_THREAD_STATE_WAITING) { return 4; /* WAIT - see JdwpConstants */ @@ -329,9 +333,14 @@ JNIEXPORT struct gnu_classpath_jdwp_util_MethodResult* JNICALL Java_gnu_classpat JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getSourceFile(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) { char* srcname; jstring str; + jvmtiError err; + + if (JVMTI_ERROR_NONE !=(err=(*jvmtienv)-> + GetSourceFileName(jvmtienv, (jclass)par1, &srcname))) { + printjvmtierror("VMVirtualMachine.getSourceFile GetSourceFileName", err); + return NULL; + } - (*jvmtienv)-> - GetSourceFileName(jvmtienv, (jclass)par1, &srcname); str = (*env)->NewString(env,(jchar*)srcname,(jsize)strlen(srcname)); return (struct java_lang_String*)str; @@ -371,15 +380,17 @@ JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_registerEvent(JN 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_ENABLE, - EventKind2jvmtiEvent(kind), NULL); + EventKind2jvmtiEvent(kind), NULL))) + printjvmtierror("VMVirtualMachine_registerEvent SetEventNotificationMode",err); /* todo: error handling, suspend policy */ }