Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/logging/logOutputList.cpp
40930 views
1
/*
2
* Copyright (c) 2015, 2018, 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
#include "precompiled.hpp"
25
#include "logging/logLevel.hpp"
26
#include "logging/logOutputList.hpp"
27
#include "memory/allocation.inline.hpp"
28
#include "runtime/atomic.hpp"
29
#include "runtime/orderAccess.hpp"
30
#include "utilities/globalDefinitions.hpp"
31
32
jint LogOutputList::increase_readers() {
33
jint result = Atomic::add(&_active_readers, 1);
34
assert(_active_readers > 0, "Ensure we have consistent state");
35
return result;
36
}
37
38
jint LogOutputList::decrease_readers() {
39
jint result = Atomic::add(&_active_readers, -1);
40
assert(result >= 0, "Ensure we have consistent state");
41
return result;
42
}
43
44
void LogOutputList::wait_until_no_readers() const {
45
OrderAccess::storeload();
46
while (_active_readers != 0) {
47
// Busy wait
48
}
49
}
50
51
void LogOutputList::set_output_level(LogOutput* output, LogLevelType level) {
52
LogOutputNode* node = find(output);
53
if (level == LogLevel::Off && node != NULL) {
54
remove_output(node);
55
} else if (level != LogLevel::Off && node == NULL) {
56
add_output(output, level);
57
} else if (node != NULL) {
58
update_output_level(node, level);
59
}
60
}
61
62
LogOutputList::LogOutputNode* LogOutputList::find(const LogOutput* output) const {
63
for (LogOutputNode* node = _level_start[LogLevel::Last]; node != NULL; node = node->_next) {
64
if (output == node->_value) {
65
return node;
66
}
67
}
68
return NULL;
69
}
70
71
void LogOutputList::clear() {
72
73
// Grab the linked list
74
LogOutputNode* cur = _level_start[LogLevel::Last];
75
76
// Clear _level_start
77
for (uint level = LogLevel::First; level < LogLevel::Count; level++) {
78
_level_start[level] = NULL;
79
}
80
81
// Delete all nodes from the linked list
82
wait_until_no_readers();
83
while (cur != NULL) {
84
LogOutputNode* next = cur->_next;
85
delete cur;
86
cur = next;
87
}
88
}
89
90
void LogOutputList::remove_output(LogOutputList::LogOutputNode* node) {
91
assert(node != NULL, "Node must be non-null");
92
93
// Remove node from _level_start first
94
bool found = false;
95
for (uint level = LogLevel::First; level < LogLevel::Count; level++) {
96
if (_level_start[level] == node) {
97
found = true;
98
_level_start[level] = node->_next;
99
}
100
}
101
102
// Now remove it from the linked list
103
for (LogOutputNode* cur = _level_start[LogLevel::Last]; cur != NULL; cur = cur->_next) {
104
if (cur->_next == node) {
105
found = true;
106
cur->_next = node->_next;
107
break;
108
}
109
}
110
assert(found, "Node to be removed should always be found");
111
112
wait_until_no_readers();
113
delete node;
114
}
115
116
void LogOutputList::add_output(LogOutput* output, LogLevelType level) {
117
LogOutputNode* node = new LogOutputNode();
118
node->_value = output;
119
node->_level = level;
120
121
// Set the next pointer to the first node of a lower level
122
for (node->_next = _level_start[level];
123
node->_next != NULL && node->_next->_level == level;
124
node->_next = node->_next->_next) {
125
}
126
127
// Update the _level_start index
128
for (int l = LogLevel::Last; l >= level; l--) {
129
if (_level_start[l] == NULL || _level_start[l]->_level < level) {
130
_level_start[l] = node;
131
}
132
}
133
134
// Add the node the list
135
for (LogOutputNode* cur = _level_start[LogLevel::Last]; cur != NULL; cur = cur->_next) {
136
if (cur != node && cur->_next == node->_next) {
137
cur->_next = node;
138
break;
139
}
140
}
141
}
142
143
void LogOutputList::update_output_level(LogOutputList::LogOutputNode* node, LogLevelType level) {
144
add_output(node->_value, level);
145
wait_until_no_readers();
146
remove_output(node);
147
}
148
149