Commit a53785f9 by Warren Levy Committed by Warren Levy

ObjectInputStream.java (readObject): Added code to conditionally dump out the serialized data.

	* java/io/ObjectInputStream.java (readObject): Added code to
	conditionally dump out the serialized data.
	Handle ENDBLOCKDATA case a bit more gracefully since the current
	behavior doesn't seem to work as expected.
	(readStreamHeader): Added code for serialized data dumper.
	(readNextBlock): Ditto.
	(readFields): Ditto.
	(dump): New private static field for turning on/off dumper.
	(setDump): New native method.
	(dumpElement): New native method.
	(dumpElementln): New native method.
	* java/io/natObjectInputStream.cc (setDump): New method.
	(dumpElement): New method.
	(dumpElementln): New method.

Serialization dumper.  Enable by configuring with --enable-libgcj-debug
and calling java.io.ObjectInputStream.setDump(true) in your test program.
The output will be generated as the object is deserialized (i.e. the
readObject() method is executed).

From-SVN: r37223
parent 6678181b
2000-11-02 Warren Levy <warrenl@cygnus.com> 2000-11-02 Warren Levy <warrenl@cygnus.com>
* java/io/ObjectInputStream.java (readObject): Added code to
conditionally dump out the serialized data.
Handle ENDBLOCKDATA case a bit more gracefully since the current
behavior doesn't seem to work as expected.
(readStreamHeader): Added code for serialized data dumper.
(readNextBlock): Ditto.
(readFields): Ditto.
(dump): New private static field for turning on/off dumper.
(setDump): New native method.
(dumpElement): New native method.
(dumpElementln): New native method.
* java/io/natObjectInputStream.cc (setDump): New method.
(dumpElement): New method.
(dumpElementln): New method.
2000-11-02 Warren Levy <warrenl@cygnus.com>
* java/net/InetAddress.java (addr): Renamed from 'address'. * java/net/InetAddress.java (addr): Renamed from 'address'.
(address): New field to match Serialized Form doc. (address): New field to match Serialized Form doc.
(hostName): Renamed from 'hostname' to match Serialized Form doc. (hostName): Renamed from 'hostname' to match Serialized Form doc.
......
...@@ -106,24 +106,30 @@ public class ObjectInputStream extends InputStream ...@@ -106,24 +106,30 @@ public class ObjectInputStream extends InputStream
this.isDeserializing = true; this.isDeserializing = true;
// DEBUG ("MARKER ");
byte marker = this.realInputStream.readByte (); byte marker = this.realInputStream.readByte ();
dumpElement ("MARKER: 0x" + Integer.toHexString(marker) + " ");
switch (marker) switch (marker)
{ {
case TC_BLOCKDATA: case TC_BLOCKDATA:
case TC_BLOCKDATALONG: case TC_BLOCKDATALONG:
if (marker == TC_BLOCKDATALONG)
dumpElementln ("BLOCKDATALONG");
else
dumpElementln ("BLOCKDATA");
readNextBlock (marker); readNextBlock (marker);
throw new BlockDataException (this.blockDataBytes); throw new BlockDataException (this.blockDataBytes);
case TC_NULL: case TC_NULL:
dumpElementln ("NULL");
ret_val = null; ret_val = null;
break; break;
case TC_REFERENCE: case TC_REFERENCE:
{ {
// DEBUG ("REFERENCE "); dumpElement ("REFERENCE ");
Integer oid = new Integer (this.realInputStream.readInt ()); Integer oid = new Integer (this.realInputStream.readInt ());
dumpElementln (Integer.toHexString(oid.intValue()));
ret_val = ((ObjectIdentityWrapper) ret_val = ((ObjectIdentityWrapper)
this.objectLookupTable.get (oid)).object; this.objectLookupTable.get (oid)).object;
break; break;
...@@ -131,6 +137,7 @@ public class ObjectInputStream extends InputStream ...@@ -131,6 +137,7 @@ public class ObjectInputStream extends InputStream
case TC_CLASS: case TC_CLASS:
{ {
dumpElementln ("CLASS");
ObjectStreamClass osc = (ObjectStreamClass)readObject (); ObjectStreamClass osc = (ObjectStreamClass)readObject ();
Class clazz = osc.forClass (); Class clazz = osc.forClass ();
assignNewHandle (clazz); assignNewHandle (clazz);
...@@ -140,14 +147,15 @@ public class ObjectInputStream extends InputStream ...@@ -140,14 +147,15 @@ public class ObjectInputStream extends InputStream
case TC_CLASSDESC: case TC_CLASSDESC:
{ {
// DEBUG ("CLASSDESC NAME "); dumpElement ("CLASSDESC NAME=");
String name = this.realInputStream.readUTF (); String name = this.realInputStream.readUTF ();
// DEBUG ("UID "); dumpElement (name + "; UID=");
long uid = this.realInputStream.readLong (); long uid = this.realInputStream.readLong ();
// DEBUG ("FLAGS "); dumpElement (Long.toHexString(uid) + "; FLAGS=");
byte flags = this.realInputStream.readByte (); byte flags = this.realInputStream.readByte ();
// DEBUG ("FIELD COUNT "); dumpElement (Integer.toHexString(flags) + "; FIELD COUNT=");
short field_count = this.realInputStream.readShort (); short field_count = this.realInputStream.readShort ();
dumpElementln (Short.toString(field_count));
ObjectStreamField[] fields = new ObjectStreamField[field_count]; ObjectStreamField[] fields = new ObjectStreamField[field_count];
ObjectStreamClass osc = new ObjectStreamClass (name, uid, ObjectStreamClass osc = new ObjectStreamClass (name, uid,
...@@ -156,10 +164,11 @@ public class ObjectInputStream extends InputStream ...@@ -156,10 +164,11 @@ public class ObjectInputStream extends InputStream
for (int i=0; i < field_count; i++) for (int i=0; i < field_count; i++)
{ {
// DEBUG ("TYPE CODE "); dumpElement (" TYPE CODE=");
char type_code = (char)this.realInputStream.readByte (); char type_code = (char)this.realInputStream.readByte ();
// DEBUG ("FIELD NAME "); dumpElement (type_code + "; FIELD NAME=");
String field_name = this.realInputStream.readUTF (); String field_name = this.realInputStream.readUTF ();
dumpElementln (field_name);
String class_name; String class_name;
if (type_code == 'L' || type_code == '[') if (type_code == 'L' || type_code == '[')
...@@ -177,9 +186,9 @@ public class ObjectInputStream extends InputStream ...@@ -177,9 +186,9 @@ public class ObjectInputStream extends InputStream
osc.setClass (resolveClass (osc)); osc.setClass (resolveClass (osc));
setBlockDataMode (false); setBlockDataMode (false);
// DEBUG ("ENDBLOCKDATA ");
if (this.realInputStream.readByte () != TC_ENDBLOCKDATA) if (this.realInputStream.readByte () != TC_ENDBLOCKDATA)
throw new IOException ("Data annotated to class was not consumed."); throw new IOException ("Data annotated to class was not consumed.");
dumpElementln ("ENDBLOCKDATA ");
osc.setSuperclass ((ObjectStreamClass)readObject ()); osc.setSuperclass ((ObjectStreamClass)readObject ());
ret_val = osc; ret_val = osc;
...@@ -188,27 +197,33 @@ public class ObjectInputStream extends InputStream ...@@ -188,27 +197,33 @@ public class ObjectInputStream extends InputStream
case TC_STRING: case TC_STRING:
{ {
// DEBUG ("STRING "); dumpElement ("STRING=");
String s = this.realInputStream.readUTF (); String s = this.realInputStream.readUTF ();
dumpElementln (s);
ret_val = processResolution (s, assignNewHandle (s)); ret_val = processResolution (s, assignNewHandle (s));
break; break;
} }
case TC_ARRAY: case TC_ARRAY:
{ {
dumpElementln ("ARRAY");
ObjectStreamClass osc = (ObjectStreamClass)readObject (); ObjectStreamClass osc = (ObjectStreamClass)readObject ();
Class componenetType = osc.forClass ().getComponentType (); Class componenetType = osc.forClass ().getComponentType ();
// DEBUG ("ARRAY LENGTH "); dumpElement ("ARRAY LENGTH=");
int length = this.realInputStream.readInt (); int length = this.realInputStream.readInt ();
dumpElementln (length + "; COMPONENT TYPE=" + componenetType);
Object array = Array.newInstance (componenetType, length); Object array = Array.newInstance (componenetType, length);
int handle = assignNewHandle (array); int handle = assignNewHandle (array);
readArrayElements (array, componenetType); readArrayElements (array, componenetType);
for (int i=0, len=Array.getLength(array); i < len; i++)
dumpElementln (" ELEMENT[" + i + "]=" + Array.get(array, i).toString());
ret_val = processResolution (array, handle); ret_val = processResolution (array, handle);
break; break;
} }
case TC_OBJECT: case TC_OBJECT:
{ {
dumpElementln ("OBJECT");
ObjectStreamClass osc = (ObjectStreamClass)readObject (); ObjectStreamClass osc = (ObjectStreamClass)readObject ();
Class clazz = osc.forClass (); Class clazz = osc.forClass ();
...@@ -284,8 +299,8 @@ public class ObjectInputStream extends InputStream ...@@ -284,8 +299,8 @@ public class ObjectInputStream extends InputStream
{ {
this.currentObjectStreamClass = hierarchy[i]; this.currentObjectStreamClass = hierarchy[i];
// DEBUGln ("Reading fields of " dumpElementln ("Reading fields of "
// + this.currentObjectStreamClass.getName ()); + this.currentObjectStreamClass.getName ());
has_read = true; has_read = true;
...@@ -308,9 +323,23 @@ public class ObjectInputStream extends InputStream ...@@ -308,9 +323,23 @@ public class ObjectInputStream extends InputStream
if (has_read) if (has_read)
{ {
// DEBUG ("ENDBLOCKDATA? "); dumpElement ("ENDBLOCKDATA? ");
if (this.realInputStream.readByte () != TC_ENDBLOCKDATA) try
throw new IOException ("No end of block data seen for class with readObject (ObjectInputStream) method."); {
// FIXME: XXX: This try block is to catch EOF which is
// thrown for some objects. That indicates a bug in the logic.
if (this.realInputStream.readByte () != TC_ENDBLOCKDATA)
throw new IOException ("No end of block data seen for class with readObject (ObjectInputStream) method.");
dumpElementln ("yes");
}
catch (EOFException e)
{
dumpElementln ("no, got EOFException");
}
catch (IOException e)
{
dumpElementln ("no, got IOException");
}
} }
} }
...@@ -321,13 +350,16 @@ public class ObjectInputStream extends InputStream ...@@ -321,13 +350,16 @@ public class ObjectInputStream extends InputStream
} }
case TC_RESET: case TC_RESET:
dumpElementln ("RESET");
clearHandles (); clearHandles ();
ret_val = readObject (); ret_val = readObject ();
break; break;
case TC_EXCEPTION: case TC_EXCEPTION:
{ {
dumpElement ("EXCEPTION=");
Exception e = (Exception)readObject (); Exception e = (Exception)readObject ();
dumpElementln (e.toString());
clearHandles (); clearHandles ();
throw new WriteAbortedException ("Exception thrown during writing of stream", e); throw new WriteAbortedException ("Exception thrown during writing of stream", e);
} }
...@@ -512,11 +544,11 @@ public class ObjectInputStream extends InputStream ...@@ -512,11 +544,11 @@ public class ObjectInputStream extends InputStream
protected void readStreamHeader () protected void readStreamHeader ()
throws IOException, StreamCorruptedException throws IOException, StreamCorruptedException
{ {
// DEBUG ("STREAM MAGIC "); dumpElement ("STREAM MAGIC ");
if (this.realInputStream.readShort () != STREAM_MAGIC) if (this.realInputStream.readShort () != STREAM_MAGIC)
throw new StreamCorruptedException ("Invalid stream magic number"); throw new StreamCorruptedException ("Invalid stream magic number");
// DEBUG ("STREAM VERSION "); dumpElementln ("STREAM VERSION ");
if (this.realInputStream.readShort () != STREAM_VERSION) if (this.realInputStream.readShort () != STREAM_VERSION)
throw new StreamCorruptedException ("Invalid stream version number"); throw new StreamCorruptedException ("Invalid stream version number");
} }
...@@ -982,7 +1014,7 @@ public class ObjectInputStream extends InputStream ...@@ -982,7 +1014,7 @@ public class ObjectInputStream extends InputStream
private void readNextBlock () throws IOException private void readNextBlock () throws IOException
{ {
// DEBUG ("MARKER "); // DEBUGln ("In readNextBlock ");
readNextBlock (this.realInputStream.readByte ()); readNextBlock (this.realInputStream.readByte ());
} }
...@@ -991,13 +1023,15 @@ public class ObjectInputStream extends InputStream ...@@ -991,13 +1023,15 @@ public class ObjectInputStream extends InputStream
{ {
if (marker == TC_BLOCKDATA) if (marker == TC_BLOCKDATA)
{ {
// DEBUG ("BLOCK DATA SIZE "); dumpElement ("BLOCK DATA SIZE=");
this.blockDataBytes = this.realInputStream.readUnsignedByte (); this.blockDataBytes = this.realInputStream.readUnsignedByte ();
dumpElementln (Integer.toString(this.blockDataBytes));
} }
else if (marker == TC_BLOCKDATALONG) else if (marker == TC_BLOCKDATALONG)
{ {
// DEBUG ("BLOCK DATA LONG SIZE "); dumpElement ("BLOCK DATA LONG SIZE=");
this.blockDataBytes = this.realInputStream.readInt (); this.blockDataBytes = this.realInputStream.readInt ();
dumpElementln (Integer.toString(this.blockDataBytes));
} }
else else
{ {
...@@ -1088,8 +1122,10 @@ public class ObjectInputStream extends InputStream ...@@ -1088,8 +1122,10 @@ public class ObjectInputStream extends InputStream
ObjectStreamClass stream_osc) ObjectStreamClass stream_osc)
throws ClassNotFoundException, IOException throws ClassNotFoundException, IOException
{ {
// DEBUGln ("In readFields");
if (call_read_method) if (call_read_method)
{ {
// DEBUGln (" call_read_method is true");
fieldsAlreadyRead = false; fieldsAlreadyRead = false;
setBlockDataMode (true); setBlockDataMode (true);
callReadMethod (obj, stream_osc.forClass ()); callReadMethod (obj, stream_osc.forClass ());
...@@ -1157,6 +1193,8 @@ public class ObjectInputStream extends InputStream ...@@ -1157,6 +1193,8 @@ public class ObjectInputStream extends InputStream
{ {
boolean value = boolean value =
default_initialize ? false : this.realInputStream.readBoolean (); default_initialize ? false : this.realInputStream.readBoolean ();
if (!default_initialize && set_value)
dumpElementln (" " + field_name + ": " + value);
if (set_value) if (set_value)
setBooleanField (obj, field_name, value); setBooleanField (obj, field_name, value);
} }
...@@ -1164,6 +1202,8 @@ public class ObjectInputStream extends InputStream ...@@ -1164,6 +1202,8 @@ public class ObjectInputStream extends InputStream
{ {
byte value = byte value =
default_initialize ? 0 : this.realInputStream.readByte (); default_initialize ? 0 : this.realInputStream.readByte ();
if (!default_initialize && set_value)
dumpElementln (" " + field_name + ": " + value);
if (set_value) if (set_value)
setByteField (obj, field_name, value); setByteField (obj, field_name, value);
} }
...@@ -1171,6 +1211,8 @@ public class ObjectInputStream extends InputStream ...@@ -1171,6 +1211,8 @@ public class ObjectInputStream extends InputStream
{ {
char value = char value =
default_initialize ? (char)0 : this.realInputStream.readChar (); default_initialize ? (char)0 : this.realInputStream.readChar ();
if (!default_initialize && set_value)
dumpElementln (" " + field_name + ": " + value);
if (set_value) if (set_value)
setCharField (obj, field_name, value); setCharField (obj, field_name, value);
} }
...@@ -1178,6 +1220,8 @@ public class ObjectInputStream extends InputStream ...@@ -1178,6 +1220,8 @@ public class ObjectInputStream extends InputStream
{ {
double value = double value =
default_initialize ? 0 : this.realInputStream.readDouble (); default_initialize ? 0 : this.realInputStream.readDouble ();
if (!default_initialize && set_value)
dumpElementln (" " + field_name + ": " + value);
if (set_value) if (set_value)
setDoubleField (obj, field_name, value); setDoubleField (obj, field_name, value);
} }
...@@ -1185,6 +1229,8 @@ public class ObjectInputStream extends InputStream ...@@ -1185,6 +1229,8 @@ public class ObjectInputStream extends InputStream
{ {
float value = float value =
default_initialize ? 0 : this.realInputStream.readFloat (); default_initialize ? 0 : this.realInputStream.readFloat ();
if (!default_initialize && set_value)
dumpElementln (" " + field_name + ": " + value);
if (set_value) if (set_value)
setFloatField (obj, field_name, value); setFloatField (obj, field_name, value);
} }
...@@ -1192,6 +1238,8 @@ public class ObjectInputStream extends InputStream ...@@ -1192,6 +1238,8 @@ public class ObjectInputStream extends InputStream
{ {
int value = int value =
default_initialize ? 0 : this.realInputStream.readInt (); default_initialize ? 0 : this.realInputStream.readInt ();
if (!default_initialize && set_value)
dumpElementln (" " + field_name + ": " + value);
if (set_value) if (set_value)
setIntField (obj, field_name, value); setIntField (obj, field_name, value);
} }
...@@ -1199,6 +1247,8 @@ public class ObjectInputStream extends InputStream ...@@ -1199,6 +1247,8 @@ public class ObjectInputStream extends InputStream
{ {
long value = long value =
default_initialize ? 0 : this.realInputStream.readLong (); default_initialize ? 0 : this.realInputStream.readLong ();
if (!default_initialize && set_value)
dumpElementln (" " + field_name + ": " + value);
if (set_value) if (set_value)
setLongField (obj, field_name, value); setLongField (obj, field_name, value);
} }
...@@ -1206,6 +1256,8 @@ public class ObjectInputStream extends InputStream ...@@ -1206,6 +1256,8 @@ public class ObjectInputStream extends InputStream
{ {
short value = short value =
default_initialize ? (short)0 : this.realInputStream.readShort (); default_initialize ? (short)0 : this.realInputStream.readShort ();
if (!default_initialize && set_value)
dumpElementln (" " + field_name + ": " + value);
if (set_value) if (set_value)
setShortField (obj, field_name, value); setShortField (obj, field_name, value);
} }
...@@ -1458,6 +1510,11 @@ public class ObjectInputStream extends InputStream ...@@ -1458,6 +1510,11 @@ public class ObjectInputStream extends InputStream
private boolean fieldsAlreadyRead; private boolean fieldsAlreadyRead;
private Vector validators; private Vector validators;
private static boolean dump;
public native static void setDump (boolean dump);
private native void dumpElement (String msg);
private native void dumpElementln (String msg);
/* FIXME: These 2 methods cause a build error on i686-pc-linux-gnu. /* FIXME: These 2 methods cause a build error on i686-pc-linux-gnu.
private void DEBUG (String msg) private void DEBUG (String msg)
......
...@@ -20,6 +20,11 @@ details. */ ...@@ -20,6 +20,11 @@ details. */
#include <java/lang/reflect/Modifier.h> #include <java/lang/reflect/Modifier.h>
#include <java/lang/reflect/Method.h> #include <java/lang/reflect/Method.h>
#ifdef DEBUG
#include <java/lang/System.h>
#include <java/io/PrintStream.h>
#endif
jobject jobject
java::io::ObjectInputStream::allocateObject (jclass klass) java::io::ObjectInputStream::allocateObject (jclass klass)
{ {
...@@ -74,3 +79,39 @@ java::io::ObjectInputStream::getMethod (jclass klass, jstring name, ...@@ -74,3 +79,39 @@ java::io::ObjectInputStream::getMethod (jclass klass, jstring name,
return klass->getPrivateMethod (name, arg_types); return klass->getPrivateMethod (name, arg_types);
} }
#ifdef DEBUG
void
java::io::ObjectInputStream::setDump (jboolean dump)
{
java::io::ObjectInputStream::dump = dump;
}
void
java::io::ObjectInputStream::dumpElement (jstring msg)
{
if (dump)
java::lang::System::out->print (msg);
}
void
java::io::ObjectInputStream::dumpElementln (jstring msg)
{
if (dump)
java::lang::System::out->println (msg);
}
#else
void
java::io::ObjectInputStream::setDump (jboolean dump)
{
}
void
java::io::ObjectInputStream::dumpElement (jstring msg)
{
}
void
java::io::ObjectInputStream::dumpElementln (jstring msg)
{
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment