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> pushing and popping of object
024 * references. In addition, this can sort the entries currently on
025 * the shared stack.
026 */
027 @Uninterruptible public class SortTODObjectReferenceStack extends LocalDeque
028 implements Constants {
029
030 /****************************************************************************
031 *
032 * Public instance methods
033 */
034
035 /**
036 * Constructor
037 *
038 * @param queue The shared stack to which this stack 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 SortTODObjectReferenceStack(SortTODSharedDeque queue) {
043 super(queue);
044 }
045
046 /**
047 * Sort the address on the shared stack.
048 */
049 public final void sort() {
050 flushLocal();
051 ((SortTODSharedDeque) queue).sort();
052 }
053
054 /**
055 * Push an address onto the address stack.
056 *
057 * @param object the object to be pushed onto the object queue
058 */
059 @Inline
060 public final void push(ObjectReference object) {
061 Address addr = object.toAddress();
062 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr.isZero());
063 checkHeadInsert(1);
064 uncheckedHeadInsert(addr);
065 }
066
067 /**
068 * Pop an address from the address stack, return zero if the stack
069 * is empty.
070 *
071 * @return The next address in the address stack, or zero if the
072 * stack is empty
073 */
074 @Inline
075 public final ObjectReference pop() {
076 if (checkDequeue(1)) {
077 return uncheckedDequeue().toObjectReference();
078 } else {
079 return ObjectReference.nullReference();
080 }
081 }
082
083 /**
084 * Check if the (local and shared) stacks are empty.
085 *
086 * @return True if there are no more entries on the local & shared stack,
087 * false otherwise.
088 */
089 @Inline
090 public final boolean isEmpty() {
091 return !checkDequeue(1);
092 }
093 }