buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Nicolas Geoffray | 0e33643 | 2014-02-26 18:24:38 +0000 | [diff] [blame] | 17 | #include "arena_allocator.h" |
| 18 | #include "arena_bit_vector.h" |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 19 | |
| 20 | namespace art { |
| 21 | |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 22 | template <typename ArenaAlloc> |
Brian Carlstrom | 413e89f | 2013-10-21 23:53:49 -0700 | [diff] [blame] | 23 | class ArenaBitVectorAllocator : public Allocator { |
| 24 | public: |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 25 | explicit ArenaBitVectorAllocator(ArenaAlloc* arena) : arena_(arena) {} |
Brian Carlstrom | 413e89f | 2013-10-21 23:53:49 -0700 | [diff] [blame] | 26 | ~ArenaBitVectorAllocator() {} |
| 27 | |
| 28 | virtual void* Alloc(size_t size) { |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 29 | return arena_->Alloc(size, kArenaAllocGrowableBitMap); |
Brian Carlstrom | 413e89f | 2013-10-21 23:53:49 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | virtual void Free(void*) {} // Nop. |
| 33 | |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 34 | static void* operator new(size_t size, ArenaAlloc* arena) { |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 35 | return arena->Alloc(sizeof(ArenaBitVectorAllocator), kArenaAllocGrowableBitMap); |
Brian Carlstrom | 413e89f | 2013-10-21 23:53:49 -0700 | [diff] [blame] | 36 | } |
| 37 | static void operator delete(void* p) {} // Nop. |
| 38 | |
| 39 | private: |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 40 | ArenaAlloc* arena_; |
Brian Carlstrom | 413e89f | 2013-10-21 23:53:49 -0700 | [diff] [blame] | 41 | DISALLOW_COPY_AND_ASSIGN(ArenaBitVectorAllocator); |
| 42 | }; |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 43 | |
| 44 | ArenaBitVector::ArenaBitVector(ArenaAllocator* arena, unsigned int start_bits, |
| 45 | bool expandable, OatBitMapKind kind) |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 46 | : BitVector(start_bits, expandable, |
| 47 | new (arena) ArenaBitVectorAllocator<ArenaAllocator>(arena)), kind_(kind) { |
| 48 | UNUSED(kind_); |
| 49 | } |
| 50 | |
| 51 | ArenaBitVector::ArenaBitVector(ScopedArenaAllocator* arena, unsigned int start_bits, |
| 52 | bool expandable, OatBitMapKind kind) |
| 53 | : BitVector(start_bits, expandable, |
| 54 | new (arena) ArenaBitVectorAllocator<ScopedArenaAllocator>(arena)), kind_(kind) { |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 55 | UNUSED(kind_); |
| 56 | } |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 57 | |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 58 | } // namespace art |