Class PowerOfTwoAllocator
java.lang.Object
java.util.AbstractCollection<Region>
java.util.AbstractSet<Region>
org.terracotta.offheapstore.util.AATreeSet<Region>
org.terracotta.offheapstore.storage.allocator.PowerOfTwoAllocator
- All Implemented Interfaces:
Iterable<Region>, Collection<Region>, SequencedCollection<Region>, SequencedSet<Region>, Set<Region>, SortedSet<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 ClassesNested classes/interfaces inherited from class AATreeSet
AATreeSet.AbstractTreeNode<E>, AATreeSet.Node<E> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanprivate intThis is volatile because we read it without any locking throughUpfrontAllocatingPageSource.getAllocatedSizeUnSync()private final intprivate static final boolean -
Constructor Summary
ConstructorsConstructorDescriptionPowerOfTwoAllocator(int size) Create a power-of-two allocator with the given initial 'free' size area. -
Method Summary
Modifier and TypeMethodDescriptionintallocate(int size, PowerOfTwoAllocator.Packing packing) voidclaim(int address, int size) intfind(int size, PowerOfTwoAllocator.Packing packing) private RegionfindRegion(int size, PowerOfTwoAllocator.Packing packing) Find a region of the given size.voidfree(int address, int length) private voidprivate voidInsert into the tree.intoccupied()toString()voidtryFree(int address, int length) private booleanprivate booleanprivate voidMethods inherited from class AATreeSet
add, clear, comparator, first, getRoot, headSet, isEmpty, iterator, last, remove, size, subSet, tailSetMethods inherited from class AbstractSet
equals, hashCode, removeAllMethods inherited from class AbstractCollection
addAll, contains, containsAll, retainAll, toArray, toArrayMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface Set
addAll, contains, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArrayMethods inherited from interface SortedSet
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, reversed, spliterator
-
Field Details
-
DEBUG
private static final boolean DEBUG -
VALIDATING
private static final boolean VALIDATING -
size
private final int size -
occupied
private volatile int occupiedThis is volatile because we read it without any locking throughUpfrontAllocatingPageSource.getAllocatedSizeUnSync()
-
-
Constructor Details
-
PowerOfTwoAllocator
public PowerOfTwoAllocator(int size) Create a power-of-two allocator with the given initial 'free' size area.- Parameters:
size- initial free size
-
-
Method Details
-
allocate
-
free
public void free(int address, int length) -
tryFree
public void tryFree(int address, int length) -
find
-
claim
public void claim(int address, int size) -
occupied
public int occupied() -
removeAndReturn
- Overrides:
removeAndReturnin classAATreeSet<Region>
-
find
-
free
-
tryFree
-
insert
-
tryInsert
-
findRegion
Find a region of the given size. -
toString
- Overrides:
toStringin classAbstractCollection<Region>
-
validateFreeSpace
private void validateFreeSpace()
-