Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8326436

Improve the accuracy of the instance size in hprof heap dumps

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Withdrawn
    • Icon: P4 P4
    • None
    • core-svc
    • None
    • behavioral
    • minimal
    • Hide
      Compatibility risk is minimal.
      HPROF format itself is not changed.
      Value of the "instance size" field is not required for reading/parsing HPROF records.
      If some HPROF consumer needs the value as it's reported now, it can be computed using class information already present in the HPROF file.
      HPROF tools can detect that the field contains actual instance size by checking the field for lava.lang.Object class.
      Show
      Compatibility risk is minimal. HPROF format itself is not changed. Value of the "instance size" field is not required for reading/parsing HPROF records. If some HPROF consumer needs the value as it's reported now, it can be computed using class information already present in the HPROF file. HPROF tools can detect that the field contains actual instance size by checking the field for lava.lang.Object class.
    • File or wire format
    • JDK

      Summary

      Change implementation of heap dumpers (VM and Serviceability Agent) to report actual instance size.

      Problem

      For all loaded classes HPROF heap dump file contains a HPROF_GC_CLASS_DUMP record. One of the field of the record is

      u4         instance size (in bytes)

      HPROF format was created to be independent of VM and value of the field was reported as sum of sizes of all instance fields.

      HPROF tools for memory analysis require actual size of the instances in the heap (taking into account object header, padding, compressed oops, etc.). So the tools cannot rely on the reported value and instead try to calculate actual instance size from class information (class fields/types, class hierarchy), using knowledge about VM internals. This is prone to errors in estimations.

      Solution

      VM and SA knows actual instance size and can report it in HPROF heap dump.

      Specification

      There is no official HPROF format spec, the only description of the format are comments in the JDK source code (2 identical copies in VM heap dumper C++ code and in SA Java code):

      https://github.com/openjdk/jdk/blob/master/src/hotspot/share/services/heapDumper.cpp#L71

      https://github.com/openjdk/jdk/blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java#L47

      To clarify meaning of the field description should be updated in both copies:

      u4         instance size (in bytes, including header, padding)

            amenkov Alex Menkov
            thurka Tomáš Hůrka
            Serguei Spitsyn
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: