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.generational.copying;
014
015 import org.mmtk.plan.generational.Gen;
016 import org.mmtk.plan.generational.GenCollector;
017 import org.mmtk.plan.Plan;
018 import org.mmtk.plan.TraceLocal;
019 import org.mmtk.policy.CopyLocal;
020 import org.mmtk.utility.ForwardingWord;
021 import org.mmtk.utility.HeaderByte;
022 import org.mmtk.utility.alloc.Allocator;
023 import org.mmtk.vm.VM;
024
025 import org.vmmagic.unboxed.*;
026 import org.vmmagic.pragma.*;
027
028 /**
029 * This class implements <i>per-collector thread</i> behavior and state for
030 * the <code>GenCopy</code> two-generational copying collector.<p>
031 *
032 * Specifically, this class defines semantics specific to the collection of
033 * the mature generation (<code>GenCollector</code> defines nursery semantics).
034 * In particular the mature space allocator is defined (for collection-time
035 * allocation into the mature space), and the mature space per-collector thread
036 * collection time semantics are defined.<p>
037 *
038 * @see GenCopy for a description of the <code>GenCopy</code> algorithm.
039 *
040 * @see GenCopy
041 * @see GenCopyMutator
042 * @see GenCollector
043 * @see org.mmtk.plan.StopTheWorldCollector
044 * @see org.mmtk.plan.CollectorContext
045 */
046 @Uninterruptible
047 public class GenCopyCollector extends GenCollector {
048
049 /******************************************************************
050 * Instance fields
051 */
052
053 /** The allocator for the mature space */
054 private final CopyLocal mature;
055
056 /** The trace object for full-heap collections */
057 private final GenCopyMatureTraceLocal matureTrace;
058
059 /****************************************************************************
060 *
061 * Initialization
062 */
063
064 /**
065 * Constructor
066 */
067 public GenCopyCollector() {
068 mature = new CopyLocal(GenCopy.toSpace());
069 matureTrace = new GenCopyMatureTraceLocal(global().matureTrace, this);
070 }
071
072 /****************************************************************************
073 *
074 * Collection-time allocation
075 */
076
077 /**
078 * {@inheritDoc}
079 */
080 @Override
081 @Inline
082 public Address allocCopy(ObjectReference original, int bytes,
083 int align, int offset, int allocator) {
084 if (allocator == Plan.ALLOC_LOS) {
085 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(Allocator.getMaximumAlignedSize(bytes, align) > Plan.MAX_NON_LOS_COPY_BYTES);
086 return los.alloc(bytes, align, offset);
087 } else {
088 if (VM.VERIFY_ASSERTIONS) {
089 VM.assertions._assert(bytes <= Plan.MAX_NON_LOS_COPY_BYTES);
090 VM.assertions._assert(allocator == GenCopy.ALLOC_MATURE_MINORGC ||
091 allocator == GenCopy.ALLOC_MATURE_MAJORGC);
092 }
093 return mature.alloc(bytes, align, offset);
094 }
095 }
096
097 /**
098 * {@inheritDoc}<p>
099 *
100 * In this case we clear any bits used for this object's GC metadata.
101 */
102 @Override
103 @Inline
104 public final void postCopy(ObjectReference object, ObjectReference typeRef,
105 int bytes, int allocator) {
106 ForwardingWord.clearForwardingBits(object);
107 if (allocator == Plan.ALLOC_LOS)
108 Plan.loSpace.initializeHeader(object, false);
109 else if (GenCopy.IGNORE_REMSETS)
110 GenCopy.immortalSpace.traceObject(getCurrentTrace(), object); // FIXME this does not look right
111 if (Gen.USE_OBJECT_BARRIER)
112 HeaderByte.markAsUnlogged(object);
113 }
114
115
116 /*****************************************************************************
117 *
118 * Collection
119 */
120
121 /**
122 * {@inheritDoc}
123 */
124 @Override
125 public void collectionPhase(short phaseId, boolean primary) {
126 if (global().traceFullHeap()) {
127 if (phaseId == GenCopy.PREPARE) {
128 super.collectionPhase(phaseId, primary);
129 if (global().gcFullHeap) mature.rebind(GenCopy.toSpace());
130 }
131 if (phaseId == GenCopy.CLOSURE) {
132 matureTrace.completeTrace();
133 return;
134 }
135 if (phaseId == GenCopy.RELEASE) {
136 matureTrace.release();
137 super.collectionPhase(phaseId, primary);
138 return;
139 }
140 }
141 super.collectionPhase(phaseId, primary);
142 }
143
144 /*****************************************************************************
145 *
146 * Miscellaneous
147 */
148
149 /** @return The active global plan as a <code>GenCopy</code> instance. */
150 private static GenCopy global() {
151 return (GenCopy) VM.activePlan.global();
152 }
153
154 /** Show the status of the mature allocator. */
155 protected final void showMature() {
156 mature.show();
157 }
158
159 @Override
160 public final TraceLocal getFullHeapTrace() { return matureTrace; }
161 }