Changeset 250945 in webkit


Ignore:
Timestamp:
Oct 9, 2019 5:13:22 PM (5 years ago)
Author:
dbates@webkit.org
Message:

Add support for CompactPointerTuple<..., OptionSet<...>>
https://bugs.webkit.org/show_bug.cgi?id=201316

Reviewed by Yusuke Suzuki.

Source/WebCore:

Use the new CompactPointerTuple capability to replace CompactPointerTuple<RenderObject*, uint8_t>
with CompactPointerTuple<RenderObject*, OptionSet<ElementStyleFlag>> in Node.h.

  • dom/Node.h:

(WebCore::Node::hasStyleFlag const):
(WebCore::Node::setStyleFlag):
(WebCore::Node::clearStyleFlags):
Update code now that we support CompactPointerTuple<..., OptionSet<...>>.

Source/WTF:

Support using an OptionSet<> for the byte value portion of a CompactPointerTuple so that
you can encode both a pointer and 8-bit bitmask in a type-safe way. Another benefit of
supporting OptionSet<> is that we have a LLDB pretty-printer for it so this makes it easy
to see the set flags in such a CompactPointerTuple.

  • wtf/CompactPointerTuple.h:

Tools:

Add a test to ensure we encode and decode a compact pointer tuple correctly when an uint8_t and
a OptionSet<> as the byte value portion of the tuple.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WTF/CompactPointerTuple.cpp: Added.

(TestWebKitAPI::TEST):

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r250943 r250945  
     12019-10-09  Daniel Bates  <dabates@apple.com>
     2
     3        Add support for CompactPointerTuple<..., OptionSet<...>>
     4        https://bugs.webkit.org/show_bug.cgi?id=201316
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Support using an OptionSet<> for the byte value portion of a CompactPointerTuple so that
     9        you can encode both a pointer and 8-bit bitmask in a type-safe way. Another benefit of
     10        supporting OptionSet<> is that we have a LLDB pretty-printer for it so this makes it easy
     11        to see the set flags in such a CompactPointerTuple.
     12
     13        * wtf/CompactPointerTuple.h:
     14
    1152019-10-09  Russell Epstein  <repstein@apple.com>
    216
  • trunk/Source/WTF/wtf/CompactPointerTuple.h

    r250943 r250945  
    11/*
    22 * Copyright (C) 2018 Yusuke Suzuki <utatane.tea@gmail.com>.
     3 * Copyright (C) 2019 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2728
    2829#include <type_traits>
     30#include <wtf/OptionSet.h>
    2931#include <wtf/StdLibExtras.h>
    3032
    3133namespace WTF {
     34
     35template <typename T>
     36struct IsOptionSet : public std::integral_constant<bool, WTF::IsTemplate<std::decay_t<T>, OptionSet>::value> { };
     37
     38template<typename T> struct ByteValueTypeAdapter {
     39    static constexpr uint8_t toByte(T value) { return value; }
     40    static constexpr T fromByte(uint8_t value) { return static_cast<T>(value); }
     41};
     42
     43template<typename U> struct ByteValueTypeAdapter<OptionSet<U>> {
     44    static constexpr uint8_t toByte(OptionSet<U> value) { return value.toRaw(); }
     45    static constexpr OptionSet<U> fromByte(uint8_t value) { return OptionSet<U>::fromRaw(value); }
     46};
    3247
    3348// The goal of this class is folding a pointer and 1 byte value into 8 bytes in both 32bit and 64bit architectures.
     
    3550// In 64bit, we use the upper 5 bits and lower 3 bits (zero due to alignment) since these bits are safe to use even
    3651// with 5-level page tables where the effective pointer width is 57bits.
    37 template<typename PointerType, typename Type>
     52template<typename PointerType, typename Type, typename Adapter = ByteValueTypeAdapter<Type>>
    3853class CompactPointerTuple final {
    3954    WTF_MAKE_FAST_ALLOCATED;
     
    4156    static_assert(sizeof(Type) == 1, "");
    4257    static_assert(std::is_pointer<PointerType>::value, "");
    43     static_assert(std::is_integral<Type>::value || std::is_enum<Type>::value, "");
     58    static_assert(std::is_integral<Type>::value || std::is_enum<Type>::value || IsOptionSet<Type>::value, "");
    4459
    4560    CompactPointerTuple() = default;
     
    6378
    6479    CompactPointerTuple(PointerType pointer, Type type)
    65         : m_data(bitwise_cast<uint64_t>(pointer) | encodeType(static_cast<uint8_t>(type)))
     80        : m_data { bitwise_cast<uint64_t>(pointer) | encodeType(Adapter::toByte(type)) }
    6681    {
    6782        ASSERT((bitwise_cast<uint64_t>(pointer) & 0b111) == 0x0);
     
    7691    }
    7792
    78     Type type() const { return static_cast<Type>(decodeType(m_data)); }
     93    Type type() const { return Adapter::fromByte(decodeType(m_data)); }
    7994    void setType(Type type)
    8095    {
     
    99114private:
    100115    PointerType m_pointer { nullptr };
    101     Type m_type { 0 };
     116    Type m_type { };
    102117#endif
    103118};
  • trunk/Source/WebCore/ChangeLog

    r250944 r250945  
     12019-10-09  Daniel Bates  <dabates@apple.com>
     2
     3        Add support for CompactPointerTuple<..., OptionSet<...>>
     4        https://bugs.webkit.org/show_bug.cgi?id=201316
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Use the new CompactPointerTuple capability to replace CompactPointerTuple<RenderObject*, uint8_t>
     9        with CompactPointerTuple<RenderObject*, OptionSet<ElementStyleFlag>> in Node.h.
     10
     11        * dom/Node.h:
     12        (WebCore::Node::hasStyleFlag const):
     13        (WebCore::Node::setStyleFlag):
     14        (WebCore::Node::clearStyleFlags):
     15        Update code now that we support CompactPointerTuple<..., OptionSet<...>>.
     16
    1172019-10-09  John Wilander  <wilander@apple.com>
    218
  • trunk/Source/WebCore/dom/Node.h

    r250943 r250945  
    3737#include <wtf/ListHashSet.h>
    3838#include <wtf/MainThread.h>
     39#include <wtf/OptionSet.h>
    3940#include <wtf/URLHash.h>
    4041
     
    616617    };
    617618
    618     bool hasStyleFlag(ElementStyleFlag state) const { return m_rendererWithStyleFlags.type() & static_cast<uint8_t>(state); }
    619     void setStyleFlag(ElementStyleFlag state) { m_rendererWithStyleFlags.setType(m_rendererWithStyleFlags.type() | static_cast<uint8_t>(state)); }
    620     void clearStyleFlags() { m_rendererWithStyleFlags.setType(0); }
     619    bool hasStyleFlag(ElementStyleFlag state) const { return m_rendererWithStyleFlags.type().contains(state); }
     620    void setStyleFlag(ElementStyleFlag state) { m_rendererWithStyleFlags.setType(m_rendererWithStyleFlags.type() | state); }
     621    void clearStyleFlags() { m_rendererWithStyleFlags.setType({ }); }
    621622
    622623    virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const { }
     
    676677    Node* m_previous { nullptr };
    677678    Node* m_next { nullptr };
    678     CompactPointerTuple<RenderObject*, uint8_t> m_rendererWithStyleFlags;
     679    CompactPointerTuple<RenderObject*, OptionSet<ElementStyleFlag>> m_rendererWithStyleFlags;
    679680    std::unique_ptr<NodeRareData, NodeRareDataDeleter> m_rareData;
    680681};
  • trunk/Tools/ChangeLog

    r250943 r250945  
     12019-10-09  Daniel Bates  <dabates@apple.com>
     2
     3        Add support for CompactPointerTuple<..., OptionSet<...>>
     4        https://bugs.webkit.org/show_bug.cgi?id=201316
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Add a test to ensure we encode and decode a compact pointer tuple correctly when an uint8_t and
     9        a OptionSet<> as the byte value portion of the tuple.
     10
     11        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     12        * TestWebKitAPI/Tests/WTF/CompactPointerTuple.cpp: Added.
     13        (TestWebKitAPI::TEST):
     14
    1152019-10-09  Russell Epstein  <repstein@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r250943 r250945  
    927927                CE6E81A420A933D500E2C80F /* set-timeout-function.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CE6E81A320A933B800E2C80F /* set-timeout-function.html */; };
    928928                CE78705F2107AB980053AC67 /* MoveOnlyLifecycleLogger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE78705D2107AB8C0053AC67 /* MoveOnlyLifecycleLogger.cpp */; };
     929                CE9B07F2231889E300A09BC7 /* CompactPointerTuple.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE9B07F1231889E300A09BC7 /* CompactPointerTuple.cpp */; };
    929930                CEA6CF2819CCF69D0064F5A7 /* open-and-close-window.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */; };
    930931                CEA7F57D2089624B0078EF6E /* DidResignInputElementStrongPasswordAppearance.mm in Sources */ = {isa = PBXBuildFile; fileRef = CEA7F57B20895F5B0078EF6E /* DidResignInputElementStrongPasswordAppearance.mm */; };
     
    24022403                CE78705C2107AB8C0053AC67 /* MoveOnlyLifecycleLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MoveOnlyLifecycleLogger.h; sourceTree = "<group>"; };
    24032404                CE78705D2107AB8C0053AC67 /* MoveOnlyLifecycleLogger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MoveOnlyLifecycleLogger.cpp; sourceTree = "<group>"; };
     2405                CE9B07F1231889E300A09BC7 /* CompactPointerTuple.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CompactPointerTuple.cpp; sourceTree = "<group>"; };
    24042406                CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OpenAndCloseWindow.mm; sourceTree = "<group>"; };
    24052407                CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "open-and-close-window.html"; sourceTree = "<group>"; };
     
    36183620                                E40019301ACE9B5C001B0A2A /* BloomFilter.cpp */,
    36193621                                A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */,
     3622                                CE9B07F1231889E300A09BC7 /* CompactPointerTuple.cpp */,
    36203623                                0F30CB5B1FCE1792004B5323 /* ConcurrentPtrHashSet.cpp */,
    36213624                                0FEAE3671B7D19CB00CE17F2 /* Condition.cpp */,
     
    43094312                                7C83DE9C1D0A590C00FEBCF3 /* BloomFilter.cpp in Sources */,
    43104313                                7C83DEA01D0A590C00FEBCF3 /* CheckedArithmeticOperations.cpp in Sources */,
     4314                                CE9B07F2231889E300A09BC7 /* CompactPointerTuple.cpp in Sources */,
    43114315                                0F30CB5C1FCE1796004B5323 /* ConcurrentPtrHashSet.cpp in Sources */,
    43124316                                7C83DEC31D0A590C00FEBCF3 /* Condition.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.