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