public class Immortals
extends java.lang.Object
This class gives access to the global immortal objects pool.
An immortal object has two major properties:
Constructor and Description |
---|
Immortals() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
deepImmortal(java.lang.Object 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(java.lang.Object o)
Gets whether an object is immortal or not.
|
static void |
run(java.lang.Runnable runnable)
Calls the method
Runnable.run() of the given runnable. |
static java.lang.Object |
setImmortal(java.lang.Object o)
Turns the given object into an immortal object.
|
static long |
totalMemory()
Returns the total amount of immortal memory.
|
public static boolean isImmortal(java.lang.Object o)
Gets whether an object is immortal or not.
An object is immortal:
setImmortal(Object)
,o
- the object to checktrue
if the queried object is immortal or immutable, false
otherwisejava.lang.NullPointerException
- if given object is nullImmutables.isImmutable(Object)
public static java.lang.Object setImmortal(java.lang.Object o)
Turns the given object into an immortal object.
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.
java.lang.OutOfMemoryError
- if the immortal memory is fullpublic static java.lang.Object deepImmortal(java.lang.Object root)
Turns the given object and all objects referred from it into immortal objects.
Weakly reachable objects are not turned into immortal objects.
root
- the root of the objects graph to turn into immortalpublic static void run(java.lang.Runnable runnable)
Calls the method 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 executejava.lang.NullPointerException
- if the given runnable is null
public static long freeMemory()
Returns the amount of free immortal memory still available.
public static long totalMemory()
Returns the total amount of immortal memory.
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.