[concurrency-interest] Safe publishing strategy
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:
> 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
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
Observed state Occurrences Expectation Interpretation
[-1] ( 97,403,388) ACCEPTABLE Not published yet.
 ( 2,731) ACCEPTABLE 0 fields visible.
 ( 6,099) ACCEPTABLE 1 field visible.
 ( 6,533) ACCEPTABLE 2 fields visible.
 ( 17,607) ACCEPTABLE 3 fields visible.
 ( 24,692,082) ACCEPTABLE All fields visible.
Tell me something about "theoretical" again?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: OpenPGP digital signature
More information about the Concurrency-interest