blob: 988d4e79e735d4ec54dc5ee5fd656b905ebecd26 [file] [log] [blame]
Mathieu Chartier2b82db42012-11-14 17:29:05 -08001/*
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 Rogers2dd0e2c2013-01-24 12:42:14 -080017#include "heap.h"
Mathieu Chartier2b82db42012-11-14 17:29:05 -080018#include "large_object_space.h"
19#include "space.h"
20#include "sticky_mark_sweep.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "thread.h"
Mathieu Chartier2b82db42012-11-14 17:29:05 -080022
23namespace art {
Mathieu Chartier2b82db42012-11-14 17:29:05 -080024
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025StickyMarkSweep::StickyMarkSweep(Heap* heap, bool is_concurrent)
26 : PartialMarkSweep(heap, is_concurrent) {
27 cumulative_timings_.SetName(GetName());
28}
Mathieu Chartier2b82db42012-11-14 17:29:05 -080029
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030StickyMarkSweep::~StickyMarkSweep() {
Mathieu Chartier2b82db42012-11-14 17:29:05 -080031
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032}
Mathieu Chartier2b82db42012-11-14 17:29:05 -080033
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034void 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 Chartier2b82db42012-11-14 17:29:05 -080047 }
Mathieu Chartier2b82db42012-11-14 17:29:05 -080048 }
49
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050 GetHeap()->GetLargeObjectsSpace()->CopyLiveToMarked();
51}
Mathieu Chartier2b82db42012-11-14 17:29:05 -080052
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053void StickyMarkSweep::MarkReachableObjects() {
54 DisableFinger();
55 RecursiveMarkDirtyObjects(CardTable::kCardDirty - 1);
56}
57
58void 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 Chartier2b82db42012-11-14 17:29:05 -080064} // namespace art