On Tue, 11 Mar 2025 22:11:02 GMT, Harshitha Onkar <hon...@openjdk.org> wrote:

>I think @azuev-java has a valid point here. It might be better to check if 
>enough memory is available upfront rather than end up with OOME later on.

I think this is the first use of the totalMemory/freeMemory combination in the 
JDK codebase. It’s essentially code that tries to emulate what the JVM already 
does best. If totalSize is trusted and we want to check it, we can simply 
allocate data - gc will have a chance to clean up memory and report whether 
allocation is possible or not we can catch that . This approach will work 
reliably in multithreaded code as well.

The current solution may throw an exception even when we could produce correct 
data, and it may pass in cases where we run into an OOM later.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23814#issuecomment-2722956952

Reply via email to