News for hackers. Stuff that matters.
Re:Using JDK 9 Memory Order Modes by sreque on Wednesday March 15, 2017 @12:25PM (#13877249)
It's actually not possible to get a hold of partially-constructed thing in this manner, assuming the thing only has final variables. See http://g.oswego.edu/dl/jmm/cookbook.html.

"The initial load (i.e., the very first encounter by a thread) of a final field cannot be reordered with the initial load of the reference to the object containing the final field. This comes into play in: x = sharedRef; ... ; i = x.finalField; A compiler would never reorder these since they are dependent, but there can be consequences of this rule on some processors."

Note that there are no constraints placed on sharedRef. It does not need to be volatile, for instance.

This link also has more useful info and examples: https://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.ht...

Re:Using JDK 9 Memory Order Modes by chrisseaton on Wednesday March 15, 2017 @12:27PM (#13877268)
> there can be consequences of this rule on some processors

Right - I think the processor can still reorder. I've never been sure why the compiler is not allowed to reorder in this case, since this doesn't help you if the processor will do it anyway.

Re:Using JDK 9 Memory Order Modes by sreque on Wednesday March 15, 2017 @12:29PM (#13877286)
The "consequences on some processors" simply means that a conforming java compiler/VM may need to insert memory barriers to enforce the memory model for constructors, resulting in a performance penalty. A conforming compiler or VM cannot generate code that would allow processor re-orderings to break the memory model.
Re:Using JDK 9 Memory Order Modes by xxs on Wednesday March 15, 2017 @01:13PM (#13877797)
In such a case the compiler has to insert a store-store barrier and not reorder the instructions to conform to JMM.
Re:Using JDK 9 Memory Order Modes by hinkley on Wednesday March 15, 2017 @02:38PM (#13878588)
GP just has old information. Prior to widespread adoption of JSR-133, at which point Java was over 10 years old, things were demonstrably broken if you got clever with concurrency.