public interface ValueType extends Immutable
This interface identifies objects which can be manipulated by value; a JVM implementation may allocate instances of this class on the stack and pass references by copy.
Realtime
instances can be "explicitly" allocated on the
"stack" by executing within a StackContext
and creating new instances with an ObjectFactory
.
It is the responsibility of the users to ensure
that "stack" objects are copied out
when
referenced outside of the stack context. For example:
public final class Complex implements Realtime, ValueType { ... }
...
public Complex sumOf(Complex[] values) {
StackContext.enter(); // Starts stack allocation.
try {
Complex sum = Complex.ZERO;
for (Complex c : values) {
sum = sum.plus(c);
}
return StackContext.outerCopy(sum); // Copies outside the stack.
} finally {
StackContext.exit(); // Resets stacks.
}
}
Note: "Stack" allocation is not the only optimization that a VM
can do on ValueType
. The VM might decide not to perform any
allocation at all and store values directly in registers.
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
copy()
Returns a deep copy of this object allocated in the memory area (RTSJ)
and/or
context (Javolution)
of the calling thread (the one making the copy). |
java.lang.Object copy()
context
(Javolution)
of the calling thread (the one making the copy).Copyright © 2005 - 2007 Javolution.