Exemple #1
0
        public override void Free(OffHeapBlockAllocator_MemoryBlock block, MemoryAllocationTracker tracker)
        {
            if (_released || !IsCacheable(block.Size))
            {
                DoFree(block, tracker);
                return;
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.BlockingQueue<OffHeapBlockAllocator_MemoryBlock> cache = caches[log2floor(block.size)];
            BlockingQueue <OffHeapBlockAllocator_MemoryBlock> cache = _caches[log2floor(block.Size)];

            if (!cache.offer(block))
            {
                DoFree(block, tracker);
                return;
            }

            // it is possible that allocator is released just before we put the block into queue;
            // in such case case we need to free memory right away, since release() will never be called again
            if (_released && cache.remove(block))
            {
                DoFree(block, tracker);
                return;
            }

            tracker.Deallocated(block.UnalignedSize);
        }
            public override Memory Copy()
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator_MemoryBlock copy = blockAllocator.allocate(block.size, tracker);
                OffHeapBlockAllocator_MemoryBlock copy = outerInstance.blockAllocator.Allocate(Block.size, outerInstance.tracker);

                copyMemory(Block.addr, copy.Addr, Block.size);
                return(new OffHeapMemory(_outerInstance, copy));
            }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void freeAfterRelease()
        internal virtual void FreeAfterRelease()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator_MemoryBlock block = allocator.allocate(128, memoryTracker);
            OffHeapBlockAllocator_MemoryBlock block = _allocator.allocate(128, _memoryTracker);

            _allocator.release();
            _allocator.free(block, _memoryTracker);
            verify(_allocator).doFree(eq(block), any());
        }
Exemple #4
0
 public override void Free(OffHeapBlockAllocator_MemoryBlock block, MemoryAllocationTracker tracker)
 {
     try
     {
         _impl.free(block, tracker);
     }
     finally
     {
         _usedMemory.addAndGet(-block.Size);
     }
 }
        public override Memory Allocate(long size, bool zeroed)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator_MemoryBlock block = blockAllocator.allocate(size, tracker);
            OffHeapBlockAllocator_MemoryBlock block = _blockAllocator.allocate(size, _tracker);

            if (zeroed)
            {
                setMemory(block.UnalignedAddr, block.UnalignedSize, ( sbyte )0);
            }
            return(new OffHeapMemory(this, block));
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @ValueSource(longs = {8, 64, 128}) void allocateCacheableSize(long bytes)
        internal virtual void AllocateCacheableSize(long bytes)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator_MemoryBlock block1 = allocator.allocate(bytes, memoryTracker);
            OffHeapBlockAllocator_MemoryBlock block1 = _allocator.allocate(bytes, _memoryTracker);

            _allocator.free(block1, _memoryTracker);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator_MemoryBlock block2 = allocator.allocate(bytes, memoryTracker);
            OffHeapBlockAllocator_MemoryBlock block2 = _allocator.allocate(bytes, _memoryTracker);

            _allocator.free(block2, _memoryTracker);

            verify(_allocator).allocateNew(eq(bytes), any());
            verify(_allocator, never()).doFree(any(), any());
            assertEquals(0, _memoryTracker.usedDirectMemory());
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void maxMemoryLimit()
        internal virtual void MaxMemoryLimit()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.memory.MemoryAllocationTracker tracker = mock(org.neo4j.memory.MemoryAllocationTracker.class);
            MemoryAllocationTracker tracker = mock(typeof(MemoryAllocationTracker));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final OffHeapBlockAllocator allocator = mock(OffHeapBlockAllocator.class);
            OffHeapBlockAllocator allocator = mock(typeof(OffHeapBlockAllocator));

            when(allocator.Allocate(anyLong(), any(typeof(MemoryAllocationTracker)))).then(invocation =>
            {
                long size = invocation.getArgument <long>(0);
                return(new MemoryBlock(0, size, 0, size));
            });
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final CapacityLimitingBlockAllocatorDecorator decorator = new CapacityLimitingBlockAllocatorDecorator(allocator, 1024);
            CapacityLimitingBlockAllocatorDecorator decorator = new CapacityLimitingBlockAllocatorDecorator(allocator, 1024);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator_MemoryBlock> blocks = new java.util.ArrayList<>();
            IList <OffHeapBlockAllocator_MemoryBlock> blocks = new List <OffHeapBlockAllocator_MemoryBlock>();

            for (int i = 0; i < 8; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator_MemoryBlock block = decorator.allocate(128, tracker);
                OffHeapBlockAllocator_MemoryBlock block = decorator.Allocate(128, tracker);
                blocks.Add(block);
            }

            assertThrows(typeof(Exception), () => decorator.Allocate(128, tracker));

            decorator.Free(blocks.RemoveAt(0), tracker);
            assertDoesNotThrow(() => decorator.Allocate(128, tracker));

            assertThrows(typeof(Exception), () => decorator.Allocate(256, tracker));
            decorator.Free(blocks.RemoveAt(0), tracker);
            assertThrows(typeof(Exception), () => decorator.Allocate(256, tracker));

            decorator.Free(blocks.RemoveAt(0), tracker);
            assertDoesNotThrow(() => decorator.Allocate(256, tracker));
        }
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void allocateAndFree()
        internal virtual void AllocateAndFree()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator_MemoryBlock block1 = allocator.allocate(128, memoryTracker);
            OffHeapBlockAllocator_MemoryBlock block1 = _allocator.allocate(128, _memoryTracker);

            assertEquals(block1.Size, 128);
            assertEquals(128 + Long.BYTES - 1, block1.UnalignedSize);
            assertEquals(block1.UnalignedSize, _memoryTracker.usedDirectMemory());

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.collection.OffHeapBlockAllocator_MemoryBlock block2 = allocator.allocate(256, memoryTracker);
            OffHeapBlockAllocator_MemoryBlock block2 = _allocator.allocate(256, _memoryTracker);

            assertEquals(block2.Size, 256);
            assertEquals(256 + Long.BYTES - 1, block2.UnalignedSize);
            assertEquals(block1.UnalignedSize + block2.UnalignedSize, _memoryTracker.usedDirectMemory());

            _allocator.free(block1, _memoryTracker);
            _allocator.free(block2, _memoryTracker);
            assertEquals(0, _memoryTracker.usedDirectMemory());
        }
Exemple #9
0
        public override OffHeapBlockAllocator_MemoryBlock Allocate(long size, MemoryAllocationTracker tracker)
        {
            requirePositive(size);
            checkState(!_released, "Allocator is already released");
            if (!IsCacheable(size))
            {
                return(AllocateNew(size, tracker));
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.BlockingQueue<OffHeapBlockAllocator_MemoryBlock> cache = caches[log2floor(size)];
            BlockingQueue <OffHeapBlockAllocator_MemoryBlock> cache = _caches[log2floor(size)];
            OffHeapBlockAllocator_MemoryBlock block = cache.poll();

            if (block == null)
            {
                block = AllocateNew(size, tracker);
            }
            else
            {
                tracker.Allocated(block.UnalignedSize);
            }
            return(block);
        }
 internal OffHeapMemory(OffHeapMemoryAllocator outerInstance, OffHeapBlockAllocator_MemoryBlock block)
 {
     this._outerInstance = outerInstance;
     this.Block          = block;
 }
Exemple #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @VisibleForTesting void doFree(OffHeapBlockAllocator_MemoryBlock block, org.neo4j.memory.MemoryAllocationTracker tracker)
        internal virtual void DoFree(OffHeapBlockAllocator_MemoryBlock block, MemoryAllocationTracker tracker)
        {
            UnsafeUtil.free(block.UnalignedAddr, block.UnalignedSize, tracker);
        }