001    // RefCountArea.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    /** <code>RefCountArea</code> is a new <code>MemoryArea</code> which
007     *  allows access from anywhere, access to <code>ImmortalMemory</code>
008     *  and the heap, where objects live as long as there are references
009     *  to them.  Performance is upper-bounded by a constant for every assignment
010     *  and for every allocation.  No pauses at any other time are permitted.
011     *  Cycles are strictly prohibited (use roles analysis).  Performance
012     *  for this <code>MemoryArea</code> is expected to be slightly slower
013     *  than for <code>VTMemory</code>'s.
014     * @author Wes Beebee <<a href="mailto:wbeebee@mit.edu">wbeebee@mit.edu</a>>
015     */
016    
017    public class RefCountArea extends ImmortalMemory {
018        private static RefCountArea refCountArea;
019    
020        /* Don't use this! */
021        public RefCountArea() {
022            super();
023        }
024    
025        /** Initialize the native component of this <code>MemoryArea</code>. */
026        
027        protected native void initNative(long sizeInBytes);
028    
029        /** Returns the only RefCountArea instance, allocated out of 
030         *  an ImmortalMemory. 
031         */
032    
033        public static RefCountArea refInstance() {
034            if (refCountArea == null) {
035                if (RealtimeThread.RTJ_init_in_progress) {
036                    return null;
037                }
038                try {
039                    refCountArea = (RefCountArea)
040                        ImmortalMemory.instance().newInstance(RefCountArea.class);
041                } catch (Exception e) {
042                    throw new Error("Can't instantiate RefCountArea:" + e.toString());
043                }
044            }
045            return refCountArea;
046        }
047    
048        /** These two methods will go away in the future... */
049        public native void INCREF(Object o);
050        public native void DECREF(Object o);
051    
052        public String toString() {
053            return "RefCountArea: " + super.toString();
054        }
055    }