java - 调试 Java 代理

标签 java debugging profiler instrumentation

我目前正在开发 Java Agent为了促进新旧 Java 应用程序的动态检测。

我突然想到,就 IDE 调试而言,Java 代理可能被认为是一种特殊情况,因为它们需要注入(inject)到目标 JVM 进程中才能运行。因此,这自然会引发一个问题,即如何调试、测试和分析代理类型的应用程序。

对现有解决方案的粗略搜索显示了一些基于命令行的选项(即 YourKit、JIP 等),但其中许多在底层也是 Java 代理。如果使用它,至少在我看来,会导致代理调试/分析另一个代理的相当奇怪的场景。我知道代理可以分层排列,但是我不确定代理应用程序是否可以通过在此庄园中堆叠代理来调试。

最佳答案

Java How To ... The -javaagent: Option 中所述:

An agent is just an interceptor in front of your main method, executed in the same JVM and loaded by the same system classloader, and governed by the same security policy and context.

The name is misleading, since the word agent usually suggests something working remotely and separately from the primary entity. But it turns out the java agent as used in -javaagent: is much simpler than that.

One java application may have any number of agents by using -javaagent: option any number of times. Agents are invoked in the same order as specified in options.

Each agent may also take String-valued args. I guess that's the reason why we have to use this option multiple times for multiple agents. Otherwise, we could've just done something like:

-javaagent agent1.jar:agent2.jar

, which is incorrect.

因此,通过将探查器代理(例如 YourKit、JIP 等)放在您自己的代理之前,您可以将调试控制权交给您。

关于java - 调试 Java 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17675518/

相关文章:

java - 为什么 Java 中除负零会返回正无穷大?

java - 获取时区偏移量 - Java

c# - 需要了解这个新错误的含义吗?

java - JVM中如何定义内存泄漏?

ubuntu - 使用 ubuntu 9 设置速度跟踪器

java - 坚持这段代码

java - 为什么java中有两种不同的for循环?

c - IDE 中的 PostgreSQL 单步调试

perl - 如何调试自定义调试器?

java - 堆内存与对象内存