Package ej.bon
Class Immortals
- java.lang.Object
-
- ej.bon.Immortals
-
public class Immortals extends Object
This class gives access to the global immortal objects pool.An immortal object has two major properties:
- it is not managed by the garbage collector,
- it does not move around in memory, i.e. its physical memory location remains the same forever.
-
-
Constructor Summary
Constructors Constructor Description Immortals()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TdeepImmortal(T root)Turns the given object and all objects referred from it into immortal objects.static longfreeMemory()Returns the amount of free immortal memory still available.static booleanisImmortal(Object o)Gets whether an object is immortal or not.static voidrun(Runnable runnable)Calls the methodRunnable.run()of the given runnable.static <T> TsetImmortal(T o)Turns the given object into an immortal object.static longtotalMemory()Returns the total amount of immortal memory.
-
-
-
Method Detail
-
isImmortal
public static boolean isImmortal(Object o)
Gets whether an object is immortal or not.An object is immortal:
- if it has been declared as immortal calling
setImmortal(Object), - if it is immutable.
- Parameters:
o- the object to check- Returns:
trueif the queried object is immortal or immutable,falseotherwise- Throws:
NullPointerException- if given object is null- See Also:
Immutables.isImmutable(Object)
- if it has been declared as immortal calling
-
setImmortal
public static <T> T setImmortal(T 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
OutOfMemoryErroris thrown.- Type Parameters:
T- the object type- Parameters:
o- the object to turn into an immortal- Returns:
- the given object turned into immortal
- Throws:
OutOfMemoryError- if the immortal memory is full
-
deepImmortal
public static <T> T deepImmortal(T root)
Turns the given object and all objects referred from it into immortal objects.Weakly reachable objects are not turned into immortal objects.
- Type Parameters:
T- the root object type- Parameters:
root- the root of the objects graph to turn into immortal- Returns:
- the given object turned into immortal
-
run
public static void run(Runnable runnable)
Calls the methodRunnable.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.- Parameters:
runnable- the runnable to execute- Throws:
NullPointerException- if the given runnable isnull
-
freeMemory
public static long freeMemory()
Returns the amount of free immortal memory still available.- Returns:
- the amount of free immortal memory
-
totalMemory
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.
- Returns:
- the total amount of immortal memory
-
-