Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java JNI : Memory allocation / partitioning

When using JNI, does the JNI binary use its own memory, or use part of the memory allocated to the JVM?


Details

When you specify -Xmx1024m as a JVM option, does the JVM allocate all 1024 mb of memory to Java objects?
Does it use part of this for Java objects and part of this for the JNI binary, or does the JNI binary have to use memory in addition to this amount? How does the JVM allocate/ partition/ manage memory use in this scenario?


Related questions:

Java memory allocation limit

like image 553
bguiz Avatar asked May 13 '11 02:05

bguiz


1 Answers

As I discovered first hand when we had a memory leak in some JNI code, the JNI binary uses its own memory within the JVM process outside of any JVM heap space. We were seeing Linux actually kill off the JVM because the JVM as a whole was exceeding 3GB of virtual memory. But we were using -Xmx384m and were only using about 40MB of that on the Java objects side of things, which pretty much proves that JNI uses memory outside of the JVM heap space.

like image 184
QuantumMechanic Avatar answered Sep 20 '22 15:09

QuantumMechanic