Bug 186360 - Do some hardening in JSLazyEventListener
Summary: Do some hardening in JSLazyEventListener
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-06-06 12:13 PDT by Chris Dumez
Modified: 2019-02-06 09:19 PST (History)
6 users (show)

See Also:


Attachments
Patch (17.69 KB, patch)
2018-06-06 12:21 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 2018-06-06 12:13:17 PDT
Do some hardening in JSLazyEventListener.
Comment 1 Chris Dumez 2018-06-06 12:13:31 PDT
<rdar://problem/34297947>
Comment 2 Chris Dumez 2018-06-06 12:21:54 PDT
Created attachment 342071 [details]
Patch
Comment 3 Geoffrey Garen 2018-06-06 12:30:27 PDT
Comment on attachment 342071 [details]
Patch

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

> Source/WebCore/dom/NodeRareData.cpp:41
>  struct SameSizeAsNodeRareData {
>      unsigned m_bitfields : 20;
> -    void* m_pointer[3];
> +    void* m_pointer[4];
>  };
>  
>  COMPILE_ASSERT(sizeof(NodeRareData) == sizeof(SameSizeAsNodeRareData), NodeRareDataShouldStaySmall);

It looks like Ryosuke at one point believed it was important to performance for this class to stay small: <https://trac.webkit.org/changeset/137003/webkit>.

Are we sure it's OK to get bigger, especially just for hardening?

I believe that only elements can have inline event listeners. Maybe we reduce the pain by putting the weak pointer factory on element?
Comment 4 Chris Dumez 2018-06-06 12:34:40 PDT
(In reply to Geoffrey Garen from comment #3)
> Comment on attachment 342071 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=342071&action=review
> 
> > Source/WebCore/dom/NodeRareData.cpp:41
> >  struct SameSizeAsNodeRareData {
> >      unsigned m_bitfields : 20;
> > -    void* m_pointer[3];
> > +    void* m_pointer[4];
> >  };
> >  
> >  COMPILE_ASSERT(sizeof(NodeRareData) == sizeof(SameSizeAsNodeRareData), NodeRareDataShouldStaySmall);
> 
> It looks like Ryosuke at one point believed it was important to performance
> for this class to stay small:
> <https://trac.webkit.org/changeset/137003/webkit>.

I will let Ryosuke comment on this.

> 
> Are we sure it's OK to get bigger, especially just for hardening?

Well, hardening against a very valid crash (see radar).

> 
> I believe that only elements can have inline event listeners. Maybe we
> reduce the pain by putting the weak pointer factory on element?

In this class, m_originalNode can either be an Element or a Document, so I don't think I can move it to Element / ElementRareData.

Note that until fairly recently, we had a WeakPtrFactory in ElementRareData. I killed recently because there were no more users for it. That said, we never saw a regression when I added this WeakPtrFactory in ElementRareData in the past.
Comment 5 Geoffrey Garen 2018-06-06 12:39:00 PDT
> > Are we sure it's OK to get bigger, especially just for hardening?
> 
> Well, hardening against a very valid crash (see radar).

Yeah, I guess it's a distraction to question the value of hardening. Let's focus on whether it's OK to grow this data structure, and what alternatives to consider if it's not OK.
Comment 6 Ryosuke Niwa 2018-06-06 22:35:15 PDT
Comment on attachment 342071 [details]
Patch

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

>>> Source/WebCore/dom/NodeRareData.cpp:41
>>>  COMPILE_ASSERT(sizeof(NodeRareData) == sizeof(SameSizeAsNodeRareData), NodeRareDataShouldStaySmall);
>> 
>> It looks like Ryosuke at one point believed it was important to performance for this class to stay small: <https://trac.webkit.org/changeset/137003/webkit>.
>> 
>> Are we sure it's OK to get bigger, especially just for hardening?
>> 
>> I believe that only elements can have inline event listeners. Maybe we reduce the pain by putting the weak pointer factory on element?
> 
> I will let Ryosuke comment on this.

I don't think this is okay. We make zillions of Text nodes with whitespaces in any given page.
We should limit this to only Element and also run Speedometer, PLT, & our internal memory tests to ensure there is no regression.
Comment 7 Chris Dumez 2018-06-07 08:51:41 PDT
(In reply to Ryosuke Niwa from comment #6)
> Comment on attachment 342071 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=342071&action=review
> 
> >>> Source/WebCore/dom/NodeRareData.cpp:41
> >>>  COMPILE_ASSERT(sizeof(NodeRareData) == sizeof(SameSizeAsNodeRareData), NodeRareDataShouldStaySmall);
> >> 
> >> It looks like Ryosuke at one point believed it was important to performance for this class to stay small: <https://trac.webkit.org/changeset/137003/webkit>.
> >> 
> >> Are we sure it's OK to get bigger, especially just for hardening?
> >> 
> >> I believe that only elements can have inline event listeners. Maybe we reduce the pain by putting the weak pointer factory on element?
> > 
> > I will let Ryosuke comment on this.
> 
> I don't think this is okay. We make zillions of Text nodes with whitespaces
> in any given page.
> We should limit this to only Element and also run Speedometer, PLT, & our
> internal memory tests to ensure there is no regression.

As I previously explained, I did not limit this to Element because m_originalNode is a ContainerNode (can be an Element or a Document).
Comment 8 Chris Dumez 2018-06-08 11:16:30 PDT
WONTFIX for now, even though this seems power-neutral on Speedometer. I'll try and get better repro-steps for the crash to fix the underlying issue instead.
Comment 9 Lucas Forschler 2019-02-06 09:19:09 PST
Mass move bugs into the DOM component.