harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r648977 - in /harmony/enhanced/classlib/trunk/modules/luni: META-INF/ src/main/java/java/io/ src/main/native/luni/shared/ src/main/native/luni/unix/ src/main/native/luni/windows/
Date Thu, 17 Apr 2008 06:43:59 GMT
Author: tonywu
Date: Wed Apr 16 23:43:55 2008
New Revision: 648977

URL: http://svn.apache.org/viewvc?rev=648977&view=rev
Log:
Apply patch for HARMONY-5722 ([classlib][luni][performance] ObjectInputStream/ObjectOutputStream
can use optimized API for accessing fields)

Removed:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/oos.c
Modified:
    harmony/enhanced/classlib/trunk/modules/luni/META-INF/MANIFEST.MF
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamField.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/ois.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/makefile
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile

Modified: harmony/enhanced/classlib/trunk/modules/luni/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/META-INF/MANIFEST.MF?rev=648977&r1=648976&r2=648977&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/META-INF/MANIFEST.MF (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/META-INF/MANIFEST.MF Wed Apr 16 23:43:55
2008
@@ -29,6 +29,7 @@
  javax.net.ssl,
  javax.xml.parsers,
  org.apache.harmony.awt.gl.image,
+ org.apache.harmony.misc.accessors,
  org.apache.harmony.nio,
  org.apache.harmony.testframework.serialization;hy_usage=test;resolution:=optional,
  org.w3c.dom,

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java?rev=648977&r1=648976&r2=648977&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
Wed Apr 16 23:43:55 2008
@@ -30,6 +30,9 @@
 import java.util.HashMap;
 import java.util.Iterator;
 
+import org.apache.harmony.misc.accessors.ObjectAccessor;
+import org.apache.harmony.misc.accessors.AccessorFactory;
+
 import org.apache.harmony.kernel.vm.VM;
 import org.apache.harmony.luni.internal.nls.Messages;
 import org.apache.harmony.luni.util.Msg;
@@ -119,6 +122,8 @@
         PRIMITIVE_CLASSES.put("double", double.class); //$NON-NLS-1$
     }
 
+    private ObjectAccessor accessor = AccessorFactory.getObjectAccessor();
+
     // Internal type used to keep track of validators & corresponding priority
     static class InputValidationDesc {
         ObjectInputValidation validator;
@@ -1124,41 +1129,61 @@
         }
 
         for (ObjectStreamField fieldDesc : fields) {
+
+            // get associated Field 
+            long fieldID = fieldDesc.getFieldID(accessor, declaringClass);
+
             // Code duplication starts, just because Java is typed
             if (fieldDesc.isPrimitive()) {
                 try {
                     switch (fieldDesc.getTypeCode()) {
                         case 'B':
-                            setField(obj, declaringClass, fieldDesc.getName(),
-                                    input.readByte());
+                            byte srcByte = input.readByte();
+                            if (fieldID != ObjectStreamField.FIELD_IS_ABSENT) { 
+                                accessor.setByte(obj, fieldID, srcByte);
+                            };
                             break;
                         case 'C':
-                            setField(obj, declaringClass, fieldDesc.getName(),
-                                    input.readChar());
+                            char srcChar = input.readChar();
+                            if (fieldID != ObjectStreamField.FIELD_IS_ABSENT) { 
+                                accessor.setChar(obj, fieldID, srcChar);
+                            }
                             break;
                         case 'D':
-                            setField(obj, declaringClass, fieldDesc.getName(),
-                                    input.readDouble());
+                            double srcDouble = input.readDouble();
+                            if (fieldID != ObjectStreamField.FIELD_IS_ABSENT) { 
+                                accessor.setDouble(obj, fieldID, srcDouble);
+                            }
                             break;
                         case 'F':
-                            setField(obj, declaringClass, fieldDesc.getName(),
-                                    input.readFloat());
+                            float srcFloat = input.readFloat();
+                            if (fieldID != ObjectStreamField.FIELD_IS_ABSENT) { 
+                                accessor.setFloat(obj, fieldID, srcFloat);
+                            }
                             break;
                         case 'I':
-                            setField(obj, declaringClass, fieldDesc.getName(),
-                                    input.readInt());
+                            int srcInt = input.readInt();
+                            if (fieldID != ObjectStreamField.FIELD_IS_ABSENT) { 
+                                accessor.setInt(obj, fieldID, srcInt);
+                            }
                             break;
                         case 'J':
-                            setField(obj, declaringClass, fieldDesc.getName(),
-                                    input.readLong());
+                            long srcLong = input.readLong();
+                            if (fieldID != ObjectStreamField.FIELD_IS_ABSENT) { 
+                                accessor.setLong(obj, fieldID, srcLong);
+                            }
                             break;
                         case 'S':
-                            setField(obj, declaringClass, fieldDesc.getName(),
-                                    input.readShort());
+                            short srcShort = input.readShort();
+                            if (fieldID != ObjectStreamField.FIELD_IS_ABSENT) { 
+                                accessor.setShort(obj, fieldID, srcShort);
+                            }
                             break;
                         case 'Z':
-                            setField(obj, declaringClass, fieldDesc.getName(),
-                                    input.readBoolean());
+                            boolean srcBoolean = input.readBoolean();
+                            if (fieldID != ObjectStreamField.FIELD_IS_ABSENT) { 
+                                accessor.setBoolean(obj, fieldID, srcBoolean);
+                            }
                             break;
                         default:
                             throw new StreamCorruptedException(Msg.getString(
@@ -1195,8 +1220,9 @@
                                                     + fieldName }));
                         }
                         try {
-                            objSetField(obj, declaringClass, fieldName, fieldDesc
-                                    .getTypeString(), toSet);
+                            if (fieldID != ObjectStreamField.FIELD_IS_ABSENT) { 
+                                accessor.setObject(obj, fieldID, toSet);
+                            }
                         } catch (NoSuchFieldError e) {
                             // Ignored
                         }
@@ -2432,250 +2458,6 @@
         // By default no object replacement. Subclasses can override
         return object;
     }
-
-    /**
-     * Set a given declared field named <code>fieldName</code> of
-     * <code>instance</code> to the new <code>byte</code> value
-     * <code>value</code>.
-     * 
-     * This method could be implemented non-natively on top of java.lang.reflect
-     * implementations that support the <code>setAccessible</code> API, at the
-     * expense of extra object creation (java.lang.reflect.Field). Otherwise
-     * Serialization could not set private fields, except by the use of a native
-     * method like this one.
-     * 
-     * @param instance
-     *            Object whose field to set
-     * @param declaringClass
-     *            <code>instance</code>'s declaring class
-     * @param fieldName
-     *            Name of the field to set
-     * @param value
-     *            New value for the field
-     * 
-     * @throws NoSuchFieldError
-     *             If the field does not exist.
-     */
-    private static native void setField(Object instance,
-            Class<?> declaringClass, String fieldName, byte value)
-            throws NoSuchFieldError;
-
-    /**
-     * Set a given declared field named <code>fieldName</code> of
-     * <code>instance</code> to the new <code>char</code> value
-     * <code>value</code>.
-     * 
-     * This method could be implemented non-natively on top of java.lang.reflect
-     * implementations that support the <code>setAccessible</code> API, at the
-     * expense of extra object creation (java.lang.reflect.Field). Otherwise
-     * Serialization could not set private fields, except by the use of a native
-     * method like this one.
-     * 
-     * @param instance
-     *            Object whose field to set
-     * @param declaringClass
-     *            <code>instance</code>'s declaring class
-     * @param fieldName
-     *            Name of the field to set
-     * @param value
-     *            New value for the field
-     * 
-     * @throws NoSuchFieldError
-     *             If the field does not exist.
-     */
-    private static native void setField(Object instance,
-            Class<?> declaringClass, String fieldName, char value)
-            throws NoSuchFieldError;
-
-    /**
-     * Set a given declared field named <code>fieldName</code> of
-     * <code>instance</code> to the new <code>double</code> value
-     * <code>value</code>.
-     * 
-     * This method could be implemented non-natively on top of java.lang.reflect
-     * implementations that support the <code>setAccessible</code> API, at the
-     * expense of extra object creation (java.lang.reflect.Field). Otherwise
-     * Serialization could not set private fields, except by the use of a native
-     * method like this one.
-     * 
-     * @param instance
-     *            Object whose field to set
-     * @param declaringClass
-     *            <code>instance</code>'s declaring class
-     * @param fieldName
-     *            Name of the field to set
-     * @param value
-     *            New value for the field
-     * 
-     * @throws NoSuchFieldError
-     *             If the field does not exist.
-     */
-    private static native void setField(Object instance,
-            Class<?> declaringClass, String fieldName, double value)
-            throws NoSuchFieldError;
-
-    /**
-     * Set a given declared field named <code>fieldName</code> of
-     * <code>instance</code> to the new <code>float</code> value
-     * <code>value</code>.
-     * 
-     * This method could be implemented non-natively on top of java.lang.reflect
-     * implementations that support the <code>setAccessible</code> API, at the
-     * expense of extra object creation (java.lang.reflect.Field). Otherwise
-     * Serialization could not set private fields, except by the use of a native
-     * method like this one.
-     * 
-     * @param instance
-     *            Object whose field to set
-     * @param declaringClass
-     *            <code>instance</code>'s declaring class
-     * @param fieldName
-     *            Name of the field to set
-     * @param value
-     *            New value for the field
-     * 
-     * @throws NoSuchFieldError
-     *             If the field does not exist.
-     */
-    private static native void setField(Object instance,
-            Class<?> declaringClass, String fieldName, float value)
-            throws NoSuchFieldError;
-
-    /**
-     * Set a given declared field named <code>fieldName</code> of
-     * <code>instance</code> to the new <code>int</code> value
-     * <code>value</code>.
-     * 
-     * This method could be implemented non-natively on top of java.lang.reflect
-     * implementations that support the <code>setAccessible</code> API, at the
-     * expense of extra object creation (java.lang.reflect.Field). Otherwise
-     * Serialization could not set private fields, except by the use of a native
-     * method like this one.
-     * 
-     * @param instance
-     *            Object whose field to set
-     * @param declaringClass
-     *            <code>instance</code>'s declaring class
-     * @param fieldName
-     *            Name of the field to set
-     * @param value
-     *            New value for the field
-     * 
-     * @throws NoSuchFieldError
-     *             If the field does not exist.
-     */
-    private static native void setField(Object instance,
-            Class<?> declaringClass, String fieldName, int value)
-            throws NoSuchFieldError;
-
-    /**
-     * Set a given declared field named <code>fieldName</code> of
-     * <code>instance</code> to the new <code>long</code> value
-     * <code>value</code>.
-     * 
-     * This method could be implemented non-natively on top of java.lang.reflect
-     * implementations that support the <code>setAccessible</code> API, at the
-     * expense of extra object creation (java.lang.reflect.Field). Otherwise
-     * Serialization could not set private fields, except by the use of a native
-     * method like this one.
-     * 
-     * @param instance
-     *            Object whose field to set
-     * @param declaringClass
-     *            <code>instance</code>'s declaring class
-     * @param fieldName
-     *            Name of the field to set
-     * @param value
-     *            New value for the field
-     * 
-     * @throws NoSuchFieldError
-     *             If the field does not exist.
-     */
-    private static native void setField(Object instance,
-            Class<?> declaringClass, String fieldName, long value)
-            throws NoSuchFieldError;
-
-    /**
-     * Set a given declared field named <code>fieldName</code> of
-     * <code>instance</code> to the new value <code>value</code>.
-     * 
-     * This method could be implemented non-natively on top of java.lang.reflect
-     * implementations that support the <code>setAccessible</code> API, at the
-     * expense of extra object creation (java.lang.reflect.Field). Otherwise
-     * Serialization could not set private fields, except by the use of a native
-     * method like this one.
-     * 
-     * @param instance
-     *            Object whose field to set
-     * @param declaringClass
-     *            Class which declares the field
-     * @param fieldName
-     *            Name of the field to set
-     * @param fieldTypeName
-     *            Name of the class defining the type of the field
-     * @param value
-     *            New value for the field
-     * 
-     * @throws NoSuchFieldError
-     *             If the field does not exist.
-     */
-    private static native void objSetField(Object instance,
-            Class<?> declaringClass, String fieldName, String fieldTypeName,
-            Object value) throws NoSuchFieldError;
-
-    /**
-     * Set a given declared field named <code>fieldName</code> of
-     * <code>instance</code> to the new <code>short</code> value
-     * <code>value</code>.
-     * 
-     * This method could be implemented non-natively on top of java.lang.reflect
-     * implementations that support the <code>setAccessible</code> API, at the
-     * expense of extra object creation (java.lang.reflect.Field). Otherwise
-     * Serialization could not set private fields, except by the use of a native
-     * method like this one.
-     * 
-     * @param instance
-     *            Object whose field to set
-     * @param declaringClass
-     *            <code>instance</code>'s declaring class
-     * @param fieldName
-     *            Name of the field to set
-     * @param value
-     *            New value for the field
-     * 
-     * @throws NoSuchFieldError
-     *             If the field does not exist.
-     */
-    private static native void setField(Object instance,
-            Class<?> declaringClass, String fieldName, short value)
-            throws NoSuchFieldError;
-
-    /**
-     * Set a given declared field named <code>fieldName</code> of
-     * <code>instance</code> to the new <code>boolean</code> value
-     * <code>value</code>.
-     * 
-     * This method could be implemented non-natively on top of java.lang.reflect
-     * implementations that support the <code>setAccessible</code> API, at the
-     * expense of extra object creation (java.lang.reflect.Field). Otherwise
-     * Serialization could not set private fields, except by the use of a native
-     * method like this one.
-     * 
-     * @param instance
-     *            Object whose field to set
-     * @param declaringClass
-     *            <code>instance</code>'s declaring class
-     * @param fieldName
-     *            Name of the field to set
-     * @param value
-     *            New value for the field
-     * 
-     * @throws NoSuchFieldError
-     *             If the field does not exist.
-     */
-    private static native void setField(Object instance,
-            Class<?> declaringClass, String fieldName, boolean value)
-            throws NoSuchFieldError;
 
     /**
      * Skips <code>length</code> bytes of primitive data from the receiver. It

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java?rev=648977&r1=648976&r2=648977&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
Wed Apr 16 23:43:55 2008
@@ -22,6 +22,9 @@
 import java.lang.reflect.Proxy;
 import java.util.IdentityHashMap;
 
+import org.apache.harmony.misc.accessors.ObjectAccessor;
+import org.apache.harmony.misc.accessors.AccessorFactory;
+
 import org.apache.harmony.luni.util.Msg;
 
 /**
@@ -108,7 +111,9 @@
      * Allows the receiver to decide if it needs to call writeObjectOverride
      */
     private boolean subclassOverridingImplementation;
+    
 
+    private ObjectAccessor accessor = AccessorFactory.getObjectAccessor();
 
     /**
      * Inner class to provide access to serializable fields
@@ -416,195 +421,6 @@
         output.flush();
     }
 
-    /**
-     * Get the value of field named
-     * <code>fieldName<code> of object <code>instance</code>. The
-     * field is declared by class <code>declaringClass</code>. The field is supposed
to be
-     * a boolean.
-     *
-     * This method could be implemented non-natively on top of java.lang.reflect implementations
-     * that support the <code>setAccessible</code> API, at the expense of extra
object creation
-     * (java.lang.reflect.Field). Otherwise Serialization could not fetch private fields,
except
-     * by the use of a native method like this one.
-     *
-     * @param		instance		Object whose field value we want to fetch
-     * @param		declaringClass	The class that declares the field
-     * @param		fieldName		Name of the field we want to fetch
-     * @return		the value of the field
-     *
-     * @throws		NoSuchFieldError If the field does not exist.
-     */
-    private static native boolean getFieldBool(Object instance,
-            Class<?> declaringClass, String fieldName);
-
-    /**
-     * Get the value of field named
-     * <code>fieldName<code> of object <code>instance</code>. The
-     * field is declared by class <code>declaringClass</code>. The field is supposed
to be
-     * a byte
-     *
-     * This method could be implemented non-natively on top of java.lang.reflect implementations
-     * that support the <code>setAccessible</code> API, at the expense of extra
object creation
-     * (java.lang.reflect.Field). Otherwise Serialization could not fetch private fields,
except
-     * by the use of a native method like this one.
-     *
-     * @param		instance		Object whose field value we want to fetch
-     * @param		declaringClass	The class that declares the field
-     * @param		fieldName		Name of the field we want to fetch
-     * @return		the value of the field
-     *
-     * @throws		NoSuchFieldError If the field does not exist.
-     */
-    private static native byte getFieldByte(Object instance,
-            Class<?> declaringClass, String fieldName);
-
-    /**
-     * Get the value of field named
-     * <code>fieldName<code> of object <code>instance</code>. The
-     * field is declared by class <code>declaringClass</code>. The field is supposed
to be
-     * a char.
-     *
-     * This method could be implemented non-natively on top of java.lang.reflect implementations
-     * that support the <code>setAccessible</code> API, at the expense of extra
object creation
-     * (java.lang.reflect.Field). Otherwise Serialization could not fetch private fields,
except
-     * by the use of a native method like this one.
-     *
-     * @param		instance		Object whose field value we want to fetch
-     * @param		declaringClass	The class that declares the field
-     * @param		fieldName		Name of the field we want to fetch
-     * @return		the value of the field
-     *
-     * @throws		NoSuchFieldError If the field does not exist.
-     */
-    private static native char getFieldChar(Object instance,
-            Class<?> declaringClass, String fieldName);
-
-    /**
-     * Get the value of field named
-     * <code>fieldName<code> of object <code>instance</code>. The
-     * field is declared by class <code>declaringClass</code>. The field is supposed
to be
-     * a double.
-     *
-     * This method could be implemented non-natively on top of java.lang.reflect implementations
-     * that support the <code>setAccessible</code> API, at the expense of extra
object creation
-     * (java.lang.reflect.Field). Otherwise Serialization could not fetch private fields,
except
-     * by the use of a native method like this one.
-     *
-     * @param		instance		Object whose field value we want to fetch
-     * @param		declaringClass	The class that declares the field
-     * @param		fieldName		Name of the field we want to fetch
-     * @return		the value of the field
-     *
-     * @throws		NoSuchFieldError If the field does not exist.
-     */
-    private static native double getFieldDouble(Object instance,
-            Class<?> declaringClass, String fieldName);
-
-    /**
-     * Get the value of field named
-     * <code>fieldName<code> of object <code>instance</code>. The
-     * field is declared by class <code>declaringClass</code>. The field is supposed
to be
-     * a float.
-     *
-     * This method could be implemented non-natively on top of java.lang.reflect implementations
-     * that support the <code>setAccessible</code> API, at the expense of extra
object creation
-     * (java.lang.reflect.Field). Otherwise Serialization could not fetch private fields,
except
-     * by the use of a native method like this one.
-     *
-     * @param		instance		Object whose field value we want to fetch
-     * @param		declaringClass	The class that declares the field
-     * @param		fieldName		Name of the field we want to fetch
-     * @return		the value of the field
-     *
-     * @throws		NoSuchFieldError If the field does not exist.
-     */
-    private static native float getFieldFloat(Object instance,
-            Class<?> declaringClass, String fieldName);
-
-    /**
-     * Get the value of field named
-     * <code>fieldName<code> of object <code>instance</code>. The
-     * field is declared by class <code>declaringClass</code>. The field is supposed
to be
-     * an int.
-     *
-     * This method could be implemented non-natively on top of java.lang.reflect implementations
-     * that support the <code>setAccessible</code> API, at the expense of extra
object creation
-     * (java.lang.reflect.Field). Otherwise Serialization could not fetch private fields,
except
-     * by the use of a native method like this one.
-     *
-     * @param		instance		Object whose field value we want to fetch
-     * @param		declaringClass	The class that declares the field
-     * @param		fieldName		Name of the field we want to fetch
-     * @return		the value of the field
-     *
-     * @throws		NoSuchFieldError If the field does not exist.
-     */
-    private static native int getFieldInt(Object instance,
-            Class<?> declaringClass, String fieldName);
-
-    /**
-     * Get the value of field named
-     * <code>fieldName<code> of object <code>instance</code>. The
-     * field is declared by class <code>declaringClass</code>. The field is supposed
to be
-     * a long.
-     *
-     * This method could be implemented non-natively on top of java.lang.reflect implementations
-     * that support the <code>setAccessible</code> API, at the expense of extra
object creation
-     * (java.lang.reflect.Field). Otherwise Serialization could not fetch private fields,
except
-     * by the use of a native method like this one.
-     *
-     * @param		instance		Object whose field value we want to fetch
-     * @param		declaringClass	The class that declares the field
-     * @param		fieldName		Name of the field we want to fetch
-     * @return		the value of the field
-     *
-     * @throws		NoSuchFieldError If the field does not exist.
-     */
-    private static native long getFieldLong(Object instance,
-            Class<?> declaringClass, String fieldName);
-
-    /**
-     * Get the value of field named
-     * <code>fieldName<code> of object <code>instance</code>. The
-     * field is declared by class <code>declaringClass</code>. The field is supposed
to be
-     * an Object type whose name is <code>fieldTypeName</code>.
-     *
-     * This method could be implemented non-natively on top of java.lang.reflect implementations
-     * that support the <code>setAccessible</code> API, at the expense of extra
object creation
-     * (java.lang.reflect.Field). Otherwise Serialization could not fetch private fields,
except
-     * by the use of a native method like this one.
-     *
-     * @param		instance		Object whose field value we want to fetch
-     * @param		declaringClass	The class that declares the field
-     * @param		fieldName		Name of the field we want to fetch
-     * @param		fieldTypeName	Name of the class that defines the type of this field
-     * @return		the value of the field
-     *
-     * @throws		NoSuchFieldError If the field does not exist.
-     */
-    private static native Object getFieldObj(Object instance,
-            Class<?> declaringClass, String fieldName, String fieldTypeName);
-
-    /**
-     * Get the value of field named
-     * <code>fieldName<code> of object <code>instance</code>. The
-     * field is declared by class <code>declaringClass</code>. The field is supposed
to be
-     * a short.
-     *
-     * This method could be implemented non-natively on top of java.lang.reflect implementations
-     * that support the <code>setAccessible</code> API, at the expense of extra
object creation
-     * (java.lang.reflect.Field). Otherwise Serialization could not fetch private fields,
except
-     * by the use of a native method like this one.
-     *
-     * @param		instance		Object whose field value we want to fetch
-     * @param		declaringClass	The class that declares the field
-     * @param		fieldName		Name of the field we want to fetch
-     * @return		the value of the field
-     *
-     * @throws		NoSuchFieldError If the field does not exist.
-     */
-    private static native short getFieldShort(Object instance,
-            Class<?> declaringClass, String fieldName);
 
     /**
      * Return the next <code>int</code> handle to be used to indicate cyclic
@@ -1160,6 +976,7 @@
         }
     }
 
+
     /**
      * Writes a collection of field values for the fields described by class
      * descriptor <code>classDesc</code> (an <code>ObjectStreamClass</code>).
@@ -1182,43 +999,38 @@
             throws IOException {
         ObjectStreamField[] fields = classDesc.fields();
         Class<?> declaringClass = classDesc.forClass();
-        for (int i = 0; i < fields.length; i++) {
+        for(ObjectStreamField fieldDesc : fields) {
             try {
+                
+                // get associated Field 
+                long fieldID = fieldDesc.getFieldID(accessor, declaringClass);
+
                 // Code duplication starts, just because Java is typed
-                ObjectStreamField fieldDesc = fields[i];
                 if (fieldDesc.isPrimitive()) {
                     switch (fieldDesc.getTypeCode()) {
                         case 'B':
-                            output.writeByte(getFieldByte(obj, declaringClass,
-                                    fieldDesc.getName()));
+                            output.writeByte(accessor.getByte(obj, fieldID));
                             break;
                         case 'C':
-                            output.writeChar(getFieldChar(obj, declaringClass,
-                                    fieldDesc.getName()));
+                            output.writeChar(accessor.getChar(obj, fieldID));
                             break;
                         case 'D':
-                            output.writeDouble(getFieldDouble(obj,
-                                    declaringClass, fieldDesc.getName()));
+                            output.writeDouble(accessor.getDouble(obj, fieldID));
                             break;
                         case 'F':
-                            output.writeFloat(getFieldFloat(obj,
-                                    declaringClass, fieldDesc.getName()));
+                            output.writeFloat(accessor.getFloat(obj, fieldID));
                             break;
                         case 'I':
-                            output.writeInt(getFieldInt(obj, declaringClass,
-                                    fieldDesc.getName()));
+                            output.writeInt(accessor.getInt(obj, fieldID));
                             break;
                         case 'J':
-                            output.writeLong(getFieldLong(obj, declaringClass,
-                                    fieldDesc.getName()));
+                            output.writeLong(accessor.getLong(obj, fieldID));
                             break;
                         case 'S':
-                            output.writeShort(getFieldShort(obj,
-                                    declaringClass, fieldDesc.getName()));
+                            output.writeShort(accessor.getShort(obj, fieldID));
                             break;
                         case 'Z':
-                            output.writeBoolean(getFieldBool(obj,
-                                    declaringClass, fieldDesc.getName()));
+                            output.writeBoolean(accessor.getBoolean(obj, fieldID));
                             break;
                         default:
                             throw new IOException(
@@ -1227,12 +1039,11 @@
                     }
                 } else {
                     // Object type (array included).
-                    Object field = getFieldObj(obj, declaringClass, fieldDesc
-                            .getName(), fieldDesc.getTypeString());
+                    Object objField = accessor.getObject(obj, fieldID);
                     if (fieldDesc.isUnshared()) {
-                        writeUnshared(field);
+                        writeUnshared(objField);
                     } else {
-                        writeObject(field);
+                        writeObject(objField);
                     }
                 }
             } catch (NoSuchFieldError nsf) {
@@ -2013,8 +1824,8 @@
         // Only write field "name" for enum class, which is the second field of
         // enum, that is fields[1]. Ignore all non-fields and fields.length < 2
         if (null != fields && fields.length > 1) {
-            String str = (String) getFieldObj(object, declaringClass, fields[1]
-                    .getName(), fields[1].getTypeString());
+            String str = (String) accessor.getObject(object, fields[1].getFieldID(accessor,
declaringClass));
+
             Integer strhandle = null;
             if (!unshared) {
                 strhandle = dumpCycle(str);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamField.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamField.java?rev=648977&r1=648976&r2=648977&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamField.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamField.java
Wed Apr 16 23:43:55 2008
@@ -21,6 +21,8 @@
 import java.util.Arrays;
 import java.util.Comparator;
 
+import org.apache.harmony.misc.accessors.ObjectAccessor;
+
 /**
  * This class represents object fields that are saved to the stream, by
  * serialization. Classes can define the collection of fields to be dumped,
@@ -31,6 +33,9 @@
  */
 public class ObjectStreamField implements Comparable<Object> {
 
+    static final int FIELD_IS_NOT_RESOLVED = -1;
+    static final int FIELD_IS_ABSENT = -2;
+
     // Declared name of the field
     private String name;
 
@@ -46,6 +51,21 @@
     private boolean unshared;
 
     private boolean isDeserialized;
+
+    private long assocFieldID = FIELD_IS_NOT_RESOLVED;
+
+    long getFieldID(ObjectAccessor accessor, Class<?> declaringClass) {
+        if (assocFieldID != FIELD_IS_NOT_RESOLVED) {
+            return assocFieldID;
+        } else {
+            try {  
+                assocFieldID = accessor.getFieldID(declaringClass, name);
+            } catch(NoSuchFieldError e) {
+                assocFieldID = FIELD_IS_ABSENT;
+            }
+            return assocFieldID;
+        }
+    }
 
     /**
      * Constructs an ObjectStreamField with the given name and the given type

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/ois.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/ois.c?rev=648977&r1=648976&r2=648977&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/ois.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/ois.c Wed Apr
16 23:43:55 2008
@@ -17,148 +17,6 @@
 
 #include "jni.h"
 
-JNIEXPORT void JNICALL
-  Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2Z
-  (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass,
-   jobject fieldName, jboolean newValue)
-{
-  const char *fieldNameInC;
-  jfieldID fid;
-  if (targetObject == NULL)
-    return;
-  fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
-  fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "Z");
-  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
-
-  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real
value */
-  if (fid != 0)
-    {
-      (*env)->SetBooleanField (env, targetObject, fid, newValue);
-    }
-}
-
-JNIEXPORT void JNICALL
-  Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2C
-  (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass,
-   jobject fieldName, jchar newValue)
-{
-  const char *fieldNameInC;
-  jfieldID fid;
-  if (targetObject == NULL)
-    return;
-  fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
-  fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "C");
-  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
-
-  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real
value */
-  if (fid != 0)
-    {
-      (*env)->SetCharField (env, targetObject, fid, newValue);
-    }
-}
-
-JNIEXPORT void JNICALL
-  Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2I
-  (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass,
-   jobject fieldName, jint newValue)
-{
-  const char *fieldNameInC;
-  jfieldID fid;
-  if (targetObject == NULL)
-    return;
-  fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
-  fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "I");
-  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
-
-  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real
value */
-  if (fid != 0)
-    {
-      (*env)->SetIntField (env, targetObject, fid, newValue);
-    }
-}
-
-JNIEXPORT void JNICALL
-  Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2F
-  (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass,
-   jobject fieldName, jfloat newValue)
-{
-  const char *fieldNameInC;
-  jfieldID fid;
-  if (targetObject == NULL)
-    return;
-  fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
-  fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "F");
-  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
-
-  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real
value */
-  if (fid != 0)
-    {
-      (*env)->SetFloatField (env, targetObject, fid, newValue);
-    }
-}
-
-JNIEXPORT void JNICALL
-  Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2D
-  (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass,
-   jobject fieldName, jdouble newValue)
-{
-  const char *fieldNameInC;
-  jfieldID fid;
-  if (targetObject == NULL)
-    return;
-  fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
-  fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "D");
-  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
-
-  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real
value */
-  if (fid != 0)
-    {
-      (*env)->SetDoubleField (env, targetObject, fid, newValue);
-    }
-
-}
-
-JNIEXPORT void JNICALL
-  Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2S
-  (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass,
-   jobject fieldName, jshort newValue)
-{
-  const char *fieldNameInC;
-  jfieldID fid;
-  if (targetObject == NULL)
-    return;
-  fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
-  fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "S");
-  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
-
-  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real
value */
-  if (fid != 0)
-    {
-      (*env)->SetShortField (env, targetObject, fid, newValue);
-    }
-
-}
-
-JNIEXPORT void JNICALL
-  Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2J
-  (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass,
-   jobject fieldName, jlong newValue)
-{
-  const char *fieldNameInC;
-  jfieldID fid;
-  if (targetObject == NULL)
-    return;
-  fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
-  fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "J");
-  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
-
-  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real
value */
-  if (fid != 0)
-    {
-      (*env)->SetLongField (env, targetObject, fid, newValue);
-    }
-}
-
 JNIEXPORT jobject JNICALL
 Java_java_io_ObjectInputStream_newInstance (JNIEnv * env, jclass clazz,
                                             jobject instantiationClass,
@@ -186,48 +44,3 @@
 
 }
 
-JNIEXPORT void JNICALL
-  Java_java_io_ObjectInputStream_setField__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_String_2B
-  (JNIEnv * env, jclass clazz, jobject targetObject, jobject declaringClass,
-   jobject fieldName, jbyte newValue)
-{
-  const char *fieldNameInC;
-  jfieldID fid;
-  if (targetObject == NULL)
-    return;
-  fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
-  fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "B");
-  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
-
-  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real
value */
-  if (fid != 0)
-    {
-      (*env)->SetByteField (env, targetObject, fid, newValue);
-    }
-}
-
-JNIEXPORT void JNICALL
-Java_java_io_ObjectInputStream_objSetField (JNIEnv * env, jclass clazz,
-                                            jobject targetObject,
-                                            jobject declaringClass,
-                                            jobject fieldName,
-                                            jobject fieldTypeName,
-                                            jobject newValue)
-{
-  const char *fieldNameInC, *fieldTypeNameInC;
-  jfieldID fid;
-  if (targetObject == NULL)
-    return;
-  fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
-  fieldTypeNameInC = (*env)->GetStringUTFChars (env, fieldTypeName, NULL);
-  fid =
-    (*env)->GetFieldID (env, declaringClass, fieldNameInC, fieldTypeNameInC);
-  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
-  (*env)->ReleaseStringUTFChars (env, fieldTypeName, fieldTypeNameInC);
-
-  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real
value */
-  if (fid != 0)
-    {
-      (*env)->SetObjectField (env, targetObject, fid, newValue);
-    }
-}

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/makefile?rev=648977&r1=648976&r2=648977&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/makefile (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/makefile Wed Apr
16 23:43:55 2008
@@ -26,7 +26,7 @@
 
 BUILDFILES = \
 	$(SHAREDSUB)luni_copyright.o $(SHAREDSUB)file.o procimpl.o \
-	$(SHAREDSUB)oos.o $(SHAREDSUB)nethelp.o \
+	$(SHAREDSUB)nethelp.o \
 	$(SHAREDSUB)floatbits.o $(SHAREDSUB)ois.o \
 	helpers.o $(SHAREDSUB)math.o $(SHAREDSUB)luniglob.o \
 	$(SHAREDSUB)proxy.o \

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile?rev=648977&r1=648976&r2=648977&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile Wed
Apr 16 23:43:55 2008
@@ -27,7 +27,6 @@
 
 BUILDFILES = \
   $(SHAREDSUB)luni_copyright.obj $(SHAREDSUB)file.obj procimpl.obj \
-  $(SHAREDSUB)oos.obj \
   $(SHAREDSUB)nethelp.obj $(SHAREDSUB)floatbits.obj \
   $(SHAREDSUB)ois.obj helpers.obj $(SHAREDSUB)math.obj \
   $(SHAREDSUB)luniglob.obj $(SHAREDSUB)proxy.obj $(SHAREDSUB)netif.obj \



Mime
View raw message