Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which VMs or GCs support JNI pinning?

Get<PrimitiveType>ArrayElements family of functions are documented to either copy arrays, or pin them in place (and, in so doing, prevent a compacting garbage collector from moving them). It is documented as a safer, less-restrictive alternative to GetPrimitiveArrayCritical. However, I'd like to know which VMs and/or garbage collectors (if any) actually pin arrays instead of copying them.

like image 225
Aleksandr Dubinsky Avatar asked Jan 17 '14 00:01

Aleksandr Dubinsky


2 Answers

Older IBM JVMs pinned (1.4 and before - ie: NOT the current IBM J9 JVM) but since then, they have not. In general, JVMs don't like pinning as it really messes up copying garbage collectors, which is what most production JVMs do today. I'm not 100% up to date (ie: latest Java 7 builds), but historically HotSpot didn't either (for the same generational GC reasons).

Be aware: a JVM that pins today might not tomorrow, and vice versa, so you need to write your code to handle it both ways, just like the base Java libraries do.

like image 98
Trent Gray-Donald Avatar answered Sep 21 '22 02:09

Trent Gray-Donald


Shenandoah supports pinning (although it is not clear if it does so when using Get*ArrayElements or only when Get*Critical): https://shipilev.net/jvm-anatomy-park/9-jni-critical-gclocker/

like image 32
Aleksandr Dubinsky Avatar answered Sep 22 '22 02:09

Aleksandr Dubinsky