Advanced Processor Technologies Home
APT Advanced Processor Technologies Research Group

Manchester University Transactions for Scala (MUTS)

MUTS is a Software Transactional Memory System for Scala and Java. It builds on the existing work done with Deuce STM to provide transactional memory for Scala. The granularity of these transactions can range from single lines of code to transactions spanning many objects and methods across many different classes both currently compiled and already compiled. This is achieved through byte-code rewriting which is used to instrument the methods for transactions as required. This can either be done offline or dynamically when the classes are loaded into the Java Virtual Machine (JVM). The use of rewriting prevents transactions from being restricted to the classes you are able to recompile and allows them to expand into any byte code you can run on a JVM including legacy code. This also means that the programmer is not require to construct two copies of methods in situations when they are called from inside and outside of transactional code, instead the rewrite automatically constructs an instrumented version to compliment the non instrumented version. This greatly simplifies the development and maintenance of such code by insuring that all modifications only have to be made in one location, and methods cannot have different behaviour depending on whether the calling code is transactional or not.


  • Daniel Goodman, Behram Khan, Salman Khan, Behram Khan, Mikel Luján, and Ian Watson. Software transactional memories for Scala. In the Journal of Parallel and Distributed Computing, October 2012. [.pdf]
  • Daniel Goodman, Behram Khan, Salman Khan, Chris Kirkham, Mikel Lujan and Ian Watson. MUTS: Native Scala Constructs for Software Transactional Memory In Proceedings of Scala Days 2011, Stanford CA, June 2011. [.pdf]


We will now demonstrate the different syntax's available for MUTS transactions. All of these are interoperable with each other, so you are not restricted to a single style of transaction, but instead you are free to choose which ever style best suits a particular instance where a transaction is required. Some simple examples are available for download here.


Mimicking the notation used in Deuce STM, MUTS provides the ability to turn an entire method into a transaction through the addition of a single annotation as can be seen in this example:

import org.deuce.Atomic


def transfer()
   // Code for transactional function transfer


Annotations restrict the user to making entire methods transactional, however, often you will want to make just a few lines within a method transactional. This can be achieved through the use of the library call atomic as shown in this example. The syntax of these closures has been simplified in version 1.1 and the atomic blocks can now return values.

import eu.teraflux.uniman.transactions.TMLib._


// Non transactional code
   // Transactional code
// Non transactional code

Compiler Keywords

The construction of closures adds some syntactic clutter and overhead to the system. To address this we have constructed a version of this code that modifies the parser in the 2.7.7 version of the Scala compiler. This can be installed by replacing the scala-compiler.jar jar file in the 2.7.7 compiler lib directory this jar with this jar file. You will also still need the MUTS_2.7.jar file in your path for the compiler to link against. Once this is done, it is possible to add transactions using the new keywords in the language. For example:

// Non transactional code
   // Code for transactional function transfer
} TFretry;
// Non transactional code

The prefix TF has been added to address namespace collisions through the addition of new keywords to the compiler. Details of how this is implemented can be found in this paper. While we realise that the 2.7 compiler is now somewhat out dated, this does serve as an example of how easily such additional functionality can be inserted into the language without effect on legacy code or the rest of the compiler pipeline.


Latest Version

MUTS 1.1 for Scala 2.7
MUTS 1.1 for Scala 2.8 and 2.9
MUTS 1.1 for Scala 2.10
MUTS 1.1 examples

Version 1.0

MUTS 1.0 for Scala 2.7
MUTS 1.0 for Scala 2.8 and 2.9
MUTS 1.0 examples

Keyword extensions for Scala 2.7 compiler - Remember MUTS_2.7.jar is also required.

Compiling and Executing MUTS Code

MUTS comes packaged in a single jar file, these are available in two versions, one for Scala 2.7 and one for Scala 2.8 and 2.9. Once you have downloaded the appropriate jar file you can use it to add transactions into your program and to execute transactional code.

Compiling MUTS code

To compile code that includes MUTS code you just need to add the MUTS jar file to your compilers class path. For example:

scalac -cp /home/daniel/muts_2.8-v1.1.jar:. helloWorld.scala

Executing MUTS code

Once the code is compiled you can now execute it. To do this you need to add the jar file as javaagent to your JVM arguments. The JVM argument to achieve this is:


For execution within an IDE this will be done by setting the property within your project run configuration. If you are running Scala from the command line it can be achieved by modifying the values stored in the JAVA_OPTS environmental parameter. This can be achieved with the command:

export JAVA_OPTS="-Xmx256M -Xms32M -javaagent:/home/daniel/muts_2.8-v1.1.jar"

Additional arguments for Scala 2.9

By default Scala 2.9 disables a range of features from the JVM for all classes relating to the Scala environment including Java Agent rewriting. This is done as a means of improving the start time for Scala. A command line option for has been included to allow these to be reinstated, and this needs to be used when executing code containing MUTS transactions. This argument is:


Making an example execution:

scala -nobootcp helloWorld

Some IDEs such as Eclipse do not use the scala command to start the applications and instead you must modify the execution class path manually. By default the path will look like this:

From here you need to remove the scala-library.jar jar file from the boot class path, and add it using the "add external jar" option to the user class path so that the resulting configuration looks like this:

Benefits of MUTS

  • Works with legacy code. As the instrumentation is added by a rewrite of the compiled byte code any byte code can be executed in a transactional context, regardless of when or how it was compiled or by whom.
  • Compatible with Deuce STM and Java. MUTS uses the backend STM algorithms implemented in Deuce STM, and used the Deuce STM Java Agent as a starting point for the construction of our own Java Agent. As a result, Java code annotated to work with Deuce STM will also work with MUTS, and MUTS can be used to instrument Java code.
  • Range of syntax options for different use cases. MUTS supports a range of different syntax options for different use cases. All of these are interoperable, leaving you free to use which ever syntax best suits each location where a transaction is required.
  • Programmers only need to write one copy of each method. Unlike software transactional memories such as CCSTM and MultiVerse, where two copies are required for methods that are called from both inside and outside of transactions, MUTS automatically creates the transactional version of the method from the non transactional one. This means that the programmer only has to write and maintain one method. This greatly reduces the opportunities to add errors into the system.

About Us

MUTS has been produced at the University of Manchester as part of the EU FP7 Teraflux Project. We hope you like MUTS and find it use full, if you have any comments or questions please email me at daniel.goodman [ AT]