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