JQian
JQian

Reputation: 226

Profile the locks in OpenJDK or any Java VM

The thing I want to do is, count how many locks happened during the execution of one JVM application. (I know the lock number may change from run to run, but I just want to get the average number). And I cannot change the application, since it is one benchmark.

I have tried to use JRockit-JDK, but two problems:

  1. -Djrockit.lockprofiling=true does not give me the profile information (link);
  2. does "-Xverbose:locks" print the right information?

The platform I am using is Ubuntu Server. Any suggestions on this would be great appreciated.

Upvotes: 1

Views: 314

Answers (1)

selig
selig

Reputation: 4844

To do this previously I've used AspectJ with a pointcut that detects locking and a counter i.e.

public aspect CountLocks{

   private static AtomicInteger locks = new AtomicInteger();

   before(Object l) : lock() && args(l) { locks.incrementAndGet(); }

   after() : execution(void main(String[])) { System.out.println(locks+" locks"); }

}

But this obviously involves weaving the code, potentially changing its performance characteristics.

Upvotes: 0

Related Questions