Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8080588 VarHandles development
  3. JDK-8130756

MethodType[] VarHandle.types wastes memory

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Fixed
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • None

      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.

            psandoz Paul Sandoz
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: