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 * object references
025 */
026 @Uninterruptible public class ObjectReferenceDeque extends LocalDeque
027 implements Constants {
028
029 /****************************************************************************
030 *
031 * Public instance methods
032 */
033 public final String name;
034
035 /**
036 * Constructor
037 *
038 * @param queue The shared queue to which this queue will append
039 * its buffers (when full or flushed) and from which it will aquire 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 circumstnaces 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 }