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
17 #include "arena_allocator.h"
18 #include "arena_bit_vector.h"
19
20 namespace art {
21
22 template <typename ArenaAlloc>
23 class ArenaBitVectorAllocator : public Allocator {
24 public:
ArenaBitVectorAllocator(ArenaAlloc * arena)25 explicit ArenaBitVectorAllocator(ArenaAlloc* arena) : arena_(arena) {}
~ArenaBitVectorAllocator()26 ~ArenaBitVectorAllocator() {}
27
Alloc(size_t size)28 virtual void* Alloc(size_t size) {
29 return arena_->Alloc(size, kArenaAllocGrowableBitMap);
30 }
31
Free(void *)32 virtual void Free(void*) {} // Nop.
33
operator new(size_t size,ArenaAlloc * arena)34 static void* operator new(size_t size, ArenaAlloc* arena) {
35 return arena->Alloc(sizeof(ArenaBitVectorAllocator), kArenaAllocGrowableBitMap);
36 }
operator delete(void * p)37 static void operator delete(void* p) {} // Nop.
38
39 private:
40 ArenaAlloc* arena_;
41 DISALLOW_COPY_AND_ASSIGN(ArenaBitVectorAllocator);
42 };
43
ArenaBitVector(ArenaAllocator * arena,unsigned int start_bits,bool expandable,OatBitMapKind kind)44 ArenaBitVector::ArenaBitVector(ArenaAllocator* arena, unsigned int start_bits,
45 bool expandable, OatBitMapKind kind)
46 : BitVector(start_bits, expandable,
47 new (arena) ArenaBitVectorAllocator<ArenaAllocator>(arena)), kind_(kind) {
48 UNUSED(kind_);
49 }
50
ArenaBitVector(ScopedArenaAllocator * arena,unsigned int start_bits,bool expandable,OatBitMapKind kind)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) {
55 UNUSED(kind_);
56 }
57
58 } // namespace art
59