This was checked in to gcc.gnu.org on August 20.

Index: libjava/ChangeLog
from  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.

Index: libjava/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
--- libjava/gnu/gcj/runtime/VMClassLoader.java 9 Dec 2002 00:03:59 -0000 1.9
+++ libjava/gnu/gcj/runtime/VMClassLoader.java 16 Aug 2003 22:02:28 -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
@@ -19,6 +20,20 @@
   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 @@
   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;
 }
Index: libjava/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
--- libjava/gnu/gcj/runtime/natVMClassLoader.cc 11 Dec 2002 03:15:14 -0000 1.1
+++ libjava/gnu/gcj/runtime/natVMClassLoader.cc 16 Aug 2003 22:02:28 -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)
@@ -25,7 +26,7 @@
   _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 @@
 	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 ('-');

