This class represents an allocator from immortal memory (RTSJ).
It is typically used to allocate (and recycle) from immortal memory
allowing dynamically created static instances to be accessible by
NoHeapRealtimeThread :[code]
public synchronized Text intern() {
if (!INTERN_INSTANCES.containsKey(this)) {
ImmortalContext.enter();
try { // Forces interned instance to be in immortal memory.
Text txt = this.copy(); // In ImmortalMemory.
INTERN_INSTANCES.put(txt, txt);
} finally {
ImmortalContext.exit();
}
}
return (Text) INTERN_INSTANCES.get(str);
}[/code]
Because class initialization may occur while running in a non-heap
context (e.g.
StackContext ), it is recommended to force
factory produced constants to immortal memory:[code]
public class Rational {
public static final Rational ZERO;
public static final Rational ONE;
...
static { // Forces constants to ImmortalMemory.
ImmortalContext.enter();
try {
ZERO = Rational.valueOf(0, 1); // Factory produced.
ONE = Rational.valueOf(1, 1); // Factory produced.
} finally {
ImmortalContext.exit();
}
}
}[/code]
author: Jean-Marie Dautelle version: 5.2, August 19, 2007 |