8271514: support JFR use of new ThreadsList::Iterator

Co-authored-by: Kim Barrett <kbarrett@openjdk.org>
Reviewed-by: sspitsyn, mgronlun
This commit is contained in:
Daniel D. Daugherty 2021-10-12 17:05:47 +00:00
parent b8bd259bb8
commit 8657f77608
2 changed files with 28 additions and 19 deletions
src/hotspot/share/jfr/utilities

@ -26,6 +26,7 @@
#include "jfr/support/jfrThreadLocal.hpp"
#include "jfr/utilities/jfrThreadIterator.hpp"
#include "runtime/thread.inline.hpp"
#include "runtime/threadSMR.inline.hpp"
static bool thread_inclusion_predicate(Thread* t) {
assert(t != NULL, "invariant");
@ -40,14 +41,6 @@ static bool java_thread_inclusion_predicate(JavaThread* jt, bool live_only) {
return thread_inclusion_predicate(jt);
}
static JavaThread* next_java_thread(JavaThreadIteratorWithHandle& iter, bool live_only) {
JavaThread* next = iter.next();
while (next != NULL && !java_thread_inclusion_predicate(next, live_only)) {
next = iter.next();
}
return next;
}
static NonJavaThread* next_non_java_thread(NonJavaThread::Iterator& iter) {
while (!iter.end()) {
NonJavaThread* next = iter.current();
@ -60,15 +53,29 @@ static NonJavaThread* next_non_java_thread(NonJavaThread::Iterator& iter) {
return NULL;
}
JfrJavaThreadIteratorAdapter::JfrJavaThreadIteratorAdapter(bool live_only /* true */) : _iter(),
_next(next_java_thread(_iter, live_only)),
_live_only(live_only) {}
JfrJavaThreadIteratorAdapter::JfrJavaThreadIteratorAdapter(bool live_only /* true */) :
_tlist(),
_it(_tlist.begin()),
_end(_tlist.end()),
_live_only(live_only)
{
skip_excluded();
}
bool JfrJavaThreadIteratorAdapter::has_next() const {
return _it != _end;
}
void JfrJavaThreadIteratorAdapter::skip_excluded() {
while (has_next() && !java_thread_inclusion_predicate(*_it, _live_only)) {
++_it;
}
}
JavaThread* JfrJavaThreadIteratorAdapter::next() {
assert(has_next(), "invariant");
Type* const temp = _next;
_next = next_java_thread(_iter, _live_only);
assert(temp != _next, "invariant");
Type* const temp = *_it++;
skip_excluded();
return temp;
}

@ -47,15 +47,17 @@ class JfrThreadIterator : public AP {
class JfrJavaThreadIteratorAdapter {
private:
JavaThreadIteratorWithHandle _iter;
JavaThread* _next;
ThreadsListHandle _tlist;
ThreadsListHandle::Iterator _it;
ThreadsListHandle::Iterator _end;
bool _live_only;
void skip_excluded();
public:
typedef JavaThread Type;
JfrJavaThreadIteratorAdapter(bool live_only = true);
bool has_next() const {
return _next != NULL;
}
bool has_next() const;
Type* next();
};