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