104

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?

Mike Partridge
  • 5,128
  • 8
  • 35
  • 47

6 Answers6

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.

Zack Macomber
  • 6,682
  • 14
  • 57
  • 104
  • 2
    On (my copy of :) OSX: /System/Library/Java/Support/VisualVM.bundle/Contents/Home/etc/visualvm.conf – Jonas N Oct 05 '12 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 '13 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... – Zack Macomber Feb 18 '13 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 '13 at 20:52
  • FYI, on Linux (Mint, presumably Ubuntu as well) it's `/usr/lib/jvm/java-6-sun/lib/visualvm/etc/visualvm.conf`. – David Moles May 31 '13 at 21:01
  • On (my copy of :) latest OS X 10.11: /Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/lib/visualvm/etc/visualvm.conf – Dmitry Jul 21 '16 at 19:27
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

Kevin Welker
  • 7,719
  • 1
  • 40
  • 56
  • 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. – Mike Partridge Mar 05 '12 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? – Kevin Welker Mar 05 '12 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. – Mike Partridge Mar 05 '12 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` – Kevin Welker Mar 05 '12 at 18:52
  • Could you please explain what is the meaning of -J? Thanks. – Diego Ramos Jan 25 '21 at 22:17
34

I started with

jvisualvm -J-Xms1024m -J-Xmx2048m

and it worked.

Grzegorz Rożniecki
  • 27,415
  • 11
  • 90
  • 112
Prabhat Jha
  • 396
  • 3
  • 6
  • 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 '16 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 '16 at 15:28
  • Could you please explain what is the meaning of -J? Thanks – Diego Ramos Jan 25 '21 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. – Kevin Welker Jan 27 '21 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"
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
aspdeepak
  • 2,640
  • 2
  • 32
  • 37
  • 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 '16 at 22:31
  • And with the question tagged [tag:windows], your answer is going to hard to find for Mac users. Consider making it a new question *anyway*. – Martijn Pieters Mar 27 '16 at 22:33
  • I did not vote on this post, please don't jump to conclusions. – Martijn Pieters Mar 28 '16 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 '16 at 06: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 '16 at 06:57
  • If you're using JVisualVm as part of a JDK installation, it might be located on a path like `/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/lib/visualvm/etc/visualvm.conf` – Shannon Oct 12 '16 at 14:49
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

Hardik Modha
  • 12,098
  • 3
  • 36
  • 40
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
isapir
  • 21,295
  • 13
  • 115
  • 116