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.plan.refcount.generational;
014
015import org.mmtk.plan.refcount.RCBase;
016import org.mmtk.policy.CopySpace;
017import org.mmtk.policy.Space;
018import org.mmtk.utility.heap.VMRequest;
019import org.mmtk.utility.options.Options;
020import org.vmmagic.pragma.*;
021import org.vmmagic.unboxed.ObjectReference;
022
023/**
024 * This class implements the global state of a a simple reference counting collector.
025 */
026@Uninterruptible
027public class GenRC extends RCBase {
028
029  public static final int ALLOC_NURSERY = ALLOC_DEFAULT;
030  public static final int ALLOC_RC      = RCBase.ALLOCATORS + 1;
031
032  /** The nursery space is where all new objects are allocated by default */
033  public static final CopySpace nurserySpace = new CopySpace("nursery", false, VMRequest.highFraction(0.15f));
034
035  public static final int NURSERY = nurserySpace.getDescriptor();
036
037  /*****************************************************************************
038   *
039   * Collection
040   */
041
042  /**
043   * {@inheritDoc}
044   */
045  @Override
046  public final void collectionPhase(short phaseId) {
047   if (phaseId == PREPARE) {
048      nurserySpace.prepare(true);
049      super.collectionPhase(phaseId);
050      return;
051    }
052
053    if (phaseId == RELEASE) {
054      super.collectionPhase(phaseId);
055      nurserySpace.release();
056      switchNurseryZeroingApproach(nurserySpace);
057      return;
058    }
059
060    super.collectionPhase(phaseId);
061  }
062
063  @Override
064  public final boolean collectionRequired(boolean spaceFull, Space space) {
065    boolean nurseryFull = nurserySpace.reservedPages() > Options.nurserySize.getMaxNursery();
066    return super.collectionRequired(spaceFull, space) || nurseryFull;
067  }
068
069  /*****************************************************************************
070   *
071   * Accounting
072   */
073
074  /**
075   * Return the number of pages available for allocation, <i>assuming
076   * all future allocation is to the nursery</i>.
077   *
078   * @return The number of pages available for allocation, <i>assuming
079   * all future allocation is to the nursery</i>.
080   */
081  @Override
082  public int getPagesAvail() {
083    return super.getPagesAvail() >> 1;
084  }
085
086  /**
087   * Return the number of pages reserved for copying.
088   */
089  @Override
090  public final int getCollectionReserve() {
091    return nurserySpace.reservedPages() + super.getCollectionReserve();
092  }
093
094  @Override
095  public boolean willNeverMove(ObjectReference object) {
096    if (Space.isInSpace(NURSERY, object)) {
097      return false;
098    }
099    if (Space.isInSpace(REF_COUNT_LOS, object)) {
100      return true;
101    }
102    return super.willNeverMove(object);
103  }
104
105  @Interruptible
106  @Override
107  public void fullyBooted() {
108    super.fullyBooted();
109    nurserySpace.setZeroingApproach(Options.nurseryZeroing.getNonTemporal(), Options.nurseryZeroing.getConcurrent());
110  }
111}