author | mgronlun |
Tue, 17 Sep 2019 13:59:11 +0200 | |
branch | JEP-349-branch |
changeset 58188 | 78b0d3d2f7b5 |
parent 57878 | bffba8d6611a |
permissions | -rw-r--r-- |
57361 | 1 |
/* |
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
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 "jfr/support/jfrThreadLocal.hpp" |
|
27 |
#include "jfr/utilities/jfrThreadIterator.hpp" |
|
28 |
#include "runtime/thread.inline.hpp" |
|
29 |
||
30 |
static bool thread_inclusion_predicate(Thread* t) { |
|
31 |
assert(t != NULL, "invariant"); |
|
57878
bffba8d6611a
Thread metadata to include excluded threads, thread sampler to exclude excluded threads, thread name friend
mgronlun
parents:
57361
diff
changeset
|
32 |
return !t->jfr_thread_local()->is_dead(); |
57361 | 33 |
} |
34 |
||
35 |
static bool java_thread_inclusion_predicate(JavaThread* jt) { |
|
36 |
assert(jt != NULL, "invariant"); |
|
37 |
return thread_inclusion_predicate(jt) && jt->thread_state() != _thread_new; |
|
38 |
} |
|
39 |
||
40 |
static JavaThread* next_java_thread(JavaThreadIteratorWithHandle& iter) { |
|
41 |
JavaThread* next = iter.next(); |
|
42 |
while (next != NULL && !java_thread_inclusion_predicate(next)) { |
|
43 |
next = iter.next(); |
|
44 |
} |
|
45 |
return next; |
|
46 |
} |
|
47 |
||
48 |
static NonJavaThread* next_non_java_thread(NonJavaThread::Iterator& iter) { |
|
49 |
NonJavaThread* next = NULL; |
|
50 |
while (!iter.end()) { |
|
51 |
next = iter.current(); |
|
52 |
iter.step(); |
|
53 |
assert(next != NULL, "invariant"); |
|
54 |
if (!thread_inclusion_predicate(next)) { |
|
55 |
continue; |
|
56 |
} |
|
57 |
} |
|
58 |
return next; |
|
59 |
} |
|
60 |
||
61 |
JfrJavaThreadIteratorAdapter::JfrJavaThreadIteratorAdapter() : _iter(), _next(next_java_thread(_iter)) {} |
|
62 |
||
63 |
JavaThread* JfrJavaThreadIteratorAdapter::next() { |
|
64 |
assert(has_next(), "invariant"); |
|
65 |
Type* const temp = _next; |
|
66 |
_next = next_java_thread(_iter); |
|
67 |
assert(temp != _next, "invariant"); |
|
68 |
return temp; |
|
69 |
} |
|
70 |
||
71 |
JfrNonJavaThreadIteratorAdapter::JfrNonJavaThreadIteratorAdapter() : _iter(), _next(next_non_java_thread(_iter)) {} |
|
72 |
||
73 |
bool JfrNonJavaThreadIteratorAdapter::has_next() const { |
|
74 |
return _next != NULL; |
|
75 |
} |
|
76 |
||
77 |
NonJavaThread* JfrNonJavaThreadIteratorAdapter::next() { |
|
78 |
assert(has_next(), "invariant"); |
|
79 |
Type* const temp = _next; |
|
80 |
_next = next_non_java_thread(_iter); |
|
81 |
assert(temp != _next, "invariant"); |
|
82 |
return temp; |
|
83 |
} |
|
84 |
||
85 |
// explicit instantiations |
|
86 |
template class JfrThreadIterator<JfrJavaThreadIteratorAdapter, StackObj>; |
|
87 |
template class JfrThreadIterator<JfrNonJavaThreadIteratorAdapter, StackObj>; |