Tigran Mkrtchyan
2009-Oct-05 16:38 UTC
[dtrace-discuss] Java hotspot monitor-contended-enter probe
By reading manual, I have an impression that this probe is fired when a thread enters a synchronized block, but in my simple example it did not. <p>If this is not the right probe for it which one I have to use? <p>Thanks, Tigran. <p>P.S: my test app <pre> import java.util.concurrent.TimeUnit; import java.util.Vector; public class a { public static void main(String[] args) throws Exception { Vector v = new Vector(); final Object lock = new Object(); for(int i = 0; i < 100000; i++) { synchronized(lock) { v.add(i); } try { TimeUnit.SECONDS.sleep(2); System.out.print("."); } catch (InterruptedException ex) { ex.printStackTrace(); } } System.out.println("\n"); } } </pre> -- This message posted from opensolaris.org
Frederic Parain
2009-Oct-05 16:48 UTC
[dtrace-discuss] Java hotspot monitor-contended-enter probe
This probe is fired only when the thread tries to enter a contended monitor. In your example below, there''s only one thread trying to acquire the lock, so no contention occur. Fred Tigran Mkrtchyan wrote:> By reading manual, I have an impression that this probe is fired when a thread enters a synchronized block, but in my simple example it did not. > > <p>If this is not the right probe for it which one I have to use? > > <p>Thanks, > Tigran. > > > <p>P.S: my test app > <pre> > import java.util.concurrent.TimeUnit; > import java.util.Vector; > public class a { > > public static void main(String[] args) throws Exception { > Vector v = new Vector(); > final Object lock = new Object(); > for(int i = 0; i < 100000; i++) { > synchronized(lock) { > v.add(i); > } > try { > TimeUnit.SECONDS.sleep(2); > System.out.print("."); > } catch (InterruptedException ex) { > ex.printStackTrace(); > } > > } > System.out.println("\n"); > } > } > </pre>-- Frederic Parain - Sun Microsystems 180, av. de l''Europe, ZIRST de Montbonnot 38334 Saint Ismier, FRANCE Phone: +33 4 76 18 81 17 Email: Frederic.Parain at Sun.COM
Tigran Mkrtchyan
2009-Oct-05 17:58 UTC
[dtrace-discuss] Java hotspot monitor-contended-enter probe
In other word only when other thread in synchronized block. Fair enough, but is there another probe which fired when a thread enters a synchronized block? Thanks, Tigran. -- This message posted from opensolaris.org
Frederic Parain
2009-Oct-05 18:10 UTC
[dtrace-discuss] Java hotspot monitor-contended-enter probe
There''s no such probe. In fact, entering a not contended monitor is very common is Java, so in this case, the VM uses a highly optimized fast path which is not instrumented with a DTrace probe. Fred Tigran Mkrtchyan wrote:> In other word only when other thread in synchronized block. > Fair enough, but is there another probe which fired when a thread enters a > synchronized block? > > Thanks, > Tigran.-- Frederic Parain - Sun Microsystems 180, av. de l''Europe, ZIRST de Montbonnot 38334 Saint Ismier, FRANCE Phone: +33 4 76 18 81 17 Email: Frederic.Parain at Sun.COM
Tigran Mkrtchyan
2009-Oct-05 18:28 UTC
[dtrace-discuss] Java hotspot monitor-contended-enter probe
That''s unfortunate. I was hoping to write a script for deadlock detection by following lock which each thread holds. Ok, will try to some other ways to do so (may be jvm tools provides some information). Thanks a lot, Tigran. -- This message posted from opensolaris.org
Frederic Parain
2009-Oct-05 18:52 UTC
[dtrace-discuss] Java hotspot monitor-contended-enter probe
You should look at jstack. http://java.sun.com/javase/6/webnotes/trouble/TSG-VM/html/tooldescr.html#gblfh Fred Tigran Mkrtchyan wrote:> That''s unfortunate. I was hoping to write a script for deadlock detection > by following lock which each thread holds. > > Ok, will try to some other ways to do so (may be jvm tools provides some information). > > Thanks a lot, > Tigran.-- Frederic Parain - Sun Microsystems 180, av. de l''Europe, ZIRST de Montbonnot 38334 Saint Ismier, FRANCE Phone: +33 4 76 18 81 17 Email: Frederic.Parain at Sun.COM
Keith McGuigan
2009-Oct-05 19:07 UTC
[dtrace-discuss] Java hotspot monitor-contended-enter probe
Tigran Mkrtchyan wrote:> That''s unfortunate. I was hoping to write a script for deadlock detection > by following lock which each thread holds. > > Ok, will try to some other ways to do so (may be jvm tools provides some information). > > Thanks a lot, > Tigran.The JVM already does some deadlock detection, but I''m not sure exactly what you''re trying to do so perhaps it''s not usable. If you looking for actual deadlocks (as opposed to "potential" deadlocks), then the contended lock cases are in fact what you want, since each lock involved in the deadlock would be contended. -- - Keith