Changeset 228678 in webkit


Ignore:
Timestamp:
Feb 19, 2018 5:59:56 AM (6 years ago)
Author:
Carlos Garcia Campos
Message:

Merge r228453 - REGRESSION(r228313): Membuster | macOS | All Devices | 1.5 MB
https://bugs.webkit.org/show_bug.cgi?id=182744
<rdar://problem/37463770>

Reviewed by Zalan Bujtas.

We need to respect low memory notifications explicitly now that the compiled selectors are not part of RuleData.

  • css/StyleRule.cpp:

(WebCore::StyleRule::StyleRule):

  • css/StyleRule.h:

Switch to std::unique_ptr<[]> from Vector to avoid unnecessary bloat.

  • css/StyleSheetContents.cpp:

(WebCore::traverseRulesInVector):
(WebCore::StyleSheetContents::traverseRules const):

Add a rule traversal function, similar to the existing traverseSubresources.

(WebCore::StyleSheetContents::traverseSubresources const):

Use traverseRules to implement traverseSubresources.

(WebCore::traverseSubresourcesInRules): Deleted.

  • css/StyleSheetContents.h:
  • page/MemoryRelease.cpp:

(WebCore::releaseCriticalMemory):

  • style/StyleScope.cpp:

(WebCore::Style::Scope::releaseMemory):

Release memory for compiled selectors on memory notification.

  • style/StyleScope.h:
Location:
releases/WebKitGTK/webkit-2.20/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog

    r228677 r228678  
     12018-02-13  Antti Koivisto  <antti@apple.com>
     2
     3        REGRESSION(r228313): Membuster | macOS | All Devices | 1.5 MB
     4        https://bugs.webkit.org/show_bug.cgi?id=182744
     5        <rdar://problem/37463770>
     6
     7        Reviewed by Zalan Bujtas.
     8
     9        We need to respect low memory notifications explicitly now that the compiled selectors are not part of RuleData.
     10
     11        * css/StyleRule.cpp:
     12        (WebCore::StyleRule::StyleRule):
     13        * css/StyleRule.h:
     14
     15        Switch to std::unique_ptr<[]> from Vector to avoid unnecessary bloat.
     16
     17        * css/StyleSheetContents.cpp:
     18        (WebCore::traverseRulesInVector):
     19        (WebCore::StyleSheetContents::traverseRules const):
     20
     21        Add a rule traversal function, similar to the existing traverseSubresources.
     22
     23        (WebCore::StyleSheetContents::traverseSubresources const):
     24
     25        Use traverseRules to implement traverseSubresources.
     26
     27        (WebCore::traverseSubresourcesInRules): Deleted.
     28        * css/StyleSheetContents.h:
     29        * page/MemoryRelease.cpp:
     30        (WebCore::releaseCriticalMemory):
     31        * style/StyleScope.cpp:
     32        (WebCore::Style::Scope::releaseMemory):
     33
     34        Release memory for compiled selectors on memory notification.
     35
     36        * style/StyleScope.h:
     37
    1382018-02-09  Antti Koivisto  <antti@apple.com>
    239
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.cpp

    r228677 r228678  
    192192    , m_properties(o.properties().mutableCopy())
    193193    , m_selectorList(o.m_selectorList)
    194 #if ENABLE(CSS_SELECTOR_JIT)
    195     , m_compiledSelectors(o.m_compiledSelectors)
    196 #endif
    197194{
    198195}
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.h

    r228677 r228678  
    133133    using StyleRuleBase::hasDocumentSecurityOrigin;
    134134
    135     void parserAdoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectors) { m_selectorList.adoptSelectorVector(selectors); }
    136     void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList = WTFMove(selectors); }
     135    void wrapperAdoptSelectorList(CSSSelectorList& selectors)
     136    {
     137        m_selectorList = WTFMove(selectors);
     138#if ENABLE(CSS_SELECTOR_JIT)
     139        m_compiledSelectors = nullptr;
     140#endif
     141    }
    137142    void parserAdoptSelectorArray(CSSSelector* selectors) { m_selectorList.adoptSelectorArray(selectors); }
    138143
     
    144149    CompiledSelector& compiledSelectorForListIndex(unsigned index)
    145150    {
    146         if (m_compiledSelectors.isEmpty())
    147             m_compiledSelectors.grow(m_selectorList.listSize());
     151        if (!m_compiledSelectors)
     152            m_compiledSelectors = std::make_unique<CompiledSelector[]>(m_selectorList.listSize());
    148153        return m_compiledSelectors[index];
     154    }
     155    void releaseCompiledSelectors() const
     156    {
     157        m_compiledSelectors = nullptr;
    149158    }
    150159#endif
     
    162171
    163172#if ENABLE(CSS_SELECTOR_JIT)
    164     Vector<CompiledSelector> m_compiledSelectors;
     173    mutable std::unique_ptr<CompiledSelector[]> m_compiledSelectors;
    165174#endif
    166175};
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleSheetContents.cpp

    r222259 r228678  
    431431}
    432432
    433 static bool traverseSubresourcesInRules(const Vector<RefPtr<StyleRuleBase>>& rules, const WTF::Function<bool (const CachedResource&)>& handler)
     433static bool traverseRulesInVector(const Vector<RefPtr<StyleRuleBase>>& rules, const WTF::Function<bool (const StyleRuleBase&)>& handler)
    434434{
    435435    for (auto& rule : rules) {
     436        if (handler(*rule))
     437            return true;
    436438        switch (rule->type()) {
    437         case StyleRuleBase::Style: {
    438             auto* properties = downcast<StyleRule>(*rule).propertiesWithoutDeferredParsing();
    439             if (properties && properties->traverseSubresources(handler))
    440                 return true;
    441             break;
    442         }
    443         case StyleRuleBase::FontFace:
    444             if (downcast<StyleRuleFontFace>(*rule).properties().traverseSubresources(handler))
    445                 return true;
    446             break;
    447439        case StyleRuleBase::Media: {
    448440            auto* childRules = downcast<StyleRuleMedia>(*rule).childRulesWithoutDeferredParsing();
    449             if (childRules && traverseSubresourcesInRules(*childRules, handler))
     441            if (childRules && traverseRulesInVector(*childRules, handler))
    450442                return true;
    451443            break;
     
    453445        case StyleRuleBase::Import:
    454446            ASSERT_NOT_REACHED();
    455 #if ASSERT_DISABLED
    456             FALLTHROUGH;
    457 #endif
     447            break;
     448        case StyleRuleBase::Style:
     449        case StyleRuleBase::FontFace:
    458450        case StyleRuleBase::Page:
    459451        case StyleRuleBase::Keyframes:
     
    472464}
    473465
     466bool StyleSheetContents::traverseRules(const WTF::Function<bool (const StyleRuleBase&)>& handler) const
     467{
     468    for (auto& importRule : m_importRules) {
     469        if (handler(*importRule))
     470            return true;
     471        auto* importedStyleSheet = importRule->styleSheet();
     472        if (importedStyleSheet && importedStyleSheet->traverseRules(handler))
     473            return true;
     474    }
     475    return traverseRulesInVector(m_childRules, handler);
     476}
     477
    474478bool StyleSheetContents::traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const
    475479{
    476     for (auto& importRule : m_importRules) {
    477         if (auto* cachedResource = importRule->cachedCSSStyleSheet()) {
    478             if (handler(*cachedResource))
    479                 return true;
     480    return traverseRules([&] (const StyleRuleBase& rule) {
     481        switch (rule.type()) {
     482        case StyleRuleBase::Style: {
     483            auto* properties = downcast<StyleRule>(rule).propertiesWithoutDeferredParsing();
     484            return properties && properties->traverseSubresources(handler);
    480485        }
    481         auto* importedStyleSheet = importRule->styleSheet();
    482         if (importedStyleSheet && importedStyleSheet->traverseSubresources(handler))
    483             return true;
    484     }
    485     return traverseSubresourcesInRules(m_childRules, handler);
     486        case StyleRuleBase::FontFace:
     487            return downcast<StyleRuleFontFace>(rule).properties().traverseSubresources(handler);
     488        case StyleRuleBase::Import:
     489            if (auto* cachedResource = downcast<StyleRuleImport>(rule).cachedCSSStyleSheet())
     490                return handler(*cachedResource);
     491            return false;
     492        case StyleRuleBase::Media:
     493        case StyleRuleBase::Page:
     494        case StyleRuleBase::Keyframes:
     495        case StyleRuleBase::Namespace:
     496        case StyleRuleBase::Unknown:
     497        case StyleRuleBase::Charset:
     498        case StyleRuleBase::Keyframe:
     499        case StyleRuleBase::Supports:
     500#if ENABLE(CSS_DEVICE_ADAPTATION)
     501        case StyleRuleBase::Viewport:
     502#endif
     503            return false;
     504        };
     505        ASSERT_NOT_REACHED();
     506        return false;
     507    });
    486508}
    487509
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleSheetContents.h

    r222422 r228678  
    8787
    8888    URL completeURL(const String& url) const;
     89    bool traverseRules(const WTF::Function<bool (const StyleRuleBase&)>& handler) const;
    8990    bool traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const;
    9091
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/page/MemoryRelease.cpp

    r223238 r228678  
    8585
    8686    for (auto& document : copyToVectorOf<RefPtr<Document>>(Document::allDocuments())) {
    87         document->styleScope().clearResolver();
     87        document->styleScope().releaseMemory();
    8888        document->fontSelector().emptyCaches();
    8989    }
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/style/StyleScope.cpp

    r224864 r228678  
    133133    if (!m_shadowRoot)
    134134        m_document.didClearStyleResolver();
     135}
     136
     137void Scope::releaseMemory()
     138{
     139    if (!m_shadowRoot) {
     140        for (auto* descendantShadowRoot : m_document.inDocumentShadowRoots())
     141            descendantShadowRoot->styleScope().releaseMemory();
     142    }
     143
     144#if ENABLE(CSS_SELECTOR_JIT)
     145    for (auto& sheet : m_activeStyleSheets) {
     146        sheet->contents().traverseRules([] (const StyleRuleBase& rule) {
     147            if (is<StyleRule>(rule))
     148                downcast<StyleRule>(rule).releaseCompiledSelectors();
     149            return false;
     150        });
     151    }
     152#endif
     153    clearResolver();
    135154}
    136155
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/style/StyleScope.h

    r224535 r228678  
    119119    StyleResolver* resolverIfExists();
    120120    void clearResolver();
     121    void releaseMemory();
    121122
    122123    const Document& document() const { return m_document; }
Note: See TracChangeset for help on using the changeset viewer.