blob: 34c15c7f8b0eff91894ebd02d50b8196286f1a16 [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 Chartierbbd695c2014-04-16 09:48:48 -070033 for (const auto& bitmap : large_object_bitmaps_) {
34 bitmap->VisitMarkedRange(bitmap->HeapBegin(), bitmap->HeapLimit(), visitor);
Ian Rogers1d54e732013-05-02 21:10:01 -070035 }
Ian Rogers1d54e732013-05-02 21:10:01 -070036}
37
Mathieu Chartier4aeec172014-03-27 16:09:46 -070038inline bool HeapBitmap::Test(const mirror::Object* obj) {
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070039 ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj);
Mathieu Chartier4aeec172014-03-27 16:09:46 -070040 if (LIKELY(bitmap != nullptr)) {
41 return bitmap->Test(obj);
Mathieu Chartier4aeec172014-03-27 16:09:46 -070042 }
Andreas Gampe277ccbd2014-11-03 21:36:10 -080043 for (const auto& lo_bitmap : large_object_bitmaps_) {
44 if (LIKELY(lo_bitmap->HasAddress(obj))) {
45 return lo_bitmap->Test(obj);
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070046 }
47 }
48 LOG(FATAL) << "Invalid object " << obj;
49 return false;
Mathieu Chartier4aeec172014-03-27 16:09:46 -070050}
51
52inline void HeapBitmap::Clear(const mirror::Object* obj) {
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070053 ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj);
Mathieu Chartier4aeec172014-03-27 16:09:46 -070054 if (LIKELY(bitmap != nullptr)) {
55 bitmap->Clear(obj);
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070056 return;
Mathieu Chartier4aeec172014-03-27 16:09:46 -070057 }
Andreas Gampe277ccbd2014-11-03 21:36:10 -080058 for (const auto& lo_bitmap : large_object_bitmaps_) {
59 if (LIKELY(lo_bitmap->HasAddress(obj))) {
60 lo_bitmap->Clear(obj);
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070061 }
62 }
63 LOG(FATAL) << "Invalid object " << obj;
Mathieu Chartier4aeec172014-03-27 16:09:46 -070064}
65
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070066template<typename LargeObjectSetVisitor>
67inline bool HeapBitmap::Set(const mirror::Object* obj, const LargeObjectSetVisitor& visitor) {
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070068 ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj);
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070069 if (LIKELY(bitmap != nullptr)) {
70 return bitmap->Set(obj);
Mathieu Chartier4aeec172014-03-27 16:09:46 -070071 }
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070072 visitor(obj);
Andreas Gampe277ccbd2014-11-03 21:36:10 -080073 for (const auto& lo_bitmap : large_object_bitmaps_) {
74 if (LIKELY(lo_bitmap->HasAddress(obj))) {
75 return lo_bitmap->Set(obj);
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070076 }
77 }
78 LOG(FATAL) << "Invalid object " << obj;
79 return false;
80}
81
82template<typename LargeObjectSetVisitor>
83inline bool HeapBitmap::AtomicTestAndSet(const mirror::Object* obj,
84 const LargeObjectSetVisitor& visitor) {
85 ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj);
86 if (LIKELY(bitmap != nullptr)) {
87 return bitmap->AtomicTestAndSet(obj);
88 }
89 visitor(obj);
Andreas Gampe277ccbd2014-11-03 21:36:10 -080090 for (const auto& lo_bitmap : large_object_bitmaps_) {
91 if (LIKELY(lo_bitmap->HasAddress(obj))) {
92 return lo_bitmap->AtomicTestAndSet(obj);
Mathieu Chartierbbd695c2014-04-16 09:48:48 -070093 }
94 }
95 LOG(FATAL) << "Invalid object " << obj;
96 return false;
Mathieu Chartier4aeec172014-03-27 16:09:46 -070097}
98
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070099inline ContinuousSpaceBitmap* HeapBitmap::GetContinuousSpaceBitmap(const mirror::Object* obj) const {
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700100 for (const auto& bitmap : continuous_space_bitmaps_) {
101 if (bitmap->HasAddress(obj)) {
102 return bitmap;
103 }
104 }
105 return nullptr;
106}
107
Ian Rogers1d54e732013-05-02 21:10:01 -0700108} // namespace accounting
109} // namespace gc
110} // namespace art
111
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700112#endif // ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_INL_H_