From 142c311e3b9bd3f00edaa6ba7bcbc9fc285ee9b9 Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Mon, 25 Mar 2024 13:04:07 +0000 Subject: [PATCH] 8328744: Parallel: Parallel GC throws OOM before heap is fully expanded Reviewed-by: ayang, tschatzl --- src/hotspot/share/gc/parallel/psScavenge.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/gc/parallel/psScavenge.cpp b/src/hotspot/share/gc/parallel/psScavenge.cpp index 926006a8a0e..78fba1dfe72 100644 --- a/src/hotspot/share/gc/parallel/psScavenge.cpp +++ b/src/hotspot/share/gc/parallel/psScavenge.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, 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 @@ -702,12 +702,14 @@ bool PSScavenge::should_attempt_scavenge() { size_t avg_promoted = (size_t) policy->padded_average_promoted_in_bytes(); size_t promotion_estimate = MIN2(avg_promoted, young_gen->used_in_bytes()); - bool result = promotion_estimate < old_gen->free_in_bytes(); + // Total free size after possible old gen expansion + size_t free_in_old_gen = old_gen->max_gen_size() - old_gen->used_in_bytes(); + bool result = promotion_estimate < free_in_old_gen; log_trace(ergo)("%s scavenge: average_promoted " SIZE_FORMAT " padded_average_promoted " SIZE_FORMAT " free in old gen " SIZE_FORMAT, result ? "Do" : "Skip", (size_t) policy->average_promoted_in_bytes(), (size_t) policy->padded_average_promoted_in_bytes(), - old_gen->free_in_bytes()); + free_in_old_gen); if (young_gen->used_in_bytes() < (size_t) policy->padded_average_promoted_in_bytes()) { log_trace(ergo)(" padded_promoted_average is greater than maximum promotion = " SIZE_FORMAT, young_gen->used_in_bytes()); }