提交 56970535 编写于 作者: M mchung

6895456: Eliminate dependency on java.io.ObjectStreamClass during boot

Summary: Duplicate ObjectStreamClass.getClassSignature method in ObjectStreamField class
Reviewed-by: alanb
上级 5a304f4e
...@@ -99,7 +99,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -99,7 +99,7 @@ public class ObjectStreamClass implements Serializable {
} }
/** class associated with this descriptor (if any) */ /** class associated with this descriptor (if any) */
private Class cl; private Class<?> cl;
/** name of class represented by this descriptor */ /** name of class represented by this descriptor */
private String name; private String name;
/** serialVersionUID of represented class (null if not computed yet) */ /** serialVersionUID of represented class (null if not computed yet) */
...@@ -276,7 +276,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -276,7 +276,7 @@ public class ObjectStreamClass implements Serializable {
* @param all if true, return descriptors for all classes; if false, only * @param all if true, return descriptors for all classes; if false, only
* return descriptors for serializable classes * return descriptors for serializable classes
*/ */
static ObjectStreamClass lookup(Class cl, boolean all) { static ObjectStreamClass lookup(Class<?> cl, boolean all) {
if (!(all || Serializable.class.isAssignableFrom(cl))) { if (!(all || Serializable.class.isAssignableFrom(cl))) {
return null; return null;
} }
...@@ -414,7 +414,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -414,7 +414,7 @@ public class ObjectStreamClass implements Serializable {
/** /**
* Creates local class descriptor representing given class. * Creates local class descriptor representing given class.
*/ */
private ObjectStreamClass(final Class cl) { private ObjectStreamClass(final Class<?> cl) {
this.cl = cl; this.cl = cl;
name = cl.getName(); name = cl.getName();
isProxy = Proxy.isProxyClass(cl); isProxy = Proxy.isProxyClass(cl);
...@@ -422,7 +422,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -422,7 +422,7 @@ public class ObjectStreamClass implements Serializable {
serializable = Serializable.class.isAssignableFrom(cl); serializable = Serializable.class.isAssignableFrom(cl);
externalizable = Externalizable.class.isAssignableFrom(cl); externalizable = Externalizable.class.isAssignableFrom(cl);
Class superCl = cl.getSuperclass(); Class<?> superCl = cl.getSuperclass();
superDesc = (superCl != null) ? lookup(superCl, false) : null; superDesc = (superCl != null) ? lookup(superCl, false) : null;
localDesc = this; localDesc = this;
...@@ -453,10 +453,10 @@ public class ObjectStreamClass implements Serializable { ...@@ -453,10 +453,10 @@ public class ObjectStreamClass implements Serializable {
} else { } else {
cons = getSerializableConstructor(cl); cons = getSerializableConstructor(cl);
writeObjectMethod = getPrivateMethod(cl, "writeObject", writeObjectMethod = getPrivateMethod(cl, "writeObject",
new Class[] { ObjectOutputStream.class }, new Class<?>[] { ObjectOutputStream.class },
Void.TYPE); Void.TYPE);
readObjectMethod = getPrivateMethod(cl, "readObject", readObjectMethod = getPrivateMethod(cl, "readObject",
new Class[] { ObjectInputStream.class }, new Class<?>[] { ObjectInputStream.class },
Void.TYPE); Void.TYPE);
readObjectNoDataMethod = getPrivateMethod( readObjectNoDataMethod = getPrivateMethod(
cl, "readObjectNoData", null, Void.TYPE); cl, "readObjectNoData", null, Void.TYPE);
...@@ -507,7 +507,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -507,7 +507,7 @@ public class ObjectStreamClass implements Serializable {
/** /**
* Initializes class descriptor representing a proxy class. * Initializes class descriptor representing a proxy class.
*/ */
void initProxy(Class cl, void initProxy(Class<?> cl,
ClassNotFoundException resolveEx, ClassNotFoundException resolveEx,
ObjectStreamClass superDesc) ObjectStreamClass superDesc)
throws InvalidClassException throws InvalidClassException
...@@ -540,7 +540,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -540,7 +540,7 @@ public class ObjectStreamClass implements Serializable {
* Initializes class descriptor representing a non-proxy class. * Initializes class descriptor representing a non-proxy class.
*/ */
void initNonProxy(ObjectStreamClass model, void initNonProxy(ObjectStreamClass model,
Class cl, Class<?> cl,
ClassNotFoundException resolveEx, ClassNotFoundException resolveEx,
ObjectStreamClass superDesc) ObjectStreamClass superDesc)
throws InvalidClassException throws InvalidClassException
...@@ -1131,7 +1131,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1131,7 +1131,7 @@ public class ObjectStreamClass implements Serializable {
throws InvalidClassException throws InvalidClassException
{ {
ArrayList<ClassDataSlot> slots = new ArrayList<ClassDataSlot>(); ArrayList<ClassDataSlot> slots = new ArrayList<ClassDataSlot>();
Class start = cl, end = cl; Class<?> start = cl, end = cl;
// locate closest non-serializable superclass // locate closest non-serializable superclass
while (end != null && Serializable.class.isAssignableFrom(end)) { while (end != null && Serializable.class.isAssignableFrom(end)) {
...@@ -1142,8 +1142,8 @@ public class ObjectStreamClass implements Serializable { ...@@ -1142,8 +1142,8 @@ public class ObjectStreamClass implements Serializable {
// search up inheritance hierarchy for class with matching name // search up inheritance hierarchy for class with matching name
String searchName = (d.cl != null) ? d.cl.getName() : d.name; String searchName = (d.cl != null) ? d.cl.getName() : d.name;
Class match = null; Class<?> match = null;
for (Class c = start; c != end; c = c.getSuperclass()) { for (Class<?> c = start; c != end; c = c.getSuperclass()) {
if (searchName.equals(c.getName())) { if (searchName.equals(c.getName())) {
match = c; match = c;
break; break;
...@@ -1152,7 +1152,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1152,7 +1152,7 @@ public class ObjectStreamClass implements Serializable {
// add "no data" slot for each unmatched class below match // add "no data" slot for each unmatched class below match
if (match != null) { if (match != null) {
for (Class c = start; c != match; c = c.getSuperclass()) { for (Class<?> c = start; c != match; c = c.getSuperclass()) {
slots.add(new ClassDataSlot( slots.add(new ClassDataSlot(
ObjectStreamClass.lookup(c, true), false)); ObjectStreamClass.lookup(c, true), false));
} }
...@@ -1164,7 +1164,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1164,7 +1164,7 @@ public class ObjectStreamClass implements Serializable {
} }
// add "no data" slot for any leftover unmatched classes // add "no data" slot for any leftover unmatched classes
for (Class c = start; c != end; c = c.getSuperclass()) { for (Class<?> c = start; c != end; c = c.getSuperclass()) {
slots.add(new ClassDataSlot( slots.add(new ClassDataSlot(
ObjectStreamClass.lookup(c, true), false)); ObjectStreamClass.lookup(c, true), false));
} }
...@@ -1288,7 +1288,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1288,7 +1288,7 @@ public class ObjectStreamClass implements Serializable {
* descriptor, returns reference to this class descriptor. Otherwise, * descriptor, returns reference to this class descriptor. Otherwise,
* returns variant of this class descriptor bound to given class. * returns variant of this class descriptor bound to given class.
*/ */
private ObjectStreamClass getVariantFor(Class cl) private ObjectStreamClass getVariantFor(Class<?> cl)
throws InvalidClassException throws InvalidClassException
{ {
if (this.cl == cl) { if (this.cl == cl) {
...@@ -1355,8 +1355,8 @@ public class ObjectStreamClass implements Serializable { ...@@ -1355,8 +1355,8 @@ public class ObjectStreamClass implements Serializable {
* method (if any). * method (if any).
*/ */
private static Method getInheritableMethod(Class<?> cl, String name, private static Method getInheritableMethod(Class<?> cl, String name,
Class[] argTypes, Class<?>[] argTypes,
Class returnType) Class<?> returnType)
{ {
Method meth = null; Method meth = null;
Class<?> defCl = cl; Class<?> defCl = cl;
...@@ -1410,7 +1410,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1410,7 +1410,7 @@ public class ObjectStreamClass implements Serializable {
* Returns true if classes are defined in the same runtime package, false * Returns true if classes are defined in the same runtime package, false
* otherwise. * otherwise.
*/ */
private static boolean packageEquals(Class cl1, Class cl2) { private static boolean packageEquals(Class<?> cl1, Class<?> cl2) {
return (cl1.getClassLoader() == cl2.getClassLoader() && return (cl1.getClassLoader() == cl2.getClassLoader() &&
getPackageName(cl1).equals(getPackageName(cl2))); getPackageName(cl1).equals(getPackageName(cl2)));
} }
...@@ -1418,7 +1418,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1418,7 +1418,7 @@ public class ObjectStreamClass implements Serializable {
/** /**
* Returns package name of given class. * Returns package name of given class.
*/ */
private static String getPackageName(Class cl) { private static String getPackageName(Class<?> cl) {
String s = cl.getName(); String s = cl.getName();
int i = s.lastIndexOf('['); int i = s.lastIndexOf('[');
if (i >= 0) { if (i >= 0) {
...@@ -1441,7 +1441,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1441,7 +1441,7 @@ public class ObjectStreamClass implements Serializable {
/** /**
* Returns JVM type signature for given class. * Returns JVM type signature for given class.
*/ */
static String getClassSignature(Class cl) { private static String getClassSignature(Class<?> cl) {
StringBuilder sbuf = new StringBuilder(); StringBuilder sbuf = new StringBuilder();
while (cl.isArray()) { while (cl.isArray()) {
sbuf.append('['); sbuf.append('[');
...@@ -1478,8 +1478,8 @@ public class ObjectStreamClass implements Serializable { ...@@ -1478,8 +1478,8 @@ public class ObjectStreamClass implements Serializable {
/** /**
* Returns JVM type signature for given list of parameters and return type. * Returns JVM type signature for given list of parameters and return type.
*/ */
private static String getMethodSignature(Class[] paramTypes, private static String getMethodSignature(Class<?>[] paramTypes,
Class retType) Class<?> retType)
{ {
StringBuilder sbuf = new StringBuilder(); StringBuilder sbuf = new StringBuilder();
sbuf.append('('); sbuf.append('(');
...@@ -1515,7 +1515,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1515,7 +1515,7 @@ public class ObjectStreamClass implements Serializable {
* Field objects. Throws InvalidClassException if the (explicitly * Field objects. Throws InvalidClassException if the (explicitly
* declared) serializable fields are invalid. * declared) serializable fields are invalid.
*/ */
private static ObjectStreamField[] getSerialFields(Class cl) private static ObjectStreamField[] getSerialFields(Class<?> cl)
throws InvalidClassException throws InvalidClassException
{ {
ObjectStreamField[] fields; ObjectStreamField[] fields;
...@@ -1545,7 +1545,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1545,7 +1545,7 @@ public class ObjectStreamClass implements Serializable {
* InvalidClassException if the declared serializable fields are * InvalidClassException if the declared serializable fields are
* invalid--e.g., if multiple fields share the same name. * invalid--e.g., if multiple fields share the same name.
*/ */
private static ObjectStreamField[] getDeclaredSerialFields(Class cl) private static ObjectStreamField[] getDeclaredSerialFields(Class<?> cl)
throws InvalidClassException throws InvalidClassException
{ {
ObjectStreamField[] serialPersistentFields = null; ObjectStreamField[] serialPersistentFields = null;
...@@ -1602,7 +1602,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1602,7 +1602,7 @@ public class ObjectStreamClass implements Serializable {
* contains a Field object for the field it represents. If no default * contains a Field object for the field it represents. If no default
* serializable fields exist, NO_FIELDS is returned. * serializable fields exist, NO_FIELDS is returned.
*/ */
private static ObjectStreamField[] getDefaultSerialFields(Class cl) { private static ObjectStreamField[] getDefaultSerialFields(Class<?> cl) {
Field[] clFields = cl.getDeclaredFields(); Field[] clFields = cl.getDeclaredFields();
ArrayList<ObjectStreamField> list = new ArrayList<ObjectStreamField>(); ArrayList<ObjectStreamField> list = new ArrayList<ObjectStreamField>();
int mask = Modifier.STATIC | Modifier.TRANSIENT; int mask = Modifier.STATIC | Modifier.TRANSIENT;
...@@ -1621,7 +1621,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1621,7 +1621,7 @@ public class ObjectStreamClass implements Serializable {
* Returns explicit serial version UID value declared by given class, or * Returns explicit serial version UID value declared by given class, or
* null if none. * null if none.
*/ */
private static Long getDeclaredSUID(Class cl) { private static Long getDeclaredSUID(Class<?> cl) {
try { try {
Field f = cl.getDeclaredField("serialVersionUID"); Field f = cl.getDeclaredField("serialVersionUID");
int mask = Modifier.STATIC | Modifier.FINAL; int mask = Modifier.STATIC | Modifier.FINAL;
...@@ -1637,7 +1637,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1637,7 +1637,7 @@ public class ObjectStreamClass implements Serializable {
/** /**
* Computes the default serial version UID value for the given class. * Computes the default serial version UID value for the given class.
*/ */
private static long computeDefaultSUID(Class cl) { private static long computeDefaultSUID(Class<?> cl) {
if (!Serializable.class.isAssignableFrom(cl) || Proxy.isProxyClass(cl)) if (!Serializable.class.isAssignableFrom(cl) || Proxy.isProxyClass(cl))
{ {
return 0L; return 0L;
...@@ -1671,7 +1671,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1671,7 +1671,7 @@ public class ObjectStreamClass implements Serializable {
* Class.getInterfaces() was modified to return Cloneable and * Class.getInterfaces() was modified to return Cloneable and
* Serializable for array classes. * Serializable for array classes.
*/ */
Class[] interfaces = cl.getInterfaces(); Class<?>[] interfaces = cl.getInterfaces();
String[] ifaceNames = new String[interfaces.length]; String[] ifaceNames = new String[interfaces.length];
for (int i = 0; i < interfaces.length; i++) { for (int i = 0; i < interfaces.length; i++) {
ifaceNames[i] = interfaces[i].getName(); ifaceNames[i] = interfaces[i].getName();
...@@ -1784,7 +1784,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1784,7 +1784,7 @@ public class ObjectStreamClass implements Serializable {
* Returns true if the given class defines a static initializer method, * Returns true if the given class defines a static initializer method,
* false otherwise. * false otherwise.
*/ */
private native static boolean hasStaticInitializer(Class cl); private native static boolean hasStaticInitializer(Class<?> cl);
/** /**
* Class for computing and caching field/constructor/method signatures * Class for computing and caching field/constructor/method signatures
...@@ -1837,7 +1837,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -1837,7 +1837,7 @@ public class ObjectStreamClass implements Serializable {
/** field type codes */ /** field type codes */
private final char[] typeCodes; private final char[] typeCodes;
/** field types */ /** field types */
private final Class[] types; private final Class<?>[] types;
/** /**
* Constructs FieldReflector capable of setting/getting values from the * Constructs FieldReflector capable of setting/getting values from the
...@@ -2071,7 +2071,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -2071,7 +2071,7 @@ public class ObjectStreamClass implements Serializable {
throws InvalidClassException throws InvalidClassException
{ {
// class irrelevant if no fields // class irrelevant if no fields
Class cl = (localDesc != null && fields.length > 0) ? Class<?> cl = (localDesc != null && fields.length > 0) ?
localDesc.cl : null; localDesc.cl : null;
processQueue(Caches.reflectorsQueue, Caches.reflectors); processQueue(Caches.reflectorsQueue, Caches.reflectors);
FieldReflectorKey key = new FieldReflectorKey(cl, fields, FieldReflectorKey key = new FieldReflectorKey(cl, fields,
...@@ -2136,7 +2136,7 @@ public class ObjectStreamClass implements Serializable { ...@@ -2136,7 +2136,7 @@ public class ObjectStreamClass implements Serializable {
private final int hash; private final int hash;
private final boolean nullClass; private final boolean nullClass;
FieldReflectorKey(Class cl, ObjectStreamField[] fields, FieldReflectorKey(Class<?> cl, ObjectStreamField[] fields,
ReferenceQueue<Class<?>> queue) ReferenceQueue<Class<?>> queue)
{ {
super(cl, queue); super(cl, queue);
......
...@@ -45,7 +45,7 @@ public class ObjectStreamField ...@@ -45,7 +45,7 @@ public class ObjectStreamField
/** canonical JVM signature of field type */ /** canonical JVM signature of field type */
private final String signature; private final String signature;
/** field type (Object.class if unknown non-primitive type) */ /** field type (Object.class if unknown non-primitive type) */
private final Class type; private final Class<?> type;
/** whether or not to (de)serialize field values as unshared */ /** whether or not to (de)serialize field values as unshared */
private final boolean unshared; private final boolean unshared;
/** corresponding reflective field object, if any */ /** corresponding reflective field object, if any */
...@@ -88,7 +88,7 @@ public class ObjectStreamField ...@@ -88,7 +88,7 @@ public class ObjectStreamField
this.name = name; this.name = name;
this.type = type; this.type = type;
this.unshared = unshared; this.unshared = unshared;
signature = ObjectStreamClass.getClassSignature(type).intern(); signature = getClassSignature(type).intern();
field = null; field = null;
} }
...@@ -132,9 +132,9 @@ public class ObjectStreamField ...@@ -132,9 +132,9 @@ public class ObjectStreamField
this.field = field; this.field = field;
this.unshared = unshared; this.unshared = unshared;
name = field.getName(); name = field.getName();
Class ftype = field.getType(); Class<?> ftype = field.getType();
type = (showType || ftype.isPrimitive()) ? ftype : Object.class; type = (showType || ftype.isPrimitive()) ? ftype : Object.class;
signature = ObjectStreamClass.getClassSignature(ftype).intern(); signature = getClassSignature(ftype).intern();
} }
/** /**
...@@ -274,4 +274,41 @@ public class ObjectStreamField ...@@ -274,4 +274,41 @@ public class ObjectStreamField
String getSignature() { String getSignature() {
return signature; return signature;
} }
/**
* Returns JVM type signature for given class.
*/
private static String getClassSignature(Class<?> cl) {
StringBuilder sbuf = new StringBuilder();
while (cl.isArray()) {
sbuf.append('[');
cl = cl.getComponentType();
}
if (cl.isPrimitive()) {
if (cl == Integer.TYPE) {
sbuf.append('I');
} else if (cl == Byte.TYPE) {
sbuf.append('B');
} else if (cl == Long.TYPE) {
sbuf.append('J');
} else if (cl == Float.TYPE) {
sbuf.append('F');
} else if (cl == Double.TYPE) {
sbuf.append('D');
} else if (cl == Short.TYPE) {
sbuf.append('S');
} else if (cl == Character.TYPE) {
sbuf.append('C');
} else if (cl == Boolean.TYPE) {
sbuf.append('Z');
} else if (cl == Void.TYPE) {
sbuf.append('V');
} else {
throw new InternalError();
}
} else {
sbuf.append('L' + cl.getName().replace('.', '/') + ';');
}
return sbuf.toString();
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册