blob: ca6dc46bde69215278943475a00f6a08582b4f3f [file] [log] [blame]
Ian Rogers1d54e732013-05-02 21:10:01 -07001/*
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 Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_
18#define ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_
Ian Rogers1d54e732013-05-02 21:10:01 -070019
Mathieu Chartierbad02672014-08-25 13:08:22 -070020#include "base/allocator.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070021#include "base/logging.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080022#include "object_callbacks.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070023#include "space_bitmap.h"
24
25namespace art {
26namespace gc {
27
28class Heap;
29
30namespace accounting {
31
32class HeapBitmap {
33 public:
Mathieu Chartier4aeec172014-03-27 16:09:46 -070034 bool Test(const mirror::Object* obj) SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
35 void Clear(const mirror::Object* obj) EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070036 template<typename LargeObjectSetVisitor>
37 bool Set(const mirror::Object* obj, const LargeObjectSetVisitor& visitor)
38 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) ALWAYS_INLINE;
39 template<typename LargeObjectSetVisitor>
40 bool AtomicTestAndSet(const mirror::Object* obj, const LargeObjectSetVisitor& visitor)
41 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) ALWAYS_INLINE;
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070042 ContinuousSpaceBitmap* GetContinuousSpaceBitmap(const mirror::Object* obj) const;
Ian Rogers1d54e732013-05-02 21:10:01 -070043
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080044 void Walk(ObjectCallback* callback, void* arg)
Ian Rogers1d54e732013-05-02 21:10:01 -070045 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
46
47 template <typename Visitor>
48 void Visit(const Visitor& visitor)
49 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
50 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
51
52 // Find and replace a bitmap pointer, this is used by for the bitmap swapping in the GC.
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070053 void ReplaceBitmap(ContinuousSpaceBitmap* old_bitmap, ContinuousSpaceBitmap* new_bitmap)
Ian Rogers1d54e732013-05-02 21:10:01 -070054 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
55
56 // Find and replace a object set pointer, this is used by for the bitmap swapping in the GC.
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070057 void ReplaceLargeObjectBitmap(LargeObjectBitmap* old_bitmap, LargeObjectBitmap* new_bitmap)
Ian Rogers1d54e732013-05-02 21:10:01 -070058 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
59
Brian Carlstrom93ba8932013-07-17 21:31:49 -070060 explicit HeapBitmap(Heap* heap) : heap_(heap) {}
Ian Rogers1d54e732013-05-02 21:10:01 -070061
62 private:
Ian Rogers1d54e732013-05-02 21:10:01 -070063 const Heap* const heap_;
64
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070065 void AddContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap);
66 void RemoveContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap);
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070067 void AddLargeObjectBitmap(LargeObjectBitmap* bitmap);
68 void RemoveLargeObjectBitmap(LargeObjectBitmap* bitmap);
Ian Rogers1d54e732013-05-02 21:10:01 -070069
70 // Bitmaps covering continuous spaces.
Mathieu Chartierbad02672014-08-25 13:08:22 -070071 std::vector<ContinuousSpaceBitmap*,
72 TrackingAllocator<ContinuousSpaceBitmap*, kAllocatorTagHeapBitmap>>
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070073 continuous_space_bitmaps_;
Ian Rogers1d54e732013-05-02 21:10:01 -070074
75 // Sets covering discontinuous spaces.
Mathieu Chartierbad02672014-08-25 13:08:22 -070076 std::vector<LargeObjectBitmap*,
77 TrackingAllocator<LargeObjectBitmap*, kAllocatorTagHeapBitmapLOS>>
78 large_object_bitmaps_;
Ian Rogers1d54e732013-05-02 21:10:01 -070079
80 friend class art::gc::Heap;
81};
82
83} // namespace accounting
84} // namespace gc
85} // namespace art
86
Brian Carlstromfc0e3212013-07-17 14:40:12 -070087#endif // ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_