diff options
| author | bothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-09-29 19:16:27 +0000 |
|---|---|---|
| committer | bothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-09-29 19:16:27 +0000 |
| commit | 59b13f6a04c204a50ccbfa1cb00f1f731746322b (patch) | |
| tree | 3afc5859d7b6dac23868ad24de5cf88d0fceb4db /libjava/gnu | |
| parent | 759d75c321eba9440946d84e762a9a76a07109ec (diff) | |
| download | ppe42-gcc-59b13f6a04c204a50ccbfa1cb00f1f731746322b.tar.gz ppe42-gcc-59b13f6a04c204a50ccbfa1cb00f1f731746322b.zip | |
* gnu/gcj/runtime/SharedLibLoader.java: New class.
* gnu/gcj/runtime/natSharedLibLoader.cc: Native methods.
* Makefile.am: Update accordingly.
* configure.in: Add AC_CHECK_LIB for dlopen.
* include/config.h.in: Add HAVE_DLOPEN.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45885 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/gnu')
| -rw-r--r-- | libjava/gnu/gcj/runtime/SharedLibLoader.java | 75 | ||||
| -rw-r--r-- | libjava/gnu/gcj/runtime/natSharedLibLoader.cc | 75 |
2 files changed, 150 insertions, 0 deletions
diff --git a/libjava/gnu/gcj/runtime/SharedLibLoader.java b/libjava/gnu/gcj/runtime/SharedLibLoader.java new file mode 100644 index 00000000000..ac2f72d4b64 --- /dev/null +++ b/libjava/gnu/gcj/runtime/SharedLibLoader.java @@ -0,0 +1,75 @@ +/* Copyright (C) 2001 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. */ + +package gnu.gcj.runtime; +import java.util.Hashtable; + +/** + * A ClassLoader backed by a gcj-compiled shared library. + * @author Per Bothner <per@bothner.com>, Brainfood Inc. + */ + +public class SharedLibLoader extends ClassLoader +{ + public native void finalize (); + + /** Called during dlopen's processing of the init section. */ + void registerClass(String name, Class cls) + { + classMap.put(name, cls); + } + + /** Load a shared library, and associate a ClassLoader with it. + * @param libname named of shared library (passed to dlopen) + * @param parent the parent ClassLoader + * @parem flags passed to dlopen + */ + public SharedLibLoader(String libname, ClassLoader parent, int flags) + { + super(parent); + init(libname, flags); + } + + + /** Load a shared library, and asociate a ClassLoader with it. + * @param libname named of shared library (passed to dlopen) + */ + public SharedLibLoader(String libname) + { + super(getSystemClassLoader()); + init(libname, 0); + } + + void init(String libname, int flags) + { + init(libname.getBytes(), flags); + } + + native void init(byte[] libname, int flags); + + public Class loadClass(String name) + throws ClassNotFoundException + { + return super.loadClass(name); + } + + public Class findClass(String name) + throws ClassNotFoundException + { + Object cls = classMap.get(name); + if (cls == null) + throw new ClassNotFoundException(name); + return (Class) cls; + } + + /** The handle returned by dlopen. */ + gnu.gcj.RawData handler; + + /** Map classnames to Classes. */ + Hashtable classMap = new Hashtable(20); +} diff --git a/libjava/gnu/gcj/runtime/natSharedLibLoader.cc b/libjava/gnu/gcj/runtime/natSharedLibLoader.cc new file mode 100644 index 00000000000..a5e9738b255 --- /dev/null +++ b/libjava/gnu/gcj/runtime/natSharedLibLoader.cc @@ -0,0 +1,75 @@ +// natSharedLibLoader.cc - Implementation of FirstThread native methods. + +/* Copyright (C) 2001 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 <config.h> + +#include <gcj/cni.h> +#include <gnu/gcj/runtime/SharedLibLoader.h> +#include <dlfcn.h> +#include <java/io/IOException.h> +#include <java/lang/UnsupportedOperationException.h> + +#ifdef HAVE_DLOPEN +/* Only used during dlopen, while having a lock on Class.class. */ +static gnu::gcj::runtime::SharedLibLoader* curLoader; + +typedef void (*ClassHookFunc) (jclass); + +static void +::register_hook(jclass cls) +{ + curLoader->registerClass(cls->getName(), cls); +} + +struct SharedLibDummy +{ + ClassHookFunc saved; + SharedLibDummy() + { + saved = _Jv_RegisterClassHook; + } + ~SharedLibDummy() + { + _Jv_RegisterClassHook = saved; + curLoader = NULL; + } +}; +#endif + +void +gnu::gcj::runtime::SharedLibLoader::init(jbyteArray libname, jint flags) +{ +#ifdef HAVE_DLOPEN + char *lname = (char*) elements(libname); + if (flags==0) + flags = RTLD_LAZY; + JvSynchronize dummy1(&java::lang::Class::class$); + SharedLibDummy dummy2; + curLoader = this; + _Jv_RegisterClassHook = ::register_hook; + void *h = dlopen(lname, flags); + if (h == NULL) + { + const char *msg = dlerror(); + } + handler = (gnu::gcj::RawData*) h; +#else + const char *msg = "ShareedLibLoader is not supported on this platform"; + throw new java::lang::UnsupportedOperationException(JvNewStringLatin1(msg)); +#endif +} + +void +gnu::gcj::runtime::SharedLibLoader::finalize() +{ +#ifdef HAVE_DLOPEN + dlclose (handler); +#endif +} |

