如何使用 OpenJ9 Xtrace 选项转储方法参数的内容

How to dump the content of method argument with OpenJ9 Xtrace Option

背景:

我想记录 Eclipse 上的用户活动,例如,用户克隆了哪些 git 存储库,合并冲突何时发生,等等。

我想到了使用 OpenJ9 -Xtrace 选项。首先,为了测试 OpenJ9 -Xtrace 选项功能,我用 OpenJ9: Xtrace Option Builder 做了以下选项,并将这些选项添加到 eclipse.ini 以记录克隆的 git 存储库。

-Xtrace:none,maximal={mt{entry},mt{exit},mt{exception}},methods={org/eclipse/jgit/api/CloneCommand.setURI(),org/eclipse/jgit/api/CloneCommand.call()},output="C:\tmp\mytrace.trc"
-Xjit:exclude={org/eclipse/jgit/api/CloneCommand.setURI*|org/eclipse/jgit/api/CloneCommand.call*}

然后我使用 -clean 选项启动了 Eclipse,克隆了一个存储库,然后退出了 Eclipse。 我用 traceformat 命令转换了 mytrace.trc,并在 mytrace.trc.fmt:

中得到了这个输出
                Trace Formatted Data 

Time (UTC)          Thread ID          Tracepoint ID       Type        Tracepoint Data
07:56:41.541990300 *0x0000000001fafe00 mt.0                Entry      >org/eclipse/jgit/api/CloneCommand.setURI(Ljava/lang/String;)Lorg/eclipse/jgit/api/CloneCommand; bytecode method, this = 0x7f9788a98
07:56:41.541991900  0x0000000001fafe00 mt.6                Exit       <org/eclipse/jgit/api/CloneCommand.setURI(Ljava/lang/String;)Lorg/eclipse/jgit/api/CloneCommand; bytecode method
07:56:41.542010000  0x0000000001fafe00 mt.0                Entry      >org/eclipse/jgit/api/CloneCommand.call()Lorg/eclipse/jgit/api/Git; bytecode method, this = 0x7f9788a98
07:56:46.512616000  0x0000000001fafe00 mt.6                Exit       <org/eclipse/jgit/api/CloneCommand.call()Lorg/eclipse/jgit/api/Git; bytecode method
07:56:47.631399600  0x0000000001fafe00 dg.262              Debug       ***** Thread termination - trace purged *****

此输出显示 setURI() 方法有一个参数 (Ljava/lang/String;),但没有 JGit 克隆的 URI。

问题:

如何使用 OpenJ9 Xtrace 选项转储方法参数的内容?

How can I dump the content of method argument with OpenJ9 Xtrace option?

您的选项仅启用 entryexitexception 方法跟踪跟踪点。方法参数打印在不同的跟踪点下。如果您改用 this option,您应该会看到包含参数的附加跟踪条目。

但是,虽然原始参数的值显示在跟踪中,但当参数是一个对象时,您只会在 [=34= 上看到对象的地址] 堆。例如,当跟踪对 *.println() 的调用时,您会看到类似这样的内容:

15:31:13.710 0x33acc00              mt.18       - this: java/io/PrintStream@00000000FFF04AE0 method arguments: (java/lang/String@00000000E0002768)

我的理解是,该限制是由于 Xtrace 引擎的架构,以及解析字符串等对象并将其存储在跟踪缓冲区中的性能影响。

虽然地址对于在 Java 堆中定位感兴趣的对象非常有用,例如当使用 Eclipse 内存分析器查看关联的系统转储时,Xtrace 无法提供您想要的功能。

另一种方法是使用 Java 代理在运行时修改(检测)org/eclipse/jgit/api/CloneCommand class 以将日志记录代码添加到 .setURI() 方法。