OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> | 3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> |
4 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 4 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple 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 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 public: | 65 public: |
66 MemoryCache(); | 66 MemoryCache(); |
67 virtual ~MemoryCache(); | 67 virtual ~MemoryCache(); |
68 | 68 |
69 class MemoryCacheEntry { | 69 class MemoryCacheEntry { |
70 public: | 70 public: |
71 static PassOwnPtr<MemoryCacheEntry> create(Resource* resource) { return
adoptPtr(new MemoryCacheEntry(resource)); } | 71 static PassOwnPtr<MemoryCacheEntry> create(Resource* resource) { return
adoptPtr(new MemoryCacheEntry(resource)); } |
72 | 72 |
73 ResourcePtr<Resource> m_resource; | 73 ResourcePtr<Resource> m_resource; |
74 bool m_inLiveDecodedResourcesList; | 74 bool m_inLiveDecodedResourcesList; |
| 75 unsigned m_accessCount; |
75 | 76 |
76 MemoryCacheEntry* m_previousInLiveResourcesList; | 77 MemoryCacheEntry* m_previousInLiveResourcesList; |
77 MemoryCacheEntry* m_nextInLiveResourcesList; | 78 MemoryCacheEntry* m_nextInLiveResourcesList; |
78 MemoryCacheEntry* m_previousInAllResourcesList; | 79 MemoryCacheEntry* m_previousInAllResourcesList; |
79 MemoryCacheEntry* m_nextInAllResourcesList; | 80 MemoryCacheEntry* m_nextInAllResourcesList; |
80 | 81 |
81 private: | 82 private: |
82 MemoryCacheEntry(Resource* resource) | 83 MemoryCacheEntry(Resource* resource) |
83 : m_resource(resource) | 84 : m_resource(resource) |
84 , m_inLiveDecodedResourcesList(false) | 85 , m_inLiveDecodedResourcesList(false) |
| 86 , m_accessCount(0) |
85 , m_previousInLiveResourcesList(0) | 87 , m_previousInLiveResourcesList(0) |
86 , m_nextInLiveResourcesList(0) | 88 , m_nextInLiveResourcesList(0) |
87 , m_previousInAllResourcesList(0) | 89 , m_previousInAllResourcesList(0) |
88 , m_nextInAllResourcesList(0) | 90 , m_nextInAllResourcesList(0) |
89 { | 91 { |
90 } | 92 } |
91 }; | 93 }; |
92 | 94 |
93 struct LRUList { | 95 struct LRUList { |
94 MemoryCacheEntry* m_head; | 96 MemoryCacheEntry* m_head; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 TypeStatistic xslStyleSheets; | 130 TypeStatistic xslStyleSheets; |
129 TypeStatistic fonts; | 131 TypeStatistic fonts; |
130 TypeStatistic other; | 132 TypeStatistic other; |
131 }; | 133 }; |
132 | 134 |
133 Resource* resourceForURL(const KURL&); | 135 Resource* resourceForURL(const KURL&); |
134 | 136 |
135 void add(Resource*); | 137 void add(Resource*); |
136 void replace(Resource* newResource, Resource* oldResource); | 138 void replace(Resource* newResource, Resource* oldResource); |
137 void remove(Resource* resource) { evict(resource); } | 139 void remove(Resource* resource) { evict(resource); } |
| 140 bool contains(Resource*); |
138 | 141 |
139 static KURL removeFragmentIdentifierIfNeeded(const KURL& originalURL); | 142 static KURL removeFragmentIdentifierIfNeeded(const KURL& originalURL); |
140 | 143 |
141 // Sets the cache's memory capacities, in bytes. These will hold only approx
imately, | 144 // Sets the cache's memory capacities, in bytes. These will hold only approx
imately, |
142 // since the decoded cost of resources like scripts and stylesheets is not k
nown. | 145 // since the decoded cost of resources like scripts and stylesheets is not k
nown. |
143 // - minDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is under pressure. | 146 // - minDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is under pressure. |
144 // - maxDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is not under pressure. | 147 // - maxDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is not under pressure. |
145 // - totalBytes: The maximum number of bytes that the cache should consume
overall. | 148 // - totalBytes: The maximum number of bytes that the cache should consume
overall. |
146 void setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t totalByt
es); | 149 void setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t totalByt
es); |
147 void setDelayBeforeLiveDecodedPrune(double seconds) { m_delayBeforeLiveDecod
edPrune = seconds; } | 150 void setDelayBeforeLiveDecodedPrune(double seconds) { m_delayBeforeLiveDecod
edPrune = seconds; } |
148 void setMaxPruneDeferralDelay(double seconds) { m_maxPruneDeferralDelay = se
conds; } | 151 void setMaxPruneDeferralDelay(double seconds) { m_maxPruneDeferralDelay = se
conds; } |
149 | 152 |
150 void evictResources(); | 153 void evictResources(); |
151 | 154 |
152 void prune(Resource* justReleasedResource = 0); | 155 void prune(Resource* justReleasedResource = 0); |
153 | 156 |
154 // Calls to put the cached resource into and out of LRU lists. | 157 // Called to adjust a resource's size, lru list position, and access count. |
155 void insertInLRUList(Resource*); | 158 void update(Resource*, size_t oldSize, size_t newSize, bool wasAccessed = fa
lse); |
156 void removeFromLRUList(Resource*); | 159 void updateForAccess(Resource* resource) { update(resource, resource->size()
, resource->size(), true); } |
157 | |
158 // Called to adjust the cache totals when a resource changes size. | |
159 void adjustSize(bool live, ptrdiff_t delta); | |
160 | 160 |
161 // Track decoded resources that are in the cache and referenced by a Web pag
e. | 161 // Track decoded resources that are in the cache and referenced by a Web pag
e. |
162 void insertInLiveDecodedResourcesList(Resource*); | 162 void insertInLiveDecodedResourcesList(Resource*); |
163 void removeFromLiveDecodedResourcesList(Resource*); | 163 void removeFromLiveDecodedResourcesList(Resource*); |
164 bool isInLiveDecodedResourcesList(Resource*); | 164 bool isInLiveDecodedResourcesList(Resource*); |
165 | 165 |
166 void addToLiveResourcesSize(Resource*); | 166 void addToLiveResourcesSize(Resource*); |
167 void removeFromLiveResourcesSize(Resource*); | 167 void removeFromLiveResourcesSize(Resource*); |
168 | 168 |
169 static void removeURLFromCache(ExecutionContext*, const KURL&); | 169 static void removeURLFromCache(ExecutionContext*, const KURL&); |
170 | 170 |
171 Statistics getStatistics(); | 171 Statistics getStatistics(); |
172 | 172 |
173 size_t minDeadCapacity() const { return m_minDeadCapacity; } | 173 size_t minDeadCapacity() const { return m_minDeadCapacity; } |
174 size_t maxDeadCapacity() const { return m_maxDeadCapacity; } | 174 size_t maxDeadCapacity() const { return m_maxDeadCapacity; } |
175 size_t capacity() const { return m_capacity; } | 175 size_t capacity() const { return m_capacity; } |
176 size_t liveSize() const { return m_liveSize; } | 176 size_t liveSize() const { return m_liveSize; } |
177 size_t deadSize() const { return m_deadSize; } | 177 size_t deadSize() const { return m_deadSize; } |
178 | 178 |
179 // TaskObserver implementation | 179 // TaskObserver implementation |
180 virtual void willProcessTask() OVERRIDE; | 180 virtual void willProcessTask() OVERRIDE; |
181 virtual void didProcessTask() OVERRIDE; | 181 virtual void didProcessTask() OVERRIDE; |
182 | 182 |
183 private: | 183 private: |
184 LRUList* lruListFor(MemoryCacheEntry*); | 184 LRUList* lruListFor(unsigned accessCount, size_t); |
185 | 185 |
186 #ifdef MEMORY_CACHE_STATS | 186 #ifdef MEMORY_CACHE_STATS |
187 void dumpStats(Timer<MemoryCache>*); | 187 void dumpStats(Timer<MemoryCache>*); |
188 void dumpLRULists(bool includeLive) const; | 188 void dumpLRULists(bool includeLive) const; |
189 #endif | 189 #endif |
190 | 190 |
| 191 // Calls to put the cached resource into and out of LRU lists. |
| 192 void insertInLRUList(MemoryCacheEntry*, LRUList*); |
| 193 void removeFromLRUList(MemoryCacheEntry*, LRUList*); |
| 194 |
191 size_t liveCapacity() const; | 195 size_t liveCapacity() const; |
192 size_t deadCapacity() const; | 196 size_t deadCapacity() const; |
193 | 197 |
194 // pruneDeadResources() - Flush decoded and encoded data from resources not
referenced by Web pages. | 198 // pruneDeadResources() - Flush decoded and encoded data from resources not
referenced by Web pages. |
195 // pruneLiveResources() - Flush decoded data from resources still referenced
by Web pages. | 199 // pruneLiveResources() - Flush decoded data from resources still referenced
by Web pages. |
196 void pruneDeadResources(); // Automatically decide how much to prune. | 200 void pruneDeadResources(); // Automatically decide how much to prune. |
197 void pruneLiveResources(); | 201 void pruneLiveResources(); |
198 void pruneNow(double currentTime); | 202 void pruneNow(double currentTime); |
199 | 203 |
200 bool evict(Resource*); | 204 bool evict(Resource*); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 242 |
239 // Returns the global cache. | 243 // Returns the global cache. |
240 MemoryCache* memoryCache(); | 244 MemoryCache* memoryCache(); |
241 | 245 |
242 // Sets the global cache, used to swap in a test instance. | 246 // Sets the global cache, used to swap in a test instance. |
243 void setMemoryCacheForTesting(MemoryCache*); | 247 void setMemoryCacheForTesting(MemoryCache*); |
244 | 248 |
245 } | 249 } |
246 | 250 |
247 #endif | 251 #endif |
OLD | NEW |