Changeset 228677 in webkit


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

Merge r228313 - Move compiled selectors to StyleRule
https://bugs.webkit.org/show_bug.cgi?id=182602

Reviewed by Zalan Bujtas.

Currently they are owned by RuleData. Several RuleData objects can refer to the same StyleRule, requiring recompilation.
Compiled selectors are context-independent so they can be shared between all clients.

  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSSelectorList.cpp:

(WebCore::CSSSelectorList::listSize const):

Compute the number of complex selectors on the list.

  • css/CSSSelectorList.h:
  • css/DocumentRuleSets.cpp:

(WebCore::makeRuleSet):
(WebCore::DocumentRuleSets::classInvalidationRuleSets const):

Pass around list index along with the selector index (compiled selectors are found by list index).

  • css/ElementRuleCollector.cpp:

(WebCore::ElementRuleCollector::ruleMatches):

  • css/RuleSet.cpp:

(WebCore::RuleData::RuleData):

  • css/RuleSet.h:

(WebCore::RuleData::compilationStatus const): Deleted.
(WebCore::RuleData::compiledSelectorCodeRef const): Deleted.
(WebCore::RuleData::setCompiledSelector const): Deleted.
(WebCore::RuleData::~RuleData): Deleted.
(WebCore::RuleData::compiledSelectorUsed const): Deleted.

  • css/StyleRule.cpp:

(WebCore::StyleRule::StyleRule):

  • css/StyleRule.h:

Add CompiledSelector member.

  • cssjit/CompiledSelector.h: Added.

Move to a header of its own to keeps dependencies simple.

(WebCore::SelectorCompilationStatus::SelectorCompilationStatus):
(WebCore::SelectorCompilationStatus::operator Status const):

  • cssjit/SelectorCompiler.h:

(): Deleted.
(WebCore::SelectorCompilationStatus::SelectorCompilationStatus): Deleted.
(WebCore::SelectorCompilationStatus::operator Status const): Deleted.

Location:
releases/WebKitGTK/webkit-2.20/Source/WebCore
Files:
1 added
13 edited

Legend:

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

    r228676 r228677  
     12018-02-09  Antti Koivisto  <antti@apple.com>
     2
     3        Move compiled selectors to StyleRule
     4        https://bugs.webkit.org/show_bug.cgi?id=182602
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Currently they are owned by RuleData. Several RuleData objects can refer to the same StyleRule, requiring recompilation.
     9        Compiled selectors are context-independent so they can be shared between all clients.
     10
     11        * WebCore.xcodeproj/project.pbxproj:
     12        * css/CSSSelectorList.cpp:
     13        (WebCore::CSSSelectorList::listSize const):
     14
     15        Compute the number of complex selectors on the list.
     16
     17        * css/CSSSelectorList.h:
     18        * css/DocumentRuleSets.cpp:
     19        (WebCore::makeRuleSet):
     20        (WebCore::DocumentRuleSets::classInvalidationRuleSets const):
     21
     22        Pass around list index along with the selector index (compiled selectors are found by list index).
     23
     24        * css/ElementRuleCollector.cpp:
     25        (WebCore::ElementRuleCollector::ruleMatches):
     26        * css/RuleSet.cpp:
     27        (WebCore::RuleData::RuleData):
     28        * css/RuleSet.h:
     29        (WebCore::RuleData::compilationStatus const): Deleted.
     30        (WebCore::RuleData::compiledSelectorCodeRef const): Deleted.
     31        (WebCore::RuleData::setCompiledSelector const): Deleted.
     32        (WebCore::RuleData::~RuleData): Deleted.
     33        (WebCore::RuleData::compiledSelectorUsed const): Deleted.
     34        * css/StyleRule.cpp:
     35        (WebCore::StyleRule::StyleRule):
     36        * css/StyleRule.h:
     37
     38            Add CompiledSelector member.
     39
     40        * cssjit/CompiledSelector.h: Added.
     41
     42            Move to a header of its own to keeps dependencies simple.
     43
     44        (WebCore::SelectorCompilationStatus::SelectorCompilationStatus):
     45        (WebCore::SelectorCompilationStatus::operator Status const):
     46        * cssjit/SelectorCompiler.h:
     47        (): Deleted.
     48        (WebCore::SelectorCompilationStatus::SelectorCompilationStatus): Deleted.
     49        (WebCore::SelectorCompilationStatus::operator Status const): Deleted.
     50
    1512018-02-08  Antoine Quint  <graouts@apple.com>
    252
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r228632 r228677  
    1400814008                E43AF8E51AC5B7DD00CA717E /* CacheValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheValidation.h; sourceTree = "<group>"; };
    1400914009                E440AA951C68420800A265CC /* ElementAndTextDescendantIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementAndTextDescendantIterator.h; sourceTree = "<group>"; };
     14010                E4451077202C7E0100657D33 /* CompiledSelector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompiledSelector.h; sourceTree = "<group>"; };
    1401014011                E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLAudioElement.cpp; sourceTree = "<group>"; };
    1401114012                E44613900CD6331000FADA75 /* HTMLAudioElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLAudioElement.h; sourceTree = "<group>"; };
     
    1597515976                        isa = PBXGroup;
    1597615977                        children = (
     15978                                E4451077202C7E0100657D33 /* CompiledSelector.h */,
    1597715979                                26B999921803B9D900D01121 /* FunctionCall.h */,
    1597815980                                26B9998E1803AE7200D01121 /* RegisterAllocator.h */,
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/CSSSelectorList.cpp

    r219237 r228677  
    9696}
    9797
     98unsigned CSSSelectorList::listSize() const
     99{
     100    if (!m_selectorArray)
     101        return 0;
     102    unsigned size = 1;
     103    CSSSelector* current = m_selectorArray;
     104    while (!current->isLastInSelectorList()) {
     105        if (current->isLastInTagHistory())
     106            ++size;
     107        ++current;
     108    }
     109    return size;
     110}
     111
    98112CSSSelectorList& CSSSelectorList::operator=(CSSSelectorList&& other)
    99113{
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/CSSSelectorList.h

    r208668 r228677  
    6767
    6868    unsigned componentCount() const;
     69    unsigned listSize() const;
    6970
    7071    CSSSelectorList& operator=(CSSSelectorList&&);
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/DocumentRuleSets.cpp

    r228669 r228677  
    115115    auto ruleSet = std::make_unique<RuleSet>();
    116116    for (size_t i = 0; i < size; ++i)
    117         ruleSet->addRule(rules[i].rule, rules[i].selectorIndex);
     117        ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, rules[i].selectorListIndex);
    118118    ruleSet->shrinkToFit();
    119119    return ruleSet;
     
    188188            if (!ruleSet)
    189189                ruleSet = std::make_unique<RuleSet>();
    190             ruleSet->addRule(feature.rule, feature.selectorIndex);
     190            ruleSet->addRule(feature.rule, feature.selectorIndex, feature.selectorListIndex);
    191191            if (feature.invalidationSelector)
    192192                invalidationSelectorArray[arrayIndex].append(feature.invalidationSelector);
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/ElementRuleCollector.cpp

    r226011 r228677  
    384384
    385385#if ENABLE(CSS_SELECTOR_JIT)
    386     void* compiledSelectorChecker = ruleData.compiledSelectorCodeRef().code().executableAddress();
    387     if (!compiledSelectorChecker && ruleData.compilationStatus() == SelectorCompilationStatus::NotCompiled) {
    388         SelectorCompilationStatus compilationStatus;
    389         JSC::MacroAssemblerCodeRef compiledSelectorCodeRef;
    390         compilationStatus = SelectorCompiler::compileSelector(ruleData.selector(), SelectorCompiler::SelectorContext::RuleCollector, compiledSelectorCodeRef);
    391 
    392         ruleData.setCompiledSelector(compilationStatus, compiledSelectorCodeRef);
    393         compiledSelectorChecker = ruleData.compiledSelectorCodeRef().code().executableAddress();
    394     }
    395 
    396     if (compiledSelectorChecker && ruleData.compilationStatus() == SelectorCompilationStatus::SimpleSelectorChecker) {
    397         SelectorCompiler::RuleCollectorSimpleSelectorChecker selectorChecker = SelectorCompiler::ruleCollectorSimpleSelectorCheckerFunction(compiledSelectorChecker, ruleData.compilationStatus());
     386    auto& compiledSelector = ruleData.rule()->compiledSelectorForListIndex(ruleData.selectorListIndex());
     387    void* compiledSelectorChecker = compiledSelector.codeRef.code().executableAddress();
     388    if (!compiledSelectorChecker && compiledSelector.status == SelectorCompilationStatus::NotCompiled) {
     389        compiledSelector.status = SelectorCompiler::compileSelector(ruleData.selector(), SelectorCompiler::SelectorContext::RuleCollector, compiledSelector.codeRef);
     390
     391        compiledSelectorChecker = compiledSelector.codeRef.code().executableAddress();
     392    }
     393
     394    if (compiledSelectorChecker && compiledSelector.status == SelectorCompilationStatus::SimpleSelectorChecker) {
     395        auto selectorChecker = SelectorCompiler::ruleCollectorSimpleSelectorCheckerFunction(compiledSelectorChecker, compiledSelector.status);
    398396#if !ASSERT_MSG_DISABLED
    399397        unsigned ignoreSpecificity;
     
    421419#if ENABLE(CSS_SELECTOR_JIT)
    422420    if (compiledSelectorChecker) {
    423         ASSERT(ruleData.compilationStatus() == SelectorCompilationStatus::SelectorCheckerWithCheckingContext);
    424 
    425         SelectorCompiler::RuleCollectorSelectorCheckerWithCheckingContext selectorChecker = SelectorCompiler::ruleCollectorSelectorCheckerFunctionWithCheckingContext(compiledSelectorChecker, ruleData.compilationStatus());
     421        ASSERT(compiledSelector.status == SelectorCompilationStatus::SelectorCheckerWithCheckingContext);
     422
     423        auto selectorChecker = SelectorCompiler::ruleCollectorSelectorCheckerFunctionWithCheckingContext(compiledSelectorChecker, compiledSelector.status);
    426424
    427425#if CSS_SELECTOR_JIT_PROFILING
    428         ruleData.compiledSelectorUsed();
     426        compiledSelector.useCount++;
    429427#endif
    430428        selectorMatches = selectorChecker(&m_element, &context, &specificity);
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/RuleFeature.cpp

    r228669 r228677  
    169169    recursivelyCollectFeaturesFromSelector(selectorFeatures, *ruleData.selector());
    170170    if (selectorFeatures.hasSiblingSelector)
    171         siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex()));
     171        siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.selectorListIndex()));
    172172    if (ruleData.containsUncommonAttributeSelector())
    173         uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex()));
     173        uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.selectorListIndex()));
    174174
    175175    for (auto& nameAndMatch : selectorFeatures.classes) {
    176176        classRules.ensure(nameAndMatch.first, [] {
    177177            return std::make_unique<Vector<RuleFeature>>();
    178         }).iterator->value->append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), nameAndMatch.second));
     178        }).iterator->value->append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.selectorListIndex(), nameAndMatch.second));
    179179        if (nameAndMatch.second == MatchElement::Host)
    180180            classesAffectingHost.add(nameAndMatch.first);
    181181    }
    182 
    183182    for (auto& selectorAndMatch : selectorFeatures.attributes) {
    184183        auto* selector = selectorAndMatch.first;
     
    186185        attributeRules.ensure(selector->attribute().localName().convertToASCIILowercase(), [] {
    187186            return std::make_unique<Vector<RuleFeature>>();
    188         }).iterator->value->append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), matchElement, selector));
     187        }).iterator->value->append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.selectorListIndex(), matchElement, selector));
    189188        if (matchElement == MatchElement::Host)
    190189            attributesAffectingHost.add(selector->attribute().localName().convertToASCIILowercase());
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/RuleFeature.h

    r228669 r228677  
    3838
    3939struct RuleFeature {
    40     RuleFeature(StyleRule* rule, unsigned selectorIndex, std::optional<MatchElement> matchElement = std::nullopt, const CSSSelector* invalidationSelector = nullptr)
     40    RuleFeature(StyleRule* rule, unsigned selectorIndex, unsigned selectorListIndex, std::optional<MatchElement> matchElement = std::nullopt, const CSSSelector* invalidationSelector = nullptr)
    4141        : rule(rule)
    4242        , selectorIndex(selectorIndex)
     43        , selectorListIndex(selectorListIndex)
    4344        , matchElement(matchElement)
    4445        , invalidationSelector(invalidationSelector)
     
    4748    StyleRule* rule;
    4849    unsigned selectorIndex;
     50    unsigned selectorListIndex;
    4951    std::optional<MatchElement> matchElement;
    5052    const CSSSelector* invalidationSelector;
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/RuleSet.cpp

    r225650 r228677  
    149149}
    150150
    151 RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position)
     151RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned selectorListIndex, unsigned position)
    152152    : m_rule(rule)
    153153    , m_selectorIndex(selectorIndex)
     154    , m_selectorListIndex(selectorListIndex)
    154155    , m_position(position)
    155156    , m_matchBasedOnRuleHash(static_cast<unsigned>(computeMatchBasedOnRuleHash(*selector())))
     
    159160    , m_propertyWhitelistType(determinePropertyWhitelistType(selector()))
    160161    , m_descendantSelectorIdentifierHashes(SelectorFilter::collectHashes(*selector()))
    161 #if ENABLE(CSS_SELECTOR_JIT) && CSS_SELECTOR_JIT_PROFILING
    162     , m_compiledSelectorUseCount(0)
    163 #endif
    164162{
    165163    ASSERT(m_position == position);
     
    202200}
    203201
    204 void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex)
    205 {
    206     RuleData ruleData(rule, selectorIndex, m_ruleCount++);
     202void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex, unsigned selectorListIndex)
     203{
     204    RuleData ruleData(rule, selectorIndex, selectorListIndex, m_ruleCount++);
    207205    m_features.collectFeatures(ruleData);
    208206
     
    405403void RuleSet::addStyleRule(StyleRule* rule)
    406404{
     405    unsigned selectorListIndex = 0;
    407406    for (size_t selectorIndex = 0; selectorIndex != notFound; selectorIndex = rule->selectorList().indexOfNextSelectorAfter(selectorIndex))
    408         addRule(rule, selectorIndex);
     407        addRule(rule, selectorIndex, selectorListIndex++);
    409408}
    410409
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/RuleSet.h

    r225650 r228677  
    6060    static const unsigned maximumSelectorComponentCount = 8192;
    6161
    62     RuleData(StyleRule*, unsigned selectorIndex, unsigned position);
     62    RuleData(StyleRule*, unsigned selectorIndex, unsigned selectorListIndex, unsigned position);
    6363
    6464    unsigned position() const { return m_position; }
     
    6666    const CSSSelector* selector() const { return m_rule->selectorList().selectorAt(m_selectorIndex); }
    6767    unsigned selectorIndex() const { return m_selectorIndex; }
     68    unsigned selectorListIndex() const { return m_selectorListIndex; }
    6869
    6970    bool canMatchPseudoElement() const { return m_canMatchPseudoElement; }
     
    7677    void disableSelectorFiltering() { m_descendantSelectorIdentifierHashes[0] = 0; }
    7778
    78 #if ENABLE(CSS_SELECTOR_JIT)
    79     SelectorCompilationStatus compilationStatus() const { return m_compilationStatus; }
    80     JSC::MacroAssemblerCodeRef compiledSelectorCodeRef() const { return m_compiledSelectorCodeRef; }
    81     void setCompiledSelector(SelectorCompilationStatus status, JSC::MacroAssemblerCodeRef codeRef) const
    82     {
    83         m_compilationStatus = status;
    84         m_compiledSelectorCodeRef = codeRef;
    85     }
    86 #if CSS_SELECTOR_JIT_PROFILING
    87     ~RuleData()
    88     {
    89         if (m_compiledSelectorCodeRef.code().executableAddress())
    90             dataLogF("RuleData compiled selector %d \"%s\"\n", m_compiledSelectorUseCount, selector()->selectorText().utf8().data());
    91     }
    92     void compiledSelectorUsed() const { m_compiledSelectorUseCount++; }
    93 #endif
    94 #endif // ENABLE(CSS_SELECTOR_JIT)
    95 
    9679private:
    9780    RefPtr<StyleRule> m_rule;
    98     unsigned m_selectorIndex : 13;
     81    unsigned m_selectorIndex : 16;
     82    unsigned m_selectorListIndex : 16;
    9983    // This number was picked fairly arbitrarily. We can probably lower it if we need to.
    10084    // Some simple testing showed <100,000 RuleData's on large sites.
     
    10690    unsigned m_propertyWhitelistType : 2;
    10791    SelectorFilter::Hashes m_descendantSelectorIdentifierHashes;
    108 #if ENABLE(CSS_SELECTOR_JIT)
    109     mutable SelectorCompilationStatus m_compilationStatus;
    110     mutable JSC::MacroAssemblerCodeRef m_compiledSelectorCodeRef;
    111 #if CSS_SELECTOR_JIT_PROFILING
    112     mutable unsigned m_compiledSelectorUseCount;
    113 #endif
    114 #endif // ENABLE(CSS_SELECTOR_JIT)
    11592};
    11693   
    11794struct SameSizeAsRuleData {
    118 #if ENABLE(CSS_SELECTOR_JIT)
    119     unsigned compilationStatus;
    120     void* compiledSelectorPointer;
    121     void* codeRefPtr;
    122 #if CSS_SELECTOR_JIT_PROFILING
    123     unsigned compiledSelectorUseCount;
    124 #endif
    125 #endif // ENABLE(CSS_SELECTOR_JIT)
    126 
    12795    void* a;
    12896    unsigned b;
     
    153121
    154122    void addStyleRule(StyleRule*);
    155     void addRule(StyleRule*, unsigned selectorIndex);
     123    void addRule(StyleRule*, unsigned selectorIndex, unsigned selectorListIndex);
    156124    void addPageRule(StyleRulePage*);
    157125    void addToRuleSet(const AtomicString& key, AtomRuleMap&, const RuleData&);
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.cpp

    r225650 r228677  
    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
    194197{
    195198}
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.h

    r225650 r228677  
    2323
    2424#include "CSSSelectorList.h"
     25#include "CompiledSelector.h"
    2526#include "StyleProperties.h"
    2627#include <wtf/RefPtr.h>
     
    140141    Vector<RefPtr<StyleRule>> splitIntoMultipleRulesWithMaximumSelectorComponentCount(unsigned) const;
    141142
     143#if ENABLE(CSS_SELECTOR_JIT)
     144    CompiledSelector& compiledSelectorForListIndex(unsigned index)
     145    {
     146        if (m_compiledSelectors.isEmpty())
     147            m_compiledSelectors.grow(m_selectorList.listSize());
     148        return m_compiledSelectors[index];
     149    }
     150#endif
     151
    142152    static unsigned averageSizeInBytes();
    143153
     
    150160    mutable Ref<StylePropertiesBase> m_properties;
    151161    CSSSelectorList m_selectorList;
     162
     163#if ENABLE(CSS_SELECTOR_JIT)
     164    Vector<CompiledSelector> m_compiledSelectors;
     165#endif
    152166};
    153167
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/cssjit/SelectorCompiler.h

    r226011 r228677  
    2828#if ENABLE(CSS_SELECTOR_JIT)
    2929
     30#include "CompiledSelector.h"
    3031#include "SelectorChecker.h"
    31 #include <JavaScriptCore/MacroAssemblerCodeRef.h>
    3232
    3333#define CSS_SELECTOR_JIT_PROFILING 0
    34 
    35 namespace JSC {
    36 class MacroAssemblerCodeRef;
    37 }
    3834
    3935namespace WebCore {
     
    4137class CSSSelector;
    4238class Element;
    43 class RenderStyle;
    44 
    45 class SelectorCompilationStatus {
    46 public:
    47     enum Status {
    48         NotCompiled,
    49         CannotCompile,
    50         SimpleSelectorChecker,
    51         SelectorCheckerWithCheckingContext
    52     };
    53 
    54     SelectorCompilationStatus()
    55         : m_status(NotCompiled)
    56     { }
    57 
    58     SelectorCompilationStatus(Status status)
    59         : m_status(status)
    60     { }
    61 
    62     operator Status() const { return m_status; }
    63 
    64 private:
    65     Status m_status;
    66 };
    6739
    6840namespace SelectorCompiler {
Note: See TracChangeset for help on using the changeset viewer.