RacerAJ (for race detection)
RacerAJ is an AspectJ based implementation of the Racer algorithm, a variant of Eraser. It allows you to detect data races in Java and AspectJ programs at runtime. The implementation of RacerAJ is based on three novel pointcuts that we implemented as an extension to the AspectBench Compiler.
- lock()matches whenever one enters a synchronized block or synchronized method
- one can use lock() && args(l) to expose the lock l to the advice
- unlock()matches whenever one exits a synchronized block or synchronized method
- one can use unlock() && args(l) to expose the lock l to the advice
- maybeShared(), a “semantic pointcut,” matches any field access (set or get), but only those that may be accessing shared fields; in particular we apply a static thread-local objects analysis to make it match on as few unshared field accesses as possible – this can speed up runtime evaluation
The ajc compiler also supports the first two pointcuts if you give it the –Xjoinpoints:synchronization option. However, the maybeShared() pointcut only exists in the latest version of abc.
Using RacerAJ to find races in your programs
To apply RacerAJ to your Java or AspectJ program download one of the following packages.
- RacerAJ version 1.0 (ZIP file, released May 8th, 2008, GPL3)
This is the version described in our ISSTA 2008 paper, which won an ACM Distinguished Paper Award.
- RacerAJ version 2.0 (ZIP file, released May 9th, 2012, GPL3)
This is the version described in our TSE paper. Opposed to the 1.0 version, this one supports a sound modeling of Thread.start() events.
This package contains a src folder holding all aspects and classes that implement RacerAJ. RacerAJ consists mainly of the following two aspects:
- Locking.aj – this file keeps track of lock sets
- Racer.aj – this aspect keeps tracks of (potentially shared) field accesses and implements the main logic
Furthermore, the download package contains a current version of the abc compiler that implements the three new pointcuts mentioned above.
Compilation with abc
To compile your programs with abc, and to enable these new pointcuts you have to pass the following arguments to abc:
… -ext abc.ja.eaj -debug enableLockPointcuts -sourceroots src:yourSourceFolder1:yourSourceFolder2 -outjar out.jar
The flag “-ext abc.ja.eaj” tells abc to use the new JastAdd based frontend, which supports Java 5 syntax. The flag “-debug enableLockPointcuts” tells abc to enable the lock() and unlock() pointcuts. By default they are disabled to avoid “keyword stealing”. The other arguments tell abc to include RacerAJ’s source folder “src” and you own source folders, and the JAR file in which abc should put the woven classes.
Enabling static optimization of maybeShared()
By default abc will consider maybeShared() be always true, i.e. the pointcut will match any field set or get. to enable our static whole-program optimizations, use the following additional argument:
For more help on abc command line options, please consult this document.
Compilation with ajc
You can also compile RacerAJ with ajc if you like. The only problem is that ajc does not support the maybeShared() pointcut. Therefore you have to add the following definition to the Racer.aj file:
pointcut maybeShared(): if(true);
This will just make ajc assume that all field accesses may be shared. This is has the same effect as using abc without giving the “-debug optimizeMaybeSharedPointcut” option.
To enable lock() and unlock() pointcuts in ajc, pass this command line option:
(If you use AJDT in Eclipse, you can set the option in the project’s preferences.)
Furthermore you have to make sure that abc-runtime.jar from the above distribution is on your classpath. This is because RacerAJ makes use of WeakIdentityHashMaps that are part of this library.
To run your program with RacerAJ enabled, simply run the woven binary with abc-runtime.jar on your classpath. If and when RacerAJ detects a race it will give you output as follows, indicating a data race on the field shared in this example code:
========================== Race condition found! Field 'static int Task.shared' is accessed unprotected. Owner object: 1743665428 ========================== ca.mcgill.sable.racer.Read at Task.java:7 ca.mcgill.sable.racer.Write at Task.java:7 --------------------------
Using lock(), unlock() and maybeShared() pointcuts for your own algorithms
We designed our extension to abc specifically in such a way that other researchers could use it to implement their own race detection, deadlock detection and I don’t know what algorithms using these novel pointcuts. Simply use the same command line shown above and have fun with the language extension!
The pointcuts are already contained in abc version 1.3.0, however only in the package “abc.eaj”, which supports Java 1.4 syntax. For Java 5 support you have to use “abc.ja.eaj”, contained in abc-complete.jar in the above download package.