mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 02:54:35 +02:00
8144527: NewSizeThreadIncrease would make an overflow
Revert to previous value if NewSizeThreadIncrease related calculation overflows Reviewed-by: jwilhelm, mgerdin, mchernov
This commit is contained in:
parent
73c45490a2
commit
7479dffbc6
3 changed files with 168 additions and 6 deletions
|
@ -364,6 +364,36 @@ bool DefNewGeneration::expand(size_t bytes) {
|
|||
return success;
|
||||
}
|
||||
|
||||
size_t DefNewGeneration::adjust_for_thread_increase(size_t new_size_candidate,
|
||||
size_t new_size_before,
|
||||
size_t alignment) const {
|
||||
size_t desired_new_size = new_size_before;
|
||||
|
||||
if (NewSizeThreadIncrease > 0) {
|
||||
int threads_count;
|
||||
size_t thread_increase_size = 0;
|
||||
|
||||
// 1. Check an overflow at 'threads_count * NewSizeThreadIncrease'.
|
||||
threads_count = Threads::number_of_non_daemon_threads();
|
||||
if (NewSizeThreadIncrease <= max_uintx / threads_count) {
|
||||
thread_increase_size = threads_count * NewSizeThreadIncrease;
|
||||
|
||||
// 2. Check an overflow at 'new_size_candidate + thread_increase_size'.
|
||||
if (new_size_candidate <= max_uintx - thread_increase_size) {
|
||||
new_size_candidate += thread_increase_size;
|
||||
|
||||
// 3. Check an overflow at 'align_size_up'.
|
||||
size_t aligned_max = ((max_uintx - alignment) & ~(alignment-1));
|
||||
if (new_size_candidate <= aligned_max) {
|
||||
desired_new_size = align_size_up(new_size_candidate, alignment);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return desired_new_size;
|
||||
}
|
||||
|
||||
void DefNewGeneration::compute_new_size() {
|
||||
// This is called after a GC that includes the old generation, so from-space
|
||||
// will normally be empty.
|
||||
|
@ -385,12 +415,13 @@ void DefNewGeneration::compute_new_size() {
|
|||
// All space sizes must be multiples of Generation::GenGrain.
|
||||
size_t alignment = Generation::GenGrain;
|
||||
|
||||
// Compute desired new generation size based on NewRatio and
|
||||
// NewSizeThreadIncrease
|
||||
size_t desired_new_size = old_size/NewRatio;
|
||||
int threads_count = Threads::number_of_non_daemon_threads();
|
||||
size_t thread_increase_size = threads_count * NewSizeThreadIncrease;
|
||||
desired_new_size = align_size_up(desired_new_size + thread_increase_size, alignment);
|
||||
int threads_count = 0;
|
||||
size_t thread_increase_size = 0;
|
||||
|
||||
size_t new_size_candidate = old_size / NewRatio;
|
||||
// Compute desired new generation size based on NewRatio and NewSizeThreadIncrease
|
||||
// and reverts to previous value if any overflow happens
|
||||
size_t desired_new_size = adjust_for_thread_increase(new_size_candidate, new_size_before, alignment);
|
||||
|
||||
// Adjust new generation size
|
||||
desired_new_size = MAX2(MIN2(desired_new_size, max_new_size), min_new_size);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue