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

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: add comment for ShareableElementData new 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 : public NoBaseWillBeGarbageCollectedFinalized<Cac hedMatchedProperties> {
zerny-chromium 2014/06/25 06:19:02 Nit: FINAL
wibling-chromium 2014/06/25 09:03:28 Done.
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.
Mads Ager (chromium) 2014/06/25 06:31:48 MatchedPropertiesCache -> matchedProperties vector
wibling-chromium 2014/06/25 09:03:27 I was thinking about it being the entries in the c
54 #if ENABLE(OILPAN)
55 struct CachedMatchedPropertiesHashTraits : HashTraits<Member<CachedMatchedProper ties> > {
56 static const WTF::WeakHandlingFlag weakHandlingFlag = WTF::WeakHandlingInCol lections;
57 static bool traceInCollection(Visitor* visitor, Member<CachedMatchedProperti es>& cachedProperties, WTF::ShouldWeakPointersBeMarkedStrongly strongify)
58 {
59 // The below loop serves two purposes. It either marks the MatchedProper ties'
60 // "properties" field strong if "strongify" is set to WeakPointersActStr ong.
61 // Otherwise it checks if any of the MatchedProperties has a "properties "
62 // field that is dead and if so the entire entry in m_cache is removed
63 // (by returning isDead == true).
64 HeapVector<MatchedProperties>::iterator it = cachedProperties->matchedPr operties.begin();
65 HeapVector<MatchedProperties>::iterator end = cachedProperties->matchedP roperties.end();
66 bool isDead = false;
67 while (it != end) {
zerny-chromium 2014/06/25 06:19:02 Nit: for(; it != end; ++it)
wibling-chromium 2014/06/25 09:03:27 Done.
68 if (strongify == WTF::WeakPointersActStrong) {
69 visitor->traceInCollection(it->properties, strongify);
70 } else if (!visitor->isAlive(it->properties)) {
71 isDead = true;
zerny-chromium 2014/06/25 06:19:02 It looks like this might as well be: return tru
wibling-chromium 2014/06/25 09:03:27 Done.
72 break;
73 }
74 ++it;
75 }
76
77 // If none of the entries in the matchedProperties vector had a dead wea k
78 // member we trace CachedMatchedProperties normally.
79 if (!isDead)
80 visitor->trace(cachedProperties);
81 return isDead;
82 }
83 };
84 #endif
85
48 class MatchedPropertiesCache { 86 class MatchedPropertiesCache {
87 DISALLOW_ALLOCATION();
49 WTF_MAKE_NONCOPYABLE(MatchedPropertiesCache); 88 WTF_MAKE_NONCOPYABLE(MatchedPropertiesCache);
50 public: 89 public:
51 MatchedPropertiesCache(); 90 MatchedPropertiesCache();
52 91
53 const CachedMatchedProperties* find(unsigned hash, const StyleResolverState& , const MatchResult&); 92 const CachedMatchedProperties* find(unsigned hash, const StyleResolverState& , const MatchResult&);
54 void add(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&); 93 void add(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&);
55 94
56 void clear(); 95 void clear();
57 void clearViewportDependent(); 96 void clearViewportDependent();
58 97
59 static bool isCacheable(const Element*, const RenderStyle*, const RenderStyl e* parentStyle); 98 static bool isCacheable(const Element*, const RenderStyle*, const RenderStyl e* parentStyle);
60 99
100 void trace(Visitor*);
101
61 private: 102 private:
103 #if ENABLE(OILPAN)
104 typedef HeapHashMap<unsigned, Member<CachedMatchedProperties>, DefaultHash<u nsigned>::Hash, HashTraits<unsigned>, CachedMatchedPropertiesHashTraits > Cache;
105 #else
62 // Every N additions to the matched declaration cache trigger a sweep where entries holding 106 // 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. 107 // the last reference to a style declaration are garbage collected.
64 void sweep(Timer<MatchedPropertiesCache>*); 108 void sweep(Timer<MatchedPropertiesCache>*);
65 109
66 unsigned m_additionsSinceLastSweep; 110 unsigned m_additionsSinceLastSweep;
67 111
68 typedef HashMap<unsigned, OwnPtr<CachedMatchedProperties> > Cache; 112 typedef HashMap<unsigned, OwnPtr<CachedMatchedProperties> > Cache;
113 Timer<MatchedPropertiesCache> m_sweepTimer;
114 #endif
69 Cache m_cache; 115 Cache m_cache;
70
71 Timer<MatchedPropertiesCache> m_sweepTimer;
72 }; 116 };
73 117
74 } 118 }
75 119
76 #endif 120 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698