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.nogc;
014
015import org.mmtk.plan.MutatorContext;
016import org.mmtk.policy.ImmortalLocal;
017import org.mmtk.policy.Space;
018import org.mmtk.utility.alloc.Allocator;
019import org.mmtk.vm.VM;
020
021import org.vmmagic.pragma.*;
022import org.vmmagic.unboxed.*;
023
024/**
025 * This class implements <i>per-mutator thread</i> behavior and state
026 * for the <i>NoGC</i> plan, which simply allocates (without ever collecting
027 * until the available space is exhausted.<p>
028 *
029 * Specifically, this class defines <i>NoGC</i> mutator-time allocation
030 * through a bump pointer (<code>def</code>) and includes stubs for
031 * per-mutator thread collection semantics (since there is no collection
032 * in this plan, these remain just stubs).
033 *
034 * @see NoGC
035 * @see NoGCCollector
036 * @see org.mmtk.plan.StopTheWorldMutator
037 * @see org.mmtk.plan.MutatorContext
038 */
039@Uninterruptible
040public class NoGCMutator extends MutatorContext {
041
042  /************************************************************************
043   * Instance fields
044   */
045
046  /**
047   *
048   */
049  private final ImmortalLocal nogc = new ImmortalLocal(NoGC.noGCSpace);
050
051
052  /****************************************************************************
053   * Mutator-time allocation
054   */
055
056  /**
057   * {@inheritDoc}
058   */
059  @Inline
060  @Override
061  public Address alloc(int bytes, int align, int offset, int allocator, int site) {
062    if (allocator == NoGC.ALLOC_DEFAULT) {
063      return nogc.alloc(bytes, align, offset);
064    }
065    return super.alloc(bytes, align, offset, allocator, site);
066  }
067
068  @Inline
069  @Override
070  public void postAlloc(ObjectReference ref, ObjectReference typeRef,
071      int bytes, int allocator) {
072    if (allocator != NoGC.ALLOC_DEFAULT) {
073      super.postAlloc(ref, typeRef, bytes, allocator);
074    }
075  }
076
077  @Override
078  public Allocator getAllocatorFromSpace(Space space) {
079    if (space == NoGC.noGCSpace) return nogc;
080    return super.getAllocatorFromSpace(space);
081  }
082
083
084  /****************************************************************************
085   * Collection
086   */
087
088  /**
089   * {@inheritDoc}
090   */
091  @Inline
092  @Override
093  public final void collectionPhase(short phaseId, boolean primary) {
094    VM.assertions.fail("GC Triggered in NoGC Plan.");
095    /*
096     if (phaseId == NoGC.PREPARE) {
097     }
098
099     if (phaseId == NoGC.RELEASE) {
100     }
101     super.collectionPhase(phaseId, primary);
102     */
103  }
104}