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.markcompact;
014
015 import org.mmtk.plan.TraceLocal;
016 import org.mmtk.plan.Trace;
017 import org.mmtk.policy.Space;
018 import org.mmtk.vm.VM;
019
020 import org.vmmagic.pragma.*;
021 import org.vmmagic.unboxed.*;
022
023 /**
024 * This class implments the thread-local functionality for a transitive
025 * closure over a mark-compact space during the forwarding phase.
026 */
027 @Uninterruptible
028 public final class MCForwardTraceLocal extends TraceLocal {
029 /**
030 * Constructor
031 */
032 public MCForwardTraceLocal(Trace trace) {
033 super(MC.SCAN_FORWARD, trace);
034 }
035
036 /****************************************************************************
037 *
038 * Externally visible Object processing and tracing
039 */
040
041 /**
042 * Is the specified object live?
043 *
044 * @param object The object.
045 * @return True if the object is live.
046 */
047 public boolean isLive(ObjectReference object) {
048 if (object.isNull()) return false;
049 if (Space.isInSpace(MC.MARK_COMPACT, object)) {
050 return MC.mcSpace.isLive(object);
051 }
052 return super.isLive(object);
053 }
054
055 /**
056 * This method is the core method during the trace of the object graph.
057 * The role of this method is to:
058 *
059 * 1. Ensure the traced object is not collected.
060 * 2. If this is the first visit to the object enqueue it to be scanned.
061 * 3. Return the forwarded reference to the object.
062 *
063 * In this instance, we refer objects in the mark-sweep space to the
064 * msSpace for tracing, and defer to the superclass for all others.
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 (object.isNull()) return object;
072 if (Space.isInSpace(MC.MARK_COMPACT, object))
073 return MC.mcSpace.traceForwardObject(this, object);
074 return super.traceObject(object);
075 }
076
077 /**
078 * Will this object move from this point on, during the current trace ?
079 *
080 * @param object The object to query.
081 * @return True if the object will not move.
082 */
083 public boolean willNotMoveInCurrentCollection(ObjectReference object) {
084 return !Space.isInSpace(MC.MARK_COMPACT, object);
085 }
086
087 /**
088 * Ensure that this object will not move for the rest of the GC.
089 *
090 * @param object The object that must not move
091 * @return The new object, guaranteed stable for the rest of the GC.
092 */
093 @Inline
094 public ObjectReference precopyObject(ObjectReference object) {
095 if (VM.VERIFY_ASSERTIONS) {
096 // All precopying must occur during the initial trace.
097 VM.assertions._assert(!Space.isInSpace(MC.MARK_COMPACT, object));
098 }
099 return super.precopyObject(object);
100 }
101
102 }