如何创建 jvmti 代理来查看所有加载的类、对象及其字段详细信息
我想编写一个java代理来检测一些应用程序。我有兴趣获取应用程序实例化的对象(即它们的字段)的详细信息。我还想在运行时捕获对任何这些对象/它们的字段的任何读写访问。
您能否指导我编写代理并让我知道我应该探索哪些类和方法。我只知道 java.lang.instrument 类。但我在那里找不到任何可以捕获这些事件的东西。
我也愿意接受您认为可以帮助我的任何其他 Java 仪器技术。
I want to write a java agent to instrument some applications. I am interested in getting the details of the objects, (i.e. their fields) instantiated by the applications. I would also like to catch any read and write access to any of those objects/their fields while running.
Can you please guide me in writing the agents and let me know what classes and methods should I explore. I just know about java.lang.instrument class. But I could not find anything there that could catch these events.
I am also open to any other java instrumentation techniques that you think can help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 AspectJ 与加载时编织 (javaagent) 结合使用。例如,您可以编写方面来监视构造函数调用(调用/执行切入点)和监视字段访问(设置/获取切入点)。
我正在使用基于注释的开发。例如,要监视给定包中所有类中所有非静态非最终和非瞬态字段的设置,您可以创建方面:
在 META-INF 中放置 aop.xml:
将 acpectjrt.jar 和aspectjweaver.jar 放在类路径上并使用
- 运行 JVM javaagent:lib/aspectjweaver.jar
参数。以下是一些示例和文档 http://www.eclipse.org/aspectj /doc/released/adk15notebook/ataspectj.html
You can use the AspectJ with load-time weaving (javaagent). You can e.g. write aspects to monitor constructor calls (call/execution pointcuts) and monitor field access (set/get pointcuts).
I'm using annotation-based development. For example to monitor setting all nonstatic nonfinal and nontransient fields in all classes in given package you can create aspect:
in META-INF place aop.xml:
Place acpectjrt.jar and aspectjweaver.jar on classpath and run your JVM with
-javaagent:lib/aspectjweaver.jar
parameter.Here are some examples and documentation http://www.eclipse.org/aspectj/doc/released/adk15notebook/ataspectj.html