/
jfrThreadLocal.hpp
237 lines (187 loc) · 5.69 KB
/
jfrThreadLocal.hpp
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
/*
* Copyright (c) 2012, 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.
*
*/
#ifndef SHARE_JFR_SUPPORT_JFRTHREADLOCAL_HPP
#define SHARE_JFR_SUPPORT_JFRTHREADLOCAL_HPP
#include "jfr/utilities/jfrBlob.hpp"
#include "jfr/utilities/jfrTypes.hpp"
class JavaThread;
class JfrBuffer;
class JfrStackFrame;
class Thread;
class JfrThreadLocal {
friend class JfrVirtualThread;
private:
jobject _java_event_writer;
mutable JfrBuffer* _java_buffer;
mutable JfrBuffer* _native_buffer;
JfrBuffer* _shelved_buffer;
mutable JfrStackFrame* _stackframes;
JfrBlobHandle _thread;
mutable traceid _static_thread_id;
mutable traceid _thread_id_limit;
mutable traceid _next_thread_id;
u8 _data_lost;
traceid _stack_trace_id;
jlong _user_time;
jlong _cpu_time;
jlong _wallclock_time;
unsigned int _stack_trace_hash;
mutable u4 _stackdepth;
volatile jint _entering_suspend_flag;
bool _excluded;
bool _dead;
JfrBuffer* install_native_buffer() const;
JfrBuffer* install_java_buffer() const;
JfrStackFrame* install_stackframes() const;
void release(Thread* t);
static void release(JfrThreadLocal* tl, Thread* t);
static traceid reinitialize_thread_local_ids(const JfrThreadLocal* tl);
traceid next_thread_local_id() const;
public:
JfrThreadLocal();
JfrBuffer* native_buffer() const {
return _native_buffer != NULL ? _native_buffer : install_native_buffer();
}
bool has_native_buffer() const {
return _native_buffer != NULL;
}
void set_native_buffer(JfrBuffer* buffer) {
_native_buffer = buffer;
}
JfrBuffer* java_buffer() const {
return _java_buffer != NULL ? _java_buffer : install_java_buffer();
}
bool has_java_buffer() const {
return _java_buffer != NULL;
}
void set_java_buffer(JfrBuffer* buffer) {
_java_buffer = buffer;
}
JfrBuffer* shelved_buffer() const {
return _shelved_buffer;
}
void shelve_buffer(JfrBuffer* buffer) {
_shelved_buffer = buffer;
}
bool has_java_event_writer() const {
return _java_event_writer != NULL;
}
jobject java_event_writer() {
return _java_event_writer;
}
void set_java_event_writer(jobject java_event_writer) {
_java_event_writer = java_event_writer;
}
JfrStackFrame* stackframes() const {
return _stackframes != NULL ? _stackframes : install_stackframes();
}
void set_stackframes(JfrStackFrame* frames) {
_stackframes = frames;
}
u4 stackdepth() const;
void set_stackdepth(u4 depth) {
_stackdepth = depth;
}
// runtime determined id (VirtualThreads etc)
static traceid thread_id(const Thread* t);
// statically determined id for real HW thread
static traceid static_thread_id(const Thread* t);
static void set_static_thread_id(const Thread* t, traceid thread_id);
void set_cached_stack_trace_id(traceid id, unsigned int hash = 0) {
_stack_trace_id = id;
_stack_trace_hash = hash;
}
bool has_cached_stack_trace() const {
return _stack_trace_id != max_julong;
}
void clear_cached_stack_trace() {
_stack_trace_id = max_julong;
_stack_trace_hash = 0;
}
traceid cached_stack_trace_id() const {
return _stack_trace_id;
}
unsigned int cached_stack_trace_hash() const {
return _stack_trace_hash;
}
void set_trace_block() {
_entering_suspend_flag = 1;
}
void clear_trace_block() {
_entering_suspend_flag = 0;
}
bool is_trace_block() const {
return _entering_suspend_flag != 0;
}
u8 data_lost() const {
return _data_lost;
}
u8 add_data_lost(u8 value);
jlong get_user_time() const {
return _user_time;
}
void set_user_time(jlong user_time) {
_user_time = user_time;
}
jlong get_cpu_time() const {
return _cpu_time;
}
void set_cpu_time(jlong cpu_time) {
_cpu_time = cpu_time;
}
jlong get_wallclock_time() const {
return _wallclock_time;
}
void set_wallclock_time(jlong wallclock_time) {
_wallclock_time = wallclock_time;
}
traceid trace_id() const {
return _static_thread_id;
}
traceid* const trace_id_addr() const {
return &_static_thread_id;
}
void set_trace_id(traceid id) const {
_static_thread_id = id;
}
bool is_excluded() const {
return _excluded;
}
bool is_dead() const {
return _dead;
}
bool has_thread_blob() const;
void set_thread_blob(const JfrBlobHandle& handle);
const JfrBlobHandle& thread_blob() const;
static void exclude(Thread* t);
static void include(Thread* t);
static void on_start(Thread* t);
static void on_vthread_start(JavaThread* jt, jobject vthread);
static void on_exit(Thread* t);
static void on_vthread_exit(JavaThread* jt, jobject vthread);
// Code generation
static ByteSize trace_id_offset();
static ByteSize java_event_writer_offset();
};
#endif // SHARE_JFR_SUPPORT_JFRTHREADLOCAL_HPP