Colin Cross | d6b3a2a | 2016-03-02 17:53:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #ifndef LIBMEMUNREACHABLE_LEAK_FOLDING_H_ |
| 18 | #define LIBMEMUNREACHABLE_LEAK_FOLDING_H_ |
| 19 | |
| 20 | #include "HeapWalker.h" |
| 21 | |
| 22 | class LeakFolding { |
| 23 | public: |
| 24 | LeakFolding(Allocator<void> allocator, HeapWalker& heap_walker) |
Colin Cross | a83881e | 2017-06-22 10:50:05 -0700 | [diff] [blame^] | 25 | : allocator_(allocator), |
| 26 | heap_walker_(heap_walker), |
| 27 | leak_map_(allocator), |
| 28 | leak_graph_(allocator), |
| 29 | leak_scc_(allocator) {} |
Colin Cross | d6b3a2a | 2016-03-02 17:53:39 -0800 | [diff] [blame] | 30 | |
| 31 | bool FoldLeaks(); |
| 32 | |
| 33 | struct Leak { |
| 34 | const Range range; |
| 35 | size_t referenced_count; |
| 36 | size_t referenced_size; |
| 37 | }; |
| 38 | |
Colin Cross | a83881e | 2017-06-22 10:50:05 -0700 | [diff] [blame^] | 39 | bool Leaked(allocator::vector<Leak>& leaked, size_t* num_leaks_out, size_t* leak_bytes_out); |
Colin Cross | d6b3a2a | 2016-03-02 17:53:39 -0800 | [diff] [blame] | 40 | |
| 41 | private: |
| 42 | DISALLOW_COPY_AND_ASSIGN(LeakFolding); |
| 43 | Allocator<void> allocator_; |
| 44 | HeapWalker& heap_walker_; |
| 45 | |
| 46 | struct SCCInfo { |
| 47 | public: |
| 48 | Node<SCCInfo> node; |
| 49 | |
| 50 | size_t count; |
| 51 | size_t size; |
| 52 | |
| 53 | size_t cuumulative_count; |
| 54 | size_t cuumulative_size; |
| 55 | |
| 56 | bool dominator; |
| 57 | SCCInfo* accumulator; |
| 58 | |
Colin Cross | a83881e | 2017-06-22 10:50:05 -0700 | [diff] [blame^] | 59 | explicit SCCInfo(Allocator<SCCInfo> allocator) |
| 60 | : node(this, allocator), |
| 61 | count(0), |
| 62 | size(0), |
| 63 | cuumulative_count(0), |
| 64 | cuumulative_size(0), |
| 65 | dominator(false), |
| 66 | accumulator(nullptr) {} |
| 67 | |
Colin Cross | d6b3a2a | 2016-03-02 17:53:39 -0800 | [diff] [blame] | 68 | private: |
| 69 | SCCInfo(SCCInfo&&) = delete; |
| 70 | DISALLOW_COPY_AND_ASSIGN(SCCInfo); |
| 71 | }; |
| 72 | |
| 73 | struct LeakInfo { |
| 74 | public: |
| 75 | Node<LeakInfo> node; |
| 76 | |
| 77 | const Range range; |
| 78 | |
| 79 | SCCInfo* scc; |
| 80 | |
| 81 | LeakInfo(const Range& range, Allocator<LeakInfo> allocator) |
Colin Cross | a83881e | 2017-06-22 10:50:05 -0700 | [diff] [blame^] | 82 | : node(this, allocator), range(range), scc(nullptr) {} |
Colin Cross | d6b3a2a | 2016-03-02 17:53:39 -0800 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | DISALLOW_COPY_AND_ASSIGN(LeakInfo); |
| 86 | }; |
| 87 | |
| 88 | void ComputeDAG(); |
| 89 | void AccumulateLeaks(SCCInfo* dominator); |
| 90 | |
Colin Cross | e4cbe0e | 2016-03-04 16:34:42 -0800 | [diff] [blame] | 91 | allocator::map<Range, LeakInfo, compare_range> leak_map_; |
Colin Cross | d6b3a2a | 2016-03-02 17:53:39 -0800 | [diff] [blame] | 92 | Graph<LeakInfo> leak_graph_; |
| 93 | allocator::vector<Allocator<SCCInfo>::unique_ptr> leak_scc_; |
| 94 | }; |
| 95 | |
Colin Cross | a83881e | 2017-06-22 10:50:05 -0700 | [diff] [blame^] | 96 | #endif // LIBMEMUNREACHABLE_LEAK_FOLDING_H_ |