blob: a1014c2c7f8c5f0a29d94ba9f3b42901063c0190 [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#ifndef ART_SRC_GC_GARBAGE_COLLECTOR_H_
18#define ART_SRC_GC_GARBAGE_COLLECTOR_H_
Mathieu Chartier2b82db42012-11-14 17:29:05 -080019
20#include "locks.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021
22#include <stdint.h>
23#include <vector>
Mathieu Chartier2b82db42012-11-14 17:29:05 -080024
25namespace art {
26
27class Heap;
28
29class GarbageCollector {
30 public:
31 // Returns true iff the garbage collector is concurrent.
32 virtual bool IsConcurrent() const = 0;
33
34 GarbageCollector(Heap* heap);
35
36 virtual ~GarbageCollector();
37
38 // Run the garbage collector.
39 void Run();
40
41 Heap* GetHeap() {
42 return heap_;
43 }
44
45 // Returns how long the mutators were paused in nanoseconds.
46 const std::vector<uint64_t>& GetPauseTimes() const {
47 return pause_times_;
48 }
49
50 // Returns how long the GC took to complete in nanoseconds.
51 uint64_t GetDuration() const {
52 return duration_;
53 }
54
55
56 virtual std::string GetName() const = 0;
57
58 void RegisterPause(uint64_t nano_length);
59
60 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080061 // The initial phase. Done without mutators paused.
Mathieu Chartier2b82db42012-11-14 17:29:05 -080062 virtual void InitializePhase() = 0;
63
64 // Mark all reachable objects, done concurrently.
65 virtual void MarkingPhase() = 0;
66
67 // Only called for concurrent GCs. Gets called repeatedly until it succeeds.
68 virtual bool HandleDirtyObjectsPhase() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
69
70 // Called with mutators running.
71 virtual void ReclaimPhase() = 0;
72
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073 // Called after the GC is finished. Done without mutators paused.
Mathieu Chartier2b82db42012-11-14 17:29:05 -080074 virtual void FinishPhase() = 0;
75
76 Heap* heap_;
77 std::vector<uint64_t> pause_times_;
78 uint64_t duration_;
79};
80
81} // namespace art
82
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080083#endif // ART_SRC_GC_GARBAGE_COLLECTOR_H_