diff options
author | jfrijters <jfrijters> | 2013-08-09 13:46:52 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2013-08-09 13:46:52 +0400 |
commit | 8ac9625c272225bc134508181c31a4025f0dcdb3 (patch) | |
tree | e6e1b0dc5a7e15a7075668c4eed15f62c675e9e0 | |
parent | 546f3216e16771166236121ca70441e01360840a (diff) |
Merged in some missing changes.
-rw-r--r-- | openjdk/java/io/ObjectStreamClass.java | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/openjdk/java/io/ObjectStreamClass.java b/openjdk/java/io/ObjectStreamClass.java index 7cca3552..b448ab10 100644 --- a/openjdk/java/io/ObjectStreamClass.java +++ b/openjdk/java/io/ObjectStreamClass.java @@ -1848,8 +1848,10 @@ public class ObjectStreamClass implements Serializable { private final ObjectStreamField[] fields; /** number of primitive fields */ private final int numPrimFields; - /** unsafe field keys */ - private final long[] keys; + /** unsafe field keys for reading fields - may contain dupes */ + private final long[] readKeys; + /** unsafe fields keys for writing fields - no dupes */ + private final long[] writeKeys; /** field data offsets */ private final int[] offsets; /** field type codes */ @@ -1867,16 +1869,22 @@ public class ObjectStreamClass implements Serializable { FieldReflector(ObjectStreamField[] fields) { this.fields = fields; int nfields = fields.length; - keys = new long[nfields]; + readKeys = new long[nfields]; + writeKeys = new long[nfields]; offsets = new int[nfields]; typeCodes = new char[nfields]; ArrayList<Class<?>> typeList = new ArrayList<>(); + Set<Long> usedKeys = new HashSet<>(); + for (int i = 0; i < nfields; i++) { ObjectStreamField f = fields[i]; Field rf = f.getField(); - keys[i] = (rf != null) ? + long key = (rf != null) ? unsafe.objectFieldOffset(rf) : Unsafe.INVALID_FIELD_OFFSET; + readKeys[i] = key; + writeKeys[i] = usedKeys.add(key) ? + key : Unsafe.INVALID_FIELD_OFFSET; offsets[i] = f.getOffset(); typeCodes[i] = f.getTypeCode(); if (!f.isPrimitive()) { @@ -1912,7 +1920,7 @@ public class ObjectStreamClass implements Serializable { * in array should be equal to Unsafe.INVALID_FIELD_OFFSET. */ for (int i = 0; i < numPrimFields; i++) { - long key = keys[i]; + long key = readKeys[i]; int off = offsets[i]; switch (typeCodes[i]) { case 'Z': @@ -1963,7 +1971,7 @@ public class ObjectStreamClass implements Serializable { throw new NullPointerException(); } for (int i = 0; i < numPrimFields; i++) { - long key = keys[i]; + long key = writeKeys[i]; if (key == Unsafe.INVALID_FIELD_OFFSET) { continue; // discard value } @@ -2024,7 +2032,7 @@ public class ObjectStreamClass implements Serializable { switch (typeCodes[i]) { case 'L': case '[': - vals[offsets[i]] = unsafe.getObject(obj, keys[i]); + vals[offsets[i]] = unsafe.getObject(obj, readKeys[i]); break; default: @@ -2045,7 +2053,7 @@ public class ObjectStreamClass implements Serializable { throw new NullPointerException(); } for (int i = numPrimFields; i < fields.length; i++) { - long key = keys[i]; + long key = writeKeys[i]; if (key == Unsafe.INVALID_FIELD_OFFSET) { continue; // discard value } @@ -2148,7 +2156,7 @@ public class ObjectStreamClass implements Serializable { } } - private static native Object getFastFieldReflector(Object fields); + private static native Object getFastFieldReflector(ObjectStreamField[] fields); /** * FieldReflector cache lookup key. Keys are considered equal if they |