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.MS; 016 017import org.vmmagic.pragma.*; 018import org.vmmagic.unboxed.Address; 019import org.vmmagic.unboxed.ObjectReference; 020import 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 027public class Poisoned extends MS { 028 029 @Override 030 public Word bootTimeWriteBarrier(Word reference) { 031 return reference.or(Word.one()); 032 } 033 034 /** 035 * Poisons a reference value. 036 * 037 * @param reference the reference to poison 038 * @return the poisoned value 039 */ 040 @Inline 041 public static Word poison(ObjectReference reference) { 042 return reference.toAddress().toWord().or(Word.one()); 043 } 044 045 /** 046 * DePoisons a reference value. 047 * 048 * @param value the reference to dePoison 049 * @return the dePoisoned value 050 */ 051 @Inline 052 public static ObjectReference depoison(Word value) { 053 return value.and(Word.one().not()).toAddress().toObjectReference(); 054 } 055 056 /**************************************************************************** 057 * Internal read/write barriers. 058 */ 059 060 /** 061 * {@inheritDoc} 062 */ 063 @Override 064 @Inline 065 public void storeObjectReference(Address slot, ObjectReference value) { 066 slot.store(poison(value)); 067 } 068 069 @Override 070 @Inline 071 public ObjectReference loadObjectReference(Address slot) { 072 return depoison(slot.loadWord()); 073 } 074}