RFR: JDK-8033696: "assert(thread != NULL) failed: just checking" due to Thread::current() and JNI pthread interaction

Dmitry Samersoff dmitry.samersoff at oracle.com
Wed Feb 26 20:14:20 UTC 2014


Andreas,

With JDK7 I didn't observe any crash with or without your patch.
Without the patch the number of active threads constantly grows,
with patch it remains the same.


uname -a
FreeBSD samersoff.net 9.2-RELEASE FreeBSD 9.2-RELEASE #1: Thu Jan  2
02:15:13 MSK 2014     dms at minext:/sys/amd64/compile/MIRCAT  amd64


With patch:

#java -version

openjdk version "1.7.0_45"
OpenJDK Runtime Environment (build 1.7.0_45-b18)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
Thread 80103f400 has exited with leftover thread-specific data after 4
destructor iterations

#$JAVA_HOME/bin/java -Djava.library.path=$NATIVE com.test.callback.App

Java callback: native thread: 34376799232, java thread: Thread-391, 2
active threads
Successfully detached native thread 0x801045400
Deleting callback


Without patch:

#/opt/openjdk7/bin/java -version

openjdk version "1.7.0_25"
OpenJDK Runtime Environment (build 1.7.0_25-b15)
OpenJDK 64-Bit Server VM (build 23.21-b01, mixed mode)

#/opt/openjdk7/bin/java -Djava.library.path=$NATIVE com.test.callback.App

Java callback: native thread: 34376788992, java thread: Thread-402, 404
active threads
Successfully detached native thread 0x801042c00
Deleting callback

-Dmitry


On 2014-02-10 20:21, Andreas Eriksson wrote:
> Hi,
> 
> Could I please get reviews for this change.
> JBS: https://bugs.openjdk.java.net/browse/JDK-8033696
> Webrev: http://cr.openjdk.java.net/~aeriksso/8033696/webrev.00/
> Mail discussion:
> http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2014-February/010759.html
> 
> 
> Summary:
> JNI code is using pthread_key_create with a destructor to detach the
> thread from the JVM when the thread is exiting.
> For some flavors of Linux and BSD the JVM is also using the
> pthread_key_create, to store the Thread::current() value in a thread
> local storage.
> Since the thread local storage containing the thread pointer is erased
> (by pthread) before the JNI destructor runs, we run detachCurrentThread
> on a thread that has NULL as current thread.
> This fix uses a destructor for the thread pointer that restores the
> value, so that the JNI destructor can run detachCurrentThread successfully.
> More info in JBS.
> 
> Testing:
> Native code regtest attached to JBS tested on Linux, but not on Mac
> since I don't have access to one.
> JPRT ran without a problem.
> 
> Regards,
> Andreas


-- 
Dmitry Samersoff
Oracle Java development team, Saint Petersburg, Russia
* I would love to change the world, but they won't give me the sources.


More information about the hotspot-runtime-dev mailing list