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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 // The list might not be sorted by the m_lastDecodedFrameTimeStamp. The impa
ct | 252 // The list might not be sorted by the m_lastDecodedFrameTimeStamp. The impa
ct |
253 // of this weaker invariant is minor as the below if statement to check the | 253 // of this weaker invariant is minor as the below if statement to check the |
254 // elapsedTime will evaluate to false as the current time will be a lot | 254 // elapsedTime will evaluate to false as the current time will be a lot |
255 // greater than the current->m_lastDecodedFrameTimeStamp. | 255 // greater than the current->m_lastDecodedFrameTimeStamp. |
256 // For more details see: https://bugs.webkit.org/show_bug.cgi?id=30209 | 256 // For more details see: https://bugs.webkit.org/show_bug.cgi?id=30209 |
257 | 257 |
258 MemoryCacheEntry* current = m_liveDecodedResources.m_tail; | 258 MemoryCacheEntry* current = m_liveDecodedResources.m_tail; |
259 while (current) { | 259 while (current) { |
260 Resource* resource = current->resource(); | 260 Resource* resource = current->resource(); |
261 MemoryCacheEntry* previous = current->m_previousInLiveResourcesList; | 261 MemoryCacheEntry* previous = current->m_previousInLiveResourcesList; |
262 ASSERT(resource->hasClientsOrObservers()); | 262 DCHECK(resource->isAlive()); |
263 | 263 |
264 if (resource->isLoaded() && resource->decodedSize()) { | 264 if (resource->isLoaded() && resource->decodedSize()) { |
265 // Check to see if the remaining resources are too new to prune. | 265 // Check to see if the remaining resources are too new to prune. |
266 double elapsedTime = m_pruneFrameTimeStamp - current->m_lastDecodedA
ccessTime; | 266 double elapsedTime = m_pruneFrameTimeStamp - current->m_lastDecodedA
ccessTime; |
267 if (strategy == AutomaticPrune && elapsedTime < m_delayBeforeLiveDec
odedPrune) | 267 if (strategy == AutomaticPrune && elapsedTime < m_delayBeforeLiveDec
odedPrune) |
268 return; | 268 return; |
269 | 269 |
270 // Destroy our decoded data if possible. This will remove us | 270 // Destroy our decoded data if possible. This will remove us |
271 // from m_liveDecodedResources, and possibly move us to a | 271 // from m_liveDecodedResources, and possibly move us to a |
272 // different LRU list in m_allResources. | 272 // different LRU list in m_allResources. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 MemoryCacheEntry* previous = current->m_previousInAllResourcesList; | 304 MemoryCacheEntry* previous = current->m_previousInAllResourcesList; |
305 | 305 |
306 // Decoded data may reference other resources. Skip |current| if | 306 // Decoded data may reference other resources. Skip |current| if |
307 // |current| somehow got kicked out of cache during | 307 // |current| somehow got kicked out of cache during |
308 // destroyDecodedData(). | 308 // destroyDecodedData(). |
309 if (!resource || !contains(resource)) { | 309 if (!resource || !contains(resource)) { |
310 current = previous; | 310 current = previous; |
311 continue; | 311 continue; |
312 } | 312 } |
313 | 313 |
314 if (!resource->hasClientsOrObservers() && !resource->isPreloaded() &
& resource->isLoaded()) { | 314 if (!resource->isAlive() && !resource->isPreloaded() && resource->is
Loaded()) { |
315 // Destroy our decoded data. This will remove us from | 315 // Destroy our decoded data. This will remove us from |
316 // m_liveDecodedResources, and possibly move us to a different | 316 // m_liveDecodedResources, and possibly move us to a different |
317 // LRU list in m_allResources. | 317 // LRU list in m_allResources. |
318 resource->prune(); | 318 resource->prune(); |
319 | 319 |
320 if (targetSize && m_deadSize <= targetSize) | 320 if (targetSize && m_deadSize <= targetSize) |
321 return; | 321 return; |
322 } | 322 } |
323 current = previous; | 323 current = previous; |
324 } | 324 } |
325 | 325 |
326 // Now evict objects from this queue. | 326 // Now evict objects from this queue. |
327 current = m_allResources[i].m_tail; | 327 current = m_allResources[i].m_tail; |
328 while (current) { | 328 while (current) { |
329 Resource* resource = current->resource(); | 329 Resource* resource = current->resource(); |
330 MemoryCacheEntry* previous = current->m_previousInAllResourcesList; | 330 MemoryCacheEntry* previous = current->m_previousInAllResourcesList; |
331 if (!resource || !contains(resource)) { | 331 if (!resource || !contains(resource)) { |
332 current = previous; | 332 current = previous; |
333 continue; | 333 continue; |
334 } | 334 } |
335 if (!resource->hasClientsOrObservers() && !resource->isPreloaded())
{ | 335 if (!resource->isAlive() && !resource->isPreloaded()) { |
336 evict(current); | 336 evict(current); |
337 if (targetSize && m_deadSize <= targetSize) | 337 if (targetSize && m_deadSize <= targetSize) |
338 return; | 338 return; |
339 } | 339 } |
340 current = previous; | 340 current = previous; |
341 } | 341 } |
342 | 342 |
343 // Shrink the vector back down so we don't waste time inspecting | 343 // Shrink the vector back down so we don't waste time inspecting |
344 // empty LRU lists on future prunes. | 344 // empty LRU lists on future prunes. |
345 if (m_allResources[i].m_head) | 345 if (m_allResources[i].m_head) |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 // The object must now be moved to a different queue, since either its size
or its accessCount has been changed, | 538 // The object must now be moved to a different queue, since either its size
or its accessCount has been changed, |
539 // and both of those are used to determine which LRU queue the resource shou
ld be in. | 539 // and both of those are used to determine which LRU queue the resource shou
ld be in. |
540 if (oldSize) | 540 if (oldSize) |
541 removeFromLRUList(entry, lruListFor(entry->m_accessCount, oldSize)); | 541 removeFromLRUList(entry, lruListFor(entry->m_accessCount, oldSize)); |
542 if (wasAccessed) | 542 if (wasAccessed) |
543 entry->m_accessCount++; | 543 entry->m_accessCount++; |
544 if (newSize) | 544 if (newSize) |
545 insertInLRUList(entry, lruListFor(entry->m_accessCount, newSize)); | 545 insertInLRUList(entry, lruListFor(entry->m_accessCount, newSize)); |
546 | 546 |
547 ptrdiff_t delta = newSize - oldSize; | 547 ptrdiff_t delta = newSize - oldSize; |
548 if (resource->hasClientsOrObservers()) { | 548 if (resource->isAlive()) { |
549 ASSERT(delta >= 0 || m_liveSize >= static_cast<size_t>(-delta) ); | 549 ASSERT(delta >= 0 || m_liveSize >= static_cast<size_t>(-delta) ); |
550 m_liveSize += delta; | 550 m_liveSize += delta; |
551 } else { | 551 } else { |
552 ASSERT(delta >= 0 || m_deadSize >= static_cast<size_t>(-delta) ); | 552 ASSERT(delta >= 0 || m_deadSize >= static_cast<size_t>(-delta) ); |
553 m_deadSize += delta; | 553 m_deadSize += delta; |
554 } | 554 } |
555 } | 555 } |
556 | 556 |
557 void MemoryCache::updateDecodedResource(Resource* resource, UpdateReason reason) | 557 void MemoryCache::updateDecodedResource(Resource* resource, UpdateReason reason) |
558 { | 558 { |
559 MemoryCacheEntry* entry = getEntryForResource(resource); | 559 MemoryCacheEntry* entry = getEntryForResource(resource); |
560 if (!entry) | 560 if (!entry) |
561 return; | 561 return; |
562 | 562 |
563 removeFromLiveDecodedResourcesList(entry); | 563 removeFromLiveDecodedResourcesList(entry); |
564 if (resource->decodedSize() && resource->hasClientsOrObservers()) | 564 if (resource->decodedSize() && resource->isAlive()) |
565 insertInLiveDecodedResourcesList(entry); | 565 insertInLiveDecodedResourcesList(entry); |
566 | 566 |
567 if (reason != UpdateForAccess) | 567 if (reason != UpdateForAccess) |
568 return; | 568 return; |
569 | 569 |
570 double timestamp = resource->isImage() ? m_lastFramePaintTimeStamp : 0.0; | 570 double timestamp = resource->isImage() ? m_lastFramePaintTimeStamp : 0.0; |
571 if (!timestamp) | 571 if (!timestamp) |
572 timestamp = currentTime(); | 572 timestamp = currentTime(); |
573 entry->m_lastDecodedAccessTime = timestamp; | 573 entry->m_lastDecodedAccessTime = timestamp; |
574 } | 574 } |
575 | 575 |
576 void MemoryCache::removeURLFromCache(const KURL& url) | 576 void MemoryCache::removeURLFromCache(const KURL& url) |
577 { | 577 { |
578 HeapVector<Member<Resource>> resources = resourcesForURL(url); | 578 HeapVector<Member<Resource>> resources = resourcesForURL(url); |
579 for (Resource* resource : resources) | 579 for (Resource* resource : resources) |
580 memoryCache()->remove(resource); | 580 memoryCache()->remove(resource); |
581 } | 581 } |
582 | 582 |
583 void MemoryCache::TypeStatistic::addResource(Resource* o) | 583 void MemoryCache::TypeStatistic::addResource(Resource* o) |
584 { | 584 { |
585 count++; | 585 count++; |
586 size += o->size(); | 586 size += o->size(); |
587 liveSize += o->hasClientsOrObservers() ? o->size() : 0; | 587 liveSize += o->isAlive() ? o->size() : 0; |
588 decodedSize += o->decodedSize(); | 588 decodedSize += o->decodedSize(); |
589 encodedSize += o->encodedSize(); | 589 encodedSize += o->encodedSize(); |
590 encodedSizeDuplicatedInDataURLs += o->url().protocolIsData() ? o->encodedSiz
e() : 0; | 590 encodedSizeDuplicatedInDataURLs += o->url().protocolIsData() ? o->encodedSiz
e() : 0; |
591 } | 591 } |
592 | 592 |
593 MemoryCache::Statistics MemoryCache::getStatistics() | 593 MemoryCache::Statistics MemoryCache::getStatistics() |
594 { | 594 { |
595 Statistics stats; | 595 Statistics stats; |
596 for (const auto& resourceMapIter : m_resourceMaps) { | 596 for (const auto& resourceMapIter : m_resourceMaps) { |
597 for (const auto& resourceIter : *resourceMapIter.value) { | 597 for (const auto& resourceIter : *resourceMapIter.value) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 void MemoryCache::dumpLRULists(bool includeLive) const | 773 void MemoryCache::dumpLRULists(bool includeLive) const |
774 { | 774 { |
775 printf("LRU-SP lists in eviction order (Kilobytes decoded, Kilobytes encoded
, Access count, Referenced, isPurgeable):\n"); | 775 printf("LRU-SP lists in eviction order (Kilobytes decoded, Kilobytes encoded
, Access count, Referenced, isPurgeable):\n"); |
776 | 776 |
777 int size = m_allResources.size(); | 777 int size = m_allResources.size(); |
778 for (int i = size - 1; i >= 0; i--) { | 778 for (int i = size - 1; i >= 0; i--) { |
779 printf("\n\nList %d: ", i); | 779 printf("\n\nList %d: ", i); |
780 MemoryCacheEntry* current = m_allResources[i].m_tail; | 780 MemoryCacheEntry* current = m_allResources[i].m_tail; |
781 while (current) { | 781 while (current) { |
782 Resource* currentResource = current->resource(); | 782 Resource* currentResource = current->resource(); |
783 if (includeLive || !currentResource->hasClientsOrObservers()) | 783 if (includeLive || !currentResource->isAlive()) |
784 printf("(%.1fK, %.1fK, %uA, %dR); ", currentResource->decodedSiz
e() / 1024.0f, (currentResource->encodedSize() + currentResource->overheadSize()
) / 1024.0f, current->m_accessCount, currentResource->hasClientsOrObservers()); | 784 printf("(%.1fK, %.1fK, %uA, %dR); ", currentResource->decodedSiz
e() / 1024.0f, (currentResource->encodedSize() + currentResource->overheadSize()
) / 1024.0f, current->m_accessCount, currentResource->isAlive()); |
785 | 785 |
786 current = current->m_previousInAllResourcesList; | 786 current = current->m_previousInAllResourcesList; |
787 } | 787 } |
788 } | 788 } |
789 } | 789 } |
790 | 790 |
791 #endif // MEMORY_CACHE_STATS | 791 #endif // MEMORY_CACHE_STATS |
792 | 792 |
793 } // namespace blink | 793 } // namespace blink |
OLD | NEW |