Diff
Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog (228677 => 228678)
--- releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog 2018-02-19 13:59:49 UTC (rev 228677)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog 2018-02-19 13:59:56 UTC (rev 228678)
@@ -1,3 +1,40 @@
+2018-02-13 Antti Koivisto <an...@apple.com>
+
+ 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:
+
2018-02-09 Antti Koivisto <an...@apple.com>
Move compiled selectors to StyleRule
Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.cpp (228677 => 228678)
--- releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.cpp 2018-02-19 13:59:49 UTC (rev 228677)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.cpp 2018-02-19 13:59:56 UTC (rev 228678)
@@ -191,9 +191,6 @@
: StyleRuleBase(o)
, m_properties(o.properties().mutableCopy())
, m_selectorList(o.m_selectorList)
-#if ENABLE(CSS_SELECTOR_JIT)
- , m_compiledSelectors(o.m_compiledSelectors)
-#endif
{
}
Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.h (228677 => 228678)
--- releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.h 2018-02-19 13:59:49 UTC (rev 228677)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleRule.h 2018-02-19 13:59:56 UTC (rev 228678)
@@ -132,8 +132,13 @@
using StyleRuleBase::hasDocumentSecurityOrigin;
- void parserAdoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectors) { m_selectorList.adoptSelectorVector(selectors); }
- void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList = WTFMove(selectors); }
+ void wrapperAdoptSelectorList(CSSSelectorList& selectors)
+ {
+ m_selectorList = WTFMove(selectors);
+#if ENABLE(CSS_SELECTOR_JIT)
+ m_compiledSelectors = nullptr;
+#endif
+ }
void parserAdoptSelectorArray(CSSSelector* selectors) { m_selectorList.adoptSelectorArray(selectors); }
Ref<StyleRule> copy() const { return adoptRef(*new StyleRule(*this)); }
@@ -143,10 +148,14 @@
#if ENABLE(CSS_SELECTOR_JIT)
CompiledSelector& compiledSelectorForListIndex(unsigned index)
{
- if (m_compiledSelectors.isEmpty())
- m_compiledSelectors.grow(m_selectorList.listSize());
+ if (!m_compiledSelectors)
+ m_compiledSelectors = std::make_unique<CompiledSelector[]>(m_selectorList.listSize());
return m_compiledSelectors[index];
}
+ void releaseCompiledSelectors() const
+ {
+ m_compiledSelectors = nullptr;
+ }
#endif
static unsigned averageSizeInBytes();
@@ -161,7 +170,7 @@
CSSSelectorList m_selectorList;
#if ENABLE(CSS_SELECTOR_JIT)
- Vector<CompiledSelector> m_compiledSelectors;
+ mutable std::unique_ptr<CompiledSelector[]> m_compiledSelectors;
#endif
};
Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleSheetContents.cpp (228677 => 228678)
--- releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleSheetContents.cpp 2018-02-19 13:59:49 UTC (rev 228677)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleSheetContents.cpp 2018-02-19 13:59:56 UTC (rev 228678)
@@ -430,31 +430,23 @@
return m_parserContext.completeURL(url);
}
-static bool traverseSubresourcesInRules(const Vector<RefPtr<StyleRuleBase>>& rules, const WTF::Function<bool (const CachedResource&)>& handler)
+static bool traverseRulesInVector(const Vector<RefPtr<StyleRuleBase>>& rules, const WTF::Function<bool (const StyleRuleBase&)>& handler)
{
for (auto& rule : rules) {
+ if (handler(*rule))
+ return true;
switch (rule->type()) {
- case StyleRuleBase::Style: {
- auto* properties = downcast<StyleRule>(*rule).propertiesWithoutDeferredParsing();
- if (properties && properties->traverseSubresources(handler))
- return true;
- break;
- }
- case StyleRuleBase::FontFace:
- if (downcast<StyleRuleFontFace>(*rule).properties().traverseSubresources(handler))
- return true;
- break;
case StyleRuleBase::Media: {
auto* childRules = downcast<StyleRuleMedia>(*rule).childRulesWithoutDeferredParsing();
- if (childRules && traverseSubresourcesInRules(*childRules, handler))
+ if (childRules && traverseRulesInVector(*childRules, handler))
return true;
break;
}
case StyleRuleBase::Import:
ASSERT_NOT_REACHED();
-#if ASSERT_DISABLED
- FALLTHROUGH;
-#endif
+ break;
+ case StyleRuleBase::Style:
+ case StyleRuleBase::FontFace:
case StyleRuleBase::Page:
case StyleRuleBase::Keyframes:
case StyleRuleBase::Namespace:
@@ -471,20 +463,50 @@
return false;
}
-bool StyleSheetContents::traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const
+bool StyleSheetContents::traverseRules(const WTF::Function<bool (const StyleRuleBase&)>& handler) const
{
for (auto& importRule : m_importRules) {
- if (auto* cachedResource = importRule->cachedCSSStyleSheet()) {
- if (handler(*cachedResource))
- return true;
- }
+ if (handler(*importRule))
+ return true;
auto* importedStyleSheet = importRule->styleSheet();
- if (importedStyleSheet && importedStyleSheet->traverseSubresources(handler))
+ if (importedStyleSheet && importedStyleSheet->traverseRules(handler))
return true;
}
- return traverseSubresourcesInRules(m_childRules, handler);
+ return traverseRulesInVector(m_childRules, handler);
}
+bool StyleSheetContents::traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const
+{
+ return traverseRules([&] (const StyleRuleBase& rule) {
+ switch (rule.type()) {
+ case StyleRuleBase::Style: {
+ auto* properties = downcast<StyleRule>(rule).propertiesWithoutDeferredParsing();
+ return properties && properties->traverseSubresources(handler);
+ }
+ case StyleRuleBase::FontFace:
+ return downcast<StyleRuleFontFace>(rule).properties().traverseSubresources(handler);
+ case StyleRuleBase::Import:
+ if (auto* cachedResource = downcast<StyleRuleImport>(rule).cachedCSSStyleSheet())
+ return handler(*cachedResource);
+ return false;
+ case StyleRuleBase::Media:
+ case StyleRuleBase::Page:
+ case StyleRuleBase::Keyframes:
+ case StyleRuleBase::Namespace:
+ case StyleRuleBase::Unknown:
+ case StyleRuleBase::Charset:
+ case StyleRuleBase::Keyframe:
+ case StyleRuleBase::Supports:
+#if ENABLE(CSS_DEVICE_ADAPTATION)
+ case StyleRuleBase::Viewport:
+#endif
+ return false;
+ };
+ ASSERT_NOT_REACHED();
+ return false;
+ });
+}
+
bool StyleSheetContents::subresourcesAllowReuse(CachePolicy cachePolicy, FrameLoader& loader) const
{
bool hasFailedOrExpiredResources = traverseSubresources([cachePolicy, &loader](const CachedResource& resource) {
Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleSheetContents.h (228677 => 228678)
--- releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleSheetContents.h 2018-02-19 13:59:49 UTC (rev 228677)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/css/StyleSheetContents.h 2018-02-19 13:59:56 UTC (rev 228678)
@@ -86,6 +86,7 @@
bool loadCompleted() const { return m_loadCompleted; }
URL completeURL(const String& url) const;
+ bool traverseRules(const WTF::Function<bool (const StyleRuleBase&)>& handler) const;
bool traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const;
void setIsUserStyleSheet(bool b) { m_isUserStyleSheet = b; }
Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/page/MemoryRelease.cpp (228677 => 228678)
--- releases/WebKitGTK/webkit-2.20/Source/WebCore/page/MemoryRelease.cpp 2018-02-19 13:59:49 UTC (rev 228677)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/page/MemoryRelease.cpp 2018-02-19 13:59:56 UTC (rev 228678)
@@ -84,7 +84,7 @@
CSSValuePool::singleton().drain();
for (auto& document : copyToVectorOf<RefPtr<Document>>(Document::allDocuments())) {
- document->styleScope().clearResolver();
+ document->styleScope().releaseMemory();
document->fontSelector().emptyCaches();
}
Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/style/StyleScope.cpp (228677 => 228678)
--- releases/WebKitGTK/webkit-2.20/Source/WebCore/style/StyleScope.cpp 2018-02-19 13:59:49 UTC (rev 228677)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/style/StyleScope.cpp 2018-02-19 13:59:56 UTC (rev 228678)
@@ -134,6 +134,25 @@
m_document.didClearStyleResolver();
}
+void Scope::releaseMemory()
+{
+ if (!m_shadowRoot) {
+ for (auto* descendantShadowRoot : m_document.inDocumentShadowRoots())
+ descendantShadowRoot->styleScope().releaseMemory();
+ }
+
+#if ENABLE(CSS_SELECTOR_JIT)
+ for (auto& sheet : m_activeStyleSheets) {
+ sheet->contents().traverseRules([] (const StyleRuleBase& rule) {
+ if (is<StyleRule>(rule))
+ downcast<StyleRule>(rule).releaseCompiledSelectors();
+ return false;
+ });
+ }
+#endif
+ clearResolver();
+}
+
Scope& Scope::forNode(Node& node)
{
ASSERT(node.isConnected());
Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/style/StyleScope.h (228677 => 228678)
--- releases/WebKitGTK/webkit-2.20/Source/WebCore/style/StyleScope.h 2018-02-19 13:59:49 UTC (rev 228677)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/style/StyleScope.h 2018-02-19 13:59:56 UTC (rev 228678)
@@ -118,6 +118,7 @@
StyleResolver& resolver();
StyleResolver* resolverIfExists();
void clearResolver();
+ void releaseMemory();
const Document& document() const { return m_document; }