diff --git a/community/common/src/main/java/org/neo4j/memory/LocalMemoryTracker.java b/community/common/src/main/java/org/neo4j/memory/LocalMemoryTracker.java index 17519f1c5d2b2..e305b72510d92 100644 --- a/community/common/src/main/java/org/neo4j/memory/LocalMemoryTracker.java +++ b/community/common/src/main/java/org/neo4j/memory/LocalMemoryTracker.java @@ -22,7 +22,6 @@ /** * Memory allocation tracker that can be used in local context that required * tracking of memory that is independent from global. - * All allocations/de-allocation reported to this trackers also will be reported to global tracker transparently. */ public class LocalMemoryTracker implements MemoryAllocationTracker { @@ -31,19 +30,17 @@ public class LocalMemoryTracker implements MemoryAllocationTracker @Override public void allocated( long bytes ) { - GlobalMemoryTracker.INSTANCE.allocated( bytes ); this.allocatedBytes += bytes; } @Override public void deallocated( long bytes ) { - GlobalMemoryTracker.INSTANCE.deallocated( bytes ); this.allocatedBytes -= bytes; } /** - * @return number of locally used bytes. + * @return number of used bytes. */ @Override public long usedDirectMemory() diff --git a/community/common/src/test/java/org/neo4j/memory/LocalMemoryTrackerTest.java b/community/common/src/test/java/org/neo4j/memory/LocalMemoryTrackerTest.java index 2bd6d97f1e45c..5074a1712af6a 100644 --- a/community/common/src/test/java/org/neo4j/memory/LocalMemoryTrackerTest.java +++ b/community/common/src/test/java/org/neo4j/memory/LocalMemoryTrackerTest.java @@ -48,21 +48,4 @@ void trackMemoryDeallocations() memoryTracker.deallocated( 40 ); assertEquals( 40, memoryTracker.usedDirectMemory() ); } - - @Test - void localMemoryTrackerPropagatesAllocationsToGlobalTracker() - { - GlobalMemoryTracker globalMemoryTracker = GlobalMemoryTracker.INSTANCE; - long initialGlobalUsage = globalMemoryTracker.usedDirectMemory(); - LocalMemoryTracker memoryTracker = new LocalMemoryTracker(); - - memoryTracker.allocated( 100 ); - assertEquals( 100, memoryTracker.usedDirectMemory() ); - assertEquals( 100, globalMemoryTracker.usedDirectMemory() - initialGlobalUsage ); - - memoryTracker.deallocated( 50 ); - assertEquals( 50, memoryTracker.usedDirectMemory() ); - assertEquals( 50, globalMemoryTracker.usedDirectMemory() - initialGlobalUsage ); - } - } diff --git a/community/unsafe/src/main/java/org/neo4j/unsafe/impl/internal/dragons/UnsafeUtil.java b/community/unsafe/src/main/java/org/neo4j/unsafe/impl/internal/dragons/UnsafeUtil.java index 58850b91481e2..e14a4f9bea5bd 100644 --- a/community/unsafe/src/main/java/org/neo4j/unsafe/impl/internal/dragons/UnsafeUtil.java +++ b/community/unsafe/src/main/java/org/neo4j/unsafe/impl/internal/dragons/UnsafeUtil.java @@ -385,15 +385,16 @@ public static long allocateMemory( long sizeInBytes ) * The memory is aligned such that it can be used for any data type. * The memory is uninitialised, so it may contain random garbage, or it may not. */ - public static long allocateMemory( long sizeInBytes, MemoryAllocationTracker allocationTracker ) + public static long allocateMemory( long bytes, MemoryAllocationTracker allocationTracker ) { - final long pointer = unsafe.allocateMemory( sizeInBytes ); + final long pointer = unsafe.allocateMemory( bytes ); if ( DIRTY_MEMORY ) { - setMemory( pointer, sizeInBytes, (byte) 0xA5 ); + setMemory( pointer, bytes, (byte) 0xA5 ); } - addAllocatedPointer( pointer, sizeInBytes ); - allocationTracker.allocated( sizeInBytes ); + addAllocatedPointer( pointer, bytes ); + allocationTracker.allocated( bytes ); + GlobalMemoryTracker.INSTANCE.allocated( bytes ); return pointer; } @@ -432,6 +433,7 @@ public static void free( long pointer, long bytes, MemoryAllocationTracker alloc checkFree( pointer ); unsafe.freeMemory( pointer ); allocationTracker.deallocated( bytes ); + GlobalMemoryTracker.INSTANCE.deallocated( bytes ); } private static final class FreeTrace extends Throwable implements Comparable