org.terracotta.offheapstore.paging
Class PhantomReferenceLimitedPageSource

java.lang.Object
  extended by 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.

Author:
Chris Dennis

Constructor Summary
PhantomReferenceLimitedPageSource(long max)
          Create a source that will allocate at most max bytes.
 
Method Summary
 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.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2016. All rights reserved.