Mercurial > hg > graal-jvmci-8
comparison src/share/vm/services/memBaseline.hpp @ 20366:dd3939fe8424
8054546: NMT2 leaks memory
Summary: Fixed memory leak in NMT by baselining memory in c heap instead of an arena.
Reviewed-by: coleenp, minqi
author | zgu |
---|---|
date | Wed, 20 Aug 2014 08:41:15 -0400 |
parents | 833b0f92429a |
children | 417e3b8d04c5 |
comparison
equal
deleted
inserted
replaced
20365:3adc0e278f49 | 20366:dd3939fe8424 |
---|---|
59 by_size, // by memory size | 59 by_size, // by memory size |
60 by_site // by call site where the memory is allocated from | 60 by_site // by call site where the memory is allocated from |
61 }; | 61 }; |
62 | 62 |
63 private: | 63 private: |
64 // All baseline data is stored in this arena | |
65 Arena* _arena; | |
66 | |
67 // Summary information | 64 // Summary information |
68 MallocMemorySnapshot* _malloc_memory_snapshot; | 65 MallocMemorySnapshot _malloc_memory_snapshot; |
69 VirtualMemorySnapshot* _virtual_memory_snapshot; | 66 VirtualMemorySnapshot _virtual_memory_snapshot; |
70 | 67 |
71 size_t _class_count; | 68 size_t _class_count; |
72 | 69 |
73 // Allocation sites information | 70 // Allocation sites information |
74 // Malloc allocation sites | 71 // Malloc allocation sites |
75 LinkedListImpl<MallocSite, ResourceObj::ARENA> | 72 LinkedListImpl<MallocSite> _malloc_sites; |
76 _malloc_sites; | |
77 | 73 |
78 // All virtual memory allocations | 74 // All virtual memory allocations |
79 LinkedListImpl<ReservedMemoryRegion, ResourceObj::ARENA> | 75 LinkedListImpl<ReservedMemoryRegion> _virtual_memory_allocations; |
80 _virtual_memory_allocations; | |
81 | 76 |
82 // Virtual memory allocations by allocation sites, always in by_address | 77 // Virtual memory allocations by allocation sites, always in by_address |
83 // order | 78 // order |
84 LinkedListImpl<VirtualMemoryAllocationSite, ResourceObj::ARENA> | 79 LinkedListImpl<VirtualMemoryAllocationSite> _virtual_memory_sites; |
85 _virtual_memory_sites; | |
86 | 80 |
87 SortingOrder _malloc_sites_order; | 81 SortingOrder _malloc_sites_order; |
88 SortingOrder _virtual_memory_sites_order; | 82 SortingOrder _virtual_memory_sites_order; |
89 | 83 |
90 BaselineType _baseline_type; | 84 BaselineType _baseline_type; |
91 | 85 |
92 public: | 86 public: |
93 // create a memory baseline | 87 // create a memory baseline |
94 MemBaseline(): | 88 MemBaseline(): |
95 _baseline_type(Not_baselined), | 89 _baseline_type(Not_baselined), |
96 _class_count(0), | 90 _class_count(0) { |
97 _arena(NULL), | |
98 _malloc_memory_snapshot(NULL), | |
99 _virtual_memory_snapshot(NULL), | |
100 _malloc_sites(NULL) { | |
101 } | 91 } |
102 | 92 |
103 ~MemBaseline() { | 93 ~MemBaseline() { |
104 reset(); | 94 reset(); |
105 if (_arena != NULL) { | |
106 delete _arena; | |
107 } | |
108 } | 95 } |
109 | 96 |
110 bool baseline(bool summaryOnly = true); | 97 bool baseline(bool summaryOnly = true); |
111 | 98 |
112 BaselineType baseline_type() const { return _baseline_type; } | 99 BaselineType baseline_type() const { return _baseline_type; } |
113 | 100 |
114 MallocMemorySnapshot* malloc_memory_snapshot() const { | 101 MallocMemorySnapshot* malloc_memory_snapshot() { |
115 return _malloc_memory_snapshot; | 102 return &_malloc_memory_snapshot; |
116 } | 103 } |
117 | 104 |
118 VirtualMemorySnapshot* virtual_memory_snapshot() const { | 105 VirtualMemorySnapshot* virtual_memory_snapshot() { |
119 return _virtual_memory_snapshot; | 106 return &_virtual_memory_snapshot; |
120 } | 107 } |
121 | 108 |
122 MallocSiteIterator malloc_sites(SortingOrder order); | 109 MallocSiteIterator malloc_sites(SortingOrder order); |
123 VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order); | 110 VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order); |
124 | 111 |
131 | 118 |
132 // Total reserved memory = total malloc'd memory + total reserved virtual | 119 // Total reserved memory = total malloc'd memory + total reserved virtual |
133 // memory | 120 // memory |
134 size_t total_reserved_memory() const { | 121 size_t total_reserved_memory() const { |
135 assert(baseline_type() != Not_baselined, "Not yet baselined"); | 122 assert(baseline_type() != Not_baselined, "Not yet baselined"); |
136 assert(_virtual_memory_snapshot != NULL, "No virtual memory snapshot"); | 123 size_t amount = _malloc_memory_snapshot.total() + |
137 assert(_malloc_memory_snapshot != NULL, "No malloc memory snapshot"); | 124 _virtual_memory_snapshot.total_reserved(); |
138 size_t amount = _malloc_memory_snapshot->total() + | |
139 _virtual_memory_snapshot->total_reserved(); | |
140 return amount; | 125 return amount; |
141 } | 126 } |
142 | 127 |
143 // Total committed memory = total malloc'd memory + total committed | 128 // Total committed memory = total malloc'd memory + total committed |
144 // virtual memory | 129 // virtual memory |
145 size_t total_committed_memory() const { | 130 size_t total_committed_memory() const { |
146 assert(baseline_type() != Not_baselined, "Not yet baselined"); | 131 assert(baseline_type() != Not_baselined, "Not yet baselined"); |
147 assert(_virtual_memory_snapshot != NULL, | 132 size_t amount = _malloc_memory_snapshot.total() + |
148 "Not a snapshot"); | 133 _virtual_memory_snapshot.total_committed(); |
149 size_t amount = _malloc_memory_snapshot->total() + | |
150 _virtual_memory_snapshot->total_committed(); | |
151 return amount; | 134 return amount; |
152 } | 135 } |
153 | 136 |
154 size_t total_arena_memory() const { | 137 size_t total_arena_memory() const { |
155 assert(baseline_type() != Not_baselined, "Not yet baselined"); | 138 assert(baseline_type() != Not_baselined, "Not yet baselined"); |
156 assert(_malloc_memory_snapshot != NULL, "Not yet baselined"); | 139 return _malloc_memory_snapshot.total_arena(); |
157 return _malloc_memory_snapshot->total_arena(); | |
158 } | 140 } |
159 | 141 |
160 size_t malloc_tracking_overhead() const { | 142 size_t malloc_tracking_overhead() const { |
161 assert(baseline_type() != Not_baselined, "Not yet baselined"); | 143 assert(baseline_type() != Not_baselined, "Not yet baselined"); |
162 return _malloc_memory_snapshot->malloc_overhead()->size(); | 144 MemBaseline* bl = const_cast<MemBaseline*>(this); |
163 } | 145 return bl->_malloc_memory_snapshot.malloc_overhead()->size(); |
164 | 146 } |
165 const MallocMemory* malloc_memory(MEMFLAGS flag) const { | 147 |
166 assert(_malloc_memory_snapshot != NULL, "Not a snapshot"); | 148 MallocMemory* malloc_memory(MEMFLAGS flag) { |
167 return _malloc_memory_snapshot->by_type(flag); | 149 assert(baseline_type() != Not_baselined, "Not yet baselined"); |
168 } | 150 return _malloc_memory_snapshot.by_type(flag); |
169 | 151 } |
170 const VirtualMemory* virtual_memory(MEMFLAGS flag) const { | 152 |
171 assert(_virtual_memory_snapshot != NULL, "Not a snapshot"); | 153 VirtualMemory* virtual_memory(MEMFLAGS flag) { |
172 return _virtual_memory_snapshot->by_type(flag); | 154 assert(baseline_type() != Not_baselined, "Not yet baselined"); |
155 return _virtual_memory_snapshot.by_type(flag); | |
173 } | 156 } |
174 | 157 |
175 | 158 |
176 size_t class_count() const { | 159 size_t class_count() const { |
177 assert(baseline_type() != Not_baselined, "Not yet baselined"); | 160 assert(baseline_type() != Not_baselined, "Not yet baselined"); |
178 return _class_count; | 161 return _class_count; |
179 } | 162 } |
180 | 163 |
181 size_t thread_count() const { | 164 size_t thread_count() const { |
182 assert(baseline_type() != Not_baselined, "Not yet baselined"); | 165 assert(baseline_type() != Not_baselined, "Not yet baselined"); |
183 assert(_malloc_memory_snapshot != NULL, "Baselined?"); | 166 return _malloc_memory_snapshot.thread_count(); |
184 return _malloc_memory_snapshot->thread_count(); | |
185 } | 167 } |
186 | 168 |
187 // reset the baseline for reuse | 169 // reset the baseline for reuse |
188 void reset() { | 170 void reset() { |
189 _baseline_type = Not_baselined; | 171 _baseline_type = Not_baselined; |
190 _malloc_memory_snapshot = NULL; | 172 _malloc_memory_snapshot.reset(); |
191 _virtual_memory_snapshot = NULL; | 173 _virtual_memory_snapshot.reset(); |
192 _class_count = 0; | 174 _class_count = 0; |
193 | 175 |
194 _malloc_sites = NULL; | 176 _malloc_sites.clear(); |
195 _virtual_memory_sites = NULL; | 177 _virtual_memory_sites.clear(); |
196 _virtual_memory_allocations = NULL; | 178 _virtual_memory_allocations.clear(); |
197 | |
198 if (_arena != NULL) { | |
199 _arena->destruct_contents(); | |
200 } | |
201 } | 179 } |
202 | 180 |
203 private: | 181 private: |
204 // Baseline summary information | 182 // Baseline summary information |
205 bool baseline_summary(); | 183 bool baseline_summary(); |
207 // Baseline allocation sites (detail tracking only) | 185 // Baseline allocation sites (detail tracking only) |
208 bool baseline_allocation_sites(); | 186 bool baseline_allocation_sites(); |
209 | 187 |
210 // Aggregate virtual memory allocation by allocation sites | 188 // Aggregate virtual memory allocation by allocation sites |
211 bool aggregate_virtual_memory_allocation_sites(); | 189 bool aggregate_virtual_memory_allocation_sites(); |
212 | |
213 Arena* arena() { return _arena; } | |
214 | 190 |
215 // Sorting allocation sites in different orders | 191 // Sorting allocation sites in different orders |
216 // Sort allocation sites in size order | 192 // Sort allocation sites in size order |
217 void malloc_sites_to_size_order(); | 193 void malloc_sites_to_size_order(); |
218 // Sort allocation sites in call site address order | 194 // Sort allocation sites in call site address order |