001    // VTMemory.java, created by wbeebee
002    // Copyright (C) 2001 Wes Beebee <wbeebee@mit.edu>
003    // Licensed under the terms of the GNU GPL; see COPYING for details.
004    package javax.realtime;
005    
006    /**
007     * @author Wes Beebee <<a href="mailto:wbeebee@mit.edu">wbeebee@mit.edu</a>>
008     */
009    
010    /** The execution time of an allocation from a <code>VTMemory</code> area may
011     *  take a variable amount of time. However, since <code>VTMemory</code> areas
012     *  are not subject to garbage collection and objects within it may not be moved,
013     *  these areas can be used by instances of <code>NoHeapRealtimeThread</code>.
014     */
015    public class VTMemory extends ScopedMemory {
016    
017        /** The logic associated with <code>this</code> */
018        Runnable logic;
019    
020        /** Creates a <code>VTMemory</code> with the given parameters.
021         *
022         *  @param initial The size in bytes of the memory to initially allocate for
023         *                 this area.
024         *  @param maximum The maximum size in bytes of this memory area to which
025         *                 the size may grow.
026         */
027        public VTMemory(long initialSizeInBytes, long maxSizeInBytes) {
028            super(maxSizeInBytes);
029        }
030    
031        /** Creates a <code>VTMemory</code> with the given parameters.
032         *
033         *  @param initial The size in bytes of the memory to initially allocate for
034         *                 this area.
035         *  @param maximum The maximum size in bytes of this memory area to which
036         *                 the size may grow.
037         *  @param logic An instance of <code>java.lang.Runnable</code> whose
038         *               <code>run()</code> method will use <code>this</code> as its
039         *               initial memory area.
040         */
041        public VTMemory(long initialSizeInBytes, long maxSizeInBytes,
042                        Runnable logic) {
043            this(initialSizeInBytes, maxSizeInBytes);
044            this.logic = logic;
045        }
046    
047        /** Creates a <code>VTMemory</code> with the given parameters.
048         *
049         *  @param initial The size in bytes of the memory to initially allocate for
050         *                 this area.
051         *  @param maximum The maximum size in bytes of this memory area to which
052         *                 the size may grow estimated by an instance of
053         *                 <code>SizeEstimator</code>.
054         */
055        public VTMemory(SizeEstimator initial, SizeEstimator maximum) {
056            this(initial.getEstimate(), maximum.getEstimate());
057        }
058    
059        /** Creates a <code>VTMemory</code> with the given parameters.
060         *
061         *  @param initial The size in bytes of the memory to initially allocate for
062         *                 this area.
063         *  @param maximum The maximum size in bytes of this memory area to which
064         *                 the size may grow estimated by an instance of
065         *                 <code>SizeEstimator</code>.
066         *  @param logic An instance of <code>java.lang.Runnable</code> whose
067         *               <code>run()</code> method will use <code>this<code> as its
068         *               initial memory area.
069         */
070        public VTMemory(SizeEstimator initial, SizeEstimator maximum,
071                        Runnable logic) {
072            this(initial, maximum);
073            this.logic = logic;
074        }
075    
076        /** Alternate constructor, with no limits */
077        public VTMemory() {
078            super(0);
079        }
080    
081        /** Gets the value of the maximum size to which <code>this</code> can grow.
082         *
083         *  @return The maximum size value.
084         */
085        public long getMaximumSize() {
086            return size;
087        }
088    
089        /** Create a string representing the name of <code>this</code>.
090         *
091         *  @return A string representing the name of <code>this</code>.
092         */
093        public String toString() {
094            return "VTMemory: " + super.toString();
095        }
096    
097        /** Initialize the native component of this VTMemory. */
098        protected native void initNative(long sizeInBytes);
099    }