This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Object serialization patch


Hi,

I am about to commit this fix concerning serialization in classpath.
It will solve again some problems with serialPersistentFields (principally) which has been
introduced by the former optimization patch.

Guilhem.

ChangeLog entry:
2004-02-22  Guilhem Lavaux <guilhem@kaffe.org>

	* java/io/ObjectInputStream.java
	(readClassDescriptor): Fixed field sorting. Keep elements of the
	mapping non null.
	(readFields): Fixed main loop and base logic. Small reindentation.

	* java/io/ObjectStreamField.java
	(lookupField): New method to update the field reference.
	(setBooleanField, setByteField, setCharField, setShortField,
	setIntField, setLongField, setFloatField, setDoubleField,
	setObjectField): Improved exception reporting.

	* java/io/ObjectStreamClass.java
	(setClass, setFields): Call lookupField when building the field
	database.




Index: java/io/ObjectInputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/ObjectInputStream.java,v
retrieving revision 1.38
diff -u -r1.38 ObjectInputStream.java
--- java/io/ObjectInputStream.java	10 Feb 2004 07:28:09 -0000	1.38
+++ java/io/ObjectInputStream.java	22 Feb 2004 08:44:09 -0000
@@ -513,7 +513,7 @@
 	else
 	  {
 	    int comp_val =
-		real_fields[real_idx].compareTo (stream_fields[stream_idx]);
+		real_fields[real_idx].getName().compareTo (stream_fields[stream_idx].getName());
 
 	    if (comp_val < 0)
 	      {
@@ -527,21 +527,13 @@
 	      {
 		stream_field = stream_fields[stream_idx++];
 		real_field = real_fields[real_idx++];
-		if(stream_field.getType() != real_field.getType())
-		    throw new InvalidClassException
-			("invalid field type for " + real_field.getName() +
-			" in class " + name);
+		if (stream_field.getType() != real_field.getType())
+		  throw new InvalidClassException
+		    ("invalid field type for " + real_field.getName() +
+		     " in class " + name);
 	      }
 	  }
-	if (stream_field != null)
-	  {
-	    if (stream_field.getOffset() < 0)
-		stream_field = null;
-	    else if (!stream_field.isToSet())
-		real_field = null;
-	  }
-	if (real_field != null && !real_field.isToSet())
-	    real_field = null;
+
 	/* If some of stream_fields does not correspond to any of real_fields,
 	 * or the opposite, then fieldmapping will go short.
 	 */
@@ -550,7 +542,7 @@
 	    ObjectStreamField[] newfieldmapping =
 	      new ObjectStreamField[fieldmapping.length + 2];
 	    System.arraycopy(fieldmapping, 0,
-	      newfieldmapping, 0, fieldmapping.length);
+			     newfieldmapping, 0, fieldmapping.length);
 	    fieldmapping = newfieldmapping;
 	  }
 	fieldmapping[map_idx++] = stream_field;
@@ -1576,121 +1568,119 @@
       {
 	ObjectStreamField stream_field = fields[i];
 	ObjectStreamField real_field = fields[i + 1];
-	if(stream_field != null || real_field != null)
-	  {
-	    boolean read_value = stream_field != null;
-	    boolean set_value = real_field != null;
-	    String field_name;
-	    char type;
-	    if (stream_field != null)
-	      {
-		field_name = stream_field.getName();
-		type = stream_field.getTypeCode();
-	      }
-	    else
-	      {
-		field_name = real_field.getName();
-		type = real_field.getTypeCode();
-	      }
+	boolean read_value = (stream_field != null && stream_field.getOffset() >= 0 && stream_field.isToSet());
+	boolean set_value = (real_field != null && real_field.isToSet());
+	String field_name;
+	char type;
 
-	    switch(type)
-	      {
-		case 'Z':
-		  {
-		    boolean value =
-			read_value ? this.realInputStream.readBoolean() : false;
-		    if (dump && read_value && set_value)
-		    dumpElementln("  " + field_name + ": " + value);
-		    if (set_value)
-			real_field.setBooleanField(obj, value);
-		    break;
-		  }
-		case 'B':
-		  {
-		    byte value =
-			read_value ? this.realInputStream.readByte() : 0;
-		    if (dump && read_value && set_value)
-		    dumpElementln("  " + field_name + ": " + value);
-		    if (set_value)
-			real_field.setByteField(obj, value);
-		    break;
-		  }
-		case 'C':
-		  {
-		    char value =
-			read_value ? this.realInputStream.readChar(): 0;
-		    if (dump && read_value && set_value)
-		    dumpElementln("  " + field_name + ": " + value);
-		    if (set_value)
-			real_field.setCharField(obj, value);
-		    break;
-		  }
-		case 'D':
-		  {
-		    double value =
-			read_value ? this.realInputStream.readDouble() : 0;
-		    if (dump && read_value && set_value)
-		    dumpElementln("  " + field_name + ": " + value);
-		    if (set_value)
-			real_field.setDoubleField(obj, value);
-		    break;
-		  }
-		case 'F':
-		  {
-		    float value =
-			read_value ? this.realInputStream.readFloat() : 0;
-		    if (dump && read_value && set_value)
-		    dumpElementln("  " + field_name + ": " + value);
-		    if (set_value)
-			real_field.setFloatField(obj, value);
-		    break;
-		  }
-		case 'I':
-		  {
-		    int value =
-			read_value ? this.realInputStream.readInt() : 0;
-		    if (dump && read_value && set_value)
-		    dumpElementln("  " + field_name + ": " + value);
-		    if (set_value)
-			real_field.setIntField(obj, value);
-		    break;
-		  }
-		case 'J':
-		  {
-		    long value =
-			read_value ? this.realInputStream.readLong() : 0;
-		    if (dump && read_value && set_value)
-		    dumpElementln("  " + field_name + ": " + value);
-		    if (set_value)
-			real_field.setLongField(obj, value);
-		    break;
-		  }
-		case 'S':
-		  {
-		    short value =
-			read_value ? this.realInputStream.readShort() : 0;
-		    if (dump && read_value && set_value)
-		    dumpElementln("  " + field_name + ": " + value);
-		    if (set_value)
-			real_field.setShortField(obj, value);
-		    break;
-		  }
-		case 'L':
-		case '[':
-		  {
-		    Object value =
-			read_value ? readObject() : null;
-		    if (set_value)
-			real_field.setObjectField(obj, value);
-		    break;
-		  }
-		default:
-		    throw new InternalError("Invalid type code: " + type);
-	      }
+	if (stream_field != null)
+	  {
+	    field_name = stream_field.getName();
+	    type = stream_field.getTypeCode();
+	  }
+	else
+	  {
+	    field_name = real_field.getName();
+	    type = real_field.getTypeCode();
+	  }
+	
+	switch(type)
+	  {
+	  case 'Z':
+	    {
+	      boolean value =
+		read_value ? this.realInputStream.readBoolean() : false;
+	      if (dump && read_value && set_value)
+		dumpElementln("  " + field_name + ": " + value);
+	      if (set_value)
+		real_field.setBooleanField(obj, value);
+	      break;
+	    }
+	  case 'B':
+	    {
+	      byte value =
+		read_value ? this.realInputStream.readByte() : 0;
+	      if (dump && read_value && set_value)
+		dumpElementln("  " + field_name + ": " + value);
+	      if (set_value)
+		real_field.setByteField(obj, value);
+	      break;
+	    }
+	  case 'C':
+	    {
+	      char value =
+		read_value ? this.realInputStream.readChar(): 0;
+	      if (dump && read_value && set_value)
+		dumpElementln("  " + field_name + ": " + value);
+	      if (set_value)
+		real_field.setCharField(obj, value);
+	      break;
+	    }
+	  case 'D':
+	    {
+	      double value =
+		read_value ? this.realInputStream.readDouble() : 0;
+	      if (dump && read_value && set_value)
+		dumpElementln("  " + field_name + ": " + value);
+	      if (set_value)
+		real_field.setDoubleField(obj, value);
+	      break;
+	    }
+	  case 'F':
+	    {
+	      float value =
+		read_value ? this.realInputStream.readFloat() : 0;
+	      if (dump && read_value && set_value)
+		dumpElementln("  " + field_name + ": " + value);
+	      if (set_value)
+		real_field.setFloatField(obj, value);
+	      break;
+	    }
+	  case 'I':
+	    {
+	      int value =
+		read_value ? this.realInputStream.readInt() : 0;
+	      if (dump && read_value && set_value)
+		dumpElementln("  " + field_name + ": " + value);
+	      if (set_value)
+		real_field.setIntField(obj, value);
+	      break;
+	    }
+	  case 'J':
+	    {
+	      long value =
+		read_value ? this.realInputStream.readLong() : 0;
+	      if (dump && read_value && set_value)
+		dumpElementln("  " + field_name + ": " + value);
+	      if (set_value)
+		real_field.setLongField(obj, value);
+	      break;
+	    }
+	  case 'S':
+	    {
+	      short value =
+		read_value ? this.realInputStream.readShort() : 0;
+	      if (dump && read_value && set_value)
+		dumpElementln("  " + field_name + ": " + value);
+	      if (set_value)
+		real_field.setShortField(obj, value);
+	      break;
+	    }
+	  case 'L':
+	  case '[':
+	    {
+	      Object value =
+		read_value ? readObject() : null;
+	      if (set_value && stream_field != null)
+		real_field.setObjectField(obj, stream_field.getTypeString(), value);
+	      break;
+	    }
+	  default:
+	    throw new InternalError("Invalid type code: " + type);
 	  }
       }
   }
-
+  
   // Toggles writing primitive data to block-data buffer.
   private boolean setBlockDataMode (boolean on)
   {
@@ -1820,7 +1810,7 @@
   {
     if (Configuration.INIT_LOAD_LIBRARY)
       {
-	System.loadLibrary ("javaio");
+	System.loadLibrary ("io");
       }
   }
 }
Index: java/io/ObjectOutputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/ObjectOutputStream.java,v
retrieving revision 1.43
diff -u -r1.43 ObjectOutputStream.java
--- java/io/ObjectOutputStream.java	31 Dec 2003 10:28:19 -0000	1.43
+++ java/io/ObjectOutputStream.java	22 Feb 2004 08:44:09 -0000
@@ -1538,7 +1538,7 @@
   {
     if (Configuration.INIT_LOAD_LIBRARY)
       {
-        System.loadLibrary("javaio");
+        System.loadLibrary("io");
       }
   }
 }
Index: java/io/ObjectStreamClass.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/ObjectStreamClass.java,v
retrieving revision 1.30
diff -u -r1.30 ObjectStreamClass.java
--- java/io/ObjectStreamClass.java	2 Feb 2004 10:26:51 -0000	1.30
+++ java/io/ObjectStreamClass.java	22 Feb 2004 08:44:09 -0000
@@ -344,6 +344,7 @@
 		newFieldList[k] = exportedFields[j];
 		newFieldList[k].setPersistent(true);
 		newFieldList[k].setToSet(false);
+		newFieldList[k].lookupField(clazz);
 		j++;
 	      }
 	    else
@@ -554,6 +555,19 @@
 	    if (fields != null)
 	      {
 		Arrays.sort (fields);
+		// Retrieve field reference.
+		for (int i=0; i < fields.length; i++)
+		  {
+		    try
+		      {
+			fields[i].lookupField(cl);
+		      }
+		    catch (NoSuchFieldException _)
+		      {
+			fields[i].setToSet(false);
+		      }
+		  }
+		
 		calculateOffsets();
 		return;
 	      }
@@ -798,7 +812,7 @@
 
     fieldsArray = new ObjectStreamField[ o.length ];
     System.arraycopy(o, 0, fieldsArray, 0, o.length);
-    
+
     return fieldsArray;
   }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]