[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: serialization speedups

Kaffe CVS cvs-commits at kaffe.org
Fri Dec 3 10:09:57 PST 2004


PatchSet 5525 
Date: 2004/12/03 18:05:48
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: serialization speedups

2004-12-03  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/java/io/ObjectOutputStream.java,
        libraries/javalib/java/io/ObjectStreamClass.java:
        Resynced with GNU Classpath.

        2004-12-01  Jeroen Frijters  <jeroen at frijters.net>

        * java/io/ObjectOutputStream.java
        (writeObject, callWriteMethod): Replaced reflection with accessing
        cached info in ObjectStreamClass.
        (getMethod): Removed.
        * java/io/ObjectStreamClass.java
        (findMethod): Added check to make sure the method found has the
        right modifiers.
        (cacheMethods): Added writeReplace and writeObject methods.
        (setFlags): Look at new writeObjectMethod field instead of doing
        reflection again.
        (writeReplaceMethod): New field.
        (writeObjectMethod): New field.

Members: 
	ChangeLog:1.3071->1.3072 
	libraries/javalib/java/io/ObjectOutputStream.java:1.27->1.28 
	libraries/javalib/java/io/ObjectStreamClass.java:1.26->1.27 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3071 kaffe/ChangeLog:1.3072
--- kaffe/ChangeLog:1.3071	Fri Dec  3 17:44:22 2004
+++ kaffe/ChangeLog	Fri Dec  3 18:05:48 2004
@@ -1,5 +1,26 @@
 2004-12-03  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/java/io/ObjectOutputStream.java,
+	libraries/javalib/java/io/ObjectStreamClass.java:
+	Resynced with GNU Classpath.
+
+	2004-12-01  Jeroen Frijters  <jeroen at frijters.net>
+
+	* java/io/ObjectOutputStream.java
+	(writeObject, callWriteMethod): Replaced reflection with accessing
+	cached info in ObjectStreamClass.
+	(getMethod): Removed.
+	* java/io/ObjectStreamClass.java
+	(findMethod): Added check to make sure the method found has the
+	right modifiers.
+	(cacheMethods): Added writeReplace and writeObject methods.
+	(setFlags): Look at new writeObjectMethod field instead of doing
+	reflection again.
+	(writeReplaceMethod): New field.
+	(writeObjectMethod): New field.
+
+2004-12-03  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/clib/awt/classpath-gtk/classpath/Makefile.in,
 	libraries/javalib/Makefile.am,
 	libraries/javalib/Makefile.in,
Index: kaffe/libraries/javalib/java/io/ObjectOutputStream.java
diff -u kaffe/libraries/javalib/java/io/ObjectOutputStream.java:1.27 kaffe/libraries/javalib/java/io/ObjectOutputStream.java:1.28
--- kaffe/libraries/javalib/java/io/ObjectOutputStream.java:1.27	Tue Nov  9 21:45:25 2004
+++ kaffe/libraries/javalib/java/io/ObjectOutputStream.java	Fri Dec  3 18:05:50 2004
@@ -250,6 +250,11 @@
 		break;
 	      }
 
+	    Class clazz = obj.getClass();
+	    ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz);
+	    if (osc == null)
+	      throw new NotSerializableException(clazz.getName());
+	    
 	    if ((replacementEnabled || obj instanceof Serializable)
 		&& ! replaceDone)
 	      {
@@ -257,19 +262,11 @@
 		
 		if (obj instanceof Serializable)
 		  {
-		    Method m = null;
 		    try
 		      {
-			Class classArgs[] = {};
-			m = getMethod(obj.getClass(), "writeReplace",
-				      classArgs);
-			// m can't be null by definition since an
-			// exception would have been thrown so a check
-			// for null is not needed.
-			obj = m.invoke(obj, new Object[] {});
-		      }
-		    catch (NoSuchMethodException ignore)
-		      {
+                        Method m = osc.writeReplaceMethod;
+                        if (m != null)
+                            obj = m.invoke(obj, new Object[0]);
 		      }
 		    catch (IllegalAccessException ignore)
 		      {
@@ -294,11 +291,6 @@
 		break;
 	      }
 
-	    Class clazz = obj.getClass();
-	    ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz);
-	    if (osc == null)
-	      throw new NotSerializableException(clazz.getName());
-	    
 	    if (clazz.isArray ())
 	      {
 		realOutput.writeByte(TC_ARRAY);
@@ -1261,18 +1253,11 @@
   private void callWriteMethod(Object obj, ObjectStreamClass osc)
     throws IOException
   {
-    Class klass = osc.forClass();
     currentPutField = null;
     try
       {
-	Class classArgs[] = {ObjectOutputStream.class};
-	Method m = getMethod(klass, "writeObject", classArgs);
-	Object args[] = {this};
-	m.invoke(obj, args);	
-      }
-    catch (NoSuchMethodException nsme)
-      {
-	// Nothing.
+        Object args[] = {this};
+        osc.writeObjectMethod.invoke(obj, args);
       }
     catch (InvocationTargetException x)
       {
@@ -1283,9 +1268,10 @@
 	if (exception instanceof IOException)
 	  throw (IOException) exception;
 
-	IOException ioe
+        IOException ioe
 	  = new IOException("Exception thrown from writeObject() on " +
-			    klass + ": " + exception.getClass().getName());
+			    osc.forClass().getName() + ": " +
+                            exception.getClass().getName());
 	ioe.initCause(exception);
 	throw ioe;
       }
@@ -1293,7 +1279,8 @@
       {
 	IOException ioe
 	  = new IOException("Failure invoking writeObject() on " +
-			    klass + ": " + x.getClass().getName());
+			    osc.forClass().getName() + ": " +
+			    x.getClass().getName());
 	ioe.initCause(x);
 	throw ioe;
       }
@@ -1533,15 +1520,6 @@
 	throw new InvalidClassException
 	  ("no field called " + name + " in class " + klass.getName());
       }
-  }
-
-  private Method getMethod (Class klass, String name, Class[] args)
-    throws java.lang.NoSuchMethodException
-  {
-    final Method m = klass.getDeclaredMethod(name, args);
-    setAccessible.setMember(m);
-    AccessController.doPrivileged(setAccessible);
-    return m;
   }
 
   private void dumpElementln (String msg)
Index: kaffe/libraries/javalib/java/io/ObjectStreamClass.java
diff -u kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.26 kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.27
--- kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.26	Mon Oct  4 14:46:23 2004
+++ kaffe/libraries/javalib/java/io/ObjectStreamClass.java	Fri Dec  3 18:05:50 2004
@@ -452,27 +452,33 @@
   }
 
   private Method findMethod(Method[] methods, String name, Class[] params,
-			    Class returnType)
+			    Class returnType, boolean mustBePrivate)
   {
 outer:
-    for(int i = 0; i < methods.length; i++)
+    for (int i = 0; i < methods.length; i++)
     {
-	if(methods[i].getName().equals(name) &&
-	   methods[i].getReturnType() == returnType)
+	final Method m = methods[i];
+        int mods = m.getModifiers();
+        if (Modifier.isStatic(mods)
+            || (mustBePrivate && !Modifier.isPrivate(mods)))
+        {
+            continue;
+        }
+
+	if (m.getName().equals(name)
+	   && m.getReturnType() == returnType)
 	{
-	    Class[] mp = methods[i].getParameterTypes();
-	    if(mp.length == params.length)
+	    Class[] mp = m.getParameterTypes();
+	    if (mp.length == params.length)
 	    {
-		for(int j = 0; j < mp.length; j++)
+		for (int j = 0; j < mp.length; j++)
 		{
-		    if(mp[j] != params[j])
+		    if (mp[j] != params[j])
 		    {
 			continue outer;
 		    }
 		}
-		final Method m = methods[i];
-		SetAccessibleAction setAccessible = new SetAccessibleAction(m);
-		AccessController.doPrivileged(setAccessible);
+		AccessController.doPrivileged(new SetAccessibleAction(m));
 		return m;
 	    }
 	}
@@ -485,9 +491,14 @@
     Method[] methods = forClass().getDeclaredMethods();
     readObjectMethod = findMethod(methods, "readObject",
 				  new Class[] { ObjectInputStream.class },
-				  Void.TYPE);
+				  Void.TYPE, true);
+    writeObjectMethod = findMethod(methods, "writeObject",
+                                   new Class[] { ObjectOutputStream.class },
+                                   Void.TYPE, true);
     readResolveMethod = findMethod(methods, "readResolve",
-				   new Class[0], Object.class);
+				   new Class[0], Object.class, false);
+    writeReplaceMethod = findMethod(methods, "writeReplace",
+                                    new Class[0], Object.class, false);
   }
 
   private ObjectStreamClass(Class cl)
@@ -517,20 +528,8 @@
       // only set this bit if CL is NOT Externalizable
       flags |= ObjectStreamConstants.SC_SERIALIZABLE;
 
-    try
-      {
-	Method writeMethod = cl.getDeclaredMethod("writeObject",
-						  writeMethodArgTypes);
-	int modifiers = writeMethod.getModifiers();
-
-	if (writeMethod.getReturnType() == Void.TYPE
-	    && Modifier.isPrivate(modifiers)
-	    && !Modifier.isStatic(modifiers))
-	  flags |= ObjectStreamConstants.SC_WRITE_METHOD;
-      }
-    catch(NoSuchMethodException oh_well)
-      {
-      }
+    if (writeObjectMethod != null)
+      flags |= ObjectStreamConstants.SC_WRITE_METHOD;
   }
 
 
@@ -884,6 +883,8 @@
 
   Method readObjectMethod;
   Method readResolveMethod;
+  Method writeReplaceMethod;
+  Method writeObjectMethod;
   boolean realClassIsSerializable;
   boolean realClassIsExternalizable;
   ObjectStreamField[] fieldMapping;




More information about the kaffe mailing list