/* * This file is part of the Jikes RVM project (http://jikesrvm.org). * * This file is licensed to You under the Eclipse Public License (EPL); * You may not use this file except in compliance with the License. You * may obtain a copy of the License at * * http://www.opensource.org/licenses/eclipse-1.0.php * * See the COPYRIGHT.txt file distributed with this work for information * regarding copyright ownership. */ package org.mmtk.plan.poisoned; import org.mmtk.plan.marksweep.MSMutator; import org.mmtk.vm.VM; import org.vmmagic.pragma.*; import org.vmmagic.unboxed.Address; import org.vmmagic.unboxed.ObjectReference; import org.vmmagic.unboxed.Word; /** * This class implements a poisoned collector, that is essentially a test * case for read and write barriers in the VM. */ @Uninterruptible public class PoisonedMutator extends MSMutator { /**************************************************************************** * * Write and read barriers. By default do nothing, override if * appropriate. */ /** * A new reference is about to be created. Take appropriate write * barrier actions.<p> * * <b>By default do nothing, override if appropriate.</b> * * @param src The object into which the new reference will be stored * @param slot The address into which the new reference will be * stored. * @param tgt The target of the new reference * @param metaDataA A value that assists the host VM in creating a store * @param metaDataB A value that assists the host VM in creating a store * @param mode The context in which the store occurred */ @Inline @Override public void objectReferenceWrite(ObjectReference src, Address slot, ObjectReference tgt, Word metaDataA, Word metaDataB, int mode) { VM.barriers.wordWrite(src, Poisoned.poison(tgt), metaDataA, metaDataB, mode); } /** * Attempt to atomically exchange the value in the given slot * with the passed replacement value. If a new reference is * created, we must then take appropriate write barrier actions.<p> * * <b>By default do nothing, override if appropriate.</b> * * @param src The object into which the new reference will be stored * @param slot The address into which the new reference will be * stored. * @param old The old reference to be swapped out * @param tgt The target of the new reference * @param metaDataA A value that assists the host VM in creating a store * @param metaDataB A value that assists the host VM in creating a store * @param mode The context in which the store occurred * @return True if the swap was successful. */ @Override public boolean objectReferenceTryCompareAndSwap(ObjectReference src, Address slot, ObjectReference old, ObjectReference tgt, Word metaDataA, Word metaDataB, int mode) { return VM.barriers.wordTryCompareAndSwap(src, Poisoned.poison(old), Poisoned.poison(tgt), metaDataA, metaDataB, mode); } /** * Read a reference. Take appropriate read barrier action, and * return the value that was read.<p> This is a <b>substituting<b> * barrier. The call to this barrier takes the place of a load.<p> * * @param src The object reference holding the field being read. * @param slot The address of the slot being read. * @param metaDataA A value that assists the host VM in creating a load * @param metaDataB A value that assists the host VM in creating a load * @param mode The context in which the load occurred * @return The reference that was read. */ @Inline @Override public ObjectReference objectReferenceRead(ObjectReference src, Address slot, Word metaDataA, Word metaDataB, int mode) { return Poisoned.depoison(VM.barriers.wordRead(src, metaDataA, metaDataB, mode)); } }