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.Uninterruptible;
021
022
023 /**
024 * This supports <i>unsynchronized</i> enqueuing and dequeuing of
025 * address triples
026 */
027 @Uninterruptible public class AddressTripleDeque extends LocalDeque implements Constants {
028
029 /****************************************************************************
030 *
031 * Public instance methods
032 */
033
034 /**
035 * Constructor
036 *
037 * @param queue The shared queue to which this queue will append its
038 * buffers (when full or flushed) and from which it will acquire new
039 * buffers when it has exhausted its own.
040 */
041 AddressTripleDeque(SharedDeque queue) {
042 super(queue);
043 }
044
045 /**
046 * Insert an address triple into the address queue.
047 *
048 * @param addr1 the first address to be inserted into the address queue
049 * @param addr2 the second address to be inserted into the address queue
050 * @param addr3 the third address to be inserted into the address queue
051 */
052 public final void insert(Address addr1, Address addr2,
053 Address addr3) {
054 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr1.isZero());
055 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr2.isZero());
056 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr3.isZero());
057 checkTailInsert(3);
058 uncheckedTailInsert(addr1);
059 uncheckedTailInsert(addr2);
060 uncheckedTailInsert(addr3);
061 }
062 /**
063 * Push an address pair onto the address queue.
064 *
065 * @param addr1 the first value to be pushed onto the address queue
066 * @param addr2 the second value to be pushed onto the address queue
067 * @param addr3 the third address to be pushed onto the address queue
068 */
069 public final void push(Address addr1, Address addr2, Address addr3) {
070 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr1.isZero());
071 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr2.isZero());
072 if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(!addr3.isZero());
073 checkHeadInsert(3);
074 uncheckedHeadInsert(addr3);
075 uncheckedHeadInsert(addr2);
076 uncheckedHeadInsert(addr1);
077 }
078
079 /**
080 * Pop the first address in a triple from the address queue, return
081 * zero if the queue is empty.
082 *
083 * @return The next address in the address queue, or zero if the
084 * queue is empty
085 */
086 public final Address pop1() {
087 if (checkDequeue(3))
088 return uncheckedDequeue();
089 else
090 return Address.zero();
091 }
092
093 /**
094 * Pop the second address in a triple from the address queue.
095 *
096 * @return The next address in the address queue
097 */
098 public final Address pop2() {
099 return uncheckedDequeue();
100 }
101
102
103 /**
104 * Pop the third address in a triple from the address queue.
105 *
106 * @return The next address in the address queue
107 */
108 public final Address pop3() {
109 return uncheckedDequeue();
110 }
111 }