blob: 39f7d185a62ee5e622341ce948377e0489780397 [file] [log] [blame]
buzbee862a7602013-04-05 10:58:54 -07001/*
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 Geoffray0e336432014-02-26 18:24:38 +000017#include "arena_allocator.h"
18#include "arena_bit_vector.h"
buzbee862a7602013-04-05 10:58:54 -070019
20namespace art {
21
Vladimir Markobfea9c22014-01-17 17:49:33 +000022template <typename ArenaAlloc>
Brian Carlstrom413e89f2013-10-21 23:53:49 -070023class ArenaBitVectorAllocator : public Allocator {
24 public:
Vladimir Markobfea9c22014-01-17 17:49:33 +000025 explicit ArenaBitVectorAllocator(ArenaAlloc* arena) : arena_(arena) {}
Brian Carlstrom413e89f2013-10-21 23:53:49 -070026 ~ArenaBitVectorAllocator() {}
27
28 virtual void* Alloc(size_t size) {
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000029 return arena_->Alloc(size, kArenaAllocGrowableBitMap);
Brian Carlstrom413e89f2013-10-21 23:53:49 -070030 }
31
32 virtual void Free(void*) {} // Nop.
33
Vladimir Markobfea9c22014-01-17 17:49:33 +000034 static void* operator new(size_t size, ArenaAlloc* arena) {
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000035 return arena->Alloc(sizeof(ArenaBitVectorAllocator), kArenaAllocGrowableBitMap);
Brian Carlstrom413e89f2013-10-21 23:53:49 -070036 }
37 static void operator delete(void* p) {} // Nop.
38
39 private:
Vladimir Markobfea9c22014-01-17 17:49:33 +000040 ArenaAlloc* arena_;
Brian Carlstrom413e89f2013-10-21 23:53:49 -070041 DISALLOW_COPY_AND_ASSIGN(ArenaBitVectorAllocator);
42};
buzbee862a7602013-04-05 10:58:54 -070043
44ArenaBitVector::ArenaBitVector(ArenaAllocator* arena, unsigned int start_bits,
45 bool expandable, OatBitMapKind kind)
Vladimir Markobfea9c22014-01-17 17:49:33 +000046 : BitVector(start_bits, expandable,
47 new (arena) ArenaBitVectorAllocator<ArenaAllocator>(arena)), kind_(kind) {
48 UNUSED(kind_);
49}
50
51ArenaBitVector::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 Rogersb48b9eb2014-02-28 16:20:21 -080055 UNUSED(kind_);
56}
buzbee862a7602013-04-05 10:58:54 -070057
buzbee862a7602013-04-05 10:58:54 -070058} // namespace art