|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.javamex.classmexer.MemoryUtil
public class MemoryUtil
Provides various static methods for measuring the memory usage of objects. For these methods to work, the JVM must be started with classmexer.jar installed as an agent, for example:
java -javaagent:classmexer.jar mypackage/MyClass
Nested Class Summary | |
---|---|
static class |
MemoryUtil.VisibilityFilter
|
Method Summary | |
---|---|
static long |
deepMemoryUsageOf(java.lang.Object obj)
Returns an estimation, in bytes, of the memory usage of the given object plus (recursively) objects it references via non-static private or protected fields. |
static long |
deepMemoryUsageOf(java.lang.Object obj,
MemoryUtil.VisibilityFilter referenceFilter)
Returns an estimation, in bytes, of the memory usage of the given object plus (recursively) objects it references via non-static references. |
static long |
deepMemoryUsageOfAll(java.util.Collection<? extends java.lang.Object> objs)
Returns an estimation, in bytes, of the memory usage of the given objects plus (recursively) objects referenced via non-static references from any of those objects via non-public fields. |
static long |
deepMemoryUsageOfAll(java.util.Collection<? extends java.lang.Object> objs,
MemoryUtil.VisibilityFilter referenceFilter)
Returns an estimation, in bytes, of the memory usage of the given objects plus (recursively) objects referenced via non-static references from any of those objects. |
static long |
memoryUsageOf(java.lang.Object obj)
Returns an estimation of the "shallow" memory usage, in bytes, of the given object. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static long memoryUsageOf(java.lang.Object obj)
The estimate is provided by the running JVM and is likely to be as accurate a measure as can be reasonably made by the running Java program. It will generally include memory taken up for "housekeeping" of that object.
The shallow memory usage does not count the memory used by objects referenced by obj.
obj
- The object whose memory usage is to be estimated.
java.lang.IllegalStateException
- If the Agent wasn't installed when the JVM was started up.public static long deepMemoryUsageOf(java.lang.Object obj)
The estimate for each individual object is provided by the running JVM and is likely to be as accurate a measure as can be reasonably made by the running Java program. It will generally include memory taken up for "housekeeping" of that object.
Optionally,
obj
- The object whose memory usage (and that of objects it references)
is to be estimated.
java.lang.SecurityException
- If the field definitions of obj cannot be read
via reflection for the purpose of traversing its object graph.
java.lang.IllegalStateException
- If the Agent wasn't installed when the JVM was started up.public static long deepMemoryUsageOf(java.lang.Object obj, MemoryUtil.VisibilityFilter referenceFilter)
The estimate for each individual object is provided by the running JVM and is likely to be as accurate a measure as can be reasonably made by the running Java program. It will generally include memory taken up for "housekeeping" of that object.
obj
- The object whose memory usage (and that of objects it references)
is to be estimated.referenceFilter
- Specifies which references are to be recursively included in the
resulting sount.
java.lang.SecurityException
- If the field definitions of obj cannot be read
via reflection for the purpose of traversing its object graph.
java.lang.IllegalStateException
- If the Agent wasn't installed when the JVM was started up.public static long deepMemoryUsageOfAll(java.util.Collection<? extends java.lang.Object> objs)
If two or more of the given objects reference the same Object X, then the memory used by Object X will only be counted once. However, the method guarantees that the memory for a given object (either in the passed-in collection or found while traversing the object graphs from those objects) will not be counted more than once.
The estimate for each individual object is provided by the running JVM and is likely to be as accurate a measure as can be reasonably made by the running Java program. It will generally include memory taken up for "housekeeping" of that object.
objs
- The collection of objects whose memory usage is to be totalled.
java.lang.SecurityException
- If the field definitions of any objects in objs cannot be read
via reflection for the purpose of traversing the corresponding object graph.
java.lang.IllegalStateException
- If the Agent wasn't installed when the JVM was started up.public static long deepMemoryUsageOfAll(java.util.Collection<? extends java.lang.Object> objs, MemoryUtil.VisibilityFilter referenceFilter)
If two or more of the given objects reference the same Object X, then the memory used by Object X will only be counted once. However, the method guarantees that the memory for a given object (either in the passed-in collection or found while traversing the object graphs from those objects) will not be counted more than once.
The estimate for each individual object is provided by the running JVM and is likely to be as accurate a measure as can be reasonably made by the running Java program. It will generally include memory taken up for "housekeeping" of that object.
objs
- The collection of objects whose memory usage is to be totalled.referenceFilter
- Specifies which references are to be recursively included in the
resulting count.
java.lang.SecurityException
- If the field definitions of any objects in objs cannot be read
via reflection for the purpose of traversing the corresponding object graph.
java.lang.IllegalStateException
- If the Agent wasn't installed when the JVM was started up.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |