| 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. |
| 11 | 11 |
| 12 This library is distributed in the hope that it will be useful, | 12 This library is distributed in the hope that it will be useful, |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 Library General Public License for more details. | 15 Library General Public License for more details. |
| 16 | 16 |
| 17 You should have received a copy of the GNU Library General Public License | 17 You should have received a copy of the GNU Library General Public License |
| 18 along with this library; see the file COPYING.LIB. If not, write to | 18 along with this library; see the file COPYING.LIB. If not, write to |
| 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 Boston, MA 02110-1301, USA. | 20 Boston, MA 02110-1301, USA. |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "core/fetch/MemoryCache.h" | 23 #include "core/fetch/MemoryCache.h" |
| 24 | 24 |
| 25 #include "core/fetch/ResourcePtr.h" | |
| 26 #include "core/fetch/WebCacheMemoryDumpProvider.h" | 25 #include "core/fetch/WebCacheMemoryDumpProvider.h" |
| 27 #include "platform/Logging.h" | 26 #include "platform/Logging.h" |
| 28 #include "platform/TraceEvent.h" | 27 #include "platform/TraceEvent.h" |
| 29 #include "platform/weborigin/SecurityOrigin.h" | 28 #include "platform/weborigin/SecurityOrigin.h" |
| 30 #include "platform/weborigin/SecurityOriginHash.h" | 29 #include "platform/weborigin/SecurityOriginHash.h" |
| 31 #include "public/platform/Platform.h" | 30 #include "public/platform/Platform.h" |
| 32 #include "wtf/Assertions.h" | 31 #include "wtf/Assertions.h" |
| 33 #include "wtf/CurrentTime.h" | 32 #include "wtf/CurrentTime.h" |
| 34 #include "wtf/MainThread.h" | 33 #include "wtf/MainThread.h" |
| 35 #include "wtf/MathExtras.h" | 34 #include "wtf/MathExtras.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 49 MemoryCache* memoryCache() | 48 MemoryCache* memoryCache() |
| 50 { | 49 { |
| 51 ASSERT(WTF::isMainThread()); | 50 ASSERT(WTF::isMainThread()); |
| 52 if (!gMemoryCache) | 51 if (!gMemoryCache) |
| 53 gMemoryCache = new Persistent<MemoryCache>(MemoryCache::create()); | 52 gMemoryCache = new Persistent<MemoryCache>(MemoryCache::create()); |
| 54 return gMemoryCache->get(); | 53 return gMemoryCache->get(); |
| 55 } | 54 } |
| 56 | 55 |
| 57 MemoryCache* replaceMemoryCacheForTesting(MemoryCache* cache) | 56 MemoryCache* replaceMemoryCacheForTesting(MemoryCache* cache) |
| 58 { | 57 { |
| 59 #if ENABLE(OILPAN) | |
| 60 // Move m_liveResources content to keep Resource objects alive. | |
| 61 for (const auto& resource : memoryCache()->m_liveResources) | |
| 62 cache->m_liveResources.add(resource); | |
| 63 memoryCache()->m_liveResources.clear(); | |
| 64 #endif | |
| 65 memoryCache(); | 58 memoryCache(); |
| 66 MemoryCache* oldCache = gMemoryCache->release(); | 59 MemoryCache* oldCache = gMemoryCache->release(); |
| 67 *gMemoryCache = cache; | 60 *gMemoryCache = cache; |
| 68 WebCacheMemoryDumpProvider::instance()->setMemoryCache(cache); | 61 WebCacheMemoryDumpProvider::instance()->setMemoryCache(cache); |
| 69 return oldCache; | 62 return oldCache; |
| 70 } | 63 } |
| 71 | 64 |
| 72 DEFINE_TRACE(MemoryCacheEntry) | 65 DEFINE_TRACE(MemoryCacheEntry) |
| 73 { | 66 { |
| 67 visitor->trace(m_resource); |
| 74 visitor->trace(m_previousInLiveResourcesList); | 68 visitor->trace(m_previousInLiveResourcesList); |
| 75 visitor->trace(m_nextInLiveResourcesList); | 69 visitor->trace(m_nextInLiveResourcesList); |
| 76 visitor->trace(m_previousInAllResourcesList); | 70 visitor->trace(m_previousInAllResourcesList); |
| 77 visitor->trace(m_nextInAllResourcesList); | 71 visitor->trace(m_nextInAllResourcesList); |
| 78 } | 72 } |
| 79 | 73 |
| 80 void MemoryCacheEntry::dispose() | 74 void MemoryCacheEntry::dispose() |
| 81 { | 75 { |
| 76 m_resource->removedFromMemoryCache(); |
| 82 m_resource.clear(); | 77 m_resource.clear(); |
| 83 } | 78 } |
| 84 | 79 |
| 85 DEFINE_TRACE(MemoryCacheLRUList) | 80 DEFINE_TRACE(MemoryCacheLRUList) |
| 86 { | 81 { |
| 87 visitor->trace(m_head); | 82 visitor->trace(m_head); |
| 88 visitor->trace(m_tail); | 83 visitor->trace(m_tail); |
| 89 } | 84 } |
| 90 | 85 |
| 91 inline MemoryCache::MemoryCache() | 86 inline MemoryCache::MemoryCache() |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 if (m_prunePending) | 118 if (m_prunePending) |
| 124 Platform::current()->currentThread()->removeTaskObserver(this); | 119 Platform::current()->currentThread()->removeTaskObserver(this); |
| 125 } | 120 } |
| 126 | 121 |
| 127 DEFINE_TRACE(MemoryCache) | 122 DEFINE_TRACE(MemoryCache) |
| 128 { | 123 { |
| 129 visitor->trace(m_allResources); | 124 visitor->trace(m_allResources); |
| 130 for (size_t i = 0; i < WTF_ARRAY_LENGTH(m_liveDecodedResources); ++i) | 125 for (size_t i = 0; i < WTF_ARRAY_LENGTH(m_liveDecodedResources); ++i) |
| 131 visitor->trace(m_liveDecodedResources[i]); | 126 visitor->trace(m_liveDecodedResources[i]); |
| 132 visitor->trace(m_resourceMaps); | 127 visitor->trace(m_resourceMaps); |
| 133 #if ENABLE(OILPAN) | |
| 134 visitor->trace(m_liveResources); | |
| 135 #endif | |
| 136 } | 128 } |
| 137 | 129 |
| 138 KURL MemoryCache::removeFragmentIdentifierIfNeeded(const KURL& originalURL) | 130 KURL MemoryCache::removeFragmentIdentifierIfNeeded(const KURL& originalURL) |
| 139 { | 131 { |
| 140 if (!originalURL.hasFragmentIdentifier()) | 132 if (!originalURL.hasFragmentIdentifier()) |
| 141 return originalURL; | 133 return originalURL; |
| 142 // Strip away fragment identifier from HTTP URLs. | 134 // Strip away fragment identifier from HTTP URLs. |
| 143 // Data URLs must be unmodified. For file and custom URLs clients may expect
resources | 135 // Data URLs must be unmodified. For file and custom URLs clients may expect
resources |
| 144 // to be unique even when they differ by the fragment identifier only. | 136 // to be unique even when they differ by the fragment identifier only. |
| 145 if (!originalURL.protocolIsInHTTPFamily()) | 137 if (!originalURL.protocolIsInHTTPFamily()) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 return nullptr; | 192 return nullptr; |
| 201 ASSERT(!cacheIdentifier.isNull()); | 193 ASSERT(!cacheIdentifier.isNull()); |
| 202 ResourceMap* resources = m_resourceMaps.get(cacheIdentifier); | 194 ResourceMap* resources = m_resourceMaps.get(cacheIdentifier); |
| 203 if (!resources) | 195 if (!resources) |
| 204 return nullptr; | 196 return nullptr; |
| 205 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); | 197 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); |
| 206 MemoryCacheEntry* entry = resources->get(url); | 198 MemoryCacheEntry* entry = resources->get(url); |
| 207 if (!entry) | 199 if (!entry) |
| 208 return nullptr; | 200 return nullptr; |
| 209 Resource* resource = entry->m_resource.get(); | 201 Resource* resource = entry->m_resource.get(); |
| 210 if (resource && !resource->lock()) { | 202 if (resource && !resource->lock()) |
| 211 ASSERT(!resource->hasClients()); | |
| 212 bool didEvict = evict(entry); | |
| 213 ASSERT_UNUSED(didEvict, didEvict); | |
| 214 return nullptr; | 203 return nullptr; |
| 215 } | |
| 216 return resource; | 204 return resource; |
| 217 } | 205 } |
| 218 | 206 |
| 219 WillBeHeapVector<RawPtrWillBeMember<Resource>> MemoryCache::resourcesForURL(cons
t KURL& resourceURL) | 207 WillBeHeapVector<RawPtrWillBeMember<Resource>> MemoryCache::resourcesForURL(cons
t KURL& resourceURL) |
| 220 { | 208 { |
| 221 ASSERT(WTF::isMainThread()); | 209 ASSERT(WTF::isMainThread()); |
| 222 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); | 210 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); |
| 223 WillBeHeapVector<RawPtrWillBeMember<Resource>> results; | 211 WillBeHeapVector<RawPtrWillBeMember<Resource>> results; |
| 224 for (const auto& resourceMapIter : m_resourceMaps) { | 212 for (const auto& resourceMapIter : m_resourceMaps) { |
| 225 if (MemoryCacheEntry* entry = resourceMapIter.value->get(url)) | 213 if (MemoryCacheEntry* entry = resourceMapIter.value->get(url)) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 { | 281 { |
| 294 size_t capacity = deadCapacity(); | 282 size_t capacity = deadCapacity(); |
| 295 if (strategy == MaximalPrune) | 283 if (strategy == MaximalPrune) |
| 296 capacity = 0; | 284 capacity = 0; |
| 297 if (!m_deadSize || (capacity && m_deadSize <= capacity)) | 285 if (!m_deadSize || (capacity && m_deadSize <= capacity)) |
| 298 return; | 286 return; |
| 299 | 287 |
| 300 size_t targetSize = static_cast<size_t>(capacity * cTargetPrunePercentage);
// Cut by a percentage to avoid immediately pruning again. | 288 size_t targetSize = static_cast<size_t>(capacity * cTargetPrunePercentage);
// Cut by a percentage to avoid immediately pruning again. |
| 301 | 289 |
| 302 int size = m_allResources.size(); | 290 int size = m_allResources.size(); |
| 303 | |
| 304 // See if we have any purged resources we can evict. | |
| 305 for (int i = 0; i < size; i++) { | |
| 306 MemoryCacheEntry* current = m_allResources[i].m_tail; | |
| 307 while (current) { | |
| 308 MemoryCacheEntry* previous = current->m_previousInAllResourcesList; | |
| 309 // Main Resources in the cache are only substitue data that was | |
| 310 // precached and should not be evicted. | |
| 311 if (current->m_resource->wasPurged() && current->m_resource->canDele
te() | |
| 312 && current->m_resource->type() != Resource::MainResource) { | |
| 313 ASSERT(!current->m_resource->hasClients()); | |
| 314 ASSERT(!current->m_resource->isPreloaded()); | |
| 315 bool wasEvicted = evict(current); | |
| 316 ASSERT_UNUSED(wasEvicted, wasEvicted); | |
| 317 } | |
| 318 current = previous; | |
| 319 } | |
| 320 } | |
| 321 if (targetSize && m_deadSize <= targetSize) | 291 if (targetSize && m_deadSize <= targetSize) |
| 322 return; | 292 return; |
| 323 | 293 |
| 324 bool canShrinkLRULists = true; | 294 bool canShrinkLRULists = true; |
| 325 for (int i = size - 1; i >= 0; i--) { | 295 for (int i = size - 1; i >= 0; i--) { |
| 326 // Remove from the tail, since this is the least frequently accessed of
the objects. | 296 // Remove from the tail, since this is the least frequently accessed of
the objects. |
| 327 MemoryCacheEntry* current = m_allResources[i].m_tail; | 297 MemoryCacheEntry* current = m_allResources[i].m_tail; |
| 328 | 298 |
| 329 // First flush all the decoded data in this queue. | 299 // First flush all the decoded data in this queue. |
| 330 while (current) { | 300 while (current) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 350 } | 320 } |
| 351 | 321 |
| 352 // Now evict objects from this queue. | 322 // Now evict objects from this queue. |
| 353 current = m_allResources[i].m_tail; | 323 current = m_allResources[i].m_tail; |
| 354 while (current) { | 324 while (current) { |
| 355 MemoryCacheEntry* previous = current->m_previousInAllResourcesList; | 325 MemoryCacheEntry* previous = current->m_previousInAllResourcesList; |
| 356 if (previous) { | 326 if (previous) { |
| 357 ASSERT(previous->m_resource); | 327 ASSERT(previous->m_resource); |
| 358 ASSERT(contains(previous->m_resource.get())); | 328 ASSERT(contains(previous->m_resource.get())); |
| 359 } | 329 } |
| 360 if (!current->m_resource->hasClients() && !current->m_resource->isPr
eloaded() | 330 if (!current->m_resource->hasClients() && !current->m_resource->isPr
eloaded()) { |
| 361 && !current->m_resource->isCacheValidator() && current->m_resour
ce->canDelete() | 331 evict(current); |
| 362 && current->m_resource->type() != Resource::MainResource) { | |
| 363 // Main Resources in the cache are only substitue data that was | |
| 364 // precached and should not be evicted. | |
| 365 bool wasEvicted = evict(current); | |
| 366 ASSERT_UNUSED(wasEvicted, wasEvicted); | |
| 367 if (targetSize && m_deadSize <= targetSize) | 332 if (targetSize && m_deadSize <= targetSize) |
| 368 return; | 333 return; |
| 369 } | 334 } |
| 370 if (!previous || !previous->m_resource || !contains(previous->m_reso
urce.get())) | 335 if (!previous || !previous->m_resource || !contains(previous->m_reso
urce.get())) |
| 371 break; | 336 break; |
| 372 current = previous; | 337 current = previous; |
| 373 } | 338 } |
| 374 | 339 |
| 375 // Shrink the vector back down so we don't waste time inspecting | 340 // Shrink the vector back down so we don't waste time inspecting |
| 376 // empty LRU lists on future prunes. | 341 // empty LRU lists on future prunes. |
| 377 if (m_allResources[i].m_head) | 342 if (m_allResources[i].m_head) |
| 378 canShrinkLRULists = false; | 343 canShrinkLRULists = false; |
| 379 else if (canShrinkLRULists) | 344 else if (canShrinkLRULists) |
| 380 m_allResources.resize(i); | 345 m_allResources.resize(i); |
| 381 } | 346 } |
| 382 } | 347 } |
| 383 | 348 |
| 384 void MemoryCache::setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t
totalBytes) | 349 void MemoryCache::setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t
totalBytes) |
| 385 { | 350 { |
| 386 ASSERT(minDeadBytes <= maxDeadBytes); | 351 ASSERT(minDeadBytes <= maxDeadBytes); |
| 387 ASSERT(maxDeadBytes <= totalBytes); | 352 ASSERT(maxDeadBytes <= totalBytes); |
| 388 m_minDeadCapacity = minDeadBytes; | 353 m_minDeadCapacity = minDeadBytes; |
| 389 m_maxDeadCapacity = maxDeadBytes; | 354 m_maxDeadCapacity = maxDeadBytes; |
| 390 m_maxDeferredPruneDeadCapacity = cDeferredPruneDeadCapacityFactor * maxDeadB
ytes; | 355 m_maxDeferredPruneDeadCapacity = cDeferredPruneDeadCapacityFactor * maxDeadB
ytes; |
| 391 m_capacity = totalBytes; | 356 m_capacity = totalBytes; |
| 392 prune(); | 357 prune(); |
| 393 } | 358 } |
| 394 | 359 |
| 395 bool MemoryCache::evict(MemoryCacheEntry* entry) | 360 void MemoryCache::evict(MemoryCacheEntry* entry) |
| 396 { | 361 { |
| 397 ASSERT(WTF::isMainThread()); | 362 ASSERT(WTF::isMainThread()); |
| 398 | 363 |
| 399 Resource* resource = entry->m_resource.get(); | 364 Resource* resource = entry->m_resource.get(); |
| 400 bool canDelete = resource->canDelete(); | |
| 401 WTF_LOG(ResourceLoading, "Evicting resource %p for '%s' from cache", resourc
e, resource->url().string().latin1().data()); | 365 WTF_LOG(ResourceLoading, "Evicting resource %p for '%s' from cache", resourc
e, resource->url().string().latin1().data()); |
| 402 // The resource may have already been removed by someone other than our call
er, | 366 // The resource may have already been removed by someone other than our call
er, |
| 403 // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bu
g.cgi?id=12479#c6>. | 367 // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bu
g.cgi?id=12479#c6>. |
| 404 update(resource, resource->size(), 0, false); | 368 update(resource, resource->size(), 0, false); |
| 405 removeFromLiveDecodedResourcesList(entry); | 369 removeFromLiveDecodedResourcesList(entry); |
| 406 | 370 |
| 407 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); | 371 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); |
| 408 ASSERT(resources); | 372 ASSERT(resources); |
| 409 ResourceMap::iterator it = resources->find(resource->url()); | 373 ResourceMap::iterator it = resources->find(resource->url()); |
| 410 ASSERT(it != resources->end()); | 374 ASSERT(it != resources->end()); |
| 411 | 375 |
| 412 MemoryCacheEntry* entryPtr = it->value; | 376 MemoryCacheEntry* entryPtr = it->value; |
| 413 resources->remove(it); | 377 resources->remove(it); |
| 414 if (entryPtr) | 378 if (entryPtr) |
| 415 entryPtr->dispose(); | 379 entryPtr->dispose(); |
| 416 | |
| 417 return canDelete; | |
| 418 } | 380 } |
| 419 | 381 |
| 420 MemoryCacheEntry* MemoryCache::getEntryForResource(const Resource* resource) con
st | 382 MemoryCacheEntry* MemoryCache::getEntryForResource(const Resource* resource) con
st |
| 421 { | 383 { |
| 422 if (resource->url().isNull() || resource->url().isEmpty()) | 384 if (resource->url().isNull() || resource->url().isEmpty()) |
| 423 return nullptr; | 385 return nullptr; |
| 424 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); | 386 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); |
| 425 if (!resources) | 387 if (!resources) |
| 426 return nullptr; | 388 return nullptr; |
| 427 MemoryCacheEntry* entry = resources->get(resource->url()); | 389 MemoryCacheEntry* entry = resources->get(resource->url()); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 583 |
| 622 void MemoryCache::removeURLFromCache(const KURL& url) | 584 void MemoryCache::removeURLFromCache(const KURL& url) |
| 623 { | 585 { |
| 624 WillBeHeapVector<RawPtrWillBeMember<Resource>> resources = resourcesForURL(u
rl); | 586 WillBeHeapVector<RawPtrWillBeMember<Resource>> resources = resourcesForURL(u
rl); |
| 625 for (Resource* resource : resources) | 587 for (Resource* resource : resources) |
| 626 memoryCache()->remove(resource); | 588 memoryCache()->remove(resource); |
| 627 } | 589 } |
| 628 | 590 |
| 629 void MemoryCache::TypeStatistic::addResource(Resource* o) | 591 void MemoryCache::TypeStatistic::addResource(Resource* o) |
| 630 { | 592 { |
| 631 bool purged = o->wasPurged(); | 593 bool purgeable = o->isPurgeable(); |
| 632 bool purgeable = o->isPurgeable() && !purged; | |
| 633 size_t pageSize = (o->encodedSize() + o->overheadSize() + 4095) & ~4095; | 594 size_t pageSize = (o->encodedSize() + o->overheadSize() + 4095) & ~4095; |
| 634 count++; | 595 count++; |
| 635 size += purged ? 0 : o->size(); | 596 size += o->size(); |
| 636 liveSize += o->hasClients() ? o->size() : 0; | 597 liveSize += o->hasClients() ? o->size() : 0; |
| 637 decodedSize += o->decodedSize(); | 598 decodedSize += o->decodedSize(); |
| 638 encodedSize += o->encodedSize(); | 599 encodedSize += o->encodedSize(); |
| 639 encodedSizeDuplicatedInDataURLs += o->url().protocolIsData() ? o->encodedSiz
e() : 0; | 600 encodedSizeDuplicatedInDataURLs += o->url().protocolIsData() ? o->encodedSiz
e() : 0; |
| 640 purgeableSize += purgeable ? pageSize : 0; | 601 purgeableSize += purgeable ? pageSize : 0; |
| 641 purgedSize += purged ? pageSize : 0; | |
| 642 } | 602 } |
| 643 | 603 |
| 644 MemoryCache::Statistics MemoryCache::getStatistics() | 604 MemoryCache::Statistics MemoryCache::getStatistics() |
| 645 { | 605 { |
| 646 Statistics stats; | 606 Statistics stats; |
| 647 for (const auto& resourceMapIter : m_resourceMaps) { | 607 for (const auto& resourceMapIter : m_resourceMaps) { |
| 648 for (const auto& resourceIter : *resourceMapIter.value) { | 608 for (const auto& resourceIter : *resourceMapIter.value) { |
| 649 Resource* resource = resourceIter.value->m_resource.get(); | 609 Resource* resource = resourceIter.value->m_resource.get(); |
| 650 switch (resource->type()) { | 610 switch (resource->type()) { |
| 651 case Resource::Image: | 611 case Resource::Image: |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 | 748 |
| 789 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y) | 749 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y) |
| 790 { | 750 { |
| 791 MemoryCacheEntry* ex = getEntryForResource(x); | 751 MemoryCacheEntry* ex = getEntryForResource(x); |
| 792 MemoryCacheEntry* ey = getEntryForResource(y); | 752 MemoryCacheEntry* ey = getEntryForResource(y); |
| 793 ASSERT(ex); | 753 ASSERT(ex); |
| 794 ASSERT(ey); | 754 ASSERT(ey); |
| 795 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo
unt, y->size()); | 755 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo
unt, y->size()); |
| 796 } | 756 } |
| 797 | 757 |
| 798 void MemoryCache::registerLiveResource(Resource& resource) | |
| 799 { | |
| 800 #if ENABLE(OILPAN) | |
| 801 ASSERT(!m_liveResources.contains(&resource)); | |
| 802 m_liveResources.add(&resource); | |
| 803 #endif | |
| 804 } | |
| 805 | |
| 806 void MemoryCache::unregisterLiveResource(Resource& resource) | |
| 807 { | |
| 808 #if ENABLE(OILPAN) | |
| 809 ASSERT(m_liveResources.contains(&resource)); | |
| 810 m_liveResources.remove(&resource); | |
| 811 #endif | |
| 812 } | |
| 813 | |
| 814 #ifdef MEMORY_CACHE_STATS | 758 #ifdef MEMORY_CACHE_STATS |
| 815 | 759 |
| 816 void MemoryCache::dumpStats(Timer<MemoryCache>*) | 760 void MemoryCache::dumpStats(Timer<MemoryCache>*) |
| 817 { | 761 { |
| 818 Statistics s = getStatistics(); | 762 Statistics s = getStatistics(); |
| 819 printf("%-13s %-13s %-13s %-13s %-13s %-13s %-13s\n", "", "Count", "Size", "
LiveSize", "DecodedSize", "PurgeableSize", "PurgedSize"); | 763 printf("%-13s %-13s %-13s %-13s %-13s %-13s %-13s\n", "", "Count", "Size", "
LiveSize", "DecodedSize", "PurgeableSize", "PurgedSize"); |
| 820 printf("%-13s %-13s %-13s %-13s %-13s %-13s %-13s\n", "-------------", "----
---------", "-------------", "-------------", "-------------", "-------------",
"-------------"); | 764 printf("%-13s %-13s %-13s %-13s %-13s %-13s %-13s\n", "-------------", "----
---------", "-------------", "-------------", "-------------", "-------------",
"-------------"); |
| 821 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "Images", s.images.count, s.
images.size, s.images.liveSize, s.images.decodedSize, s.images.purgeableSize, s.
images.purgedSize); | 765 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "Images", s.images.count, s.
images.size, s.images.liveSize, s.images.decodedSize, s.images.purgeableSize, s.
images.purgedSize); |
| 822 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "CSS", s.cssStyleSheets.coun
t, s.cssStyleSheets.size, s.cssStyleSheets.liveSize, s.cssStyleSheets.decodedSiz
e, s.cssStyleSheets.purgeableSize, s.cssStyleSheets.purgedSize); | 766 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "CSS", s.cssStyleSheets.coun
t, s.cssStyleSheets.size, s.cssStyleSheets.liveSize, s.cssStyleSheets.decodedSiz
e, s.cssStyleSheets.purgeableSize, s.cssStyleSheets.purgedSize); |
| 823 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "XSL", s.xslStyleSheets.coun
t, s.xslStyleSheets.size, s.xslStyleSheets.liveSize, s.xslStyleSheets.decodedSiz
e, s.xslStyleSheets.purgeableSize, s.xslStyleSheets.purgedSize); | 767 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "XSL", s.xslStyleSheets.coun
t, s.xslStyleSheets.size, s.xslStyleSheets.liveSize, s.xslStyleSheets.decodedSiz
e, s.xslStyleSheets.purgeableSize, s.xslStyleSheets.purgedSize); |
| 824 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "JavaScript", s.scripts.coun
t, s.scripts.size, s.scripts.liveSize, s.scripts.decodedSize, s.scripts.purgeabl
eSize, s.scripts.purgedSize); | 768 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "JavaScript", s.scripts.coun
t, s.scripts.size, s.scripts.liveSize, s.scripts.decodedSize, s.scripts.purgeabl
eSize, s.scripts.purgedSize); |
| 825 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "Fonts", s.fonts.count, s.fo
nts.size, s.fonts.liveSize, s.fonts.decodedSize, s.fonts.purgeableSize, s.fonts.
purgedSize); | 769 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "Fonts", s.fonts.count, s.fo
nts.size, s.fonts.liveSize, s.fonts.decodedSize, s.fonts.purgeableSize, s.fonts.
purgedSize); |
| 826 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "Other", s.other.count, s.ot
her.size, s.other.liveSize, s.other.decodedSize, s.other.purgeableSize, s.other.
purgedSize); | 770 printf("%-13s %13d %13d %13d %13d %13d %13d\n", "Other", s.other.count, s.ot
her.size, s.other.liveSize, s.other.decodedSize, s.other.purgeableSize, s.other.
purgedSize); |
| 827 printf("%-13s %-13s %-13s %-13s %-13s %-13s %-13s\n\n", "-------------", "--
-----------", "-------------", "-------------", "-------------", "-------------"
, "-------------"); | 771 printf("%-13s %-13s %-13s %-13s %-13s %-13s %-13s\n\n", "-------------", "--
-----------", "-------------", "-------------", "-------------", "-------------"
, "-------------"); |
| 828 | 772 |
| 829 printf("Duplication of encoded data from data URLs\n"); | 773 printf("Duplication of encoded data from data URLs\n"); |
| 830 printf("%-13s %13d of %13d\n", "Images", s.images.encodedSizeDuplicatedI
nDataURLs, s.images.encodedSize); | 774 printf("%-13s %13d of %13d\n", "Images", s.images.encodedSizeDuplicatedI
nDataURLs, s.images.encodedSize); |
| 831 printf("%-13s %13d of %13d\n", "CSS", s.cssStyleSheets.encodedSizeDup
licatedInDataURLs, s.cssStyleSheets.encodedSize); | 775 printf("%-13s %13d of %13d\n", "CSS", s.cssStyleSheets.encodedSizeDup
licatedInDataURLs, s.cssStyleSheets.encodedSize); |
| 832 printf("%-13s %13d of %13d\n", "XSL", s.xslStyleSheets.encodedSizeDup
licatedInDataURLs, s.xslStyleSheets.encodedSize); | 776 printf("%-13s %13d of %13d\n", "XSL", s.xslStyleSheets.encodedSizeDup
licatedInDataURLs, s.xslStyleSheets.encodedSize); |
| 833 printf("%-13s %13d of %13d\n", "JavaScript", s.scripts.encodedSizeDuplicated
InDataURLs, s.scripts.encodedSize); | 777 printf("%-13s %13d of %13d\n", "JavaScript", s.scripts.encodedSizeDuplicated
InDataURLs, s.scripts.encodedSize); |
| 834 printf("%-13s %13d of %13d\n", "Fonts", s.fonts.encodedSizeDuplicatedIn
DataURLs, s.fonts.encodedSize); | 778 printf("%-13s %13d of %13d\n", "Fonts", s.fonts.encodedSizeDuplicatedIn
DataURLs, s.fonts.encodedSize); |
| 835 printf("%-13s %13d of %13d\n", "Other", s.other.encodedSizeDuplicatedIn
DataURLs, s.other.encodedSize); | 779 printf("%-13s %13d of %13d\n", "Other", s.other.encodedSizeDuplicatedIn
DataURLs, s.other.encodedSize); |
| 836 } | 780 } |
| 837 | 781 |
| 838 void MemoryCache::dumpLRULists(bool includeLive) const | 782 void MemoryCache::dumpLRULists(bool includeLive) const |
| 839 { | 783 { |
| 840 printf("LRU-SP lists in eviction order (Kilobytes decoded, Kilobytes encoded
, Access count, Referenced, isPurgeable, wasPurged):\n"); | 784 printf("LRU-SP lists in eviction order (Kilobytes decoded, Kilobytes encoded
, Access count, Referenced, isPurgeable):\n"); |
| 841 | 785 |
| 842 int size = m_allResources.size(); | 786 int size = m_allResources.size(); |
| 843 for (int i = size - 1; i >= 0; i--) { | 787 for (int i = size - 1; i >= 0; i--) { |
| 844 printf("\n\nList %d: ", i); | 788 printf("\n\nList %d: ", i); |
| 845 MemoryCacheEntry* current = m_allResources[i].m_tail; | 789 MemoryCacheEntry* current = m_allResources[i].m_tail; |
| 846 while (current) { | 790 while (current) { |
| 847 ResourcePtr<Resource> currentResource = current->m_resource; | 791 RefPtrWillBeRawPtr<Resource> currentResource = current->m_resource; |
| 848 if (includeLive || !currentResource->hasClients()) | 792 if (includeLive || !currentResource->hasClients()) |
| 849 printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", currentResource->de
codedSize() / 1024.0f, (currentResource->encodedSize() + currentResource->overhe
adSize()) / 1024.0f, current->m_accessCount, currentResource->hasClients(), curr
entResource->isPurgeable(), currentResource->wasPurged()); | 793 printf("(%.1fK, %.1fK, %uA, %dR, %d); ", currentResource->decode
dSize() / 1024.0f, (currentResource->encodedSize() + currentResource->overheadSi
ze()) / 1024.0f, current->m_accessCount, currentResource->hasClients(), currentR
esource->isPurgeable()); |
| 850 | 794 |
| 851 current = current->m_previousInAllResourcesList; | 795 current = current->m_previousInAllResourcesList; |
| 852 } | 796 } |
| 853 } | 797 } |
| 854 } | 798 } |
| 855 | 799 |
| 856 #endif // MEMORY_CACHE_STATS | 800 #endif // MEMORY_CACHE_STATS |
| 857 | 801 |
| 858 } // namespace blink | 802 } // namespace blink |
| OLD | NEW |