Skip to content

Commit 8657f77

Browse files
Daniel D. DaughertyKim Barrett
andcommitted
8271514: support JFR use of new ThreadsList::Iterator
Co-authored-by: Kim Barrett <[email protected]> Reviewed-by: sspitsyn, mgronlun
1 parent b8bd259 commit 8657f77

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

src/hotspot/share/jfr/utilities/jfrThreadIterator.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "jfr/support/jfrThreadLocal.hpp"
2727
#include "jfr/utilities/jfrThreadIterator.hpp"
2828
#include "runtime/thread.inline.hpp"
29+
#include "runtime/threadSMR.inline.hpp"
2930

3031
static bool thread_inclusion_predicate(Thread* t) {
3132
assert(t != NULL, "invariant");
@@ -40,14 +41,6 @@ static bool java_thread_inclusion_predicate(JavaThread* jt, bool live_only) {
4041
return thread_inclusion_predicate(jt);
4142
}
4243

43-
static JavaThread* next_java_thread(JavaThreadIteratorWithHandle& iter, bool live_only) {
44-
JavaThread* next = iter.next();
45-
while (next != NULL && !java_thread_inclusion_predicate(next, live_only)) {
46-
next = iter.next();
47-
}
48-
return next;
49-
}
50-
5144
static NonJavaThread* next_non_java_thread(NonJavaThread::Iterator& iter) {
5245
while (!iter.end()) {
5346
NonJavaThread* next = iter.current();
@@ -60,15 +53,29 @@ static NonJavaThread* next_non_java_thread(NonJavaThread::Iterator& iter) {
6053
return NULL;
6154
}
6255

63-
JfrJavaThreadIteratorAdapter::JfrJavaThreadIteratorAdapter(bool live_only /* true */) : _iter(),
64-
_next(next_java_thread(_iter, live_only)),
65-
_live_only(live_only) {}
56+
JfrJavaThreadIteratorAdapter::JfrJavaThreadIteratorAdapter(bool live_only /* true */) :
57+
_tlist(),
58+
_it(_tlist.begin()),
59+
_end(_tlist.end()),
60+
_live_only(live_only)
61+
{
62+
skip_excluded();
63+
}
64+
65+
bool JfrJavaThreadIteratorAdapter::has_next() const {
66+
return _it != _end;
67+
}
68+
69+
void JfrJavaThreadIteratorAdapter::skip_excluded() {
70+
while (has_next() && !java_thread_inclusion_predicate(*_it, _live_only)) {
71+
++_it;
72+
}
73+
}
6674

6775
JavaThread* JfrJavaThreadIteratorAdapter::next() {
6876
assert(has_next(), "invariant");
69-
Type* const temp = _next;
70-
_next = next_java_thread(_iter, _live_only);
71-
assert(temp != _next, "invariant");
77+
Type* const temp = *_it++;
78+
skip_excluded();
7279
return temp;
7380
}
7481

src/hotspot/share/jfr/utilities/jfrThreadIterator.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ class JfrThreadIterator : public AP {
4747

4848
class JfrJavaThreadIteratorAdapter {
4949
private:
50-
JavaThreadIteratorWithHandle _iter;
51-
JavaThread* _next;
50+
ThreadsListHandle _tlist;
51+
ThreadsListHandle::Iterator _it;
52+
ThreadsListHandle::Iterator _end;
5253
bool _live_only;
54+
55+
void skip_excluded();
56+
5357
public:
5458
typedef JavaThread Type;
5559
JfrJavaThreadIteratorAdapter(bool live_only = true);
56-
bool has_next() const {
57-
return _next != NULL;
58-
}
60+
bool has_next() const;
5961
Type* next();
6062
};
6163

0 commit comments

Comments
 (0)