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.GenMutator;
016 import org.mmtk.policy.CopyLocal;
017 import org.mmtk.policy.Space;
018 import org.mmtk.utility.alloc.Allocator;
019 import org.mmtk.vm.VM;
020
021 import org.vmmagic.unboxed.*;
022 import org.vmmagic.pragma.*;
023
024 /**
025 * This class implements <i>per-mutator thread</i> behavior and state for
026 * the <code>GenCopy</code> two-generational copying collector.<p>
027 *
028 * Specifically, this class defines mutator-time semantics specific to the
029 * mature generation (<code>GenMutator</code> defines nursery semantics).
030 * In particular the mature space allocator is defined (for mutator-time
031 * allocation into the mature space via pre-tenuring), and the mature space
032 * per-mutator thread collection time semantics are defined (rebinding
033 * the mature space allocator).<p>
034 *
035 * @see GenCopy for a description of the <code>GenCopy</code> algorithm.
036 *
037 * @see GenCopy
038 * @see GenCopyCollector
039 * @see GenMutator
040 * @see org.mmtk.plan.StopTheWorldMutator
041 * @see org.mmtk.plan.MutatorContext
042 */
043 @Uninterruptible
044 public class GenCopyMutator extends GenMutator {
045 /******************************************************************
046 * Instance fields
047 */
048
049 /**
050 * The allocator for the copying mature space (the mutator may
051 * "pretenure" objects into this space otherwise used only by
052 * the collector)
053 */
054 private CopyLocal mature;
055
056 /****************************************************************************
057 *
058 * Initialization
059 */
060
061 /**
062 * Constructor
063 */
064 public GenCopyMutator() {
065 mature = new CopyLocal();
066 }
067
068 /**
069 * Called before the MutatorContext is used, but after the context has been
070 * fully registered and is visible to collection.
071 */
072 @Override
073 public void initMutator(int id) {
074 super.initMutator(id);
075 mature.rebind(GenCopy.toSpace());
076 }
077
078 /****************************************************************************
079 *
080 * Mutator-time allocation
081 */
082
083 /**
084 * {@inheritDoc}
085 */
086 @Override
087 @Inline
088 public final Address alloc(int bytes, int align, int offset, int allocator, int site) {
089 if (allocator == GenCopy.ALLOC_MATURE) {
090 return mature.alloc(bytes, align, offset);
091 }
092 return super.alloc(bytes, align, offset, allocator, site);
093 }
094
095 @Override
096 @Inline
097 public final void postAlloc(ObjectReference object, ObjectReference typeRef,
098 int bytes, int allocator) {
099 // nothing to be done
100 if (allocator == GenCopy.ALLOC_MATURE) return;
101 super.postAlloc(object, typeRef, bytes, allocator);
102 }
103
104 @Override
105 public final Allocator getAllocatorFromSpace(Space space) {
106 if (space == GenCopy.matureSpace0 || space == GenCopy.matureSpace1) return mature;
107 return super.getAllocatorFromSpace(space);
108 }
109
110
111 /*****************************************************************************
112 *
113 * Collection
114 */
115
116 /**
117 * {@inheritDoc}
118 */
119 @Override
120 public void collectionPhase(short phaseId, boolean primary) {
121 if (global().traceFullHeap()) {
122 if (phaseId == GenCopy.RELEASE) {
123 super.collectionPhase(phaseId, primary);
124 if (global().gcFullHeap) mature.rebind(GenCopy.toSpace());
125 return;
126 }
127 }
128
129 super.collectionPhase(phaseId, primary);
130 }
131
132 /*****************************************************************************
133 *
134 * Miscellaneous
135 */
136
137 /** @return The active global plan as a <code>GenCopy</code> instance. */
138 private static GenCopy global() {
139 return (GenCopy) VM.activePlan.global();
140 }
141
142 }