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.poisoned;
014
015import org.mmtk.plan.marksweep.MSMutator;
016import org.mmtk.vm.VM;
017
018import org.vmmagic.pragma.*;
019import org.vmmagic.unboxed.Address;
020import org.vmmagic.unboxed.ObjectReference;
021import org.vmmagic.unboxed.Word;
022
023/**
024 * This class implements a poisoned collector, that is essentially a test
025 * case for read and write barriers in the VM.
026 */
027@Uninterruptible
028public class PoisonedMutator extends MSMutator {
029
030  /****************************************************************************
031   *
032   * Write and read barriers. By default do nothing, override if
033   * appropriate.
034   */
035
036  /**
037   * {@inheritDoc}
038   */
039  @Inline
040  @Override
041  public void objectReferenceWrite(ObjectReference src, Address slot, ObjectReference tgt, Word metaDataA, Word metaDataB, int mode) {
042    VM.barriers.wordWrite(src, Poisoned.poison(tgt), metaDataA, metaDataB, mode);
043  }
044
045  @Override
046  public boolean objectReferenceTryCompareAndSwap(ObjectReference src, Address slot, ObjectReference old, ObjectReference tgt,
047                                               Word metaDataA, Word metaDataB, int mode) {
048    return VM.barriers.wordTryCompareAndSwap(src, Poisoned.poison(old), Poisoned.poison(tgt), metaDataA, metaDataB, mode);
049  }
050
051  @Inline
052  @Override
053  public ObjectReference objectReferenceRead(ObjectReference src, Address slot, Word metaDataA, Word metaDataB, int mode) {
054    return Poisoned.depoison(VM.barriers.wordRead(src, metaDataA, metaDataB, mode));
055  }
056}