author | mgronlun |
Wed, 30 Oct 2019 19:43:52 +0100 | |
changeset 58863 | c16ac7a2eba4 |
parent 58132 | caa25ab47aca |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 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 |
||
25 |
#include "precompiled.hpp" |
|
26 |
#include "jfrfiles/jfrTypes.hpp" |
|
27 |
#include "jfr/leakprofiler/chains/edge.hpp" |
|
28 |
#include "jfr/leakprofiler/chains/edgeStore.hpp" |
|
29 |
#include "jfr/leakprofiler/chains/edgeUtils.hpp" |
|
30 |
#include "jfr/leakprofiler/checkpoint/objectSampleDescription.hpp" |
|
31 |
#include "jfr/leakprofiler/checkpoint/objectSampleWriter.hpp" |
|
32 |
#include "jfr/leakprofiler/checkpoint/rootResolver.hpp" |
|
33 |
#include "jfr/leakprofiler/sampling/objectSampler.hpp" |
|
34 |
#include "jfr/leakprofiler/utilities/rootType.hpp" |
|
35 |
#include "jfr/leakprofiler/utilities/unifiedOop.hpp" |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
36 |
#include "jfr/metadata/jfrSerializer.hpp" |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
37 |
#include "jfr/writers/jfrTypeWriterHost.hpp" |
50113 | 38 |
#include "oops/oop.inline.hpp" |
39 |
#include "oops/symbol.hpp" |
|
40 |
#include "utilities/growableArray.hpp" |
|
41 |
||
42 |
template <typename Data> |
|
43 |
class ObjectSampleAuxInfo : public ResourceObj { |
|
44 |
public: |
|
45 |
Data _data; |
|
46 |
traceid _id; |
|
47 |
ObjectSampleAuxInfo() : _data(), _id(0) {} |
|
48 |
}; |
|
49 |
||
50 |
class ObjectSampleArrayData { |
|
51 |
public: |
|
52 |
int _array_size; |
|
53 |
int _array_index; |
|
54 |
ObjectSampleArrayData() : _array_size(0), _array_index(0) {} |
|
55 |
}; |
|
56 |
||
57 |
class ObjectSampleFieldInfo : public ResourceObj { |
|
58 |
public: |
|
59 |
const Symbol* _field_name_symbol; |
|
60 |
jshort _field_modifiers; |
|
61 |
ObjectSampleFieldInfo() : _field_name_symbol(NULL), _field_modifiers(0) {} |
|
62 |
}; |
|
63 |
||
64 |
class ObjectSampleRootDescriptionData { |
|
65 |
public: |
|
66 |
const Edge* _root_edge; |
|
67 |
const char* _description; |
|
68 |
OldObjectRoot::System _system; |
|
69 |
OldObjectRoot::Type _type; |
|
70 |
ObjectSampleRootDescriptionData() : _root_edge(NULL), |
|
71 |
_description(NULL), |
|
72 |
_system(OldObjectRoot::_system_undetermined), |
|
73 |
_type(OldObjectRoot::_type_undetermined) {} |
|
74 |
}; |
|
75 |
||
76 |
class OldObjectSampleData { |
|
77 |
public: |
|
78 |
oop _object; |
|
79 |
traceid _reference_id; |
|
80 |
}; |
|
81 |
||
82 |
class ReferenceData { |
|
83 |
public: |
|
84 |
traceid _field_info_id; |
|
85 |
traceid _array_info_id; |
|
86 |
traceid _old_object_sample_id; |
|
87 |
size_t _skip; |
|
88 |
}; |
|
89 |
||
90 |
static int initial_storage_size = 16; |
|
91 |
||
92 |
template <typename Data> |
|
93 |
class SampleSet : public ResourceObj { |
|
94 |
private: |
|
95 |
GrowableArray<Data>* _storage; |
|
96 |
public: |
|
97 |
SampleSet() : _storage(NULL) {} |
|
98 |
||
99 |
traceid store(Data data) { |
|
100 |
assert(data != NULL, "invariant"); |
|
101 |
if (_storage == NULL) { |
|
102 |
_storage = new GrowableArray<Data>(initial_storage_size); |
|
103 |
} |
|
104 |
assert(_storage != NULL, "invariant"); |
|
105 |
assert(_storage->find(data) == -1, "invariant"); |
|
106 |
_storage->append(data); |
|
107 |
return data->_id; |
|
108 |
} |
|
109 |
||
110 |
size_t size() const { |
|
111 |
return _storage != NULL ? (size_t)_storage->length() : 0; |
|
112 |
} |
|
113 |
||
114 |
template <typename Functor> |
|
115 |
void iterate(Functor& functor) { |
|
116 |
if (_storage != NULL) { |
|
117 |
for (int i = 0; i < _storage->length(); ++i) { |
|
118 |
functor(_storage->at(i)); |
|
119 |
} |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
const GrowableArray<Data>& storage() const { |
|
124 |
return *_storage; |
|
125 |
} |
|
126 |
}; |
|
127 |
||
128 |
typedef ObjectSampleAuxInfo<ObjectSampleArrayData> ObjectSampleArrayInfo; |
|
129 |
typedef ObjectSampleAuxInfo<ObjectSampleRootDescriptionData> ObjectSampleRootDescriptionInfo; |
|
130 |
typedef ObjectSampleAuxInfo<OldObjectSampleData> OldObjectSampleInfo; |
|
131 |
typedef ObjectSampleAuxInfo<ReferenceData> ReferenceInfo; |
|
132 |
||
133 |
class FieldTable : public ResourceObj { |
|
134 |
template <typename, |
|
135 |
typename, |
|
136 |
template<typename, typename> class, |
|
137 |
typename, |
|
138 |
size_t> |
|
139 |
friend class HashTableHost; |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
140 |
typedef HashTableHost<const ObjectSampleFieldInfo*, traceid, JfrHashtableEntry, FieldTable, 109> FieldInfoTable; |
50113 | 141 |
public: |
142 |
typedef FieldInfoTable::HashEntry FieldInfoEntry; |
|
143 |
||
144 |
private: |
|
145 |
static traceid _field_id_counter; |
|
146 |
FieldInfoTable* _table; |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
147 |
const ObjectSampleFieldInfo* _lookup; |
50113 | 148 |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
149 |
void on_link(FieldInfoEntry* entry) { |
50113 | 150 |
assert(entry != NULL, "invariant"); |
151 |
entry->set_id(++_field_id_counter); |
|
152 |
} |
|
153 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
154 |
bool on_equals(uintptr_t hash, const FieldInfoEntry* entry) { |
50113 | 155 |
assert(hash == entry->hash(), "invariant"); |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
156 |
assert(_lookup != NULL, "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
157 |
return entry->literal()->_field_modifiers == _lookup->_field_modifiers; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
158 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
159 |
|
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
160 |
void on_unlink(FieldInfoEntry* entry) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
161 |
assert(entry != NULL, "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
162 |
// nothing |
50113 | 163 |
} |
164 |
||
165 |
public: |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
166 |
FieldTable() : _table(new FieldInfoTable(this)), _lookup(NULL) {} |
50113 | 167 |
~FieldTable() { |
168 |
assert(_table != NULL, "invariant"); |
|
169 |
delete _table; |
|
170 |
} |
|
171 |
||
172 |
traceid store(const ObjectSampleFieldInfo* field_info) { |
|
173 |
assert(field_info != NULL, "invariant"); |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
174 |
_lookup = field_info; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
175 |
const FieldInfoEntry& entry = _table->lookup_put(field_info->_field_name_symbol->identity_hash(), field_info); |
50113 | 176 |
return entry.id(); |
177 |
} |
|
178 |
||
179 |
size_t size() const { |
|
180 |
return _table->cardinality(); |
|
181 |
} |
|
182 |
||
183 |
template <typename T> |
|
184 |
void iterate(T& functor) const { |
|
185 |
_table->iterate_entry<T>(functor); |
|
186 |
} |
|
187 |
}; |
|
188 |
||
189 |
traceid FieldTable::_field_id_counter = 0; |
|
190 |
||
191 |
typedef SampleSet<const OldObjectSampleInfo*> SampleInfo; |
|
192 |
typedef SampleSet<const ReferenceInfo*> RefInfo; |
|
193 |
typedef SampleSet<const ObjectSampleArrayInfo*> ArrayInfo; |
|
194 |
typedef SampleSet<const ObjectSampleRootDescriptionInfo*> RootDescriptionInfo; |
|
195 |
||
196 |
static SampleInfo* sample_infos = NULL; |
|
197 |
static RefInfo* ref_infos = NULL; |
|
198 |
static ArrayInfo* array_infos = NULL; |
|
199 |
static FieldTable* field_infos = NULL; |
|
200 |
static RootDescriptionInfo* root_infos = NULL; |
|
201 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
202 |
int __write_sample_info__(JfrCheckpointWriter* writer, const void* si) { |
50113 | 203 |
assert(writer != NULL, "invariant"); |
204 |
assert(si != NULL, "invariant"); |
|
205 |
const OldObjectSampleInfo* const oosi = (const OldObjectSampleInfo*)si; |
|
206 |
oop object = oosi->_data._object; |
|
207 |
assert(object != NULL, "invariant"); |
|
208 |
writer->write(oosi->_id); |
|
209 |
writer->write((u8)(const HeapWord*)object); |
|
210 |
writer->write(const_cast<const Klass*>(object->klass())); |
|
211 |
ObjectSampleDescription od(object); |
|
212 |
writer->write(od.description()); |
|
213 |
writer->write(oosi->_data._reference_id); |
|
214 |
return 1; |
|
215 |
} |
|
216 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
217 |
typedef JfrTypeWriterImplHost<const OldObjectSampleInfo*, __write_sample_info__> SampleWriterImpl; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
218 |
typedef JfrTypeWriterHost<SampleWriterImpl, TYPE_OLDOBJECT> SampleWriter; |
50113 | 219 |
|
220 |
static void write_sample_infos(JfrCheckpointWriter& writer) { |
|
221 |
if (sample_infos != NULL) { |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
222 |
SampleWriter sw(&writer); |
50113 | 223 |
sample_infos->iterate(sw); |
224 |
} |
|
225 |
} |
|
226 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
227 |
int __write_reference_info__(JfrCheckpointWriter* writer, const void* ri) { |
50113 | 228 |
assert(writer != NULL, "invariant"); |
229 |
assert(ri != NULL, "invariant"); |
|
230 |
const ReferenceInfo* const ref_info = (const ReferenceInfo*)ri; |
|
231 |
writer->write(ref_info->_id); |
|
232 |
writer->write(ref_info->_data._array_info_id); |
|
233 |
writer->write(ref_info->_data._field_info_id); |
|
234 |
writer->write(ref_info->_data._old_object_sample_id); |
|
235 |
writer->write<s4>((s4)ref_info->_data._skip); |
|
236 |
return 1; |
|
237 |
} |
|
238 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
239 |
typedef JfrTypeWriterImplHost<const ReferenceInfo*, __write_reference_info__> ReferenceWriterImpl; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
240 |
typedef JfrTypeWriterHost<ReferenceWriterImpl, TYPE_REFERENCE> ReferenceWriter; |
50113 | 241 |
|
242 |
static void write_reference_infos(JfrCheckpointWriter& writer) { |
|
243 |
if (ref_infos != NULL) { |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
244 |
ReferenceWriter rw(&writer); |
50113 | 245 |
ref_infos->iterate(rw); |
246 |
} |
|
247 |
} |
|
248 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
249 |
int __write_array_info__(JfrCheckpointWriter* writer, const void* ai) { |
50113 | 250 |
assert(writer != NULL, "invariant"); |
251 |
assert(ai != NULL, "invariant"); |
|
252 |
const ObjectSampleArrayInfo* const osai = (const ObjectSampleArrayInfo*)ai; |
|
253 |
writer->write(osai->_id); |
|
254 |
writer->write(osai->_data._array_size); |
|
255 |
writer->write(osai->_data._array_index); |
|
256 |
return 1; |
|
257 |
} |
|
258 |
||
259 |
static traceid get_array_info_id(const Edge& edge, traceid id) { |
|
260 |
if (edge.is_root() || !EdgeUtils::is_array_element(edge)) { |
|
261 |
return 0; |
|
262 |
} |
|
263 |
if (array_infos == NULL) { |
|
264 |
array_infos = new ArrayInfo(); |
|
265 |
} |
|
266 |
assert(array_infos != NULL, "invariant"); |
|
267 |
||
268 |
ObjectSampleArrayInfo* const osai = new ObjectSampleArrayInfo(); |
|
269 |
assert(osai != NULL, "invariant"); |
|
270 |
osai->_id = id; |
|
271 |
osai->_data._array_size = EdgeUtils::array_size(edge); |
|
272 |
osai->_data._array_index = EdgeUtils::array_index(edge); |
|
273 |
return array_infos->store(osai); |
|
274 |
} |
|
275 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
276 |
typedef JfrTypeWriterImplHost<const ObjectSampleArrayInfo*, __write_array_info__> ArrayWriterImpl; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
277 |
typedef JfrTypeWriterHost<ArrayWriterImpl, TYPE_OLDOBJECTARRAY> ArrayWriter; |
50113 | 278 |
|
279 |
static void write_array_infos(JfrCheckpointWriter& writer) { |
|
280 |
if (array_infos != NULL) { |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
281 |
ArrayWriter aw(&writer); |
50113 | 282 |
array_infos->iterate(aw); |
283 |
} |
|
284 |
} |
|
285 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
286 |
int __write_field_info__(JfrCheckpointWriter* writer, const void* fi) { |
50113 | 287 |
assert(writer != NULL, "invariant"); |
288 |
assert(fi != NULL, "invariant"); |
|
289 |
const FieldTable::FieldInfoEntry* field_info_entry = (const FieldTable::FieldInfoEntry*)fi; |
|
290 |
writer->write(field_info_entry->id()); |
|
291 |
const ObjectSampleFieldInfo* const osfi = field_info_entry->literal(); |
|
292 |
writer->write(osfi->_field_name_symbol->as_C_string()); |
|
293 |
writer->write(osfi->_field_modifiers); |
|
294 |
return 1; |
|
295 |
} |
|
296 |
||
297 |
static traceid get_field_info_id(const Edge& edge) { |
|
298 |
if (edge.is_root()) { |
|
299 |
return 0; |
|
300 |
} |
|
301 |
||
302 |
assert(!EdgeUtils::is_array_element(edge), "invariant"); |
|
303 |
const Symbol* const field_name_symbol = EdgeUtils::field_name_symbol(edge); |
|
304 |
if (field_name_symbol == NULL) { |
|
305 |
return 0; |
|
306 |
} |
|
307 |
||
308 |
if (field_infos == NULL) { |
|
309 |
field_infos = new FieldTable(); |
|
310 |
} |
|
311 |
assert(field_infos != NULL, "invariant"); |
|
312 |
||
313 |
ObjectSampleFieldInfo* const osfi = new ObjectSampleFieldInfo(); |
|
314 |
assert(osfi != NULL, "invariant"); |
|
315 |
osfi->_field_name_symbol = field_name_symbol; |
|
316 |
osfi->_field_modifiers = EdgeUtils::field_modifiers(edge); |
|
317 |
return field_infos->store(osfi); |
|
318 |
} |
|
319 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
320 |
typedef JfrTypeWriterImplHost<const FieldTable::FieldInfoEntry*, __write_field_info__> FieldWriterImpl; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
321 |
typedef JfrTypeWriterHost<FieldWriterImpl, TYPE_OLDOBJECTFIELD> FieldWriter; |
50113 | 322 |
|
323 |
static void write_field_infos(JfrCheckpointWriter& writer) { |
|
324 |
if (field_infos != NULL) { |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
325 |
FieldWriter fw(&writer); |
50113 | 326 |
field_infos->iterate(fw); |
327 |
} |
|
328 |
} |
|
329 |
||
330 |
static const char* description(const ObjectSampleRootDescriptionInfo* osdi) { |
|
331 |
assert(osdi != NULL, "invariant"); |
|
332 |
||
333 |
if (osdi->_data._description == NULL) { |
|
334 |
return NULL; |
|
335 |
} |
|
336 |
||
337 |
ObjectDescriptionBuilder description; |
|
338 |
if (osdi->_data._system == OldObjectRoot::_threads) { |
|
339 |
description.write_text("Thread Name: "); |
|
340 |
} |
|
341 |
description.write_text(osdi->_data._description); |
|
342 |
return description.description(); |
|
343 |
} |
|
344 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
345 |
int __write_root_description_info__(JfrCheckpointWriter* writer, const void* di) { |
50113 | 346 |
assert(writer != NULL, "invariant"); |
347 |
assert(di != NULL, "invariant"); |
|
348 |
const ObjectSampleRootDescriptionInfo* const osdi = (const ObjectSampleRootDescriptionInfo*)di; |
|
349 |
writer->write(osdi->_id); |
|
350 |
writer->write(description(osdi)); |
|
351 |
writer->write<u8>(osdi->_data._system); |
|
352 |
writer->write<u8>(osdi->_data._type); |
|
353 |
return 1; |
|
354 |
} |
|
355 |
||
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
356 |
static traceid get_gc_root_description_info_id(const Edge& edge, traceid id) { |
50113 | 357 |
assert(edge.is_root(), "invariant"); |
358 |
if (root_infos == NULL) { |
|
359 |
root_infos = new RootDescriptionInfo(); |
|
360 |
} |
|
361 |
assert(root_infos != NULL, "invariant"); |
|
362 |
ObjectSampleRootDescriptionInfo* const oodi = new ObjectSampleRootDescriptionInfo(); |
|
363 |
oodi->_id = id; |
|
364 |
oodi->_data._root_edge = &edge; |
|
365 |
return root_infos->store(oodi); |
|
366 |
} |
|
367 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
368 |
typedef JfrTypeWriterImplHost<const ObjectSampleRootDescriptionInfo*, __write_root_description_info__> RootDescriptionWriterImpl; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
369 |
typedef JfrTypeWriterHost<RootDescriptionWriterImpl, TYPE_OLDOBJECTGCROOT> RootDescriptionWriter; |
50113 | 370 |
|
371 |
||
372 |
int _edge_reference_compare_(uintptr_t lhs, uintptr_t rhs) { |
|
373 |
return lhs > rhs ? 1 : (lhs < rhs) ? -1 : 0; |
|
374 |
} |
|
375 |
||
376 |
int _root_desc_compare_(const ObjectSampleRootDescriptionInfo*const & lhs, const ObjectSampleRootDescriptionInfo* const& rhs) { |
|
377 |
const uintptr_t lhs_ref = (uintptr_t)lhs->_data._root_edge->reference(); |
|
378 |
const uintptr_t rhs_ref = (uintptr_t)rhs->_data._root_edge->reference(); |
|
379 |
return _edge_reference_compare_(lhs_ref, rhs_ref); |
|
380 |
} |
|
381 |
||
382 |
static int find_sorted(const RootCallbackInfo& callback_info, |
|
383 |
const GrowableArray<const ObjectSampleRootDescriptionInfo*>* arr, |
|
384 |
int length, |
|
385 |
bool& found) { |
|
386 |
assert(arr != NULL, "invariant"); |
|
387 |
assert(length >= 0, "invariant"); |
|
388 |
assert(length <= arr->length(), "invariant"); |
|
389 |
||
390 |
found = false; |
|
391 |
int min = 0; |
|
392 |
int max = length; |
|
393 |
while (max >= min) { |
|
394 |
const int mid = (int)(((uint)max + min) / 2); |
|
395 |
int diff = _edge_reference_compare_((uintptr_t)callback_info._high, |
|
396 |
(uintptr_t)arr->at(mid)->_data._root_edge->reference()); |
|
397 |
if (diff > 0) { |
|
398 |
min = mid + 1; |
|
399 |
} else if (diff < 0) { |
|
400 |
max = mid - 1; |
|
401 |
} else { |
|
402 |
found = true; |
|
403 |
return mid; |
|
404 |
} |
|
405 |
} |
|
406 |
return min; |
|
407 |
} |
|
408 |
||
409 |
class RootResolutionSet : public ResourceObj, public RootCallback { |
|
410 |
private: |
|
411 |
GrowableArray<const ObjectSampleRootDescriptionInfo*>* _unresolved_roots; |
|
412 |
||
413 |
const uintptr_t high() const { |
|
414 |
return (uintptr_t)_unresolved_roots->last()->_data._root_edge->reference(); |
|
415 |
} |
|
416 |
||
417 |
const uintptr_t low() const { |
|
418 |
return (uintptr_t)_unresolved_roots->first()->_data._root_edge->reference(); |
|
419 |
} |
|
420 |
||
421 |
bool in_set_address_range(const RootCallbackInfo& callback_info) const { |
|
422 |
assert(callback_info._low == NULL, "invariant"); |
|
423 |
const uintptr_t addr = (uintptr_t)callback_info._high; |
|
424 |
return low() <= addr && high() >= addr; |
|
425 |
} |
|
426 |
||
427 |
int compare_to_range(const RootCallbackInfo& callback_info) const { |
|
428 |
assert(callback_info._high != NULL, "invariant"); |
|
429 |
assert(callback_info._low != NULL, "invariant"); |
|
430 |
||
431 |
for (int i = 0; i < _unresolved_roots->length(); ++i) { |
|
432 |
const uintptr_t ref_addr = (uintptr_t)_unresolved_roots->at(i)->_data._root_edge->reference(); |
|
433 |
if ((uintptr_t)callback_info._low <= ref_addr && (uintptr_t)callback_info._high >= ref_addr) { |
|
434 |
return i; |
|
435 |
} |
|
436 |
} |
|
437 |
return -1; |
|
438 |
} |
|
439 |
||
440 |
int exact(const RootCallbackInfo& callback_info) const { |
|
441 |
assert(callback_info._high != NULL, "invariant"); |
|
442 |
assert(in_set_address_range(callback_info), "invariant"); |
|
443 |
||
444 |
bool found; |
|
445 |
const int idx = find_sorted(callback_info, _unresolved_roots, _unresolved_roots->length(), found); |
|
446 |
return found ? idx : -1; |
|
447 |
} |
|
448 |
||
449 |
bool resolve_root(const RootCallbackInfo& callback_info, int idx) const { |
|
450 |
assert(idx >= 0, "invariant"); |
|
451 |
assert(idx < _unresolved_roots->length(), "invariant"); |
|
452 |
||
453 |
ObjectSampleRootDescriptionInfo* const desc = |
|
454 |
const_cast<ObjectSampleRootDescriptionInfo*>(_unresolved_roots->at(idx)); |
|
455 |
assert(desc != NULL, "invariant"); |
|
456 |
assert((uintptr_t)callback_info._high == (uintptr_t)desc->_data._root_edge->reference(), "invariant"); |
|
457 |
||
458 |
desc->_data._system = callback_info._system; |
|
459 |
desc->_data._type = callback_info._type; |
|
460 |
||
461 |
if (callback_info._system == OldObjectRoot::_threads) { |
|
462 |
const JavaThread* jt = (const JavaThread*)callback_info._context; |
|
463 |
assert(jt != NULL, "invariant"); |
|
464 |
desc->_data._description = jt->name(); |
|
465 |
} |
|
466 |
||
467 |
_unresolved_roots->remove_at(idx); |
|
468 |
return _unresolved_roots->is_empty(); |
|
469 |
} |
|
470 |
||
471 |
public: |
|
472 |
RootResolutionSet(RootDescriptionInfo* info) : _unresolved_roots(NULL) { |
|
473 |
assert(info != NULL, "invariant"); |
|
474 |
// construct a sorted copy |
|
475 |
const GrowableArray<const ObjectSampleRootDescriptionInfo*>& info_storage = info->storage(); |
|
476 |
const int length = info_storage.length(); |
|
477 |
_unresolved_roots = new GrowableArray<const ObjectSampleRootDescriptionInfo*>(length); |
|
478 |
assert(_unresolved_roots != NULL, "invariant"); |
|
479 |
||
480 |
for (int i = 0; i < length; ++i) { |
|
481 |
_unresolved_roots->insert_sorted<_root_desc_compare_>(info_storage.at(i)); |
|
482 |
} |
|
483 |
} |
|
484 |
||
485 |
bool process(const RootCallbackInfo& callback_info) { |
|
486 |
if (NULL == callback_info._low) { |
|
487 |
if (in_set_address_range(callback_info)) { |
|
488 |
const int idx = exact(callback_info); |
|
489 |
return idx == -1 ? false : resolve_root(callback_info, idx); |
|
490 |
} |
|
491 |
return false; |
|
492 |
} |
|
493 |
assert(callback_info._low != NULL, "invariant"); |
|
494 |
const int idx = compare_to_range(callback_info); |
|
495 |
return idx == -1 ? false : resolve_root(callback_info, idx); |
|
496 |
} |
|
497 |
||
498 |
int entries() const { |
|
499 |
return _unresolved_roots->length(); |
|
500 |
} |
|
501 |
||
502 |
const void* at(int idx) const { |
|
503 |
assert(idx >= 0, "invariant"); |
|
504 |
assert(idx < _unresolved_roots->length(), "invariant"); |
|
505 |
return _unresolved_roots->at(idx)->_data._root_edge->reference(); |
|
506 |
} |
|
507 |
}; |
|
508 |
||
509 |
static void write_root_descriptors(JfrCheckpointWriter& writer) { |
|
510 |
if (root_infos != NULL) { |
|
511 |
// resolve roots |
|
512 |
RootResolutionSet rrs(root_infos); |
|
513 |
RootResolver::resolve(rrs); |
|
514 |
// write roots |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
515 |
RootDescriptionWriter rw(&writer); |
50113 | 516 |
root_infos->iterate(rw); |
517 |
} |
|
518 |
} |
|
519 |
||
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
520 |
static void add_old_object_sample_info(const StoredEdge* current, traceid id) { |
50113 | 521 |
assert(current != NULL, "invariant"); |
522 |
if (sample_infos == NULL) { |
|
523 |
sample_infos = new SampleInfo(); |
|
524 |
} |
|
525 |
assert(sample_infos != NULL, "invariant"); |
|
526 |
OldObjectSampleInfo* const oosi = new OldObjectSampleInfo(); |
|
527 |
assert(oosi != NULL, "invariant"); |
|
528 |
oosi->_id = id; |
|
529 |
oosi->_data._object = current->pointee(); |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
530 |
oosi->_data._reference_id = current->parent() == NULL ? (traceid)0 : id; |
50113 | 531 |
sample_infos->store(oosi); |
532 |
} |
|
533 |
||
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
534 |
static void add_reference_info(const StoredEdge* current, traceid id, traceid parent_id) { |
50113 | 535 |
assert(current != NULL, "invariant"); |
536 |
if (ref_infos == NULL) { |
|
537 |
ref_infos = new RefInfo(); |
|
538 |
} |
|
539 |
||
540 |
assert(ref_infos != NULL, "invariant"); |
|
541 |
ReferenceInfo* const ri = new ReferenceInfo(); |
|
542 |
assert(ri != NULL, "invariant"); |
|
543 |
||
544 |
ri->_id = id; |
|
545 |
ri->_data._array_info_id = !current->is_skip_edge() ? get_array_info_id(*current, id) : 0; |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
546 |
ri->_data._field_info_id = ri->_data._array_info_id == 0 && !current->is_skip_edge() ? get_field_info_id(*current) : (traceid)0; |
50113 | 547 |
ri->_data._old_object_sample_id = parent_id; |
548 |
ri->_data._skip = current->skip_length(); |
|
549 |
ref_infos->store(ri); |
|
550 |
} |
|
551 |
||
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
552 |
static bool is_gc_root(const StoredEdge* current) { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
553 |
assert(current != NULL, "invariant"); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
554 |
return current->parent() == NULL && current->gc_root_id() != 0; |
50113 | 555 |
} |
556 |
||
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
557 |
static traceid add_gc_root_info(const StoredEdge* root, traceid id) { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
558 |
assert(root != NULL, "invariant"); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
559 |
assert(is_gc_root(root), "invariant"); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
560 |
return get_gc_root_description_info_id(*root, id); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
561 |
} |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
562 |
|
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
563 |
void ObjectSampleWriter::write(const StoredEdge* edge) { |
50113 | 564 |
assert(edge != NULL, "invariant"); |
565 |
const traceid id = _store->get_id(edge); |
|
566 |
add_old_object_sample_info(edge, id); |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
567 |
const StoredEdge* const parent = edge->parent(); |
50113 | 568 |
if (parent != NULL) { |
569 |
add_reference_info(edge, id, _store->get_id(parent)); |
|
570 |
} else { |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
571 |
if (is_gc_root(edge)) { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
572 |
assert(edge->gc_root_id() == id, "invariant"); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
573 |
add_gc_root_info(edge, id); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
574 |
} |
50113 | 575 |
} |
576 |
} |
|
577 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
578 |
class RootSystemType : public JfrSerializer { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
579 |
public: |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
580 |
void serialize(JfrCheckpointWriter& writer) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
581 |
const u4 nof_root_systems = OldObjectRoot::_number_of_systems; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
582 |
writer.write_count(nof_root_systems); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
583 |
for (u4 i = 0; i < nof_root_systems; ++i) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
584 |
writer.write_key(i); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
585 |
writer.write(OldObjectRoot::system_description((OldObjectRoot::System)i)); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
586 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
587 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
588 |
}; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
589 |
|
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
590 |
class RootType : public JfrSerializer { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
591 |
public: |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
592 |
void serialize(JfrCheckpointWriter& writer) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
593 |
const u4 nof_root_types = OldObjectRoot::_number_of_types; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
594 |
writer.write_count(nof_root_types); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
595 |
for (u4 i = 0; i < nof_root_types; ++i) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
596 |
writer.write_key(i); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
597 |
writer.write(OldObjectRoot::type_description((OldObjectRoot::Type)i)); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
598 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
599 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
600 |
}; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
601 |
|
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
602 |
static void register_serializers() { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
603 |
static bool is_registered = false; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
604 |
if (!is_registered) { |
58863 | 605 |
JfrSerializer::register_serializer(TYPE_OLDOBJECTROOTSYSTEM, true, new RootSystemType()); |
606 |
JfrSerializer::register_serializer(TYPE_OLDOBJECTROOTTYPE, true, new RootType()); |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
607 |
is_registered = true; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
608 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
609 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
610 |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
611 |
ObjectSampleWriter::ObjectSampleWriter(JfrCheckpointWriter& writer, EdgeStore* store) : |
50113 | 612 |
_writer(writer), |
613 |
_store(store) { |
|
614 |
assert(store != NULL, "invariant"); |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
615 |
assert(!store->is_empty(), "invariant"); |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
616 |
register_serializers(); |
50113 | 617 |
sample_infos = NULL; |
618 |
ref_infos = NULL; |
|
619 |
array_infos = NULL; |
|
620 |
field_infos = NULL; |
|
621 |
root_infos = NULL; |
|
622 |
} |
|
623 |
||
624 |
ObjectSampleWriter::~ObjectSampleWriter() { |
|
625 |
write_sample_infos(_writer); |
|
626 |
write_reference_infos(_writer); |
|
627 |
write_array_infos(_writer); |
|
628 |
write_field_infos(_writer); |
|
629 |
write_root_descriptors(_writer); |
|
630 |
} |
|
631 |
||
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
632 |
bool ObjectSampleWriter::operator()(StoredEdge& e) { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50113
diff
changeset
|
633 |
write(&e); |
50113 | 634 |
return true; |
635 |
} |