Class ConcurrentBitField

java.lang.Object
org.eclipse.mat.collect.ConcurrentBitField

public final class ConcurrentBitField extends Object
This class manages huge bit fields. It is much faster than BitSet and was specifically developed to be used with huge bit sets in ISnapshot (e.g. needed in virtual GC traces). Out of performance reasons no method does any parameter checking, i.e. only valid values are expected. This is a fully thread-safe/concurrent implementation.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConcurrentBitField(boolean[] bits)
     
    Creates a bit field with the given number of bits.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    clear(int index)
    Clears the bit on the given index.
    final boolean
    compareAndSet(int index, boolean expectedValue, boolean newValue)
    Compare and set the value atomically.
    final boolean
    get(int index)
    Gets the bit on the given index.
    final void
    intoBooleanArrayNonAtomic(boolean[] output)
    Gets the full array.
    final void
    set(int index)
    Sets the bit on the given index.
    final int
    The size of the bitfield.
    final boolean[]
    Gets the full array.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConcurrentBitField

      public ConcurrentBitField(int size)
      Creates a bit field with the given number of bits. Size is expected to be positive.
      Parameters:
      size - the maximum size of the BitField
    • ConcurrentBitField

      public ConcurrentBitField(boolean[] bits)
  • Method Details

    • set

      public final void set(int index)
      Sets the bit on the given index. Index is expected to be in range - out of performance reasons no checks are done!
      Parameters:
      index - The 0-based index into the BitField.
    • clear

      public final void clear(int index)
      Clears the bit on the given index. Index is expected to be in range - out of performance reasons no checks are done!
      Parameters:
      index - The 0-based index into the BitField.
    • compareAndSet

      public final boolean compareAndSet(int index, boolean expectedValue, boolean newValue)
      Compare and set the value atomically. NB multiple underlying CAS might be competing, but only once ever for the same bit.
      Parameters:
      index -
      Returns:
      true if successful. False return indicates that the actual value was not equal to the expected value.
    • get

      public final boolean get(int index)
      Gets the bit on the given index. Index is expected to be in range - out of performance reasons no checks are done!
      Parameters:
      index - The 0-based index into the BitField.
      Returns:
      true if the BitField was set, false if it was cleared or never set.
    • size

      public final int size()
      The size of the bitfield.
      Returns:
    • toBooleanArrayNonAtomic

      public final boolean[] toBooleanArrayNonAtomic()
      Gets the full array. Note that this is _not_ a thread-safe snapshot.
      Returns:
    • intoBooleanArrayNonAtomic

      public final void intoBooleanArrayNonAtomic(boolean[] output)
      Gets the full array. Note that this is _not_ a thread-safe snapshot.
      Parameters:
      output - array to fill