blob: 0b96979a30627c8f30e28f6cd1b409b46ee0016a [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 Chartier90443472015-07-16 20:32:27 -070038 bool Test(const mirror::Object* obj) SHARED_REQUIRES(Locks::heap_bitmap_lock_);
39 void Clear(const mirror::Object* obj) REQUIRES(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)
Mathieu Chartier90443472015-07-16 20:32:27 -070042 SHARED_REQUIRES(Locks::mutator_lock_)
43 REQUIRES(Locks::heap_bitmap_lock_) ALWAYS_INLINE;
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070044 template<typename LargeObjectSetVisitor>
45 bool AtomicTestAndSet(const mirror::Object* obj, const LargeObjectSetVisitor& visitor)
Mathieu Chartier90443472015-07-16 20:32:27 -070046 SHARED_REQUIRES(Locks::mutator_lock_)
47 REQUIRES(Locks::heap_bitmap_lock_) ALWAYS_INLINE;
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070048 ContinuousSpaceBitmap* GetContinuousSpaceBitmap(const mirror::Object* obj) const;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080049 LargeObjectBitmap* GetLargeObjectBitmap(const mirror::Object* obj) const;
Ian Rogers1d54e732013-05-02 21:10:01 -070050
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080051 void Walk(ObjectCallback* callback, void* arg)
Mathieu Chartier90443472015-07-16 20:32:27 -070052 SHARED_REQUIRES(Locks::heap_bitmap_lock_);
Ian Rogers1d54e732013-05-02 21:10:01 -070053
54 template <typename Visitor>
55 void Visit(const Visitor& visitor)
Mathieu Chartier90443472015-07-16 20:32:27 -070056 REQUIRES(Locks::heap_bitmap_lock_)
57 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers1d54e732013-05-02 21:10:01 -070058
59 // Find and replace a bitmap pointer, this is used by for the bitmap swapping in the GC.
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070060 void ReplaceBitmap(ContinuousSpaceBitmap* old_bitmap, ContinuousSpaceBitmap* new_bitmap)
Mathieu Chartier90443472015-07-16 20:32:27 -070061 REQUIRES(Locks::heap_bitmap_lock_);
Ian Rogers1d54e732013-05-02 21:10:01 -070062
63 // 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 -070064 void ReplaceLargeObjectBitmap(LargeObjectBitmap* old_bitmap, LargeObjectBitmap* new_bitmap)
Mathieu Chartier90443472015-07-16 20:32:27 -070065 REQUIRES(Locks::heap_bitmap_lock_);
Ian Rogers1d54e732013-05-02 21:10:01 -070066
Brian Carlstrom93ba8932013-07-17 21:31:49 -070067 explicit HeapBitmap(Heap* heap) : heap_(heap) {}
Ian Rogers1d54e732013-05-02 21:10:01 -070068
69 private:
Ian Rogers1d54e732013-05-02 21:10:01 -070070 const Heap* const heap_;
71
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070072 void AddContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap);
73 void RemoveContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap);
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070074 void AddLargeObjectBitmap(LargeObjectBitmap* bitmap);
75 void RemoveLargeObjectBitmap(LargeObjectBitmap* bitmap);
Ian Rogers1d54e732013-05-02 21:10:01 -070076
77 // Bitmaps covering continuous spaces.
Mathieu Chartierbad02672014-08-25 13:08:22 -070078 std::vector<ContinuousSpaceBitmap*,
79 TrackingAllocator<ContinuousSpaceBitmap*, kAllocatorTagHeapBitmap>>
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070080 continuous_space_bitmaps_;
Ian Rogers1d54e732013-05-02 21:10:01 -070081
82 // Sets covering discontinuous spaces.
Mathieu Chartierbad02672014-08-25 13:08:22 -070083 std::vector<LargeObjectBitmap*,
84 TrackingAllocator<LargeObjectBitmap*, kAllocatorTagHeapBitmapLOS>>
85 large_object_bitmaps_;
Ian Rogers1d54e732013-05-02 21:10:01 -070086
87 friend class art::gc::Heap;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080088 friend class art::gc::collector::ConcurrentCopying;
Ian Rogers1d54e732013-05-02 21:10:01 -070089};
90
91} // namespace accounting
92} // namespace gc
93} // namespace art
94
Brian Carlstromfc0e3212013-07-17 14:40:12 -070095#endif // ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_