src/hotspot/share/logging/logTag.cpp
changeset 49015 a12c9536d8a6
parent 47216 71c04702a3d5
child 49163 580bb0b85f63
--- a/src/hotspot/share/logging/logTag.cpp	Fri Dec 08 13:47:08 2017 +0100
+++ b/src/hotspot/share/logging/logTag.cpp	Mon Feb 19 09:16:04 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,8 @@
 #include "precompiled.hpp"
 #include "logging/logTag.hpp"
 #include "utilities/globalDefinitions.hpp"
+#include "utilities/ostream.hpp"
+#include "utilities/quickSort.hpp"
 
 const char* LogTag::_name[] = {
   "", // __NO_TAG
@@ -40,3 +42,29 @@
   }
   return __NO_TAG;
 }
+
+static int cmp_logtag(LogTagType a, LogTagType b) {
+  return strcmp(LogTag::name(a), LogTag::name(b));
+}
+
+static const size_t sorted_tagcount = LogTag::Count - 1; // Not counting _NO_TAG
+static LogTagType sorted_tags[sorted_tagcount];
+
+class TagSorter {
+ public:
+  TagSorter() {
+    for (size_t i = 1; i < LogTag::Count; i++) {
+      sorted_tags[i - 1] = static_cast<LogTagType>(i);
+    }
+    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();
+}