From b666f4805c8ae707ea6fd7f6c7f375e0b000dba8 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Wed, 18 Feb 2015 14:33:14 -0800 Subject: Move arenas into runtime Moved arena pool into the runtime. Motivation: Allow GC to use arena allocators, recycle arena pool for linear alloc. Bug: 19264997 Change-Id: I8ddbb6d55ee923a980b28fb656c758c5d7697c2f --- compiler/utils/arena_containers.h | 206 -------------------------------------- 1 file changed, 206 deletions(-) delete mode 100644 compiler/utils/arena_containers.h (limited to 'compiler/utils/arena_containers.h') diff --git a/compiler/utils/arena_containers.h b/compiler/utils/arena_containers.h deleted file mode 100644 index a7a7438849..0000000000 --- a/compiler/utils/arena_containers.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ART_COMPILER_UTILS_ARENA_CONTAINERS_H_ -#define ART_COMPILER_UTILS_ARENA_CONTAINERS_H_ - -#include -#include -#include -#include - -#include "utils/arena_allocator.h" -#include "safe_map.h" - -namespace art { - -// Adapter for use of ArenaAllocator in STL containers. -// Use ArenaAllocator::Adapter() to create an adapter to pass to container constructors. -// For example, -// struct Foo { -// explicit Foo(ArenaAllocator* allocator) -// : foo_vector(allocator->Adapter(kArenaAllocMisc)), -// foo_map(std::less(), allocator->Adapter()) { -// } -// ArenaVector foo_vector; -// ArenaSafeMap foo_map; -// }; -template -class ArenaAllocatorAdapter; - -template -using ArenaDeque = std::deque>; - -template -using ArenaQueue = std::queue>; - -template -using ArenaVector = std::vector>; - -template > -using ArenaSet = std::set>; - -template > -using ArenaSafeMap = - SafeMap>>; - -// Implementation details below. - -template -class ArenaAllocatorAdapterKindImpl; - -template <> -class ArenaAllocatorAdapterKindImpl { - public: - // Not tracking allocations, ignore the supplied kind and arbitrarily provide kArenaAllocSTL. - explicit ArenaAllocatorAdapterKindImpl(ArenaAllocKind kind) { UNUSED(kind); } - ArenaAllocatorAdapterKindImpl& operator=(const ArenaAllocatorAdapterKindImpl& other) = default; - ArenaAllocKind Kind() { return kArenaAllocSTL; } -}; - -template -class ArenaAllocatorAdapterKindImpl { - public: - explicit ArenaAllocatorAdapterKindImpl(ArenaAllocKind kind) : kind_(kind) { } - ArenaAllocatorAdapterKindImpl& operator=(const ArenaAllocatorAdapterKindImpl& other) = default; - ArenaAllocKind Kind() { return kind_; } - - private: - ArenaAllocKind kind_; -}; - -typedef ArenaAllocatorAdapterKindImpl ArenaAllocatorAdapterKind; - -template <> -class ArenaAllocatorAdapter - : private DebugStackReference, private ArenaAllocatorAdapterKind { - public: - typedef void value_type; - typedef void* pointer; - typedef const void* const_pointer; - - template - struct rebind { - typedef ArenaAllocatorAdapter other; - }; - - explicit ArenaAllocatorAdapter(ArenaAllocator* arena_allocator, - ArenaAllocKind kind = kArenaAllocSTL) - : DebugStackReference(arena_allocator), - ArenaAllocatorAdapterKind(kind), - arena_allocator_(arena_allocator) { - } - template - ArenaAllocatorAdapter(const ArenaAllocatorAdapter& other) - : DebugStackReference(other), - ArenaAllocatorAdapterKind(other), - arena_allocator_(other.arena_allocator_) { - } - ArenaAllocatorAdapter(const ArenaAllocatorAdapter& other) = default; - ArenaAllocatorAdapter& operator=(const ArenaAllocatorAdapter& other) = default; - ~ArenaAllocatorAdapter() = default; - - private: - ArenaAllocator* arena_allocator_; - - template - friend class ArenaAllocatorAdapter; -}; - -template -class ArenaAllocatorAdapter : private DebugStackReference, private ArenaAllocatorAdapterKind { - public: - typedef T value_type; - typedef T* pointer; - typedef T& reference; - typedef const T* const_pointer; - typedef const T& const_reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - - template - struct rebind { - typedef ArenaAllocatorAdapter other; - }; - - explicit ArenaAllocatorAdapter(ArenaAllocator* arena_allocator, ArenaAllocKind kind) - : DebugStackReference(arena_allocator), - ArenaAllocatorAdapterKind(kind), - arena_allocator_(arena_allocator) { - } - template - ArenaAllocatorAdapter(const ArenaAllocatorAdapter& other) - : DebugStackReference(other), - ArenaAllocatorAdapterKind(other), - arena_allocator_(other.arena_allocator_) { - } - ArenaAllocatorAdapter(const ArenaAllocatorAdapter& other) = default; - ArenaAllocatorAdapter& operator=(const ArenaAllocatorAdapter& other) = default; - ~ArenaAllocatorAdapter() = default; - - size_type max_size() const { - return static_cast(-1) / sizeof(T); - } - - pointer address(reference x) const { return &x; } - const_pointer address(const_reference x) const { return &x; } - - pointer allocate(size_type n, ArenaAllocatorAdapter::pointer hint = nullptr) { - UNUSED(hint); - DCHECK_LE(n, max_size()); - return arena_allocator_->AllocArray(n, ArenaAllocatorAdapterKind::Kind()); - } - void deallocate(pointer p, size_type n) { - UNUSED(p, n); - } - - void construct(pointer p, const_reference val) { - new (static_cast(p)) value_type(val); - } - void destroy(pointer p) { - p->~value_type(); - } - - private: - ArenaAllocator* arena_allocator_; - - template - friend class ArenaAllocatorAdapter; - - template - friend bool operator==(const ArenaAllocatorAdapter& lhs, - const ArenaAllocatorAdapter& rhs); -}; - -template -inline bool operator==(const ArenaAllocatorAdapter& lhs, - const ArenaAllocatorAdapter& rhs) { - return lhs.arena_allocator_ == rhs.arena_allocator_; -} - -template -inline bool operator!=(const ArenaAllocatorAdapter& lhs, - const ArenaAllocatorAdapter& rhs) { - return !(lhs == rhs); -} - -inline ArenaAllocatorAdapter ArenaAllocator::Adapter(ArenaAllocKind kind) { - return ArenaAllocatorAdapter(this, kind); -} - -} // namespace art - -#endif // ART_COMPILER_UTILS_ARENA_CONTAINERS_H_ -- cgit v1.2.3-59-g8ed1b