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.refcount.generational;
014
015 import org.mmtk.plan.TraceLocal;
016 import org.mmtk.plan.Trace;
017 import org.mmtk.plan.refcount.RCHeader;
018 import org.mmtk.policy.Space;
019 import org.mmtk.utility.deque.ObjectReferenceDeque;
020 import org.mmtk.vm.VM;
021
022 import org.vmmagic.pragma.*;
023 import org.vmmagic.unboxed.*;
024
025 /**
026 * This class implements the thread-local core functionality for a transitive
027 * closure over the heap graph.
028 */
029 @Uninterruptible
030 public final class GenRCFindRootSetTraceLocal extends TraceLocal {
031
032 private final ObjectReferenceDeque rootBuffer;
033
034 /**
035 * Constructor
036 */
037 public GenRCFindRootSetTraceLocal(Trace trace, ObjectReferenceDeque rootBuffer) {
038 super(trace);
039 this.rootBuffer = rootBuffer;
040 }
041
042 /****************************************************************************
043 *
044 * Externally visible Object processing and tracing
045 */
046
047 /**
048 * Is the specified object reachable?
049 *
050 * @return <code>true</code> if the object is reachable.
051 */
052 @Override
053 public boolean isLive(ObjectReference object) {
054 return GenRC.isRCObject(object) && RCHeader.isLiveRC(object) ||
055 (!Space.isInSpace(GenRC.NURSERY, object) && super.isLive(object));
056 }
057
058 /**
059 * When we trace a non-root object we do nothing.
060 */
061 @Override
062 @Inline
063 public ObjectReference traceObject(ObjectReference object) {
064 return traceObject(object, false);
065 }
066
067 /**
068 * When we trace a root object we remember it.
069 */
070 @Override
071 @Inline
072 public ObjectReference traceObject(ObjectReference object, boolean root) {
073 if (object.isNull()) return object;
074
075 if (Space.isInSpace(GenRC.NURSERY, object)) {
076 object = GenRC.nurserySpace.traceObject(this, object, GenRC.ALLOC_RC);
077 } else if (!GenRC.isRCObject(object)) {
078 return object;
079 }
080
081 if (root) {
082 rootBuffer.push(object);
083 } else {
084 RCHeader.incRC(object);
085 }
086
087 return object;
088 }
089
090 @Override
091 public boolean willNotMoveInCurrentCollection(ObjectReference object) {
092 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!object.isNull());
093 return !(Space.isInSpace(GenRC.NURSERY, object));
094 }
095 }