JDK-8231770 : Test java/util/zip/FlaterTest.java fails with -Xcheck:jni
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 11,13,14
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2019-10-02
  • Updated: 2020-06-01
  • Resolved: 2019-10-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 13 JDK 14
11.0.6-oracleFixed 13.0.2Fixed 14 b18Fixed
Related Reports
Relates :  
Description
The -Xcheck:jni option is an option that performs extra checks JNI code.  It's frequently given to customers to determine whether they have a bug in their JNI code, which may cause some other problem.  Running the jdk tests with this option causes this test failure:
stdout: FATAL ERROR in native method: ReleasePrimitiveArrayCritical: unrecognized elements

The -Xcheck:jni code checks the guard wrapper around the memory return by ReleasePrimitiveArrayCritical, matches that allocated with GetPrimitiveArrayCritical.  Since there's no tag in this wrapper it looks like the memory wasn't allocated with GetPrimitiveArrayCritical (?)

Running test 'jtreg:open/test/jdk/java/util/zip/FlaterTest.java'
[2019-10-02 14:39:50,597] Agent[1]: stdout: ReleasePrimitiveArrayCritical: unrecognized elements. array: 0x00002af048982db0 carray: 0x00002af0489c8030
[2019-10-02 14:39:50,597] Agent[1]: stdout: GuardedMemory(0x00002af048982b80) base_addr=0x00002af0489c8010 tag=0x0000000000000000 user_size=1048576 user_data=0x00002af0489c8030
[2019-10-02 14:39:50,597] Agent[1]: stdout:   Header guard @0x00002af0489c8010 is OK
[2019-10-02 14:39:50,598] Agent[1]: stdout:   Trailer guard @0x00002af048ac8030 is OK
[2019-10-02 14:39:50,598] Agent[1]: stdout:   User data appears to be in use
[2019-10-02 14:39:50,598] Agent[1]: stdout: FATAL ERROR in native method: ReleasePrimitiveArrayCritical: unrecognized elements
[2019-10-02 14:39:50,598] Agent[1]: stdout: 	at java.util.zip.Deflater.deflateBufferBytes(java.base@14-internal/Native Method)
[2019-10-02 14:39:50,598] Agent[1]: stdout: 	at java.util.zip.Deflater.deflate(java.base@14-internal/Deflater.java:596)
[2019-10-02 14:39:50,598] Agent[1]: stdout: 	- locked <0x00000000ef497b98> (a java.util.zip.Deflater$DeflaterZStreamRef)
[2019-10-02 14:39:50,598] Agent[1]: stdout: 	at java.util.zip.Deflater.deflate(java.base@14-internal/Deflater.java:484)
[2019-10-02 14:39:50,598] Agent[1]: stdout: 	at FlaterTest.getDeflatedLength(FlaterTest.java:73)
[2019-10-02 14:39:50,598] Agent[1]: stdout: 	at FlaterTest.go(FlaterTest.java:101)

To reproduce run:

make test TEST=java/util/zip/FlaterTest.java JTREG="VM_OPTIONS=-Xcheck:jni"
Comments
Fix Request (11u) Backporting this fix corrects the simple JNI mistake in Deflater.c, and keeps codebases in sync (I see 11.0.6-oracle). As far as I see it, the failure is not critical as of now, as Hotspot implementation ignores the affected argument; still, it should be fixed for cleanliness. Patch applies cleanly to 11u. Affected test crashes without the product patch, passes with it. Patched JDK passes tier1, tier2 tests.
14-10-2019

I'm slightly horrified that running tests with -Xcheck:jni isn't something that anyone does on a regular basis. Else the mistake would have been caught before jdk11 release.
10-10-2019

Fix Request (13u) Minor correction to the native code that had wrong arguments. Updated the corresponding test to run with -Xcheck:jni to prevent further occurrences of similar issue. Patch applies clean to 13u and passes tier1,2,3 of mach5.
10-10-2019

I believe this is added by JDK-6341887, which means it affects JDKs starting 11, marking as such. Current jdk-updates/jdk11u-dev fails, reproduce with: CONF=linux-x86_64-normal-server-fastdebug make images run-test TEST=jdk/java/util/zip/FlaterTest.java TEST_VM_OPTS="-Xcheck:jni"
10-10-2019

URL: https://hg.openjdk.java.net/jdk/jdk/rev/7605e97c9491 User: coffeys Date: 2019-10-09 10:14:47 +0000
09-10-2019

starter issue for Kiran
07-10-2019

diff --git a/src/java.base/share/native/libzip/Deflater.c b/src/java.base/share/native/libzip/Deflater.c --- a/src/java.base/share/native/libzip/Deflater.c +++ b/src/java.base/share/native/libzip/Deflater.c @@ -257,7 +257,7 @@ res = doDeflate(env, addr, input, inputLen, output + outputOff, outputLen, flush, params); - (*env)->ReleasePrimitiveArrayCritical(env, outputArray, input, 0); + (*env)->ReleasePrimitiveArrayCritical(env, outputArray, output, 0); retVal = checkDeflateStatus(env, addr, inputLen, outputLen, params, res); return retVal;
02-10-2019