On Mon, 14 Nov 2022 22:59:22 GMT, John R Rose <jr...@openjdk.org> wrote:
> > So the data structure for lock records (per thread) could consist of a > > series of distinct values [ A B C ] and each of the values could be > > repeated, but only adjacently: [ A A A B C C ] for example. > > @rose00 why only adjacently? Nested locking can be interleaved on different > > monitors. > > Yes it can; you can have nesting A, B, A. But the thread-based fast-locking > list might not cover that case. If it were restricted to only adjacent > records in the way I sketched, it would need to use a different, slower > technique for the A, B, A case. The trade-off is that if you only allow > adjacent recursive locks on the list, you don't need to search the list > beyond the first element, to detect re-locking. Dunno if that pencils out to > a real advantage, though, since the fallback is slow. TBH, I don't currently think that making fast-locking recursive is very important. In-fact, the need for the fast-locking appears somewhat questionable to begin with - the scenario where it performs better than OM-locking is rather narrow and really only relevant for legacy code. Stack-locking and fast-locking only help workloads that 1. Do lots of uncontended, e.g. single-threaded locking and 2. Churn lots of monitor objects. It is not enough to use a single Vector a lot - the cost of allocating the OM would soon be amortized by lots of OM action. In order for stack-/fast-locking to be useful, you have to have a workload that keeps allocating new lock objects and use them only once or very few times. For example, I have seen this in OpenJDK's XML code, where the XSLT compiler would generate code that uses an ungodly amount StringBuffers (this probably warrants a separate fix). Now, where would recursive locking support for the fast-locking path be useful? I have yet to see a workloa d that suffers because of a lack of recursive locking support. Implementing recursive fast-locking means we'd have to add code in the fast-path, and that would affect non-recursive locking as well. I'd rather keep the implementation simple and fast. ------------- PR: https://git.openjdk.org/jdk/pull/10590