author | mgronlun |
Sat, 14 Sep 2019 14:40:09 +0200 | |
changeset 58132 | caa25ab47aca |
parent 58084 | cddef3bde924 |
child 58157 | 9dca61a7df19 |
child 58679 | 9c3209ff7550 |
child 58863 | c16ac7a2eba4 |
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), |
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
58 |
_dead(false) {} |
50113 | 59 |
|
60 |
u8 JfrThreadLocal::add_data_lost(u8 value) { |
|
61 |
_data_lost += value; |
|
62 |
return _data_lost; |
|
63 |
} |
|
64 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
65 |
bool JfrThreadLocal::has_thread_blob() const { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
66 |
return _thread.valid(); |
50113 | 67 |
} |
68 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
69 |
void JfrThreadLocal::set_thread_blob(const JfrBlobHandle& ref) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
70 |
assert(!_thread.valid(), "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
71 |
_thread = ref; |
50113 | 72 |
} |
73 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
74 |
const JfrBlobHandle& JfrThreadLocal::thread_blob() const { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
75 |
return _thread; |
50113 | 76 |
} |
77 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
78 |
static void send_java_thread_start_event(JavaThread* jt) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
79 |
EventThreadStart event; |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
80 |
event.set_thread(jt->jfr_thread_local()->thread_id()); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
81 |
event.commit(); |
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
82 |
} |
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
83 |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
84 |
void JfrThreadLocal::on_start(Thread* t) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
85 |
assert(t != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
86 |
assert(Thread::current() == t, "invariant"); |
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
87 |
if (JfrRecorder::is_recording()) { |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
88 |
if (t->is_Java_thread()) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
89 |
send_java_thread_start_event((JavaThread*)t); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
90 |
} |
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
91 |
} |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
92 |
} |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
93 |
|
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
94 |
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
|
95 |
assert(jt != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
96 |
assert(Thread::current() == jt, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
97 |
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
|
98 |
if (JfrRecorder::is_recording()) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
99 |
EventThreadEnd event; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
100 |
event.set_thread(id); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
101 |
event.commit(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
102 |
JfrThreadCPULoadEvent::send_event_for_thread(jt); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
103 |
} |
50113 | 104 |
} |
105 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
106 |
void JfrThreadLocal::release(JfrThreadLocal* tl, Thread* t) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
107 |
assert(tl != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
108 |
assert(t != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
109 |
assert(Thread::current() == t, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
110 |
assert(!tl->is_dead(), "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
111 |
assert(tl->shelved_buffer() == NULL, "invariant"); |
50113 | 112 |
if (tl->has_native_buffer()) { |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
113 |
JfrStorage::release_thread_local(tl->native_buffer(), t); |
50113 | 114 |
} |
115 |
if (tl->has_java_buffer()) { |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
116 |
JfrStorage::release_thread_local(tl->java_buffer(), t); |
50113 | 117 |
} |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
118 |
if (tl->has_java_event_writer()) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
119 |
assert(t->is_Java_thread(), "invariant"); |
50113 | 120 |
JfrJavaSupport::destroy_global_jni_handle(tl->java_event_writer()); |
121 |
} |
|
58084
cddef3bde924
8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents:
55571
diff
changeset
|
122 |
FREE_C_HEAP_ARRAY(JfrStackFrame, tl->_stackframes); |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
123 |
tl->_dead = true; |
50113 | 124 |
} |
125 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
126 |
void JfrThreadLocal::on_exit(Thread* t) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
127 |
assert(t != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
128 |
JfrThreadLocal * const tl = t->jfr_thread_local(); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
129 |
assert(!tl->is_dead(), "invariant"); |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
130 |
if (t->is_Java_thread()) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
131 |
JavaThread* const jt = (JavaThread*)t; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
132 |
ObjectSampleCheckpoint::on_thread_exit(jt); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58084
diff
changeset
|
133 |
send_java_thread_end_events(tl->thread_id(), jt); |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
134 |
} |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
135 |
release(tl, Thread::current()); // because it could be that Thread::current() != t |
50113 | 136 |
} |
137 |
||
138 |
JfrBuffer* JfrThreadLocal::install_native_buffer() const { |
|
139 |
assert(!has_native_buffer(), "invariant"); |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
140 |
_native_buffer = JfrStorage::acquire_thread_local(Thread::current()); |
50113 | 141 |
return _native_buffer; |
142 |
} |
|
143 |
||
144 |
JfrBuffer* JfrThreadLocal::install_java_buffer() const { |
|
145 |
assert(!has_java_buffer(), "invariant"); |
|
146 |
assert(!has_java_event_writer(), "invariant"); |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
147 |
_java_buffer = JfrStorage::acquire_thread_local(Thread::current()); |
50113 | 148 |
return _java_buffer; |
149 |
} |
|
150 |
||
151 |
JfrStackFrame* JfrThreadLocal::install_stackframes() const { |
|
152 |
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
|
153 |
_stackframes = NEW_C_HEAP_ARRAY(JfrStackFrame, stackdepth(), mtTracing); |
50113 | 154 |
return _stackframes; |
155 |
} |
|
156 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
157 |
ByteSize JfrThreadLocal::trace_id_offset() { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
158 |
return in_ByteSize(offset_of(JfrThreadLocal, _trace_id)); |
50113 | 159 |
} |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
160 |
|
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
161 |
ByteSize JfrThreadLocal::java_event_writer_offset() { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
162 |
return in_ByteSize(offset_of(JfrThreadLocal, _java_event_writer)); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
163 |
} |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
164 |
|
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
165 |
u4 JfrThreadLocal::stackdepth() const { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
166 |
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
|
167 |
} |