Hi,

I improved the reference implementation of VMClassLoader.getRessources by adding a static HashMap which is filled when a boot zip is opened (typically glibj.zip). In the previous implementation, the code kept opening and closing the zip file.

Another solution would be to have a static initializer for VMClassLoader which would parse the java.boot.class.path property, and puts the files into a static Enumeration object. I tried this solution too, but performance isn't improved and it results in all boot files opened.

Comments welcomed

2005-10-06  Nicolas Geoffray  <[EMAIL PROTECTED]>

        * vm/reference/java/lang/VMClassLoader.java
       (getResources): uses a new static field HashMap to
       store opened zip files from property java.boot.class.path.



Cheers,
Nicolas


--- classpath-0.18/vm/reference/java/lang/VMClassLoader.java	2005-10-06 10:26:34.000000000 +0200
+++ classpath-0.18-jnjvm/vm/reference/java/lang/VMClassLoader.java	2005-10-06 14:47:02.000000000 +0200
@@ -119,6 +119,9 @@
     return null;
   }
 
+  /** jars from property java.boot.class.path */
+  static final HashMap bootjars = new HashMap();
+  
   /**
    * Helper to get a list of resources from the bootstrap class loader.
    *
@@ -139,8 +142,9 @@
 	  {
 	    try
 	      {
-		v.add(new URL("file://"
-		  + new File(file, name).getAbsolutePath()));
+                File f = new File(file, name);
+                if(!f.exists()) continue;
+                v.add(new URL("file://" + f.getAbsolutePath()));
 	      }
 	    catch (MalformedURLException e)
 	      {
@@ -150,30 +154,28 @@
 	else if (file.isFile())
 	  {
 	    ZipFile zip;
-	    try
-	      {
-		zip = new ZipFile(file);
-	      }
-	    catch (IOException e)
-	      {
-		continue;
-	      }
-	    String zname = name.startsWith("/") ? name.substring(1) : name;
-	    try
-	      {
-		if (zip.getEntry(zname) == null)
+            synchronized(bootjars)
+              {
+                zip = (ZipFile) bootjars.get(file.getName());
+              }
+            if(zip == null)
+              {
+                try
+	          {
+                    zip = new ZipFile(file);
+                    synchronized(bootjars)
+                      {
+                        bootjars.put(file.getName(), zip);
+                      }
+	          }
+	        catch (IOException e)
+	          {
 		    continue;
-	      }
-	    finally
-	      {
-		try
-		  {
-		    zip.close();
-		  }
-		catch (IOException e)
-		  {
-		  }
-	      }
+	          }
+              }
+	    String zname = name.startsWith("/") ? name.substring(1) : name;
+	    if (zip.getEntry(zname) == null)
+	      continue;
 	    try
 	      {
 		v.add(new URL("jar:file://"
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to