src/hotspot/share/logging/logTag.cpp
changeset 49015 a12c9536d8a6
parent 47216 71c04702a3d5
child 49163 580bb0b85f63
equal deleted inserted replaced
49014:407a8495d4b3 49015:a12c9536d8a6
     1 /*
     1 /*
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    22  *
    22  *
    23  */
    23  */
    24 #include "precompiled.hpp"
    24 #include "precompiled.hpp"
    25 #include "logging/logTag.hpp"
    25 #include "logging/logTag.hpp"
    26 #include "utilities/globalDefinitions.hpp"
    26 #include "utilities/globalDefinitions.hpp"
       
    27 #include "utilities/ostream.hpp"
       
    28 #include "utilities/quickSort.hpp"
    27 
    29 
    28 const char* LogTag::_name[] = {
    30 const char* LogTag::_name[] = {
    29   "", // __NO_TAG
    31   "", // __NO_TAG
    30 #define LOG_TAG(name) #name,
    32 #define LOG_TAG(name) #name,
    31   LOG_TAG_LIST
    33   LOG_TAG_LIST
    38       return static_cast<LogTagType>(i);
    40       return static_cast<LogTagType>(i);
    39     }
    41     }
    40   }
    42   }
    41   return __NO_TAG;
    43   return __NO_TAG;
    42 }
    44 }
       
    45 
       
    46 static int cmp_logtag(LogTagType a, LogTagType b) {
       
    47   return strcmp(LogTag::name(a), LogTag::name(b));
       
    48 }
       
    49 
       
    50 static const size_t sorted_tagcount = LogTag::Count - 1; // Not counting _NO_TAG
       
    51 static LogTagType sorted_tags[sorted_tagcount];
       
    52 
       
    53 class TagSorter {
       
    54  public:
       
    55   TagSorter() {
       
    56     for (size_t i = 1; i < LogTag::Count; i++) {
       
    57       sorted_tags[i - 1] = static_cast<LogTagType>(i);
       
    58     }
       
    59     QuickSort::sort(sorted_tags, sorted_tagcount, cmp_logtag, true);
       
    60   }
       
    61 };
       
    62 
       
    63 static TagSorter tagsorter; // Sorts tags during static initialization
       
    64 
       
    65 void LogTag::list_tags(outputStream* out) {
       
    66   for (size_t i = 0; i < sorted_tagcount; i++) {
       
    67     out->print("%s %s", (i == 0 ? "" : ","), _name[sorted_tags[i]]);
       
    68   }
       
    69   out->cr();
       
    70 }