Top Description Inners Fields Constructors Methods
one.jpro.jmemorybuddy

public Class JMemoryBuddy

extends Object
Class Inheritance
Imports
com.sun.management.HotSpotDiagnosticMXBean, javax.management.MBeanServer, java.io.File, .IOException, java.lang.management.ManagementFactory, java.lang.ref.WeakReference, java.text.SimpleDateFormat, java.util.Date, .LinkedList, .Objects, java.util.function.Consumer

JMemoryBuddy provides various methods to test for memory leaks. It makes it easy to verify the memory behavior in a unit test ensuring the stability and quality of your code. Checkout https://github.com/Sandec/JMemoryBuddy for more documentation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static class
public static interface
JMemoryBuddy.MemoryTestAPI

This class provides different methods, which can be used to declare memory-constraints.

private static class

Field Summary

Modifier and TypeField and Description
private static final boolean
private static final int
private static String
private static String
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
assertCollectable(WeakReference<?>
The WeakReference to check.
weakReference
)

Checks whether the content of the WeakReference can be collected.

public static void
assertNotCollectable(WeakReference<Object>
The WeakReference to check.
weakReference
)

Checks whether the content of the WeakReference cannot be collected.

public static boolean

Returns:

Returns true, when the provided WeakReference can be collected.
checkCollectable
(WeakReference<?>
The WeakReference to check.
weakReference
)

Checks whether the content of the WeakReference can be collected.

private static int
checkCollectable(int stepsLeft, WeakReference<?> weakReference)

public static boolean

Returns:

Returns true, when the provided WeakReference cannot be collected.
checkNotCollectable
(WeakReference<?>
The WeakReference to check.
weakReference
)

Checks whether the content of the WeakReference cannot be collected.

pack-priv static void
pack-priv static void
private static String
private static HotSpotDiagnosticMXBean
public static void
memoryTest(Consumer<JMemoryBuddy.MemoryTestAPI>
A function which gets executed with the API to define the required memory semantic.
f
)

A standard method to define a test which checks code for specific memory semantic.

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

createHeapdumpback to summary
private static final boolean createHeapdump
garbageAmountback to summary
private static final int garbageAmount
mxBeanProxyNameback to summary
private static String mxBeanProxyName
outputFolderStringback to summary
private static String outputFolderString
sleepDurationback to summary
private static final int sleepDuration
stepsback to summary
private static final int steps
testDurationback to summary
private static final int testDuration

Constructor Detail

JMemoryBuddyback to summary
public JMemoryBuddy()

Method Detail

assertCollectableback to summary
public static void assertCollectable(WeakReference<?> weakReference)

Checks whether the content of the WeakReference can be collected.

Parameters
weakReference:WeakReference<?>

The WeakReference to check.

assertNotCollectableback to summary
public static void assertNotCollectable(WeakReference<Object> weakReference)

Checks whether the content of the WeakReference cannot be collected.

Parameters
weakReference:WeakReference<Object>

The WeakReference to check.

checkCollectableback to summary
public static boolean checkCollectable(WeakReference<?> weakReference)

Checks whether the content of the WeakReference can be collected.

Parameters
weakReference:WeakReference<?>

The WeakReference to check.

Returns:boolean

Returns true, when the provided WeakReference can be collected.

checkCollectableback to summary
private static int checkCollectable(int stepsLeft, WeakReference<?> weakReference)
checkNotCollectableback to summary
public static boolean checkNotCollectable(WeakReference<?> weakReference)

Checks whether the content of the WeakReference cannot be collected.

Parameters
weakReference:WeakReference<?>

The WeakReference to check.

Returns:boolean

Returns true, when the provided WeakReference cannot be collected.

createGarbageback to summary
pack-priv static void createGarbage()
createHeapDumpback to summary
pack-priv static void createHeapDump()
getDefaultOutputFolderback to summary
private static String getDefaultOutputFolder()
getHotspotMBeanback to summary
private static HotSpotDiagnosticMXBean getHotspotMBean() throws IOException
memoryTestback to summary
public static void memoryTest(Consumer<JMemoryBuddy.MemoryTestAPI> f)

A standard method to define a test which checks code for specific memory semantic. The parameter of the lambda provides an API to define the required memory semantic.

Parameters
f:Consumer<JMemoryBuddy.MemoryTestAPI>

A function which gets executed with the API to define the required memory semantic.

setMxBeanProxyNameback to summary
private static void setMxBeanProxyName(String mxBeanName)
one.jpro.jmemorybuddy back to summary

pack-priv Class JMemoryBuddy.AssertCollectable

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv WeakReference<?>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv WeakReference<?>
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

assertCollectableback to summary
pack-priv WeakReference<?> assertCollectable

Constructor Detail

AssertCollectableback to summary
pack-priv AssertCollectable(WeakReference<?> ref)

Method Detail

getWeakReferenceback to summary
pack-priv WeakReference<?> getWeakReference()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
one.jpro.jmemorybuddy back to summary

private Class JMemoryBuddy.AssertNotCollectable

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv WeakReference<?>
pack-priv String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv WeakReference<?>
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

assertNotCollectableback to summary
pack-priv WeakReference<?> assertNotCollectable
originalResultOfToStringback to summary
pack-priv String originalResultOfToString

Constructor Detail

AssertNotCollectableback to summary
pack-priv AssertNotCollectable(Object ref)

Method Detail

getWeakReferenceback to summary
pack-priv WeakReference<?> getWeakReference()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
one.jpro.jmemorybuddy back to summary

public Interface JMemoryBuddy.MemoryTestAPI


This class provides different methods, which can be used to declare memory-constraints. You can get an instance through the lambda of the method JMemoryBuddy.memoryTest.

Method Summary

Modifier and TypeMethod and Description
public void
assertCollectable(Object
The reference which should be collectable.
ref
)

After executing the lambda, the provided ref must be collectable.

public void
assertNotCollectable(Object
The reference which should not be collectable.
ref
)

After executing the lambda, the provided ref must be not collectable.

public void
setAsReferenced(Object
The reference which should get a hard reference for this test.
ref
)

The provided reference will be reference hard, so it won't be collected, until memoryTest finishes.

Method Detail

assertCollectableback to summary
public void assertCollectable(Object ref)

After executing the lambda, the provided ref must be collectable. Otherwise, an Exception is thrown.

Parameters
ref:Object

The reference which should be collectable.

assertNotCollectableback to summary
public void assertNotCollectable(Object ref)

After executing the lambda, the provided ref must be not collectable. Otherwise, an Exception is thrown.

Parameters
ref:Object

The reference which should not be collectable.

setAsReferencedback to summary
public void setAsReferenced(Object ref)

The provided reference will be reference hard, so it won't be collected, until memoryTest finishes.

Parameters
ref:Object

The reference which should get a hard reference for this test.

one.jpro.jmemorybuddy back to summary

private Class JMemoryBuddy.SetAsReferenced

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv Object

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

setAsReferencedback to summary
pack-priv Object setAsReferenced

Constructor Detail

SetAsReferencedback to summary
pack-priv SetAsReferenced(Object ref)