author | mgronlun |
Wed, 30 Oct 2019 19:43:52 +0100 | |
changeset 58863 | c16ac7a2eba4 |
parent 58132 | caa25ab47aca |
child 59252 | 623722a6aeb9 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
52334
diff
changeset
|
2 |
* Copyright (c) 2011, 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" |
|
26 |
#include "classfile/classLoaderData.inline.hpp" |
|
27 |
#include "classfile/symbolTable.hpp" |
|
28 |
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" |
|
29 |
#include "jfr/utilities/jfrTypes.hpp" |
|
30 |
#include "oops/arrayKlass.inline.hpp" |
|
31 |
#include "oops/klass.inline.hpp" |
|
32 |
#include "oops/instanceKlass.inline.hpp" |
|
33 |
#include "oops/method.hpp" |
|
34 |
#include "oops/oop.inline.hpp" |
|
35 |
#include "runtime/atomic.hpp" |
|
36 |
#include "runtime/vm_version.hpp" |
|
37 |
#include "runtime/jniHandles.inline.hpp" |
|
38 |
#include "runtime/thread.inline.hpp" |
|
39 |
#include "utilities/debug.hpp" |
|
40 |
||
41 |
// returns updated value |
|
42 |
static traceid atomic_inc(traceid volatile* const dest) { |
|
43 |
assert(VM_Version::supports_cx8(), "invariant"); |
|
44 |
traceid compare_value; |
|
45 |
traceid exchange_value; |
|
46 |
do { |
|
58863 | 47 |
compare_value = *dest; |
50113 | 48 |
exchange_value = compare_value + 1; |
49 |
} while (Atomic::cmpxchg(exchange_value, dest, compare_value) != compare_value); |
|
50 |
return exchange_value; |
|
51 |
} |
|
52 |
||
53 |
static traceid next_class_id() { |
|
54 |
static volatile traceid class_id_counter = MaxJfrEventId + 100; |
|
55 |
return atomic_inc(&class_id_counter) << TRACE_ID_SHIFT; |
|
56 |
} |
|
57 |
||
58 |
static traceid next_thread_id() { |
|
59 |
static volatile traceid thread_id_counter = 0; |
|
60 |
return atomic_inc(&thread_id_counter); |
|
61 |
} |
|
62 |
||
63 |
static traceid next_module_id() { |
|
64 |
static volatile traceid module_id_counter = 1; |
|
65 |
return atomic_inc(&module_id_counter) << TRACE_ID_SHIFT; |
|
66 |
} |
|
67 |
||
68 |
static traceid next_package_id() { |
|
69 |
static volatile traceid package_id_counter = 1; |
|
70 |
return atomic_inc(&package_id_counter) << TRACE_ID_SHIFT; |
|
71 |
} |
|
72 |
||
73 |
static traceid next_class_loader_data_id() { |
|
74 |
static volatile traceid cld_id_counter = 1; |
|
75 |
return atomic_inc(&cld_id_counter) << TRACE_ID_SHIFT; |
|
76 |
} |
|
77 |
||
52334
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
78 |
static bool found_jdk_internal_event_klass = false; |
50113 | 79 |
static bool found_jdk_jfr_event_klass = false; |
80 |
||
81 |
static void check_klass(const Klass* klass) { |
|
82 |
assert(klass != NULL, "invariant"); |
|
52334
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
83 |
if (found_jdk_internal_event_klass && found_jdk_jfr_event_klass) { |
50113 | 84 |
return; |
85 |
} |
|
52334
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
86 |
static const Symbol* jdk_internal_event_sym = NULL; |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
87 |
if (jdk_internal_event_sym == NULL) { |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
88 |
// setup when loading the first TypeArrayKlass (Universe::genesis) hence single threaded invariant |
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
52334
diff
changeset
|
89 |
jdk_internal_event_sym = SymbolTable::new_permanent_symbol("jdk/internal/event/Event"); |
52334
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
90 |
} |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
91 |
assert(jdk_internal_event_sym != NULL, "invariant"); |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
92 |
|
50113 | 93 |
static const Symbol* jdk_jfr_event_sym = NULL; |
94 |
if (jdk_jfr_event_sym == NULL) { |
|
95 |
// setup when loading the first TypeArrayKlass (Universe::genesis) hence single threaded invariant |
|
54847
59ea39bb2809
8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents:
52334
diff
changeset
|
96 |
jdk_jfr_event_sym = SymbolTable::new_permanent_symbol("jdk/jfr/Event"); |
50113 | 97 |
} |
98 |
assert(jdk_jfr_event_sym != NULL, "invariant"); |
|
52334
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
99 |
const Symbol* const klass_name = klass->name(); |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
100 |
|
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
101 |
if (!found_jdk_internal_event_klass) { |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
102 |
if (jdk_internal_event_sym == klass_name && klass->class_loader() == NULL) { |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
103 |
found_jdk_internal_event_klass = true; |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
104 |
JfrTraceId::tag_as_jdk_jfr_event(klass); |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
105 |
return; |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
106 |
} |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
107 |
} |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
108 |
|
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
109 |
if (!found_jdk_jfr_event_klass) { |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
110 |
if (jdk_jfr_event_sym == klass_name && klass->class_loader() == NULL) { |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
111 |
found_jdk_jfr_event_klass = true; |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
112 |
JfrTraceId::tag_as_jdk_jfr_event(klass); |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
113 |
return; |
a181612f0715
8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents:
51444
diff
changeset
|
114 |
} |
50113 | 115 |
} |
116 |
} |
|
117 |
||
118 |
void JfrTraceId::assign(const Klass* klass) { |
|
119 |
assert(klass != NULL, "invariant"); |
|
120 |
klass->set_trace_id(next_class_id()); |
|
121 |
check_klass(klass); |
|
122 |
const Klass* const super = klass->super(); |
|
123 |
if (super == NULL) { |
|
124 |
return; |
|
125 |
} |
|
126 |
if (IS_EVENT_KLASS(super)) { |
|
127 |
tag_as_jdk_jfr_event_sub(klass); |
|
128 |
} |
|
129 |
} |
|
130 |
||
131 |
void JfrTraceId::assign(const ModuleEntry* module) { |
|
132 |
assert(module != NULL, "invariant"); |
|
133 |
module->set_trace_id(next_module_id()); |
|
134 |
} |
|
135 |
||
136 |
void JfrTraceId::assign(const PackageEntry* package) { |
|
137 |
assert(package != NULL, "invariant"); |
|
138 |
package->set_trace_id(next_package_id()); |
|
139 |
} |
|
140 |
||
141 |
void JfrTraceId::assign(const ClassLoaderData* cld) { |
|
142 |
assert(cld != NULL, "invariant"); |
|
51444
3e5d28e6de32
8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents:
50429
diff
changeset
|
143 |
if (cld->is_unsafe_anonymous()) { |
50113 | 144 |
cld->set_trace_id(0); |
145 |
return; |
|
146 |
} |
|
147 |
cld->set_trace_id(next_class_loader_data_id()); |
|
148 |
} |
|
149 |
||
150 |
traceid JfrTraceId::assign_thread_id() { |
|
151 |
return next_thread_id(); |
|
152 |
} |
|
153 |
||
154 |
// used by CDS / APPCDS as part of "remove_unshareable_info" |
|
155 |
void JfrTraceId::remove(const Klass* k) { |
|
156 |
assert(k != NULL, "invariant"); |
|
157 |
// Mask off and store the event flags. |
|
158 |
// This mechanism will retain the event specific flags |
|
159 |
// in the archive, allowing for event flag restoration |
|
160 |
// when renewing the traceid on klass revival. |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54847
diff
changeset
|
161 |
k->set_trace_id(EVENT_KLASS_MASK(k)); |
50113 | 162 |
} |
163 |
||
164 |
// used by CDS / APPCDS as part of "restore_unshareable_info" |
|
165 |
void JfrTraceId::restore(const Klass* k) { |
|
166 |
assert(k != NULL, "invariant"); |
|
167 |
if (IS_JDK_JFR_EVENT_KLASS(k)) { |
|
168 |
found_jdk_jfr_event_klass = true; |
|
169 |
} |
|
170 |
const traceid event_flags = k->trace_id(); |
|
171 |
// get a fresh traceid and restore the original event flags |
|
172 |
k->set_trace_id(next_class_id() | event_flags); |
|
173 |
} |
|
174 |
||
175 |
traceid JfrTraceId::get(jclass jc) { |
|
176 |
assert(jc != NULL, "invariant"); |
|
177 |
assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant"); |
|
178 |
const oop my_oop = JNIHandles::resolve(jc); |
|
179 |
assert(my_oop != NULL, "invariant"); |
|
180 |
return get(java_lang_Class::as_Klass(my_oop)); |
|
181 |
} |
|
182 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54847
diff
changeset
|
183 |
traceid JfrTraceId::use(jclass jc) { |
50113 | 184 |
assert(jc != NULL, "invariant"); |
185 |
assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant"); |
|
186 |
const oop my_oop = JNIHandles::resolve(jc); |
|
187 |
assert(my_oop != NULL, "invariant"); |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54847
diff
changeset
|
188 |
return use(java_lang_Class::as_Klass(my_oop)); |
50113 | 189 |
} |
190 |
||
191 |
bool JfrTraceId::in_visible_set(const jclass jc) { |
|
192 |
assert(jc != NULL, "invariant"); |
|
193 |
assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant"); |
|
194 |
const oop mirror = JNIHandles::resolve(jc); |
|
195 |
assert(mirror != NULL, "invariant"); |
|
196 |
return in_visible_set(java_lang_Class::as_Klass(mirror)); |
|
197 |
} |
|
198 |
||
199 |
bool JfrTraceId::in_jdk_jfr_event_hierarchy(const jclass jc) { |
|
200 |
assert(jc != NULL, "invariant"); |
|
201 |
const oop mirror = JNIHandles::resolve(jc); |
|
202 |
assert(mirror != NULL, "invariant"); |
|
203 |
return in_jdk_jfr_event_hierarchy(java_lang_Class::as_Klass(mirror)); |
|
204 |
} |
|
205 |
||
206 |
bool JfrTraceId::is_jdk_jfr_event_sub(const jclass jc) { |
|
207 |
assert(jc != NULL, "invariant"); |
|
208 |
const oop mirror = JNIHandles::resolve(jc); |
|
209 |
assert(mirror != NULL, "invariant"); |
|
210 |
return is_jdk_jfr_event_sub(java_lang_Class::as_Klass(mirror)); |
|
211 |
} |
|
212 |
||
213 |
bool JfrTraceId::is_jdk_jfr_event(const jclass jc) { |
|
214 |
assert(jc != NULL, "invariant"); |
|
215 |
const oop mirror = JNIHandles::resolve(jc); |
|
216 |
assert(mirror != NULL, "invariant"); |
|
217 |
return is_jdk_jfr_event(java_lang_Class::as_Klass(mirror)); |
|
218 |
} |
|
219 |
||
220 |
bool JfrTraceId::is_event_host(const jclass jc) { |
|
221 |
assert(jc != NULL, "invariant"); |
|
222 |
const oop mirror = JNIHandles::resolve(jc); |
|
223 |
assert(mirror != NULL, "invariant"); |
|
224 |
return is_event_host(java_lang_Class::as_Klass(mirror)); |
|
225 |
} |
|
226 |
||
227 |
void JfrTraceId::tag_as_jdk_jfr_event_sub(const jclass jc) { |
|
228 |
assert(jc != NULL, "invariant"); |
|
229 |
const oop mirror = JNIHandles::resolve(jc); |
|
230 |
assert(mirror != NULL, "invariant"); |
|
231 |
const Klass* const k = java_lang_Class::as_Klass(mirror); |
|
232 |
tag_as_jdk_jfr_event_sub(k); |
|
233 |
assert(IS_JDK_JFR_EVENT_SUBKLASS(k), "invariant"); |
|
234 |
} |
|
235 |
||
236 |
void JfrTraceId::tag_as_event_host(const jclass jc) { |
|
237 |
assert(jc != NULL, "invariant"); |
|
238 |
const oop mirror = JNIHandles::resolve(jc); |
|
239 |
assert(mirror != NULL, "invariant"); |
|
240 |
const Klass* const k = java_lang_Class::as_Klass(mirror); |
|
241 |
tag_as_event_host(k); |
|
242 |
assert(IS_EVENT_HOST_KLASS(k), "invariant"); |
|
243 |
} |