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.plan;
014
015import org.mmtk.utility.Log;
016import org.mmtk.utility.options.Options;
017import org.vmmagic.pragma.*;
018
019/**
020 * This abstract class implements the core functionality for
021 * stop-the-world collectors.  Stop-the-world collectors should
022 * inherit from this class.<p>
023 *
024 * This class defines the collection phases, and provides base
025 * level implementations of them.  Subclasses should provide
026 * implementations for the spaces that they introduce, and
027 * delegate up the class hierarchy.<p>
028 *
029 * For details of the split between global and thread-local operations
030 * @see org.mmtk.plan.Plan
031 */
032@Uninterruptible
033public abstract class StopTheWorld extends Simple {
034
035  // CHECKSTYLE:OFF
036
037  /** Build and validate a sanity table */
038  protected static final short preSanityPhase = Phase.createComplex("pre-sanity", null,
039      Phase.scheduleGlobal     (SANITY_SET_PREGC),
040      Phase.scheduleComplex    (sanityBuildPhase),
041      Phase.scheduleComplex    (sanityCheckPhase));
042
043  /** Build and validate a sanity table */
044  protected static final short postSanityPhase = Phase.createComplex("post-sanity", null,
045      Phase.scheduleGlobal     (SANITY_SET_POSTGC),
046      Phase.scheduleComplex    (sanityBuildPhase),
047      Phase.scheduleComplex    (sanityCheckPhase));
048
049  // CHECKSTYLE:ON
050
051  /****************************************************************************
052   * Collection
053   */
054
055  /**
056   * {@inheritDoc}
057   */
058  @Override
059  @Interruptible
060  public void processOptions() {
061    super.processOptions();
062
063    if (Options.sanityCheck.getValue()) {
064      Log.writeln("Collection sanity checking enabled.");
065      replacePhase(Phase.schedulePlaceholder(PRE_SANITY_PLACEHOLDER),  Phase.scheduleComplex(preSanityPhase));
066      replacePhase(Phase.schedulePlaceholder(POST_SANITY_PLACEHOLDER), Phase.scheduleComplex(postSanityPhase));
067    }
068  }
069}