That's unfortunate. Can you steal a bit in one of the int fields? E.g. lastAnnotationsRedefinedCount surely doesn't need the full range right? :) Sent from my phone On Jan 25, 2013 11:02 AM, "Peter Levart" <peter.levart@gmail.com> wrote:
On 01/25/2013 06:35 AM, David Holmes wrote:
On 25/01/2013 2:36 AM, Peter Levart wrote:
On 01/24/2013 04:45 PM, Peter Levart wrote:
Is there really no existing alignment gap in j.l.Class layout that a boolean can slide into?
There might be, I will check.
All instance fields in j.l.Class are either references or ints.
Instance are also 8-byte aligned though so does that leave any slop where an extra field would not make an actual difference. (I should know the answer to that after the ReflectionData changes but don't recall.)
Note: I have not looked at this, just considering the "add a field" aspect of it.
David
Here's what the Unsafe reports about current layout of j.l.Class (ReflectionData changes already taken into account):
32 bit pointers:
java.lang.Class instance field offsets:
Field Type Field Name Offset ---------- ---------- ------ Constructor cachedConstructor 12 Class newInstanceCallerCache 16 String name 20 SoftReference reflectionData 24 ClassRepository genericInfo 28 Object[] enumConstants 32 Map enumConstantDirectory 36 Map annotations 40 Map declaredAnnotations 44 AnnotationType annotationType 48 ClassValueMap classValueMap 52 int classRedefinedCount 80 int lastAnnotationsRedefinedCount 84
java.lang.String static field offsets:
Field Type Field Name Offset ---------- ---------- ------ ObjectStreamField[] serialPersistentFields 96 Comparator CASE_INSENSITIVE_ORDER 100 long serialVersionUID 104 int HASHING_SEED 112
64 bit pointers:
java.lang.Class instance field offsets:
Field Type Field Name Offset ---------- ---------- ------ Constructor cachedConstructor 16 Class newInstanceCallerCache 24 String name 32 SoftReference reflectionData 40 ClassRepository genericInfo 48 Object[] enumConstants 56 Map enumConstantDirectory 64 Map annotations 72 Map declaredAnnotations 80 AnnotationType annotationType 88 ClassValueMap classValueMap 96 int classRedefinedCount 128 int lastAnnotationsRedefinedCount 132
java.lang.String static field offsets:
Field Type Field Name Offset ---------- ---------- ------ ObjectStreamField[] serialPersistentFields 144 Comparator CASE_INSENSITIVE_ORDER 152 long serialVersionUID 160 int HASHING_SEED 168
If I add a boolean instance field "isProxy" to j.l.Class the report changes to:
32 bit pointers:
java.lang.Class instance field offsets:
Field Type Field Name Offset ---------- ---------- ------ Constructor cachedConstructor 12 Class newInstanceCallerCache 16 String name 20 SoftReference reflectionData 24 ClassRepository genericInfo 28 Object[] enumConstants 32 Map enumConstantDirectory 36 Map annotations 40 Map declaredAnnotations 44 AnnotationType annotationType 48 ClassValueMap classValueMap 52 int classRedefinedCount 80 int lastAnnotationsRedefinedCount 84 boolean isProxy 96
java.lang.String static field offsets:
Field Type Field Name Offset ---------- ---------- ------ ObjectStreamField[] serialPersistentFields 104 Comparator CASE_INSENSITIVE_ORDER 108 long serialVersionUID 112 int HASHING_SEED 120
64 bit pointers:
java.lang.Class instance field offsets:
Field Type Field Name Offset ---------- ---------- ------ Constructor cachedConstructor 16 Class newInstanceCallerCache 24 String name 32 SoftReference reflectionData 40 ClassRepository genericInfo 48 Object[] enumConstants 56 Map enumConstantDirectory 64 Map annotations 72 Map declaredAnnotations 80 AnnotationType annotationType 88 ClassValueMap classValueMap 96 int classRedefinedCount 128 int lastAnnotationsRedefinedCount 132 boolean isProxy 144
java.lang.String static field offsets:
Field Type Field Name Offset ---------- ---------- ------ ObjectStreamField[] serialPersistentFields 152 Comparator CASE_INSENSITIVE_ORDER 160 long serialVersionUID 168 int HASHING_SEED 176
...so it seems that in both cases, adding a boolean to j.l.Class wastes 8 bytes per Class object :-(
Regards, Peter