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.utility.sanitychecker;
014
015import org.mmtk.plan.TraceLocal;
016import org.mmtk.plan.Trace;
017import org.mmtk.vm.VM;
018
019import org.vmmagic.pragma.*;
020import org.vmmagic.unboxed.*;
021
022/**
023 * This class implements the parallel root-gathering part of a sanity check.
024 */
025@Uninterruptible
026public final class SanityRootTraceLocal extends TraceLocal {
027
028  public SanityRootTraceLocal(Trace trace) {
029    super(trace);
030  }
031
032  /****************************************************************************
033   *
034   * Object processing and tracing
035   */
036
037  /**
038   * Copy root values across to the 'real' single-threaded trace that will do
039   * the sanity checking.
040   *
041   * @param trace the trace that will do the sanity checking
042   */
043  @Inline
044  public void copyRootValuesTo(TraceLocal trace) {
045    while (!rootLocations.isEmpty()) {
046      ObjectReference object = rootLocations.pop().loadObjectReference();
047      if (!object.isNull()) {
048        trace.traceObject(object, true);
049      }
050    }
051    while (!values.isEmpty()) {
052      trace.traceObject(values.pop(), true);
053    }
054  }
055
056  /**
057   * Process delayed roots. This does not make sense for SanityRootTraceLocal.
058   * are empty.
059   */
060  @Override
061  @Inline
062  public void processRoots() {
063    VM.assertions.fail("SanityRootTraceLocal.processRoots called.");
064  }
065
066  /**
067   * Finishing processing all GC work. This does not make sense for SanityRootTraceLocal.
068   */
069  @Override
070  @Inline
071  public void completeTrace() {
072    VM.assertions.fail("SanityRootTraceLocal.completeTrace called.");
073  }
074
075  /**
076   * Trace a root object, i.e. root must be <code>true</code>.
077   */
078  @Override
079  @Inline
080  public ObjectReference traceObject(ObjectReference object, boolean root) {
081    if (!root) VM.assertions.fail("SanityRootTraceLocal.traceObject called for non-root object.");
082    if (!object.isNull()) {
083      values.push(object);
084    }
085    return object;
086  }
087
088  /**
089   * Will this object move from this point on, during the current trace ?
090   *
091   * @param object The object to query.
092   * @return {@code true} if the object will not move.
093   */
094  @Override
095  public boolean willNotMoveInCurrentCollection(ObjectReference object) {
096    // We never move objects!
097    return true;
098  }
099}