Class PhantomReferenceLimitedPageSource

java.lang.Object
org.terracotta.offheapstore.paging.PhantomReferenceLimitedPageSource
All Implemented Interfaces:
PageSource

public class PhantomReferenceLimitedPageSource extends 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 Details

  • Constructor Details

    • 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 Details

    • 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 String toString()
      Overrides:
      toString in class Object