Path: blob/master/src/hotspot/share/jfr/utilities/jfrThreadIterator.cpp
41149 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "jfr/support/jfrThreadLocal.hpp"26#include "jfr/utilities/jfrThreadIterator.hpp"27#include "runtime/thread.inline.hpp"2829static bool thread_inclusion_predicate(Thread* t) {30assert(t != NULL, "invariant");31return !t->jfr_thread_local()->is_dead();32}3334static bool java_thread_inclusion_predicate(JavaThread* jt, bool live_only) {35assert(jt != NULL, "invariant");36if (live_only && jt->thread_state() == _thread_new) {37return false;38}39return thread_inclusion_predicate(jt);40}4142static JavaThread* next_java_thread(JavaThreadIteratorWithHandle& iter, bool live_only) {43JavaThread* next = iter.next();44while (next != NULL && !java_thread_inclusion_predicate(next, live_only)) {45next = iter.next();46}47return next;48}4950static NonJavaThread* next_non_java_thread(NonJavaThread::Iterator& iter) {51while (!iter.end()) {52NonJavaThread* next = iter.current();53iter.step();54assert(next != NULL, "invariant");55if (thread_inclusion_predicate(next)) {56return next;57}58}59return NULL;60}6162JfrJavaThreadIteratorAdapter::JfrJavaThreadIteratorAdapter(bool live_only /* true */) : _iter(),63_next(next_java_thread(_iter, live_only)),64_live_only(live_only) {}6566JavaThread* JfrJavaThreadIteratorAdapter::next() {67assert(has_next(), "invariant");68Type* const temp = _next;69_next = next_java_thread(_iter, _live_only);70assert(temp != _next, "invariant");71return temp;72}7374JfrNonJavaThreadIteratorAdapter::JfrNonJavaThreadIteratorAdapter(bool live_only /* true */) : _iter(), _next(next_non_java_thread(_iter)) {}7576bool JfrNonJavaThreadIteratorAdapter::has_next() const {77return _next != NULL;78}7980NonJavaThread* JfrNonJavaThreadIteratorAdapter::next() {81assert(has_next(), "invariant");82Type* const temp = _next;83_next = next_non_java_thread(_iter);84assert(temp != _next, "invariant");85return temp;86}8788// explicit instantiations89template class JfrThreadIterator<JfrJavaThreadIteratorAdapter, StackObj>;90template class JfrThreadIterator<JfrNonJavaThreadIteratorAdapter, StackObj>;919293