Package one.nio.mem

Class MallocMT

java.lang.Object
one.nio.mem.Malloc
one.nio.mem.MallocMT
All Implemented Interfaces:
Allocator, MallocMXBean
Direct Known Subclasses:
MallocAnalyzer

public class MallocMT extends Malloc
Concurrent implementation of Malloc. Divides the whole memory space into several synchronized Malloc-segments to reduce lock contention.
  • Field Details

    • DEFAULT_CONCURRENCY_LEVEL

      public static final int DEFAULT_CONCURRENCY_LEVEL
      See Also:
    • segments

      private Malloc[] segments
    • segmentSize

      private long segmentSize
  • Constructor Details

    • MallocMT

      public MallocMT(long capacity, int concurrencyLevel)
    • MallocMT

      public MallocMT(long capacity)
    • MallocMT

      public MallocMT(long base, long capacity, int concurrencyLevel)
    • MallocMT

      public MallocMT(long base, long capacity)
    • MallocMT

      public MallocMT(MappedFile mmap, int concurrencyLevel)
    • MallocMT

      public MallocMT(MappedFile mmap)
  • Method Details

    • segments

      public int segments()
    • segment

      public Malloc segment(int index)
    • segmentFor

      public Malloc segmentFor(long n)
      Deterministically get one of the segments by some long value
      Parameters:
      n - an index of the segment to return
      Returns:
      the Malloc instance for the specified segment
    • getFreeMemory

      public long getFreeMemory()
      Specified by:
      getFreeMemory in interface MallocMXBean
      Overrides:
      getFreeMemory in class Malloc
    • malloc

      public long malloc(int size)
      Specified by:
      malloc in interface Allocator
      Overrides:
      malloc in class Malloc
    • segmentByAddress

      private Malloc segmentByAddress(long address)
    • free

      public void free(long address)
      Specified by:
      free in interface Allocator
      Overrides:
      free in class Malloc
    • allocatedSize

      public int allocatedSize(long address)
      Overrides:
      allocatedSize in class Malloc
    • verify

      public void verify()
      Description copied from interface: Allocator
      Verify the layout of the heap. Expensive operation, used only for debugging purposes.
      Specified by:
      verify in interface Allocator
      Overrides:
      verify in class Malloc
    • init

      void init()
      Overrides:
      init in class Malloc
    • initSegments

      private void initSegments(int concurrencyLevel)