Skip to content

Commit

Permalink
8253397: Ensure LogTag types are sorted
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, kbarrett, tschatzl
  • Loading branch information
cl4es committed Sep 23, 2020
1 parent b8ea80a commit 5f1d612
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
41 changes: 21 additions & 20 deletions src/hotspot/share/logging/logTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
#include "utilities/stringUtils.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/ostream.hpp"
#include "utilities/quickSort.hpp"

const char* LogTag::_name[] = {
const char* const LogTag::_name[] = {
"", // __NO_TAG
#define LOG_TAG(name) #name,
LOG_TAG_LIST
Expand Down Expand Up @@ -60,28 +59,30 @@ LogTagType LogTag::fuzzy_match(const char *str) {
return match;
}

static int cmp_logtag(LogTagType a, LogTagType b) {
return strcmp(LogTag::name(a), LogTag::name(b));
void LogTag::list_tags(outputStream* out) {
for (size_t i = 1; i < LogTag::Count; i++) { // Not including __NO_TAG
out->print("%s %s", (i == 1 ? "" : ","), _name[static_cast<LogTagType>(i)]);
}
out->cr();
}

static const size_t sorted_tagcount = LogTag::Count - 1; // Not counting _NO_TAG
static LogTagType sorted_tags[sorted_tagcount];

class TagSorter {
#ifdef ASSERT
class LogTagTypeChecker {
public:
TagSorter() {
for (size_t i = 1; i < LogTag::Count; i++) {
sorted_tags[i - 1] = static_cast<LogTagType>(i);
LogTagTypeChecker() {
assert(LogTagType::__NO_TAG == static_cast<LogTagType>(0), "First tag should be __NO_TAG");

// assert the LogTag type enum is sorted
for (size_t i = 1; i < LogTag::Count - 1; i++) {
const char* a = LogTag::name(static_cast<LogTagType>(i));
const char* b = LogTag::name(static_cast<LogTagType>(i + 1));

assert(strcmp(a, b) < 0,
"LogTag type not in alphabetical order at index %zu: %s should be after %s",
i, a, b);
}
QuickSort::sort(sorted_tags, sorted_tagcount, cmp_logtag, true);
}
};

static TagSorter tagsorter; // Sorts tags during static initialization

void LogTag::list_tags(outputStream* out) {
for (size_t i = 0; i < sorted_tagcount; i++) {
out->print("%s %s", (i == 0 ? "" : ","), _name[sorted_tags[i]]);
}
out->cr();
}
static LogTagTypeChecker logtagtypechecker; // Assert LogTag tags are set up as expected during static initialization
#endif // ASSERT
33 changes: 17 additions & 16 deletions src/hotspot/share/logging/logTag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
#include "memory/allocation.hpp"
#include "utilities/globalDefinitions.hpp"

// List of available logging tags. New tags should be added here.
// List of available logging tags. New tags should be added here, in
// alphabetical order.
// (The tags 'all', 'disable' and 'help' are special tags that can
// not be used in log calls, and should not be listed below.)
#define LOG_TAG_LIST \
LOG_TAG(add) \
LOG_TAG(age) \
LOG_TAG(alloc) \
LOG_TAG(aot) \
LOG_TAG(annotation) \
LOG_TAG(aot) \
LOG_TAG(arguments) \
LOG_TAG(attach) \
LOG_TAG(barrier) \
Expand All @@ -53,8 +54,8 @@
LOG_TAG(compaction) \
LOG_TAG(compilation) \
LOG_TAG(condy) \
LOG_TAG(constraints) \
LOG_TAG(constantpool) \
LOG_TAG(constraints) \
LOG_TAG(container) \
LOG_TAG(coops) \
LOG_TAG(cpu) \
Expand Down Expand Up @@ -101,10 +102,11 @@
LOG_TAG(marking) \
LOG_TAG(membername) \
LOG_TAG(memops) \
LOG_TAG(methodcomparator) \
LOG_TAG(metadata) \
LOG_TAG(metaspace) \
LOG_TAG(methodcomparator) \
LOG_TAG(methodhandles) \
LOG_TAG(mirror) \
LOG_TAG(mmu) \
LOG_TAG(module) \
LOG_TAG(monitorinflation) \
Expand All @@ -123,34 +125,35 @@
LOG_TAG(os) \
LOG_TAG(owner) \
LOG_TAG(pagesize) \
LOG_TAG(parser) \
LOG_TAG(patch) \
LOG_TAG(path) \
LOG_TAG(perf) \
LOG_TAG(periodic) \
LOG_TAG(phases) \
LOG_TAG(plab) \
LOG_TAG(preorder) /* Trace all classes loaded in order referenced (not loaded) */ \
LOG_TAG(preview) /* Trace loading of preview feature types */ \
LOG_TAG(primitivewrappers) \
LOG_TAG(promotion) \
LOG_TAG(preorder) /* Trace all classes loaded in order referenced (not loaded) */ \
LOG_TAG(protectiondomain) /* "Trace protection domain verification" */ \
LOG_TAG(ref) \
LOG_TAG(ptrqueue) \
LOG_TAG(purge) \
LOG_TAG(record) \
LOG_TAG(redefine) \
LOG_TAG(ref) \
LOG_TAG(refine) \
LOG_TAG(region) \
LOG_TAG(reloc) \
LOG_TAG(remset) \
LOG_TAG(parser) \
LOG_TAG(ptrqueue) \
LOG_TAG(purge) \
LOG_TAG(record) \
LOG_TAG(resolve) \
LOG_TAG(safepoint) \
LOG_TAG(sampling) \
LOG_TAG(scavenge) \
LOG_TAG(sealed) \
LOG_TAG(setting) \
LOG_TAG(smr) \
LOG_TAG(stackmap) \
LOG_TAG(stacktrace) \
LOG_TAG(stackwalk) \
LOG_TAG(start) \
Expand All @@ -160,24 +163,22 @@
LOG_TAG(streaming) \
LOG_TAG(stringdedup) \
LOG_TAG(stringtable) \
LOG_TAG(symboltable) \
LOG_TAG(stackmap) \
LOG_TAG(subclass) \
LOG_TAG(survivor) \
LOG_TAG(sweep) \
LOG_TAG(symboltable) \
LOG_TAG(system) \
LOG_TAG(table) \
LOG_TAG(task) \
DEBUG_ONLY(LOG_TAG(test)) \
LOG_TAG(thread) \
LOG_TAG(tlab) \
LOG_TAG(time) \
LOG_TAG(timer) \
LOG_TAG(tlab) \
LOG_TAG(tracking) \
LOG_TAG(update) \
LOG_TAG(unload) /* Trace unloading of classes */ \
LOG_TAG(unshareable) \
LOG_TAG(mirror) \
LOG_TAG(update) \
LOG_TAG(verification) \
LOG_TAG(verify) \
LOG_TAG(vmmutex) \
Expand Down Expand Up @@ -227,7 +228,7 @@ class LogTag : public AllStatic {
static void list_tags(outputStream* out);

private:
static const char* _name[];
static const char* const _name[];
};

typedef LogTag::type LogTagType;
Expand Down

0 comments on commit 5f1d612

Please sign in to comment.