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) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
6 | 6 |
7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "platform/TraceEvent.h" | 34 #include "platform/TraceEvent.h" |
35 #include "platform/weborigin/SecurityOrigin.h" | 35 #include "platform/weborigin/SecurityOrigin.h" |
36 #include "platform/weborigin/SecurityOriginHash.h" | 36 #include "platform/weborigin/SecurityOriginHash.h" |
37 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
38 #include "wtf/Assertions.h" | 38 #include "wtf/Assertions.h" |
39 #include "wtf/CurrentTime.h" | 39 #include "wtf/CurrentTime.h" |
40 #include "wtf/MathExtras.h" | 40 #include "wtf/MathExtras.h" |
41 #include "wtf/TemporaryChange.h" | 41 #include "wtf/TemporaryChange.h" |
42 #include "wtf/text/CString.h" | 42 #include "wtf/text/CString.h" |
43 | 43 |
44 using namespace std; | |
45 | |
46 namespace WebCore { | 44 namespace WebCore { |
47 | 45 |
48 static MemoryCache* gMemoryCache; | 46 static MemoryCache* gMemoryCache; |
49 | 47 |
50 static const unsigned cDefaultCacheCapacity = 8192 * 1024; | 48 static const unsigned cDefaultCacheCapacity = 8192 * 1024; |
51 static const unsigned cDeferredPruneDeadCapacityFactor = 2; | 49 static const unsigned cDeferredPruneDeadCapacityFactor = 2; |
52 static const int cMinDelayBeforeLiveDecodedPrune = 1; // Seconds. | 50 static const int cMinDelayBeforeLiveDecodedPrune = 1; // Seconds. |
53 static const double cMaxPruneDeferralDelay = 0.5; // Seconds. | 51 static const double cMaxPruneDeferralDelay = 0.5; // Seconds. |
54 static const float cTargetPrunePercentage = .95f; // Percentage of capacity towa
rd which we prune, to avoid immediately pruning again. | 52 static const float cTargetPrunePercentage = .95f; // Percentage of capacity towa
rd which we prune, to avoid immediately pruning again. |
55 | 53 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 bool didEvict = evict(resource); | 140 bool didEvict = evict(resource); |
143 ASSERT_UNUSED(didEvict, didEvict); | 141 ASSERT_UNUSED(didEvict, didEvict); |
144 return 0; | 142 return 0; |
145 } | 143 } |
146 return resource; | 144 return resource; |
147 } | 145 } |
148 | 146 |
149 size_t MemoryCache::deadCapacity() const | 147 size_t MemoryCache::deadCapacity() const |
150 { | 148 { |
151 // Dead resource capacity is whatever space is not occupied by live resource
s, bounded by an independent minimum and maximum. | 149 // Dead resource capacity is whatever space is not occupied by live resource
s, bounded by an independent minimum and maximum. |
152 size_t capacity = m_capacity - min(m_liveSize, m_capacity); // Start with av
ailable capacity. | 150 size_t capacity = m_capacity - std::min(m_liveSize, m_capacity); // Start wi
th available capacity. |
153 capacity = max(capacity, m_minDeadCapacity); // Make sure it's above the min
imum. | 151 capacity = std::max(capacity, m_minDeadCapacity); // Make sure it's above th
e minimum. |
154 capacity = min(capacity, m_maxDeadCapacity); // Make sure it's below the max
imum. | 152 capacity = std::min(capacity, m_maxDeadCapacity); // Make sure it's below th
e maximum. |
155 return capacity; | 153 return capacity; |
156 } | 154 } |
157 | 155 |
158 size_t MemoryCache::liveCapacity() const | 156 size_t MemoryCache::liveCapacity() const |
159 { | 157 { |
160 // Live resource capacity is whatever is left over after calculating dead re
source capacity. | 158 // Live resource capacity is whatever is left over after calculating dead re
source capacity. |
161 return m_capacity - deadCapacity(); | 159 return m_capacity - deadCapacity(); |
162 } | 160 } |
163 | 161 |
164 void MemoryCache::pruneLiveResources() | 162 void MemoryCache::pruneLiveResources() |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 adjustSize(resource->hasClients(), -static_cast<ptrdiff_t>(resource->siz
e())); | 307 adjustSize(resource->hasClients(), -static_cast<ptrdiff_t>(resource->siz
e())); |
310 } else { | 308 } else { |
311 ASSERT(m_resources.get(resource->url()) != resource); | 309 ASSERT(m_resources.get(resource->url()) != resource); |
312 } | 310 } |
313 | 311 |
314 return resource->deleteIfPossible(); | 312 return resource->deleteIfPossible(); |
315 } | 313 } |
316 | 314 |
317 MemoryCache::LRUList* MemoryCache::lruListFor(Resource* resource) | 315 MemoryCache::LRUList* MemoryCache::lruListFor(Resource* resource) |
318 { | 316 { |
319 unsigned accessCount = max(resource->accessCount(), 1U); | 317 unsigned accessCount = std::max(resource->accessCount(), 1U); |
320 unsigned queueIndex = WTF::fastLog2(resource->size() / accessCount); | 318 unsigned queueIndex = WTF::fastLog2(resource->size() / accessCount); |
321 #ifndef NDEBUG | 319 #ifndef NDEBUG |
322 resource->m_lruIndex = queueIndex; | 320 resource->m_lruIndex = queueIndex; |
323 #endif | 321 #endif |
324 if (m_allResources.size() <= queueIndex) | 322 if (m_allResources.size() <= queueIndex) |
325 m_allResources.grow(queueIndex + 1); | 323 m_allResources.grow(queueIndex + 1); |
326 return &m_allResources[queueIndex]; | 324 return &m_allResources[queueIndex]; |
327 } | 325 } |
328 | 326 |
329 void MemoryCache::removeFromLRUList(Resource* resource) | 327 void MemoryCache::removeFromLRUList(Resource* resource) |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", current->decodedSiz
e() / 1024.0f, (current->encodedSize() + current->overheadSize()) / 1024.0f, cur
rent->accessCount(), current->hasClients(), current->isPurgeable(), current->was
Purged()); | 678 printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", current->decodedSiz
e() / 1024.0f, (current->encodedSize() + current->overheadSize()) / 1024.0f, cur
rent->accessCount(), current->hasClients(), current->isPurgeable(), current->was
Purged()); |
681 | 679 |
682 current = prev; | 680 current = prev; |
683 } | 681 } |
684 } | 682 } |
685 } | 683 } |
686 | 684 |
687 #endif // MEMORY_CACHE_STATS | 685 #endif // MEMORY_CACHE_STATS |
688 | 686 |
689 } // namespace WebCore | 687 } // namespace WebCore |
OLD | NEW |