Bug 227789

Summary: Remove more custom binding code with GenerateAddOpaqueRoot
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: BindingsAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: calvaris, cdumez, changseok, darin, eric.carlson, esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, jer.noble, kangil.han, kondapallykalyan, philipj, sam, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch for landing
none
Patch for landing
none
Patch for landing none

Ryosuke Niwa
Reported 2021-07-07 21:05:48 PDT
Now that we have added GenerateAddOpaqueRoot, use in more IDL files and get rid of custom bindings code.
Attachments
Patch (34.98 KB, patch)
2021-07-07 21:17 PDT, Ryosuke Niwa
no flags
Patch for landing (34.89 KB, patch)
2021-07-08 14:52 PDT, Ryosuke Niwa
no flags
Patch for landing (32.18 KB, patch)
2021-07-08 15:08 PDT, Ryosuke Niwa
no flags
Patch for landing (32.94 KB, patch)
2021-07-08 15:26 PDT, Ryosuke Niwa
no flags
Ryosuke Niwa
Comment 1 2021-07-07 21:17:42 PDT
Chris Dumez
Comment 2 2021-07-08 13:16:36 PDT
Comment on attachment 433114 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=433114&action=review > Source/WebCore/dom/AbortController.h:43 > + void* opaqueRoot() const { return m_signal.ptr(); } Can't we use `GenerateAddOpaqueRoot=signal` in the IDL to avoid having to add a new opaqueRoot() function? I think we may need to add a WTF::getPtr() call in the generated bindings if missing to convert the reference into a pointer but otherwise, I don't see why it wouldn't work? Same comment may apply to other classes in this patch. > Source/WebCore/html/track/TrackListBase.cpp:70 > + return m_element.get()->opaqueRoot(); why .get()? Doesn't seem needed.
Ryosuke Niwa
Comment 3 2021-07-08 13:37:33 PDT
(In reply to Chris Dumez from comment #2) > Comment on attachment 433114 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=433114&action=review > > > Source/WebCore/dom/AbortController.h:43 > > + void* opaqueRoot() const { return m_signal.ptr(); } > > Can't we use `GenerateAddOpaqueRoot=signal` in the IDL to avoid having to > add a new opaqueRoot() function? I think we may need to add a WTF::getPtr() > call in the generated bindings if missing to convert the reference into a > pointer but otherwise, I don't see why it wouldn't work? > > Same comment may apply to other classes in this patch. I guess we could do that although I'm somewhat worried that people might make signal() function not thread safe in the future. > > Source/WebCore/html/track/TrackListBase.cpp:70 > > + return m_element.get()->opaqueRoot(); > > why .get()? Doesn't seem needed. m_element->opaqueRoot() will assert because of the thread safety check in WeakPtr.
Chris Dumez
Comment 4 2021-07-08 13:51:22 PDT
(In reply to Ryosuke Niwa from comment #3) > (In reply to Chris Dumez from comment #2) > > Comment on attachment 433114 [details] > > Patch > > > > View in context: > > https://bugs.webkit.org/attachment.cgi?id=433114&action=review > > > > > Source/WebCore/dom/AbortController.h:43 > > > + void* opaqueRoot() const { return m_signal.ptr(); } > > > > Can't we use `GenerateAddOpaqueRoot=signal` in the IDL to avoid having to > > add a new opaqueRoot() function? I think we may need to add a WTF::getPtr() > > call in the generated bindings if missing to convert the reference into a > > pointer but otherwise, I don't see why it wouldn't work? > > > > Same comment may apply to other classes in this patch. > > I guess we could do that although I'm somewhat worried that people might > make signal() function not thread safe in the future. > > > > Source/WebCore/html/track/TrackListBase.cpp:70 > > > + return m_element.get()->opaqueRoot(); > > > > why .get()? Doesn't seem needed. > > m_element->opaqueRoot() will assert because of the thread safety check in > WeakPtr. Seems like either this is unsafe or we should allow operator->() to get called from the GC thread? I am still a bit unclear on what safe to do on the GC thread.
Ryosuke Niwa
Comment 5 2021-07-08 13:54:09 PDT
(In reply to Chris Dumez from comment #4) > (In reply to Ryosuke Niwa from comment #3) > > m_element->opaqueRoot() will assert because of the thread safety check in > > WeakPtr. > > Seems like either this is unsafe or we should allow operator->() to get > called from the GC thread? > I am still a bit unclear on what safe to do on the GC thread. Maybe? But the fact this is explicit is a good thing. We don't want people to start doing "interesting" things in GC threads.
Chris Dumez
Comment 6 2021-07-08 14:02:13 PDT
(In reply to Ryosuke Niwa from comment #5) > (In reply to Chris Dumez from comment #4) > > (In reply to Ryosuke Niwa from comment #3) > > > m_element->opaqueRoot() will assert because of the thread safety check in > > > WeakPtr. > > > > Seems like either this is unsafe or we should allow operator->() to get > > called from the GC thread? > > I am still a bit unclear on what safe to do on the GC thread. > > Maybe? But the fact this is explicit is a good thing. We don't want people > to start doing "interesting" things in GC threads. I thought that dereferencing a WeakPtr on the GC thread was unsafe, which is why it has a threading assertion. Your code is working around that by calling get() but then still dereferencing. In my book, you are already doing an "interesting" thing on the GC thread and I don't personally understand why it is safe (although it may well be).
Chris Dumez
Comment 7 2021-07-08 14:03:49 PDT
(In reply to Chris Dumez from comment #6) > (In reply to Ryosuke Niwa from comment #5) > > (In reply to Chris Dumez from comment #4) > > > (In reply to Ryosuke Niwa from comment #3) > > > > m_element->opaqueRoot() will assert because of the thread safety check in > > > > WeakPtr. > > > > > > Seems like either this is unsafe or we should allow operator->() to get > > > called from the GC thread? > > > I am still a bit unclear on what safe to do on the GC thread. > > > > Maybe? But the fact this is explicit is a good thing. We don't want people > > to start doing "interesting" things in GC threads. > > I thought that dereferencing a WeakPtr on the GC thread was unsafe, which is > why it has a threading assertion. Your code is working around that by > calling get() but then still dereferencing. > > In my book, you are already doing an "interesting" thing on the GC thread > and I don't personally understand why it is safe (although it may well be). BTW, the previous code was calling `root(wrapped().element())` which looked safer to me at least.
Ryosuke Niwa
Comment 8 2021-07-08 14:08:11 PDT
(In reply to Chris Dumez from comment #7) > (In reply to Chris Dumez from comment #6) > > (In reply to Ryosuke Niwa from comment #5) > > > (In reply to Chris Dumez from comment #4) > > > > (In reply to Ryosuke Niwa from comment #3) > > > > > m_element->opaqueRoot() will assert because of the thread safety check in > > > > > WeakPtr. > > > > > > > > Seems like either this is unsafe or we should allow operator->() to get > > > > called from the GC thread? > > > > I am still a bit unclear on what safe to do on the GC thread. > > > > > > Maybe? But the fact this is explicit is a good thing. We don't want people > > > to start doing "interesting" things in GC threads. > > > > I thought that dereferencing a WeakPtr on the GC thread was unsafe, which is > > why it has a threading assertion. Your code is working around that by > > calling get() but then still dereferencing. > > > > In my book, you are already doing an "interesting" thing on the GC thread > > and I don't personally understand why it is safe (although it may well be). > > BTW, the previous code was calling `root(wrapped().element())` which looked > safer to me at least. In JSNodeCustom.h, we see that: inline void* root(Node* node) { return node ? node->opaqueRoot() : nullptr; } inline void* root(Node& node) { return root(&node); }
Ryosuke Niwa
Comment 9 2021-07-08 14:09:00 PDT
(In reply to Chris Dumez from comment #6) > (In reply to Ryosuke Niwa from comment #5) > > (In reply to Chris Dumez from comment #4) > > > (In reply to Ryosuke Niwa from comment #3) > > > > m_element->opaqueRoot() will assert because of the thread safety check in > > > > WeakPtr. > > > > > > Seems like either this is unsafe or we should allow operator->() to get > > > called from the GC thread? > > > I am still a bit unclear on what safe to do on the GC thread. > > > > Maybe? But the fact this is explicit is a good thing. We don't want people > > to start doing "interesting" things in GC threads. > > I thought that dereferencing a WeakPtr on the GC thread was unsafe, which is > why it has a threading assertion. Your code is working around that by > calling get() but then still dereferencing. > > In my book, you are already doing an "interesting" thing on the GC thread > and I don't personally understand why it is safe (although it may well be). To be honest, none of these are safe. Our DOM GC implementation is pretty badly broken. It's somewhat shocking we haven't gotten a lot of crashes from it so far.
Chris Dumez
Comment 10 2021-07-08 14:28:04 PDT
(In reply to Ryosuke Niwa from comment #8) > (In reply to Chris Dumez from comment #7) > > (In reply to Chris Dumez from comment #6) > > > (In reply to Ryosuke Niwa from comment #5) > > > > (In reply to Chris Dumez from comment #4) > > > > > (In reply to Ryosuke Niwa from comment #3) > > > > > > m_element->opaqueRoot() will assert because of the thread safety check in > > > > > > WeakPtr. > > > > > > > > > > Seems like either this is unsafe or we should allow operator->() to get > > > > > called from the GC thread? > > > > > I am still a bit unclear on what safe to do on the GC thread. > > > > > > > > Maybe? But the fact this is explicit is a good thing. We don't want people > > > > to start doing "interesting" things in GC threads. > > > > > > I thought that dereferencing a WeakPtr on the GC thread was unsafe, which is > > > why it has a threading assertion. Your code is working around that by > > > calling get() but then still dereferencing. > > > > > > In my book, you are already doing an "interesting" thing on the GC thread > > > and I don't personally understand why it is safe (although it may well be). > > > > BTW, the previous code was calling `root(wrapped().element())` which looked > > safer to me at least. > > In JSNodeCustom.h, we see that: > > inline void* root(Node* node) > { > return node ? node->opaqueRoot() : nullptr; > } > > inline void* root(Node& node) > { > return root(&node); > } I see. I didn't remember that code. I completely agree you code is not less safe than it used to be then. I still think it would look much nicer if you used GenerateAddOpaqueRoot=foo instead of introducing new opaqueRoot() functions. However, if you disagree, feel free to land as is, I still think this is a good improvement.
Ryosuke Niwa
Comment 11 2021-07-08 14:51:33 PDT
(In reply to Chris Dumez from comment #10) > > I see. I didn't remember that code. I completely agree you code is not less > safe than it used to be then. I still think it would look much nicer if you > used GenerateAddOpaqueRoot=foo instead of introducing new opaqueRoot() > functions. > > However, if you disagree, feel free to land as is, I still think this is a > good improvement. Oh sure, I'm making that change. It looks like the patch never got uploaded? Will land with that change.
Ryosuke Niwa
Comment 12 2021-07-08 14:52:06 PDT
Created attachment 433166 [details] Patch for landing
EWS
Comment 13 2021-07-08 14:52:53 PDT
Tools/Scripts/svn-apply failed to apply attachment 433166 [details] to trunk. Please resolve the conflicts and upload a new patch.
Ryosuke Niwa
Comment 14 2021-07-08 15:08:10 PDT
Created attachment 433167 [details] Patch for landing
Ryosuke Niwa
Comment 15 2021-07-08 15:26:29 PDT
Created attachment 433170 [details] Patch for landing
EWS
Comment 16 2021-07-08 16:08:28 PDT
Committed r279761 (239532@main): <https://commits.webkit.org/239532@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 433170 [details].
Radar WebKit Bug Importer
Comment 17 2021-07-08 16:09:18 PDT
Note You need to log in before you can comment on or make changes to this bug.