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.generational.marksweep;
014    
015    import org.mmtk.plan.generational.Gen;
016    import org.mmtk.plan.Trace;
017    import org.mmtk.plan.TransitiveClosure;
018    import org.mmtk.policy.MarkSweepSpace;
019    import org.mmtk.policy.Space;
020    import org.mmtk.utility.heap.VMRequest;
021    
022    import org.vmmagic.pragma.*;
023    import org.vmmagic.unboxed.*;
024    
025    /**
026     * This class implements the functionality of a two-generation copying
027     * collector where <b>the higher generation is a mark-sweep space</b>
028     * (free list allocation, mark-sweep collection).  Nursery collections
029     * occur when either the heap is full or the nursery is full.  The
030     * nursery size is determined by an optional command line argument.
031     * If undefined, the nursery size is "infinite", so nursery
032     * collections only occur when the heap is full (this is known as a
033     * flexible-sized nursery collector).  Thus both fixed and flexible
034     * nursery sizes are supported.  Full heap collections occur when the
035     * nursery size has dropped to a statically defined threshold,
036     * <code>NURSERY_THRESHOLD</code><p>
037     *
038     * See the Jones & Lins GC book, chapter 7 for a detailed discussion
039     * of generational collection and section 7.3 for an overview of the
040     * flexible nursery behavior ("The Standard ML of New Jersey
041     * collector"), or go to Appel's paper "Simple generational garbage
042     * collection and fast allocation." SP&E 19(2):171--183, 1989.<p>
043     *
044     *
045     * For general comments about the global/local distinction among classes refer
046     * to Plan.java and PlanLocal.java.
047     */
048    @Uninterruptible
049    public class GenMS extends Gen {
050    
051      /*****************************************************************************
052       *
053       * Class fields
054       */
055    
056      /** The mature space, which for GenMS uses a mark sweep collection policy. */
057      public static final MarkSweepSpace msSpace = new MarkSweepSpace("ms", DEFAULT_POLL_FREQUENCY, VMRequest.create());
058    
059      public static final int MS = msSpace.getDescriptor();
060    
061      /****************************************************************************
062       *
063       * Instance fields
064       */
065    
066      /* The trace class for a full-heap collection */
067      public final Trace matureTrace = new Trace(metaDataSpace);
068    
069      /*****************************************************************************
070       *
071       * Collection
072       */
073    
074      /**
075       * Perform a (global) collection phase.
076       */
077      @Inline
078      @Override
079      public final void collectionPhase(short phaseId) {
080        if (traceFullHeap()) {
081          if (phaseId == PREPARE) {
082            super.collectionPhase(phaseId);
083            matureTrace.prepare();
084            msSpace.prepare(true);
085            return;
086          }
087    
088          if (phaseId == CLOSURE) {
089            matureTrace.prepare();
090            return;
091          }
092          if (phaseId == RELEASE) {
093            matureTrace.release();
094            msSpace.release();
095            super.collectionPhase(phaseId);
096            return;
097          }
098        }
099        super.collectionPhase(phaseId);
100      }
101    
102      /*****************************************************************************
103       *
104       * Accounting
105       */
106    
107      /**
108       * Return the number of pages reserved for use given the pending
109       * allocation.
110       *
111       * @return The number of pages reserved given the pending
112       * allocation, excluding space reserved for copying.
113       */
114      @Inline
115      @Override
116      public int getPagesUsed() {
117        return msSpace.reservedPages() + super.getPagesUsed();
118      }
119    
120      /**
121       * Calculate the number of pages a collection is required to free to satisfy
122       * outstanding allocation requests.
123       *
124       * @return the number of pages a collection is required to free to satisfy
125       * outstanding allocation requests.
126       */
127      public int getPagesRequired() {
128        return super.getPagesRequired() + msSpace.requiredPages();
129      }
130    
131      /**
132       * Return the number of pages available for allocation into the mature
133       * space.
134       *
135       * @return The number of pages available for allocation into the mature
136       * space.
137       */
138      public int getMaturePhysicalPagesAvail() {
139        return (int) (msSpace.availablePhysicalPages()/MarkSweepSpace.WORST_CASE_FRAGMENTATION);
140      }
141    
142      /*****************************************************************************
143       *
144       * Miscellaneous
145       */
146    
147      /**
148       * Accessor method to allow the generic generational code in Gen.java
149       * to access the mature space.
150       *
151       * @return The active mature space
152       */
153      @Inline
154      protected final Space activeMatureSpace() {
155        return msSpace;
156      }
157    
158      /**
159       * @see org.mmtk.plan.Plan#willNeverMove
160       *
161       * @param object Object in question
162       * @return True if the object will never move
163       */
164      @Override
165      public boolean willNeverMove(ObjectReference object) {
166        if (Space.isInSpace(MS, object))
167          return true;
168        return super.willNeverMove(object);
169      }
170    
171      /**
172       * Register specialized methods.
173       */
174      @Interruptible
175      protected void registerSpecializedMethods() {
176        TransitiveClosure.registerSpecializedScan(SCAN_MATURE, GenMSMatureTraceLocal.class);
177        super.registerSpecializedMethods();
178      }
179    }