blob: e908248f93d01a89a2491e93fd967f0b03f7e232 [file] [log] [blame]
Elliott Hughes9d5ccec2011-09-19 13:19:50 -07001/*
2 * Copyright (C) 2008 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 Shapiro1fb86202011-06-27 17:43:13 -070016
17#ifndef ART_SRC_HEAP_H_
18#define ART_SRC_HEAP_H_
19
Elliott Hughesc967f782012-04-16 10:23:15 -070020#include <iosfwd>
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080021#include <string>
Carl Shapiro58551df2011-07-24 03:09:51 -070022#include <vector>
23
Ian Rogers5d76c432011-10-31 21:42:49 -070024#include "card_table.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070025#include "globals.h"
Ian Rogers30fab402012-01-23 15:43:46 -080026#include "gtest/gtest.h"
Elliott Hughes5e71b522011-10-20 13:12:32 -070027#include "heap_bitmap.h"
Brian Carlstromcd74c4b2012-01-23 13:21:00 -080028#include "mutex.h"
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070029#include "offsets.h"
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070030#include "safe_map.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -070031
Elliott Hughes3e465b12011-09-02 18:26:12 -070032#define VERIFY_OBJECT_ENABLED 0
33
Mathieu Chartierdcf8d722012-08-02 14:55:54 -070034// Fast verification means we do not verify the classes of objects.
35#define VERIFY_OBJECT_FAST 1
36
Carl Shapiro1fb86202011-06-27 17:43:13 -070037namespace art {
38
Ian Rogers30fab402012-01-23 15:43:46 -080039class AllocSpace;
Brian Carlstroma40f9bc2011-07-26 21:26:07 -070040class Class;
Mathieu Chartier5301cd22012-05-31 12:11:36 -070041class HeapBitmap;
Brian Carlstromfddf6f62012-03-15 16:56:45 -070042class ImageSpace;
Mathieu Chartier5301cd22012-05-31 12:11:36 -070043class MarkStack;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -070044class ModUnionTable;
Brian Carlstroma40f9bc2011-07-26 21:26:07 -070045class Object;
Carl Shapiro69759ea2011-07-21 18:13:35 -070046class Space;
Ian Rogers30fab402012-01-23 15:43:46 -080047class SpaceTest;
Mathieu Chartier5301cd22012-05-31 12:11:36 -070048class Thread;
Carl Shapiro69759ea2011-07-21 18:13:35 -070049
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070050typedef std::vector<Space*> Spaces;
51
Elliott Hughesf8349362012-06-18 15:00:06 -070052class LOCKABLE Heap {
Carl Shapiro1fb86202011-06-27 17:43:13 -070053 public:
Ian Rogers30fab402012-01-23 15:43:46 -080054 static const size_t kInitialSize = 2 * MB;
Carl Shapiro69759ea2011-07-21 18:13:35 -070055
Ian Rogers30fab402012-01-23 15:43:46 -080056 static const size_t kMaximumSize = 32 * MB;
Carl Shapiro69759ea2011-07-21 18:13:35 -070057
Elliott Hughes410c0c82011-09-01 17:58:25 -070058 typedef void (RootVisitor)(const Object* root, void* arg);
Elliott Hughesc33a32b2011-10-11 18:18:07 -070059 typedef bool (IsMarkedTester)(const Object* object, void* arg);
Brian Carlstrom7e93b502011-08-04 14:16:22 -070060
Brian Carlstrom58ae9412011-10-04 00:56:06 -070061 // Create a heap with the requested sizes. The possible empty
62 // image_file_names names specify Spaces to load based on
63 // ImageWriter output.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080064 explicit Heap(size_t starting_size, size_t growth_limit, size_t capacity,
65 const std::string& image_file_name);
Carl Shapiro61e019d2011-07-14 16:53:09 -070066
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080067 ~Heap();
Brian Carlstroma7f4f482011-07-17 17:01:34 -070068
Brian Carlstroma40f9bc2011-07-26 21:26:07 -070069 // Allocates and initializes storage for an object instance.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080070 Object* AllocObject(Class* klass, size_t num_bytes);
Brian Carlstroma7f4f482011-07-17 17:01:34 -070071
Elliott Hughesa2501992011-08-26 19:39:54 -070072 // Check sanity of given reference. Requires the heap lock.
Elliott Hughes3e465b12011-09-02 18:26:12 -070073#if VERIFY_OBJECT_ENABLED
Elliott Hughes1bac54f2012-03-16 12:48:31 -070074 void VerifyObject(const Object* o);
Elliott Hughes3e465b12011-09-02 18:26:12 -070075#else
Elliott Hughes1bac54f2012-03-16 12:48:31 -070076 void VerifyObject(const Object*) {}
Elliott Hughes3e465b12011-09-02 18:26:12 -070077#endif
Ian Rogers408f79a2011-08-23 18:22:33 -070078
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070079 // Check sanity of all live references. Requires the heap lock.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080080 void VerifyHeap();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070081
Elliott Hughes6a5bd492011-10-28 14:33:57 -070082 // A weaker test than IsLiveObject or VerifyObject that doesn't require the heap lock,
Elliott Hughesa2501992011-08-26 19:39:54 -070083 // and doesn't abort on error, allowing the caller to report more
84 // meaningful diagnostics.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080085 bool IsHeapAddress(const Object* obj);
86
Elliott Hughes6a5bd492011-10-28 14:33:57 -070087 // Returns true if 'obj' is a live heap object, false otherwise (including for invalid addresses).
88 // Requires the heap lock to be held.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080089 bool IsLiveObjectLocked(const Object* obj);
Elliott Hughesa2501992011-08-26 19:39:54 -070090
Carl Shapiro69759ea2011-07-21 18:13:35 -070091 // Initiates an explicit garbage collection.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080092 void CollectGarbage(bool clear_soft_references);
Carl Shapiro69759ea2011-07-21 18:13:35 -070093
Mathieu Chartier7664f5c2012-06-08 18:15:32 -070094 // Does a concurrent GC, should only be called by the GC daemon thread
95 // through runtime.
96 void ConcurrentGC();
97
Elliott Hughesbf86d042011-08-31 17:53:14 -070098 // Implements java.lang.Runtime.maxMemory.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080099 int64_t GetMaxMemory();
Elliott Hughesbf86d042011-08-31 17:53:14 -0700100 // Implements java.lang.Runtime.totalMemory.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800101 int64_t GetTotalMemory();
Elliott Hughesbf86d042011-08-31 17:53:14 -0700102 // Implements java.lang.Runtime.freeMemory.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800103 int64_t GetFreeMemory();
Elliott Hughesbf86d042011-08-31 17:53:14 -0700104
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700105 // Implements VMDebug.countInstancesOfClass.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800106 int64_t CountInstances(Class* c, bool count_assignable);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700107
Ian Rogers3bb17a62012-01-27 23:56:44 -0800108 // Removes the growth limit on the alloc space so it may grow to its maximum capacity. Used to
109 // implement dalvik.system.VMRuntime.clearGrowthLimit.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800110 void ClearGrowthLimit();
jeffhaoc1160702011-10-27 15:48:45 -0700111
Ian Rogers30fab402012-01-23 15:43:46 -0800112 // Target ideal heap utilization ratio, implements
113 // dalvik.system.VMRuntime.getTargetHeapUtilization.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800114 float GetTargetHeapUtilization() {
Brian Carlstrom395520e2011-09-25 19:35:00 -0700115 return target_utilization_;
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700116 }
Ian Rogers30fab402012-01-23 15:43:46 -0800117 // Set target ideal heap utilization ratio, implements
118 // dalvik.system.VMRuntime.setTargetHeapUtilization.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800119 void SetTargetHeapUtilization(float target) {
Ian Rogers30fab402012-01-23 15:43:46 -0800120 DCHECK_GT(target, 0.0f); // asserted in Java code
121 DCHECK_LT(target, 1.0f);
Brian Carlstrom395520e2011-09-25 19:35:00 -0700122 target_utilization_ = target;
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700123 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800124
125 // For the alloc space, sets the maximum number of bytes that the heap is allowed to allocate
126 // from the system. Doesn't allow the space to exceed its growth limit.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800127 void SetIdealFootprint(size_t max_allowed_footprint);
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700128
Mathieu Chartierfc8cfac2012-06-19 11:56:36 -0700129 // Blocks the caller until the garbage collector becomes idle and returns
130 // true if we waited for the GC to complete.
131 bool WaitForConcurrentGcToComplete();
Carl Shapiro69759ea2011-07-21 18:13:35 -0700132
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800133 pid_t GetLockOwner(); // For SignalCatcher.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800134 void AssertLockHeld() {
Brian Carlstromcd74c4b2012-01-23 13:21:00 -0800135 lock_->AssertHeld();
136 }
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800137 void AssertLockNotHeld() {
Brian Carlstromcd74c4b2012-01-23 13:21:00 -0800138 lock_->AssertNotHeld();
139 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700140
Mathieu Chartier654d3a22012-07-11 17:54:18 -0700141 const Spaces& GetSpaces() {
Carl Shapiro58551df2011-07-24 03:09:51 -0700142 return spaces_;
143 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700144
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800145 void SetReferenceOffsets(MemberOffset reference_referent_offset,
146 MemberOffset reference_queue_offset,
147 MemberOffset reference_queueNext_offset,
148 MemberOffset reference_pendingNext_offset,
149 MemberOffset finalizer_reference_zombie_offset);
Brian Carlstrom1f870082011-08-23 16:02:11 -0700150
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800151 Object* GetReferenceReferent(Object* reference);
152 void ClearReferenceReferent(Object* reference);
Brian Carlstrom1f870082011-08-23 16:02:11 -0700153
Elliott Hughesadb460d2011-10-05 17:02:34 -0700154 // Returns true if the reference object has not yet been enqueued.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800155 bool IsEnqueuable(const Object* ref);
156 void EnqueueReference(Object* ref, Object** list);
157 void EnqueuePendingReference(Object* ref, Object** list);
158 Object* DequeuePendingReference(Object** list);
Brian Carlstrom1f870082011-08-23 16:02:11 -0700159
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800160 MemberOffset GetReferencePendingNextOffset() {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700161 DCHECK_NE(reference_pendingNext_offset_.Uint32Value(), 0U);
Brian Carlstrom1f870082011-08-23 16:02:11 -0700162 return reference_pendingNext_offset_;
163 }
164
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800165 MemberOffset GetFinalizerReferenceZombieOffset() {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700166 DCHECK_NE(finalizer_reference_zombie_offset_.Uint32Value(), 0U);
Brian Carlstrom1f870082011-08-23 16:02:11 -0700167 return finalizer_reference_zombie_offset_;
168 }
169
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800170 void EnableObjectValidation() {
Ian Rogers30fab402012-01-23 15:43:46 -0800171#if VERIFY_OBJECT_ENABLED
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800172 VerifyHeap();
Ian Rogers30fab402012-01-23 15:43:46 -0800173#endif
Elliott Hughes85d15452011-09-16 17:33:01 -0700174 verify_objects_ = true;
175 }
176
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800177 void DisableObjectValidation() {
Elliott Hughes85d15452011-09-16 17:33:01 -0700178 verify_objects_ = false;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700179 }
180
Elliott Hughes92b3b562011-09-08 16:32:26 -0700181 // Callers must hold the heap lock.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800182 void RecordFreeLocked(size_t freed_objects, size_t freed_bytes);
Brian Carlstrom693267a2011-09-06 09:25:34 -0700183
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700184 // Must be called if a field of an Object in the heap changes, and before any GC safe-point.
185 // The call is not needed if NULL is stored in the field.
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700186 void WriteBarrierField(const Object* dst, MemberOffset /*offset*/, const Object* /*new_value*/) {
Ian Rogers5d76c432011-10-31 21:42:49 -0700187 if (!card_marking_disabled_) {
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700188 card_table_->MarkCard(dst);
Ian Rogers5d76c432011-10-31 21:42:49 -0700189 }
190 }
191
192 // Write barrier for array operations that update many field positions
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700193 void WriteBarrierArray(const Object* dst, int /*start_offset*/, size_t /*length TODO: element_count or byte_count?*/) {
Ian Rogers5d76c432011-10-31 21:42:49 -0700194 if (UNLIKELY(!card_marking_disabled_)) {
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700195 card_table_->MarkCard(dst);
Ian Rogers5d76c432011-10-31 21:42:49 -0700196 }
197 }
198
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800199 CardTable* GetCardTable() {
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700200 return card_table_.get();
Ian Rogers5d76c432011-10-31 21:42:49 -0700201 }
202
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800203 void DisableCardMarking() {
Ian Rogers5d76c432011-10-31 21:42:49 -0700204 // TODO: we shouldn't need to disable card marking, this is here to help the image_writer
205 card_marking_disabled_ = true;
Elliott Hughes3a4f8df2011-09-13 15:22:36 -0700206 }
Elliott Hughes5ea047b2011-09-13 14:38:18 -0700207
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800208 void AddFinalizerReference(Thread* self, Object* object);
Elliott Hughesadb460d2011-10-05 17:02:34 -0700209
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800210 size_t GetBytesAllocated() { return num_bytes_allocated_; }
211 size_t GetObjectsAllocated() { return num_objects_allocated_; }
Elliott Hughes7162ad92011-10-27 14:08:42 -0700212
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700213 size_t GetConcurrentStartSize() const { return concurrent_start_size_; }
214
215 void SetConcurrentStartSize(size_t size) {
216 concurrent_start_size_ = size;
217 }
218
219 size_t GetConcurrentMinFree() const { return concurrent_min_free_; }
220
221 void SetConcurrentMinFree(size_t size) {
222 concurrent_min_free_ = size;
223 }
224
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700225 // Functions for getting the bitmap which corresponds to an object's address.
226 // This is probably slow, TODO: use better data structure like binary tree .
227 Space* FindSpaceFromObject(const Object*) const;
228
Elliott Hughesc967f782012-04-16 10:23:15 -0700229 void DumpForSigQuit(std::ostream& os);
230
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700231 void Trim(AllocSpace* alloc_space);
232
233 HeapBitmap* GetLiveBitmap() {
234 return live_bitmap_.get();
235 }
236
237 HeapBitmap* GetMarkBitmap() {
238 return mark_bitmap_.get();
239 }
240
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700241 void PreZygoteFork();
242
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700243 // DEPRECATED: Should remove in "near" future when support for multiple image spaces is added.
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700244 // Assumes there is only one image space.
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700245 ImageSpace* GetImageSpace();
246 AllocSpace* GetAllocSpace();
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700247 void DumpSpaces();
Elliott Hughesf8349362012-06-18 15:00:06 -0700248
Carl Shapiro58551df2011-07-24 03:09:51 -0700249 private:
250 // Allocates uninitialized storage.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800251 Object* AllocateLocked(size_t num_bytes);
252 Object* AllocateLocked(AllocSpace* space, size_t num_bytes);
Carl Shapiro58551df2011-07-24 03:09:51 -0700253
Elliott Hughesf8349362012-06-18 15:00:06 -0700254 void Lock() EXCLUSIVE_LOCK_FUNCTION();
255 void Unlock() UNLOCK_FUNCTION();
Mathieu Chartiera6399032012-06-11 18:49:50 -0700256
Elliott Hughesadb460d2011-10-05 17:02:34 -0700257 // Pushes a list of cleared references out to the managed heap.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800258 void EnqueueClearedReferences(Object** cleared_references);
Elliott Hughesadb460d2011-10-05 17:02:34 -0700259
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800260 void RequestHeapTrim();
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700261 void RequestConcurrentGC();
Elliott Hughes8cf5bc02012-02-02 16:32:16 -0800262
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800263 void RecordAllocationLocked(AllocSpace* space, const Object* object);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700264
Elliott Hughesf8349362012-06-18 15:00:06 -0700265 // TODO: can we teach GCC to understand the weird locking in here?
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700266 void CollectGarbageInternal(bool partial_gc, bool concurrent, bool clear_soft_references) NO_THREAD_SAFETY_ANALYSIS;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700267
Ian Rogers3bb17a62012-01-27 23:56:44 -0800268 // Given the current contents of the alloc space, increase the allowed heap footprint to match
269 // the target utilization ratio. This should only be called immediately after a full garbage
270 // collection.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800271 void GrowForUtilization();
Carl Shapiro69759ea2011-07-21 18:13:35 -0700272
Elliott Hughesc967f782012-04-16 10:23:15 -0700273 size_t GetPercentFree();
274
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800275 void AddSpace(Space* space);
Ian Rogers30fab402012-01-23 15:43:46 -0800276
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800277 void VerifyObjectLocked(const Object *obj);
Elliott Hughes92b3b562011-09-08 16:32:26 -0700278
jeffhao25045522012-03-13 19:34:37 -0700279 void VerifyHeapLocked();
280
Brian Carlstrom78128a62011-09-15 17:21:19 -0700281 static void VerificationCallback(Object* obj, void* arg);
Elliott Hughes92b3b562011-09-08 16:32:26 -0700282
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700283 UniquePtr<Mutex> lock_;
284 UniquePtr<ConditionVariable> condition_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700285
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700286 Spaces spaces_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700287
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700288 // The alloc space which we are currently allocating into.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800289 AllocSpace* alloc_space_;
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700290
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700291 // The mod-union table remembers all of the referneces from the image space to the alloc /
292 // zygote spaces.
293 UniquePtr<ModUnionTable> mod_union_table_;
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700294
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700295 // This table holds all of the references from the zygote space to the alloc space.
296 UniquePtr<ModUnionTable> zygote_mod_union_table_;
297
298 UniquePtr<CardTable> card_table_;
Ian Rogers5d76c432011-10-31 21:42:49 -0700299
300 // Used by the image writer to disable card marking on copied objects
301 // TODO: remove
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800302 bool card_marking_disabled_;
Ian Rogers5d76c432011-10-31 21:42:49 -0700303
Carl Shapiro58551df2011-07-24 03:09:51 -0700304 // True while the garbage collector is running.
Mathieu Chartiera6399032012-06-11 18:49:50 -0700305 volatile bool is_gc_running_;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700306
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700307 // Bytes until concurrent GC starts.
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700308 size_t concurrent_start_bytes_;
309 size_t concurrent_start_size_;
310 size_t concurrent_min_free_;
311
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700312 UniquePtr<HeapBitmap> live_bitmap_;
313 UniquePtr<HeapBitmap> mark_bitmap_;
314
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700315 // True while the garbage collector is trying to signal the GC daemon thread.
316 // This flag is needed to prevent recursion from occurring when the JNI calls
317 // allocate memory and request another GC.
318 bool try_running_gc_;
319
320 // Used to ensure that we don't ever recursively request GC.
321 bool requesting_gc_;
322
Mathieu Chartier5301cd22012-05-31 12:11:36 -0700323 // Mark stack that we reuse to avoid re-allocating the mark stack
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700324 UniquePtr<MarkStack> mark_stack_;
Mathieu Chartier5301cd22012-05-31 12:11:36 -0700325
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800326 // Number of bytes allocated. Adjusted after each allocation and free.
327 size_t num_bytes_allocated_;
Carl Shapiro58551df2011-07-24 03:09:51 -0700328
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800329 // Number of objects allocated. Adjusted after each allocation and free.
330 size_t num_objects_allocated_;
Carl Shapiro58551df2011-07-24 03:09:51 -0700331
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700332 // Last trim time
333 uint64_t last_trim_time_;
334
Brian Carlstrom1f870082011-08-23 16:02:11 -0700335 // offset of java.lang.ref.Reference.referent
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800336 MemberOffset reference_referent_offset_;
Brian Carlstrom1f870082011-08-23 16:02:11 -0700337
338 // offset of java.lang.ref.Reference.queue
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800339 MemberOffset reference_queue_offset_;
Brian Carlstrom1f870082011-08-23 16:02:11 -0700340
341 // offset of java.lang.ref.Reference.queueNext
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800342 MemberOffset reference_queueNext_offset_;
Brian Carlstrom1f870082011-08-23 16:02:11 -0700343
344 // offset of java.lang.ref.Reference.pendingNext
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800345 MemberOffset reference_pendingNext_offset_;
Brian Carlstrom1f870082011-08-23 16:02:11 -0700346
347 // offset of java.lang.ref.FinalizerReference.zombie
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800348 MemberOffset finalizer_reference_zombie_offset_;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700349
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700350 // If we have a zygote space.
351 bool have_zygote_space_;
352
Brian Carlstrom395520e2011-09-25 19:35:00 -0700353 // Target ideal heap utilization ratio
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800354 float target_utilization_;
Brian Carlstrom395520e2011-09-25 19:35:00 -0700355
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800356 bool verify_objects_;
Brian Carlstrom1f870082011-08-23 16:02:11 -0700357
Mathieu Chartierb43b7d42012-06-19 13:15:09 -0700358 friend class ScopedHeapLock;
Ian Rogers30fab402012-01-23 15:43:46 -0800359 FRIEND_TEST(SpaceTest, AllocAndFree);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800360 FRIEND_TEST(SpaceTest, AllocAndFreeList);
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700361 FRIEND_TEST(SpaceTest, ZygoteSpace);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800362 friend class SpaceTest;
Ian Rogers30fab402012-01-23 15:43:46 -0800363
Carl Shapiro69759ea2011-07-21 18:13:35 -0700364 DISALLOW_IMPLICIT_CONSTRUCTORS(Heap);
365};
366
Carl Shapiro1fb86202011-06-27 17:43:13 -0700367} // namespace art
368
369#endif // ART_SRC_HEAP_H_