author | lkorinth |
Wed, 11 Sep 2019 14:16:30 +0200 | |
changeset 58084 | cddef3bde924 |
parent 55571 | 49102ba8cf14 |
child 58132 | caa25ab47aca |
child 58154 | 060d9d139109 |
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" |
50113 | 28 |
#include "jfr/periodic/jfrThreadCPULoadEvent.hpp" |
51004
162867fa0f8d
8203943: eventThreadGroup was null in TestJavaBlockedEvent.java
mgronlun
parents:
50113
diff
changeset
|
29 |
#include "jfr/recorder/jfrRecorder.hpp" |
50113 | 30 |
#include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
31 |
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" |
|
32 |
#include "jfr/recorder/service/jfrOptionSet.hpp" |
|
33 |
#include "jfr/recorder/storage/jfrStorage.hpp" |
|
34 |
#include "jfr/recorder/stacktrace/jfrStackTraceRepository.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()), |
|
49 |
_thread_cp(), |
|
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 |
||
65 |
bool JfrThreadLocal::has_thread_checkpoint() const { |
|
66 |
return _thread_cp.valid(); |
|
67 |
} |
|
68 |
||
69 |
void JfrThreadLocal::set_thread_checkpoint(const JfrCheckpointBlobHandle& ref) { |
|
70 |
assert(!_thread_cp.valid(), "invariant"); |
|
71 |
_thread_cp = ref; |
|
72 |
} |
|
73 |
||
74 |
const JfrCheckpointBlobHandle& JfrThreadLocal::thread_checkpoint() const { |
|
75 |
return _thread_cp; |
|
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"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
98 |
EventThreadEnd event; |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
99 |
event.set_thread(id); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
100 |
event.commit(); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
101 |
JfrThreadCPULoadEvent::send_event_for_thread(jt); |
50113 | 102 |
} |
103 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
104 |
void JfrThreadLocal::release(JfrThreadLocal* tl, Thread* t) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
105 |
assert(tl != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
106 |
assert(t != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
107 |
assert(Thread::current() == t, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
108 |
assert(!tl->is_dead(), "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
109 |
assert(tl->shelved_buffer() == NULL, "invariant"); |
50113 | 110 |
if (tl->has_native_buffer()) { |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
111 |
JfrStorage::release_thread_local(tl->native_buffer(), t); |
50113 | 112 |
} |
113 |
if (tl->has_java_buffer()) { |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
114 |
JfrStorage::release_thread_local(tl->java_buffer(), t); |
50113 | 115 |
} |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
116 |
if (tl->has_java_event_writer()) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
117 |
assert(t->is_Java_thread(), "invariant"); |
50113 | 118 |
JfrJavaSupport::destroy_global_jni_handle(tl->java_event_writer()); |
119 |
} |
|
58084
cddef3bde924
8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents:
55571
diff
changeset
|
120 |
FREE_C_HEAP_ARRAY(JfrStackFrame, tl->_stackframes); |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
121 |
tl->_dead = true; |
50113 | 122 |
} |
123 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
124 |
void JfrThreadLocal::on_exit(Thread* t) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
125 |
assert(t != NULL, "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
126 |
JfrThreadLocal * const tl = t->jfr_thread_local(); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
127 |
assert(!tl->is_dead(), "invariant"); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
128 |
if (JfrRecorder::is_recording()) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
129 |
if (t->is_Java_thread()) { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
130 |
send_java_thread_end_events(tl->thread_id(), (JavaThread*)t); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
131 |
} |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
132 |
} |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
133 |
release(tl, Thread::current()); // because it could be that Thread::current() != t |
50113 | 134 |
} |
135 |
||
136 |
JfrBuffer* JfrThreadLocal::install_native_buffer() const { |
|
137 |
assert(!has_native_buffer(), "invariant"); |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
138 |
_native_buffer = JfrStorage::acquire_thread_local(Thread::current()); |
50113 | 139 |
return _native_buffer; |
140 |
} |
|
141 |
||
142 |
JfrBuffer* JfrThreadLocal::install_java_buffer() const { |
|
143 |
assert(!has_java_buffer(), "invariant"); |
|
144 |
assert(!has_java_event_writer(), "invariant"); |
|
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
145 |
_java_buffer = JfrStorage::acquire_thread_local(Thread::current()); |
50113 | 146 |
return _java_buffer; |
147 |
} |
|
148 |
||
149 |
JfrStackFrame* JfrThreadLocal::install_stackframes() const { |
|
150 |
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
|
151 |
_stackframes = NEW_C_HEAP_ARRAY(JfrStackFrame, stackdepth(), mtTracing); |
50113 | 152 |
return _stackframes; |
153 |
} |
|
154 |
||
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
155 |
ByteSize JfrThreadLocal::trace_id_offset() { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
156 |
return in_ByteSize(offset_of(JfrThreadLocal, _trace_id)); |
50113 | 157 |
} |
52569
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
158 |
|
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
159 |
ByteSize JfrThreadLocal::java_event_writer_offset() { |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
160 |
return in_ByteSize(offset_of(JfrThreadLocal, _java_event_writer)); |
1a534c7926cc
8210024: JFR calls virtual is_Java_thread from ~Thread()
mgronlun
parents:
51004
diff
changeset
|
161 |
} |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
162 |
|
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
163 |
u4 JfrThreadLocal::stackdepth() const { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
52569
diff
changeset
|
164 |
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
|
165 |
} |