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;
016
017import org.vmmagic.unboxed.*;
018import org.vmmagic.pragma.*;
019
020/**
021 * This supports <i>unsynchronized</i> enqueuing and dequeuing of addresses
022 */
023@Uninterruptible public class AddressDeque extends LocalDeque {
024
025  /****************************************************************************
026   *
027   * Public instance methods
028   */
029
030  /**
031   *
032   */
033  public final String name;
034
035  /**
036   * Constructor
037   *
038   * @param n the human-readable name of this queue
039   * @param queue The shared queue to which this queue will append
040   * its buffers (when full or flushed) and from which it will aquire new
041   * buffers when it has exhausted its own.
042   */
043  public AddressDeque(String n, SharedDeque queue) {
044    super(queue);
045    name = n;
046  }
047
048  /**
049   * Insert an address into the address queue.
050   *
051   * @param addr the address to be inserted into the address queue
052   */
053  @Inline
054  public final void insert(Address addr) {
055    if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr.isZero());
056    checkTailInsert(1);
057    uncheckedTailInsert(addr);
058  }
059
060  /**
061   * Insert an address into the address queue, force this out of line
062   * ("OOL"), in some circumstances it is too expensive to have the
063   * insert inlined, so this call is made.
064   *
065   * @param addr the address to be inserted into the address queue
066   */
067  @NoInline
068  public final void insertOOL(Address addr) {
069    insert(addr);
070  }
071
072  /**
073   * Push an address onto the address queue.
074   *
075   * @param addr the address to be pushed onto the address queue
076   */
077  @Inline
078  public final void push(Address addr) {
079    if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr.isZero());
080    checkHeadInsert(1);
081    uncheckedHeadInsert(addr);
082  }
083
084  /**
085   * Push an address onto the address queue, force this out of line
086   * ("OOL"), in some circumstances it is too expensive to have the
087   * push inlined, so this call is made.
088   *
089   * @param addr the address to be pushed onto the address queue
090   */
091  @NoInline
092  public final void pushOOL(Address addr) {
093    push(addr);
094  }
095
096  /**
097   * Pop an address from the address queue, return zero if the queue
098   * is empty.
099   *
100   * @return The next address in the address queue, or zero if the
101   * queue is empty
102   */
103  @Inline
104  public final Address pop() {
105    if (checkDequeue(1)) {
106      return uncheckedDequeue();
107    } else {
108      return Address.zero();
109    }
110  }
111
112  @Inline
113  public final boolean isEmpty() {
114    return !checkDequeue(1);
115  }
116
117  @Inline
118  public final boolean isNonEmpty() {
119    return checkDequeue(1);
120  }
121
122}