Skip to content
Permalink
Browse files
8271514: support JFR use of new ThreadsList::Iterator
Co-authored-by: Kim Barrett <kbarrett@openjdk.org>
Reviewed-by: sspitsyn, mgronlun
  • Loading branch information
Daniel D. Daugherty and Kim Barrett committed Oct 12, 2021
1 parent b8bd259 commit 8657f77608f37d7ff5254032858f2f16c7c204d5
Showing 2 changed files with 28 additions and 19 deletions.
@@ -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();
};

1 comment on commit 8657f77

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 8657f77 Oct 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.