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