RFR: 8255678: Add Mutex::try_lock version without rank checks [v2]

Patricio Chilano Mateo pchilanomate at openjdk.java.net
Wed Nov 18 17:57:06 UTC 2020


On Wed, 18 Nov 2020 03:57:15 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> I'll wait until you push and then I'll merge. I still have to check the owner here though, because if the thread already owns the lock, calling check_rank() from try_lock will do the wrong check (it will assume it's being called from wait()). An alternative would be to add a boolean parameter to check_rank(), set only from try_lock() so I can differentiate the two calls.
>
> I think a different refactoring will be needed here so that:
> try_lock() -> try_lock_inner(true);
> try_lock_without_rank_check() -> try_lock_inner(false);
> try_lock_inner(bool check_rank) { ... }
> That way code duplication is minimised.

How about just:
bool Mutex::try_lock() {
  Thread * const self = Thread::current();
  DEBUG_ONLY(if (!owned_by_self()) check_rank();)
  return try_lock_inner(self);
}
keeping try_lock_without_rank_check() as is. Then I can merge try_lock_inner() with your patch.

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

PR: https://git.openjdk.java.net/jdk/pull/1242


More information about the hotspot-runtime-dev mailing list