Bug 200451 - Tighten WeakPtr threading assertions for GC threads
Summary: Tighten WeakPtr threading assertions for GC threads
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: 200504
Blocks: 199517
  Show dependency treegraph
 
Reported: 2019-08-05 15:52 PDT by Chris Dumez
Modified: 2019-08-07 14:59 PDT (History)
11 users (show)

See Also:


Attachments
WIP Patch (2.43 KB, patch)
2019-08-05 15:59 PDT, Chris Dumez
ews-watchlist: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-highsierra (3.71 MB, application/zip)
2019-08-05 17:32 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews117 for mac-highsierra (3.41 MB, application/zip)
2019-08-05 19:26 PDT, EWS Watchlist
no flags Details
WIP Patch (2.43 KB, patch)
2019-08-07 10:35 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (3.14 KB, patch)
2019-08-07 11:49 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 2019-08-05 15:52:26 PDT
Tighten WeakPtr threading assertions for GC threads. We're currently overly permissive for GC threads.
Comment 1 Chris Dumez 2019-08-05 15:59:14 PDT
Created attachment 375575 [details]
WIP Patch
Comment 2 EWS Watchlist 2019-08-05 16:01:54 PDT
Attachment 375575 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/WeakPtr.h:71:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WTF/wtf/WeakPtr.h:73:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WTF/wtf/WeakPtr.h:78:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WTF/wtf/WeakPtr.h:80:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WTF/wtf/WeakPtr.h:86:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WTF/wtf/WeakPtr.h:88:  Should have a space between // and comment  [whitespace/comments] [4]
Total errors found: 6 in 1 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 EWS Watchlist 2019-08-05 17:32:47 PDT
Comment on attachment 375575 [details]
WIP Patch

Attachment 375575 [details] did not pass mac-ews (mac):
Output: https://webkit-queues.webkit.org/results/12866226

New failing tests:
imported/w3c/web-platform-tests/html/browsers/history/the-history-interface/007.html
imported/w3c/web-platform-tests/html/browsers/history/the-history-interface/history_go_plus.html
imported/w3c/web-platform-tests/html/browsers/history/the-history-interface/history_forward.html
imported/w3c/web-platform-tests/html/browsers/history/the-history-interface/history_go_minus.html
imported/w3c/web-platform-tests/html/browsers/history/the-history-interface/combination_history_004.html
Comment 4 EWS Watchlist 2019-08-05 17:32:49 PDT
Created attachment 375587 [details]
Archive of layout-test-results from ews101 for mac-highsierra

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-highsierra  Platform: Mac OS X 10.13.6
Comment 5 EWS Watchlist 2019-08-05 19:26:13 PDT
Comment on attachment 375575 [details]
WIP Patch

Attachment 375575 [details] did not pass mac-debug-ews (mac):
Output: https://webkit-queues.webkit.org/results/12866608

New failing tests:
imported/w3c/web-platform-tests/html/browsers/history/the-history-interface/007.html
Comment 6 EWS Watchlist 2019-08-05 19:26:15 PDT
Created attachment 375595 [details]
Archive of layout-test-results from ews117 for mac-highsierra

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews117  Port: mac-highsierra  Platform: Mac OS X 10.13.6
Comment 7 Chris Dumez 2019-08-07 10:35:51 PDT
Created attachment 375712 [details]
WIP Patch
Comment 8 EWS Watchlist 2019-08-07 10:37:57 PDT
Attachment 375712 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/WeakPtr.h:71:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WTF/wtf/WeakPtr.h:73:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WTF/wtf/WeakPtr.h:78:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WTF/wtf/WeakPtr.h:80:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WTF/wtf/WeakPtr.h:86:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WTF/wtf/WeakPtr.h:88:  Should have a space between // and comment  [whitespace/comments] [4]
Total errors found: 6 in 1 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Chris Dumez 2019-08-07 11:49:16 PDT
Created attachment 375726 [details]
Patch
Comment 10 Chris Dumez 2019-08-07 12:39:55 PDT
Comment on attachment 375726 [details]
Patch

Ready for review.
Comment 11 youenn fablet 2019-08-07 13:02:35 PDT
Comment on attachment 375726 [details]
Patch

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

> Source/WTF/wtf/WeakPtr.h:102
> +        // FIXME: Our GC threads currently need to get opaque pointers from WeakPtrs and have to be special-cased.

Do we have a plan to further tighten things?
It seems fine to get access to a value stored in a DOM object from GC thread, be it an integer, a raw pointer or a weak pointer.
Comment 12 Chris Dumez 2019-08-07 13:04:27 PDT
(In reply to youenn fablet from comment #11)
> Comment on attachment 375726 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=375726&action=review
> 
> > Source/WTF/wtf/WeakPtr.h:102
> > +        // FIXME: Our GC threads currently need to get opaque pointers from WeakPtrs and have to be special-cased.
> 
> Do we have a plan to further tighten things?
> It seems fine to get access to a value stored in a DOM object from GC
> thread, be it an integer, a raw pointer or a weak pointer.

The thing is that somebody may dereference the pointer returned by get() later on, which would not be safe. I do not know if we have plans to tighten things further but Geoff said we might and suggested I put a comment when I discussed it with him.
Comment 13 WebKit Commit Bot 2019-08-07 13:35:18 PDT
Comment on attachment 375726 [details]
Patch

Clearing flags on attachment: 375726

Committed r248386: <https://trac.webkit.org/changeset/248386>
Comment 14 WebKit Commit Bot 2019-08-07 13:35:20 PDT
All reviewed patches have been landed.  Closing bug.
Comment 15 Radar WebKit Bug Importer 2019-08-07 13:36:22 PDT
<rdar://problem/54048244>
Comment 16 Darin Adler 2019-08-07 14:52:09 PDT
Idea for long term: We could consider creating a special type (or struct with just a pointer data member) for "pointer that can only be used to make GC decisions and shouldn't be used in any other way" and we could return that from a function like get, but with a different name. That special type would also help us express "this is the right pointer for GC liveness checking, not a pointer further into an object" and also "don't remember exactly what type of object this is, since you can't make good use of that". Some people don't like using types for something that's just a pointer, but I think there ways this could make code more foolproof if the idea works.
Comment 17 Ryosuke Niwa 2019-08-07 14:59:01 PDT
(In reply to Darin Adler from comment #16)
> Idea for long term: We could consider creating a special type (or struct
> with just a pointer data member) for "pointer that can only be used to make
> GC decisions and shouldn't be used in any other way" and we could return
> that from a function like get, but with a different name. That special type
> would also help us express "this is the right pointer for GC liveness
> checking, not a pointer further into an object" and also "don't remember
> exactly what type of object this is, since you can't make good use of that".
> Some people don't like using types for something that's just a pointer, but
> I think there ways this could make code more foolproof if the idea works.

Yeah, that would be a great change in long term. I think for short term, we can add a special version of WeakPtr::get which asserts that it's either called in the GC thread or during a pause-the-main-thread phase of GC, and name it accordingly.