105

I'm using VisualVM from JDK 1.6.0_26 to profile a Java webapp running under Tomcat, but VisualVM often tells me that it doesn't have enough memory to take a snapshot, and to use the -Xmx switch to provide more memory to Netbeans. The problem is, I'm running VisualVM outside of Netbeans, so how can I provide JVM arguments to jvisualvm.exe?

6 Answers 6

146

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.

6
  • 2
    On (my copy of :) OSX: /System/Library/Java/Support/VisualVM.bundle/Contents/Home/etc/visualvm.conf
    – Jonas N
    Oct 5, 2012 at 20:57
  • @Zack Can you confirm that -J-Xms and -J-Xmx are actually the correct option names? Is the -J prefix necessary when these are specified in the conf file?
    – GreenGiant
    Feb 18, 2013 at 16:58
  • @GreenGiant I'm not sure if they are or aren't...In my copy of visualvm.conf, I have -J-Xms24m & -J-Xmx256m so I assume that is the correct option names. You could probably google how to format visualvm.conf for more info... Feb 18, 2013 at 18:50
  • @Zack my conf file is the same as well. Just wanted to confirm since your answer didn't include the -J prefix.
    – GreenGiant
    Feb 18, 2013 at 20:52
  • FYI, on Linux (Mint, presumably Ubuntu as well) it's /usr/lib/jvm/java-6-sun/lib/visualvm/etc/visualvm.conf. May 31, 2013 at 21:01
59

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

5
  • I couldn't get this to work. I tried jvisualvm.exe -J-Xms256m -J-Xmx1024m from the command prompt, and when inspecting the process, I could see that the arguments were not applied. Mar 5, 2012 at 17:50
  • 3
    I just tried it and it appears to append it. So I'm seeing the default 192m and also another entry for 1024m. It looks like the latter takes precedence. What version JDK? Mar 5, 2012 at 17:58
  • I'm using 1.6.0_26. When using JConsole to inspect the VisualVM process, the VM arguments section on the VM Summary tab shows the defaults and the values I provided, but when using VisualVM to inspect itself, in Overview > JVM arguments it reports the defaults only. Mar 5, 2012 at 18:45
  • I'm using 1.6.0_20, and I see 2 lines that list Xmx. The first is the default, and the latter one is the new value. I copied your command line directly from your comment above just to be certain. Output in Overview>JVM includes: -Xms24m -Xmx192m -Dsun.jvmstat.perdata.syncWaitMs=10000 -Xms256m -Xmx1024m Mar 5, 2012 at 18:52
  • Could you please explain what is the meaning of -J? Thanks. Jan 25, 2021 at 22:17
34

I started with

jvisualvm -J-Xms1024m -J-Xmx2048m

and it worked.

4
  • I like this because the location of the .conf file has changed but this still works and presumably would work for at least some other Java programs, Contrary to comments above this is not hard to find for Mac users. The world uses Google which brings us here.
    – George Co
    Oct 11, 2016 at 15:05
  • As noted in the comments below, inside of jvisualvm when you look at VM args it seems it is not working but it does. I no longer get an OOM error.
    – George Co
    Oct 11, 2016 at 15:28
  • Could you please explain what is the meaning of -J? Thanks Jan 25, 2021 at 22:17
  • This is so long ago, I don't remember my source. But if you look at all the other answer on this page, you will notice that every argument to jvisualvm that is meant to be added to the JVM runtime is preceded by -J. Sort of like an escape sequence to indicate that the argument that follows is not meant to be processed by jvisualvm itself, but rather used to modify the JVM that jvisualvm uses. Jan 27, 2021 at 23:52
31

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"
6
  • Please keep your answer focused on the solution. If you want to add meta-information, do so in a comment please.
    – Martijn Pieters
    Mar 27, 2016 at 22:31
  • And with the question tagged windows, your answer is going to hard to find for Mac users. Consider making it a new question anyway.
    – Martijn Pieters
    Mar 27, 2016 at 22:33
  • I did not vote on this post, please don't jump to conclusions.
    – Martijn Pieters
    Mar 28, 2016 at 19:09
  • Why would you do an unnecessary edit to this answer? To gain some more reputations? The answer was already focused and crystal clear. BTW, with each of your edits I'm having a down rating!
    – aspdeepak
    Mar 29, 2016 at 6:37
  • 2
    I've made one edit here, and made it clear why I did so. If you want to insist on adding a Mac-only answer to a question aimed at Windows users by tags, that's fine, but keep meta info out of it; your post should contain a solution only, not voting advice.
    – Martijn Pieters
    Mar 29, 2016 at 6:57
2

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
2

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

2
  • 2
    on my Mac it was /Applications/VisualVM.app/Contents/Resources/visualvm/etc/visualvm.conf
    – Kranach
    Sep 4, 2020 at 20:19
  • I can confirm Kranach's comment, that this is the new path. May 10, 2021 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.