1 /* src/native/vm/gnu/gnu_classpath_jdwp_VMVirtualMachine.c - jdwp->jvmti interface
3 Copyright (C) 1996-2005, 2006, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 #include "toolbox/logging.h"
32 #include "native/jni.hpp"
33 #include "native/include/java_lang_Thread.h"
34 #include "native/include/java_nio_ByteBuffer.h"
35 #include "native/include/java_lang_Class.h"
36 #include "native/include/java_lang_ClassLoader.h"
37 #include "native/include/java_lang_reflect_Method.h"
38 #include "native/include/gnu_classpath_jdwp_event_EventRequest.h"
39 #include "native/include/gnu_classpath_jdwp_VMVirtualMachine.h"
40 #include "native/jvmti/jvmti.h"
41 #include "native/jvmti/VMjdwp.h"
45 * Class: gnu_classpath_jdwp_VMVirtualMachine
46 * Method: suspendThread
47 * Signature: (Ljava/lang/Thread;)V
49 JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_suspendThread(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1)
53 err = (*jvmtienv)->SuspendThread(jvmtienv, (jthread) par1);
54 printjvmtierror("VMVirtualMachine.suspendThread SuspendThread", err);
58 * Class: gnu_classpath_jdwp_VMVirtualMachine
59 * Method: resumeThread
60 * Signature: (Ljava/lang/Thread;)V
62 JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_resumeThread(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1)
66 err = (*jvmtienv)->ResumeThread(jvmtienv, (jthread) par1);
67 printjvmtierror("VMVirtualMachine.resumethread ResumeThread", err);
72 * Class: gnu_classpath_jdwp_VMVirtualMachine
73 * Method: getSuspendCount
74 * Signature: (Ljava/lang/Thread;)I
76 JNIEXPORT int32_t JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getSuspendCount(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) {
77 log_text ("VMVirtualMachine_getSuspendCount: not supported");
82 * Class: gnu_classpath_jdwp_VMVirtualMachine
83 * Method: getAllLoadedClassesCount
86 JNIEXPORT int32_t JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClassesCount(JNIEnv *env, jclass clazz) {
91 if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
92 GetLoadedClasses(jvmtienv, &count, &classes))) {
93 printjvmtierror("VMVirtualMachine_getAllLoadedClassCount GetLoadedClasses",err);
96 (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)classes);
101 * Class: gnu_classpath_jdwp_VMVirtualMachine
102 * Method: getAllLoadedClasses
103 * Signature: ()Ljava/util/Iterator
105 JNIEXPORT struct java_util_Iterator* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClasses(JNIEnv *env, jclass clazz) {
106 jclass *classes, *cl;
115 if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
116 GetLoadedClasses(jvmtienv, &classcount, &classes))) {
117 printjvmtierror("VMVirtualMachine_getAllLoadedClasses GetLoadedClasses",err);
119 /* we should throw JDWP Exception INTERNAL = 113;*/
120 /* env->ThrowNew(env,ec,"jvmti error occoured"); */
124 cl = (*env)->FindClass(env,"java.lang.Class");
125 if (!cl) return NULL;
127 /* Arrays.asList(Object[] classes)->List.Iterator()->Iterator */
128 joa = (*env)->NewObjectArray(env, (jsize)classcount, cl , NULL);
129 if (!joa) return NULL;
131 for (i = 0; i < classcount; i++)
132 (*env)->SetObjectArrayElement(env,joa,(jsize)i, (jobject)classes[i]);
133 (*jvmtienv)->Deallocate(jvmtienv, (unsigned char*)classes);
135 cl = (*env)->FindClass(env,"java.util.Arrays");
136 if (!cl) return NULL;
138 m = (*env)->GetStaticMethodID(env, cl, "asList", "([Ljava/lang/Object;)Ljava/util/List;");
141 ol = (*env)->CallStaticObjectMethod(env,(jclass)cl,m,joa);
142 if (!ol) return NULL;
144 cl = (*env)->FindClass(env,"java.util.List");
145 if (!cl) return NULL;
146 m = (*env)->GetMethodID(env,cl,"iterator","()Ljava/util/Iterator;");
148 oi = (*env)->CallObjectMethod(env,ol,m);
150 return (struct java_util_Iterator*)oi;
153 /* Class: gnu/classpath/jdwp/VMVirtualMachine
154 * Method: getClassStatus
155 * Signature: (Ljava/lang/Class;)I
157 JNIEXPORT int32_t JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getClassStatus(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) {
161 err = (*jvmtienv)->GetClassStatus(jvmtienv, (jclass) par1, &status);
162 printjvmtierror("VMVirtualMachine_getClassStatus GetClassStatus", err);
168 * Class: gnu/classpath/jdwp/VMVirtualMachine
169 * Method: getAllClassMethods
170 * Signature: (Ljava/lang/Class;)[Lgnu/classpath/jdwp/VMMethod;
172 JNIEXPORT java_objectarray* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getAllClassMethods(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) {
174 jmethodID* methodID, m;
182 if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
183 GetClassMethods(jvmtienv, (jclass) par1,
184 &count, &methodID))) {
185 printjvmtierror("VMVirtualMachine_getAllClassMethods GetClassMethods", err);
190 GetStaticMethodID(env, clazz, "getClassMethod",
191 "(Ljava/lang/Class;J)Lgnu/classpath/jdwp/VMMethod;");
194 cl = (*env)->FindClass(env,"gnu.classpath.jdwp.VMMethod");
195 if (!cl) return NULL;
197 joa = (*env)->NewObjectArray(env, (jsize)count, cl , NULL);
198 if (!joa) return NULL;
200 for (i = 0; i < count; i++) {
202 CallStaticObjectMethod(env,clazz,m,(jobject)par1, methodID[i]);
203 if (!ol) return NULL;
204 (*env)->SetObjectArrayElement(env,joa,(jsize)i, ol);
211 * Class: gnu/classpath/jdwp/VMVirtualMachine
212 * Method: getClassMethod
213 * Signature: (Ljava/lang/Class;J)Lgnu/classpath/jdwp/VMMethod;
215 JNIEXPORT struct gnu_classpath_jdwp_VMMethod* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getClassMethod(JNIEnv *env, jclass clazz, struct java_lang_Class* par1, s8 par2) {
220 cl = (*env)->FindClass(env,"gnu.classpath.jdwp.VMMethod");
221 if (!cl) return NULL;
223 m = (*env)->GetMethodID(env, cl, "<init>", "(Ljava/lang/Class;J)V");
226 ol = (*env)->NewObject(env, cl, m, par1, par2);
228 return (struct gnu_classpath_jdwp_VMMethod*)ol;
233 * Class: gnu/classpath/jdwp/VMVirtualMachine
235 * Signature: (Ljava/lang/Thread;II)Ljava/util/ArrayList;
237 JNIEXPORT struct java_util_ArrayList* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrames(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1, int32_t par2, int32_t par3) {
238 log_text ("VMVirtualMachine_getFrames - IMPLEMENT ME!!!");
239 /* jclass ec = (*env)->FindClass(env,"gnu/classpath/jdwp/JdwpInternalErrorException");
240 if (JVMTI_ERROR_NONE != (*jvmtienv)->GetClassStatus(jvmtienv, par1, &status))
241 env->ThrowNew(env,ec,"jvmti error occoured");*/
247 * Class: gnu/classpath/jdwp/VMVirtualMachine
249 * Signature: (Ljava/lang/Thread;Ljava/nio/ByteBuffer;)Lgnu/classpath/jdwp/VMFrame;
251 JNIEXPORT struct gnu_classpath_jdwp_VMFrame* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrame(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1, struct java_nio_ByteBuffer* par2) {
252 log_text ("VMVirtualMachine_getFrame - IMPLEMENT ME!!!");
258 * Class: gnu/classpath/jdwp/VMVirtualMachine
259 * Method: getFrameCount
260 * Signature: (Ljava/lang/Thread;)I
262 JNIEXPORT int32_t JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getFrameCount(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) {
265 err = (*jvmtienv)->GetFrameCount(jvmtienv, (jthread)par1, &count);
266 printjvmtierror("VMVirtualMachine_getFrameCount GetFrameCount", err);
272 * Class: gnu/classpath/jdwp/VMVirtualMachine
273 * Method: getThreadStatus
274 * Signature: (Ljava/lang/Thread;)I
276 JNIEXPORT int32_t JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getThreadStatus(JNIEnv *env, jclass clazz, struct java_lang_Thread* par1) {
279 if (JVMTI_ERROR_NONE != (err = (*jvmtienv)->GetThreadState(jvmtienv, (jthread)par1, &status))) {
280 printjvmtierror("VMVirtualMachine_getThreadStatus GetThreadState", err);
283 if (status && JVMTI_THREAD_STATE_ALIVE) {
284 if (status && JVMTI_THREAD_STATE_WAITING) {
285 return 4; /* WAIT - see JdwpConstants */
287 if (status && JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) {
288 return 3; /* MONITOR - see JdwpConstants */
290 if (status && JVMTI_THREAD_STATE_SLEEPING) {
291 return 2; /* SLEEPING - see JdwpConstants */
293 return 1; /* RUNNING - see JdwpConstants */
295 return 0; /* ZOMBIE - see JdwpConstants */
296 return -1; /* some error */
301 * Class: gnu/classpath/jdwp/VMVirtualMachine
302 * Method: getLoadRequests
303 * Signature: (Ljava/lang/ClassLoader;)Ljava/util/ArrayList;
305 JNIEXPORT struct java_util_ArrayList* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getLoadRequests(JNIEnv *env, jclass clazz, struct java_lang_ClassLoader* par1) {
306 log_text ("VMVirtualMachine_getLoadRequests(");
312 * Class: gnu/classpath/jdwp/VMVirtualMachine
313 * Method: executeMethod
314 * Signature: (Ljava/lang/Object;Ljava/lang/Thread;Ljava/lang/Class;Ljava/lang/reflect/Method;[Ljava/lang/Object;Z)Lgnu/classpath/jdwp/util/MethodResult;
316 JNIEXPORT struct gnu_classpath_jdwp_util_MethodResult* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_executeMethod(JNIEnv *env, jclass clazz, struct java_lang_Object* par1, struct java_lang_Thread* par2, struct java_lang_Class* par3, struct java_lang_reflect_Method* par4, java_objectarray* par5, int32_t par6) {
317 log_text ("VMVirtualMachine_executeMethod");
323 * Class: gnu/classpath/jdwp/VMVirtualMachine
324 * Method: getSourceFile
325 * Signature: (Ljava/lang/Class;)Ljava/lang/String;
327 JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_getSourceFile(JNIEnv *env, jclass clazz, struct java_lang_Class* par1) {
332 if (JVMTI_ERROR_NONE !=(err=(*jvmtienv)->
333 GetSourceFileName(jvmtienv, (jclass)par1, &srcname))) {
334 printjvmtierror("VMVirtualMachine.getSourceFile GetSourceFileName", err);
338 str = (*env)->NewString(env,(jchar*)srcname,(jsize)strlen(srcname));
340 return (struct java_lang_String*)str;
343 /* match JdwpConstants.EventKind to jvmtiEvent constants */
344 static jvmtiEvent EventKind2jvmtiEvent(jbyte kind){
346 case /* SINGLE_STEP */ 1: return JVMTI_EVENT_SINGLE_STEP;
347 case /* BREAKPOINT */ 2: return JVMTI_EVENT_BREAKPOINT;
348 case /* FRAME_POP */ 3: return JVMTI_EVENT_FRAME_POP;
349 case /* EXCEPTION */ 4: return JVMTI_EVENT_EXCEPTION;
350 case /* USER_DEFINED */ 5: return -1; /* can this be matched ? */
351 case /* THREAD_START */ 6: return JVMTI_EVENT_THREAD_START;
352 case /* THREAD_END */ 7: return JVMTI_EVENT_THREAD_END;
353 case /* CLASS_PREPARE */ 8: return JVMTI_EVENT_CLASS_PREPARE;
354 case /* CLASS_UNLOAD */ 9: return -1; /* can this be matched ? */
355 case /* CLASS_LOAD */ 10: return JVMTI_EVENT_CLASS_LOAD;
356 case /* FIELD_ACCESS */ 20: return JVMTI_EVENT_FIELD_ACCESS;
357 case /* FIELD_MODIFICATION */ 21: return JVMTI_EVENT_FIELD_MODIFICATION;
358 case /* EXCEPTION_CATCH */ 30: return JVMTI_EVENT_EXCEPTION_CATCH;
359 case /* METHOD_ENTRY */ 40: return JVMTI_EVENT_METHOD_ENTRY;
360 case /* METHOD_EXIT */ 41: return JVMTI_EVENT_METHOD_EXIT;
361 case /* VM_INIT */ 90: return JVMTI_EVENT_VM_INIT;
362 case /* VM_DEATH */ 99: return JVMTI_EVENT_VM_DEATH;
363 case /* VM_DISCONNECTED */ 100: return -1; /* can this be matched ? */
369 * Class: gnu/classpath/jdwp/VMVirtualMachine
370 * Method: registerEvent
371 * Signature: (Lgnu/classpath/jdwp/event/EventRequest;)V
373 JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_registerEvent(JNIEnv *env, jclass clazz, struct gnu_classpath_jdwp_event_EventRequest* par1) {
379 erc = (*env)->FindClass(env,"gnu.classpath.jdwp.event.EventRequest");
381 kindid = (*env)->GetFieldID(env, erc, "_kind", "B");
382 kind = (*env)->GetByteField(env, (jobject)par1, kindid);
384 if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
385 SetEventNotificationMode(jvmtienv, JVMTI_ENABLE,
386 EventKind2jvmtiEvent(kind), NULL)))
387 printjvmtierror("VMVirtualMachine_registerEvent SetEventNotificationMode",err);
393 * Class: gnu/classpath/jdwp/VMVirtualMachine
394 * Method: unregisterEvent
395 * Signature: (Lgnu/classpath/jdwp/event/EventRequest;)V
397 JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_unregisterEvent(JNIEnv *env, jclass clazz, struct gnu_classpath_jdwp_event_EventRequest* par1) {
403 erc = (*env)->FindClass(env,"gnu.classpath.jdwp.event.EventRequest");
405 kindid = (*env)->GetFieldID(env, erc, "_kind", "B");
406 kind = (*env)->GetByteField(env, (jobject)par1, kindid);
408 if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
409 SetEventNotificationMode(jvmtienv, JVMTI_DISABLE,
410 EventKind2jvmtiEvent(kind), NULL)))
411 printjvmtierror("VMVirtualMachine_registerEvent SetEventNotificationMode",err);
417 * Class: gnu/classpath/jdwp/VMVirtualMachine
418 * Method: clearEvents
421 JNIEXPORT void JNICALL Java_gnu_classpath_jdwp_VMVirtualMachine_clearEvents(JNIEnv *env, jclass clazz, int32_t par1) {
422 /* jvmti events are not saved - there is nothing to clear */
427 * These are local overrides for various environment variables in Emacs.
428 * Please do not remove this and leave it at the end of the file, where
429 * Emacs will automagically detect them.
430 * ---------------------------------------------------------------------
433 * indent-tabs-mode: t