blob: ed7b427a5f9c558ed49398e6c0087670f893bbda [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_INL_H_
18#define ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_INL_H_
Ian Rogers1d54e732013-05-02 21:10:01 -070019
20#include "heap_bitmap.h"
21
Mathieu Chartier4aeec172014-03-27 16:09:46 -070022#include "space_bitmap-inl.h"
23
Ian Rogers1d54e732013-05-02 21:10:01 -070024namespace art {
25namespace gc {
26namespace accounting {
27
28template <typename Visitor>
29inline void HeapBitmap::Visit(const Visitor& visitor) {
Mathieu Chartier02e25112013-08-14 16:14:24 -070030 for (const auto& bitmap : continuous_space_bitmaps_) {
Mathieu Chartier184e3222013-08-03 14:02:57 -070031 bitmap->VisitMarkedRange(bitmap->HeapBegin(), bitmap->HeapLimit(), visitor);
Ian Rogers1d54e732013-05-02 21:10:01 -070032 }
Mathieu Chartier02e25112013-08-14 16:14:24 -070033 DCHECK(!discontinuous_space_sets_.empty());
34 for (const auto& space_set : discontinuous_space_sets_) {
35 space_set->Visit(visitor);
Ian Rogers1d54e732013-05-02 21:10:01 -070036 }
Ian Rogers1d54e732013-05-02 21:10:01 -070037}
38
Mathieu Chartier4aeec172014-03-27 16:09:46 -070039inline bool HeapBitmap::Test(const mirror::Object* obj) {
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070040 ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj);
Mathieu Chartier4aeec172014-03-27 16:09:46 -070041 if (LIKELY(bitmap != nullptr)) {
42 return bitmap->Test(obj);
43 } else {
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070044 return GetDiscontinuousSpaceObjectSet(obj) != nullptr;
Mathieu Chartier4aeec172014-03-27 16:09:46 -070045 }
46}
47
48inline void HeapBitmap::Clear(const mirror::Object* obj) {
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070049 ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj);
Mathieu Chartier4aeec172014-03-27 16:09:46 -070050 if (LIKELY(bitmap != nullptr)) {
51 bitmap->Clear(obj);
52 } else {
53 ObjectSet* set = GetDiscontinuousSpaceObjectSet(obj);
54 DCHECK(set != NULL);
55 set->Clear(obj);
56 }
57}
58
59inline void HeapBitmap::Set(const mirror::Object* obj) {
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070060 ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj);
Mathieu Chartier4aeec172014-03-27 16:09:46 -070061 if (LIKELY(bitmap != NULL)) {
62 bitmap->Set(obj);
63 } else {
64 ObjectSet* set = GetDiscontinuousSpaceObjectSet(obj);
65 DCHECK(set != NULL);
66 set->Set(obj);
67 }
68}
69
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070070inline ContinuousSpaceBitmap* HeapBitmap::GetContinuousSpaceBitmap(const mirror::Object* obj) const {
Mathieu Chartier4aeec172014-03-27 16:09:46 -070071 for (const auto& bitmap : continuous_space_bitmaps_) {
72 if (bitmap->HasAddress(obj)) {
73 return bitmap;
74 }
75 }
76 return nullptr;
77}
78
79inline ObjectSet* HeapBitmap::GetDiscontinuousSpaceObjectSet(const mirror::Object* obj) const {
80 for (const auto& space_set : discontinuous_space_sets_) {
81 if (space_set->Test(obj)) {
82 return space_set;
83 }
84 }
85 return nullptr;
86}
87
Ian Rogers1d54e732013-05-02 21:10:01 -070088} // namespace accounting
89} // namespace gc
90} // namespace art
91
Brian Carlstromfc0e3212013-07-17 14:40:12 -070092#endif // ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_INL_H_