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.nogc;
014    
015    import org.mmtk.plan.MutatorContext;
016    import org.mmtk.policy.ImmortalLocal;
017    import org.mmtk.policy.Space;
018    import org.mmtk.utility.alloc.Allocator;
019    import org.mmtk.vm.VM;
020    
021    import org.vmmagic.pragma.*;
022    import 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
040    public class NoGCMutator extends MutatorContext {
041    
042      /************************************************************************
043       * Instance fields
044       */
045      private final ImmortalLocal nogc = new ImmortalLocal(NoGC.noGCSpace);
046    
047    
048      /****************************************************************************
049       * Mutator-time allocation
050       */
051    
052      /**
053       * Allocate memory for an object.
054       *
055       * @param bytes The number of bytes required for the object.
056       * @param align Required alignment for the object.
057       * @param offset Offset associated with the alignment.
058       * @param allocator The allocator associated with this request.
059       * @param site Allocation site
060       * @return The address of the newly allocated memory.
061       */
062      @Inline
063      @Override
064      public Address alloc(int bytes, int align, int offset, int allocator, int site) {
065        if (allocator == NoGC.ALLOC_DEFAULT) {
066          return nogc.alloc(bytes, align, offset);
067        }
068        return super.alloc(bytes, align, offset, allocator, site);
069      }
070    
071      /**
072       * Perform post-allocation actions.  For many allocators none are
073       * required.
074       *
075       * @param ref The newly allocated object
076       * @param typeRef the type reference for the instance being created
077       * @param bytes The size of the space to be allocated (in bytes)
078       * @param allocator The allocator number to be used for this allocation
079       */
080      @Inline
081      @Override
082      public void postAlloc(ObjectReference ref, ObjectReference typeRef,
083          int bytes, int allocator) {
084        if (allocator != NoGC.ALLOC_DEFAULT) {
085          super.postAlloc(ref, typeRef, bytes, allocator);
086        }
087      }
088    
089      /**
090       * Return the allocator instance associated with a space
091       * <code>space</code>, for this plan instance.
092       *
093       * @param space The space for which the allocator instance is desired.
094       * @return The allocator instance associated with this plan instance
095       * which is allocating into <code>space</code>, or <code>null</code>
096       * if no appropriate allocator can be established.
097       */
098      @Override
099      public Allocator getAllocatorFromSpace(Space space) {
100        if (space == NoGC.noGCSpace) return nogc;
101        return super.getAllocatorFromSpace(space);
102      }
103    
104    
105      /****************************************************************************
106       * Collection
107       */
108    
109      /**
110       * Perform a per-mutator collection phase.
111       *
112       * @param phaseId The collection phase to perform
113       * @param primary perform any single-threaded local activities.
114       */
115      @Inline
116      @Override
117      public final void collectionPhase(short phaseId, boolean primary) {
118        VM.assertions.fail("GC Triggered in NoGC Plan.");
119        /*
120         if (phaseId == NoGC.PREPARE) {
121         }
122    
123         if (phaseId == NoGC.RELEASE) {
124         }
125         super.collectionPhase(phaseId, primary);
126         */
127      }
128    }