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.stickyimmix;
014
015import static org.mmtk.policy.immix.ImmixConstants.MARK_LINE_AT_SCAN_TIME;
016import static org.mmtk.policy.immix.ImmixConstants.PREFER_COPY_ON_NURSERY_GC;
017
018import org.mmtk.plan.TraceLocal;
019import org.mmtk.plan.Trace;
020import org.mmtk.policy.Space;
021import org.mmtk.utility.HeaderByte;
022import org.mmtk.utility.deque.ObjectReferenceDeque;
023
024import org.vmmagic.pragma.*;
025import org.vmmagic.unboxed.*;
026
027/**
028 * This class implements the thread-local functionality for a transitive
029 * closure over a sticky-immix space.
030 */
031@Uninterruptible
032public final class StickyImmixNurseryTraceLocal extends TraceLocal {
033
034  /****************************************************************************
035  *
036  * Instance fields.
037  */
038
039  /**
040   *
041   */
042 private final ObjectReferenceDeque modBuffer;
043
044  public StickyImmixNurseryTraceLocal(Trace trace, ObjectReferenceDeque modBuffer) {
045    super(StickyImmix.SCAN_NURSERY, trace);
046    this.modBuffer = modBuffer;
047  }
048
049  /****************************************************************************
050   *
051   * Externally visible Object processing and tracing
052   */
053
054  /**
055   * {@inheritDoc}
056   */
057  @Override
058  public boolean isLive(ObjectReference object) {
059    if (object.isNull()) return false;
060    if (Space.isInSpace(StickyImmix.IMMIX, object))
061      return PREFER_COPY_ON_NURSERY_GC ? StickyImmix.immixSpace.copyNurseryIsLive(object) : StickyImmix.immixSpace.fastIsLive(object);
062    return true;
063  }
064
065  @Override
066  @Inline
067  public ObjectReference traceObject(ObjectReference object) {
068    if (object.isNull()) return object;
069    if (Space.isInSpace(StickyImmix.IMMIX, object))
070      return StickyImmix.immixSpace.nurseryTraceObject(this, object, StickyImmix.ALLOC_DEFAULT);
071    else
072      return object;
073  }
074
075  /**
076   * Return {@code true} if this object is guaranteed not to move during this
077   * collection (i.e. this object is definitely not an unforwarded
078   * object).
079   *
080   * @param object the object that might move
081   * @return {@code true} if this object is guaranteed not to move during this
082   *         collection.
083   */
084  @Override
085  public boolean willNotMoveInCurrentCollection(ObjectReference object) {
086    if (Space.isInSpace(StickyImmix.IMMIX, object)) {
087      if (!PREFER_COPY_ON_NURSERY_GC)
088        return true;
089      else
090        return StickyImmix.immixSpace.willNotMoveThisNurseryGC(object);
091    }
092    return super.willNotMoveInCurrentCollection(object);
093  }
094
095  @Inline
096  @Override
097  protected void scanObject(ObjectReference object) {
098    super.scanObject(object);
099    if (MARK_LINE_AT_SCAN_TIME && Space.isInSpace(StickyImmix.IMMIX, object))
100      StickyImmix.immixSpace.markLines(object);
101  }
102
103  /**
104   * Process any remembered set entries.  This means enumerating the
105   * mod buffer and for each entry, marking the object as unlogged
106   * and enqueing it for scanning.
107   */
108  @Override
109  protected void processRememberedSets() {
110    logMessage(2, "processing modBuffer");
111    while (!modBuffer.isEmpty()) {
112      ObjectReference src = modBuffer.pop();
113      HeaderByte.markAsUnlogged(src);
114      processNode(src);
115    }
116  }
117}