blob: 245e074294ec86f271abf03d098711a2690f91e9 [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
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080030namespace collector {
31 class ConcurrentCopying;
32} // namespace collector
33
Ian Rogers1d54e732013-05-02 21:10:01 -070034namespace accounting {
35
36class HeapBitmap {
37 public:
Mathieu Chartier4aeec172014-03-27 16:09:46 -070038 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 Chartierbbd695c2014-04-16 09:48:48 -070040 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 Chartiera8e8f9c2014-04-09 14:51:05 -070046 ContinuousSpaceBitmap* GetContinuousSpaceBitmap(const mirror::Object* obj) const;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080047 LargeObjectBitmap* GetLargeObjectBitmap(const mirror::Object* obj) const;
Ian Rogers1d54e732013-05-02 21:10:01 -070048
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080049 void Walk(ObjectCallback* callback, void* arg)
Ian Rogers1d54e732013-05-02 21:10:01 -070050 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 Chartiera8e8f9c2014-04-09 14:51:05 -070058 void ReplaceBitmap(ContinuousSpaceBitmap* old_bitmap, ContinuousSpaceBitmap* new_bitmap)
Ian Rogers1d54e732013-05-02 21:10:01 -070059 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 Chartierbbd695c2014-04-16 09:48:48 -070062 void ReplaceLargeObjectBitmap(LargeObjectBitmap* old_bitmap, LargeObjectBitmap* new_bitmap)
Ian Rogers1d54e732013-05-02 21:10:01 -070063 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
64
Brian Carlstrom93ba8932013-07-17 21:31:49 -070065 explicit HeapBitmap(Heap* heap) : heap_(heap) {}
Ian Rogers1d54e732013-05-02 21:10:01 -070066
67 private:
Ian Rogers1d54e732013-05-02 21:10:01 -070068 const Heap* const heap_;
69
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070070 void AddContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap);
71 void RemoveContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap);
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070072 void AddLargeObjectBitmap(LargeObjectBitmap* bitmap);
73 void RemoveLargeObjectBitmap(LargeObjectBitmap* bitmap);
Ian Rogers1d54e732013-05-02 21:10:01 -070074
75 // Bitmaps covering continuous spaces.
Mathieu Chartierbad02672014-08-25 13:08:22 -070076 std::vector<ContinuousSpaceBitmap*,
77 TrackingAllocator<ContinuousSpaceBitmap*, kAllocatorTagHeapBitmap>>
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070078 continuous_space_bitmaps_;
Ian Rogers1d54e732013-05-02 21:10:01 -070079
80 // Sets covering discontinuous spaces.
Mathieu Chartierbad02672014-08-25 13:08:22 -070081 std::vector<LargeObjectBitmap*,
82 TrackingAllocator<LargeObjectBitmap*, kAllocatorTagHeapBitmapLOS>>
83 large_object_bitmaps_;
Ian Rogers1d54e732013-05-02 21:10:01 -070084
85 friend class art::gc::Heap;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080086 friend class art::gc::collector::ConcurrentCopying;
Ian Rogers1d54e732013-05-02 21:10:01 -070087};
88
89} // namespace accounting
90} // namespace gc
91} // namespace art
92
Brian Carlstromfc0e3212013-07-17 14:40:12 -070093#endif // ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_