diff options
author | John Keiser <shalom@gnu.org> | 1998-06-21 06:20:58 +0000 |
---|---|---|
committer | John Keiser <shalom@gnu.org> | 1998-06-21 06:20:58 +0000 |
commit | 940dc05ba3e2e6a0b2991dfe611efe06718263ec (patch) | |
tree | 9f74365e4d1773001ed65c8667c98f4f534b5310 /native/vmi | |
parent | 3d1f1f0cf141196448fe634d79e5ef029676a38e (diff) | |
download | classpath-940dc05ba3e2e6a0b2991dfe611efe06718263ec.tar.gz |
Initial Revision
Diffstat (limited to 'native/vmi')
-rwxr-xr-x | native/vmi/DEPENDENCIES | 14 | ||||
-rwxr-xr-x | native/vmi/README | 9 | ||||
-rwxr-xr-x | native/vmi/STATUS | 3 | ||||
-rw-r--r-- | native/vmi/TODO | 28 | ||||
-rwxr-xr-x | native/vmi/vmi.c | 206 | ||||
-rwxr-xr-x | native/vmi/vmi.h | 129 |
6 files changed, 389 insertions, 0 deletions
diff --git a/native/vmi/DEPENDENCIES b/native/vmi/DEPENDENCIES new file mode 100755 index 000000000..a4c3d51b8 --- /dev/null +++ b/native/vmi/DEPENDENCIES @@ -0,0 +1,14 @@ +DEPENDENCIES for JCL VMI library: + +Japhar 1.1: +- Most functions depend on Japhar JVMDI. +- However, JNI and JCL functions are called by some of the + non-JVMDI functions. +- Additionally: + - VMI_GetFrameObject() depends on the StackFrame + structure in Japhar's interp.h. + - VMI_GetThisFrame() and VMI_GetThisThreadObject() depend + on the JThreadInfo structure and the + THREAD_getJavaInfo() function in Japhar's + native-threads.h. + diff --git a/native/vmi/README b/native/vmi/README new file mode 100755 index 000000000..4f5d1a9a2 --- /dev/null +++ b/native/vmi/README @@ -0,0 +1,9 @@ +README for JCL VMI library: + +20 June 1998: John Keiser +Initial Revision + +This is the catchall library that does all the VM-specific +interface stuff. It needs to be implemented on a per-VM +basis. Currently the only JVM supported is Japhar. + diff --git a/native/vmi/STATUS b/native/vmi/STATUS new file mode 100755 index 000000000..97365ca80 --- /dev/null +++ b/native/vmi/STATUS @@ -0,0 +1,3 @@ +STATUS for JCL VMI library: + +Japhar 1.1: all current VMI functions implemented. Compiled, untested. diff --git a/native/vmi/TODO b/native/vmi/TODO new file mode 100644 index 000000000..8107ad444 --- /dev/null +++ b/native/vmi/TODO @@ -0,0 +1,28 @@ +TODO for JCL VMI library: + +API: +- More functions will almost certainly be required. I am + adding them in only as needs arise to keep the job as + easy as possible in the short term. The full JVMDI + will presumably need to be mimicked. + +Japhar 1.1: +- Using the JVMDI for many functions, since Japhar + implements JVMDI. Several JVMDI functions are not + implemented yet, though, so it becomes a question of + waiting til they are or implementing them ourselves. +- Specifically, the JVMDI functions not yet implemented in + Japhar that the VMI calls are: + - JVMDI_GetClassModifiers() + - JVMDI_GetClassName() + - JVMDI_GetClassMethods() + - JVMDI_GetClassFields() + - JVMDI_GetImplementedInterfaces() + - JVMDI_IsInterface() + - JVMDI_IsArray() + - JVMDI_ClassLoader() + - JVMDI_GetMethodModifiers() + - JVMDI_GetThrownExceptions() + - JVMDI_GetFieldName() + - JVMDI_GetFieldDeclaringClass() + - JVMDI_GetFieldModifiers() diff --git a/native/vmi/vmi.c b/native/vmi/vmi.c new file mode 100755 index 000000000..75d5bd5de --- /dev/null +++ b/native/vmi/vmi.c @@ -0,0 +1,206 @@ +/* Japhar implementation of VMI. */ + +#include <jcl.h> +#include <vmi.h> +#include <jvmdi.h> +#include <interp.h> +#include <native-threads.h> + +JNIEXPORT vmiError JNICALL +VMI_GetFrameObject(JNIEnv *env, + jframeID frame, + jobject *obj) { + StackFrame *sframe = (StackFrame*)frame; + if(env == NULL || obj == NULL) + return VMI_ERROR_NULL_POINTER; + if(frame == NULL) + return VMI_ERROR_INVALID_FRAMEID; + + *obj = THISPTR(sframe); + return VMI_ERROR_NONE; +} + +JNIEXPORT vmiError JNICALL +VMI_GetThisFrame(JNIEnv *env, jframeID *frame) { + JThreadInfo *thread_info; + + if(env == NULL || frame == NULL) + return VMI_ERROR_NULL_POINTER; + + thread_info = THREAD_getJavaInfo(); + *frame = (jframeID)TOPFRAME(thread_info); + return VMI_ERROR_NONE; +} + +JNIEXPORT vmiError JNICALL +VMI_GetThisThreadObject(JNIEnv* env, jthread *thread) { + JThreadInfo *thread_info; + if(env == NULL || thread == NULL) + return VMI_ERROR_NULL_POINTER; + thread_info = THREAD_getJavaInfo(); + *thread = (jthread)thread_info->java_thread; + return VMI_ERROR_NONE; +} + +JNIEXPORT void JNICALL +VMI_ThrowAppropriateException(JNIEnv *env, vmiError err) { + switch(err) { + case VMI_ERROR_NONE: + JCL_ThrowException(env, "java/lang/InternalError", "ERROR_NONE passed to VMI exception thrower."); + break; + case VMI_ERROR_NULL_POINTER: + JCL_ThrowException(env, "java/lang/NullPointerException", "null pointer in VMI detected."); + break; + case VMI_ERROR_OUT_OF_MEMORY: + JCL_ThrowException(env, "java/lang/OutOfMemoryError", "Out of memory! (in VMI)."); + break; + case VMI_ERROR_INVALID_METHODID: + JCL_ThrowException(env, "java/lang/InternalError", "VMI error: INVALID_METHODID"); + break; + case VMI_ERROR_INVALID_CLASS: + JCL_ThrowException(env, "java/lang/InternalError", "VMI error: INVALID_CLASS"); + break; + case VMI_ERROR_INVALID_BCI: + JCL_ThrowException(env, "java/lang/InternalError", "VMI error: INVALID_BCI"); + break; + case VMI_ERROR_NO_SUCH_BREAKPOINT: + JCL_ThrowException(env, "java/lang/InternalError", "VMI error: NO_SUCH_BREAKPOINT"); + break; + case VMI_ERROR_VM_DEAD: + JCL_ThrowException(env, "java/lang/InternalError", "VMI error: VM Dead! Kinda makes ya wonder how this exception got thrown, huh?"); + break; + case VMI_ERROR_INVALID_FRAMEID: + JCL_ThrowException(env, "java/lang/IllegalThreadStateException", "NULL Frame ID detected in VMI."); + break; + case VMI_ERROR_INVALID_SLOT: + JCL_ThrowException(env, "java/lang/InternalError", "VMI error: INVALID_SLOT"); + break; + case VMI_ERROR_TYPE_MISMATCH: + JCL_ThrowException(env, "java/lang/InternalError", "VMI error: INVALID_SLOT"); + break; + case VMI_ERROR_NATIVE_FRAME: + JCL_ThrowException(env, "java/lang/InternalError", "VMI error: NATIVE_FRAME"); + break; + case VMI_ERROR_NO_MORE_FRAMES: + JCL_ThrowException(env, "java/lang/InternalError", "VMI error: NO_MORE_FRAMES"); + break; + case VMI_ERROR_INVALID_THREAD: + JCL_ThrowException(env, "java/lang/IllegalThreadStateException", "Invalid thread in VMI."); + break; + case VMI_ERROR_THREAD_NOT_SUSPENDED: + JCL_ThrowException(env, "java/lang/IllegalThreadStateException", "Attempt to introspect unsuspended thread in VMI."); + break; + default: + JCL_ThrowException(env, "java/lang/UnknownError", "VMI returned erroneous error value ..."); + break; + } +} + + +/* 1.2 placeholders: can be implemented for Japhar using JNI */ + +/* Thread / Frame Stuff */ + +JNIEXPORT vmiError JNICALL +VMI_GetCallerFrame(JNIEnv *env, jframeID called, jframeID *framePtr) { + return JVMDI_GetCallerFrame(env, called, framePtr); +} + + +/* Class Introspection */ + +JNIEXPORT vmiError JNICALL +VMI_GetClassModifiers(JNIEnv *env, jclass clazz, jint *modifiers) { + return JVMDI_GetClassModifiers(env, clazz, modifiers); +} + +JNIEXPORT vmiError JNICALL +VMI_GetClassName(JNIEnv *env, jclass clazz, jstring *namePtr) { + return JVMDI_GetClassName(env, clazz, namePtr); +} + +JNIEXPORT vmiError JNICALL +VMI_GetClassMethods(JNIEnv *env, jclass clazz, + jint *methodCountPtr, jmethodID **methodsPtr) { + return JVMDI_GetClassMethods(env, clazz, methodCountPtr, methodsPtr); +} + +JNIEXPORT vmiError JNICALL +VMI_GetClassFields(JNIEnv *env, jclass clazz, + jint *fieldCountPtr, jfieldID **fieldsPtr) { + return JVMDI_GetClassFields(env, clazz, fieldCountPtr, fieldsPtr); +} + +JNIEXPORT vmiError JNICALL +VMI_GetImplementedInterfaces(JNIEnv *env, jclass clazz, + jint *interfaceCountPtr, + jclass **interfacesPtr) { + return JVMDI_GetImplementedInterfaces(env, clazz, interfaceCountPtr, interfacesPtr); +} + +JNIEXPORT vmiError JNICALL +VMI_IsInterface(JNIEnv *env, jclass clazz, jboolean *isInterfacePtr) { + return JVMDI_IsInterface(env, clazz, isInterfacePtr); +} + +JNIEXPORT vmiError JNICALL +VMI_IsArray(JNIEnv *env, jclass clazz, jboolean *isArrayPtr) { + return JVMDI_IsArray(env, clazz, isArrayPtr); +} + +JNIEXPORT vmiError JNICALL +VMI_ClassLoader(JNIEnv *env, jclass clazz, jobject *classloaderPtr) { + return JVMDI_ClassLoader(env, clazz, classloaderPtr); +} + +/* Method Introspection */ + +JNIEXPORT vmiError JNICALL +VMI_GetMethodModifiers(JNIEnv *env, jmethodID m, jint *modifiers) { + return JVMDI_GetMethodModifiers(env, m, modifiers); +} + +JNIEXPORT vmiError JNICALL +VMI_GetMethodName(JNIEnv *env, jclass clazz, jmethodID method, + jstring *namePtr, jstring *signaturePtr) { + return JVMDI_GetMethodName(env, clazz, method, namePtr, signaturePtr); +} + +JNIEXPORT vmiError JNICALL +VMI_GetMethodDefiningClass(JNIEnv *env, jclass clazz, jmethodID method, + jclass *definingClassPtr) { + return JVMDI_GetMethodDefiningClass(env, clazz, method, definingClassPtr); +} + +/* Field Introspection */ + +JNIEXPORT vmiError JNICALL +VMI_GetFieldName(JNIEnv *env, jclass clazz, jfieldID field, + char **namePtr, char **signaturePtr) { + return JVMDI_GetFieldName(env, clazz, field, namePtr, signaturePtr); +} + +JNIEXPORT vmiError JNICALL +VMI_GetFieldDeclaringClass(JNIEnv *env, jclass clazz, jfieldID field, + jclass *declaringClassPtr) { + return JVMDI_GetFieldDeclaringClass(env, clazz, field, declaringClassPtr); +} + +JNIEXPORT vmiError JNICALL +VMI_GetFieldModifiers(JNIEnv *env, jclass clazz, jfieldID field, + jint *modifiersPtr) { + return JVMDI_GetFieldModifiers(env, clazz, field, modifiersPtr); +} + +JNIEXPORT vmiError JNICALL +VMI_GetThrownExceptions(JNIEnv *env, jclass clazz, jmethodID method, + jint *exceptionCountPtr, jclass **exceptionsPtr) { + return JVMDI_GetThrownExceptions(env, clazz, method, exceptionCountPtr, exceptionsPtr); +} + +JNIEXPORT vmiError JNICALL +VMI_IsMethodNative(JNIEnv *env, jclass clazz, jmethodID method, + jboolean *isNativePtr) { + return JVMDI_IsMethodNative(env, clazz, method, isNativePtr); +} + diff --git a/native/vmi/vmi.h b/native/vmi/vmi.h new file mode 100755 index 000000000..70f343fa1 --- /dev/null +++ b/native/vmi/vmi.h @@ -0,0 +1,129 @@ +#ifndef __VMI_H__ +#define __VMI_H__ + +#include <jni.h> + +typedef void * jframeID; +typedef void * jthread; + +typedef enum { + VMI_ERROR_NONE, + VMI_ERROR_NULL_POINTER, + VMI_ERROR_OUT_OF_MEMORY, + VMI_ERROR_INVALID_METHODID, + VMI_ERROR_INVALID_CLASS, + VMI_ERROR_INVALID_BCI, + VMI_ERROR_NO_SUCH_BREAKPOINT, + VMI_ERROR_VM_DEAD, + VMI_ERROR_INVALID_FRAMEID, + VMI_ERROR_INVALID_SLOT, + VMI_ERROR_TYPE_MISMATCH, + VMI_ERROR_NATIVE_FRAME, + VMI_ERROR_NO_MORE_FRAMES, + VMI_ERROR_INVALID_THREAD, + VMI_ERROR_THREAD_NOT_SUSPENDED +} vmiError; + + +#define VMI_MOD_PUBLIC 0x0001 +#define VMI_MOD_PRIVATE 0x0002 +#define VMI_MOD_PROTECTED 0x0004 +#define VMI_MOD_STATIC 0x0008 +#define VMI_MOD_FINAL 0x0010 +#define VMI_MOD_SYNCHRONIZED 0x0020 +#define VMI_MOD_VOLATILE 0x0040 +#define VMI_MOD_TRANSIENT 0x0080 +#define VMI_MOD_NATIVE 0x0100 +#define VMI_MOD_INTERFACE 0x0200 +#define VMI_MOD_ABSTRACT 0x0400 + + +JNIEXPORT vmiError JNICALL +VMI_GetFrameObject(JNIEnv *env, jframeID frame, jobject *obj); + +JNIEXPORT vmiError JNICALL +VMI_GetThisFrame(JNIEnv *env, jframeID *frame); + +JNIEXPORT vmiError JNICALL +VMI_GetThisThreadObject(JNIEnv *env, jthread *thread); + +JNIEXPORT void JNICALL +VMI_ThrowAppropriateException(JNIEnv *env, vmiError err); + + +/* + * 1.2 placeholders: stuff that will be in JVMDI but has to be in VMI for now. + */ + +/* Thread / Frame Stuff */ + +JNIEXPORT vmiError JNICALL +VMI_GetCallerFrame(JNIEnv *env, jframeID called, jframeID *framePtr); + + +/* Class Introspection */ + +JNIEXPORT vmiError JNICALL +VMI_GetClassModifiers(JNIEnv *env, jclass clazz, jint *modifiers); + +JNIEXPORT vmiError JNICALL +VMI_GetClassName(JNIEnv *env, jclass clazz, jstring *namePtr); + +JNIEXPORT vmiError JNICALL +VMI_GetClassMethods(JNIEnv *env, jclass clazz, + jint *methodCountPtr, jmethodID **methodsPtr); + +JNIEXPORT vmiError JNICALL +VMI_GetClassFields(JNIEnv *env, jclass clazz, + jint *fieldCountPtr, jfieldID **fieldsPtr); + +JNIEXPORT vmiError JNICALL +VMI_GetImplementedInterfaces(JNIEnv *env, jclass clazz, + jint *interfaceCountPtr, + jclass **interfacesPtr); + +JNIEXPORT vmiError JNICALL +VMI_IsInterface(JNIEnv *env, jclass clazz, jboolean *isInterfacePtr); + +JNIEXPORT vmiError JNICALL +VMI_IsArray(JNIEnv *env, jclass clazz, jboolean *isArrayPtr); + +JNIEXPORT vmiError JNICALL +VMI_ClassLoader(JNIEnv *env, jclass clazz, jobject *classloaderPtr); + +/* Method Introspection */ + +JNIEXPORT vmiError JNICALL +VMI_GetMethodModifiers(JNIEnv *env, jmethodID m, jint *modifiers); + +JNIEXPORT vmiError JNICALL +VMI_GetMethodName(JNIEnv *env, jclass clazz, jmethodID method, + jstring *namePtr, jstring *signaturePtr); + +JNIEXPORT vmiError JNICALL +VMI_GetMethodDefiningClass(JNIEnv *env, jclass clazz, jmethodID method, + jclass *definingClassPtr); + +/* Field Introspection */ + +JNIEXPORT vmiError JNICALL +VMI_GetFieldName(JNIEnv *env, jclass clazz, jfieldID field, + char **namePtr, char **signaturePtr); + +JNIEXPORT vmiError JNICALL +VMI_GetFieldDeclaringClass(JNIEnv *env, jclass clazz, jfieldID field, + jclass *declaringClassPtr); + +JNIEXPORT vmiError JNICALL +VMI_GetFieldModifiers(JNIEnv *env, jclass clazz, jfieldID field, + jint *modifiersPtr); + +JNIEXPORT vmiError JNICALL +VMI_GetThrownExceptions(JNIEnv *env, jclass clazz, jmethodID method, + jint *exceptionCountPtr, jclass **exceptionsPtr); + +JNIEXPORT vmiError JNICALL +VMI_IsMethodNative(JNIEnv *env, jclass clazz, jmethodID method, + jboolean *isNativePtr); + +#endif |