blob: dfbc9d2a37af3e4126eca6746100cf71591a492b [file] [log] [blame]
Elliott Hughes307f75d2011-10-12 18:04:40 -07001/*
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 Shapiro69759ea2011-07-21 18:13:35 -070016
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -070017#ifndef ART_SRC_GC_SPACE_H_
18#define ART_SRC_GC_SPACE_H_
Carl Shapiro69759ea2011-07-21 18:13:35 -070019
Elliott Hughes307f75d2011-10-12 18:04:40 -070020#include <string>
21
Mathieu Chartier7469ebf2012-09-24 16:28:36 -070022#include "../mutex.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070023#include "UniquePtr.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070024#include "globals.h"
Brian Carlstroma663ea52011-08-19 23:33:41 -070025#include "image.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070026#include "macros.h"
Ian Rogers30fab402012-01-23 15:43:46 -080027#include "dlmalloc.h"
Brian Carlstromdb4d5402011-08-09 12:18:28 -070028#include "mem_map.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070029
30namespace art {
31
Mathieu Chartierd22d5482012-11-06 17:14:12 -080032static const bool kDebugSpaces = kIsDebugBuild;
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -070033
34class DlMallocSpace;
Ian Rogers30fab402012-01-23 15:43:46 -080035class ImageSpace;
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -070036class LargeObjectSpace;
Carl Shapiro69759ea2011-07-21 18:13:35 -070037class Object;
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070038class SpaceBitmap;
Carl Shapiro69759ea2011-07-21 18:13:35 -070039
Mathieu Chartiercc236d72012-07-20 10:29:05 -070040enum GcRetentionPolicy {
Mathieu Chartier7469ebf2012-09-24 16:28:36 -070041 kGcRetentionPolicyNeverCollect,
42 kGcRetentionPolicyAlwaysCollect,
43 kGcRetentionPolicyFullCollect, // Collect only for full GC
Mathieu Chartiercc236d72012-07-20 10:29:05 -070044};
45std::ostream& operator<<(std::ostream& os, const GcRetentionPolicy& policy);
46
Mathieu Chartier2fde5332012-09-14 14:51:54 -070047enum SpaceType {
48 kSpaceTypeImageSpace,
49 kSpaceTypeAllocSpace,
50 kSpaceTypeZygoteSpace,
51 kSpaceTypeLargeObjectSpace,
52};
53std::ostream& operator<<(std::ostream& os, const SpaceType& space_type);
54
Carl Shapiro69759ea2011-07-21 18:13:35 -070055// A space contains memory allocated for managed objects.
56class Space {
57 public:
Mathieu Chartier2fde5332012-09-14 14:51:54 -070058 virtual bool CanAllocateInto() const = 0;
59 virtual bool IsCompactible() const = 0;
60 virtual bool Contains(const Object* obj) const = 0;
61 virtual SpaceType GetType() const = 0;
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -070062 virtual GcRetentionPolicy GetGcRetentionPolicy() const = 0;
63 virtual std::string GetName() const = 0;
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070064
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -070065 ImageSpace* AsImageSpace();
66 DlMallocSpace* AsAllocSpace();
67 DlMallocSpace* AsZygoteSpace();
68 LargeObjectSpace* AsLargeObjectSpace();
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -070069
Mathieu Chartier2fde5332012-09-14 14:51:54 -070070 bool IsImageSpace() const {
71 return GetType() == kSpaceTypeImageSpace;
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070072 }
73
Mathieu Chartier2fde5332012-09-14 14:51:54 -070074 bool IsAllocSpace() const {
75 return GetType() == kSpaceTypeAllocSpace || GetType() == kSpaceTypeZygoteSpace;
76 }
77
78 bool IsZygoteSpace() const {
79 return GetType() == kSpaceTypeZygoteSpace;
80 }
81
82 bool IsLargeObjectSpace() const {
83 return GetType() == kSpaceTypeLargeObjectSpace;
84 }
85
86 virtual void Dump(std::ostream& /* os */) const { }
87
88 virtual ~Space() {}
89
Ian Rogers30fab402012-01-23 15:43:46 -080090 protected:
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -070091 Space() { }
Mathieu Chartiercc236d72012-07-20 10:29:05 -070092
Mathieu Chartier2fde5332012-09-14 14:51:54 -070093 private:
Ian Rogers30fab402012-01-23 15:43:46 -080094 DISALLOW_COPY_AND_ASSIGN(Space);
95};
96
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -070097// AllocSpace interface.
98class AllocSpace {
99 public:
100 virtual bool CanAllocateInto() const {
101 return true;
102 }
103
104 // General statistics
105 virtual uint64_t GetNumBytesAllocated() const = 0;
106 virtual uint64_t GetNumObjectsAllocated() const = 0;
107 virtual uint64_t GetTotalBytesAllocated() const = 0;
108 virtual uint64_t GetTotalObjectsAllocated() const = 0;
109
110 // Allocate num_bytes without allowing growth.
111 virtual Object* Alloc(Thread* self, size_t num_bytes) = 0;
112
113 // Return the storage space required by obj.
114 virtual size_t AllocationSize(const Object* obj) = 0;
115
116 // Returns how many bytes were freed.
117 virtual size_t Free(Thread* self, Object* ptr) = 0;
118
119 // Returns how many bytes were freed.
120 virtual size_t FreeList(Thread* self, size_t num_ptrs, Object** ptrs) = 0;
121
122 protected:
123 AllocSpace() {}
124 virtual ~AllocSpace() {}
125
126 private:
127 DISALLOW_COPY_AND_ASSIGN(AllocSpace);
128};
129
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700130// Continuous spaces have bitmaps, and an address range.
131class ContinuousSpace : public Space {
132 public:
133 // Address at which the space begins
134 byte* Begin() const {
135 return begin_;
136 }
137
138 // Address at which the space ends, which may vary as the space is filled.
139 byte* End() const {
140 return end_;
141 }
142
143 // Current size of space
144 size_t Size() const {
145 return End() - Begin();
146 }
147
148 virtual SpaceBitmap* GetLiveBitmap() const = 0;
149 virtual SpaceBitmap* GetMarkBitmap() const = 0;
150
151 // Is object within this space?
152 bool HasAddress(const Object* obj) const {
153 const byte* byte_ptr = reinterpret_cast<const byte*>(obj);
154 return Begin() <= byte_ptr && byte_ptr < End();
155 }
156
157 virtual bool Contains(const Object* obj) const {
158 return HasAddress(obj);
159 }
160
161 virtual ~ContinuousSpace() {}
162
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700163 virtual std::string GetName() const {
164 return name_;
165 }
166
167 virtual GcRetentionPolicy GetGcRetentionPolicy() const {
168 return gc_retention_policy_;
169 }
170
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700171 protected:
172 ContinuousSpace(const std::string& name, byte* begin, byte* end,
173 GcRetentionPolicy gc_retention_policy);
174
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700175 std::string name_;
176 GcRetentionPolicy gc_retention_policy_;
177
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700178 // The beginning of the storage for fast access.
179 byte* begin_;
180
181 // Current end of the space.
182 byte* end_;
183
184 private:
185 DISALLOW_COPY_AND_ASSIGN(ContinuousSpace);
186};
187
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700188class DiscontinuousSpace : public virtual Space {
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700189 public:
190 // Is object within this space?
191 virtual bool Contains(const Object* obj) const = 0;
192
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700193 virtual std::string GetName() const {
194 return name_;
195 }
196
197 virtual GcRetentionPolicy GetGcRetentionPolicy() const {
198 return gc_retention_policy_;
199 }
200
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700201protected:
202 DiscontinuousSpace(const std::string& name, GcRetentionPolicy gc_retention_policy);
203
204private:
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700205 std::string name_;
206 GcRetentionPolicy gc_retention_policy_;
207
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700208 DISALLOW_COPY_AND_ASSIGN(DiscontinuousSpace);
209};
210
Ian Rogers30fab402012-01-23 15:43:46 -0800211std::ostream& operator<<(std::ostream& os, const Space& space);
212
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700213class MemMapSpace : public ContinuousSpace {
214 public:
215 // Maximum which the mapped space can grow to.
216 virtual size_t Capacity() const {
217 return mem_map_->Size();
218 }
219
220 // Size of the space without a limit on its growth. By default this is just the Capacity, but
221 // for the allocation space we support starting with a small heap and then extending it.
222 virtual size_t NonGrowthLimitCapacity() const {
223 return Capacity();
224 }
225
226 protected:
227 MemMapSpace(const std::string& name, MemMap* mem_map, size_t initial_size,
228 GcRetentionPolicy gc_retention_policy);
229
230 MemMap* GetMemMap() {
231 return mem_map_.get();
232 }
233
234 const MemMap* GetMemMap() const {
235 return mem_map_.get();
236 }
237
238 private:
239 // Underlying storage of the space
240 UniquePtr<MemMap> mem_map_;
241
242 DISALLOW_COPY_AND_ASSIGN(MemMapSpace);
243};
244
Ian Rogers30fab402012-01-23 15:43:46 -0800245// An alloc space is a space where objects may be allocated and garbage collected.
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700246class DlMallocSpace : public MemMapSpace, public AllocSpace {
Ian Rogers30fab402012-01-23 15:43:46 -0800247 public:
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -0700248 typedef void(*WalkCallback)(void *start, void *end, size_t num_bytes, void* callback_arg);
249
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700250 virtual bool CanAllocateInto() const {
251 return true;
252 }
253
254 virtual bool IsCompactible() const {
255 return false;
256 }
257
258 virtual SpaceType GetType() const {
259 return kSpaceTypeAllocSpace;
260 }
261
262 // Create a AllocSpace with the requested sizes. The requested
263 // base address is not guaranteed to be granted, if it is required,
264 // the caller should call Begin on the returned space to confirm
265 // the request was granted.
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700266 static DlMallocSpace* Create(const std::string& name, size_t initial_size, size_t growth_limit,
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700267 size_t capacity, byte* requested_begin);
268
Ian Rogers3bb17a62012-01-27 23:56:44 -0800269 // Allocate num_bytes without allowing the underlying mspace to grow.
Ian Rogers50b35e22012-10-04 10:09:15 -0700270 virtual Object* AllocWithGrowth(Thread* self, size_t num_bytes);
Ian Rogers30fab402012-01-23 15:43:46 -0800271
Ian Rogers3bb17a62012-01-27 23:56:44 -0800272 // Allocate num_bytes allowing the underlying mspace to grow.
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700273 virtual Object* Alloc(Thread* self, size_t num_bytes);
Ian Rogers30fab402012-01-23 15:43:46 -0800274
Ian Rogers3bb17a62012-01-27 23:56:44 -0800275 // Return the storage space required by obj.
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700276 virtual size_t AllocationSize(const Object* obj);
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700277 virtual size_t Free(Thread* self, Object* ptr);
278 virtual size_t FreeList(Thread* self, size_t num_ptrs, Object** ptrs);
Ian Rogers30fab402012-01-23 15:43:46 -0800279
280 void* MoreCore(intptr_t increment);
281
282 void* GetMspace() const {
283 return mspace_;
284 }
285
Elliott Hughes9eebd3b2012-06-08 13:56:31 -0700286 // Hands unused pages back to the system.
Ian Rogers30fab402012-01-23 15:43:46 -0800287 void Trim();
288
289 // Perform a mspace_inspect_all which calls back for each allocation chunk. The chunk may not be
Ian Rogers3bb17a62012-01-27 23:56:44 -0800290 // in use, indicated by num_bytes equaling zero.
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -0700291 void Walk(WalkCallback callback, void* arg);
Ian Rogers30fab402012-01-23 15:43:46 -0800292
Ian Rogers3bb17a62012-01-27 23:56:44 -0800293 // Returns the number of bytes that the heap is allowed to obtain from the system via MoreCore.
Ian Rogers30fab402012-01-23 15:43:46 -0800294 size_t GetFootprintLimit();
295
Ian Rogers3bb17a62012-01-27 23:56:44 -0800296 // Set the maximum number of bytes that the heap is allowed to obtain from the system via
297 // MoreCore. Note this is used to stop the mspace growing beyond the limit to Capacity. When
298 // allocations fail we GC before increasing the footprint limit and allowing the mspace to grow.
Ian Rogers30fab402012-01-23 15:43:46 -0800299 void SetFootprintLimit(size_t limit);
300
Ian Rogers3bb17a62012-01-27 23:56:44 -0800301 // Removes the fork time growth limit on capacity, allowing the application to allocate up to the
302 // maximum reserved size of the heap.
Ian Rogers30fab402012-01-23 15:43:46 -0800303 void ClearGrowthLimit() {
Ian Rogers3bb17a62012-01-27 23:56:44 -0800304 growth_limit_ = NonGrowthLimitCapacity();
Ian Rogers30fab402012-01-23 15:43:46 -0800305 }
306
307 // Override capacity so that we only return the possibly limited capacity
308 virtual size_t Capacity() const {
jeffhaoc1160702011-10-27 15:48:45 -0700309 return growth_limit_;
Carl Shapiro58551df2011-07-24 03:09:51 -0700310 }
311
Ian Rogers3bb17a62012-01-27 23:56:44 -0800312 // The total amount of memory reserved for the alloc space
313 virtual size_t NonGrowthLimitCapacity() const {
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700314 return GetMemMap()->Size();
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700315 }
316
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700317 virtual SpaceBitmap* GetLiveBitmap() const {
318 return live_bitmap_.get();
319 }
320
321 virtual SpaceBitmap* GetMarkBitmap() const {
322 return mark_bitmap_.get();
323 }
324
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700325 virtual void Dump(std::ostream& os) const;
326
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700327 void SetGrowthLimit(size_t growth_limit);
328
Mathieu Chartier654d3a22012-07-11 17:54:18 -0700329 // Swap the live and mark bitmaps of this space. This is used by the GC for concurrent sweeping.
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -0700330 virtual void SwapBitmaps();
Mathieu Chartier654d3a22012-07-11 17:54:18 -0700331
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700332 // Turn ourself into a zygote space and return a new alloc space which has our unused memory.
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700333 DlMallocSpace* CreateZygoteSpace();
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700334
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700335 void SetGcRetentionPolicy(GcRetentionPolicy gc_retention_policy) {
336 gc_retention_policy_ = gc_retention_policy;
337 }
338
339 virtual uint64_t GetNumBytesAllocated() const {
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700340 return num_bytes_allocated_;
341 }
342
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700343 virtual uint64_t GetNumObjectsAllocated() const {
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700344 return num_objects_allocated_;
345 }
346
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700347 virtual uint64_t GetTotalBytesAllocated() const {
Mathieu Chartier155dfe92012-10-09 14:24:49 -0700348 return total_bytes_allocated_;
349 }
350
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700351 virtual uint64_t GetTotalObjectsAllocated() const {
Mathieu Chartier155dfe92012-10-09 14:24:49 -0700352 return total_objects_allocated_;
353 }
354
Carl Shapiro69759ea2011-07-21 18:13:35 -0700355 private:
Mathieu Chartierd22d5482012-11-06 17:14:12 -0800356 size_t InternalAllocationSize(const Object* obj);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700357 Object* AllocWithoutGrowthLocked(size_t num_bytes) EXCLUSIVE_LOCKS_REQUIRED(lock_);
358
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700359 UniquePtr<SpaceBitmap> live_bitmap_;
360 UniquePtr<SpaceBitmap> mark_bitmap_;
Mathieu Chartier7469ebf2012-09-24 16:28:36 -0700361 UniquePtr<SpaceBitmap> temp_bitmap_;
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700362
363 // Approximate number of bytes which have been allocated into the space.
364 size_t num_bytes_allocated_;
365 size_t num_objects_allocated_;
Mathieu Chartier155dfe92012-10-09 14:24:49 -0700366 size_t total_bytes_allocated_;
367 size_t total_objects_allocated_;
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700368
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700369 static size_t bitmap_index_;
370
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700371 DlMallocSpace(const std::string& name, MemMap* mem_map, void* mspace, byte* begin, byte* end,
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700372 size_t growth_limit);
Ian Rogers30fab402012-01-23 15:43:46 -0800373
374 bool Init(size_t initial_size, size_t maximum_size, size_t growth_size, byte* requested_base);
375
Ian Rogers3bb17a62012-01-27 23:56:44 -0800376 static void* CreateMallocSpace(void* base, size_t morecore_start, size_t initial_size);
Ian Rogers30fab402012-01-23 15:43:46 -0800377
Carl Shapiro58551df2011-07-24 03:09:51 -0700378 // The boundary tag overhead.
379 static const size_t kChunkOverhead = kWordSize;
380
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700381 // Used to ensure mutual exclusion when the allocation spaces data structures are being modified.
Mathieu Chartier664bebf2012-11-12 16:54:11 -0800382 Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700383
Ian Rogers30fab402012-01-23 15:43:46 -0800384 // Underlying malloc space
385 void* const mspace_;
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700386
Ian Rogers30fab402012-01-23 15:43:46 -0800387 // The capacity of the alloc space until such time that ClearGrowthLimit is called.
388 // The underlying mem_map_ controls the maximum size we allow the heap to grow to. The growth
389 // limit is a value <= to the mem_map_ capacity used for ergonomic reasons because of the zygote.
390 // Prior to forking the zygote the heap will have a maximally sized mem_map_ but the growth_limit_
391 // will be set to a lower value. The growth_limit_ is used as the capacity of the alloc_space_,
392 // however, capacity normally can't vary. In the case of the growth_limit_ it can be cleared
393 // one time by a call to ClearGrowthLimit.
394 size_t growth_limit_;
395
Mathieu Chartier7469ebf2012-09-24 16:28:36 -0700396 friend class MarkSweep;
397
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700398 DISALLOW_COPY_AND_ASSIGN(DlMallocSpace);
Ian Rogers30fab402012-01-23 15:43:46 -0800399};
400
401// An image space is a space backed with a memory mapped image
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700402class ImageSpace : public MemMapSpace {
Ian Rogers30fab402012-01-23 15:43:46 -0800403 public:
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700404 virtual bool CanAllocateInto() const {
405 return false;
406 }
407
408 virtual bool IsCompactible() const {
409 return false;
410 }
411
412 virtual SpaceType GetType() const {
413 return kSpaceTypeImageSpace;
414 }
415
416 // create a Space from an image file. cannot be used for future allocation or collected.
417 static ImageSpace* Create(const std::string& image)
418 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
419
Ian Rogers30fab402012-01-23 15:43:46 -0800420 const ImageHeader& GetImageHeader() const {
421 return *reinterpret_cast<ImageHeader*>(Begin());
Elliott Hughes307f75d2011-10-12 18:04:40 -0700422 }
Carl Shapiro69759ea2011-07-21 18:13:35 -0700423
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700424 const std::string GetImageFilename() const {
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700425 return GetName();
Ian Rogers30fab402012-01-23 15:43:46 -0800426 }
Carl Shapiro69759ea2011-07-21 18:13:35 -0700427
Ian Rogers30fab402012-01-23 15:43:46 -0800428 // Mark the objects defined in this space in the given live bitmap
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700429 void RecordImageAllocations(SpaceBitmap* live_bitmap) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700430 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700431
Mathieu Chartiere0f0cb32012-08-28 11:26:00 -0700432 virtual SpaceBitmap* GetLiveBitmap() const {
433 return live_bitmap_.get();
434 }
435
436 virtual SpaceBitmap* GetMarkBitmap() const {
437 // ImageSpaces have the same bitmap for both live and marked. This helps reduce the number of
438 // special cases to test against.
439 return live_bitmap_.get();
440 }
Mathieu Chartier654d3a22012-07-11 17:54:18 -0700441
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700442 virtual void Dump(std::ostream& os) const;
443
Ian Rogers30fab402012-01-23 15:43:46 -0800444 private:
445 friend class Space;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700446
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700447 UniquePtr<SpaceBitmap> live_bitmap_;
448 static size_t bitmap_index_;
449
450 ImageSpace(const std::string& name, MemMap* mem_map);
Elliott Hughes307f75d2011-10-12 18:04:40 -0700451
Ian Rogers30fab402012-01-23 15:43:46 -0800452 DISALLOW_COPY_AND_ASSIGN(ImageSpace);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700453};
454
Elliott Hughes9eebd3b2012-06-08 13:56:31 -0700455// Callback for dlmalloc_inspect_all or mspace_inspect_all that will madvise(2) unused
456// pages back to the kernel.
457void MspaceMadviseCallback(void* start, void* end, size_t used_bytes, void* /*arg*/);
Elliott Hughes9eebd3b2012-06-08 13:56:31 -0700458
Carl Shapiro69759ea2011-07-21 18:13:35 -0700459} // namespace art
460
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700461#endif // ART_SRC_GC_SPACE_H_