Mercurial > hg > graal-compiler
annotate src/share/vm/services/memBaseline.cpp @ 12839:a6414751d537
8025996: Track metaspace usage when metaspace is expanded
Reviewed-by: coleenp, ehelin
author | stefank |
---|---|
date | Mon, 07 Oct 2013 15:51:17 +0200 |
parents | 72fce0b2d341 |
children | 833b0f92429a |
rev | line source |
---|---|
6197 | 1 /* |
10148 | 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
6197 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 #include "precompiled.hpp" | |
25 #include "memory/allocation.hpp" | |
10148 | 26 #include "runtime/safepoint.hpp" |
27 #include "runtime/thread.inline.hpp" | |
6197 | 28 #include "services/memBaseline.hpp" |
29 #include "services/memTracker.hpp" | |
30 | |
10148 | 31 |
6197 | 32 MemType2Name MemBaseline::MemType2NameMap[NUMBER_OF_MEMORY_TYPE] = { |
33 {mtJavaHeap, "Java Heap"}, | |
34 {mtClass, "Class"}, | |
35 {mtThreadStack,"Thread Stack"}, | |
36 {mtThread, "Thread"}, | |
37 {mtCode, "Code"}, | |
38 {mtGC, "GC"}, | |
39 {mtCompiler, "Compiler"}, | |
40 {mtInternal, "Internal"}, | |
41 {mtOther, "Other"}, | |
42 {mtSymbol, "Symbol"}, | |
43 {mtNMT, "Memory Tracking"}, | |
10405 | 44 {mtTracing, "Tracing"}, |
6197 | 45 {mtChunk, "Pooled Free Chunks"}, |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
46 {mtClassShared,"Shared spaces for classes"}, |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
47 {mtTest, "Test"}, |
6197 | 48 {mtNone, "Unknown"} // It can happen when type tagging records are lagging |
49 // behind | |
50 }; | |
51 | |
52 MemBaseline::MemBaseline() { | |
53 _baselined = false; | |
54 | |
55 for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { | |
56 _malloc_data[index].set_type(MemType2NameMap[index]._flag); | |
57 _vm_data[index].set_type(MemType2NameMap[index]._flag); | |
58 _arena_data[index].set_type(MemType2NameMap[index]._flag); | |
59 } | |
60 | |
61 _malloc_cs = NULL; | |
62 _vm_cs = NULL; | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
63 _vm_map = NULL; |
6197 | 64 |
65 _number_of_classes = 0; | |
66 _number_of_threads = 0; | |
67 } | |
68 | |
69 | |
70 void MemBaseline::clear() { | |
71 if (_malloc_cs != NULL) { | |
72 delete _malloc_cs; | |
73 _malloc_cs = NULL; | |
74 } | |
75 | |
76 if (_vm_cs != NULL) { | |
77 delete _vm_cs; | |
78 _vm_cs = NULL; | |
79 } | |
80 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
81 if (_vm_map != NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
82 delete _vm_map; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
83 _vm_map = NULL; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
84 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
85 |
6197 | 86 reset(); |
87 } | |
88 | |
89 | |
90 void MemBaseline::reset() { | |
91 _baselined = false; | |
92 _total_vm_reserved = 0; | |
93 _total_vm_committed = 0; | |
94 _total_malloced = 0; | |
95 _number_of_classes = 0; | |
96 | |
97 if (_malloc_cs != NULL) _malloc_cs->clear(); | |
98 if (_vm_cs != NULL) _vm_cs->clear(); | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
99 if (_vm_map != NULL) _vm_map->clear(); |
6197 | 100 |
101 for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { | |
102 _malloc_data[index].clear(); | |
103 _vm_data[index].clear(); | |
104 _arena_data[index].clear(); | |
105 } | |
106 } | |
107 | |
108 MemBaseline::~MemBaseline() { | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
109 clear(); |
6197 | 110 } |
111 | |
112 // baseline malloc'd memory records, generate overall summary and summaries by | |
113 // memory types | |
114 bool MemBaseline::baseline_malloc_summary(const MemPointerArray* malloc_records) { | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
115 MemPointerArrayIteratorImpl malloc_itr((MemPointerArray*)malloc_records); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
116 MemPointerRecord* malloc_ptr = (MemPointerRecord*)malloc_itr.current(); |
6197 | 117 size_t used_arena_size = 0; |
118 int index; | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
119 while (malloc_ptr != NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
120 index = flag2index(FLAGS_TO_MEMORY_TYPE(malloc_ptr->flags())); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
121 size_t size = malloc_ptr->size(); |
6979
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
122 if (malloc_ptr->is_arena_memory_record()) { |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
123 // We do have anonymous arenas, they are either used as value objects, |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
124 // which are embedded inside other objects, or used as stack objects. |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
125 _arena_data[index].inc(size); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
126 used_arena_size += size; |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
127 } else { |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
128 _total_malloced += size; |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
129 _malloc_data[index].inc(size); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
130 if (malloc_ptr->is_arena_record()) { |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
131 // see if arena memory record present |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
132 MemPointerRecord* next_malloc_ptr = (MemPointerRecordEx*)malloc_itr.peek_next(); |
10975
ab313d4e9a8b
8011968: Kitchensink crashed with SIGSEGV in MemBaseline::baseline
zgu
parents:
10405
diff
changeset
|
133 if (next_malloc_ptr != NULL && next_malloc_ptr->is_arena_memory_record()) { |
6979
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
134 assert(next_malloc_ptr->is_memory_record_of_arena(malloc_ptr), |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
135 "Arena records do not match"); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
136 size = next_malloc_ptr->size(); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
137 _arena_data[index].inc(size); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
138 used_arena_size += size; |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
139 malloc_itr.next(); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
140 } |
6197 | 141 } |
142 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
143 malloc_ptr = (MemPointerRecordEx*)malloc_itr.next(); |
6197 | 144 } |
145 | |
146 // substract used arena size to get size of arena chunk in free list | |
147 index = flag2index(mtChunk); | |
148 _malloc_data[index].reduce(used_arena_size); | |
149 // we really don't know how many chunks in free list, so just set to | |
150 // 0 | |
151 _malloc_data[index].overwrite_counter(0); | |
152 | |
153 return true; | |
154 } | |
155 | |
10148 | 156 // check if there is a safepoint in progress, if so, block the thread |
157 // for the safepoint | |
158 void MemBaseline::check_safepoint(JavaThread* thr) { | |
159 if (SafepointSynchronize::is_synchronizing()) { | |
10160
ed5a590835a4
8013214: BigApps fails due to 'fatal error: Illegal threadstate encountered: 6'
zgu
parents:
10148
diff
changeset
|
160 // grab and drop the SR_lock to honor the safepoint protocol |
ed5a590835a4
8013214: BigApps fails due to 'fatal error: Illegal threadstate encountered: 6'
zgu
parents:
10148
diff
changeset
|
161 MutexLocker ml(thr->SR_lock()); |
10148 | 162 } |
163 } | |
164 | |
6197 | 165 // baseline mmap'd memory records, generate overall summary and summaries by |
166 // memory types | |
167 bool MemBaseline::baseline_vm_summary(const MemPointerArray* vm_records) { | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
168 MemPointerArrayIteratorImpl vm_itr((MemPointerArray*)vm_records); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
169 VMMemRegion* vm_ptr = (VMMemRegion*)vm_itr.current(); |
6197 | 170 int index; |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
171 while (vm_ptr != NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
172 if (vm_ptr->is_reserved_region()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
173 index = flag2index(FLAGS_TO_MEMORY_TYPE(vm_ptr->flags())); |
6197 | 174 // we use the number of thread stack to count threads |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
175 if (IS_MEMORY_TYPE(vm_ptr->flags(), mtThreadStack)) { |
6197 | 176 _number_of_threads ++; |
177 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
178 _total_vm_reserved += vm_ptr->size(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
179 _vm_data[index].inc(vm_ptr->size(), 0); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
180 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
181 _total_vm_committed += vm_ptr->size(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
182 _vm_data[index].inc(0, vm_ptr->size()); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
183 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
184 vm_ptr = (VMMemRegion*)vm_itr.next(); |
6197 | 185 } |
186 return true; | |
187 } | |
188 | |
189 // baseline malloc'd memory by callsites, but only the callsites with memory allocation | |
190 // over 1KB are stored. | |
191 bool MemBaseline::baseline_malloc_details(const MemPointerArray* malloc_records) { | |
192 assert(MemTracker::track_callsite(), "detail tracking is off"); | |
193 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
194 MemPointerArrayIteratorImpl malloc_itr(const_cast<MemPointerArray*>(malloc_records)); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
195 MemPointerRecordEx* malloc_ptr = (MemPointerRecordEx*)malloc_itr.current(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
196 MallocCallsitePointer malloc_callsite; |
6197 | 197 |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
198 // initailize malloc callsite array |
6197 | 199 if (_malloc_cs == NULL) { |
200 _malloc_cs = new (std::nothrow) MemPointerArrayImpl<MallocCallsitePointer>(64); | |
201 // out of native memory | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
202 if (_malloc_cs == NULL || _malloc_cs->out_of_memory()) { |
6197 | 203 return false; |
204 } | |
205 } else { | |
206 _malloc_cs->clear(); | |
207 } | |
208 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
209 MemPointerArray* malloc_data = const_cast<MemPointerArray*>(malloc_records); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
210 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
211 // sort into callsite pc order. Details are aggregated by callsites |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
212 malloc_data->sort((FN_SORT)malloc_sort_by_pc); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
213 bool ret = true; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
214 |
6197 | 215 // baseline memory that is totaled over 1 KB |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
216 while (malloc_ptr != NULL) { |
6979
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
217 if (!MemPointerRecord::is_arena_memory_record(malloc_ptr->flags())) { |
6197 | 218 // skip thread stacks |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
219 if (!IS_MEMORY_TYPE(malloc_ptr->flags(), mtThreadStack)) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
220 if (malloc_callsite.addr() != malloc_ptr->pc()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
221 if ((malloc_callsite.amount()/K) > 0) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
222 if (!_malloc_cs->append(&malloc_callsite)) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
223 ret = false; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
224 break; |
6197 | 225 } |
226 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
227 malloc_callsite = MallocCallsitePointer(malloc_ptr->pc()); |
6197 | 228 } |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
229 malloc_callsite.inc(malloc_ptr->size()); |
6197 | 230 } |
231 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
232 malloc_ptr = (MemPointerRecordEx*)malloc_itr.next(); |
6197 | 233 } |
234 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
235 // restore to address order. Snapshot malloc data is maintained in memory |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
236 // address order. |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
237 malloc_data->sort((FN_SORT)malloc_sort_by_addr); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
238 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
239 if (!ret) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
240 return false; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
241 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
242 // deal with last record |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
243 if (malloc_callsite.addr() != 0 && (malloc_callsite.amount()/K) > 0) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
244 if (!_malloc_cs->append(&malloc_callsite)) { |
6197 | 245 return false; |
246 } | |
247 } | |
248 return true; | |
249 } | |
250 | |
251 // baseline mmap'd memory by callsites | |
252 bool MemBaseline::baseline_vm_details(const MemPointerArray* vm_records) { | |
253 assert(MemTracker::track_callsite(), "detail tracking is off"); | |
254 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
255 VMCallsitePointer vm_callsite; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
256 VMCallsitePointer* cur_callsite = NULL; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
257 MemPointerArrayIteratorImpl vm_itr((MemPointerArray*)vm_records); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
258 VMMemRegionEx* vm_ptr = (VMMemRegionEx*)vm_itr.current(); |
6197 | 259 |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
260 // initialize virtual memory map array |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
261 if (_vm_map == NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
262 _vm_map = new (std::nothrow) MemPointerArrayImpl<VMMemRegionEx>(vm_records->length()); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
263 if (_vm_map == NULL || _vm_map->out_of_memory()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
264 return false; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
265 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
266 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
267 _vm_map->clear(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
268 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
269 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
270 // initialize virtual memory callsite array |
6197 | 271 if (_vm_cs == NULL) { |
272 _vm_cs = new (std::nothrow) MemPointerArrayImpl<VMCallsitePointer>(64); | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
273 if (_vm_cs == NULL || _vm_cs->out_of_memory()) { |
6197 | 274 return false; |
275 } | |
276 } else { | |
277 _vm_cs->clear(); | |
278 } | |
279 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
280 // consolidate virtual memory data |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
281 VMMemRegionEx* reserved_rec = NULL; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
282 VMMemRegionEx* committed_rec = NULL; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
283 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
284 // vm_ptr is coming in increasing base address order |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
285 while (vm_ptr != NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
286 if (vm_ptr->is_reserved_region()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
287 // consolidate reserved memory regions for virtual memory map. |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
288 // The criteria for consolidation is: |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
289 // 1. two adjacent reserved memory regions |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
290 // 2. belong to the same memory type |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
291 // 3. reserved from the same callsite |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
292 if (reserved_rec == NULL || |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
293 reserved_rec->base() + reserved_rec->size() != vm_ptr->addr() || |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
294 FLAGS_TO_MEMORY_TYPE(reserved_rec->flags()) != FLAGS_TO_MEMORY_TYPE(vm_ptr->flags()) || |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
295 reserved_rec->pc() != vm_ptr->pc()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
296 if (!_vm_map->append(vm_ptr)) { |
6197 | 297 return false; |
298 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
299 // inserted reserved region, we need the pointer to the element in virtual |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
300 // memory map array. |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
301 reserved_rec = (VMMemRegionEx*)_vm_map->at(_vm_map->length() - 1); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
302 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
303 reserved_rec->expand_region(vm_ptr->addr(), vm_ptr->size()); |
6197 | 304 } |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
305 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
306 if (cur_callsite != NULL && !_vm_cs->append(cur_callsite)) { |
6197 | 307 return false; |
308 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
309 vm_callsite = VMCallsitePointer(vm_ptr->pc()); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
310 cur_callsite = &vm_callsite; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
311 vm_callsite.inc(vm_ptr->size(), 0); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
312 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
313 // consolidate committed memory regions for virtual memory map |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
314 // The criterial is: |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
315 // 1. two adjacent committed memory regions |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
316 // 2. committed from the same callsite |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
317 if (committed_rec == NULL || |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
318 committed_rec->base() + committed_rec->size() != vm_ptr->addr() || |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
319 committed_rec->pc() != vm_ptr->pc()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
320 if (!_vm_map->append(vm_ptr)) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
321 return false; |
10148 | 322 } |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
323 committed_rec = (VMMemRegionEx*)_vm_map->at(_vm_map->length() - 1); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
324 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
325 committed_rec->expand_region(vm_ptr->addr(), vm_ptr->size()); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
326 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
327 vm_callsite.inc(0, vm_ptr->size()); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
328 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
329 vm_ptr = (VMMemRegionEx*)vm_itr.next(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
330 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
331 // deal with last record |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
332 if (cur_callsite != NULL && !_vm_cs->append(cur_callsite)) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
333 return false; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
334 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
335 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
336 // sort it into callsite pc order. Details are aggregated by callsites |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
337 _vm_cs->sort((FN_SORT)bl_vm_sort_by_pc); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
338 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
339 // walk the array to consolidate record by pc |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
340 MemPointerArrayIteratorImpl itr(_vm_cs); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
341 VMCallsitePointer* callsite_rec = (VMCallsitePointer*)itr.current(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
342 VMCallsitePointer* next_rec = (VMCallsitePointer*)itr.next(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
343 while (next_rec != NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
344 assert(callsite_rec != NULL, "Sanity check"); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
345 if (next_rec->addr() == callsite_rec->addr()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
346 callsite_rec->inc(next_rec->reserved_amount(), next_rec->committed_amount()); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
347 itr.remove(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
348 next_rec = (VMCallsitePointer*)itr.current(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
349 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
350 callsite_rec = next_rec; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
351 next_rec = (VMCallsitePointer*)itr.next(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
352 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
353 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
354 |
6197 | 355 return true; |
356 } | |
357 | |
358 // baseline a snapshot. If summary_only = false, memory usages aggregated by | |
359 // callsites are also baselined. | |
10148 | 360 // The method call can be lengthy, especially when detail tracking info is |
361 // requested. So the method checks for safepoint explicitly. | |
6197 | 362 bool MemBaseline::baseline(MemSnapshot& snapshot, bool summary_only) { |
10148 | 363 Thread* THREAD = Thread::current(); |
364 assert(THREAD->is_Java_thread(), "must be a JavaThread"); | |
365 MutexLocker snapshot_locker(snapshot._lock); | |
6197 | 366 reset(); |
10148 | 367 _baselined = baseline_malloc_summary(snapshot._alloc_ptrs); |
368 if (_baselined) { | |
369 check_safepoint((JavaThread*)THREAD); | |
370 _baselined = baseline_vm_summary(snapshot._vm_ptrs); | |
371 } | |
7464
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6979
diff
changeset
|
372 _number_of_classes = snapshot.number_of_classes(); |
6197 | 373 |
374 if (!summary_only && MemTracker::track_callsite() && _baselined) { | |
10148 | 375 check_safepoint((JavaThread*)THREAD); |
376 _baselined = baseline_malloc_details(snapshot._alloc_ptrs); | |
377 if (_baselined) { | |
378 check_safepoint((JavaThread*)THREAD); | |
379 _baselined = baseline_vm_details(snapshot._vm_ptrs); | |
380 } | |
6197 | 381 } |
382 return _baselined; | |
383 } | |
384 | |
385 | |
386 int MemBaseline::flag2index(MEMFLAGS flag) const { | |
387 for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { | |
388 if (MemType2NameMap[index]._flag == flag) { | |
389 return index; | |
390 } | |
391 } | |
392 assert(false, "no type"); | |
393 return -1; | |
394 } | |
395 | |
396 const char* MemBaseline::type2name(MEMFLAGS type) { | |
397 for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { | |
398 if (MemType2NameMap[index]._flag == type) { | |
399 return MemType2NameMap[index]._name; | |
400 } | |
401 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
402 assert(false, err_msg("bad type %x", type)); |
6197 | 403 return NULL; |
404 } | |
405 | |
406 | |
407 MemBaseline& MemBaseline::operator=(const MemBaseline& other) { | |
408 _total_malloced = other._total_malloced; | |
409 _total_vm_reserved = other._total_vm_reserved; | |
410 _total_vm_committed = other._total_vm_committed; | |
411 | |
412 _baselined = other._baselined; | |
413 _number_of_classes = other._number_of_classes; | |
414 | |
415 for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { | |
416 _malloc_data[index] = other._malloc_data[index]; | |
417 _vm_data[index] = other._vm_data[index]; | |
418 _arena_data[index] = other._arena_data[index]; | |
419 } | |
420 | |
421 if (MemTracker::track_callsite()) { | |
422 assert(_malloc_cs != NULL && _vm_cs != NULL, "out of memory"); | |
423 assert(other._malloc_cs != NULL && other._vm_cs != NULL, | |
424 "not properly baselined"); | |
425 _malloc_cs->clear(); | |
426 _vm_cs->clear(); | |
427 int index; | |
428 for (index = 0; index < other._malloc_cs->length(); index ++) { | |
429 _malloc_cs->append(other._malloc_cs->at(index)); | |
430 } | |
431 | |
432 for (index = 0; index < other._vm_cs->length(); index ++) { | |
433 _vm_cs->append(other._vm_cs->at(index)); | |
434 } | |
435 } | |
436 return *this; | |
437 } | |
438 | |
439 /* compare functions for sorting */ | |
440 | |
441 // sort snapshot malloc'd records in callsite pc order | |
442 int MemBaseline::malloc_sort_by_pc(const void* p1, const void* p2) { | |
443 assert(MemTracker::track_callsite(),"Just check"); | |
444 const MemPointerRecordEx* mp1 = (const MemPointerRecordEx*)p1; | |
445 const MemPointerRecordEx* mp2 = (const MemPointerRecordEx*)p2; | |
446 return UNSIGNED_COMPARE(mp1->pc(), mp2->pc()); | |
447 } | |
448 | |
449 // sort baselined malloc'd records in size order | |
450 int MemBaseline::bl_malloc_sort_by_size(const void* p1, const void* p2) { | |
451 assert(MemTracker::is_on(), "Just check"); | |
452 const MallocCallsitePointer* mp1 = (const MallocCallsitePointer*)p1; | |
453 const MallocCallsitePointer* mp2 = (const MallocCallsitePointer*)p2; | |
454 return UNSIGNED_COMPARE(mp2->amount(), mp1->amount()); | |
455 } | |
456 | |
457 // sort baselined malloc'd records in callsite pc order | |
458 int MemBaseline::bl_malloc_sort_by_pc(const void* p1, const void* p2) { | |
459 assert(MemTracker::is_on(), "Just check"); | |
460 const MallocCallsitePointer* mp1 = (const MallocCallsitePointer*)p1; | |
461 const MallocCallsitePointer* mp2 = (const MallocCallsitePointer*)p2; | |
462 return UNSIGNED_COMPARE(mp1->addr(), mp2->addr()); | |
463 } | |
464 | |
465 | |
466 // sort baselined mmap'd records in size (reserved size) order | |
467 int MemBaseline::bl_vm_sort_by_size(const void* p1, const void* p2) { | |
468 assert(MemTracker::is_on(), "Just check"); | |
469 const VMCallsitePointer* mp1 = (const VMCallsitePointer*)p1; | |
470 const VMCallsitePointer* mp2 = (const VMCallsitePointer*)p2; | |
471 return UNSIGNED_COMPARE(mp2->reserved_amount(), mp1->reserved_amount()); | |
472 } | |
473 | |
474 // sort baselined mmap'd records in callsite pc order | |
475 int MemBaseline::bl_vm_sort_by_pc(const void* p1, const void* p2) { | |
476 assert(MemTracker::is_on(), "Just check"); | |
477 const VMCallsitePointer* mp1 = (const VMCallsitePointer*)p1; | |
478 const VMCallsitePointer* mp2 = (const VMCallsitePointer*)p2; | |
479 return UNSIGNED_COMPARE(mp1->addr(), mp2->addr()); | |
480 } | |
481 | |
482 | |
483 // sort snapshot malloc'd records in memory block address order | |
484 int MemBaseline::malloc_sort_by_addr(const void* p1, const void* p2) { | |
485 assert(MemTracker::is_on(), "Just check"); | |
486 const MemPointerRecord* mp1 = (const MemPointerRecord*)p1; | |
487 const MemPointerRecord* mp2 = (const MemPointerRecord*)p2; | |
488 int delta = UNSIGNED_COMPARE(mp1->addr(), mp2->addr()); | |
11102
72fce0b2d341
8011760: assert(delta != 0) failed: dup pointer in MemBaseline::malloc_sort_by_addr
zgu
parents:
10975
diff
changeset
|
489 assert(p1 == p2 || delta != 0, "dup pointer"); |
6197 | 490 return delta; |
491 } | |
492 |