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.poisoned;
014    
015    import org.mmtk.plan.marksweep.MS;
016    
017    import org.vmmagic.pragma.*;
018    import org.vmmagic.unboxed.Address;
019    import org.vmmagic.unboxed.ObjectReference;
020    import org.vmmagic.unboxed.Word;
021    
022    /**
023     * This class implements a poisoned collector, that is essentially a test
024     * case for read and write barriers in the VM.
025     */
026    @Uninterruptible
027    public class Poisoned extends MS {
028    
029      @Override
030      public Word bootTimeWriteBarrier(Word reference) {
031        return reference.or(Word.one());
032      }
033    
034      /**
035       * Poison a reference value.
036       */
037      @Inline
038      public static Word poison(ObjectReference reference) {
039        return reference.toAddress().toWord().or(Word.one());
040      }
041    
042      /**
043       * DePoison a reference value.
044       */
045      @Inline
046      public static ObjectReference depoison(Word value) {
047        return value.and(Word.one().not()).toAddress().toObjectReference();
048      }
049    
050      /****************************************************************************
051       * Internal read/write barriers.
052       */
053    
054      /**
055       * {@inheritDoc}
056       */
057      @Override
058      @Inline
059      public void storeObjectReference(Address slot, ObjectReference value) {
060        slot.store(poison(value));
061      }
062    
063      @Override
064      @Inline
065      public ObjectReference loadObjectReference(Address slot) {
066        return depoison(slot.loadWord());
067      }
068    }