You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by to...@apache.org on 2008/04/18 12:57:19 UTC
svn commit: r649457 - in
/harmony/enhanced/classlib/trunk/modules/luni/src/main:
java/java/io/ObjectInputStream.java java/java/io/ObjectStreamClass.java
native/luni/shared/ois.c native/luni/unix/makefile
native/luni/windows/makefile
Author: tonywu
Date: Fri Apr 18 03:57:06 2008
New Revision: 649457
URL: http://svn.apache.org/viewvc?rev=649457&view=rev
Log:
Apply patch for HARMONY-5756 ([classlib][luni][performance] ObjectInputStream must use accessors for instantiating objects)
Removed:
harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/ois.c
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
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/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=649457&r1=649456&r2=649457&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 Fri Apr 18 03:57:06 2008
@@ -495,25 +495,6 @@
}
/**
- * Create and return a new instance of class <code>instantiationClass</code>
- * but running the constructor defined in class
- * <code>constructorClass</code> (same as <code>instantiationClass</code>
- * or a superclass).
- *
- * Has to be native to avoid visibility rules and to be able to have
- * <code>instantiationClass</code> not the same as
- * <code>constructorClass</code> (no such API in java.lang.reflect).
- *
- * @param instantiationClass
- * The new object will be an instance of this class
- * @param constructorClass
- * The empty constructor to run will be in this class
- * @return the object created from <code>instantiationClass</code>
- */
- private static native Object newInstance(Class<?> instantiationClass,
- Class<?> constructorClass);
-
- /**
* Return the next <code>int</code> handle to be used to indicate cyclic
* references being loaded from the stream.
*
@@ -1860,51 +1841,9 @@
return Integer.valueOf(input.readInt());
}
- /**
- * Read a new object from the stream. It is assumed the object has not been
- * loaded yet (not a cyclic reference). Return the object read.
- *
- * If the object implements <code>Externalizable</code> its
- * <code>readExternal</code> is called. Otherwise, all fields described by
- * the class hierarchy are loaded. Each class can define how its declared
- * instance fields are loaded by defining a private method
- * <code>readObject</code>
- *
- * @param unshared
- * read the object unshared
- * @return the object read
- *
- * @throws IOException
- * If an IO exception happened when reading the object.
- * @throws OptionalDataException
- * If optional data could not be found when reading the object
- * graph
- * @throws ClassNotFoundException
- * If a class for one of the objects could not be found
- */
- private Object readNewObject(boolean unshared)
- throws OptionalDataException, ClassNotFoundException, IOException {
- ObjectStreamClass classDesc = readClassDesc();
-
- if (classDesc == null) {
- throw new InvalidClassException(Msg.getString("K00d1")); //$NON-NLS-1$
- }
+ private Class<?> resolveConstructorClass(Class<?> objectClass, boolean wasSerializable, boolean wasExternalizable)
+ throws OptionalDataException, ClassNotFoundException, IOException {
- Integer newHandle = Integer.valueOf(nextHandle());
-
- // Note that these values come from the Stream, and in fact it could be
- // that the classes have been changed so that the info below now
- // conflicts with the newer class
- boolean wasExternalizable = (classDesc.getFlags() & SC_EXTERNALIZABLE) > 0;
- boolean wasSerializable = (classDesc.getFlags() & SC_SERIALIZABLE) > 0;
-
- // Maybe we should cache the values above in classDesc ? It may be the
- // case that when reading classDesc we may need to read more stuff
- // depending on the values above
- Class<?> objectClass = classDesc.forClass();
-
- Object result, registeredResult = null;
- if (objectClass != null) {
// The class of the instance may not be the same as the class of the
// constructor to run
// This is the constructor to run if Externalizable
@@ -1964,9 +1903,66 @@
}
}
+ return constructorClass;
+ }
+
+ /**
+ * Read a new object from the stream. It is assumed the object has not been
+ * loaded yet (not a cyclic reference). Return the object read.
+ *
+ * If the object implements <code>Externalizable</code> its
+ * <code>readExternal</code> is called. Otherwise, all fields described by
+ * the class hierarchy are loaded. Each class can define how its declared
+ * instance fields are loaded by defining a private method
+ * <code>readObject</code>
+ *
+ * @param unshared
+ * read the object unshared
+ * @return the object read
+ *
+ * @throws IOException
+ * If an IO exception happened when reading the object.
+ * @throws OptionalDataException
+ * If optional data could not be found when reading the object
+ * graph
+ * @throws ClassNotFoundException
+ * If a class for one of the objects could not be found
+ */
+ private Object readNewObject(boolean unshared)
+ throws OptionalDataException, ClassNotFoundException, IOException {
+ ObjectStreamClass classDesc = readClassDesc();
+
+ if (classDesc == null) {
+ throw new InvalidClassException(Msg.getString("K00d1")); //$NON-NLS-1$
+ }
+
+ Integer newHandle = Integer.valueOf(nextHandle());
+
+ // Note that these values come from the Stream, and in fact it could be
+ // that the classes have been changed so that the info below now
+ // conflicts with the newer class
+ boolean wasExternalizable = (classDesc.getFlags() & SC_EXTERNALIZABLE) > 0;
+ boolean wasSerializable = (classDesc.getFlags() & SC_SERIALIZABLE) > 0;
+
+
+ // Maybe we should cache the values above in classDesc ? It may be the
+ // case that when reading classDesc we may need to read more stuff
+ // depending on the values above
+ Class<?> objectClass = classDesc.forClass();
+
+ Object result, registeredResult = null;
+ if (objectClass != null) {
+
+ long constructor = classDesc.getConstructor();
+ if (constructor == ObjectStreamClass.CONSTRUCTOR_IS_NOT_RESOLVED) {
+ constructor = accessor.getMethodID(resolveConstructorClass(objectClass, wasSerializable, wasExternalizable), null, new Class[0]);
+ classDesc.setConstructor(constructor);
+ }
+
// Now we know which class to instantiate and which constructor to
// run. We are allowed to run the constructor.
- result = newInstance(objectClass, constructorClass);
+ result = accessor.newInstance(objectClass, constructor, null);
+
registerObjectRead(result, newHandle, unshared);
registeredResult = result;
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java?rev=649457&r1=649456&r2=649457&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java Fri Apr 18 03:57:06 2008
@@ -58,6 +58,8 @@
// Name of the field that contains the SUID value (if present)
private static final String UID_FIELD_NAME = "serialVersionUID"; //$NON-NLS-1$
+ static final long CONSTRUCTOR_IS_NOT_RESOLVED = -1;
+
private static final int CLASS_MODIFIERS_MASK;
private static final int FIELD_MODIFIERS_MASK;
@@ -173,6 +175,17 @@
// Array of ObjectStreamField describing the serialized fields of this class
private transient ObjectStreamField[] loadFields;
+
+ // MethodID for deserialization constructor
+ private transient long constructor = CONSTRUCTOR_IS_NOT_RESOLVED;
+
+ void setConstructor(long newConstructor) {
+ constructor = newConstructor;
+ }
+
+ long getConstructor() {
+ return constructor;
+ }
/*
* If an ObjectStreamClass describes an Externalizable class, it (the
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=649457&r1=649456&r2=649457&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 Fri Apr 18 03:57:06 2008
@@ -27,7 +27,7 @@
BUILDFILES = \
$(SHAREDSUB)luni_copyright.o $(SHAREDSUB)file.o procimpl.o \
$(SHAREDSUB)nethelp.o \
- $(SHAREDSUB)floatbits.o $(SHAREDSUB)ois.o \
+ $(SHAREDSUB)floatbits.o \
helpers.o $(SHAREDSUB)math.o $(SHAREDSUB)luniglob.o \
$(SHAREDSUB)proxy.o \
$(SHAREDSUB)cbigint.o $(SHAREDSUB)dblparse.o $(SHAREDSUB)fltparse.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=649457&r1=649456&r2=649457&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 Fri Apr 18 03:57:06 2008
@@ -28,7 +28,7 @@
BUILDFILES = \
$(SHAREDSUB)luni_copyright.obj $(SHAREDSUB)file.obj procimpl.obj \
$(SHAREDSUB)nethelp.obj $(SHAREDSUB)floatbits.obj \
- $(SHAREDSUB)ois.obj helpers.obj $(SHAREDSUB)math.obj \
+ helpers.obj $(SHAREDSUB)math.obj \
$(SHAREDSUB)luniglob.obj $(SHAREDSUB)proxy.obj $(SHAREDSUB)netif.obj \
$(SHAREDSUB)cbigint.obj $(SHAREDSUB)dblparse.obj $(SHAREDSUB)fltparse.obj \
$(SHAREDSUB)process.obj $(SHAREDSUB)bigint.obj $(SHAREDSUB)osc.obj \