From 12932a1d339ca9418ad0ee9f05a17da92598f0a4 Mon Sep 17 00:00:00 2001 From: Glavo Date: Wed, 12 Jan 2022 20:08:49 +0800 Subject: [PATCH] Adjust the policy of automatic memory allocation --- .../jackhuang/hmcl/game/HMCLGameRepository.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java index f298f9a80..e11262d86 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java @@ -454,6 +454,20 @@ public class HMCLGameRepository extends DefaultGameRepository { } public static long getAllocatedMemory(long minimum, long available, boolean auto) { - return auto ? Math.max(minimum, (long) (available * 0.8)) : minimum; + if (auto) { + available -= 256 * 1024 * 1024; // Reserve 256MB memory for off-heap memory and HMCL itself + if (available <= 0) { + return minimum; + } + + final long threshold = 8L * 1024 * 1024 * 1024; + final long suggested = Math.min(available <= threshold + ? (long) (available * 0.8) + : (long) (threshold * 0.8 + (available - threshold) * 0.2), + 32736L * 1024 * 1024); // Limit the maximum suggested memory to ensure that compressed oops are available + return Math.max(minimum, suggested); + } else { + return minimum; + } } }