Skip to content

Commit 8e338f6

Browse files
committedSep 28, 2020
8253646: ZGC: Avoid overhead of sorting ZStatIterableValues on bootstrap
Reviewed-by: pliden, eosterlund
1 parent ec9bee6 commit 8e338f6

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed
 

‎src/hotspot/share/gc/z/zStat.cpp

+28-13
Original file line numberDiff line numberDiff line change
@@ -390,22 +390,35 @@ ZStatIterableValue<T>::ZStatIterableValue(const char* group,
390390

391391
template <typename T>
392392
T* ZStatIterableValue<T>::insert() const {
393-
T** current = &_first;
393+
T* const next = _first;
394+
_first = (T*)this;
395+
return next;
396+
}
394397

395-
while (*current != NULL) {
396-
// First sort by group, then by name
397-
const int group_cmp = strcmp((*current)->group(), group());
398-
const int name_cmp = strcmp((*current)->name(), name());
399-
if ((group_cmp > 0) || (group_cmp == 0 && name_cmp > 0)) {
400-
break;
401-
}
398+
template <typename T>
399+
void ZStatIterableValue<T>::sort() {
400+
T* first_unsorted = _first;
401+
_first = NULL;
402+
403+
while (first_unsorted != NULL) {
404+
T* const value = first_unsorted;
405+
first_unsorted = value->_next;
406+
value->_next = NULL;
407+
408+
T** current = &_first;
409+
410+
while (*current != NULL) {
411+
// First sort by group, then by name
412+
const int group_cmp = strcmp((*current)->group(), value->group());
413+
if ((group_cmp > 0) || (group_cmp == 0 && strcmp((*current)->name(), value->name()) > 0)) {
414+
break;
415+
}
402416

403-
current = &(*current)->_next;
417+
current = &(*current)->_next;
418+
}
419+
value->_next = *current;
420+
*current = value;
404421
}
405-
406-
T* const next = *current;
407-
*current = (T*)this;
408-
return next;
409422
}
410423

411424
//
@@ -882,6 +895,8 @@ void ZStat::run_service() {
882895
ZStatSamplerHistory* const history = new ZStatSamplerHistory[ZStatSampler::count()];
883896
LogTarget(Info, gc, stats) log;
884897

898+
ZStatSampler::sort();
899+
885900
// Main loop
886901
while (_metronome.wait_for_tick()) {
887902
sample_and_collect(history);

‎src/hotspot/share/gc/z/zStat.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class ZStatIterableValue : public ZStatValue {
101101
uint32_t size);
102102

103103
public:
104+
static void sort();
105+
104106
static uint32_t count() {
105107
return _count;
106108
}

0 commit comments

Comments
 (0)
Please sign in to comment.