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.marksweep; 014 015 import org.mmtk.plan.*; 016 import org.mmtk.policy.MarkSweepLocal; 017 import org.mmtk.policy.Space; 018 import org.mmtk.utility.alloc.Allocator; 019 020 import org.vmmagic.pragma.*; 021 import org.vmmagic.unboxed.*; 022 023 /** 024 * This class implements <i>per-mutator thread</i> behavior 025 * and state for the <i>MS</i> plan, which implements a full-heap 026 * mark-sweep collector.<p> 027 * 028 * Specifically, this class defines <i>MS</i> mutator-time allocation 029 * and per-mutator thread collection semantics (flushing and restoring 030 * per-mutator allocator state).<p> 031 * 032 * @see MS 033 * @see MSCollector 034 * @see StopTheWorldMutator 035 * @see MutatorContext 036 */ 037 @Uninterruptible 038 public class MSMutator extends StopTheWorldMutator { 039 040 /**************************************************************************** 041 * Instance fields 042 */ 043 044 /** 045 * 046 */ 047 protected MarkSweepLocal ms = new MarkSweepLocal(MS.msSpace); 048 049 050 /**************************************************************************** 051 * Mutator-time allocation 052 */ 053 054 /** 055 * {@inheritDoc}<p> 056 * 057 * This class handles the default allocator from the mark sweep space, 058 * and delegates everything else to the superclass. 059 */ 060 @Inline 061 @Override 062 public Address alloc(int bytes, int align, int offset, int allocator, int site) { 063 if (allocator == MS.ALLOC_DEFAULT) { 064 return ms.alloc(bytes, align, offset); 065 } 066 return super.alloc(bytes, align, offset, allocator, site); 067 } 068 069 /** 070 * {@inheritDoc}<p> 071 * 072 * Initialize the object header for objects in the mark-sweep space, 073 * and delegate to the superclass for other objects. 074 */ 075 @Inline 076 @Override 077 public void postAlloc(ObjectReference ref, ObjectReference typeRef, 078 int bytes, int allocator) { 079 if (allocator == MS.ALLOC_DEFAULT) 080 MS.msSpace.postAlloc(ref); 081 else 082 super.postAlloc(ref, typeRef, bytes, allocator); 083 } 084 085 @Override 086 public Allocator getAllocatorFromSpace(Space space) { 087 if (space == MS.msSpace) return ms; 088 return super.getAllocatorFromSpace(space); 089 } 090 091 092 /**************************************************************************** 093 * Collection 094 */ 095 096 /** 097 * {@inheritDoc} 098 */ 099 @Inline 100 @Override 101 public void collectionPhase(short phaseId, boolean primary) { 102 if (phaseId == MS.PREPARE) { 103 super.collectionPhase(phaseId, primary); 104 ms.prepare(); 105 return; 106 } 107 108 if (phaseId == MS.RELEASE) { 109 ms.release(); 110 super.collectionPhase(phaseId, primary); 111 return; 112 } 113 114 super.collectionPhase(phaseId, primary); 115 } 116 117 @Override 118 public void flush() { 119 super.flush(); 120 ms.flush(); 121 } 122 }