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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 { | 179 { |
180 if (m_inPruneResources) | 180 if (m_inPruneResources) |
181 return; | 181 return; |
182 TemporaryChange<bool> reentrancyProtector(m_inPruneResources, true); | 182 TemporaryChange<bool> reentrancyProtector(m_inPruneResources, true); |
183 | 183 |
184 double currentTime = FrameView::currentPaintTimeStamp(); | 184 double currentTime = FrameView::currentPaintTimeStamp(); |
185 if (!currentTime) // In case prune is called directly, outside of a Frame pa int. | 185 if (!currentTime) // In case prune is called directly, outside of a Frame pa int. |
186 currentTime = WTF::currentTime(); | 186 currentTime = WTF::currentTime(); |
187 | 187 |
188 // Destroy any decoded data in live objects that we can. | 188 // Destroy any decoded data in live objects that we can. |
189 // Start from the tail, since this is the least recently accessed of the obj ects. | 189 // Start from the tail, since this is the lowest priority |
190 // and least recently accessed of the objects. | |
190 | 191 |
191 // The list might not be sorted by the m_lastDecodedAccessTime. The impact | 192 // The list might not be sorted by the m_lastDecodedAccessTime. The impact |
192 // of this weaker invariant is minor as the below if statement to check the | 193 // of this weaker invariant is minor as the below if statement to check the |
193 // elapsedTime will evaluate to false as the currentTime will be a lot | 194 // elapsedTime will evaluate to false as the currentTime will be a lot |
194 // greater than the current->m_lastDecodedAccessTime. | 195 // greater than the current->m_lastDecodedAccessTime. |
195 // For more details see: https://bugs.webkit.org/show_bug.cgi?id=30209 | 196 // For more details see: https://bugs.webkit.org/show_bug.cgi?id=30209 |
196 CachedResource* current = m_liveDecodedResources.m_tail; | 197 CachedResource* current = m_liveDecodedResources.m_tail; |
197 while (current) { | 198 while (current) { |
198 CachedResource* prev = current->m_prevInLiveResourcesList; | 199 CachedResource* prev = current->m_prevInLiveResourcesList; |
199 ASSERT(current->hasClients()); | 200 ASSERT(current->hasClients()); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 else if (m_liveDecodedResources.m_head == resource) | 471 else if (m_liveDecodedResources.m_head == resource) |
471 m_liveDecodedResources.m_head = next; | 472 m_liveDecodedResources.m_head = next; |
472 } | 473 } |
473 | 474 |
474 void MemoryCache::insertInLiveDecodedResourcesList(CachedResource* resource) | 475 void MemoryCache::insertInLiveDecodedResourcesList(CachedResource* resource) |
475 { | 476 { |
476 // Make sure we aren't in the list already. | 477 // Make sure we aren't in the list already. |
477 ASSERT(!resource->m_nextInLiveResourcesList && !resource->m_prevInLiveResour cesList && !resource->m_inLiveDecodedResourcesList); | 478 ASSERT(!resource->m_nextInLiveResourcesList && !resource->m_prevInLiveResour cesList && !resource->m_inLiveDecodedResourcesList); |
478 resource->m_inLiveDecodedResourcesList = true; | 479 resource->m_inLiveDecodedResourcesList = true; |
479 | 480 |
480 resource->m_nextInLiveResourcesList = m_liveDecodedResources.m_head; | 481 bool inserted = false; |
481 if (m_liveDecodedResources.m_head) | 482 for (CachedResource* next = m_liveDecodedResources.m_head; next; next = next ->m_nextInLiveResourcesList) { |
Justin Novosad
2013/07/19 21:09:53
This algorithm is not good, you are making success
| |
482 m_liveDecodedResources.m_head->m_prevInLiveResourcesList = resource; | 483 // Insert here if the next item is of the same or lower priority |
483 m_liveDecodedResources.m_head = resource; | 484 // TODO: make this more efficient by storing separate lists for each pri ority |
484 | 485 if (resource->decodeCachePriority() >= next->decodeCachePriority()) { |
485 if (!resource->m_nextInLiveResourcesList) | 486 if (CachedResource* prev = next->m_prevInLiveResourcesList) { |
487 prev->m_nextInLiveResourcesList = resource; | |
488 resource->m_prevInLiveResourcesList = prev; | |
489 } | |
490 resource->m_nextInLiveResourcesList = next; | |
491 next->m_prevInLiveResourcesList = resource; | |
492 | |
493 if (next == m_liveDecodedResources.m_head) | |
494 m_liveDecodedResources.m_head = resource; | |
495 | |
496 inserted = true; | |
497 break; | |
498 } | |
499 } | |
500 if (!inserted) { | |
501 // The new resource should become the tail | |
502 if (m_liveDecodedResources.m_tail) { | |
503 resource->m_prevInLiveResourcesList = m_liveDecodedResources.m_tail; | |
504 m_liveDecodedResources.m_tail->m_nextInLiveResourcesList = resource; | |
505 } | |
486 m_liveDecodedResources.m_tail = resource; | 506 m_liveDecodedResources.m_tail = resource; |
487 | 507 if (!m_liveDecodedResources.m_head) { |
508 m_liveDecodedResources.m_head = resource; | |
509 } | |
510 } | |
511 | |
488 #if !ASSERT_DISABLED | 512 #if !ASSERT_DISABLED |
513 // Verify that we are in the correct position in the list according to our d ecodeCachePriority. | |
514 ASSERT(!resource->m_nextInLiveResourcesList || resource->decodeCachePriority () >= resource->m_nextInLiveResourcesList->decodeCachePriority()); | |
515 ASSERT(!resource->m_prevInLiveResourcesList || resource->decodeCachePriority () <= resource->m_prevInLiveResourcesList->decodeCachePriority()); | |
516 | |
489 // Verify that we are in now in the list like we should be. | 517 // Verify that we are in now in the list like we should be. |
490 bool found = false; | 518 bool found = false; |
491 for (CachedResource* current = m_liveDecodedResources.m_head; current; curre nt = current->m_nextInLiveResourcesList) { | 519 for (CachedResource* current = m_liveDecodedResources.m_head; current; curre nt = current->m_nextInLiveResourcesList) { |
492 if (current == resource) { | 520 if (current == resource) { |
493 found = true; | 521 found = true; |
494 break; | 522 break; |
495 } | 523 } |
496 } | 524 } |
497 ASSERT(found); | 525 ASSERT(found); |
498 #endif | 526 #endif |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 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()); | 686 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()); |
659 | 687 |
660 current = prev; | 688 current = prev; |
661 } | 689 } |
662 } | 690 } |
663 } | 691 } |
664 | 692 |
665 #endif // MEMORY_CACHE_STATS | 693 #endif // MEMORY_CACHE_STATS |
666 | 694 |
667 } // namespace WebCore | 695 } // namespace WebCore |
OLD | NEW |