1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "gc/heap.h" 18 #include "gc/space/large_object_space.h" 19 #include "gc/space/space-inl.h" 20 #include "sticky_mark_sweep.h" 21 #include "thread-inl.h" 22 23 namespace art { 24 namespace gc { 25 namespace collector { 26 27 StickyMarkSweep::StickyMarkSweep(Heap* heap, bool is_concurrent, const std::string& name_prefix) 28 : PartialMarkSweep(heap, is_concurrent, name_prefix.empty() ? "sticky " : name_prefix) { 29 cumulative_timings_.SetName(GetName()); 30 } 31 32 void StickyMarkSweep::BindBitmaps() { 33 PartialMarkSweep::BindBitmaps(); 34 WriterMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_); 35 // For sticky GC, we want to bind the bitmaps of all spaces as the allocation stack lets us 36 // know what was allocated since the last GC. A side-effect of binding the allocation space mark 37 // and live bitmap is that marking the objects will place them in the live bitmap. 38 for (const auto& space : GetHeap()->GetContinuousSpaces()) { 39 if (space->IsContinuousMemMapAllocSpace() && 40 space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect) { 41 DCHECK(space->IsContinuousMemMapAllocSpace()); 42 space->AsContinuousMemMapAllocSpace()->BindLiveToMarkBitmap(); 43 } 44 } 45 for (const auto& space : GetHeap()->GetDiscontinuousSpaces()) { 46 CHECK(space->IsLargeObjectSpace()); 47 space->AsLargeObjectSpace()->CopyLiveToMarked(); 48 } 49 } 50 51 void StickyMarkSweep::MarkReachableObjects() { 52 // All reachable objects must be referenced by a root or a dirty card, so we can clear the mark 53 // stack here since all objects in the mark stack will Get scanned by the card scanning anyways. 54 // TODO: Not put these objects in the mark stack in the first place. 55 mark_stack_->Reset(); 56 RecursiveMarkDirtyObjects(false, accounting::CardTable::kCardDirty - 1); 57 } 58 59 void StickyMarkSweep::Sweep(bool swap_bitmaps ATTRIBUTE_UNUSED) { 60 SweepArray(GetHeap()->GetLiveStack(), false); 61 } 62 63 } // namespace collector 64 } // namespace gc 65 } // namespace art 66