diff --git a/src/hotspot/share/gc/z/zStat.cpp b/src/hotspot/share/gc/z/zStat.cpp index 21eacbe2b52..183e8d5bcc4 100644 --- a/src/hotspot/share/gc/z/zStat.cpp +++ b/src/hotspot/share/gc/z/zStat.cpp @@ -390,24 +390,37 @@ ZStatIterableValue::ZStatIterableValue(const char* group, template T* ZStatIterableValue::insert() const { - T** current = &_first; - - while (*current != NULL) { - // First sort by group, then by name - const int group_cmp = strcmp((*current)->group(), group()); - const int name_cmp = strcmp((*current)->name(), name()); - if ((group_cmp > 0) || (group_cmp == 0 && name_cmp > 0)) { - break; - } - - current = &(*current)->_next; - } - - T* const next = *current; - *current = (T*)this; + T* const next = _first; + _first = (T*)this; return next; } +template +void ZStatIterableValue::sort() { + T* first_unsorted = _first; + _first = NULL; + + while (first_unsorted != NULL) { + T* const value = first_unsorted; + first_unsorted = value->_next; + value->_next = NULL; + + T** current = &_first; + + while (*current != NULL) { + // First sort by group, then by name + const int group_cmp = strcmp((*current)->group(), value->group()); + if ((group_cmp > 0) || (group_cmp == 0 && strcmp((*current)->name(), value->name()) > 0)) { + break; + } + + current = &(*current)->_next; + } + value->_next = *current; + *current = value; + } +} + // // Stat sampler // @@ -882,6 +895,8 @@ void ZStat::run_service() { ZStatSamplerHistory* const history = new ZStatSamplerHistory[ZStatSampler::count()]; LogTarget(Info, gc, stats) log; + ZStatSampler::sort(); + // Main loop while (_metronome.wait_for_tick()) { sample_and_collect(history); diff --git a/src/hotspot/share/gc/z/zStat.hpp b/src/hotspot/share/gc/z/zStat.hpp index 9220327f6f7..3faac3b8ea5 100644 --- a/src/hotspot/share/gc/z/zStat.hpp +++ b/src/hotspot/share/gc/z/zStat.hpp @@ -101,6 +101,8 @@ protected: uint32_t size); public: + static void sort(); + static uint32_t count() { return _count; }