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