classpath
[Top][All Lists]
Advanced

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

API clean up patch


From: Archie Cobbs
Subject: API clean up patch
Date: Tue, 17 May 2005 09:56:02 -0500
User-agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.3) Gecko/20041129

I'd like to throw this patch out for comments; it fixes some of the
inconsistencies in our VM interface. The basic problem is that the VM
interface as a "stock" Classpath defines it is almost guaranteed to
require changes before a VM can actually work properly.

As a small example, consider this "stock" implementation of
VMThrowable.fillInStackTrace():

  static VMThrowable fillInStackTrace(Throwable t)
  {
    return null;
  }

Who wants a VM that's incapable of generating stack traces??

Of course, many VM implementors will want to modify the "stock" Classpath
API, which is fine.. I'd just like to not *require* them to do so if
they'd prefer to use Classpath as-is.

Along with these changes are removal of some deprecated stuff that's
been marked "this will be removed in a future version of classpath"
for a long time, and some other minor cleanups.

Summary of changes:

  - Add a "vmdata" field to ClassLoader, VMThread, and VMThrowable.
    Seems to me that every VM will require these (am I wrong?)
  - Constructor.getParameterTypes() and getExceptionTypes() become
    native methods, to align with Field.java and Method.java, and
    because nowhere is the code that sets these fields anyway.
  - Made VMThread.countStackFrames(), VMThrowable.fillInStackTrace(),
    and VMThrowable.getStackTrace() native.
  - Fixed broken VMClass.getModifiers() API (for correct behavior a
    VM is required to change this).
  - Removed deprecated methods from VMClassLoader

Let me know what you think.

Yes this changes the API, but IMHO until the major version number of
Classpath is a non-zero number we shouldn't worry about that too much..
better to clean house now while we still can..

Thanks,
-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com
Index: java/lang/ClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/ClassLoader.java,v
retrieving revision 1.50
diff -u -r1.50 ClassLoader.java
--- java/lang/ClassLoader.java  10 May 2005 09:29:48 -0000      1.50
+++ java/lang/ClassLoader.java  17 May 2005 14:52:52 -0000
@@ -246,6 +246,11 @@
   Map classAssertionStatus;
 
   /**
+   * VM private data.
+   */
+  private transient Object vmdata;
+
+  /**
    * Create a new ClassLoader with as parent the system classloader. There
    * may be a security check for <code>checkCreateClassLoader</code>.
    *
Index: vm/reference/java/lang/VMClass.java
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMClass.java,v
retrieving revision 1.11
diff -u -r1.11 VMClass.java
--- vm/reference/java/lang/VMClass.java 18 Apr 2005 08:57:50 -0000      1.11
+++ vm/reference/java/lang/VMClass.java 17 May 2005 14:52:55 -0000
@@ -191,12 +191,7 @@
    * @see Modifer
    * @since 1.1
    */
-  static int getModifiers(Class klass, boolean ignoreInnerClassesAttrib)
-  {
-    return getModifiers(klass);
-  }
-
-  private static native int getModifiers(Class klass);
+  static native int getModifiers(Class klass, boolean 
ignoreInnerClassesAttrib);
 
   /**
    * If this is a nested or inner class, return the class that declared it.
Index: vm/reference/java/lang/VMClassLoader.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/vm/reference/java/lang/VMClassLoader.java,v
retrieving revision 1.24
diff -u -r1.24 VMClassLoader.java
--- vm/reference/java/lang/VMClassLoader.java   19 Mar 2005 23:07:55 -0000      
1.24
+++ vm/reference/java/lang/VMClassLoader.java   17 May 2005 14:52:55 -0000
@@ -66,30 +66,6 @@
   /**
    * Helper to define a class using a string of bytes. This assumes that
    * the security checks have already been performed, if necessary.
-   * <strong>This method will be removed in a future version of GNU
-   * Classpath</strong>.
-   *
-   * @param name the name to give the class, or null if unknown
-   * @param data the data representing the classfile, in classfile format
-   * @param offset the offset into the data where the classfile starts
-   * @param len the length of the classfile data in the array
-   * @return the class that was defined
-   * @throws ClassFormatError if data is not in proper classfile format
-   * @deprecated Implement
-   * address@hidden #defineClass(ClassLoader, String, byte[], int, int, 
ProtectionDomain)}
-   *   instead.
-   */
-  static final native Class defineClass(ClassLoader cl, String name,
-                                        byte[] data, int offset, int len)
-    throws ClassFormatError;
-
-  /**
-   * Helper to define a class using a string of bytes. This assumes that
-   * the security checks have already been performed, if necessary.
-   *
-   * <strong>For backward compatibility, this just ignores the protection
-   * domain; that is the wrong behavior, and you should directly implement
-   * this method natively if you can.</strong>
    *
    * Implementations of this method are advised to consider the
    * situation where user code modifies the byte array after it has
@@ -105,13 +81,10 @@
    * @return the class that was defined
    * @throws ClassFormatError if data is not in proper classfile format
    */
-  static final Class defineClass(ClassLoader cl, String name,
+  static final native Class defineClass(ClassLoader cl, String name,
                                  byte[] data, int offset, int len,
                                  ProtectionDomain pd)
-    throws ClassFormatError
-  {
-    return defineClass(cl, name, data, offset, len);
-  }
+    throws ClassFormatError;
 
   /**
    * Helper to resolve all references to other classes from this class.
@@ -123,19 +96,14 @@
   /**
    * Helper to load a class from the bootstrap class loader.
    *
-   * XXX - Not implemented; this requires native help.
-   *
    * @param name the class name to load
    * @param resolve whether to resolve it
    * @return the class, loaded by the bootstrap classloader or null
    * if the class wasn't found. Returning null is equivalent to throwing
    * a ClassNotFoundException (but a possible performance optimization).
    */
-  static final Class loadClass(String name, boolean resolve)
-    throws ClassNotFoundException
-  {
-    return null;
-  }
+  static final native Class loadClass(String name, boolean resolve)
+    throws ClassNotFoundException;
 
   /**
    * Helper to load a resource from the bootstrap class loader.
@@ -262,66 +230,10 @@
    * <li>'V' - void</li>
    * </ul>
    *
-   * Note that this is currently a java version that converts the type code
-   * to a string and calls the native <code>getPrimitiveClass(String)</code>
-   * method for backwards compatibility with VMs that used old versions of
-   * GNU Classpath. Please replace this method with a native method
-   * <code>final static native Class getPrimitiveClass(char type);</code>
-   * if your VM supports it. <strong>The java version of this method and
-   * the String version of this method will disappear in a future version
-   * of GNU Classpath</strong>.
-   *
-   * @param type the primitive type
-   * @return a "bogus" class representing the primitive type
-   */
-  static final Class getPrimitiveClass(char type)
-  {
-    String t;
-    switch (type)
-      {
-      case 'Z':
-        t = "boolean";
-        break;
-      case 'B':
-        t = "byte";
-        break;
-      case 'C':
-        t = "char";
-        break;
-      case 'D':
-        t = "double";
-        break;
-      case 'F':
-        t = "float";
-        break;
-      case 'I':
-        t = "int";
-        break;
-      case 'J':
-        t = "long";
-        break;
-      case 'S':
-        t = "short";
-        break;
-      case 'V':
-        t = "void";
-        break;
-      default:
-        throw new NoClassDefFoundError("Invalid type specifier: " + type);
-      }
-    return getPrimitiveClass(t);
-  }
-
-  /**
-   * Old version of the interface, added here for backwards compatibility.
-   * Called by the java version of getPrimitiveClass(char) when no native
-   * version of that method is available.
-   * <strong>This method will be removed in a future version of GNU
-   * Classpath</strong>.
    * @param type the primitive type
    * @return a "bogus" class representing the primitive type
    */
-  static final native Class getPrimitiveClass(String type);
+  static final native Class getPrimitiveClass(char type);
 
   /**
    * The system default for assertion status. This is used for all system
Index: vm/reference/java/lang/VMThread.java
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMThread.java,v
retrieving revision 1.6
diff -u -r1.6 VMThread.java
--- vm/reference/java/lang/VMThread.java        5 Jan 2005 00:09:44 -0000       
1.6
+++ vm/reference/java/lang/VMThread.java        17 May 2005 14:52:56 -0000
@@ -82,6 +82,11 @@
     private volatile boolean running;
 
     /**
+     * VM private data.
+     */
+    private transient Object vmdata;
+
+    /**
      * Private constructor, create VMThreads with the static create method.
      *
      * @param thread The Thread object that was just created.
@@ -218,10 +223,7 @@
      *
      * @deprecated unsafe operation
      */
-    int countStackFrames()
-    {
-       return 0;
-    }
+    native int countStackFrames();
 
     /**
      * Wait the specified amount of time for the Thread in question to die.
Index: vm/reference/java/lang/VMThrowable.java
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMThrowable.java,v
retrieving revision 1.1
diff -u -r1.1 VMThrowable.java
--- vm/reference/java/lang/VMThrowable.java     4 Oct 2002 15:26:25 -0000       
1.1
+++ vm/reference/java/lang/VMThrowable.java     17 May 2005 14:52:56 -0000
@@ -50,6 +50,11 @@
 final class VMThrowable
 {
   /**
+   * VM private data.
+   */
+  private transient Object vmdata;
+
+  /**
    * Private contructor, create VMThrowables with fillInStackTrace();
    */
   private VMThrowable() { }
@@ -63,10 +68,7 @@
    * @return a new VMThrowable containing the current execution stack trace.
    * @see Throwable#fillInStackTrace()
    */
-  static VMThrowable fillInStackTrace(Throwable t)
-  {
-    return null;
-  }
+  static native VMThrowable fillInStackTrace(Throwable t);
 
   /**
    * Returns an <code>StackTraceElement</code> array based on the execution
@@ -76,8 +78,5 @@
    * @return a non-null but possible zero length array of StackTraceElement.
    * @see Throwable#getStackTrace()
    */
-  StackTraceElement[] getStackTrace(Throwable t)
-  {
-    return new StackTraceElement[0];
-  }
+  native StackTraceElement[] getStackTrace(Throwable t);
 }
Index: vm/reference/java/lang/reflect/Constructor.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/vm/reference/java/lang/reflect/Constructor.java,v
retrieving revision 1.11
diff -u -r1.11 Constructor.java
--- vm/reference/java/lang/reflect/Constructor.java     29 Mar 2004 07:07:40 
-0000      1.11
+++ vm/reference/java/lang/reflect/Constructor.java     17 May 2005 14:52:56 
-0000
@@ -78,8 +78,6 @@
 {
   private Class clazz;
   private int slot;
-  private Class[] parameterTypes;
-  private Class[] exceptionTypes;
   
   /**
    * This class is uninstantiable except from native code.
@@ -129,12 +127,7 @@
    *
    * @return a list of the types of the constructor's parameters
    */
-  public Class[] getParameterTypes()
-  {
-    if (parameterTypes == null)
-      return new Class[0];
-    return parameterTypes;
-  }
+  public native Class[] getParameterTypes();
 
   /**
    * Get the exception types this constructor says it throws, in no particular
@@ -143,12 +136,7 @@
    *
    * @return a list of the types in the constructor's throws clause
    */
-  public Class[] getExceptionTypes()
-  {
-    if (exceptionTypes == null)
-      return new Class[0];
-    return exceptionTypes;
-  }
+  public native Class[] getExceptionTypes();
 
   /**
    * Compare two objects to see if they are semantically equivalent.

reply via email to

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