Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 void CachedMatchedProperties::clear() | 49 void CachedMatchedProperties::clear() |
| 50 { | 50 { |
| 51 matchedProperties.clear(); | 51 matchedProperties.clear(); |
| 52 renderStyle = nullptr; | 52 renderStyle = nullptr; |
| 53 parentRenderStyle = nullptr; | 53 parentRenderStyle = nullptr; |
| 54 } | 54 } |
| 55 | 55 |
| 56 MatchedPropertiesCache::MatchedPropertiesCache() | 56 MatchedPropertiesCache::MatchedPropertiesCache() |
| 57 : m_additionsSinceLastSweep(0) | 57 : m_additionsSinceLastSweep(0) |
| 58 , m_sweepTimer(this, &MatchedPropertiesCache::sweep) | 58 , m_sweepTimer(this, &MatchedPropertiesCache::sweep) |
| 59 #if ENABLE(OILPAN) | |
| 60 , m_cacheNeedsCleaning(false) | |
| 61 #endif | |
| 59 { | 62 { |
| 60 } | 63 } |
| 61 | 64 |
| 62 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const StyleResolverState& styleResolverState, const MatchResult& matchResult) | 65 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const StyleResolverState& styleResolverState, const MatchResult& matchResult) |
| 63 { | 66 { |
| 64 ASSERT(hash); | 67 ASSERT(hash); |
| 65 | 68 |
| 69 #if ENABLE(OILPAN) | |
| 70 // If we had a GC since the last find we could have entries that are now inv alid. | |
| 71 // Sweep the cache to ensure it is in a valid state before doing the find. | |
| 72 if (m_cacheNeedsCleaning) | |
| 73 sweep(0); | |
|
haraken
2014/05/08 11:43:45
I understand what you're doing here, but this sign
wibling-chromium
2014/05/08 12:38:55
It does increase the likelihood, but it will only
| |
| 74 #endif | |
| 75 | |
| 66 Cache::iterator it = m_cache.find(hash); | 76 Cache::iterator it = m_cache.find(hash); |
| 67 if (it == m_cache.end()) | 77 if (it == m_cache.end()) |
| 68 return 0; | 78 return 0; |
| 69 CachedMatchedProperties* cacheItem = it->value.get(); | 79 CachedMatchedProperties* cacheItem = it->value.get(); |
| 70 ASSERT(cacheItem); | 80 ASSERT(cacheItem); |
| 71 | 81 |
| 72 size_t size = matchResult.matchedProperties.size(); | 82 size_t size = matchResult.matchedProperties.size(); |
| 73 if (size != cacheItem->matchedProperties.size()) | 83 if (size != cacheItem->matchedProperties.size()) |
| 74 return 0; | 84 return 0; |
| 75 if (cacheItem->renderStyle->insideLink() != styleResolverState.style()->insi deLink()) | 85 if (cacheItem->renderStyle->insideLink() != styleResolverState.style()->insi deLink()) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 88 static const unsigned maxAdditionsBetweenSweeps = 100; | 98 static const unsigned maxAdditionsBetweenSweeps = 100; |
| 89 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps | 99 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps |
| 90 && !m_sweepTimer.isActive()) { | 100 && !m_sweepTimer.isActive()) { |
| 91 static const unsigned sweepTimeInSeconds = 60; | 101 static const unsigned sweepTimeInSeconds = 60; |
| 92 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE); | 102 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE); |
| 93 } | 103 } |
| 94 | 104 |
| 95 ASSERT(hash); | 105 ASSERT(hash); |
| 96 Cache::AddResult addResult = m_cache.add(hash, nullptr); | 106 Cache::AddResult addResult = m_cache.add(hash, nullptr); |
| 97 if (addResult.isNewEntry) | 107 if (addResult.isNewEntry) |
| 98 addResult.storedValue->value = adoptPtr(new CachedMatchedProperties); | 108 addResult.storedValue->value = adoptPtrWillBeNoop(new CachedMatchedPrope rties); |
| 99 | 109 |
| 100 CachedMatchedProperties* cacheItem = addResult.storedValue->value.get(); | 110 CachedMatchedProperties* cacheItem = addResult.storedValue->value.get(); |
| 101 if (!addResult.isNewEntry) | 111 if (!addResult.isNewEntry) |
| 102 cacheItem->clear(); | 112 cacheItem->clear(); |
| 103 | 113 |
| 104 cacheItem->set(style, parentStyle, matchResult); | 114 cacheItem->set(style, parentStyle, matchResult); |
| 105 } | 115 } |
| 106 | 116 |
| 107 void MatchedPropertiesCache::clear() | 117 void MatchedPropertiesCache::clear() |
| 108 { | 118 { |
| 109 m_cache.clear(); | 119 m_cache.clear(); |
| 110 } | 120 } |
| 111 | 121 |
| 112 void MatchedPropertiesCache::clearViewportDependent() | 122 void MatchedPropertiesCache::clearViewportDependent() |
| 113 { | 123 { |
| 114 Vector<unsigned, 16> toRemove; | 124 Vector<unsigned, 16> toRemove; |
| 115 for (Cache::iterator it = m_cache.begin(); it != m_cache.end(); ++it) { | 125 for (Cache::iterator it = m_cache.begin(); it != m_cache.end(); ++it) { |
| 116 CachedMatchedProperties* cacheItem = it->value.get(); | 126 CachedMatchedProperties* cacheItem = it->value.get(); |
| 117 if (cacheItem->renderStyle->hasViewportUnits()) | 127 if (cacheItem->renderStyle->hasViewportUnits()) |
| 118 toRemove.append(it->key); | 128 toRemove.append(it->key); |
| 119 } | 129 } |
| 120 m_cache.removeAll(toRemove); | 130 m_cache.removeAll(toRemove); |
| 121 } | 131 } |
| 122 | 132 |
| 123 void MatchedPropertiesCache::sweep(Timer<MatchedPropertiesCache>*) | 133 void MatchedPropertiesCache::sweep(Timer<MatchedPropertiesCache>*) |
| 124 { | 134 { |
| 135 #if ENABLE(OILPAN) | |
| 136 m_cacheNeedsCleaning = false; | |
| 137 #endif | |
| 125 // Look for cache entries containing a style declaration with a single ref a nd remove them. | 138 // 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() | 139 // 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. | 140 // or presentationAttributeStyle(), potentially leaving this cache with the last ref on the old one. |
| 128 Vector<unsigned, 16> toRemove; | 141 Vector<unsigned, 16> toRemove; |
| 129 Cache::iterator it = m_cache.begin(); | 142 Cache::iterator it = m_cache.begin(); |
| 130 Cache::iterator end = m_cache.end(); | 143 Cache::iterator end = m_cache.end(); |
| 131 for (; it != end; ++it) { | 144 for (; it != end; ++it) { |
| 132 CachedMatchedProperties* cacheItem = it->value.get(); | 145 CachedMatchedProperties* cacheItem = it->value.get(); |
| 133 Vector<MatchedProperties>& matchedProperties = cacheItem->matchedPropert ies; | 146 WillBeHeapVector<MatchedProperties>& matchedProperties = cacheItem->matc hedProperties; |
| 134 for (size_t i = 0; i < matchedProperties.size(); ++i) { | 147 for (size_t i = 0; i < matchedProperties.size(); ++i) { |
| 135 if (matchedProperties[i].properties->hasOneRef()) { | 148 #if ENABLE(OILPAN) |
| 149 if (!matchedProperties[i].properties) | |
| 150 #else | |
| 151 if (matchedProperties[i].properties->hasOneRef()) | |
|
haraken
2014/05/08 11:43:45
Even if we make m_cache a hash map of weak members
wibling-chromium
2014/05/08 12:38:55
I don't quite follow. If we make m_cache a hash ma
haraken
2014/05/08 12:53:38
(Probably I'm misunderstanding.)
- First of all,
| |
| 152 #endif | |
| 153 { | |
| 136 toRemove.append(it->key); | 154 toRemove.append(it->key); |
| 137 break; | 155 break; |
| 138 } | 156 } |
| 139 } | 157 } |
| 140 } | 158 } |
| 141 m_cache.removeAll(toRemove); | 159 m_cache.removeAll(toRemove); |
| 142 m_additionsSinceLastSweep = 0; | 160 m_additionsSinceLastSweep = 0; |
| 143 } | 161 } |
| 144 | 162 |
| 145 bool MatchedPropertiesCache::isCacheable(const Element* element, const RenderSty le* style, const RenderStyle* parentStyle) | 163 bool MatchedPropertiesCache::isCacheable(const Element* element, const RenderSty le* style, const RenderStyle* parentStyle) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 159 return false; | 177 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. | 178 // 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()) | 179 if (!style->callbackSelectors().isEmpty()) |
| 162 return false; | 180 return false; |
| 163 // The cache assumes static knowledge about which properties are inherited. | 181 // The cache assumes static knowledge about which properties are inherited. |
| 164 if (parentStyle->hasExplicitlyInheritedProperties()) | 182 if (parentStyle->hasExplicitlyInheritedProperties()) |
| 165 return false; | 183 return false; |
| 166 return true; | 184 return true; |
| 167 } | 185 } |
| 168 | 186 |
| 187 void MatchedPropertiesCache::trace(Visitor* visitor) | |
| 188 { | |
| 189 visitor->trace(m_cache); | |
| 190 visitor->registerWeakMembers<MatchedPropertiesCache, &MatchedPropertiesCache ::processWeakMembers>(this); | |
| 169 } | 191 } |
| 192 | |
| 193 void MatchedPropertiesCache::processWeakMembers(Visitor*) | |
| 194 { | |
| 195 #if ENABLE(OILPAN) | |
| 196 m_cacheNeedsCleaning = true; | |
| 197 #endif | |
| 198 } | |
| 199 | |
| 200 } | |
| OLD | NEW |