Skip to content

reyerizo/jcstress-gradle-plugin

Repository files navigation

Jcstress Gradle Plugin

Maven Status Build Status Coverage Status License

This plugin integrates The Java Concurrency Stress tests with Gradle.

Usage

  1. Add the following to your build.gradle:

build.gradle:

plugins {
    id "io.github.reyerizo.gradle.jcstress" version "0.8.15"
}
  1. Put your tests in jcstress sourceset:
/src/jcstress/java       // <--- JCStress code goes here
/src/jcstress/resources  // <--- Resources go here

/src/main/java           // <--- The rest of the app
/src/main/resources      // <--- The rest of the app
  1. for reference, check the sample project:

https://github.com/reyerizo/jcstress-example

Tasks

Execute your tests with the following:

gradle jcstress

or a subset of your tests:

gradle jcstress --tests "MyFirstTest|MySecondTest"

The latter is an equivalent of regexp option below.

Configuration

If you need to customize the configuration, add a block like the following to configure the plugin:

jcstress {
    verbose = true
    timeMillis = "200"
    spinStyle = "THREAD_YIELD"
}

These are all possible configuration options:

Name Description
affinityMode Use the specific affinity mode, if available. NONE = No affinity whatsoever; GLOBAL = Affnity for the entire JVM; LOCAL = Affinity for the individual actors.
cpuCount Number of CPUs to use. Defaults to all CPUs in the system. Reducing the number of CPUs limits the amount of resources (including memory) the run is using.
heapPerFork Java heap size per fork, in megabytes. This affects the stride size: maximum footprint will never be exceeded, regardless of min/max stride sizes.
forkMultiplier "Fork multiplier for randomized/stress tests. This allows more efficient randomized testing, as each fork would use a different seed."
forks Should fork each test N times. Must be 1 or higher.
iterations Iterations per test.
jvmArgs Use given JVM arguments. This disables JVM flags auto-detection, and runs only the single JVM mode. Either a single space-separated option line, or multiple options are accepted. This option only affects forked runs.
jvmArgsPrepend Prepend given JVM arguments to auto-detected configurations. This option only affects forked runs."
mode Test mode preset: sanity, quick, default, tough, stress.
regexp Regexp selector for tests.
reportDir Target destination to put the report into.
spinStyle Busy loop wait style. HARD = hard busy loop; THREAD_YIELD = use Thread.yield(); THREAD_SPIN_WAIT = use Thread.onSpinWait(); LOCKSUPPORT_PARK_NANOS = use LockSupport.parkNanos().
splitPerActor Use split per-actor compilation mode, if available.
strideCount Internal stride count per epoch. Larger value increases cache footprint.
strideSize Internal stride size. Larger value decreases the synchronization overhead, but also reduces the number of collisions.
timeMillis Time to spend in single test iteration. Larger value improves test reliability, since schedulers do better job in the long run.
verbose Be extra verbose.

More options are available, but you probably won't need them:

Name Description
language format numbers according to the given locale, eg en, fr, etc. Will default to en. If unsure, just leave as is)

Options deprecated - will be removed completely in the next version. In current version, they don't have any effect.

Name Description
concurrency Number of CPUs to use. Defaults to all CPUs in the system. Reducing the number of CPUs limits the amount of resources (including memory) the run is using.
deoptratio Java heap size per fork, in megabytes. This affects the stride size: maximum footprint will never be exceeded, regardless of min/max stride sizes.
maxStride Should fork each test N times. 0 to run in the embedded mode with occasional forking, -1 to never ever fork.
minStride Iterations per test.

The plugin uses a separate location for jcstress files:

src/jcstress/java       // java sources
src/jcstress/resources  // resources

By default, the plugin uses jcstress-core-0.15. This can be easily changed with the following:

jcstress {
    jcstressDependency 'org.openjdk.jcstress:jcstress-core:0.x'
}

Notes

  • This plugin is heavily based on jmh-gradle-plugin and should behave in a similar way.