|
1 /* |
|
2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 * |
|
23 */ |
|
24 |
|
25 #ifndef SHARE_VM_JFR_UTILITIES_JFRTHREADITERATOR_HPP |
|
26 #define SHARE_VM_JFR_UTILITIES_JFRTHREADITERATOR_HPP |
|
27 |
|
28 #include "memory/allocation.hpp" |
|
29 #include "runtime/thread.hpp" |
|
30 #include "runtime/threadSMR.hpp" |
|
31 |
|
32 template <typename Adapter, typename AP = StackObj> |
|
33 class JfrThreadIterator : public AP { |
|
34 private: |
|
35 Adapter _adapter; |
|
36 public: |
|
37 JfrThreadIterator() : _adapter() {} |
|
38 typename Adapter::Type* next() { |
|
39 assert(has_next(), "invariant"); |
|
40 return _adapter.next(); |
|
41 } |
|
42 bool has_next() const { |
|
43 return _adapter.has_next(); |
|
44 } |
|
45 }; |
|
46 |
|
47 class JfrJavaThreadIteratorAdapter { |
|
48 private: |
|
49 JavaThreadIteratorWithHandle _iter; |
|
50 JavaThread* _next; |
|
51 public: |
|
52 typedef JavaThread Type; |
|
53 JfrJavaThreadIteratorAdapter(); |
|
54 bool has_next() const { |
|
55 return _next != NULL; |
|
56 } |
|
57 Type* next(); |
|
58 }; |
|
59 |
|
60 class JfrNonJavaThreadIteratorAdapter { |
|
61 private: |
|
62 NonJavaThread::Iterator _iter; |
|
63 NonJavaThread* _next; |
|
64 public: |
|
65 typedef NonJavaThread Type; |
|
66 JfrNonJavaThreadIteratorAdapter(); |
|
67 bool has_next() const; |
|
68 Type* next(); |
|
69 }; |
|
70 |
|
71 typedef JfrThreadIterator<JfrJavaThreadIteratorAdapter, StackObj> JfrJavaThreadIterator; |
|
72 typedef JfrThreadIterator<JfrNonJavaThreadIteratorAdapter, StackObj> JfrNonJavaThreadIterator; |
|
73 |
|
74 #endif // SHARE_VM_JFR_UTILITIES_JFRTHREADITERATOR_HPP |