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.23k stars 711 forks source link

read-only monitor optimization #8961

Open 0xdaryl opened 4 years ago

0xdaryl commented 4 years ago

@zl-wang @gita-omr @IBMJimmyk : would one of you mind summarizing the read-only monitor optimization on Power?

This is an optimization this is enabled for Power and ARM. However, ARM doesn't provide any codegen support for it. X86 seems to have some backend support for it, but doesn't enable the optimizer analysis. Z and AArch64 don't provide any support.

I remember some work being done in this space maybe 15 years ago. Is this the same optimization? What kind of performance is expected in current workloads and should this be something that should be implemented across all platforms?

FYI: @fjeremic @andrewcraik @knn-k

IBMJimmyk commented 4 years ago

Are you referring to an optimization that sets the readMonitor flag on a node? If so, Power doesn't support it in codegen either. I actaully just disabled codegen support since the generated assembly was wrong (it pre-dated the Reserved bit so it ended up setting the Reserved bit when trying to increment the RC). If needed, it should be fixable but wasn't a priority at the time since I was already checking in a rather large change.

0xdaryl commented 4 years ago

Are you referring to an optimization that sets the readMonitor flag on a node?

Yes, that's the one. OpenJ9 has been using the Reserved bit for at least a decade so perhaps the notion of read-only monitors has long been deprecated and it should be surgically removed from the code.

zl-wang commented 4 years ago

Yeah, it should be removed. Keep in mind that this is different from SimpleReadMonitor where we pattern-match the incoming trees and evaluate monEnt/read/MonExit together.

I would not go into the details of the original readonly monitor design, sufficing to say: 1) the idea was along the line of Transactional Memory before TM became welknown; 2) the design was not quite completed, especially considering Java Memory Model; 3) it is never enabled;

0xdaryl commented 4 years ago

Thanks @zl-wang. A quick read through the SimpleReadMonitor function reveals that it will only occur if isReadMonitor is set on a node, meaning that the monitor elimination analysis still seems to be relevant for it [1].

Is the SimpleReadMonitor code Power architecture specific, or can it be generalized to other platforms as well?

[1] https://github.com/eclipse/openj9/blob/61c3a700129045c0cc7819942a0a0c7412c14682/runtime/compiler/p/codegen/J9TreeEvaluator.cpp#L7823

zl-wang commented 4 years ago

it is applicable to architectures with load-Reserved and store-Conditional atomic supports. i cannot see how it can be applied to single-step CompareAndSwap or CompareAndExchange platforms.