For Example:
One day, I got into trouble with eclipse showing OutOfMemoryError error. By default, eclipse uses 256 MB PermGenSpace for the application. If you can open Configuration file with extension .INI of eclipse you will find that. Increasing that size resolved the problem for me.
From this we know that it’s not the application error. It’s a configuration problem for the application showing OutOfMemoryError error.
Understanding Eclipse IDE will help a developer to deal with all sort of problems. That’s a different ball game all together.
Remember understanding JVM working will surely help us. Our concentration here in this article is to know about debugging tool that helps us to identify memory leaks.
With the release of Java 8 it’s obvious that we need to learn the VisulaVM tool which is provided with the JDK. This also helps us to know the performance issues with the code and fix them.
Let’s look at technology called jvmstat first. Folks, understand that no use diving into the sea to find more without mastering this drop in the hand.
Visit the following link. Click on the download link and download zip folder.
http://www.oracle.com/technetwork/java/jvmstat-142257.html
Extract the zip folder named jvmstat
Place that folder as you saw in below picture (C Drive). Check the folders are as shown in the picture before moving forward.
Before proceeding set the environment variables as shown below.
Make sure you add this “C:\Program Files(x86)\Java\jdk1.7.0_40\bin;.”(Without double quotes) to the existing PATH variable
Then add the following environment variables,
Variable name: Java_Home
Variable value: C:\Program Files(x86)\Java\jre7
Variable name: JVMSTAT_JAVA_HOME
Variable value: C:\Program Files(x86)\Java\jdk1.7.0_40
If you are using 64-bit operating system. Notice that
Program Files(x86) is equivalent to
Progra~2. Don’t confuse between the two. You can use any of those whenever it’s required.
Step 1:
Type the following command in the command prompt
SET PATH= C:\jvmstat\bat;C:\jvmstat\bin;C:\jvmstat;%PATH%
%PATH% - This make sure the existing path setting for the variable name Path doesn’t get disturbed.
Step 2:
Paste the following line in the notepad and save it as jstatd.policy in root of C Drive. Please make sure you put “jstatd.policy” (in double quotes) while saving.
grant codebase "file:${java.home}/../lib/tools.jar" { permission java.security.AllPermission; };
Note: If it’s not permitted to save in root of C drive. Save it somewhere else and then copy and paste to the root of the C drive. This worked for me.
Step 3:
Type the following command as shown below
jstat -gcutil 0 1000 3
Before running the following command you need to download java2demo.jar by googling.
I placed it in the path e:\demo\jfc\Java2D\ as shown in the above image.
Type the following command as shown below
java –jar e:\demo\jfc\Java2D\java2demo.jar
You will see an application running playing music.
Step 4:
Now, take another instance of command prompt and type the following commands.
jps
SET PATH=C:\jvmstat\bat;%PATH% (We are setting this path to make sure visualgc command works for us. In the sense, we are telling where locate visualgc bat file for the system)
jstat –gcutil 6436 1000 3 (You can notice in the below figure 6436 is the lvmid given as input)
visualgc 6436 (See figure to know about input 6436 given)
Here the output as shown in the following figure
That’s it. I am done. This article helps you to understand jvmstat technology/VisualGC utility. Which is the building block to understand VisualVM. Extend your knowledge on this. Stay tuned for more.