Java Concurrent Stress Test

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

Reference

OpenJDK jcstress wiki

Jcstress samples

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容