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.Plan;
016import org.mmtk.plan.Simple;
017
018import org.mmtk.vm.VM;
019
020import org.vmmagic.pragma.*;
021
022/**
023 * This class performs sanity checks for Simple collectors.
024 */
025@Uninterruptible
026public final class SanityCheckerLocal {
027
028  /** Trace */
029  final SanityRootTraceLocal rootTraceLocal;
030
031  /****************************************************************************
032   * Constants
033   */
034  public SanityCheckerLocal() {
035    rootTraceLocal = new SanityRootTraceLocal(Plan.sanityChecker.rootTrace);
036  }
037
038  /**
039   * Perform any sanity checking collection phases.
040   *
041   * @param phaseId The id to process
042   * @param primary Perform local single threaded actions on this thread
043   * @return True if the phase was handled.
044   */
045  @NoInline
046  public boolean collectionPhase(int phaseId, boolean primary) {
047    if (phaseId == Simple.SANITY_PREPARE) {
048      rootTraceLocal.prepare();
049      return true;
050    }
051
052    if (phaseId == Simple.SANITY_ROOTS) {
053      VM.scanning.computeGlobalRoots(rootTraceLocal);
054      VM.scanning.computeThreadRoots(rootTraceLocal);
055      VM.scanning.computeStaticRoots(rootTraceLocal);
056      if (Plan.SCAN_BOOT_IMAGE) {
057        VM.scanning.computeBootImageRoots(rootTraceLocal);
058      }
059      rootTraceLocal.flush();
060      return true;
061    }
062
063    if (phaseId == Simple.SANITY_COPY_ROOTS) {
064      if (primary) {
065        rootTraceLocal.copyRootValuesTo(Plan.sanityChecker.checkTraceLocal);
066      }
067      return true;
068    }
069
070    if (phaseId == Simple.SANITY_RELEASE) {
071      rootTraceLocal.release();
072      return true;
073    }
074
075    return false;
076  }
077}