classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] RFC: VMClassLoader : hashmap for jars from property java.bo


From: Nicolas Geoffray
Subject: [cp-patches] RFC: VMClassLoader : hashmap for jars from property java.boot.class.path
Date: Thu, 06 Oct 2005 14:51:00 +0200
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050913)

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  <address@hidden>

        * 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://"

reply via email to

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