1 /*
  2  * Copyright (c) 2015, 2023, 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_LOGTAG_HPP
 25 #define SHARE_LOGGING_LOGTAG_HPP
 26 
 27 #include "memory/allStatic.hpp"
 28 #include "utilities/globalDefinitions.hpp"
 29 
 30 class outputStream;
 31 
 32 // List of available logging tags. New tags should be added here, in
 33 // alphabetical order.
 34 // (The tags 'all', 'disable' and 'help' are special tags that can
 35 // not be used in log calls, and should not be listed below.)
 36 #define LOG_TAG_LIST \
 37   LOG_TAG(add) \
 38   LOG_TAG(age) \
 39   LOG_TAG(alloc) \
 40   LOG_TAG(annotation) \
 41   LOG_TAG(arguments) \
 42   LOG_TAG(array) \
 43   LOG_TAG(attach) \
 44   LOG_TAG(barrier) \
 45   LOG_TAG(blocks) \
 46   LOG_TAG(bot) \
 47   LOG_TAG(breakpoint) \
 48   LOG_TAG(bytecode) \
 49   LOG_TAG(cause) \
 50   LOG_TAG(cds) \
 51   LOG_TAG(census) \
 52   LOG_TAG(class) \
 53   LOG_TAG(classhisto) \
 54   LOG_TAG(cleanup) \
 55   LOG_TAG(codecache) \
 56   NOT_PRODUCT(LOG_TAG(codestrings)) \
 57   LOG_TAG(compaction) \
 58   LOG_TAG(compilation) \
 59   LOG_TAG(condy) \
 60   LOG_TAG(constantpool) \
 61   LOG_TAG(constraints) \
 62   LOG_TAG(container) \
 63   LOG_TAG(continuations) \
 64   LOG_TAG(coops) \
 65   LOG_TAG(cpu) \
 66   LOG_TAG(cset) \
 67   LOG_TAG(data) \
 68   LOG_TAG(datacreation) \
 69   LOG_TAG(dcmd) \
 70   LOG_TAG(decoder) \
 71   LOG_TAG(defaultmethods) \
 72   LOG_TAG(deoptimization) \
 73   LOG_TAG(dependencies) \
 74   LOG_TAG(director) \
 75   NOT_PRODUCT(LOG_TAG(downcall)) \
 76   LOG_TAG(dump) \
 77   LOG_TAG(dynamic) \
 78   LOG_TAG(ergo) \
 79   LOG_TAG(event) \
 80   LOG_TAG(exceptions) \
 81   LOG_TAG(exit) \
 82   LOG_TAG(fastlock) \
 83   LOG_TAG(finalizer) \
 84   LOG_TAG(fingerprint) \
 85   NOT_PRODUCT(LOG_TAG(foreign)) \
 86   LOG_TAG(free) \
 87   LOG_TAG(freelist) \
 88   LOG_TAG(gc) \
 89   NOT_PRODUCT(LOG_TAG(generate)) \
 90   LOG_TAG(handshake) \
 91   LOG_TAG(hashtables) \
 92   LOG_TAG(heap) \
 93   LOG_TAG(heapdump) \
 94   NOT_PRODUCT(LOG_TAG(heapsampling)) \
 95   LOG_TAG(humongous) \
 96   LOG_TAG(ihop) \
 97   LOG_TAG(iklass) \
 98   LOG_TAG(indy) \
 99   LOG_TAG(init) \
100   LOG_TAG(inlining) \
101   LOG_TAG(install) \
102   LOG_TAG(interpreter) \
103   LOG_TAG(itables) \
104   LOG_TAG(jfr) \
105   LOG_TAG(jit) \
106   LOG_TAG(jni) \
107   LOG_TAG(jvmci) \
108   LOG_TAG(jvmti) \
109   LOG_TAG(lambda) \
110   LOG_TAG(library) \
111   LOG_TAG(liveness) \
112   LOG_TAG(load) /* Trace all classes loaded */ \
113   LOG_TAG(loader) \
114   LOG_TAG(logging) \
115   LOG_TAG(malloc) \
116   LOG_TAG(map) \
117   LOG_TAG(mark) \
118   LOG_TAG(marking) \
119   LOG_TAG(membername) \
120   LOG_TAG(memops) \
121   LOG_TAG(metadata) \
122   LOG_TAG(metaspace) \
123   LOG_TAG(methodcomparator) \
124   LOG_TAG(methodhandles) \
125   LOG_TAG(mirror) \
126   LOG_TAG(mmu) \
127   LOG_TAG(module) \
128   LOG_TAG(monitorinflation) \
129   LOG_TAG(monitormismatch) \
130   LOG_TAG(native) \
131   LOG_TAG(nestmates) \
132   LOG_TAG(nmethod) \
133   LOG_TAG(nmt) \
134   LOG_TAG(normalize) \
135   LOG_TAG(numa) \
136   LOG_TAG(objecttagging) \
137   LOG_TAG(obsolete) \
138   LOG_TAG(oldobject) \
139   LOG_TAG(oom) \
140   LOG_TAG(oopmap) \
141   LOG_TAG(oops) \
142   LOG_TAG(oopstorage) \
143   LOG_TAG(os) \
144   LOG_TAG(owner) \
145   LOG_TAG(page) \
146   LOG_TAG(pagesize) \
147   LOG_TAG(parser) \
148   LOG_TAG(patch) \
149   LOG_TAG(path) \
150   LOG_TAG(perf) \
151   LOG_TAG(periodic) \
152   LOG_TAG(phases) \
153   LOG_TAG(plab) \
154   LOG_TAG(placeholders) \
155   LOG_TAG(preempt) \
156   LOG_TAG(preload)   /* Trace successfull class preloading */ \
157   LOG_TAG(preorder)  /* Trace all classes loaded in order referenced (not loaded) */ \
158   LOG_TAG(preview)   /* Trace loading of preview feature types */ \
159   LOG_TAG(promotion) \
160   LOG_TAG(protectiondomain) /* "Trace protection domain verification" */ \
161   LOG_TAG(ptrqueue) \
162   LOG_TAG(purge) \
163   LOG_TAG(record) \
164   LOG_TAG(redefine) \
165   LOG_TAG(ref) \
166   LOG_TAG(refine) \
167   LOG_TAG(region) \
168   LOG_TAG(reloc) \
169   LOG_TAG(remset) \
170   LOG_TAG(resolve) \
171   LOG_TAG(safepoint) \
172   LOG_TAG(sampling) \
173   LOG_TAG(scavenge) \
174   LOG_TAG(sealed) \
175   LOG_TAG(setting) \
176   LOG_TAG(smr) \
177   LOG_TAG(stackbarrier) \
178   LOG_TAG(stackmap) \
179   LOG_TAG(stacktrace) \
180   LOG_TAG(stackwalk) \
181   LOG_TAG(start) \
182   LOG_TAG(startup) \
183   LOG_TAG(startuptime) \
184   LOG_TAG(state) \
185   LOG_TAG(stats) \
186   LOG_TAG(streaming) \
187   LOG_TAG(stringdedup) \
188   LOG_TAG(stringtable) \
189   LOG_TAG(stubs) \
190   LOG_TAG(subclass) \
191   LOG_TAG(survivor) \
192   LOG_TAG(suspend) \
193   LOG_TAG(sweep) \
194   LOG_TAG(symboltable) \
195   LOG_TAG(system) \
196   LOG_TAG(table) \
197   LOG_TAG(task) \
198   DEBUG_ONLY(LOG_TAG(test)) \
199   LOG_TAG(thread) \
200   LOG_TAG(throttle) \
201   LOG_TAG(timer) \
202   LOG_TAG(tlab) \
203   LOG_TAG(tracking) \
204   LOG_TAG(trimnative) /* trim native heap */ \
205   LOG_TAG(unload) /* Trace unloading of classes */ \
206   LOG_TAG(unmap) \
207   LOG_TAG(unshareable) \
208   NOT_PRODUCT(LOG_TAG(upcall)) \
209   LOG_TAG(update) \
210   LOG_TAG(valuebasedclasses) \
211   LOG_TAG(valuetypes) \
212   LOG_TAG(verification) \
213   LOG_TAG(verify) \
214   LOG_TAG(vmmutex) \
215   LOG_TAG(vmoperation) \
216   LOG_TAG(vmthread) \
217   LOG_TAG(vtables) \
218   LOG_TAG(vtablestubs)
219 
220 #define PREFIX_LOG_TAG(T) (LogTag::_##T)
221 
222 // Expand a set of log tags to their prefixed names.
223 // For error detection purposes, the macro passes one more tag than what is supported.
224 // If too many tags are given, a static assert in the log class will fail.
225 #define LOG_TAGS_EXPANDED(T0, T1, T2, T3, T4, T5, ...)  PREFIX_LOG_TAG(T0), PREFIX_LOG_TAG(T1), PREFIX_LOG_TAG(T2), \
226                                                         PREFIX_LOG_TAG(T3), PREFIX_LOG_TAG(T4), PREFIX_LOG_TAG(T5)
227 // The EXPAND_VARARGS macro is required for MSVC, or it will resolve the LOG_TAGS_EXPANDED macro incorrectly.
228 #define EXPAND_VARARGS(x) x
229 #define LOG_TAGS(...) EXPAND_VARARGS(LOG_TAGS_EXPANDED(__VA_ARGS__, _NO_TAG, _NO_TAG, _NO_TAG, _NO_TAG, _NO_TAG, _NO_TAG))
230 
231 // Log tags are used to classify log messages.
232 // Each log message can be assigned between 1 to LogTag::MaxTags number of tags.
233 // Specifying multiple tags for a log message means that only outputs configured
234 // for those exact tags, or a subset of the tags with a wildcard, will see the logging.
235 // Multiple tags should be comma separated, e.g. log_error(tag1, tag2)("msg").
236 class LogTag : public AllStatic {
237  public:
238   // The maximum number of tags that a single log message can have.
239   // E.g. there might be hundreds of different tags available,
240   // but a specific log message can only be tagged with up to MaxTags of those.
241   static const size_t MaxTags = 5;
242 
243   enum type {
244     __NO_TAG,
245 #define LOG_TAG(name) _##name,
246     LOG_TAG_LIST
247 #undef LOG_TAG
248     Count
249   };
250 
251   static const char* name(LogTag::type tag) {
252     return _name[tag];
253   }
254 
255   static LogTag::type from_string(const char *str);
256   static LogTag::type fuzzy_match(const char *tag);
257   static void list_tags(outputStream* out);
258 
259  private:
260   static const char* const _name[];
261 };
262 
263 typedef LogTag::type LogTagType;
264 
265 #endif // SHARE_LOGGING_LOGTAG_HPP