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 public void initMutator(int id) {
073 super.initMutator(id);
074 mature.rebind(GenCopy.toSpace());
075 }
076
077 /****************************************************************************
078 *
079 * Mutator-time allocation
080 */
081
082 /**
083 * Allocate space (for an object) in the specified space
084 *
085 * @param bytes The size of the space to be allocated (in bytes)
086 * @param align The requested alignment.
087 * @param offset The alignment offset.
088 * @param allocator The allocator to allocate from
089 * @param site Allocation site
090 * @return The address of the first byte of the allocated region
091 */
092 @Inline
093 public final Address alloc(int bytes, int align, int offset, int allocator, int site) {
094 if (allocator == GenCopy.ALLOC_MATURE) {
095 return mature.alloc(bytes, align, offset);
096 }
097 return super.alloc(bytes, align, offset, allocator, site);
098 }
099
100 /**
101 * Perform post-allocation initialization of an object
102 *
103 * @param object The newly allocated object
104 * @param typeRef the type reference for the instance being created
105 * @param allocator The allocator to allocate from
106 * @param bytes The size of the space allocated (in bytes)
107 */
108 @Inline
109 public final void postAlloc(ObjectReference object, ObjectReference typeRef,
110 int bytes, int allocator) {
111 // nothing to be done
112 if (allocator == GenCopy.ALLOC_MATURE) return;
113 super.postAlloc(object, typeRef, bytes, allocator);
114 }
115
116 /**
117 * Return the allocator instance associated with a space
118 * <code>space</code>, for this plan instance.
119 *
120 * @param space The space for which the allocator instance is desired.
121 * @return The allocator instance associated with this plan instance
122 * which is allocating into <code>space</code>, or <code>null</code>
123 * if no appropriate allocator can be established.
124 */
125 public final Allocator getAllocatorFromSpace(Space space) {
126 if (space == GenCopy.matureSpace0 || space == GenCopy.matureSpace1) return mature;
127 return super.getAllocatorFromSpace(space);
128 }
129
130
131 /*****************************************************************************
132 *
133 * Collection
134 */
135
136 /**
137 * Execute a per-mutator collection phase.
138 *
139 * @param phaseId The phase to execute.
140 * @param primary True if this thread should peform local single-threaded
141 * actions.
142 */
143 public void collectionPhase(short phaseId, boolean primary) {
144 if (global().traceFullHeap()) {
145 if (phaseId == GenCopy.RELEASE) {
146 super.collectionPhase(phaseId, primary);
147 if (global().gcFullHeap) mature.rebind(GenCopy.toSpace());
148 return;
149 }
150 }
151
152 super.collectionPhase(phaseId, primary);
153 }
154
155 /*****************************************************************************
156 *
157 * Miscellaneous
158 */
159
160 /** @return The active global plan as a <code>GenCopy</code> instance. */
161 private static GenCopy global() {
162 return (GenCopy) VM.activePlan.global();
163 }
164
165 }