JDK-8130756 : MethodType[] VarHandle.types wastes memory
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-07-08
  • Updated: 2015-07-10
  • Resolved: 2015-07-10
Description
So I did a few differential footprint tests, in order to discover that each VarHandle instance references its own MethodType[] array.

It might be advisable to explode the MethodType[] array into the individual fields. MethodType-s are cached already in MethodType.methodType factory.

***** double (static):
 footprint:
     COUNT       AVG       SUM   DESCRIPTION
         1        32        32   [Ljava.lang.invoke.MethodType;
         1        32        32
java.lang.invoke.VarHandleDoubles$FieldStaticReadWrite
         2                  64   (total)


java.lang.invoke.VarHandleDoubles.FieldInstanceReadWrite object internals:
 OFFSET  SIZE         TYPE DESCRIPTION                       VALUE
      0     4              (object header)                   N/A
      4     4              (object header)                   N/A
      8     4              (object header)                   N/A
     12     4 MethodType[] VarHandle.types                   N/A
     16     4      VarForm VarHandle.vform                   N/A
     20     4              (alignment/padding gap)           N/A
     24     8         long FieldInstanceReadOnly.fieldOffset N/A
Instance size: 32 bytes (reported by Instrumentation API)
Space losses: 4 bytes internal + 0 bytes external = 4 bytes total

Also, since there are four elements in MethodType[], we would reuse the alignment gap @20 without producing more gaps. Back-envelope calculation says that we save 32 (MethodType[]) - 8 (two additional slots for references in VarHandle) bytes per VarHandle instance.
Comments
Confirmed, thanks!
10-07-2015

http://hg.openjdk.java.net/jdk9/sandbox/jdk/rev/8c6d691db3ee
10-07-2015