001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.mmtk.policy;
014    
015    import org.mmtk.plan.TransitiveClosure;
016    import org.mmtk.utility.heap.*;
017    import org.mmtk.utility.Constants;
018    
019    import org.vmmagic.pragma.*;
020    import org.vmmagic.unboxed.*;
021    
022    /**
023     * Each instance of this class corresponds to one *space*.
024     * Each of the instance methods of this class may be called by any
025     * thread (i.e. synchronization must be explicit in any instance or
026     * class method).  This contrasts with the MarkSweepLocal, where
027     * instances correspond to *plan* instances and therefore to kernel
028     * threads.  Thus unlike this class, synchronization is not necessary
029     * in the instance methods of MarkSweepLocal.
030     */
031    @Uninterruptible
032    public final class ExplicitFreeListSpace extends SegregatedFreeListSpace implements Constants {
033    
034      /****************************************************************************
035       *
036       * Class variables
037       */
038    
039      /**
040       *
041       */
042      public static final int LOCAL_GC_BITS_REQUIRED = 0;
043      public static final int GLOBAL_GC_BITS_REQUIRED = 0;
044      public static final int GC_HEADER_WORDS_REQUIRED = 0;
045    
046      /****************************************************************************
047       *
048       * Initialization
049       */
050    
051      /**
052       * The caller specifies the region of virtual memory to be used for
053       * this space.  If this region conflicts with an existing space,
054       * then the constructor will fail.
055       *
056       * @param name The name of this space (used when printing error messages etc)
057       * @param vmRequest An object describing the virtual memory requested.
058       */
059      public ExplicitFreeListSpace(String name, VMRequest vmRequest) {
060        super(name, 0, vmRequest);
061      }
062    
063      @Override
064      @Inline
065      protected boolean maintainSideBitmap() {
066        return true;
067      }
068    
069      @Override
070      @Inline
071      protected boolean preserveFreeList() {
072        return false;
073      }
074    
075      /****************************************************************************
076       *
077       * Collection
078       */
079    
080      /**
081       * Prepare the next block in the free block list for use by the free
082       * list allocator.  In the case of lazy sweeping this involves
083       * sweeping the available cells.  <b>The sweeping operation must
084       * ensure that cells are pre-zeroed</b>, as this method must return
085       * pre-zeroed cells.
086       *
087       * @param block The block to be prepared for use
088       * @param sizeClass The size class of the block
089       * @return The address of the first pre-zeroed cell in the free list
090       * for this block, or zero if there are no available cells.
091       */
092      @Override
093      protected Address advanceToBlock(Address block, int sizeClass) {
094        return makeFreeList(block, sizeClass);
095      }
096    
097      @Override
098      protected void notifyNewBlock(Address block, int sizeClass) {
099        clearLiveBits(block, sizeClass);
100      }
101    
102      /**
103       * Free an object.
104       *
105       * @param object The object to be freed.
106       */
107      @Inline
108      public void free(ObjectReference object) {
109        clearLiveBit(object);
110      }
111    
112      /**
113       * Prepare for a new collection increment.
114       */
115      public void prepare() {
116        flushAvailableBlocks();
117      }
118    
119      /**
120       * A new collection increment has completed.
121       */
122      public void release() {
123        sweepConsumedBlocks(true);
124      }
125    
126      /**
127       * Release an allocated page or pages
128       *
129       * @param start The address of the start of the page or pages
130       */
131      @Override
132      @Inline
133      public void release(Address start) {
134        ((FreeListPageResource) pr).releasePages(start);
135      }
136    
137      /****************************************************************************
138       *
139       * Object processing and tracing
140       */
141    
142      /**
143       * Trace a reference to an object under a mark sweep collection
144       * policy.  If the object header is not already marked, mark the
145       * object in either the bitmap or by moving it off the treadmill,
146       * and enqueue the object for subsequent processing. The object is
147       * marked as (an atomic) side-effect of checking whether already
148       * marked.
149       *
150       * @param object The object to be traced.
151       * @return The object (there is no object forwarding in this
152       * collector, so we always return the same object: this could be a
153       * void method but for compliance to a more general interface).
154       */
155      @Override
156      @Inline
157      public ObjectReference traceObject(TransitiveClosure trace, ObjectReference object) {
158        return object;
159      }
160    
161      /**
162      * @return {@code true} if this object is known to be live (i.e. it is marked)
163      */
164      @Override
165      @Inline
166      public boolean isLive(ObjectReference object) {
167        return liveBitSet(object);
168      }
169    }