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 #ifndef SHARE_VM_LOGGING_LOGOUTPUTLIST_HPP
25 #define SHARE_VM_LOGGING_LOGOUTPUTLIST_HPP
26 #include "logging/logLevel.hpp"
27 #include "memory/allocation.hpp"
28 #include "runtime/atomic.hpp"
29 #include "utilities/globalDefinitions.hpp"
30
31 class LogOutput;
32
33 // Data structure to keep track of log outputs for a given tagset.
34 // Essentially a sorted linked list going from error level outputs
35 // to outputs of finer levels. Keeps an index from each level to
36 // the first node in the list for the corresponding level.
37 // This allows a log message on, for example, info level to jump
38 // straight into the list where the first info level output can
39 // be found. The log message will then be printed on that output,
40 // as well as all outputs in nodes that follow in the list (which
41 // can be additional info level outputs and/or debug and trace outputs).
42 //
43 // Each instance keeps track of the number of current readers of the list.
44 // To remove a node from the list the node must first be unlinked,
45 // and the memory for that node can be freed whenever the removing
46 // thread observes an active reader count of 0 (after unlinking it).
47 class LogOutputList {
48 private:
49 struct LogOutputNode : public CHeapObj<mtInternal> {
50 LogOutput* _value;
51 LogOutputNode* _next;
52 LogLevelType _level;
53 };
54
55 LogOutputNode* _level_start[LogLevel::Count];
56 volatile jint _active_readers;
57
58 LogOutputNode* find(LogOutput* output);
59 void remove_output(LogOutputNode* node);
60 void add_output(LogOutput* output, LogLevelType level);
61 void update_output_level(LogOutputNode* node, LogLevelType level);
62
63 public:
64 LogOutputList() : _active_readers(0) {
65 for (size_t i = 0; i < LogLevel::Count; i++) {
66 _level_start[i] = NULL;
67 }
68 }
69
70 // Test if the outputlist has an output for the given level.
71 bool is_level(LogLevelType level) {
72 return _level_start[level] != NULL;
73 }
74
75 // Set (add/update/remove) the output to the specified level.
76 void set_output_level(LogOutput* output, LogLevelType level);
77
78 // Bookkeeping functions to keep track of number of active readers/iterators for the list.
79 jint increase_readers();
80 jint decrease_readers();
81 void wait_until_no_readers() const;
82
83 class Iterator {
84 friend class LogOutputList;
85 private:
86 LogOutputNode* _current;
87 LogOutputList* _list;
88 Iterator(LogOutputList* list, LogOutputNode* start) : _current(start), _list(list) {
89 }
90
91 public:
92 ~Iterator() {
93 _list->decrease_readers();
94 }
95
96 LogOutput* operator*() {
97 return _current->_value;
98 }
99
100 void operator++(int) {
101 _current = _current->_next;
102 }
103
104 bool operator!=(const LogOutputNode *ref) const {
105 return _current != ref;
106 }
107 };
108
109 Iterator iterator(LogLevelType level = LogLevel::Last) {
110 increase_readers();
111 return Iterator(this, _level_start[level]);
112 }
113
114 LogOutputNode* end() const {
115 return NULL;
116 }
117 };
118
119 #endif
|
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 #ifndef SHARE_VM_LOGGING_LOGOUTPUTLIST_HPP
25 #define SHARE_VM_LOGGING_LOGOUTPUTLIST_HPP
26
27 #include "logging/logLevel.hpp"
28 #include "memory/allocation.hpp"
29 #include "runtime/atomic.hpp"
30 #include "utilities/globalDefinitions.hpp"
31
32 class LogOutput;
33
34 // Data structure to keep track of log outputs for a given tagset.
35 // Essentially a sorted linked list going from error level outputs
36 // to outputs of finer levels. Keeps an index from each level to
37 // the first node in the list for the corresponding level.
38 // This allows a log message on, for example, info level to jump
39 // straight into the list where the first info level output can
40 // be found. The log message will then be printed on that output,
41 // as well as all outputs in nodes that follow in the list (which
42 // can be additional info level outputs and/or debug and trace outputs).
43 //
44 // Each instance keeps track of the number of current readers of the list.
45 // To remove a node from the list the node must first be unlinked,
46 // and the memory for that node can be freed whenever the removing
47 // thread observes an active reader count of 0 (after unlinking it).
48 class LogOutputList VALUE_OBJ_CLASS_SPEC {
49 private:
50 struct LogOutputNode : public CHeapObj<mtLogging> {
51 LogOutput* _value;
52 LogOutputNode* _next;
53 LogLevelType _level;
54 };
55
56 LogOutputNode* _level_start[LogLevel::Count];
57 volatile jint _active_readers;
58
59 LogOutputNode* find(LogOutput* output);
60 void remove_output(LogOutputNode* node);
61 void add_output(LogOutput* output, LogLevelType level);
62 void update_output_level(LogOutputNode* node, LogLevelType level);
63
64 public:
65 LogOutputList() : _active_readers(0) {
66 for (size_t i = 0; i < LogLevel::Count; i++) {
67 _level_start[i] = NULL;
68 }
69 }
70
71 // Test if the outputlist has an output for the given level.
72 bool is_level(LogLevelType level) {
73 return _level_start[level] != NULL;
74 }
75
76 // Set (add/update/remove) the output to the specified level.
77 void set_output_level(LogOutput* output, LogLevelType level);
78
79 // Bookkeeping functions to keep track of number of active readers/iterators for the list.
80 jint increase_readers();
81 jint decrease_readers();
82 void wait_until_no_readers() const;
83
84 class Iterator VALUE_OBJ_CLASS_SPEC {
85 friend class LogOutputList;
86 private:
87 LogOutputNode* _current;
88 LogOutputList* _list;
89 Iterator(LogOutputList* list, LogOutputNode* start) : _current(start), _list(list) {
90 }
91
92 public:
93 ~Iterator() {
94 _list->decrease_readers();
95 }
96
97 LogOutput* operator*() {
98 return _current->_value;
99 }
100
101 void operator++(int) {
102 _current = _current->_next;
103 }
104
105 bool operator!=(const LogOutputNode *ref) const {
106 return _current != ref;
107 }
108 };
109
110 Iterator iterator(LogLevelType level = LogLevel::Last) {
111 increase_readers();
112 return Iterator(this, _level_start[level]);
113 }
114
115 LogOutputNode* end() const {
116 return NULL;
117 }
118 };
119
120 #endif // SHARE_VM_LOGGING_LOGOUTPUTLIST_HPP
|