如何向 VisualVM 提供 JVM 参数?

我使用来自 JDK 1.6.0 _ 26的 VisualVM 来分析运行在 Tomcat 下的 Java Web 应用,但是 VisualVM 经常告诉我它没有足够的内存来拍摄快照,并且使用-Xmx 开关为 Netbeans 提供更多的内存。问题是,我在 Netbeans 以外的地方运行 VisualVM,那么我怎样才能为 jvisalvm.exe 提供 JVM 参数呢?

60431 次浏览

Should be able to modify the memory settings in %JDK_HOME%\lib\visualvm\etc\visualvm.conf

Xms and Xmx are in the default_options line.

or I think this works too:

jvisualvm.exe -J-Xmx512m (or whatever amount you need)

-J on the .exe command line for onetime settings, or the .conf file noted in the other answer for changing defaults

In mac, you can configure them by editing this file.

/Applications/VisualVM.app/Contents/Resources/visualvm/etc/visualvm.conf

visualvm_default_options="-J-client -J-Xms4096m -J-Xmx5120m -J-XX:+IgnoreUnrecognizedVMOptions -J-Dnetbeans.accept_license_class=com.sun.tools.visualvm.modules.startup.AcceptLicense -J-Dsun.jvmstat.perdata.syncWaitMs=10000 -J-Dsun.java2d.noddraw=true"

I started with

jvisualvm -J-Xms1024m -J-Xmx2048m

and it worked.

Update:

As per the comment from @Kranach. New path is /Applications/VisualVM.app/Contents/Resources/visualvm/etc/visualvm.conf. In this configuration file, you can change the

visualvm_default_options="-J-client -J-Xms24m -J-Xmx256m

to(e.g.)

visualvm_default_options="-J-client -J-Xms24m -J-Xmx2048m

Old Answer: For Mac OSX 10.12+

If you have downloaded the visualvm dmg from https://visualvm.github.io/download.html and have moved it to the Applications directory. You can find the configuration file visualvm.conf under the location Applications/VisualVM.app/Contents/etc/visualvm.conf. In this configuration file, you can change the

visualvm_default_options="-J-client -J-Xms24m -J-Xmx256m

to(e.g.)

visualvm_default_options="-J-client -J-Xms24m -J-Xmx2048m

In VisualVM 2 the config file is in the VisualVM directory where the downloaded file was extracted, in etc/visualvm.conf

${VISUALVM}/etc/visualvm.conf