问题
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