This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: RFC: PR 9125
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 21 Jan 2003 15:52:15 -0700
- Subject: Patch: RFC: PR 9125
- Reply-to: tromey at redhat dot com
This patch fixes PR 9125 by adding a cache. This lets us check
whether we've loaded a given shared library.
Anybody have any comments on this?
It doesn't try to do any kind of cache invalidation. So, if you have
a long-running process and you install a new .so file, it might not
ever get loaded. Do you think this a serious problem?
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
Fix for PR libgcj/9125:
* gnu/gcj/runtime/natVMClassLoader.cc (findClass): Find Runtime
object outside of loop. Use tried_libraries.
* gnu/gcj/runtime/VMClassLoader.java (tried_libraries): New
field.
Index: gnu/gcj/runtime/VMClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/runtime/VMClassLoader.java,v
retrieving revision 1.9
diff -u -r1.9 VMClassLoader.java
--- gnu/gcj/runtime/VMClassLoader.java 9 Dec 2002 00:03:59 -0000 1.9
+++ gnu/gcj/runtime/VMClassLoader.java 15 Jan 2003 23:24:35 -0000
@@ -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 @@
import java.io.*;
import java.util.StringTokenizer;
+import java.util.HashSet;
import java.net.URL;
public final class VMClassLoader extends java.net.URLClassLoader
@@ -67,6 +68,9 @@
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();
+
// The only VMClassLoader that can exist.
- public static VMClassLoader instance = new VMClassLoader ();
+ public static VMClassLoader instance = new VMClassLoader();
}
Index: gnu/gcj/runtime/natVMClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/runtime/natVMClassLoader.cc,v
retrieving revision 1.1
diff -u -r1.1 natVMClassLoader.cc
--- gnu/gcj/runtime/natVMClassLoader.cc 11 Dec 2002 03:15:14 -0000 1.1
+++ gnu/gcj/runtime/natVMClassLoader.cc 15 Jan 2003 23:24:35 -0000
@@ -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 @@
#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)
@@ -41,11 +42,17 @@
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 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 ('-');