# HG changeset patch # User akasko # Date 1457997813 14400 # Mon Mar 14 19:23:33 2016 -0400 # Node ID 253460b60724e7d352515caaae8e95b641d835fd # Parent 1640de0263f71e4153ae7bb427c704b76c59f6d6 8151848: Higher native memory usage caused by upgrade to zlib 1.2.8 Reviewed-by: sherman Contributed-by: nikolay@azulsystems.com diff --git a/src/java.base/share/native/libjli/parse_manifest.c b/src/java.base/share/native/libjli/parse_manifest.c --- a/src/java.base/share/native/libjli/parse_manifest.c +++ b/src/java.base/share/native/libjli/parse_manifest.c @@ -91,7 +91,7 @@ } zs.next_out = (Byte*)out; zs.avail_out = (uInt)entry->isize; - if (inflate(&zs, Z_PARTIAL_FLUSH) < 0) { + if (inflate(&zs, Z_FINISH) != Z_STREAM_END) { free(in); free(out); return (NULL); diff --git a/src/java.base/share/native/libzip/Inflater.c b/src/java.base/share/native/libzip/Inflater.c --- a/src/java.base/share/native/libzip/Inflater.c +++ b/src/java.base/share/native/libzip/Inflater.c @@ -147,15 +147,22 @@ strm->next_out = (Bytef *) (out_buf + off); strm->avail_in = this_len; strm->avail_out = len; - ret = inflate(strm, Z_PARTIAL_FLUSH); + + /* The flush parameter of inflate() is set to Z_FINISH to skip + the allocation of a sliding window until necessary. */ + ret = inflate(strm, Z_FINISH); (*env)->ReleasePrimitiveArrayCritical(env, b, out_buf, 0); (*env)->ReleasePrimitiveArrayCritical(env, this_buf, in_buf, 0); + /* When flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it + will return Z_BUF_ERROR if it has not reached the end of the stream. + Here we keep the same processing for both these return codes. */ switch (ret) { case Z_STREAM_END: (*env)->SetBooleanField(env, this, finishedID, JNI_TRUE); /* fall through */ case Z_OK: + case Z_BUF_ERROR: this_off += this_len - strm->avail_in; (*env)->SetIntField(env, this, offID, this_off); (*env)->SetIntField(env, this, lenID, strm->avail_in); @@ -167,8 +174,6 @@ (*env)->SetIntField(env, this, offID, this_off); (*env)->SetIntField(env, this, lenID, strm->avail_in); return 0; - case Z_BUF_ERROR: - return 0; case Z_DATA_ERROR: ThrowDataFormatException(env, strm->msg); return 0; diff --git a/src/java.base/share/native/libzip/zip_util.c b/src/java.base/share/native/libzip/zip_util.c --- a/src/java.base/share/native/libzip/zip_util.c +++ b/src/java.base/share/native/libzip/zip_util.c @@ -1404,9 +1404,7 @@ strm.next_in = (Bytef *)tmp; strm.avail_in = n; do { - switch (inflate(&strm, Z_PARTIAL_FLUSH)) { - case Z_OK: - break; + switch (inflate(&strm, Z_FINISH)) { case Z_STREAM_END: if (count != 0 || strm.total_out != entry->size) { *msg = "inflateFully: Unexpected end of stream"; @@ -1524,8 +1522,9 @@ strm.avail_in = (uInt)inLen; do { - switch (inflate(&strm, Z_PARTIAL_FLUSH)) { + switch (inflate(&strm, Z_FINISH)) { case Z_OK: + case Z_BUF_ERROR: break; case Z_STREAM_END: if (strm.total_out != outLen) { diff --git a/src/jdk.pack200/share/native/common-unpack/zip.cpp b/src/jdk.pack200/share/native/common-unpack/zip.cpp --- a/src/jdk.pack200/share/native/common-unpack/zip.cpp +++ b/src/jdk.pack200/share/native/common-unpack/zip.cpp @@ -545,8 +545,11 @@ zs.avail_in = (int) read_gzin_fn(u, inbuf, 1, inbuflen); zs.next_in = (uchar*) inbuf; } - int error = inflate(&zs, Z_NO_FLUSH); - if (error != Z_OK && error != Z_STREAM_END) { + // When flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it + // will return Z_BUF_ERROR if it has not reached the end of the stream. + // So, the only normal return codes are Z_BUF_ERROR and Z_STREAM_END. + int error = inflate(&zs, Z_FINISH); + if (error != Z_BUF_ERROR && error != Z_STREAM_END) { u->abort("error inflating input"); break; }