classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] [generics] Patch: FYI: update ClassLoader


From: Tom Tromey
Subject: [cp-patches] [generics] Patch: FYI: update ClassLoader
Date: 09 Oct 2004 17:05:20 -0600

I'm checking this in on the generics branch.

This updates ClassLoader to 1.5.

Tom

Index: ChangeLog
from  Tom Tromey  <address@hidden>
        * java/lang/ClassLoader.java (defineClass): New method.
        (findClass): Updated return type.
        (findLoadedClass): Likewise.
        (findSystemClass): Likewise.
        (findResources): Likewise.
        (getSystemResources): Likewise.
        (loadClass): Likewise.
        (resolveClass): Updated argument type.
        (setSigners): Likewise.
        (loadedClasses, definedPackages): Updated types.
        (packageAssertionStatus): Likewise.
        (systemClassAssertionStatus): Likewise.
        (classAssertionStatus): Likewise.
        (defineClass): Updated return type.
        (getResource): Likewise.
        (clearAssertionStatus): Clear packageAssertionStatus and
        classAssertionStatus.

Index: java/lang/ClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/ClassLoader.java,v
retrieving revision 1.31
diff -u -r1.31 ClassLoader.java
--- java/lang/ClassLoader.java 23 Apr 2004 21:13:20 -0000 1.31
+++ java/lang/ClassLoader.java 9 Oct 2004 23:08:14 -0000
@@ -1,5 +1,5 @@
 /* ClassLoader.java -- responsible for loading classes into the VM
-   Copyright (C) 1998, 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004 Free Software Foundation, 
Inc.
 
 This file is part of GNU Classpath.
 
@@ -44,6 +44,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.ByteBuffer;
 import java.security.CodeSource;
 import java.security.PermissionCollection;
 import java.security.Policy;
@@ -112,7 +113,6 @@
  * @author Eric Blake <address@hidden>
  * @see Class
  * @since 1.0
- * @status still missing 1.4 functionality
  */
 public abstract class ClassLoader
 {
@@ -122,13 +122,13 @@
    * is not private in order to allow native code (and trusted subclasses)
    * access to this field.
    */
-  final Map loadedClasses = new HashMap();
+  final HashMap<String, Class<?>> loadedClasses = new HashMap<String, 
Class<?>>();
 
   /**
    * All packages defined by this classloader. It is not private in order to
    * allow native code (and trusted subclasses) access to this field.
    */
-  final Map definedPackages = new HashMap();
+  final HashMap<String, Package> definedPackages = new HashMap<String, 
Package>();
 
   /**
    * The classloader that is consulted before this classloader.
@@ -190,14 +190,14 @@
    * by the null key. This map must be synchronized on this instance.
    */
   // Package visible for use by Class.
-  Map packageAssertionStatus;
+  Map<String, Boolean> packageAssertionStatus;
 
   /**
    * The command-line state of the class assertion status overrides. This
    * map is never modified, so it does not need to be synchronized.
    */
   // Package visible for use by Class.
-  static final Map systemClassAssertionStatus
+  static final Map<String, Boolean> systemClassAssertionStatus
     = VMClassLoader.classAssertionStatus();
 
   /**
@@ -207,7 +207,7 @@
    * instance.
    */
   // Package visible for use by Class.
-  Map classAssertionStatus;
+  Map<String, Boolean> classAssertionStatus;
 
   /**
    * Create a new ClassLoader with as parent the system classloader. There
@@ -255,7 +255,7 @@
    * @return the loaded class
    * @throws ClassNotFoundException if the class cannot be found
    */
-  public Class loadClass(String name) throws ClassNotFoundException
+  public Class<?> loadClass(String name) throws ClassNotFoundException
   {
     return loadClass(name, false);
   }
@@ -280,11 +280,11 @@
    * @return the loaded class
    * @throws ClassNotFoundException if the class cannot be found
    */
-  protected synchronized Class loadClass(String name, boolean resolve)
+  protected synchronized Class<?> loadClass(String name, boolean resolve)
     throws ClassNotFoundException
   {
     // Have we already loaded this class?
-    Class c = findLoadedClass(name);
+    Class<?> c = findLoadedClass(name);
     if (c != null)
       return c;
 
@@ -354,7 +354,7 @@
    * @throws ClassNotFoundException when the class can not be found
    * @since 1.2
    */
-  protected Class findClass(String name) throws ClassNotFoundException
+  protected Class<?> findClass(String name) throws ClassNotFoundException
   {
     throw new ClassNotFoundException(name);
   }
@@ -372,7 +372,7 @@
    *         offset + len exceeds data
    * @deprecated use address@hidden #defineClass(String, byte[], int, int)} 
instead
    */
-  protected final Class defineClass(byte[] data, int offset, int len)
+  protected final Class<?> defineClass(byte[] data, int offset, int len)
     throws ClassFormatError
   {
     return defineClass(null, data, offset, len);
@@ -397,8 +397,8 @@
    * @throws SecurityException if name starts with "java."
    * @since 1.1
    */
-  protected final Class defineClass(String name, byte[] data, int offset,
-                                    int len) throws ClassFormatError
+  protected final Class<?> defineClass(String name, byte[] data, int offset,
+                                      int len) throws ClassFormatError
   {
     return defineClass(name, data, offset, len, null);
   }
@@ -426,21 +426,30 @@
    *         do not match up
    * @since 1.2
    */
-  protected final synchronized Class defineClass(String name, byte[] data,
-                                                int offset, int len,
-                                                ProtectionDomain domain)
+  protected final synchronized Class<?> defineClass(String name, byte[] data,
+                                                   int offset, int len,
+                                                   ProtectionDomain domain)
     throws ClassFormatError
   {
     if (domain == null)
       domain = defaultProtectionDomain;
     if (! initialized)
       throw new SecurityException("attempt to define class from uninitialized 
class loader");
-    Class retval = VMClassLoader.defineClass(this, name, data,
-                                             offset, len, domain);
+    Class<?> retval = VMClassLoader.defineClass(this, name, data,
+                                               offset, len, domain);
     loadedClasses.put(retval.getName(), retval);
     return retval;
   }
 
+  protected final Class<?> defineClass(String name, ByteBuffer buf,
+                                      ProtectionDomain domain)
+    throws ClassFormatError
+  {
+    byte[] data = new byte[buf.remaining()];
+    buf.get(data);
+    return defineClass(name, data, 0, data.length, domain);
+  }
+
   /**
    * Links the class, if that has not already been done. Linking basically
    * resolves all references to other classes made by this class.
@@ -449,7 +458,7 @@
    * @throws NullPointerException if c is null
    * @throws LinkageError if linking fails
    */
-  protected final void resolveClass(Class c)
+  protected final void resolveClass(Class<?> c)
   {
     VMClassLoader.resolveClass(c);
   }
@@ -463,7 +472,7 @@
    * @return the found class
    * @throws ClassNotFoundException if the class cannot be found
    */
-  protected final Class findSystemClass(String name)
+  protected final Class<?> findSystemClass(String name)
     throws ClassNotFoundException
   {
     return Class.forName(name, false, systemClassLoader);
@@ -485,7 +494,7 @@
     SecurityManager sm = System.getSecurityManager();
     if (sm != null)
       {
-        Class c = VMSecurityManager.getClassContext()[1];
+        Class<?> c = VMSecurityManager.getClassContext()[1];
         ClassLoader cl = c.getClassLoader();
        if (cl != null && ! cl.isAncestorOf(this))
           sm.checkPermission(new RuntimePermission("getClassLoader"));
@@ -501,7 +510,7 @@
    * @param signers the signers to set
    * @since 1.1
    */
-  protected final void setSigners(Class c, Object[] signers)
+  protected final void setSigners(Class<?> c, Object[] signers)
   {
     c.setSigners(signers);
   }
@@ -513,11 +522,11 @@
    * @return the found Class, or null if it is not found
    * @since 1.1
    */
-  protected final synchronized Class findLoadedClass(String name)
+  protected final synchronized Class<?> findLoadedClass(String name)
   {
     // NOTE: If the VM is keeping its own cache, it may make sense to have
     // this method be native.
-    return (Class) loadedClasses.get(name);
+    return loadedClasses.get(name);
   }
 
   /**
@@ -568,14 +577,14 @@
    * @throws IOException if I/O errors occur in the process
    * @since 1.2
    */
-  public final Enumeration getResources(String name) throws IOException
+  public final Enumeration<URL> getResources(String name) throws IOException
   {
-    Enumeration parentResources;
+    Enumeration<URL> parentResources;
     if (parent == null)
       parentResources = VMClassLoader.getResources(name);
     else
       parentResources = parent.getResources(name);
-    return new DoubleEnumeration(parentResources, findResources(name));
+    return new DoubleEnumeration<URL>(parentResources, findResources(name));
   }
 
   /**
@@ -595,9 +604,9 @@
    * @throws IOException if I/O errors occur in the process
    * @since 1.2
    */
-  protected Enumeration findResources(String name) throws IOException
+  protected Enumeration<URL> findResources(String name) throws IOException
   {
-    return EmptyEnumeration.getInstance();
+    return (Enumeration<URL>) EmptyEnumeration.getInstance();
   }
 
   /**
@@ -642,7 +651,8 @@
    * @throws IOException if I/O errors occur in the process
    * @since 1.2
    */
-  public static Enumeration getSystemResources(String name) throws IOException
+  public static Enumeration<URL> getSystemResources(String name)
+    throws IOException
   {
     return systemClassLoader.getResources(name);
   }
@@ -728,7 +738,7 @@
     SecurityManager sm = System.getSecurityManager();
     if (sm != null)
       {
-       Class c = VMSecurityManager.getClassContext()[1];
+       Class<?> c = VMSecurityManager.getClassContext()[1];
        ClassLoader cl = c.getClassLoader();
        if (cl != null && cl != systemClassLoader)
          sm.checkPermission(new RuntimePermission("getClassLoader"));
@@ -803,7 +813,7 @@
       {
        synchronized (definedPackages)
          {
-           p = (Package) definedPackages.get(name);
+           p = definedPackages.get(name);
          }
       }
     return p;
@@ -893,7 +903,7 @@
   {
     if (packageAssertionStatus == null)
       packageAssertionStatus
-        = new HashMap(systemPackageAssertionStatus);
+        = new HashMap<String, Boolean>(systemPackageAssertionStatus);
     packageAssertionStatus.put(name, Boolean.valueOf(enabled));
   }
   
@@ -913,7 +923,8 @@
                                                    boolean enabled)
   {
     if (classAssertionStatus == null)
-      classAssertionStatus = new HashMap(systemClassAssertionStatus);
+      classAssertionStatus
+       = new HashMap<String, Boolean>(systemClassAssertionStatus);
     // The toString() hack catches null, as required.
     classAssertionStatus.put(name.toString(), Boolean.valueOf(enabled));
   }
@@ -931,8 +942,8 @@
   public synchronized void clearAssertionStatus()
   {
     defaultAssertionStatus = false;
-    packageAssertionStatus = new HashMap();
-    classAssertionStatus = new HashMap();
+    packageAssertionStatus = null;
+    classAssertionStatus = null;
   }
 
   /**




reply via email to

[Prev in Thread] Current Thread [Next in Thread]