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 27 matching lines...) Expand all Loading... | |
38 static Persistent<MemoryCache>* gMemoryCache; | 38 static Persistent<MemoryCache>* gMemoryCache; |
39 | 39 |
40 static const unsigned cDefaultCacheCapacity = 8192 * 1024; | 40 static const unsigned cDefaultCacheCapacity = 8192 * 1024; |
41 static const unsigned cDeferredPruneDeadCapacityFactor = 2; | 41 static const unsigned cDeferredPruneDeadCapacityFactor = 2; |
42 static const int cMinDelayBeforeLiveDecodedPrune = 1; // Seconds. | 42 static const int cMinDelayBeforeLiveDecodedPrune = 1; // Seconds. |
43 static const double cMaxPruneDeferralDelay = 0.5; // Seconds. | 43 static const double cMaxPruneDeferralDelay = 0.5; // Seconds. |
44 static const float cTargetPrunePercentage = .95f; // Percentage of capacity towa rd which we prune, to avoid immediately pruning again. | 44 static const float cTargetPrunePercentage = .95f; // Percentage of capacity towa rd which we prune, to avoid immediately pruning again. |
45 | 45 |
46 MemoryCache* memoryCache() | 46 MemoryCache* memoryCache() |
47 { | 47 { |
48 ASSERT(WTF::isMainThread()); | 48 DCHECK(WTF::isMainThread()); |
49 if (!gMemoryCache) | 49 if (!gMemoryCache) |
50 gMemoryCache = new Persistent<MemoryCache>(MemoryCache::create()); | 50 gMemoryCache = new Persistent<MemoryCache>(MemoryCache::create()); |
51 return gMemoryCache->get(); | 51 return gMemoryCache->get(); |
52 } | 52 } |
53 | 53 |
54 MemoryCache* replaceMemoryCacheForTesting(MemoryCache* cache) | 54 MemoryCache* replaceMemoryCacheForTesting(MemoryCache* cache) |
55 { | 55 { |
56 memoryCache(); | 56 memoryCache(); |
57 MemoryCache* oldCache = gMemoryCache->release(); | 57 MemoryCache* oldCache = gMemoryCache->release(); |
58 *gMemoryCache = cache; | 58 *gMemoryCache = cache; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 | 149 |
150 String MemoryCache::defaultCacheIdentifier() | 150 String MemoryCache::defaultCacheIdentifier() |
151 { | 151 { |
152 return emptyString(); | 152 return emptyString(); |
153 } | 153 } |
154 | 154 |
155 MemoryCache::ResourceMap* MemoryCache::ensureResourceMap(const String& cacheIden tifier) | 155 MemoryCache::ResourceMap* MemoryCache::ensureResourceMap(const String& cacheIden tifier) |
156 { | 156 { |
157 if (!m_resourceMaps.contains(cacheIdentifier)) { | 157 if (!m_resourceMaps.contains(cacheIdentifier)) { |
158 ResourceMapIndex::AddResult result = m_resourceMaps.add(cacheIdentifier, new ResourceMap); | 158 ResourceMapIndex::AddResult result = m_resourceMaps.add(cacheIdentifier, new ResourceMap); |
159 RELEASE_ASSERT(result.isNewEntry); | 159 CHECK(result.isNewEntry); |
160 } | 160 } |
161 return m_resourceMaps.get(cacheIdentifier); | 161 return m_resourceMaps.get(cacheIdentifier); |
162 } | 162 } |
163 | 163 |
164 void MemoryCache::add(Resource* resource) | 164 void MemoryCache::add(Resource* resource) |
165 { | 165 { |
166 ASSERT(WTF::isMainThread()); | 166 DCHECK(WTF::isMainThread()); |
167 ASSERT(resource->url().isValid()); | 167 DCHECK(resource->url().isValid()); |
168 ResourceMap* resources = ensureResourceMap(resource->cacheIdentifier()); | 168 ResourceMap* resources = ensureResourceMap(resource->cacheIdentifier()); |
169 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); | 169 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); |
170 CHECK(!contains(resource)); | 170 CHECK(!contains(resource)); |
171 resources->set(url, MemoryCacheEntry::create(resource)); | 171 resources->set(url, MemoryCacheEntry::create(resource)); |
172 update(resource, 0, resource->size(), true); | 172 update(resource, 0, resource->size(), true); |
173 | 173 |
174 RESOURCE_LOADING_DVLOG(1) << "MemoryCache::add Added " << resource->url().ge tString() << ", resource " << resource; | 174 RESOURCE_LOADING_DVLOG(1) << "MemoryCache::add Added " << resource->url().ge tString() << ", resource " << resource; |
175 } | 175 } |
176 | 176 |
177 void MemoryCache::remove(Resource* resource) | 177 void MemoryCache::remove(Resource* resource) |
178 { | 178 { |
179 // The resource may have already been removed by someone other than our call er, | 179 // The resource may have already been removed by someone other than our call er, |
180 // who needed a fresh copy for a reload. | 180 // who needed a fresh copy for a reload. |
181 if (MemoryCacheEntry* entry = getEntryForResource(resource)) | 181 if (MemoryCacheEntry* entry = getEntryForResource(resource)) |
182 evict(entry); | 182 evict(entry); |
183 } | 183 } |
184 | 184 |
185 bool MemoryCache::contains(const Resource* resource) const | 185 bool MemoryCache::contains(const Resource* resource) const |
186 { | 186 { |
187 return getEntryForResource(resource); | 187 return getEntryForResource(resource); |
188 } | 188 } |
189 | 189 |
190 Resource* MemoryCache::resourceForURL(const KURL& resourceURL) | 190 Resource* MemoryCache::resourceForURL(const KURL& resourceURL) |
191 { | 191 { |
192 return resourceForURL(resourceURL, defaultCacheIdentifier()); | 192 return resourceForURL(resourceURL, defaultCacheIdentifier()); |
193 } | 193 } |
194 | 194 |
195 Resource* MemoryCache::resourceForURL(const KURL& resourceURL, const String& cac heIdentifier) | 195 Resource* MemoryCache::resourceForURL(const KURL& resourceURL, const String& cac heIdentifier) |
196 { | 196 { |
197 ASSERT(WTF::isMainThread()); | 197 DCHECK(WTF::isMainThread()); |
198 if (!resourceURL.isValid() || resourceURL.isNull()) | 198 if (!resourceURL.isValid() || resourceURL.isNull()) |
199 return nullptr; | 199 return nullptr; |
200 ASSERT(!cacheIdentifier.isNull()); | 200 DCHECK(!cacheIdentifier.isNull()); |
201 ResourceMap* resources = m_resourceMaps.get(cacheIdentifier); | 201 ResourceMap* resources = m_resourceMaps.get(cacheIdentifier); |
202 if (!resources) | 202 if (!resources) |
203 return nullptr; | 203 return nullptr; |
204 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); | 204 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); |
205 MemoryCacheEntry* entry = resources->get(url); | 205 MemoryCacheEntry* entry = resources->get(url); |
206 if (!entry) | 206 if (!entry) |
207 return nullptr; | 207 return nullptr; |
208 return entry->resource(); | 208 return entry->resource(); |
209 } | 209 } |
210 | 210 |
211 HeapVector<Member<Resource>> MemoryCache::resourcesForURL(const KURL& resourceUR L) | 211 HeapVector<Member<Resource>> MemoryCache::resourcesForURL(const KURL& resourceUR L) |
212 { | 212 { |
213 ASSERT(WTF::isMainThread()); | 213 DCHECK(WTF::isMainThread()); |
214 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); | 214 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); |
215 HeapVector<Member<Resource>> results; | 215 HeapVector<Member<Resource>> results; |
216 for (const auto& resourceMapIter : m_resourceMaps) { | 216 for (const auto& resourceMapIter : m_resourceMaps) { |
217 if (MemoryCacheEntry* entry = resourceMapIter.value->get(url)) { | 217 if (MemoryCacheEntry* entry = resourceMapIter.value->get(url)) { |
218 Resource* resource = entry->resource(); | 218 Resource* resource = entry->resource(); |
219 DCHECK(resource); | 219 DCHECK(resource); |
220 results.append(resource); | 220 results.append(resource); |
221 } | 221 } |
222 } | 222 } |
223 return results; | 223 return results; |
224 } | 224 } |
225 | 225 |
226 size_t MemoryCache::deadCapacity() const | 226 size_t MemoryCache::deadCapacity() const |
227 { | 227 { |
228 // Dead resource capacity is whatever space is not occupied by live resource s, bounded by an independent minimum and maximum. | 228 // Dead resource capacity is whatever space is not occupied by live resource s, bounded by an independent minimum and maximum. |
229 size_t capacity = m_capacity - std::min(m_liveSize, m_capacity); // Start wi th available capacity. | 229 size_t capacity = m_capacity - std::min(m_liveSize, m_capacity); // Start wi th available capacity. |
230 capacity = std::max(capacity, m_minDeadCapacity); // Make sure it's above th e minimum. | 230 capacity = std::max(capacity, m_minDeadCapacity); // Make sure it's above th e minimum. |
231 capacity = std::min(capacity, m_maxDeadCapacity); // Make sure it's below th e maximum. | 231 capacity = std::min(capacity, m_maxDeadCapacity); // Make sure it's below th e maximum. |
232 return capacity; | 232 return capacity; |
233 } | 233 } |
234 | 234 |
235 size_t MemoryCache::liveCapacity() const | 235 size_t MemoryCache::liveCapacity() const |
236 { | 236 { |
237 // Live resource capacity is whatever is left over after calculating dead re source capacity. | 237 // Live resource capacity is whatever is left over after calculating dead re source capacity. |
238 return m_capacity - deadCapacity(); | 238 return m_capacity - deadCapacity(); |
239 } | 239 } |
240 | 240 |
241 void MemoryCache::pruneLiveResources(PruneStrategy strategy) | 241 void MemoryCache::pruneLiveResources(PruneStrategy strategy) |
242 { | 242 { |
243 ASSERT(!m_prunePending); | 243 DCHECK(!m_prunePending); |
244 size_t capacity = liveCapacity(); | 244 size_t capacity = liveCapacity(); |
245 if (strategy == MaximalPrune) | 245 if (strategy == MaximalPrune) |
246 capacity = 0; | 246 capacity = 0; |
247 if (!m_liveSize || (capacity && m_liveSize <= capacity)) | 247 if (!m_liveSize || (capacity && m_liveSize <= capacity)) |
248 return; | 248 return; |
249 | 249 |
250 size_t targetSize = static_cast<size_t>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again. | 250 size_t targetSize = static_cast<size_t>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again. |
251 | 251 |
252 // Destroy any decoded data in live objects that we can. | 252 // Destroy any decoded data in live objects that we can. |
253 // Start from the tail, since this is the lowest priority | 253 // Start from the tail, since this is the lowest priority |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 // empty LRU lists on future prunes. | 348 // empty LRU lists on future prunes. |
349 if (m_allResources[i].m_head) | 349 if (m_allResources[i].m_head) |
350 canShrinkLRULists = false; | 350 canShrinkLRULists = false; |
351 else if (canShrinkLRULists) | 351 else if (canShrinkLRULists) |
352 m_allResources.resize(i); | 352 m_allResources.resize(i); |
353 } | 353 } |
354 } | 354 } |
355 | 355 |
356 void MemoryCache::setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t totalBytes) | 356 void MemoryCache::setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t totalBytes) |
357 { | 357 { |
358 ASSERT(minDeadBytes <= maxDeadBytes); | 358 DCHECK(minDeadBytes <= maxDeadBytes); |
yhirano
2016/09/12 04:33:11
DCHECK_LE
hiroshige
2016/09/13 08:43:19
Done.
| |
359 ASSERT(maxDeadBytes <= totalBytes); | 359 DCHECK(maxDeadBytes <= totalBytes); |
yhirano
2016/09/12 04:33:11
ditto
hiroshige
2016/09/13 08:43:18
Done.
| |
360 m_minDeadCapacity = minDeadBytes; | 360 m_minDeadCapacity = minDeadBytes; |
361 m_maxDeadCapacity = maxDeadBytes; | 361 m_maxDeadCapacity = maxDeadBytes; |
362 m_maxDeferredPruneDeadCapacity = cDeferredPruneDeadCapacityFactor * maxDeadB ytes; | 362 m_maxDeferredPruneDeadCapacity = cDeferredPruneDeadCapacityFactor * maxDeadB ytes; |
363 m_capacity = totalBytes; | 363 m_capacity = totalBytes; |
364 prune(); | 364 prune(); |
365 } | 365 } |
366 | 366 |
367 void MemoryCache::evict(MemoryCacheEntry* entry) | 367 void MemoryCache::evict(MemoryCacheEntry* entry) |
368 { | 368 { |
369 ASSERT(WTF::isMainThread()); | 369 DCHECK(WTF::isMainThread()); |
370 | 370 |
371 Resource* resource = entry->resource(); | 371 Resource* resource = entry->resource(); |
372 DCHECK(resource); | 372 DCHECK(resource); |
373 RESOURCE_LOADING_DVLOG(1) << "Evicting resource " << resource << " for " << resource->url().getString() << " from cache"; | 373 RESOURCE_LOADING_DVLOG(1) << "Evicting resource " << resource << " for " << resource->url().getString() << " from cache"; |
374 TRACE_EVENT1("blink", "MemoryCache::evict", "resource", resource->url().getS tring().utf8()); | 374 TRACE_EVENT1("blink", "MemoryCache::evict", "resource", resource->url().getS tring().utf8()); |
375 // The resource may have already been removed by someone other than our call er, | 375 // The resource may have already been removed by someone other than our call er, |
376 // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bu g.cgi?id=12479#c6>. | 376 // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bu g.cgi?id=12479#c6>. |
377 update(resource, resource->size(), 0, false); | 377 update(resource, resource->size(), 0, false); |
378 removeFromLiveDecodedResourcesList(entry); | 378 removeFromLiveDecodedResourcesList(entry); |
379 | 379 |
380 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); | 380 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); |
381 ASSERT(resources); | 381 DCHECK(resources); |
382 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); | 382 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); |
383 ResourceMap::iterator it = resources->find(url); | 383 ResourceMap::iterator it = resources->find(url); |
384 ASSERT(it != resources->end()); | 384 DCHECK(it != resources->end()); |
yhirano
2016/09/12 04:33:11
DCHECK_NE
hiroshige
2016/09/13 08:43:19
Done.
| |
385 | 385 |
386 MemoryCacheEntry* entryPtr = it->value; | 386 MemoryCacheEntry* entryPtr = it->value; |
387 resources->remove(it); | 387 resources->remove(it); |
388 if (entryPtr) | 388 if (entryPtr) |
389 entryPtr->dispose(); | 389 entryPtr->dispose(); |
390 } | 390 } |
391 | 391 |
392 MemoryCacheEntry* MemoryCache::getEntryForResource(const Resource* resource) con st | 392 MemoryCacheEntry* MemoryCache::getEntryForResource(const Resource* resource) con st |
393 { | 393 { |
394 if (!resource || resource->url().isNull() || resource->url().isEmpty()) | 394 if (!resource || resource->url().isNull() || resource->url().isEmpty()) |
395 return nullptr; | 395 return nullptr; |
396 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); | 396 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); |
397 if (!resources) | 397 if (!resources) |
398 return nullptr; | 398 return nullptr; |
399 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); | 399 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); |
400 MemoryCacheEntry* entry = resources->get(url); | 400 MemoryCacheEntry* entry = resources->get(url); |
401 if (!entry || entry->resource() != resource) | 401 if (!entry || entry->resource() != resource) |
402 return nullptr; | 402 return nullptr; |
403 return entry; | 403 return entry; |
404 } | 404 } |
405 | 405 |
406 MemoryCacheLRUList* MemoryCache::lruListFor(unsigned accessCount, size_t size) | 406 MemoryCacheLRUList* MemoryCache::lruListFor(unsigned accessCount, size_t size) |
407 { | 407 { |
408 ASSERT(accessCount > 0); | 408 DCHECK_GT(accessCount, 0u); |
409 unsigned queueIndex = WTF::fastLog2(size / accessCount); | 409 unsigned queueIndex = WTF::fastLog2(size / accessCount); |
410 if (m_allResources.size() <= queueIndex) | 410 if (m_allResources.size() <= queueIndex) |
411 m_allResources.grow(queueIndex + 1); | 411 m_allResources.grow(queueIndex + 1); |
412 return &m_allResources[queueIndex]; | 412 return &m_allResources[queueIndex]; |
413 } | 413 } |
414 | 414 |
415 void MemoryCache::removeFromLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* list) | 415 void MemoryCache::removeFromLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* list) |
416 { | 416 { |
417 ASSERT(containedInLRUList(entry, list)); | 417 DCHECK(containedInLRUList(entry, list)); |
418 | 418 |
419 MemoryCacheEntry* next = entry->m_nextInAllResourcesList; | 419 MemoryCacheEntry* next = entry->m_nextInAllResourcesList; |
420 MemoryCacheEntry* previous = entry->m_previousInAllResourcesList; | 420 MemoryCacheEntry* previous = entry->m_previousInAllResourcesList; |
421 entry->m_nextInAllResourcesList = nullptr; | 421 entry->m_nextInAllResourcesList = nullptr; |
422 entry->m_previousInAllResourcesList = nullptr; | 422 entry->m_previousInAllResourcesList = nullptr; |
423 | 423 |
424 if (next) | 424 if (next) |
425 next->m_previousInAllResourcesList = previous; | 425 next->m_previousInAllResourcesList = previous; |
426 else | 426 else |
427 list->m_tail = previous; | 427 list->m_tail = previous; |
428 | 428 |
429 if (previous) | 429 if (previous) |
430 previous->m_nextInAllResourcesList = next; | 430 previous->m_nextInAllResourcesList = next; |
431 else | 431 else |
432 list->m_head = next; | 432 list->m_head = next; |
433 | 433 |
434 ASSERT(!containedInLRUList(entry, list)); | 434 DCHECK(!containedInLRUList(entry, list)); |
435 } | 435 } |
436 | 436 |
437 void MemoryCache::insertInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* l ist) | 437 void MemoryCache::insertInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* l ist) |
438 { | 438 { |
439 ASSERT(!containedInLRUList(entry, list)); | 439 DCHECK(!containedInLRUList(entry, list)); |
440 | 440 |
441 entry->m_nextInAllResourcesList = list->m_head; | 441 entry->m_nextInAllResourcesList = list->m_head; |
442 list->m_head = entry; | 442 list->m_head = entry; |
443 | 443 |
444 if (entry->m_nextInAllResourcesList) | 444 if (entry->m_nextInAllResourcesList) |
445 entry->m_nextInAllResourcesList->m_previousInAllResourcesList = entry; | 445 entry->m_nextInAllResourcesList->m_previousInAllResourcesList = entry; |
446 else | 446 else |
447 list->m_tail = entry; | 447 list->m_tail = entry; |
448 | 448 |
449 ASSERT(containedInLRUList(entry, list)); | 449 DCHECK(containedInLRUList(entry, list)); |
450 } | 450 } |
451 | 451 |
452 bool MemoryCache::containedInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList * list) | 452 bool MemoryCache::containedInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList * list) |
453 { | 453 { |
454 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInAllResourcesList) { | 454 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInAllResourcesList) { |
455 if (current == entry) | 455 if (current == entry) |
456 return true; | 456 return true; |
457 } | 457 } |
458 ASSERT(!entry->m_nextInAllResourcesList && !entry->m_previousInAllResourcesL ist); | 458 DCHECK(!entry->m_nextInAllResourcesList && !entry->m_previousInAllResourcesL ist); |
459 return false; | 459 return false; |
460 } | 460 } |
461 | 461 |
462 void MemoryCache::removeFromLiveDecodedResourcesList(MemoryCacheEntry* entry) | 462 void MemoryCache::removeFromLiveDecodedResourcesList(MemoryCacheEntry* entry) |
463 { | 463 { |
464 // If we've never been accessed, then we're brand new and not in any list. | 464 // If we've never been accessed, then we're brand new and not in any list. |
465 if (!entry->m_inLiveDecodedResourcesList) | 465 if (!entry->m_inLiveDecodedResourcesList) |
466 return; | 466 return; |
467 ASSERT(containedInLiveDecodedResourcesList(entry)); | 467 DCHECK(containedInLiveDecodedResourcesList(entry)); |
468 | 468 |
469 entry->m_inLiveDecodedResourcesList = false; | 469 entry->m_inLiveDecodedResourcesList = false; |
470 | 470 |
471 MemoryCacheEntry* next = entry->m_nextInLiveResourcesList; | 471 MemoryCacheEntry* next = entry->m_nextInLiveResourcesList; |
472 MemoryCacheEntry* previous = entry->m_previousInLiveResourcesList; | 472 MemoryCacheEntry* previous = entry->m_previousInLiveResourcesList; |
473 | 473 |
474 entry->m_nextInLiveResourcesList = nullptr; | 474 entry->m_nextInLiveResourcesList = nullptr; |
475 entry->m_previousInLiveResourcesList = nullptr; | 475 entry->m_previousInLiveResourcesList = nullptr; |
476 | 476 |
477 if (next) | 477 if (next) |
478 next->m_previousInLiveResourcesList = previous; | 478 next->m_previousInLiveResourcesList = previous; |
479 else | 479 else |
480 m_liveDecodedResources.m_tail = previous; | 480 m_liveDecodedResources.m_tail = previous; |
481 | 481 |
482 if (previous) | 482 if (previous) |
483 previous->m_nextInLiveResourcesList = next; | 483 previous->m_nextInLiveResourcesList = next; |
484 else | 484 else |
485 m_liveDecodedResources.m_head = next; | 485 m_liveDecodedResources.m_head = next; |
486 | 486 |
487 ASSERT(!containedInLiveDecodedResourcesList(entry)); | 487 DCHECK(!containedInLiveDecodedResourcesList(entry)); |
488 } | 488 } |
489 | 489 |
490 void MemoryCache::insertInLiveDecodedResourcesList(MemoryCacheEntry* entry) | 490 void MemoryCache::insertInLiveDecodedResourcesList(MemoryCacheEntry* entry) |
491 { | 491 { |
492 ASSERT(!containedInLiveDecodedResourcesList(entry)); | 492 DCHECK(!containedInLiveDecodedResourcesList(entry)); |
493 | 493 |
494 entry->m_inLiveDecodedResourcesList = true; | 494 entry->m_inLiveDecodedResourcesList = true; |
495 | 495 |
496 entry->m_nextInLiveResourcesList = m_liveDecodedResources.m_head; | 496 entry->m_nextInLiveResourcesList = m_liveDecodedResources.m_head; |
497 if (m_liveDecodedResources.m_head) | 497 if (m_liveDecodedResources.m_head) |
498 m_liveDecodedResources.m_head->m_previousInLiveResourcesList = entry; | 498 m_liveDecodedResources.m_head->m_previousInLiveResourcesList = entry; |
499 m_liveDecodedResources.m_head = entry; | 499 m_liveDecodedResources.m_head = entry; |
500 | 500 |
501 if (!entry->m_nextInLiveResourcesList) | 501 if (!entry->m_nextInLiveResourcesList) |
502 m_liveDecodedResources.m_tail = entry; | 502 m_liveDecodedResources.m_tail = entry; |
503 | 503 |
504 ASSERT(containedInLiveDecodedResourcesList(entry)); | 504 DCHECK(containedInLiveDecodedResourcesList(entry)); |
505 } | 505 } |
506 | 506 |
507 bool MemoryCache::containedInLiveDecodedResourcesList(MemoryCacheEntry* entry) | 507 bool MemoryCache::containedInLiveDecodedResourcesList(MemoryCacheEntry* entry) |
508 { | 508 { |
509 for (MemoryCacheEntry* current = m_liveDecodedResources.m_head; current; cur rent = current->m_nextInLiveResourcesList) { | 509 for (MemoryCacheEntry* current = m_liveDecodedResources.m_head; current; cur rent = current->m_nextInLiveResourcesList) { |
510 if (current == entry) { | 510 if (current == entry) { |
511 ASSERT(entry->m_inLiveDecodedResourcesList); | 511 DCHECK(entry->m_inLiveDecodedResourcesList); |
512 return true; | 512 return true; |
513 } | 513 } |
514 } | 514 } |
515 ASSERT(!entry->m_nextInLiveResourcesList && !entry->m_previousInLiveResource sList && !entry->m_inLiveDecodedResourcesList); | 515 DCHECK(!entry->m_nextInLiveResourcesList && !entry->m_previousInLiveResource sList && !entry->m_inLiveDecodedResourcesList); |
yhirano
2016/09/12 04:33:11
It would be good to have three separate DCHECKs.
hiroshige
2016/09/13 08:43:18
Done.
| |
516 return false; | 516 return false; |
517 } | 517 } |
518 | 518 |
519 void MemoryCache::makeLive(Resource* resource) | 519 void MemoryCache::makeLive(Resource* resource) |
520 { | 520 { |
521 if (!contains(resource)) | 521 if (!contains(resource)) |
522 return; | 522 return; |
523 ASSERT(m_deadSize >= resource->size()); | 523 DCHECK(m_deadSize >= resource->size()); |
yhirano
2016/09/12 04:33:11
DCHEK_GE
hiroshige
2016/09/13 08:43:18
Done.
| |
524 m_liveSize += resource->size(); | 524 m_liveSize += resource->size(); |
525 m_deadSize -= resource->size(); | 525 m_deadSize -= resource->size(); |
526 } | 526 } |
527 | 527 |
528 void MemoryCache::makeDead(Resource* resource) | 528 void MemoryCache::makeDead(Resource* resource) |
529 { | 529 { |
530 if (!contains(resource)) | 530 if (!contains(resource)) |
531 return; | 531 return; |
532 m_liveSize -= resource->size(); | 532 m_liveSize -= resource->size(); |
533 m_deadSize += resource->size(); | 533 m_deadSize += resource->size(); |
(...skipping 10 matching lines...) Expand all Loading... | |
544 // and both of those are used to determine which LRU queue the resource shou ld be in. | 544 // and both of those are used to determine which LRU queue the resource shou ld be in. |
545 if (oldSize) | 545 if (oldSize) |
546 removeFromLRUList(entry, lruListFor(entry->m_accessCount, oldSize)); | 546 removeFromLRUList(entry, lruListFor(entry->m_accessCount, oldSize)); |
547 if (wasAccessed) | 547 if (wasAccessed) |
548 entry->m_accessCount++; | 548 entry->m_accessCount++; |
549 if (newSize) | 549 if (newSize) |
550 insertInLRUList(entry, lruListFor(entry->m_accessCount, newSize)); | 550 insertInLRUList(entry, lruListFor(entry->m_accessCount, newSize)); |
551 | 551 |
552 ptrdiff_t delta = newSize - oldSize; | 552 ptrdiff_t delta = newSize - oldSize; |
553 if (resource->isAlive()) { | 553 if (resource->isAlive()) { |
554 ASSERT(delta >= 0 || m_liveSize >= static_cast<size_t>(-delta) ); | 554 DCHECK(delta >= 0 || m_liveSize >= static_cast<size_t>(-delta) ); |
555 m_liveSize += delta; | 555 m_liveSize += delta; |
556 } else { | 556 } else { |
557 ASSERT(delta >= 0 || m_deadSize >= static_cast<size_t>(-delta) ); | 557 DCHECK(delta >= 0 || m_deadSize >= static_cast<size_t>(-delta) ); |
558 m_deadSize += delta; | 558 m_deadSize += delta; |
559 } | 559 } |
560 } | 560 } |
561 | 561 |
562 void MemoryCache::updateDecodedResource(Resource* resource, UpdateReason reason) | 562 void MemoryCache::updateDecodedResource(Resource* resource, UpdateReason reason) |
563 { | 563 { |
564 MemoryCacheEntry* entry = getEntryForResource(resource); | 564 MemoryCacheEntry* entry = getEntryForResource(resource); |
565 if (!entry) | 565 if (!entry) |
566 return; | 566 return; |
567 | 567 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 } | 691 } |
692 } | 692 } |
693 | 693 |
694 void MemoryCache::willProcessTask() | 694 void MemoryCache::willProcessTask() |
695 { | 695 { |
696 } | 696 } |
697 | 697 |
698 void MemoryCache::didProcessTask() | 698 void MemoryCache::didProcessTask() |
699 { | 699 { |
700 // Perform deferred pruning | 700 // Perform deferred pruning |
701 ASSERT(m_prunePending); | 701 DCHECK(m_prunePending); |
702 pruneNow(WTF::currentTime(), AutomaticPrune); | 702 pruneNow(WTF::currentTime(), AutomaticPrune); |
703 } | 703 } |
704 | 704 |
705 void MemoryCache::pruneAll() | 705 void MemoryCache::pruneAll() |
706 { | 706 { |
707 double currentTime = WTF::currentTime(); | 707 double currentTime = WTF::currentTime(); |
708 pruneNow(currentTime, MaximalPrune); | 708 pruneNow(currentTime, MaximalPrune); |
709 } | 709 } |
710 | 710 |
711 void MemoryCache::pruneNow(double currentTime, PruneStrategy strategy) | 711 void MemoryCache::pruneNow(double currentTime, PruneStrategy strategy) |
(...skipping 28 matching lines...) Expand all Loading... | |
740 | 740 |
741 void MemoryCache::onMemoryPressure(WebMemoryPressureLevel level) | 741 void MemoryCache::onMemoryPressure(WebMemoryPressureLevel level) |
742 { | 742 { |
743 pruneAll(); | 743 pruneAll(); |
744 } | 744 } |
745 | 745 |
746 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y) | 746 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y) |
747 { | 747 { |
748 MemoryCacheEntry* ex = getEntryForResource(x); | 748 MemoryCacheEntry* ex = getEntryForResource(x); |
749 MemoryCacheEntry* ey = getEntryForResource(y); | 749 MemoryCacheEntry* ey = getEntryForResource(y); |
750 ASSERT(ex); | 750 DCHECK(ex); |
751 ASSERT(ey); | 751 DCHECK(ey); |
752 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size()); | 752 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size()); |
753 } | 753 } |
754 | 754 |
755 } // namespace blink | 755 } // namespace blink |
OLD | NEW |