Can a java application allocate more memory than specified by jvm startup parameters?

£可爱£侵袭症+ 提交于 2019-12-02 04:38:20

问题


Assuming a java application is not using any native libraries. Is there a way that it anyway can allocate more memory than specified by jvm startup parameters?

Asking the other way round: Can I rely that a java application will never allocate more memory than restricted by JVM startup parameters?


回答1:


Yes, it can. It cannot allocate more memory on the JVM heap, but it can allocate native memory by using ByteBuffer.allocateDirect or by calling to custom native code.




回答2:


Indeed, you always need more memory than the -Xmx specified in your startup script. GC internals, JIT optimization tables, off heap allocations, permgen, thread stacks, etc are all taking their toll.




回答3:


No, a Java application can not go beyond the size specified by -Xmx. It wouldn't make much sense if it could - why bother having -Xmx in the first place, then?

I found an interesting link on Dream.In.Code where a user has given an example of a program that manages to resize itself, but it works by spawning a new JVM process.



来源:https://stackoverflow.com/questions/18977887/can-a-java-application-allocate-more-memory-than-specified-by-jvm-startup-parame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!