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.concurrent.marksweep;
014
015 import org.mmtk.plan.*;
016 import org.mmtk.plan.concurrent.Concurrent;
017 import org.mmtk.policy.MarkSweepSpace;
018 import org.mmtk.policy.Space;
019 import org.mmtk.utility.heap.VMRequest;
020
021 import org.vmmagic.pragma.*;
022 import org.vmmagic.unboxed.ObjectReference;
023
024 /**
025 * This class implements the global state of a concurrent mark-sweep collector.
026 */
027 @Uninterruptible
028 public class CMS extends Concurrent {
029
030 /****************************************************************************
031 * Constants
032 */
033
034 /****************************************************************************
035 * Class variables
036 */
037
038 /**
039 *
040 */
041 public static final MarkSweepSpace msSpace = new MarkSweepSpace("ms", VMRequest.create());
042 public static final int MARK_SWEEP = msSpace.getDescriptor();
043
044 static {
045 msSpace.makeAllocAsMarked();
046 smallCodeSpace.makeAllocAsMarked();
047 nonMovingSpace.makeAllocAsMarked();
048 }
049
050 /****************************************************************************
051 * Instance variables
052 */
053
054 /**
055 *
056 */
057 public final Trace msTrace = new Trace(metaDataSpace);
058
059 /*****************************************************************************
060 *
061 * Collection
062 */
063
064 /**
065 * {@inheritDoc}
066 */
067 @Override
068 @Inline
069 public void collectionPhase(short phaseId) {
070 if (phaseId == PREPARE) {
071 super.collectionPhase(phaseId);
072 msTrace.prepareNonBlocking();
073 msSpace.prepare(true);
074 return;
075 }
076
077 if (phaseId == RELEASE) {
078 msTrace.release();
079 msSpace.release();
080 super.collectionPhase(phaseId);
081 return;
082 }
083
084 super.collectionPhase(phaseId);
085 }
086
087 /*****************************************************************************
088 *
089 * Accounting
090 */
091
092 /**
093 * {@inheritDoc}
094 * The superclass accounts for its spaces, we just
095 * augment this with the mark-sweep space's contribution.
096 */
097 @Override
098 public int getPagesUsed() {
099 return (msSpace.reservedPages() + super.getPagesUsed());
100 }
101
102 @Override
103 public boolean willNeverMove(ObjectReference object) {
104 if (Space.isInSpace(MARK_SWEEP, object))
105 return true;
106 return super.willNeverMove(object);
107 }
108 }