< prev index next >

src/java.base/share/classes/java/io/ObjectStreamClass.java

Print this page

        

*** 1183,1205 **** this.desc = desc; 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() throws InvalidClassException { --- 1183,1223 ---- this.desc = desc; this.hasData = hasData; } } + private static final Unsafe U = Unsafe.getUnsafe(); + private static final long CDS_OFFSET; + + static { + Field field = null; + try { + field = ObjectStreamClass.class.getDeclaredField("dataLayout"); + } catch(NoSuchFieldException | SecurityException e) { + } + if(field == null) { + CDS_OFFSET = Unsafe.INVALID_FIELD_OFFSET; + } else { + CDS_OFFSET = U.objectFieldOffset(field); + } + } + /** * 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? ! ClassDataSlot[] slots = (ClassDataSlot[])U.getObjectAcquire(this, CDS_OFFSET); ! if (slots == null) { ! slots = getClassDataLayout0(); ! U.putObjectRelease(this, CDS_OFFSET, slots); } ! return slots; } private ClassDataSlot[] getClassDataLayout0() throws InvalidClassException {
< prev index next >