Class MemoryUsage

java.lang.Object
java.lang.management.MemoryUsage

public class MemoryUsage extends Object
Represents the memory usage of either a memory pool or the heap and non-heap memory areas of the virtual machine.
Since:
1.5
  • Constructor Summary

    Constructors
    Constructor
    Description
    MemoryUsage(long init, long used, long committed, long max)
    Constructs a new MemoryUsage instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    Receives a CompositeData representing a MemoryUsage object and attempts to return the root MemoryUsage instance.
    long
    Returns the amount of memory that has been pledged by the operating system for the virtual machine to use.
    long
    Returns the initial amount of memory requested from the underlying operating system when the virtual machine started up.
    long
    Returns the maximum amount of memory that is available to the virtual machine which may change over the lifecycle of the virtual machine.
    long
    Returns the number of bytes currently used for memory management purposes.
    Returns a text description of this memory usage.

    Methods declared in class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • MemoryUsage

      public MemoryUsage(long init, long used, long committed, long max)
      Constructs a new MemoryUsage instance.
      Parameters:
      init - if defined, the initial amount of memory that can be allocated by the virtual machine in bytes. If not defined, then -1.
      used - the number of bytes currently used for memory.
      committed - the number of bytes of committed memory.
      max - if defined, the maximum number of bytes that can be used for memory management purposes. If not defined, -1.
      Throws:
      IllegalArgumentException - if any of the following conditions applies:
      • init < -1
      • max < -1
      • used < 0
      • committed < 0
      • used > committed
      • committed > max if max is not -1.
  • Method Details

    • getCommitted

      public long getCommitted()
      Returns the amount of memory that has been pledged by the operating system for the virtual machine to use. This value is in bytes.
      Returns:
      the number of bytes committed to memory.
    • getInit

      public long getInit()
      Returns the initial amount of memory requested from the underlying operating system when the virtual machine started up. The value is given in bytes.

      if the initial memory size was not defined, this method will return a value of -1.

      Returns:
      the initial amount of memory requested at virtual machine start up. -1 if not defined.
    • getMax

      public long getMax()
      Returns the maximum amount of memory that is available to the virtual machine which may change over the lifecycle of the virtual machine. The value is in bytes.
      Returns:
      if defined, the maximum memory size in bytes. If not defined, -1.
    • getUsed

      public long getUsed()
      Returns the number of bytes currently used for memory management purposes.
      Returns:
      the current number of bytes used for memory.
    • toString

      public String toString()
      Returns a text description of this memory usage.
      Overrides:
      toString in class Object
      Returns:
      a text description of this memory usage.
    • from

      public static MemoryUsage from(CompositeData cd)
      Receives a CompositeData representing a MemoryUsage object and attempts to return the root MemoryUsage instance.
      Parameters:
      cd - a CompositeDate that represents a MemoryUsage.
      Returns:
      if cd is non- null, returns a new instance of MemoryUsage. If cd is null, returns null.
      Throws:
      IllegalArgumentException - if argument cd does not correspond to a MemoryUsage with the following attributes all of type java.long.Long:
      • committed
      • init
      • max
      • used