如何在JVMTI中跟踪锁定事件

时间:2021-10-24 06:49:36

JVMTI offers the events ContendedMonitorEnter and ContendedMonitorEntered to detect events related to the use of synchronized. synchronized is nothing else, but a ReentrantLock.

JVMTI提供事件ContendedMonitorEnter和ContendedMonitorEntered来检测与使用synchronized相关的事件。 synchronized不是别的,而是ReentrantLock。

Now I would like to track also events related to the lock structure: ReentrantLock. I could hook to method entry/exit of its lock() and unlock() events. However, these event hooks don't provide any information about the object they were invoked on. Thus I cannot distinguish between different ReentrantLock and thus cannot log any information about which lock is currently locked.

现在我想跟踪与锁结构相关的事件:ReentrantLock。我可以挂钩其lock()和unlock()事件的方法入口/出口。但是,这些事件挂钩不提供有关它们被调用的对象的任何信息。因此,我无法区分不同的ReentrantLock,因此无法记录有关当前锁定的锁的任何信息。

Is there any other way to keep track of this?

有没有其他方法来跟踪这个?

1 个解决方案

#1


0  

You'll have to instrument the classes being loaded by yourself. This is rather complicated, but fortunately we have java_crw_demo.c which is supplied (alongside with other helpful examples) together with JDK. There you can find an implementation that does some basic kinds of instrumentation. You can easily modify it to do the job. I am doing this now for some academic student project.

你必须自己设置加载的类。这相当复杂,但幸运的是我们提供了java_crw_demo.c(与其他有用的示例一起)和JDK一起提供。在那里,您可以找到执行某些基本类型的检测的实现。您可以轻松修改它以完成工作。我正在为一些学术学生项目做这件事。

#1


0  

You'll have to instrument the classes being loaded by yourself. This is rather complicated, but fortunately we have java_crw_demo.c which is supplied (alongside with other helpful examples) together with JDK. There you can find an implementation that does some basic kinds of instrumentation. You can easily modify it to do the job. I am doing this now for some academic student project.

你必须自己设置加载的类。这相当复杂,但幸运的是我们提供了java_crw_demo.c(与其他有用的示例一起)和JDK一起提供。在那里,您可以找到执行某些基本类型的检测的实现。您可以轻松修改它以完成工作。我正在为一些学术学生项目做这件事。