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: Fri, 28 Oct 2005 10:39:44 +0200
User-agent: Mozilla Thunderbird 1.0.7 (X11/20051019)

Mark Wielaard wrote:

Hi,

On Sun, 2005-10-23 at 16:17 +0200, Jeroen Frijters wrote:
Nicolas Geoffray wrote:
Mark are you OK with the changes?
I would like to see this go in before 0.19. After 0.19 (based on
feedback from other VM implementers) we should consider making
getBootPackages native so that they will be able to use the reference
VMClassLoader as is.

Agreed. This looks fine. Nicolas can you add a little note about this
(and the feedback we want) for the NEWS file?

Great! I'm committing this in.

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   28 Oct 2005 08:35: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,41 @@
     return v.elements();
   }
 
+
   /**
-   * 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.
+   * 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.
    *
    * @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 = 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        28 Oct 2005 08:37:34 -0000
@@ -594,7 +594,8 @@
     ClassLoader cl = getClassLoader();
     if (cl != null)
       return cl.getPackage(getPackagePortion(getName()));
-    return null;
+    else
+      return VMClassLoader.getPackage(getPackagePortion(getName()));
   }
 
   /**
Index: NEWS
===================================================================
RCS file: /cvsroot/classpath/classpath/NEWS,v
retrieving revision 1.99
diff -u -r1.99 NEWS
--- NEWS        21 Oct 2005 18:13:39 -0000      1.99
+++ NEWS        28 Oct 2005 08:37:43 -0000
@@ -16,6 +16,14 @@
   It can flatten graphs and, at least for the simple cases, is interoperable
   with Sun's jdk 1.5. 
 
+Runtime interface changes:
+
+* Changed implementation of VMClassLoader.getPackage(s) : new method
+  VMClassLoader.getBootPackages should be implemented by the vm, and sould
+  return a string array of boot package names ("java.lang", "java.net", ...).
+  Feedback from vm implementors for usability and relevance of the
+  getBootPackages method would be greatly appreciated.
+  
 New in release 0.18 (Sep 6, 2005)
 
 * GNU JAWT implementation, the AWT Native Interface, which allows direct

reply via email to

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