org.terracotta.offheapstore.storage.allocator
Class PowerOfTwoAllocator

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<T>
          extended by org.terracotta.offheapstore.util.AATreeSet<org.terracotta.offheapstore.storage.allocator.Region>
              extended by org.terracotta.offheapstore.storage.allocator.PowerOfTwoAllocator
All Implemented Interfaces:
Iterable<org.terracotta.offheapstore.storage.allocator.Region>, Collection<org.terracotta.offheapstore.storage.allocator.Region>, Set<org.terracotta.offheapstore.storage.allocator.Region>, SortedSet<org.terracotta.offheapstore.storage.allocator.Region>

public class PowerOfTwoAllocator
extends AATreeSet<org.terracotta.offheapstore.storage.allocator.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.

Author:
Chris Dennis

Nested Class Summary
static class PowerOfTwoAllocator.Packing
           
 
Nested classes/interfaces inherited from class org.terracotta.offheapstore.util.AATreeSet
AATreeSet.AbstractTreeNode<E extends Comparable<? super E>>, AATreeSet.Node<E extends Comparable<? super E>>
 
Constructor Summary
PowerOfTwoAllocator(int size)
          Create a power-of-two allocator with the given initial 'free' size area.
 
Method Summary
 int allocate(int size, PowerOfTwoAllocator.Packing packing)
           
 void claim(int address, int size)
           
 int find(int size, PowerOfTwoAllocator.Packing packing)
           
 org.terracotta.offheapstore.storage.allocator.Region find(Object o)
           
 void free(int address, int length)
           
 int occupied()
           
 org.terracotta.offheapstore.storage.allocator.Region removeAndReturn(Object o)
           
 String toString()
          
 void tryFree(int address, int length)
           
 
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.AbstractSet
equals, hashCode, removeAll
 
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
 
Methods inherited from interface java.util.Set
addAll, contains, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

PowerOfTwoAllocator

public PowerOfTwoAllocator(int size)
Create a power-of-two allocator with the given initial 'free' size area.

Parameters:
size - initial free size
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 org.terracotta.offheapstore.storage.allocator.Region removeAndReturn(Object o)
Overrides:
removeAndReturn in class AATreeSet<org.terracotta.offheapstore.storage.allocator.Region>

find

public org.terracotta.offheapstore.storage.allocator.Region find(Object o)
Overrides:
find in class AATreeSet<org.terracotta.offheapstore.storage.allocator.Region>

toString

public String toString()

Overrides:
toString in class AbstractCollection<org.terracotta.offheapstore.storage.allocator.Region>


Copyright © 2016. All Rights Reserved.