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