The JNI invocation API is specified here:
http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/invocation.html#wp9502

See also JNI 1.2 enhancements:
http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html#invo

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/vm/jni.h   |   22 ++++++++++++++++++++
 vm/jni-interface.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 78 insertions(+), 1 deletions(-)

diff --git a/include/vm/jni.h b/include/vm/jni.h
index 9fbb1a3..3b8acea 100644
--- a/include/vm/jni.h
+++ b/include/vm/jni.h
@@ -4,6 +4,22 @@
 #include <stdbool.h>
 #include <stdint.h>
 
+/* Version numbers.  */
+#define JNI_VERSION_1_1 0x00010001
+#define JNI_VERSION_1_2 0x00010002
+#define JNI_VERSION_1_4 0x00010004
+#define JNI_VERSION_1_6 0x00010006
+
+/* Used when releasing array elements.  */
+#define JNI_COMMIT 1
+#define JNI_ABORT  2
+
+/* Error codes */
+#define JNI_OK            0
+#define JNI_ERR          (-1)
+#define JNI_EDETACHED    (-2)
+#define JNI_EVERSION     (-3)
+
 #define JNI_FALSE  0
 #define JNI_TRUE   1
 
@@ -47,6 +63,12 @@ struct vm_jni_env {
        void **jni_table;
 };
 
+struct java_vm {
+       void **jni_invoke_interface_table;
+};
+
+typedef struct java_vm JavaVM;
+
 void vm_jni_init(void);
 struct vm_jni_env *vm_jni_get_jni_env(void);
 int vm_jni_load_object(const char *name);
diff --git a/vm/jni-interface.c b/vm/jni-interface.c
index 81b95ab..59391e9 100644
--- a/vm/jni-interface.c
+++ b/vm/jni-interface.c
@@ -52,6 +52,53 @@
        if (!vm_object_is_instance_of((x), vm_java_lang_Class))         \
                return NULL;
 
+static void vm_jni_destroy_java_vm(void) {
+       NOT_IMPLEMENTED;
+}
+
+static void vm_jni_attach_current_thread(void) {
+       NOT_IMPLEMENTED;
+}
+
+static void vm_jni_detach_current_thread(void) {
+       NOT_IMPLEMENTED;
+}
+
+static jint vm_jni_get_env(JavaVM *vm, void **env, jint version) {
+       enter_vm_from_jni();
+
+       /* XXX: We are actually supporting only a little part of 1.2 yet. */
+       if (version > JNI_VERSION_1_2) {
+               *env = NULL;
+               return JNI_EVERSION;
+       }
+
+       *env = vm_jni_get_jni_env();
+       return JNI_OK;
+}
+
+static void vm_jni_attach_current_thread_as_daemon(void) {
+       NOT_IMPLEMENTED;
+}
+
+void *vm_jni_invoke_interface[] = {
+       NULL,
+       NULL,
+       NULL,
+
+       vm_jni_destroy_java_vm,
+       vm_jni_attach_current_thread,
+       vm_jni_detach_current_thread,
+
+       /* JNI_VERSION_1_2 */
+       vm_jni_get_env,
+       vm_jni_attach_current_thread_as_daemon,
+};
+
+struct java_vm vm_jni_default_java_vm = {
+       .jni_invoke_interface_table = vm_jni_invoke_interface,
+};
+
 static jclass
 vm_jni_find_class(struct vm_jni_env *env, const char *name)
 {
@@ -361,6 +408,14 @@ static void vm_jni_delete_global_ref(struct vm_jni_env 
*env, jobject obj)
        NOT_IMPLEMENTED;
 }
 
+static jint vm_jni_get_java_vm(struct vm_jni_env *env, struct java_vm **vm)
+{
+       enter_vm_from_jni();
+
+       *vm = &vm_jni_default_java_vm;
+       return 0;
+}
+
 /*
  * The JNI native interface table.
  * See: http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/functions.html
@@ -672,7 +727,7 @@ void *vm_jni_native_interface[] = {
        NULL, /* UnregisterNatives */
        NULL, /* MonitorEnter */
        NULL, /* MonitorExit */
-       NULL, /* GetJavaVM */
+       vm_jni_get_java_vm,
 
        /* 220 */
        NULL, /* GetJavaVM */
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to