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.stickyms;
014
015import org.mmtk.plan.TraceLocal;
016import org.mmtk.plan.Trace;
017import org.mmtk.policy.Space;
018import org.mmtk.utility.HeaderByte;
019import org.mmtk.utility.deque.ObjectReferenceDeque;
020
021import org.vmmagic.pragma.*;
022import org.vmmagic.unboxed.*;
023
024/**
025 * This class implements the thread-local functionality for a transitive
026 * closure over a mark-sweep space.
027 */
028@Uninterruptible
029public final class StickyMSNurseryTraceLocal extends TraceLocal {
030
031  /****************************************************************************
032  *
033  * Instance fields.
034  */
035
036 /**
037  *
038  */
039 private final ObjectReferenceDeque modBuffer;
040
041  public StickyMSNurseryTraceLocal(Trace trace, ObjectReferenceDeque modBuffer) {
042    super(StickyMS.SCAN_NURSERY, trace);
043    this.modBuffer = modBuffer;
044  }
045
046  /****************************************************************************
047   *
048   * Externally visible Object processing and tracing
049   */
050
051  /**
052   * {@inheritDoc}
053   */
054  @Override
055  public boolean isLive(ObjectReference object) {
056    if (object.isNull()) return false;
057    if (Space.isInSpace(StickyMS.MARK_SWEEP, object))
058      return StickyMS.msSpace.isLive(object);
059    return true;
060  }
061
062  /**
063   * {@inheritDoc}<p>
064   *
065   * In this instance, we refer objects in the mark-sweep space to the
066   * msSpace for tracing, and defer to the superclass for all others.
067   *
068   * @param object The object to be traced.
069   * @return The new reference to the same object instance.
070   */
071  @Override
072  @Inline
073  public ObjectReference traceObject(ObjectReference object) {
074    if (object.isNull()) return object;
075    if (Space.isInSpace(StickyMS.MARK_SWEEP, object))
076      return StickyMS.msSpace.traceObject(this, object);
077    else
078      return object;
079  }
080
081  /**
082   * Process any remembered set entries.  This means enumerating the
083   * mod buffer and for each entry, marking the object as unlogged
084   * and enqueing it for scanning.
085   */
086  @Override
087  protected void processRememberedSets() {
088    logMessage(2, "processing modBuffer");
089    while (!modBuffer.isEmpty()) {
090      ObjectReference src = modBuffer.pop();
091      HeaderByte.markAsUnlogged(src);
092      processNode(src);
093    }
094  }
095}