eclipse-openj9 / openj9

Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Other
3.27k stars 721 forks source link

Fences for Volatile Field Stores #11266

Open r30shah opened 3 years ago

r30shah commented 3 years ago

On Z, I am porting change from @fjeremic for to put fences for volatile field stores. (https://github.com/eclipse/openj9/pull/11262), where most of the write barrier nodes and store nodes goes through the xstoreVolatileHelper [1] which will generate a fence for volatile fields. We would have write barrier under ArrayStoreCHK node [2] as well and we do not generate fence for volatiles under that node.

I am opening up this issue to get more clarity about the behaviour about volatile array reference, i.e, when we declare a volatile array variable in java, in my understanding, only variable is volatile not its elements, right? So if that is the case, would it be ever possible to have volatile field under ArrayStoreCHK node?

[1]. https://github.com/eclipse/openj9/blob/c97d10cd625f94716bbe5d7efb5f530eb72c0c9f/runtime/compiler/z/codegen/J9TreeEvaluator.cpp#L4150-L4186 [2]. https://github.com/eclipse/omr/blob/4ede03ca616f2303dbed143df6694a248e439c84/compiler/il/OMRILOpCodeProperties.hpp#L9457-L9490

r30shah commented 3 years ago

FYI @fjeremic @aviansie-ben

@DanHeidinga @pshipton Wanted to know the java behaviour around volatile arrays, if you can shed some lights it will be really useful

r30shah commented 2 months ago

While cleaning up to get the PR https://github.com/eclipse-openj9/openj9/pull/11262, I did wanted to get some clarity on this issue - i.e, do we ever have a volatile elements in array? When an array is declared volatile, the reference to the array object is volatile and need to adhere to serialization requirement of Java memory model. looking at the code generated and going through JVM specification, I can not for sure find information about the elements in the volatile array.

So resuming discussion here, tagging @TobiAjila and @joransiu to get opinion on this.