summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-20 15:32:23 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-20 15:32:23 +0000
commite54cfd0fadb3c8955708e30afb39da0a0948b610 (patch)
tree9dc3ee43232dc76c5cf29cca667d555d8d9c62e7
parent8ccf652f585e2e342f72683532515d659168d7c6 (diff)
downloadgcc-e54cfd0fadb3c8955708e30afb39da0a0948b610.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@70600 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libjava/ChangeLog9
-rw-r--r--libjava/gnu/gcj/runtime/VMClassLoader.java30
-rw-r--r--libjava/gnu/gcj/runtime/natVMClassLoader.cc18
3 files changed, 51 insertions, 6 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index c310fb87381..1cf3b82b944 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -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.
diff --git a/libjava/gnu/gcj/runtime/VMClassLoader.java b/libjava/gnu/gcj/runtime/VMClassLoader.java
index fd0c32c2c57..ca0f663c9cc 100644
--- a/libjava/gnu/gcj/runtime/VMClassLoader.java
+++ b/libjava/gnu/gcj/runtime/VMClassLoader.java
@@ -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;
}
diff --git a/libjava/gnu/gcj/runtime/natVMClassLoader.cc b/libjava/gnu/gcj/runtime/natVMClassLoader.cc
index 33b63d6759a..42ac2a02107 100644
--- a/libjava/gnu/gcj/runtime/natVMClassLoader.cc
+++ b/libjava/gnu/gcj/runtime/natVMClassLoader.cc
@@ -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 ('-');