Changeset 228677 in webkit
- Timestamp:
- Feb 19, 2018 5:59:49 AM (6 years ago)
- 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 1 2018-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 1 51 2018-02-08 Antoine Quint <graouts@apple.com> 2 52 -
releases/WebKitGTK/webkit-2.20/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r228632 r228677 14008 14008 E43AF8E51AC5B7DD00CA717E /* CacheValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheValidation.h; sourceTree = "<group>"; }; 14009 14009 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>"; }; 14010 14011 E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLAudioElement.cpp; sourceTree = "<group>"; }; 14011 14012 E44613900CD6331000FADA75 /* HTMLAudioElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLAudioElement.h; sourceTree = "<group>"; }; … … 15975 15976 isa = PBXGroup; 15976 15977 children = ( 15978 E4451077202C7E0100657D33 /* CompiledSelector.h */, 15977 15979 26B999921803B9D900D01121 /* FunctionCall.h */, 15978 15980 26B9998E1803AE7200D01121 /* RegisterAllocator.h */, -
releases/WebKitGTK/webkit-2.20/Source/WebCore/css/CSSSelectorList.cpp
r219237 r228677 96 96 } 97 97 98 unsigned 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 98 112 CSSSelectorList& CSSSelectorList::operator=(CSSSelectorList&& other) 99 113 { -
releases/WebKitGTK/webkit-2.20/Source/WebCore/css/CSSSelectorList.h
r208668 r228677 67 67 68 68 unsigned componentCount() const; 69 unsigned listSize() const; 69 70 70 71 CSSSelectorList& operator=(CSSSelectorList&&); -
releases/WebKitGTK/webkit-2.20/Source/WebCore/css/DocumentRuleSets.cpp
r228669 r228677 115 115 auto ruleSet = std::make_unique<RuleSet>(); 116 116 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); 118 118 ruleSet->shrinkToFit(); 119 119 return ruleSet; … … 188 188 if (!ruleSet) 189 189 ruleSet = std::make_unique<RuleSet>(); 190 ruleSet->addRule(feature.rule, feature.selectorIndex );190 ruleSet->addRule(feature.rule, feature.selectorIndex, feature.selectorListIndex); 191 191 if (feature.invalidationSelector) 192 192 invalidationSelectorArray[arrayIndex].append(feature.invalidationSelector); -
releases/WebKitGTK/webkit-2.20/Source/WebCore/css/ElementRuleCollector.cpp
r226011 r228677 384 384 385 385 #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); 398 396 #if !ASSERT_MSG_DISABLED 399 397 unsigned ignoreSpecificity; … … 421 419 #if ENABLE(CSS_SELECTOR_JIT) 422 420 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); 426 424 427 425 #if CSS_SELECTOR_JIT_PROFILING 428 ruleData.compiledSelectorUsed();426 compiledSelector.useCount++; 429 427 #endif 430 428 selectorMatches = selectorChecker(&m_element, &context, &specificity); -
releases/WebKitGTK/webkit-2.20/Source/WebCore/css/RuleFeature.cpp
r228669 r228677 169 169 recursivelyCollectFeaturesFromSelector(selectorFeatures, *ruleData.selector()); 170 170 if (selectorFeatures.hasSiblingSelector) 171 siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex() ));171 siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.selectorListIndex())); 172 172 if (ruleData.containsUncommonAttributeSelector()) 173 uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex() ));173 uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.selectorListIndex())); 174 174 175 175 for (auto& nameAndMatch : selectorFeatures.classes) { 176 176 classRules.ensure(nameAndMatch.first, [] { 177 177 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)); 179 179 if (nameAndMatch.second == MatchElement::Host) 180 180 classesAffectingHost.add(nameAndMatch.first); 181 181 } 182 183 182 for (auto& selectorAndMatch : selectorFeatures.attributes) { 184 183 auto* selector = selectorAndMatch.first; … … 186 185 attributeRules.ensure(selector->attribute().localName().convertToASCIILowercase(), [] { 187 186 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)); 189 188 if (matchElement == MatchElement::Host) 190 189 attributesAffectingHost.add(selector->attribute().localName().convertToASCIILowercase()); -
releases/WebKitGTK/webkit-2.20/Source/WebCore/css/RuleFeature.h
r228669 r228677 38 38 39 39 struct 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) 41 41 : rule(rule) 42 42 , selectorIndex(selectorIndex) 43 , selectorListIndex(selectorListIndex) 43 44 , matchElement(matchElement) 44 45 , invalidationSelector(invalidationSelector) … … 47 48 StyleRule* rule; 48 49 unsigned selectorIndex; 50 unsigned selectorListIndex; 49 51 std::optional<MatchElement> matchElement; 50 52 const CSSSelector* invalidationSelector; -
releases/WebKitGTK/webkit-2.20/Source/WebCore/css/RuleSet.cpp
r225650 r228677 149 149 } 150 150 151 RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position)151 RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned selectorListIndex, unsigned position) 152 152 : m_rule(rule) 153 153 , m_selectorIndex(selectorIndex) 154 , m_selectorListIndex(selectorListIndex) 154 155 , m_position(position) 155 156 , m_matchBasedOnRuleHash(static_cast<unsigned>(computeMatchBasedOnRuleHash(*selector()))) … … 159 160 , m_propertyWhitelistType(determinePropertyWhitelistType(selector())) 160 161 , m_descendantSelectorIdentifierHashes(SelectorFilter::collectHashes(*selector())) 161 #if ENABLE(CSS_SELECTOR_JIT) && CSS_SELECTOR_JIT_PROFILING162 , m_compiledSelectorUseCount(0)163 #endif164 162 { 165 163 ASSERT(m_position == position); … … 202 200 } 203 201 204 void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex )205 { 206 RuleData ruleData(rule, selectorIndex, m_ruleCount++);202 void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex, unsigned selectorListIndex) 203 { 204 RuleData ruleData(rule, selectorIndex, selectorListIndex, m_ruleCount++); 207 205 m_features.collectFeatures(ruleData); 208 206 … … 405 403 void RuleSet::addStyleRule(StyleRule* rule) 406 404 { 405 unsigned selectorListIndex = 0; 407 406 for (size_t selectorIndex = 0; selectorIndex != notFound; selectorIndex = rule->selectorList().indexOfNextSelectorAfter(selectorIndex)) 408 addRule(rule, selectorIndex );407 addRule(rule, selectorIndex, selectorListIndex++); 409 408 } 410 409 -
releases/WebKitGTK/webkit-2.20/Source/WebCore/css/RuleSet.h
r225650 r228677 60 60 static const unsigned maximumSelectorComponentCount = 8192; 61 61 62 RuleData(StyleRule*, unsigned selectorIndex, unsigned position);62 RuleData(StyleRule*, unsigned selectorIndex, unsigned selectorListIndex, unsigned position); 63 63 64 64 unsigned position() const { return m_position; } … … 66 66 const CSSSelector* selector() const { return m_rule->selectorList().selectorAt(m_selectorIndex); } 67 67 unsigned selectorIndex() const { return m_selectorIndex; } 68 unsigned selectorListIndex() const { return m_selectorListIndex; } 68 69 69 70 bool canMatchPseudoElement() const { return m_canMatchPseudoElement; } … … 76 77 void disableSelectorFiltering() { m_descendantSelectorIdentifierHashes[0] = 0; } 77 78 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) const82 {83 m_compilationStatus = status;84 m_compiledSelectorCodeRef = codeRef;85 }86 #if CSS_SELECTOR_JIT_PROFILING87 ~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 #endif94 #endif // ENABLE(CSS_SELECTOR_JIT)95 96 79 private: 97 80 RefPtr<StyleRule> m_rule; 98 unsigned m_selectorIndex : 13; 81 unsigned m_selectorIndex : 16; 82 unsigned m_selectorListIndex : 16; 99 83 // This number was picked fairly arbitrarily. We can probably lower it if we need to. 100 84 // Some simple testing showed <100,000 RuleData's on large sites. … … 106 90 unsigned m_propertyWhitelistType : 2; 107 91 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_PROFILING112 mutable unsigned m_compiledSelectorUseCount;113 #endif114 #endif // ENABLE(CSS_SELECTOR_JIT)115 92 }; 116 93 117 94 struct SameSizeAsRuleData { 118 #if ENABLE(CSS_SELECTOR_JIT)119 unsigned compilationStatus;120 void* compiledSelectorPointer;121 void* codeRefPtr;122 #if CSS_SELECTOR_JIT_PROFILING123 unsigned compiledSelectorUseCount;124 #endif125 #endif // ENABLE(CSS_SELECTOR_JIT)126 127 95 void* a; 128 96 unsigned b; … … 153 121 154 122 void addStyleRule(StyleRule*); 155 void addRule(StyleRule*, unsigned selectorIndex );123 void addRule(StyleRule*, unsigned selectorIndex, unsigned selectorListIndex); 156 124 void addPageRule(StyleRulePage*); 157 125 void addToRuleSet(const AtomicString& key, AtomRuleMap&, const RuleData&); -
releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.cpp
r225650 r228677 192 192 , m_properties(o.properties().mutableCopy()) 193 193 , m_selectorList(o.m_selectorList) 194 #if ENABLE(CSS_SELECTOR_JIT) 195 , m_compiledSelectors(o.m_compiledSelectors) 196 #endif 194 197 { 195 198 } -
releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.h
r225650 r228677 23 23 24 24 #include "CSSSelectorList.h" 25 #include "CompiledSelector.h" 25 26 #include "StyleProperties.h" 26 27 #include <wtf/RefPtr.h> … … 140 141 Vector<RefPtr<StyleRule>> splitIntoMultipleRulesWithMaximumSelectorComponentCount(unsigned) const; 141 142 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 142 152 static unsigned averageSizeInBytes(); 143 153 … … 150 160 mutable Ref<StylePropertiesBase> m_properties; 151 161 CSSSelectorList m_selectorList; 162 163 #if ENABLE(CSS_SELECTOR_JIT) 164 Vector<CompiledSelector> m_compiledSelectors; 165 #endif 152 166 }; 153 167 -
releases/WebKitGTK/webkit-2.20/Source/WebCore/cssjit/SelectorCompiler.h
r226011 r228677 28 28 #if ENABLE(CSS_SELECTOR_JIT) 29 29 30 #include "CompiledSelector.h" 30 31 #include "SelectorChecker.h" 31 #include <JavaScriptCore/MacroAssemblerCodeRef.h>32 32 33 33 #define CSS_SELECTOR_JIT_PROFILING 0 34 35 namespace JSC {36 class MacroAssemblerCodeRef;37 }38 34 39 35 namespace WebCore { … … 41 37 class CSSSelector; 42 38 class Element; 43 class RenderStyle;44 45 class SelectorCompilationStatus {46 public:47 enum Status {48 NotCompiled,49 CannotCompile,50 SimpleSelectorChecker,51 SelectorCheckerWithCheckingContext52 };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 };67 39 68 40 namespace SelectorCompiler {
Note: See TracChangeset
for help on using the changeset viewer.