[jmm-dev] easily observable examples of non-sc behaviours in Java

Aleksey Shipilev aleksey.shipilev at oracle.com
Thu Jan 15 19:05:23 UTC 2015


On 01/15/2015 08:31 PM, Francesco Zappa Nardelli wrote:
> Does any of you have suggestions or snippets of code that
> highlighlits non-sc behaviours for racy Java programs (possibly on a
> recent HotSpot VM)?

Go and run jcstress:
 http://openjdk.java.net/projects/code-tools/jcstress/

For example, unsynchronized Dekker scenario:
 http://hg.openjdk.java.net/code-tools/jcstress/file/fc7efa97034e/tests-custom/src/main/java/org/openjdk/jcstress/tests/fences/UnfencedDekkerTest.java

On my x86:

$ java -jar tests-custom/target/jcstress.jar -t .*UnfencedDekkerTest.* -v

[OK] o.o.j.t.fences.UnfencedDekkerTest
 Obs. state     Occurrences        Expectation Interpretation
     [0, 1] (   57,387,764)         ACCEPTABLE Acceptable under SC
     [1, 0] (   58,281,884)         ACCEPTABLE Acceptable under SC
     [1, 1] (           39)         ACCEPTABLE Acceptable under SC
     [0, 0] (   41,035,293) ACCEPTABLE_INTERESTING Acceptable with no SC
enforced

As opposed to synchronized Dekker scenario:
http://hg.openjdk.java.net/code-tools/jcstress/file/fc7efa97034e/tests-custom/src/main/java/org/openjdk/jcstress/tests/volatiles/DekkerTest.java

[OK] o.o.j.t.volatiles.DekkerTest
 Obs. state     Occurrences   Expectation Interpretation
     [0, 1] (   46,799,613)    ACCEPTABLE Trivial under SC
     [1, 0] (   47,327,893)    ACCEPTABLE Trivial under SC
     [1, 1] (      443,904)    ACCEPTABLE Trivial under SC
     [0, 0] (            0)    FORBIDDEN  Violates SC

Thanks,
-Aleksey.



More information about the jmm-dev mailing list