Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "mark_sweep.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 18 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 19 | #include <functional> |
| 20 | #include <numeric> |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 21 | #include <climits> |
| 22 | #include <vector> |
| 23 | |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 24 | #include "barrier.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 25 | #include "base/logging.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 26 | #include "base/macros.h" |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 27 | #include "base/mutex-inl.h" |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 28 | #include "card_table.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | #include "card_table-inl.h" |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 30 | #include "heap.h" |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 31 | #include "indirect_reference_table.h" |
| 32 | #include "intern_table.h" |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 33 | #include "jni_internal.h" |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 34 | #include "large_object_space.h" |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 35 | #include "monitor.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 36 | #include "mark_sweep-inl.h" |
| 37 | #include "mirror/class-inl.h" |
| 38 | #include "mirror/class_loader.h" |
| 39 | #include "mirror/dex_cache.h" |
| 40 | #include "mirror/field.h" |
| 41 | #include "mirror/field-inl.h" |
| 42 | #include "mirror/object-inl.h" |
| 43 | #include "mirror/object_array.h" |
| 44 | #include "mirror/object_array-inl.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 45 | #include "runtime.h" |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 46 | #include "space.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 47 | #include "space_bitmap-inl.h" |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 48 | #include "timing_logger.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 49 | #include "thread.h" |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 50 | #include "thread_list.h" |
Ian Rogers | 0825427 | 2012-10-23 17:49:23 -0700 | [diff] [blame] | 51 | #include "verifier/method_verifier.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 52 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 53 | using namespace art::mirror; |
| 54 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 55 | namespace art { |
| 56 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 57 | // Performance options. |
| 58 | static const bool kParallelMarkStack = true; |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 59 | static const bool kDisableFinger = kParallelMarkStack; |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 60 | static const bool kUseMarkStackPrefetch = true; |
| 61 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 62 | // Profiling and information flags. |
| 63 | static const bool kCountClassesMarked = false; |
| 64 | static const bool kProfileLargeObjects = false; |
| 65 | static const bool kMeasureOverhead = false; |
| 66 | static const bool kCountTasks = false; |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 67 | static const bool kCountJavaLangRefs = false; |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 68 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 69 | class SetFingerVisitor { |
| 70 | public: |
| 71 | SetFingerVisitor(MarkSweep* const mark_sweep) : mark_sweep_(mark_sweep) { |
| 72 | |
| 73 | } |
| 74 | |
| 75 | void operator ()(void* finger) const { |
| 76 | mark_sweep_->SetFinger(reinterpret_cast<Object*>(finger)); |
| 77 | } |
| 78 | |
| 79 | private: |
| 80 | MarkSweep* const mark_sweep_; |
| 81 | }; |
| 82 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 83 | std::string MarkSweep::GetName() const { |
| 84 | std::ostringstream ss; |
| 85 | ss << (IsConcurrent() ? "Concurrent" : "") << GetGcType(); |
| 86 | return ss.str(); |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 87 | } |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 88 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 89 | void MarkSweep::ImmuneSpace(ContinuousSpace* space) { |
| 90 | // Bind live to mark bitmap if necessary. |
| 91 | if (space->GetLiveBitmap() != space->GetMarkBitmap()) { |
| 92 | BindLiveToMarkBitmap(space); |
| 93 | } |
| 94 | |
| 95 | // Add the space to the immune region. |
| 96 | if (immune_begin_ == NULL) { |
| 97 | DCHECK(immune_end_ == NULL); |
| 98 | SetImmuneRange(reinterpret_cast<Object*>(space->Begin()), |
| 99 | reinterpret_cast<Object*>(space->End())); |
| 100 | } else { |
| 101 | const Spaces& spaces = GetHeap()->GetSpaces(); |
| 102 | const ContinuousSpace* prev_space = NULL; |
| 103 | // Find out if the previous space is immune. |
| 104 | // TODO: C++0x |
| 105 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
| 106 | if (*it == space) { |
| 107 | break; |
| 108 | } |
| 109 | prev_space = *it; |
| 110 | } |
| 111 | |
| 112 | // If previous space was immune, then extend the immune region. |
| 113 | if (prev_space != NULL && |
| 114 | immune_begin_ <= reinterpret_cast<Object*>(prev_space->Begin()) && |
| 115 | immune_end_ >= reinterpret_cast<Object*>(prev_space->End())) { |
| 116 | immune_begin_ = std::min(reinterpret_cast<Object*>(space->Begin()), immune_begin_); |
| 117 | immune_end_ = std::max(reinterpret_cast<Object*>(space->End()), immune_end_); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Bind the live bits to the mark bits of bitmaps based on the gc type. |
| 123 | void MarkSweep::BindBitmaps() { |
| 124 | Spaces& spaces = GetHeap()->GetSpaces(); |
| 125 | WriterMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_); |
| 126 | |
| 127 | // Mark all of the spaces we never collect as immune. |
| 128 | for (Spaces::iterator it = spaces.begin(); it != spaces.end(); ++it) { |
| 129 | ContinuousSpace* space = *it; |
| 130 | if (space->GetGcRetentionPolicy() == kGcRetentionPolicyNeverCollect) { |
| 131 | ImmuneSpace(space); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | MarkSweep::MarkSweep(Heap* heap, bool is_concurrent) |
| 137 | : GarbageCollector(heap), |
| 138 | gc_barrier_(new Barrier(0)), |
| 139 | large_object_lock_("large object lock"), |
| 140 | mark_stack_expand_lock_("mark stack expand lock"), |
| 141 | timings_(GetName(), true), |
| 142 | cumulative_timings_(GetName(), true), |
| 143 | is_concurrent_(is_concurrent) { |
| 144 | cumulative_timings_.SetName(GetName()); |
| 145 | ResetCumulativeStatistics(); |
| 146 | } |
| 147 | |
| 148 | void MarkSweep::InitializePhase() { |
| 149 | mark_stack_ = GetHeap()->mark_stack_.get(); |
| 150 | DCHECK(mark_stack_ != NULL); |
| 151 | finger_ = NULL; |
| 152 | SetImmuneRange(NULL, NULL); |
| 153 | soft_reference_list_ = NULL; |
| 154 | weak_reference_list_ = NULL; |
| 155 | finalizer_reference_list_ = NULL; |
| 156 | phantom_reference_list_ = NULL; |
| 157 | cleared_reference_list_ = NULL; |
| 158 | freed_bytes_ = 0; |
| 159 | freed_objects_ = 0; |
| 160 | class_count_ = 0; |
| 161 | array_count_ = 0; |
| 162 | other_count_ = 0; |
| 163 | large_object_test_ = 0; |
| 164 | large_object_mark_ = 0; |
| 165 | classes_marked_ = 0; |
| 166 | overhead_time_ = 0; |
| 167 | work_chunks_created_ = 0; |
| 168 | work_chunks_deleted_ = 0; |
| 169 | reference_count_ = 0; |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 170 | java_lang_Class_ = Class::GetJavaLangClass(); |
| 171 | CHECK(java_lang_Class_ != NULL); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 172 | FindDefaultMarkBitmap(); |
Mathieu Chartier | 9ebae1f | 2012-10-15 17:38:16 -0700 | [diff] [blame] | 173 | // Mark any concurrent roots as dirty since we need to scan them at least once during this GC. |
| 174 | Runtime::Current()->DirtyRoots(); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 175 | timings_.Reset(); |
| 176 | // Do any pre GC verification. |
| 177 | heap_->PreGcVerification(this); |
| 178 | } |
| 179 | |
| 180 | void MarkSweep::ProcessReferences(Thread* self) { |
Mathieu Chartier | 8e56c7e | 2012-11-20 13:25:50 -0800 | [diff] [blame] | 181 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 182 | ProcessReferences(&soft_reference_list_, clear_soft_references_, &weak_reference_list_, |
| 183 | &finalizer_reference_list_, &phantom_reference_list_); |
| 184 | timings_.AddSplit("ProcessReferences"); |
| 185 | } |
| 186 | |
| 187 | bool MarkSweep::HandleDirtyObjectsPhase() { |
| 188 | Thread* self = Thread::Current(); |
| 189 | ObjectStack* allocation_stack = GetHeap()->allocation_stack_.get(); |
| 190 | Locks::mutator_lock_->AssertExclusiveHeld(self); |
| 191 | |
| 192 | { |
| 193 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
| 194 | |
| 195 | // Re-mark root set. |
| 196 | ReMarkRoots(); |
| 197 | timings_.AddSplit("ReMarkRoots"); |
| 198 | |
| 199 | // Scan dirty objects, this is only required if we are not doing concurrent GC. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 200 | RecursiveMarkDirtyObjects(CardTable::kCardDirty); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | ProcessReferences(self); |
| 204 | |
| 205 | // Only need to do this if we have the card mark verification on, and only during concurrent GC. |
| 206 | if (GetHeap()->verify_missing_card_marks_) { |
| 207 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
| 208 | // This second sweep makes sure that we don't have any objects in the live stack which point to |
| 209 | // freed objects. These cause problems since their references may be previously freed objects. |
| 210 | SweepArray(timings_, allocation_stack, false); |
| 211 | } else { |
| 212 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
| 213 | // We only sweep over the live stack, and the live stack should not intersect with the |
| 214 | // allocation stack, so it should be safe to UnMark anything in the allocation stack as live. |
| 215 | heap_->UnMarkAllocStack(GetHeap()->alloc_space_->GetMarkBitmap(), |
| 216 | GetHeap()->large_object_space_->GetMarkObjects(), |
| 217 | allocation_stack); |
| 218 | timings_.AddSplit("UnMarkAllocStack"); |
| 219 | } |
| 220 | return true; |
| 221 | } |
| 222 | |
| 223 | bool MarkSweep::IsConcurrent() const { |
| 224 | return is_concurrent_; |
| 225 | } |
| 226 | |
| 227 | void MarkSweep::MarkingPhase() { |
| 228 | Heap* heap = GetHeap(); |
| 229 | Thread* self = Thread::Current(); |
| 230 | |
| 231 | BindBitmaps(); |
| 232 | FindDefaultMarkBitmap(); |
| 233 | timings_.AddSplit("BindBitmaps"); |
| 234 | |
| 235 | // Process dirty cards and add dirty cards to mod union tables. |
| 236 | heap->ProcessCards(timings_); |
| 237 | |
| 238 | // Need to do this before the checkpoint since we don't want any threads to add references to |
| 239 | // the live stack during the recursive mark. |
| 240 | heap->SwapStacks(); |
| 241 | timings_.AddSplit("SwapStacks"); |
| 242 | |
| 243 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
| 244 | if (Locks::mutator_lock_->IsExclusiveHeld(self)) { |
| 245 | // If we exclusively hold the mutator lock, all threads must be suspended. |
| 246 | MarkRoots(); |
| 247 | timings_.AddSplit("MarkConcurrentRoots"); |
| 248 | } else { |
| 249 | MarkRootsCheckpoint(); |
| 250 | timings_.AddSplit("MarkRootsCheckpoint"); |
| 251 | MarkNonThreadRoots(); |
| 252 | timings_.AddSplit("MarkNonThreadRoots"); |
| 253 | } |
| 254 | MarkConcurrentRoots(); |
| 255 | timings_.AddSplit("MarkConcurrentRoots"); |
| 256 | |
| 257 | heap->UpdateAndMarkModUnion(this, timings_, GetGcType()); |
| 258 | MarkReachableObjects(); |
| 259 | } |
| 260 | |
| 261 | void MarkSweep::MarkReachableObjects() { |
| 262 | // Mark everything allocated since the last as GC live so that we can sweep concurrently, |
| 263 | // knowing that new allocations won't be marked as live. |
| 264 | ObjectStack* live_stack = heap_->GetLiveStack(); |
| 265 | heap_->MarkAllocStack(heap_->alloc_space_->GetLiveBitmap(), |
| 266 | heap_->large_object_space_->GetLiveObjects(), |
| 267 | live_stack); |
| 268 | live_stack->Reset(); |
| 269 | timings_.AddSplit("MarkStackAsLive"); |
| 270 | // Recursively mark all the non-image bits set in the mark bitmap. |
| 271 | RecursiveMark(); |
| 272 | DisableFinger(); |
| 273 | } |
| 274 | |
| 275 | void MarkSweep::ReclaimPhase() { |
| 276 | Thread* self = Thread::Current(); |
| 277 | |
| 278 | if (!IsConcurrent()) { |
| 279 | ProcessReferences(self); |
| 280 | } |
| 281 | |
| 282 | // Before freeing anything, lets verify the heap. |
| 283 | if (kIsDebugBuild) { |
| 284 | ReaderMutexLock mu(self, *Locks::heap_bitmap_lock_); |
| 285 | VerifyImageRoots(); |
| 286 | } |
| 287 | heap_->PreSweepingGcVerification(this); |
| 288 | |
| 289 | { |
| 290 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
| 291 | |
| 292 | // Reclaim unmarked objects. |
| 293 | Sweep(timings_, false); |
| 294 | |
| 295 | // Swap the live and mark bitmaps for each space which we modified space. This is an |
| 296 | // optimization that enables us to not clear live bits inside of the sweep. Only swaps unbound |
| 297 | // bitmaps. |
| 298 | SwapBitmaps(); |
| 299 | timings_.AddSplit("SwapBitmaps"); |
| 300 | |
| 301 | // Unbind the live and mark bitmaps. |
| 302 | UnBindBitmaps(); |
| 303 | } |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void MarkSweep::SwapBitmaps() { |
| 307 | // Swap the live and mark bitmaps for each alloc space. This is needed since sweep re-swaps |
| 308 | // these bitmaps. The bitmap swapping is an optimization so that we do not need to clear the live |
| 309 | // bits of dead objects in the live bitmap. |
| 310 | const GcType gc_type = GetGcType(); |
| 311 | // TODO: C++0x |
| 312 | Spaces& spaces = heap_->GetSpaces(); |
| 313 | for (Spaces::iterator it = spaces.begin(); it != spaces.end(); ++it) { |
| 314 | ContinuousSpace* space = *it; |
| 315 | // We never allocate into zygote spaces. |
| 316 | if (space->GetGcRetentionPolicy() == kGcRetentionPolicyAlwaysCollect || |
| 317 | (gc_type == kGcTypeFull && |
| 318 | space->GetGcRetentionPolicy() == kGcRetentionPolicyFullCollect)) { |
| 319 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
| 320 | SpaceBitmap* mark_bitmap = space->GetMarkBitmap(); |
| 321 | if (live_bitmap != mark_bitmap) { |
| 322 | heap_->GetLiveBitmap()->ReplaceBitmap(live_bitmap, mark_bitmap); |
| 323 | heap_->GetMarkBitmap()->ReplaceBitmap(mark_bitmap, live_bitmap); |
| 324 | space->AsAllocSpace()->SwapBitmaps(); |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | SwapLargeObjects(); |
| 329 | } |
| 330 | |
| 331 | void MarkSweep::SwapLargeObjects() { |
| 332 | LargeObjectSpace* large_object_space = heap_->GetLargeObjectsSpace(); |
| 333 | large_object_space->SwapBitmaps(); |
| 334 | heap_->GetLiveBitmap()->SetLargeObjects(large_object_space->GetLiveObjects()); |
| 335 | heap_->GetMarkBitmap()->SetLargeObjects(large_object_space->GetMarkObjects()); |
| 336 | } |
| 337 | |
| 338 | void MarkSweep::SetImmuneRange(Object* begin, Object* end) { |
| 339 | immune_begin_ = begin; |
| 340 | immune_end_ = end; |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 343 | void MarkSweep::FindDefaultMarkBitmap() { |
| 344 | const Spaces& spaces = heap_->GetSpaces(); |
| 345 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
| 346 | if ((*it)->GetGcRetentionPolicy() == kGcRetentionPolicyAlwaysCollect) { |
| 347 | current_mark_bitmap_ = (*it)->GetMarkBitmap(); |
| 348 | CHECK(current_mark_bitmap_ != NULL); |
| 349 | return; |
| 350 | } |
| 351 | } |
| 352 | GetHeap()->DumpSpaces(); |
| 353 | LOG(FATAL) << "Could not find a default mark bitmap"; |
| 354 | } |
| 355 | |
Mathieu Chartier | ac86a7c | 2012-11-12 15:03:16 -0800 | [diff] [blame] | 356 | void MarkSweep::ExpandMarkStack() { |
| 357 | // Rare case, no need to have Thread::Current be a parameter. |
| 358 | MutexLock mu(Thread::Current(), mark_stack_expand_lock_); |
| 359 | if (UNLIKELY(mark_stack_->Size() < mark_stack_->Capacity())) { |
| 360 | // Someone else acquired the lock and expanded the mark stack before us. |
| 361 | return; |
| 362 | } |
| 363 | std::vector<Object*> temp; |
| 364 | temp.insert(temp.begin(), mark_stack_->Begin(), mark_stack_->End()); |
| 365 | mark_stack_->Resize(mark_stack_->Capacity() * 2); |
| 366 | for (size_t i = 0; i < temp.size(); ++i) { |
| 367 | mark_stack_->PushBack(temp[i]); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | inline void MarkSweep::MarkObjectNonNullParallel(const Object* obj, bool check_finger) { |
| 372 | DCHECK(obj != NULL); |
| 373 | if (MarkObjectParallel(obj)) { |
| 374 | if (kDisableFinger || (check_finger && obj < finger_)) { |
| 375 | while (UNLIKELY(!mark_stack_->AtomicPushBack(const_cast<Object*>(obj)))) { |
| 376 | // Only reason a push can fail is that the mark stack is full. |
| 377 | ExpandMarkStack(); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 383 | inline void MarkSweep::MarkObjectNonNull(const Object* obj, bool check_finger) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 384 | DCHECK(obj != NULL); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 385 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 386 | if (obj >= immune_begin_ && obj < immune_end_) { |
| 387 | DCHECK(IsMarked(obj)); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 388 | return; |
| 389 | } |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 390 | |
| 391 | // Try to take advantage of locality of references within a space, failing this find the space |
| 392 | // the hard way. |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 393 | SpaceBitmap* object_bitmap = current_mark_bitmap_; |
| 394 | if (UNLIKELY(!object_bitmap->HasAddress(obj))) { |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 395 | SpaceBitmap* new_bitmap = heap_->GetMarkBitmap()->GetSpaceBitmap(obj); |
| 396 | if (new_bitmap != NULL) { |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 397 | object_bitmap = new_bitmap; |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 398 | } else { |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 399 | MarkLargeObject(obj); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 400 | return; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 401 | } |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 404 | // This object was not previously marked. |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 405 | if (!object_bitmap->Test(obj)) { |
| 406 | object_bitmap->Set(obj); |
| 407 | if (kDisableFinger || (check_finger && obj < finger_)) { |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 408 | // Do we need to expand the mark stack? |
| 409 | if (UNLIKELY(mark_stack_->Size() >= mark_stack_->Capacity())) { |
Mathieu Chartier | ac86a7c | 2012-11-12 15:03:16 -0800 | [diff] [blame] | 410 | ExpandMarkStack(); |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 411 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 412 | // The object must be pushed on to the mark stack. |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 413 | mark_stack_->PushBack(const_cast<Object*>(obj)); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 418 | // Rare case, probably not worth inlining since it will increase instruction cache miss rate. |
| 419 | bool MarkSweep::MarkLargeObject(const Object* obj) { |
| 420 | LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); |
| 421 | SpaceSetMap* large_objects = large_object_space->GetMarkObjects(); |
| 422 | if (kProfileLargeObjects) { |
| 423 | ++large_object_test_; |
| 424 | } |
| 425 | if (UNLIKELY(!large_objects->Test(obj))) { |
| 426 | if (!large_object_space->Contains(obj)) { |
| 427 | LOG(ERROR) << "Tried to mark " << obj << " not contained by any spaces"; |
| 428 | LOG(ERROR) << "Attempting see if it's a bad root"; |
| 429 | VerifyRoots(); |
| 430 | LOG(FATAL) << "Can't mark bad root"; |
| 431 | } |
| 432 | if (kProfileLargeObjects) { |
| 433 | ++large_object_mark_; |
| 434 | } |
| 435 | large_objects->Set(obj); |
| 436 | // Don't need to check finger since large objects never have any object references. |
| 437 | return true; |
| 438 | } |
| 439 | return false; |
| 440 | } |
| 441 | |
| 442 | inline bool MarkSweep::MarkObjectParallel(const Object* obj) { |
| 443 | DCHECK(obj != NULL); |
| 444 | |
| 445 | if (obj >= immune_begin_ && obj < immune_end_) { |
| 446 | DCHECK(IsMarked(obj)); |
| 447 | return false; |
| 448 | } |
| 449 | |
| 450 | // Try to take advantage of locality of references within a space, failing this find the space |
| 451 | // the hard way. |
| 452 | SpaceBitmap* object_bitmap = current_mark_bitmap_; |
| 453 | if (UNLIKELY(!object_bitmap->HasAddress(obj))) { |
| 454 | SpaceBitmap* new_bitmap = heap_->GetMarkBitmap()->GetSpaceBitmap(obj); |
| 455 | if (new_bitmap != NULL) { |
| 456 | object_bitmap = new_bitmap; |
| 457 | } else { |
| 458 | // TODO: Remove the Thread::Current here? |
| 459 | // TODO: Convert this to some kind of atomic marking? |
| 460 | MutexLock mu(Thread::Current(), large_object_lock_); |
| 461 | return MarkLargeObject(obj); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | // Return true if the object was not previously marked. |
| 466 | return !object_bitmap->AtomicTestAndSet(obj); |
| 467 | } |
| 468 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 469 | // Used to mark objects when recursing. Recursion is done by moving |
| 470 | // the finger across the bitmaps in address order and marking child |
| 471 | // objects. Any newly-marked objects whose addresses are lower than |
| 472 | // the finger won't be visited by the bitmap scan, so those objects |
| 473 | // need to be added to the mark stack. |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 474 | void MarkSweep::MarkObject(const Object* obj) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 475 | if (obj != NULL) { |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 476 | MarkObjectNonNull(obj, true); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 480 | void MarkSweep::MarkRoot(const Object* obj) { |
| 481 | if (obj != NULL) { |
| 482 | MarkObjectNonNull(obj, false); |
| 483 | } |
| 484 | } |
| 485 | |
Mathieu Chartier | ac86a7c | 2012-11-12 15:03:16 -0800 | [diff] [blame] | 486 | void MarkSweep::MarkRootParallelCallback(const Object* root, void* arg) { |
| 487 | DCHECK(root != NULL); |
| 488 | DCHECK(arg != NULL); |
| 489 | MarkSweep* mark_sweep = reinterpret_cast<MarkSweep*>(arg); |
| 490 | mark_sweep->MarkObjectNonNullParallel(root, false); |
| 491 | } |
| 492 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 493 | void MarkSweep::MarkObjectCallback(const Object* root, void* arg) { |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 494 | DCHECK(root != NULL); |
| 495 | DCHECK(arg != NULL); |
| 496 | MarkSweep* mark_sweep = reinterpret_cast<MarkSweep*>(arg); |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 497 | mark_sweep->MarkObjectNonNull(root, false); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 500 | void MarkSweep::ReMarkObjectVisitor(const Object* root, void* arg) { |
| 501 | DCHECK(root != NULL); |
| 502 | DCHECK(arg != NULL); |
| 503 | MarkSweep* mark_sweep = reinterpret_cast<MarkSweep*>(arg); |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 504 | mark_sweep->MarkObjectNonNull(root, true); |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 507 | void MarkSweep::VerifyRootCallback(const Object* root, void* arg, size_t vreg, |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 508 | const StackVisitor* visitor) { |
| 509 | reinterpret_cast<MarkSweep*>(arg)->VerifyRoot(root, vreg, visitor); |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 512 | void MarkSweep::VerifyRoot(const Object* root, size_t vreg, const StackVisitor* visitor) { |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 513 | // See if the root is on any space bitmap. |
Mathieu Chartier | 128c52c | 2012-10-16 14:12:41 -0700 | [diff] [blame] | 514 | if (GetHeap()->GetLiveBitmap()->GetSpaceBitmap(root) == NULL) { |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 515 | LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); |
Mathieu Chartier | 4202b74 | 2012-10-17 17:51:25 -0700 | [diff] [blame] | 516 | if (!large_object_space->Contains(root)) { |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 517 | LOG(ERROR) << "Found invalid root: " << root; |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 518 | if (visitor != NULL) { |
| 519 | LOG(ERROR) << visitor->DescribeLocation() << " in VReg: " << vreg; |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | void MarkSweep::VerifyRoots() { |
| 526 | Runtime::Current()->GetThreadList()->VerifyRoots(VerifyRootCallback, this); |
| 527 | } |
| 528 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 529 | // Marks all objects in the root set. |
| 530 | void MarkSweep::MarkRoots() { |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 531 | Runtime::Current()->VisitNonConcurrentRoots(MarkObjectCallback, this); |
Mathieu Chartier | 9ebae1f | 2012-10-15 17:38:16 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 534 | void MarkSweep::MarkNonThreadRoots() { |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 535 | Runtime::Current()->VisitNonThreadRoots(MarkObjectCallback, this); |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Mathieu Chartier | 9ebae1f | 2012-10-15 17:38:16 -0700 | [diff] [blame] | 538 | void MarkSweep::MarkConcurrentRoots() { |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 539 | Runtime::Current()->VisitConcurrentRoots(MarkObjectCallback, this); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 542 | class CheckObjectVisitor { |
| 543 | public: |
| 544 | CheckObjectVisitor(MarkSweep* const mark_sweep) |
| 545 | : mark_sweep_(mark_sweep) { |
| 546 | |
| 547 | } |
| 548 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 549 | void operator ()(const Object* obj, const Object* ref, MemberOffset offset, bool is_static) const |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 550 | NO_THREAD_SAFETY_ANALYSIS { |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 551 | if (kDebugLocking) { |
| 552 | Locks::heap_bitmap_lock_->AssertSharedHeld(Thread::Current()); |
| 553 | } |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 554 | mark_sweep_->CheckReference(obj, ref, offset, is_static); |
| 555 | } |
| 556 | |
| 557 | private: |
| 558 | MarkSweep* const mark_sweep_; |
| 559 | }; |
| 560 | |
| 561 | void MarkSweep::CheckObject(const Object* obj) { |
| 562 | DCHECK(obj != NULL); |
| 563 | CheckObjectVisitor visitor(this); |
| 564 | VisitObjectReferences(obj, visitor); |
| 565 | } |
| 566 | |
| 567 | void MarkSweep::VerifyImageRootVisitor(Object* root, void* arg) { |
| 568 | DCHECK(root != NULL); |
| 569 | DCHECK(arg != NULL); |
| 570 | MarkSweep* mark_sweep = reinterpret_cast<MarkSweep*>(arg); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 571 | DCHECK(mark_sweep->heap_->GetMarkBitmap()->Test(root)); |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 572 | mark_sweep->CheckObject(root); |
| 573 | } |
| 574 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 575 | void MarkSweep::BindLiveToMarkBitmap(ContinuousSpace* space) { |
| 576 | CHECK(space->IsAllocSpace()); |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 577 | DlMallocSpace* alloc_space = space->AsAllocSpace(); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 578 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
| 579 | SpaceBitmap* mark_bitmap = alloc_space->mark_bitmap_.release(); |
| 580 | GetHeap()->GetMarkBitmap()->ReplaceBitmap(mark_bitmap, live_bitmap); |
| 581 | alloc_space->temp_bitmap_.reset(mark_bitmap); |
| 582 | alloc_space->mark_bitmap_.reset(live_bitmap); |
| 583 | } |
| 584 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 585 | class ScanObjectVisitor { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 586 | public: |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 587 | ScanObjectVisitor(MarkSweep* const mark_sweep) : mark_sweep_(mark_sweep) { |
| 588 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 591 | // TODO: Fixme when anotatalysis works with visitors. |
| 592 | void operator ()(const Object* obj) const NO_THREAD_SAFETY_ANALYSIS { |
| 593 | if (kDebugLocking) { |
| 594 | Locks::mutator_lock_->AssertSharedHeld(Thread::Current()); |
| 595 | Locks::heap_bitmap_lock_->AssertExclusiveHeld(Thread::Current()); |
| 596 | } |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 597 | mark_sweep_->ScanObject(obj); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | private: |
| 601 | MarkSweep* const mark_sweep_; |
| 602 | }; |
| 603 | |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 604 | void MarkSweep::ScanGrayObjects(byte minimum_age) { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 605 | const Spaces& spaces = heap_->GetSpaces(); |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 606 | CardTable* card_table = heap_->GetCardTable(); |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 607 | ScanObjectVisitor visitor(this); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 608 | SetFingerVisitor finger_visitor(this); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 609 | // TODO: C++ 0x auto |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 610 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 611 | ContinuousSpace* space = *it; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 612 | byte* begin = space->Begin(); |
| 613 | byte* end = space->End(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 614 | // Image spaces are handled properly since live == marked for them. |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 615 | SpaceBitmap* mark_bitmap = space->GetMarkBitmap(); |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 616 | card_table->Scan(mark_bitmap, begin, end, visitor, VoidFunctor(), minimum_age); |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 620 | class CheckBitmapVisitor { |
| 621 | public: |
| 622 | CheckBitmapVisitor(MarkSweep* mark_sweep) : mark_sweep_(mark_sweep) { |
| 623 | |
| 624 | } |
| 625 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 626 | void operator ()(const Object* obj) const |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 627 | NO_THREAD_SAFETY_ANALYSIS { |
| 628 | if (kDebugLocking) { |
| 629 | Locks::heap_bitmap_lock_->AssertSharedHeld(Thread::Current()); |
| 630 | } |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 631 | DCHECK(obj != NULL); |
| 632 | mark_sweep_->CheckObject(obj); |
| 633 | } |
| 634 | |
| 635 | private: |
| 636 | MarkSweep* mark_sweep_; |
| 637 | }; |
| 638 | |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 639 | void MarkSweep::VerifyImageRoots() { |
| 640 | // Verify roots ensures that all the references inside the image space point |
| 641 | // objects which are either in the image space or marked objects in the alloc |
| 642 | // space |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 643 | CheckBitmapVisitor visitor(this); |
| 644 | const Spaces& spaces = heap_->GetSpaces(); |
| 645 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 646 | if ((*it)->IsImageSpace()) { |
| 647 | ImageSpace* space = (*it)->AsImageSpace(); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 648 | uintptr_t begin = reinterpret_cast<uintptr_t>(space->Begin()); |
| 649 | uintptr_t end = reinterpret_cast<uintptr_t>(space->End()); |
| 650 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 651 | DCHECK(live_bitmap != NULL); |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 652 | live_bitmap->VisitMarkedRange(begin, end, visitor, VoidFunctor()); |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 653 | } |
| 654 | } |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 657 | // Populates the mark stack based on the set of marked objects and |
| 658 | // recursively marks until the mark stack is emptied. |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 659 | void MarkSweep::RecursiveMark() { |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 660 | // RecursiveMark will build the lists of known instances of the Reference classes. |
| 661 | // See DelayReferenceReferent for details. |
| 662 | CHECK(soft_reference_list_ == NULL); |
| 663 | CHECK(weak_reference_list_ == NULL); |
| 664 | CHECK(finalizer_reference_list_ == NULL); |
| 665 | CHECK(phantom_reference_list_ == NULL); |
| 666 | CHECK(cleared_reference_list_ == NULL); |
| 667 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 668 | const bool partial = GetGcType() == kGcTypePartial; |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 669 | const Spaces& spaces = heap_->GetSpaces(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 670 | SetFingerVisitor set_finger_visitor(this); |
| 671 | ScanObjectVisitor scan_visitor(this); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 672 | if (!kDisableFinger) { |
| 673 | finger_ = NULL; |
| 674 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
| 675 | ContinuousSpace* space = *it; |
| 676 | if ((space->GetGcRetentionPolicy() == kGcRetentionPolicyAlwaysCollect) || |
| 677 | (!partial && space->GetGcRetentionPolicy() == kGcRetentionPolicyFullCollect) |
| 678 | ) { |
| 679 | current_mark_bitmap_ = space->GetMarkBitmap(); |
| 680 | if (current_mark_bitmap_ == NULL) { |
| 681 | GetHeap()->DumpSpaces(); |
| 682 | LOG(FATAL) << "invalid bitmap"; |
| 683 | } |
| 684 | // This function does not handle heap end increasing, so we must use the space end. |
| 685 | uintptr_t begin = reinterpret_cast<uintptr_t>(space->Begin()); |
| 686 | uintptr_t end = reinterpret_cast<uintptr_t>(space->End()); |
| 687 | current_mark_bitmap_->VisitMarkedRange(begin, end, scan_visitor, set_finger_visitor); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 688 | } |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 689 | } |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 690 | } |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 691 | DisableFinger(); |
| 692 | timings_.AddSplit("RecursiveMark"); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 693 | ProcessMarkStack(); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 694 | timings_.AddSplit("ProcessMarkStack"); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | bool MarkSweep::IsMarkedCallback(const Object* object, void* arg) { |
| 698 | return |
| 699 | reinterpret_cast<MarkSweep*>(arg)->IsMarked(object) || |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 700 | !reinterpret_cast<MarkSweep*>(arg)->GetHeap()->GetLiveBitmap()->Test(object); |
| 701 | } |
| 702 | |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 703 | void MarkSweep::RecursiveMarkDirtyObjects(byte minimum_age) { |
| 704 | ScanGrayObjects(minimum_age); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 705 | timings_.AddSplit("ScanGrayObjects"); |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 706 | ProcessMarkStack(); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 707 | timings_.AddSplit("ProcessMarkStack"); |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 710 | void MarkSweep::ReMarkRoots() { |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 711 | Runtime::Current()->VisitRoots(ReMarkObjectVisitor, this); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 714 | void MarkSweep::SweepJniWeakGlobals(IsMarkedTester is_marked, void* arg) { |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 715 | JavaVMExt* vm = Runtime::Current()->GetJavaVM(); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 716 | MutexLock mu(Thread::Current(), vm->weak_globals_lock); |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 717 | IndirectReferenceTable* table = &vm->weak_globals; |
Mathieu Chartier | 654d3a2 | 2012-07-11 17:54:18 -0700 | [diff] [blame] | 718 | typedef IndirectReferenceTable::iterator It; // TODO: C++0x auto |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 719 | for (It it = table->begin(), end = table->end(); it != end; ++it) { |
| 720 | const Object** entry = *it; |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 721 | if (!is_marked(*entry, arg)) { |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 722 | *entry = kClearedJniWeakGlobal; |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 727 | struct ArrayMarkedCheck { |
| 728 | ObjectStack* live_stack; |
| 729 | MarkSweep* mark_sweep; |
| 730 | }; |
| 731 | |
| 732 | // Either marked or not live. |
| 733 | bool MarkSweep::IsMarkedArrayCallback(const Object* object, void* arg) { |
| 734 | ArrayMarkedCheck* array_check = reinterpret_cast<ArrayMarkedCheck*>(arg); |
| 735 | if (array_check->mark_sweep->IsMarked(object)) { |
| 736 | return true; |
| 737 | } |
| 738 | ObjectStack* live_stack = array_check->live_stack; |
| 739 | return std::find(live_stack->Begin(), live_stack->End(), object) == live_stack->End(); |
| 740 | } |
| 741 | |
| 742 | void MarkSweep::SweepSystemWeaksArray(ObjectStack* allocations) { |
Mathieu Chartier | 46a2363 | 2012-08-07 18:44:40 -0700 | [diff] [blame] | 743 | Runtime* runtime = Runtime::Current(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 744 | // The callbacks check |
| 745 | // !is_marked where is_marked is the callback but we want |
| 746 | // !IsMarked && IsLive |
| 747 | // So compute !(!IsMarked && IsLive) which is equal to (IsMarked || !IsLive). |
| 748 | // Or for swapped (IsLive || !IsMarked). |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 749 | |
| 750 | ArrayMarkedCheck visitor; |
| 751 | visitor.live_stack = allocations; |
| 752 | visitor.mark_sweep = this; |
| 753 | runtime->GetInternTable()->SweepInternTableWeaks(IsMarkedArrayCallback, &visitor); |
| 754 | runtime->GetMonitorList()->SweepMonitorList(IsMarkedArrayCallback, &visitor); |
| 755 | SweepJniWeakGlobals(IsMarkedArrayCallback, &visitor); |
| 756 | } |
| 757 | |
| 758 | void MarkSweep::SweepSystemWeaks() { |
| 759 | Runtime* runtime = Runtime::Current(); |
| 760 | // The callbacks check |
| 761 | // !is_marked where is_marked is the callback but we want |
| 762 | // !IsMarked && IsLive |
| 763 | // So compute !(!IsMarked && IsLive) which is equal to (IsMarked || !IsLive). |
| 764 | // Or for swapped (IsLive || !IsMarked). |
| 765 | runtime->GetInternTable()->SweepInternTableWeaks(IsMarkedCallback, this); |
| 766 | runtime->GetMonitorList()->SweepMonitorList(IsMarkedCallback, this); |
| 767 | SweepJniWeakGlobals(IsMarkedCallback, this); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 770 | bool MarkSweep::VerifyIsLiveCallback(const Object* obj, void* arg) { |
| 771 | reinterpret_cast<MarkSweep*>(arg)->VerifyIsLive(obj); |
| 772 | // We don't actually want to sweep the object, so lets return "marked" |
| 773 | return true; |
| 774 | } |
| 775 | |
| 776 | void MarkSweep::VerifyIsLive(const Object* obj) { |
| 777 | Heap* heap = GetHeap(); |
| 778 | if (!heap->GetLiveBitmap()->Test(obj)) { |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 779 | LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); |
| 780 | if (!large_object_space->GetLiveObjects()->Test(obj)) { |
| 781 | if (std::find(heap->allocation_stack_->Begin(), heap->allocation_stack_->End(), obj) == |
| 782 | heap->allocation_stack_->End()) { |
| 783 | // Object not found! |
| 784 | heap->DumpSpaces(); |
| 785 | LOG(FATAL) << "Found dead object " << obj; |
| 786 | } |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | void MarkSweep::VerifySystemWeaks() { |
| 792 | Runtime* runtime = Runtime::Current(); |
| 793 | // Verify system weaks, uses a special IsMarked callback which always returns true. |
| 794 | runtime->GetInternTable()->SweepInternTableWeaks(VerifyIsLiveCallback, this); |
| 795 | runtime->GetMonitorList()->SweepMonitorList(VerifyIsLiveCallback, this); |
| 796 | |
| 797 | JavaVMExt* vm = runtime->GetJavaVM(); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 798 | MutexLock mu(Thread::Current(), vm->weak_globals_lock); |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 799 | IndirectReferenceTable* table = &vm->weak_globals; |
| 800 | typedef IndirectReferenceTable::iterator It; // TODO: C++0x auto |
| 801 | for (It it = table->begin(), end = table->end(); it != end; ++it) { |
| 802 | const Object** entry = *it; |
| 803 | VerifyIsLive(*entry); |
| 804 | } |
| 805 | } |
| 806 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 807 | struct SweepCallbackContext { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 808 | MarkSweep* mark_sweep; |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 809 | AllocSpace* space; |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 810 | Thread* self; |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 811 | }; |
| 812 | |
Mathieu Chartier | 0e4627e | 2012-10-23 16:13:36 -0700 | [diff] [blame] | 813 | class CheckpointMarkThreadRoots : public Closure { |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 814 | public: |
| 815 | CheckpointMarkThreadRoots(MarkSweep* mark_sweep) : mark_sweep_(mark_sweep) { |
| 816 | |
| 817 | } |
| 818 | |
| 819 | virtual void Run(Thread* thread) NO_THREAD_SAFETY_ANALYSIS { |
| 820 | // Note: self is not necessarily equal to thread since thread may be suspended. |
| 821 | Thread* self = Thread::Current(); |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 822 | CHECK(thread == self || thread->IsSuspended() || thread->GetState() == kWaitingPerformingGc) |
| 823 | << thread->GetState() << " thread " << thread << " self " << self; |
Mathieu Chartier | ac86a7c | 2012-11-12 15:03:16 -0800 | [diff] [blame] | 824 | thread->VisitRoots(MarkSweep::MarkRootParallelCallback, mark_sweep_); |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 825 | mark_sweep_->GetBarrier().Pass(self); |
| 826 | } |
| 827 | |
| 828 | private: |
| 829 | MarkSweep* mark_sweep_; |
| 830 | }; |
| 831 | |
| 832 | Barrier& MarkSweep::GetBarrier() { |
| 833 | return *gc_barrier_; |
| 834 | } |
| 835 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 836 | const TimingLogger& MarkSweep::GetTimings() const { |
| 837 | return timings_; |
| 838 | } |
| 839 | |
| 840 | const CumulativeLogger& MarkSweep::GetCumulativeTimings() const { |
| 841 | return cumulative_timings_; |
| 842 | } |
| 843 | |
| 844 | void MarkSweep::ResetCumulativeStatistics() { |
| 845 | cumulative_timings_.Reset(); |
| 846 | total_time_ = 0; |
| 847 | total_paused_time_ = 0; |
| 848 | total_freed_objects_ = 0; |
| 849 | total_freed_bytes_ = 0; |
| 850 | } |
| 851 | |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 852 | void MarkSweep::MarkRootsCheckpoint() { |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 853 | CheckpointMarkThreadRoots check_point(this); |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 854 | ThreadList* thread_list = Runtime::Current()->GetThreadList(); |
| 855 | // Increment the count of the barrier. If all of the checkpoints have already been finished then |
| 856 | // will hit 0 and continue. Otherwise we are still waiting for some checkpoints, so the counter |
| 857 | // will go positive and we will unblock when it hits zero. |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 858 | gc_barrier_->Increment(Thread::Current(), thread_list->RunCheckpoint(&check_point)); |
Mathieu Chartier | 858f1c5 | 2012-10-17 17:45:55 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 861 | void MarkSweep::SweepCallback(size_t num_ptrs, Object** ptrs, void* arg) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 862 | SweepCallbackContext* context = static_cast<SweepCallbackContext*>(arg); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 863 | MarkSweep* mark_sweep = context->mark_sweep; |
| 864 | Heap* heap = mark_sweep->GetHeap(); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 865 | AllocSpace* space = context->space; |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 866 | Thread* self = context->self; |
| 867 | Locks::heap_bitmap_lock_->AssertExclusiveHeld(self); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 868 | // Use a bulk free, that merges consecutive objects before freeing or free per object? |
| 869 | // Documentation suggests better free performance with merging, but this may be at the expensive |
| 870 | // of allocation. |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 871 | size_t freed_objects = num_ptrs; |
| 872 | // AllocSpace::FreeList clears the value in ptrs, so perform after clearing the live bit |
| 873 | size_t freed_bytes = space->FreeList(self, num_ptrs, ptrs); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 874 | heap->RecordFree(freed_objects, freed_bytes); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 875 | mark_sweep->freed_objects_ += freed_objects; |
| 876 | mark_sweep->freed_bytes_ += freed_bytes; |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 879 | void MarkSweep::ZygoteSweepCallback(size_t num_ptrs, Object** ptrs, void* arg) { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 880 | SweepCallbackContext* context = static_cast<SweepCallbackContext*>(arg); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 881 | Locks::heap_bitmap_lock_->AssertExclusiveHeld(context->self); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 882 | Heap* heap = context->mark_sweep->GetHeap(); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 883 | // We don't free any actual memory to avoid dirtying the shared zygote pages. |
| 884 | for (size_t i = 0; i < num_ptrs; ++i) { |
| 885 | Object* obj = static_cast<Object*>(ptrs[i]); |
| 886 | heap->GetLiveBitmap()->Clear(obj); |
| 887 | heap->GetCardTable()->MarkCard(obj); |
| 888 | } |
| 889 | } |
| 890 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 891 | void MarkSweep::SweepArray(TimingLogger& logger, ObjectStack* allocations, bool swap_bitmaps) { |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 892 | size_t freed_bytes = 0; |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 893 | DlMallocSpace* space = heap_->GetAllocSpace(); |
Elliott Hughes | 2da5036 | 2011-10-10 16:57:08 -0700 | [diff] [blame] | 894 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 895 | // If we don't swap bitmaps then newly allocated Weaks go into the live bitmap but not mark |
| 896 | // bitmap, resulting in occasional frees of Weaks which are still in use. |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 897 | SweepSystemWeaksArray(allocations); |
| 898 | logger.AddSplit("SweepSystemWeaks"); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 899 | |
| 900 | // Newly allocated objects MUST be in the alloc space and those are the only objects which we are |
| 901 | // going to free. |
| 902 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
| 903 | SpaceBitmap* mark_bitmap = space->GetMarkBitmap(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 904 | LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); |
| 905 | SpaceSetMap* large_live_objects = large_object_space->GetLiveObjects(); |
| 906 | SpaceSetMap* large_mark_objects = large_object_space->GetMarkObjects(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 907 | if (swap_bitmaps) { |
| 908 | std::swap(live_bitmap, mark_bitmap); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 909 | std::swap(large_live_objects, large_mark_objects); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 912 | size_t freed_large_objects = 0; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 913 | size_t count = allocations->Size(); |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 914 | Object** objects = const_cast<Object**>(allocations->Begin()); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 915 | Object** out = objects; |
| 916 | |
| 917 | // Empty the allocation stack. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 918 | Thread* self = Thread::Current(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 919 | for (size_t i = 0;i < count;++i) { |
| 920 | Object* obj = objects[i]; |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 921 | // There should only be objects in the AllocSpace/LargeObjectSpace in the allocation stack. |
| 922 | if (LIKELY(mark_bitmap->HasAddress(obj))) { |
| 923 | if (!mark_bitmap->Test(obj)) { |
| 924 | // Don't bother un-marking since we clear the mark bitmap anyways. |
| 925 | *(out++) = obj; |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 926 | } |
| 927 | } else if (!large_mark_objects->Test(obj)) { |
| 928 | ++freed_large_objects; |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 929 | freed_bytes += large_object_space->Free(self, obj); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | logger.AddSplit("Process allocation stack"); |
| 933 | |
| 934 | size_t freed_objects = out - objects; |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 935 | freed_bytes += space->FreeList(self, freed_objects, objects); |
Mathieu Chartier | 40e978b | 2012-09-07 11:38:36 -0700 | [diff] [blame] | 936 | VLOG(heap) << "Freed " << freed_objects << "/" << count |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 937 | << " objects with size " << PrettySize(freed_bytes); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 938 | heap_->RecordFree(freed_objects + freed_large_objects, freed_bytes); |
Mathieu Chartier | 40e978b | 2012-09-07 11:38:36 -0700 | [diff] [blame] | 939 | freed_objects_ += freed_objects; |
| 940 | freed_bytes_ += freed_bytes; |
| 941 | logger.AddSplit("FreeList"); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 942 | allocations->Reset(); |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 943 | logger.AddSplit("ResetStack"); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 946 | void MarkSweep::Sweep(TimingLogger& timings, bool swap_bitmaps) { |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 947 | DCHECK(mark_stack_->IsEmpty()); |
| 948 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 949 | // If we don't swap bitmaps then newly allocated Weaks go into the live bitmap but not mark |
| 950 | // bitmap, resulting in occasional frees of Weaks which are still in use. |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 951 | SweepSystemWeaks(); |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 952 | timings.AddSplit("SweepSystemWeaks"); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 953 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 954 | const bool partial = GetGcType() == kGcTypePartial; |
Mathieu Chartier | 46a2363 | 2012-08-07 18:44:40 -0700 | [diff] [blame] | 955 | const Spaces& spaces = heap_->GetSpaces(); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 956 | SweepCallbackContext scc; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 957 | scc.mark_sweep = this; |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 958 | scc.self = Thread::Current(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 959 | // TODO: C++0x auto |
| 960 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 961 | ContinuousSpace* space = *it; |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 962 | if ( |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 963 | space->GetGcRetentionPolicy() == kGcRetentionPolicyAlwaysCollect || |
| 964 | (!partial && space->GetGcRetentionPolicy() == kGcRetentionPolicyFullCollect) |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 965 | ) { |
| 966 | uintptr_t begin = reinterpret_cast<uintptr_t>(space->Begin()); |
| 967 | uintptr_t end = reinterpret_cast<uintptr_t>(space->End()); |
| 968 | scc.space = space->AsAllocSpace(); |
| 969 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
| 970 | SpaceBitmap* mark_bitmap = space->GetMarkBitmap(); |
Mathieu Chartier | fd678be | 2012-08-30 14:50:54 -0700 | [diff] [blame] | 971 | if (swap_bitmaps) { |
| 972 | std::swap(live_bitmap, mark_bitmap); |
| 973 | } |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 974 | if (space->GetGcRetentionPolicy() == kGcRetentionPolicyAlwaysCollect) { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 975 | // Bitmaps are pre-swapped for optimization which enables sweeping with the heap unlocked. |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 976 | SpaceBitmap::SweepWalk(*live_bitmap, *mark_bitmap, begin, end, |
| 977 | &SweepCallback, reinterpret_cast<void*>(&scc)); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 978 | } else { |
| 979 | // Zygote sweep takes care of dirtying cards and clearing live bits, does not free actual memory. |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 980 | SpaceBitmap::SweepWalk(*live_bitmap, *mark_bitmap, begin, end, |
| 981 | &ZygoteSweepCallback, reinterpret_cast<void*>(&scc)); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 982 | } |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 983 | } |
| 984 | } |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 985 | timings.AddSplit("Sweep"); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 986 | |
| 987 | SweepLargeObjects(swap_bitmaps); |
| 988 | timings.AddSplit("SweepLargeObjects"); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 991 | void MarkSweep::SweepLargeObjects(bool swap_bitmaps) { |
| 992 | // Sweep large objects |
| 993 | LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 994 | SpaceSetMap* large_live_objects = large_object_space->GetLiveObjects(); |
| 995 | SpaceSetMap* large_mark_objects = large_object_space->GetMarkObjects(); |
| 996 | if (swap_bitmaps) { |
| 997 | std::swap(large_live_objects, large_mark_objects); |
| 998 | } |
| 999 | SpaceSetMap::Objects& live_objects = large_live_objects->GetObjects(); |
| 1000 | // O(n*log(n)) but hopefully there are not too many large objects. |
| 1001 | size_t freed_objects = 0; |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 1002 | size_t freed_bytes = 0; |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 1003 | // TODO: C++0x |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 1004 | Thread* self = Thread::Current(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 1005 | for (SpaceSetMap::Objects::iterator it = live_objects.begin(); it != live_objects.end(); ++it) { |
| 1006 | if (!large_mark_objects->Test(*it)) { |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 1007 | freed_bytes += large_object_space->Free(self, const_cast<Object*>(*it)); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 1008 | ++freed_objects; |
| 1009 | } |
| 1010 | } |
| 1011 | freed_objects_ += freed_objects; |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 1012 | freed_bytes_ += freed_bytes; |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 1013 | // Large objects don't count towards bytes_allocated. |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 1014 | GetHeap()->RecordFree(freed_objects, freed_bytes); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 1017 | void MarkSweep::CheckReference(const Object* obj, const Object* ref, MemberOffset offset, bool is_static) { |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1018 | const Spaces& spaces = heap_->GetSpaces(); |
| 1019 | // TODO: C++0x auto |
| 1020 | for (Spaces::const_iterator cur = spaces.begin(); cur != spaces.end(); ++cur) { |
| 1021 | if ((*cur)->IsAllocSpace() && (*cur)->Contains(ref)) { |
| 1022 | DCHECK(IsMarked(obj)); |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 1023 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1024 | bool is_marked = IsMarked(ref); |
| 1025 | if (!is_marked) { |
| 1026 | LOG(INFO) << **cur; |
| 1027 | LOG(WARNING) << (is_static ? "Static ref'" : "Instance ref'") << PrettyTypeOf(ref) |
| 1028 | << "' (" << reinterpret_cast<const void*>(ref) << ") in '" << PrettyTypeOf(obj) |
| 1029 | << "' (" << reinterpret_cast<const void*>(obj) << ") at offset " |
| 1030 | << reinterpret_cast<void*>(offset.Int32Value()) << " wasn't marked"; |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 1031 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1032 | const Class* klass = is_static ? obj->AsClass() : obj->GetClass(); |
| 1033 | DCHECK(klass != NULL); |
| 1034 | const ObjectArray<Field>* fields = is_static ? klass->GetSFields() : klass->GetIFields(); |
| 1035 | DCHECK(fields != NULL); |
| 1036 | bool found = false; |
| 1037 | for (int32_t i = 0; i < fields->GetLength(); ++i) { |
| 1038 | const Field* cur = fields->Get(i); |
| 1039 | if (cur->GetOffset().Int32Value() == offset.Int32Value()) { |
| 1040 | LOG(WARNING) << "Field referencing the alloc space was " << PrettyField(cur); |
| 1041 | found = true; |
| 1042 | break; |
| 1043 | } |
| 1044 | } |
| 1045 | if (!found) { |
| 1046 | LOG(WARNING) << "Could not find field in object alloc space with offset " << offset.Int32Value(); |
| 1047 | } |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 1048 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1049 | bool obj_marked = heap_->GetCardTable()->IsDirty(obj); |
| 1050 | if (!obj_marked) { |
| 1051 | LOG(WARNING) << "Object '" << PrettyTypeOf(obj) << "' " |
| 1052 | << "(" << reinterpret_cast<const void*>(obj) << ") contains references to " |
| 1053 | << "the alloc space, but wasn't card marked"; |
Mathieu Chartier | 262e5ff | 2012-06-01 17:35:38 -0700 | [diff] [blame] | 1054 | } |
| 1055 | } |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 1056 | } |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1057 | break; |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1061 | // Process the "referent" field in a java.lang.ref.Reference. If the |
| 1062 | // referent has not yet been marked, put it on the appropriate list in |
| 1063 | // the gcHeap for later processing. |
| 1064 | void MarkSweep::DelayReferenceReferent(Object* obj) { |
| 1065 | DCHECK(obj != NULL); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 1066 | Class* klass = obj->GetClass(); |
| 1067 | DCHECK(klass != NULL); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1068 | DCHECK(klass->IsReferenceClass()); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1069 | Object* pending = obj->GetFieldObject<Object*>(heap_->GetReferencePendingNextOffset(), false); |
| 1070 | Object* referent = heap_->GetReferenceReferent(obj); |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 1071 | if (kCountJavaLangRefs) { |
| 1072 | ++reference_count_; |
| 1073 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1074 | if (pending == NULL && referent != NULL && !IsMarked(referent)) { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 1075 | Object** list = NULL; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1076 | if (klass->IsSoftReferenceClass()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1077 | list = &soft_reference_list_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1078 | } else if (klass->IsWeakReferenceClass()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1079 | list = &weak_reference_list_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1080 | } else if (klass->IsFinalizerReferenceClass()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1081 | list = &finalizer_reference_list_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1082 | } else if (klass->IsPhantomReferenceClass()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1083 | list = &phantom_reference_list_; |
| 1084 | } |
Brian Carlstrom | 0796af0 | 2011-10-12 14:31:45 -0700 | [diff] [blame] | 1085 | DCHECK(list != NULL) << PrettyClass(klass) << " " << std::hex << klass->GetAccessFlags(); |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1086 | // TODO: One lock per list? |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1087 | heap_->EnqueuePendingReference(obj, list); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1091 | void MarkSweep::ScanRoot(const Object* obj) { |
| 1092 | ScanObject(obj); |
| 1093 | } |
| 1094 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1095 | class MarkObjectVisitor { |
| 1096 | public: |
| 1097 | MarkObjectVisitor(MarkSweep* const mark_sweep) : mark_sweep_(mark_sweep) { |
| 1098 | } |
| 1099 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 1100 | // TODO: Fixme when anotatalysis works with visitors. |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1101 | void operator ()(const Object* /* obj */, const Object* ref, const MemberOffset& /* offset */, |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 1102 | bool /* is_static */) const |
| 1103 | NO_THREAD_SAFETY_ANALYSIS { |
| 1104 | if (kDebugLocking) { |
| 1105 | Locks::mutator_lock_->AssertSharedHeld(Thread::Current()); |
| 1106 | Locks::heap_bitmap_lock_->AssertExclusiveHeld(Thread::Current()); |
| 1107 | } |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1108 | mark_sweep_->MarkObject(ref); |
| 1109 | } |
| 1110 | |
| 1111 | private: |
| 1112 | MarkSweep* const mark_sweep_; |
| 1113 | }; |
| 1114 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1115 | // Scans an object reference. Determines the type of the reference |
| 1116 | // and dispatches to a specialized scanning routine. |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 1117 | void MarkSweep::ScanObject(const Object* obj) { |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1118 | MarkObjectVisitor visitor(this); |
| 1119 | ScanObjectVisit(obj, visitor); |
| 1120 | } |
| 1121 | |
| 1122 | class MarkStackChunk : public Task { |
| 1123 | public: |
| 1124 | MarkStackChunk(ThreadPool* thread_pool, MarkSweep* mark_sweep, Object** begin, Object** end) |
| 1125 | : mark_sweep_(mark_sweep), |
| 1126 | thread_pool_(thread_pool), |
| 1127 | index_(0), |
| 1128 | length_(0), |
| 1129 | output_(NULL) { |
| 1130 | length_ = end - begin; |
| 1131 | if (begin != end) { |
| 1132 | // Cost not significant since we only do this for the initial set of mark stack chunks. |
| 1133 | memcpy(data_, begin, length_ * sizeof(*begin)); |
| 1134 | } |
| 1135 | if (kCountTasks) { |
| 1136 | ++mark_sweep_->work_chunks_created_; |
| 1137 | } |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1138 | } |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1139 | |
| 1140 | ~MarkStackChunk() { |
| 1141 | DCHECK(output_ == NULL || output_->length_ == 0); |
| 1142 | DCHECK_GE(index_, length_); |
| 1143 | delete output_; |
| 1144 | if (kCountTasks) { |
| 1145 | ++mark_sweep_->work_chunks_deleted_; |
| 1146 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1147 | } |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1148 | |
| 1149 | MarkSweep* const mark_sweep_; |
| 1150 | ThreadPool* const thread_pool_; |
| 1151 | static const size_t max_size = 1 * KB; |
| 1152 | // Index of which object we are scanning. Only needs to be atomic if we are doing work stealing. |
| 1153 | size_t index_; |
| 1154 | // Input / output mark stack. We add newly marked references to data_ until length reaches |
| 1155 | // max_size. This is an optimization so that less tasks are created. |
| 1156 | // TODO: Investigate using a bounded buffer FIFO. |
| 1157 | Object* data_[max_size]; |
| 1158 | // How many elements in data_ we need to scan. |
| 1159 | size_t length_; |
| 1160 | // Output block, newly marked references get added to the ouput block so that another thread can |
| 1161 | // scan them. |
| 1162 | MarkStackChunk* output_; |
| 1163 | |
| 1164 | class MarkObjectParallelVisitor { |
| 1165 | public: |
| 1166 | MarkObjectParallelVisitor(MarkStackChunk* chunk_task) : chunk_task_(chunk_task) { |
| 1167 | |
| 1168 | } |
| 1169 | |
| 1170 | void operator ()(const Object* /* obj */, const Object* ref, |
| 1171 | const MemberOffset& /* offset */, bool /* is_static */) const { |
| 1172 | if (ref != NULL && chunk_task_->mark_sweep_->MarkObjectParallel(ref)) { |
| 1173 | chunk_task_->MarkStackPush(ref); |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | private: |
| 1178 | MarkStackChunk* const chunk_task_; |
| 1179 | }; |
| 1180 | |
| 1181 | // Push an object into the block. |
| 1182 | // Don't need to use atomic ++ since we only one thread is writing to an output block at any |
| 1183 | // given time. |
| 1184 | void Push(Object* obj) { |
| 1185 | data_[length_++] = obj; |
| 1186 | } |
| 1187 | |
| 1188 | void MarkStackPush(const Object* obj) { |
| 1189 | if (static_cast<size_t>(length_) < max_size) { |
| 1190 | Push(const_cast<Object*>(obj)); |
| 1191 | } else { |
| 1192 | // Internal buffer is full, push to a new buffer instead. |
| 1193 | if (UNLIKELY(output_ == NULL)) { |
| 1194 | AllocateOutputChunk(); |
| 1195 | } else if (UNLIKELY(static_cast<size_t>(output_->length_) == max_size)) { |
| 1196 | // Output block is full, queue it up for processing and obtain a new block. |
| 1197 | EnqueueOutput(); |
| 1198 | AllocateOutputChunk(); |
| 1199 | } |
| 1200 | output_->Push(const_cast<Object*>(obj)); |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | void ScanObject(Object* obj) { |
| 1205 | mark_sweep_->ScanObjectVisit(obj, MarkObjectParallelVisitor(this)); |
| 1206 | } |
| 1207 | |
| 1208 | void EnqueueOutput() { |
| 1209 | if (output_ != NULL) { |
| 1210 | uint64_t start = 0; |
| 1211 | if (kMeasureOverhead) { |
| 1212 | start = NanoTime(); |
| 1213 | } |
| 1214 | thread_pool_->AddTask(Thread::Current(), output_); |
| 1215 | output_ = NULL; |
| 1216 | if (kMeasureOverhead) { |
| 1217 | mark_sweep_->overhead_time_ += NanoTime() - start; |
| 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | void AllocateOutputChunk() { |
| 1223 | uint64_t start = 0; |
| 1224 | if (kMeasureOverhead) { |
| 1225 | start = NanoTime(); |
| 1226 | } |
| 1227 | output_ = new MarkStackChunk(thread_pool_, mark_sweep_, NULL, NULL); |
| 1228 | if (kMeasureOverhead) { |
| 1229 | mark_sweep_->overhead_time_ += NanoTime() - start; |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | void Finalize() { |
| 1234 | EnqueueOutput(); |
| 1235 | delete this; |
| 1236 | } |
| 1237 | |
| 1238 | // Scans all of the objects |
| 1239 | virtual void Run(Thread* self) { |
| 1240 | int index; |
| 1241 | while ((index = index_++) < length_) { |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1242 | if (kUseMarkStackPrefetch) { |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 1243 | static const size_t prefetch_look_ahead = 1; |
| 1244 | __builtin_prefetch(data_[std::min(index + prefetch_look_ahead, length_ - 1)]); |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1245 | } |
| 1246 | Object* obj = data_[index]; |
| 1247 | DCHECK(obj != NULL); |
| 1248 | ScanObject(obj); |
| 1249 | } |
| 1250 | } |
| 1251 | }; |
| 1252 | |
| 1253 | void MarkSweep::ProcessMarkStackParallel() { |
| 1254 | CHECK(kDisableFinger) << "parallel mark stack processing cannot work when finger is enabled"; |
| 1255 | Thread* self = Thread::Current(); |
| 1256 | ThreadPool* thread_pool = GetHeap()->GetThreadPool(); |
| 1257 | // Split the current mark stack up into work tasks. |
| 1258 | const size_t num_threads = thread_pool->GetThreadCount(); |
| 1259 | const size_t stack_size = mark_stack_->Size(); |
| 1260 | const size_t chunk_size = |
| 1261 | std::min((stack_size + num_threads - 1) / num_threads, |
| 1262 | static_cast<size_t>(MarkStackChunk::max_size)); |
| 1263 | size_t index = 0; |
| 1264 | for (size_t i = 0; i < num_threads || index < stack_size; ++i) { |
| 1265 | Object** begin = &mark_stack_->Begin()[std::min(stack_size, index)]; |
| 1266 | Object** end = &mark_stack_->Begin()[std::min(stack_size, index + chunk_size)]; |
| 1267 | index += chunk_size; |
| 1268 | thread_pool->AddTask(self, new MarkStackChunk(thread_pool, this, begin, end)); |
| 1269 | } |
| 1270 | thread_pool->StartWorkers(self); |
| 1271 | mark_stack_->Reset(); |
| 1272 | thread_pool->Wait(self, true); |
| 1273 | //LOG(INFO) << "Idle wait time " << PrettyDuration(thread_pool->GetWaitTime()); |
| 1274 | CHECK_EQ(work_chunks_created_, work_chunks_deleted_) << " some of the work chunks were leaked"; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 1277 | // Scan anything that's on the mark stack. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1278 | void MarkSweep::ProcessMarkStack() { |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1279 | ThreadPool* thread_pool = GetHeap()->GetThreadPool(); |
| 1280 | if (kParallelMarkStack && thread_pool != NULL && thread_pool->GetThreadCount() > 0) { |
| 1281 | ProcessMarkStackParallel(); |
| 1282 | return; |
| 1283 | } |
| 1284 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 1285 | if (kUseMarkStackPrefetch) { |
| 1286 | const size_t fifo_size = 4; |
| 1287 | const size_t fifo_mask = fifo_size - 1; |
| 1288 | const Object* fifo[fifo_size]; |
| 1289 | for (size_t i = 0;i < fifo_size;++i) { |
| 1290 | fifo[i] = NULL; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1291 | } |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 1292 | size_t fifo_pos = 0; |
| 1293 | size_t fifo_count = 0; |
| 1294 | for (;;) { |
| 1295 | const Object* obj = fifo[fifo_pos & fifo_mask]; |
| 1296 | if (obj != NULL) { |
| 1297 | ScanObject(obj); |
| 1298 | fifo[fifo_pos & fifo_mask] = NULL; |
| 1299 | --fifo_count; |
| 1300 | } |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1301 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 1302 | if (!mark_stack_->IsEmpty()) { |
| 1303 | const Object* obj = mark_stack_->PopBack(); |
| 1304 | DCHECK(obj != NULL); |
| 1305 | fifo[fifo_pos & fifo_mask] = obj; |
| 1306 | __builtin_prefetch(obj); |
| 1307 | fifo_count++; |
| 1308 | } |
| 1309 | fifo_pos++; |
| 1310 | |
| 1311 | if (!fifo_count) { |
| 1312 | CHECK(mark_stack_->IsEmpty()) << mark_stack_->Size(); |
| 1313 | break; |
| 1314 | } |
| 1315 | } |
| 1316 | } else { |
| 1317 | while (!mark_stack_->IsEmpty()) { |
| 1318 | const Object* obj = mark_stack_->PopBack(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1319 | DCHECK(obj != NULL); |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 1320 | ScanObject(obj); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1321 | } |
| 1322 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1325 | // Walks the reference list marking any references subject to the |
| 1326 | // reference clearing policy. References with a black referent are |
| 1327 | // removed from the list. References with white referents biased |
| 1328 | // toward saving are blackened and also removed from the list. |
| 1329 | void MarkSweep::PreserveSomeSoftReferences(Object** list) { |
| 1330 | DCHECK(list != NULL); |
| 1331 | Object* clear = NULL; |
| 1332 | size_t counter = 0; |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 1333 | |
| 1334 | DCHECK(mark_stack_->IsEmpty()); |
| 1335 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1336 | while (*list != NULL) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1337 | Object* ref = heap_->DequeuePendingReference(list); |
| 1338 | Object* referent = heap_->GetReferenceReferent(ref); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1339 | if (referent == NULL) { |
| 1340 | // Referent was cleared by the user during marking. |
| 1341 | continue; |
| 1342 | } |
| 1343 | bool is_marked = IsMarked(referent); |
| 1344 | if (!is_marked && ((++counter) & 1)) { |
| 1345 | // Referent is white and biased toward saving, mark it. |
| 1346 | MarkObject(referent); |
| 1347 | is_marked = true; |
| 1348 | } |
| 1349 | if (!is_marked) { |
| 1350 | // Referent is white, queue it for clearing. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1351 | heap_->EnqueuePendingReference(ref, &clear); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | *list = clear; |
| 1355 | // Restart the mark with the newly black references added to the |
| 1356 | // root set. |
| 1357 | ProcessMarkStack(); |
| 1358 | } |
| 1359 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 1360 | inline bool MarkSweep::IsMarked(const Object* object) const |
| 1361 | SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) { |
| 1362 | if (object >= immune_begin_ && object < immune_end_) { |
| 1363 | return true; |
| 1364 | } |
| 1365 | DCHECK(current_mark_bitmap_ != NULL); |
| 1366 | if (current_mark_bitmap_->HasAddress(object)) { |
| 1367 | return current_mark_bitmap_->Test(object); |
| 1368 | } |
| 1369 | return heap_->GetMarkBitmap()->Test(object); |
| 1370 | } |
| 1371 | |
| 1372 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1373 | // Unlink the reference list clearing references objects with white |
| 1374 | // referents. Cleared references registered to a reference queue are |
| 1375 | // scheduled for appending by the heap worker thread. |
| 1376 | void MarkSweep::ClearWhiteReferences(Object** list) { |
| 1377 | DCHECK(list != NULL); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1378 | while (*list != NULL) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1379 | Object* ref = heap_->DequeuePendingReference(list); |
| 1380 | Object* referent = heap_->GetReferenceReferent(ref); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1381 | if (referent != NULL && !IsMarked(referent)) { |
| 1382 | // Referent is white, clear it. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1383 | heap_->ClearReferenceReferent(ref); |
| 1384 | if (heap_->IsEnqueuable(ref)) { |
| 1385 | heap_->EnqueueReference(ref, &cleared_reference_list_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | DCHECK(*list == NULL); |
| 1390 | } |
| 1391 | |
| 1392 | // Enqueues finalizer references with white referents. White |
| 1393 | // referents are blackened, moved to the zombie field, and the |
| 1394 | // referent field is cleared. |
| 1395 | void MarkSweep::EnqueueFinalizerReferences(Object** list) { |
| 1396 | DCHECK(list != NULL); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1397 | MemberOffset zombie_offset = heap_->GetFinalizerReferenceZombieOffset(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1398 | bool has_enqueued = false; |
| 1399 | while (*list != NULL) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1400 | Object* ref = heap_->DequeuePendingReference(list); |
| 1401 | Object* referent = heap_->GetReferenceReferent(ref); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1402 | if (referent != NULL && !IsMarked(referent)) { |
| 1403 | MarkObject(referent); |
| 1404 | // If the referent is non-null the reference must queuable. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1405 | DCHECK(heap_->IsEnqueuable(ref)); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1406 | ref->SetFieldObject(zombie_offset, referent, false); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1407 | heap_->ClearReferenceReferent(ref); |
| 1408 | heap_->EnqueueReference(ref, &cleared_reference_list_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1409 | has_enqueued = true; |
| 1410 | } |
| 1411 | } |
| 1412 | if (has_enqueued) { |
| 1413 | ProcessMarkStack(); |
| 1414 | } |
| 1415 | DCHECK(*list == NULL); |
| 1416 | } |
| 1417 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 1418 | // Process reference class instances and schedule finalizations. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1419 | void MarkSweep::ProcessReferences(Object** soft_references, bool clear_soft, |
| 1420 | Object** weak_references, |
| 1421 | Object** finalizer_references, |
| 1422 | Object** phantom_references) { |
| 1423 | DCHECK(soft_references != NULL); |
| 1424 | DCHECK(weak_references != NULL); |
| 1425 | DCHECK(finalizer_references != NULL); |
| 1426 | DCHECK(phantom_references != NULL); |
| 1427 | |
| 1428 | // Unless we are in the zygote or required to clear soft references |
| 1429 | // with white references, preserve some white referents. |
Ian Rogers | 2945e24 | 2012-06-03 14:45:16 -0700 | [diff] [blame] | 1430 | if (!clear_soft && !Runtime::Current()->IsZygote()) { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1431 | PreserveSomeSoftReferences(soft_references); |
| 1432 | } |
| 1433 | |
| 1434 | // Clear all remaining soft and weak references with white |
| 1435 | // referents. |
| 1436 | ClearWhiteReferences(soft_references); |
| 1437 | ClearWhiteReferences(weak_references); |
| 1438 | |
| 1439 | // Preserve all white objects with finalize methods and schedule |
| 1440 | // them for finalization. |
| 1441 | EnqueueFinalizerReferences(finalizer_references); |
| 1442 | |
| 1443 | // Clear all f-reachable soft and weak references with white |
| 1444 | // referents. |
| 1445 | ClearWhiteReferences(soft_references); |
| 1446 | ClearWhiteReferences(weak_references); |
| 1447 | |
| 1448 | // Clear all phantom references with white referents. |
| 1449 | ClearWhiteReferences(phantom_references); |
| 1450 | |
| 1451 | // At this point all reference lists should be empty. |
| 1452 | DCHECK(*soft_references == NULL); |
| 1453 | DCHECK(*weak_references == NULL); |
| 1454 | DCHECK(*finalizer_references == NULL); |
| 1455 | DCHECK(*phantom_references == NULL); |
| 1456 | } |
| 1457 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 1458 | void MarkSweep::UnBindBitmaps() { |
| 1459 | const Spaces& spaces = heap_->GetSpaces(); |
| 1460 | // TODO: C++0x auto |
| 1461 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
| 1462 | Space* space = *it; |
| 1463 | if (space->IsAllocSpace()) { |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 1464 | DlMallocSpace* alloc_space = space->AsAllocSpace(); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 1465 | if (alloc_space->temp_bitmap_.get() != NULL) { |
| 1466 | // At this point, the temp_bitmap holds our old mark bitmap. |
| 1467 | SpaceBitmap* new_bitmap = alloc_space->temp_bitmap_.release(); |
| 1468 | GetHeap()->GetMarkBitmap()->ReplaceBitmap(alloc_space->mark_bitmap_.get(), new_bitmap); |
| 1469 | CHECK_EQ(alloc_space->mark_bitmap_.release(), alloc_space->live_bitmap_.get()); |
| 1470 | alloc_space->mark_bitmap_.reset(new_bitmap); |
| 1471 | DCHECK(alloc_space->temp_bitmap_.get() == NULL); |
| 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | } |
| 1476 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 1477 | void MarkSweep::FinishPhase() { |
| 1478 | // Can't enqueue referneces if we hold the mutator lock. |
| 1479 | Object* cleared_references = GetClearedReferences(); |
| 1480 | heap_->EnqueueClearedReferences(&cleared_references); |
| 1481 | |
| 1482 | heap_->PostGcVerification(this); |
| 1483 | |
Mathieu Chartier | 65db880 | 2012-11-20 12:36:46 -0800 | [diff] [blame] | 1484 | heap_->GrowForUtilization(GetDuration()); |
| 1485 | timings_.AddSplit("GrowForUtilization"); |
| 1486 | |
| 1487 | heap_->RequestHeapTrim(); |
| 1488 | timings_.AddSplit("RequestHeapTrim"); |
| 1489 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 1490 | // Update the cumulative statistics |
| 1491 | total_time_ += GetDuration(); |
| 1492 | total_paused_time_ += std::accumulate(GetPauseTimes().begin(), GetPauseTimes().end(), 0, |
| 1493 | std::plus<uint64_t>()); |
| 1494 | total_freed_objects_ += GetFreedObjects(); |
| 1495 | total_freed_bytes_ += GetFreedBytes(); |
| 1496 | |
| 1497 | // Ensure that the mark stack is empty. |
| 1498 | CHECK(mark_stack_->IsEmpty()); |
| 1499 | |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 1500 | if (kCountScannedTypes) { |
| 1501 | VLOG(gc) << "MarkSweep scanned classes=" << class_count_ << " arrays=" << array_count_ |
| 1502 | << " other=" << other_count_; |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | if (kCountTasks) { |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 1506 | VLOG(gc) << "Total number of work chunks allocated: " << work_chunks_created_; |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | if (kMeasureOverhead) { |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 1510 | VLOG(gc) << "Overhead time " << PrettyDuration(overhead_time_); |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | if (kProfileLargeObjects) { |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 1514 | VLOG(gc) << "Large objects tested " << large_object_test_ << " marked " << large_object_mark_; |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | if (kCountClassesMarked) { |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 1518 | VLOG(gc) << "Classes marked " << classes_marked_; |
| 1519 | } |
| 1520 | |
| 1521 | if (kCountJavaLangRefs) { |
| 1522 | VLOG(gc) << "References scanned " << reference_count_; |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 1525 | // Update the cumulative loggers. |
| 1526 | cumulative_timings_.Start(); |
| 1527 | cumulative_timings_.AddLogger(timings_); |
| 1528 | cumulative_timings_.End(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1529 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 1530 | // Clear all of the spaces' mark bitmaps. |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1531 | const Spaces& spaces = heap_->GetSpaces(); |
| 1532 | // TODO: C++0x auto |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1533 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 1534 | ContinuousSpace* space = *it; |
| 1535 | if (space->GetGcRetentionPolicy() != kGcRetentionPolicyNeverCollect) { |
| 1536 | space->GetMarkBitmap()->Clear(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1537 | } |
| 1538 | } |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 1539 | mark_stack_->Reset(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 1540 | |
| 1541 | // Reset the marked large objects. |
| 1542 | LargeObjectSpace* large_objects = GetHeap()->GetLargeObjectsSpace(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 1543 | large_objects->GetMarkObjects()->Clear(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 1546 | MarkSweep::~MarkSweep() { |
| 1547 | |
| 1548 | } |
| 1549 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1550 | } // namespace art |