Initial preview: JEP-149 Reduced Class instance size

David Holmes david.holmes at oracle.com
Thu Apr 5 02:50:59 UTC 2012


http://cr.openjdk.java.net/~dholmes/JEP-149/webrev/

This is an early look at a proposed change to reduce the instance size 
of Java Class objects in the common case that reflection is not used.

In SE 7 a java.lang.Class instance is 104 bytes on 32-bit systems. It 
consists of the 8-byte object header, 19 declared fields and 5 injected 
fields (fields added by the VM as-if they were declared in 
java.lang.Class but which do not appear in the Java source code). There 
are 10 reference fields associated with reflection caching that can be 
moved to a helper object with no impact on the VM or serialization 
protocols. Adding back a reference for the helper, that saves 9 
references. Notionally this is 36 bytes on 32-bit but due to 8-byte 
alignment it only saves 32 bytes. That gives a size of 72 bytes - a 
reduction of 30%. This initial modification has been prototyped for 
initial performance measurements.

Note that if reflection is used then the amount of memory used by the 
Class will increase by 8-bytes - that being the additional object header 
of the ReflectionHelper instance. So the net gain depends on the ratio 
of reflection using classes to non-reflection-using classes in an 
application.

Please note that I've put this out just before I disappear on vacation 
for 10 days, so if you don't see any responses from me that is why. :)

Thanks,
David Holmes



More information about the core-libs-dev mailing list