[concurrency-interest] Safe publishing strategy

Aleksey Shipilev aleksey.shipilev at oracle.com
Fri Jan 23 17:37:38 EST 2015

On 01/24/2015 12:25 AM, Vitaly Davidovich wrote:
>     Yes, if you have enough field stores to spill over the publication of
>     the object. See also:
>      http://shipilev.net/blog/2014/safe-public-construction/
> Can you elaborate on what you mean by "enough field stores to spill over
> the publication"?

If you do quite a few non-final field stores in constructor, the
instruction scheduler may decide to emit a few field stores, then
publish the reference, then emit the rest of the field stores. I managed
to observe this at least once back in JDK 7 and 32-bit VMs days on a
real-life application.

Out of curiosity, I slapped together a reproducer with jcstress:

On my i7-4790K, JDK 8u40 EA, Linux x86_64, it does:

$ java -XX:-UseCompressedOops -jar tests-custom/target/jcstress.jar -t
.*UnsafePublication.*  -v

[OK] o.o.j.t.unsafe.UnsafePublication
Observed state     Occurrences    Expectation   Interpretation
          [-1] (   97,403,388)     ACCEPTABLE   Not published yet.
           [0] (        2,731)     ACCEPTABLE   0 fields visible.
           [1] (        6,099)     ACCEPTABLE   1 field visible.
           [2] (        6,533)     ACCEPTABLE   2 fields visible.
           [3] (       17,607)     ACCEPTABLE   3 fields visible.
           [4] (   24,692,082)     ACCEPTABLE   All fields visible.

Tell me something about "theoretical" again?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20150124/dca75147/attachment-0001.bin>

More information about the Concurrency-interest mailing list