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

Review Locker #4058

Closed
sbordet opened this issue Sep 5, 2019 · 1 comment
Closed

Review Locker #4058

sbordet opened this issue Sep 5, 2019 · 1 comment

Comments

@sbordet
Copy link
Contributor

sbordet commented Sep 5, 2019

Class Locker has an _unlock field that is completely unnecessary, wasting memory and causing pointer chasing to call close() on it.
Class Locker.Lock is not static so it has a hidden field pointing back to Locker increasing memory waste.

I propose the introduction of a new class called AutoLock which implements AutoCloseable and returns itself:

class AutoLock implements AutoCloseable
{
    private final ReentrantLock _lock = new ReentrantLock();

    public AutoLock lock()
    {
        _lock.lock();
        return this;
    }

    @Override
    public void close()
    {
        _lock.unlock();
    }

    ...
}

The idiom will change from:

try (Locker.Lock lock = _locker.lock())
{
}

to

try (AutoLock lock = _autoLock.lock())
{
}

This will require a large change in the codebase, but has the advantage that it will be as easy to use as synchronized and will play better for the future in case of Project Loom.

@gregw
Copy link
Contributor

gregw commented Sep 6, 2019

@sbordet You'll have to also support newCondition() API, but I think that is trivial.

We can remove the lockIfNotHeld stuff as no longer used.

@janbartel I think we should use this issue and resulting PR to cleanup the usage of Locker.isLocked() by sessions. I think that was introduced as a defence when the locking was last changed, but I don't think we need to check it anymore. Note there are a few methods that do call session methods without the lock (and thus will fail this test), but they are deprecated and/or never called - so we can just fail in them rather than check everywhere.

@sbordet sbordet added this to To Do in Jetty 10.0.0 via automation Sep 6, 2019
sbordet added a commit that referenced this issue Sep 9, 2019
Removes the Locker class, replaced by AutoLock.
Removed usages of Locker.isLocked() from the session code
since it was not necessary.
Took the chance to do a little code cleanup.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
sbordet added a commit that referenced this issue Sep 9, 2019
Removes the Locker class, replaced by AutoLock.
Removed usages of Locker.isLocked() from the session code
since it was not necessary.
Took the chance to do a little code cleanup.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
sbordet added a commit that referenced this issue Sep 11, 2019
@sbordet sbordet closed this as completed Sep 11, 2019
Jetty 10.0.0 automation moved this from To Do to Done Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Jetty 10.0.0
  
Done
Development

No branches or pull requests

2 participants