mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-31 11:50:57 +08:00
SharedLibLoader.java: New class.
* 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. From-SVN: r45885
This commit is contained in:
parent
793e95585c
commit
8107bcf9f3
@ -1,3 +1,11 @@
|
||||
2001-09-28 Per Bothner <per@bothner.com>
|
||||
|
||||
* 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.
|
||||
|
||||
2001-09-29 Jeff Sturm <jsturm@one-point.com>
|
||||
|
||||
* Makefile.am (libgcj_la_LDFLAGS): Added $(GCLIBS), $(ZLIBS).
|
||||
|
@ -1136,6 +1136,7 @@ gnu/gcj/protocol/jar/Connection.java \
|
||||
gnu/gcj/protocol/jar/Handler.java \
|
||||
gnu/gcj/runtime/FileDeleter.java \
|
||||
gnu/gcj/runtime/FirstThread.java \
|
||||
gnu/gcj/runtime/SharedLibLoader.java \
|
||||
gnu/gcj/runtime/VMClassLoader.java \
|
||||
gnu/java/io/ClassLoaderObjectInputStream.java \
|
||||
gnu/java/io/NullOutputStream.java \
|
||||
@ -1491,6 +1492,7 @@ gnu/gcj/io/natSimpleSHSStream.cc \
|
||||
gnu/gcj/io/shs.cc \
|
||||
gnu/gcj/protocol/core/natCoreInputStream.cc \
|
||||
gnu/gcj/runtime/natFirstThread.cc \
|
||||
gnu/gcj/runtime/natSharedLibLoader.cc \
|
||||
java/io/natFile.cc \
|
||||
java/io/natFileDescriptor.cc \
|
||||
java/io/natObjectInputStream.cc \
|
||||
|
1170
libjava/Makefile.in
1170
libjava/Makefile.in
File diff suppressed because one or more lines are too long
1079
libjava/configure
vendored
1079
libjava/configure
vendored
File diff suppressed because it is too large
Load Diff
@ -540,6 +540,8 @@ else
|
||||
AC_MSG_ERROR([memcpy is required])
|
||||
fi
|
||||
|
||||
AC_CHECK_LIB(dl, dlopen, [AC_DEFINE(HAVE_DLOPEN)])
|
||||
|
||||
# Some library-finding code we stole from Tcl.
|
||||
#--------------------------------------------------------------------
|
||||
# Check for the existence of the -lsocket and -lnsl libraries.
|
||||
|
75
libjava/gnu/gcj/runtime/SharedLibLoader.java
Normal file
75
libjava/gnu/gcj/runtime/SharedLibLoader.java
Normal file
@ -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);
|
||||
}
|
75
libjava/gnu/gcj/runtime/natSharedLibLoader.cc
Normal file
75
libjava/gnu/gcj/runtime/natSharedLibLoader.cc
Normal file
@ -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
|
||||
}
|
@ -148,6 +148,8 @@
|
||||
/* Define if you have dladdr() */
|
||||
#undef HAVE_DLADDR
|
||||
|
||||
/* Define if yo have dlopen(). */
|
||||
#undef HAVE_DLOPEN
|
||||
|
||||
/* Define if getuid() and friends are missing. */
|
||||
#undef NO_GETUID
|
||||
|
Loading…
x
Reference in New Issue
Block a user