Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/share/logging/logDecorators.cpp
64440 views
1
/*
2
* Copyright (c) 2015, 2021, 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/logDecorators.hpp"
26
#include "runtime/os.hpp"
27
28
template <LogDecorators::Decorator d>
29
struct AllBitmask {
30
// Use recursive template deduction to calculate the bitmask of all decorations.
31
static const uint _value = (1 << d) | AllBitmask<static_cast<LogDecorators::Decorator>(d + 1)>::_value;
32
};
33
34
template<>
35
struct AllBitmask<LogDecorators::Count> {
36
static const uint _value = 0;
37
};
38
39
const LogDecorators LogDecorators::None = LogDecorators(0);
40
const LogDecorators LogDecorators::All = LogDecorators(AllBitmask<time_decorator>::_value);
41
42
const char* LogDecorators::_name[][2] = {
43
#define DECORATOR(n, a) {#n, #a},
44
DECORATOR_LIST
45
#undef DECORATOR
46
};
47
48
LogDecorators::Decorator LogDecorators::from_string(const char* str) {
49
for (size_t i = 0; i < Count; i++) {
50
Decorator d = static_cast<Decorator>(i);
51
if (strcasecmp(str, name(d)) == 0 || strcasecmp(str, abbreviation(d)) == 0) {
52
return d;
53
}
54
}
55
return Invalid;
56
}
57
58
bool LogDecorators::parse(const char* decorator_args, outputStream* errstream) {
59
if (decorator_args == NULL || strlen(decorator_args) == 0) {
60
_decorators = DefaultDecoratorsMask;
61
return true;
62
}
63
64
if (strcasecmp(decorator_args, "none") == 0 ) {
65
_decorators = 0;
66
return true;
67
}
68
69
bool result = true;
70
uint tmp_decorators = 0;
71
char* args_copy = os::strdup_check_oom(decorator_args, mtLogging);
72
char* token = args_copy;
73
char* comma_pos;
74
do {
75
comma_pos = strchr(token, ',');
76
if (comma_pos != NULL) {
77
*comma_pos = '\0';
78
}
79
Decorator d = from_string(token);
80
if (d == Invalid) {
81
if (errstream != NULL) {
82
errstream->print_cr("Invalid decorator '%s'.", token);
83
}
84
result = false;
85
break;
86
}
87
tmp_decorators |= mask(d);
88
token = comma_pos + 1;
89
} while (comma_pos != NULL);
90
os::free(args_copy);
91
if (result) {
92
_decorators = tmp_decorators;
93
}
94
return result;
95
}
96
97