J avolution v5.5 (J2SE 1.6+)

javolution.lang
Interface ValueType

All Superinterfaces:
Immutable
All Known Implementing Classes:
Text

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.

Version:
5.0, May 6, 2007
Author:
Jean-Marie Dautelle

Method Summary
 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).
 

Method Detail

copy

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).

Returns:
an object identical to this object but allocated by the calling thread (e.g. on the "stack" of the calling thread).

J avolution v5.5 (J2SE 1.6+)

Copyright © 2005 - 2009 Javolution.