Class MemoryReport

java.lang.Object
cz.drg.pregrouper.util.MemoryReport

public final class MemoryReport extends Object
Programmatic memory introspection for a running JVM — everything Runtime doesn't tell you. Verified on OpenJDK 21. Run the host app with -XX:NativeMemoryTracking=summary to enable nativeMemory().
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Direct and mapped buffer pools.
    static String
    Instance count + bytes per class.
    static void
    Everything at once.
    static void
    heapDump(String path, boolean liveOnly)
    Write a heap dump for offline analysis in Eclipse MAT / VisualVM.
    static String
    jcmd(String operation, String... args)
    Invoke any jcmd diagnostic command in-process.
    static long
    mappingResidentBytes(String fileNameFragment)
    Resident bytes of a specific file's mapping, from /proc/self/smaps (Linux).
    static String
    Categorised native memory.
    static void
    Heap and non-heap pools: Eden, Survivor, Old, Metaspace, code heaps, class space.
    static void
    Process virtual size vs resident set — the only way to see mmap residency.
    static void
    Cumulative bytes allocated per live thread — shows which thread is churning.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • pools

      public static void pools()
      Heap and non-heap pools: Eden, Survivor, Old, Metaspace, code heaps, class space.
    • buffers

      public static void buffers()
      Direct and mapped buffer pools. NOTE: for "mapped", memoryUsed is the total mapped *address space*, not resident pages — see residency() for that.
    • threadAllocation

      public static void threadAllocation()
      Cumulative bytes allocated per live thread — shows which thread is churning.
    • residency

      public static void residency() throws Exception
      Process virtual size vs resident set — the only way to see mmap residency.
      Throws:
      Exception
    • mappingResidentBytes

      public static long mappingResidentBytes(String fileNameFragment) throws Exception
      Resident bytes of a specific file's mapping, from /proc/self/smaps (Linux).
      Throws:
      Exception
    • jcmd

      public static String jcmd(String operation, String... args) throws Exception
      Invoke any jcmd diagnostic command in-process.
      Throws:
      Exception
    • classHistogram

      public static String classHistogram() throws Exception
      Instance count + bytes per class. Stops the world; not for hot paths.
      Throws:
      Exception
    • nativeMemory

      public static String nativeMemory() throws Exception
      Categorised native memory. Requires -XX:NativeMemoryTracking=summary.
      Throws:
      Exception
    • heapDump

      public static void heapDump(String path, boolean liveOnly) throws Exception
      Write a heap dump for offline analysis in Eclipse MAT / VisualVM.
      Throws:
      Exception
    • dumpAll

      public static void dumpAll()
      Everything at once.