java.lang.management
Class MemoryUsage

java.lang.Object
  extended by java.lang.management.MemoryUsage

public class MemoryUsage
extends Object

Retains information on the usage of a particular memory pool, or heap/non-heap memory as a whole. Memory usage is represented by four values (all in bytes):

Since:
1.5
See Also:
MemoryMXBean, MemoryPoolMXBean

Constructor Summary
MemoryUsage(long init, long used, long committed, long maximum)
          Constructs a new MemoryUsage object with the specified allocation levels.
 
Method Summary
static MemoryUsage from(CompositeData data)
           Returns a MemoryUsage instance using the values given in the supplied CompositeData object.
 long getCommitted()
          Returns the amount of memory committed for use by this memory pool (in bytes).
 long getInit()
          Returns the initial amount of memory allocated to the pool (in bytes).
 long getMax()
          Returns the maximum amount of memory available for this pool (in bytes).
 long getUsed()
          Returns the amount of memory used (in bytes).
 String toString()
          Returns a String representation of this MemoryUsage object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MemoryUsage

public MemoryUsage(long init,
                   long used,
                   long committed,
                   long maximum)
Constructs a new MemoryUsage object with the specified allocation levels.

Parameters:
init - the initial amount of memory allocated, or -1 if this value is undefined. Must be >= -1.
used - the amount of memory used. Must be >= 0, and <= committed.
committed - the amount of memory committed for use at present. Must be >= 0 and <= maximum (if defined).
maximum - the maximum amount of memory that may be used, or -1 if this value is undefined. Must be >= -1.
Throws:
IllegalArgumentException - if the values break any of the limits specified above.
Method Detail

from

public static MemoryUsage from(CompositeData data)

Returns a MemoryUsage instance using the values given in the supplied CompositeData object. The composite data instance should contain the following attributes:

All should have the type, java.lang.Long.

Parameters:
data - the composite data structure to take values from.
Returns:
a new instance containing the values from the composite data structure, or null if the data structure was also null.
Throws:
IllegalArgumentException - if the composite data structure does not match the structure outlined above, or the values are invalid.

getCommitted

public long getCommitted()
Returns the amount of memory committed for use by this memory pool (in bytes). This amount is guaranteed to be available, unlike the maximum.

Returns:
the committed amount of memory.

getInit

public long getInit()
Returns the initial amount of memory allocated to the pool (in bytes). This method may return -1, if the value is undefined.

Returns:
the initial amount of memory allocated, or -1 if this value is undefined.

getMax

public long getMax()
Returns the maximum amount of memory available for this pool (in bytes). This amount is not guaranteed to actually be usable. This method may return -1, if the value is undefined.

Returns:
the maximum amount of memory available, or -1 if this value is undefined.

getUsed

public long getUsed()
Returns the amount of memory used (in bytes).

Returns:
the amount of used memory.

toString

public String toString()
Returns a String representation of this MemoryUsage object. This takes the form java.lang.management.MemoryUsage[init=i, used=u, committed=c, maximum=m], where i is the initial level, u is the used level, c is the committed level and m is the maximum level.

Overrides:
toString in class Object
Returns:
the string specified above.
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)