This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
jfrType.cpp
304 lines (277 loc) · 10.4 KB
/
jfrType.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "classfile/javaClasses.inline.hpp"
#include "code/codeBlob.hpp"
#include "code/codeCache.hpp"
#include "compiler/compilerDefinitions.hpp"
#include "gc/shared/gcCause.hpp"
#include "gc/shared/gcName.hpp"
#include "gc/shared/gcTrace.hpp"
#include "gc/shared/gcWhen.hpp"
#include "jfr/leakprofiler/leakProfiler.hpp"
#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
#include "jfr/recorder/checkpoint/types/jfrType.hpp"
#include "jfr/recorder/jfrRecorder.hpp"
#include "jfr/recorder/checkpoint/types/jfrThreadGroup.hpp"
#include "jfr/recorder/checkpoint/types/jfrThreadState.hpp"
#include "jfr/support/jfrThreadLocal.hpp"
#include "jfr/writers/jfrJavaEventWriter.hpp"
#include "jfr/utilities/jfrThreadIterator.hpp"
#include "memory/iterator.hpp"
#include "memory/metaspaceGCThresholdUpdater.hpp"
#include "memory/referenceType.hpp"
#include "memory/universe.hpp"
#include "oops/compressedOops.hpp"
#include "runtime/flags/jvmFlag.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/osThread.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/synchronizer.hpp"
#include "runtime/thread.inline.hpp"
#include "runtime/vmOperations.hpp"
#ifdef COMPILER2
#include "opto/compile.hpp"
#include "opto/node.hpp"
#endif
// Requires a ResourceMark for get_thread_name/as_utf8
class JfrCheckpointThreadClosure : public ThreadClosure {
private:
JfrCheckpointWriter& _writer;
JfrCheckpointContext _ctx;
const int64_t _count_position;
Thread* const _curthread;
u4 _count;
public:
JfrCheckpointThreadClosure(JfrCheckpointWriter& writer) : _writer(writer),
_ctx(writer.context()),
_count_position(writer.reserve(sizeof(u4))),
_curthread(Thread::current()),
_count(0) {
}
~JfrCheckpointThreadClosure() {
if (_count == 0) {
// restore
_writer.set_context(_ctx);
return;
}
_writer.write_count(_count, _count_position);
}
void do_thread(Thread* t);
};
void JfrCheckpointThreadClosure::do_thread(Thread* t) {
assert(t != NULL, "invariant");
++_count;
_writer.write_key(JfrThreadId::jfr_id(t));
const char* const name = JfrThreadName::name(t);
assert(name != NULL, "invariant");
_writer.write(name);
_writer.write<traceid>(JfrThreadId::os_id(t));
if (t->is_Java_thread()) {
_writer.write(name);
_writer.write(JfrThreadId::id(t));
_writer.write(JfrThreadGroup::thread_group_id((JavaThread*)t, _curthread));
return;
}
_writer.write((const char*)NULL); // java name
_writer.write((traceid)0); // java thread id
_writer.write((traceid)0); // java thread group
}
void JfrThreadConstantSet::serialize(JfrCheckpointWriter& writer) {
JfrCheckpointThreadClosure tc(writer);
JfrJavaThreadIterator javathreads(false); // include not yet live threads (_thread_new)
while (javathreads.has_next()) {
tc.do_thread(javathreads.next());
}
JfrNonJavaThreadIterator nonjavathreads;
while (nonjavathreads.has_next()) {
tc.do_thread(nonjavathreads.next());
}
}
void JfrThreadGroupConstant::serialize(JfrCheckpointWriter& writer) {
JfrThreadGroup::serialize(writer);
}
static const char* flag_value_origin_to_string(JVMFlag::Flags origin) {
switch (origin) {
case JVMFlag::DEFAULT: return "Default";
case JVMFlag::COMMAND_LINE: return "Command line";
case JVMFlag::ENVIRON_VAR: return "Environment variable";
case JVMFlag::CONFIG_FILE: return "Config file";
case JVMFlag::MANAGEMENT: return "Management";
case JVMFlag::ERGONOMIC: return "Ergonomic";
case JVMFlag::ATTACH_ON_DEMAND: return "Attach on demand";
case JVMFlag::INTERNAL: return "Internal";
case JVMFlag::JIMAGE_RESOURCE: return "JImage resource";
default: ShouldNotReachHere(); return "";
}
}
void FlagValueOriginConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = JVMFlag::LAST_VALUE_ORIGIN + 1;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(flag_value_origin_to_string((JVMFlag::Flags)i));
}
}
void MonitorInflateCauseConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = ObjectSynchronizer::inflate_cause_nof;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(ObjectSynchronizer::inflate_cause_name((ObjectSynchronizer::InflateCause)i));
}
}
void GCCauseConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = GCCause::_last_gc_cause;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(GCCause::to_string((GCCause::Cause)i));
}
}
void GCNameConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = GCNameEndSentinel;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(GCNameHelper::to_string((GCName)i));
}
}
void GCWhenConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = GCWhen::GCWhenEndSentinel;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(GCWhen::to_string((GCWhen::Type)i));
}
}
void GCThresholdUpdaterConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = MetaspaceGCThresholdUpdater::Last;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(MetaspaceGCThresholdUpdater::to_string((MetaspaceGCThresholdUpdater::Type)i));
}
}
void MetadataTypeConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = Metaspace::MetadataTypeCount;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(Metaspace::metadata_type_name((Metaspace::MetadataType)i));
}
}
void MetaspaceObjectTypeConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = MetaspaceObj::_number_of_types;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(MetaspaceObj::type_name((MetaspaceObj::Type)i));
}
}
static const char* reference_type_to_string(ReferenceType rt) {
switch (rt) {
case REF_NONE: return "None reference";
case REF_OTHER: return "Other reference";
case REF_SOFT: return "Soft reference";
case REF_WEAK: return "Weak reference";
case REF_FINAL: return "Final reference";
case REF_PHANTOM: return "Phantom reference";
default:
ShouldNotReachHere();
return NULL;
}
}
void ReferenceTypeConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = REF_PHANTOM + 1;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(reference_type_to_string((ReferenceType)i));
}
}
void NarrowOopModeConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = CompressedOops::HeapBasedNarrowOop + 1;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(CompressedOops::mode_to_string((CompressedOops::Mode)i));
}
}
void CodeBlobTypeConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = CodeBlobType::NumTypes;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(CodeCache::get_code_heap_name(i));
}
};
void VMOperationTypeConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = VM_Operation::VMOp_Terminating;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(VM_Operation::name(VM_Operation::VMOp_Type(i)));
}
}
void ThreadStateConstant::serialize(JfrCheckpointWriter& writer) {
JfrThreadState::serialize(writer);
}
void JfrThreadConstant::serialize(JfrCheckpointWriter& writer) {
assert(_thread != NULL, "invariant");
assert(_thread == Thread::current(), "invariant");
writer.write_count(1);
writer.write_key(JfrThreadId::jfr_id(_thread));
const char* const name = JfrThreadName::name(_thread);
writer.write(name);
writer.write(JfrThreadId::os_id(_thread));
if (_thread->is_Java_thread()) {
writer.write(name);
writer.write(JfrThreadId::id(_thread));
JavaThread* const jt = (JavaThread*)_thread;
const traceid thread_group_id = JfrThreadGroup::thread_group_id(jt, jt);
writer.write(thread_group_id);
JfrThreadGroup::serialize(&writer, thread_group_id);
return;
}
writer.write((const char*)NULL); // java name
writer.write((traceid)0); // java thread id
writer.write((traceid)0); // java thread group
}
void BytecodeConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = Bytecodes::number_of_codes;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(Bytecodes::name((Bytecodes::Code)i));
}
}
void CompilerTypeConstant::serialize(JfrCheckpointWriter& writer) {
static const u4 nof_entries = compiler_number_of_types;
writer.write_count(nof_entries);
for (u4 i = 0; i < nof_entries; ++i) {
writer.write_key(i);
writer.write(compilertype2name((CompilerType)i));
}
}