]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix for PR libgcj/9125:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Aug 2003 15:32:23 +0000 (15:32 +0000)
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Aug 2003 15:32:23 +0000 (15:32 +0000)
* 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

libjava/ChangeLog
libjava/gnu/gcj/runtime/VMClassLoader.java
libjava/gnu/gcj/runtime/natVMClassLoader.cc

index c310fb8738181b48eb3fa741756678e4bd65545d..1cf3b82b944da8cee401e85375033be179ffe84f 100644 (file)
@@ -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.
index fd0c32c2c57dbb39c271be84efab3ab138d121b4..ca0f663c9ccb4a202ae0f4d2feb8b055cc27de38 100644 (file)
@@ -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;
 }
index 33b63d6759a1931fdd4de3e14ae6123a73097688..42ac2a02107b2f41cf9bb029bfd2582575084737 100644 (file)
@@ -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 ('-');