8383772: runtime/reflect/ReflectOutOfMemoryError.java can fail intermittently on Shenandoah with small heaps

Reviewed-by: kdnilsen, wkemper
This commit is contained in:
Xiaolong Peng 2026-05-04 16:57:38 +00:00
parent 3ba94aec79
commit 14bdfeb08c

View File

@ -38,7 +38,8 @@ public class ReflectOutOfMemoryError {
try {
// Repository for objects, which should be allocated:
int index = 0;
for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
// Halving loop starting from max possible size constrained by max heap size
for (int size = (int)(Runtime.getRuntime().maxMemory()>>2); size > 0 && pool == null; size >>= 1)
try {
pool = new Object[size];
} catch (OutOfMemoryError oome) {