(AC_CHECK_ENABLE_DL): Added.
* m4/ltdl.m4: Removed.
* m4/dl.m4: New file.
* src/cacao/cacao.c [ENABLE_LIBJVM] (ltdl.h): Removed.
(vmcore/system.h): Added.
(LIBJVM_NAME): New define.
(main): Use system_dl* functions.
* src/native/native.c: Replaced ltdl stuff with sytem_dl* stuff.
* src/native/native.h (NATIVE_LIBRARY_PREFIX): New define.
(NATIVE_LIBRARY_SUFFIX): Likewise.
* src/native/vm/gnuclasspath/java_lang_VMRuntime.c (mapLibraryName):
Use NATIVE_LIBRARY_* defines.
* src/vmcore/system.h [HAVE_DLFCN_H] (dlfcn.h): Added.
(system_dlclose): New function.
(system_dlerror): Likewise.
(system_dlopen): Likewise.
(system_dlsym): Likewise.
dnl Checks for libraries (NOTE: Should be done before function checks,
dnl as some functions may be in libraries we check for).
-AC_CHECK_LIB(dl, dlopen,,)
dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_SUBST(CACAO_LIBDIR)
-AC_CHECK_ENABLE_LTDL
-
+AC_CHECK_ENABLE_DL
AC_CHECK_ENABLE_JAVA
AC_CHECK_ENABLE_JIT
--- /dev/null
+dnl m4/dl.m4
+dnl
+dnl Copyright (C) 2008
+dnl CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+dnl
+dnl This file is part of CACAO.
+dnl
+dnl This program is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU General Public License as
+dnl published by the Free Software Foundation; either version 2, or (at
+dnl your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful, but
+dnl WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+dnl General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+dnl 02110-1301, USA.
+
+
+dnl check if dynamic library loading should be used
+
+AC_DEFUN([AC_CHECK_ENABLE_DL],[
+AC_MSG_CHECKING(whether to support dynamic library loading)
+AC_ARG_ENABLE([dl],
+ [AS_HELP_STRING(--disable-dl,disable dynamic library loading (needs libdl) [[default=enabled]])],
+ [case "${enableval}" in
+ no) ENABLE_DL=no;;
+ *) ENABLE_DL=yes;;
+ esac],
+ [ENABLE_DL=yes])
+AC_MSG_RESULT(${ENABLE_DL})
+
+if test x"${ENABLE_DL}" = "xyes"; then
+ AC_CHECK_HEADERS([dlfcn.h],, [AC_MSG_ERROR(cannot find dlfcn.h)])
+ AC_CHECK_LIB([dl], [dlopen],, [AC_MSG_ERROR(cannot find libdl)])
+ AC_CHECK_FUNCS([dlclose])
+ AC_CHECK_FUNCS([dlerror])
+ AC_CHECK_FUNCS([dlopen])
+ AC_CHECK_FUNCS([dlsym])
+ AC_DEFINE([ENABLE_DL], 1, [Enable dynamic library loading.])
+fi
+])
+++ /dev/null
-dnl m4/ltdl.m4
-dnl
-dnl Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
-dnl C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-dnl E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-dnl J. Wenninger, Institut f. Computersprachen - TU Wien
-dnl
-dnl This file is part of CACAO.
-dnl
-dnl This program is free software; you can redistribute it and/or
-dnl modify it under the terms of the GNU General Public License as
-dnl published by the Free Software Foundation; either version 2, or (at
-dnl your option) any later version.
-dnl
-dnl This program is distributed in the hope that it will be useful, but
-dnl WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-dnl General Public License for more details.
-dnl
-dnl You should have received a copy of the GNU General Public License
-dnl along with this program; if not, write to the Free Software
-dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-dnl 02110-1301, USA.
-
-
-dnl check if ltdl should be used
-
-AC_DEFUN([AC_CHECK_ENABLE_LTDL],[
-AC_MSG_CHECKING(whether ltdl should be used)
-AC_ARG_ENABLE([ltdl],
- [AS_HELP_STRING(--disable-ltdl,disable ltdl support [[default=enabled]])],
- [case "${enableval}" in
- no)
- ENABLE_LTDL=no
- ;;
- *)
- ENABLE_LTDL=yes
- ;;
- esac],
- [ENABLE_LTDL=yes])
-AC_MSG_RESULT(${ENABLE_LTDL})
-
-if test x"${ENABLE_LTDL}" = "xyes"; then
- dnl we need this check for --enable-staticvm, otherwise ltdl can't find dlopen
- if test x"${ENABLE_STATICVM}" = "xyes"; then
- AC_CHECK_LIB(dl, dlopen,, [AC_MSG_ERROR(cannot find libdl)])
- fi
-
- AC_CHECK_HEADERS([ltdl.h],, [AC_MSG_ERROR(cannot find ltdl.h)])
- AC_CHECK_LIB(ltdl, lt_dlopen,, [AC_MSG_ERROR(cannot find libltdl)])
- AC_DEFINE([ENABLE_LTDL], 1, [use ltdl])
-fi
-
-AM_CONDITIONAL([ENABLE_LTDL], test x"${ENABLE_LTDL}" = "xyes")
-])
#include <assert.h>
-#if defined(ENABLE_LIBJVM)
-# include <ltdl.h>
-#endif
-
#if defined(ENABLE_JRE_LAYOUT)
# include <errno.h>
# include <libgen.h>
#include "vm/types.h"
#include "native/jni.h"
+#include "native/native.h"
#if defined(ENABLE_JVMTI)
# include "native/jvmti/jvmti.h"
# include "threads/mutex.h"
#endif
+#include "vmcore/system.h"
+
#include "vm/vm.h"
+/* Defines. *******************************************************************/
+
+#define LIBJVM_NAME NATIVE_LIBRARY_PREFIX"jvm"NATIVE_LIBRARY_SUFFIX
+
+
/* forward declarations *******************************************************/
static JavaVMInitArgs *cacao_options_prepare(int argc, char **argv);
int main(int argc, char **argv)
{
#if defined(ENABLE_LIBJVM)
- char *path;
+ char* path;
+
+# if defined(ENABLE_JRE_LAYOUT)
+ int len;
+# endif
#endif
#if defined(ENABLE_LIBJVM)
/* Variables for JNI_CreateJavaVM dlopen call. */
- lt_dlhandle libjvm_handle;
- lt_ptr libjvm_vm_createjvm;
- lt_ptr libjvm_vm_run;
- const char *lterror;
+ void* libjvm_handle;
+ void* libjvm_vm_createjvm;
+ void* libjvm_vm_run;
+ const char* lterror;
bool (*vm_createjvm)(JavaVM **, void **, void *);
void (*vm_run)(JavaVM *, JavaVMInitArgs *);
/* get the path of the current executable */
path = dirname(path);
+ len = strlen(path) + strlen("/../lib/"LIBJVM_NAME) + strlen("0");
- if ((strlen(path) + strlen("/../lib/libjvm") + strlen("0")) > 4096) {
+ if (len > 4096) {
fprintf(stderr, "main: libjvm name to long for buffer\n");
abort();
}
/* concatinate the library name */
- strcat(path, "/../lib/libjvm");
+ strcat(path, "/../lib/"LIBJVM_NAME);
# else
- path = CACAO_LIBDIR"/libjvm";
+ path = CACAO_LIBDIR"/"LIBJVM_NAME;
# endif
- if (lt_dlinit()) {
- fprintf(stderr, "main: lt_dlinit failed: %s\n", lt_dlerror());
- abort();
- }
-
/* First try to open where dlopen searches, e.g. LD_LIBRARY_PATH.
If not found, try the absolute path. */
- if (!(libjvm_handle = lt_dlopenext("libjvm"))) {
+ libjvm_handle = system_dlopen(LIBJVM_NAME, RTLD_LAZY);
+
+ if (libjvm_handle == NULL) {
/* save the error message */
- lterror = strdup(lt_dlerror());
+ lterror = strdup(system_dlerror());
+
+ libjvm_handle = system_dlopen(path, RTLD_LAZY);
- if (!(libjvm_handle = lt_dlopenext(path))) {
+ if (libjvm_handle == NULL) {
/* print the first error message too */
- fprintf(stderr, "main: lt_dlopenext failed: %s\n", lterror);
+ fprintf(stderr, "main: system_dlopen failed: %s\n", lterror);
/* and now the current one */
- fprintf(stderr, "main: lt_dlopenext failed: %s\n", lt_dlerror());
+ fprintf(stderr, "main: system_dlopen failed: %s\n",
+ system_dlerror());
abort();
}
free((void *) lterror);
}
- if (!(libjvm_vm_createjvm = lt_dlsym(libjvm_handle, "vm_createjvm"))) {
- fprintf(stderr, "main: lt_dlsym failed: %s\n", lt_dlerror());
+ libjvm_vm_createjvm = system_dlsym(libjvm_handle, "vm_createjvm");
+
+ if (libjvm_vm_createjvm == NULL) {
+ fprintf(stderr, "main: lt_dlsym failed: %s\n", system_dlerror());
abort();
}
#endif
#if defined(ENABLE_LIBJVM)
- if (!(libjvm_vm_run = lt_dlsym(libjvm_handle, "vm_run"))) {
- fprintf(stderr, "lt_dlsym failed: %s\n", lt_dlerror());
+ libjvm_vm_run = system_dlsym(libjvm_handle, "vm_run");
+
+ if (libjvm_vm_run == NULL) {
+ fprintf(stderr, "main: system_dlsym failed: %s\n", system_dlerror());
abort();
}
-/* src/native/native.c - table of native functions
+/* src/native/native.c - native library support
Copyright (C) 1996-2005, 2006, 2007, 2008
CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
#include <assert.h>
#include <ctype.h>
-#if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
-# include <ltdl.h>
-#endif
-
#include <stdint.h>
#include "vm/types.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/global.h"
+#include "vm/resolve.h"
#include "vm/stringlocal.h"
#include "vm/vm.h"
#include "vmcore/loader.h"
#include "vmcore/options.h"
-#include "vm/resolve.h"
+#include "vmcore/system.h"
#if defined(ENABLE_JVMTI)
#include "native/jvmti/cacaodbg.h"
static avl_tree_t *tree_native_methods;
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
static hashtable *hashtable_library;
#endif
{
TRACESUBSYSTEMINITIALIZATION("native_init");
-#if defined(ENABLE_LTDL)
- /* initialize libltdl */
-
- if (lt_dlinit())
- vm_abort("native_init: lt_dlinit failed: %s\n", lt_dlerror());
-
+#if defined(ENABLE_DL)
/* initialize library hashtable, 10 entries should be enough */
hashtable_library = NEW(hashtable);
utf *name;
utf *newname;
functionptr f;
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
classloader_t *cl;
hashtable_library_loader_entry *le;
hashtable_library_name_entry *ne;
f = NULL;
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
/* Get the classloader. */
cl = class_get_classloader(m->clazz);
ne = le->namelink;
while ((ne != NULL) && (f == NULL)) {
- f = (functionptr) (ptrint) lt_dlsym(ne->handle, name->text);
+ f = (functionptr) (ptrint) system_dlsym(ne->handle, name->text);
if (f == NULL)
- f = (functionptr) (ptrint) lt_dlsym(ne->handle, newname->text);
+ f = (functionptr) (ptrint) system_dlsym(ne->handle, newname->text);
ne = ne->hashlink;
}
*******************************************************************************/
-#if defined(ENABLE_LTDL)
-lt_dlhandle native_library_open(utf *filename)
+#if defined(ENABLE_DL)
+void* native_library_open(utf *filename)
{
- lt_dlhandle handle;
+ void* handle;
if (opt_verbosejni) {
printf("[Loading native library ");
/* try to open the library */
- handle = lt_dlopen(filename->text);
+ handle = system_dlopen(filename->text, RTLD_LAZY);
if (handle == NULL) {
if (opt_verbosejni)
if (opt_verbose) {
log_start();
- log_print("native_library_open: lt_dlopen failed: ");
- log_print(lt_dlerror());
+ log_print("native_library_open: system_dlopen failed: ");
+ log_print(dlerror());
log_finish();
}
*******************************************************************************/
-#if defined(ENABLE_LTDL)
-void native_library_close(lt_dlhandle handle)
+#if defined(ENABLE_DL)
+void native_library_close(void* handle)
{
int result;
/* Close the library. */
- result = lt_dlclose(handle);
+ result = system_dlclose(handle);
if (result != 0) {
if (opt_verbose) {
log_start();
- log_print("native_library_close: lt_dlclose failed: ");
- log_print(lt_dlerror());
+ log_print("native_library_close: system_dlclose failed: ");
+ log_print(dlerror());
log_finish();
}
}
*******************************************************************************/
-#if defined(ENABLE_LTDL)
-void native_library_add(utf *filename, classloader_t *loader, lt_dlhandle handle)
+#if defined(ENABLE_DL)
+void native_library_add(utf *filename, classloader_t *loader, void* handle)
{
hashtable_library_loader_entry *le;
hashtable_library_name_entry *ne; /* library name */
*******************************************************************************/
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
hashtable_library_name_entry *native_library_find(utf *filename,
classloader_t *loader)
{
int native_library_load(JNIEnv *env, utf *name, classloader_t *cl)
{
-#if defined(ENABLE_LTDL)
- lt_dlhandle handle;
+#if defined(ENABLE_DL)
+ void* handle;
# if defined(ENABLE_JNI)
- lt_ptr onload;
- int32_t version;
+ void* onload;
+ int32_t version;
# endif
if (name == NULL) {
# if defined(ENABLE_JNI)
/* Resolve JNI_OnLoad function. */
- onload = lt_dlsym(handle, "JNI_OnLoad");
+ onload = system_dlsym(handle, "JNI_OnLoad");
if (onload != NULL) {
JNIEXPORT int32_t (JNICALL *JNI_OnLoad) (JavaVM *, void *);
loaded. */
if ((version != JNI_VERSION_1_2) && (version != JNI_VERSION_1_4)) {
- lt_dlclose(handle);
+ system_dlclose(handle);
return 0;
}
}
-/* src/native/native.h - table of native functions
+/* src/native/native.h - native library support
Copyright (C) 1996-2005, 2006, 2007, 2008
CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
#include "config.h"
-#if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
-# include <ltdl.h>
-#endif
-
#include <stdint.h>
#include "native/jni.h"
#include "vmcore/class.h"
#include "vmcore/loader.h"
#include "vmcore/method.h"
+#include "vmcore/system.h"
#include "vmcore/utf8.h"
#define NATIVE_METHODS_COUNT sizeof(methods) / sizeof(JNINativeMethod)
+#define NATIVE_LIBRARY_PREFIX "lib"
+
+#if defined(__DARWIN__)
+# define NATIVE_LIBRARY_SUFFIX ".dylib"
+#else
+# define NATIVE_LIBRARY_SUFFIX ".so"
+#endif
+
+
/* native_methods_node_t ******************************************************/
typedef struct native_methods_node_t native_methods_node_t;
/* hashtable_library_loader_entry *********************************************/
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
typedef struct hashtable_library_name_entry hashtable_library_name_entry;
/* hashtable_library_name_entry ***********************************************/
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
struct hashtable_library_name_entry {
utf *name; /* library name */
- lt_dlhandle handle; /* libtool library handle */
+ void* handle; /* libtool library handle */
hashtable_library_name_entry *hashlink; /* link for external chaining */
};
#endif
void native_method_register(utf *classname, const JNINativeMethod *methods, int32_t count);
functionptr native_method_resolve(methodinfo *m);
-#if defined(ENABLE_LTDL)
-lt_dlhandle native_library_open(utf *filename);
-void native_library_close(lt_dlhandle handle);
-void native_library_add(utf *filename, classloader_t *loader, lt_dlhandle handle);
+#if defined(ENABLE_DL)
+void* native_library_open(utf *filename);
+void native_library_close(void* handle);
+void native_library_add(utf *filename, classloader_t *loader, void *handle);
hashtable_library_name_entry *native_library_find(utf *filename, classloader_t *loader);
int native_library_load(JNIEnv *env, utf *name, classloader_t *cl);
#endif
/* calculate length of library name */
- buffer_len = strlen("lib");
-
- buffer_len += utf_bytes(u);
-
-#if defined(__DARWIN__)
- buffer_len += strlen(".dylib");
-#else
- buffer_len += strlen(".so");
-#endif
-
- buffer_len += strlen("0");
+ buffer_len =
+ strlen(NATIVE_LIBRARY_PREFIX) +
+ utf_bytes(u) +
+ strlen(NATIVE_LIBRARY_SUFFIX) +
+ strlen("0");
DMARKER;
/* generate library name */
- strcpy(buffer, "lib");
+ strcpy(buffer, NATIVE_LIBRARY_PREFIX);
utf_cat(buffer, u);
-
-#if defined(__DARWIN__)
- strcat(buffer, ".dylib");
-#else
- strcat(buffer, ".so");
-#endif
+ strcat(buffer, NATIVE_LIBRARY_SUFFIX);
o = javastring_new_from_utf_string(buffer);
# include <dirent.h>
#endif
+#if defined(HAVE_DLFCN_H)
+# include <dlfcn.h>
+#endif
+
#if defined(HAVE_FCNTL_H)
# include <fcntl.h>
#endif
}
#endif
+inline static int system_dlclose(void* handle)
+{
+#if defined(HAVE_DLCLOSE)
+ return dlclose(handle);
+#else
+# error dlclose not available
+#endif
+}
+
+inline static char* system_dlerror(void)
+{
+#if defined(HAVE_DLERROR)
+ return dlerror();
+#else
+# error dlerror not available
+#endif
+}
+
+inline static void* system_dlopen(const char* filename, int flag)
+{
+#if defined(HAVE_DLOPEN)
+ return dlopen(filename, flag);
+#else
+# error dlopen not available
+#endif
+}
+
+inline static void* system_dlsym(void* handle, const char* symbol)
+{
+#if defined(HAVE_DLSYM)
+ return dlsym(handle, symbol);
+#else
+# error dlsym not available
+#endif
+}
+
inline static FILE *system_fopen(const char *path, const char *mode)
{
#if defined(HAVE_FOPEN)