blob: 871ebac8a71811856acd4a3bdffe0c25e0de03b8 [file] [log] [blame]
Ian Rogers1d54e732013-05-02 21:10:01 -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 */
16
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_GC_SPACE_SPACE_H_
18#define ART_RUNTIME_GC_SPACE_SPACE_H_
Ian Rogers1d54e732013-05-02 21:10:01 -070019
Ian Rogers700a4022014-05-19 16:49:03 -070020#include <memory>
Ian Rogers1d54e732013-05-02 21:10:01 -070021#include <string>
22
Ian Rogersbe2a1df2014-07-10 00:56:36 -070023#include "atomic.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070024#include "base/macros.h"
25#include "base/mutex.h"
26#include "gc/accounting/space_bitmap.h"
Mathieu Chartier10fb83a2014-06-15 15:15:43 -070027#include "gc/collector/garbage_collector.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070028#include "globals.h"
29#include "image.h"
30#include "mem_map.h"
31
32namespace art {
33namespace mirror {
34 class Object;
35} // namespace mirror
36
37namespace gc {
38
Ian Rogers1d54e732013-05-02 21:10:01 -070039class Heap;
40
41namespace space {
42
Mathieu Chartier590fee92013-09-13 13:46:47 -070043class AllocSpace;
Mathieu Chartier7410f292013-11-24 13:17:35 -080044class BumpPointerSpace;
Mathieu Chartiera1602f22014-01-13 17:19:19 -080045class ContinuousMemMapAllocSpace;
Mathieu Chartier590fee92013-09-13 13:46:47 -070046class ContinuousSpace;
Mathieu Chartier590fee92013-09-13 13:46:47 -070047class DiscontinuousSpace;
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070048class MallocSpace;
49class DlMallocSpace;
50class RosAllocSpace;
Ian Rogers1d54e732013-05-02 21:10:01 -070051class ImageSpace;
52class LargeObjectSpace;
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080053class RegionSpace;
Mathieu Chartiera1602f22014-01-13 17:19:19 -080054class ZygoteSpace;
Ian Rogers1d54e732013-05-02 21:10:01 -070055
Mathieu Chartier0f72e412013-09-06 16:40:01 -070056static constexpr bool kDebugSpaces = kIsDebugBuild;
Ian Rogers1d54e732013-05-02 21:10:01 -070057
58// See Space::GetGcRetentionPolicy.
59enum GcRetentionPolicy {
60 // Objects are retained forever with this policy for a space.
61 kGcRetentionPolicyNeverCollect,
62 // Every GC cycle will attempt to collect objects in this space.
63 kGcRetentionPolicyAlwaysCollect,
64 // Objects will be considered for collection only in "full" GC cycles, ie faster partial
65 // collections won't scan these areas such as the Zygote.
66 kGcRetentionPolicyFullCollect,
67};
68std::ostream& operator<<(std::ostream& os, const GcRetentionPolicy& policy);
69
70enum SpaceType {
71 kSpaceTypeImageSpace,
Mathieu Chartiera1602f22014-01-13 17:19:19 -080072 kSpaceTypeMallocSpace,
Ian Rogers1d54e732013-05-02 21:10:01 -070073 kSpaceTypeZygoteSpace,
Mathieu Chartier590fee92013-09-13 13:46:47 -070074 kSpaceTypeBumpPointerSpace,
Ian Rogers1d54e732013-05-02 21:10:01 -070075 kSpaceTypeLargeObjectSpace,
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080076 kSpaceTypeRegionSpace,
Ian Rogers1d54e732013-05-02 21:10:01 -070077};
78std::ostream& operator<<(std::ostream& os, const SpaceType& space_type);
79
80// A space contains memory allocated for managed objects.
81class Space {
82 public:
83 // Dump space. Also key method for C++ vtables.
84 virtual void Dump(std::ostream& os) const;
85
86 // Name of the space. May vary, for example before/after the Zygote fork.
87 const char* GetName() const {
88 return name_.c_str();
89 }
90
91 // The policy of when objects are collected associated with this space.
92 GcRetentionPolicy GetGcRetentionPolicy() const {
93 return gc_retention_policy_;
94 }
95
Ian Rogers1d54e732013-05-02 21:10:01 -070096 // Is the given object contained within this space?
97 virtual bool Contains(const mirror::Object* obj) const = 0;
98
99 // The kind of space this: image, alloc, zygote, large object.
100 virtual SpaceType GetType() const = 0;
101
102 // Is this an image space, ie one backed by a memory mapped image file.
103 bool IsImageSpace() const {
104 return GetType() == kSpaceTypeImageSpace;
105 }
106 ImageSpace* AsImageSpace();
107
108 // Is this a dlmalloc backed allocation space?
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700109 bool IsMallocSpace() const {
Ian Rogers1d54e732013-05-02 21:10:01 -0700110 SpaceType type = GetType();
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800111 return type == kSpaceTypeMallocSpace;
Ian Rogers1d54e732013-05-02 21:10:01 -0700112 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700113 MallocSpace* AsMallocSpace();
114
115 virtual bool IsDlMallocSpace() const {
116 return false;
117 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800118 virtual DlMallocSpace* AsDlMallocSpace();
119
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700120 virtual bool IsRosAllocSpace() const {
121 return false;
122 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800123 virtual RosAllocSpace* AsRosAllocSpace();
Ian Rogers1d54e732013-05-02 21:10:01 -0700124
Ian Rogers6fac4472014-02-25 17:01:10 -0800125 // Is this the space allocated into by the Zygote and no-longer in use for allocation?
Ian Rogers1d54e732013-05-02 21:10:01 -0700126 bool IsZygoteSpace() const {
127 return GetType() == kSpaceTypeZygoteSpace;
128 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800129 virtual ZygoteSpace* AsZygoteSpace();
Ian Rogers1d54e732013-05-02 21:10:01 -0700130
Mathieu Chartier590fee92013-09-13 13:46:47 -0700131 // Is this space a bump pointer space?
132 bool IsBumpPointerSpace() const {
133 return GetType() == kSpaceTypeBumpPointerSpace;
134 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800135 virtual BumpPointerSpace* AsBumpPointerSpace();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700136
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800137 bool IsRegionSpace() const {
138 return GetType() == kSpaceTypeRegionSpace;
139 }
140 virtual RegionSpace* AsRegionSpace();
141
Ian Rogers1d54e732013-05-02 21:10:01 -0700142 // Does this space hold large objects and implement the large object space abstraction?
143 bool IsLargeObjectSpace() const {
144 return GetType() == kSpaceTypeLargeObjectSpace;
145 }
146 LargeObjectSpace* AsLargeObjectSpace();
147
Mathieu Chartier590fee92013-09-13 13:46:47 -0700148 virtual bool IsContinuousSpace() const {
149 return false;
150 }
151 ContinuousSpace* AsContinuousSpace();
152
153 virtual bool IsDiscontinuousSpace() const {
154 return false;
155 }
156 DiscontinuousSpace* AsDiscontinuousSpace();
157
158 virtual bool IsAllocSpace() const {
159 return false;
160 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800161 virtual AllocSpace* AsAllocSpace();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700162
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800163 virtual bool IsContinuousMemMapAllocSpace() const {
164 return false;
165 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800166 virtual ContinuousMemMapAllocSpace* AsContinuousMemMapAllocSpace();
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800167
Mathieu Chartier31f44142014-04-08 14:40:03 -0700168 // Returns true if objects in the space are movable.
169 virtual bool CanMoveObjects() const = 0;
170
Ian Rogers1d54e732013-05-02 21:10:01 -0700171 virtual ~Space() {}
172
173 protected:
174 Space(const std::string& name, GcRetentionPolicy gc_retention_policy);
175
176 void SetGcRetentionPolicy(GcRetentionPolicy gc_retention_policy) {
177 gc_retention_policy_ = gc_retention_policy;
178 }
179
180 // Name of the space that may vary due to the Zygote fork.
181 std::string name_;
182
Mathieu Chartier590fee92013-09-13 13:46:47 -0700183 protected:
Ian Rogers1d54e732013-05-02 21:10:01 -0700184 // When should objects within this space be reclaimed? Not constant as we vary it in the case
185 // of Zygote forking.
186 GcRetentionPolicy gc_retention_policy_;
187
Mathieu Chartier590fee92013-09-13 13:46:47 -0700188 private:
Ian Rogers1d54e732013-05-02 21:10:01 -0700189 friend class art::gc::Heap;
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700190 DISALLOW_IMPLICIT_CONSTRUCTORS(Space);
Ian Rogers1d54e732013-05-02 21:10:01 -0700191};
192std::ostream& operator<<(std::ostream& os, const Space& space);
193
194// AllocSpace interface.
195class AllocSpace {
196 public:
197 // Number of bytes currently allocated.
Hiroshi Yamauchibe031ff2013-10-08 16:42:37 -0700198 virtual uint64_t GetBytesAllocated() = 0;
Ian Rogers1d54e732013-05-02 21:10:01 -0700199 // Number of objects currently allocated.
Hiroshi Yamauchibe031ff2013-10-08 16:42:37 -0700200 virtual uint64_t GetObjectsAllocated() = 0;
Ian Rogers1d54e732013-05-02 21:10:01 -0700201
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700202 // Allocate num_bytes without allowing growth. If the allocation
203 // succeeds, the output parameter bytes_allocated will be set to the
204 // actually allocated bytes which is >= num_bytes.
Mathieu Chartier0651d412014-04-29 14:37:57 -0700205 // Alloc can be called from multiple threads at the same time and must be thread-safe.
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700206 //
207 // bytes_tl_bulk_allocated - bytes allocated in bulk ahead of time for a thread local allocation,
208 // if applicable. It can be
209 // 1) equal to bytes_allocated if it's not a thread local allocation,
210 // 2) greater than bytes_allocated if it's a thread local
211 // allocation that required a new buffer, or
212 // 3) zero if it's a thread local allocation in an existing
213 // buffer.
214 // This is what is to be added to Heap::num_bytes_allocated_.
Ian Rogers6fac4472014-02-25 17:01:10 -0800215 virtual mirror::Object* Alloc(Thread* self, size_t num_bytes, size_t* bytes_allocated,
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700216 size_t* usable_size, size_t* bytes_tl_bulk_allocated) = 0;
Ian Rogers1d54e732013-05-02 21:10:01 -0700217
Mathieu Chartier0651d412014-04-29 14:37:57 -0700218 // Thread-unsafe allocation for when mutators are suspended, used by the semispace collector.
219 virtual mirror::Object* AllocThreadUnsafe(Thread* self, size_t num_bytes, size_t* bytes_allocated,
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700220 size_t* usable_size,
221 size_t* bytes_tl_bulk_allocated)
Mathieu Chartier0651d412014-04-29 14:37:57 -0700222 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700223 return Alloc(self, num_bytes, bytes_allocated, usable_size, bytes_tl_bulk_allocated);
Mathieu Chartier0651d412014-04-29 14:37:57 -0700224 }
225
Ian Rogers1d54e732013-05-02 21:10:01 -0700226 // Return the storage space required by obj.
Ian Rogers6fac4472014-02-25 17:01:10 -0800227 virtual size_t AllocationSize(mirror::Object* obj, size_t* usable_size) = 0;
Ian Rogers1d54e732013-05-02 21:10:01 -0700228
229 // Returns how many bytes were freed.
230 virtual size_t Free(Thread* self, mirror::Object* ptr) = 0;
231
232 // Returns how many bytes were freed.
233 virtual size_t FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) = 0;
234
Ian Rogers6fac4472014-02-25 17:01:10 -0800235 // Revoke any sort of thread-local buffers that are used to speed up allocations for the given
236 // thread, if the alloc space implementation uses any.
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700237 // Returns the total free bytes in the revoked thread local runs that's to be subtracted
238 // from Heap::num_bytes_allocated_ or zero if unnecessary.
239 virtual size_t RevokeThreadLocalBuffers(Thread* thread) = 0;
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700240
Ian Rogers6fac4472014-02-25 17:01:10 -0800241 // Revoke any sort of thread-local buffers that are used to speed up allocations for all the
242 // threads, if the alloc space implementation uses any.
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700243 // Returns the total free bytes in the revoked thread local runs that's to be subtracted
244 // from Heap::num_bytes_allocated_ or zero if unnecessary.
245 virtual size_t RevokeAllThreadLocalBuffers() = 0;
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700246
Mathieu Chartierb363f662014-07-16 13:28:58 -0700247 virtual void LogFragmentationAllocFailure(std::ostream& os, size_t failed_alloc_bytes) = 0;
248
Ian Rogers1d54e732013-05-02 21:10:01 -0700249 protected:
Mathieu Chartier10fb83a2014-06-15 15:15:43 -0700250 struct SweepCallbackContext {
251 SweepCallbackContext(bool swap_bitmaps, space::Space* space);
252 const bool swap_bitmaps;
253 space::Space* const space;
254 Thread* const self;
255 collector::ObjectBytePair freed;
256 };
257
Ian Rogers1d54e732013-05-02 21:10:01 -0700258 AllocSpace() {}
259 virtual ~AllocSpace() {}
260
261 private:
262 DISALLOW_COPY_AND_ASSIGN(AllocSpace);
263};
264
265// Continuous spaces have bitmaps, and an address range. Although not required, objects within
266// continuous spaces can be marked in the card table.
267class ContinuousSpace : public Space {
268 public:
Mathieu Chartier590fee92013-09-13 13:46:47 -0700269 // Address at which the space begins.
Ian Rogers13735952014-10-08 12:43:28 -0700270 uint8_t* Begin() const {
Ian Rogers1d54e732013-05-02 21:10:01 -0700271 return begin_;
272 }
273
Mathieu Chartier590fee92013-09-13 13:46:47 -0700274 // Current address at which the space ends, which may vary as the space is filled.
Ian Rogers13735952014-10-08 12:43:28 -0700275 uint8_t* End() const {
Ian Rogersbe2a1df2014-07-10 00:56:36 -0700276 return end_.LoadRelaxed();
Ian Rogers1d54e732013-05-02 21:10:01 -0700277 }
278
Mathieu Chartier590fee92013-09-13 13:46:47 -0700279 // The end of the address range covered by the space.
Ian Rogers13735952014-10-08 12:43:28 -0700280 uint8_t* Limit() const {
Mathieu Chartier590fee92013-09-13 13:46:47 -0700281 return limit_;
282 }
283
284 // Change the end of the space. Be careful with use since changing the end of a space to an
285 // invalid value may break the GC.
Ian Rogers13735952014-10-08 12:43:28 -0700286 void SetEnd(uint8_t* end) {
Ian Rogersbe2a1df2014-07-10 00:56:36 -0700287 end_.StoreRelaxed(end);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700288 }
289
Ian Rogers13735952014-10-08 12:43:28 -0700290 void SetLimit(uint8_t* limit) {
Mathieu Chartier590fee92013-09-13 13:46:47 -0700291 limit_ = limit;
292 }
293
Ian Rogers1d54e732013-05-02 21:10:01 -0700294 // Current size of space
295 size_t Size() const {
296 return End() - Begin();
297 }
298
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -0700299 virtual accounting::ContinuousSpaceBitmap* GetLiveBitmap() const = 0;
300 virtual accounting::ContinuousSpaceBitmap* GetMarkBitmap() const = 0;
Ian Rogers1d54e732013-05-02 21:10:01 -0700301
Mathieu Chartier590fee92013-09-13 13:46:47 -0700302 // Maximum which the mapped space can grow to.
303 virtual size_t Capacity() const {
304 return Limit() - Begin();
305 }
306
Ian Rogers1d54e732013-05-02 21:10:01 -0700307 // Is object within this space? We check to see if the pointer is beyond the end first as
308 // continuous spaces are iterated over from low to high.
309 bool HasAddress(const mirror::Object* obj) const {
Ian Rogers13735952014-10-08 12:43:28 -0700310 const uint8_t* byte_ptr = reinterpret_cast<const uint8_t*>(obj);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700311 return byte_ptr >= Begin() && byte_ptr < Limit();
Ian Rogers1d54e732013-05-02 21:10:01 -0700312 }
313
314 bool Contains(const mirror::Object* obj) const {
315 return HasAddress(obj);
316 }
317
Mathieu Chartier590fee92013-09-13 13:46:47 -0700318 virtual bool IsContinuousSpace() const {
319 return true;
320 }
321
Ian Rogers1d54e732013-05-02 21:10:01 -0700322 virtual ~ContinuousSpace() {}
323
324 protected:
325 ContinuousSpace(const std::string& name, GcRetentionPolicy gc_retention_policy,
Ian Rogers13735952014-10-08 12:43:28 -0700326 uint8_t* begin, uint8_t* end, uint8_t* limit) :
Mathieu Chartier590fee92013-09-13 13:46:47 -0700327 Space(name, gc_retention_policy), begin_(begin), end_(end), limit_(limit) {
Ian Rogers1d54e732013-05-02 21:10:01 -0700328 }
329
Ian Rogers1d54e732013-05-02 21:10:01 -0700330 // The beginning of the storage for fast access.
Ian Rogers13735952014-10-08 12:43:28 -0700331 uint8_t* begin_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700332
333 // Current end of the space.
Ian Rogers13735952014-10-08 12:43:28 -0700334 Atomic<uint8_t*> end_;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700335
336 // Limit of the space.
Ian Rogers13735952014-10-08 12:43:28 -0700337 uint8_t* limit_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700338
339 private:
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700340 DISALLOW_IMPLICIT_CONSTRUCTORS(ContinuousSpace);
Ian Rogers1d54e732013-05-02 21:10:01 -0700341};
342
343// A space where objects may be allocated higgledy-piggledy throughout virtual memory. Currently
344// the card table can't cover these objects and so the write barrier shouldn't be triggered. This
345// is suitable for use for large primitive arrays.
346class DiscontinuousSpace : public Space {
347 public:
Mathieu Chartierbbd695c2014-04-16 09:48:48 -0700348 accounting::LargeObjectBitmap* GetLiveBitmap() const {
349 return live_bitmap_.get();
Ian Rogers1d54e732013-05-02 21:10:01 -0700350 }
351
Mathieu Chartierbbd695c2014-04-16 09:48:48 -0700352 accounting::LargeObjectBitmap* GetMarkBitmap() const {
353 return mark_bitmap_.get();
Ian Rogers1d54e732013-05-02 21:10:01 -0700354 }
355
Mathieu Chartierbbd695c2014-04-16 09:48:48 -0700356 virtual bool IsDiscontinuousSpace() const OVERRIDE {
Mathieu Chartier590fee92013-09-13 13:46:47 -0700357 return true;
358 }
359
Ian Rogers1d54e732013-05-02 21:10:01 -0700360 virtual ~DiscontinuousSpace() {}
361
362 protected:
363 DiscontinuousSpace(const std::string& name, GcRetentionPolicy gc_retention_policy);
364
Ian Rogers700a4022014-05-19 16:49:03 -0700365 std::unique_ptr<accounting::LargeObjectBitmap> live_bitmap_;
366 std::unique_ptr<accounting::LargeObjectBitmap> mark_bitmap_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700367
368 private:
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700369 DISALLOW_IMPLICIT_CONSTRUCTORS(DiscontinuousSpace);
Ian Rogers1d54e732013-05-02 21:10:01 -0700370};
371
372class MemMapSpace : public ContinuousSpace {
373 public:
Ian Rogers1d54e732013-05-02 21:10:01 -0700374 // Size of the space without a limit on its growth. By default this is just the Capacity, but
375 // for the allocation space we support starting with a small heap and then extending it.
376 virtual size_t NonGrowthLimitCapacity() const {
377 return Capacity();
378 }
379
Ian Rogers1d54e732013-05-02 21:10:01 -0700380 MemMap* GetMemMap() {
381 return mem_map_.get();
382 }
383
384 const MemMap* GetMemMap() const {
385 return mem_map_.get();
386 }
387
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800388 MemMap* ReleaseMemMap() {
389 return mem_map_.release();
390 }
391
Mathieu Chartier590fee92013-09-13 13:46:47 -0700392 protected:
Ian Rogers13735952014-10-08 12:43:28 -0700393 MemMapSpace(const std::string& name, MemMap* mem_map, uint8_t* begin, uint8_t* end, uint8_t* limit,
Mathieu Chartier590fee92013-09-13 13:46:47 -0700394 GcRetentionPolicy gc_retention_policy)
395 : ContinuousSpace(name, gc_retention_policy, begin, end, limit),
396 mem_map_(mem_map) {
397 }
398
Ian Rogers1d54e732013-05-02 21:10:01 -0700399 // Underlying storage of the space
Ian Rogers700a4022014-05-19 16:49:03 -0700400 std::unique_ptr<MemMap> mem_map_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700401
Mathieu Chartier590fee92013-09-13 13:46:47 -0700402 private:
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700403 DISALLOW_IMPLICIT_CONSTRUCTORS(MemMapSpace);
Ian Rogers1d54e732013-05-02 21:10:01 -0700404};
405
Mathieu Chartier590fee92013-09-13 13:46:47 -0700406// Used by the heap compaction interface to enable copying from one type of alloc space to another.
407class ContinuousMemMapAllocSpace : public MemMapSpace, public AllocSpace {
408 public:
Ian Rogers6fac4472014-02-25 17:01:10 -0800409 bool IsAllocSpace() const OVERRIDE {
Mathieu Chartier590fee92013-09-13 13:46:47 -0700410 return true;
411 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800412 AllocSpace* AsAllocSpace() OVERRIDE {
Mathieu Chartier590fee92013-09-13 13:46:47 -0700413 return this;
414 }
415
Ian Rogers6fac4472014-02-25 17:01:10 -0800416 bool IsContinuousMemMapAllocSpace() const OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800417 return true;
418 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800419 ContinuousMemMapAllocSpace* AsContinuousMemMapAllocSpace() {
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800420 return this;
421 }
422
423 bool HasBoundBitmaps() const EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
424 void BindLiveToMarkBitmap()
425 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
426 void UnBindBitmaps() EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
Mathieu Chartier1f3b5352014-02-03 14:00:42 -0800427 // Swap the live and mark bitmaps of this space. This is used by the GC for concurrent sweeping.
428 void SwapBitmaps();
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800429
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -0700430 // Clear the space back to an empty space.
Ian Rogers6fac4472014-02-25 17:01:10 -0800431 virtual void Clear() = 0;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700432
Mathieu Chartier4c13a3f2014-07-14 14:57:16 -0700433 accounting::ContinuousSpaceBitmap* GetLiveBitmap() const OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800434 return live_bitmap_.get();
435 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800436
Mathieu Chartier4c13a3f2014-07-14 14:57:16 -0700437 accounting::ContinuousSpaceBitmap* GetMarkBitmap() const OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800438 return mark_bitmap_.get();
439 }
440
Mathieu Chartier10fb83a2014-06-15 15:15:43 -0700441 collector::ObjectBytePair Sweep(bool swap_bitmaps);
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -0700442 virtual accounting::ContinuousSpaceBitmap::SweepCallback* GetSweepCallback() = 0;
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800443
Mathieu Chartier590fee92013-09-13 13:46:47 -0700444 protected:
Ian Rogers700a4022014-05-19 16:49:03 -0700445 std::unique_ptr<accounting::ContinuousSpaceBitmap> live_bitmap_;
446 std::unique_ptr<accounting::ContinuousSpaceBitmap> mark_bitmap_;
447 std::unique_ptr<accounting::ContinuousSpaceBitmap> temp_bitmap_;
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800448
Ian Rogers13735952014-10-08 12:43:28 -0700449 ContinuousMemMapAllocSpace(const std::string& name, MemMap* mem_map, uint8_t* begin,
450 uint8_t* end, uint8_t* limit, GcRetentionPolicy gc_retention_policy)
Mathieu Chartier590fee92013-09-13 13:46:47 -0700451 : MemMapSpace(name, mem_map, begin, end, limit, gc_retention_policy) {
452 }
453
454 private:
Mathieu Chartiera1602f22014-01-13 17:19:19 -0800455 friend class gc::Heap;
Mathieu Chartier3130cdf2015-05-03 15:20:23 -0700456 DISALLOW_IMPLICIT_CONSTRUCTORS(ContinuousMemMapAllocSpace);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700457};
458
Ian Rogers1d54e732013-05-02 21:10:01 -0700459} // namespace space
460} // namespace gc
461} // namespace art
462
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700463#endif // ART_RUNTIME_GC_SPACE_SPACE_H_