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