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.immix;
014
015 import static org.mmtk.policy.immix.ImmixConstants.MARK_LINE_AT_SCAN_TIME;
016
017 import org.mmtk.plan.Plan;
018 import org.mmtk.plan.TraceLocal;
019 import org.mmtk.plan.Trace;
020 import org.mmtk.policy.Space;
021 import org.mmtk.utility.HeaderByte;
022 import org.mmtk.utility.deque.ObjectReferenceDeque;
023 import org.mmtk.vm.VM;
024
025 import org.vmmagic.pragma.*;
026 import org.vmmagic.unboxed.*;
027
028 /**
029 * This class implements the thread-local functionality for a defragmenting
030 * transitive closure over an immix space.
031 */
032 @Uninterruptible
033 public final class ImmixDefragTraceLocal extends TraceLocal {
034
035 /****************************************************************************
036 *
037 * Instance fields
038 */
039 private final ObjectReferenceDeque modBuffer;
040
041 /**
042 * Constructor
043 * @param modBuffer TODO
044 */
045 public ImmixDefragTraceLocal(Trace trace, ObjectReferenceDeque modBuffer) {
046 super(Immix.SCAN_DEFRAG, trace);
047 this.modBuffer = modBuffer;
048 }
049
050 /****************************************************************************
051 *
052 * Externally visible Object processing and tracing
053 */
054
055 /**
056 * Is the specified object live?
057 *
058 * @param object The object.
059 * @return True if the object is live.
060 */
061 public boolean isLive(ObjectReference object) {
062 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(Immix.immixSpace.inImmixDefragCollection());
063 if (object.isNull()) return false;
064 if (Space.isInSpace(Immix.IMMIX, object)) {
065 return Immix.immixSpace.isLive(object);
066 }
067 return super.isLive(object);
068 }
069
070 /**
071 * This method is the core method during the trace of the object graph.
072 * The role of this method is to:
073 *
074 * 1. Ensure the traced object is not collected.
075 * 2. If this is the first visit to the object enqueue it to be scanned.
076 * 3. Return the forwarded reference to the object.
077 *
078 * In this instance, we refer objects in the mark-sweep space to the
079 * immixSpace for tracing, and defer to the superclass for all others.
080 *
081 * @param object The object to be traced.
082 * @return The new reference to the same object instance.
083 */
084 @Inline
085 public ObjectReference traceObject(ObjectReference object) {
086 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(Immix.immixSpace.inImmixDefragCollection());
087 if (object.isNull()) return object;
088 if (Space.isInSpace(Immix.IMMIX, object))
089 return Immix.immixSpace.traceObject(this, object, Plan.ALLOC_DEFAULT);
090 return super.traceObject(object);
091 }
092
093 @Inline
094 @Override
095 public ObjectReference precopyObject(ObjectReference object) {
096 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(Immix.immixSpace.inImmixDefragCollection());
097 ObjectReference rtn = traceObject(object);
098 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(willNotMoveInCurrentCollection(rtn));
099 return rtn;
100 }
101
102 /**
103 * Return true if this object is guaranteed not to move during this
104 * collection (i.e. this object is defintely not an unforwarded
105 * object).
106 *
107 * @param object
108 * @return True if this object is guaranteed not to move during this
109 * collection.
110 */
111 @Override
112 public boolean willNotMoveInCurrentCollection(ObjectReference object) {
113 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(Immix.immixSpace.inImmixDefragCollection());
114 if (Space.isInSpace(Immix.IMMIX, object))
115 return Immix.immixSpace.willNotMoveThisGC(object);
116 return true;
117 }
118
119 /**
120 * Collectors that move objects <b>must</b> override this method.
121 * It performs the deferred scanning of objects which are forwarded
122 * during bootstrap of each copying collection. Because of the
123 * complexities of the collection bootstrap (such objects are
124 * generally themselves gc-critical), the forwarding and scanning of
125 * the objects must be dislocated. It is an error for a non-moving
126 * collector to call this method.
127 *
128 * @param object The forwarded object to be scanned
129 */
130 @Inline
131 @Override
132 protected void scanObject(ObjectReference object) {
133 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(Immix.immixSpace.inImmixDefragCollection());
134 super.scanObject(object);
135 if (MARK_LINE_AT_SCAN_TIME && Space.isInSpace(Immix.IMMIX, object))
136 Immix.immixSpace.markLines(object);
137 }
138
139 /**
140 * Process any remembered set entries. This means enumerating the
141 * mod buffer and for each entry, marking the object as unlogged
142 * (we don't enqueue for scanning since we're doing a full heap GC).
143 */
144 protected void processRememberedSets() {
145 if (modBuffer != null) {
146 logMessage(5, "clearing modBuffer");
147 while (!modBuffer.isEmpty()) {
148 ObjectReference src = modBuffer.pop();
149 HeaderByte.markAsUnlogged(src);
150 }
151 }
152 }
153 }