Garbage collection and JNI call

后端 未结 3 990
庸人自扰
庸人自扰 2021-01-07 00:07

I am having an issue with a JNI program randomly running out of memory.

This is a 32 bit java program which reads a file, does some image processing, typically using

3条回答
  •  鱼传尺愫
    2021-01-07 00:52

    The following assumes you're using the hotspot jvm.

    32bit processes are not just constrained by committed memory, far more importantly they're constrained by virtual memory, i.e. reserved address space. On 64bit systems you only have 4GB worth of addresses that can be used, on 32bit systems it's only 2-3GB.

    The JVM will reserve a fixed, possibly large amount of address space for the managed heap up front, then dynamically allocates some internal structures on top of that amount and then possibly even more for DirectByteBuffers or memory-mapped files. This can leave very little room for native code to run.

    Use Native Memory Tracking to determine how much various parts of the JVMs are using and pmap to check for memory-mapped files. Then try to limit that without hampering your application.

    Alternatively you could spawn a new process and do the image processing there.

提交回复
热议问题