1 /*
   2  * Copyright (c) 2015, 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_VM_LOGGING_LOGTAG_HPP
  25 #define SHARE_VM_LOGGING_LOGTAG_HPP
  26 #include "utilities/globalDefinitions.hpp"
  27 
  28 // List of available logging tags. New tags should be added here.
  29 // (The tags 'all', 'disable' and 'help' are special tags that can
  30 // not be used in log calls, and should not be listed below.)
  31 #define LOG_TAG_LIST \
  32   LOG_TAG(gc) \
  33   LOG_TAG(rt) \
  34   LOG_TAG(svc) \
  35   LOG_TAG(logging) \
  36   LOG_TAG(comp)
  37 
  38 #define PREFIX_LOG_TAG(T) (LogTag::T)
  39 
  40 // Expand a set of log tags to their prefixed names.
  41 // For error detection purposes, the macro passes one more tag than what is supported.
  42 // If too many tags are given, a static assert in the log class will fail.
  43 #define LOG_TAGS_EXPANDED(T0, T1, T2, T3, T4, T5, ...)  PREFIX_LOG_TAG(T0), PREFIX_LOG_TAG(T1), PREFIX_LOG_TAG(T2), \
  44                                                         PREFIX_LOG_TAG(T3), PREFIX_LOG_TAG(T4), PREFIX_LOG_TAG(T5)
  45 // The EXPAND_VARARGS macro is required for MSVC, or it will resolve the LOG_TAGS_EXPANDED macro incorrectly.
  46 #define EXPAND_VARARGS(x) x
  47 #define LOG_TAGS(...) EXPAND_VARARGS(LOG_TAGS_EXPANDED(__VA_ARGS__, __NO_TAG, __NO_TAG, __NO_TAG, __NO_TAG, __NO_TAG, __NO_TAG))
  48 
  49 class LogTag {
  50  public:
  51   static const size_t MaxTags = 5;
  52 
  53   enum type {
  54     __NO_TAG,
  55 #define LOG_TAG(name) name,
  56     LOG_TAG_LIST
  57 #undef LOG_TAG
  58     Count
  59   };
  60 
  61   static const char* name(LogTag::type tag) {
  62     return _name[tag];
  63   }
  64 
  65   static LogTag::type from_string(const char *str);
  66 
  67  private:
  68   static const char* _name[];
  69 };
  70 
  71 typedef LogTag::type LogTagType;
  72 
  73 #endif