class CCSTM extends CCSTMExecutor with STMImpl with Factory
The reference STM implementation for scala.concurrent.stm
. CCSTM is a
library-only STM based on the SwissTM algorithm, extended to reduce the
overhead of non-transactional accesses, allow partial rollback, and include
modular blocking and composition operators retry
and orAtomic
.
During construction the system property "ccstm.stats" is checked. If it is
"true" or "1" (actually if it starts with any of the characters 't', 'T',
'y', 'Y', or '1') then statistics are recorded while the program runs and
printed to Console
during JVM shutdown.
Statistics are tracked separately for top-level transactions and true nested transactions. Many nested atomic blocks can be merged into the top-level transaction by CCSTM for efficiency; these are not reported as nested.
Reported statistics are either counts or exponential histograms. For
histograms sum
is the sum of the samples, count
is the number of
transactions for which the statistic was non-zero, avg
is sum/count
and the histogram reports in brackets the number of samples that had a
value of 1, 2..3, 4..7, 8..15, and so on.
Counters:
commits
-- committed transactionsalternatives
-- alternatives provided toatomic
, one sample per call toatomic
retrySet
-- memory locations watched while performing modular blocking, one sample per top-level blocking eventretryWaitElapsed
-- milliseconds elapsed during modular blocking, one sample per top-level blocking eventexplicitRetries
-- explicit retries usingretry
,retryFor
,Ref.View.await
orRef.View.tryAwait
unrecordedTxns
-- rollbacks that were to erase a successful use ofatomic.unrecorded
optimisticRetries
-- rollbacks that were automatically retried, one line perOptimisticFailureCause.category
failures
-- rollbacks that were not retried, one line for each type of exception inUncaughtExceptionCause
blockingAcquires
-- internal locks that could not be acquired immediatelycommitReadSet
-- optimisticRef
reads, one sample per committed top-level transactioncommitBargeSet
-- locations read pessimistically, one sample per committed top-level transactioncommitWriteSet
-- locations written, one sample per committed top-level transactionrollbackReadSet
-- optimisticRef
reads, one sample per transaction that was rolled backrollbackBargeSet
-- locations read pessimistically, one sample per transaction that was rolled backrollbackWriteSet
-- locations written pessimistically, one sample per transaction that was rolled back
Read and write set counts for a nested transaction are merged into its parent if it commits, they are not counted separately during the nested commit.
- Alphabetic
- By Inheritance
- CCSTM
- Factory
- STMImpl
- TxnContext
- RefFactory
- CCSTMExecutor
- Serializable
- Serializable
- Product
- Equals
- TxnExecutor
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new CCSTM()
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
apply[Z](block: (InTxn) ⇒ Z)(implicit mt: MaybeTxn): Z
Executes
block
one or more times until an atomic execution is achieved, buffering and/or locking writes so they are not visible until success.Executes
block
one or more times until an atomic execution is achieved, buffering and/or locking writes so they are not visible until success.- Z
the return type of the atomic block
- block
code to execute atomically
- returns
the value returned from
block
after a successful optimistic concurrency attempt
- Definition Classes
- CCSTMExecutor → TxnExecutor
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
compareAndSet[A, B](a: Ref[A], a0: A, a1: A, b: Ref[B], b0: B, b1: B): Boolean
Atomically compares and sets two
Ref
s, probably more efficiently then the corresponding transaction.Atomically compares and sets two
Ref
s, probably more efficiently then the corresponding transaction. Equivalent toatomic { implicit t => a() == a0 && b() == b0 && { a() = a1 ; b() = b1 ; true } }
- Definition Classes
- CCSTMExecutor → TxnExecutor
-
def
compareAndSetIdentity[A <: AnyRef, B <: AnyRef](a: Ref[A], a0: A, a1: A, b: Ref[B], b0: B, b1: B): Boolean
Atomically compares and sets two
Ref
s using identity comparison, probably more efficiently then the corresponding transaction.Atomically compares and sets two
Ref
s using identity comparison, probably more efficiently then the corresponding transaction. Equivalent toatomic { implicit t => val f = (a() eq a0) && (b() eq b0) if (f && (a0 ne a1)) a() = a1 if (f && (b0 ne b1)) b() = b1 f }
- Definition Classes
- CCSTMExecutor → TxnExecutor
-
val
controlFlowTest: (Throwable) ⇒ Boolean
- Definition Classes
- CCSTMExecutor
-
def
dynCurrentOrNull: InTxn
Returns the current
InTxn
instance if it is active or in the process of committing on the current thread,null
otherwise.Returns the current
InTxn
instance if it is active or in the process of committing on the current thread,null
otherwise. Always performs a dynamic lookup.- Definition Classes
- CCSTM → TxnContext
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
findCurrent(implicit mt: MaybeTxn): Option[InTxn]
Returns
Some(txn)
iftxn
is theInTxn
active or in the process of committing on the current thread,None
otherwise.Returns
Some(txn)
iftxn
is theInTxn
active or in the process of committing on the current thread,None
otherwise.- Definition Classes
- CCSTM → TxnContext
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
isControlFlow(x: Throwable): Boolean
Returns true if
x
should be treated as a transfer of control, rather than an error.Returns true if
x
should be treated as a transfer of control, rather than an error. Atomic blocks that end with an uncaught control flow exception are committed, while atomic blocks that end with an uncaught error exception are rolled back.All implementations of this method must return true for instances that implement
scala.util.control.ControlThrowable
.- Definition Classes
- CCSTMExecutor → TxnExecutor
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
newCommitBarrier(timeout: Long, unit: TimeUnit): CommitBarrier
Returns a new commit barrier suitable for coordinating commits by this STM implementation.
-
def
newRef[T](v0: T)(implicit arg0: ClassManifest[T]): Ref[T]
T
will not be one of the primitive types (for which anewRef
specialization exists).T
will not be one of the primitive types (for which anewRef
specialization exists).- Definition Classes
- Factory → RefFactory
-
def
newRef(v0: Unit): Ref[Unit]
- Definition Classes
- Factory → RefFactory
-
def
newRef(v0: Double): Ref[Double]
- Definition Classes
- Factory → RefFactory
-
def
newRef(v0: Long): Ref[Long]
- Definition Classes
- Factory → RefFactory
-
def
newRef(v0: Float): Ref[Float]
- Definition Classes
- Factory → RefFactory
-
def
newRef(v0: Int): Ref[Int]
- Definition Classes
- Factory → RefFactory
-
def
newRef(v0: Char): Ref[Char]
- Definition Classes
- Factory → RefFactory
-
def
newRef(v0: Short): Ref[Short]
- Definition Classes
- Factory → RefFactory
-
def
newRef(v0: Byte): Ref[Byte]
- Definition Classes
- Factory → RefFactory
-
def
newRef(v0: Boolean): Ref[Boolean]
- Definition Classes
- Factory → RefFactory
-
def
newTArray[A](xs: TraversableOnce[A])(implicit arg0: ClassManifest[A]): TArray[A]
- Definition Classes
- Factory → RefFactory
-
def
newTArray[A](length: Int)(implicit arg0: ClassManifest[A]): TArray[A]
- Definition Classes
- Factory → RefFactory
-
def
newTMap[A, B]: TMap[A, B]
- Definition Classes
- Factory → RefFactory
-
def
newTMapBuilder[A, B]: Builder[(A, B), TMap[A, B]] { ... /* 2 definitions in type refinement */ }
- Definition Classes
- Factory → RefFactory
-
def
newTSet[A]: TSet[A]
- Definition Classes
- Factory → RefFactory
-
def
newTSetBuilder[A]: Builder[A, TSet[A]] { ... /* 2 definitions in type refinement */ }
- Definition Classes
- Factory → RefFactory
-
def
newTxnLocal[A](init: ⇒ A, initialValue: (InTxn) ⇒ A, beforeCommit: (InTxn) ⇒ Unit, whilePreparing: (InTxnEnd) ⇒ Unit, whileCommitting: (InTxnEnd) ⇒ Unit, afterCommit: (A) ⇒ Unit, afterRollback: (Status) ⇒ Unit, afterCompletion: (Status) ⇒ Unit): TxnLocal[A]
- Definition Classes
- Factory → RefFactory
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
oneOf[Z](blocks: (InTxn) ⇒ Z*)(implicit mt: MaybeTxn): Z
Atomically executes a transaction that is composed from
blocks
by joining with a left-biasedorAtomic
operator.Atomically executes a transaction that is composed from
blocks
by joining with a left-biasedorAtomic
operator. The following two examples are equivalent. UsingorAtomic
:atomic { implicit t => // body A } orAtomic { implicit t => // body B } ...
Using
oneOf
:atomic.oneOf( { implicit t: InTxn => // body A }, { implicit t: InTxn => // body B } )
The first block will be attempted in an optimistic transaction until it either succeeds, fails with no retry possible (in which case the causing exception will be rethrown), or performs a call to
retry
. If a retry is requested, then the next block will be attempted in the same fashion. If all blocks are explicitly retried then execution resumes at the first block, but only after another context has changed some value read by one of the attempts.The left-biasing of the
orAtomic
composition guarantees that if the first block does not callretry
, no other blocks will be executed.- Definition Classes
- CCSTMExecutor → TxnExecutor
-
val
postDecisionFailureHandler: (Status, Throwable) ⇒ Unit
- Definition Classes
- CCSTMExecutor → TxnExecutor
-
def
pushAlternative[Z](mt: MaybeTxn, block: (InTxn) ⇒ Z): Boolean
(rare) Associates an alternative atomic block with the current thread.
(rare) Associates an alternative atomic block with the current thread. The next call to
apply
will considerblock
to be an alternative. Multiple alternatives may be associated before callingapply
. Returns true if this is the first pushed alternative, false otherwise. This method is not usually called directly. Alternative atomic blocks are only attempted if the previous alternatives callretry
.Note that it is not required that
pushAlternative
be called on the same instance ofTxnExecutor
asapply
, just that they have been derived from the same original executor.- Definition Classes
- CCSTMExecutor → TxnExecutor
-
val
retryTimeoutNanos: Option[Long]
- Definition Classes
- CCSTMExecutor → TxnExecutor
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- CCSTMExecutor → AnyRef → Any
-
def
unrecorded[Z](block: (InTxn) ⇒ Z, outerFailure: (RollbackCause) ⇒ Z)(implicit mt: MaybeTxn): Z
Performs a computation in a transaction and returns the result, but always rolls back the transaction.
Performs a computation in a transaction and returns the result, but always rolls back the transaction. No writes performed by
block
will be committed or exposed to other threads. This may be useful for heuristic decisions or for debugging, as for the variousdbgStr
implementations.The caller is responsible for correctness: It is a code smell if Z is a type that is constructed from Ref
,
TMap,
TSet, .....
If this method is executed inside an outer transaction that has status
Txn.RolledBack
thenblock
can't complete. The default behavior (ifouterFailure
is null) in that case is to immediately roll back the outer transaction. If a non-nullouterFailure
handler has been provided, however, it allow this method to return. This is useful when the unrecorded transaction is being used for debugging or logging.atomic.unrecorded { implicit txn => code }
is roughly equivalent to the following, except that the rollback cause used will beTxn.UnrecordedTxnCause
:case class Tunnel(z: Z) extends Exception {} try { atomic.withControlFlowRecognizer({ case Tunnel(_) => false }) { implicit txn => throw Tunnel(code) } } catch { case Tunnel(z) => z }
- Definition Classes
- CCSTMExecutor → TxnExecutor
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
withControlFlowRecognizer(pf: PartialFunction[Throwable, Boolean]): TxnExecutor
Returns a
TxnExecutor e
that is identical to this one, except thate.isControlFlow(x)
will returnpf(x)
ifpf.isDefined(x)
.Returns a
TxnExecutor e
that is identical to this one, except thate.isControlFlow(x)
will returnpf(x)
ifpf.isDefined(x)
. For exceptions for whichpf
is not defined the decision will be deferred to the previous implementation.This function may be combined with
TxnExecutor.transformDefault
to add system-wide recognition of a control-transfer exception that does not extendscala.util.control.ControlThrowable
. For example, to modify the default behavior of allTxnExecutor.isControlFlow
calls to acceptDSLNonLocalControlTransferException
:TxnExecutor.transformDefault { e => e.withControlFlowRecognizer { case _: DSLNonLocalControlTransferException => true } }
- Definition Classes
- CCSTMExecutor → TxnExecutor
-
def
withPostDecisionFailureHandler(handler: (Status, Throwable) ⇒ Unit): TxnExecutor
Returns a
TxnExecutor e
that is identical to this one, except thate.postDecisionFailureHandler
will returnhandler
.Returns a
TxnExecutor e
that is identical to this one, except thate.postDecisionFailureHandler
will returnhandler
. This function may be called from inside a function passed toTxnExecutor.transformDefault
to change the system-wide post-decision failure handler.- Definition Classes
- CCSTMExecutor → TxnExecutor
-
def
withRetryTimeout(timeout: Long, unit: TimeUnit = TimeUnit.MILLISECONDS): TxnExecutor
Returns a
TxnExecutor
that is identical to this one except that it has the specified retry timeout.Returns a
TxnExecutor
that is identical to this one except that it has the specified retry timeout. The default time unit is milliseconds. If the retry timeout expires the retry will be cancelled with anInterruptedException
.- Definition Classes
- TxnExecutor
-
def
withRetryTimeoutNanos(timeout: Option[Long]): TxnExecutor
Returns a
TxnExecutor
that is identical to this one, except that it has aretryTimeout
oftimeoutNanos
.Returns a
TxnExecutor
that is identical to this one, except that it has aretryTimeout
oftimeoutNanos
.- Definition Classes
- CCSTMExecutor → TxnExecutor