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

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

Issue 273843003: [Oilpan]: Make StylePropertySet fully garbage collected. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix crash found by svg/custom/invisible-text-after-scrolling.xhtml 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 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
4 * Copyright (C) 2013 Google Inc. All rights reserved. 4 * Copyright (C) 2013 Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 * 20 *
21 */ 21 */
22 22
23 #ifndef MatchedPropertiesCache_h 23 #ifndef MatchedPropertiesCache_h
24 #define MatchedPropertiesCache_h 24 #define MatchedPropertiesCache_h
25 25
26 #include "core/css/StylePropertySet.h"
26 #include "core/css/resolver/MatchResult.h" 27 #include "core/css/resolver/MatchResult.h"
27
28 #include "platform/Timer.h" 28 #include "platform/Timer.h"
29 #include "platform/heap/Handle.h"
29 #include "wtf/Forward.h" 30 #include "wtf/Forward.h"
30 #include "wtf/HashMap.h" 31 #include "wtf/HashMap.h"
31 #include "wtf/Noncopyable.h" 32 #include "wtf/Noncopyable.h"
32 33
33 namespace WebCore { 34 namespace WebCore {
34 35
35 class RenderStyle; 36 class RenderStyle;
36 class StyleResolverState; 37 class StyleResolverState;
37 38
38 struct CachedMatchedProperties { 39 class CachedMatchedProperties FINAL : public NoBaseWillBeGarbageCollectedFinaliz ed<CachedMatchedProperties> {
39 Vector<MatchedProperties> matchedProperties; 40
41 public:
42 WillBeHeapVector<MatchedProperties> matchedProperties;
40 MatchRanges ranges; 43 MatchRanges ranges;
41 RefPtr<RenderStyle> renderStyle; 44 RefPtr<RenderStyle> renderStyle;
42 RefPtr<RenderStyle> parentRenderStyle; 45 RefPtr<RenderStyle> parentRenderStyle;
43 46
44 void set(const RenderStyle*, const RenderStyle* parentStyle, const MatchResu lt&); 47 void set(const RenderStyle*, const RenderStyle* parentStyle, const MatchResu lt&);
45 void clear(); 48 void clear();
49 void trace(Visitor* visitor) { visitor->trace(matchedProperties); }
46 }; 50 };
47 51
52 // Specialize the HashTraits for CachedMatchedProperties to check for dead
53 // entries in the MatchedPropertiesCache.
54 #if ENABLE(OILPAN)
55 struct CachedMatchedPropertiesHashTraits : HashTraits<Member<CachedMatchedProper ties> > {
esprehn 2014/06/26 09:48:53 Does this really need to be inline? I'd rather it
56 static const WTF::WeakHandlingFlag weakHandlingFlag = WTF::WeakHandlingInCol lections;
57 static bool traceInCollection(Visitor* visitor, Member<CachedMatchedProperti es>& cachedProperties, WTF::ShouldWeakPointersBeMarkedStrongly strongify)
58 {
59 // Only honor the cache's weakness semantics if the collection
60 // is traced without the strongify flag set to WeakPointersActStrong.
haraken 2014/06/25 13:37:11 ... if the collection is traced with WeakPointersA
wibling-chromium 2014/06/26 09:31:00 Done.
61 // Otherwise just trace the cachedProperties strongly, ie. call trace
62 // on it.
63 if (strongify != WTF::WeakPointersActStrong) {
haraken 2014/06/25 13:37:11 if (strongify == WTF::WeakPointersActWeak)
wibling-chromium 2014/06/26 09:31:00 Done.
64 // A given cache entry is only kept alive if none of the MatchedProp erties
65 // in the CachedMatchedProperties value contain a dead "properties" field.
66 // If there is a dead field the entire cache entry is removed.
67 HeapVector<MatchedProperties>::iterator it = cachedProperties->match edProperties.begin();
68 HeapVector<MatchedProperties>::iterator end = cachedProperties->matc hedProperties.end();
69 for (; it != end; ++it) {
70 if (!visitor->isAlive(it->properties)) {
71 // For now report the cache entry as dead. This might not
72 // be the final result if in a subsequent call to this
haraken 2014/06/25 13:37:11 in a subsequent call to this the properties... =>
wibling-chromium 2014/06/26 09:30:59 I have rephrased it a bit.
73 // the "properties" field has been marked via another
74 // path.
75 return true;
76 }
77 }
78 }
79 // At this point none of the entries in the matchedProperties vector
80 // had a dead "properties" field so trace CachedMatchedProperties normal ly.
haraken 2014/06/25 13:37:11 normally => strongly
wibling-chromium 2014/06/26 09:30:59 Done.
81 visitor->trace(cachedProperties);
82 return false;
83 }
84 };
85 #endif
86
48 class MatchedPropertiesCache { 87 class MatchedPropertiesCache {
88 DISALLOW_ALLOCATION();
49 WTF_MAKE_NONCOPYABLE(MatchedPropertiesCache); 89 WTF_MAKE_NONCOPYABLE(MatchedPropertiesCache);
50 public: 90 public:
51 MatchedPropertiesCache(); 91 MatchedPropertiesCache();
52 92
53 const CachedMatchedProperties* find(unsigned hash, const StyleResolverState& , const MatchResult&); 93 const CachedMatchedProperties* find(unsigned hash, const StyleResolverState& , const MatchResult&);
54 void add(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&); 94 void add(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&);
55 95
56 void clear(); 96 void clear();
57 void clearViewportDependent(); 97 void clearViewportDependent();
58 98
59 static bool isCacheable(const Element*, const RenderStyle*, const RenderStyl e* parentStyle); 99 static bool isCacheable(const Element*, const RenderStyle*, const RenderStyl e* parentStyle);
60 100
101 void trace(Visitor*);
102
61 private: 103 private:
104 #if ENABLE(OILPAN)
105 typedef HeapHashMap<unsigned, Member<CachedMatchedProperties>, DefaultHash<u nsigned>::Hash, HashTraits<unsigned>, CachedMatchedPropertiesHashTraits > Cache;
haraken 2014/06/25 13:37:11 I don't fully understand why this is not a WeakMem
wibling-chromium 2014/06/26 09:31:00 There is no requirement for a WeakMember to be in
haraken 2014/06/26 10:31:36 Makes sense, thanks for the clarification!
106 #else
62 // Every N additions to the matched declaration cache trigger a sweep where entries holding 107 // Every N additions to the matched declaration cache trigger a sweep where entries holding
63 // the last reference to a style declaration are garbage collected. 108 // the last reference to a style declaration are garbage collected.
64 void sweep(Timer<MatchedPropertiesCache>*); 109 void sweep(Timer<MatchedPropertiesCache>*);
65 110
66 unsigned m_additionsSinceLastSweep; 111 unsigned m_additionsSinceLastSweep;
67 112
68 typedef HashMap<unsigned, OwnPtr<CachedMatchedProperties> > Cache; 113 typedef HashMap<unsigned, OwnPtr<CachedMatchedProperties> > Cache;
114 Timer<MatchedPropertiesCache> m_sweepTimer;
115 #endif
69 Cache m_cache; 116 Cache m_cache;
70
71 Timer<MatchedPropertiesCache> m_sweepTimer;
72 }; 117 };
73 118
74 } 119 }
75 120
76 #endif 121 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698