| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 enum UpdateReason { | 68 enum UpdateReason { |
| 69 UpdateForAccess, | 69 UpdateForAccess, |
| 70 UpdateForPropertyChange | 70 UpdateForPropertyChange |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // MemoryCacheEntry class is used only in MemoryCache class, but we don't make | 73 // MemoryCacheEntry class is used only in MemoryCache class, but we don't make |
| 74 // MemoryCacheEntry class an inner class of MemoryCache because of dependency | 74 // MemoryCacheEntry class an inner class of MemoryCache because of dependency |
| 75 // from MemoryCacheLRUList. | 75 // from MemoryCacheLRUList. |
| 76 class MemoryCacheEntry final : public NoBaseWillBeGarbageCollectedFinalized<Memo
ryCacheEntry> { | 76 class MemoryCacheEntry final : public GarbageCollectedFinalized<MemoryCacheEntry
> { |
| 77 public: | 77 public: |
| 78 static PassOwnPtrWillBeRawPtr<MemoryCacheEntry> create(Resource* resource) | 78 static MemoryCacheEntry* create(Resource* resource) |
| 79 { | 79 { |
| 80 return adoptPtrWillBeNoop(new MemoryCacheEntry(resource)); | 80 return new MemoryCacheEntry(resource); |
| 81 } | 81 } |
| 82 DECLARE_TRACE(); | 82 DECLARE_TRACE(); |
| 83 #if ENABLE(OILPAN) | |
| 84 void dispose(); | 83 void dispose(); |
| 85 #endif | |
| 86 | 84 |
| 87 ResourcePtr<Resource> m_resource; | 85 ResourcePtr<Resource> m_resource; |
| 88 bool m_inLiveDecodedResourcesList; | 86 bool m_inLiveDecodedResourcesList; |
| 89 unsigned m_accessCount; | 87 unsigned m_accessCount; |
| 90 MemoryCacheLiveResourcePriority m_liveResourcePriority; | 88 MemoryCacheLiveResourcePriority m_liveResourcePriority; |
| 91 double m_lastDecodedAccessTime; // Used as a thrash guard | 89 double m_lastDecodedAccessTime; // Used as a thrash guard |
| 92 | 90 |
| 93 RawPtrWillBeMember<MemoryCacheEntry> m_previousInLiveResourcesList; | 91 Member<MemoryCacheEntry> m_previousInLiveResourcesList; |
| 94 RawPtrWillBeMember<MemoryCacheEntry> m_nextInLiveResourcesList; | 92 Member<MemoryCacheEntry> m_nextInLiveResourcesList; |
| 95 RawPtrWillBeMember<MemoryCacheEntry> m_previousInAllResourcesList; | 93 Member<MemoryCacheEntry> m_previousInAllResourcesList; |
| 96 RawPtrWillBeMember<MemoryCacheEntry> m_nextInAllResourcesList; | 94 Member<MemoryCacheEntry> m_nextInAllResourcesList; |
| 97 | 95 |
| 98 private: | 96 private: |
| 99 explicit MemoryCacheEntry(Resource* resource) | 97 explicit MemoryCacheEntry(Resource* resource) |
| 100 : m_resource(resource) | 98 : m_resource(resource) |
| 101 , m_inLiveDecodedResourcesList(false) | 99 , m_inLiveDecodedResourcesList(false) |
| 102 , m_accessCount(0) | 100 , m_accessCount(0) |
| 103 , m_liveResourcePriority(MemoryCacheLiveResourcePriorityLow) | 101 , m_liveResourcePriority(MemoryCacheLiveResourcePriorityLow) |
| 104 , m_lastDecodedAccessTime(0.0) | 102 , m_lastDecodedAccessTime(0.0) |
| 105 , m_previousInLiveResourcesList(nullptr) | 103 , m_previousInLiveResourcesList(nullptr) |
| 106 , m_nextInLiveResourcesList(nullptr) | 104 , m_nextInLiveResourcesList(nullptr) |
| 107 , m_previousInAllResourcesList(nullptr) | 105 , m_previousInAllResourcesList(nullptr) |
| 108 , m_nextInAllResourcesList(nullptr) | 106 , m_nextInAllResourcesList(nullptr) |
| 109 { | 107 { |
| 110 } | 108 } |
| 111 }; | 109 }; |
| 112 | 110 |
| 113 WILL_NOT_BE_EAGERLY_TRACED_CLASS(MemoryCacheEntry); | 111 WILL_NOT_BE_EAGERLY_TRACED_CLASS(MemoryCacheEntry); |
| 114 | 112 |
| 115 // MemoryCacheLRUList is used only in MemoryCache class, but we don't make | 113 // MemoryCacheLRUList is used only in MemoryCache class, but we don't make |
| 116 // MemoryCacheLRUList an inner struct of MemoryCache because we can't define | 114 // MemoryCacheLRUList an inner struct of MemoryCache because we can't define |
| 117 // VectorTraits for inner structs. | 115 // VectorTraits for inner structs. |
| 118 struct MemoryCacheLRUList final { | 116 struct MemoryCacheLRUList final { |
| 119 ALLOW_ONLY_INLINE_ALLOCATION(); | 117 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 120 public: | 118 public: |
| 121 RawPtrWillBeMember<MemoryCacheEntry> m_head; | 119 Member<MemoryCacheEntry> m_head; |
| 122 RawPtrWillBeMember<MemoryCacheEntry> m_tail; | 120 Member<MemoryCacheEntry> m_tail; |
| 123 | 121 |
| 124 MemoryCacheLRUList() : m_head(nullptr), m_tail(nullptr) { } | 122 MemoryCacheLRUList() : m_head(nullptr), m_tail(nullptr) { } |
| 125 DECLARE_TRACE(); | 123 DECLARE_TRACE(); |
| 126 }; | 124 }; |
| 127 | 125 |
| 128 } | 126 } |
| 129 | 127 |
| 130 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::MemoryCacheLRUList); | 128 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::MemoryCacheLRUList); |
| 131 | 129 |
| 132 namespace blink { | 130 namespace blink { |
| 133 | 131 |
| 134 class CORE_EXPORT MemoryCache final : public NoBaseWillBeGarbageCollectedFinaliz
ed<MemoryCache>, public WebThread::TaskObserver { | 132 class CORE_EXPORT MemoryCache final : public GarbageCollectedFinalized<MemoryCac
he>, public WebThread::TaskObserver { |
| 135 WTF_MAKE_NONCOPYABLE(MemoryCache); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(M
emoryCache); | 133 WTF_MAKE_NONCOPYABLE(MemoryCache); |
| 136 public: | 134 public: |
| 137 static PassOwnPtrWillBeRawPtr<MemoryCache> create(); | 135 static MemoryCache* create(); |
| 138 ~MemoryCache(); | 136 ~MemoryCache(); |
| 139 DECLARE_TRACE(); | 137 DECLARE_TRACE(); |
| 140 | 138 |
| 141 struct TypeStatistic { | 139 struct TypeStatistic { |
| 142 int count; | 140 int count; |
| 143 int size; | 141 int size; |
| 144 int liveSize; | 142 int liveSize; |
| 145 int decodedSize; | 143 int decodedSize; |
| 146 int encodedSize; | 144 int encodedSize; |
| 147 int encodedSizeDuplicatedInDataURLs; | 145 int encodedSizeDuplicatedInDataURLs; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 size_t m_maxDeadCapacity; | 284 size_t m_maxDeadCapacity; |
| 287 size_t m_maxDeferredPruneDeadCapacity; | 285 size_t m_maxDeferredPruneDeadCapacity; |
| 288 double m_delayBeforeLiveDecodedPrune; | 286 double m_delayBeforeLiveDecodedPrune; |
| 289 | 287 |
| 290 size_t m_liveSize; // The number of bytes currently consumed by "live" resou
rces in the cache. | 288 size_t m_liveSize; // The number of bytes currently consumed by "live" resou
rces in the cache. |
| 291 size_t m_deadSize; // The number of bytes currently consumed by "dead" resou
rces in the cache. | 289 size_t m_deadSize; // The number of bytes currently consumed by "dead" resou
rces in the cache. |
| 292 | 290 |
| 293 // Size-adjusted and popularity-aware LRU list collection for cache objects.
This collection can hold | 291 // Size-adjusted and popularity-aware LRU list collection for cache objects.
This collection can hold |
| 294 // more resources than the cached resource map, since it can also hold "stal
e" multiple versions of objects that are | 292 // more resources than the cached resource map, since it can also hold "stal
e" multiple versions of objects that are |
| 295 // waiting to die when the clients referencing them go away. | 293 // waiting to die when the clients referencing them go away. |
| 296 WillBeHeapVector<MemoryCacheLRUList, 32> m_allResources; | 294 HeapVector<MemoryCacheLRUList, 32> m_allResources; |
| 297 | 295 |
| 298 // Lists just for live resources with decoded data. Access to this list is b
ased off of painting the resource. | 296 // Lists just for live resources with decoded data. Access to this list is b
ased off of painting the resource. |
| 299 // The lists are ordered by decode priority, with higher indices having high
er priorities. | 297 // The lists are ordered by decode priority, with higher indices having high
er priorities. |
| 300 MemoryCacheLRUList m_liveDecodedResources[MemoryCacheLiveResourcePriorityHig
h + 1]; | 298 MemoryCacheLRUList m_liveDecodedResources[MemoryCacheLiveResourcePriorityHig
h + 1]; |
| 301 | 299 |
| 302 // A URL-based map of all resources that are in the cache (including the fre
shest version of objects that are currently being | 300 // A URL-based map of all resources that are in the cache (including the fre
shest version of objects that are currently being |
| 303 // referenced by a Web page). | 301 // referenced by a Web page). |
| 304 using ResourceMap = WillBeHeapHashMap<String, OwnPtrWillBeMember<MemoryCache
Entry>>; | 302 using ResourceMap = HeapHashMap<String, Member<MemoryCacheEntry>>; |
| 305 using ResourceMapIndex = WillBeHeapHashMap<String, OwnPtrWillBeMember<Resour
ceMap>>; | 303 using ResourceMapIndex = HeapHashMap<String, Member<ResourceMap>>; |
| 306 ResourceMap* ensureResourceMap(const String& cacheIdentifier); | 304 ResourceMap* ensureResourceMap(const String& cacheIdentifier); |
| 307 ResourceMapIndex m_resourceMaps; | 305 ResourceMapIndex m_resourceMaps; |
| 308 | 306 |
| 309 #if ENABLE(OILPAN) | 307 #if ENABLE(OILPAN) |
| 310 // Unlike m_allResources, m_liveResources is a set of Resource objects which | 308 // Unlike m_allResources, m_liveResources is a set of Resource objects which |
| 311 // should not be deleted. m_allResources only contains on-cache Resource | 309 // should not be deleted. m_allResources only contains on-cache Resource |
| 312 // objects. | 310 // objects. |
| 313 // FIXME: Can we remove manual lifetime management of Resource and this? | 311 // FIXME: Can we remove manual lifetime management of Resource and this? |
| 314 HeapHashSet<Member<Resource>> m_liveResources; | 312 HeapHashSet<Member<Resource>> m_liveResources; |
| 315 friend CORE_EXPORT RawPtr<MemoryCache> replaceMemoryCacheForTesting(RawPtr<M
emoryCache>); | 313 friend CORE_EXPORT MemoryCache* replaceMemoryCacheForTesting(MemoryCache*); |
| 316 #endif | 314 #endif |
| 317 | 315 |
| 318 friend class MemoryCacheTest; | 316 friend class MemoryCacheTest; |
| 319 #ifdef MEMORY_CACHE_STATS | 317 #ifdef MEMORY_CACHE_STATS |
| 320 Timer<MemoryCache> m_statsTimer; | 318 Timer<MemoryCache> m_statsTimer; |
| 321 #endif | 319 #endif |
| 322 }; | 320 }; |
| 323 | 321 |
| 324 // Returns the global cache. | 322 // Returns the global cache. |
| 325 CORE_EXPORT MemoryCache* memoryCache(); | 323 CORE_EXPORT MemoryCache* memoryCache(); |
| 326 | 324 |
| 327 // Sets the global cache, used to swap in a test instance. Returns the old | 325 // Sets the global cache, used to swap in a test instance. Returns the old |
| 328 // MemoryCache object. | 326 // MemoryCache object. |
| 329 CORE_EXPORT PassOwnPtrWillBeRawPtr<MemoryCache> replaceMemoryCacheForTesting(Pas
sOwnPtrWillBeRawPtr<MemoryCache>); | 327 CORE_EXPORT MemoryCache* replaceMemoryCacheForTesting(MemoryCache*); |
| 330 | 328 |
| 331 } | 329 } |
| 332 | 330 |
| 333 #endif | 331 #endif |
| OLD | NEW |