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.utility.deque; 014 015import org.mmtk.vm.VM; 016import org.vmmagic.pragma.Uninterruptible; 017import org.vmmagic.unboxed.Address; 018 019/** 020 * This supports <i>unsynchronized</i> enqueuing and dequeuing of 021 * address pairs 022 */ 023@Uninterruptible public class AddressPairDeque extends LocalDeque { 024 025 /**************************************************************************** 026 * 027 * Public instance methods 028 */ 029 030 /** 031 * Constructor 032 * 033 * @param queue The shared queue to which this queue will append 034 * its buffers (when full or flushed) and from which it will acquire new 035 * buffers when it has exhausted its own. 036 */ 037 public AddressPairDeque(SharedDeque queue) { 038 super(queue); 039 } 040 041 /** 042 * Insert an address pair into the address queue. 043 * 044 * @param addr1 the first address to be inserted into the address queue 045 * @param addr2 the second address to be inserted into the address queue 046 */ 047 public final void insert(Address addr1, Address addr2) { 048 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr1.isZero()); 049 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr2.isZero()); 050 checkTailInsert(2); 051 uncheckedTailInsert(addr1); 052 uncheckedTailInsert(addr2); 053 } 054 055 /** 056 * Push an address pair onto the address queue. 057 * 058 * @param addr1 the first value to be pushed onto the address queue 059 * @param addr2 the second value to be pushed onto the address queue 060 */ 061 public final void push(Address addr1, Address addr2) { 062 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr1.isZero()); 063 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr2.isZero()); 064 checkHeadInsert(2); 065 uncheckedHeadInsert(addr2); 066 uncheckedHeadInsert(addr1); 067 } 068 069 /** 070 * Pop the first address in a pair from the address queue, return 071 * zero if the queue is empty. 072 * 073 * @return The next address in the address queue, or zero if the 074 * queue is empty 075 */ 076 public final Address pop1() { 077 if (checkDequeue(2)) 078 return uncheckedDequeue(); 079 else 080 return Address.zero(); 081 } 082 083 /** 084 * Pop the second address in a pair from the address queue. 085 * 086 * @return The next address in the address queue 087 */ 088 public final Address pop2() { 089 return uncheckedDequeue(); 090 } 091 092 public final boolean isEmpty() { 093 return !checkDequeue(2); 094 } 095}