VisualVM unable to sampler memory - java

I have a tomcat instance with the JMXRemote parameter configured. The local VisualVM is able to get a sampler on CPU, however, not for Memory. The memory button is grayed out with a summary saying: "Memory sampling: Not available. Cannot connect to target application. Make sure the application is running on a supported JDK 6 or JDK 7"
JMXRemote parameter:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
Tomcat JDK version:
JDK1.6.0.30
VisualVM version:
Version: 1.6.0_30 (Build 1320-110325); platform 110131-9c8b3bfb3a1e
System: Windows Server 2008 R2 (6.1) , amd64 64bit
Java: 1.6.0_30; Java HotSpot(TM) 64-Bit Server VM (20.5-b03, mixed mode)
Vendor: Sun Microsystems Inc., http://java.sun.com/
Environment: Cp1252; en_US (visualvm)
Userdir: C:\Users\Administrator\AppData\Roaming\.visualvm\7
Clusters: C:\Program Files\Java\jdk1.6.0_30\lib\visualvm\platform
C:\Program Files\Java\jdk1.6.0_30\lib\visualvm\visualvm
C:\Program Files\Java\jdk1.6.0_30\lib\visualvm\profiler
Tomcat version:
Tomcat 6.0.32
I am running both the VisualVM and Tomcat at win server 2008. Anything i did wrong?

I had the same problem before.
You must have downloaded the version from jvisualvm homepage, right?
Don't do it!
If you use new jdk 1.7, VisualVM is already packaged in your jdk folder.
Use this version, you will not have any problem with memory sample.

This blog post leads me to believe that the temp directories of JVisualVM and Tomcat need to be the same for memory sampling to work. One of the comments on the post:
the temp directory must be set to the one used by JVisualVM, which can be discovered from the VisualVM system properties tab (java.io.tmpdir). Once I set the CATALINA_TMPDIR directory properly, this worked beautifully.

I've just run into this same issue and the answers above solved my problem but it took me a while to figure out how. Just in case anyone else is still having trouble and ends up this far down the thread, I was using the JDK that is part of the weblogic server configured through Eclipse and not the JDK that I installed seperately. I'm still a junior programmer and I wasn't putting 2 and 2 together until I started looking through my eclipse settings and verified my Installed JREs.
Ran the jvisualvm.exe from the weblogic jdk and all worked.

I would check the version of VisualVM is exactly the same as the JVM.
VisualVM is very version specific. I assume its still under fairly rapid development.
(Re posted as an answer as it may be the solution)

I've faced similar issues with JVisualVM, I've even asked a question about it here
A couple of insights/advices:
So, in order to sample memory you don't need jmx options.
I would double check whether you have 64 bit jvms installed along with 32 bit jdks on the same machine (even if they're not running and all the environment vars defined properly), I've read somewhere that sometimes it drives the JVisualVM crazy :) (yes I know it doesn't sound reasonable to us, java developers)
If it doesn't work, just uninstall all jdks that you have and install only 1 that you need. It can solve the issue.
I hope it will help you to resolve the issue, after all like Peter said these things are new and evolving

Here is my solution for similar problem: https://stackoverflow.com/a/16330238/715483
You can resolved this error by
$ ssh -Y user#remotemachine
$ wget http://java.net/projects/visualvm/downloads/download/release135/visualvm_135.zip
$ unzip visualvm_135.zip
$ cd visualvm_135/bin
$ ./visualvm
This instance of visualvm will be full featured, including memory and CPU sampling.
Read more about it here: http://shahriarinia.blogspot.com/2013/05/java-cpumemory-heap-usage-monitoring.html
http://mshahriarinia.com/

Make sure your VirtualVM/JDK is a 32-bit copy if your JRE is. If you are using Eclipse, check the selected JRE on Installed JRE's section.

And I have the same problem.
I always launched tomcat as a service and connected it with visualvm through jmx connection.
When had corrected catalina.bat:
set JAVA_OPTS=%JAVA_OPTS%
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=9090
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
and launched it with startup.bat, visualvm automatically determine tomcat, and memory sampling was active.

I've got the same problem but with different envirnoment. My server was a Linux machine, the client a Windows 7 machine, but the problem is the same.
The solution was to launch the jvisualvm in the same machine and with the same user that is running the targeted application. If i run jvisualvm with other other user (ex: root) the memory button became gray.

Firstly, JMX should be enabled. Add the linked command line environment variables necessary to activate JMX if you haven't.
The environment variable CATALINA_TMPDIR should be set to match the JVisualVM as seen in the "System properties" tab of the Local > VisualVM. You can open this by double clicking on the "VisualVM" labeled entry in the Applications pane on the left.
Environment variables can be set by searching for environment, "edit environment variables for your account". New... > Enter a name and value.
If you would like the temporary directory of VisualVM to be somewhere else, you'll have to launch VisualVM from the command line and add an argument.
C:\Program Files\Java\jdk1.8.0_65\bin>jvisualvm.exe -J-Djava.io.tmpdir=C:\Users\You\Temp

Related

pyCharm debugging: JRE without jstack?

I need to debug pyCharm community version on Windows 7 and try to follow what their manual says:
JStack
This command line utility is provided with the JDK installation and
can be found in JAVA_HOME\bin directory. Make sure to use the same or
close JDK version to the one the IDE runs under (see Help | About). It
will not work if IDE runs under 32-bit JDK and you run jstack from the
64-bit JDK distribution and vice versa.
To use jstack you need the IDE process identifier (PID). PID can be
obtained using jps utility that is located in the same directory as
jstack.
jps -mv
My pyCharm: help/about reads: JRE 1.7.0_40 b43 x86
How ever, in C:\Program Files (x86)\Java\jre7\bin there is no jps and no jstack. I'm not used to the command line in Windows - perhaps I'm doing something wrong here? Am I supposed to look in a different directory? I could not find any system wide environmental variable JAVA_HOME what could give any clues here.
Well, you need a Java Development Kit (JDK) instead of a Java Runtime Environment (JRE).
It is a bit larger but has many other dev tools (like jstack, jps, jvisualvm, etc., even the source code of Java). Download and install one to see the differences.

Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine

I am facing this problem since more than a month, here is what I see when I run java on command line:
$ java -Xmx1300m
Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.
If I run with less memory it works fine
$ java -Xmx1240m Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) ..... .....
I spent a week trying to debug this and nothing worked. Finally I had my IT support guys replace the laptop. This happened a month ago on 10/23. Now, after a month, the same problem is back on my new system.
My system configuration is:
Win 7 Enterprise (64-bit), Service Pack 1. Intel(R) Core(TM) i7-2640M
CPU # 2.80GHz 8.00 GB RAM
Java: java version "1.5.0_20" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_20-b02) Java HotSpot(TM) Client VM (build 1.5.0_20-b02, mixed mode)
We are a team of about 30 guys here and I am the only one facing this. All others have almost the same config and working fine for them.
An important observation is Java works fine for some time and then this problem appears once it appears it doesn't go away, even if I re-install java.
I faced this issue the 3rd time after the IT support guys re-imaged by laptop. It worked for a month and now the same problem is back.
Everybody is completely clueless. I have started using 2 laptops now. :-)
Anyway, here is how to fix it:
Go to Start->Control Panel->System->Advanced(tab)->Environment Variables->System Variables->New:
Variable name: _JAVA_OPTIONS
Variable value: -Xmx512M
taken from this link
Eureka ! Finally I found a solution on this.
This is caused by Windows update that stops any 32-bit processes from consuming more than 1200 MB on a 64-bit machine. The only way you can repair this is by using the System Restore option on Win 7.
Start >> All Programs >> Accessories >> System Tools >> System Restore.
And then restore to a date on which your Java worked fine. This worked for me. What is surprising here is Windows still pushes system updates under the name of "Critical Updates" even when you disable all windows updates. ^&%)#* Windows :-)
This might also occur if you are running on 64-bit Machine with 32-bit JVM (JDK), switch it to 64-bit JVM. Check your (Right Click on My Computer --> Properties) Control Panel\System and Security\System --> Advanced System Settings -->Advanced Tab--> Environment Variables --> JAVA_HOME...
Thanks.I changed heap space from 2000MB to 1024MB and it worked...
I've just seen this problem myself, Jboss AS7 with jdk1.5.0_09. Update System Property JAVA_HOME to jdk1.7+ to fix (I'm using jdk1.7.0_67).
If your computer is a 64bit, all you need to do is uninstall your Java x86 version and install a 64bit version. I had the same problem and this worked. Nothing further needs to be done.
you can do update the User path as inside
_JAVA_OPTIONS : -Xmx512M
Path : C:\Program Files (x86)\Java\jdk1.8.0_231\bin;C:\Program Files(x86)\Java\jdk1.8.0_231\jre\bin
for now it is working /
/
Sometimes it may happen that you run multiple applications on the same java VM. In Case you have tried all the other solutions described above and it didnt work. Try Running your process by running it on a newly created java VM by passing vmargs
-agentlib:jdwp=transport=dt_socket,server=y,address=10049,suspend=n .
Here address is what the vm takes.

“Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G

First of all, I have a box with 8gb of ram, so I doubt total memory is the issue.
This application is running fine on machines with 6gb or less.
I am trying to reserve 3GB of space using -Xmx3G under "VM Arguments" in Run Configurations in Eclipse.
Every time I try to reserve more than 1500mb, I get this error:
“Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G
What is going on here?
Could it be that you're using a 32-bit jvm on that machine?
Here is how to fix it:
Go to Start->Control Panel->System->Advanced(tab)->Environment Variables->System
Variables->New:
Variable name: _JAVA_OPTIONS
Variable value: -Xmx512M
Variable name: Path
Variable value: ;C:\Program Files\Java\jre6\bin;F:\JDK\bin;
Change this to your appropriate path.
This is actually not an Eclipse-specific issue; it's a general
Java-on-Windows issue. It's because of how the JVM allocates memory on
Windows; it insists on allocating a contiguous chunk of memory, which
often Windows can't provide, even if there are enough separate chunks to
satisfy the allocation request.
There are utilities that will try to help Windows "defrag" its memory,
which would, in theory, help this situation; but I've not really tried
them in earnest so can't speak to their effectiveness.
One thing that I've heard sometimes that might help is to reboot Windows
and, before starting any other apps, launch the Java app that needs the
big chunk of memory. If you're lucky, Windows won't have fragmented its
memory space yet and Java will get the contiguous block that is asks for.
Somewhere out on the interwebs there are more technical explanations and
analyses of this issue, but I don't have any references handy.
I did find this, though, which looks helpful: https://stackoverflow.com/a/497757/639520
First the JRE of 32bits can't use more ~1.5Gb of ram. So if you want more, use a 64bits JRE.
Second, When a new JVM starts, this sum the -Xmx property of the all JVM that are running, and check if there is enough memory left on the system to run at their own -Xmx, if is not enough then the error occurs.
I was using Liferay with Tomcat server from eclipse IDE.
I was stuck with this same error on click on server start up.
Double click on server from eclipse.
it open up Server Overview page. Updated memory arguments from -Xmx1024m -XX:MaxPermSize=256m to -Xmx512m -XX:MaxPermSize=256m.
Then it was working for me.
Make sure that Eclipse is actually running the same JVM you think it's running. If you use java in your web browser ever, you likely have a 32-bit version floating around too that might be taking precedence if it installed or updated lately.
To be absolutely sure, I recommend adding these two lines to your eclipse.ini file at the top:
-vm
C:/Java/jdk1.6.0_27/bin
...where on my machine C:/Java/jdk1.6.0_27/bin where the JVM I know is 64-bit is located. Be sure to have the bin folder there.
(As a bonus, on Windows 7, this also allows you to actually "pin the tab" which is why I had to do this for my own usage)
This is the issue of Heap size. Edit your .bat (Batch file). It might be showing Heap size 1024. Change it to 512 Then it should work.
Just put # symbol in front of org.gradle.jvmargs=-Xmx1536m in gradle.properties
# org.gradle.jvmargs=-Xmx1536m
I also had the same problem while using Eclipse which was 32 bit and the JVM used by it was 64 bit.
When I routed the Eclipse to 32 bit JVM then it worked
I know that i am a bit late, but here my answer comes:
I just installed the Java online Version from Oracle(not the offline 64-Bit one).
After having added the JAVA_HOME ENV variable, it just worked!
Hope I could help :)
Probably you are trying wrong options anyways.
I got a similar error with supporting error log:
Java HotSpot(TM) Client VM warning: ignoring option PermSize=32M; support was removed in 8.0
Java HotSpot(TM) Client VM warning: ignoring option MaxPermSize=128M; support was removed in 8.0
Im my case, the software did not support java 8 yet(script was using old JVM arguments) but I had had java 8 by default.
One of the reason for this issue is no memory available for Tomcat to start. Try to delete the unwanted running software from windows and restart the eclipse and tomcat.
Solution is simple. No need to go deep into this issue.
If you are running on 64bit machine then follow below steps:
Unistall 32 bit java first (check in C:\Program Files (x86) for its existence)
Install the newer version JDK kit 64 bit (includes JRE)
Set the environment path (To avoid conflict error if you have two different 64bit JRE)
Check in command prompt by typing javac command.
Restart / Done
You can have two different Java installed but don't forgot to set path.
Please set JAVA_OPTS=-Xms256m -Xmx512m in environment variables, it should solve the issue, it worked for me.
Find out if you are using a 32bit version or 64bit version of Java. To know that use the command
java -version
The 3rd line of the output should give you if it 32bit or 64bit.
If it is 32bit uninstall and install a 64bit version.

VisualVM "not supported for this JVM" on all local applications?

I have already spent a long time to load and test my application, now I need to profile it. But unluckily, the VisualVM always says "not supported for this JVM" on my local applications?
The applications were started on the same JVM with VisualVM.
I found out that (at least under Windows) one can easily write small batch files to run VisualVM in combination with specific JVMs, which is important for me, since I have installed the 32bit JDK alongside with the 64bit JDK (I need both, so this is sensible for me).
I have created two batch files in the folder "S:\applications\visualvm\bin\":
run_32.bat:
#echo off
START "VisualVM 32" visualvm.exe --jdkhome "C:\Program Files (x86)\Java\jdk1.7.0_07"
run_64.bat:
#echo off
START "VisualVM 64" visualvm.exe --jdkhome "C:\Program Files\Java\jdk1.7.0_07"
Obviously, all paths may differ on your system, but the general idea should still work correctly (on all 64bit versions of Windows). The benefit is that I can use the 32bit batch file when I want to use VisualVM in combination with Java applications that run on the 32bit JVM, and so on for 64bit.
The "start" command has the only benefit that the batch file launches the application without waiting for it to finish, so the command prompt window closes immediately. This is not a feature of VisualVM, but of the Windows batch file interpreter.
In my case, even with the JVMs matching (both 64-Bit), the only way to get things working was sending the argument -Dcom.sun.management.jmxremote to the JVM to be monitored. That also works if you are having problems to connect via Java Mission Control (JMC).
According to JMX's documentation, this what the argument does:
Setting this property registered the Java VM platform's MBeans and published the Remote Method Invocation (RMI) connector via a private interface to allow JMX client applications to monitor a local Java platform, that is, a Java VM running on the same machine as the JMX client.
This was supposed to be enabled automatically, but for some reason it wasn't on my Linux.
VisualVM needs to be run with the same JVM - at least Java 6 with the same 32-bit/64-bit size - as the program to be profiled. (You also need to be the same user, but then this message does not apply).
I would be triple-check that it was the exact same JVM in your situation.
On Linux:
Make sure that your /etc/hosts correctly references the effective ip address of your "hostname"
It appears that a discrepancy here totally confuses the poor jvisualvm and its programmers.
I too got the same problem for local tomcat, I search for solutions for stackoverflow. after some serious debugging, I figured out that VisualGC don't have permissions to get GC informations from tool.jar file.
by links
http://docs.oracle.com/javase/7/docs/technotes/tools/share/jstatd.html#SECURITY
https://stackoverflow.com/a/42107355/3876619
I following steps to solve the issue
1) Create a permission file
vim /tmp/tools.policy
Add
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
save it
2) Now add /tmp/tools.policy to JVM startup parameters
-Djava.security.policy=/tmp/tools.policy
3) Run jvisualVm with sudo
An issue that I just found, thanks to the hint from #user3356656, is that if you start the program while your machine is on one IP, and then try to connect while it is on a different IP, it will fail.
I also met this issue. My case is that on linux, I started tomcat with tomcat_user but I run jvisualvm with root user. It works after I start tomcat with root user.
I was having the problem having of visualvm detect my local tomcat installation on Windows 7. I could connect manually, but then things like memory snapshots and visualgc plugin were not enabled. I confirmed that I was using same JVM version, temp file permissions, etc. Didn't work. Then I found that starting visualvm first, and then tomcat, solved the problem.
As you can see, you are running VisualVM on 32bit JVM
You don't need to unistall 32bit JVM. Just tell VisualVM to use tour 64bit JVM.
If you want to change it permanently, you can edit
in visualvm_13\etc\visualvm.conf and specify the path of jvm here
My problem was JVM optimizations - -XX:+PerfDisableSharedMem flag will break VisualGC. This is apparent if jps will not show your app in the listing.
I can reproduce next behaviour.
I have a java application with right-click menu item to open jvisualvm.
I'm running this java application as standalone setup from a bat file.
It means I modify %path% and other needed environment variables like JDK
accordingly to form my environment.
The BAT that starts application is marked running as non-admin. Environment points to a 64-bit JDK.
Then I start other java application as admin. VM lives from the to same 64-bit JDK-source.
Then I start jvisualvm from first app with the right click ie.as non-admin.
I can see the app in jvisualvm ‘Applications list’ but clickin ‘System properties’ gives error. Message is “Not supported for this JVM”.
JVM arguments are exposed.
Solution is like in some other previous comments:
Starting my right-click jvisualvm-starter as admin I can see also "system properties" .
Certainly if JDKs would be 32-bit and other 64-bit it would not work. been there.
I thought this notion needs to be added here.
In my case, the application was running with admin permissions. So, visualVM also need to be running as admin.
I have changed name to my Windows User and set it all lowercase, restarted my PC and it all works now.
For me, the reason is that I have run the "jstatd" with a different user with the JVM process. I have a special user in the linux to start the JVM thread(it is a tomcat), but I start the jstatd process with root. If you use root to run jps, you cannot see any information of the JVM threads belonging to other users. That is the trouble.
I killed the "jstatd" process started by root, su to the owner of the JVM process, and restart the "jstatd" process and everything wokrs fine now.

Jconsole cannot connect to java processes running as Windows 7 Services

We have a Java process which we run as a Windows service (using srvany). It runs with Java 1.6 (1.6.0.23 at the moment).
In the past (Windows XP), I could connect JConsole to the processes, on Windows 7 I cannot do this anymore.
If I run jconsole <pid> I get “Invalid process id:4488”. The services are running as SYSTEM user.
If I make the service run as my desktop user (using “Log On as This Account”) the services process ID appear in JConsole, but they are grayed out and I cannot connect.
Is it impossible to dynamically connect to Java processes when they are running as a Windows 7 service?
Perhaps it is a 64bit/32bit problem, I have several applications compiled with 32bit JDK, which could not be opened with JConsole from 64bit JDK on Windows 7 64bit, after I downloaded the 32bit JDK it worked.
Others have been able to run jstack on 2008r2 which may provide some insight on how to get jconsole to connect on Windows 7. As you noted in your comment, the permissions are important. If the service and jconsole can't access the temp directory to write to the appropriate hsperf subdirectory, it won't work. What is also important is the location of the temp directory, the user the service is running, and the user that is running jconsole.
Running SysInternals psexec -s -i <jdk_home>\bin\jconsole <PID> can be used to run jconsole as Local System, the same user that I believe you are using to run your service.
My experience running jconsole from JDK 1.5 in Server 2008 as a system user was unsuccessful. With permissions that I thought should have been sufficient, I got a Could Not Open PerfMemory error. Java 1.6 may be a different story.
In light of all the challenges with running jconsole locally, you would probably have better luck setting it up to accept remote connections. You could set it up for local-only access with your firewall blocking that port from external access.
Add the following to JAVA_OPTION
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
Then,
Use JConsole to connecet remote session:
localhost:8086
I am currently facing the same problem but on Windows 2003 R2 (SP2). There is on open bug in Oracle Bug database (bug id 6399729)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6399729
Also there is a work-around posted towards the end. It talks about installing java in "install" mode :-), but didn't work for me on Windows 2003 though. But your mileage may vary!!
Change Environment Variable TEMP and Tmp to a different folder that you created.
Like c:\theTemp
It might be a problem with the folder %TMP%/hsperfdata_{USER_NAME}.
In my case, it worked after I :
close all applications running over the JVM
delete the folder %TMP%/hsperfdata_{USER_NAME} (exemple: C:/Temp/hsperfdata_MyUser)
reopen JConsole (it recreates the folder)
Hope it helps. You can also take a look at this thread in Oracle community.

Categories