Diff
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/ChangeLog (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/ChangeLog 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/ChangeLog 2020-02-25 16:02:12 UTC (rev 257339)
@@ -1,5 +1,57 @@
2020-02-12 Yusuke Suzuki <ysuz...@apple.com>
+ CSSValuePool's constant CSS values should not be allocated dynamically (and same for Vectors)
+ https://bugs.webkit.org/show_bug.cgi?id=207666
+
+ Reviewed by Mark Lam.
+
+ r252785 changes contents (CSSValues and Vectors) of CSSValuePool from static ones to
+ dynamically allocated ones. This was done since we would like to use static CSSValues
+ even in the other threads (workers etc.) for OffscreenCanvas feature.
+
+ But this causes memory regression in Membuster since we allocates many CSSValues and
+ large Vectors, and they are kept persistently.
+
+ This patch removes dynamic allocation part of r252785 to recover memory regression.
+ The key of this patch is introducing Static CSSValue feature. When incrementing / decrementing
+ m_refCount of CSSValue, we add / subtract by 0x2. And we put 0x1 as a static-flag. So, even if
+ this CSSValue is used by multiple threads, we never see that CSSValue gets 0 m_refCount if
+ it is marked as static (having 0x1). This is the same design to our static StringImpl.
+
+ No behavior change.
+
+ * css/CSSInheritedValue.h:
+ * css/CSSInitialValue.h:
+ * css/CSSPrimitiveValue.cpp:
+ (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
+ * css/CSSPrimitiveValue.h:
+ * css/CSSRevertValue.h:
+ * css/CSSUnsetValue.h:
+ * css/CSSValue.cpp:
+ * css/CSSValue.h:
+ (WebCore::CSSValue::ref const):
+ (WebCore::CSSValue::hasOneRef const):
+ (WebCore::CSSValue::refCount const):
+ (WebCore::CSSValue::hasAtLeastOneRef const):
+ (WebCore::CSSValue::deref):
+ (WebCore::CSSValue::makeStatic):
+ * css/CSSValuePool.cpp:
+ (WebCore::StaticCSSValuePool::StaticCSSValuePool):
+ (WebCore::StaticCSSValuePool::init):
+ (WebCore::CSSValuePool::CSSValuePool):
+ (WebCore::CSSValuePool::singleton):
+ (WebCore::CSSValuePool::createIdentifierValue):
+ (WebCore::CSSValuePool::createColorValue):
+ (WebCore::CSSValuePool::createValue):
+ * css/CSSValuePool.h:
+ (WebCore::CSSValuePool::createInheritedValue):
+ (WebCore::CSSValuePool::createImplicitInitialValue):
+ (WebCore::CSSValuePool::createExplicitInitialValue):
+ (WebCore::CSSValuePool::createUnsetValue):
+ (WebCore::CSSValuePool::createRevertValue):
+
+2020-02-12 Yusuke Suzuki <ysuz...@apple.com>
+
Shrink CachedResource
https://bugs.webkit.org/show_bug.cgi?id=207618
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSInheritedValue.h (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSInheritedValue.h 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSInheritedValue.h 2020-02-25 16:02:12 UTC (rev 257339)
@@ -26,16 +26,16 @@
class CSSInheritedValue final : public CSSValue {
public:
- static Ref<CSSInheritedValue> create() { return adoptRef(*new CSSInheritedValue()); }
-
String customCSSText() const;
bool equals(const CSSInheritedValue&) const { return true; }
private:
- CSSInheritedValue()
+ friend LazyNeverDestroyed<CSSInheritedValue>;
+ CSSInheritedValue(StaticCSSValueTag)
: CSSValue(InheritedClass)
{
+ makeStatic();
}
};
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSInitialValue.h (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSInitialValue.h 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSInitialValue.h 2020-02-25 16:02:12 UTC (rev 257339)
@@ -26,15 +26,6 @@
class CSSInitialValue final : public CSSValue {
public:
- static Ref<CSSInitialValue> createExplicit()
- {
- return adoptRef(*new CSSInitialValue(/* implicit */ false));
- }
- static Ref<CSSInitialValue> createImplicit()
- {
- return adoptRef(*new CSSInitialValue(/* implicit */ true));
- }
-
String customCSSText() const;
bool isImplicit() const { return m_isImplicit; }
@@ -43,10 +34,11 @@
private:
friend LazyNeverDestroyed<CSSInitialValue>;
- CSSInitialValue(bool implicit)
+ CSSInitialValue(StaticCSSValueTag, bool implicit)
: CSSValue(InitialClass)
, m_isImplicit(implicit)
{
+ makeStatic();
}
private:
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSPrimitiveValue.cpp (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSPrimitiveValue.cpp 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSPrimitiveValue.cpp 2020-02-25 16:02:12 UTC (rev 257339)
@@ -306,6 +306,24 @@
init(lengthSize, style);
}
+CSSPrimitiveValue::CSSPrimitiveValue(StaticCSSValueTag, CSSValueID valueID)
+ : CSSPrimitiveValue(valueID)
+{
+ makeStatic();
+}
+
+CSSPrimitiveValue::CSSPrimitiveValue(StaticCSSValueTag, const Color& color)
+ : CSSPrimitiveValue(color)
+{
+ makeStatic();
+}
+
+CSSPrimitiveValue::CSSPrimitiveValue(StaticCSSValueTag, double num, CSSUnitType type)
+ : CSSPrimitiveValue(num, type)
+{
+ makeStatic();
+}
+
void CSSPrimitiveValue::init(const Length& length)
{
switch (length.type()) {
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSPrimitiveValue.h (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSPrimitiveValue.h 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSPrimitiveValue.h 2020-02-25 16:02:12 UTC (rev 257339)
@@ -218,6 +218,10 @@
CSSPrimitiveValue(const String&, CSSUnitType);
CSSPrimitiveValue(double, CSSUnitType);
+ CSSPrimitiveValue(StaticCSSValueTag, CSSValueID);
+ CSSPrimitiveValue(StaticCSSValueTag, const Color&);
+ CSSPrimitiveValue(StaticCSSValueTag, double, CSSUnitType);
+
template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMappings.h
template<typename T> CSSPrimitiveValue(RefPtr<T>&&);
template<typename T> CSSPrimitiveValue(Ref<T>&&);
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSRevertValue.h (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSRevertValue.h 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSRevertValue.h 2020-02-25 16:02:12 UTC (rev 257339)
@@ -31,16 +31,16 @@
class CSSRevertValue final : public CSSValue {
public:
- static Ref<CSSRevertValue> create() { return adoptRef(*new CSSRevertValue()); }
-
String customCSSText() const;
bool equals(const CSSRevertValue&) const { return true; }
private:
- CSSRevertValue()
+ friend LazyNeverDestroyed<CSSRevertValue>;
+ CSSRevertValue(StaticCSSValueTag)
: CSSValue(RevertClass)
{
+ makeStatic();
}
};
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSUnsetValue.h (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSUnsetValue.h 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSUnsetValue.h 2020-02-25 16:02:12 UTC (rev 257339)
@@ -31,16 +31,16 @@
class CSSUnsetValue final : public CSSValue {
public:
- static Ref<CSSUnsetValue> create() { return adoptRef(*new CSSUnsetValue()); }
-
String customCSSText() const;
bool equals(const CSSUnsetValue&) const { return true; }
private:
- CSSUnsetValue()
+ friend LazyNeverDestroyed<CSSUnsetValue>;
+ CSSUnsetValue(StaticCSSValueTag)
: CSSValue(UnsetClass)
{
+ makeStatic();
}
};
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValue.cpp (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValue.cpp 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValue.cpp 2020-02-25 16:02:12 UTC (rev 257339)
@@ -74,7 +74,8 @@
namespace WebCore {
-struct SameSizeAsCSSValue : public RefCounted<SameSizeAsCSSValue> {
+struct SameSizeAsCSSValue {
+ uint32_t refCount;
uint32_t bitfields;
};
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValue.h (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValue.h 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValue.h 2020-02-25 16:02:12 UTC (rev 257339)
@@ -39,7 +39,8 @@
enum CSSPropertyID : uint16_t;
DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(CSSValue);
-class CSSValue : public RefCounted<CSSValue> {
+class CSSValue {
+ WTF_MAKE_NONCOPYABLE(CSSValue);
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(CSSValue);
public:
enum Type {
@@ -52,12 +53,26 @@
CSS_REVERT = 6
};
- // Override RefCounted's deref() to ensure operator delete is called on
- // the appropriate subclass type.
+ static constexpr unsigned refCountFlagIsStatic = 0x1;
+ static constexpr unsigned refCountIncrement = 0x2; // This allows us to ref / deref without disturbing the static CSSValue flag.
+ void ref() const
+ {
+ m_refCount += refCountIncrement;
+ }
+ bool hasOneRef() const { return m_refCount == refCountIncrement; }
+ unsigned refCount() const { return m_refCount / refCountIncrement; }
+ bool hasAtLeastOneRef() const { return m_refCount; }
+
void deref()
{
- if (derefBase())
+ // Customized deref() to ensure operator delete is called on
+ // the appropriate subclass type.
+ unsigned tempRefCount = m_refCount - refCountIncrement;
+ if (!tempRefCount) {
destroy();
+ return;
+ }
+ m_refCount = tempRefCount;
}
Type cssValueType() const;
@@ -214,6 +229,7 @@
CommaSeparator,
SlashSeparator
};
+ enum StaticCSSValueTag { StaticCSSValue };
protected:
ClassType classType() const { return static_cast<ClassType>(m_classType); }
@@ -227,6 +243,11 @@
{
}
+ void makeStatic()
+ {
+ m_refCount |= refCountFlagIsStatic;
+ }
+
// NOTE: This class is non-virtual for memory and performance reasons.
// Don't go making it virtual again unless you know exactly what you're doing!
@@ -235,10 +256,10 @@
private:
WEBCORE_EXPORT void destroy();
+ mutable unsigned m_refCount { refCountIncrement };
protected:
// The bits in this section are only used by specific subclasses but kept here
// to maximize struct packing.
-
// CSSPrimitiveValue bits:
unsigned m_primitiveUnitType : 7; // CSSUnitType
mutable unsigned m_hasCachedCSSText : 1;
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValuePool.cpp (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValuePool.cpp 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValuePool.cpp 2020-02-25 16:02:12 UTC (rev 257339)
@@ -34,41 +34,54 @@
namespace WebCore {
-CSSValuePool& CSSValuePool::singleton()
+LazyNeverDestroyed<StaticCSSValuePool> staticCSSValuePool;
+
+StaticCSSValuePool::StaticCSSValuePool()
{
- ASSERT(isMainThread());
- static NeverDestroyed<CSSValuePool> pool;
- return pool;
+ m_inheritedValue.construct(CSSValue::StaticCSSValue);
+ m_implicitInitialValue.construct(CSSValue::StaticCSSValue, true);
+ m_explicitInitialValue.construct(CSSValue::StaticCSSValue, false);
+ m_unsetValue.construct(CSSValue::StaticCSSValue);
+ m_revertValue.construct(CSSValue::StaticCSSValue);
+
+ m_transparentColor.construct(CSSValue::StaticCSSValue, Color(Color::transparent));
+ m_whiteColor.construct(CSSValue::StaticCSSValue, Color(Color::white));
+ m_blackColor.construct(CSSValue::StaticCSSValue, Color(Color::black));
+
+ for (unsigned i = firstCSSValueKeyword; i <= lastCSSValueKeyword; ++i)
+ m_identifierValues[i].construct(CSSValue::StaticCSSValue, static_cast<CSSValueID>(i));
+
+ for (unsigned i = 0; i < (maximumCacheableIntegerValue + 1); ++i) {
+ m_pixelValues[i].construct(CSSValue::StaticCSSValue, i, CSSUnitType::CSS_PX);
+ m_percentValues[i].construct(CSSValue::StaticCSSValue, i, CSSUnitType::CSS_PERCENTAGE);
+ m_numberValues[i].construct(CSSValue::StaticCSSValue, i, CSSUnitType::CSS_NUMBER);
+ }
}
+void StaticCSSValuePool::init()
+{
+ static std::once_flag onceKey;
+ std::call_once(onceKey, []() {
+ staticCSSValuePool.construct();
+ });
+}
+
CSSValuePool::CSSValuePool()
- : m_inheritedValue(CSSInheritedValue::create())
- , m_implicitInitialValue(CSSInitialValue::createImplicit())
- , m_explicitInitialValue(CSSInitialValue::createExplicit())
- , m_unsetValue(CSSUnsetValue::create())
- , m_revertValue(CSSRevertValue::create())
- , m_transparentColor(CSSPrimitiveValue::create(Color(Color::transparent)))
- , m_whiteColor(CSSPrimitiveValue::create(Color(Color::white)))
- , m_blackColor(CSSPrimitiveValue::create(Color(Color::black)))
{
- m_identifierValues.reserveInitialCapacity(numCSSValueKeywords);
- for (unsigned i = 0; i < numCSSValueKeywords; ++i)
- m_identifierValues.uncheckedAppend(CSSPrimitiveValue::create(static_cast<CSSValueID>(i)));
+ StaticCSSValuePool::init();
+}
- m_pixelValues.reserveInitialCapacity(maximumCacheableIntegerValue + 1);
- m_percentValues.reserveInitialCapacity(maximumCacheableIntegerValue + 1);
- m_numberValues.reserveInitialCapacity(maximumCacheableIntegerValue + 1);
- for (unsigned i = 0; i < (maximumCacheableIntegerValue + 1); ++i) {
- m_pixelValues.uncheckedAppend(CSSPrimitiveValue::create(i, CSSUnitType::CSS_PX));
- m_percentValues.uncheckedAppend(CSSPrimitiveValue::create(i, CSSUnitType::CSS_PERCENTAGE));
- m_numberValues.uncheckedAppend(CSSPrimitiveValue::create(i, CSSUnitType::CSS_NUMBER));
- }
+CSSValuePool& CSSValuePool::singleton()
+{
+ ASSERT(isMainThread());
+ static NeverDestroyed<CSSValuePool> pool;
+ return pool;
}
Ref<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ident)
{
RELEASE_ASSERT(ident >= firstCSSValueKeyword && ident <= lastCSSValueKeyword);
- return m_identifierValues[ident].get();
+ return staticCSSValuePool->m_identifierValues[ident].get();
}
Ref<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSPropertyID ident)
@@ -80,12 +93,12 @@
{
// These are the empty and deleted values of the hash table.
if (color == Color::transparent)
- return m_transparentColor.get();
+ return staticCSSValuePool->m_transparentColor.get();
if (color == Color::white)
- return m_whiteColor.get();
+ return staticCSSValuePool->m_whiteColor.get();
// Just because it is common.
if (color == Color::black)
- return m_blackColor.get();
+ return staticCSSValuePool->m_blackColor.get();
// Remove one entry at random if the cache grows too large.
// FIXME: Use TinyLRUCache instead?
@@ -102,7 +115,7 @@
{
ASSERT(std::isfinite(value));
- if (value < 0 || value > maximumCacheableIntegerValue)
+ if (value < 0 || value > StaticCSSValuePool::maximumCacheableIntegerValue)
return CSSPrimitiveValue::create(value, type);
int intValue = static_cast<int>(value);
@@ -111,11 +124,11 @@
switch (type) {
case CSSUnitType::CSS_PX:
- return m_pixelValues[intValue].get();
+ return staticCSSValuePool->m_pixelValues[intValue].get();
case CSSUnitType::CSS_PERCENTAGE:
- return m_percentValues[intValue].get();
+ return staticCSSValuePool->m_percentValues[intValue].get();
case CSSUnitType::CSS_NUMBER:
- return m_numberValues[intValue].get();
+ return staticCSSValuePool->m_numberValues[intValue].get();
default:
return CSSPrimitiveValue::create(value, type);
}
Modified: releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValuePool.h (257338 => 257339)
--- releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValuePool.h 2020-02-25 16:02:06 UTC (rev 257338)
+++ releases/WebKitGTK/webkit-2.28/Source/WebCore/css/CSSValuePool.h 2020-02-25 16:02:12 UTC (rev 257339)
@@ -37,15 +37,44 @@
#include <wtf/HashMap.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
#include <wtf/text/AtomStringHash.h>
namespace WebCore {
class CSSValueList;
+class CSSValuePool;
enum class FromSystemFontID { No, Yes };
+class StaticCSSValuePool {
+ friend class CSSValuePool;
+ friend class LazyNeverDestroyed<StaticCSSValuePool>;
+public:
+ static void init();
+
+private:
+ StaticCSSValuePool();
+
+ LazyNeverDestroyed<CSSInheritedValue> m_inheritedValue;
+ LazyNeverDestroyed<CSSInitialValue> m_implicitInitialValue;
+ LazyNeverDestroyed<CSSInitialValue> m_explicitInitialValue;
+ LazyNeverDestroyed<CSSUnsetValue> m_unsetValue;
+ LazyNeverDestroyed<CSSRevertValue> m_revertValue;
+
+ LazyNeverDestroyed<CSSPrimitiveValue> m_transparentColor;
+ LazyNeverDestroyed<CSSPrimitiveValue> m_whiteColor;
+ LazyNeverDestroyed<CSSPrimitiveValue> m_blackColor;
+
+ static constexpr int maximumCacheableIntegerValue = 255;
+
+ LazyNeverDestroyed<CSSPrimitiveValue> m_pixelValues[maximumCacheableIntegerValue + 1];
+ LazyNeverDestroyed<CSSPrimitiveValue> m_percentValues[maximumCacheableIntegerValue + 1];
+ LazyNeverDestroyed<CSSPrimitiveValue> m_numberValues[maximumCacheableIntegerValue + 1];
+ LazyNeverDestroyed<CSSPrimitiveValue> m_identifierValues[numCSSValueKeywords];
+};
+
+WEBCORE_EXPORT extern LazyNeverDestroyed<StaticCSSValuePool> staticCSSValuePool;
+
class CSSValuePool {
WTF_MAKE_FAST_ALLOCATED;
public:
@@ -55,11 +84,11 @@
RefPtr<CSSValueList> createFontFaceValue(const AtomString&);
Ref<CSSPrimitiveValue> createFontFamilyValue(const String&, FromSystemFontID = FromSystemFontID::No);
- Ref<CSSInheritedValue> createInheritedValue() { return m_inheritedValue.get(); }
- Ref<CSSInitialValue> createImplicitInitialValue() { return m_implicitInitialValue.get(); }
- Ref<CSSInitialValue> createExplicitInitialValue() { return m_explicitInitialValue.get(); }
- Ref<CSSUnsetValue> createUnsetValue() { return m_unsetValue.get(); }
- Ref<CSSRevertValue> createRevertValue() { return m_revertValue.get(); }
+ Ref<CSSInheritedValue> createInheritedValue() { return staticCSSValuePool->m_inheritedValue.get(); }
+ Ref<CSSInitialValue> createImplicitInitialValue() { return staticCSSValuePool->m_implicitInitialValue.get(); }
+ Ref<CSSInitialValue> createExplicitInitialValue() { return staticCSSValuePool->m_explicitInitialValue.get(); }
+ Ref<CSSUnsetValue> createUnsetValue() { return staticCSSValuePool->m_unsetValue.get(); }
+ Ref<CSSRevertValue> createRevertValue() { return staticCSSValuePool->m_revertValue.get(); }
Ref<CSSPrimitiveValue> createIdentifierValue(CSSValueID identifier);
Ref<CSSPrimitiveValue> createIdentifierValue(CSSPropertyID identifier);
Ref<CSSPrimitiveValue> createColorValue(const Color&);
@@ -81,24 +110,7 @@
typedef HashMap<std::pair<String, bool>, RefPtr<CSSPrimitiveValue>> FontFamilyValueCache;
FontFamilyValueCache m_fontFamilyValueCache;
- friend class WTF::NeverDestroyed<CSSValuePool>;
-
- Ref<CSSInheritedValue> m_inheritedValue;
- Ref<CSSInitialValue> m_implicitInitialValue;
- Ref<CSSInitialValue> m_explicitInitialValue;
- Ref<CSSUnsetValue> m_unsetValue;
- Ref<CSSRevertValue> m_revertValue;
-
- Ref<CSSPrimitiveValue> m_transparentColor;
- Ref<CSSPrimitiveValue> m_whiteColor;
- Ref<CSSPrimitiveValue> m_blackColor;
-
- static const int maximumCacheableIntegerValue = 255;
-
- Vector<Ref<CSSPrimitiveValue>> m_pixelValues;
- Vector<Ref<CSSPrimitiveValue>> m_percentValues;
- Vector<Ref<CSSPrimitiveValue>> m_numberValues;
- Vector<Ref<CSSPrimitiveValue>> m_identifierValues;
+ friend class NeverDestroyed<CSSValuePool>;
};
} // namespace WebCore