mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 18:44:38 +02:00
8133051: Concurrent refinement threads may be activated and deactivated at random
Establish min threshold step; earlier primary refinement thread activation. Reviewed-by: tschatzl, drwhite, mgerdin, jmasa
This commit is contained in:
parent
633da50166
commit
3079c942b6
9 changed files with 302 additions and 117 deletions
|
@ -29,42 +29,174 @@
|
|||
#include "gc/g1/g1HotCardCache.hpp"
|
||||
#include "gc/g1/g1Predictions.hpp"
|
||||
#include "runtime/java.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
#include "utilities/pair.hpp"
|
||||
#include <math.h>
|
||||
|
||||
ConcurrentG1Refine::ConcurrentG1Refine(G1CollectedHeap* g1h, const G1Predictions* predictor) :
|
||||
_threads(NULL),
|
||||
_sample_thread(NULL),
|
||||
_predictor_sigma(predictor->sigma()),
|
||||
_hot_card_cache(g1h)
|
||||
{
|
||||
// Ergonomically select initial concurrent refinement parameters
|
||||
if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {
|
||||
FLAG_SET_DEFAULT(G1ConcRefinementGreenZone, ParallelGCThreads);
|
||||
// Arbitrary but large limits, to simplify some of the zone calculations.
|
||||
// The general idea is to allow expressions like
|
||||
// MIN2(x OP y, max_XXX_zone)
|
||||
// without needing to check for overflow in "x OP y", because the
|
||||
// ranges for x and y have been restricted.
|
||||
STATIC_ASSERT(sizeof(LP64_ONLY(jint) NOT_LP64(jshort)) <= (sizeof(size_t)/2));
|
||||
const size_t max_yellow_zone = LP64_ONLY(max_jint) NOT_LP64(max_jshort);
|
||||
const size_t max_green_zone = max_yellow_zone / 2;
|
||||
const size_t max_red_zone = INT_MAX; // For dcqs.set_max_completed_queue.
|
||||
STATIC_ASSERT(max_yellow_zone <= max_red_zone);
|
||||
|
||||
// Range check assertions for green zone values.
|
||||
#define assert_zone_constraints_g(green) \
|
||||
do { \
|
||||
size_t azc_g_green = (green); \
|
||||
assert(azc_g_green <= max_green_zone, \
|
||||
"green exceeds max: " SIZE_FORMAT, azc_g_green); \
|
||||
} while (0)
|
||||
|
||||
// Range check assertions for green and yellow zone values.
|
||||
#define assert_zone_constraints_gy(green, yellow) \
|
||||
do { \
|
||||
size_t azc_gy_green = (green); \
|
||||
size_t azc_gy_yellow = (yellow); \
|
||||
assert_zone_constraints_g(azc_gy_green); \
|
||||
assert(azc_gy_yellow <= max_yellow_zone, \
|
||||
"yellow exceeds max: " SIZE_FORMAT, azc_gy_yellow); \
|
||||
assert(azc_gy_green <= azc_gy_yellow, \
|
||||
"green (" SIZE_FORMAT ") exceeds yellow (" SIZE_FORMAT ")", \
|
||||
azc_gy_green, azc_gy_yellow); \
|
||||
} while (0)
|
||||
|
||||
// Range check assertions for green, yellow, and red zone values.
|
||||
#define assert_zone_constraints_gyr(green, yellow, red) \
|
||||
do { \
|
||||
size_t azc_gyr_green = (green); \
|
||||
size_t azc_gyr_yellow = (yellow); \
|
||||
size_t azc_gyr_red = (red); \
|
||||
assert_zone_constraints_gy(azc_gyr_green, azc_gyr_yellow); \
|
||||
assert(azc_gyr_red <= max_red_zone, \
|
||||
"red exceeds max: " SIZE_FORMAT, azc_gyr_red); \
|
||||
assert(azc_gyr_yellow <= azc_gyr_red, \
|
||||
"yellow (" SIZE_FORMAT ") exceeds red (" SIZE_FORMAT ")", \
|
||||
azc_gyr_yellow, azc_gyr_red); \
|
||||
} while (0)
|
||||
|
||||
// Logging tag sequence for refinement control updates.
|
||||
#define CTRL_TAGS gc, ergo, refine
|
||||
|
||||
// For logging zone values, ensuring consistency of level and tags.
|
||||
#define LOG_ZONES(...) log_debug( CTRL_TAGS )(__VA_ARGS__)
|
||||
|
||||
// Package for pair of refinement thread activation and deactivation
|
||||
// thresholds. The activation and deactivation levels are resp. the first
|
||||
// and second values of the pair.
|
||||
typedef Pair<size_t, size_t> Thresholds;
|
||||
inline size_t activation_level(const Thresholds& t) { return t.first; }
|
||||
inline size_t deactivation_level(const Thresholds& t) { return t.second; }
|
||||
|
||||
static Thresholds calc_thresholds(size_t green_zone,
|
||||
size_t yellow_zone,
|
||||
uint worker_i) {
|
||||
double yellow_size = yellow_zone - green_zone;
|
||||
double step = yellow_size / ConcurrentG1Refine::thread_num();
|
||||
if (worker_i == 0) {
|
||||
// Potentially activate worker 0 more aggressively, to keep
|
||||
// available buffers near green_zone value. When yellow_size is
|
||||
// large we don't want to allow a full step to accumulate before
|
||||
// doing any processing, as that might lead to significantly more
|
||||
// than green_zone buffers to be processed by update_rs.
|
||||
step = MIN2(step, ParallelGCThreads / 2.0);
|
||||
}
|
||||
set_green_zone(G1ConcRefinementGreenZone);
|
||||
|
||||
if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {
|
||||
FLAG_SET_DEFAULT(G1ConcRefinementYellowZone, green_zone() * 3);
|
||||
}
|
||||
set_yellow_zone(MAX2(G1ConcRefinementYellowZone, green_zone()));
|
||||
|
||||
if (FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {
|
||||
FLAG_SET_DEFAULT(G1ConcRefinementRedZone, yellow_zone() * 2);
|
||||
}
|
||||
set_red_zone(MAX2(G1ConcRefinementRedZone, yellow_zone()));
|
||||
|
||||
size_t activate_offset = static_cast<size_t>(ceil(step * (worker_i + 1)));
|
||||
size_t deactivate_offset = static_cast<size_t>(floor(step * worker_i));
|
||||
return Thresholds(green_zone + activate_offset,
|
||||
green_zone + deactivate_offset);
|
||||
}
|
||||
|
||||
ConcurrentG1Refine* ConcurrentG1Refine::create(G1CollectedHeap* g1h, CardTableEntryClosure* refine_closure, jint* ecode) {
|
||||
G1CollectorPolicy* policy = g1h->g1_policy();
|
||||
ConcurrentG1Refine* cg1r = new ConcurrentG1Refine(g1h, &policy->predictor());
|
||||
ConcurrentG1Refine::ConcurrentG1Refine(G1CollectedHeap* g1h,
|
||||
size_t green_zone,
|
||||
size_t yellow_zone,
|
||||
size_t red_zone,
|
||||
size_t min_yellow_zone_size) :
|
||||
_threads(NULL),
|
||||
_sample_thread(NULL),
|
||||
_n_worker_threads(thread_num()),
|
||||
_green_zone(green_zone),
|
||||
_yellow_zone(yellow_zone),
|
||||
_red_zone(red_zone),
|
||||
_min_yellow_zone_size(min_yellow_zone_size),
|
||||
_hot_card_cache(g1h)
|
||||
{
|
||||
assert_zone_constraints_gyr(green_zone, yellow_zone, red_zone);
|
||||
}
|
||||
|
||||
static size_t calc_min_yellow_zone_size() {
|
||||
size_t step = G1ConcRefinementThresholdStep;
|
||||
uint n_workers = ConcurrentG1Refine::thread_num();
|
||||
if ((max_yellow_zone / step) < n_workers) {
|
||||
return max_yellow_zone;
|
||||
} else {
|
||||
return step * n_workers;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t calc_init_green_zone() {
|
||||
size_t green = G1ConcRefinementGreenZone;
|
||||
if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {
|
||||
green = ParallelGCThreads;
|
||||
}
|
||||
return MIN2(green, max_green_zone);
|
||||
}
|
||||
|
||||
static size_t calc_init_yellow_zone(size_t green, size_t min_size) {
|
||||
size_t config = G1ConcRefinementYellowZone;
|
||||
size_t size = 0;
|
||||
if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {
|
||||
size = green * 2;
|
||||
} else if (green < config) {
|
||||
size = config - green;
|
||||
}
|
||||
size = MAX2(size, min_size);
|
||||
size = MIN2(size, max_yellow_zone);
|
||||
return MIN2(green + size, max_yellow_zone);
|
||||
}
|
||||
|
||||
static size_t calc_init_red_zone(size_t green, size_t yellow) {
|
||||
size_t size = yellow - green;
|
||||
if (!FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {
|
||||
size_t config = G1ConcRefinementRedZone;
|
||||
if (yellow < config) {
|
||||
size = MAX2(size, config - yellow);
|
||||
}
|
||||
}
|
||||
return MIN2(yellow + size, max_red_zone);
|
||||
}
|
||||
|
||||
ConcurrentG1Refine* ConcurrentG1Refine::create(G1CollectedHeap* g1h,
|
||||
CardTableEntryClosure* refine_closure,
|
||||
jint* ecode) {
|
||||
size_t min_yellow_zone_size = calc_min_yellow_zone_size();
|
||||
size_t green_zone = calc_init_green_zone();
|
||||
size_t yellow_zone = calc_init_yellow_zone(green_zone, min_yellow_zone_size);
|
||||
size_t red_zone = calc_init_red_zone(green_zone, yellow_zone);
|
||||
|
||||
LOG_ZONES("Initial Refinement Zones: "
|
||||
"green: " SIZE_FORMAT ", "
|
||||
"yellow: " SIZE_FORMAT ", "
|
||||
"red: " SIZE_FORMAT ", "
|
||||
"min yellow size: " SIZE_FORMAT,
|
||||
green_zone, yellow_zone, red_zone, min_yellow_zone_size);
|
||||
|
||||
ConcurrentG1Refine* cg1r = new ConcurrentG1Refine(g1h,
|
||||
green_zone,
|
||||
yellow_zone,
|
||||
red_zone,
|
||||
min_yellow_zone_size);
|
||||
|
||||
if (cg1r == NULL) {
|
||||
*ecode = JNI_ENOMEM;
|
||||
vm_shutdown_during_initialization("Could not create ConcurrentG1Refine");
|
||||
return NULL;
|
||||
}
|
||||
cg1r->_n_worker_threads = thread_num();
|
||||
|
||||
cg1r->reset_threshold_step();
|
||||
|
||||
cg1r->_threads = NEW_C_HEAP_ARRAY_RETURN_NULL(ConcurrentG1RefineThread*, cg1r->_n_worker_threads, mtGC);
|
||||
if (cg1r->_threads == NULL) {
|
||||
|
@ -77,7 +209,15 @@ ConcurrentG1Refine* ConcurrentG1Refine::create(G1CollectedHeap* g1h, CardTableEn
|
|||
|
||||
ConcurrentG1RefineThread *next = NULL;
|
||||
for (uint i = cg1r->_n_worker_threads - 1; i != UINT_MAX; i--) {
|
||||
ConcurrentG1RefineThread* t = new ConcurrentG1RefineThread(cg1r, next, refine_closure, worker_id_offset, i);
|
||||
Thresholds thresholds = calc_thresholds(green_zone, yellow_zone, i);
|
||||
ConcurrentG1RefineThread* t =
|
||||
new ConcurrentG1RefineThread(cg1r,
|
||||
next,
|
||||
refine_closure,
|
||||
worker_id_offset,
|
||||
i,
|
||||
activation_level(thresholds),
|
||||
deactivation_level(thresholds));
|
||||
assert(t != NULL, "Conc refine should have been created");
|
||||
if (t->osthread() == NULL) {
|
||||
*ecode = JNI_ENOMEM;
|
||||
|
@ -101,14 +241,6 @@ ConcurrentG1Refine* ConcurrentG1Refine::create(G1CollectedHeap* g1h, CardTableEn
|
|||
return cg1r;
|
||||
}
|
||||
|
||||
void ConcurrentG1Refine::reset_threshold_step() {
|
||||
if (FLAG_IS_DEFAULT(G1ConcRefinementThresholdStep)) {
|
||||
_thread_threshold_step = (yellow_zone() - green_zone()) / (worker_thread_num() + 1);
|
||||
} else {
|
||||
_thread_threshold_step = G1ConcRefinementThresholdStep;
|
||||
}
|
||||
}
|
||||
|
||||
void ConcurrentG1Refine::init(G1RegionToSpaceMapper* card_counts_storage) {
|
||||
_hot_card_cache.initialize(card_counts_storage);
|
||||
}
|
||||
|
@ -120,10 +252,11 @@ void ConcurrentG1Refine::stop() {
|
|||
_sample_thread->stop();
|
||||
}
|
||||
|
||||
void ConcurrentG1Refine::reinitialize_threads() {
|
||||
reset_threshold_step();
|
||||
void ConcurrentG1Refine::update_thread_thresholds() {
|
||||
for (uint i = 0; i < _n_worker_threads; i++) {
|
||||
_threads[i]->initialize();
|
||||
Thresholds thresholds = calc_thresholds(_green_zone, _yellow_zone, i);
|
||||
_threads[i]->update_thresholds(activation_level(thresholds),
|
||||
deactivation_level(thresholds));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +275,7 @@ void ConcurrentG1Refine::threads_do(ThreadClosure *tc) {
|
|||
}
|
||||
|
||||
void ConcurrentG1Refine::worker_threads_do(ThreadClosure * tc) {
|
||||
for (uint i = 0; i < worker_thread_num(); i++) {
|
||||
for (uint i = 0; i < _n_worker_threads; i++) {
|
||||
tc->do_thread(_threads[i]);
|
||||
}
|
||||
}
|
||||
|
@ -160,34 +293,80 @@ void ConcurrentG1Refine::print_worker_threads_on(outputStream* st) const {
|
|||
st->cr();
|
||||
}
|
||||
|
||||
static size_t calc_new_green_zone(size_t green,
|
||||
double update_rs_time,
|
||||
size_t update_rs_processed_buffers,
|
||||
double goal_ms) {
|
||||
// Adjust green zone based on whether we're meeting the time goal.
|
||||
// Limit to max_green_zone.
|
||||
const double inc_k = 1.1, dec_k = 0.9;
|
||||
if (update_rs_time > goal_ms) {
|
||||
if (green > 0) {
|
||||
green = static_cast<size_t>(green * dec_k);
|
||||
}
|
||||
} else if (update_rs_time < goal_ms &&
|
||||
update_rs_processed_buffers > green) {
|
||||
green = static_cast<size_t>(MAX2(green * inc_k, green + 1.0));
|
||||
green = MIN2(green, max_green_zone);
|
||||
}
|
||||
return green;
|
||||
}
|
||||
|
||||
static size_t calc_new_yellow_zone(size_t green, size_t min_yellow_size) {
|
||||
size_t size = green * 2;
|
||||
size = MAX2(size, min_yellow_size);
|
||||
return MIN2(green + size, max_yellow_zone);
|
||||
}
|
||||
|
||||
static size_t calc_new_red_zone(size_t green, size_t yellow) {
|
||||
return MIN2(yellow + (yellow - green), max_red_zone);
|
||||
}
|
||||
|
||||
void ConcurrentG1Refine::update_zones(double update_rs_time,
|
||||
size_t update_rs_processed_buffers,
|
||||
double goal_ms) {
|
||||
log_trace( CTRL_TAGS )("Updating Refinement Zones: "
|
||||
"update_rs time: %.3fms, "
|
||||
"update_rs buffers: " SIZE_FORMAT ", "
|
||||
"update_rs goal time: %.3fms",
|
||||
update_rs_time,
|
||||
update_rs_processed_buffers,
|
||||
goal_ms);
|
||||
|
||||
_green_zone = calc_new_green_zone(_green_zone,
|
||||
update_rs_time,
|
||||
update_rs_processed_buffers,
|
||||
goal_ms);
|
||||
_yellow_zone = calc_new_yellow_zone(_green_zone, _min_yellow_zone_size);
|
||||
_red_zone = calc_new_red_zone(_green_zone, _yellow_zone);
|
||||
|
||||
assert_zone_constraints_gyr(_green_zone, _yellow_zone, _red_zone);
|
||||
LOG_ZONES("Updated Refinement Zones: "
|
||||
"green: " SIZE_FORMAT ", "
|
||||
"yellow: " SIZE_FORMAT ", "
|
||||
"red: " SIZE_FORMAT,
|
||||
_green_zone, _yellow_zone, _red_zone);
|
||||
}
|
||||
|
||||
void ConcurrentG1Refine::adjust(double update_rs_time,
|
||||
double update_rs_processed_buffers,
|
||||
size_t update_rs_processed_buffers,
|
||||
double goal_ms) {
|
||||
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
|
||||
|
||||
if (G1UseAdaptiveConcRefinement) {
|
||||
const int k_gy = 3, k_gr = 6;
|
||||
const double inc_k = 1.1, dec_k = 0.9;
|
||||
update_zones(update_rs_time, update_rs_processed_buffers, goal_ms);
|
||||
update_thread_thresholds();
|
||||
|
||||
size_t g = green_zone();
|
||||
if (update_rs_time > goal_ms) {
|
||||
g = (size_t)(g * dec_k); // Can become 0, that's OK. That would mean a mutator-only processing.
|
||||
} else {
|
||||
if (update_rs_time < goal_ms && update_rs_processed_buffers > g) {
|
||||
g = (size_t)MAX2(g * inc_k, g + 1.0);
|
||||
}
|
||||
}
|
||||
// Change the refinement threads params
|
||||
set_green_zone(g);
|
||||
set_yellow_zone(g * k_gy);
|
||||
set_red_zone(g * k_gr);
|
||||
reinitialize_threads();
|
||||
|
||||
size_t processing_threshold_delta = MAX2<size_t>(green_zone() * _predictor_sigma, 1);
|
||||
size_t processing_threshold = MIN2(green_zone() + processing_threshold_delta,
|
||||
yellow_zone());
|
||||
// Change the barrier params
|
||||
dcqs.set_process_completed_threshold((int)processing_threshold);
|
||||
if (_n_worker_threads == 0) {
|
||||
// Disable dcqs notification when there are no threads to notify.
|
||||
dcqs.set_process_completed_threshold(INT_MAX);
|
||||
} else {
|
||||
// Worker 0 is the primary; wakeup is via dcqs notification.
|
||||
STATIC_ASSERT(max_yellow_zone <= INT_MAX);
|
||||
size_t activate = _threads[0]->activation_threshold();
|
||||
dcqs.set_process_completed_threshold((int)activate);
|
||||
}
|
||||
dcqs.set_max_completed_queue((int)red_zone());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue