blob: fbbfd84fcf93d7e48797695a161c0b433c2dd019 [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_bit_vector.h"
buzbee862a7602013-04-05 10:58:54 -070018
Vladimir Marko3481ba22015-04-13 12:22:36 +010019#include "base/allocator.h"
Mathieu Chartierb666f482015-02-18 14:33:14 -080020#include "base/arena_allocator.h"
21
buzbee862a7602013-04-05 10:58:54 -070022namespace art {
23
Vladimir Markobfea9c22014-01-17 17:49:33 +000024template <typename ArenaAlloc>
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070025class ArenaBitVectorAllocator FINAL : public Allocator,
26 public ArenaObject<kArenaAllocGrowableBitMap> {
Brian Carlstrom413e89f2013-10-21 23:53:49 -070027 public:
Vladimir Markobfea9c22014-01-17 17:49:33 +000028 explicit ArenaBitVectorAllocator(ArenaAlloc* arena) : arena_(arena) {}
Brian Carlstrom413e89f2013-10-21 23:53:49 -070029 ~ArenaBitVectorAllocator() {}
30
31 virtual void* Alloc(size_t size) {
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000032 return arena_->Alloc(size, kArenaAllocGrowableBitMap);
Brian Carlstrom413e89f2013-10-21 23:53:49 -070033 }
34
35 virtual void Free(void*) {} // Nop.
36
Brian Carlstrom413e89f2013-10-21 23:53:49 -070037 private:
Ian Rogerse77493c2014-08-20 15:08:45 -070038 ArenaAlloc* const arena_;
Brian Carlstrom413e89f2013-10-21 23:53:49 -070039 DISALLOW_COPY_AND_ASSIGN(ArenaBitVectorAllocator);
40};
buzbee862a7602013-04-05 10:58:54 -070041
42ArenaBitVector::ArenaBitVector(ArenaAllocator* arena, unsigned int start_bits,
43 bool expandable, OatBitMapKind kind)
Vladimir Markobfea9c22014-01-17 17:49:33 +000044 : BitVector(start_bits, expandable,
45 new (arena) ArenaBitVectorAllocator<ArenaAllocator>(arena)), kind_(kind) {
46 UNUSED(kind_);
47}
48
49ArenaBitVector::ArenaBitVector(ScopedArenaAllocator* arena, unsigned int start_bits,
50 bool expandable, OatBitMapKind kind)
51 : BitVector(start_bits, expandable,
52 new (arena) ArenaBitVectorAllocator<ScopedArenaAllocator>(arena)), kind_(kind) {
Ian Rogersb48b9eb2014-02-28 16:20:21 -080053 UNUSED(kind_);
54}
buzbee862a7602013-04-05 10:58:54 -070055
buzbee862a7602013-04-05 10:58:54 -070056} // namespace art