Memory allocation by java

2019-05-16 22:54发布

Problem : I have setted Xms512m and Xmx1024m for running application which intern use C++ native layer for performing other operation, I am getting OutOfMemory exception when running application. I need to know C++ uses which memory (ie from assigned memory Xms512m and Xmx1024m or it uses other than this setted memory).

How to get heap space and stack space for Java and C++ code while running application separately.

4条回答
女痞
2楼-- · 2019-05-16 23:30

You may use jconsole or VisualVM to see heap usage of the application.

查看更多
做自己的国王
3楼-- · 2019-05-16 23:42

The memory allocated to your JVM and the memory used by JNI and native applications are completely different. Tools like VisualVM and Jprofiler can help you determine JVM specific heap usage. If however the memory leak is from JNI or a native application, you should use options like -Xrunjnichk (available on the IBM JDK) to debug JNI calls.

查看更多
狗以群分
4楼-- · 2019-05-16 23:51

The memory allocated by native code is not in the Java Heap. Your OutOfMemory Exception caused by the java application. OOM is a clue to get you a sign that java app may use more than 1024mb memory. You can make it larger or consider the memory leak problem.

There are some links about memory leak detection:

You can do it simply:

  • get java app pid by jps
qty:~ qrtt1$ jps
4437 start.jar
10470 Jps
  • get heap dump data by jmap
jmap -dump:format=b,file=my_app_heap_data.hprof 4437
  • use mat to open it, like this:

mat

查看更多
可以哭但决不认输i
5楼-- · 2019-05-16 23:54

You can Use below monitoring applications:
jconsole
javamelody
visualvm

查看更多
登录 后发表回答