visualvm intellij “Failed to create JMX connection

2019-02-08 11:02发布

问题:

I am trying to use visualVM for profiling a simple java application that I am debugging with Intellij. I start the application to debug, open visualVM, and I can see my application in the list. I can open it; however, I am unable to use sampling or profiling for my application. Other applications, such as Intellij, can be profiled just fine. When I check the visualVM logs I see:

INFO [com.sun.tools.visualvm.jmx.impl.JmxModelImpl]: connect(2749) com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded

more information: Operating System = Mac OS X version 10.9.1 running on x86_64 Java; VM; Vendor = 1.7.0_51; Java HotSpot(TM) 64-Bit Server VM 24.51-b03; Oracle Corporation Intellij IDEA = 13.0.2

if anyone has this working, please let me know how you got it. I would like to use the Intellij VisualVMLauncher as well if I can get it going.

回答1:

Maybe this helps:

java -Dcom.sun.management.jmxremote \
  -Dcom.sun.management.jmxremote.port=9010 \
  -Dcom.sun.management.jmxremote.local.only=false \
  -Dcom.sun.management.jmxremote.authenticate=false \
  -Dcom.sun.management.jmxremote.ssl=false \
  -jar xxx.jar


回答2:

This looks the JDK bug #8023786. Until this is fixed in JDK 7u60, you can run the profiled application with -XX:+StartAttachListener. Some details about this bug are also in this email thread.



回答3:

I had a similar issue earlier when running a standalone visualvm. Instead, try running the visualvm bundled with the same jdk used to run the application (in my case c:\jdk1.7.0\bin\jvisualvm.exe) and it may not need jmx in the first place.



回答4:

I tried Tomas Hurka's suggestion: add -XX:+StartAttachListener to the run config. I similarly had visualvm hang when connecting to a new debug process.

In my case I was running a JUnit test file. I set a couple of breakpoints in the tests. It turns out that when I click the resume program execution button (fn+F9 in Mac OSX), and stop at a new breakpoint in the tests, visualvm is no longer hanging, and has logged the CPU usage successfully up until that point of execution. (Previously it said CPU usage was not available for my JVM).

I was able to finally start CPU sampling and even calibrate the visualvm profiler from the breakpoint onwards. After pressing resume execution enough times the tests were over and I had a complete snapshot, which I was able to save as csv.

So, for the time being, just set a breakpoint at the earliest sensible line of your code, and make sure you turn on sampling/profiling from then on. Not ideal, but for now better than paying the huge sum for the commercial profilers.

Also, it turns out we are not the only ones with the issue of visualVM hanging, eclipse people have this problem too: Java VisualVM hangs connecting to locally process launched from eclipse

Something to do with proxy usage. Using Cmd+Shift+A and searching network in intelliJ brings this interesting result for me (second search result, below Edit Network options):

'You have JVM property java.net.useSystemProxies set to true. This will cause some network calls to go through operating system-defined proxy. If you didn't intend to use system-defined proxy, disable this property.'

I have not looked further into this avenue, since it seems that I am able to get around the hang in VisualVM by adding -XX:+StartAttachListener to run config and judicious use of breakpoints and the 'resume program execution' button.

For reference, I am using IDEA 14 Community Edition on Retina MBP 2013,OSX Mavericks, and JDK 8, with both Project SDK and VisualVM coming from the same oracle JDK (JDK 8).

I hope this was of some help, it is ridiculous that this issue has lasted nearly 1 year.