Patch: Serialization mods
Warren Levy
warrenl@cygnus.com
Thu Jul 27 16:55:00 GMT 2000
Folks,
I'm checking the following mods in for serialization. They fix up several
discrepancies against the spec/JDK. Nothing earth-shattering; the most
noteworthy one for any kind of review would be the ALL_FLAGS change
in java/lang/reflect/Modifier.java which adds the bit to the mask for
the strictfp functionality added in JDK 1.2. FWIW, there's some code in
defineclass.cc that verifies the modifier associated with the object;
I didn't add any checking for STRICT in there, but that shouldn't hurt
anything right now.
Libgcj does a much better job now of dealing with serialVersionUID and
most classes now match the JDK as they should. Some classes compute to
a different value from the JDK still, but that is due mostly to a different
(but equivalent) implementation in libgcj. We'll need to examine those
one-by-one to determine which ones need an explicit serialVersionUID
(and/or what else needs to be fixed ;-).
Enjoy!
--warrenl
2000-07-27 Warren Levy <warrenl@cygnus.com>
* mauve-libgcj: Activated serialization tests.
* gcj/field.h (getModifiers): Mask off unknown flags.
* gnu/java/security/provider/SHA.java (munch): Reset buffer to 0 so
spurious bits don't cause discrepancies.
* java/io/ObjectOutputStream.java: Fixed typo in comment.
* java/io/ObjectStreamClass.java: Fixed typos in comments.
(lookup): Applied patch from Brian Jones <cbj@gnu.org> to optimize.
(hasClassInitializer): Call getDeclaredMethod instead of getMethod.
* java/lang/Throwable.java (serialVersionUID): New field.
* java/lang/reflect/Modifier.java (ALL_FLAGS): Preserve STRICT if used.
* java/lang/reflect/natConstructor.cc (getModifiers): Mask off
unknown flags.
* java/lang/reflect/natMethod.cc: Ditto.
* java/security/Key.java (serialVersionUID): Removed field for now.
* java/security/interfaces/DSAPrivateKey.java (serialVersionUID): Ditto.
* java/security/interfaces/DSAPublicKey.java (serialVersionUID): Ditto.
Index: mauve-libgcj
===================================================================
RCS file: /cvs/java/libgcj/libjava/mauve-libgcj,v
retrieving revision 1.14
diff -u -p -r1.14 mauve-libgcj
--- mauve-libgcj 2000/05/19 17:55:27 1.14
+++ mauve-libgcj 2000/07/27 23:08:47
@@ -8,9 +8,9 @@ java.lang.Character.classify12
java.lang.String.hash
# We support 1.2 for these 3 tests.
java.lang.reflect.Modifier.toString12
-!java.io.ObjectInputOutput.InputTest
-!java.io.ObjectInputOutput.OutputTest
-!java.io.ObjectStreamClass.Test
+java.io.ObjectInputOutput.InputTest
+java.io.ObjectInputOutput.OutputTest
+java.io.ObjectStreamClass.Test
java.math
!java.rmi
java.security
Index: gcj/field.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/gcj/field.h,v
retrieving revision 1.7
diff -u -p -r1.7 field.h
--- field.h 2000/05/05 04:46:26 1.7
+++ field.h 2000/07/27 23:08:49
@@ -13,6 +13,7 @@ details. */
#include <java/lang/Class.h>
#include <java/lang/reflect/Field.h>
+#include <java/lang/reflect/Modifier.h>
#define _Jv_FIELD_UNRESOLVED_FLAG 0x8000
#define _Jv_FIELD_CONSTANT_VALUE 0x4000
@@ -74,8 +75,11 @@ struct _Jv_Field
return type;
}
- // FIXME - may need to mask off internal flags.
- int getModifiers() { return flags; }
+ // Need to mask off all unknown/internal flags before returning.
+ int getModifiers()
+ {
+ return flags & java::lang::reflect::Modifier::ALL_FLAGS;
+ }
#ifdef COMPACT_FIELDS
_Jv_Utf8Const * getNameUtf8Const (jclass cls)
Index: gnu/java/security/provider/SHA.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/gnu/java/security/provider/SHA.java,v
retrieving revision 1.1
diff -u -p -r1.1 SHA.java
--- SHA.java 2000/06/28 11:24:05 1.1
+++ SHA.java 2000/07/27 23:08:50
@@ -1,5 +1,5 @@
/* SHA.java -- Class implementing the SHA-1 algorithm as specified in [1].
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -198,6 +198,10 @@ public class SHA extends MessageDigest i
H2 += C;
H3 += D;
H4 += E;
+
+ // Reset W by clearing it.
+ for (int t = 0; t < 80; ++ t)
+ W[t] = 0;
}
public Object clone ()
Index: java/io/ObjectOutputStream.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/ObjectOutputStream.java,v
retrieving revision 1.2
diff -u -p -r1.2 ObjectOutputStream.java
--- ObjectOutputStream.java 2000/05/24 21:15:51 1.2
+++ ObjectOutputStream.java 2000/07/27 23:08:50
@@ -54,7 +54,7 @@ import gnu.java.lang.reflect.TypeSignatu
Using default serialization, information about the class of an
object is written, all of the non-transient, non-static fields of
- the object are written, if any of these fields are objects, the are
+ the object are written, if any of these fields are objects, they are
written out in the same manner.
An object is only written out the first time it is encountered. If
Index: java/io/ObjectStreamClass.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/ObjectStreamClass.java,v
retrieving revision 1.2
diff -u -p -r1.2 ObjectStreamClass.java
--- ObjectStreamClass.java 2000/06/28 11:24:05 1.2
+++ ObjectStreamClass.java 2000/07/27 23:08:50
@@ -1,6 +1,6 @@
/* ObjectStreamClass.java -- Class used to write class information
about serialized objects.
- Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -51,7 +51,7 @@ public class ObjectStreamClass implement
/**
Returns the <code>ObjectStreamClass</code> for <code>cl</code>.
If <code>cl</code> is null, or is not <code>Serializable</code>,
- null is returned. <code>ObjectStreamClass</code>'s are memoized;
+ null is returned. <code>ObjectStreamClass</code>'s are memorized;
later calls to this method with the same class will return the
same <code>ObjectStreamClass</code> object and no recalculation
will be done.
@@ -62,13 +62,13 @@ public class ObjectStreamClass implement
{
if (cl == null)
return null;
+ if (! (Serializable.class).isAssignableFrom (cl))
+ return null;
ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (cl);
if (osc != null)
return osc;
- else if (! (Serializable.class).isAssignableFrom (cl))
- return null;
else
{
osc = new ObjectStreamClass (cl);
@@ -161,7 +161,7 @@ public class ObjectStreamClass implement
// private void writeObject (ObjectOutputStream)
//
// This method is used by the class to override default
- // serialization behaivior.
+ // serialization behavior.
boolean hasWriteMethod ()
{
return (flags & ObjectStreamConstants.SC_WRITE_METHOD) != 0;
@@ -396,7 +396,7 @@ public class ObjectStreamClass implement
calculateOffsets ();
}
- // Sets uid be serial version UID defined by class, or if that
+ // Sets uid to be serial version UID defined by class, or if that
// isn't present, calculates value of serial version UID.
private void setUID (Class cl)
{
@@ -603,7 +603,7 @@ public class ObjectStreamClass implement
try
{
Class classArgs[] = {};
- m = clazz.getMethod ("<clinit>", classArgs);
+ m = clazz.getDeclaredMethod ("<clinit>", classArgs);
}
catch (java.lang.NoSuchMethodException e)
{
Index: java/lang/Throwable.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/Throwable.java,v
retrieving revision 1.7
diff -u -p -r1.7 Throwable.java
--- Throwable.java 2000/06/27 05:10:02 1.7
+++ Throwable.java 2000/07/27 23:08:50
@@ -165,4 +165,5 @@ public class Throwable implements Serial
private String detailMessage;
private transient byte stackTrace[];
+ private static final long serialVersionUID = -3042686055658047285L;
}
Index: java/lang/reflect/Modifier.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/reflect/Modifier.java,v
retrieving revision 1.5
diff -u -p -r1.5 Modifier.java
--- Modifier.java 2000/03/07 19:55:27 1.5
+++ Modifier.java 2000/07/27 23:08:50
@@ -37,7 +37,7 @@ public class Modifier
public static final int STRICT = 0x800;
// This is only used by the C++ code, so it is not public.
- static final int ALL_FLAGS = 0x7ff;
+ static final int ALL_FLAGS = 0xfff;
public static boolean isAbstract (int mod)
{
Index: java/lang/reflect/natConstructor.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/reflect/natConstructor.cc,v
retrieving revision 1.4
diff -u -p -r1.4 natConstructor.cc
--- natConstructor.cc 2000/03/07 19:55:27 1.4
+++ natConstructor.cc 2000/07/27 23:08:50
@@ -23,7 +23,8 @@ details. */
jint
java::lang::reflect::Constructor::getModifiers ()
{
- return _Jv_FromReflectedConstructor (this)->accflags;
+ // Ignore all unknown flags.
+ return _Jv_FromReflectedConstructor (this)->accflags & Modifier::ALL_FLAGS;
}
void
Index: java/lang/reflect/natMethod.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/reflect/natMethod.cc,v
retrieving revision 1.11
diff -u -p -r1.11 natMethod.cc
--- natMethod.cc 2000/06/23 17:39:00 1.11
+++ natMethod.cc 2000/07/27 23:08:51
@@ -182,7 +182,8 @@ java::lang::reflect::Method::invoke (job
jint
java::lang::reflect::Method::getModifiers ()
{
- return _Jv_FromReflectedMethod (this)->accflags;
+ // Ignore all unknown flags.
+ return _Jv_FromReflectedMethod (this)->accflags & Modifier::ALL_FLAGS;
}
jstring
Index: java/security/Key.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/security/Key.java,v
retrieving revision 1.2
diff -u -p -r1.2 Key.java
--- Key.java 2000/03/10 05:10:40 1.2
+++ Key.java 2000/07/27 23:08:51
@@ -21,7 +21,7 @@ import java.io.Serializable;
public interface Key extends Serializable
{
// FIXME: need to set this at some point when serialization is implemented.
- public static final long serialVersionUID = 0;
+ // public static final long serialVersionUID = 0L;
public String getAlgorithm();
public String getFormat();
Index: java/security/interfaces/DSAPrivateKey.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/security/interfaces/DSAPrivateKey.java,v
retrieving revision 1.2
diff -u -p -r1.2 DSAPrivateKey.java
--- DSAPrivateKey.java 2000/03/10 05:10:40 1.2
+++ DSAPrivateKey.java 2000/07/27 23:08:52
@@ -22,7 +22,7 @@ import java.math.BigInteger;
public interface DSAPrivateKey extends DSAKey, PrivateKey
{
// FIXME: need to set this at some point when serialization is implemented.
- public static final long serialVersionUID = 0;
+ // public static final long serialVersionUID = 0L;
public BigInteger getX();
}
Index: java/security/interfaces/DSAPublicKey.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/security/interfaces/DSAPublicKey.java,v
retrieving revision 1.2
diff -u -p -r1.2 DSAPublicKey.java
--- DSAPublicKey.java 2000/03/10 05:10:40 1.2
+++ DSAPublicKey.java 2000/07/27 23:08:52
@@ -22,7 +22,7 @@ import java.math.BigInteger;
public interface DSAPublicKey extends DSAKey, PublicKey
{
// FIXME: need to set this at some point when serialization is implemented.
- public static final long serialVersionUID = 0;
+ // public static final long serialVersionUID = 0L;
public BigInteger getY();
}
More information about the Java-patches
mailing list