use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.
the class HeapTrackingUnifiedSetTest method setUp.
@BeforeEach
void setUp() {
memoryPool = new MemoryPools().pool(MemoryGroup.TRANSACTION, 0L, null);
memoryTracker = new LocalMemoryTracker(memoryPool);
}
use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.
the class HeapTrackingIntObjectHashMapTest method setUp.
@BeforeEach
void setUp() {
memoryPool = new MemoryPools().pool(MemoryGroup.TRANSACTION, 0L, null);
memoryTracker = new LocalMemoryTracker(memoryPool);
}
use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.
the class UnsafeUtilTest method directByteBufferCreationAndInitialisation.
@Test
void directByteBufferCreationAndInitialisation() throws Throwable {
int sizeInBytes = 313;
var tracker = new LocalMemoryTracker();
long address = allocateMemory(sizeInBytes, tracker);
try {
setMemory(address, sizeInBytes, (byte) 0);
ByteBuffer a = newDirectByteBuffer(address, sizeInBytes);
assertThat(a).isNotSameAs(newDirectByteBuffer(address, sizeInBytes));
assertThat(a.hasArray()).isEqualTo(false);
assertThat(a.isDirect()).isEqualTo(true);
assertThat(a.capacity()).isEqualTo(sizeInBytes);
assertThat(a.limit()).isEqualTo(sizeInBytes);
assertThat(a.position()).isEqualTo(0);
assertThat(a.remaining()).isEqualTo(sizeInBytes);
assertThat(getByte(address)).isEqualTo((byte) 0);
a.put((byte) -1);
assertThat(getByte(address)).isEqualTo((byte) -1);
a.position(101);
a.mark();
a.limit(202);
int sizeInBytes2 = 424;
long address2 = allocateMemory(sizeInBytes2, tracker);
try {
setMemory(address2, sizeInBytes2, (byte) 0);
initDirectByteBuffer(a, address2, sizeInBytes2);
assertThat(a.hasArray()).isEqualTo(false);
assertThat(a.isDirect()).isEqualTo(true);
assertThat(a.capacity()).isEqualTo(sizeInBytes2);
assertThat(a.limit()).isEqualTo(sizeInBytes2);
assertThat(a.position()).isEqualTo(0);
assertThat(a.remaining()).isEqualTo(sizeInBytes2);
assertThat(getByte(address2)).isEqualTo((byte) 0);
a.put((byte) -1);
assertThat(getByte(address2)).isEqualTo((byte) -1);
} finally {
free(address2, sizeInBytes2, tracker);
}
} finally {
free(address, sizeInBytes, tracker);
}
}
use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.
the class HeapTrackingLongEnumerationListTest method addRemoveScenario.
@Test
void addRemoveScenario() {
MemoryTracker memoryTracker = new LocalMemoryTracker();
HeapTrackingLongEnumerationList<Long> table = HeapTrackingLongEnumerationList.create(memoryTracker, 4);
assertEmpty(table);
table.add(0L);
table.add(1L);
table.add(2L);
assertContainsOnly(table, 0, 2);
table.remove(0L);
table.remove(1L);
assertContainsOnly(table, 2);
table.remove(2);
assertEmpty(table);
table.add(3L);
table.add(4L);
table.add(5L);
assertContainsOnly(table, 3, 5);
table.remove(5);
assertContainsOnly(table, 3, 4);
table.remove(4);
assertContainsOnly(table, 3);
long measured1 = meter.measureDeep(table) - measuredMemoryTracker;
assertEquals(measured1, memoryTracker.estimatedHeapMemory() + HeapEstimator.LONG_SIZE);
table.add(6L);
assertContainsOnly(table, new long[] { 3L, 6L });
long measured2 = meter.measureDeep(table) - measuredMemoryTracker;
assertEquals(measured2, memoryTracker.estimatedHeapMemory() + 2 * HeapEstimator.LONG_SIZE);
assertEquals(HeapEstimator.LONG_SIZE, measured2 - measured1);
// New chunk needed
table.add(7L);
assertContainsOnly(table, new long[] { 3L, 6, 7L });
// New chunk allocated because of poor alignment in tail chunks
table.add(8L);
assertContainsOnly(table, new long[] { 3L, 6L, 7L, 8L });
table.remove(6L);
assertContainsOnly(table, new long[] { 3L, 7L, 8L });
// Should recycle chunk
table.remove(3L);
assertContainsOnly(table, new long[] { 7L, 8L });
// Should recycle chunk
table.remove(7L);
assertContainsOnly(table, 8L);
// Memory should be back to one chunk + one value
long measured3 = meter.measureDeep(table) - measuredMemoryTracker;
assertEquals(measured3, memoryTracker.estimatedHeapMemory() + HeapEstimator.LONG_SIZE);
assertEquals(measured1, measured3);
table.add(9L);
table.add(10L);
table.add(11L);
assertContainsOnly(table, 8, 11);
table.remove(8L);
table.remove(10L);
table.remove(11L);
assertContainsOnly(table, 9);
table.add(12L);
assertContainsOnly(table, new long[] { 9L, 12L });
table.remove(9L);
assertContainsOnly(table, 12);
// Memory should be one chunk + one value
long measured4 = meter.measureDeep(table) - measuredMemoryTracker;
assertEquals(measured4, memoryTracker.estimatedHeapMemory() + HeapEstimator.LONG_SIZE);
assertEquals(measured3, measured4);
table.close();
}
use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.
the class MutableLinearProbeLongHashSetTest method freeFrozenMemory.
@Test
void freeFrozenMemory() {
final MemoryTracker memoryTrackerSpy = spy(new LocalMemoryTracker());
final MutableLinearProbeLongHashSet set2 = new MutableLinearProbeLongHashSet(new OffHeapMemoryAllocator(blockAllocator), memoryTrackerSpy);
verify(memoryTrackerSpy).allocateNative(anyLong());
set2.addAll(100, 200, 300);
set2.freeze();
set2.remove(100);
set2.freeze();
set2.clear();
set2.close();
verify(memoryTrackerSpy, times(3)).releaseNative(anyLong());
}
Aggregations