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 | #ifndef ART_SRC_GC_GARBAGE_COLLECTOR_H_ |
| 18 | #define ART_SRC_GC_GARBAGE_COLLECTOR_H_ |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 19 | |
| 20 | #include "locks.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | |
| 22 | #include <stdint.h> |
| 23 | #include <vector> |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | class Heap; |
| 28 | |
| 29 | class 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 Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 61 | // The initial phase. Done without mutators paused. |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 62 | 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 Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 73 | // Called after the GC is finished. Done without mutators paused. |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 74 | 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 Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 83 | #endif // ART_SRC_GC_GARBAGE_COLLECTOR_H_ |