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.Gen;
016    import org.mmtk.plan.generational.GenCollector;
017    import org.mmtk.plan.generational.GenMatureTraceLocal;
018    import org.mmtk.plan.Trace;
019    import org.mmtk.policy.Space;
020    
021    import org.mmtk.vm.VM;
022    
023    import org.vmmagic.pragma.*;
024    import org.vmmagic.unboxed.*;
025    
026    /**
027     * This class implments the core functionality for a transitive
028     * closure over the heap graph, specifically in a Generational copying
029     * collector.
030     */
031    @Uninterruptible
032    public final class GenCopyMatureTraceLocal extends GenMatureTraceLocal {
033    
034      /**
035       * Constructor
036       */
037      public GenCopyMatureTraceLocal(Trace global, GenCollector plan) {
038        super(global, plan);
039      }
040    
041      private static GenCopy global() {
042        return (GenCopy) VM.activePlan.global();
043      }
044    
045      /**
046       * Trace a reference into the mature space during GC. This involves
047       * determining whether the instance is in from space, and if so,
048       * calling the <code>traceObject</code> method of the Copy
049       * collector.
050       *
051       * @param object The object reference to be traced.  This is <i>NOT</i> an
052       * interior pointer.
053       * @return The possibly moved reference.
054       */
055      public ObjectReference traceObject(ObjectReference object) {
056        if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(global().traceFullHeap());
057        if (object.isNull()) return object;
058    
059        if (Space.isInSpace(GenCopy.MS0, object))
060          return GenCopy.matureSpace0.traceObject(this, object, Gen.ALLOC_MATURE_MAJORGC);
061        if (Space.isInSpace(GenCopy.MS1, object))
062          return GenCopy.matureSpace1.traceObject(this, object, Gen.ALLOC_MATURE_MAJORGC);
063        return super.traceObject(object);
064      }
065    
066      /**
067       * Return true if <code>obj</code> is a live object.
068       *
069       * @param object The object in question
070       * @return True if <code>obj</code> is a live object.
071       */
072      public boolean isLive(ObjectReference object) {
073        if (object.isNull()) return false;
074        if (Space.isInSpace(GenCopy.MS0, object))
075          return GenCopy.hi ? GenCopy.matureSpace0.isLive(object) : true;
076        if (Space.isInSpace(GenCopy.MS1, object))
077          return GenCopy.hi ? true : GenCopy.matureSpace1.isLive(object);
078        return super.isLive(object);
079      }
080    
081      /****************************************************************************
082       *
083       * Object processing and tracing
084       */
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      public boolean willNotMoveInCurrentCollection(ObjectReference object) {
097        if (Space.isInSpace(GenCopy.toSpaceDesc(), object)) {
098          return true;
099        }
100        if (Space.isInSpace(GenCopy.fromSpaceDesc(), object)) {
101          return false;
102        }
103        return super.willNotMoveInCurrentCollection(object);
104      }
105    }