1 /* 2 * Copyright (C) 2013 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 #ifndef ART_LIBARTBASE_BASE_ARENA_BIT_VECTOR_H_ 18 #define ART_LIBARTBASE_BASE_ARENA_BIT_VECTOR_H_ 19 20 #include "arena_object.h" 21 #include "base/arena_allocator.h" 22 #include "bit_vector.h" 23 24 namespace art { 25 26 class ArenaAllocator; 27 class ScopedArenaAllocator; 28 29 /* 30 * A BitVector implementation that uses Arena allocation. 31 */ 32 class ArenaBitVector : public BitVector, public ArenaObject<kArenaAllocGrowableBitMap> { 33 public: 34 template <typename Allocator> 35 static ArenaBitVector* Create(Allocator* allocator, 36 uint32_t start_bits, 37 bool expandable, 38 ArenaAllocKind kind = kArenaAllocGrowableBitMap) { 39 void* storage = allocator->template Alloc<ArenaBitVector>(kind); 40 return new (storage) ArenaBitVector(allocator, start_bits, expandable, kind); 41 } 42 43 ArenaBitVector(ArenaAllocator* allocator, 44 uint32_t start_bits, 45 bool expandable, 46 ArenaAllocKind kind = kArenaAllocGrowableBitMap); 47 ArenaBitVector(ScopedArenaAllocator* allocator, 48 uint32_t start_bits, 49 bool expandable, 50 ArenaAllocKind kind = kArenaAllocGrowableBitMap); ~ArenaBitVector()51 ~ArenaBitVector() {} 52 53 ArenaBitVector(ArenaBitVector&&) = default; 54 ArenaBitVector(const ArenaBitVector&) = delete; 55 }; 56 57 // A BitVectorArray implementation that uses Arena allocation. See 58 // BitVectorArray for more information. 59 // This is a helper for dealing with 2d bit-vector arrays packed into a single 60 // bit-vector 61 class ArenaBitVectorArray final : public BaseBitVectorArray, 62 public ArenaObject<kArenaAllocGrowableBitMap> { 63 public: 64 ArenaBitVectorArray(const ArenaBitVectorArray& bv) = delete; 65 ArenaBitVectorArray& operator=(const ArenaBitVectorArray& other) = delete; 66 ArenaBitVectorArray(ArenaBitVector && bv)67 explicit ArenaBitVectorArray(ArenaBitVector&& bv) : BaseBitVectorArray(), data_(std::move(bv)) {} ArenaBitVectorArray(ArenaBitVector && bv,size_t cols)68 ArenaBitVectorArray(ArenaBitVector&& bv, size_t cols) 69 : BaseBitVectorArray(BaseBitVectorArray::MaxRowsFor(bv, cols), cols), data_(std::move(bv)) {} 70 71 ArenaBitVectorArray(ArenaAllocator* allocator, 72 size_t start_rows, 73 size_t start_cols, 74 bool expandable, 75 ArenaAllocKind kind = kArenaAllocGrowableBitMap) BaseBitVectorArray(start_rows,start_cols)76 : BaseBitVectorArray(start_rows, start_cols), 77 data_(ArenaBitVector(allocator, 78 BaseBitVectorArray::RequiredBitVectorSize(start_rows, start_cols), 79 expandable, 80 kind)) {} 81 82 ArenaBitVectorArray(ScopedArenaAllocator* allocator, 83 size_t start_rows, 84 size_t start_cols, 85 bool expandable, 86 ArenaAllocKind kind = kArenaAllocGrowableBitMap) BaseBitVectorArray(start_rows,start_cols)87 : BaseBitVectorArray(start_rows, start_cols), 88 data_(ArenaBitVector(allocator, 89 BaseBitVectorArray::RequiredBitVectorSize(start_rows, start_cols), 90 expandable, 91 kind)) {} 92 ~ArenaBitVectorArray()93 ~ArenaBitVectorArray() override {} 94 GetRawData()95 const BitVector& GetRawData() const override { 96 return data_; 97 } 98 GetRawData()99 BitVector& GetRawData() override { 100 return data_; 101 } 102 103 private: 104 ArenaBitVector data_; 105 }; 106 107 } // namespace art 108 109 #endif // ART_LIBARTBASE_BASE_ARENA_BIT_VECTOR_H_ 110