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