Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_ |
| 18 | #define ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_ |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 19 | |
Mathieu Chartier | bad0267 | 2014-08-25 13:08:22 -0700 | [diff] [blame] | 20 | #include "base/allocator.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 21 | #include "base/logging.h" |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 22 | #include "object_callbacks.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 23 | #include "space_bitmap.h" |
| 24 | |
| 25 | namespace art { |
| 26 | namespace gc { |
| 27 | |
| 28 | class Heap; |
| 29 | |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 30 | namespace collector { |
| 31 | class ConcurrentCopying; |
| 32 | } // namespace collector |
| 33 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 34 | namespace accounting { |
| 35 | |
| 36 | class HeapBitmap { |
| 37 | public: |
Mathieu Chartier | 4aeec17 | 2014-03-27 16:09:46 -0700 | [diff] [blame] | 38 | bool Test(const mirror::Object* obj) SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); |
| 39 | void Clear(const mirror::Object* obj) EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); |
Mathieu Chartier | bbd695c | 2014-04-16 09:48:48 -0700 | [diff] [blame] | 40 | template<typename LargeObjectSetVisitor> |
| 41 | bool Set(const mirror::Object* obj, const LargeObjectSetVisitor& visitor) |
| 42 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) ALWAYS_INLINE; |
| 43 | template<typename LargeObjectSetVisitor> |
| 44 | bool AtomicTestAndSet(const mirror::Object* obj, const LargeObjectSetVisitor& visitor) |
| 45 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) ALWAYS_INLINE; |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 46 | ContinuousSpaceBitmap* GetContinuousSpaceBitmap(const mirror::Object* obj) const; |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 47 | LargeObjectBitmap* GetLargeObjectBitmap(const mirror::Object* obj) const; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 48 | |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 49 | void Walk(ObjectCallback* callback, void* arg) |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 50 | SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); |
| 51 | |
| 52 | template <typename Visitor> |
| 53 | void Visit(const Visitor& visitor) |
| 54 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) |
| 55 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 56 | |
| 57 | // Find and replace a bitmap pointer, this is used by for the bitmap swapping in the GC. |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 58 | void ReplaceBitmap(ContinuousSpaceBitmap* old_bitmap, ContinuousSpaceBitmap* new_bitmap) |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 59 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); |
| 60 | |
| 61 | // Find and replace a object set pointer, this is used by for the bitmap swapping in the GC. |
Mathieu Chartier | bbd695c | 2014-04-16 09:48:48 -0700 | [diff] [blame] | 62 | void ReplaceLargeObjectBitmap(LargeObjectBitmap* old_bitmap, LargeObjectBitmap* new_bitmap) |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 63 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); |
| 64 | |
Brian Carlstrom | 93ba893 | 2013-07-17 21:31:49 -0700 | [diff] [blame] | 65 | explicit HeapBitmap(Heap* heap) : heap_(heap) {} |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 66 | |
| 67 | private: |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 68 | const Heap* const heap_; |
| 69 | |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 70 | void AddContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap); |
| 71 | void RemoveContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap); |
Mathieu Chartier | bbd695c | 2014-04-16 09:48:48 -0700 | [diff] [blame] | 72 | void AddLargeObjectBitmap(LargeObjectBitmap* bitmap); |
| 73 | void RemoveLargeObjectBitmap(LargeObjectBitmap* bitmap); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 74 | |
| 75 | // Bitmaps covering continuous spaces. |
Mathieu Chartier | bad0267 | 2014-08-25 13:08:22 -0700 | [diff] [blame] | 76 | std::vector<ContinuousSpaceBitmap*, |
| 77 | TrackingAllocator<ContinuousSpaceBitmap*, kAllocatorTagHeapBitmap>> |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 78 | continuous_space_bitmaps_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 79 | |
| 80 | // Sets covering discontinuous spaces. |
Mathieu Chartier | bad0267 | 2014-08-25 13:08:22 -0700 | [diff] [blame] | 81 | std::vector<LargeObjectBitmap*, |
| 82 | TrackingAllocator<LargeObjectBitmap*, kAllocatorTagHeapBitmapLOS>> |
| 83 | large_object_bitmaps_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 84 | |
| 85 | friend class art::gc::Heap; |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 86 | friend class art::gc::collector::ConcurrentCopying; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | } // namespace accounting |
| 90 | } // namespace gc |
| 91 | } // namespace art |
| 92 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 93 | #endif // ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_ |