⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 279365 in webkit


Ignore:
Timestamp:
Jun 29, 2021, 12:19:27 AM (5 years ago)
Author:
Antti Koivisto
Message:

Enable Probabilistic Guard Malloc for RuleData and RuleFeature vectors
​https://bugs.webkit.org/show_bug.cgi?id=227446

Reviewed by Geoffrey Garen.

Source/WebCore:

Help for catching a crash.

  • style/RuleFeature.cpp:

(WebCore::Style::RuleFeatureSet::collectFeatures):
(WebCore::Style::RuleFeatureSet::add):

  • style/RuleFeature.h:
  • style/RuleSet.h:
  • style/StyleScopeRuleSets.cpp:

(WebCore::Style::makeRuleSet):
(WebCore::Style::ensureInvalidationRuleSets):

Source/WTF:

Add SystemMalloc type that can be used with containers like Vector and
ProbabilisticGuardMalloc alias for it on Mac/iOS platforms.

  • WTF.xcodeproj/project.pbxproj:
  • wtf/CMakeLists.txt:
  • wtf/SystemMalloc.h: Added.

(WTF::SystemMalloc::malloc):
(WTF::SystemMalloc::tryMalloc):
(WTF::SystemMalloc::zeroedMalloc):
(WTF::SystemMalloc::tryZeroedMalloc):
(WTF::SystemMalloc::realloc):
(WTF::SystemMalloc::tryRealloc):
(WTF::SystemMalloc::free):

  • wtf/Vector.h:

(WTF::Malloc>::appendVector):

Include all template parameters for the appendVector argument.

Location:
trunk/Source
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r279341 r279365  
     12021-06-29  Antti Koivisto  <antti@apple.com>
     2
     3        Enable Probabilistic Guard Malloc for RuleData and RuleFeature vectors
     4        https://bugs.webkit.org/show_bug.cgi?id=227446
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Add SystemMalloc type that can be used with containers like Vector and
     9        ProbabilisticGuardMalloc alias for it on Mac/iOS platforms.
     10
     11        * WTF.xcodeproj/project.pbxproj:
     12        * wtf/CMakeLists.txt:
     13        * wtf/SystemMalloc.h: Added.
     14        (WTF::SystemMalloc::malloc):
     15        (WTF::SystemMalloc::tryMalloc):
     16        (WTF::SystemMalloc::zeroedMalloc):
     17        (WTF::SystemMalloc::tryZeroedMalloc):
     18        (WTF::SystemMalloc::realloc):
     19        (WTF::SystemMalloc::tryRealloc):
     20        (WTF::SystemMalloc::free):
     21        * wtf/Vector.h:
     22        (WTF::Malloc>::appendVector):
     23
     24        Include all template parameters for the appendVector argument.
     25
    1262021-06-28  Mikhail R. Gadelha  <mikhail@igalia.com>
    227
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r279339 r279365  
    761761                E4A0AD381A96245500536DF6 /* WorkQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkQueue.h; sourceTree = "<group>"; };
    762762                E4A0AD3C1A96253C00536DF6 /* WorkQueueCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueueCocoa.cpp; sourceTree = "<group>"; };
     763                E4D2AE4D268A4C7F00DFEA02 /* SystemMalloc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SystemMalloc.h; sourceTree = "<group>"; };
    763764                EB2C86D8267B275C0052CB9A /* CPUTimePOSIX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPUTimePOSIX.cpp; sourceTree = "<group>"; };
    764765                EB61EDC62409CCC0001EFE36 /* SystemTracingCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SystemTracingCocoa.cpp; sourceTree = "<group>"; };
    … …  
    12931294                                5597F82C1D94B9970066BC21 /* SynchronizedFixedQueue.h */,
    12941295                                E3E158251EADA53C004A079D /* SystemFree.h */,
     1296                                E4D2AE4D268A4C7F00DFEA02 /* SystemMalloc.h */,
    12951297                                0FB317C31C488001007E395A /* SystemTracing.h */,
    12961298                                DEF7FE5F22581AC800C15129 /* TaggedArrayStoragePtr.h */,
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r278891 r279365  
    265265    SynchronizedFixedQueue.h
    266266    SystemFree.h
     267    SystemMalloc.h
    267268    SystemTracing.h
    268269    TaggedArrayStoragePtr.h
  • trunk/Source/WTF/wtf/Vector.h

    r279051 r279365  
    785785    template<typename U> ALWAYS_INLINE void append(const U* u, size_t size) { append<FailureAction::Crash>(u, size); }
    786786    template<typename U> ALWAYS_INLINE bool tryAppend(const U* u, size_t size) { return append<FailureAction::Report>(u, size); }
    787     template<typename U, size_t otherCapacity> void appendVector(const Vector<U, otherCapacity>&);
    788     template<typename U, size_t otherCapacity> void appendVector(Vector<U, otherCapacity>&&);
     787    template<typename U, size_t otherCapacity, typename OtherOverflowHandler, size_t otherMinCapacity, typename OtherMalloc> void appendVector(const Vector<U, otherCapacity, OtherOverflowHandler, otherMinCapacity, OtherMalloc>&);
     788    template<typename U, size_t otherCapacity, typename OtherOverflowHandler, size_t otherMinCapacity, typename OtherMalloc> void appendVector(Vector<U, otherCapacity, OtherOverflowHandler, otherMinCapacity, OtherMalloc>&&);
    789789
    790790    void insert(size_t position, ValueType&& value) { insert<ValueType>(position, std::forward<ValueType>(value)); }
    … …  
    13841384
    13851385template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    1386 template<typename U, size_t otherCapacity>
    1387 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendVector(const Vector<U, otherCapacity>& val)
     1386template<typename U, size_t otherCapacity, typename OtherOverflowHandler, size_t otherMinCapacity, typename OtherMalloc>
     1387inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendVector(const Vector<U, otherCapacity, OtherOverflowHandler, otherMinCapacity, OtherMalloc>& val)
    13881388{
    13891389    append(val.begin(), val.size());
    … …  
    13911391
    13921392template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    1393 template<typename U, size_t otherCapacity>
    1394 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendVector(Vector<U, otherCapacity>&& val)
     1393template<typename U, size_t otherCapacity, typename OtherOverflowHandler, size_t otherMinCapacity, typename OtherMalloc>
     1394inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendVector(Vector<U, otherCapacity, OtherOverflowHandler, otherMinCapacity, OtherMalloc>&& val)
    13951395{
    13961396    size_t newSize = m_size + val.size();
  • trunk/Source/WebCore/ChangeLog

    r279364 r279365  
     12021-06-29  Antti Koivisto  <antti@apple.com>
     2
     3        Enable Probabilistic Guard Malloc for RuleData and RuleFeature vectors
     4        https://bugs.webkit.org/show_bug.cgi?id=227446
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Help for catching a crash.
     9
     10        * style/RuleFeature.cpp:
     11        (WebCore::Style::RuleFeatureSet::collectFeatures):
     12        (WebCore::Style::RuleFeatureSet::add):
     13        * style/RuleFeature.h:
     14        * style/RuleSet.h:
     15        * style/StyleScopeRuleSets.cpp:
     16        (WebCore::Style::makeRuleSet):
     17        (WebCore::Style::ensureInvalidationRuleSets):
     18
    1192021-06-29  Martin Robinson  <mrobinson@igalia.com>
    220
  • trunk/Source/WebCore/style/RuleFeature.cpp

    r278253 r279365  
    187187    for (auto& nameAndMatch : selectorFeatures.classes) {
    188188        classRules.ensure(nameAndMatch.first, [] {
    189             return makeUnique<Vector<RuleFeature>>();
     189            return makeUnique<RuleFeatureVector>();
    190190        }).iterator->value->append({ ruleData, nameAndMatch.second });
    191191        if (nameAndMatch.second == MatchElement::Host)
    … …  
    203203    for (auto& keyAndMatch : selectorFeatures.pseudoClasses) {
    204204        pseudoClassRules.ensure(keyAndMatch.first, [] {
    205             return makeUnique<Vector<RuleFeature>>();
     205            return makeUnique<RuleFeatureVector>();
    206206        }).iterator->value->append({ ruleData, keyAndMatch.second });
    207207        if (keyAndMatch.second == MatchElement::Host)
    … …  
    221221    for (auto& keyValuePair : other.classRules) {
    222222        classRules.ensure(keyValuePair.key, [] {
    223             return makeUnique<Vector<RuleFeature>>();
     223            return makeUnique<RuleFeatureVector>();
    224224        }).iterator->value->appendVector(*keyValuePair.value);
    225225    }
    … …  
    235235    for (auto& keyValuePair : other.pseudoClassRules) {
    236236        pseudoClassRules.ensure(keyValuePair.key, [] {
    237             return makeUnique<Vector<RuleFeature>>();
     237            return makeUnique<RuleFeatureVector>();
    238238        }).iterator->value->appendVector(*keyValuePair.value);
    239239    }
  • trunk/Source/WebCore/style/RuleFeature.h

    r278253 r279365  
    2626#include <wtf/HashMap.h>
    2727#include <wtf/HashSet.h>
     28#include <wtf/SystemMalloc.h>
    2829#include <wtf/text/AtomString.h>
    2930#include <wtf/text/AtomStringHash.h>
    … …  
    3940enum class MatchElement : uint8_t { Subject, Parent, Ancestor, DirectSibling, IndirectSibling, AnySibling, ParentSibling, AncestorSibling, Host };
    4041constexpr unsigned matchElementCount = static_cast<unsigned>(MatchElement::Host) + 1;
     42
     43#if HAVE(PROBABILISTIC_GUARD_MALLOC)
     44// Help finding rdar://77450900
     45using RuleMalloc = ProbabilisticGuardMalloc;
     46#else
     47using RuleMalloc = FastMalloc;
     48#endif
    4149
    4250struct RuleFeature {
    … …  
    5967};
    6068
     69using RuleFeatureVector = Vector<RuleFeature, 0, CrashOnOverflow, 16, RuleMalloc>;
     70
    6171struct RuleFeatureSet {
    6272    void add(const RuleFeatureSet&);
    … …  
    7181    HashSet<AtomString> attributeLocalNamesInRules;
    7282    HashSet<AtomString> contentAttributeNamesInRules;
    73     Vector<RuleFeature> siblingRules;
    74     Vector<RuleFeature> uncommonAttributeRules;
     83    RuleFeatureVector siblingRules;
     84    RuleFeatureVector uncommonAttributeRules;
    7585   
    76     HashMap<AtomString, std::unique_ptr<Vector<RuleFeature>>> classRules;
     86    HashMap<AtomString, std::unique_ptr<RuleFeatureVector>> classRules;
    7787    HashMap<AtomString, std::unique_ptr<Vector<RuleFeatureWithInvalidationSelector>>> attributeRules;
    78     HashMap<CSSSelector::PseudoClassType, std::unique_ptr<Vector<RuleFeature>>, WTF::IntHash<CSSSelector::PseudoClassType>, WTF::StrongEnumHashTraits<CSSSelector::PseudoClassType>> pseudoClassRules;
     88    HashMap<CSSSelector::PseudoClassType, std::unique_ptr<RuleFeatureVector>, WTF::IntHash<CSSSelector::PseudoClassType>, WTF::StrongEnumHashTraits<CSSSelector::PseudoClassType>> pseudoClassRules;
    7989    HashSet<AtomString> classesAffectingHost;
    8090    HashSet<AtomString> attributesAffectingHost;
  • trunk/Source/WebCore/style/RuleSet.h

    r279242 r279365  
    6868    ~RuleSet();
    6969
    70     typedef Vector<RuleData, 1> RuleDataVector;
     70    typedef Vector<RuleData, 1, CrashOnOverflow, 16, RuleMalloc> RuleDataVector;
    7171    typedef HashMap<AtomString, std::unique_ptr<RuleDataVector>> AtomRuleMap;
    7272
    … …  
    7474        Vector<Ref<const MediaQuerySet>> mediaQuerySets;
    7575        Vector<size_t> affectedRulePositions;
    76         Vector<RuleFeature> ruleFeatures;
     76        RuleFeatureVector ruleFeatures;
    7777        bool requiresFullReset { false };
    7878        bool result { true };
    … …  
    8888            Ref<const MediaQuerySet> set;
    8989            Vector<size_t> affectedRulePositions { };
    90             Vector<RuleFeature> ruleFeatures { };
     90            RuleFeatureVector ruleFeatures { };
    9191        };
    9292        Vector<DynamicContext> dynamicContextStack { };
    … …  
    148148        bool requiredFullReset { false };
    149149        Vector<size_t> changedQueryIndexes { };
    150         Vector<const Vector<RuleFeature>*> ruleFeatures { };
     150        Vector<RuleFeatureVector*> ruleFeatures { };
    151151    };
    152152    CollectedMediaQueryChanges evaluateDynamicMediaQueryRules(const MediaQueryEvaluator&, size_t startIndex);
  • trunk/Source/WebCore/style/StyleScopeRuleSets.cpp

    r278253 r279365  
    118118}
    119119
    120 static RefPtr<RuleSet> makeRuleSet(const Vector<RuleFeature>& rules)
     120static RefPtr<RuleSet> makeRuleSet(const RuleFeatureVector& rules)
    121121{
    122122    size_t size = rules.size();
    … …  
    220220}
    221221
    222 template<typename KeyType, typename RuleFeatureType, typename Hash, typename HashTraits>
    223 static Vector<InvalidationRuleSet>* ensureInvalidationRuleSets(const KeyType& key, HashMap<KeyType, std::unique_ptr<Vector<InvalidationRuleSet>>, Hash, HashTraits>& ruleSetMap, const HashMap<KeyType, std::unique_ptr<Vector<RuleFeatureType>>, Hash, HashTraits>& ruleFeatures)
     222template<typename KeyType, typename RuleFeatureVectorType, typename Hash, typename HashTraits>
     223static Vector<InvalidationRuleSet>* ensureInvalidationRuleSets(const KeyType& key, HashMap<KeyType, std::unique_ptr<Vector<InvalidationRuleSet>>, Hash, HashTraits>& ruleSetMap, const HashMap<KeyType, std::unique_ptr<RuleFeatureVectorType>, Hash, HashTraits>& ruleFeatures)
    224224{
    225225    return ruleSetMap.ensure(key, [&] () -> std::unique_ptr<Vector<InvalidationRuleSet>> {
    … …  
    231231        std::array<Vector<const CSSSelector*>, matchElementCount> invalidationSelectorArray;
    232232        for (auto& feature : *features) {
     233            RELEASE_ASSERT(feature.matchElement);
    233234            auto arrayIndex = static_cast<unsigned>(*feature.matchElement);
     235            RELEASE_ASSERT(arrayIndex < matchElementArray.size());
     236
    234237            auto& ruleSet = matchElementArray[arrayIndex];
    235238            if (!ruleSet)
    236239                ruleSet = RuleSet::create();
    237240            ruleSet->addRule(*feature.styleRule, feature.selectorIndex, feature.selectorListIndex);
    238             if constexpr (std::is_same<RuleFeatureType, RuleFeatureWithInvalidationSelector>::value) {
     241            if constexpr (std::is_same<typename RuleFeatureVectorType::ValueType, RuleFeatureWithInvalidationSelector>::value) {
    239242                if (feature.invalidationSelector)
    240243                    invalidationSelectorArray[arrayIndex].append(feature.invalidationSelector);
Note: See TracChangeset for help on using the changeset viewer.