Class PowerOfTwoAllocator
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<T>
-
- org.terracotta.offheapstore.util.AATreeSet<Region>
-
- org.terracotta.offheapstore.storage.allocator.PowerOfTwoAllocator
-
- All Implemented Interfaces:
java.lang.Iterable<Region>,java.util.Collection<Region>,java.util.Set<Region>,java.util.SortedSet<Region>
public class PowerOfTwoAllocator extends AATreeSet<Region>
An augmented AA tree allocator with unusual alignment/allocation properties.This allocator allocates only power-of-two size chunks. In addition these chunks are then only allocated on alignment with their own size. Hence a chunk of 2n size can only be allocated to an address satisfying a=2nx where x is an integer.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPowerOfTwoAllocator.Packing-
Nested classes/interfaces inherited from class org.terracotta.offheapstore.util.AATreeSet
AATreeSet.AbstractTreeNode<E extends java.lang.Comparable<? super E>>, AATreeSet.Node<E extends java.lang.Comparable<? super E>>
-
-
Field Summary
Fields Modifier and Type Field Description private static booleanDEBUGprivate intoccupiedThis is volatile because we read it without any locking throughUpfrontAllocatingPageSource.getAllocatedSizeUnSync()private intsizeprivate static booleanVALIDATING
-
Constructor Summary
Constructors Constructor Description PowerOfTwoAllocator(int size)Create a power-of-two allocator with the given initial 'free' size area.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intallocate(int size, PowerOfTwoAllocator.Packing packing)voidclaim(int address, int size)intfind(int size, PowerOfTwoAllocator.Packing packing)Regionfind(java.lang.Object o)private RegionfindRegion(int size, PowerOfTwoAllocator.Packing packing)Find a region of the given size.voidfree(int address, int length)private voidfree(Region r)private voidinsert(Region x)Insert into the tree.intoccupied()RegionremoveAndReturn(java.lang.Object o)java.lang.StringtoString()voidtryFree(int address, int length)private booleantryFree(Region r)private booleantryInsert(Region x)private voidvalidateFreeSpace()-
Methods inherited from class org.terracotta.offheapstore.util.AATreeSet
add, clear, comparator, first, getRoot, headSet, isEmpty, iterator, last, remove, size, subSet, tailSet
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
-
VALIDATING
private static final boolean VALIDATING
-
size
private final int size
-
occupied
private volatile int occupied
This is volatile because we read it without any locking throughUpfrontAllocatingPageSource.getAllocatedSizeUnSync()
-
-
Method Detail
-
allocate
public int allocate(int size, PowerOfTwoAllocator.Packing packing)
-
free
public void free(int address, int length)
-
tryFree
public void tryFree(int address, int length)
-
find
public int find(int size, PowerOfTwoAllocator.Packing packing)
-
claim
public void claim(int address, int size)
-
occupied
public int occupied()
-
removeAndReturn
public Region removeAndReturn(java.lang.Object o)
- Overrides:
removeAndReturnin classAATreeSet<Region>
-
free
private void free(Region r)
-
tryFree
private boolean tryFree(Region r)
-
insert
private void insert(Region x)
Insert into the tree.- Parameters:
x- the item to insert.
-
tryInsert
private boolean tryInsert(Region x)
-
findRegion
private Region findRegion(int size, PowerOfTwoAllocator.Packing packing)
Find a region of the given size.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection<Region>
-
validateFreeSpace
private void validateFreeSpace()
-
-