blob: 29a7b1f396fbcc9754c1f438785b478d6e4f6d92 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
Mathieu Chartierb062fdd2012-07-03 09:51:48 -07002 * Copyright (C) 2012 The Android Open Source Project
Elliott Hughes2faa5f12012-01-30 14:42:07 -08003 *
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 */
Carl Shapiro69759ea2011-07-21 18:13:35 -070016
Elliott Hughes5e71b522011-10-20 13:12:32 -070017#ifndef ART_SRC_HEAP_BITMAP_H_
18#define ART_SRC_HEAP_BITMAP_H_
Carl Shapiro69759ea2011-07-21 18:13:35 -070019
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070020#include "space_bitmap.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070021
22namespace art {
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070023 class Heap;
24 class SpaceBitmap;
Carl Shapiro69759ea2011-07-21 18:13:35 -070025
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070026 class HeapBitmap {
Mathieu Chartierb43b7d42012-06-19 13:15:09 -070027 public:
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070028 bool Test(const Object* obj) {
29 SpaceBitmap* bitmap = GetSpaceBitmap(obj);
30 DCHECK(bitmap != NULL);
31 return bitmap->Test(obj);
Mathieu Chartierb43b7d42012-06-19 13:15:09 -070032 }
33
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070034 void Clear(const Object* obj) {
35 SpaceBitmap* bitmap = GetSpaceBitmap(obj);
36 DCHECK(bitmap != NULL)
37 << "tried to clear object "
38 << reinterpret_cast<const void*>(obj)
39 << " which did not belong to any bitmaps";
40 return bitmap->Clear(obj);
Mathieu Chartierb43b7d42012-06-19 13:15:09 -070041 }
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070042
43 void Set(const Object* obj) {
44 SpaceBitmap* bitmap = GetSpaceBitmap(obj);
45 DCHECK(bitmap != NULL)
46 << "tried to mark object "
47 << reinterpret_cast<const void*>(obj)
48 << " which did not belong to any bitmaps";
49 bitmap->Set(obj);
50 }
51
52 SpaceBitmap* GetSpaceBitmap(const Object* obj) {
53 // TODO: C++0x auto
Mathieu Chartier654d3a22012-07-11 17:54:18 -070054 for (Bitmaps::iterator cur = bitmaps_.begin(); cur != bitmaps_.end(); ++cur) {
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070055 if ((*cur)->HasAddress(obj)) {
56 return *cur;
57 }
58 }
59 return NULL;
60 }
61
62 void Walk(SpaceBitmap::Callback* callback, void* arg) {
63 // TODO: C++0x auto
Mathieu Chartier654d3a22012-07-11 17:54:18 -070064 for (Bitmaps::iterator cur = bitmaps_.begin(); cur != bitmaps_.end(); ++cur) {
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070065 (*cur)->Walk(callback, arg);
66 }
67 }
68
Mathieu Chartier654d3a22012-07-11 17:54:18 -070069 // Find and replace a bitmap pointer, this is used by for the bitmap swapping in the GC.
70 void ReplaceBitmap(SpaceBitmap* old_bitmap, SpaceBitmap* new_bitmap);
71
Mathieu Chartierb43b7d42012-06-19 13:15:09 -070072 private:
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070073 void AddSpaceBitmap(SpaceBitmap* space) {
74 bitmaps_.push_back(space);
75 }
76
Mathieu Chartier654d3a22012-07-11 17:54:18 -070077 typedef std::vector<SpaceBitmap*> Bitmaps;
78 Bitmaps bitmaps_;
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070079
80 friend class Heap;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -070081 };
Carl Shapiro69759ea2011-07-21 18:13:35 -070082} // namespace art
83
Elliott Hughes5e71b522011-10-20 13:12:32 -070084#endif // ART_SRC_HEAP_BITMAP_H_