82 new ReflectionFactory.GetReflectionFactoryAction()); |
82 new ReflectionFactory.GetReflectionFactoryAction()); |
83 |
83 |
84 private static class Caches { |
84 private static class Caches { |
85 /** cache mapping local classes -> descriptors */ |
85 /** cache mapping local classes -> descriptors */ |
86 static final ConcurrentMap<WeakClassKey,Reference<?>> localDescs = |
86 static final ConcurrentMap<WeakClassKey,Reference<?>> localDescs = |
87 new ConcurrentHashMap<WeakClassKey,Reference<?>>(); |
87 new ConcurrentHashMap<>(); |
88 |
88 |
89 /** cache mapping field group/local desc pairs -> field reflectors */ |
89 /** cache mapping field group/local desc pairs -> field reflectors */ |
90 static final ConcurrentMap<FieldReflectorKey,Reference<?>> reflectors = |
90 static final ConcurrentMap<FieldReflectorKey,Reference<?>> reflectors = |
91 new ConcurrentHashMap<FieldReflectorKey,Reference<?>>(); |
91 new ConcurrentHashMap<>(); |
92 |
92 |
93 /** queue for WeakReferences to local classes */ |
93 /** queue for WeakReferences to local classes */ |
94 private static final ReferenceQueue<Class<?>> localDescsQueue = |
94 private static final ReferenceQueue<Class<?>> localDescsQueue = |
95 new ReferenceQueue<Class<?>>(); |
95 new ReferenceQueue<>(); |
96 /** queue for WeakReferences to field reflectors keys */ |
96 /** queue for WeakReferences to field reflectors keys */ |
97 private static final ReferenceQueue<Class<?>> reflectorsQueue = |
97 private static final ReferenceQueue<Class<?>> reflectorsQueue = |
98 new ReferenceQueue<Class<?>>(); |
98 new ReferenceQueue<>(); |
99 } |
99 } |
100 |
100 |
101 /** class associated with this descriptor (if any) */ |
101 /** class associated with this descriptor (if any) */ |
102 private Class<?> cl; |
102 private Class<?> cl; |
103 /** name of class represented by this descriptor */ |
103 /** name of class represented by this descriptor */ |
288 entry = ref.get(); |
288 entry = ref.get(); |
289 } |
289 } |
290 EntryFuture future = null; |
290 EntryFuture future = null; |
291 if (entry == null) { |
291 if (entry == null) { |
292 EntryFuture newEntry = new EntryFuture(); |
292 EntryFuture newEntry = new EntryFuture(); |
293 Reference<?> newRef = new SoftReference<EntryFuture>(newEntry); |
293 Reference<?> newRef = new SoftReference<>(newEntry); |
294 do { |
294 do { |
295 if (ref != null) { |
295 if (ref != null) { |
296 Caches.localDescs.remove(key, ref); |
296 Caches.localDescs.remove(key, ref); |
297 } |
297 } |
298 ref = Caches.localDescs.putIfAbsent(key, newRef); |
298 ref = Caches.localDescs.putIfAbsent(key, newRef); |
327 entry = new ObjectStreamClass(cl); |
327 entry = new ObjectStreamClass(cl); |
328 } catch (Throwable th) { |
328 } catch (Throwable th) { |
329 entry = th; |
329 entry = th; |
330 } |
330 } |
331 if (future.set(entry)) { |
331 if (future.set(entry)) { |
332 Caches.localDescs.put(key, new SoftReference<Object>(entry)); |
332 Caches.localDescs.put(key, new SoftReference<>(entry)); |
333 } else { |
333 } else { |
334 // nested lookup call already set future |
334 // nested lookup call already set future |
335 entry = future.get(); |
335 entry = future.get(); |
336 } |
336 } |
337 } |
337 } |
1128 } |
1128 } |
1129 |
1129 |
1130 private ClassDataSlot[] getClassDataLayout0() |
1130 private ClassDataSlot[] getClassDataLayout0() |
1131 throws InvalidClassException |
1131 throws InvalidClassException |
1132 { |
1132 { |
1133 ArrayList<ClassDataSlot> slots = new ArrayList<ClassDataSlot>(); |
1133 ArrayList<ClassDataSlot> slots = new ArrayList<>(); |
1134 Class<?> start = cl, end = cl; |
1134 Class<?> start = cl, end = cl; |
1135 |
1135 |
1136 // locate closest non-serializable superclass |
1136 // locate closest non-serializable superclass |
1137 while (end != null && Serializable.class.isAssignableFrom(end)) { |
1137 while (end != null && Serializable.class.isAssignableFrom(end)) { |
1138 end = end.getSuperclass(); |
1138 end = end.getSuperclass(); |
1564 return NO_FIELDS; |
1564 return NO_FIELDS; |
1565 } |
1565 } |
1566 |
1566 |
1567 ObjectStreamField[] boundFields = |
1567 ObjectStreamField[] boundFields = |
1568 new ObjectStreamField[serialPersistentFields.length]; |
1568 new ObjectStreamField[serialPersistentFields.length]; |
1569 Set<String> fieldNames = new HashSet<String>(serialPersistentFields.length); |
1569 Set<String> fieldNames = new HashSet<>(serialPersistentFields.length); |
1570 |
1570 |
1571 for (int i = 0; i < serialPersistentFields.length; i++) { |
1571 for (int i = 0; i < serialPersistentFields.length; i++) { |
1572 ObjectStreamField spf = serialPersistentFields[i]; |
1572 ObjectStreamField spf = serialPersistentFields[i]; |
1573 |
1573 |
1574 String fname = spf.getName(); |
1574 String fname = spf.getName(); |
1602 * contains a Field object for the field it represents. If no default |
1602 * contains a Field object for the field it represents. If no default |
1603 * serializable fields exist, NO_FIELDS is returned. |
1603 * serializable fields exist, NO_FIELDS is returned. |
1604 */ |
1604 */ |
1605 private static ObjectStreamField[] getDefaultSerialFields(Class<?> cl) { |
1605 private static ObjectStreamField[] getDefaultSerialFields(Class<?> cl) { |
1606 Field[] clFields = cl.getDeclaredFields(); |
1606 Field[] clFields = cl.getDeclaredFields(); |
1607 ArrayList<ObjectStreamField> list = new ArrayList<ObjectStreamField>(); |
1607 ArrayList<ObjectStreamField> list = new ArrayList<>(); |
1608 int mask = Modifier.STATIC | Modifier.TRANSIENT; |
1608 int mask = Modifier.STATIC | Modifier.TRANSIENT; |
1609 |
1609 |
1610 for (int i = 0; i < clFields.length; i++) { |
1610 for (int i = 0; i < clFields.length; i++) { |
1611 if ((clFields[i].getModifiers() & mask) == 0) { |
1611 if ((clFields[i].getModifiers() & mask) == 0) { |
1612 list.add(new ObjectStreamField(clFields[i], false, true)); |
1612 list.add(new ObjectStreamField(clFields[i], false, true)); |
1853 int nfields = fields.length; |
1853 int nfields = fields.length; |
1854 readKeys = new long[nfields]; |
1854 readKeys = new long[nfields]; |
1855 writeKeys = new long[nfields]; |
1855 writeKeys = new long[nfields]; |
1856 offsets = new int[nfields]; |
1856 offsets = new int[nfields]; |
1857 typeCodes = new char[nfields]; |
1857 typeCodes = new char[nfields]; |
1858 ArrayList<Class<?>> typeList = new ArrayList<Class<?>>(); |
1858 ArrayList<Class<?>> typeList = new ArrayList<>(); |
1859 Set<Long> usedKeys = new HashSet<Long>(); |
1859 Set<Long> usedKeys = new HashSet<>(); |
1860 |
1860 |
1861 |
1861 |
1862 for (int i = 0; i < nfields; i++) { |
1862 for (int i = 0; i < nfields; i++) { |
1863 ObjectStreamField f = fields[i]; |
1863 ObjectStreamField f = fields[i]; |
1864 Field rf = f.getField(); |
1864 Field rf = f.getField(); |
2090 entry = ref.get(); |
2090 entry = ref.get(); |
2091 } |
2091 } |
2092 EntryFuture future = null; |
2092 EntryFuture future = null; |
2093 if (entry == null) { |
2093 if (entry == null) { |
2094 EntryFuture newEntry = new EntryFuture(); |
2094 EntryFuture newEntry = new EntryFuture(); |
2095 Reference<?> newRef = new SoftReference<EntryFuture>(newEntry); |
2095 Reference<?> newRef = new SoftReference<>(newEntry); |
2096 do { |
2096 do { |
2097 if (ref != null) { |
2097 if (ref != null) { |
2098 Caches.reflectors.remove(key, ref); |
2098 Caches.reflectors.remove(key, ref); |
2099 } |
2099 } |
2100 ref = Caches.reflectors.putIfAbsent(key, newRef); |
2100 ref = Caches.reflectors.putIfAbsent(key, newRef); |
2116 entry = new FieldReflector(matchFields(fields, localDesc)); |
2116 entry = new FieldReflector(matchFields(fields, localDesc)); |
2117 } catch (Throwable th) { |
2117 } catch (Throwable th) { |
2118 entry = th; |
2118 entry = th; |
2119 } |
2119 } |
2120 future.set(entry); |
2120 future.set(entry); |
2121 Caches.reflectors.put(key, new SoftReference<Object>(entry)); |
2121 Caches.reflectors.put(key, new SoftReference<>(entry)); |
2122 } |
2122 } |
2123 |
2123 |
2124 if (entry instanceof FieldReflector) { |
2124 if (entry instanceof FieldReflector) { |
2125 return (FieldReflector) entry; |
2125 return (FieldReflector) entry; |
2126 } else if (entry instanceof InvalidClassException) { |
2126 } else if (entry instanceof InvalidClassException) { |