On Wed, 8 May 2024 22:40:26 GMT, Serguei Spitsyn <sspit...@openjdk.org> wrote:

>> If the following are all true 
>> - you are entering is a leaf monitor
>> - the current thread has already entered a leaf monitor
>> - the rank of the monitor you are entering is lower than the rank of the 
>> monitor already held
>> 
>> Then you have both a rank order violation and a violation for entering a 
>> leaf monitor when you have already entered a leaf monitor. My current 
>> implementation will complain about the rank violation (although can easily 
>> be made to instead complain about the leaf violation or complain about 
>> both). Yours will complain about the leaf violation.  To make yours instead 
>> complain about the rank violation, the first loop needs to also check all 
>> the leaf monitors. Since the 2nd loop also checks all the leaf monitors (but 
>> for a different reason), this means iterating over the leaf monitors twice. 
>> Complaining about both violations would also require iterating over the leaf 
>> monitors twice.
>
> Okay, thanks.
>> Then you have both a rank order violation and a violation for entering a 
>> leaf monitor when you have already entered a leaf monitor. 
> 
> I kind of disagree with the second part of this statement.
> My understanding is that the second loop does a little bit different check:
>   "Violation for entering ANY monitor when you have already entered a leaf 
> monitor."
> Please, note that `rank` can be any rank including those with conditions:
> 
>    rank < FIRST_LEAF_DEBUG_RAW_MONITOR
>    rank >= FIRST_LEAF_DEBUG_RAW_MONITOR
> 
> It seems to me that if the second rule (in my edition) is violated then the 
> first rule does not matter.
> It means that the first rule is for both ranks from the range:
> 
>    0 <= rank < FIRST_LEAF_DEBUG_RAW_MONITOR
>  ```

Yes, the 2nd loop is a different check. That's why I said it also checks all 
the leaf monitors "but for a different reason".  Your two loops do not flag a 
rank violation if both monitors are leafs, even if grabbed in the wrong order. 
It only flags the leaf violation. Your two checks will always catch any 
violation, it just a matter of whether my example (which is both a leaf and a 
rank violation) is flagged as a leaf violation or a rank violation (or even 
both could be indicated if we choose). Yours flags it as a leaf violation. My 
code flags it as a rank violation. Mine could flag both violations without any 
additional iterations. Your would need to iterate over the leaf monitors twice 
to detect if there is both a rank and a leaf violation.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19044#discussion_r1594784168

Reply via email to