author | mgronlun |
Wed, 30 Oct 2019 19:43:52 +0100 | |
changeset 58863 | c16ac7a2eba4 |
parent 58132 | caa25ab47aca |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
58084
cddef3bde924
8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents:
55571
diff
changeset
|
2 |
* Copyright (c) 2012, 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" |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
26 |
#include "jfr/jfrEvents.hpp" |
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
27 |
#include "jfr/jni/jfrJavaSupport.hpp" |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
28 |
#include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp" |
50113 | 29 |
#include "jfr/periodic/jfrThreadCPULoadEvent.hpp" |
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
30 |
#include "jfr/recorder/jfrRecorder.hpp" |
50113 | 31 |
#include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
32 |
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" |
|
33 |
#include "jfr/recorder/service/jfrOptionSet.hpp" |
|
34 |
#include "jfr/recorder/storage/jfrStorage.hpp" |
|
35 |
#include "jfr/support/jfrThreadLocal.hpp" |
|
36 |
#include "memory/allocation.inline.hpp" |
|
37 |
#include "runtime/os.hpp" |
|
38 |
#include "runtime/thread.inline.hpp" |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
39 |
#include "utilities/sizes.hpp" |
50113 | 40 |
|
41 |
/* This data structure is per thread and only accessed by the thread itself, no locking required */ |
|
42 |
JfrThreadLocal::JfrThreadLocal() : |
|
43 |
_java_event_writer(NULL), |
|
44 |
_java_buffer(NULL), |
|
45 |
_native_buffer(NULL), |
|
46 |
_shelved_buffer(NULL), |
|
47 |
_stackframes(NULL), |
|
48 |
_trace_id(JfrTraceId::assign_thread_id()), |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
49 |
_thread(), |
50113 | 50 |
_data_lost(0), |
51 |
_stack_trace_id(max_julong), |
|
52 |
_user_time(0), |
|
53 |
_cpu_time(0), |
|
54 |
_wallclock_time(os::javaTimeNanos()), |
|
55 |
_stack_trace_hash(0), |
|
56 |
_stackdepth(0), |
|
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
57 |
_entering_suspend_flag(0), |
58863 | 58 |
_excluded(false), |
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
59 |
_dead(false) {} |
50113 | 60 |
|
61 |
u8 JfrThreadLocal::add_data_lost(u8 value) { |
|
62 |
_data_lost += value; |
|
63 |
return _data_lost; |
|
64 |
} |
|
65 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
66 |
bool JfrThreadLocal::has_thread_blob() const { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
67 |
return _thread.valid(); |
50113 | 68 |
} |
69 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
70 |
void JfrThreadLocal::set_thread_blob(const JfrBlobHandle& ref) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
71 |
assert(!_thread.valid(), "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
72 |
_thread = ref; |
50113 | 73 |
} |
74 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
75 |
const JfrBlobHandle& JfrThreadLocal::thread_blob() const { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
76 |
return _thread; |
50113 | 77 |
} |
78 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
79 |
static void send_java_thread_start_event(JavaThread* jt) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
80 |
EventThreadStart event; |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
81 |
event.set_thread(jt->jfr_thread_local()->thread_id()); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
82 |
event.commit(); |
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
83 |
} |
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
84 |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
85 |
void JfrThreadLocal::on_start(Thread* t) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
86 |
assert(t != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
87 |
assert(Thread::current() == t, "invariant"); |
58863 | 88 |
JfrJavaSupport::on_thread_start(t); |
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
89 |
if (JfrRecorder::is_recording()) { |
58863 | 90 |
if (!t->jfr_thread_local()->is_excluded()) { |
91 |
JfrCheckpointManager::write_thread_checkpoint(t); |
|
92 |
if (t->is_Java_thread()) { |
|
93 |
send_java_thread_start_event((JavaThread*)t); |
|
94 |
} |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
95 |
} |
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
96 |
} |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
97 |
} |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
98 |
|
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
99 |
static void send_java_thread_end_events(traceid id, JavaThread* jt) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
100 |
assert(jt != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
101 |
assert(Thread::current() == jt, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
102 |
assert(jt->jfr_thread_local()->trace_id() == id, "invariant"); |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
103 |
if (JfrRecorder::is_recording()) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
104 |
EventThreadEnd event; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
105 |
event.set_thread(id); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
106 |
event.commit(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
107 |
JfrThreadCPULoadEvent::send_event_for_thread(jt); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
108 |
} |
50113 | 109 |
} |
110 |
||
58863 | 111 |
void JfrThreadLocal::release(Thread* t) { |
112 |
if (has_java_event_writer()) { |
|
113 |
assert(t->is_Java_thread(), "invariant"); |
|
114 |
JfrJavaSupport::destroy_global_jni_handle(java_event_writer()); |
|
115 |
_java_event_writer = NULL; |
|
116 |
} |
|
117 |
if (has_native_buffer()) { |
|
118 |
JfrStorage::release_thread_local(native_buffer(), t); |
|
119 |
_native_buffer = NULL; |
|
120 |
} |
|
121 |
if (has_java_buffer()) { |
|
122 |
JfrStorage::release_thread_local(java_buffer(), t); |
|
123 |
_java_buffer = NULL; |
|
124 |
} |
|
125 |
if (_stackframes != NULL) { |
|
126 |
FREE_C_HEAP_ARRAY(JfrStackFrame, _stackframes); |
|
127 |
_stackframes = NULL; |
|
128 |
} |
|
129 |
} |
|
130 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
131 |
void JfrThreadLocal::release(JfrThreadLocal* tl, Thread* t) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
132 |
assert(tl != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
133 |
assert(t != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
134 |
assert(Thread::current() == t, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
135 |
assert(!tl->is_dead(), "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
136 |
assert(tl->shelved_buffer() == NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
137 |
tl->_dead = true; |
58863 | 138 |
tl->release(t); |
50113 | 139 |
} |
140 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
141 |
void JfrThreadLocal::on_exit(Thread* t) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
142 |
assert(t != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
143 |
JfrThreadLocal * const tl = t->jfr_thread_local(); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
144 |
assert(!tl->is_dead(), "invariant"); |
58863 | 145 |
if (JfrRecorder::is_recording()) { |
146 |
if (t->is_Java_thread()) { |
|
147 |
JavaThread* const jt = (JavaThread*)t; |
|
148 |
ObjectSampleCheckpoint::on_thread_exit(jt); |
|
149 |
send_java_thread_end_events(tl->thread_id(), jt); |
|
150 |
} |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
151 |
} |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
152 |
release(tl, Thread::current()); // because it could be that Thread::current() != t |
50113 | 153 |
} |
154 |
||
58863 | 155 |
static JfrBuffer* acquire_buffer(bool excluded) { |
156 |
JfrBuffer* const buffer = JfrStorage::acquire_thread_local(Thread::current()); |
|
157 |
if (buffer != NULL && excluded) { |
|
158 |
buffer->set_excluded(); |
|
159 |
} |
|
160 |
return buffer; |
|
161 |
} |
|
162 |
||
50113 | 163 |
JfrBuffer* JfrThreadLocal::install_native_buffer() const { |
164 |
assert(!has_native_buffer(), "invariant"); |
|
58863 | 165 |
_native_buffer = acquire_buffer(_excluded); |
50113 | 166 |
return _native_buffer; |
167 |
} |
|
168 |
||
169 |
JfrBuffer* JfrThreadLocal::install_java_buffer() const { |
|
170 |
assert(!has_java_buffer(), "invariant"); |
|
171 |
assert(!has_java_event_writer(), "invariant"); |
|
58863 | 172 |
_java_buffer = acquire_buffer(_excluded); |
50113 | 173 |
return _java_buffer; |
174 |
} |
|
175 |
||
176 |
JfrStackFrame* JfrThreadLocal::install_stackframes() const { |
|
177 |
assert(_stackframes == NULL, "invariant"); |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
178 |
_stackframes = NEW_C_HEAP_ARRAY(JfrStackFrame, stackdepth(), mtTracing); |
50113 | 179 |
return _stackframes; |
180 |
} |
|
181 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
182 |
ByteSize JfrThreadLocal::trace_id_offset() { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
183 |
return in_ByteSize(offset_of(JfrThreadLocal, _trace_id)); |
50113 | 184 |
} |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
185 |
|
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
186 |
ByteSize JfrThreadLocal::java_event_writer_offset() { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
187 |
return in_ByteSize(offset_of(JfrThreadLocal, _java_event_writer)); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
188 |
} |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
189 |
|
58863 | 190 |
void JfrThreadLocal::exclude(Thread* t) { |
191 |
assert(t != NULL, "invariant"); |
|
192 |
t->jfr_thread_local()->_excluded = true; |
|
193 |
t->jfr_thread_local()->release(t); |
|
194 |
} |
|
195 |
||
196 |
void JfrThreadLocal::include(Thread* t) { |
|
197 |
assert(t != NULL, "invariant"); |
|
198 |
t->jfr_thread_local()->_excluded = false; |
|
199 |
t->jfr_thread_local()->release(t); |
|
200 |
} |
|
201 |
||
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
202 |
u4 JfrThreadLocal::stackdepth() const { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
203 |
return _stackdepth != 0 ? _stackdepth : (u4)JfrOptionSet::stackdepth(); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
204 |
} |