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.
Asked
Active
Viewed 479 times
7

Aleksandr Dubinsky
- 22,436
- 15
- 82
- 99
2 Answers
10
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.

Trent Gray-Donald
- 2,286
- 14
- 17
2
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/

Aleksandr Dubinsky
- 22,436
- 15
- 82
- 99
-
Shanandoah became available as an experimental feature of OpenJDK 12. – Aleksandr Dubinsky Aug 12 '19 at 11:11
-
Shenandoah reached GA in Java 15. – Aleksandr Dubinsky Aug 31 '21 at 09:59