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

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: forgot some 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 * 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> > {
56 static const WTF::WeakHandlingFlag weakHandlingFlag = WTF::WeakHandlingInCol lections;
57 static bool traceInCollection(Visitor* visitor, Member<CachedMatchedProperti es>& cachedProperties, WTF::ShouldWeakPointersBeMarkedStrongly strongify)
58 {
59 // A given cache entry is only kept alive if none of the MatchedProperti es
60 // in the CachedMatchedProperties value contain a dead "properties" fiel d.
61 // If there is a dead field the entire cache entry is removed.
62 HeapVector<MatchedProperties>::iterator it = cachedProperties->matchedPr operties.begin();
63 HeapVector<MatchedProperties>::iterator end = cachedProperties->matchedP roperties.end();
64 for (;it != end; ++it) {
Mads Ager (chromium) 2014/06/25 09:18:33 space after ;
wibling-chromium 2014/06/25 09:30:47 Done.
65 if (!visitor->isAlive(it->properties)) {
66 // For now report the cache entry as dead. This might not
67 // be the final result if in a subsequent call to this
68 // the "properties" field has been marked via another
69 // path.
70 return true;
71 }
72 }
73 // At this point none of the entries in the matchedProperties vector
74 // had a dead "properties" field so trace CachedMatchedProperties normal ly.
75 visitor->trace(cachedProperties);
76 return false;
77 }
78 };
79 #endif
80
48 class MatchedPropertiesCache { 81 class MatchedPropertiesCache {
82 DISALLOW_ALLOCATION();
49 WTF_MAKE_NONCOPYABLE(MatchedPropertiesCache); 83 WTF_MAKE_NONCOPYABLE(MatchedPropertiesCache);
50 public: 84 public:
51 MatchedPropertiesCache(); 85 MatchedPropertiesCache();
52 86
53 const CachedMatchedProperties* find(unsigned hash, const StyleResolverState& , const MatchResult&); 87 const CachedMatchedProperties* find(unsigned hash, const StyleResolverState& , const MatchResult&);
54 void add(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&); 88 void add(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&);
55 89
56 void clear(); 90 void clear();
57 void clearViewportDependent(); 91 void clearViewportDependent();
58 92
59 static bool isCacheable(const Element*, const RenderStyle*, const RenderStyl e* parentStyle); 93 static bool isCacheable(const Element*, const RenderStyle*, const RenderStyl e* parentStyle);
60 94
95 void trace(Visitor*);
96
61 private: 97 private:
98 #if ENABLE(OILPAN)
99 typedef HeapHashMap<unsigned, Member<CachedMatchedProperties>, DefaultHash<u nsigned>::Hash, HashTraits<unsigned>, CachedMatchedPropertiesHashTraits > Cache;
100 #else
62 // Every N additions to the matched declaration cache trigger a sweep where entries holding 101 // 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. 102 // the last reference to a style declaration are garbage collected.
64 void sweep(Timer<MatchedPropertiesCache>*); 103 void sweep(Timer<MatchedPropertiesCache>*);
65 104
66 unsigned m_additionsSinceLastSweep; 105 unsigned m_additionsSinceLastSweep;
67 106
68 typedef HashMap<unsigned, OwnPtr<CachedMatchedProperties> > Cache; 107 typedef HashMap<unsigned, OwnPtr<CachedMatchedProperties> > Cache;
108 Timer<MatchedPropertiesCache> m_sweepTimer;
109 #endif
69 Cache m_cache; 110 Cache m_cache;
70
71 Timer<MatchedPropertiesCache> m_sweepTimer;
72 }; 111 };
73 112
74 } 113 }
75 114
76 #endif 115 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698