1
votes

VisualVM supports executing unsafe BTrace scripts (https://kenai.com/projects/btrace/pages/UserGuide). Is it possible to use an unsafe BTrace script to kill/interrupt some Java thread? Some threads in my Eclipse IDE are deadlocked and I'd like to gracefully shutdown the IDE.

"Worker-3571" prio=6 tid=0x00000000114b7800 nid=0x964 waiting for monitor entry [0x000000002a45f000] java.lang.Thread.State: BLOCKED (on object monitor) at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$3.run(SelectionListenerWithASTManager.java:155) - waiting to lock <0x00000000f7490ce8> (a java.lang.Object) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

"Worker-3568" prio=6 tid=0x00000000114b9000 nid=0x2984 waiting for monitor entry [0x000000002958f000] java.lang.Thread.State: BLOCKED (on object monitor) at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$3.run(SelectionListenerWithASTManager.java:155) - waiting to lock <0x00000000f7490ce8> (a java.lang.Object) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

"Worker-3570" prio=6 tid=0x00000000114bc000 nid=0x1980 in Object.wait() [0x000000002998f000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:503) at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:457) - locked <0x00000000e10979a0> (a java.lang.Object) at org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:128) at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:170) at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$3.run(SelectionListenerWithASTManager.java:155) - locked <0x00000000f7490ce8> (a java.lang.Object) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

1
I'm not sure there is any way to kill a thread from outside of a JVM aside from JMX or some other communications.Gray
The closest I've found so far is stackoverflow.com/questions/11610902/…buzz3791
Java does not support "killing" threads. There is nothing BTrace can help you with :(JB-
One idea I've had is a BTrace script which adds a java.lang.reflect.Proxy relevant to one of the threads involved in the deadlock. Then I'll still need a way to interrupt one of the WAITING / BLOCKED threads.buzz3791
Still no answer. Here's one response that claims BTrace can't do it... kenai.com/projects/btrace/forums/forum/topics/…buzz3791

1 Answers

1
votes

No, this can't be done for the following reasons:

  1. BTrace supports only what is available through Java APIs. There is no Java API to kill an arbitrary thread.
  2. BTrace uses class retransformation to inject its code. Even though a class bytecode is modified all the methods which are currently on stack keep on using the original bytecode and are swapped to the new version only when they leave the stack (return, exception). Meaning that when your thread is stuck (especially WAITING/BLOCKED) the method you want to instrument is kept on stack and the new bytecode is never applied.

You will have more luck with JPDA based solutions (eg. jdb, youdebug)