com.sun.btrace
Class BTraceUtils.Sys.Memory

java.lang.Object
  extended by com.sun.btrace.BTraceUtils.Sys.Memory
Enclosing class:
BTraceUtils.Sys

public static class BTraceUtils.Sys.Memory
extends java.lang.Object


Constructor Summary
BTraceUtils.Sys.Memory()
           
 
Method Summary
static long committed(java.lang.management.MemoryUsage mu)
          Returns the amount of memory in bytes that is committed for the Java virtual machine to use.
static void dumpHeap(java.lang.String fileName)
          Dump the snapshot of the Java heap to a file in hprof binary format.
static void dumpHeap(java.lang.String fileName, boolean live)
          Dump the snapshot of the Java heap to a file in hprof binary format.
static long finalizationCount()
          Returns the approximate number of objects for which finalization is pending.
static long freeMemory()
          Returns the amount of free memory in the Java Virtual Machine.
static void gc()
          Runs the garbage collector.
static java.lang.String getMemoryPoolUsage(java.lang.String poolFormat)
          Returns an overview of available memory pools
It is possible to provide a text format the overview will use
static long getTotalGcTime()
          Returns the total amount of time spent in GarbageCollection up to this point since the application was started.
static java.lang.management.MemoryUsage heapUsage()
          Returns heap memory usage
static long init(java.lang.management.MemoryUsage mu)
          Returns the amount of memory in bytes that the Java virtual machine initially requests from the operating system for memory management.
static long max(java.lang.management.MemoryUsage mu)
          Returns the maximum amount of memory in bytes that can be used for memory management.
static long maxMemory()
          Returns the maximum amount of memory that the Java virtual machine will attempt to use.
static java.lang.management.MemoryUsage nonHeapUsage()
          Returns non-heap memory usage
static void runFinalization()
          Runs the finalization methods of any objects pending finalization.
static long totalMemory()
          Returns the total amount of memory in the Java virtual machine.
static long used(java.lang.management.MemoryUsage mu)
          Returns the amount of used memory in bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BTraceUtils.Sys.Memory

public BTraceUtils.Sys.Memory()
Method Detail

freeMemory

public static long freeMemory()
Returns the amount of free memory in the Java Virtual Machine. Calling the gc method may result in increasing the value returned by freeMemory.

Returns:
an approximation to the total amount of memory currently available for future allocated objects, measured in bytes.

totalMemory

public static long totalMemory()
Returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.

Note that the amount of memory required to hold an object of any given type may be implementation-dependent.

Returns:
the total amount of memory currently available for current and future objects, measured in bytes.

maxMemory

public static long maxMemory()
Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned.

Returns:
the maximum amount of memory that the virtual machine will attempt to use, measured in bytes

heapUsage

public static java.lang.management.MemoryUsage heapUsage()
Returns heap memory usage


nonHeapUsage

public static java.lang.management.MemoryUsage nonHeapUsage()
Returns non-heap memory usage


init

public static long init(java.lang.management.MemoryUsage mu)
Returns the amount of memory in bytes that the Java virtual machine initially requests from the operating system for memory management.


committed

public static long committed(java.lang.management.MemoryUsage mu)
Returns the amount of memory in bytes that is committed for the Java virtual machine to use. This amount of memory is guaranteed for the Java virtual machine to use.


max

public static long max(java.lang.management.MemoryUsage mu)
Returns the maximum amount of memory in bytes that can be used for memory management. This method returns -1 if the maximum memory size is undefined.


used

public static long used(java.lang.management.MemoryUsage mu)
Returns the amount of used memory in bytes.


finalizationCount

public static long finalizationCount()
Returns the approximate number of objects for which finalization is pending.


dumpHeap

public static void dumpHeap(java.lang.String fileName)
Dump the snapshot of the Java heap to a file in hprof binary format. Only the live objects are dumped. Under the current dir of traced app, ./btrace<pid>/<btrace-class>/ directory is created. Under that directory, a file of given fileName is created.

Parameters:
fileName - name of the file to which heap is dumped

dumpHeap

public static void dumpHeap(java.lang.String fileName,
                            boolean live)
Dump the snapshot of the Java heap to a file in hprof binary format. Under the current dir of traced app, ./btrace<pid>/<btrace-class>/ directory is created. Under that directory, a file of given fileName is created.

Parameters:
fileName - name of the file to which heap is dumped
live - flag that tells whether only live objects are to be dumped or all objects are to be dumped.

gc

public static void gc()
Runs the garbage collector.

Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects. This method calls Sys.gc() to perform GC.


getTotalGcTime

public static long getTotalGcTime()
Returns the total amount of time spent in GarbageCollection up to this point since the application was started.

Returns:
Returns the amount of overall time spent in GC

getMemoryPoolUsage

public static java.lang.String getMemoryPoolUsage(java.lang.String poolFormat)
Returns an overview of available memory pools
It is possible to provide a text format the overview will use

Parameters:
poolFormat - The text format string to format the overview.
Exactly 5 arguments are passed to the format function.
The format defaults to ";%1$s;%2$d;%3$d;%4$d;%5$d;Memory]"
Returns:
Returns the formatted value of memory pools overview
Since:
1.2

runFinalization

public static void runFinalization()
Runs the finalization methods of any objects pending finalization.

Calling this method suggests that the Java Virtual Machine expend effort toward running the finalize methods of objects that have been found to be discarded but whose finalize methods have not yet been run. When control returns from the method call, the Java Virtual Machine has made a best effort to complete all outstanding finalizations. This method calls Sys.runFinalization() to run finalization.