ART: Use arena allocator with HashSet/HashMap.
Allow passing ArenaAllocatorAdapter (or any other allocator)
to HashSet/HashMap and create appropriate Arena- aliases.
Use the ArenaHashMap in StackMapsStream.
Update arena allocator adapters' construct()/destroy() to
C++11 std::allocator<> API.
Change-Id: I18544f718f84c6d6580228dd35297daf7f6afb5e
diff --git a/runtime/base/arena_containers.h b/runtime/base/arena_containers.h
index 66b5289..9174d2d 100644
--- a/runtime/base/arena_containers.h
+++ b/runtime/base/arena_containers.h
@@ -20,9 +20,12 @@
#include <deque>
#include <queue>
#include <set>
+#include <utility>
#include "arena_allocator.h"
#include "base/dchecked_vector.h"
+#include "hash_map.h"
+#include "hash_set.h"
#include "safe_map.h"
namespace art {
@@ -57,6 +60,24 @@
using ArenaSafeMap =
SafeMap<K, V, Comparator, ArenaAllocatorAdapter<std::pair<const K, V>>>;
+template <typename T,
+ typename EmptyFn = DefaultEmptyFn<T>,
+ typename HashFn = std::hash<T>,
+ typename Pred = std::equal_to<T>>
+using ArenaHashSet = HashSet<T, EmptyFn, HashFn, Pred, ArenaAllocatorAdapter<T>>;
+
+template <typename Key,
+ typename Value,
+ typename EmptyFn = DefaultEmptyFn<std::pair<Key, Value>>,
+ typename HashFn = std::hash<Key>,
+ typename Pred = std::equal_to<Key>>
+using ArenaHashMap = HashMap<Key,
+ Value,
+ EmptyFn,
+ HashFn,
+ Pred,
+ ArenaAllocatorAdapter<std::pair<Key, Value>>>;
+
// Implementation details below.
template <bool kCount>
@@ -164,11 +185,13 @@
arena_allocator_->MakeInaccessible(p, sizeof(T) * n);
}
- void construct(pointer p, const_reference val) {
- new (static_cast<void*>(p)) value_type(val);
+ template <typename U, typename... Args>
+ void construct(U* p, Args&&... args) {
+ ::new (static_cast<void*>(p)) U(std::forward<Args>(args)...);
}
- void destroy(pointer p) {
- p->~value_type();
+ template <typename U>
+ void destroy(U* p) {
+ p->~U();
}
private: