On Thu, 21 Jul 2022 15:37:40 GMT, Сергей Цыпанов <d...@openjdk.org> wrote:

> We can use `InputStream.readAllBytes()` in `ModuleHashes` and `X509CertPath`.

By "surrogate code" I mean hand-written snippets reading all the bytes from an 
InputStream.

> It means the whole content from the input stream is read into a single array 
> and this could lead to a sudden peak memory usage if the size is big.

`InputStream.readAllBytes()` reads data from the InputStream in chunks of 8192 
bytes, then combines them into one resulting array which is returned. In theory 
this could lead even to OOME in case the size the resulting array exceeds 
`Integer.MAX_VALUE`, I doubt however this would ever happen.

I've looked into the history of `ModulerHashes`: prior to `byte[]` it used 
`ByteBuffer` of the same size (32 kB) as intermediate storage. I think 
digesting all the data at once might be faster than doing it chunk by chunk, on 
the other hand I understand memory concern.

Can I reliably measure it somehow?

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

PR: https://git.openjdk.org/jdk/pull/9596

Reply via email to