我想做的是,计算一个 JVM 应用程序执行期间发生了多少锁。(我知道锁号可能会随着运行而变化,但我只想得到平均数)。而且我不能更改应用程序,因为它是一个基准。
我曾尝试使用 JRockit-JDK,但有两个问题:
- -Djrockit.lockprofiling=true 不给我个人资料信息(链接);
- “-Xverbose:locks”是否打印正确的信息?
我使用的平台是 Ubuntu Server。对此的任何建议将不胜感激。
为此,我之前使用了带有检测锁定和计数器的切入点的 AspectJ,即
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"); }
}
但这显然涉及编织代码,可能会改变其性能特征。