Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 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 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 17 | #include "heap.h" |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 18 | #include "large_object_space.h" |
| 19 | #include "space.h" |
| 20 | #include "sticky_mark_sweep.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | #include "thread.h" |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 22 | |
| 23 | namespace art { |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 24 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 25 | StickyMarkSweep::StickyMarkSweep(Heap* heap, bool is_concurrent) |
| 26 | : PartialMarkSweep(heap, is_concurrent) { |
| 27 | cumulative_timings_.SetName(GetName()); |
| 28 | } |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 29 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | StickyMarkSweep::~StickyMarkSweep() { |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 31 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | } |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 33 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | void StickyMarkSweep::BindBitmaps() { |
| 35 | PartialMarkSweep::BindBitmaps(); |
| 36 | |
| 37 | Spaces& spaces = GetHeap()->GetSpaces(); |
| 38 | WriterMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_); |
| 39 | // For sticky GC, we want to bind the bitmaps of both the zygote space and the alloc space. |
| 40 | // This lets us start with the mark bitmap of the previous garbage collection as the current |
| 41 | // mark bitmap of the alloc space. After the sticky GC finishes, we then unbind the bitmaps, |
| 42 | // making it so that the live bitmap of the alloc space is contains the newly marked objects |
| 43 | // from the sticky GC. |
| 44 | for (Spaces::iterator it = spaces.begin(); it != spaces.end(); ++it) { |
| 45 | if ((*it)->GetGcRetentionPolicy() == kGcRetentionPolicyAlwaysCollect) { |
| 46 | BindLiveToMarkBitmap(*it); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 47 | } |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 50 | GetHeap()->GetLargeObjectsSpace()->CopyLiveToMarked(); |
| 51 | } |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 52 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 53 | void StickyMarkSweep::MarkReachableObjects() { |
| 54 | DisableFinger(); |
| 55 | RecursiveMarkDirtyObjects(CardTable::kCardDirty - 1); |
| 56 | } |
| 57 | |
| 58 | void StickyMarkSweep::Sweep(TimingLogger& timings, bool swap_bitmaps) { |
| 59 | ObjectStack* live_stack = GetHeap()->GetLiveStack(); |
| 60 | SweepArray(timings_, live_stack, false); |
| 61 | timings_.AddSplit("SweepArray"); |
| 62 | } |
| 63 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 64 | } // namespace art |