无法在Mac OS X上通过jinfo启用DTrace探针

时间:2011-02-03 23:19:05

标签: java debugging macos dtrace jinfo

在Snow Leopard上运行Java 6。

你应该能够turn on ExtendedDTraceProbes on a running Java process with the jinfo utility。即使在我的命令提示符下 jinfo 也会谈到启用常规标志:

Usage:
    jinfo [option] <pid>
        (to connect to running process)
...
where <option> is one of:
    -flag [+|-]<name>    to enable or disable the named VM flag

据我所知,DTrace标志没有任何特殊价值,重要的只是它们的存在与否。

但是当我尝试这样做时,我会得到两个错误之一,这取决于我是否以sudo为前缀。

假设:
JPS

1234 StayRunning
...

与StayRunning流程相同的用户:
jinfo -flag + ExtendedDTraceProbes 1234

Exception in thread "main" java.io.IOException: Command failed in target VM
at sun.tools.attach.MacosxVirtualMachine.execute(MacosxVirtualMachine.java:200)
at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:195)
at sun.tools.attach.HotSpotVirtualMachine.setFlag(HotSpotVirtualMachine.java:172)
at sun.tools.jinfo.JInfo.flag(JInfo.java:111)
at sun.tools.jinfo.JInfo.main(JInfo.java:58)

以root身份尝试:
sudo jinfo -flag + ExtendedDTraceProbes 1234

Password: (which I enter)
1234: Unable to open socket file: target process not responding or HotSpot VM not loaded

错误位于第二行,当然该过程仍在运行。

奇怪的是,this page doesn't show the "+" option for OS X,但是我自己的机器会打印出使用信息。

这是我的简单代码。它与Eclipse类似地失败。

StayRunning.java

class StayRunning {
    public static void main( String [] args ) throws Exception {
        long counter = 0L;
        while( true ) {
            Thread.sleep( 1000 );
            counter++;
            System.out.println( "tick "+counter );
        }
    }
}

1 个答案:

答案 0 :(得分:3)

你是正确的,这个探针可以是'设置'或'未设置'(即没有特定的'值'与它相关联)。

这几乎肯定是Hotspot JVM中的一个(长期存在的)错误,并不是OSX独有的。以下是某人无法通过Windows上的jinfo设置VM标记的报告:

http://www.herongyang.com/Java-Tools/jstack-jinfo-Change-HotSpot-VM-Option.html

我可以提供无法在Linux上通过jinfo动态设置ExtendedDTraceProbes和(科学!)其他几个标志的第一手经验。事实上,经过一些尝试后,我无法找到我可以动态设置的标志。

我遇到了Sun / Oracle的相关错误:

http://bugs.sun.com/view_bug.do;jsessionid=24c1d7e1b0cda2ffffffff97aef6bbd818cf2?bug_id=6445836

最有趣的是,在评估部分: “jinfo -flag是一个动态启用DTrace探测器的临时解决方案。正如Mandy所说,这可能会消失。”

部分基于此,以及我自己过去的Hotspot文档严重过时和/或不准确的经历,我怀疑,尽管jinfo的文档/手册页,以及探针本身的文档(http://download.oracle.com/javase/6/docs/technotes/guides/vm/dtrace.html)另有说明,Hotspot中的某些实现细节已更改为使此标志的动态设置不可能,或者是它被禁用是不切实际的。换句话说,这是一个无法修复的错误。