Changeset 219281 in webkit


Ignore:
Timestamp:
Jul 9, 2017, 5:22:58 AM (8 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Use fastMalloc / fastFree for STL containers
https://bugs.webkit.org/show_bug.cgi?id=174297

Reviewed by Sam Weinig.

Source/JavaScriptCore:

In some places, we intentionally use STL containers over WTF containers.
For example, we sometimes use std::unordered_{set,map} instead of WTF::Hash{Set,Map}
because we do not have effective empty / deleted representations in the space of key's value.
But just using STL container means using libc's malloc instead of our fast malloc (bmalloc if it is enabled).

We introduce WTF::FastAllocator. This is C++ allocator implementation using fastMalloc and fastFree.
We specify this allocator to STL containers' template parameter to allocate memory from fastMalloc.

This WTF::FastAllocator gives us a chance to use STL containers if it is necessary
without compromising memory allocation throughput.

  • dfg/DFGGraph.h:
  • dfg/DFGIntegerCheckCombiningPhase.cpp:
  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::switchStringSlow):

  • runtime/FunctionHasExecutedCache.h:
  • runtime/TypeLocationCache.h:

Source/WTF:

  • wtf/FastMalloc.h:

(WTF::FastAllocator::FastAllocator):
(WTF::FastAllocator::allocate):
(WTF::FastAllocator::deallocate):
(WTF::FastAllocator::operator==):
(WTF::FastAllocator::operator!=):

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r219276 r219281  
     12017-07-09  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Use fastMalloc / fastFree for STL containers
     4        https://bugs.webkit.org/show_bug.cgi?id=174297
     5
     6        Reviewed by Sam Weinig.
     7
     8        In some places, we intentionally use STL containers over WTF containers.
     9        For example, we sometimes use std::unordered_{set,map} instead of WTF::Hash{Set,Map}
     10        because we do not have effective empty / deleted representations in the space of key's value.
     11        But just using STL container means using libc's malloc instead of our fast malloc (bmalloc if it is enabled).
     12
     13        We introduce WTF::FastAllocator. This is C++ allocator implementation using fastMalloc and fastFree.
     14        We specify this allocator to STL containers' template parameter to allocate memory from fastMalloc.
     15
     16        This WTF::FastAllocator gives us a chance to use STL containers if it is necessary
     17        without compromising memory allocation throughput.
     18
     19        * dfg/DFGGraph.h:
     20        * dfg/DFGIntegerCheckCombiningPhase.cpp:
     21        * ftl/FTLLowerDFGToB3.cpp:
     22        (JSC::FTL::DFG::LowerDFGToB3::switchStringSlow):
     23        * runtime/FunctionHasExecutedCache.h:
     24        * runtime/TypeLocationCache.h:
     25
    1262017-07-08  Yusuke Suzuki  <utatane.tea@gmail.com>
    227
  • trunk/Source/JavaScriptCore/dfg/DFGGraph.h

    r219046 r219281  
    998998
    999999#if USE(JSVALUE32_64)
    1000     std::unordered_map<int64_t, double*> m_doubleConstantsMap;
     1000    std::unordered_map<int64_t, double*, std::hash<int64_t>, std::equal_to<int64_t>, FastAllocator<std::pair<const int64_t, double*>>> m_doubleConstantsMap;
    10011001    std::unique_ptr<Bag<double>> m_doubleConstants;
    10021002#endif
  • trunk/Source/JavaScriptCore/dfg/DFGIntegerCheckCombiningPhase.cpp

    r214240 r219281  
    397397    }
    398398   
    399     typedef std::unordered_map<RangeKey, Range, HashMethod<RangeKey>> RangeMap;
     399    using RangeMap = std::unordered_map<RangeKey, Range, HashMethod<RangeKey>, std::equal_to<RangeKey>, FastAllocator<std::pair<const RangeKey, Range>>>;
    400400    RangeMap m_map;
    401401   
  • trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp

    r219187 r219281  
    1185011850       
    1185111851        Vector<SwitchCase> cases;
    11852         std::unordered_set<int32_t> alreadyHandled; // These may be negative, or zero, or probably other stuff, too. We don't want to mess with HashSet's corner cases and we don't really care about throughput here.
     11852        // These may be negative, or zero, or probably other stuff, too. We don't want to mess with HashSet's corner cases and we don't really care about throughput here.
     11853        std::unordered_set<int32_t, std::hash<int32_t>, std::equal_to<int32_t>, FastAllocator<int32_t>> alreadyHandled;
    1185311854        for (unsigned i = 0; i < data->cases.size(); ++i) {
    1185411855            // FIXME: The fact that we're using the bytecode's switch table means that the
  • trunk/Source/JavaScriptCore/runtime/FunctionHasExecutedCache.h

    r206525 r219281  
    5454    Vector<std::tuple<bool, unsigned, unsigned>> getFunctionRanges(intptr_t id);
    5555
    56 private:     
    57     typedef std::unordered_map<FunctionRange, bool, HashMethod<FunctionRange>> RangeMap;
    58     typedef std::unordered_map<intptr_t, RangeMap> SourceIDToRangeMap;
     56private:
     57    using RangeMap = std::unordered_map<FunctionRange, bool, HashMethod<FunctionRange>, std::equal_to<FunctionRange>, FastAllocator<std::pair<const FunctionRange, bool>>>;
     58    using SourceIDToRangeMap = std::unordered_map<intptr_t, RangeMap, std::hash<intptr_t>, std::equal_to<intptr_t>, FastAllocator<std::pair<const intptr_t, RangeMap>>>;
    5959    SourceIDToRangeMap m_rangeMap;
    6060};
  • trunk/Source/JavaScriptCore/runtime/TypeLocationCache.h

    r212365 r219281  
    2828#include "TypeLocation.h"
    2929#include <unordered_map>
     30#include <wtf/FastMalloc.h>
    3031#include <wtf/HashMethod.h>
    3132
     
    5859
    5960    std::pair<TypeLocation*, bool> getTypeLocation(GlobalVariableID, intptr_t, unsigned start, unsigned end, RefPtr<TypeSet>&&, VM*);
    60 private:     
    61     typedef std::unordered_map<LocationKey, TypeLocation*, HashMethod<LocationKey>> LocationMap;
     61private:
     62    using LocationMap = std::unordered_map<LocationKey, TypeLocation*, HashMethod<LocationKey>, std::equal_to<LocationKey>, FastAllocator<std::pair<const LocationKey, TypeLocation*>>>;
    6263    LocationMap m_locationMap;
    6364};
  • trunk/Source/WTF/ChangeLog

    r219274 r219281  
     12017-07-09  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Use fastMalloc / fastFree for STL containers
     4        https://bugs.webkit.org/show_bug.cgi?id=174297
     5
     6        Reviewed by Sam Weinig.
     7
     8        * wtf/FastMalloc.h:
     9        (WTF::FastAllocator::FastAllocator):
     10        (WTF::FastAllocator::allocate):
     11        (WTF::FastAllocator::deallocate):
     12        (WTF::FastAllocator::operator==):
     13        (WTF::FastAllocator::operator!=):
     14
    1152017-07-07  Brent Fulgham  <bfulgham@apple.com>
    216
  • trunk/Source/WTF/wtf/FastMalloc.h

    r210840 r219281  
    105105}
    106106
     107// C++ STL allocator implementation. You can integrate fastMalloc into STL containers.
     108// e.g. std::unordered_map<Key, Value, std::hash<Key>, std::equal_to<Key>, FastAllocator<std::pair<const Key, Value>>>.
     109template<typename T>
     110class FastAllocator {
     111public:
     112    using value_type = T;
     113
     114    FastAllocator() = default;
     115
     116    template<typename U> FastAllocator(const FastAllocator<U>&) { }
     117
     118    T* allocate(size_t count)
     119    {
     120        return reinterpret_cast<T*>(fastMalloc(sizeof(T) * count));
     121    }
     122
     123    void deallocate(T* pointer, size_t)
     124    {
     125        fastFree(pointer);
     126    }
     127
     128    template<typename U> bool operator==(const FastAllocator<U>&) { return true; }
     129
     130    template<typename U> bool operator!=(const FastAllocator<U>&) { return false; }
     131};
     132
    107133} // namespace WTF
    108134
     
    126152using WTF::fastAlignedMalloc;
    127153using WTF::fastAlignedFree;
     154using WTF::FastAllocator;
    128155
    129156#if COMPILER(GCC_OR_CLANG) && OS(DARWIN)
Note: See TracChangeset for help on using the changeset viewer.