blob: 094790aeb0b0f6f0933044afc7b447b25ecda5e5 [file] [log] [blame]
Carl Shapiro69759ea2011-07-21 18:13:35 -07001// Copyright 2011 Google Inc. All Rights Reserved.
Carl Shapiro69759ea2011-07-21 18:13:35 -07002
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07003#include "heap.h"
Carl Shapiro58551df2011-07-24 03:09:51 -07004
5#include <vector>
6
Elliott Hughes90a33692011-08-30 13:27:07 -07007#include "UniquePtr.h"
Brian Carlstrom9cff8e12011-08-18 16:47:29 -07008#include "image.h"
Carl Shapiro58551df2011-07-24 03:09:51 -07009#include "mark_sweep.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070010#include "object.h"
11#include "space.h"
Carl Shapiro58551df2011-07-24 03:09:51 -070012#include "stl_util.h"
Elliott Hughes8d768a92011-09-14 16:35:25 -070013#include "thread_list.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070014
15namespace art {
16
Carl Shapiro58551df2011-07-24 03:09:51 -070017std::vector<Space*> Heap::spaces_;
Carl Shapiro69759ea2011-07-21 18:13:35 -070018
Brian Carlstroma663ea52011-08-19 23:33:41 -070019Space* Heap::boot_space_ = NULL;
20
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070021Space* Heap::alloc_space_ = NULL;
Carl Shapiro69759ea2011-07-21 18:13:35 -070022
23size_t Heap::maximum_size_ = 0;
24
Carl Shapiro58551df2011-07-24 03:09:51 -070025size_t Heap::num_bytes_allocated_ = 0;
26
27size_t Heap::num_objects_allocated_ = 0;
28
Carl Shapiro69759ea2011-07-21 18:13:35 -070029bool Heap::is_gc_running_ = false;
30
31HeapBitmap* Heap::mark_bitmap_ = NULL;
32
33HeapBitmap* Heap::live_bitmap_ = NULL;
34
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070035MemberOffset Heap::reference_referent_offset_ = MemberOffset(0);
36MemberOffset Heap::reference_queue_offset_ = MemberOffset(0);
37MemberOffset Heap::reference_queueNext_offset_ = MemberOffset(0);
38MemberOffset Heap::reference_pendingNext_offset_ = MemberOffset(0);
39MemberOffset Heap::finalizer_reference_zombie_offset_ = MemberOffset(0);
Brian Carlstrom1f870082011-08-23 16:02:11 -070040
Elliott Hughes92b3b562011-09-08 16:32:26 -070041Mutex* Heap::lock_ = NULL;
42
43class ScopedHeapLock {
44 public:
45 ScopedHeapLock() {
46 Heap::Lock();
47 }
48
49 ~ScopedHeapLock() {
50 Heap::Unlock();
51 }
52};
53
Elliott Hughesbe759c62011-09-08 19:38:21 -070054void Heap::Init(size_t initial_size, size_t maximum_size,
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070055 const char* boot_image_file_name,
56 std::vector<const char*>& image_file_names) {
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070057 Space* boot_space;
58 byte* requested_base;
59 if (boot_image_file_name == NULL) {
60 boot_space = NULL;
61 requested_base = NULL;
62 } else {
63 boot_space = Space::Create(boot_image_file_name);
64 if (boot_space == NULL) {
Elliott Hughesbe759c62011-09-08 19:38:21 -070065 LOG(FATAL) << "Failed to create space from " << boot_image_file_name;
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070066 }
67 spaces_.push_back(boot_space);
68 requested_base = boot_space->GetBase() + RoundUp(boot_space->Size(), kPageSize);
69 }
70
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070071 std::vector<Space*> image_spaces;
72 for (size_t i = 0; i < image_file_names.size(); i++) {
73 Space* space = Space::Create(image_file_names[i]);
74 if (space == NULL) {
Elliott Hughesbe759c62011-09-08 19:38:21 -070075 LOG(FATAL) << "Failed to create space from " << image_file_names[i];
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070076 }
77 image_spaces.push_back(space);
78 spaces_.push_back(space);
79 requested_base = space->GetBase() + RoundUp(space->Size(), kPageSize);
80 }
81
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070082 Space* space = Space::Create(initial_size, maximum_size, requested_base);
Carl Shapiro58551df2011-07-24 03:09:51 -070083 if (space == NULL) {
Elliott Hughesbe759c62011-09-08 19:38:21 -070084 LOG(FATAL) << "Failed to create alloc space";
Carl Shapiro69759ea2011-07-21 18:13:35 -070085 }
86
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070087 if (boot_space == NULL) {
88 boot_space = space;
89 }
90 byte* base = std::min(boot_space->GetBase(), space->GetBase());
91 byte* limit = std::max(boot_space->GetLimit(), space->GetLimit());
92 DCHECK_LT(base, limit);
93 size_t num_bytes = limit - base;
Carl Shapiro69759ea2011-07-21 18:13:35 -070094
95 // Allocate the initial live bitmap.
Elliott Hughes90a33692011-08-30 13:27:07 -070096 UniquePtr<HeapBitmap> live_bitmap(HeapBitmap::Create(base, num_bytes));
97 if (live_bitmap.get() == NULL) {
Elliott Hughesbe759c62011-09-08 19:38:21 -070098 LOG(FATAL) << "Failed to create live bitmap";
Carl Shapiro69759ea2011-07-21 18:13:35 -070099 }
100
101 // Allocate the initial mark bitmap.
Elliott Hughes90a33692011-08-30 13:27:07 -0700102 UniquePtr<HeapBitmap> mark_bitmap(HeapBitmap::Create(base, num_bytes));
103 if (mark_bitmap.get() == NULL) {
Elliott Hughesbe759c62011-09-08 19:38:21 -0700104 LOG(FATAL) << "Failed to create mark bitmap";
Carl Shapiro69759ea2011-07-21 18:13:35 -0700105 }
106
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700107 alloc_space_ = space;
Carl Shapiro58551df2011-07-24 03:09:51 -0700108 spaces_.push_back(space);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700109 maximum_size_ = maximum_size;
110 live_bitmap_ = live_bitmap.release();
111 mark_bitmap_ = mark_bitmap.release();
112
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700113 num_bytes_allocated_ = 0;
114 num_objects_allocated_ = 0;
115
Carl Shapiro69759ea2011-07-21 18:13:35 -0700116 // TODO: allocate the card table
117
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700118 // Make objects in boot_space live (after live_bitmap_ is set)
119 if (boot_image_file_name != NULL) {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700120 boot_space_ = boot_space;
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700121 RecordImageAllocations(boot_space);
122 }
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700123 for (size_t i = 0; i < image_spaces.size(); i++) {
124 RecordImageAllocations(image_spaces[i]);
125 }
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700126
Elliott Hughes85d15452011-09-16 17:33:01 -0700127 Heap::EnableObjectValidation();
128
Elliott Hughes92b3b562011-09-08 16:32:26 -0700129 // It's still to early to take a lock because there are no threads yet,
130 // but we can create the heap lock now. We don't create it earlier to
131 // make it clear that you can't use locks during heap initialization.
Elliott Hughes8daa0922011-09-11 13:46:25 -0700132 lock_ = new Mutex("Heap lock");
Carl Shapiro69759ea2011-07-21 18:13:35 -0700133}
134
135void Heap::Destroy() {
Elliott Hughes92b3b562011-09-08 16:32:26 -0700136 ScopedHeapLock lock;
Carl Shapiro58551df2011-07-24 03:09:51 -0700137 STLDeleteElements(&spaces_);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700138 if (mark_bitmap_ != NULL) {
139 delete mark_bitmap_;
140 mark_bitmap_ = NULL;
141 }
142 if (live_bitmap_ != NULL) {
143 delete live_bitmap_;
144 }
145 live_bitmap_ = NULL;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700146}
147
Carl Shapiro58551df2011-07-24 03:09:51 -0700148Object* Heap::AllocObject(Class* klass, size_t num_bytes) {
Elliott Hughes92b3b562011-09-08 16:32:26 -0700149 ScopedHeapLock lock;
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700150 DCHECK(klass == NULL
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700151 || klass->GetDescriptor() == NULL
Brian Carlstrom4873d462011-08-21 15:23:39 -0700152 || (klass->IsClassClass() && num_bytes >= sizeof(Class))
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700153 || (klass->IsVariableSize() || klass->GetObjectSize() == num_bytes));
154 DCHECK(num_bytes >= sizeof(Object));
Elliott Hughes92b3b562011-09-08 16:32:26 -0700155 Object* obj = AllocateLocked(num_bytes);
Carl Shapiro58551df2011-07-24 03:09:51 -0700156 if (obj != NULL) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700157 obj->SetClass(klass);
Carl Shapiro58551df2011-07-24 03:09:51 -0700158 }
159 return obj;
160}
161
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700162bool Heap::IsHeapAddress(const Object* obj) {
Elliott Hughes92b3b562011-09-08 16:32:26 -0700163 // Note: we deliberately don't take the lock here, and mustn't test anything that would
164 // require taking the lock.
Elliott Hughesa2501992011-08-26 19:39:54 -0700165 if (!IsAligned(obj, kObjectAlignment)) {
166 return false;
167 }
168 // TODO
169 return true;
170}
171
Elliott Hughes85d15452011-09-16 17:33:01 -0700172bool Heap::verify_objects_ = false;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700173
Elliott Hughes3e465b12011-09-02 18:26:12 -0700174#if VERIFY_OBJECT_ENABLED
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700175void Heap::VerifyObject(const Object* obj) {
Elliott Hughes85d15452011-09-16 17:33:01 -0700176 if (!verify_objects_) {
177 return;
178 }
Elliott Hughes92b3b562011-09-08 16:32:26 -0700179 ScopedHeapLock lock;
180 Heap::VerifyObjectLocked(obj);
181}
182#endif
183
184void Heap::VerifyObjectLocked(const Object* obj) {
Elliott Hughes8daa0922011-09-11 13:46:25 -0700185 lock_->AssertHeld();
Elliott Hughes85d15452011-09-16 17:33:01 -0700186 if (obj != NULL) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700187 if (!IsAligned(obj, kObjectAlignment)) {
188 LOG(FATAL) << "Object isn't aligned: " << obj;
189 } else if (!live_bitmap_->Test(obj)) {
190 // TODO: we don't hold a lock here as it is assumed the live bit map
191 // isn't changing if the mutator is running.
192 LOG(FATAL) << "Object is dead: " << obj;
193 }
194 // Ignore early dawn of the universe verifications
Brian Carlstromdbc05252011-09-09 01:59:59 -0700195 if (num_objects_allocated_ > 10) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700196 const byte* raw_addr = reinterpret_cast<const byte*>(obj) +
197 Object::ClassOffset().Int32Value();
198 const Class* c = *reinterpret_cast<Class* const *>(raw_addr);
199 if (c == NULL) {
200 LOG(FATAL) << "Null class" << " in object: " << obj;
201 } else if (!IsAligned(c, kObjectAlignment)) {
202 LOG(FATAL) << "Class isn't aligned: " << c << " in object: " << obj;
203 } else if (!live_bitmap_->Test(c)) {
204 LOG(FATAL) << "Class of object is dead: " << c << " in object: " << obj;
205 }
206 // Check obj.getClass().getClass() == obj.getClass().getClass().getClass()
207 // NB we don't use the accessors here as they have internal sanity checks
208 // that we don't want to run
209 raw_addr = reinterpret_cast<const byte*>(c) +
210 Object::ClassOffset().Int32Value();
211 const Class* c_c = *reinterpret_cast<Class* const *>(raw_addr);
212 raw_addr = reinterpret_cast<const byte*>(c_c) +
213 Object::ClassOffset().Int32Value();
214 const Class* c_c_c = *reinterpret_cast<Class* const *>(raw_addr);
215 CHECK_EQ(c_c, c_c_c);
216 }
217 }
218}
219
Brian Carlstrom78128a62011-09-15 17:21:19 -0700220void Heap::VerificationCallback(Object* obj, void* arg) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700221 DCHECK(obj != NULL);
Elliott Hughes92b3b562011-09-08 16:32:26 -0700222 Heap::VerifyObjectLocked(obj);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700223}
224
225void Heap::VerifyHeap() {
Elliott Hughes92b3b562011-09-08 16:32:26 -0700226 ScopedHeapLock lock;
227 live_bitmap_->Walk(Heap::VerificationCallback, NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700228}
229
Elliott Hughes92b3b562011-09-08 16:32:26 -0700230void Heap::RecordAllocationLocked(Space* space, const Object* obj) {
231#ifndef NDEBUG
232 if (Runtime::Current()->IsStarted()) {
Elliott Hughes8daa0922011-09-11 13:46:25 -0700233 lock_->AssertHeld();
Elliott Hughes92b3b562011-09-08 16:32:26 -0700234 }
235#endif
Carl Shapiro58551df2011-07-24 03:09:51 -0700236 size_t size = space->AllocationSize(obj);
237 DCHECK_NE(size, 0u);
238 num_bytes_allocated_ += size;
239 num_objects_allocated_ += 1;
240 live_bitmap_->Set(obj);
241}
242
Elliott Hughes92b3b562011-09-08 16:32:26 -0700243void Heap::RecordFreeLocked(Space* space, const Object* obj) {
Elliott Hughes8daa0922011-09-11 13:46:25 -0700244 lock_->AssertHeld();
Carl Shapiro58551df2011-07-24 03:09:51 -0700245 size_t size = space->AllocationSize(obj);
246 DCHECK_NE(size, 0u);
247 if (size < num_bytes_allocated_) {
248 num_bytes_allocated_ -= size;
249 } else {
250 num_bytes_allocated_ = 0;
251 }
252 live_bitmap_->Clear(obj);
253 if (num_objects_allocated_ > 0) {
254 num_objects_allocated_ -= 1;
255 }
256}
257
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700258void Heap::RecordImageAllocations(Space* space) {
Elliott Hughes92b3b562011-09-08 16:32:26 -0700259 DCHECK(!Runtime::Current()->IsStarted());
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700260 CHECK(space != NULL);
261 CHECK(live_bitmap_ != NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700262 byte* current = space->GetBase() + RoundUp(sizeof(ImageHeader), kObjectAlignment);
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700263 while (current < space->GetLimit()) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700264 DCHECK(IsAligned(current, kObjectAlignment));
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700265 const Object* obj = reinterpret_cast<const Object*>(current);
266 live_bitmap_->Set(obj);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700267 current += RoundUp(obj->SizeOf(), kObjectAlignment);
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700268 }
269}
270
Elliott Hughes92b3b562011-09-08 16:32:26 -0700271Object* Heap::AllocateLocked(size_t size) {
Elliott Hughes8daa0922011-09-11 13:46:25 -0700272 lock_->AssertHeld();
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700273 DCHECK(alloc_space_ != NULL);
274 Space* space = alloc_space_;
Elliott Hughes92b3b562011-09-08 16:32:26 -0700275 Object* obj = AllocateLocked(space, size);
Carl Shapiro58551df2011-07-24 03:09:51 -0700276 if (obj != NULL) {
Elliott Hughes92b3b562011-09-08 16:32:26 -0700277 RecordAllocationLocked(space, obj);
Carl Shapiro58551df2011-07-24 03:09:51 -0700278 }
279 return obj;
280}
281
Elliott Hughes92b3b562011-09-08 16:32:26 -0700282Object* Heap::AllocateLocked(Space* space, size_t size) {
Elliott Hughes8daa0922011-09-11 13:46:25 -0700283 lock_->AssertHeld();
Elliott Hughes92b3b562011-09-08 16:32:26 -0700284
Carl Shapiro69759ea2011-07-21 18:13:35 -0700285 // Fail impossible allocations. TODO: collect soft references.
286 if (size > maximum_size_) {
287 return NULL;
288 }
289
Carl Shapiro58551df2011-07-24 03:09:51 -0700290 Object* ptr = space->AllocWithoutGrowth(size);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700291 if (ptr != NULL) {
292 return ptr;
293 }
294
295 // The allocation failed. If the GC is running, block until it
296 // completes and retry.
297 if (is_gc_running_) {
298 // The GC is concurrently tracing the heap. Release the heap
299 // lock, wait for the GC to complete, and retrying allocating.
300 WaitForConcurrentGcToComplete();
Carl Shapiro58551df2011-07-24 03:09:51 -0700301 ptr = space->AllocWithoutGrowth(size);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700302 if (ptr != NULL) {
303 return ptr;
304 }
305 }
306
307 // Another failure. Our thread was starved or there may be too many
308 // live objects. Try a foreground GC. This will have no effect if
309 // the concurrent GC is already running.
Carl Shapiro58551df2011-07-24 03:09:51 -0700310 CollectGarbageInternal();
311 ptr = space->AllocWithoutGrowth(size);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700312 if (ptr != NULL) {
313 return ptr;
314 }
315
316 // Even that didn't work; this is an exceptional state.
317 // Try harder, growing the heap if necessary.
Carl Shapiro58551df2011-07-24 03:09:51 -0700318 ptr = space->AllocWithGrowth(size);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700319 if (ptr != NULL) {
320 //size_t new_footprint = dvmHeapSourceGetIdealFootprint();
Carl Shapiro58551df2011-07-24 03:09:51 -0700321 size_t new_footprint = space->MaxAllowedFootprint();
322 // TODO: may want to grow a little bit more so that the amount of
323 // free space is equal to the old free space + the
324 // utilization slop for the new allocation.
325 LOG(INFO) << "Grow heap (frag case) to " << new_footprint / MB
Carl Shapiro69759ea2011-07-21 18:13:35 -0700326 << "for " << size << "-byte allocation";
327 return ptr;
328 }
329
330 // Most allocations should have succeeded by now, so the heap is
331 // really full, really fragmented, or the requested size is really
332 // big. Do another GC, collecting SoftReferences this time. The VM
333 // spec requires that all SoftReferences have been collected and
334 // cleared before throwing an OOME.
335
Carl Shapiro58551df2011-07-24 03:09:51 -0700336 // TODO: wait for the finalizers from the previous GC to finish
Carl Shapiro69759ea2011-07-21 18:13:35 -0700337 LOG(INFO) << "Forcing collection of SoftReferences for "
338 << size << "-byte allocation";
Carl Shapiro58551df2011-07-24 03:09:51 -0700339 CollectGarbageInternal();
340 ptr = space->AllocWithGrowth(size);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700341 if (ptr != NULL) {
342 return ptr;
343 }
Carl Shapiro69759ea2011-07-21 18:13:35 -0700344
Carl Shapiro69759ea2011-07-21 18:13:35 -0700345 LOG(ERROR) << "Out of memory on a " << size << " byte allocation";
346
Carl Shapiro58551df2011-07-24 03:09:51 -0700347 // TODO: tell the HeapSource to dump its state
348 // TODO: dump stack traces for all threads
Carl Shapiro69759ea2011-07-21 18:13:35 -0700349
Carl Shapiro69759ea2011-07-21 18:13:35 -0700350 return NULL;
351}
352
Elliott Hughesbf86d042011-08-31 17:53:14 -0700353int64_t Heap::GetMaxMemory() {
354 UNIMPLEMENTED(WARNING);
355 return 0;
356}
357
358int64_t Heap::GetTotalMemory() {
359 UNIMPLEMENTED(WARNING);
360 return 0;
361}
362
363int64_t Heap::GetFreeMemory() {
364 UNIMPLEMENTED(WARNING);
365 return 0;
366}
367
Carl Shapiro69759ea2011-07-21 18:13:35 -0700368void Heap::CollectGarbage() {
Elliott Hughes92b3b562011-09-08 16:32:26 -0700369 ScopedHeapLock lock;
Carl Shapiro58551df2011-07-24 03:09:51 -0700370 CollectGarbageInternal();
Carl Shapiro69759ea2011-07-21 18:13:35 -0700371}
372
373void Heap::CollectGarbageInternal() {
Elliott Hughes8daa0922011-09-11 13:46:25 -0700374 lock_->AssertHeld();
Carl Shapiro58551df2011-07-24 03:09:51 -0700375
Elliott Hughes8d768a92011-09-14 16:35:25 -0700376 ThreadList* thread_list = Runtime::Current()->GetThreadList();
377 thread_list->SuspendAll();
Carl Shapiro58551df2011-07-24 03:09:51 -0700378 {
379 MarkSweep mark_sweep;
380
381 mark_sweep.Init();
382
383 mark_sweep.MarkRoots();
384
385 // Push marked roots onto the mark stack
386
387 // TODO: if concurrent
388 // unlock heap
Elliott Hughes8d768a92011-09-14 16:35:25 -0700389 // thread_list->ResumeAll();
Carl Shapiro58551df2011-07-24 03:09:51 -0700390
391 mark_sweep.RecursiveMark();
392
393 // TODO: if concurrent
394 // lock heap
Elliott Hughes8d768a92011-09-14 16:35:25 -0700395 // thread_list->SuspendAll();
Carl Shapiro58551df2011-07-24 03:09:51 -0700396 // re-mark root set
397 // scan dirty objects
398
399 mark_sweep.ProcessReferences(false);
400
401 // TODO: swap bitmaps
402
403 mark_sweep.Sweep();
404 }
405
406 GrowForUtilization();
Elliott Hughes8d768a92011-09-14 16:35:25 -0700407 thread_list->ResumeAll();
Carl Shapiro69759ea2011-07-21 18:13:35 -0700408}
409
410void Heap::WaitForConcurrentGcToComplete() {
Elliott Hughes8daa0922011-09-11 13:46:25 -0700411 lock_->AssertHeld();
Carl Shapiro69759ea2011-07-21 18:13:35 -0700412}
413
414// Given the current contents of the active heap, increase the allowed
415// heap footprint to match the target utilization ratio. This should
416// only be called immediately after a full garbage collection.
417void Heap::GrowForUtilization() {
Elliott Hughes8daa0922011-09-11 13:46:25 -0700418 lock_->AssertHeld();
Elliott Hughes53b61312011-08-12 18:28:20 -0700419 UNIMPLEMENTED(ERROR);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700420}
421
Elliott Hughes92b3b562011-09-08 16:32:26 -0700422void Heap::Lock() {
Elliott Hughes93e74e82011-09-13 11:07:03 -0700423 // TODO: grab the lock, but put ourselves into Thread::kVmWait if it looks like
Elliott Hughes92b3b562011-09-08 16:32:26 -0700424 // we're going to have to wait on the mutex.
425 lock_->Lock();
426}
427
428void Heap::Unlock() {
429 lock_->Unlock();
430}
431
Carl Shapiro69759ea2011-07-21 18:13:35 -0700432} // namespace art