summaryrefslogtreecommitdiff
path: root/libjava/jni-libjvm.cc
diff options
context:
space:
mode:
authorfitzsim <fitzsim@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-20 19:25:32 +0000
committerfitzsim <fitzsim@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-20 19:25:32 +0000
commit10fd8185f15498797ae2ee1e6fc2722b5d47379c (patch)
tree0045d406677ce30008114e5f5c2fe72d66197382 /libjava/jni-libjvm.cc
parent545ee73275915a5217ba63b4fe90587a96d47496 (diff)
downloadgcc-10fd8185f15498797ae2ee1e6fc2722b5d47379c.tar.gz
2006-06-20 Thomas Fitzsimmons <fitzsim@redhat.com>
* Makefile.am (AM_CXXFLAGS): Define GCJ_VERSIONED_LIBDIR to "$(dbexecdir)". Build libjvm.la. * Makefile.in: Regenerate. * jni.cc (the_vm): Rename and export as ... (_Jv_the_vm): New exported symbol. (_Jv_JNI_AttachCurrentThread): Export. (_Jv_JNI_DestroyJavaVM): Replace the_vm references with _Jv_the_vm references. (_Jv_GetJavaVM): Likewise. (JNI_GetDefaultJavaVMInitArgs, JNI_CreateJavaVM, JNI_GetCreatedJavaVMs): Move to ... * jni-libjvm.cc: New file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114824 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/jni-libjvm.cc')
-rw-r--r--libjava/jni-libjvm.cc89
1 files changed, 89 insertions, 0 deletions
diff --git a/libjava/jni-libjvm.cc b/libjava/jni-libjvm.cc
new file mode 100644
index 00000000000..d0c3036538e
--- /dev/null
+++ b/libjava/jni-libjvm.cc
@@ -0,0 +1,89 @@
+// jni-libjvm.cc - an implementation of the JNI invocation API.
+
+/* Copyright (C) 2006 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <gcj/cni.h>
+#include <gcj/javaprims.h>
+#include <java-assert.h>
+#include <jvm.h>
+#include <jni.h>
+
+using namespace gcj;
+
+// Forward declarations.
+extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions;
+extern jint JNICALL _Jv_JNI_AttachCurrentThread (JavaVM *vm,
+ void **penv, void *args);
+extern JavaVM *_Jv_the_vm;
+
+jint JNICALL
+JNI_GetDefaultJavaVMInitArgs (void *args)
+{
+ jint version = * (jint *) args;
+ // Here we only support 1.2 and 1.4.
+ if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
+ return JNI_EVERSION;
+
+ JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
+ ia->version = JNI_VERSION_1_4;
+ ia->nOptions = 0;
+ ia->options = NULL;
+ ia->ignoreUnrecognized = true;
+
+ return 0;
+}
+
+jint JNICALL
+JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args)
+{
+ JvAssert (! _Jv_the_vm);
+
+ jint version = * (jint *) args;
+ // We only support 1.2 and 1.4.
+ if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
+ return JNI_EVERSION;
+
+ JvVMInitArgs* vm_args = reinterpret_cast<JvVMInitArgs *> (args);
+
+ jint result = _Jv_CreateJavaVM (vm_args);
+ if (result)
+ return result;
+
+ // FIXME: synchronize
+ JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
+ if (nvm == NULL)
+ return JNI_ERR;
+ nvm->functions = &_Jv_JNI_InvokeFunctions;
+
+ jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL);
+ if (r < 0)
+ return r;
+
+ _Jv_the_vm = nvm;
+ *vm = _Jv_the_vm;
+
+ return 0;
+}
+
+jint JNICALL
+JNI_GetCreatedJavaVMs (JavaVM **vm_buffer, jsize buf_len, jsize *n_vms)
+{
+ if (buf_len <= 0)
+ return JNI_ERR;
+
+ // We only support a single VM.
+ if (_Jv_the_vm != NULL)
+ {
+ vm_buffer[0] = _Jv_the_vm;
+ *n_vms = 1;
+ }
+ else
+ *n_vms = 0;
+ return 0;
+}