blob: 1648aef51fe67393c5f04df8cb6e604b5ea9d97d [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)
Hiroshi Yamauchieb2baaf2015-05-13 21:14:22 -070042 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070043 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) ALWAYS_INLINE;
44 template<typename LargeObjectSetVisitor>
45 bool AtomicTestAndSet(const mirror::Object* obj, const LargeObjectSetVisitor& visitor)
Hiroshi Yamauchieb2baaf2015-05-13 21:14:22 -070046 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070047 EXCLUSIVE_LOCKS_REQUIRED(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)
Ian Rogers1d54e732013-05-02 21:10:01 -070052 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
53
54 template <typename Visitor>
55 void Visit(const Visitor& visitor)
56 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
57 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
58
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)
Ian Rogers1d54e732013-05-02 21:10:01 -070061 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
62
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)
Ian Rogers1d54e732013-05-02 21:10:01 -070065 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
66
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_