From ea6244280b016b12843432c1381a2a9064f60d00 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Sat, 27 Jan 2007 16:34:32 +0000 Subject: [PATCH] * gnu/classpath/jdwp/natVMVirtualMachine.cc (getAllClassMethods): Move error handling to ... (throw_jvmti_error): ... here. (jdwpClassPrepareCB): New function. (jdwpThreadEndCB): New function. (jdwpThreadStartCB): New function. (jdwpVMDeathCB): New function. (jdwpVMInitCB): Define and enable callbacks for ClassPrepare, ThreadEnd, ThreadStart, and VMDeath. From-SVN: r121233 --- libjava/ChangeLog | 12 ++ .../gnu/classpath/jdwp/natVMVirtualMachine.cc | 112 +++++++++++++++--- 2 files changed, 110 insertions(+), 14 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 28602c2e7a3..4e6e238684e 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,15 @@ +2007-01-27 Keith Seitz + + * gnu/classpath/jdwp/natVMVirtualMachine.cc + (getAllClassMethods): Move error handling to ... + (throw_jvmti_error): ... here. + (jdwpClassPrepareCB): New function. + (jdwpThreadEndCB): New function. + (jdwpThreadStartCB): New function. + (jdwpVMDeathCB): New function. + (jdwpVMInitCB): Define and enable callbacks for + ClassPrepare, ThreadEnd, ThreadStart, and VMDeath. + 2007-01-27 Jakub Jelinek * Makefile.am (generic_header_files): Add $(inner_nat_headers). diff --git a/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc b/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc index ef4fe281d2f..1e0806652c5 100644 --- a/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc +++ b/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc @@ -28,7 +28,11 @@ details. */ #include #include #include +#include #include +#include +#include +#include #include #include #include @@ -39,7 +43,12 @@ using namespace gnu::classpath::jdwp::event; using namespace gnu::classpath::jdwp::util; // Forward declarations +static void JNICALL jdwpClassPrepareCB (jvmtiEnv *, JNIEnv *, jthread, jclass); +static void JNICALL jdwpThreadEndCB (jvmtiEnv *, JNIEnv *, jthread); +static void JNICALL jdwpThreadStartCB (jvmtiEnv *, JNIEnv *, jthread); +static void JNICALL jdwpVMDeathCB (jvmtiEnv *, JNIEnv *); static void JNICALL jdwpVMInitCB (jvmtiEnv *, JNIEnv *, jthread); +static void throw_jvmti_error (jvmtiError); #define DEFINE_CALLBACK(Cb,Event) Cb.Event = jdwp ## Event ## CB #define ENABLE_EVENT(Event,Thread) \ @@ -313,20 +322,7 @@ getAllClassMethods (jclass klass) jmethodID *methods; jvmtiError err = _jdwp_jvmtiEnv->GetClassMethods (klass, &count, &methods); if (err != JVMTI_ERROR_NONE) - { - char *error; - jstring msg; - if (_jdwp_jvmtiEnv->GetErrorName (err, &error) != JVMTI_ERROR_NONE) - { - msg = JvNewStringLatin1 (error); - _jdwp_jvmtiEnv->Deallocate ((unsigned char *) error); - } - else - msg = JvNewStringLatin1 ("out of memory"); - - using namespace gnu::classpath::jdwp::exception; - throw new JdwpInternalErrorException (msg); - } + throw_jvmti_error (err); JArray *result = (JArray *) JvNewObjectArray (count, @@ -407,10 +403,98 @@ getSourceFile (MAYBE_UNUSED jclass clazz) return NULL; } +static void +throw_jvmti_error (jvmtiError err) +{ + char *error; + jstring msg; + if (_jdwp_jvmtiEnv->GetErrorName (err, &error) == JVMTI_ERROR_NONE) + { + msg = JvNewStringLatin1 (error); + _jdwp_jvmtiEnv->Deallocate ((unsigned char *) error); + } + else + msg = JvNewStringLatin1 ("out of memory"); + + using namespace gnu::classpath::jdwp::exception; + throw new JdwpInternalErrorException (msg); +} + +static void JNICALL +jdwpClassPrepareCB (jvmtiEnv *env, MAYBE_UNUSED JNIEnv *jni_env, + jthread thread, jclass klass) +{ + using namespace gnu::classpath::jdwp; + + Thread *t = reinterpret_cast (thread); + jint flags = 0; + jvmtiError err = env->GetClassStatus (klass, &flags); + if (err != JVMTI_ERROR_NONE) + throw_jvmti_error (err); + + using namespace gnu::classpath::jdwp::event; + jint status = 0; + if (flags & JVMTI_CLASS_STATUS_VERIFIED) + status |= ClassPrepareEvent::STATUS_VERIFIED; + if (flags & JVMTI_CLASS_STATUS_PREPARED) + status |= ClassPrepareEvent::STATUS_PREPARED; + if (flags & JVMTI_CLASS_STATUS_ERROR) + status |= ClassPrepareEvent::STATUS_ERROR; + if (flags & JVMTI_CLASS_STATUS_INITIALIZED) + status |= ClassPrepareEvent::STATUS_INITIALIZED; + + event::ClassPrepareEvent *event + = new event::ClassPrepareEvent (t, klass, status); + Jdwp::notify (event); +} + +static void JNICALL +jdwpThreadEndCB (MAYBE_UNUSED jvmtiEnv *env, MAYBE_UNUSED JNIEnv *jni_env, + jthread thread) +{ + using namespace gnu::classpath::jdwp::event; + + Thread *t = reinterpret_cast (thread); + ThreadEndEvent *e = new ThreadEndEvent (t); + gnu::classpath::jdwp::Jdwp::notify (e); +} + +static void JNICALL +jdwpThreadStartCB (MAYBE_UNUSED jvmtiEnv *env, MAYBE_UNUSED JNIEnv *jni_env, + jthread thread) +{ + using namespace gnu::classpath::jdwp::event; + + Thread *t = reinterpret_cast (thread); + ThreadStartEvent *e = new ThreadStartEvent (t); + gnu::classpath::jdwp::Jdwp::notify (e); +} + +static void JNICALL +jdwpVMDeathCB (MAYBE_UNUSED jvmtiEnv *env, MAYBE_UNUSED JNIEnv *jni_env) +{ + using namespace gnu::classpath::jdwp::event; + gnu::classpath::jdwp::Jdwp::notify (new VmDeathEvent ()); +} + static void JNICALL jdwpVMInitCB (MAYBE_UNUSED jvmtiEnv *env, MAYBE_UNUSED JNIEnv *jni_env, jthread thread) { + // The VM is now initialized, add our callbacks + jvmtiEventCallbacks callbacks; + DEFINE_CALLBACK (callbacks, ClassPrepare); + DEFINE_CALLBACK (callbacks, ThreadEnd); + DEFINE_CALLBACK (callbacks, ThreadStart); + DEFINE_CALLBACK (callbacks, VMDeath); + _jdwp_jvmtiEnv->SetEventCallbacks (&callbacks, sizeof (callbacks)); + + // Enable callbacks + ENABLE_EVENT (CLASS_PREPARE, NULL); + ENABLE_EVENT (THREAD_END, NULL); + ENABLE_EVENT (THREAD_START, NULL); + ENABLE_EVENT (VM_DEATH, NULL); + // Send JDWP VMInit using namespace gnu::classpath::jdwp::event; Thread *init_thread = reinterpret_cast (thread); -- 2.30.2