Class ABAProblemDetector.AgentSlot

java.lang.Object
se.deversity.asynctest.diagnostics.ABAProblemDetector.AgentSlot
Enclosing class:
ABAProblemDetector

@API(status=INTERNAL) public static final class ABAProblemDetector.AgentSlot extends Object
One AtomicReference the agent feeds (#817): each woven operation on it runs here, with its record taken inside the same lock, so the records of one atomic are in the order its operations ran.

Only woven operations of threads whose test has this detector take the lock; any other code touches the atomic as before. A change that bypasses the lock can hide an A-B-A, never make one: every read and change judged here ran in the order it was recorded, so a reported one really went from the value a thread read, away and back, before that thread's compare-and-set expecting it succeeded.

No history is kept. Each thread's last read is the premise its next compare-and-set is judged against, as on the recording path, and each change updates the other threads' premises as it happens: away from the value they read, then back to it.

Since:
1.12.3
  • Method Details

    • read

      public @Nullable Object read(Object holder, @Nullable Object selector, int index, ABAProblemDetector.AgentSlot.SlotRead read)
      Performs read on a slot other than an AtomicReference (#817), recorded as the calling thread's premise, as get(java.util.concurrent.atomic.AtomicReference<java.lang.Object>) records.
      Parameters:
      holder - the object or array holding the slot
      selector - the updater or handle that reaches it, or null for an element
      index - the element's index, or 0
      read - the read, a non-capturing lambda
      Returns:
      what the read returned
    • store

      public void store(Object holder, @Nullable Object selector, int index, @Nullable Object value, ABAProblemDetector.AgentSlot.SlotRead current, ABAProblemDetector.AgentSlot.SlotStore store)
      Performs store, recorded as a change from what current read before it.
      Parameters:
      holder - the object or array holding the slot
      selector - the updater or handle that reaches it, or null for an element
      index - the element's index, or 0
      value - the reference to store
      current - reads what the slot holds now, a non-capturing lambda
      store - the store, a non-capturing lambda
    • compareAndSet

      public boolean compareAndSet(Object holder, @Nullable Object selector, int index, @Nullable Object expected, @Nullable Object update, ABAProblemDetector.AgentSlot.SlotSwap swap)
      Parameters:
      holder - the object or array holding the slot
      selector - the updater or handle that reaches it, or null for an element
      index - the element's index, or 0
      expected - the reference the slot must hold
      update - the reference to store
      swap - the compare-and-set, a non-capturing lambda
      Returns:
      whether it swapped
    • getAndSet

      public @Nullable Object getAndSet(Object holder, @Nullable Object selector, int index, @Nullable Object value, ABAProblemDetector.AgentSlot.SlotExchange exchange)
      Performs exchange, recorded as a change from the value it returns.
      Parameters:
      holder - the object or array holding the slot
      selector - the updater or handle that reaches it, or null for an element
      index - the element's index, or 0
      value - the reference to store
      exchange - the get-and-set, a non-capturing lambda
      Returns:
      what the slot held
    • getStamped

      public @Nullable Object getStamped(AtomicStampedReference<Object> atomic, int[] stampHolder)
      Performs AtomicStampedReference.get(int[]), recorded as the calling thread's premise: the reference and the stamp read together (#817).
      Parameters:
      atomic - the atomic this slot describes
      stampHolder - receives the stamp
      Returns:
      the reference
    • getStampedReference

      public @Nullable Object getStampedReference(AtomicStampedReference<Object> atomic)
      Performs AtomicStampedReference.getReference(), recorded as getStamped(java.util.concurrent.atomic.AtomicStampedReference<java.lang.Object>, int[]) records: the reference with the stamp it held at that moment.
      Parameters:
      atomic - the atomic this slot describes
      Returns:
      the reference
    • setStamped

      public void setStamped(AtomicStampedReference<Object> atomic, @Nullable Object value, int stamp)
      Performs AtomicStampedReference.set, recorded as a change of the pair.
      Parameters:
      atomic - the atomic this slot describes
      value - the reference to store
      stamp - the stamp to store
    • compareAndSetStamped

      public boolean compareAndSetStamped(AtomicStampedReference<Object> atomic, @Nullable Object expected, @Nullable Object update, int expectedStamp, int newStamp, boolean weak)
      Performs AtomicStampedReference.compareAndSet or weakCompareAndSet, judged against the calling thread's premise of the pair. With a stamp that only grows, a pair that left never comes back, so a reported one reused a stamp.
      Parameters:
      atomic - the atomic this slot describes
      expected - the reference the atomic must hold
      update - the reference to store
      expectedStamp - the stamp it must hold
      newStamp - the stamp to store
      weak - whether the call was weakCompareAndSet
      Returns:
      whether it swapped
    • attemptStamp

      public boolean attemptStamp(AtomicStampedReference<Object> atomic, @Nullable Object expected, int newStamp)
      Performs AtomicStampedReference.attemptStamp, recorded, when it took, as a change of the stamp alone.
      Parameters:
      atomic - the atomic this slot describes
      expected - the reference the atomic must hold
      newStamp - the stamp to store
      Returns:
      whether the stamp was set
    • get

      public @Nullable Object get(AtomicReference<Object> atomic)
      Performs AtomicReference.get, recorded as the calling thread's premise.
      Parameters:
      atomic - the atomic this slot describes
      Returns:
      what get returned
    • getAcquire

      public @Nullable Object getAcquire(AtomicReference<Object> atomic)
      Performs AtomicReference.getAcquire, recorded as get(java.util.concurrent.atomic.AtomicReference<java.lang.Object>) records.
      Parameters:
      atomic - the atomic this slot describes
      Returns:
      what getAcquire returned
    • set

      public void set(AtomicReference<Object> atomic, @Nullable Object value)
      Performs AtomicReference.set, recorded as a change from what the atomic held.
      Parameters:
      atomic - the atomic this slot describes
      value - the reference to store
    • lazySet

      public void lazySet(AtomicReference<Object> atomic, @Nullable Object value)
      Parameters:
      atomic - the atomic this slot describes
      value - the reference to store
    • setRelease

      public void setRelease(AtomicReference<Object> atomic, @Nullable Object value)
      Performs AtomicReference.setRelease, recorded as set(java.util.concurrent.atomic.AtomicReference<java.lang.Object>, java.lang.Object) records.
      Parameters:
      atomic - the atomic this slot describes
      value - the reference to store
    • getAndSet

      public @Nullable Object getAndSet(AtomicReference<Object> atomic, @Nullable Object value)
      Performs AtomicReference.getAndSet, recorded as a change from the value it returns.
      Parameters:
      atomic - the atomic this slot describes
      value - the reference to store
      Returns:
      the reference the atomic held
    • compareAndSet

      public boolean compareAndSet(AtomicReference<Object> atomic, @Nullable Object expected, @Nullable Object update)
      Performs AtomicReference.compareAndSet, judged against the calling thread's premise and recorded, when it swapped, as a change from expected. Either way the premise is used up: a retry reads again.
      Parameters:
      atomic - the atomic this slot describes
      expected - the reference the atomic must hold
      update - the reference to store
      Returns:
      whether it swapped