author | mgronlun |
Tue, 17 Sep 2019 13:32:27 +0200 | |
branch | JEP-349-branch |
changeset 58187 | 8994744e221c |
parent 58184 | 2bc0dc4b7119 |
child 58251 | c4067538a0f2 |
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/thread.inline.hpp" |
38 |
#include "utilities/exceptions.hpp" |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
39 |
#include "runtime/semaphore.hpp" |
50113 | 40 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
41 |
class JfrSerializerRegistration : public JfrCHeapObj { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
42 |
private: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
43 |
JfrSerializerRegistration* _next; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
44 |
JfrSerializerRegistration* _prev; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
45 |
JfrSerializer* _serializer; |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
46 |
mutable JfrBlobHandle _cache; |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
47 |
JfrTypeId _id; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
48 |
bool _permit_cache; |
50113 | 49 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
50 |
public: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
51 |
JfrSerializerRegistration(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) : |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
52 |
_next(NULL), _prev(NULL), _serializer(serializer), _cache(), _id(id), _permit_cache(permit_cache) {} |
50113 | 53 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
54 |
~JfrSerializerRegistration() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
55 |
delete _serializer; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
56 |
} |
50113 | 57 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
58 |
JfrSerializerRegistration* next() const { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
59 |
return _next; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
60 |
} |
50113 | 61 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
62 |
void set_next(JfrSerializerRegistration* next) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
63 |
_next = next; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
64 |
} |
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 |
JfrSerializerRegistration* prev() const { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
67 |
return _prev; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
68 |
} |
50113 | 69 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
70 |
void set_prev(JfrSerializerRegistration* prev) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
71 |
_prev = prev; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
72 |
} |
50113 | 73 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
74 |
JfrTypeId id() const { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
75 |
return _id; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
76 |
} |
50113 | 77 |
|
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
78 |
void on_rotation() const { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
79 |
_serializer->on_rotation(); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
80 |
} |
57360 | 81 |
|
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
82 |
void invoke(JfrCheckpointWriter& writer) const { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
83 |
if (_cache.valid()) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
84 |
writer.increment(); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
85 |
_cache->write(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
86 |
return; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
87 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
88 |
const JfrCheckpointContext ctx = writer.context(); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
89 |
// serialize the type id before invoking callback |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
90 |
writer.write_type(_id); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
91 |
const intptr_t start = writer.current_offset(); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
92 |
// invoke the serializer routine |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
93 |
_serializer->serialize(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
94 |
if (start == writer.current_offset()) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
95 |
// the serializer implementation did nothing, rewind to restore |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
96 |
writer.set_context(ctx); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
97 |
return; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
98 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
99 |
if (_permit_cache) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
100 |
_cache = writer.copy(&ctx); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
101 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
102 |
} |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
103 |
}; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
104 |
|
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
105 |
static void serialize_threads(JfrCheckpointWriter& writer) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
106 |
JfrThreadConstantSet thread_set; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
107 |
writer.write_type(TYPE_THREAD); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
108 |
thread_set.serialize(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
109 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
110 |
|
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
111 |
static void serialize_thread_groups(JfrCheckpointWriter& writer) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
112 |
JfrThreadGroupConstant thread_group_set; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
113 |
writer.write_type(TYPE_THREADGROUP); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
114 |
thread_group_set.serialize(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
115 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
116 |
|
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
117 |
void JfrTypeManager::write_threads(JfrCheckpointWriter& writer) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
118 |
serialize_threads(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
119 |
serialize_thread_groups(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
120 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
121 |
|
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
122 |
void JfrTypeManager::create_thread_blob(Thread* t) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
123 |
assert(t != NULL, "invariant"); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
124 |
ResourceMark rm(t); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
125 |
HandleMark hm(t); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
126 |
JfrThreadConstant type_thread(t); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
127 |
JfrCheckpointWriter writer(t, true, THREADS); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
128 |
writer.write_type(TYPE_THREAD); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
129 |
type_thread.serialize(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
130 |
// create and install a checkpoint blob |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
131 |
t->jfr_thread_local()->set_thread_blob(writer.move()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
132 |
assert(t->jfr_thread_local()->has_thread_blob(), "invariant"); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
133 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
134 |
|
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
135 |
void JfrTypeManager::write_thread_checkpoint(Thread* t) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
136 |
assert(t != NULL, "invariant"); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
137 |
ResourceMark rm(t); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
138 |
HandleMark hm(t); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
139 |
JfrThreadConstant type_thread(t); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
140 |
JfrCheckpointWriter writer(t, true, THREADS); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
141 |
writer.write_type(TYPE_THREAD); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
142 |
type_thread.serialize(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
143 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
144 |
|
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
145 |
size_t JfrTypeManager::flush_type_set() { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
146 |
JfrCheckpointWriter writer; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
147 |
FlushTypeSet flush; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
148 |
flush.serialize(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
149 |
return flush.elements(); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
150 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
151 |
|
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
152 |
void JfrTypeManager::write_type_set() { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
153 |
if (!LeakProfiler::is_running()) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
154 |
JfrCheckpointWriter writer; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
155 |
TypeSet set; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
156 |
set.serialize(writer); |
50113 | 157 |
return; |
158 |
} |
|
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
159 |
JfrCheckpointWriter leakp_writer; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
160 |
JfrCheckpointWriter writer; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
161 |
TypeSet set(&leakp_writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
162 |
set.serialize(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
163 |
ObjectSampleCheckpoint::on_type_set(leakp_writer); |
50113 | 164 |
} |
165 |
||
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
166 |
void JfrTypeManager::write_type_set_for_unloaded_classes() { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
167 |
JfrCheckpointWriter writer; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
168 |
const JfrCheckpointContext ctx = writer.context(); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
169 |
ClassUnloadTypeSet class_unload_set; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
170 |
class_unload_set.serialize(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
171 |
if (LeakProfiler::is_running()) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
172 |
ObjectSampleCheckpoint::on_type_set_unload(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
173 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
174 |
if (!Jfr::is_recording()) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
175 |
// discard anything written |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
176 |
writer.set_context(ctx); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
177 |
} |
57360 | 178 |
} |
179 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
180 |
class SerializerRegistrationGuard : public StackObj { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
181 |
private: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
182 |
static Semaphore _mutex_semaphore; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
183 |
public: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
184 |
SerializerRegistrationGuard() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
185 |
_mutex_semaphore.wait(); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
186 |
} |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
187 |
~SerializerRegistrationGuard() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
188 |
_mutex_semaphore.signal(); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
189 |
} |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
190 |
}; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
191 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
192 |
Semaphore SerializerRegistrationGuard::_mutex_semaphore(1); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
193 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
194 |
typedef JfrDoublyLinkedList<JfrSerializerRegistration> List; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
195 |
typedef StopOnNullIterator<const List> Iterator; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
196 |
static List types; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
197 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
198 |
void JfrTypeManager::clear() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
199 |
SerializerRegistrationGuard guard; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
200 |
Iterator iter(types); |
50113 | 201 |
JfrSerializerRegistration* registration; |
202 |
while (iter.has_next()) { |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
203 |
registration = types.remove(iter.next()); |
50113 | 204 |
assert(registration != NULL, "invariant"); |
205 |
delete registration; |
|
206 |
} |
|
207 |
} |
|
208 |
||
58184 | 209 |
void JfrTypeManager::on_rotation() { |
57360 | 210 |
const Iterator iter(types); |
50113 | 211 |
while (iter.has_next()) { |
57360 | 212 |
iter.next()->on_rotation(); |
50113 | 213 |
} |
214 |
} |
|
215 |
||
216 |
#ifdef ASSERT |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
217 |
static void assert_not_registered_twice(JfrTypeId id, List& list) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
218 |
const Iterator iter(list); |
50113 | 219 |
while (iter.has_next()) { |
220 |
assert(iter.next()->id() != id, "invariant"); |
|
221 |
} |
|
222 |
} |
|
223 |
#endif |
|
224 |
||
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
225 |
static bool new_registration = false; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
226 |
|
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
227 |
static bool register_static_type(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) { |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
228 |
assert(serializer != NULL, "invariant"); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
229 |
JfrSerializerRegistration* const registration = new JfrSerializerRegistration(id, permit_cache, serializer); |
50113 | 230 |
if (registration == NULL) { |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
231 |
delete serializer; |
50113 | 232 |
return false; |
233 |
} |
|
57360 | 234 |
assert(!types.in_list(registration), "invariant"); |
235 |
DEBUG_ONLY(assert_not_registered_twice(id, types);) |
|
236 |
if (Jfr::is_recording()) { |
|
57934 | 237 |
JfrCheckpointWriter writer(STATICS); |
57360 | 238 |
registration->invoke(writer); |
57934 | 239 |
new_registration = true; |
50113 | 240 |
} |
57360 | 241 |
types.prepend(registration); |
50113 | 242 |
return true; |
243 |
} |
|
244 |
||
245 |
bool JfrTypeManager::initialize() { |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
246 |
SerializerRegistrationGuard guard; |
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
247 |
register_static_type(TYPE_FLAGVALUEORIGIN, true, new FlagValueOriginConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
248 |
register_static_type(TYPE_INFLATECAUSE, true, new MonitorInflateCauseConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
249 |
register_static_type(TYPE_GCCAUSE, true, new GCCauseConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
250 |
register_static_type(TYPE_GCNAME, true, new GCNameConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
251 |
register_static_type(TYPE_GCWHEN, true, new GCWhenConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
252 |
register_static_type(TYPE_GCTHRESHOLDUPDATER, true, new GCThresholdUpdaterConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
253 |
register_static_type(TYPE_METADATATYPE, true, new MetadataTypeConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
254 |
register_static_type(TYPE_METASPACEOBJECTTYPE, true, new MetaspaceObjectTypeConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
255 |
register_static_type(TYPE_REFERENCETYPE, true, new ReferenceTypeConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
256 |
register_static_type(TYPE_NARROWOOPMODE, true, new NarrowOopModeConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
257 |
register_static_type(TYPE_COMPILERPHASETYPE, true, new CompilerPhaseTypeConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
258 |
register_static_type(TYPE_CODEBLOBTYPE, true, new CodeBlobTypeConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
259 |
register_static_type(TYPE_VMOPERATIONTYPE, true, new VMOperationTypeConstant()); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
260 |
register_static_type(TYPE_THREADSTATE, true, new ThreadStateConstant()); |
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 |
57360 | 265 |
bool JfrSerializer::register_serializer(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) { |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
266 |
SerializerRegistrationGuard guard; |
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
267 |
return register_static_type(id, permit_cache, serializer); |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
268 |
} |
57934 | 269 |
|
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
270 |
bool JfrTypeManager::has_new_static_type() { |
57934 | 271 |
if (new_registration) { |
272 |
SerializerRegistrationGuard guard; |
|
273 |
new_registration = false; |
|
274 |
return true; |
|
275 |
} |
|
276 |
return false; |
|
277 |
} |
|
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
278 |
|
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
279 |
void JfrTypeManager::write_static_types(JfrCheckpointWriter& writer) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
280 |
SerializerRegistrationGuard guard; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
281 |
const Iterator iter(types); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
282 |
while (iter.has_next()) { |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
283 |
iter.next()->invoke(writer); |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
284 |
} |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
285 |
new_registration = false; |
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
286 |
} |