2010-11-04 Pratik Solanki <psolanki@apple.com>

        Reviewed by Darin Adler.

        Should make use of purge priorities for different resource types
        https://bugs.webkit.org/show_bug.cgi?id=48684

        Assign purge priorities to CachedResource objects. JavaScript and CSS stylesheets are more
        important than images so hint to the kernel to purge them last. We do this by repurposing
        the previously unused function, PurgeableBuffer::setPurgePriority(). It now just sets the
        priority field and does not have side-effects like calling makePurgeable(true).

        Also, remove unusued PurgeableBuffer::create(const Vector<char>&) function and move the
        purgeable memory size threshold from CachedResource to PurgeableBuffer.

        * WebCore.xcodeproj/project.pbxproj: Add new PurgePriority.h header and mark it as private
        header.
        * loader/CachedCSSStyleSheet.h:
        (WebCore::CachedCSSStyleSheet::purgePriority):
        * loader/CachedImage.h:
        (WebCore::CachedImage::purgePriority):
        * loader/CachedResource.cpp:
        (WebCore::CachedResource::makePurgeable): Set the purge priority on the PurgeableBffer.
        Also, move the check for purgeable size threshold to PurgeableBuffer.
        * loader/CachedResource.h:
        (WebCore::CachedResource::purgePriority): Added. New virtual method that lets the class
        specify its purge priority.
        * loader/CachedScript.h:
        (WebCore::CachedScript::purgePriority):
        * platform/PurgePriority.h: Added. Move the PurgePriority enum from PurgeableBuffer class to
        its own header file.
        (WebCore::):
        * platform/PurgeableBuffer.h:
        (WebCore::PurgeableBuffer::setPurgePriority): Update this previously unused function to just
        set the priority and not call makePurgeable(true).
        * platform/mac/PurgeableBufferMac.cpp: Update size threshold to 16KB which is what
        CachedResource was using.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@71318 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ddb6d570
2010-11-04 Pratik Solanki <psolanki@apple.com>
Reviewed by Darin Adler.
Should make use of purge priorities for different resource types
https://bugs.webkit.org/show_bug.cgi?id=48684
Assign purge priorities to CachedResource objects. JavaScript and CSS stylesheets are more
important than images so hint to the kernel to purge them last. We do this by repurposing
the previously unused function, PurgeableBuffer::setPurgePriority(). It now just sets the
priority field and does not have side-effects like calling makePurgeable(true).
Also, remove unusued PurgeableBuffer::create(const Vector<char>&) function and move the
purgeable memory size threshold from CachedResource to PurgeableBuffer.
* WebCore.xcodeproj/project.pbxproj: Add new PurgePriority.h header and mark it as private
header.
* loader/CachedCSSStyleSheet.h:
(WebCore::CachedCSSStyleSheet::purgePriority):
* loader/CachedImage.h:
(WebCore::CachedImage::purgePriority):
* loader/CachedResource.cpp:
(WebCore::CachedResource::makePurgeable): Set the purge priority on the PurgeableBffer.
Also, move the check for purgeable size threshold to PurgeableBuffer.
* loader/CachedResource.h:
(WebCore::CachedResource::purgePriority): Added. New virtual method that lets the class
specify its purge priority.
* loader/CachedScript.h:
(WebCore::CachedScript::purgePriority):
* platform/PurgePriority.h: Added. Move the PurgePriority enum from PurgeableBuffer class to
its own header file.
(WebCore::):
* platform/PurgeableBuffer.h:
(WebCore::PurgeableBuffer::setPurgePriority): Update this previously unused function to just
set the priority and not call makePurgeable(true).
* platform/mac/PurgeableBufferMac.cpp: Update size threshold to 16KB which is what
CachedResource was using.
2010-11-04 Chris Guillory <chris.guillory@google.com>
Reviewed by Chris Fleizach.
......@@ -1552,6 +1552,7 @@
7ADE722610CBBB9B006B3B3A /* ContextMenuProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 7ADE722510CBBB9B006B3B3A /* ContextMenuProvider.h */; };
7AFD4A8B1131C2760035B883 /* ScriptBreakpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AFD4A8A1131C2760035B883 /* ScriptBreakpoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
7AFD4FF4113277B60035B883 /* ScriptDebugListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AFD4FF3113277B60035B883 /* ScriptDebugListener.h */; settings = {ATTRIBUTES = (Private, ); }; };
7E33CD01127F340D00BE8F17 /* PurgePriority.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E33CD00127F340D00BE8F17 /* PurgePriority.h */; settings = {ATTRIBUTES = (Private, ); }; };
81A7325E1210189B00FC0D9E /* IDBCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 81A7325D1210189B00FC0D9E /* IDBCursor.h */; };
81A73260121018A400FC0D9E /* IDBCursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81A7325F121018A400FC0D9E /* IDBCursor.cpp */; };
81A73278121019E100FC0D9E /* IDBCursorBackendImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 81A73277121019E100FC0D9E /* IDBCursorBackendImpl.h */; };
......@@ -7702,6 +7703,7 @@
7ADE722510CBBB9B006B3B3A /* ContextMenuProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContextMenuProvider.h; sourceTree = "<group>"; };
7AFD4A8A1131C2760035B883 /* ScriptBreakpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptBreakpoint.h; sourceTree = "<group>"; };
7AFD4FF3113277B60035B883 /* ScriptDebugListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptDebugListener.h; sourceTree = "<group>"; };
7E33CD00127F340D00BE8F17 /* PurgePriority.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PurgePriority.h; sourceTree = "<group>"; };
81A7325D1210189B00FC0D9E /* IDBCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBCursor.h; sourceTree = "<group>"; };
81A7325F121018A400FC0D9E /* IDBCursor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBCursor.cpp; sourceTree = "<group>"; };
81A73277121019E100FC0D9E /* IDBCursorBackendImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBCursorBackendImpl.h; sourceTree = "<group>"; };
......@@ -17446,6 +17448,7 @@
ABC128760B33AA6D00C693D5 /* PopupMenuClient.h */,
BC3BE12A0E98092F00835588 /* PopupMenuStyle.h */,
E4D687780ED7AE4F006EA978 /* PurgeableBuffer.h */,
7E33CD00127F340D00BE8F17 /* PurgePriority.h */,
1C63A2460F71646600C09D5A /* RunLoopTimer.h */,
5162C7F211F77EFA00612EFE /* SchemeRegistry.cpp */,
5162C7F311F77EFB00612EFE /* SchemeRegistry.h */,
......@@ -20530,6 +20533,7 @@
51A052561058874000CC9E95 /* ProtectionSpaceHash.h in Headers */,
1AF8E11A1256592600230FF7 /* ProxyServer.h in Headers */,
E4D687790ED7AE4F006EA978 /* PurgeableBuffer.h in Headers */,
7E33CD01127F340D00BE8F17 /* PurgePriority.h in Headers */,
550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */,
B22279720D00BF220071B782 /* RadialGradientAttributes.h in Headers */,
F55B3DCC1251F12D003EF269 /* RadioInputType.h in Headers */,
......@@ -55,6 +55,7 @@ namespace WebCore {
private:
bool canUseSheet(bool enforceMIMEType, bool* hasValidMIMEType) const;
virtual PurgePriority purgePriority() const { return PurgeLast; }
protected:
RefPtr<TextResourceDecoder> m_decoder;
......
......@@ -93,6 +93,7 @@ private:
// If not null, changeRect is the changed part of the image.
void notifyObservers(const IntRect* changeRect = 0);
void decodedDataDeletionTimerFired(Timer<CachedImage>*);
virtual PurgePriority purgePriority() const { return PurgeFirst; }
RefPtr<Image> m_image;
Timer<CachedImage> m_decodedDataDeletionTimer;
......
......@@ -517,17 +517,13 @@ bool CachedResource::makePurgeable(bool purgeable)
if (!m_data->hasOneRef())
return false;
// Purgeable buffers are allocated in multiples of the page size (4KB in common CPUs) so it does not make sense for very small buffers.
const size_t purgeableThreshold = 4 * 4096;
if (m_data->size() < purgeableThreshold)
return false;
if (m_data->hasPurgeableBuffer()) {
m_purgeableData = m_data->releasePurgeableBuffer();
} else {
m_purgeableData = PurgeableBuffer::create(m_data->data(), m_data->size());
if (!m_purgeableData)
return false;
m_purgeableData->setPurgePriority(purgePriority());
}
m_purgeableData->makePurgeable(true);
......
......@@ -26,6 +26,7 @@
#include "CachePolicy.h"
#include "FrameLoaderTypes.h"
#include "PlatformString.h"
#include "PurgePriority.h"
#include "ResourceResponse.h"
#include <wtf/HashCountedSet.h>
#include <wtf/HashSet.h>
......@@ -42,8 +43,8 @@ class CachedResourceHandleBase;
class CachedResourceLoader;
class Frame;
class InspectorResource;
class Request;
class PurgeableBuffer;
class Request;
// A resource that is held in the cache. Classes who want to use this object should derive
// from CachedResourceClient, to get the function calls in case the requested data has arrived.
......@@ -229,6 +230,7 @@ private:
void switchClientsToRevalidatedResource();
void clearResourceToRevalidate();
void updateResponseAfterRevalidation(const ResourceResponse& validatingResponse);
virtual PurgePriority purgePriority() const { return PurgeDefault; }
double currentAge() const;
double freshnessLifetime() const;
......
......@@ -54,6 +54,7 @@ namespace WebCore {
private:
void decodedDataDeletionTimerFired(Timer<CachedScript>*);
virtual PurgePriority purgePriority() const { return PurgeLast; }
String m_script;
RefPtr<TextResourceDecoder> m_decoder;
......
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PurgePriority_h
#define PurgePriority_h
namespace WebCore {
enum PurgePriority {
PurgeLast,
PurgeMiddle,
PurgeFirst,
PurgeDefault = PurgeMiddle
};
}
#endif // PurgePriority_h
......@@ -26,6 +26,7 @@
#ifndef PurgeableBuffer_h
#define PurgeableBuffer_h
#include "PurgePriority.h"
#include <wtf/Noncopyable.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/Vector.h>
......@@ -35,7 +36,6 @@ namespace WebCore {
class PurgeableBuffer : public Noncopyable {
public:
static PassOwnPtr<PurgeableBuffer> create(const char* data, size_t);
static PassOwnPtr<PurgeableBuffer> create(const Vector<char>& vector) { return create(vector.data(), vector.size()); }
~PurgeableBuffer();
......@@ -43,9 +43,8 @@ namespace WebCore {
const char* data() const;
size_t size() const { return m_size; }
enum PurgePriority { PurgeLast, PurgeMiddle, PurgeFirst, PurgeDefault = PurgeMiddle };
PurgePriority purgePriority() const { return m_purgePriority; }
void setPurgePriority(PurgePriority);
void setPurgePriority(PurgePriority priority) { m_purgePriority = priority; }
bool isPurgeable() const { return m_state != NonVolatile; }
bool wasPurged() const;
......@@ -67,7 +66,6 @@ namespace WebCore {
inline PassOwnPtr<PurgeableBuffer> PurgeableBuffer::create(const char*, size_t) { return PassOwnPtr<PurgeableBuffer>(); }
inline PurgeableBuffer::~PurgeableBuffer() { }
inline const char* PurgeableBuffer::data() const { return 0; }
inline void PurgeableBuffer::setPurgePriority(PurgePriority) { }
inline bool PurgeableBuffer::wasPurged() const { return false; }
inline bool PurgeableBuffer::makePurgeable(bool) { return false; }
#endif
......
......@@ -35,7 +35,9 @@
namespace WebCore {
static const size_t minPurgeableBufferSize = 4096; // one page
// Purgeable buffers are allocated in multiples of the page size (4KB in common CPUs) so
// it does not make sense for very small buffers. Set our minimum size to 16KB.
static const size_t minPurgeableBufferSize = 4 * 4096;
PurgeableBuffer::PurgeableBuffer(char* data, size_t size)
: m_data(data)
......@@ -143,17 +145,6 @@ bool PurgeableBuffer::wasPurged() const
return false;
}
void PurgeableBuffer::setPurgePriority(PurgePriority priority)
{
if (priority == m_purgePriority)
return;
m_purgePriority = priority;
if (m_state != Volatile)
return;
m_state = NonVolatile;
makePurgeable(true);
}
const char* PurgeableBuffer::data() const
{
ASSERT(m_state == NonVolatile);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment