FreeListManager { boolean isAdjacent(long lowAddr, int lowSize, long highAddr) { return (lowAddr + lowSize) == highAddr; } FreeListManager(MemoryAllocatorImpl ma, final Slab[] slabs); long getUsedMemory(); long getFreeMemory(); @SuppressWarnings("synthetic-access") OffHeapStoredObject allocate(int size); @SuppressWarnings("synthetic-access") void free(long addr); static final int TINY_MULTIPLE; static final int TINY_FREE_LIST_COUNT; static final int HUGE_MULTIPLE; static final int MAX_TINY; }
@Test public void isAdjacentBoundaryConditions() { SlabImpl chunk = new SlabImpl(10); this.freeListManager = createFreeListManager(ma, new Slab[] {chunk}); assertThat(!this.freeListManager.isAdjacent(Long.MAX_VALUE - 4, 4, Long.MAX_VALUE + 1)); assertThat(this.freeListManager.isAdjacent(Long.MAX_VALUE - 4, 4, Long.MAX_VALUE)); assertThat(this.freeListManager.isAdjacent(-8L, 4, -4L)); long lowAddr = Long.MAX_VALUE; long highAddr = lowAddr + 4; assertThat(this.freeListManager.isAdjacent(lowAddr, 4, highAddr)); assertThat(!this.freeListManager.isAdjacent(lowAddr, 4, highAddr - 1)); assertThat(!this.freeListManager.isAdjacent(lowAddr, 4, highAddr + 1)); lowAddr = highAddr; highAddr = lowAddr + 4; assertThat(this.freeListManager.isAdjacent(lowAddr, 4, highAddr)); assertThat(!this.freeListManager.isAdjacent(highAddr, 4, lowAddr)); }