无法在 Mac OS X 上通过 jinfo 启用 DTrace 探针
在 Snow Leopard 上运行 Java 6。
您应该能够使用 jinfo 实用程序在正在运行的 Java 进程上打开 ExtendedDTraceProbes< /a>.即使在我的命令提示符下,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
错误在第二行,当然进程仍在运行。
奇怪的是,此页面不显示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 );
}
}
}
Running Java 6 on Snow Leopard.
You're supposed to be able to turn on ExtendedDTraceProbes on a running Java process with the jinfo utility. Even at my command prompt jinfo talks about about enabling general flags:
Usage:
jinfo [option] <pid>
(to connect to running process)
...
where <option> is one of:
-flag [+|-]<name> to enable or disable the named VM flag
And as far as I know the DTrace flags do not have any special value, it's just their presence or absence that matters.
But when I try to do it I get one of two errors, depending on whether I preface it with sudo or not.
Assuming:
jps
1234 StayRunning
...
Same user as StayRunning process:
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)
Trying as 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
The error is on the second line, and of course the process is still running.
Oddly, this page doesn't show the "+" option for OS X, but my own machine prints out the usage message.
Here's my simple code. It fails similarly with 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 );
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是正确的,该探测器可以“设置”或“取消设置”(即没有与其关联的特定“值”)。
这几乎肯定是 Hotspot JVM 中的一个(长期存在的)错误,而不是 OSX 所独有的。以下是无法在 Windows 上通过 jinfo 设置 VM 标志的人的报告:
http://www.herongyang.com/Java-Tools/jstack-jinfo-Change-HotSpot-VM-Option.html
我可以提供无法设置 ExtendedDTraceProbes 的第一手经验和(为了科学!)在 Linux 上通过 jinfo 动态地设置其他几个标志。事实上,经过几次尝试后,我无法找到可以动态设置的标志。
我在 Sun/Oracle 上遇到了一个相关错误:
https://bugs .java.com/bugdatabase/view_bug;jsessionid=24c1d7e1b0cda2ffffffff97aef6bbd818cf2?bug_id=6445836
最有趣的是,在评估部分:
“jinfo -flag 是动态启用 DTrace 探测的临时解决方案。正如 Mandy 所说,这应该会消失。”
部分基于此,以及我自己过去的 Hotspot 文档经验,这些文档严重过时和/或不准确,我怀疑,尽管 jinfo 的文档/手册页以及探测器本身的文档(http://download.oracle.com/javase/6/ docs/technotes/guides/vm/dtrace.html)否则表明,Hotspot 中的某些实现细节发生了更改,导致该标志的动态设置要么不可能,要么不切实际以至于被禁用。换句话说,这是一个无法修复的错误。
You are correct that this probe is one that can either be 'set' or 'unset' (ie no particular 'value' is associated with it).
This is almost definitely a (longstanding) bug in the Hotspot JVM, and not unique to OSX. Here is a report from someone unable to set VM flags via jinfo on Windows:
http://www.herongyang.com/Java-Tools/jstack-jinfo-Change-HotSpot-VM-Option.html
I can provide firsthand experience of being unable to set ExtendedDTraceProbes and (for science!) several other flags dynamically via jinfo on Linux. In fact, after a handful of tries I was not able to find a flag that I could set dynamically.
I came across a relevant bug on Sun/Oracle:
https://bugs.java.com/bugdatabase/view_bug;jsessionid=24c1d7e1b0cda2ffffffff97aef6bbd818cf2?bug_id=6445836
Most interestingly, in the Evaluation section:
"jinfo -flag is an interim solution to enable DTrace probes dynamically. As Mandy said, this is suppose to go away."
Based in part on this, as well as my own past experiences with Hotspot documentation being grossly out of date and/or inaccurate, I suspect that, despite the documentation/manpage for jinfo, as well as the documentation for the probes themselves (http://download.oracle.com/javase/6/docs/technotes/guides/vm/dtrace.html) indicating otherwise, that some implementation detail in Hotspot changed to make the dynamic setting of this flag either impossible, or so impractical that it was disabled. In other words, this is a bug that will not get fixed.