RFR: 6478546: FileInputStream.read() throws OutOfMemoryError when there is plenty available

Brian Burkhalter bpb at openjdk.org
Tue Jul 25 02:12:52 UTC 2023


On Mon, 24 Jul 2023 13:16:56 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Limit native memory allocation and move write loop from the native layer into Java. This change should make the OOME reported in the issue much less likely.
>
> src/java.base/share/native/libjava/io_util.c line 62:
> 
>> 60: /* The maximum size of a dynamically-allocated buffer.
>> 61:  */
>> 62: #define MAX_MALLOC_SIZE 2097152
> 
> How did you choose 2Mb, it seems high.

It's based on micro-benchmarks. Having the loops in Java reduces throughput but allocating memory using `malloc(len)` also reduces throughput as `len` gets larger and this threshold appears to balance the two.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14981#discussion_r1272921060


More information about the security-dev mailing list