The Java Concurrency Stress tests (jcstress) is an experimental harness and a suite of tests to aid the research in the correctness of concurrency support in the JVM, class libraries, and hardware.
All source code is available at github.
How to run jstress test
- Create jcstress maven project
[yunpxu@yunpxu-mac IdeaProjects]$ mvn archetype:generate \
-DinteractiveMode=false \
-DarchetypeGroupId=org.openjdk.jcstress \
-DarchetypeArtifactId=jcstress-java-test-archetype \
-DarchetypeVersion=0.5 \
-DgroupId=com.jcst \
-DartifactId=jcst \
-Dversion=1.0
- Import jcstress-samples
<dependency>
<groupId>org.openjdk.jcstress</groupId>
<artifactId>jcstress-samples</artifactId>
<version>${jcstress.version}</version>
</dependency>
- Clean Package
[yunpxu@yunpxu-mac IdeaProjects]$ cd jcst/
[yunpxu@yunpxu-mac jcst]$ mvn clean package
- Jstress help
java -jar target/jcstress.jar -h
- List jstress test with full class name match APISample
java -jar target/jcstress.jar -t APISample -l
- Run jstress test with full class name match ConcurrencyTest
[yunpxu@yunpxu-mac jcst]$ java -jar target/jcstress.jar -t ConcurrencyTest
- Run all jstress tests
[yunpxu@yunpxu-mac jcst]$ java -jar target/jcstress.jar
- Check jcst results
[yunpxu@yunpxu-mac jcst]$ tree
.
├── jcst.iml
├── jcstress-results-2019-03-19-17-31-42.bin.gz
├── pom.xml
├── results
├── com.jcst.ConcurrencyTest.html
└── index.html
Concepts
- JCStressTest
Mark the class as JCStress test. - Description
@Description("Sample Hello World test")
- Ref
@Ref("http://openjdk.java.net/projects/code-tools/jcstress/")
- JCStressMeta
@JCStressMeta(APISample_05_SharedMetadata.class)
Inherit Description, Outcome and Ref etc.. from the pointed class - Mode.Continuous
Run multiple Actor/Arbiter threads - Mode.Termination
Run a single Actor thread - Outcome
Describes the test outcome, and how to deal with it.
@Outcome(id = "1, 1", expect = Expect.ACCEPTABLE, desc = "")
@Outcome(id = "1, 2", expect = Expect.ACCEPTABLE_INTERESTING, desc = "")
@Outcome(id = "2, 1", expect = Expect.FORBIDDEN, desc = "")
- State
It annotates the class that holds the data mutated/read by the tests. - Actor
Actor method is executed by multiple threads. - Arbiter
Arbiter method is executed after Actor, memory effects from Actor are visible to Arbiter. - Signal
Signal method deliver a termination signal to a running Actor.
JCST Samples
You can check the sample source code from here.
You can run all the jcst samples with java -jar target/jcstress.jar
, this may take about 30mins.
Environment and Test Configurations.png
API Sample
API Sample.png
Operation Atomicity
Concurrency Sample Operation Atomicity.png
ConcurrentHashMap
Concurrency Sample ConcurrentHashMap.png
JMM NatureAccessAtomicity
JMM Nature Access Atomicity.png
JMM UnNatureAccessAtomicity
JMM UnNature Access Atomicity.png
JMM Sample Word Tearing
Word Tearing.png
JMM Sample Coherence
Coherence.png
JMM Sample Partial Order
Partial Order.png
JMM Sample Total Order
Total Order.png
JMM Sample Finals
Finals.png