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