Created
March 26, 2012 08:56
-
-
Save rednaxelafx/2204011 to your computer and use it in GitHub Desktop.
Monitors locked in native method (via JNI MonitorEnter) doesn't show up directly in jstack (unless there's a deadlock), because monitors are only shown with a stack frame, and native frames don't show up in plain old jstack.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g++ -I $JAVA_HOME/include/ -I $JAVA_HOME/include/linux/ -fPIC -shared -o libfoo.so foo.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[sajia@211 test_native_monitorenter]$ java -version | |
java version "1.6.0_30" | |
Java(TM) SE Runtime Environment (build 1.6.0_30-b12) | |
OpenJDK 64-Bit Server VM (build 20.0-b12-internal-fastdebug, mixed mode) | |
[sajia@211 test_native_monitorenter]$ jps | |
12676 Jps | |
12651 Main | |
[sajia@211 test_native_monitorenter]$ jstack -l 12651 | |
2012-03-26 16:51:08 | |
Full thread dump OpenJDK 64-Bit Server VM (20.0-b12-internal-fastdebug mixed mode): | |
"Attach Listener" daemon prio=10 tid=0x00002aaaafcbd800 nid=0x31b2 runnable [0x0000000000000000] | |
java.lang.Thread.State: RUNNABLE | |
JavaThread state: _thread_blocked | |
Thread: 0x00002aaaafcbd800 [0x31b2] State: _call_back _has_called_back 1 _at_poll_safepoint 0 | |
JavaThread state: _thread_blocked | |
Locked ownable synchronizers: | |
- None | |
"Low Memory Detector" daemon prio=10 tid=0x00002aaab8007800 nid=0x3180 runnable [0x0000000000000000] | |
java.lang.Thread.State: RUNNABLE | |
JavaThread state: _thread_blocked | |
Thread: 0x00002aaab8007800 [0x3180] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0 | |
JavaThread state: _thread_blocked | |
Locked ownable synchronizers: | |
- None | |
"C2 CompilerThread1" daemon prio=10 tid=0x00002aaab8004800 nid=0x317f waiting on condition [0x0000000000000000] | |
java.lang.Thread.State: RUNNABLE | |
JavaThread state: _thread_blocked | |
Thread: 0x00002aaab8004800 [0x317f] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0 | |
JavaThread state: _thread_blocked | |
Locked ownable synchronizers: | |
- None | |
"C2 CompilerThread0" daemon prio=10 tid=0x00002aaab8001000 nid=0x317e waiting on condition [0x0000000000000000] | |
java.lang.Thread.State: RUNNABLE | |
JavaThread state: _thread_blocked | |
Thread: 0x00002aaab8001000 [0x317e] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0 | |
JavaThread state: _thread_blocked | |
Locked ownable synchronizers: | |
- None | |
"Signal Dispatcher" daemon prio=10 tid=0x00002aaaafc83000 nid=0x317d runnable [0x0000000000000000] | |
java.lang.Thread.State: RUNNABLE | |
JavaThread state: _thread_blocked | |
Thread: 0x00002aaaafc83000 [0x317d] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0 | |
JavaThread state: _thread_blocked | |
Locked ownable synchronizers: | |
- None | |
"Finalizer" daemon prio=10 tid=0x00002aaaafc53800 nid=0x317c in Object.wait() [0x000000004199a000] | |
java.lang.Thread.State: WAITING (on object monitor) | |
JavaThread state: _thread_blocked | |
Thread: 0x00002aaaafc53800 [0x317c] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0 | |
JavaThread state: _thread_blocked | |
at java.lang.Object.wait(Native Method) | |
- waiting on <0x0000000758601300> (a java.lang.ref.ReferenceQueue$Lock) | |
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) | |
- locked <0x0000000758601300> (a java.lang.ref.ReferenceQueue$Lock) | |
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) | |
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159) | |
Locked ownable synchronizers: | |
- None | |
"Reference Handler" daemon prio=10 tid=0x00002aaaafc51800 nid=0x317b in Object.wait() [0x0000000041899000] | |
java.lang.Thread.State: WAITING (on object monitor) | |
JavaThread state: _thread_blocked | |
Thread: 0x00002aaaafc51800 [0x317b] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0 | |
JavaThread state: _thread_blocked | |
at java.lang.Object.wait(Native Method) | |
- waiting on <0x00000007586011d8> (a java.lang.ref.Reference$Lock) | |
at java.lang.Object.wait(Object.java:485) | |
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116) | |
- locked <0x00000007586011d8> (a java.lang.ref.Reference$Lock) | |
Locked ownable synchronizers: | |
- None | |
"main" prio=10 tid=0x00000000420a5000 nid=0x316c runnable [0x0000000040871000] | |
java.lang.Thread.State: RUNNABLE | |
JavaThread state: _thread_blocked | |
Thread: 0x00000000420a5000 [0x316c] State: _call_back _has_called_back 1 _at_poll_safepoint 0 | |
JavaThread state: _thread_blocked | |
at Foo.spinWait(Foo.java:13) | |
at Foo.lockMe(Native Method) | |
at Foo.bar(Foo.java:7) | |
at Main.main(Main.java:3) | |
Locked ownable synchronizers: | |
- None | |
"VM Thread" prio=10 tid=0x00002aaaafc49000 nid=0x317a runnable | |
"GC task thread#0 (ParallelGC)" prio=10 tid=0x00000000420bd000 nid=0x316d runnable | |
"GC task thread#1 (ParallelGC)" prio=10 tid=0x00000000420bf000 nid=0x316e runnable | |
"GC task thread#2 (ParallelGC)" prio=10 tid=0x00000000420c1800 nid=0x316f runnable | |
"GC task thread#3 (ParallelGC)" prio=10 tid=0x00000000420c3800 nid=0x3170 runnable | |
"GC task thread#4 (ParallelGC)" prio=10 tid=0x00000000420c5800 nid=0x3171 runnable | |
"GC task thread#5 (ParallelGC)" prio=10 tid=0x00000000420c7800 nid=0x3172 runnable | |
"GC task thread#6 (ParallelGC)" prio=10 tid=0x00000000420c9800 nid=0x3173 runnable | |
"GC task thread#7 (ParallelGC)" prio=10 tid=0x00000000420cb800 nid=0x3174 runnable | |
"GC task thread#8 (ParallelGC)" prio=10 tid=0x00000000420cd800 nid=0x3175 runnable | |
"GC task thread#9 (ParallelGC)" prio=10 tid=0x00000000420cf800 nid=0x3176 runnable | |
"GC task thread#10 (ParallelGC)" prio=10 tid=0x00000000420d1800 nid=0x3177 runnable | |
"GC task thread#11 (ParallelGC)" prio=10 tid=0x00000000420d3800 nid=0x3178 runnable | |
"GC task thread#12 (ParallelGC)" prio=10 tid=0x00000000420d5800 nid=0x3179 runnable | |
"VM Periodic Task Thread" prio=10 tid=0x00002aaab8013800 nid=0x3181 waiting on condition | |
Compiler thread printing unimplemented. | |
JNI global references: 873 | |
[sajia@211 test_native_monitorenter]$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Foo.h" | |
void JNICALL Java_Foo_lockMe(JNIEnv* env, jobject self) { | |
env->MonitorEnter(self); | |
jmethodID mid = env->GetMethodID(env->GetObjectClass(self), "spinWait", "()V"); | |
env->CallVoidMethod(self, mid); | |
env->MonitorExit(self); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* DO NOT EDIT THIS FILE - it is machine generated */ | |
#include <jni.h> | |
/* Header for class Foo */ | |
#ifndef _Included_Foo | |
#define _Included_Foo | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
/* | |
* Class: Foo | |
* Method: lockMe | |
* Signature: ()V | |
*/ | |
JNIEXPORT void JNICALL Java_Foo_lockMe | |
(JNIEnv *, jobject); | |
#ifdef __cplusplus | |
} | |
#endif | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Foo { | |
static { | |
System.loadLibrary("foo"); | |
} | |
public void bar() { | |
lockMe(); | |
} | |
private void spinWait() { | |
while (true) { | |
// burn some CPU | |
int i = 0; | |
i++; | |
} | |
} | |
public native void lockMe(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
new Foo().bar(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment