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.stickyimmix;
014    
015    import static org.mmtk.policy.immix.ImmixConstants.MARK_LINE_AT_SCAN_TIME;
016    import static org.mmtk.policy.immix.ImmixConstants.TMP_PREFER_COPY_ON_NURSERY_GC;
017    
018    import org.mmtk.plan.TraceLocal;
019    import org.mmtk.plan.Trace;
020    import org.mmtk.policy.Space;
021    import org.mmtk.utility.HeaderByte;
022    import org.mmtk.utility.deque.ObjectReferenceDeque;
023    import org.mmtk.vm.VM;
024    
025    import org.vmmagic.pragma.*;
026    import org.vmmagic.unboxed.*;
027    
028    /**
029     * This class implements the thread-local functionality for a transitive
030     * closure over a sticky-immix space.
031     */
032    @Uninterruptible
033    public final class StickyImmixNurseryTraceLocal extends TraceLocal {
034    
035      /****************************************************************************
036      *
037      * Instance fields.
038      */
039     private final ObjectReferenceDeque modBuffer;
040    
041      /**
042       * Constructor
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       * Is the specified object live?
056       *
057       * @param object The object.
058       * @return True if the object is live.
059       */
060      public boolean isLive(ObjectReference object) {
061        if (object.isNull()) return false;
062        if (Space.isInSpace(StickyImmix.IMMIX, object))
063          return TMP_PREFER_COPY_ON_NURSERY_GC ? StickyImmix.immixSpace.copyNurseryIsLive(object) : StickyImmix.immixSpace.fastIsLive(object);
064        if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(super.isLive(object));
065        return true;
066      }
067    
068      /**
069       * This method is the core method during the trace of the object graph.
070       * The role of this method is to:
071       *
072       * 1. Ensure the traced object is not collected.
073       * 2. If this is the first visit to the object enqueue it to be scanned.
074       * 3. Return the forwarded reference to the object.
075       *
076       * In this instance, we refer objects in the mark-sweep space to the
077       * msSpace for tracing, and defer to the superclass for all others.
078       *
079       * @param object The object to be traced.
080       * @return The new reference to the same object instance.
081       */
082      @Inline
083      public ObjectReference traceObject(ObjectReference object) {
084        if (object.isNull()) return object;
085        if (Space.isInSpace(StickyImmix.IMMIX, object))
086          return StickyImmix.immixSpace.nurseryTraceObject(this, object, StickyImmix.ALLOC_DEFAULT);
087        else
088          return object;
089      }
090    
091      /**
092       * Return true if this object is guaranteed not to move during this
093       * collection (i.e. this object is definitely not an unforwarded
094       * object).
095       *
096       * @param object
097       * @return True if this object is guaranteed not to move during this
098       *         collection.
099       */
100      @Override
101      public boolean willNotMoveInCurrentCollection(ObjectReference object) {
102        if (Space.isInSpace(StickyImmix.IMMIX, object)) {
103          if (!TMP_PREFER_COPY_ON_NURSERY_GC)
104            return true;
105          else
106            return StickyImmix.immixSpace.willNotMoveThisNurseryGC(object);
107        }
108        return super.willNotMoveInCurrentCollection(object);
109      }
110    
111      /**
112       * Collectors that move objects <b>must</b> override this method.
113       * It performs the deferred scanning of objects which are forwarded
114       * during bootstrap of each copying collection.  Because of the
115       * complexities of the collection bootstrap (such objects are
116       * generally themselves gc-critical), the forwarding and scanning of
117       * the objects must be dislocated.  It is an error for a non-moving
118       * collector to call this method.
119       *
120       * @param object The forwarded object to be scanned
121       */
122      @Inline
123      @Override
124      protected void scanObject(ObjectReference object) {
125        super.scanObject(object);
126        if (MARK_LINE_AT_SCAN_TIME && Space.isInSpace(StickyImmix.IMMIX, object))
127          StickyImmix.immixSpace.markLines(object);
128      }
129    
130      /**
131       * Process any remembered set entries.  This means enumerating the
132       * mod buffer and for each entry, marking the object as unlogged
133       * and enqueing it for scanning.
134       */
135      protected void processRememberedSets() {
136        logMessage(2, "processing modBuffer");
137        while (!modBuffer.isEmpty()) {
138          ObjectReference src = modBuffer.pop();
139          HeaderByte.markAsUnlogged(src);
140          processNode(src);
141        }
142      }
143    }