Java performance tuning, JNI memory leak - java

I have a Java application. It is a Linux platform. and we are using Java 6. It is normal sdk java plus some JNI.
We using visualvm to monitor the memory leak. We notice from visualvm application does not consume heap continuously. But the whole process memory increases all the time up to linux killing the process.
Then we are suspecting the JNI part. Since JNI part memory leak could not be seen by visualvm. Could someone drop some hints on how to check JNI memory leak when do Java Performance testing?

Oracle has some documentation on how you can create your own leak tracker in such a case. The dbx command is mentioned as one alternative available on Linux.

Related

Java memory usage breakdown - native library (DLL) usage

My Java program is taking up huge amounts of memory ~3GB and I have set xmx300MB. Additionally different tools report different memory usage.
jcmd: 576MB
Task Manager: 967MB
Resource Monitor: 3478MB
When I close the program Task Manager shows the memory usage dropping by about 3GB. My question is how can I see what is using this memory? It seems like it is not java due to the output I see by jcmd. I suspect it might be a DLL that my Java program is using. Are there any tools which can be used here?
Here's a toolset and instructions.
You can first confirm your suspicions that it is the DLL by enabling Native Memory Tracking with -XX:NativeMemoryTracking=summary (or detail), then re-check with jcmd VM.native_memory to verify it's not Java doing native memory allocation.
If you don't see a large obvious chunk under the Native Memory Tracking part, you'll be out of Java land and have to try the tools listed in "Native Memory Leaks from Outside the JVM" (jemalloc, valgrind, Purify, etc.).

how can i find which application is causing memory leaks

I am running Tomcat-6.0.32 on the RHEL 5.4 with JDK-1.6.0_23 version. I am running almost more than 15 applications. Applications are small applications only. My RAM is 8GB and swap is 12GB. I set the heap size from 512Mb to 4GB.
The issue is after a few hours or days of running, the tomcat is not providing service though it is up and running. While I could see the catalina.out log file, it is showing memory leak problem.
Now, my concern is I need to show a solution to that issue or at least I need to highlight the application which is causing the memory leaks.
Could anyone explain how I can discover which application is causing the memory leak issue?
One option is to use heap dumps (see How to get a thread and heap dump of a Java process on Windows that's not running in a console) and analyze heap dump later on.
Or another option is to analyse process directly using tools like jmap, VisualVM and similar.
You may use the combination of jmap/jhat tools (Both these are unsupported as of Java 8) to gather the heap dump (using mmap) and identify the top objects in heap (using jhat). Try to co-relate these objects with the application and identify the rogue one.

Memory Leak Detection in DLLs

I use third party DLL's in my java application to access native methods written in C. My application often gets crashed with malloc failed or out of swap space error message. There is no memory leak in my java application (Verified with profilers). Now I doubt that memory leak in third party DLL's. Is there any way to find out leak in DLL's.
I've used a C/C++ tool to detect memory leaks in my dlls several months ago:
http://www.codeproject.com/Articles/8448/Memory-Leak-Detection
And you also have:
http://vld.codeplex.com/
my first choice to detect memory issues is valgrind. with java and JIT it might however not always work.
but still worth to give it a shot. try running
valgrind --smc-check=all --trace-children=yes --show-reachable=yes --leak-check=full [your command]
cheers,

Java Process consumes more then 2 GB of memory

The Java Process of JacORB notification service consumes about 2 GB of memory in Windows 2008. From YourKit I came to know that the Java Heap does not exceed 30 MB. So I concluded that there is no leak in the Java Heap. I would like to know how to find where is memory getting consumed. I read a few articles on the internet talking about the Java Native Heap. How to conclude if there is a leak in the Native Heap? We are using JRE 1.6 from Oracle (sun).
Exceptionally good tool for analyzing memory leaks in Java is Memory Analyzer. It could be downloaded as an Eclipse plugin, or as a standalone application. However, I recommend the latter. Check it out. It also has very good help pages.

Analyze Tomcat Heap in detail on a production System

Having analyzed a light-load web application running in tomcat, using JMX Console, it turns out the "PS Old Gen" is growing slowly but constant. It starts with 200MB and grows around 80MB/Hour.
CPU is not an issue, it runs at 0-1% on average, but somewhere it leaks memory, so it will become unstable some days after deployment.
How do i find out what objects are allocated on the heap? Are there any good tutorials or tools you know?
You could try jmap, one of the JDK Development Tools. You can use jhat with the output to walk heap dumps using your web browser.
See this answer for a short explanation.
This comes up quite often, so searching SO for those tools should turn up some alternatives.
I've used the HeapAnalyzer tool from IBM's alphaWorks with good success. It takes output from Java's heap profile, hprof, and analyzes it to show you the most likely memory leaks.
You can use NetBeans profiler. It has 2 modes, launching tomcat profiled directly from ide (for localhost) or using a remote profiling with a JAR provided and some run config on server.
I used it in a project for a memory leak and it was useful.
See my answer here:
Strategies for the diagnosis of Java memory issues
And there are also tips here:
How can I figure out what is holding on to unfreed objects?
What you are seeing is normal, unless you can prove otherwise.
You do not need to analyze the heap when the additional "consumed space" disappears when a GC in the old space happens.
At some point, when the used space reaches your maximum heap size you will observe a pause caused by the default GC you use and afterwards the used memory should go down a lot. Only if it does not go down after a GC you might be interested what is still holding onto those objects.
JRockit Mission Control can analyze memory leaks while connected to JVM. No need to take snapshots all the time. This can be useful if you have a server with a large heap.
Just hook the tool up to the JVM and it will give you a trend table where you can see which type of objects that are growing the most, and then you can explore references to those objects. You can also get allocations traces, while the JVM is running, so you can see where in the application the objects are allocated.
You can download it here for free

Categories