Mercurial > hg > truffle
annotate src/share/vm/services/memBaseline.cpp @ 10252:712a1e9c91f3
8013063: nsk/jvmti/RetransformClasses/retransform001 failed debug version on os::free
Summary: Clear out class_file_bytes so they aren't deallocated twice
Reviewed-by: dcubed, sspitsyn
author | coleenp |
---|---|
date | Tue, 07 May 2013 09:46:15 -0400 |
parents | ed5a590835a4 |
children | f2110083203d |
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"}, | |
44 {mtChunk, "Pooled Free Chunks"}, | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
45 {mtClassShared,"Shared spaces for classes"}, |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
46 {mtTest, "Test"}, |
6197 | 47 {mtNone, "Unknown"} // It can happen when type tagging records are lagging |
48 // behind | |
49 }; | |
50 | |
51 MemBaseline::MemBaseline() { | |
52 _baselined = false; | |
53 | |
54 for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { | |
55 _malloc_data[index].set_type(MemType2NameMap[index]._flag); | |
56 _vm_data[index].set_type(MemType2NameMap[index]._flag); | |
57 _arena_data[index].set_type(MemType2NameMap[index]._flag); | |
58 } | |
59 | |
60 _malloc_cs = NULL; | |
61 _vm_cs = NULL; | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
62 _vm_map = NULL; |
6197 | 63 |
64 _number_of_classes = 0; | |
65 _number_of_threads = 0; | |
66 } | |
67 | |
68 | |
69 void MemBaseline::clear() { | |
70 if (_malloc_cs != NULL) { | |
71 delete _malloc_cs; | |
72 _malloc_cs = NULL; | |
73 } | |
74 | |
75 if (_vm_cs != NULL) { | |
76 delete _vm_cs; | |
77 _vm_cs = NULL; | |
78 } | |
79 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
80 if (_vm_map != NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
81 delete _vm_map; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
82 _vm_map = NULL; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
83 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
84 |
6197 | 85 reset(); |
86 } | |
87 | |
88 | |
89 void MemBaseline::reset() { | |
90 _baselined = false; | |
91 _total_vm_reserved = 0; | |
92 _total_vm_committed = 0; | |
93 _total_malloced = 0; | |
94 _number_of_classes = 0; | |
95 | |
96 if (_malloc_cs != NULL) _malloc_cs->clear(); | |
97 if (_vm_cs != NULL) _vm_cs->clear(); | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
98 if (_vm_map != NULL) _vm_map->clear(); |
6197 | 99 |
100 for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { | |
101 _malloc_data[index].clear(); | |
102 _vm_data[index].clear(); | |
103 _arena_data[index].clear(); | |
104 } | |
105 } | |
106 | |
107 MemBaseline::~MemBaseline() { | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
108 clear(); |
6197 | 109 } |
110 | |
111 // baseline malloc'd memory records, generate overall summary and summaries by | |
112 // memory types | |
113 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
|
114 MemPointerArrayIteratorImpl malloc_itr((MemPointerArray*)malloc_records); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
115 MemPointerRecord* malloc_ptr = (MemPointerRecord*)malloc_itr.current(); |
6197 | 116 size_t used_arena_size = 0; |
117 int index; | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
118 while (malloc_ptr != NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 // 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
|
123 // 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
|
124 _arena_data[index].inc(size); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
125 used_arena_size += size; |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
126 } else { |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
127 _total_malloced += size; |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
128 _malloc_data[index].inc(size); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
129 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
|
130 // 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
|
131 MemPointerRecord* next_malloc_ptr = (MemPointerRecordEx*)malloc_itr.peek_next(); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
132 if (next_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
|
133 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
|
134 "Arena records do not match"); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
135 size = next_malloc_ptr->size(); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
136 _arena_data[index].inc(size); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
137 used_arena_size += size; |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
138 malloc_itr.next(); |
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
139 } |
6197 | 140 } |
141 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
142 malloc_ptr = (MemPointerRecordEx*)malloc_itr.next(); |
6197 | 143 } |
144 | |
145 // substract used arena size to get size of arena chunk in free list | |
146 index = flag2index(mtChunk); | |
147 _malloc_data[index].reduce(used_arena_size); | |
148 // we really don't know how many chunks in free list, so just set to | |
149 // 0 | |
150 _malloc_data[index].overwrite_counter(0); | |
151 | |
152 return true; | |
153 } | |
154 | |
10148 | 155 // check if there is a safepoint in progress, if so, block the thread |
156 // for the safepoint | |
157 void MemBaseline::check_safepoint(JavaThread* thr) { | |
158 if (SafepointSynchronize::is_synchronizing()) { | |
10160
ed5a590835a4
8013214: BigApps fails due to 'fatal error: Illegal threadstate encountered: 6'
zgu
parents:
10148
diff
changeset
|
159 // 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
|
160 MutexLocker ml(thr->SR_lock()); |
10148 | 161 } |
162 } | |
163 | |
6197 | 164 // baseline mmap'd memory records, generate overall summary and summaries by |
165 // memory types | |
166 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
|
167 MemPointerArrayIteratorImpl vm_itr((MemPointerArray*)vm_records); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
168 VMMemRegion* vm_ptr = (VMMemRegion*)vm_itr.current(); |
6197 | 169 int index; |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
170 while (vm_ptr != NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
171 if (vm_ptr->is_reserved_region()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
172 index = flag2index(FLAGS_TO_MEMORY_TYPE(vm_ptr->flags())); |
6197 | 173 // 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
|
174 if (IS_MEMORY_TYPE(vm_ptr->flags(), mtThreadStack)) { |
6197 | 175 _number_of_threads ++; |
176 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
177 _total_vm_reserved += vm_ptr->size(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
178 _vm_data[index].inc(vm_ptr->size(), 0); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
179 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
180 _total_vm_committed += vm_ptr->size(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
181 _vm_data[index].inc(0, vm_ptr->size()); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
182 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
183 vm_ptr = (VMMemRegion*)vm_itr.next(); |
6197 | 184 } |
185 return true; | |
186 } | |
187 | |
188 // baseline malloc'd memory by callsites, but only the callsites with memory allocation | |
189 // over 1KB are stored. | |
190 bool MemBaseline::baseline_malloc_details(const MemPointerArray* malloc_records) { | |
191 assert(MemTracker::track_callsite(), "detail tracking is off"); | |
192 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
193 MemPointerArrayIteratorImpl malloc_itr(const_cast<MemPointerArray*>(malloc_records)); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
194 MemPointerRecordEx* malloc_ptr = (MemPointerRecordEx*)malloc_itr.current(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
195 MallocCallsitePointer malloc_callsite; |
6197 | 196 |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
197 // initailize malloc callsite array |
6197 | 198 if (_malloc_cs == NULL) { |
199 _malloc_cs = new (std::nothrow) MemPointerArrayImpl<MallocCallsitePointer>(64); | |
200 // out of native memory | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
201 if (_malloc_cs == NULL || _malloc_cs->out_of_memory()) { |
6197 | 202 return false; |
203 } | |
204 } else { | |
205 _malloc_cs->clear(); | |
206 } | |
207 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
208 MemPointerArray* malloc_data = const_cast<MemPointerArray*>(malloc_records); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
209 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
210 // 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
|
211 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
|
212 bool ret = true; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
213 |
6197 | 214 // 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
|
215 while (malloc_ptr != NULL) { |
6979
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
216 if (!MemPointerRecord::is_arena_memory_record(malloc_ptr->flags())) { |
6197 | 217 // skip thread stacks |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
218 if (!IS_MEMORY_TYPE(malloc_ptr->flags(), mtThreadStack)) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
219 if (malloc_callsite.addr() != malloc_ptr->pc()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
220 if ((malloc_callsite.amount()/K) > 0) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
221 if (!_malloc_cs->append(&malloc_callsite)) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
222 ret = false; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
223 break; |
6197 | 224 } |
225 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
226 malloc_callsite = MallocCallsitePointer(malloc_ptr->pc()); |
6197 | 227 } |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
228 malloc_callsite.inc(malloc_ptr->size()); |
6197 | 229 } |
230 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
231 malloc_ptr = (MemPointerRecordEx*)malloc_itr.next(); |
6197 | 232 } |
233 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
234 // 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
|
235 // address order. |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
236 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
|
237 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
238 if (!ret) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
239 return false; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
240 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
241 // deal with last record |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
242 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
|
243 if (!_malloc_cs->append(&malloc_callsite)) { |
6197 | 244 return false; |
245 } | |
246 } | |
247 return true; | |
248 } | |
249 | |
250 // baseline mmap'd memory by callsites | |
251 bool MemBaseline::baseline_vm_details(const MemPointerArray* vm_records) { | |
252 assert(MemTracker::track_callsite(), "detail tracking is off"); | |
253 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
254 VMCallsitePointer vm_callsite; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
255 VMCallsitePointer* cur_callsite = NULL; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
256 MemPointerArrayIteratorImpl vm_itr((MemPointerArray*)vm_records); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
257 VMMemRegionEx* vm_ptr = (VMMemRegionEx*)vm_itr.current(); |
6197 | 258 |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
259 // initialize virtual memory map array |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
260 if (_vm_map == NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
261 _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
|
262 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
|
263 return false; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
264 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
265 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
266 _vm_map->clear(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
267 } |
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 // initialize virtual memory callsite array |
6197 | 270 if (_vm_cs == NULL) { |
271 _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
|
272 if (_vm_cs == NULL || _vm_cs->out_of_memory()) { |
6197 | 273 return false; |
274 } | |
275 } else { | |
276 _vm_cs->clear(); | |
277 } | |
278 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
279 // consolidate virtual memory data |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
280 VMMemRegionEx* reserved_rec = NULL; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
281 VMMemRegionEx* committed_rec = NULL; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
282 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
283 // 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
|
284 while (vm_ptr != NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
285 if (vm_ptr->is_reserved_region()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
286 // consolidate reserved memory regions for virtual memory map. |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
287 // The criteria for consolidation is: |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
288 // 1. two adjacent reserved memory regions |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
289 // 2. belong to the same memory type |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
290 // 3. reserved from the same callsite |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
291 if (reserved_rec == NULL || |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
292 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
|
293 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
|
294 reserved_rec->pc() != vm_ptr->pc()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
295 if (!_vm_map->append(vm_ptr)) { |
6197 | 296 return false; |
297 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
298 // 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
|
299 // memory map array. |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
300 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
|
301 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
302 reserved_rec->expand_region(vm_ptr->addr(), vm_ptr->size()); |
6197 | 303 } |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
304 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
305 if (cur_callsite != NULL && !_vm_cs->append(cur_callsite)) { |
6197 | 306 return false; |
307 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
308 vm_callsite = VMCallsitePointer(vm_ptr->pc()); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
309 cur_callsite = &vm_callsite; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
310 vm_callsite.inc(vm_ptr->size(), 0); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
311 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
312 // consolidate committed memory regions for virtual memory map |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
313 // The criterial is: |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
314 // 1. two adjacent committed memory regions |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
315 // 2. committed from the same callsite |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
316 if (committed_rec == NULL || |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
317 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
|
318 committed_rec->pc() != vm_ptr->pc()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
319 if (!_vm_map->append(vm_ptr)) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
320 return false; |
10148 | 321 } |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
322 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
|
323 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
324 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
|
325 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
326 vm_callsite.inc(0, vm_ptr->size()); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
327 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
328 vm_ptr = (VMMemRegionEx*)vm_itr.next(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
329 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
330 // deal with last record |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
331 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
|
332 return false; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
333 } |
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 // 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
|
336 _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
|
337 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
338 // walk the array to consolidate record by pc |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
339 MemPointerArrayIteratorImpl itr(_vm_cs); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
340 VMCallsitePointer* callsite_rec = (VMCallsitePointer*)itr.current(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
341 VMCallsitePointer* next_rec = (VMCallsitePointer*)itr.next(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
342 while (next_rec != NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
343 assert(callsite_rec != NULL, "Sanity check"); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
344 if (next_rec->addr() == callsite_rec->addr()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
345 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
|
346 itr.remove(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
347 next_rec = (VMCallsitePointer*)itr.current(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
348 } else { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
349 callsite_rec = next_rec; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
350 next_rec = (VMCallsitePointer*)itr.next(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
351 } |
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 |
6197 | 354 return true; |
355 } | |
356 | |
357 // baseline a snapshot. If summary_only = false, memory usages aggregated by | |
358 // callsites are also baselined. | |
10148 | 359 // The method call can be lengthy, especially when detail tracking info is |
360 // requested. So the method checks for safepoint explicitly. | |
6197 | 361 bool MemBaseline::baseline(MemSnapshot& snapshot, bool summary_only) { |
10148 | 362 Thread* THREAD = Thread::current(); |
363 assert(THREAD->is_Java_thread(), "must be a JavaThread"); | |
364 MutexLocker snapshot_locker(snapshot._lock); | |
6197 | 365 reset(); |
10148 | 366 _baselined = baseline_malloc_summary(snapshot._alloc_ptrs); |
367 if (_baselined) { | |
368 check_safepoint((JavaThread*)THREAD); | |
369 _baselined = baseline_vm_summary(snapshot._vm_ptrs); | |
370 } | |
7464
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6979
diff
changeset
|
371 _number_of_classes = snapshot.number_of_classes(); |
6197 | 372 |
373 if (!summary_only && MemTracker::track_callsite() && _baselined) { | |
10148 | 374 check_safepoint((JavaThread*)THREAD); |
375 _baselined = baseline_malloc_details(snapshot._alloc_ptrs); | |
376 if (_baselined) { | |
377 check_safepoint((JavaThread*)THREAD); | |
378 _baselined = baseline_vm_details(snapshot._vm_ptrs); | |
379 } | |
6197 | 380 } |
381 return _baselined; | |
382 } | |
383 | |
384 | |
385 int MemBaseline::flag2index(MEMFLAGS flag) const { | |
386 for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { | |
387 if (MemType2NameMap[index]._flag == flag) { | |
388 return index; | |
389 } | |
390 } | |
391 assert(false, "no type"); | |
392 return -1; | |
393 } | |
394 | |
395 const char* MemBaseline::type2name(MEMFLAGS type) { | |
396 for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { | |
397 if (MemType2NameMap[index]._flag == type) { | |
398 return MemType2NameMap[index]._name; | |
399 } | |
400 } | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6197
diff
changeset
|
401 assert(false, err_msg("bad type %x", type)); |
6197 | 402 return NULL; |
403 } | |
404 | |
405 | |
406 MemBaseline& MemBaseline::operator=(const MemBaseline& other) { | |
407 _total_malloced = other._total_malloced; | |
408 _total_vm_reserved = other._total_vm_reserved; | |
409 _total_vm_committed = other._total_vm_committed; | |
410 | |
411 _baselined = other._baselined; | |
412 _number_of_classes = other._number_of_classes; | |
413 | |
414 for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { | |
415 _malloc_data[index] = other._malloc_data[index]; | |
416 _vm_data[index] = other._vm_data[index]; | |
417 _arena_data[index] = other._arena_data[index]; | |
418 } | |
419 | |
420 if (MemTracker::track_callsite()) { | |
421 assert(_malloc_cs != NULL && _vm_cs != NULL, "out of memory"); | |
422 assert(other._malloc_cs != NULL && other._vm_cs != NULL, | |
423 "not properly baselined"); | |
424 _malloc_cs->clear(); | |
425 _vm_cs->clear(); | |
426 int index; | |
427 for (index = 0; index < other._malloc_cs->length(); index ++) { | |
428 _malloc_cs->append(other._malloc_cs->at(index)); | |
429 } | |
430 | |
431 for (index = 0; index < other._vm_cs->length(); index ++) { | |
432 _vm_cs->append(other._vm_cs->at(index)); | |
433 } | |
434 } | |
435 return *this; | |
436 } | |
437 | |
438 /* compare functions for sorting */ | |
439 | |
440 // sort snapshot malloc'd records in callsite pc order | |
441 int MemBaseline::malloc_sort_by_pc(const void* p1, const void* p2) { | |
442 assert(MemTracker::track_callsite(),"Just check"); | |
443 const MemPointerRecordEx* mp1 = (const MemPointerRecordEx*)p1; | |
444 const MemPointerRecordEx* mp2 = (const MemPointerRecordEx*)p2; | |
445 return UNSIGNED_COMPARE(mp1->pc(), mp2->pc()); | |
446 } | |
447 | |
448 // sort baselined malloc'd records in size order | |
449 int MemBaseline::bl_malloc_sort_by_size(const void* p1, const void* p2) { | |
450 assert(MemTracker::is_on(), "Just check"); | |
451 const MallocCallsitePointer* mp1 = (const MallocCallsitePointer*)p1; | |
452 const MallocCallsitePointer* mp2 = (const MallocCallsitePointer*)p2; | |
453 return UNSIGNED_COMPARE(mp2->amount(), mp1->amount()); | |
454 } | |
455 | |
456 // sort baselined malloc'd records in callsite pc order | |
457 int MemBaseline::bl_malloc_sort_by_pc(const void* p1, const void* p2) { | |
458 assert(MemTracker::is_on(), "Just check"); | |
459 const MallocCallsitePointer* mp1 = (const MallocCallsitePointer*)p1; | |
460 const MallocCallsitePointer* mp2 = (const MallocCallsitePointer*)p2; | |
461 return UNSIGNED_COMPARE(mp1->addr(), mp2->addr()); | |
462 } | |
463 | |
464 | |
465 // sort baselined mmap'd records in size (reserved size) order | |
466 int MemBaseline::bl_vm_sort_by_size(const void* p1, const void* p2) { | |
467 assert(MemTracker::is_on(), "Just check"); | |
468 const VMCallsitePointer* mp1 = (const VMCallsitePointer*)p1; | |
469 const VMCallsitePointer* mp2 = (const VMCallsitePointer*)p2; | |
470 return UNSIGNED_COMPARE(mp2->reserved_amount(), mp1->reserved_amount()); | |
471 } | |
472 | |
473 // sort baselined mmap'd records in callsite pc order | |
474 int MemBaseline::bl_vm_sort_by_pc(const void* p1, const void* p2) { | |
475 assert(MemTracker::is_on(), "Just check"); | |
476 const VMCallsitePointer* mp1 = (const VMCallsitePointer*)p1; | |
477 const VMCallsitePointer* mp2 = (const VMCallsitePointer*)p2; | |
478 return UNSIGNED_COMPARE(mp1->addr(), mp2->addr()); | |
479 } | |
480 | |
481 | |
482 // sort snapshot malloc'd records in memory block address order | |
483 int MemBaseline::malloc_sort_by_addr(const void* p1, const void* p2) { | |
484 assert(MemTracker::is_on(), "Just check"); | |
485 const MemPointerRecord* mp1 = (const MemPointerRecord*)p1; | |
486 const MemPointerRecord* mp2 = (const MemPointerRecord*)p2; | |
487 int delta = UNSIGNED_COMPARE(mp1->addr(), mp2->addr()); | |
488 assert(delta != 0, "dup pointer"); | |
489 return delta; | |
490 } | |
491 |