This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
RFC: libjvm.so
- From: Thomas Fitzsimmons <fitzsim at redhat dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Mon, 19 Jun 2006 19:44:41 -0400
- Subject: RFC: libjvm.so
Hi,
This patch introduces a new library, libjvm.so, that implements the JNI
Invocation API. Binaries that want to embed a VM, such as the GNU Classpath
tool wrappers, can link to this library.
This patch adds the necessary build logic, moves the symbols to a separate file
and exports other symbols that libjvm.so needs from libgcj.so. In order to make
our libjvm.so binary compatible with other implementations, we'll need a
libjvm.so with a SONAME of "libjvm.so" instead of the current "libjvm.so.7".
But I'll do that as a separate patch since Bryce is working on a solution to the
same problem for libgcj-bc.so.
Tom
2006-06-19 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.
Index: jni-libjvm.cc
===================================================================
--- jni-libjvm.cc (revision 0)
+++ jni-libjvm.cc (revision 0)
@@ -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;
+}
Index: jni.cc
===================================================================
--- jni.cc (revision 114777)
+++ jni.cc (working copy)
@@ -107,7 +107,7 @@
static java::util::IdentityHashMap *global_ref_table;
// The only VM.
-static JavaVM *the_vm;
+JavaVM *_Jv_the_vm;
#ifdef ENABLE_JVMPI
// The only JVMPI interface description.
@@ -2408,7 +2408,7 @@
}
// This is the one actually used by JNI.
-static jint JNICALL
+jint JNICALL
_Jv_JNI_AttachCurrentThread (JavaVM *vm, void **penv, void *args)
{
return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, false);
@@ -2424,7 +2424,7 @@
static jint JNICALL
_Jv_JNI_DestroyJavaVM (JavaVM *vm)
{
- JvAssert (the_vm && vm == the_vm);
+ JvAssert (_Jv_the_vm && vm == _Jv_the_vm);
union
{
@@ -2496,82 +2496,16 @@
return 0;
}
-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 (! 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;
-
- the_vm = nvm;
- *vm = 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 (the_vm != NULL)
- {
- vm_buffer[0] = the_vm;
- *n_vms = 1;
- }
- else
- *n_vms = 0;
- return 0;
-}
-
JavaVM *
_Jv_GetJavaVM ()
{
// FIXME: synchronize
- if (! the_vm)
+ if (! _Jv_the_vm)
{
JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
if (nvm != NULL)
nvm->functions = &_Jv_JNI_InvokeFunctions;
- the_vm = nvm;
+ _Jv_the_vm = nvm;
}
// If this is a Java thread, we want to make sure it has an
@@ -2579,10 +2513,10 @@
if (_Jv_ThreadCurrent () != NULL)
{
void *ignore;
- _Jv_JNI_AttachCurrentThread (the_vm, &ignore, NULL);
+ _Jv_JNI_AttachCurrentThread (_Jv_the_vm, &ignore, NULL);
}
- return the_vm;
+ return _Jv_the_vm;
}
static jint JNICALL
Index: Makefile.am
===================================================================
--- Makefile.am (revision 114777)
+++ Makefile.am (working copy)
@@ -40,6 +40,8 @@
toolexeclib_LTLIBRARIES += lib-gnu-awt-xlib.la
endif
+dbexec_LTLIBRARIES = libjvm.la
+
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libgcj.pc
@@ -122,7 +124,7 @@
-DBOOT_CLASS_PATH="\"$(BOOT_CLASS_PATH_DIR)\"" \
-DJAVA_EXT_DIRS="\"$(jardir)/ext\"" \
-DGCJ_ENDORSED_DIRS="\"$(jardir)/gcj-endorsed\"" \
- -DGCJ_VERSIONED_LIBDIR="\"$(libdir)/gcj-$(gcc_version)\"" \
+ -DGCJ_VERSIONED_LIBDIR="\"$(dbexecdir)\"" \
-DPATH_SEPARATOR="\"$(CLASSPATH_SEPARATOR)\"" \
-DLIBGCJ_DEFAULT_DATABASE="\"$(dbexecdir)/$(db_name)\"" \
-DLIBGCJ_DEFAULT_DATABASE_PATH_TAIL="\"$(db_pathtail)\"" \
@@ -232,6 +234,14 @@
$(LIBLTDL) $(libgcj_la_LIBADD)
libgcj_la_LINK = $(LIBLINK)
+## libjvm.so
+libjvm_la_SOURCES = jni-libjvm.cc
+libjvm_la_DEPENDENCIES = libgcj.la libgcj.spec
+## See jv_convert_LDADD.
+libjvm_la_LIBADD = -L$(here)/.libs libgcj.la
+## The mysterious backslash in the grep pattern is consumed by make.
+libjvm_la_LDFLAGS = -rpath $(toolexeclibdir) \
+ -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(LIBGCJ_LD_SYMBOLIC)
## The .db file. This rule is only used for native builds, so it is
## safe to invoke gcj-dbtool.
@@ -887,6 +897,7 @@
$(libgcj_la_OBJECTS) $(gcj_dbtool_OBJECTS) $(xlib_nat_files): headers.stamp
$(libgij_la_OBJECTS): headers.stamp
+$(libjvm_la_OBJECTS): headers.stamp
## ################################################################