blob: de35f3d1973d911ce8cc31e257cd59e108544efe [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"
Ian Rogerse77493c2014-08-20 15:08:45 -070019#include "base/allocator.h"
buzbee862a7602013-04-05 10:58:54 -070020
21namespace art {
22
Vladimir Markobfea9c22014-01-17 17:49:33 +000023template <typename ArenaAlloc>
Ian Rogerse77493c2014-08-20 15:08:45 -070024class ArenaBitVectorAllocator FINAL : public Allocator {
Brian Carlstrom413e89f2013-10-21 23:53:49 -070025 public:
Vladimir Markobfea9c22014-01-17 17:49:33 +000026 explicit ArenaBitVectorAllocator(ArenaAlloc* arena) : arena_(arena) {}
Brian Carlstrom413e89f2013-10-21 23:53:49 -070027 ~ArenaBitVectorAllocator() {}
28
29 virtual void* Alloc(size_t size) {
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000030 return arena_->Alloc(size, kArenaAllocGrowableBitMap);
Brian Carlstrom413e89f2013-10-21 23:53:49 -070031 }
32
33 virtual void Free(void*) {} // Nop.
34
Vladimir Markobfea9c22014-01-17 17:49:33 +000035 static void* operator new(size_t size, ArenaAlloc* arena) {
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000036 return arena->Alloc(sizeof(ArenaBitVectorAllocator), kArenaAllocGrowableBitMap);
Brian Carlstrom413e89f2013-10-21 23:53:49 -070037 }
38 static void operator delete(void* p) {} // Nop.
39
40 private:
Ian Rogerse77493c2014-08-20 15:08:45 -070041 ArenaAlloc* const arena_;
Brian Carlstrom413e89f2013-10-21 23:53:49 -070042 DISALLOW_COPY_AND_ASSIGN(ArenaBitVectorAllocator);
43};
buzbee862a7602013-04-05 10:58:54 -070044
45ArenaBitVector::ArenaBitVector(ArenaAllocator* arena, unsigned int start_bits,
46 bool expandable, OatBitMapKind kind)
Vladimir Markobfea9c22014-01-17 17:49:33 +000047 : BitVector(start_bits, expandable,
48 new (arena) ArenaBitVectorAllocator<ArenaAllocator>(arena)), kind_(kind) {
49 UNUSED(kind_);
50}
51
52ArenaBitVector::ArenaBitVector(ScopedArenaAllocator* arena, unsigned int start_bits,
53 bool expandable, OatBitMapKind kind)
54 : BitVector(start_bits, expandable,
55 new (arena) ArenaBitVectorAllocator<ScopedArenaAllocator>(arena)), kind_(kind) {
Ian Rogersb48b9eb2014-02-28 16:20:21 -080056 UNUSED(kind_);
57}
buzbee862a7602013-04-05 10:58:54 -070058
buzbee862a7602013-04-05 10:58:54 -070059} // namespace art