8150629: Initializing all ParScanThreadStates causes significant unaccounted "Other" times
Summary: Lazily allocate ParScanThreadStates within the worker threads instead of doing this work upfront serially.
Reviewed-by: mgerdin, jmasa
--- a/hotspot/src/share/vm/gc/g1/g1ParScanThreadState.cpp Fri Feb 26 13:02:30 2016 +0100
+++ b/hotspot/src/share/vm/gc/g1/g1ParScanThreadState.cpp Fri Feb 26 13:02:30 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, 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
@@ -327,6 +327,9 @@
G1ParScanThreadState* G1ParScanThreadStateSet::state_for_worker(uint worker_id) {
assert(worker_id < _n_workers, "out of bounds access");
+ if (_states[worker_id] == NULL) {
+ _states[worker_id] = new_par_scan_state(worker_id, _young_cset_length);
+ }
return _states[worker_id];
}
@@ -352,6 +355,10 @@
for (uint worker_index = 0; worker_index < _n_workers; ++worker_index) {
G1ParScanThreadState* pss = _states[worker_index];
+ if (pss == NULL) {
+ continue;
+ }
+
_total_cards_scanned += _cards_scanned[worker_index];
pss->flush(_surviving_young_words_total);
--- a/hotspot/src/share/vm/gc/g1/g1ParScanThreadState.hpp Fri Feb 26 13:02:30 2016 +0100
+++ b/hotspot/src/share/vm/gc/g1/g1ParScanThreadState.hpp Fri Feb 26 13:02:30 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, 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
@@ -200,6 +200,7 @@
size_t* _surviving_young_words_total;
size_t* _cards_scanned;
size_t _total_cards_scanned;
+ size_t _young_cset_length;
uint _n_workers;
bool _flushed;
@@ -210,10 +211,11 @@
_surviving_young_words_total(NEW_C_HEAP_ARRAY(size_t, young_cset_length, mtGC)),
_cards_scanned(NEW_C_HEAP_ARRAY(size_t, n_workers, mtGC)),
_total_cards_scanned(0),
+ _young_cset_length(young_cset_length),
_n_workers(n_workers),
_flushed(false) {
for (uint i = 0; i < n_workers; ++i) {
- _states[i] = new_par_scan_state(i, young_cset_length);
+ _states[i] = NULL;
}
memset(_surviving_young_words_total, 0, young_cset_length * sizeof(size_t));
memset(_cards_scanned, 0, n_workers * sizeof(size_t));