Class ByteBufferGuard

java.lang.Object
org.apache.lucene.store.ByteBufferGuard

final class ByteBufferGuard extends Object
A guard that is created for every ByteBufferIndexInput that tries on best effort to reject any access to the ByteBuffer behind, once it is unmapped. A single instance of this is used for the original and all clones, so once the original is closed and unmapped all clones also throw AlreadyClosedException, triggered by a NullPointerException.

This code tries to hopefully flush any CPU caches using a store-store barrier. It also yields the current thread to give other threads a chance to finish in-flight requests...

  • Field Details

    • resourceDescription

      private final String resourceDescription
    • cleaner

      private final ByteBufferGuard.BufferCleaner cleaner
    • invalidated

      private boolean invalidated
      Not volatile; see comments on visibility below!
    • barrier

      private final AtomicInteger barrier
      Used as a store-store barrier; see comments below!
  • Constructor Details

  • Method Details

    • invalidateAndUnmap

      public void invalidateAndUnmap(ByteBuffer... bufs) throws IOException
      Invalidates this guard and unmaps (if supported).
      Throws:
      IOException
    • ensureValid

      private void ensureValid()
    • getBytes

      public void getBytes(ByteBuffer receiver, byte[] dst, int offset, int length)
    • getByte

      public byte getByte(ByteBuffer receiver)
    • getShort

      public short getShort(ByteBuffer receiver)
    • getInt

      public int getInt(ByteBuffer receiver)
    • getLong

      public long getLong(ByteBuffer receiver)
    • getByte

      public byte getByte(ByteBuffer receiver, int pos)
    • getShort

      public short getShort(ByteBuffer receiver, int pos)
    • getInt

      public int getInt(ByteBuffer receiver, int pos)
    • getLong

      public long getLong(ByteBuffer receiver, int pos)
    • getLongs

      public void getLongs(LongBuffer receiver, long[] dst, int offset, int length)
    • getInts

      public void getInts(IntBuffer receiver, int[] dst, int offset, int length)
    • getFloats

      public void getFloats(FloatBuffer receiver, float[] dst, int offset, int length)