Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/logging/log.hpp
40930 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
#ifndef SHARE_LOGGING_LOG_HPP
25
#define SHARE_LOGGING_LOG_HPP
26
27
#include "logging/logLevel.hpp"
28
#include "logging/logPrefix.hpp"
29
#include "logging/logTagSet.hpp"
30
#include "logging/logTag.hpp"
31
#include "utilities/debug.hpp"
32
33
class LogMessageBuffer;
34
35
//
36
// Logging macros
37
//
38
// Usage:
39
// log_<level>(<comma separated log tags>)(<printf-style log arguments>);
40
// e.g.
41
// log_debug(logging)("message %d", i);
42
//
43
// Note that these macros will not evaluate the arguments unless the logging is enabled.
44
//
45
#define log_error(...) (!log_is_enabled(Error, __VA_ARGS__)) ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Error>
46
#define log_warning(...) (!log_is_enabled(Warning, __VA_ARGS__)) ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Warning>
47
#define log_info(...) (!log_is_enabled(Info, __VA_ARGS__)) ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Info>
48
#define log_debug(...) (!log_is_enabled(Debug, __VA_ARGS__)) ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Debug>
49
#define log_trace(...) (!log_is_enabled(Trace, __VA_ARGS__)) ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Trace>
50
51
// Macros for logging that should be excluded in product builds.
52
// Available for levels Info, Debug and Trace. Includes test macro that
53
// evaluates to false in product builds.
54
#ifndef PRODUCT
55
#define log_develop_info(...) (!log_is_enabled(Info, __VA_ARGS__)) ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Info>
56
#define log_develop_debug(...) (!log_is_enabled(Debug, __VA_ARGS__)) ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Debug>
57
#define log_develop_trace(...) (!log_is_enabled(Trace, __VA_ARGS__)) ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Trace>
58
#define log_develop_is_enabled(level, ...) log_is_enabled(level, __VA_ARGS__)
59
#else
60
#define DUMMY_ARGUMENT_CONSUMER(...)
61
#define log_develop_info(...) DUMMY_ARGUMENT_CONSUMER
62
#define log_develop_debug(...) DUMMY_ARGUMENT_CONSUMER
63
#define log_develop_trace(...) DUMMY_ARGUMENT_CONSUMER
64
#define log_develop_is_enabled(...) false
65
#endif
66
67
// Convenience macro to test if the logging is enabled on the specified level for given tags.
68
#define log_is_enabled(level, ...) (LogImpl<LOG_TAGS(__VA_ARGS__)>::is_level(LogLevel::level))
69
70
//
71
// Log class for more advanced logging scenarios.
72
// Has printf-style member functions for each log level (trace(), debug(), etc).
73
//
74
// The (trace(), debug(), etc) functions can also be used along with the LogStream
75
// class to obtain an outputStream object, to be passed to various printing
76
// functions that accept an outputStream:
77
//
78
// Example usage:
79
// Log(codecache, sweep) log;
80
// if (log.is_debug()) {
81
// log.debug("result = %d", result).trace(" tracing info");
82
// LogStream ls(log.debug());
83
// CodeCache::print_summary(&ls, false);
84
// }
85
//
86
#define Log(...) LogImpl<LOG_TAGS(__VA_ARGS__)>
87
88
//
89
// Log class that embeds both log tags and a log level.
90
//
91
// The class provides a way to write the tags and log level once,
92
// so that redundant specification of tags or levels can be avoided.
93
//
94
// Example usage:
95
// LogTarget(Debug, codecache, sweep) out;
96
// if (out.is_enabled()) {
97
// out.print("result = %d", result);
98
// LogStream ls(out);
99
// CodeCache::print_summary(&ls, false);
100
// }
101
//
102
#define LogTarget(level, ...) LogTargetImpl<LogLevel::level, LOG_TAGS(__VA_ARGS__)>
103
104
template <LogLevelType level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
105
class LogTargetImpl;
106
107
template <LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG, LogTagType T3 = LogTag::__NO_TAG,
108
LogTagType T4 = LogTag::__NO_TAG, LogTagType GuardTag = LogTag::__NO_TAG>
109
class LogImpl {
110
private:
111
static const size_t LogBufferSize = 512;
112
public:
113
// Make sure no more than the maximum number of tags have been given.
114
// The GuardTag allows this to be detected if/when it happens. If the GuardTag
115
// is not __NO_TAG, the number of tags given exceeds the maximum allowed.
116
STATIC_ASSERT(GuardTag == LogTag::__NO_TAG); // Number of logging tags exceeds maximum supported!
117
118
// Empty constructor to avoid warnings on MSVC about unused variables
119
// when the log instance is only used for static functions.
120
LogImpl() {
121
}
122
123
static bool is_level(LogLevelType level) {
124
return LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().is_level(level);
125
}
126
127
ATTRIBUTE_PRINTF(2, 3)
128
static void write(LogLevelType level, const char* fmt, ...) {
129
va_list args;
130
va_start(args, fmt);
131
vwrite(level, fmt, args);
132
va_end(args);
133
}
134
135
static void write(const LogMessageBuffer& msg) {
136
LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().log(msg);
137
};
138
139
template <LogLevelType Level>
140
ATTRIBUTE_PRINTF(1, 2)
141
static void write(const char* fmt, ...) {
142
va_list args;
143
va_start(args, fmt);
144
vwrite(Level, fmt, args);
145
va_end(args);
146
}
147
148
ATTRIBUTE_PRINTF(2, 0)
149
static void vwrite(LogLevelType level, const char* fmt, va_list args) {
150
LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().vwrite(level, fmt, args);
151
}
152
153
#define LOG_LEVEL(level, name) ATTRIBUTE_PRINTF(2, 0) \
154
LogImpl& v##name(const char* fmt, va_list args) { \
155
vwrite(LogLevel::level, fmt, args); \
156
return *this; \
157
} \
158
LogImpl& name(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3) { \
159
va_list args; \
160
va_start(args, fmt); \
161
vwrite(LogLevel::level, fmt, args); \
162
va_end(args); \
163
return *this; \
164
} \
165
static bool is_##name() { \
166
return is_level(LogLevel::level); \
167
} \
168
static LogTargetImpl<LogLevel::level, T0, T1, T2, T3, T4, GuardTag>* name() { \
169
return (LogTargetImpl<LogLevel::level, T0, T1, T2, T3, T4, GuardTag>*)NULL; \
170
}
171
LOG_LEVEL_LIST
172
#undef LOG_LEVEL
173
};
174
175
// Combines logging tags and a logging level.
176
template <LogLevelType level, LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG,
177
LogTagType T3 = LogTag::__NO_TAG, LogTagType T4 = LogTag::__NO_TAG, LogTagType GuardTag = LogTag::__NO_TAG>
178
class LogTargetImpl {
179
public:
180
// Empty constructor to avoid warnings on MSVC about unused variables
181
// when the log instance is only used for static functions.
182
LogTargetImpl() {
183
}
184
185
static bool is_enabled() {
186
return LogImpl<T0, T1, T2, T3, T4, GuardTag>::is_level(level);
187
}
188
189
static bool develop_is_enabled() {
190
NOT_PRODUCT(return is_enabled());
191
PRODUCT_ONLY(return false);
192
}
193
194
static void print(const char* fmt, ...) ATTRIBUTE_PRINTF(1, 2) {
195
va_list args;
196
va_start(args, fmt);
197
LogImpl<T0, T1, T2, T3, T4, GuardTag>::vwrite(level, fmt, args);
198
va_end(args);
199
}
200
201
};
202
203
#endif // SHARE_LOGGING_LOG_HPP
204
205