classpath-patches
[Top][All Lists]
Advanced

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

Re: [cp-patches] RFC: implementation of getPackage for the vmreference


From: Nicolas Geoffray
Subject: Re: [cp-patches] RFC: implementation of getPackage for the vmreference
Date: Sun, 23 Oct 2005 12:34:40 +0200
User-agent: Mozilla Thunderbird 1.0.7 (X11/20051019)


Why should it be native? It might be the same work for all VMs.
Maybe we could add a static initializer to VMClassLoader
that would look for java.boot.class.path property and fill the packages (eg the directories) it finds in the
definedPackages hashmap.

I just assumed it would have to be native, but I don't really know which
VMs use VMClassLoader as-is (I don't use it, for example). If a
non-native implementation that works for everyone (that uses the
reference VMClassLoader) is possible, then that would obviously be the
best option.

I looked at it a little further, and i realized the java.boot.class.path can be overidden. So using it is not the best solution. I implemented what you said : having a method that returns a String[] of native package names, getBootPackages. The (new) static initializer of VMClassLoader calls getBootPackages, constructs the packages and
puts it into the definedPackages hashMap. The getBootPackages doesn't bother
(yet?) with infos needed by the Package constructor.

This implementation would considerably ease the work of a vm implementation, not
creating packages but strings, and not dealing with a native hashmap.
This modifies the VM integration guide (even though it doesn't break the old
implementation). Mark are you OK with the changes?


2005-10-21  Nicolas Geoffray  <address@hidden>

           Reported by: Gael Thomas <address@hidden>
           * vm/reference/java/lang/VMClassLoader.java:
           Added new definedPackages field to store packages
           loaded by the bootstrap classloader.
           Added new static initializer to create all packages
           which names are returned by getBootPackages
           (getBootPackages): new private method. Helper
           to get as a String[] the native package names
           (getPackage): uses the new definedPackages field
           (getPackages): uses the new definedPackages field
           * java/lang/Class.java:
           (getPackage): if the classloader of the class is null
           then call VMClassLoader.getPackage

Nicolas
Index: vm/reference/java/lang/VMClassLoader.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/vm/reference/java/lang/VMClassLoader.java,v
retrieving revision 1.32
diff -u -r1.32 VMClassLoader.java
--- vm/reference/java/lang/VMClassLoader.java   21 Oct 2005 10:47:17 -0000      
1.32
+++ vm/reference/java/lang/VMClassLoader.java   23 Oct 2005 10:05:47 -0000
@@ -40,6 +40,7 @@
 package java.lang;
 
 import gnu.classpath.SystemProperties;
+import gnu.classpath.Configuration;
 
 import java.io.File;
 import java.io.IOException;
@@ -63,6 +64,48 @@
  */
 final class VMClassLoader
 {
+
+
+  /** packages loaded by the bootstrap class loader */
+  static final HashMap definedPackages = new HashMap();
+
+  /**
+   * Converts the array string of native package names to
+   * Packages. The packages are then put into the
+   * definedPackages hashMap
+   */
+  static
+  {
+    String[] packages = getBootPackages();
+    
+    if( packages != null)
+      {
+        String specName = 
+              SystemProperties.getProperty("java.specification.name");
+        String vendor =
+              SystemProperties.getProperty("java.specification.vendor");
+        String version =
+              SystemProperties.getProperty("java.specification.version");
+        
+        Package p;
+              
+        for(int i = 0; i < packages.length; i++)
+          {
+            p = new Package(packages[i],
+                  specName,
+                  vendor,
+                  version,
+                  "GNU Classpath",
+                  "GNU",
+                  Configuration.CLASSPATH_VERSION,
+                  null);
+
+            definedPackages.put(packages[i], p);
+          }
+      }
+  }
+
+  
   /**
    * Helper to define a class using a string of bytes. This assumes that
    * the security checks have already been performed, if necessary.
@@ -190,29 +233,45 @@
     return v.elements();
   }
 
+
+  /**
+   * Returns a String[] of native package names. The default
+   * implementation returns an empty array, or you may decide
+   * this needs native help.
+   */
+  private static String[] getBootPackages()
+  {
+    return new String[0];
+  }
+
+
   /**
-   * Helper to get a package from the bootstrap class loader.  The default
-   * implementation of returning null may be adequate, or you may decide
-   * that this needs some native help.
+   * Helper to get a package from the bootstrap class loader.
    *
    * @param name the name to find
    * @return the named package, if it exists
    */
   static Package getPackage(String name)
   {
-    return null;
+    return (Package)definedPackages.get(name);
   }
 
+
+  
   /**
-   * Helper to get all packages from the bootstrap class loader.  The default
-   * implementation of returning an empty array may be adequate, or you may
-   * decide that this needs some native help.
+   * Helper to get all packages from the bootstrap class loader.  
    *
    * @return all named packages, if any exist
    */
   static Package[] getPackages()
   {
-    return new Package[0];
+    Package[] packages;
+    synchronized(definedPackages)
+      {
+        packages = new Package[definedPackages.size()];
+        definedPackages.values().toArray(packages);
+      }
+    return packages;
   }
 
   /**
Index: java/lang/Class.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Class.java,v
retrieving revision 1.40
diff -u -r1.40 Class.java
--- java/lang/Class.java        15 Sep 2005 14:42:36 -0000      1.40
+++ java/lang/Class.java        23 Oct 2005 10:05:58 -0000
@@ -594,7 +594,8 @@
     ClassLoader cl = getClassLoader();
     if (cl != null)
       return cl.getPackage(getPackagePortion(getName()));
-    return null;
+    else
+      return VMClassLoader.getPackage(getPackagePortion(getName()));
   }
 
   /**

reply via email to

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