Transactional Execution of Java Programs
Brian D. Carlstrom, JaeWoong Chung, Hassan Chafi, Austen McDonald, Chi Cao Minh
Lance Hammond, Christos Kozyrakis, and Kunle Olukotun
Computer Systems Laboratory
Stanford University{bdc, jwchung, hchafi, austenmc, caominh, lance, kozyraki, kunle}@stanford.edu

ABSTRACT
Parallel programming is difficult due to the complexity ofdealing with conventional lock-based synchronization. To
simplify parallel programming, there have been a numberof proposals to support transactions directly in hardwareand eliminate locks completely. Although hardware support
for transactions has the potential to completely change theway parallel programs are written, initially transactions will
be used to execute existing parallel programs. In this paper we investigate the implications of using transactions to
execute existing parallel Java programs. Our results showthat transactions can be used to support all aspects of Java
multithreaded programs. Moreover, the conversion of alock-based application into transactions is largely straightforward. The performance that these converted applications
achieve is equal to or sometimes better than the originallock-based implementation.

Categories and Subject Descriptors
C.5.0 [Computer Systems Implementation]: General;
D.1.3 [Programming Techniques]: Concurrent Programming – parallel programming; D.3.3 [Programming Languages]: Language Constructs and Features – concurrent
programming structures

General Terms
Performance, Design, Languages

Keywords
Transactions, feedback optimization, multiprocessor architecture

1.

INTRODUCTION

Processor vendors have exhausted their ability to improvesingle-thread performance using techniques such as simply
increasing clock frequency [41, 2]. Hence they are turningen masse to single-chip multiprocessors (CMPs) as a realistic path towards scalable performance for server, embedded,
and even desktop platforms [22, 20, 34, 5]. While parallelizing server applications is straightforward with CMPs,
parallelizing existing desktop applications is much harder.
Traditional multithreaded programming focuses on using
locks for mutual exclusion. By convention, access to shareddata is coordinated through ownership of one or more locks.
Typically a programmer will use one lock per data structure
to keep the locking protocol simple. Unfortunately, suchcoarse-grained locking often leads to serialization on highcontention data structures. On the other hand, finer-grained
locking can improve concurrency, but only by making codemuch more complex. With such code, it is often easy to end
up in deadlock situations.
Transactional memory has been proposed as an abstraction to simplify parallel programming [16, 36, 17, 14]. Transactions eliminate locking completely by grouping sequencesof object references into atomic execution units. They provide an easy-to-use technique for non-blocking synchronization over multiple objects, because the programmers canfocus on determining where atomicity is necessary, and not
the implementation details of synchronization. Althoughtransactional memory has the potential to change the way
parallel programs are written, initially transactions will be
used to execute existing parallel programs. To understandissues associated with executing existing parallel programs
using transactional memory, we investigate how Java parallel programs interact with hardware-supported transactional
memory that provides continuous transactions. There havebeen several recent proposals that can support continuoustransactions such as Transactional Coherence and Consistency (TCC), Unbounded Transactional Memory (UTM),
and Virtual Transactional Memory (VTM) [13, 4, 33].
Our general approach of executing Java parallel programswith hardware transactional memory is to turn synchronized blocks into atomic transactions. Transactions provide strong atomicity semantics for all referenced objects,
providing a natural replacement for critical sections definedby synchronized. The programmer does not have to identify shared objects a priori and follow disciplined locking
and nesting conventions for correct synchronization. Studies show that this is what programmers usually mean bysynchronized in Java applications [9]. Optimistic execution of transactions provides good parallel performance inthe common case of non-conflicting object accesses, without the need for fine-grain locking mechanisms that further
complicate correctness and introduce significant overhead.

The paper makes the following contributions:• We show how hardware transactional memory can support all aspects of Java multithreaded programming,
including synchronized blocks, native methods, synchronization on condition variables, and I/O statements. We show how existing Java applications canbe run with few, if any, changes to the program.
• We demonstrate the results of running parallel Java
programs, showing how our transactional execution
matches or exceeds the performance of the originallock-based versions.
The rest of the paper is organized as follows. Section 2
provides an architectural overview of continuous transactional execution models. Section 3 describes running Javaapplications with transactions. In Section 4, we evaluate
the performance of transactional Java programs. Section 5
discusses related work, and we conclude in Section 6.

2.

CONTINUOUS TRANSACTIONAL
ARCHITECTURES

The particular variant of transactional memory we consider in this paper is continuous transactions. Continuous transactional architectures provide hardware support fortransactional memory in a shared-memory multiprocessor.
Each thread consists of a sequence of transactions, where
each transaction is a sequence of instructions guaranteed to
execute and complete only as an atomic unit. As opposed
to earlier hardware transactional memory proposals, there
is no execution outside of transactions. The processors execute transactions, enforce atomicity, and maintain memory
consistency and cache coherence only at transaction boundaries, when object updates are propagated to shared memory. By using the continuous transactional model, we hopeto uncover a wider range of issues than would be found in asystem that only uses transactions a fraction of the time.
Each processor follows a cycle of transaction execution,commit, and potential re-execution. Each transaction is
executed speculatively, assuming it operates on data thatis disjoint from transactions running concurrently on otherprocessors. Writes are buffered locally, and do not updateshared memory before the transaction commits. Transactions are considered indivisible if they are supporting a programmer defined notion of atomicity or divisible if they canbe split as needed by the hardware. For example, if an indivisible transaction exceeds its processor’s cache capacity,
its write-set overflow can be managed by software buffering [16, 14] or lower levels of the memory hierarchy [10, 4,33] whereas a divisible transaction can be split as needed by
a commit.
When a transaction commits, it communicates its writeset to the rest of the system. Other processors determine
when they have speculatively read data that has been modified by another transaction. These data dependency violations trigger re-execution to maintain atomicity, usually ofthe other processor’s current transaction, but potentially of
the committing processor. Hardware guarantees that transaction commits are seen by all processors in the same order,
so commits are always globally serialized. Some systems allow programmer specified ordering of transaction commits
to support such features as loop speculation and speculating through barriers. Systems that only support unorderedtransactions sometimes require transactions to commit fromoldest to youngest to ensure forward progress which could
lead to load balancing issues. Some systems simply favorolder transactions when a data dependency violation is detected. Other systems simply allow transactions to commit on a first come, first served basis, addressing forward
progress through other mechanisms.
Transactional buffering and commit provide atomicity of
execution across threads at hardware speeds. A multithreaded language like Java can build on these mechanisms to provide non-blocking synchronization and mutual exclusion capabilities, as we explain in Section 3.

3.

RUNNING JAVA WITH TRANSACTIONSIn this section we explain how the concurrency featuresof the Java programming language are mapped to a transactional execution model in order to run existing Java programs with a continuous transactional execution model. In
the course of our explanation, we discuss how transactions
interact with the Java Memory Model, the Java Native Interface, non-transactional operations, and exceptions.

3.1

Mapping Java to Transactions

In this section we discuss how various existing Java constructs are mapped into transactional concepts.

synchronized blocks
When running with a transactional memory model, synchronized blocks are used to mark indivisible transactions
within a thread. Since continuous transactional hardware
runs code in transactions at all times, a synchronized block
defines three transaction regions: the divisible transactions
before the block, the indivisible transaction within the block,and the divisible transactions after the block. Similarly, accesses to volatile fields are considered to be small indivisible transactions. As an example, consider the simple
program shown in Figure 1. This program creates an indivisible transaction separated by other divisible transactions
by commit points as shown.
When synchronized blocks are nested, either within amethod or across method calls, only the outermost synchronized block defines an indivisible transaction. This isreferred to as a closed nesting model [28]. As an example,
consider the simple program shown in Figure 2. This program also creates a single indivisible transaction as shown.
Handling nested transactions is important for composability. It allows the atomicity needs of a caller and callee to behandled correctly without either method being aware of theother’s implementation. The block structured style of synchronized is fundamental to this, as it ensures that transaction begins and ends are properly balanced and nested. Simply exposing a commit method to programmers would allow
a library routine to commit arbitrarily, potentially breaking
the atomicity requirements of a caller.
While nested transactions are necessary for composability, the run-time flattening into a single transaction simplifies execution, making the common case fast. The databasecommunity has explored alternatives, including nested transactions allowing partial rollback. Evaluating the need forand implementing such alternatives is beyond the scope of
this paper.
Although synchronized blocks are used to mark indivisible transactions, the actual lock object specified is notpublic static void main(String[] args){a();synchronized(x){
b();}
c();}

a();
// divisible transactions
COMMIT();b();// indivisible transaction
COMMIT();c();// divisible transactions
COMMIT();

Figure 1: Converting a synchronized block into transactions.
public static void main(String[] args){a();synchronized(x){b1();
synchronized(y){b2();}
b3();}c();}a();// divisible transactions
COMMIT();
b1();
//
b2();
// indivisible transaction
b3();//
COMMIT();c();// divisible transactions
COMMIT();

Figure 2: Converting nested synchronized blocks into transactions.
used. That is because the continuous transactional hardware will detect any true data dependencies at runtime. Ina purely transactional variant of Java, one can imagine replacing synchronized blocks with a simpler atomic syntax
omitting the lock variable as is done in other systems [14, 3,
7]. In such a system, programmers would not need to createa mapping between shared data and the lock objects that
protect them.
The fact that the lock variables are not used points to a
key advantage of transactions over locks. In Java withouttransactions, there is not a direct link between a lock object
and the data it protects. Even well intentioned programs canmistakenly synchronize on the wrong object when accessing
data. With transactions, all data accesses are protected,
guaranteeing atomic semantics in all cases. There is no reason for basic data structures to provide any synchronization,
because the caller defines its own atomicity requirements.
Hence, programmers can write data structures without resorting to complex fine grained locking schemes to minimize
the length of critical sections.
For example, the evolution of Java collections shows how
locking can complicate one of the most basic data structureclasses: the hash table. Java’s original Hashtable used synchronized to guarantee internal consistency, which is important in a sandbox environment. However, in JDK 1.2, a simpler non-locking HashMap was introduced, since most applications needed to avoid the overhead of the implicit lockingof the original Hashtable. Recently, JDK 1.5 has complicated matters further by adding a ConcurrentHashMap thatallows multiple concurrent readers and writers.
A transactional memory model eliminates the need forthis kind of complexity in the common case. Consider thesimple string interning example in Figure 3. With transactional execution, there is no need to use anything other thanthe original simple Hashtable. Concurrent reads happen inparallel due to speculation. Even non-conflicting concurrent
writes happen in parallel. Only conflicting and concurrent
reads and writes cause serialization and this is handled automatically by the system, not the programmer.
Traditionally, users of synchronized blocks are encouraged to make them as short as possible to minimize blocking
other threads’ access to critical sections. The consequencesof making the critical section too large is that processors

often spend more time waiting and less time on useful work.
At worst, it can lead to complete serialization of work. Consider the example code in Figure 4. Because of the way thiscode is written with a synchronized block around the entire routine, a multithreaded web server becomes effectively
single threaded, with all requests pessimistically blocked on
the sessions lock even though the reads and writes are
non-conflicting. Because a transactional system can simply
optimistically speculate through the lock, it does not havethis serialization problem.

wait, notify, notifyAll
When threads need exclusive access to a resource, they use
synchronized blocks. When threads need to coordinate
their work, they use wait, notify, and notifyAll. Typically, these condition variable methods are used for implementing producer-consumer patterns or barriers.
Consider the example of a simple producer-consumer usage of wait and notifyAll derived from [6] shown in Figure 5 and in Figure 6. This code works in a non-transactional
system as follows. When a consumer tries to get the contents, it takes the lock on the container, checks for contents
to be available, and calls wait if there is none, releasing
the lock. After returning from wait, the caller has reacquired the lock but has to again check for contents to beavailable since another consumer may have taken it. Oncethe data is marked as taken, the consumer uses notifyAll
to alert any blocking producers that there is now space to
put a value. An analogous process happens for producers
with put.
In a transactional system, the get method is synchronized so the method is run as an indivisible transaction. If
there is no data available and we need to wait, we commit the transaction as if the synchronized block was closed.
This is keeping analogous to the semantics of wait releasing the lock and making updates visible. When the thread
returns from waiting, we start a new indivisible transaction.
Because we commit on wait, we also are committing statefrom any outer synchronized blocks, potentially breaking
atomicity of nested locks. One alternative considered wasusing rollback, since that would preserve the atomicity ofouter synchronized blocks and works for most producerconsumer examples. However, many commonly used pat-String intern(){synchronized(map){
Object o=map.get(this);if (o!=null){
return (String)o;}
map.put(this,this);return this;}}Figure 3: A string interning example.
synchronized int get(){while (available == false) wait();available = false;
notifyAll();
return contents;}
Figure 5: get code used by the consumer.
terns for barriers would not work with rollback. Rollback
prevents all communication, but the existing Java semantics
of wait are to release a lock and make any changes visible.
This loss of atomicity in outer synchronized blocks becauseof nesting is a common source of problems in existing Java
programs as well [35].
Fortunately, the nesting of wait in synchronized blocks
is rare, since it causes problems in existing Java programs
as well. Java programmers are advised not to place calls
to wait within nested synchronized blocks because when athread waits, it retains all but one lock while it is asleep [35].
By their very nature, condition variables are used to coordinate the high-level interactions of threads, so it is rare forthem to be used deeply in library routines. For example,
a survey of the Apache Jakarta Tomcat web server version
5.5.8 does not reveal any wait calls nested within an outersynchronized block. Tomcat does have libraries for purposes such as producer-consumer queuing that include usesof wait on an object with a corresponding synchronizedblock on the same object, but they are used only for highlevel dispatching and not called from synchronized blocks
on other objects. A further example is in SPECjbb2000,
which has one example of a barrier where committing works
and rollback would fail.
The handling of wait is the thorniest problem in the transactional execution of Java programs. If we treat wait as arollback, we have composable transactional semantics but
existing programs will not run. If we treat wait as a commit, it is easy to come up with contrived programs that will
not match the previous semantics. However we have neverseen a benchmark or system that exhibits a problem treating wait as commit. In a programming language built withtransactions in mind, the rollback semantics would makemore sense; all of the problematic examples requiring commit could be rewritten to use rollback semantics.

3.2

Impact of Transactions on JavaIn this section we discuss how transactions relate to several aspects of the Java programming language.

Java Memory ModelA new Java memory model was recently adopted to bettersupport various shared memory consistency models [1, 30,

void handleRequest(String id, String command){synchronized(sessions){
Session s=sessions.get(id);s.handle(command);sessions.put(id,s);}}Figure 4: Synchronizing on a Session object.
synchronized void put(int value){
while (available == true) wait();contents = value;available = true;
notifyAll();}Figure 6: put code used by the producer.
19]. The new model has been summarized in [14] as follows:
if a location is shared between threads, either:(i). all accesses to it must be controlled by agiven mutex, or(ii). it must be marked as volatile.
These rules, while simplified, are an excellent match fortransactional execution. The Java memory model ties communication to synchronized and volatile code. In oursystem, these same constructs are used to create indivisible
transactions working with shared data.
Run-time violation detection can be used to detect programs that violate these rules, an advantage of continuoustransactional execution with “always on” violation detection. For example, a divisible transaction might be violated,indicating that a location is shared between threads without being protected by a synchronized block or volatile
keyword. Alternatively, an indivisible transaction can be violated by divisible transaction. These typically unexpectedviolations could be logged or additional extensions could allow the program to respond to exceptional cases.

Java Native Interface
The Java Native Interface (JNI) allows Java programs tocall methods written in other programming languages, suchas C [25]. Software transactional memory systems typicallyforbid most native methods within transactions [14]. This isbecause those systems only can control the code compiled bytheir JIT compiler and not any code within native libraries.
While some specific runtime functions can be marked assafe or rewritten to be safe, this places a lot of runtimefunctionality in the non-transactional category.
This limitation of software transactional memory systems
destroys the composability and portability of Java software
components. Code within synchronized blocks cannot callmethods without understanding their implementation. For
example, an application using JDBC to access a databaseneeds to know if the driver uses JNI. Even “100% Pure Java”
drivers may use java.* class libraries that are supported bynative code. Therefore, code carefully written to work on
one Java virtual machine may not work on another system,
since the language and library specifications only consider

nativeness to be an implementation detail, and not part ofthe signature of a method.
On the other hand, hardware transactional memory systems do not suffer from this limitation, since they are sourcelanguage neutral. Transactions cover memory accesses bothby Java and native code. This allows programmers to treat
code that traverses both Java and native code together as alogical unit, without implementation-specific restrictions.

Non-transactional operations
Certain operations are inherently non-transactional, such as
I/O operations. Many transactional memory systems simply
consider it an error to perform a non-transactional operation
within a transaction. This certainly would prevent correct
execution of existing Java programs.
Continuous transactional architectures might seem to posean extra challenge because of their “all transactions, all thetime” nature. However, divisible transactions can handle
non-transactional operations by implicitly committing before the operation so there is no memory state to be violated and cause a rollback. Since these code regions do notguarantee atomicity, it is legal to freely commit their results
at any point. There are a variety of approaches to the moredifficult case of non-transactional operations in indivisible
transactions.
A simple approach is to allow only one indivisible transactions to run non-transactional operations at a time. Other
transactions that do not need to run non-transactional operations may continue to execute in parallel, but cannot
commit. Once the indivisible transactions that performed
the non-transactional operation commit, other transactions
may then commit or begin their own non-transactional operations. This approach generally works with current Java
programs. In contrast, the other, more advanced approaches
presented below require changes in applications, libraries, orthe underlying runtime. In this study we have taken thissimple approach.
Another approach to non-transactional operations is torequire that the operations be moved outside of indivisible transactions. For example, an HTTP server can read arequest from the network interface into memory, use transactions as it likes, producing a response buffered to memory,and finally write the response to the network after the transactions have committed. However, manually restructuringcode in this way is undesirable. Modular systems are built
on composable libraries. We need a general way to address
non-transactional operations without disturbing the logicalstructure of code.
A more programmer-friendly way to implement this structure is with changes to the runtime system. Non-transactional operations within indivisible transactions are recorded
at each call but only performed at commit time using transaction callbacks, a common solution in traditional databasesystems. For example, a logging interface for debugging
typically prints messages as they are received. A transactional runtime implementation could buffer the messages ina thread local variable when running in an indivisible transactional after registering a commit callback. Only when
the original, indivisible transaction commits is the callback
called to write out the buffered messages. This is a relatively simple pattern that can generally be applied to librarycode. For convenience, a reusable wrapper class can be used
for such common cases as buffering stream output. In atransactional runtime, this functionality could be built into
the standard BufferedOutputStream and BufferedWriterclasses, allowing most output code to work without modification. While commit handlers are useful for delay output,
rollback handlers can be used for some cases of reverting
input. However, with the combination of rollback handlers
and transactional memory this is problematic because when
the transaction rolls back, the registration of the handler itself could be rolled back. We will describe a possible solution
to this issue in Section 5.
There are several classes of non-transactional operations.
Most non-transactional operations are concerned with I/O.
However, some operations, such as asking for the current
time, may be deemed safe for use within transactions without being considered “non-transactional” operations. Another common non-transactional operation in our current
model is thread creation. Although alternative and more
complex models could support rolling back of thread creation, this is of little practical value. As in the above example of nesting barriers within existing transactions, it seems
better to consider thread creation a high-level operation thatrarely occurs within deep nesting of synchronized blocks.

Exceptions
We treat transactions and exceptions as orthogonal mechanisms. Most exceptions in practice are IOExceptions orRuntimeExceptions. Since we would not be able to guarantee the rollback of non-transactional operations, our exception handling follows the flow of control as expected bytoday’s Java programmers. Figure 7 illustrates an example.
If no exceptions are thrown, the code produces the transactions shown in Figure 8. On the other hand, if b2() throws
an IOException and e2() throws a RuntimeException, thecode is equivalent to Figure 9. This is exactly the same
control flow as current Java exception handling.

4.

PERFORMANCE EVALUATIONIn this section we compare the performance of existingJava programs running on a traditional multi-processor using snoopy cache coherence and the same applications converted to run on a continuous transactional multi-processor.
We discuss the Java virtual machine and simulator used forevaluation, describe the benchmarks performed, and discuss
the results.

4.1

Environment

We evaluated programs using JikesRVM with the following changes. The scheduler was changed to pin threads
to processors and not migrate threads between processors.
Methods were compiled before the start of the main program execution. The garbage collector was disabled and a
one gigabyte heap was used. When running transactionally,
synchronized blocks and methods were run transactionallyand Object.wait() was changed to perform a transaction
commit. The results focus on benchmark execution time,skipping virtual machine startup.
JikesRVM was run with an execution-driven simulator ofa PowerPC CMP system that implements the TCC continuous transaction architecture as well as MESI snoopy cachecoherence for evaluating locking [27]. All instructions, except loads and stores, have a CPI of 1.0. The memory system models the timing of the L1 caches, the shared L2 cache,and buses. All contention and queuing for accesses to cachestry {
a();synchronized(x){
b1();
b2();
b3();}
c();}catch (IOException e) {d();synchronized(y){
e1();
e2();
e3();}
f();}
finally {
g();}

a();
COMMIT();
b1();
b2();
b3();
COMMIT();c();
COMMIT();g();
COMMIT();// tryFigure 7: A try-catch constructcontaining synchronized blocks.

Figure 8: Runtime transactions
created by the non-exception
case from code in Figure 7.

//// try//// try// finallya();// tryCOMMIT();
b1();
//
b2();
// IOException
COMMIT();d();// catch
COMMIT();
e1();
//
e2();
// RuntimeException
COMMIT();g();// finally
COMMIT();

Figure 9: Runtime transactions
created by the exception casefrom code in Figure 7.

FeatureDescription

CPU
L1
Victim Cache

1–16 single-issue PowerPC cores
64-KB, 32-byte cache line, 4-way associative, 1 cycle latency
8 entries fully associative

Bus Width
Bus Arbitration
Transfer Latency

16 bytes
3 pipelined cycles
3 pipelined cycles

L2 Cache
Main Memory

8MB, 8-way, 16 cycles hit time
100 cycles latency, up to 8 outstanding transfers

Table 1: Parameters for the simulated CMP architecture. Bus width and latency parameters apply to bothcommit and refill buses. L2 hit time includes arbitration and bus transfer time.
and buses is modeled. In particular, the simulator models
the contention for the single data port in the L1 caches,
which is used for processor accesses and commits for transactions or cache-to-cache transfers for MESI. Table 1 presents
the main parameters for the simulated CMP architecture.
The victim cache is used for recently evicted data from theL1 cache.

4.2

Results

To evaluate running Java with hardware transactional
memory, we ran a collection of benchmarks, as summarizedin Table 2, using both locks and transactions. The singleprocessor version with locks is used as the baseline for calculating the percentage of normalized execution time, witha lower percentage indicating better performance. The execution time is broken down into five components. Usefultime is for program instruction execution. L1 Miss time results from stalls on loads and stores. When running withlocks, Idle/Sync time is due to the synchronization overhead. When running with transactions, Commit time isspent committing the write-set to shared memory, and Violation time is the time wasted from data dependency violations.
The micro-benchmarks are based on recent transactional
memory papers from Hammond [11] and Harris [14]. For aserver benchmark we included SPECjbb2000 [38], while fornumerical benchmarks we included the multi-thread Java

Grande kernels and applications [18]. For each benchmark,we provide a description of its conversion to transactions.

TestHistogram
TestHistogram is a micro-benchmark to demonstrate transactional programming from Hammond [11]. Random numbers between 0 and 100 are counted in bins. When runningwith locks, each bin has a separate lock to prevent concurrent updates. When running with transactions, each update
to a bin is one transaction.
Figure 10 shows the results from TestHistogram. Whilethe locking version does exhibit scalability over the single processor baseline, the minimal amount of computation
results in significant overhead for acquiring and releasing
locks, which dominates time spent in the application. The
transactional version eliminates the overhead of locks anddemonstrates scaling to 8 CPUs; transactions allow optimistic speculation while locks caused pessimistic waiting.
However, at 16 CPUs the performance of the transactionalversion levels off, because data dependency violations start
to become more frequent with this number of bins.

TestHashtable
TestHashtable is a micro-benchmark that compares different java.util.Map implementations. Multiple threads contend for access to a single Map instance. The threads run a
mix of 50% get and 50% put operations. We vary the num-Benchmark
TestHistogram
TestHashtable
TestCompound
SPECjbb2000
Series
LUFactCrypt
SOR
SparseMatmult
MolDynMonteCarlo
RayTracer

Description
create histogram of student test scores
multithreaded Map read and write
multithreaded Map value swaps
Java Business Benchmark
Fourier series
LU factorization
IDEA encryption
sucessive over relaxation
sparse matrix multiplication
N-body molecular dynamics
financial simulation
3D ray tracer

SourceHammond [11]Harris [14]Harris [14]SPEC [38]Java Grande [18]Java Grande [18]Java Grande [18]Java Grande [18]Java Grande [18]Java Grande [18]Java Grande [18]Java Grande [18]Input
80,000 scores
4,000 get(), 4,000 put()
8,000 swaps
368 transactions
100 coefficients
500x500 matrix
300,000 bytes
100x100 grid
5000x5000 matrix
256 particles, 10 iterations
160 runs
16x16 image

Table 2: Summary of benchmark applications
ber of processors and measure the speedup attained over the
single processor case.
When running with locks, we run the original synchronized Hashtable, a HashMap synchronized using the Collections class’s synchronizedMap method, and a ConcurrentHashMap from util.concurrent Release 1.3.4 [24]. Hashtable and HashMap use a single mutex, while ConcurrentHashMap uses finer grained locking to support concurrent
access. When running with transactions, we run each HashMap
operation within one transaction.
Figure 11 shows the results from TestHashtable. The
results using locks for Hashtable (HT) and HashMap (HM)show the problems of scaling when using a simple critical section on traditional multi-processors. The synchronizedMap
version of HashMap actually slows down as more threads areadded while Hashtable only gets a very small improvement
up to 8 processors and a slowdown at 16 processors. While
ConcurrentHashMap (CHM Fine) shows that fine-grained
locking implementation is scalable, this implementation requires significant complexity. With transactions, we can use
the simple HashMap with the same critical region as ConcurrentHashMap and achieve similar performance.

TestCompound
TestCompound is a micro-benchmark that compares the same
Map implementations as TestHashtable. Again the threads
contend for access to a single object instance, but this time
instead of performing a single atomic operation on the sharedinstance, they need to perform four operations to swap thevalues of two keys. We perform two experiments that demonstrate both low-contention and high-contention scenarios:
the low-contention case uses a 256 element table and thehigh-contention case uses an 8 element table.
We use the same basic Map implementations as with TestHashtable. For Hashtable and HashMap, our critical sectionuses the Map instance as the lock. For ConcurrentHashMap,
we use two variations of the benchmark representing coarsegrained locking and fine-grained locking. The coarse-grained
locking variation uses the Map instance as a lock, as with
Hashtable and HashMap. The fine-grained locking variation
uses the keys of the values being swapped as locks, being
careful to order the acquisition of the locks to avoid deadlock.
The left side of Figure 12 shows the results of TestCompound with low contention for locks. Again, running
Hashtable and HashMap with simple locking show the prob-

lems of simple locking in traditional systems. Furthermore,
the coarse-grained version of ConcurrentHashMap (CHM Coarse)
demonstrates that simply getting programmers to use data
structures designed for concurrent access is not sufficient tomaximize application performance. With locking, the application programmer must understand how to use fine-grained
locking in their own application to properly take advantage
of such data structures. As we continue to increase the number of threads, these applications with coarse-grained locks
do not continue to scale, and, as shown, often perform worse
than the baseline case. Only fine-grained version of ConcurrentHashMap compares favorably with transactions. Transactions have a performance advantage due to speculation.
More importantly, transactions are able to beat the performance of fine-grained locks using only the most straightforward code consisting of a single synchronized block andthe unsynchronized HashMap. Hence, transactions allow programmers to write simple code focused on correctness that
performs better than complex code focused on performance.
The right side of Figure 12 shows the results of TestCompound with high contention for locks. The locking version of Hashtable, HashMap, and coarse-grained ConcurrentHashMap all perform similarly to the low contention case.
Fine-grained ConcurrentHashMap and transactional performance are both degraded from the low-contention case because of lock contention and data dependency violations.
However, in this especially tough case, transactions manage
to beat out locks by the largest margin seen in all of theseresults.

SPECjbb2000
SPECjbb2000 is a server-side Java benchmark, focusing on
business object manipulation. I/O is limited, with clients
replaced by driver threads and database storage replacedwith in-memory binary trees. The main loop iterates over
five application transaction types: new orders, payments, order status, deliveries, and stock levels. New orders and payments are weighted to occur ten times more often than othertransactions and the actual order of transactions is randomized. We ran using the default configuration that varies thenumber of threads and warehouses from 1 to 16, although wemeasured for a fixed number of 368 application-level transactions instead of a fixed amount of wall clock time. The
first part of Figure 13 shows the results from SPECjbb2000.
Both locking and transactional versions show linear speedup
in all configurations because there is very little contention

CHM Fine-2

low contention

Figure 12: TestCompoundhigh contention

200

150

100

50

0

CHM Fine-8

HT-8

HM-8

Trans. HM-16

Trans. HM-16

CHM Fine-16

CHM Coarse-16

CHM Fine-16

HT-16

Commit/Communication

HT-16

HM-16

HM-16

250

Trans. HM-8

Violation

CHM Fine-8

Figure 11: TestHashtable

Trans. HM-8

CHM Coarse-8

HT-8

HM-8

Trans. HM-4

Trans. HM-4

CHM Fine-4

HT-4

HM-4

CHM Fine-2

Idle/Sync

CHM Fine-4

Commit/Communication

CHM Coarse-4

HT-4

HM-4

160

140

120

100
80

60

40

20
0

Trans. HM-2

180

HT-2

200
L1MissTrans. HM-2

Idle/Sync

HT-2

Figure 10: TestHistogram

CHM Coarse-2

L1Miss

HM-2

0

HM-2

10

CHM Fine-16

20

Trans. HM-16

30

HT-16

40

Normalized Execution Time (%)

50

CHM Coarse-16

Trans.-16

Locks-16

Trans.-8

Locks-8

Trans.-4

Locks-4

Trans.-2

Locks-2

Normalized Execution Time (%)
60

HM-16

Trans. HM-8

UsefulCHM Fine-8

CHM Coarse-8

HT-8

HM-8

Trans. HM-4

CHM Fine-4

CHM Coarse-4

HT-4

HM-4

Trans. HM-2

CHM Fine-2

CHM Coarse-2

HT-2

HM-2

Normalized Execution Time (%)

Violation
Commit/Communication
Idle/Sync
L1MissUsefulUsefulViolation

Normalized Execution Time (%)
40

35

30

25

20

15

10

5

0
Locks-2
Trans.-2
Locks-4
Trans.-4
Locks-2
Trans.-2
Locks-4
Trans.-4
Locks-2
Trans.-2
Locks-4
Trans.-4
Locks-2
Trans.-2
Locks-4
Trans.-4
Locks-2
Trans.-2
Locks-4
Trans.-4
Locks-2
Trans.-2
Locks-4
Trans.-4
Locks-2
Trans.-2
Locks-4
Trans.-4
Locks-2
Trans.-2
Locks-4
Trans.-4

SparseMatmult
LUFactCrypt
SOR
MolDynMonteCarlo
RayTracer

Locks-8
Trans.-8
Locks-16
Trans.-16

Locks-8
Trans.-8
Locks-16
Trans.-16

Locks-8
Trans.-8
Locks-16
Trans.-16

Locks-8
Trans.-8
Locks-16
Trans.-16

Locks-8
Trans.-8
Locks-16
Trans.-16

Locks-8
Trans.-8
Locks-16
Trans.-16

Locks-8
Trans.-8
Locks-16
Trans.-16

SPECjbb2000
SeriesLocks-8
Trans.-8
Locks-16
Trans.-16

Locks-2
Trans.-2
Locks-4
Trans.-4

45
SPECjbb2000

Locks-8
Trans.-8
Locks-16
Trans.-16

Normalized Execution Time (%)

UsefulL1MissIdle/Sync
Commit/Communication
Violation

70

60

50

40

30

20

10

0

SeriesSparseMatmult

LUFactCrypt

SOR

MolDynMonteCarlo

RayTracer

Figure 13: SPECjbb2000 and Java Grande benchmarks. Series, SparseMatmult, LUFact, Crypt, SOR are Java
Grande section 2 kernels. MolDyn, MonteCarlo, RayTracer are Java Grande section 3 applications.

between warehouse threads. However, the locking version
is slightly slower in all cases because it must still pay thelocking overhead to protect itself from the 1% chance of aninter-warehouse order. Most importantly, the transactionalversion of SPECjbb2000 did not need any manual changes toachieve these results; automatically changing synchronizedblocks to transactions and committing on Object.wait()
was sufficient.

Java GrandeJava Grande provides a representative set of multithreaded
kernels and applications. These benchmarks are often Java
versions of benchmarks available in C or Fortran from suites
such as SPEC CPU, SPLASH-2, and Linpack. We ran with
the input sizes shown in Table 2.
The next five parts of Figure 13 show the results fromthe Java Grande section 2 kernel programs. These highlytuned, lock-based kernels show comparable scaling when run
with transactions. The transactional versions of Series
and SparseMatmult initially are slightly slower because ofcommit overhead, but as the number of threads increases,
lock contention becomes a factor for the version with locks.
Transactions and locks perform equally well on LUFact and
Crypt, with lock contention and violations having comparable cost as threads are added. The transactional version of
SOR has similar scaling to the lock-based version, with only
minimal relative slowdown due to violations.
The final three parts of Figure 13 show the results fromthe Java Grande section 3 application programs. MolDyn
has limited scalability for both locks and transactions, withlock overhead being slightly less performance limiting thantime lost to violations. MonteCarlo exhibits scaling withboth locks and transactions, but similar to TestHistogram,transactions have better absolute performance because of
the overhead cost of locking. RayTracer is similar to thekernels Series and SparseMatmult, with locks performing
better with fewer processors and transactions performing
better as the number of threads is increased.
Unlike SPECjbb2000, some minor source changes werenecessary to achieve these results. LUFact, MolDyn, RayTracer all use a common TournamentBarrier class that does
not use synchronized blocks. Each thread that enters thebarrier writes to indicate its progress and then busy waits
to continue. With transactions, it was necessary to place
the write within a synchronized block before busy-waiting,for otherwise all threads loop forever, believing they are theonly one to have reached the barrier. SOR has the same problem in its own barrier code; again adding a synchronizedblock around the assignment in its barrier code solved the
problem. Note that these changes were necessary because
the programs did not follow the Java Memory Model rules
presented in Section 3.2. We did not find any programs thatneeded changes beyond those to comply with these rules.

5.

RELATED WORK

Recent transactional hardware proposals build on earlier hardware transactional memory work as well as threadlevel speculation (TLS). Java programming with transactions builds on earlier work on speculating through locks
and transactional memory in general.

5.1

Hardware Transactional Memory

Knight first proposed using hardware to detect data racesin the parallel execution of implicit transactions found in
mostly functional programming languages such as Lisp [21].
Herlihy and Moss proposed transactional memory as a generalized version of load-linked and store-conditional, meant
for replacing short critical sections [16]. Recent proposals
such as TCC, UTM, and VTM have relieved earlier data
size restrictions on transactions, allowing the developmentof continuous transactional models [13, 4, 33]. Thread-level
Speculation (TLS) uses hardware support to allow speculative parallelization of sequential code [12, 23, 37, 39]. In
particular, Chen and Olukotun proposed a system for Java
that allowed automatic parallelization of loops using a profile driven JIT compiler on TLS hardware [8].
From the hardware perspective, these earlier systems generally layered speculative execution on top of a conventional
cache coherence and consistency protocol. TLS systems allowed speculative threads to communicate results to otherspeculative threads continuously. In contrast, TCC completely replaces the underlying coherence and consistency
protocol, and allows transactions to make their write statevisible only at commit time, which should generally make it
scalable to larger numbers of processors.
From a programming model perspective, earlier hardware
transactional memory systems did not allow program control over transaction order. TLS systems allow only ordered
execution [29]. TCC allows unordered and ordered transactions, including the use of both models simultaneously.

5.2

Speculating Through Locks

Rajwar and Goodman proposed Speculative Lock Elision(SLE) [32]. SLE speculates through lock acquisition, allowing concurrent execution using hardware support. If a data
dependency is detected, all involved processors roll back.
Later, Rajwar and Goodman extended SLE to create Transactional Lock Removal (TLR) which used timestamps to
avoid rolling back all processors, giving priority to the oldest outstanding work [31].
Martı́nez and Torrellas proposed Speculative Synchronization [26] based on TLS hardware. It supports speculating
not just through locks, but also barriers and flags. Thesesystems have the concept of a safe thread that is non-speculative, and that thread has priority when data dependencies
are detected, similar to TLR’s use of the oldest timestamp.
SLE, TLR, and Speculative Synchronization build upon
conventional cache coherence and consistency, such as early
hardware transactional memory and TLS. As such, they do
not detect run-time races outside of critical regions like continuous transactional hardware does. They always commit
in order of transaction creation, providing no way for the
programmer to specify the desire for unordered transactions.

5.3

Software Transactional Memory

Shavit and Touitou first proposed a software-only approach
to transactional memory, but it was limited to static transactions where the data set is known in advance, such as
k-word compare-and-swap [36]. Herlihy et al. overcame thisstatic limitation with their dynamic software transactional
memory work, which offered a Java interface through library calls [17]. Harris and Fraser provide language support
for software transactional memory, allowing existing Java
code to run as part of a transaction and providing an effi-cient implementation of Hoare’s conditional critical regions(CCRs) [14]. Welc et al. provide transactional monitors inJava through JikesRVM compiler extensions, treating Object.wait() as a thread yield without committing [42].
Unlike Shavit and Touitou, later proposals support dynamic transactional memory. Unlike Herlihy et al. Harris and Fraser can run unmodified code within transactions.
Unlike Harris and Fraser, hardware transactions can run
both Java and native code within a transaction as well support non-transactional operations within atomic regions. Unlike Welc et al. our proposal can run code containing conditional variables such as barriers that require communication
on Object.wait().
Harris et al. later explored integrating software transactional memory with Concurrent Haskell [15]. Haskell is amostly functional programming language where most memory operations do not need to be part of rollback state.
Haskell’s type system identifies I/O operations as part ofsignatures. This allows static checking for non-transactional
operations with atomic regions. This work extends the earlier CCR work by allowing an atomic region to block on
multiple complex conditions in a composable way.
Vitek et al. have created a calculus for Transaction Featherweight Java (TFJ) to study the semantics of adding transactions to a programming language. They provide soundness and serializability proofs for both an optimistic concurrency model and a two-phase locking protocol [40].
The advantages of hardware transactional memory oversoftware-only versions are performance and language transparency. Software transactional systems encourage small
critical sections because of the instruction overhead of maintaining each transaction’s data dependencies. Also, runninga program consisting entirely of transactions would be prohibitively slow with software transactional memory. Current
transactional memory systems, both hardware and software,
do not require the programmer to identify which loads andstores are to shared memory. However, for software transactional memory this requires compiler support, preventing
transactional code from using mechanisms such as JNI for
calling output from non-transactional compilers and hindering reuse of existing code.

6.

CONCLUSIONSContinuous transactional models promise to simplify writing of new parallel applications, but they can also be applied
to parallelize today’s programs. We have shown that conventional Java language constructs for identifying criticalregions can be used to run these existing programs transactionally with minimal changes to applications. We havedemonstrated that a continuous transactional system candeliver performance equal to or better than a lock-based
implementation using the same programmer-defined criticalregions. We also showed that simple, coarse-grained transactions can perform as well as fine-grained locking, demonstrating both the potential for simplified parallel programming and the increased performance of existing applications
implemented using coarse-grained locking. The combinationof good performance on conventional Java concurrency constructs, combined with the potential for simpler code thattransactions offer, provides a foundation for easing the taskof parallel software development.

7.

ACKNOWLEDGMENTS

This research was sponsored by the Defense Advanced
Research Projects Agency (DARPA) through the Department of the Interior National Business Center under grant
number NBCH104009. The views and conclusions containedin this document are those of the authors and should not
be interpreted as representing the official policies, either
expressed or implied, of the Defense Advanced Research
Projects Agency (DARPA) or the U.S. Government.
Additional support was also available through NSF grant0444470. Brian D. Carlstrom is supported by an Intel Foundation PhD Fellowship.

8.

REFERENCES[1] S. V. Adve and K. Gharachorloo. Shared memory
consistency models: A tutorial. IEEE Computer,29(12):66–76, December 1996.
[2] V. Agarwal, M. S. Hrishikesh, S. W. Keckler, and
D. Burger. Clock rate versus IPC: the end of the roadfor conventional microarchitectures. In Proceedings ofthe 27th Annual International Symposium on
Computer Architecture, pages 248–259, 2000.
[3] E. Allen, D. Chase, V. Luchangco, J.-W. Maessen,
S. Ryu, G. L. S. Jr., and S. Tobin-Hochstadt. The
Fortress Language Specification. Sun Microsystems,
2005.
[4] S. Ananian, K. Asanovic, et al. Unboundedtransactional memory. In Proceedings of the 11th
International Symposium on High Performance
Computer Architecture, February 2005.
[5] The Broadcom BCM-1250 Multiprocessor. Technicalreport, Broadcom Corporation, April 2002.
[6] M. Campione, K. Walrath, and A. Huml. The Java
Tutorial. Addison-Wesley Professional, third edition,
January 2000.
[7] P. Charles, C. Donawa, K. Ebcioglu, C. Grothoff,
A. Kielstra, C. von Praun, V. Saraswat, and
V. Sarkar. X10: An object-oriented approach to
non-uniform cluster computing. In OOPSLA ’05:
Proceedings of the 20th annual ACM SIGPLAN
conference on Object-oriented programing, systems,
languages, and applications. ACM Press, 2005.
[8] M. K. Chen and K. Olukotun. The Jrpm system for
dynamically parallelizing java programs. In
Proceedings of the 30th International Symposium on
Computer Architecture, pages 434–445, June 2003.
[9] C. Flanagan. Atomicity in multithreaded software. In
Workshop on Transactional Systems, April 2005.
[10] M. Garzaran, M. Prvulovic, et al. Tradeoffs inbuffering multi-version memory state for speculative
thread-level parallelization in multiprocessors. In
Proceedings of the 9th International Symposium on
High Performance Computer Architecture, February
2003.
[11] L. Hammond, B. D. Carlstrom, V. Wong,
B. Hertzberg, M. Chen, C. Kozyrakis, andK. Olukotun. Programming with transactional
coherence and consistency. In Proceedings of the 11th
International Conference on Architecture Support for
Programming Languages and Operating Systems, Oct.
2004.
[12] L. Hammond, B. Hubbert, M. Siu, M. Prabhu,
M. Chen, and K. Olukotun. The Stanford HydraCMP. IEEE MICRO Magazine, March–April 2000.
[13] L. Hammond, V. Wong, M. Chen, B. D. Carlstrom,
J. D. Davis, B. Hertzberg, M. K. Prabhu, H. Wijaya,
C. Kozyrakis, and K. Olukotun. Transactional
memory coherence and consistency. In Proceedings ofthe 31st International Symposium on Computer
Architecture, pages 102–113, June 2004.
[14] T. Harris and K. Fraser. Language support forlightweight transactions. In OOPSLA ’03: Proceedingsof the 18th annual ACM SIGPLAN conference on
Object-oriented programing, systems, languages, andapplications, pages 388–402. ACM Press, 2003.
[15] T. Harris, S. Marlow, S. P. Jones, and M. Herlihy.
Composable memory transactions. In Proceedings of
the Principles and Practice of Parallel Programming,
July 2005.
[16] M. Herlihy and J. E. B. Moss. Transactional memory:
Architectural support for lock-free data structures. In
Proceedings of the 20th International Symposium on
Computer Architecture, pages 289–300, 1993.
[17] M. P. Herlihy, V. Luchangco, M. Moir, and W. M.
Scherer. Software transactional memory for
dynamic-sized data structures. In Proceedings of the
22nd Annual Symposium on Principles of Distributed
Computing, July 2003.
[18] Java Grande Forum, Java Grande Benchmark Suite.
http://www.epcc.ed.ac.uk/javagrande/, 2000.
[19] Java Specification Request (JSR) 133: Java Memory
Model and Thread Specification, September 2004.
[20] R. Kalla, B. Sinharoy, and J. Tendler. Simultaneous
multi-threading implementation in POWER5. In
Conference Record of Hot Chips 15 Symposium,
Stanford, CA, August 2003.
[21] T. Knight. An architecture for mostly functional
languages. In Proceedings of the 1986 ACM Conferenceon Lisp and Functional Programming, August 1986.
[22] P. Kongetira, K. Aingaran, and K. Olukotun. Niagara:
A 32-way multithreaded Sparc processor. IEEE
MICRO Magazine, 25(2):21–29, March-April 2005.
[23] V. Krishnan and J. Torrellas. A chip multiprocessor
architecture with speculative multithreading. IEEE
Transactions on Computers, Special Issue on
Multithreaded Architecture, September 1999.
[24] D. Lea. package util.concurrent.
http://gee.cs.oswego.edu/dl, May 2004.
[25] S. Liang. Java Native Interface: Programmer’s Guide
and Reference. Addison-Wesley Longman Publishing
Company, Inc., 1999.
[26] J. Martinez and J. Torrellas. Speculativesynchronization: Applying thread-level speculation toparallel applications. In Proceedings of the 10th
International Conference on Architectural Support for
Programming Languages and Operating Systems,
October 2002.
[27] A. McDonald, J. Chung, H. Chafi, C. Cao Minh, B. D.
Carlstrom, L. Hammond, C. Kozyrakis, andK. Olukotun. Characterization of tcc on
chip-multiprocessors. In Proceedings of the 14th
International Conference on Parallel Architectures andCompilation Techniques, September 2005.
[28] J. E. B. Moss. Nested Transactions: An Approach to

Reliable Distributed Computing. MIT Press, March
1985.
[29] M. K. Prabhu and K. Olukotun. Using thread-level
speculation to simplify manual parallelization. In
Proceedings of the Principles and Practice of Parallel
Programming, pages 1–12, 2003.
[30] W. Pugh. The Java memory model is fatally flawed.
Concurrency - Practice and Experience,
12(6):445–455, 2000.
[31] R. Rajwar and J. Goodman. Transactional lock-free
execution of lock-based programs. In Proceedings ofthe 10th International Conference on Architectural
Support for Programming Languages and Operating
Systems, October 2002.
[32] R. Rajwar and J. R. Goodman. Speculative lockelision: enabling highly concurrent multithreaded
execution. In MICRO 34: Proceedings of the 34th
annual ACM/IEEE international symposium on
Microarchitecture, pages 294–305. IEEE Computer
Society, 2001.
[33] R. Rajwar, M. Herlihy, and K. Lai. Virtualizing
transactional memory. In Proceedings of the 32nd
International Symposium on Computer Architecture,
June 2005.
[34] R. Raman. UltraSparc Gemini: Dual CPU processor.
In Conference Record of Hot Chips 15 Symposium,
Palo Alto, CA, August 2003.
[35] B. Sandén. Coping with Java threads. IEEE
Computer, 37(4):20–27, 2004.
[36] N. Shavit and S. Touitou. Software transactional
memory. In Proceedings of the 14th Annual ACM
Symposium on Principles of Distributed Computing,pages 204–213, Ottawa, Canada, August 1995.
[37] G. Sohi, S. Breach, and T. Vijaykumar. Multiscalar
processors. In Proceedings of the 22nd Annual
International Symposium on Computer Architecture,pages 414–425, June 1995.
[38] Standard Performance Evaluation Corporation,
SPECjbb2000 Benchmark .
http://www.spec.org/jbb2000/, 2000.
[39] J. Steffan and T. Mowry. The potential for using
thread-level data speculation to facilitate automaticparallelization. In Proceedings of the FourthInternational Symposium on High-Performance
Computer Architecture, Las Vegas, Nevada, 1998.
[40] J. Vitek, S. Jagannathan, A. Welc, and A. L. Hosking.
A semantic framework for designer transactions. In
D. A. Schmidt, editor, Proceedings of the European
Symposium on Programming, volume 2986 of Lecture
Notes in Computer Science, pages 249–263.
Springer-Verlag, 2004.
[41] D. W. Wall. Limits of instruction-level parallelism. In
ASPLOS-IV: Proceedings of the fourth international
conference on Architectural support for programming
languages and operating systems, pages 176–188. ACM
Press, 1991.
[42] A. Welc, S. Jagannathan, and A. L. Hosking.
Transactional monitors for concurrent objects. In
M. Odersky, editor, Proceedings of the European
Conference on Object-Oriented Programming, volume
3086 of Lecture Notes in Computer Science, pages
519–542. Springer-Verlag, 2004.