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.plan.refcount.generational;
014
015 import org.mmtk.plan.refcount.RCBase;
016 import org.mmtk.plan.refcount.RCBaseMutator;
017 import org.mmtk.policy.CopyLocal;
018 import org.mmtk.policy.Space;
019 import org.mmtk.utility.alloc.Allocator;
020 import org.vmmagic.pragma.*;
021 import org.vmmagic.unboxed.Address;
022 import org.vmmagic.unboxed.ObjectReference;
023
024 /**
025 * This class implements the mutator context for a simple reference counting collector.
026 */
027 @Uninterruptible
028 public class GenRCMutator extends RCBaseMutator {
029 /************************************************************************
030 * Instance fields
031 */
032
033 /**
034 *
035 */
036 private final CopyLocal nursery;
037
038 public GenRCMutator() {
039 nursery = new CopyLocal(GenRC.nurserySpace);
040 }
041
042 /****************************************************************************
043 *
044 * Mutator-time allocation
045 */
046
047 /**
048 * {@inheritDoc}
049 */
050 @Override
051 @Inline
052 public Address alloc(int bytes, int align, int offset, int allocator, int site) {
053 if (allocator == GenRC.ALLOC_NURSERY) {
054 return nursery.alloc(bytes, align, offset);
055 }
056 return super.alloc(bytes, align, offset, allocator, site);
057 }
058
059 @Override
060 @Inline
061 public void postAlloc(ObjectReference ref, ObjectReference typeRef, int bytes, int allocator) {
062 if (allocator == GenRC.ALLOC_NURSERY) {
063 return;
064 }
065 super.postAlloc(ref, typeRef, bytes, allocator);
066 }
067
068 @Override
069 public Allocator getAllocatorFromSpace(Space space) {
070 if (space == GenRC.nurserySpace) return nursery;
071
072 return super.getAllocatorFromSpace(space);
073 }
074
075 /****************************************************************************
076 *
077 * Collection
078 */
079
080 /**
081 * {@inheritDoc}
082 */
083 @Override
084 public final void collectionPhase(short phaseId, boolean primary) {
085 if (phaseId == RCBase.PREPARE) {
086 nursery.rebind(GenRC.nurserySpace);
087 super.collectionPhase(phaseId, primary);
088 return;
089 }
090
091 super.collectionPhase(phaseId, primary);
092 }
093 }