public class Immortals extends Object
An immortal object has two major properties:
Constructor and Description |
---|
Immortals() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
deepImmortal(T root)
Turns the given object and all objects referred from it into immortal
objects.
|
static long |
freeMemory()
Returns the amount of free immortal memory still available.
|
static boolean |
isImmortal(Object o)
Gets whether an object is immortal or not.
|
static void |
run(Runnable runnable)
Calls the method
Runnable.run() of the given runnable. |
static <T> T |
setImmortal(T o)
Turns the given object into an immortal object.
|
static long |
totalMemory()
Returns the total amount of immortal memory.
|
public static boolean isImmortal(Object o)
An object is immortal:
setImmortal(Object)
,o
- the object to checktrue
if the queried object is immortal or immutable,
false
otherwiseNullPointerException
- if given object is nullImmutables.isImmutable(Object)
public static <T> T setImmortal(T o)
If the received object was immutable, it remains immutable.
If the object was already immortal, it remains immortal.
If the object was a reclaimable object it turns into an immortal object. Upon
success, the returned object is immortal, otherwise an
OutOfMemoryError
is thrown.
T
- the object typeo
- the object to turn into an immortalOutOfMemoryError
- if the immortal memory is fullpublic static <T> T deepImmortal(T root)
Weakly reachable objects are not turned into immortal objects.
T
- the root object typeroot
- the root of the objects graph to turn into immortalpublic static void run(Runnable runnable)
Runnable.run()
of the given runnable.
All the objects allocated in the context of this method are directly
allocated as immortals. While the Runnable.run()
method of the
runnable executes all created objects are allocated as immortal objects.
runnable
- the runnable to executeNullPointerException
- if the given runnable is null
public static long freeMemory()
public static long totalMemory()
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.