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.semispace;
014
015import org.mmtk.plan.*;
016import org.mmtk.policy.CopyLocal;
017import org.mmtk.policy.Space;
018import org.mmtk.utility.alloc.Allocator;
019
020import org.vmmagic.unboxed.*;
021import org.vmmagic.pragma.*;
022
023/**
024 * This class implements <i>per-mutator thread</i> behavior
025 * and state for the <i>SS</i> plan, which implements a full-heap
026 * semi-space collector.<p>
027 *
028 * Specifically, this class defines <i>SS</i> mutator-time allocation
029 * and per-mutator thread collection semantics (flushing and restoring
030 * per-mutator allocator state).<p>
031 *
032 * See {@link SS} for an overview of the semi-space algorithm.
033 *
034 * @see SS
035 * @see SSCollector
036 * @see StopTheWorldMutator
037 * @see MutatorContext
038 */
039@Uninterruptible
040public class SSMutator extends StopTheWorldMutator {
041  /****************************************************************************
042   * Instance fields
043   */
044  protected final CopyLocal ss;
045
046  /****************************************************************************
047   *
048   * Initialization
049   */
050
051  /**
052   * Constructor
053   */
054  public SSMutator() {
055    ss = new CopyLocal();
056  }
057
058  /**
059   * Called before the MutatorContext is used, but after the context has been
060   * fully registered and is visible to collection.
061   */
062  @Override
063  public void initMutator(int id) {
064    super.initMutator(id);
065    ss.rebind(SS.toSpace());
066  }
067
068  /****************************************************************************
069   *
070   * Mutator-time allocation
071   */
072
073  /**
074   * {@inheritDoc}
075   */
076  @Override
077  @Inline
078  public Address alloc(int bytes, int align, int offset, int allocator, int site) {
079    if (allocator == SS.ALLOC_SS)
080      return ss.alloc(bytes, align, offset);
081    else
082      return super.alloc(bytes, align, offset, allocator, site);
083  }
084
085  @Override
086  @Inline
087  public void postAlloc(ObjectReference object, ObjectReference typeRef,
088      int bytes, int allocator) {
089    if (allocator == SS.ALLOC_SS) return;
090    super.postAlloc(object, typeRef, bytes, allocator);
091  }
092
093  @Override
094  public Allocator getAllocatorFromSpace(Space space) {
095    if (space == SS.copySpace0 || space == SS.copySpace1) return ss;
096    return super.getAllocatorFromSpace(space);
097  }
098
099  /****************************************************************************
100   *
101   * Collection
102   */
103
104  /**
105   * {@inheritDoc}
106   */
107  @Override
108  @Inline
109  public void collectionPhase(short phaseId, boolean primary) {
110    if (phaseId == SS.PREPARE) {
111      super.collectionPhase(phaseId, primary);
112      return;
113    }
114
115    if (phaseId == SS.RELEASE) {
116      super.collectionPhase(phaseId, primary);
117      // rebind the allocation bump pointer to the appropriate semispace.
118      ss.rebind(SS.toSpace());
119      return;
120    }
121
122    super.collectionPhase(phaseId, primary);
123  }
124
125
126  /****************************************************************************
127   *
128   * Miscellaneous
129   */
130
131  /**
132   * Show the status of each of the allocators.
133   */
134  public final void show() {
135    ss.show();
136    los.show();
137    immortal.show();
138  }
139
140}