sticky_mark_sweep.cc revision 02e25119b15a6f619f17db99f5d05124a5807ff3
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.h"
20#include "sticky_mark_sweep.h"
21#include "thread.h"
22
23namespace art {
24namespace gc {
25namespace collector {
26
27StickyMarkSweep::StickyMarkSweep(Heap* heap, bool is_concurrent, const std::string& name_prefix)
28    : PartialMarkSweep(heap, is_concurrent,
29                       name_prefix + (name_prefix.empty() ? "" : " ") + "sticky") {
30  cumulative_timings_.SetName(GetName());
31}
32
33void StickyMarkSweep::BindBitmaps() {
34  PartialMarkSweep::BindBitmaps();
35
36  WriterMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_);
37  // For sticky GC, we want to bind the bitmaps of all spaces as the allocation stack lets us
38  // know what was allocated since the last GC. A side-effect of binding the allocation space mark
39  // and live bitmap is that marking the objects will place them in the live bitmap.
40  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
41    if (space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect) {
42      BindLiveToMarkBitmap(space);
43    }
44  }
45
46  GetHeap()->GetLargeObjectsSpace()->CopyLiveToMarked();
47}
48
49void StickyMarkSweep::MarkReachableObjects() {
50  RecursiveMarkDirtyObjects(accounting::CardTable::kCardDirty - 1);
51}
52
53void StickyMarkSweep::Sweep(bool swap_bitmaps) {
54  accounting::ObjectStack* live_stack = GetHeap()->GetLiveStack();
55  SweepArray(live_stack, false);
56}
57
58}  // namespace collector
59}  // namespace gc
60}  // namespace art
61