author | kvn |
Wed, 01 May 2019 12:31:29 -0700 | |
changeset 54669 | ad45b3802d4e |
parent 52431 | b0af758a092c |
child 54786 | ebf733a324d4 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
2 |
* Copyright (c) 2014, 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 "aot/aotLoader.hpp" |
|
51959
db0c3952de52
8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
50113
diff
changeset
|
27 |
#include "classfile/classLoaderDataGraph.hpp" |
50113 | 28 |
#include "classfile/stringTable.hpp" |
29 |
#include "gc/shared/strongRootsScope.hpp" |
|
30 |
#include "jfr/leakprofiler/utilities/unifiedOop.hpp" |
|
31 |
#include "jfr/leakprofiler/checkpoint/rootResolver.hpp" |
|
32 |
#include "memory/iterator.hpp" |
|
33 |
#include "oops/klass.hpp" |
|
34 |
#include "oops/markOop.hpp" |
|
35 |
#include "oops/oop.hpp" |
|
36 |
#include "prims/jvmtiThreadState.hpp" |
|
37 |
#include "runtime/frame.inline.hpp" |
|
38 |
#include "runtime/mutexLocker.hpp" |
|
39 |
#include "runtime/threadSMR.inline.hpp" |
|
40 |
#include "runtime/vframe_hp.hpp" |
|
41 |
#include "services/management.hpp" |
|
42 |
#include "utilities/growableArray.hpp" |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
43 |
#if INCLUDE_JVMCI |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
44 |
#include "jvmci/jvmci.hpp" |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
45 |
#endif |
50113 | 46 |
|
47 |
class ReferenceLocateClosure : public OopClosure { |
|
48 |
protected: |
|
49 |
RootCallback& _callback; |
|
50 |
RootCallbackInfo _info; |
|
51 |
bool _complete; |
|
52 |
||
53 |
void do_oop_shared(const void* ref); |
|
54 |
||
55 |
public: |
|
56 |
ReferenceLocateClosure(RootCallback& callback, |
|
57 |
OldObjectRoot::System system, |
|
58 |
OldObjectRoot::Type type, |
|
59 |
const void* context) : _callback(callback), |
|
60 |
_info(), |
|
61 |
_complete(false) { |
|
62 |
_info._high = NULL; |
|
63 |
_info._low = NULL; |
|
64 |
_info._system = system; |
|
65 |
_info._type = type; |
|
66 |
_info._context = context; |
|
67 |
} |
|
68 |
||
69 |
virtual void do_oop(oop* ref); |
|
70 |
virtual void do_oop(narrowOop* ref); |
|
71 |
||
72 |
bool complete() const { |
|
73 |
return _complete; |
|
74 |
} |
|
75 |
}; |
|
76 |
||
77 |
void ReferenceLocateClosure::do_oop_shared(const void* ref) { |
|
78 |
assert(ref != NULL, "invariant"); |
|
79 |
if (!_complete) { |
|
80 |
_info._high = ref; |
|
81 |
_complete = _callback.process(_info); |
|
82 |
} |
|
83 |
} |
|
84 |
||
85 |
void ReferenceLocateClosure::do_oop(oop* ref) { |
|
86 |
do_oop_shared(ref); |
|
87 |
} |
|
88 |
||
89 |
void ReferenceLocateClosure::do_oop(narrowOop* ref) { |
|
90 |
do_oop_shared(ref); |
|
91 |
} |
|
92 |
||
93 |
class ReferenceToRootClosure : public StackObj { |
|
94 |
private: |
|
95 |
RootCallback& _callback; |
|
96 |
RootCallbackInfo _info; |
|
97 |
bool _complete; |
|
98 |
||
99 |
bool do_cldg_roots(); |
|
100 |
bool do_object_synchronizer_roots(); |
|
101 |
bool do_universe_roots(); |
|
102 |
bool do_jni_handle_roots(); |
|
103 |
bool do_jvmti_roots(); |
|
104 |
bool do_system_dictionary_roots(); |
|
105 |
bool do_management_roots(); |
|
106 |
bool do_string_table_roots(); |
|
107 |
bool do_aot_loader_roots(); |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
108 |
JVMCI_ONLY(bool do_jvmci_roots();) |
50113 | 109 |
|
110 |
bool do_roots(); |
|
111 |
||
112 |
public: |
|
113 |
ReferenceToRootClosure(RootCallback& callback) : _callback(callback), |
|
114 |
_info(), |
|
115 |
_complete(false) { |
|
116 |
_info._high = NULL; |
|
117 |
_info._low = NULL; |
|
118 |
_info._context = NULL; |
|
119 |
_info._system = OldObjectRoot::_system_undetermined; |
|
120 |
_info._type = OldObjectRoot::_type_undetermined; |
|
121 |
||
122 |
assert_locked_or_safepoint(Threads_lock); |
|
123 |
do_roots(); |
|
124 |
} |
|
125 |
||
126 |
bool complete() const { |
|
127 |
return _complete; |
|
128 |
} |
|
129 |
}; |
|
130 |
||
131 |
bool ReferenceToRootClosure::do_cldg_roots() { |
|
132 |
assert(!complete(), "invariant"); |
|
133 |
ReferenceLocateClosure rlc(_callback, OldObjectRoot::_class_loader_data, OldObjectRoot::_type_undetermined, NULL); |
|
52141
de6dc206a92b
8210330: Make CLD claiming allow multiple claim bits
eosterlund
parents:
51959
diff
changeset
|
134 |
CLDToOopClosure cldt_closure(&rlc, ClassLoaderData::_claim_strong); |
50113 | 135 |
ClassLoaderDataGraph::always_strong_cld_do(&cldt_closure); |
136 |
return rlc.complete(); |
|
137 |
} |
|
138 |
||
139 |
bool ReferenceToRootClosure::do_object_synchronizer_roots() { |
|
140 |
assert(!complete(), "invariant"); |
|
141 |
ReferenceLocateClosure rlc(_callback, OldObjectRoot::_object_synchronizer, OldObjectRoot::_type_undetermined, NULL); |
|
142 |
ObjectSynchronizer::oops_do(&rlc); |
|
143 |
return rlc.complete(); |
|
144 |
} |
|
145 |
||
146 |
bool ReferenceToRootClosure::do_universe_roots() { |
|
147 |
assert(!complete(), "invariant"); |
|
148 |
ReferenceLocateClosure rlc(_callback, OldObjectRoot::_universe, OldObjectRoot::_type_undetermined, NULL); |
|
149 |
Universe::oops_do(&rlc); |
|
150 |
return rlc.complete(); |
|
151 |
} |
|
152 |
||
153 |
bool ReferenceToRootClosure::do_jni_handle_roots() { |
|
154 |
assert(!complete(), "invariant"); |
|
155 |
ReferenceLocateClosure rlc(_callback, OldObjectRoot::_global_jni_handles, OldObjectRoot::_global_jni_handle, NULL); |
|
156 |
JNIHandles::oops_do(&rlc); |
|
157 |
return rlc.complete(); |
|
158 |
} |
|
159 |
||
160 |
bool ReferenceToRootClosure::do_jvmti_roots() { |
|
161 |
assert(!complete(), "invariant"); |
|
162 |
ReferenceLocateClosure rlc(_callback, OldObjectRoot::_jvmti, OldObjectRoot::_global_jni_handle, NULL); |
|
163 |
JvmtiExport::oops_do(&rlc); |
|
164 |
return rlc.complete(); |
|
165 |
} |
|
166 |
||
167 |
bool ReferenceToRootClosure::do_system_dictionary_roots() { |
|
168 |
assert(!complete(), "invariant"); |
|
169 |
ReferenceLocateClosure rlc(_callback, OldObjectRoot::_system_dictionary, OldObjectRoot::_type_undetermined, NULL); |
|
170 |
SystemDictionary::oops_do(&rlc); |
|
171 |
return rlc.complete(); |
|
172 |
} |
|
173 |
||
174 |
bool ReferenceToRootClosure::do_management_roots() { |
|
175 |
assert(!complete(), "invariant"); |
|
176 |
ReferenceLocateClosure rlc(_callback, OldObjectRoot::_management, OldObjectRoot::_type_undetermined, NULL); |
|
177 |
Management::oops_do(&rlc); |
|
178 |
return rlc.complete(); |
|
179 |
} |
|
180 |
||
181 |
bool ReferenceToRootClosure::do_string_table_roots() { |
|
182 |
assert(!complete(), "invariant"); |
|
183 |
ReferenceLocateClosure rlc(_callback, OldObjectRoot::_string_table, OldObjectRoot::_type_undetermined, NULL); |
|
184 |
StringTable::oops_do(&rlc); |
|
185 |
return rlc.complete(); |
|
186 |
} |
|
187 |
||
188 |
bool ReferenceToRootClosure::do_aot_loader_roots() { |
|
189 |
assert(!complete(), "invariant"); |
|
190 |
ReferenceLocateClosure rcl(_callback, OldObjectRoot::_aot, OldObjectRoot::_type_undetermined, NULL); |
|
191 |
AOTLoader::oops_do(&rcl); |
|
192 |
return rcl.complete(); |
|
193 |
} |
|
194 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
195 |
#if INCLUDE_JVMCI |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
196 |
bool ReferenceToRootClosure::do_jvmci_roots() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
197 |
assert(!complete(), "invariant"); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
198 |
ReferenceLocateClosure rcl(_callback, OldObjectRoot::_jvmci, OldObjectRoot::_type_undetermined, NULL); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
199 |
JVMCI::oops_do(&rcl); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
200 |
return rcl.complete(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
201 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
202 |
#endif |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
203 |
|
50113 | 204 |
bool ReferenceToRootClosure::do_roots() { |
205 |
assert(!complete(), "invariant"); |
|
206 |
assert(OldObjectRoot::_system_undetermined == _info._system, "invariant"); |
|
207 |
assert(OldObjectRoot::_type_undetermined == _info._type, "invariant"); |
|
208 |
||
209 |
if (do_cldg_roots()) { |
|
210 |
_complete = true; |
|
211 |
return true; |
|
212 |
} |
|
213 |
||
214 |
if (do_object_synchronizer_roots()) { |
|
215 |
_complete = true; |
|
216 |
return true; |
|
217 |
} |
|
218 |
||
219 |
if (do_universe_roots()) { |
|
220 |
_complete = true; |
|
221 |
return true; |
|
222 |
} |
|
223 |
||
224 |
if (do_jni_handle_roots()) { |
|
225 |
_complete = true; |
|
226 |
return true; |
|
227 |
} |
|
228 |
||
229 |
if (do_jvmti_roots()) { |
|
230 |
_complete = true; |
|
231 |
return true; |
|
232 |
} |
|
233 |
||
234 |
if (do_system_dictionary_roots()) { |
|
235 |
_complete = true; |
|
236 |
return true; |
|
237 |
} |
|
238 |
||
239 |
if (do_management_roots()) { |
|
240 |
_complete = true; |
|
241 |
return true; |
|
242 |
} |
|
243 |
||
244 |
if (do_string_table_roots()) { |
|
245 |
_complete = true; |
|
246 |
return true; |
|
247 |
} |
|
248 |
||
249 |
if (do_aot_loader_roots()) { |
|
250 |
_complete = true; |
|
251 |
return true; |
|
252 |
} |
|
253 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
254 |
#if INCLUDE_JVMCI |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
255 |
if (do_jvmci_roots()) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
256 |
_complete = true; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
257 |
return true; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
258 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
259 |
#endif |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52431
diff
changeset
|
260 |
|
50113 | 261 |
return false; |
262 |
} |
|
263 |
||
264 |
class ReferenceToThreadRootClosure : public StackObj { |
|
265 |
private: |
|
266 |
RootCallback& _callback; |
|
267 |
bool _complete; |
|
268 |
||
269 |
bool do_java_threads_oops(JavaThread* jt); |
|
270 |
bool do_thread_roots(JavaThread* jt); |
|
271 |
bool do_thread_stack_fast(JavaThread* jt); |
|
272 |
bool do_thread_stack_detailed(JavaThread* jt); |
|
273 |
bool do_thread_jni_handles(JavaThread* jt); |
|
274 |
bool do_thread_handle_area(JavaThread* jt); |
|
275 |
||
276 |
public: |
|
277 |
ReferenceToThreadRootClosure(RootCallback& callback) :_callback(callback), _complete(false) { |
|
278 |
assert_locked_or_safepoint(Threads_lock); |
|
279 |
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) { |
|
280 |
if (do_thread_roots(jt)) { |
|
281 |
return; |
|
282 |
} |
|
283 |
} |
|
284 |
} |
|
285 |
||
286 |
bool complete() const { |
|
287 |
return _complete; |
|
288 |
} |
|
289 |
}; |
|
290 |
||
291 |
bool ReferenceToThreadRootClosure::do_thread_handle_area(JavaThread* jt) { |
|
292 |
assert(jt != NULL, "invariant"); |
|
293 |
assert(!complete(), "invariant"); |
|
294 |
ReferenceLocateClosure rcl(_callback, OldObjectRoot::_threads, OldObjectRoot::_handle_area, jt); |
|
295 |
jt->handle_area()->oops_do(&rcl); |
|
296 |
return rcl.complete(); |
|
297 |
} |
|
298 |
||
299 |
bool ReferenceToThreadRootClosure::do_thread_jni_handles(JavaThread* jt) { |
|
300 |
assert(jt != NULL, "invariant"); |
|
301 |
assert(!complete(), "invariant"); |
|
302 |
||
303 |
ReferenceLocateClosure rcl(_callback, OldObjectRoot::_threads, OldObjectRoot::_local_jni_handle, jt); |
|
304 |
jt->active_handles()->oops_do(&rcl); |
|
305 |
return rcl.complete(); |
|
306 |
} |
|
307 |
||
308 |
bool ReferenceToThreadRootClosure::do_thread_stack_fast(JavaThread* jt) { |
|
309 |
assert(jt != NULL, "invariant"); |
|
310 |
assert(!complete(), "invariant"); |
|
311 |
||
312 |
if (_callback.entries() == 0) { |
|
313 |
_complete = true; |
|
314 |
return true; |
|
315 |
} |
|
316 |
||
317 |
RootCallbackInfo info; |
|
318 |
info._high = NULL; |
|
319 |
info._low = NULL; |
|
320 |
info._context = jt; |
|
321 |
info._system = OldObjectRoot::_threads; |
|
322 |
info._type = OldObjectRoot::_stack_variable; |
|
323 |
||
324 |
for (int i = 0; i < _callback.entries(); ++i) { |
|
325 |
const address adr = (address)_callback.at(i); |
|
326 |
if (jt->is_in_usable_stack(adr)) { |
|
327 |
info._high = adr; |
|
328 |
_complete = _callback.process(info); |
|
329 |
if (_complete) { |
|
330 |
return true; |
|
331 |
} |
|
332 |
} |
|
333 |
} |
|
334 |
assert(!complete(), "invariant"); |
|
335 |
return false; |
|
336 |
} |
|
337 |
||
338 |
bool ReferenceToThreadRootClosure::do_thread_stack_detailed(JavaThread* jt) { |
|
339 |
assert(jt != NULL, "invariant"); |
|
340 |
assert(!complete(), "invariant"); |
|
341 |
||
342 |
ReferenceLocateClosure rcl(_callback, OldObjectRoot::_threads, OldObjectRoot::_stack_variable, jt); |
|
343 |
||
344 |
if (jt->has_last_Java_frame()) { |
|
345 |
// traverse the registered growable array gc_array |
|
346 |
// can't do this as it is not reachable from outside |
|
347 |
||
348 |
// Traverse the monitor chunks |
|
349 |
MonitorChunk* chunk = jt->monitor_chunks(); |
|
350 |
for (; chunk != NULL; chunk = chunk->next()) { |
|
351 |
chunk->oops_do(&rcl); |
|
352 |
} |
|
353 |
||
354 |
if (rcl.complete()) { |
|
355 |
return true; |
|
356 |
} |
|
357 |
||
358 |
// Traverse the execution stack |
|
359 |
for (StackFrameStream fst(jt); !fst.is_done(); fst.next()) { |
|
360 |
fst.current()->oops_do(&rcl, NULL, fst.register_map()); |
|
361 |
} |
|
362 |
||
363 |
} // last java frame |
|
364 |
||
365 |
if (rcl.complete()) { |
|
366 |
return true; |
|
367 |
} |
|
368 |
||
369 |
GrowableArray<jvmtiDeferredLocalVariableSet*>* const list = jt->deferred_locals(); |
|
370 |
if (list != NULL) { |
|
371 |
for (int i = 0; i < list->length(); i++) { |
|
372 |
list->at(i)->oops_do(&rcl); |
|
373 |
} |
|
374 |
} |
|
375 |
||
376 |
if (rcl.complete()) { |
|
377 |
return true; |
|
378 |
} |
|
379 |
||
380 |
// Traverse instance variables at the end since the GC may be moving things |
|
381 |
// around using this function |
|
382 |
/* |
|
383 |
* // can't reach these oop* from the outside |
|
384 |
f->do_oop((oop*) &_threadObj); |
|
385 |
f->do_oop((oop*) &_vm_result); |
|
386 |
f->do_oop((oop*) &_exception_oop); |
|
387 |
f->do_oop((oop*) &_pending_async_exception); |
|
388 |
*/ |
|
389 |
||
390 |
JvmtiThreadState* const jvmti_thread_state = jt->jvmti_thread_state(); |
|
391 |
if (jvmti_thread_state != NULL) { |
|
392 |
jvmti_thread_state->oops_do(&rcl); |
|
393 |
} |
|
394 |
||
395 |
return rcl.complete(); |
|
396 |
} |
|
397 |
||
398 |
bool ReferenceToThreadRootClosure::do_java_threads_oops(JavaThread* jt) { |
|
399 |
assert(jt != NULL, "invariant"); |
|
400 |
assert(!complete(), "invariant"); |
|
401 |
||
402 |
ReferenceLocateClosure rcl(_callback, OldObjectRoot::_threads, OldObjectRoot::_global_jni_handle, jt); |
|
403 |
jt->oops_do(&rcl, NULL); |
|
404 |
return rcl.complete(); |
|
405 |
} |
|
406 |
||
407 |
bool ReferenceToThreadRootClosure::do_thread_roots(JavaThread* jt) { |
|
408 |
assert(jt != NULL, "invariant"); |
|
409 |
||
410 |
if (do_thread_stack_fast(jt)) { |
|
411 |
_complete = true; |
|
412 |
return true; |
|
413 |
} |
|
414 |
||
415 |
if (do_thread_jni_handles(jt)) { |
|
416 |
_complete = true; |
|
417 |
return true; |
|
418 |
} |
|
419 |
||
420 |
if (do_thread_handle_area(jt)) { |
|
421 |
_complete = true; |
|
422 |
return true; |
|
423 |
} |
|
424 |
||
425 |
if (do_thread_stack_detailed(jt)) { |
|
426 |
_complete = true; |
|
427 |
return true; |
|
428 |
} |
|
429 |
||
430 |
return false; |
|
431 |
} |
|
432 |
||
433 |
class RootResolverMarkScope : public MarkScope { |
|
434 |
}; |
|
435 |
||
436 |
void RootResolver::resolve(RootCallback& callback) { |
|
437 |
||
438 |
// Need to clear cld claim bit before starting |
|
439 |
ClassLoaderDataGraph::clear_claimed_marks(); |
|
440 |
RootResolverMarkScope mark_scope; |
|
441 |
||
442 |
// thread local roots |
|
443 |
ReferenceToThreadRootClosure rtrc(callback); |
|
444 |
if (rtrc.complete()) { |
|
445 |
return; |
|
446 |
} |
|
447 |
// system global roots |
|
448 |
ReferenceToRootClosure rrc(callback); |
|
449 |
} |