Bug 226157 - Make CheckedLock the default Lock
Summary: Make CheckedLock the default Lock
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on: 226145 226152
Blocks: 226176
  Show dependency treegraph
 
Reported: 2021-05-23 12:47 PDT by Chris Dumez
Modified: 2021-05-24 10:02 PDT (History)
43 users (show)

See Also:


Attachments
Patch (92.42 KB, patch)
2021-05-23 14:39 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (97.40 KB, patch)
2021-05-23 15:08 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (98.29 KB, patch)
2021-05-23 15:56 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (99.33 KB, patch)
2021-05-23 16:21 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (100.21 KB, patch)
2021-05-23 16:36 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (100.33 KB, patch)
2021-05-23 16:51 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (100.41 KB, patch)
2021-05-23 17:08 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (101.40 KB, patch)
2021-05-23 18:14 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (102.84 KB, patch)
2021-05-23 21:17 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2021-05-23 12:47:51 PDT
Make CheckedLock the default Lock.

Rename Lock to UncheckedLock, CheckedLock to Lock. Also rename Condition to UncheckedCondition and CheckedCondition to Condition.
Comment 1 Darin Adler 2021-05-23 13:17:57 PDT
Safer to do this in separate steps. A single patch where Lock is valid both before and after but means two different things is much more risky.

Also, should the Unchecked ones exist long term, or are they deprecated and slated for destruction? If the latter, then I suggest names with Deprecated in them.
Comment 2 Chris Dumez 2021-05-23 13:23:03 PDT
(In reply to Darin Adler from comment #1)
> Safer to do this in separate steps. A single patch where Lock is valid both
> before and after but means two different things is much more risky.

The issue is that not ALL existing Lock cases will be renamed to UncheckedLock. As a matter of fact, most of them will just build fine as is when the UncheckedLock become the Lock.

The approach I used was doing the rename of the Locks, and then only update variables from Lock to UncheckedLock if I get a build failure.

I am not sure I understand the risk you're referring to here. Either it builds or it doesn't. The locks are identical at run time.

> Also, should the Unchecked ones exist long term, or are they deprecated and
> slated for destruction? If the latter, then I suggest names with Deprecated
> in them.

I am proposing to start with UncheckedLock for now and see how it goes. If we see that things go well and we managed to get to low usage then add deprecated to the name later on. There are cases that rely on Locker having a move constructor, in particular in JavaScriptCore and this is something that Locker<CheckedLock> cannot support for e.g.
Comment 3 Chris Dumez 2021-05-23 13:28:07 PDT
By the way, the reason I landed so many patches before this one ( to get rid of holdLock() / tryHoldLock and LockHolder variables) is because as a result, most existing Locks will build just fine as a result once I rename CheckedLock to Lock.

The cases that will need to be renamed to UncheckedLock are mostly cases where lockers are moved and passed as parameter as AbstractLocker. And Lockers that take in a pointer to a lock (instead of a reference). With some work though, we can likely factor the code a bit differently to get rid of UncheckedLock I hope.
Comment 4 Darin Adler 2021-05-23 14:02:05 PDT
(In reply to Chris Dumez from comment #2)
> I am not sure I understand the risk you're referring to here. Either it
> builds or it doesn't. The locks are identical at run time.

OK. I guess this is an unusual case where it’s completely safe to get it wrong!
Comment 5 Chris Dumez 2021-05-23 14:39:22 PDT Comment hidden (obsolete)
Comment 6 EWS Watchlist 2021-05-23 14:40:09 PDT
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See https://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Comment 7 Chris Dumez 2021-05-23 15:08:12 PDT Comment hidden (obsolete)
Comment 8 Chris Dumez 2021-05-23 15:56:08 PDT Comment hidden (obsolete)
Comment 9 Chris Dumez 2021-05-23 16:21:14 PDT Comment hidden (obsolete)
Comment 10 Chris Dumez 2021-05-23 16:36:37 PDT Comment hidden (obsolete)
Comment 11 Chris Dumez 2021-05-23 16:51:21 PDT Comment hidden (obsolete)
Comment 12 Chris Dumez 2021-05-23 17:08:44 PDT Comment hidden (obsolete)
Comment 13 Chris Dumez 2021-05-23 18:14:39 PDT
Created attachment 429493 [details]
Patch
Comment 14 Chris Dumez 2021-05-23 19:58:42 PDT
I am preparing an explanation email for Clang thread safety analysis in WebKit and the related annotations for webkit-dev. This way, people will know our to leverage this in new code or how to deal with compilation errors when they modify the code. I'll send out the mail after this lands.
Comment 15 Darin Adler 2021-05-23 20:54:07 PDT
Comment on attachment 429493 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=429493&action=review

Seems like a good start. I couldn’t really discern the pattern of where we use UncheckedLock explicitly in this patch, even though you explained the strategy and rationale, but I suppose the main point is switching to the checking from CheckedLock almost everywhere that is *not* in the patch.

> Source/WTF/wtf/Lock.h:216
> +using WTF::assertIsHeld;

Just occurred to me that we might not need this because of argument dependent lookup <https://en.cppreference.com/w/cpp/language/adl>. If the argument is in the WTF namespace, then the function is looked for in the WTF namespace without requiring a WTF:: prefix, so this using line solves a problem that does not exist.

> Source/WebCore/html/canvas/WebGLObject.h:31
> +#include <wtf/Lock.h>

Could we use Forward.h here instead, and remove the forward declaration of AbstractLocker below?
Comment 16 Chris Dumez 2021-05-23 20:57:47 PDT
(In reply to Darin Adler from comment #15)
> Comment on attachment 429493 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=429493&action=review
> 
> Seems like a good start. I couldn’t really discern the pattern of where we
> use UncheckedLock explicitly in this patch, even though you explained the
> strategy and rationale, but I suppose the main point is switching to the
> checking from CheckedLock almost everywhere that is *not* in the patch.
> 
> > Source/WTF/wtf/Lock.h:216
> > +using WTF::assertIsHeld;
> 
> Just occurred to me that we might not need this because of argument
> dependent lookup <https://en.cppreference.com/w/cpp/language/adl>. If the
> argument is in the WTF namespace, then the function is looked for in the WTF
> namespace without requiring a WTF:: prefix, so this using line solves a
> problem that does not exist.

Will try.

> 
> > Source/WebCore/html/canvas/WebGLObject.h:31
> > +#include <wtf/Lock.h>
> 
> Could we use Forward.h here instead, and remove the forward declaration of
> AbstractLocker below?

I think this means adding those forward declarations to Forward.h since they are not currently present.
Comment 17 Darin Adler 2021-05-23 21:05:35 PDT
Comment on attachment 429493 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=429493&action=review

>>> Source/WebCore/html/canvas/WebGLObject.h:31
>>> +#include <wtf/Lock.h>
>> 
>> Could we use Forward.h here instead, and remove the forward declaration of AbstractLocker below?
> 
> I think this means adding those forward declarations to Forward.h since they are not currently present.

We should do that eventually, even if we don’t do it right now.
Comment 18 Chris Dumez 2021-05-23 21:17:24 PDT
Created attachment 429499 [details]
Patch
Comment 19 EWS 2021-05-23 22:37:49 PDT
Committed r277943 (238070@main): <https://commits.webkit.org/238070@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 429499 [details].
Comment 20 Radar WebKit Bug Importer 2021-05-23 22:38:20 PDT
<rdar://problem/78385912>