Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ART_SRC_SPACE_H_ |
| 18 | #define ART_SRC_SPACE_H_ |
| 19 | |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 22 | #include "UniquePtr.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 23 | #include "globals.h" |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 24 | #include "image.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 25 | #include "macros.h" |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 26 | #include "dlmalloc.h" |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 27 | #include "mem_map.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 28 | |
| 29 | namespace art { |
| 30 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 31 | class AllocSpace; |
| 32 | class ImageSpace; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 33 | class Object; |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 34 | class SpaceBitmap; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 35 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 36 | enum GcRetentionPolicy { |
| 37 | GCRP_NEVER_COLLECT, |
| 38 | GCRP_ALWAYS_COLLECT, |
| 39 | GCRP_FULL_COLLECT, |
| 40 | }; |
| 41 | std::ostream& operator<<(std::ostream& os, const GcRetentionPolicy& policy); |
| 42 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 43 | // A space contains memory allocated for managed objects. |
| 44 | class Space { |
| 45 | public: |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 46 | // Create a AllocSpace with the requested sizes. The requested |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 47 | // base address is not guaranteed to be granted, if it is required, |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 48 | // the caller should call Begin on the returned space to confirm |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 49 | // the request was granted. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 50 | static AllocSpace* CreateAllocSpace(const std::string& name, size_t initial_size, |
| 51 | size_t growth_limit, size_t capacity, |
| 52 | byte* requested_begin); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 53 | |
| 54 | // create a Space from an image file. cannot be used for future allocation or collected. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 55 | static ImageSpace* CreateImageSpace(const std::string& image) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 56 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 57 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 58 | virtual ~Space() {} |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 59 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 60 | const std::string& GetSpaceName() const { |
| 61 | return name_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 64 | // Address at which the space begins |
| 65 | byte* Begin() const { |
| 66 | return begin_; |
| 67 | } |
| 68 | |
| 69 | // Address at which the space ends, which may vary as the space is filled |
| 70 | byte* End() const { |
| 71 | return end_; |
| 72 | } |
| 73 | |
| 74 | // Is object within this space? |
| 75 | bool Contains(const Object* obj) const { |
| 76 | const byte* byte_ptr = reinterpret_cast<const byte*>(obj); |
| 77 | return Begin() <= byte_ptr && byte_ptr < End(); |
| 78 | } |
| 79 | |
| 80 | // Current size of space |
| 81 | size_t Size() const { |
| 82 | return End() - Begin(); |
| 83 | } |
| 84 | |
| 85 | // Maximum size of space |
| 86 | virtual size_t Capacity() const { |
| 87 | return mem_map_->Size(); |
| 88 | } |
| 89 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 90 | // Size of the space without a limit on its growth. By default this is just the Capacity, but |
| 91 | // for the allocation space we support starting with a small heap and then extending it. |
| 92 | virtual size_t NonGrowthLimitCapacity() const { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 93 | return Capacity(); |
| 94 | } |
| 95 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 96 | GcRetentionPolicy GetGcRetentionPolicy() const { |
| 97 | return gc_retention_policy_; |
| 98 | } |
| 99 | |
| 100 | void SetGcRetentionPolicy(GcRetentionPolicy gc_retention_policy) { |
| 101 | gc_retention_policy_ = gc_retention_policy; |
| 102 | } |
| 103 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 104 | ImageSpace* AsImageSpace() { |
| 105 | DCHECK(IsImageSpace()); |
| 106 | return down_cast<ImageSpace*>(this); |
| 107 | } |
| 108 | |
| 109 | AllocSpace* AsAllocSpace() { |
| 110 | DCHECK(IsAllocSpace()); |
| 111 | return down_cast<AllocSpace*>(this); |
| 112 | } |
| 113 | |
| 114 | virtual bool IsAllocSpace() const = 0; |
| 115 | virtual bool IsImageSpace() const = 0; |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 116 | virtual bool IsZygoteSpace() const = 0; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 117 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 118 | virtual SpaceBitmap* GetLiveBitmap() const = 0; |
| 119 | virtual SpaceBitmap* GetMarkBitmap() const = 0; |
| 120 | |
| 121 | const std::string GetName() const { |
| 122 | return name_; |
| 123 | } |
| 124 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 125 | protected: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 126 | Space(const std::string& name, MemMap* mem_map, byte* begin, byte* end, |
| 127 | GcRetentionPolicy gc_retention_policy) |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 128 | : name_(name), |
| 129 | mem_map_(mem_map), |
| 130 | begin_(begin), |
| 131 | end_(end), |
| 132 | gc_retention_policy_(gc_retention_policy) {} |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 133 | |
| 134 | std::string name_; |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 135 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 136 | // Underlying storage of the space |
| 137 | UniquePtr<MemMap> mem_map_; |
| 138 | |
| 139 | // The beginning of the storage for fast access (always equals mem_map_->GetAddress()) |
| 140 | byte* const begin_; |
| 141 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 142 | // Current end of the space. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 143 | byte* end_; |
| 144 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 145 | // Garbage collection retention policy, used to figure out when we should sweep over this space. |
| 146 | GcRetentionPolicy gc_retention_policy_; |
| 147 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 148 | DISALLOW_COPY_AND_ASSIGN(Space); |
| 149 | }; |
| 150 | |
| 151 | std::ostream& operator<<(std::ostream& os, const Space& space); |
| 152 | |
| 153 | // An alloc space is a space where objects may be allocated and garbage collected. |
| 154 | class AllocSpace : public Space { |
| 155 | public: |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 156 | // Allocate num_bytes without allowing the underlying mspace to grow. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 157 | Object* AllocWithGrowth(size_t num_bytes); |
| 158 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 159 | // Allocate num_bytes allowing the underlying mspace to grow. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 160 | Object* AllocWithoutGrowth(size_t num_bytes); |
| 161 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 162 | // Return the storage space required by obj. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 163 | size_t AllocationSize(const Object* obj); |
| 164 | |
| 165 | void Free(Object* ptr); |
| 166 | |
| 167 | void FreeList(size_t num_ptrs, Object** ptrs); |
| 168 | |
| 169 | void* MoreCore(intptr_t increment); |
| 170 | |
| 171 | void* GetMspace() const { |
| 172 | return mspace_; |
| 173 | } |
| 174 | |
Elliott Hughes | 9eebd3b | 2012-06-08 13:56:31 -0700 | [diff] [blame] | 175 | // Hands unused pages back to the system. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 176 | void Trim(); |
| 177 | |
| 178 | // Perform a mspace_inspect_all which calls back for each allocation chunk. The chunk may not be |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 179 | // in use, indicated by num_bytes equaling zero. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 180 | void Walk(void(*callback)(void *start, void *end, size_t num_bytes, void* callback_arg), |
| 181 | void* arg); |
| 182 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 183 | // Returns the number of bytes that the heap is allowed to obtain from the system via MoreCore. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 184 | size_t GetFootprintLimit(); |
| 185 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 186 | // Set the maximum number of bytes that the heap is allowed to obtain from the system via |
| 187 | // MoreCore. Note this is used to stop the mspace growing beyond the limit to Capacity. When |
| 188 | // allocations fail we GC before increasing the footprint limit and allowing the mspace to grow. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 189 | void SetFootprintLimit(size_t limit); |
| 190 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 191 | // Removes the fork time growth limit on capacity, allowing the application to allocate up to the |
| 192 | // maximum reserved size of the heap. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 193 | void ClearGrowthLimit() { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 194 | growth_limit_ = NonGrowthLimitCapacity(); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | // Override capacity so that we only return the possibly limited capacity |
| 198 | virtual size_t Capacity() const { |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 199 | return growth_limit_; |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 202 | // The total amount of memory reserved for the alloc space |
| 203 | virtual size_t NonGrowthLimitCapacity() const { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 204 | return mem_map_->End() - mem_map_->Begin(); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 207 | virtual bool IsAllocSpace() const { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 208 | return gc_retention_policy_ != GCRP_NEVER_COLLECT; |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 211 | virtual bool IsImageSpace() const { |
| 212 | return false; |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 215 | virtual bool IsZygoteSpace() const { |
| 216 | return gc_retention_policy_ == GCRP_FULL_COLLECT; |
| 217 | } |
| 218 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 219 | virtual SpaceBitmap* GetLiveBitmap() const { |
| 220 | return live_bitmap_.get(); |
| 221 | } |
| 222 | |
| 223 | virtual SpaceBitmap* GetMarkBitmap() const { |
| 224 | return mark_bitmap_.get(); |
| 225 | } |
| 226 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 227 | void SetGrowthLimit(size_t growth_limit); |
| 228 | |
Mathieu Chartier | 654d3a2 | 2012-07-11 17:54:18 -0700 | [diff] [blame] | 229 | // Swap the live and mark bitmaps of this space. This is used by the GC for concurrent sweeping. |
| 230 | void SwapBitmaps(); |
| 231 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 232 | // Turn ourself into a zygote space and return a new alloc space which has our unused memory. |
| 233 | AllocSpace* CreateZygoteSpace(); |
| 234 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 235 | private: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 236 | Object* AllocWithoutGrowthLocked(size_t num_bytes) EXCLUSIVE_LOCKS_REQUIRED(lock_); |
| 237 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 238 | friend class Space; |
| 239 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 240 | UniquePtr<SpaceBitmap> live_bitmap_; |
| 241 | UniquePtr<SpaceBitmap> mark_bitmap_; |
| 242 | static size_t bitmap_index_; |
| 243 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 244 | AllocSpace(const std::string& name, MemMap* mem_map, void* mspace, byte* begin, byte* end, |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 245 | size_t growth_limit); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 246 | |
| 247 | bool Init(size_t initial_size, size_t maximum_size, size_t growth_size, byte* requested_base); |
| 248 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 249 | static void* CreateMallocSpace(void* base, size_t morecore_start, size_t initial_size); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 250 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 251 | // The boundary tag overhead. |
| 252 | static const size_t kChunkOverhead = kWordSize; |
| 253 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 254 | // Used to ensure mutual exclusion when the allocation spaces data structures are being modified. |
| 255 | Mutex lock_; |
| 256 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 257 | // Underlying malloc space |
| 258 | void* const mspace_; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 259 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 260 | // The capacity of the alloc space until such time that ClearGrowthLimit is called. |
| 261 | // The underlying mem_map_ controls the maximum size we allow the heap to grow to. The growth |
| 262 | // limit is a value <= to the mem_map_ capacity used for ergonomic reasons because of the zygote. |
| 263 | // Prior to forking the zygote the heap will have a maximally sized mem_map_ but the growth_limit_ |
| 264 | // will be set to a lower value. The growth_limit_ is used as the capacity of the alloc_space_, |
| 265 | // however, capacity normally can't vary. In the case of the growth_limit_ it can be cleared |
| 266 | // one time by a call to ClearGrowthLimit. |
| 267 | size_t growth_limit_; |
| 268 | |
| 269 | DISALLOW_COPY_AND_ASSIGN(AllocSpace); |
| 270 | }; |
| 271 | |
| 272 | // An image space is a space backed with a memory mapped image |
| 273 | class ImageSpace : public Space { |
| 274 | public: |
| 275 | const ImageHeader& GetImageHeader() const { |
| 276 | return *reinterpret_cast<ImageHeader*>(Begin()); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 277 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 278 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 279 | const std::string& GetImageFilename() const { |
| 280 | return name_; |
| 281 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 282 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 283 | // Mark the objects defined in this space in the given live bitmap |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 284 | void RecordImageAllocations(SpaceBitmap* live_bitmap) const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 285 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 286 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 287 | virtual bool IsAllocSpace() const { |
| 288 | return false; |
| 289 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 290 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 291 | virtual bool IsImageSpace() const { |
| 292 | return true; |
| 293 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 294 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 295 | virtual bool IsZygoteSpace() const { |
| 296 | return false; |
| 297 | } |
| 298 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 299 | virtual SpaceBitmap* GetLiveBitmap() const { |
| 300 | return live_bitmap_.get(); |
| 301 | } |
| 302 | |
| 303 | virtual SpaceBitmap* GetMarkBitmap() const { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 304 | // ImageSpaces have the same bitmap for both live and marked. This helps reduce the number of |
| 305 | // special cases to test against. |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 306 | return live_bitmap_.get(); |
| 307 | } |
Mathieu Chartier | 654d3a2 | 2012-07-11 17:54:18 -0700 | [diff] [blame] | 308 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 309 | private: |
| 310 | friend class Space; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 311 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 312 | UniquePtr<SpaceBitmap> live_bitmap_; |
| 313 | static size_t bitmap_index_; |
| 314 | |
| 315 | ImageSpace(const std::string& name, MemMap* mem_map); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 316 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 317 | DISALLOW_COPY_AND_ASSIGN(ImageSpace); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 318 | }; |
| 319 | |
Elliott Hughes | 9eebd3b | 2012-06-08 13:56:31 -0700 | [diff] [blame] | 320 | // Callback for dlmalloc_inspect_all or mspace_inspect_all that will madvise(2) unused |
| 321 | // pages back to the kernel. |
| 322 | void MspaceMadviseCallback(void* start, void* end, size_t used_bytes, void* /*arg*/); |
Elliott Hughes | 9eebd3b | 2012-06-08 13:56:31 -0700 | [diff] [blame] | 323 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 324 | } // namespace art |
| 325 | |
| 326 | #endif // ART_SRC_SPACE_H_ |