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.
![](https://img.haomeiwen.com/i14754391/b0a76b3ca1f1a374.png)
API Sample
![](https://img.haomeiwen.com/i14754391/25179791c46004fe.png)
Operation Atomicity
![](https://img.haomeiwen.com/i14754391/46b5e99ef9d3c376.png)
ConcurrentHashMap
![](https://img.haomeiwen.com/i14754391/8fbafd486901496a.png)
JMM NatureAccessAtomicity
![](https://img.haomeiwen.com/i14754391/1ba7b1cff48b2f81.png)
JMM UnNatureAccessAtomicity
![](https://img.haomeiwen.com/i14754391/120ccf048181d826.png)
JMM Sample Word Tearing
![](https://img.haomeiwen.com/i14754391/ee62f512086722a4.png)
JMM Sample Coherence
![](https://img.haomeiwen.com/i14754391/32bcaafbcd3b1519.png)
JMM Sample Partial Order
![](https://img.haomeiwen.com/i14754391/602e668c0e47b607.png)
JMM Sample Total Order
![](https://img.haomeiwen.com/i14754391/5c46a3093534a9bf.png)
JMM Sample Finals
![](https://img.haomeiwen.com/i14754391/e534c0397622f81c.png)
网友评论