1cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi/*
2cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi * Copyright (C) 2013 The Android Open Source Project
3cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi *
4cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi * Licensed under the Apache License, Version 2.0 (the "License");
5cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi * you may not use this file except in compliance with the License.
6cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi * You may obtain a copy of the License at
7cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi *
8cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi *      http://www.apache.org/licenses/LICENSE-2.0
9cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi *
10cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi * Unless required by applicable law or agreed to in writing, software
11cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi * distributed under the License is distributed on an "AS IS" BASIS,
12cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi * See the License for the specific language governing permissions and
14cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi * limitations under the License.
15cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi */
16cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
17cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi#ifndef ART_RUNTIME_GC_SPACE_MALLOC_SPACE_H_
18cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi#define ART_RUNTIME_GC_SPACE_MALLOC_SPACE_H_
19cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
20cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi#include "space.h"
21cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
22cf7f19135f0e273f7b0136315633c2abfc715343Ian Rogers#include <ostream>
231e13374baf7dfaf442ffbf9809c37c131d681eafEvgenii Stepanov#include "base/memory_tool.h"
247cb7bbcfffb2716ef8d68ecb747954ec42c4bdc5Hiroshi Yamauchi
25cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchinamespace art {
26cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchinamespace gc {
27cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
28cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchinamespace collector {
29cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  class MarkSweep;
30cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi}  // namespace collector
31cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
32cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchinamespace space {
33cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
34a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartierclass ZygoteSpace;
35a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier
36cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi// TODO: Remove define macro
37cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi#define CHECK_MEMORY_CALL(call, args, what) \
38cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  do { \
39cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi    int rc = call args; \
40cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi    if (UNLIKELY(rc != 0)) { \
41cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi      errno = rc; \
42cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi      PLOG(FATAL) << # call << " failed for " << what; \
43cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi    } \
44cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  } while (false)
45cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
46cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi// A common parent of DlMallocSpace and RosAllocSpace.
47cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchiclass MallocSpace : public ContinuousMemMapAllocSpace {
48cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi public:
49cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  typedef void(*WalkCallback)(void *start, void *end, size_t num_bytes, void* callback_arg);
50cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
51cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  SpaceType GetType() const {
52a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier    return kSpaceTypeMallocSpace;
53cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  }
54cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
55cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Allocate num_bytes allowing the underlying space to grow.
566fac447555dc94a935b78198479cce645c837b89Ian Rogers  virtual mirror::Object* AllocWithGrowth(Thread* self, size_t num_bytes,
574460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi                                          size_t* bytes_allocated, size_t* usable_size,
584460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi                                          size_t* bytes_tl_bulk_allocated) = 0;
596fac447555dc94a935b78198479cce645c837b89Ian Rogers  // Allocate num_bytes without allowing the underlying space to grow.
606fac447555dc94a935b78198479cce645c837b89Ian Rogers  virtual mirror::Object* Alloc(Thread* self, size_t num_bytes, size_t* bytes_allocated,
614460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi                                size_t* usable_size, size_t* bytes_tl_bulk_allocated) = 0;
622cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier  // Return the storage space required by obj. If usable_size isn't null then it is set to the
636fac447555dc94a935b78198479cce645c837b89Ian Rogers  // amount of the storage space that may be used by obj.
646fac447555dc94a935b78198479cce645c837b89Ian Rogers  virtual size_t AllocationSize(mirror::Object* obj, size_t* usable_size) = 0;
65ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers  virtual size_t Free(Thread* self, mirror::Object* ptr)
6690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) = 0;
67ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers  virtual size_t FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs)
6890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) = 0;
69cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
704460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi  // Returns the maximum bytes that could be allocated for the given
714460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi  // size in bulk, that is the maximum value for the
724460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi  // bytes_allocated_bulk out param returned by MallocSpace::Alloc().
734460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi  virtual size_t MaxBytesBulkAllocatedFor(size_t num_bytes) = 0;
744460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi
75cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi#ifndef NDEBUG
76cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  virtual void CheckMoreCoreForPrecondition() {}  // to be overridden in the debug build.
77cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi#else
78cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  void CheckMoreCoreForPrecondition() {}  // no-op in the non-debug build.
79cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi#endif
80cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
81cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  void* MoreCore(intptr_t increment);
82cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
83cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Hands unused pages back to the system.
84cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  virtual size_t Trim() = 0;
85cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
86cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Perform a mspace_inspect_all which calls back for each allocation chunk. The chunk may not be
87cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // in use, indicated by num_bytes equaling zero.
88cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  virtual void Walk(WalkCallback callback, void* arg) = 0;
89cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
90cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Returns the number of bytes that the space has currently obtained from the system. This is
91cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // greater or equal to the amount of live data in the space.
92cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  virtual size_t GetFootprint() = 0;
93cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
94cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Returns the number of bytes that the heap is allowed to obtain from the system via MoreCore.
95cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  virtual size_t GetFootprintLimit() = 0;
96cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
97cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Set the maximum number of bytes that the heap is allowed to obtain from the system via
98cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // MoreCore. Note this is used to stop the mspace growing beyond the limit to Capacity. When
99cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // allocations fail we GC before increasing the footprint limit and allowing the mspace to grow.
100cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  virtual void SetFootprintLimit(size_t limit) = 0;
101cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
102cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Removes the fork time growth limit on capacity, allowing the application to allocate up to the
103cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // maximum reserved size of the heap.
104cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  void ClearGrowthLimit() {
105cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi    growth_limit_ = NonGrowthLimitCapacity();
106cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  }
107cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
108cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Override capacity so that we only return the possibly limited capacity
109cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  size_t Capacity() const {
110cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi    return growth_limit_;
111cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  }
112cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
113cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // The total amount of memory reserved for the alloc space.
114cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  size_t NonGrowthLimitCapacity() const {
115cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi    return GetMemMap()->Size();
116cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  }
117cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
118379d09fe3c3feb7c2a2fb5a3623689b5ace7e79bMathieu Chartier  // Change the non growth limit capacity by shrinking or expanding the map. Currently, only
119379d09fe3c3feb7c2a2fb5a3623689b5ace7e79bMathieu Chartier  // shrinking is supported.
120379d09fe3c3feb7c2a2fb5a3623689b5ace7e79bMathieu Chartier  void ClampGrowthLimit();
121379d09fe3c3feb7c2a2fb5a3623689b5ace7e79bMathieu Chartier
122cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  void Dump(std::ostream& os) const;
123cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
124cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  void SetGrowthLimit(size_t growth_limit);
125cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
126d7576328811e5103e99d31f834a857522cc1463fAndreas Gampe  virtual MallocSpace* CreateInstance(MemMap* mem_map, const std::string& name, void* allocator,
127d7576328811e5103e99d31f834a857522cc1463fAndreas Gampe                                      uint8_t* begin, uint8_t* end, uint8_t* limit,
128d7576328811e5103e99d31f834a857522cc1463fAndreas Gampe                                      size_t growth_limit, bool can_move_objects) = 0;
129cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
130a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier  // Splits ourself into a zygote space and new malloc space which has our unused memory. When true,
131a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier  // the low memory mode argument specifies that the heap wishes the created space to be more
132a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier  // aggressive in releasing unused pages. Invalidates the space its called on.
133a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier  ZygoteSpace* CreateZygoteSpace(const char* alloc_space_name, bool low_memory_mode,
134a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier                                 MallocSpace** out_malloc_space) NO_THREAD_SAFETY_ANALYSIS;
135cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  virtual uint64_t GetBytesAllocated() = 0;
136cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  virtual uint64_t GetObjectsAllocated() = 0;
137cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
138cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Returns the class of a recently freed object.
139cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  mirror::Class* FindRecentFreedObject(const mirror::Object* obj);
140cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
14131f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier  bool CanMoveObjects() const OVERRIDE {
14231f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier    return can_move_objects_;
14331f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier  }
14431f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier
1456a7824dc81aaab3cb09ced16affca72d1b1da649Mathieu Chartier  void DisableMovingObjects() {
1466a7824dc81aaab3cb09ced16affca72d1b1da649Mathieu Chartier    can_move_objects_ = false;
1476a7824dc81aaab3cb09ced16affca72d1b1da649Mathieu Chartier  }
1486a7824dc81aaab3cb09ced16affca72d1b1da649Mathieu Chartier
149cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi protected:
15013735955f39b3b304c37d2b2840663c131262c18Ian Rogers  MallocSpace(const std::string& name, MemMap* mem_map, uint8_t* begin, uint8_t* end,
15113735955f39b3b304c37d2b2840663c131262c18Ian Rogers              uint8_t* limit, size_t growth_limit, bool create_bitmaps, bool can_move_objects,
15231f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier              size_t starting_size, size_t initial_size);
153cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
154cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  static MemMap* CreateMemMap(const std::string& name, size_t starting_size, size_t* initial_size,
15513735955f39b3b304c37d2b2840663c131262c18Ian Rogers                              size_t* growth_limit, size_t* capacity, uint8_t* requested_begin);
156cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
1576fac447555dc94a935b78198479cce645c837b89Ian Rogers  // When true the low memory mode argument specifies that the heap wishes the created allocator to
1586fac447555dc94a935b78198479cce645c837b89Ian Rogers  // be more aggressive in releasing unused pages.
159573f7d2d68e1838a0485e6b40d90c967526e00c2Hiroshi Yamauchi  virtual void* CreateAllocator(void* base, size_t morecore_start, size_t initial_size,
16026d69ffc0ebc98fbc5f316d8cd3ee6ba5b2001acHiroshi Yamauchi                                size_t maximum_size, bool low_memory_mode) = 0;
161cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
162661974a5561e5ccdfbac8cb5d8df8b7e6f3483b8Mathieu Chartier  virtual void RegisterRecentFree(mirror::Object* ptr)
16390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_)
16490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      REQUIRES(lock_);
165cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
166a8e8f9c0a8e259a807d7b99a148d14104c24209dMathieu Chartier  virtual accounting::ContinuousSpaceBitmap::SweepCallback* GetSweepCallback() {
167a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier    return &SweepCallback;
168a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier  }
169cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
170cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Recent allocation buffer.
171cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  static constexpr size_t kRecentFreeCount = kDebugSpaces ? (1 << 16) : 0;
172cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  static constexpr size_t kRecentFreeMask = kRecentFreeCount - 1;
173cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  std::pair<const mirror::Object*, mirror::Class*> recent_freed_objects_[kRecentFreeCount];
174cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  size_t recent_free_pos_;
175cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
176cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  static size_t bitmap_index_;
177cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
178cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Used to ensure mutual exclusion when the allocation spaces data structures are being modified.
179cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
180cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
181cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // The capacity of the alloc space until such time that ClearGrowthLimit is called.
182cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // The underlying mem_map_ controls the maximum size we allow the heap to grow to. The growth
183cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // limit is a value <= to the mem_map_ capacity used for ergonomic reasons because of the zygote.
184cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // Prior to forking the zygote the heap will have a maximally sized mem_map_ but the growth_limit_
185cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // will be set to a lower value. The growth_limit_ is used as the capacity of the alloc_space_,
186cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // however, capacity normally can't vary. In the case of the growth_limit_ it can be cleared
187cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  // one time by a call to ClearGrowthLimit.
188cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  size_t growth_limit_;
189cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
19031f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier  // True if objects in the space are movable.
1916a7824dc81aaab3cb09ced16affca72d1b1da649Mathieu Chartier  bool can_move_objects_;
19231f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier
19331f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier  // Starting and initial sized, used when you reset the space.
19431f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier  const size_t starting_size_;
19531f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier  const size_t initial_size_;
19631f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier
197e5eedcb4a634246d1f912992853441f715d705ccHiroshi Yamauchi private:
198ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers  static void SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg)
19990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
200a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier
201cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi  DISALLOW_COPY_AND_ASSIGN(MallocSpace);
202cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi};
203cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
204cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi}  // namespace space
205cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi}  // namespace gc
206cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi}  // namespace art
207cf58d4adf461eb9b8e84baa8019054c88cd8acc6Hiroshi Yamauchi
208e5eedcb4a634246d1f912992853441f715d705ccHiroshi Yamauchi#endif  // ART_RUNTIME_GC_SPACE_MALLOC_SPACE_H_
209