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.immix;
014
015 import static org.mmtk.policy.immix.ImmixConstants.MARK_LINE_AT_SCAN_TIME;
016
017 import org.mmtk.plan.generational.GenCollector;
018 import org.mmtk.plan.generational.GenMatureTraceLocal;
019 import org.mmtk.plan.Trace;
020 import org.mmtk.policy.Space;
021 import org.mmtk.utility.Log;
022 import org.mmtk.utility.options.Options;
023 import org.mmtk.vm.VM;
024
025 import org.vmmagic.unboxed.*;
026 import org.vmmagic.pragma.*;
027
028 /**
029 * This class implments the core functionality for a transitive
030 * closure over the heap graph, specifically in a defragmenting pass over
031 * a generational immix collector.
032 */
033 @Uninterruptible
034 public final class GenImmixMatureDefragTraceLocal extends GenMatureTraceLocal{
035
036 /**
037 * Constructor
038 */
039 public GenImmixMatureDefragTraceLocal(Trace global, GenCollector plan) {
040 super(GenImmix.SCAN_DEFRAG, global, plan);
041 }
042
043 /**
044 * Is the specified object live?
045 *
046 * @param object The object.
047 * @return True if the object is live.
048 */
049 public boolean isLive(ObjectReference object) {
050 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(GenImmix.immixSpace.inImmixDefragCollection());
051 if (object.isNull()) return false;
052 if (Space.isInSpace(GenImmix.IMMIX, object)) {
053 return GenImmix.immixSpace.isLive(object);
054 }
055 return super.isLive(object);
056 }
057
058 /**
059 * This method is the core method during the trace of the object graph.
060 * The role of this method is to:
061 *
062 * 1. Ensure the traced object is not collected.
063 * 2. If this is the first visit to the object enqueue it to be scanned.
064 * 3. Return the forwarded reference to the object.
065 *
066 * @param object The object to be traced.
067 * @return The new reference to the same object instance.
068 */
069 @Inline
070 public ObjectReference traceObject(ObjectReference object) {
071 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(GenImmix.immixSpace.inImmixDefragCollection());
072 if (object.isNull()) return object;
073 if (Space.isInSpace(GenImmix.IMMIX, object))
074 return GenImmix.immixSpace.traceObject(this, object, GenImmix.ALLOC_MATURE_MAJORGC);
075 return super.traceObject(object);
076 }
077
078 @Inline
079 @Override
080 public ObjectReference precopyObject(ObjectReference object) {
081 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(GenImmix.immixSpace.inImmixDefragCollection());
082 ObjectReference rtn = traceObject(object);
083 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(willNotMoveInCurrentCollection(rtn));
084 return rtn;
085 }
086
087 /**
088 * Return true if this object is guaranteed not to move during this
089 * collection (i.e. this object is defintely not an unforwarded
090 * object).
091 *
092 * @param object
093 * @return True if this object is guaranteed not to move during this
094 * collection.
095 */
096 @Override
097 public boolean willNotMoveInCurrentCollection(ObjectReference object) {
098 if (Space.isInSpace(GenImmix.IMMIX, object)) {
099 return GenImmix.immixSpace.willNotMoveThisGC(object);
100 }
101 return super.willNotMoveInCurrentCollection(object);
102 }
103
104 /**
105 * Collectors that move objects <b>must</b> override this method.
106 * It performs the deferred scanning of objects which are forwarded
107 * during bootstrap of each copying collection. Because of the
108 * complexities of the collection bootstrap (such objects are
109 * generally themselves gc-critical), the forwarding and scanning of
110 * the objects must be dislocated. It is an error for a non-moving
111 * collector to call this method.
112 *
113 * @param object The forwarded object to be scanned
114 */
115 @Inline
116 @Override
117 protected void scanObject(ObjectReference object) {
118 if (VM.VERIFY_ASSERTIONS && Options.verbose.getValue() >= 9) {
119 Log.write("SO["); Log.write(object); Log.writeln("]");
120 }
121 super.scanObject(object);
122 if (MARK_LINE_AT_SCAN_TIME && Space.isInSpace(GenImmix.IMMIX, object))
123 GenImmix.immixSpace.markLines(object);
124 }
125 }