RFR: 8320318: ObjectMonitor Responsible thread [v3]

Patricio Chilano Mateo pchilanomate at openjdk.org
Thu Sep 19 19:12:38 UTC 2024


On Wed, 18 Sep 2024 21:01:18 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:

>> src/hotspot/share/runtime/objectMonitor.cpp line 385:
>> 
>>> 383: }
>>> 384: 
>>> 385: bool ObjectMonitor::try_enter(JavaThread* current, bool check_owner) {
>> 
>> The `check_owner` name is a little confusing to me. To me it looks more like `check_for_recursion` or `handle_recursion`.
>
> I think the name should describe what setting the value actually does, but if it is just a hack to do what the comment bellow says, then it sounds like a friend declaration for `SharedRuntime::monitor_exit_helper()` is what is wanted. (Or make TryLock() public.)
>> Set check_owner to false (it's default value is true) if you want
>> to use ObjectMonitor::try_enter() as a public way of doing TryLock().
>> Used this way in SharedRuntime::monitor_exit_helper().

Maybe `check_already_owned`? FTR I prefer this version than a friend declaration. We would also have to rename it as try_lock to be consistent. And having to expose and check for TryLockResult is also uglier in my opinion than checking a boolean. I don't see it as a hack, we are just skipping the already owned case since we know in this case it will fail. I would actually remove this comment.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19454#discussion_r1767473271


More information about the hotspot-dev mailing list