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.plan;
014
015import org.mmtk.utility.deque.WriteBuffer;
016import org.vmmagic.pragma.*;
017import org.vmmagic.unboxed.*;
018
019/**
020 * This class is used to push values in one direction during a trace. It
021 * was designed for use in mutators that use write barriers to push
022 * work to collector threads during concurrent tracing.
023 *
024 * @see org.mmtk.plan.TraceLocal
025 */
026@Uninterruptible
027public final class TraceWriteBuffer extends TransitiveClosure {
028  /****************************************************************************
029   *
030   * Instance variables
031   */
032
033  /**
034   *
035   */
036  private final WriteBuffer buffer;
037
038  /****************************************************************************
039   *
040   * Initialization
041   */
042
043  /**
044   * Constructor
045   *
046   * @param trace The global trace class to use.
047   */
048  public TraceWriteBuffer(Trace trace) {
049    buffer = new WriteBuffer(trace.valuePool);
050  }
051
052  /**
053   * Flush the buffer to the trace.
054   */
055  public void flush() {
056    buffer.flushLocal();
057  }
058
059
060  /**
061   * @return <code>true</code> if the buffer is flushed.
062   */
063  public boolean isFlushed() {
064    return buffer.isFlushed();
065  }
066
067  /**
068   * Enqueue an object during a trace.
069   *
070   * @param object The object to enqueue
071   */
072  @Override
073  @Inline
074  public void processNode(ObjectReference object) {
075    buffer.insert(object.toAddress());
076  }
077}