8340814: ZipFileInflaterInputStream should release its Inflater after observing EOF #21157
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please consider this PR which makes
ZipFileInflaterInputStream
release itsInflater
instance back to the pool when observing that the stream has been fully consumed.This is motivated by the following observations:
ZipFileInflaterInputStream
has reached the end of stream, itsInflater
instance no longer does useful work.ZipFile::getInputStream
without properly closing it is probably common. Obtaining it without fully consuming it is probably more rare. (Something likeclassLoader.getInputStream(entry).readAllBytes()
is probably common)Inflater
when theCleaner
closes the stream, this will only happen at some later point in time. In the meantime,ZipFile::getInputStream
may produce many newInflater
instances. These will all be released to the pool once GC eventually catches up.Inflater
is released to to pool, it will stay there for the lifetime of theZipFile
ZipFile
may often be as long as the application (consider class loaders).This PR suggests the following changes:
ZipFileInflaterInputStream.eof
tocompressedEof
. (This tracks the EOF of the filtered input stream)ZipFileInflaterInputStream.eof
to track the EOF of uncompressed data.ZipFileInflaterInputStream.read(byte[] b, int off, int len)
to detect the EOF of uncompressed data and release theInflater
instance back to the pool when it is no longer needed.Inflater
instance from being used after being released and reset, the following updates are needed:ZipFileInflaterInputStream.read
must check if EOF has been reached but that the stream has not yet been closed. In this case, EOF should be returned.ZipFileInflaterInputStream.available
needs an update to return 0 if EOF has been detected.The PR adds a test
ReleaseInflaterOnEOF
which verifies that all fully consumed input streams are backed by the sameInflater
instance.This PR was inspired by JDK-7031076 and this discussion: https://mail.openjdk.org/pipermail/core-libs-dev/2011-March/006341.html
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21157/head:pull/21157
$ git checkout pull/21157
Update a local copy of the PR:
$ git checkout pull/21157
$ git pull https://git.openjdk.org/jdk.git pull/21157/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 21157
View PR using the GUI difftool:
$ git pr show -t 21157
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21157.diff
Webrev
Link to Webrev Comment