Package org.jvnet.hudson.test
Class MemoryAssert
java.lang.Object
org.jvnet.hudson.test.MemoryAssert
Static utility methods for verifying heap memory usage.
Uses the INSANE library
to traverse the heap from within your test.
Object sizes are in an idealized JVM in which pointers are 4 bytes
(realistic even for modern 64-bit JVMs in which -XX:+UseCompressedOops is the default)
but objects are aligned on 8-byte boundaries (so dropping an int field does not always save memory).
import static org.jvnet.hudson.test.MemoryAssert.*; to use.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertGC(WeakReference<?> reference) Deprecated.static voidassertGC(WeakReference<?> reference, boolean allowSoft) Forces GC by causing an OOM and then verifies the givenWeakReferencehas been garbage collected.static voidassertHeapUsage(Object o, int max) Verifies that an object and its transitive reference graph occupy at most a predetermined amount of memory.static List<MemoryAssert.HistogramElement>increasedMemory(Callable<Void> callable, org.netbeans.insane.scanner.Filter... filters) Counts how much more memory is held in Jenkins by doing some operation.
-
Method Details
-
assertHeapUsage
Verifies that an object and its transitive reference graph occupy at most a predetermined amount of memory. The referents ofWeakReferenceand the like are ignored.To use, run your test for the first time with
maxof0; when it fails, use the reported actual size as your assertion maximum. When improving memory usage, run again with0and tighten the test to both demonstrate your improvement quantitatively and prevent regressions.- Parameters:
o- the object to measuremax- the maximum desired memory usage (in bytes)- Throws:
Exception
-
increasedMemory
public static List<MemoryAssert.HistogramElement> increasedMemory(Callable<Void> callable, org.netbeans.insane.scanner.Filter... filters) throws Exception Counts how much more memory is held in Jenkins by doing some operation.- Parameters:
callable- an actionfilters- things to exclude- Returns:
- a histogram of the heap delta after running the operation
- Throws:
Exception- Since:
- 1.500
-
assertGC
Deprecated. -
assertGC
Forces GC by causing an OOM and then verifies the givenWeakReferencehas been garbage collected.- Parameters:
reference- object used to verify garbage collection.allowSoft- if true, pass even ifSoftReferences apparently needed to be cleared by forcing anOutOfMemoryError; if false, fail in such a case (though the failure will be slow)
-