author | mgronlun |
Sat, 14 Sep 2019 14:40:09 +0200 | |
changeset 58132 | caa25ab47aca |
parent 58003 | a645b2f7bece |
child 58157 | 9dca61a7df19 |
child 58679 | 9c3209ff7550 |
child 58786 | 7909763ad193 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
52212
diff
changeset
|
2 |
* Copyright (c) 2016, 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" |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
26 |
#include "jfr/jfr.hpp" |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
27 |
#include "jfr/leakprofiler/leakProfiler.hpp" |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
28 |
#include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp" |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
29 |
#include "jfr/metadata/jfrSerializer.hpp" |
50113 | 30 |
#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
31 |
#include "jfr/recorder/checkpoint/types/jfrType.hpp" |
|
32 |
#include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp" |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
33 |
#include "jfr/utilities/jfrDoublyLinkedList.hpp" |
50113 | 34 |
#include "jfr/utilities/jfrIterator.hpp" |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
35 |
#include "memory/resourceArea.hpp" |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
36 |
#include "runtime/handles.inline.hpp" |
50113 | 37 |
#include "runtime/safepoint.hpp" |
38 |
#include "runtime/thread.inline.hpp" |
|
39 |
#include "utilities/exceptions.hpp" |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
40 |
#include "runtime/semaphore.hpp" |
50113 | 41 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
42 |
class JfrSerializerRegistration : public JfrCHeapObj { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
43 |
private: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
44 |
JfrSerializerRegistration* _next; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
45 |
JfrSerializerRegistration* _prev; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
46 |
JfrSerializer* _serializer; |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
47 |
mutable JfrBlobHandle _cache; |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
48 |
JfrTypeId _id; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
49 |
bool _permit_cache; |
50113 | 50 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
51 |
public: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
52 |
JfrSerializerRegistration(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) : |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
53 |
_next(NULL), _prev(NULL), _serializer(serializer), _cache(), _id(id), _permit_cache(permit_cache) {} |
50113 | 54 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
55 |
~JfrSerializerRegistration() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
56 |
delete _serializer; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
57 |
} |
50113 | 58 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
59 |
JfrSerializerRegistration* next() const { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
60 |
return _next; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
61 |
} |
50113 | 62 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
63 |
void set_next(JfrSerializerRegistration* next) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
64 |
_next = next; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
65 |
} |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
66 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
67 |
JfrSerializerRegistration* prev() const { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
68 |
return _prev; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
69 |
} |
50113 | 70 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
71 |
void set_prev(JfrSerializerRegistration* prev) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
72 |
_prev = prev; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
73 |
} |
50113 | 74 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
75 |
JfrTypeId id() const { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
76 |
return _id; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
77 |
} |
50113 | 78 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
79 |
void invoke(JfrCheckpointWriter& writer) const; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
80 |
}; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
81 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
82 |
void JfrSerializerRegistration::invoke(JfrCheckpointWriter& writer) const { |
50113 | 83 |
if (_cache.valid()) { |
84 |
writer.increment(); |
|
85 |
_cache->write(writer); |
|
86 |
return; |
|
87 |
} |
|
88 |
const JfrCheckpointContext ctx = writer.context(); |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
89 |
// serialize the type id before invoking callback |
50113 | 90 |
writer.write_type(_id); |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
91 |
const intptr_t start = writer.current_offset(); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
92 |
// invoke the serializer routine |
50113 | 93 |
_serializer->serialize(writer); |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
94 |
if (start == writer.current_offset() ) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
95 |
// the serializer implementation did nothing, rewind to restore |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
96 |
writer.set_context(ctx); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
97 |
return; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
98 |
} |
50113 | 99 |
if (_permit_cache) { |
100 |
_cache = writer.copy(&ctx); |
|
101 |
} |
|
102 |
} |
|
103 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
104 |
class SerializerRegistrationGuard : public StackObj { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
105 |
private: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
106 |
static Semaphore _mutex_semaphore; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
107 |
public: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
108 |
SerializerRegistrationGuard() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
109 |
_mutex_semaphore.wait(); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
110 |
} |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
111 |
~SerializerRegistrationGuard() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
112 |
_mutex_semaphore.signal(); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
113 |
} |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
114 |
}; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
115 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
116 |
Semaphore SerializerRegistrationGuard::_mutex_semaphore(1); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
117 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
118 |
typedef JfrDoublyLinkedList<JfrSerializerRegistration> List; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
119 |
typedef StopOnNullIterator<const List> Iterator; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
120 |
static List types; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
121 |
static List safepoint_types; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
122 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
123 |
void JfrTypeManager::clear() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
124 |
SerializerRegistrationGuard guard; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
125 |
Iterator iter(types); |
50113 | 126 |
JfrSerializerRegistration* registration; |
127 |
while (iter.has_next()) { |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
128 |
registration = types.remove(iter.next()); |
50113 | 129 |
assert(registration != NULL, "invariant"); |
130 |
delete registration; |
|
131 |
} |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
132 |
Iterator sp_type_iter(safepoint_types); |
50113 | 133 |
while (sp_type_iter.has_next()) { |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
134 |
registration = safepoint_types.remove(sp_type_iter.next()); |
50113 | 135 |
assert(registration != NULL, "invariant"); |
136 |
delete registration; |
|
137 |
} |
|
138 |
} |
|
139 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
140 |
void JfrTypeManager::write_types(JfrCheckpointWriter& writer) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
141 |
const Iterator iter(types); |
50113 | 142 |
while (iter.has_next()) { |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
143 |
iter.next()->invoke(writer); |
50113 | 144 |
} |
145 |
} |
|
146 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
147 |
void JfrTypeManager::write_safepoint_types(JfrCheckpointWriter& writer) { |
50113 | 148 |
assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
149 |
const Iterator iter(safepoint_types); |
50113 | 150 |
while (iter.has_next()) { |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
151 |
iter.next()->invoke(writer); |
50113 | 152 |
} |
153 |
} |
|
154 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
155 |
void JfrTypeManager::write_type_set() { |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
156 |
assert(!SafepointSynchronize::is_at_safepoint(), "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
157 |
// can safepoint here |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
158 |
MutexLocker cld_lock(ClassLoaderDataGraph_lock); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
159 |
MutexLocker module_lock(Module_lock); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
160 |
if (!LeakProfiler::is_running()) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
161 |
JfrCheckpointWriter writer(true, true, Thread::current()); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
162 |
TypeSet set; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
163 |
set.serialize(writer); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
164 |
return; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
165 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
166 |
JfrCheckpointWriter leakp_writer(false, true, Thread::current()); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
167 |
JfrCheckpointWriter writer(false, true, Thread::current()); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
168 |
TypeSet set(&leakp_writer); |
50113 | 169 |
set.serialize(writer); |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
170 |
ObjectSampleCheckpoint::on_type_set(leakp_writer); |
50113 | 171 |
} |
172 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
173 |
void JfrTypeManager::write_type_set_for_unloaded_classes() { |
52212
e6973df15152
8212663: Remove conservative at_safepoint assert when JFR writes type sets during class unloading
eosterlund
parents:
51608
diff
changeset
|
174 |
assert_locked_or_safepoint(ClassLoaderDataGraph_lock); |
50113 | 175 |
JfrCheckpointWriter writer(false, true, Thread::current()); |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
176 |
const JfrCheckpointContext ctx = writer.context(); |
50113 | 177 |
ClassUnloadTypeSet class_unload_set; |
178 |
class_unload_set.serialize(writer); |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
179 |
if (LeakProfiler::is_running()) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
180 |
ObjectSampleCheckpoint::on_type_set_unload(writer); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
181 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
182 |
if (!Jfr::is_recording()) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
183 |
// discard anything written |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
184 |
writer.set_context(ctx); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
185 |
} |
50113 | 186 |
} |
187 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
188 |
void JfrTypeManager::create_thread_blob(JavaThread* jt) { |
50113 | 189 |
assert(jt != NULL, "invariant"); |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
190 |
ResourceMark rm(jt); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
191 |
HandleMark hm(jt); |
50113 | 192 |
JfrThreadConstant type_thread(jt); |
193 |
JfrCheckpointWriter writer(false, true, jt); |
|
194 |
writer.write_type(TYPE_THREAD); |
|
195 |
type_thread.serialize(writer); |
|
196 |
// create and install a checkpoint blob |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
197 |
jt->jfr_thread_local()->set_thread_blob(writer.move()); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
198 |
assert(jt->jfr_thread_local()->has_thread_blob(), "invariant"); |
50113 | 199 |
} |
200 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
201 |
void JfrTypeManager::write_thread_checkpoint(JavaThread* jt) { |
50113 | 202 |
assert(jt != NULL, "JavaThread is NULL!"); |
203 |
ResourceMark rm(jt); |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
204 |
HandleMark hm(jt); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
205 |
JfrThreadConstant type_thread(jt); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
206 |
JfrCheckpointWriter writer(false, true, jt); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
207 |
writer.write_type(TYPE_THREAD); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
208 |
type_thread.serialize(writer); |
50113 | 209 |
} |
210 |
||
211 |
#ifdef ASSERT |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
212 |
static void assert_not_registered_twice(JfrTypeId id, List& list) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
213 |
const Iterator iter(list); |
50113 | 214 |
while (iter.has_next()) { |
215 |
assert(iter.next()->id() != id, "invariant"); |
|
216 |
} |
|
217 |
} |
|
218 |
#endif |
|
219 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
220 |
static bool register_type(JfrTypeId id, bool require_safepoint, bool permit_cache, JfrSerializer* serializer) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
221 |
assert(serializer != NULL, "invariant"); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
222 |
JfrSerializerRegistration* const registration = new JfrSerializerRegistration(id, permit_cache, serializer); |
50113 | 223 |
if (registration == NULL) { |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
224 |
delete serializer; |
50113 | 225 |
return false; |
226 |
} |
|
227 |
if (require_safepoint) { |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
228 |
assert(!safepoint_types.in_list(registration), "invariant"); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
229 |
DEBUG_ONLY(assert_not_registered_twice(id, safepoint_types);) |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
230 |
safepoint_types.prepend(registration); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
231 |
} else { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
232 |
assert(!types.in_list(registration), "invariant"); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
233 |
DEBUG_ONLY(assert_not_registered_twice(id, types);) |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
234 |
types.prepend(registration); |
50113 | 235 |
} |
236 |
return true; |
|
237 |
} |
|
238 |
||
239 |
bool JfrTypeManager::initialize() { |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
240 |
SerializerRegistrationGuard guard; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
241 |
|
50113 | 242 |
// register non-safepointing type serialization |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
243 |
register_type(TYPE_FLAGVALUEORIGIN, false, true, new FlagValueOriginConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
244 |
register_type(TYPE_INFLATECAUSE, false, true, new MonitorInflateCauseConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
245 |
register_type(TYPE_GCCAUSE, false, true, new GCCauseConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
246 |
register_type(TYPE_GCNAME, false, true, new GCNameConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
247 |
register_type(TYPE_GCWHEN, false, true, new GCWhenConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
248 |
register_type(TYPE_GCTHRESHOLDUPDATER, false, true, new GCThresholdUpdaterConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
249 |
register_type(TYPE_METADATATYPE, false, true, new MetadataTypeConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
250 |
register_type(TYPE_METASPACEOBJECTTYPE, false, true, new MetaspaceObjectTypeConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
251 |
register_type(TYPE_REFERENCETYPE, false, true, new ReferenceTypeConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
252 |
register_type(TYPE_NARROWOOPMODE, false, true, new NarrowOopModeConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
253 |
register_type(TYPE_COMPILERPHASETYPE, false, true, new CompilerPhaseTypeConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
254 |
register_type(TYPE_CODEBLOBTYPE, false, true, new CodeBlobTypeConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
255 |
register_type(TYPE_VMOPERATIONTYPE, false, true, new VMOperationTypeConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
256 |
register_type(TYPE_THREADSTATE, false, true, new ThreadStateConstant()); |
50113 | 257 |
|
258 |
// register safepointing type serialization |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
259 |
register_type(TYPE_THREADGROUP, true, false, new JfrThreadGroupConstant()); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
260 |
register_type(TYPE_THREAD, true, false, new JfrThreadConstantSet()); |
50113 | 261 |
return true; |
262 |
} |
|
263 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
264 |
// implementation for the static registration function exposed in the JfrSerializer api |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
265 |
bool JfrSerializer::register_serializer(JfrTypeId id, bool require_safepoint, bool permit_cache, JfrSerializer* serializer) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
266 |
SerializerRegistrationGuard guard; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
267 |
return register_type(id, require_safepoint, permit_cache, serializer); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
268 |
} |