Class PhantomReferenceLimitedPageSource

  • All Implemented Interfaces:
    PageSource

    public class PhantomReferenceLimitedPageSource
    extends java.lang.Object
    implements PageSource
    A PhantomReference based limited byte buffer source.

    This buffer source tracks 'freeing' of allocated byte buffers using phantom references to the allocated buffers and an associated reference queue. An AtomicLong is then used to track number of available bytes for allocation.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ref.ReferenceQueue<java.nio.ByteBuffer> allocatedBuffers  
      private java.util.Map<java.lang.ref.PhantomReference<java.nio.ByteBuffer>,​java.lang.Integer> bufferSizes  
      private java.util.concurrent.atomic.AtomicLong max  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Page allocate​(int size, boolean thief, boolean victim, OffHeapStorageArea owner)
      Allocates a byte buffer of the given size.
      void free​(Page buffer)
      Frees the supplied buffer.
      private void processQueue()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • allocatedBuffers

        private final java.lang.ref.ReferenceQueue<java.nio.ByteBuffer> allocatedBuffers
      • bufferSizes

        private final java.util.Map<java.lang.ref.PhantomReference<java.nio.ByteBuffer>,​java.lang.Integer> bufferSizes
      • max

        private final java.util.concurrent.atomic.AtomicLong max
    • Constructor Detail

      • PhantomReferenceLimitedPageSource

        public PhantomReferenceLimitedPageSource​(long max)
        Create a source that will allocate at most max bytes.
        Parameters:
        max - the maximum total size of all available buffers
    • Method Detail

      • allocate

        public Page allocate​(int size,
                             boolean thief,
                             boolean victim,
                             OffHeapStorageArea owner)
        Allocates a byte buffer of the given size.

        This BufferSource places no restrictions on the requested size of the buffer.

        Specified by:
        allocate in interface PageSource
        Parameters:
        size - size of page to allocate
        thief - true if the allocation can steal space from victims
        victim - true if the allocated page should be eligible for stealing
        owner - owner from which subsequent steal should occur
        Returns:
        an allocated page, or null in the case of failure
      • free

        public void free​(Page buffer)
        Frees the supplied buffer.

        This implementation is a no-op, no validation of the supplied buffer is attempted, as freeing of allocated buffers is monitored via phantom references.

        Specified by:
        free in interface PageSource
      • processQueue

        private void processQueue()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object