NIO IOUtils Direct vs Heap

Andrew Haley aph at redhat.com
Mon Aug 1 00:47:53 UTC 2016


On 01/08/16 01:23, Jon V. wrote:

> So it basically comes down to the need to keep the threads at safe
> points as often as possible?  Don’t JNI calls already prevent GC due
> to references as arguments?

No.  JNI calls don't prevent GC.  When you access the elements of a
byte array in JNI you use GetByteArrayElements, and that copies the
data to native memory.  You could use GetPrimitiveArrayCritical which
may not do such copying and may block the GC, but in that case you
must not make any blocking system call.  If you do, you are on the
fast road to deadlock.  There's no getting away from it: if you want
to call write(), your data must be in native memory.

Andrew.


More information about the jdk8u-dev mailing list