JDK-8225189 : assert(!JavaThread::current()->in_critical()) failed: Would deadlock
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 11,13
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2019-06-03
  • Updated: 2020-09-03
  • Resolved: 2019-06-11
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.5Fixed 13 b25Fixed 14Fixed
Related Reports
Relates :  
Description
test/jdk/java/util/zip/ZipFile/MultiThreadedReadTest.java fails with:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (src/hotspot/share/gc/shared/gcLocker.cpp:105), pid=69003, tid=34563
#  assert(!JavaThread::current()->in_critical()) failed: Would deadlock
#
# JRE version: Java(TM) SE Runtime Environment (13.0) (fastdebug build 13-ea+0-1200)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 13-ea+0-1200, compiled mode, compressed oops, g1 gc, bsd-amd64)
# Core dump will be written. Default location: /cores/core.69003
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#
Comments
11u Fix Request: I would like to backport this patch to 11u, as it is on Oracle's 11u backport. The JDK13 patch applies cleanly.
08-08-2019

The refactoring done for JDK-6341887 means that errors encountered can lead to a FindClass/ThrowNew while in the critical section. Previously the handing of errors and the throwing of exceptions was after existing the critical section.
04-06-2019

This code also does not seem to be specific to any hardware/software platform
04-06-2019

This looks like a JNI spec violation in the ZIP library implementation, calling a JNI method within critical sections.
04-06-2019

The code seems to have called the JNI GetXXXCritical() methods twice before the call to the JNI ThrowNew method (the thread's _jni_active_critical count is two). Calling other JNI methods within critical sections is forbidden within critical sections, see e.g. the documentation for GetPrimitiveArrayCritical (https://docs.oracle.com/en/java/javase/12/docs/specs/jni/functions.html#getprimitivearraycritical-releaseprimitivearraycritical) which explicitly states: "Inside a critical region, native code must not call other JNI functions, or any system call that may cause the current thread to block and wait for another Java thread" This includes the ThrowNew call.
04-06-2019

ZIP decoding seems to come across an error while inflating ("invalid stored block lengths"), throwing a Java exception. That exception can cause memory allocation that fails (i.e. allocating the exception message j.l.String on the java heap), starting into the GCLocker protocol. JNI forbids(?) allocating memory from the Java heap in a critical section due to potential deadlock.
04-06-2019

Stack: [0x000070000c0fc000,0x000070000c1fc000], sp=0x000070000c1fad80, free space=1019k Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code) V [libjvm.dylib+0xc05b42] VMError::report_and_die(int, char const*, char const*, __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long)+0x6ac V [libjvm.dylib+0xc0621d] VMError::report_and_die(Thread*, void*, char const*, int, char const*, char const*, __va_list_tag*)+0x47 V [libjvm.dylib+0x4170b0] report_vm_error(char const*, int, char const*, char const*, ...)+0x145 V [libjvm.dylib+0x562647] GCLocker::stall_until_clear()+0x9d V [libjvm.dylib+0x4d5e13] G1CollectedHeap::attempt_allocation_slow(unsigned long)+0x1cb V [libjvm.dylib+0x4d547a] G1CollectedHeap::attempt_allocation(unsigned long, unsigned long, unsigned long*)+0x172 V [libjvm.dylib+0x94fa17] MemAllocator::allocate_inside_tlab_slow(MemAllocator::Allocation&) const+0x29d V [libjvm.dylib+0x94fd1c] MemAllocator::mem_allocate(MemAllocator::Allocation&) const+0x24 V [libjvm.dylib+0x94fd86] MemAllocator::allocate() const+0x50 V [libjvm.dylib+0x36ca00] CollectedHeap::obj_allocate(Klass*, int, Thread*)+0x32 V [libjvm.dylib+0x5df496] InstanceKlass::allocate_instance(Thread*)+0x6e V [libjvm.dylib+0x6071c9] java_lang_String::basic_create(int, bool, Thread*)+0xc5 V [libjvm.dylib+0x607be4] java_lang_String::create_from_str(char const*, Thread*)+0x56 V [libjvm.dylib+0x4b612f] Exceptions::new_exception(Thread*, Symbol*, char const*, Handle, Handle, Handle, Exceptions::ExceptionMsgToUtf8Mode)+0x2d5 V [libjvm.dylib+0x4b5e36] Exceptions::_throw_msg(Thread*, char const*, int, Symbol*, char const*, Handle, Handle)+0x144 V [libjvm.dylib+0x679241] jni_ThrowNew+0x3bd C [libzip.dylib+0x1367] doInflate+0xc2 C [libzip.dylib+0x122a] Java_java_util_zip_Inflater_inflateBytesBytes+0x83 J 2900 java.util.zip.Inflater.inflateBytesBytes(J[BII[BII)J java.base@13-ea (0 bytes) @ 0x0000000118af773d [0x0000000118af75c0+0x000000000000017d] J 2896 c2 java.util.zip.Inflater.inflate([BII)I java.base@13-ea (418 bytes) @ 0x0000000118b29858 [0x0000000118b29480+0x00000000000003d8] J 2894 c2 java.util.zip.InflaterInputStream.read([BII)I java.base@13-ea (138 bytes) @ 0x0000000118af8334 [0x0000000118af8280+0x00000000000000b4] j java.util.zip.InflaterInputStream.read()I+11 java.base@13-ea j MultiThreadedReadTest.run()V+3 v ~StubRoutines::call_stub V [libjvm.dylib+0x605f6c] JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, Thread*)+0x3e4 V [libjvm.dylib+0x604a3d] JavaCalls::call_virtual(JavaValue*, Klass*, Symbol*, Symbol*, JavaCallArguments*, Thread*)+0x1f1 V [libjvm.dylib+0x604b58] JavaCalls::call_virtual(JavaValue*, Handle, Klass*, Symbol*, Symbol*, Thread*)+0x58 V [libjvm.dylib+0x70ad79] thread_entry(JavaThread*, Thread*)+0x13f V [libjvm.dylib+0xb849c1] JavaThread::thread_main_inner()+0x1a1 V [libjvm.dylib+0xb84574] JavaThread::run()+0x2aa V [libjvm.dylib+0xb810eb] Thread::call_run()+0x11b V [libjvm.dylib+0x9ecd08] thread_native_entry(Thread*)+0x13a C [libsystem_pthread.dylib+0x3661] _pthread_body+0x154 C [libsystem_pthread.dylib+0x350d] _pthread_body+0x0 C [libsystem_pthread.dylib+0x2bf9] thread_start+0xd
03-06-2019