Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LOGMGR-319] Rework locking for Loom compatibility #380

Merged
merged 1 commit into from
May 8, 2023

Conversation

dmlloyd
Copy link
Member

@dmlloyd dmlloyd commented May 5, 2023

  • Change synchronized constructs that cover blocking code to use a shared (per-instance) ReentrantLock
  • Unify discrete locks among ExtHandler subclasses
  • Remove protected outputLock object which was used for synchronization among subclasses of WriterHandler and replace with shared lock
  • Protect setCharset with lock to retain behavior of java.util.logging.Handler
  • Shadow private fields from j.u.l.Handler which are protected by synchronized in that class
  • Replace tree lock with ReentrantLock

This is technically a compatibility-impacting change (and thus should not be backported) since the protected outputLock field has been removed from WriterHandler and not replaced. The new lock field is called lock and it is on ExtHandler itself. The new field must have a distinct name from the old field, otherwise existing third-party code which tries to synchronize on the lock field will lock on the ReentrantLock's monitor, not the ReentrantLock itself.

Another behavioral change is that the handler tree previously had a few locks (three or four), with subclass hierarchies often maintaining their own lock. I don't expect this to be a problem (if anything I expect to avoid possible deadlock scenarios) but it is worth mentioning.

In one case a different lock was used to read and write a non-volatile field on a handler which was a source of possible obscure bugs; this has been fixed to use the common lock.

Related to openjdk/jdk#13832. Depends on #378.

@dmlloyd
Copy link
Member Author

dmlloyd commented May 5, 2023

This one needs some significant testing. :)

* Change `synchronized` constructs that cover blocking code to use a shared `ReentrantLock`
* Unify discrete locks among `ExtHandler` subclasses
* Remove `protected` `outputLock` object which was used for synchronization among subclasses of `WriterHandler` and replace with shared `lock`
* Protect `setCharset` with lock to retain behavior of `java.util.logging.Handler`
* Shadow private fields from `j.u.l.Handler` which are protected by `synchronized` in that class
* Replace tree lock with `ReentrantLock`
@dmlloyd dmlloyd merged commit d13957b into jboss-logging:main May 8, 2023
@dmlloyd dmlloyd deleted the loom branch May 8, 2023 19:35
@dmlloyd dmlloyd changed the title Rework locking for Loom compatibility [LOGMGR-319] Rework locking for Loom compatibility May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants