1 /* 2 * Copyright (C) 2012 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_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_ 18 #define ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_ 19 20 #include <android-base/logging.h> 21 22 #include "base/allocator.h" 23 #include "base/locks.h" 24 #include "base/macros.h" 25 #include "space_bitmap.h" 26 27 namespace art { 28 namespace gc { 29 30 class Heap; 31 32 namespace collector { 33 class ConcurrentCopying; 34 } // namespace collector 35 36 namespace accounting { 37 38 class HeapBitmap { 39 public: 40 bool Test(const mirror::Object* obj) REQUIRES_SHARED(Locks::heap_bitmap_lock_); 41 void Clear(const mirror::Object* obj) REQUIRES(Locks::heap_bitmap_lock_); 42 template<typename LargeObjectSetVisitor> 43 bool Set(const mirror::Object* obj, const LargeObjectSetVisitor& visitor) 44 REQUIRES_SHARED(Locks::mutator_lock_) 45 REQUIRES(Locks::heap_bitmap_lock_) ALWAYS_INLINE; 46 template<typename LargeObjectSetVisitor> 47 bool AtomicTestAndSet(const mirror::Object* obj, const LargeObjectSetVisitor& visitor) 48 REQUIRES_SHARED(Locks::mutator_lock_) 49 REQUIRES(Locks::heap_bitmap_lock_) ALWAYS_INLINE; 50 ContinuousSpaceBitmap* GetContinuousSpaceBitmap(const mirror::Object* obj) const; 51 LargeObjectBitmap* GetLargeObjectBitmap(const mirror::Object* obj) const; 52 53 template <typename Visitor> 54 ALWAYS_INLINE void Visit(Visitor&& visitor) 55 REQUIRES(Locks::heap_bitmap_lock_) 56 REQUIRES_SHARED(Locks::mutator_lock_); 57 HeapBitmap(Heap * heap)58 explicit HeapBitmap(Heap* heap) : heap_(heap) {} 59 60 private: 61 const Heap* const heap_; 62 63 void AddContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap); 64 void RemoveContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap); 65 void AddLargeObjectBitmap(LargeObjectBitmap* bitmap); 66 void RemoveLargeObjectBitmap(LargeObjectBitmap* bitmap); 67 68 // Bitmaps covering continuous spaces. 69 std::vector<ContinuousSpaceBitmap*, 70 TrackingAllocator<ContinuousSpaceBitmap*, kAllocatorTagHeapBitmap>> 71 continuous_space_bitmaps_; 72 73 // Sets covering discontinuous spaces. 74 std::vector<LargeObjectBitmap*, 75 TrackingAllocator<LargeObjectBitmap*, kAllocatorTagHeapBitmapLOS>> 76 large_object_bitmaps_; 77 78 friend class art::gc::Heap; 79 friend class art::gc::collector::ConcurrentCopying; 80 }; 81 82 } // namespace accounting 83 } // namespace gc 84 } // namespace art 85 86 #endif // ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_ 87