Java JNI:内存分配/分区 [英] Java JNI : Memory allocation / partitioning
问题描述
当您指定 -Xmx1024m
作为JVM选项时,JVM是否分配了所有1024 MB的内存到Java对象?
它是否将部分内容用于Java对象,其中一部分用于JNI二进制文件,还是JNI二进制文件除此之外还必须使用内存?在这种情况下,JVM如何分配/分区/管理内存使用?
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?
推荐答案
正如我在一些JNI代码中发现内存泄漏时发现的第一手资料,JNI二进制文件在任何JVM堆之外的JVM进程中使用自己的内存空间。我们看到Linux实际上已经淘汰了JVM,因为JVM整体上超过了3GB的虚拟内存。但是我们使用 -Xmx384m
并且只在Java对象方面使用了大约40MB,这几乎证明了JNI使用JVM堆空间之外的内存。
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.
这篇关于Java JNI:内存分配/分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!