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.stickyms;
014    
015    import org.mmtk.plan.TraceLocal;
016    import org.mmtk.plan.Trace;
017    import org.mmtk.policy.Space;
018    import org.mmtk.utility.HeaderByte;
019    import org.mmtk.utility.deque.ObjectReferenceDeque;
020    import org.mmtk.vm.VM;
021    
022    import org.vmmagic.pragma.*;
023    import org.vmmagic.unboxed.*;
024    
025    /**
026     * This class implements the thread-local functionality for a transitive
027     * closure over a mark-sweep space.
028     */
029    @Uninterruptible
030    public final class StickyMSNurseryTraceLocal extends TraceLocal {
031    
032      /****************************************************************************
033      *
034      * Instance fields.
035      */
036     private final ObjectReferenceDeque modBuffer;
037    
038      /**
039       * Constructor
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       * Is the specified object live?
053       *
054       * @param object The object.
055       * @return True if the object is live.
056       */
057      public boolean isLive(ObjectReference object) {
058        if (object.isNull()) return false;
059        if (Space.isInSpace(StickyMS.MARK_SWEEP, object))
060          return StickyMS.msSpace.isLive(object);
061        if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(super.isLive(object));
062        return true;
063      }
064    
065      /**
066       * This method is the core method during the trace of the object graph.
067       * The role of this method is to:
068       *
069       * 1. Ensure the traced object is not collected.
070       * 2. If this is the first visit to the object enqueue it to be scanned.
071       * 3. Return the forwarded reference to the object.
072       *
073       * In this instance, we refer objects in the mark-sweep space to the
074       * msSpace for tracing, and defer to the superclass for all others.
075       *
076       * @param object The object to be traced.
077       * @return The new reference to the same object instance.
078       */
079      @Inline
080      public ObjectReference traceObject(ObjectReference object) {
081        if (object.isNull()) return object;
082        if (Space.isInSpace(StickyMS.MARK_SWEEP, object))
083          return StickyMS.msSpace.traceObject(this, object);
084        else
085          return object;
086      }
087    
088      /**
089       * Process any remembered set entries.  This means enumerating the
090       * mod buffer and for each entry, marking the object as unlogged
091       * and enqueing it for scanning.
092       */
093      protected void processRememberedSets() {
094        logMessage(2, "processing modBuffer");
095        while (!modBuffer.isEmpty()) {
096          ObjectReference src = modBuffer.pop();
097          HeaderByte.markAsUnlogged(src);
098          processNode(src);
099        }
100      }
101    }