Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (219280 => 219281)
--- trunk/Source/_javascript_Core/ChangeLog 2017-07-09 05:05:41 UTC (rev 219280)
+++ trunk/Source/_javascript_Core/ChangeLog 2017-07-09 12:22:58 UTC (rev 219281)
@@ -1,3 +1,28 @@
+2017-07-09 Yusuke Suzuki <utatane....@gmail.com>
+
+ [JSC] Use fastMalloc / fastFree for STL containers
+ https://bugs.webkit.org/show_bug.cgi?id=174297
+
+ Reviewed by Sam Weinig.
+
+ 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:
+
2017-07-08 Yusuke Suzuki <utatane....@gmail.com>
Drop NOSNIFF compile flag
Modified: trunk/Source/_javascript_Core/dfg/DFGGraph.h (219280 => 219281)
--- trunk/Source/_javascript_Core/dfg/DFGGraph.h 2017-07-09 05:05:41 UTC (rev 219280)
+++ trunk/Source/_javascript_Core/dfg/DFGGraph.h 2017-07-09 12:22:58 UTC (rev 219281)
@@ -997,7 +997,7 @@
HashMap<const StringImpl*, String> m_copiedStrings;
#if USE(JSVALUE32_64)
- std::unordered_map<int64_t, double*> m_doubleConstantsMap;
+ std::unordered_map<int64_t, double*, std::hash<int64_t>, std::equal_to<int64_t>, FastAllocator<std::pair<const int64_t, double*>>> m_doubleConstantsMap;
std::unique_ptr<Bag<double>> m_doubleConstants;
#endif
Modified: trunk/Source/_javascript_Core/dfg/DFGIntegerCheckCombiningPhase.cpp (219280 => 219281)
--- trunk/Source/_javascript_Core/dfg/DFGIntegerCheckCombiningPhase.cpp 2017-07-09 05:05:41 UTC (rev 219280)
+++ trunk/Source/_javascript_Core/dfg/DFGIntegerCheckCombiningPhase.cpp 2017-07-09 12:22:58 UTC (rev 219281)
@@ -396,7 +396,7 @@
nodeIndex, origin, jsNumber(addend), source.useKind()));
}
- typedef std::unordered_map<RangeKey, Range, HashMethod<RangeKey>> RangeMap;
+ using RangeMap = std::unordered_map<RangeKey, Range, HashMethod<RangeKey>, std::equal_to<RangeKey>, FastAllocator<std::pair<const RangeKey, Range>>>;
RangeMap m_map;
InsertionSet m_insertionSet;
Modified: trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp (219280 => 219281)
--- trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp 2017-07-09 05:05:41 UTC (rev 219280)
+++ trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp 2017-07-09 12:22:58 UTC (rev 219281)
@@ -11849,7 +11849,8 @@
StringJumpTable& table = codeBlock()->stringSwitchJumpTable(data->switchTableIndex);
Vector<SwitchCase> cases;
- 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.
+ // 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.
+ std::unordered_set<int32_t, std::hash<int32_t>, std::equal_to<int32_t>, FastAllocator<int32_t>> alreadyHandled;
for (unsigned i = 0; i < data->cases.size(); ++i) {
// FIXME: The fact that we're using the bytecode's switch table means that the
// following DFG IR transformation would be invalid.
Modified: trunk/Source/_javascript_Core/runtime/FunctionHasExecutedCache.h (219280 => 219281)
--- trunk/Source/_javascript_Core/runtime/FunctionHasExecutedCache.h 2017-07-09 05:05:41 UTC (rev 219280)
+++ trunk/Source/_javascript_Core/runtime/FunctionHasExecutedCache.h 2017-07-09 12:22:58 UTC (rev 219281)
@@ -53,9 +53,9 @@
void removeUnexecutedRange(intptr_t id, unsigned start, unsigned end);
Vector<std::tuple<bool, unsigned, unsigned>> getFunctionRanges(intptr_t id);
-private:
- typedef std::unordered_map<FunctionRange, bool, HashMethod<FunctionRange>> RangeMap;
- typedef std::unordered_map<intptr_t, RangeMap> SourceIDToRangeMap;
+private:
+ using RangeMap = std::unordered_map<FunctionRange, bool, HashMethod<FunctionRange>, std::equal_to<FunctionRange>, FastAllocator<std::pair<const FunctionRange, bool>>>;
+ using SourceIDToRangeMap = std::unordered_map<intptr_t, RangeMap, std::hash<intptr_t>, std::equal_to<intptr_t>, FastAllocator<std::pair<const intptr_t, RangeMap>>>;
SourceIDToRangeMap m_rangeMap;
};
Modified: trunk/Source/_javascript_Core/runtime/TypeLocationCache.h (219280 => 219281)
--- trunk/Source/_javascript_Core/runtime/TypeLocationCache.h 2017-07-09 05:05:41 UTC (rev 219280)
+++ trunk/Source/_javascript_Core/runtime/TypeLocationCache.h 2017-07-09 12:22:58 UTC (rev 219281)
@@ -27,6 +27,7 @@
#include "TypeLocation.h"
#include <unordered_map>
+#include <wtf/FastMalloc.h>
#include <wtf/HashMethod.h>
namespace JSC {
@@ -57,8 +58,8 @@
};
std::pair<TypeLocation*, bool> getTypeLocation(GlobalVariableID, intptr_t, unsigned start, unsigned end, RefPtr<TypeSet>&&, VM*);
-private:
- typedef std::unordered_map<LocationKey, TypeLocation*, HashMethod<LocationKey>> LocationMap;
+private:
+ using LocationMap = std::unordered_map<LocationKey, TypeLocation*, HashMethod<LocationKey>, std::equal_to<LocationKey>, FastAllocator<std::pair<const LocationKey, TypeLocation*>>>;
LocationMap m_locationMap;
};
Modified: trunk/Source/WTF/ChangeLog (219280 => 219281)
--- trunk/Source/WTF/ChangeLog 2017-07-09 05:05:41 UTC (rev 219280)
+++ trunk/Source/WTF/ChangeLog 2017-07-09 12:22:58 UTC (rev 219281)
@@ -1,3 +1,17 @@
+2017-07-09 Yusuke Suzuki <utatane....@gmail.com>
+
+ [JSC] Use fastMalloc / fastFree for STL containers
+ https://bugs.webkit.org/show_bug.cgi?id=174297
+
+ Reviewed by Sam Weinig.
+
+ * wtf/FastMalloc.h:
+ (WTF::FastAllocator::FastAllocator):
+ (WTF::FastAllocator::allocate):
+ (WTF::FastAllocator::deallocate):
+ (WTF::FastAllocator::operator==):
+ (WTF::FastAllocator::operator!=):
+
2017-07-07 Brent Fulgham <bfulg...@apple.com>
[WK2] Use a rolling 30-day uptime for processing statistics
Modified: trunk/Source/WTF/wtf/FastMalloc.h (219280 => 219281)
--- trunk/Source/WTF/wtf/FastMalloc.h 2017-07-09 05:05:41 UTC (rev 219280)
+++ trunk/Source/WTF/wtf/FastMalloc.h 2017-07-09 12:22:58 UTC (rev 219281)
@@ -104,6 +104,32 @@
return data;
}
+// C++ STL allocator implementation. You can integrate fastMalloc into STL containers.
+// e.g. std::unordered_map<Key, Value, std::hash<Key>, std::equal_to<Key>, FastAllocator<std::pair<const Key, Value>>>.
+template<typename T>
+class FastAllocator {
+public:
+ using value_type = T;
+
+ FastAllocator() = default;
+
+ template<typename U> FastAllocator(const FastAllocator<U>&) { }
+
+ T* allocate(size_t count)
+ {
+ return reinterpret_cast<T*>(fastMalloc(sizeof(T) * count));
+ }
+
+ void deallocate(T* pointer, size_t)
+ {
+ fastFree(pointer);
+ }
+
+ template<typename U> bool operator==(const FastAllocator<U>&) { return true; }
+
+ template<typename U> bool operator!=(const FastAllocator<U>&) { return false; }
+};
+
} // namespace WTF
#if !defined(NDEBUG)
@@ -125,6 +151,7 @@
using WTF::tryFastZeroedMalloc;
using WTF::fastAlignedMalloc;
using WTF::fastAlignedFree;
+using WTF::FastAllocator;
#if COMPILER(GCC_OR_CLANG) && OS(DARWIN)
#define WTF_PRIVATE_INLINE __private_extern__ inline __attribute__((always_inline))