This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: java.net.URL: caching protocol handlers


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I have written two patches (attached) to merge some classpath ability 
to libgcj. It introduces the gnu.java.net.nocache_protocol_handlers 
property. This property allows it to disable caching of protocol 
handlers in java.net.URL.

Please review and comment.


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/GmtfWSOgCCdjSDsRAqY/AJ9MmUYs3ymGqxr4meKzgoa68U+rEQCgjkrg
nLs8udwu/OSHsjYA5SeTP7Q=
=132U
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2039
diff -u -b -B -r1.2039 ChangeLog
--- ChangeLog	20 Jul 2003 07:30:58 -0000	1.2039
+++ ChangeLog	20 Jul 2003 09:58:30 -0000
@@ -1,6 +1,19 @@
 2003-07-20  Michael Koch  <konqueror@gmx.de>
 
 	* java/net/URL.java
+	(URL): Added paragraph about the
+	gnu.java.net.nocache_protocol_handlers property.
+	(ph_cache): Renamed from handlers to match classpath's implementation.
+	Reordered it with factory and serialVersionUID member variables.
+	(cache_handlers): New member variable.
+	(static): New static initializer to initialize cache_handlers from
+	gnu.java.net.nocache_protocol_handlers property.
+	(URL): Use ph_cache instead of handlers, reformatted some code to
+	match classpath's implementation.
+
+2003-07-20  Michael Koch  <konqueror@gmx.de>
+
+	* java/net/URL.java
 	(URL): Fixed documentation to name an argument correcty, Reformatted
 	one method declaration.
 	(getURLStreamHandler): Added documentation from classpath.
Index: java/net/URL.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URL.java,v
retrieving revision 1.23
diff -u -b -B -r1.23 URL.java
--- java/net/URL.java	20 Jul 2003 07:30:59 -0000	1.23
+++ java/net/URL.java	20 Jul 2003 09:58:30 -0000
@@ -98,6 +98,14 @@
   * <p>
   * Please note that a protocol handler must be a subclass of
   * URLStreamHandler.
+  * <p>
+  * Normally, this class caches protocol handlers.  Once it finds a handler
+  * for a particular protocol, it never tries to look up a new handler
+  * again.  However, if the system property
+  * gnu.java.net.nocache_protocol_handlers is set, then this
+  * caching behavior is disabled.  This property is specific to this
+  * implementation.  Sun's JDK may or may not do protocol caching, but it
+  * almost certainly does not examine this property.
   *
   * @author Aaron M. Renn <arenn@urbanophile.com>
   * @author Warren Levy <warrenl@cygnus.com>
@@ -150,18 +158,32 @@
   transient URLStreamHandler ph;
 
   /**
+   * If an application installs its own protocol handler factory, this is
+   * where we keep track of it.
+   */
+  private static URLStreamHandlerFactory factory;
+
+  private static final long serialVersionUID = -7627629688361524110L;
+
+  /**
    * This a table where we cache protocol handlers to avoid the overhead
    * of looking them up each time.
    */
-  private static Hashtable handlers = new Hashtable();
+  private static Hashtable ph_cache = new Hashtable();
 
   /**
-   * If an application installs its own protocol handler factory, this is
-   * where we keep track of it.
+   * Whether or not to cache protocol handlers.
    */
-  private static URLStreamHandlerFactory factory;
+  private static boolean cache_handlers;
 
-  private static final long serialVersionUID = -7627629688361524110L;
+  static
+    {
+      String s = System.getProperty("gnu.java.net.nocache_protocol_handlers");
+      if (s == null)
+        cache_handlers = true;
+      else
+        cache_handlers = false;
+    }
 
   /**
    * Constructs a URL and loads a protocol handler for the values passed as
@@ -732,12 +754,14 @@
     URLStreamHandler ph;
 
     // See if a handler has been cached for this protocol.
-    if ((ph = (URLStreamHandler) handlers.get(protocol)) != null)
+    if ((ph = (URLStreamHandler) ph_cache.get(protocol)) != null)
       return ph;
 
     // If a non-default factory has been set, use it to find the protocol.
     if (factory != null)
+      {
       ph = factory.createURLStreamHandler(protocol);
+      }
     else if (protocol.equals ("core"))
       {
  	ph = new gnu.gcj.protocol.core.Handler ();
@@ -790,7 +814,7 @@
     // Update the hashtable with the new protocol handler.
     if (ph != null)
       if (ph instanceof URLStreamHandler)
-	handlers.put(protocol, ph);
+	ph_cache.put(protocol, ph);
       else
 	ph = null;
 
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/ChangeLog,v
retrieving revision 1.769
diff -u -b -B -r1.769 ChangeLog
--- ChangeLog	10 Jul 2003 05:04:03 -0000	1.769
+++ ChangeLog	20 Jul 2003 09:52:40 -0000
@@ -1,3 +1,9 @@
+2003-07-20  Michael Koch  <konqueror@gmx.de>
+
+	* gcc/java/gcj.texi
+	(gnu.java.net.nocache_protocol_handlers): Added item about this
+	property.
+
 2003-07-10  Alexandre Oliva  <aoliva@redhat.com>
 
 	* configure: Rebuilt.
Index: gcc/java/gcj.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/gcj.texi,v
retrieving revision 1.54
diff -u -b -B -r1.54 gcj.texi
--- gcc/java/gcj.texi	8 Jul 2003 21:25:54 -0000	1.54
+++ gcc/java/gcj.texi	20 Jul 2003 09:52:42 -0000
@@ -2238,6 +2237,10 @@
 Whether an external process (@command{addr2line} or @command{addr2name.awk})
 should be used as fallback to convert the addresses to function names when
 the runtime is unable to do it through @code{dladdr}.
+
+@item gnu.java.net.nocache_protocol_handlers
+Whether the protocol handlers used by @code{java.net.URL} are cached. If this
+property is set caching is disabled.
 
 @end table
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]