Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 5f1d612

Browse files
committedSep 23, 2020
8253397: Ensure LogTag types are sorted
Reviewed-by: dholmes, kbarrett, tschatzl
1 parent b8ea80a commit 5f1d612

File tree

2 files changed

+38
-36
lines changed

2 files changed

+38
-36
lines changed
 

‎src/hotspot/share/logging/logTag.cpp

+21-20
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
#include "utilities/stringUtils.hpp"
2727
#include "utilities/globalDefinitions.hpp"
2828
#include "utilities/ostream.hpp"
29-
#include "utilities/quickSort.hpp"
3029

31-
const char* LogTag::_name[] = {
30+
const char* const LogTag::_name[] = {
3231
"", // __NO_TAG
3332
#define LOG_TAG(name) #name,
3433
LOG_TAG_LIST
@@ -60,28 +59,30 @@ LogTagType LogTag::fuzzy_match(const char *str) {
6059
return match;
6160
}
6261

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

67-
static const size_t sorted_tagcount = LogTag::Count - 1; // Not counting _NO_TAG
68-
static LogTagType sorted_tags[sorted_tagcount];
69-
70-
class TagSorter {
69+
#ifdef ASSERT
70+
class LogTagTypeChecker {
7171
public:
72-
TagSorter() {
73-
for (size_t i = 1; i < LogTag::Count; i++) {
74-
sorted_tags[i - 1] = static_cast<LogTagType>(i);
72+
LogTagTypeChecker() {
73+
assert(LogTagType::__NO_TAG == static_cast<LogTagType>(0), "First tag should be __NO_TAG");
74+
75+
// assert the LogTag type enum is sorted
76+
for (size_t i = 1; i < LogTag::Count - 1; i++) {
77+
const char* a = LogTag::name(static_cast<LogTagType>(i));
78+
const char* b = LogTag::name(static_cast<LogTagType>(i + 1));
79+
80+
assert(strcmp(a, b) < 0,
81+
"LogTag type not in alphabetical order at index %zu: %s should be after %s",
82+
i, a, b);
7583
}
76-
QuickSort::sort(sorted_tags, sorted_tagcount, cmp_logtag, true);
7784
}
7885
};
7986

80-
static TagSorter tagsorter; // Sorts tags during static initialization
81-
82-
void LogTag::list_tags(outputStream* out) {
83-
for (size_t i = 0; i < sorted_tagcount; i++) {
84-
out->print("%s %s", (i == 0 ? "" : ","), _name[sorted_tags[i]]);
85-
}
86-
out->cr();
87-
}
87+
static LogTagTypeChecker logtagtypechecker; // Assert LogTag tags are set up as expected during static initialization
88+
#endif // ASSERT

‎src/hotspot/share/logging/logTag.hpp

+17-16
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@
2727
#include "memory/allocation.hpp"
2828
#include "utilities/globalDefinitions.hpp"
2929

30-
// List of available logging tags. New tags should be added here.
30+
// List of available logging tags. New tags should be added here, in
31+
// alphabetical order.
3132
// (The tags 'all', 'disable' and 'help' are special tags that can
3233
// not be used in log calls, and should not be listed below.)
3334
#define LOG_TAG_LIST \
3435
LOG_TAG(add) \
3536
LOG_TAG(age) \
3637
LOG_TAG(alloc) \
37-
LOG_TAG(aot) \
3838
LOG_TAG(annotation) \
39+
LOG_TAG(aot) \
3940
LOG_TAG(arguments) \
4041
LOG_TAG(attach) \
4142
LOG_TAG(barrier) \
@@ -53,8 +54,8 @@
5354
LOG_TAG(compaction) \
5455
LOG_TAG(compilation) \
5556
LOG_TAG(condy) \
56-
LOG_TAG(constraints) \
5757
LOG_TAG(constantpool) \
58+
LOG_TAG(constraints) \
5859
LOG_TAG(container) \
5960
LOG_TAG(coops) \
6061
LOG_TAG(cpu) \
@@ -101,10 +102,11 @@
101102
LOG_TAG(marking) \
102103
LOG_TAG(membername) \
103104
LOG_TAG(memops) \
104-
LOG_TAG(methodcomparator) \
105105
LOG_TAG(metadata) \
106106
LOG_TAG(metaspace) \
107+
LOG_TAG(methodcomparator) \
107108
LOG_TAG(methodhandles) \
109+
LOG_TAG(mirror) \
108110
LOG_TAG(mmu) \
109111
LOG_TAG(module) \
110112
LOG_TAG(monitorinflation) \
@@ -123,34 +125,35 @@
123125
LOG_TAG(os) \
124126
LOG_TAG(owner) \
125127
LOG_TAG(pagesize) \
128+
LOG_TAG(parser) \
126129
LOG_TAG(patch) \
127130
LOG_TAG(path) \
128131
LOG_TAG(perf) \
129132
LOG_TAG(periodic) \
130133
LOG_TAG(phases) \
131134
LOG_TAG(plab) \
135+
LOG_TAG(preorder) /* Trace all classes loaded in order referenced (not loaded) */ \
132136
LOG_TAG(preview) /* Trace loading of preview feature types */ \
133137
LOG_TAG(primitivewrappers) \
134138
LOG_TAG(promotion) \
135-
LOG_TAG(preorder) /* Trace all classes loaded in order referenced (not loaded) */ \
136139
LOG_TAG(protectiondomain) /* "Trace protection domain verification" */ \
137-
LOG_TAG(ref) \
140+
LOG_TAG(ptrqueue) \
141+
LOG_TAG(purge) \
142+
LOG_TAG(record) \
138143
LOG_TAG(redefine) \
144+
LOG_TAG(ref) \
139145
LOG_TAG(refine) \
140146
LOG_TAG(region) \
141147
LOG_TAG(reloc) \
142148
LOG_TAG(remset) \
143-
LOG_TAG(parser) \
144-
LOG_TAG(ptrqueue) \
145-
LOG_TAG(purge) \
146-
LOG_TAG(record) \
147149
LOG_TAG(resolve) \
148150
LOG_TAG(safepoint) \
149151
LOG_TAG(sampling) \
150152
LOG_TAG(scavenge) \
151153
LOG_TAG(sealed) \
152154
LOG_TAG(setting) \
153155
LOG_TAG(smr) \
156+
LOG_TAG(stackmap) \
154157
LOG_TAG(stacktrace) \
155158
LOG_TAG(stackwalk) \
156159
LOG_TAG(start) \
@@ -160,24 +163,22 @@
160163
LOG_TAG(streaming) \
161164
LOG_TAG(stringdedup) \
162165
LOG_TAG(stringtable) \
163-
LOG_TAG(symboltable) \
164-
LOG_TAG(stackmap) \
165166
LOG_TAG(subclass) \
166167
LOG_TAG(survivor) \
167168
LOG_TAG(sweep) \
169+
LOG_TAG(symboltable) \
168170
LOG_TAG(system) \
169171
LOG_TAG(table) \
170172
LOG_TAG(task) \
171173
DEBUG_ONLY(LOG_TAG(test)) \
172174
LOG_TAG(thread) \
173-
LOG_TAG(tlab) \
174175
LOG_TAG(time) \
175176
LOG_TAG(timer) \
177+
LOG_TAG(tlab) \
176178
LOG_TAG(tracking) \
177-
LOG_TAG(update) \
178179
LOG_TAG(unload) /* Trace unloading of classes */ \
179180
LOG_TAG(unshareable) \
180-
LOG_TAG(mirror) \
181+
LOG_TAG(update) \
181182
LOG_TAG(verification) \
182183
LOG_TAG(verify) \
183184
LOG_TAG(vmmutex) \
@@ -227,7 +228,7 @@ class LogTag : public AllStatic {
227228
static void list_tags(outputStream* out);
228229

229230
private:
230-
static const char* _name[];
231+
static const char* const _name[];
231232
};
232233

233234
typedef LogTag::type LogTagType;

0 commit comments

Comments
 (0)
This repository has been archived.