2

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?

yaccob
  • 1,230
  • 13
  • 16
  • 1
    A Java *application* will always use more than the maximum memory (heap size) defined by the parameters. See for example: http://stackoverflow.com/q/4247735/829571 – assylias Sep 24 '13 at 09:41

3 Answers3

2

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.

Piotr Kołaczkowski
  • 2,601
  • 12
  • 14
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.

Flexo
  • 87,323
  • 22
  • 191
  • 272
Ivo
  • 444
  • 3
  • 7
-1

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.

DeadlyFugu
  • 152
  • 5