Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: Source/core/css/resolver/MatchedPropertiesCache.cpp

Issue 273843003: [Oilpan]: Make StylePropertySet fully garbage collected. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review feedback Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 17 matching lines...) Expand all
28 28
29 #include "config.h" 29 #include "config.h"
30 #include "core/css/resolver/MatchedPropertiesCache.h" 30 #include "core/css/resolver/MatchedPropertiesCache.h"
31 31
32 #include "core/css/StylePropertySet.h" 32 #include "core/css/StylePropertySet.h"
33 #include "core/css/resolver/StyleResolverState.h" 33 #include "core/css/resolver/StyleResolverState.h"
34 #include "core/rendering/style/RenderStyle.h" 34 #include "core/rendering/style/RenderStyle.h"
35 35
36 namespace WebCore { 36 namespace WebCore {
37 37
38 #if ENABLE(OILPAN)
39 bool CachedMatchedPropertiesHashTraits::traceInCollection(Visitor* visitor, Memb er<CachedMatchedProperties>& cachedProperties, WTF::ShouldWeakPointersBeMarkedSt rongly strongify)
40 {
41 // Only honor the cache's weakness semantics if the collection is traced
42 // with WeakPointersActWeak. Otherwise just trace the cachedProperties
43 // strongly, ie. call trace on it.
44 if (strongify == WTF::WeakPointersActWeak) {
45 // A given cache entry is only kept alive if none of the MatchedProperti es
46 // in the CachedMatchedProperties value contain a dead "properties" fiel d.
47 // If there is a dead field the entire cache entry is removed.
48 HeapVector<MatchedProperties>::iterator it = cachedProperties->matchedPr operties.begin();
49 HeapVector<MatchedProperties>::iterator end = cachedProperties->matchedP roperties.end();
50 for (; it != end; ++it) {
51 if (!visitor->isAlive(it->properties)) {
52 // For now report the cache entry as dead. This might not
53 // be the final result if in a subsequent call for this entry,
54 // the "properties" field has been marked via another path.
55 return true;
56 }
57 }
58 }
59 // At this point none of the entries in the matchedProperties vector
60 // had a dead "properties" field so trace CachedMatchedProperties strongly.
61 visitor->trace(cachedProperties);
62 return false;
63 }
64 #endif
65
38 void CachedMatchedProperties::set(const RenderStyle* style, const RenderStyle* p arentStyle, const MatchResult& matchResult) 66 void CachedMatchedProperties::set(const RenderStyle* style, const RenderStyle* p arentStyle, const MatchResult& matchResult)
39 { 67 {
40 matchedProperties.appendVector(matchResult.matchedProperties); 68 matchedProperties.appendVector(matchResult.matchedProperties);
41 ranges = matchResult.ranges; 69 ranges = matchResult.ranges;
42 70
43 // Note that we don't cache the original RenderStyle instance. It may be fur ther modified. 71 // Note that we don't cache the original RenderStyle instance. It may be fur ther modified.
44 // The RenderStyle in the cache is really just a holder for the substructure s and never used as-is. 72 // The RenderStyle in the cache is really just a holder for the substructure s and never used as-is.
45 this->renderStyle = RenderStyle::clone(style); 73 this->renderStyle = RenderStyle::clone(style);
46 this->parentRenderStyle = RenderStyle::clone(parentStyle); 74 this->parentRenderStyle = RenderStyle::clone(parentStyle);
47 } 75 }
48 76
49 void CachedMatchedProperties::clear() 77 void CachedMatchedProperties::clear()
50 { 78 {
51 matchedProperties.clear(); 79 matchedProperties.clear();
52 renderStyle = nullptr; 80 renderStyle = nullptr;
53 parentRenderStyle = nullptr; 81 parentRenderStyle = nullptr;
54 } 82 }
55 83
56 MatchedPropertiesCache::MatchedPropertiesCache() 84 MatchedPropertiesCache::MatchedPropertiesCache()
85 #if !ENABLE(OILPAN)
57 : m_additionsSinceLastSweep(0) 86 : m_additionsSinceLastSweep(0)
58 , m_sweepTimer(this, &MatchedPropertiesCache::sweep) 87 , m_sweepTimer(this, &MatchedPropertiesCache::sweep)
88 #endif
59 { 89 {
60 } 90 }
61 91
62 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const StyleResolverState& styleResolverState, const MatchResult& matchResult) 92 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const StyleResolverState& styleResolverState, const MatchResult& matchResult)
63 { 93 {
64 ASSERT(hash); 94 ASSERT(hash);
65 95
66 Cache::iterator it = m_cache.find(hash); 96 Cache::iterator it = m_cache.find(hash);
67 if (it == m_cache.end()) 97 if (it == m_cache.end())
68 return 0; 98 return 0;
69 CachedMatchedProperties* cacheItem = it->value.get(); 99 CachedMatchedProperties* cacheItem = it->value.get();
70 ASSERT(cacheItem); 100 ASSERT(cacheItem);
71 101
72 size_t size = matchResult.matchedProperties.size(); 102 size_t size = matchResult.matchedProperties.size();
73 if (size != cacheItem->matchedProperties.size()) 103 if (size != cacheItem->matchedProperties.size())
74 return 0; 104 return 0;
75 if (cacheItem->renderStyle->insideLink() != styleResolverState.style()->insi deLink()) 105 if (cacheItem->renderStyle->insideLink() != styleResolverState.style()->insi deLink())
76 return 0; 106 return 0;
77 for (size_t i = 0; i < size; ++i) { 107 for (size_t i = 0; i < size; ++i) {
78 if (matchResult.matchedProperties[i] != cacheItem->matchedProperties[i]) 108 if (matchResult.matchedProperties[i] != cacheItem->matchedProperties[i])
79 return 0; 109 return 0;
80 } 110 }
81 if (cacheItem->ranges != matchResult.ranges) 111 if (cacheItem->ranges != matchResult.ranges)
82 return 0; 112 return 0;
83 return cacheItem; 113 return cacheItem;
84 } 114 }
85 115
86 void MatchedPropertiesCache::add(const RenderStyle* style, const RenderStyle* pa rentStyle, unsigned hash, const MatchResult& matchResult) 116 void MatchedPropertiesCache::add(const RenderStyle* style, const RenderStyle* pa rentStyle, unsigned hash, const MatchResult& matchResult)
87 { 117 {
118 #if !ENABLE(OILPAN)
88 static const unsigned maxAdditionsBetweenSweeps = 100; 119 static const unsigned maxAdditionsBetweenSweeps = 100;
89 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps 120 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps
90 && !m_sweepTimer.isActive()) { 121 && !m_sweepTimer.isActive()) {
91 static const unsigned sweepTimeInSeconds = 60; 122 static const unsigned sweepTimeInSeconds = 60;
92 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE); 123 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE);
93 } 124 }
125 #endif
94 126
95 ASSERT(hash); 127 ASSERT(hash);
96 Cache::AddResult addResult = m_cache.add(hash, nullptr); 128 Cache::AddResult addResult = m_cache.add(hash, nullptr);
97 if (addResult.isNewEntry) 129 if (addResult.isNewEntry)
98 addResult.storedValue->value = adoptPtr(new CachedMatchedProperties); 130 addResult.storedValue->value = adoptPtrWillBeNoop(new CachedMatchedPrope rties);
99 131
100 CachedMatchedProperties* cacheItem = addResult.storedValue->value.get(); 132 CachedMatchedProperties* cacheItem = addResult.storedValue->value.get();
101 if (!addResult.isNewEntry) 133 if (!addResult.isNewEntry)
102 cacheItem->clear(); 134 cacheItem->clear();
103 135
104 cacheItem->set(style, parentStyle, matchResult); 136 cacheItem->set(style, parentStyle, matchResult);
105 } 137 }
106 138
107 void MatchedPropertiesCache::clear() 139 void MatchedPropertiesCache::clear()
108 { 140 {
109 m_cache.clear(); 141 m_cache.clear();
110 } 142 }
111 143
112 void MatchedPropertiesCache::clearViewportDependent() 144 void MatchedPropertiesCache::clearViewportDependent()
113 { 145 {
114 Vector<unsigned, 16> toRemove; 146 Vector<unsigned, 16> toRemove;
115 for (Cache::iterator it = m_cache.begin(); it != m_cache.end(); ++it) { 147 for (Cache::iterator it = m_cache.begin(); it != m_cache.end(); ++it) {
116 CachedMatchedProperties* cacheItem = it->value.get(); 148 CachedMatchedProperties* cacheItem = it->value.get();
117 if (cacheItem->renderStyle->hasViewportUnits()) 149 if (cacheItem->renderStyle->hasViewportUnits())
118 toRemove.append(it->key); 150 toRemove.append(it->key);
119 } 151 }
120 m_cache.removeAll(toRemove); 152 m_cache.removeAll(toRemove);
121 } 153 }
122 154
155 #if !ENABLE(OILPAN)
123 void MatchedPropertiesCache::sweep(Timer<MatchedPropertiesCache>*) 156 void MatchedPropertiesCache::sweep(Timer<MatchedPropertiesCache>*)
124 { 157 {
125 // Look for cache entries containing a style declaration with a single ref a nd remove them. 158 // Look for cache entries containing a style declaration with a single ref a nd remove them.
126 // This may happen when an element attribute mutation causes it to generate a new inlineStyle() 159 // This may happen when an element attribute mutation causes it to generate a new inlineStyle()
127 // or presentationAttributeStyle(), potentially leaving this cache with the last ref on the old one. 160 // or presentationAttributeStyle(), potentially leaving this cache with the last ref on the old one.
128 Vector<unsigned, 16> toRemove; 161 Vector<unsigned, 16> toRemove;
129 Cache::iterator it = m_cache.begin(); 162 Cache::iterator it = m_cache.begin();
130 Cache::iterator end = m_cache.end(); 163 Cache::iterator end = m_cache.end();
131 for (; it != end; ++it) { 164 for (; it != end; ++it) {
132 CachedMatchedProperties* cacheItem = it->value.get(); 165 CachedMatchedProperties* cacheItem = it->value.get();
133 Vector<MatchedProperties>& matchedProperties = cacheItem->matchedPropert ies; 166 Vector<MatchedProperties>& matchedProperties = cacheItem->matchedPropert ies;
134 for (size_t i = 0; i < matchedProperties.size(); ++i) { 167 for (size_t i = 0; i < matchedProperties.size(); ++i) {
135 if (matchedProperties[i].properties->hasOneRef()) { 168 if (matchedProperties[i].properties->hasOneRef()) {
136 toRemove.append(it->key); 169 toRemove.append(it->key);
137 break; 170 break;
138 } 171 }
139 } 172 }
140 } 173 }
141 m_cache.removeAll(toRemove); 174 m_cache.removeAll(toRemove);
142 m_additionsSinceLastSweep = 0; 175 m_additionsSinceLastSweep = 0;
143 } 176 }
177 #endif
144 178
145 bool MatchedPropertiesCache::isCacheable(const Element* element, const RenderSty le* style, const RenderStyle* parentStyle) 179 bool MatchedPropertiesCache::isCacheable(const Element* element, const RenderSty le* style, const RenderStyle* parentStyle)
146 { 180 {
147 // FIXME: CSSPropertyWebkitWritingMode modifies state when applying to docum ent element. We can't skip the applying by caching. 181 // FIXME: CSSPropertyWebkitWritingMode modifies state when applying to docum ent element. We can't skip the applying by caching.
148 if (element == element->document().documentElement() && element->document(). writingModeSetOnDocumentElement()) 182 if (element == element->document().documentElement() && element->document(). writingModeSetOnDocumentElement())
149 return false; 183 return false;
150 if (style->unique() || (style->styleType() != NOPSEUDO && parentStyle->uniqu e())) 184 if (style->unique() || (style->styleType() != NOPSEUDO && parentStyle->uniqu e()))
151 return false; 185 return false;
152 if (style->hasAppearance()) 186 if (style->hasAppearance())
153 return false; 187 return false;
154 if (style->zoom() != RenderStyle::initialZoom()) 188 if (style->zoom() != RenderStyle::initialZoom())
155 return false; 189 return false;
156 if (style->writingMode() != RenderStyle::initialWritingMode()) 190 if (style->writingMode() != RenderStyle::initialWritingMode())
157 return false; 191 return false;
158 if (style->hasCurrentColor()) 192 if (style->hasCurrentColor())
159 return false; 193 return false;
160 // CSSPropertyInternalCallback sets the rule's selector name into the Render Style, and that's not recalculated if the RenderStyle is loaded from the cache, so don't cache it. 194 // CSSPropertyInternalCallback sets the rule's selector name into the Render Style, and that's not recalculated if the RenderStyle is loaded from the cache, so don't cache it.
161 if (!style->callbackSelectors().isEmpty()) 195 if (!style->callbackSelectors().isEmpty())
162 return false; 196 return false;
163 // The cache assumes static knowledge about which properties are inherited. 197 // The cache assumes static knowledge about which properties are inherited.
164 if (parentStyle->hasExplicitlyInheritedProperties()) 198 if (parentStyle->hasExplicitlyInheritedProperties())
165 return false; 199 return false;
166 return true; 200 return true;
167 } 201 }
168 202
203 void MatchedPropertiesCache::trace(Visitor* visitor)
204 {
205 visitor->trace(m_cache);
169 } 206 }
207
208 }
OLDNEW
« no previous file with comments | « Source/core/css/resolver/MatchedPropertiesCache.h ('k') | Source/core/css/resolver/StyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698