natVMClassLoader.cc (getSystemClassLoaderInternal): Updated for name change.
[gcc.git] / libjava / java / lang / VMClassLoader.java
index 1afda4570ea363d32a5ab5c2fb47abb0cc385cd2..c48fc709991367de972f9bfffc90323596abcda1 100644 (file)
@@ -40,15 +40,21 @@ package java.lang;
 
 import gnu.java.util.EmptyEnumeration;
 import java.lang.reflect.Constructor;
+import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.security.AllPermission;
 import java.security.Permission;
 import java.security.Permissions;
 import java.security.ProtectionDomain;
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.StringTokenizer;
+import gnu.gcj.runtime.BootClassLoader;
 
 /**
  * java.lang.VMClassLoader is a package-private helper for VMs to implement
@@ -78,6 +84,21 @@ final class VMClassLoader
 
   static final HashMap definedPackages = new HashMap();
 
+  // This is a helper for handling java.endorsed.dirs.  It is null
+  // until we've initialized the system, at which point it is created.
+  static BootClassLoader bootLoader;
+
+  // This keeps track of shared libraries we've already tried to load.
+  private static HashSet tried_libraries;
+
+  // Holds one of the LIB_* constants; used to determine how shared
+  // library loads are done.
+  private static int lib_control;
+
+  private static final int LIB_FULL = 0;
+  private static final int LIB_CACHE = 1;
+  private static final int LIB_NEVER = 2;
+
   /**
    * Helper to define a class using a string of bytes. This assumes that
    * the security checks have already been performed, if necessary.
@@ -149,6 +170,8 @@ final class VMClassLoader
    */
   static URL getResource(String name)
   {
+    if (bootLoader != null)
+      return bootLoader.bootGetResource(name);
     return null;
   }
 
@@ -164,6 +187,8 @@ final class VMClassLoader
    */
   static Enumeration getResources(String name) throws IOException
   {
+    if (bootLoader != null)
+      return bootLoader.bootGetResources(name);
     return EmptyEnumeration.getInstance();
   }
 
@@ -283,6 +308,32 @@ final class VMClassLoader
 
   static native ClassLoader getSystemClassLoaderInternal();
 
+  static native void initBootLoader(String libdir);
+
+  static void initialize(String libdir)
+  {
+    initBootLoader(libdir);
+
+    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))
+      lib_control = LIB_FULL;
+    else
+      lib_control = LIB_CACHE;
+
+    tried_libraries = new HashSet();
+  }
+
+  /**
+   * Possibly load a .so and search it for classes.
+   */
+  static native Class nativeFindClass(String name);
+
   static ClassLoader getSystemClassLoader()
   {
     // This method is called as the initialization of systemClassLoader,
@@ -300,14 +351,13 @@ final class VMClassLoader
            default_sys
              = (ClassLoader) c.newInstance(new Object[] { default_sys });
          }
-       catch (Exception e)
+       catch (Exception ex)
          {
-           System.err.println("Requested system classloader "
-                              + loader + " failed, using "
-                              + "gnu.gcj.runtime.VMClassLoader");
-           e.printStackTrace();
+           throw new Error("Failed to load requested system classloader "
+                              + loader, ex);
          }
       }
+
     return default_sys;
   }
 }