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.semispace;
014
015import org.mmtk.plan.TraceLocal;
016import org.mmtk.plan.Trace;
017import org.mmtk.policy.Space;
018
019import org.vmmagic.pragma.*;
020import org.vmmagic.unboxed.*;
021
022/**
023 * This class implements the core functionality for a transitive
024 * closure over the heap graph.
025 */
026@Uninterruptible
027public class SSTraceLocal extends TraceLocal {
028
029  public SSTraceLocal(Trace trace, boolean specialized) {
030    super(specialized ? SS.SCAN_SS : -1, trace);
031  }
032
033  /**
034   * @param trace the associated global trace
035   */
036  public SSTraceLocal(Trace trace) {
037    this(trace, true);
038  }
039
040  /****************************************************************************
041   *
042   * Externally visible Object processing and tracing
043   */
044
045  /**
046   * {@inheritDoc}
047   */
048  @Override
049  public boolean isLive(ObjectReference object) {
050    if (object.isNull()) return false;
051    if (Space.isInSpace(SS.SS0, object))
052      return SS.hi ? SS.copySpace0.isLive(object) : true;
053    if (Space.isInSpace(SS.SS1, object))
054      return SS.hi ? true : SS.copySpace1.isLive(object);
055    return super.isLive(object);
056  }
057
058
059  @Override
060  @Inline
061  public ObjectReference traceObject(ObjectReference object) {
062    if (object.isNull()) return object;
063    if (Space.isInSpace(SS.SS0, object))
064      return SS.copySpace0.traceObject(this, object, SS.ALLOC_SS);
065    if (Space.isInSpace(SS.SS1, object))
066      return SS.copySpace1.traceObject(this, object, SS.ALLOC_SS);
067    return super.traceObject(object);
068  }
069
070  /**
071   * Will this object move from this point on, during the current trace ?
072   *
073   * @param object The object to query.
074   * @return True if the object will not move.
075   */
076  @Override
077  public boolean willNotMoveInCurrentCollection(ObjectReference object) {
078    return (SS.hi && !Space.isInSpace(SS.SS0, object)) ||
079           (!SS.hi && !Space.isInSpace(SS.SS1, object));
080  }
081}