2362N/A * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Serialization's descriptor for classes. It contains the name and 0N/A * serialVersionUID of the class. The ObjectStreamClass for a specific class 0N/A * <p>The algorithm to compute the SerialVersionUID is described in 0N/A * Serialization Specification, Section 4.6, Stream Unique Identifiers</a>. 0N/A * @author Mike Warres 0N/A * @author Roger Riggs 0N/A * @see ObjectStreamField 0N/A /** serialPersistentFields value indicating no serializable fields */ 0N/A /** reflection factory for obtaining serialization constructors */ 0N/A /** cache mapping local classes -> descriptors */ 0N/A /** cache mapping field group/local desc pairs -> field reflectors */ 0N/A /** queue for WeakReferences to local classes */ 0N/A /** queue for WeakReferences to field reflectors keys */ 0N/A /** class associated with this descriptor (if any) */ 0N/A /** name of class represented by this descriptor */ 0N/A /** serialVersionUID of represented class (null if not computed yet) */ 0N/A /** true if represents dynamic proxy class */ 0N/A /** true if represents enum type */ 0N/A /** true if represented class implements Serializable */ 0N/A /** true if represented class implements Externalizable */ 0N/A /** true if desc has data written by class-defined writeObject method */ 0N/A * true if desc has externalizable data written in block data format; this 0N/A * must be true by default to accommodate ObjectInputStream subclasses which 0N/A * override readClassDescriptor() to return class descriptors obtained from 0N/A * ObjectStreamClass.lookup() (see 4461737) 0N/A * Contains information about InvalidClassException instances to be thrown 0N/A * when attempting operations on an invalid class. Note that instances of 0N/A * this class are immutable and are potentially shared among 0N/A * ObjectStreamClass instances. 0N/A * Returns (does not throw) an InvalidClassException instance created 0N/A * from the information in this object, suitable for being thrown by 0N/A /** exception (if any) thrown while attempting to resolve class */ 0N/A /** exception (if any) to throw if non-enum deserialization attempted */ 0N/A /** exception (if any) to throw if non-enum serialization attempted */ 0N/A /** exception (if any) to throw if default serialization attempted */ 0N/A /** serializable fields */ 0N/A /** aggregate marshalled size of primitive fields */ 0N/A /** number of non-primitive fields */ 0N/A /** data layout of serialized objects described by this class desc */ 0N/A /** serialization-appropriate constructor, or null if none */ 0N/A /** class-defined writeObject method, or null if none */ 0N/A /** class-defined readObject method, or null if none */ 0N/A /** class-defined readObjectNoData method, or null if none */ 0N/A /** class-defined writeReplace method, or null if none */ 0N/A /** class-defined readResolve method, or null if none */ 0N/A /** local class descriptor for represented class (may point to self) */ 0N/A /** superclass descriptor appearing in stream */ 0N/A * Initializes native code. 0N/A * Find the descriptor for a class that can be serialized. Creates an 0N/A * ObjectStreamClass instance if one does not exist yet for class. Null is 0N/A * returned if the specified class does not implement java.io.Serializable 0N/A * or java.io.Externalizable. 0N/A * @param cl class for which to get the descriptor 0N/A * @return the class descriptor for the specified class 0N/A * Returns the descriptor for any class, regardless of whether it 0N/A * implements {@link Serializable}. 0N/A * @param cl class for which to get the descriptor 0N/A * @return the class descriptor for the specified class 0N/A * Returns the name of the class described by this descriptor. 0N/A * This method returns the name of the class in the format that 0N/A * is used by the {@link Class#getName} method. 0N/A * @return a string representing the name of the class 0N/A * Return the serialVersionUID for this class. The serialVersionUID 0N/A * defines a set of classes all with the same name that have evolved from a 0N/A * common root class and agree to be serialized and deserialized using a 0N/A * common format. NonSerializable classes have a serialVersionUID of 0L. 0N/A * @return the SUID of the class described by this descriptor 0N/A // REMIND: synchronize instead of relying on volatile? 0N/A * Return the class in the local VM that this version is mapped to. Null 0N/A * is returned if there is no corresponding local class. 0N/A * @return the <code>Class</code> instance that this descriptor represents 0N/A * Return an array of the fields of this serializable class. 0N/A * @return an array containing an element for each persistent field of 0N/A * this class. Returns an array of length zero if there are no 0N/A * Get the field of this class by name. 0N/A * @param name the name of the data field to look for 0N/A * @return The ObjectStreamField object of the named field or null if 0N/A * there is no such named field. 0N/A * Return a string describing this ObjectStreamClass. 0N/A return name +
": static final long serialVersionUID = " +
0N/A * Looks up and returns class descriptor for given class, or null if class 0N/A * is non-serializable and "all" is set to false. 0N/A * @param cl class to look up 0N/A * @param all if true, return descriptors for all classes; if false, only 0N/A * return descriptors for serializable classes 0N/A * Handle nested call situation described by 4803747: waiting 0N/A * for future value to be set by a lookup() call further up the 0N/A * stack will result in deadlock, so calculate and set the 0N/A * future value here instead. 0N/A // nested lookup call already set future 0N/A * Placeholder used in class descriptor and field reflector lookup tables 0N/A * for an entry in the process of being initialized. (Internal) callers 0N/A * which receive an EntryFuture belonging to another thread as the result 0N/A * of a lookup should call the get() method of the EntryFuture; this will 0N/A * return the actual entry once it is ready for use and has been set(). To 0N/A * conserve objects, EntryFutures synchronize on themselves. 0N/A * Attempts to set the value contained by this EntryFuture. If the 0N/A * EntryFuture's value has not been set already, then the value is 0N/A * saved, any callers blocked in the get() method are notified, and 0N/A * true is returned. If the value has already been set, then no saving 0N/A * or notification occurs, and false is returned. 0N/A * Returns the value contained by this EntryFuture, blocking if 0N/A * necessary until a value is set. 0N/A * Returns the thread that created this EntryFuture. 0N/A * Creates local class descriptor representing given class. 0N/A // field mismatches impossible when matching local fields vs. self 0N/A name,
"unmatched serializable field(s) declared");
0N/A * Creates blank class descriptor which should be initialized via a 0N/A * subsequent call to initProxy(), initNonProxy() or readNonProxy(). 0N/A * Initializes class descriptor representing a proxy class. 0N/A "cannot bind proxy descriptor to a non-proxy class");
0N/A * Initializes class descriptor representing a non-proxy class. 0N/A "cannot bind non-proxy descriptor to a proxy class");
0N/A "cannot bind enum descriptor to a non-enum class" :
0N/A "cannot bind non-enum descriptor to an enum class");
0N/A "local class incompatible: " +
0N/A "stream classdesc serialVersionUID = " +
suid +
0N/A ", local class serialVersionUID = " +
0N/A "local class name incompatible with stream class " +
0N/A "Serializable incompatible with Externalizable");
0N/A // reassign to matched fields so as to reflect local unshared settings 0N/A * Reads non-proxy class descriptor information from given input stream. 0N/A * The resulting class descriptor is not fully functional; it can only be 0N/A * used as input to the ObjectInputStream.resolveClass() and 0N/A name,
"serializable and externalizable flags conflict");
0N/A "enum descriptor has non-zero serialVersionUID: " +
suid);
0N/A * Writes non-proxy class descriptor information to given output stream. 0N/A * Returns ClassNotFoundException (if any) thrown while attempting to 0N/A * resolve local class corresponding to this class descriptor. 0N/A * Throws an InvalidClassException if object instances referencing this 0N/A * class descriptor should not be allowed to deserialize. This method does 0N/A * not apply to deserialization of enum constants. 0N/A * Throws an InvalidClassException if objects whose class is represented by 0N/A * this descriptor should not be allowed to serialize. This method does 0N/A * not apply to serialization of enum constants. 0N/A * Throws an InvalidClassException if objects whose class is represented by 0N/A * this descriptor should not be permitted to use default serialization 0N/A * (e.g., if the class declares serializable fields that do not correspond 0N/A * to actual fields, and hence must use the GetField API). This method 0N/A * does not apply to deserialization of enum constants. 0N/A * Returns superclass descriptor. Note that on the receiving side, the 0N/A * superclass descriptor may be bound to a class that is not a superclass 0N/A * of the subclass descriptor's bound class. 0N/A * Returns the "local" class descriptor for the class associated with this 0N/A * class descriptor (i.e., the result of 0N/A * ObjectStreamClass.lookup(this.forClass())) or null if there is no class 0N/A * associated with this descriptor. 0N/A * Returns arrays of ObjectStreamFields representing the serializable 0N/A * fields of the represented class. If copy is true, a clone of this class 0N/A * descriptor's field array is returned, otherwise the array itself is 0N/A * Looks up a serializable field of the represented class by name and type. 0N/A * A specified type of null matches all types, Object.class matches all 0N/A * non-primitive types, and any other non-null type matches assignable 0N/A * types only. Returns matching field, or null if no match found. 0N/A * Returns true if class descriptor represents a dynamic proxy class, false 0N/A * Returns true if class descriptor represents an enum type, false 0N/A * Returns true if represented class implements Externalizable, false 0N/A * Returns true if represented class implements Serializable, false 0N/A * Returns true if class descriptor represents externalizable class that 0N/A * has written its data in 1.2 (block data) format, false otherwise. 0N/A * Returns true if class descriptor represents serializable (but not 0N/A * externalizable) class which has written its data via a custom 0N/A * writeObject() method, false otherwise. 0N/A * be instantiated by the serialization runtime--i.e., if it is 0N/A * externalizable and defines a public no-arg constructor, or if it is 0N/A * non-externalizable and its first non-serializable superclass defines an 0N/A * accessible no-arg constructor. Otherwise, returns false. 0N/A * Returns true if represented class is serializable (but not 0N/A * externalizable) and defines a conformant writeObject method. Otherwise, 0N/A * Returns true if represented class is serializable (but not 0N/A * externalizable) and defines a conformant readObject method. Otherwise, 0N/A * Returns true if represented class is serializable (but not 0N/A * externalizable) and defines a conformant readObjectNoData method. 0N/A * Otherwise, returns false. 0N/A * Returns true if represented class is serializable or externalizable and 0N/A * defines a conformant writeReplace method. Otherwise, returns false. 0N/A * Returns true if represented class is serializable or externalizable and 0N/A * defines a conformant readResolve method. Otherwise, returns false. 0N/A * Creates a new instance of the represented class. If the class is 0N/A * externalizable, invokes its public no-arg constructor; otherwise, if the 0N/A * class is serializable, invokes the no-arg constructor of the first 0N/A * non-serializable superclass. Throws UnsupportedOperationException if 0N/A * this class descriptor is not associated with a class, if the associated 0N/A * class is non-serializable or if the appropriate no-arg constructor is 0N/A // should not occur, as access checks have been suppressed 0N/A * Invokes the writeObject method of the represented serializable class. 0N/A * Throws UnsupportedOperationException if this class descriptor is not 0N/A * associated with a class, or if the class is externalizable, 0N/A * non-serializable or does not define writeObject. 0N/A // should not occur, as access checks have been suppressed 0N/A * Invokes the readObject method of the represented serializable class. 0N/A * Throws UnsupportedOperationException if this class descriptor is not 0N/A * associated with a class, or if the class is externalizable, 0N/A * non-serializable or does not define readObject. 0N/A // should not occur, as access checks have been suppressed 0N/A * Invokes the readObjectNoData method of the represented serializable 0N/A * class. Throws UnsupportedOperationException if this class descriptor is 0N/A * not associated with a class, or if the class is externalizable, 0N/A * non-serializable or does not define readObjectNoData. 0N/A // should not occur, as access checks have been suppressed 0N/A * Invokes the writeReplace method of the represented serializable class and 0N/A * returns the result. Throws UnsupportedOperationException if this class 0N/A * descriptor is not associated with a class, or if the class is 0N/A * non-serializable or does not define writeReplace. 0N/A // should not occur, as access checks have been suppressed 0N/A * Invokes the readResolve method of the represented serializable class and 0N/A * returns the result. Throws UnsupportedOperationException if this class 0N/A * descriptor is not associated with a class, or if the class is 0N/A * non-serializable or does not define readResolve. 0N/A // should not occur, as access checks have been suppressed 0N/A * Class representing the portion of an object's serialized form allotted 0N/A * to data described by a given class descriptor. If "hasData" is false, 0N/A * the object's serialized form does not contain data associated with the 0N/A /** class descriptor "occupying" this slot */ 0N/A /** true if serialized form includes data for this slot's descriptor */ 0N/A * Returns array of ClassDataSlot instances representing the data layout 0N/A * (including superclass data) for serialized objects described by this 0N/A * class descriptor. ClassDataSlots are ordered by inheritance with those 0N/A * containing "higher" superclasses appearing first. The final 0N/A * ClassDataSlot contains a reference to this descriptor. 0N/A // REMIND: synchronize instead of relying on volatile? 0N/A // locate closest non-serializable superclass 0N/A // search up inheritance hierarchy for class with matching name 0N/A // add "no data" slot for each unmatched class below match 0N/A // add "no data" slot for any leftover unmatched classes 0N/A // order slots from superclass -> subclass 0N/A * Returns aggregate size (in bytes) of marshalled primitive field values 0N/A * for represented class. * Returns number of non-primitive serializable fields of represented * Fetches the serializable primitive field values of object obj and * marshals them into byte array buf starting at offset 0. It is the * responsibility of the caller to ensure that obj is of the proper type if * Sets the serializable primitive fields of object obj using values * unmarshalled from byte array buf starting at offset 0. It is the * responsibility of the caller to ensure that obj is of the proper type if * Fetches the serializable object field values of object obj and stores * them in array vals starting at offset 0. It is the responsibility of * the caller to ensure that obj is of the proper type if non-null. * Sets the serializable object fields of object obj using values from * array vals starting at offset 0. It is the responsibility of the caller * to ensure that obj is of the proper type if non-null. * Calculates and sets serializable field offsets, as well as primitive * data size and object field count totals. Throws InvalidClassException * if fields are illegally ordered. * If given class is the same as the class associated with this class * descriptor, returns reference to this class descriptor. Otherwise, * returns variant of this class descriptor bound to given class. * Returns public no-arg constructor of given class, or null if none found. * Access checks are disabled on the returned constructor (if any), since * the defining class may still be non-public. * Returns subclass-accessible no-arg constructor of first non-serializable * superclass, or null if none found. Access checks are disabled on the * returned constructor (if any). * Returns non-static, non-abstract method with given signature provided it * is defined by or accessible (via inheritance) by the given class, or * null if no match found. Access checks are disabled on the returned * Returns non-static private method with given signature defined by given * class, or null if none found. Access checks are disabled on the * returned method (if any). * Returns true if classes are defined in the same runtime package, false * Returns package name of given class. * Compares class names for equality, ignoring package names. Returns true * if class names equal, false otherwise. * Returns JVM type signature for given class. * Returns JVM type signature for given list of parameters and return type. * Convenience method for throwing an exception that is either a * RuntimeException, Error, or of some unexpected type (in which case it is * wrapped inside an IOException). * Returns ObjectStreamField array describing the serializable fields of * the given class. Serializable fields backed by an actual field of the * class are represented by ObjectStreamFields with corresponding non-null * Field objects. Throws InvalidClassException if the (explicitly * declared) serializable fields are invalid. * Returns serializable fields of given class as defined explicitly by a * "serialPersistentFields" field, or null if no appropriate * "serialPersistentFields" field is defined. Serializable fields backed * by an actual field of the class are represented by ObjectStreamFields * with corresponding non-null Field objects. For compatibility with past * releases, a "serialPersistentFields" field with a null value is * considered equivalent to not declaring "serialPersistentFields". Throws * InvalidClassException if the declared serializable fields are * invalid--e.g., if multiple fields share the same name. "multiple serializable fields named " +
fname);
* Returns array of ObjectStreamFields corresponding to all non-static * non-transient fields declared by given class. Each ObjectStreamField * contains a Field object for the field it represents. If no default * serializable fields exist, NO_FIELDS is returned. * Returns explicit serial version UID value declared by given class, or * Computes the default serial version UID value for the given class. * compensate for javac bug in which ABSTRACT bit was set for an * interface only if the interface declared methods * compensate for change in 1.2FCS in which * Class.getInterfaces() was modified to return Cloneable and * Serializable for array classes. * Returns true if the given class defines a static initializer method, * during serialVersionUID calculation. * Class for setting and retrieving serializable field values in batch. // REMIND: dynamically generate these? /** handle for performing unsafe operations */ /** fields to operate on */ /** number of primitive fields */ /** unsafe field keys for reading fields - may contain dupes */ /** unsafe fields keys for writing fields - no dupes */ /** field data offsets */ * Constructs FieldReflector capable of setting/getting values from the * subset of fields whose ObjectStreamFields contain non-null * reflective Field objects. ObjectStreamFields with null Fields are * treated as filler, for which get operations return default values * and set operations discard given values. for (
int i =
0; i <
nfields; i++) {
* Returns list of ObjectStreamFields representing fields operated on * contained by ObjectStreamFields in the list reflect their bindings * to locally defined serializable fields. * Fetches the serializable primitive field values of object obj and * marshals them into byte array buf starting at offset 0. The caller * is responsible for ensuring that obj is of the proper type. /* assuming checkDefaultSerialize() has been called on the class * descriptor this FieldReflector was obtained from, no field keys * in array should be equal to Unsafe.INVALID_FIELD_OFFSET. * Sets the serializable primitive fields of object obj using values * unmarshalled from byte array buf starting at offset 0. The caller * is responsible for ensuring that obj is of the proper type. continue;
// discard value * Fetches the serializable object field values of object obj and * stores them in array vals starting at offset 0. The caller is * responsible for ensuring that obj is of the proper type. /* assuming checkDefaultSerialize() has been called on the class * descriptor this FieldReflector was obtained from, no field keys * in array should be equal to Unsafe.INVALID_FIELD_OFFSET. * Sets the serializable object fields of object obj using values from * array vals starting at offset 0. The caller is responsible for * ensuring that obj is of the proper type; however, attempts to set a * field with a value of the wrong type will trigger an appropriate continue;
// discard value "cannot assign instance of " +
* Matches given set of serializable fields with serializable fields * described by the given local class descriptor, and returns a * subset of fields that match (non-matching fields are treated as filler, * for which get operations return default values and set operations * discard given values). Throws InvalidClassException if unresolvable * type conflicts exist between the two sets of fields. // class irrelevant if no fields * FieldReflector cache lookup key. Keys are considered equal if they * refer to the same class and equivalent field formats. * Matches given set of serializable fields with serializable fields * obtained from the given local class descriptor (which contain bindings * to reflective Field objects). Returns list of ObjectStreamFields in * which each ObjectStreamField whose signature matches that of a local * field contains a Field object for that field; unmatched * ObjectStreamFields contain null Field objects. Shared/unshared settings * of the returned ObjectStreamFields also reflect those of matched local * ObjectStreamFields. Throws InvalidClassException if unresolvable type * conflicts exist between the two sets of fields. * Even if fields == localFields, we cannot simply return localFields * here. In previous implementations of serialization, * ObjectStreamField.getType() returned Object.class if the * ObjectStreamField represented a non-primitive field and belonged to * a non-local class descriptor. To preserve this (questionable) * behavior, the ObjectStreamField instances returned by matchFields * cannot report non-primitive types other than Object.class; hence * localFields cannot be returned directly. "incompatible types for field " + f.
getName());
* Removes from the specified map any keys that have been enqueued * on the specified reference queue. * Weak key for Class objects. * saved value of the referent's identity hash code, to maintain * a consistent hash code after the referent has been cleared * Create a new WeakClassKey to the given object, registered * Returns the identity hash code of the original referent. * Returns true if the given object is this identical * WeakClassKey instance, or, if this object's referent has not * been cleared, if the given object is another WeakClassKey * instance with the identical non-null referent as this one.