Runtime.java (loadLibraryInternal): Declare.

* java/lang/Runtime.java (loadLibraryInternal): Declare.
	* java/lang/natClassLoader.cc (_Jv_FindClass): Removed dead copy.
	(_Jv_FindClassInCache): Likewise.
	(_Jv_FindClass): Don't conditionalize body on INTERPRETER.
	(findSystemClass): Try to load class from compiled module.
	Include Runtime.h.
	* java/lang/natRuntime.cc (load): Use UTF-8 copy of filename.
	(loadLibrary): Likewise.
	(lt_preloaded_symbols): Define.
	(loadLibraryInternal): New method.
	* include/config.h.in: Rebuilt.
	* acconfig.h (USE_LTDL): Added.
	* Makefile.am (SUBDIRS): Added $(DIRLTDL).
	(INCLUDES): Added $(INCLTDL).b
	(libgcj_la_DEPENDENCIES): Added $(LIBLTDL).
	(libgcj_la_LIBADD): Likewise.
	* aclocal.m4, configure: Rebuilt.
	* configure.in: Added libltdl support.

From-SVN: r31472
This commit is contained in:
Tom Tromey 2000-01-17 19:22:20 +00:00 committed by Tom Tromey
parent 06f5673716
commit 7af8555855
14 changed files with 539 additions and 901 deletions

View file

@ -1,6 +1,6 @@
// Runtime.java - Runtime class.
/* Copyright (C) 1998, 1999 Cygnus Solutions
/* Copyright (C) 1998, 1999, 2000 Cygnus Solutions
This file is part of libgcj.
@ -97,6 +97,12 @@ public class Runtime
public native void load (String pathname);
public native void loadLibrary (String libname);
// This is a helper function for the ClassLoader which can load
// compiled libraries. Returns true if library (which is just the
// base name -- path searching is done by this function) was loaded,
// false otherwise.
native boolean loadLibraryInternal (String libname);
public native void runFinalization ();
// This method is static in JDK 1.1, but isn't listed as static in

View file

@ -34,6 +34,7 @@ details. */
#include <java/lang/ClassCircularityError.h>
#include <java/lang/IncompatibleClassChangeError.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/Runtime.h>
#define CloneableClass _CL_Q34java4lang9Cloneable
extern java::lang::Class CloneableClass;
@ -193,7 +194,35 @@ java::lang::ClassLoader::markClassErrorState0 (java::lang::Class *klass)
jclass
gnu::gcj::runtime::VMClassLoader::findSystemClass (jstring name)
{
return _Jv_FindClassInCache (_Jv_makeUtf8Const (name), 0);
_Jv_Utf8Const *name_u = _Jv_makeUtf8Const (name);
jclass klass = _Jv_FindClassInCache (name_u, 0);
if (! klass)
{
// Turn `gnu.pkg.quux' into `gnu-pkg-quux'. Then search for a
// module named (eg, on Linux) `gnu-pkg-quux.so', followed by
// `gnu-pkg.so' and `gnu.so'. If loading one of these causes
// the class to appear in the cache, then use it.
jstring so_base_name = name->replace ('.', '-');
while (! klass && so_base_name && so_base_name->length() > 0)
{
using namespace ::java::lang;
Runtime *rt = Runtime::getRuntime();
jboolean loaded = rt->loadLibraryInternal (so_base_name);
jint nd = so_base_name->lastIndexOf ('-');
if (nd == -1)
so_base_name = NULL;
else
so_base_name = so_base_name->substring (0, nd);
if (loaded)
klass = _Jv_FindClassInCache (name_u, 0);
}
}
return klass;
}
jclass
@ -403,31 +432,11 @@ _Jv_RegisterClass (jclass klass)
_Jv_RegisterClasses (classes);
}
#if 0
// NOTE: this one is out of date with the new loader stuff...
jclass
_Jv_FindClassInCache (jstring name, java::lang::ClassLoader *loader)
{
JvSynchronize sync (&ClassClass);
jint hash = name->hashCode();
jclass klass = loaded_classes[(_Jv_ushort) hash % HASH_LEN];
for ( ; klass; klass = klass->next)
{
if (loader == klass->loader
&& _Jv_equal (klass->name, name, hash))
break;
}
_Jv_MonitorExit (&ClassClass);
return klass;
}
#endif
jclass _Jv_FindClass (_Jv_Utf8Const *name,
java::lang::ClassLoader *loader)
_Jv_FindClass (_Jv_Utf8Const *name, java::lang::ClassLoader *loader)
{
jclass klass = _Jv_FindClassInCache (name, loader);
#ifdef INTERPRETER
if (! klass)
{
jstring sname = _Jv_NewStringUTF (name->data);
@ -466,44 +475,10 @@ jclass _Jv_FindClass (_Jv_Utf8Const *name,
// we're loading, so that they can refer to themselves.
_Jv_WaitForState (klass, JV_STATE_LOADED);
}
#endif
return klass;
}
#if 0
// NOTE: this one is out of date with the new class loader stuff...
jclass
_Jv_FindClass (jstring name, java::lang::ClassLoader *loader)
{
jclass klass = _Jv_FindClassInCache (name, loader);
if (! klass)
{
if (loader)
{
klass = loader->loadClass(name);
}
else
{
// jmspec 5.3.1.2
// delegate to the system loader
klass = java::lang::ClassLoader::system.loadClass (sname);
// register that we're an initiating loader
if (klass)
_Jv_RegisterInitiatingLoader (klass, 0);
}
}
else
{
_Jv_WaitForState (klass, JV_STATE_LOADED);
}
return klass;
}
#endif
jclass
_Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
java::lang::ClassLoader *loader)

View file

@ -1,6 +1,6 @@
// natRuntime.cc - Implementation of native side of Runtime class.
/* Copyright (C) 1998, 1999 Cygnus Solutions
/* Copyright (C) 1998, 1999, 2000 Cygnus Solutions
This file is part of libgcj.
@ -20,6 +20,10 @@ details. */
#ifdef USE_LTDL
#include <ltdl.h>
/* FIXME: we don't always need this. The next libtool will let us use
AC_LTDL_PREOPEN to see if we do. */
const lt_dlsymlist lt_preloaded_symbols[1] = { { 0, 0 } };
#endif
void
@ -56,8 +60,12 @@ java::lang::Runtime::load (jstring path)
checkLink (path);
using namespace java::lang;
#ifdef USE_LTDL
jint len = _Jv_GetStringUTFLength (path);
char buf[len + 1];
jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
buf[total] = '\0';
// FIXME: make sure path is absolute.
lt_dlhandle h = lt_dlopen (FIXME);
lt_dlhandle h = lt_dlopen (buf);
if (h == NULL)
{
const char *msg = lt_dlerror ();
@ -76,8 +84,12 @@ java::lang::Runtime::loadLibrary (jstring lib)
checkLink (lib);
using namespace java::lang;
#ifdef USE_LTDL
jint len = _Jv_GetStringUTFLength (lib);
char buf[len + 1];
jsize total = JvGetStringUTFRegion (lib, 0, lib->length(), buf);
buf[total] = '\0';
// FIXME: make sure path is absolute.
lt_dlhandle h = lt_dlopenext (FIXME);
lt_dlhandle h = lt_dlopenext (buf);
if (h == NULL)
{
const char *msg = lt_dlerror ();
@ -89,6 +101,24 @@ java::lang::Runtime::loadLibrary (jstring lib)
#endif /* USE_LTDL */
}
jboolean
java::lang::Runtime::loadLibraryInternal (jstring lib)
{
JvSynchronize sync (this);
using namespace java::lang;
#ifdef USE_LTDL
jint len = _Jv_GetStringUTFLength (lib);
char buf[len + 1];
jsize total = JvGetStringUTFRegion (lib, 0, lib->length(), buf);
buf[total] = '\0';
// FIXME: make sure path is absolute.
lt_dlhandle h = lt_dlopenext (buf);
return h != NULL;
#else
return false;
#endif /* USE_LTDL */
}
void
java::lang::Runtime::init (void)
{