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