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
3031static 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-
5144static 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
6775JavaThread* 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
0 commit comments