use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.
the class HeapTrackingLongIntHashMapTest 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 HeapTrackingUnifiedMapTest 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 HeapTrackingLongEnumerationListTest method addPutRemoveScenario.
@Test
void addPutRemoveScenario() {
MemoryTracker memoryTracker = new LocalMemoryTracker();
HeapTrackingLongEnumerationList<Long> table = HeapTrackingLongEnumerationList.create(memoryTracker, 4);
assertEmpty(table);
table.add(0L);
table.put(2L, 2L);
table.put(1L, 1L);
assertContainsOnly(table, 0, 2);
table.remove(0L);
table.remove(1L);
assertContainsOnly(table, 2);
table.remove(2);
assertEmpty(table);
table.add(9999L);
table.put(4L, 4L);
// Replace
assertEquals(table.put(3L, 3L), 9999L);
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.put(6L, 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 and extra chunk allocated because of poor alignment in tail chunks
table.put(8L, 8L);
assertContainsOnly(table, new long[] { 3L, 6L, 8L });
table.put(7L, 7L);
assertContainsOnly(table, new long[] { 3L, 6L, 7L, 8L });
table.remove(6L);
assertContainsOnly(table, new long[] { 3L, 7L, 8L });
table.remove(3L);
assertContainsOnly(table, new long[] { 7L, 8L });
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.put(10L, 10L);
table.put(9L, 9L);
table.add(11L);
assertContainsOnly(table, 8, 11);
table.remove(8L);
table.remove(10L);
table.remove(11L);
assertContainsOnly(table, 9);
table.put(12L, 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 MemoryAllocatorTest method trackMemoryAllocations.
@Test
void trackMemoryAllocations() {
LocalMemoryTracker memoryTracker = new LocalMemoryTracker();
GrabAllocator allocator = (GrabAllocator) MemoryAllocator.createAllocator(MebiByte.toBytes(2), memoryTracker);
assertEquals(0, memoryTracker.usedNativeMemory());
allocator.allocateAligned(ByteUnit.mebiBytes(1), 1);
assertEquals(ByteUnit.mebiBytes(1), memoryTracker.usedNativeMemory());
allocator.close();
assertEquals(0, memoryTracker.usedNativeMemory());
}
use of org.neo4j.memory.LocalMemoryTracker in project neo4j by neo4j.
the class MutableLinearProbeLongHashSetTest method allocateFreeMemory.
@Test
void allocateFreeMemory() {
final MemoryTracker memoryTrackerSpy = spy(new LocalMemoryTracker());
final MutableLinearProbeLongHashSet set2 = new MutableLinearProbeLongHashSet(new OffHeapMemoryAllocator(blockAllocator), memoryTrackerSpy);
verify(memoryTrackerSpy).allocateNative(anyLong());
for (int i = 0; i < DEFAULT_CAPACITY; i++) {
set2.add(100 + i);
}
verify(memoryTrackerSpy).releaseNative(anyLong());
verify(memoryTrackerSpy, times(2)).allocateNative(anyLong());
set2.close();
verify(memoryTrackerSpy, times(2)).releaseNative(anyLong());
}
Aggregations