mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-01-19 00:05:14 +08:00
re PR libgcj/9125 (VMClassLoader should cache the result of Runtime.(internal)loadLibrary())
Fix for PR libgcj/9125: * gnu/gcj/runtime/natVMClassLoader.cc (findClass): Find Runtime object outside of loop. Respect lib_control setting. * gnu/gcj/runtime/VMClassLoader.java (tried_libraries): New field. (lib_control): New field. (LIB_FULL, LIB_CACHE, LIB_NEVER): New constants. (VMClassLoader): Initialize new field. From-SVN: r70600
This commit is contained in:
parent
9c6f74cd3f
commit
3f1923dcc1
@ -1,5 +1,14 @@
|
||||
2003-08-20 Tom Tromey <tromey@redhat.com>
|
||||
|
||||
Fix for PR libgcj/9125:
|
||||
* gnu/gcj/runtime/natVMClassLoader.cc (findClass): Find Runtime
|
||||
object outside of loop. Respect lib_control setting.
|
||||
* gnu/gcj/runtime/VMClassLoader.java (tried_libraries): New
|
||||
field.
|
||||
(lib_control): New field.
|
||||
(LIB_FULL, LIB_CACHE, LIB_NEVER): New constants.
|
||||
(VMClassLoader): Initialize new field.
|
||||
|
||||
* java/lang/ref/natReference.cc (finalize_referred_to_object):
|
||||
Set `list->reference' to DELETED_REFERENCE when removing dead
|
||||
object.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1999, 2001, 2002 Free Software Foundation
|
||||
/* Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation
|
||||
|
||||
This file is part of libgcj.
|
||||
|
||||
@ -12,6 +12,7 @@ package gnu.gcj.runtime;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.HashSet;
|
||||
import java.net.URL;
|
||||
|
||||
public final class VMClassLoader extends java.net.URLClassLoader
|
||||
@ -19,6 +20,20 @@ public final class VMClassLoader extends java.net.URLClassLoader
|
||||
private VMClassLoader ()
|
||||
{
|
||||
super (init());
|
||||
String p
|
||||
= System.getProperty ("gnu.gcj.runtime.VMClassLoader.library_control",
|
||||
"");
|
||||
if ("never".equals(p))
|
||||
lib_control = LIB_NEVER;
|
||||
else if ("cache".equals(p))
|
||||
lib_control = LIB_CACHE;
|
||||
else if ("full".equals(p))
|
||||
{
|
||||
// In case we ever want to change the default.
|
||||
lib_control = LIB_FULL;
|
||||
}
|
||||
else
|
||||
lib_control = LIB_FULL;
|
||||
}
|
||||
|
||||
private static URL[] init()
|
||||
@ -67,6 +82,17 @@ public final class VMClassLoader extends java.net.URLClassLoader
|
||||
protected native Class findClass(String name)
|
||||
throws java.lang.ClassNotFoundException;
|
||||
|
||||
// This keeps track of shared libraries we've already tried to load.
|
||||
private HashSet tried_libraries = new HashSet();
|
||||
|
||||
// Holds one of the LIB_* constants; used to determine how shared
|
||||
// library loads are done.
|
||||
private int lib_control;
|
||||
|
||||
// The only VMClassLoader that can exist.
|
||||
public static VMClassLoader instance = new VMClassLoader ();
|
||||
public static VMClassLoader instance = new VMClassLoader();
|
||||
|
||||
private static final int LIB_FULL = 0;
|
||||
private static final int LIB_CACHE = 1;
|
||||
private static final int LIB_NEVER = 2;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Native code for VMClassLoader
|
||||
|
||||
/* Copyright (C) 2002 Free Software Foundation
|
||||
/* Copyright (C) 2002, 2003 Free Software Foundation
|
||||
|
||||
This file is part of libgcj.
|
||||
|
||||
@ -18,6 +18,7 @@ details. */
|
||||
#include <java/lang/StringBuffer.h>
|
||||
#include <java/net/URLClassLoader.h>
|
||||
#include <java/lang/Runtime.h>
|
||||
#include <java/util/HashSet.h>
|
||||
|
||||
jclass
|
||||
gnu::gcj::runtime::VMClassLoader::findClass (jstring name)
|
||||
@ -25,7 +26,7 @@ gnu::gcj::runtime::VMClassLoader::findClass (jstring name)
|
||||
_Jv_Utf8Const *name_u = _Jv_makeUtf8Const (name);
|
||||
jclass klass = _Jv_FindClassInCache (name_u, 0);
|
||||
|
||||
if (! klass)
|
||||
if (! klass && lib_control != LIB_NEVER)
|
||||
{
|
||||
// Turn `gnu.pkg.quux' into `lib-gnu-pkg-quux'. Then search for
|
||||
// a module named (eg, on Linux) `lib-gnu-pkg-quux.so', followed
|
||||
@ -41,11 +42,20 @@ gnu::gcj::runtime::VMClassLoader::findClass (jstring name)
|
||||
cn = name->substring (0, ci);
|
||||
jstring so_base_name = (sb->append (cn)->toString ())->replace ('.', '-');
|
||||
|
||||
using namespace ::java::lang;
|
||||
Runtime *rt = Runtime::getRuntime();
|
||||
|
||||
// Compare against `3' because that is the length of "lib".
|
||||
while (! klass && so_base_name && so_base_name->length() > 3)
|
||||
{
|
||||
using namespace ::java::lang;
|
||||
Runtime *rt = Runtime::getRuntime();
|
||||
if (lib_control == LIB_CACHE)
|
||||
{
|
||||
// If we've already tried this name, we're done.
|
||||
if (tried_libraries->contains(so_base_name))
|
||||
break;
|
||||
tried_libraries->add(so_base_name);
|
||||
}
|
||||
|
||||
jboolean loaded = rt->loadLibraryInternal (so_base_name);
|
||||
|
||||
jint nd = so_base_name->lastIndexOf ('-');
|
||||
|
Loading…
Reference in New Issue
Block a user