< prev index next >
src/java.base/share/classes/java/io/ObjectStreamClass.java
Print this page
*** 170,180 ****
/** number of non-primitive fields */
private int numObjFields;
/** reflector for setting/getting serializable field values */
private FieldReflector fieldRefl;
/** data layout of serialized objects described by this class desc */
! private volatile ClassDataSlot[] dataLayout;
/** serialization-appropriate constructor, or null if none */
private Constructor<?> cons;
/** class-defined writeObject method, or null if none */
private Method writeObjectMethod;
--- 170,180 ----
/** number of non-primitive fields */
private int numObjFields;
/** reflector for setting/getting serializable field values */
private FieldReflector fieldRefl;
/** data layout of serialized objects described by this class desc */
! private ClassDataSlot[] dataLayout;
/** serialization-appropriate constructor, or null if none */
private Constructor<?> cons;
/** class-defined writeObject method, or null if none */
private Method writeObjectMethod;
*** 1184,1203 ****
this.hasData = hasData;
}
}
/**
* Returns array of ClassDataSlot instances representing the data layout
* (including superclass data) for serialized objects described by this
* class descriptor. ClassDataSlots are ordered by inheritance with those
* containing "higher" superclasses appearing first. The final
* ClassDataSlot contains a reference to this descriptor.
*/
ClassDataSlot[] getClassDataLayout() throws InvalidClassException {
// REMIND: synchronize instead of relying on volatile?
if (dataLayout == null) {
! dataLayout = getClassDataLayout0();
}
return dataLayout;
}
private ClassDataSlot[] getClassDataLayout0()
--- 1184,1215 ----
this.hasData = hasData;
}
}
/**
+ * Class to ensure elements of ClassDataSlot[] are visible to other
+ * threads. The "final" qualifier of the variable slots is necessary.
+ */
+ private static class DataLayout {
+ final ClassDataSlot[] slots;
+ DataLayout(ClassDataSlot[] s) {
+ slots = s;
+ }
+ }
+
+ /**
* Returns array of ClassDataSlot instances representing the data layout
* (including superclass data) for serialized objects described by this
* class descriptor. ClassDataSlots are ordered by inheritance with those
* containing "higher" superclasses appearing first. The final
* ClassDataSlot contains a reference to this descriptor.
*/
ClassDataSlot[] getClassDataLayout() throws InvalidClassException {
// REMIND: synchronize instead of relying on volatile?
if (dataLayout == null) {
! ClassDataSlot[] slots = getClassDataLayout0();
! dataLayout = new DataLayout(slots).slots;
}
return dataLayout;
}
private ClassDataSlot[] getClassDataLayout0()
< prev index next >